Can you have a struct in another struct?
Displaying 1-11 of 11 total.
1
Please enter a numerical value for the importance of this sticky.
Enter 0 to unsticky.
blues_zodiakos

I'm finding something very hard to do without classes. It REALLY makes me wonder how they programmed it back in 1984 :D

Basically, here's a simple version of the problem.


struct portformat
{
int x;
int y;
int state;
}

struct Object
{
int x;
int y;
int state;
portformat port[7];
}


Is it possible to do this?

(yay, I understand what 'pre' does now. If only I could get greater than and less than to work.)

Posted on 2004-05-23 13:06:32

mcgrue

You wish that was valid.

...

I do too, really.

Here's what I do, instead:



#define MAX_PORTFORMATS 99
#define MAX_OBJECTS 99

#define REF_PORTFORMAT int
#define REF_OBJECT int


struct portformat
{
int x;
int y;
int state;
}

portformat Master_Portformats[MAX_PORTFORMATS];
int Master_Portformats_Count;

struct Object
{
int x;
int y;
int state;
REF_PORTFORMAT port[7];
int port_count;
}

Object Master_Object[MAX_OBJECTS];
int Master_Object_Count;


Assume that there is code that initializes the Master arrays with their values here.

Now, your references between Object and portformat are integer values that plug into the Master_Portformats array.

Assuming you created the stacks properly, this would print out all of the Portformat in a given Object




void log_my_portraits( REF_OBJECT me ) {

int i;

log( "LOGGING THE PORTRAITS IN OBJECT["+str(me)+"]" );
log( "============================================" );

for( i=0; i<Master_Object[me].port_count; i++ ) {

log( " Port["+str(i)+ "].x: " + str( Master_Portformats[Master_Object[me].port[i]].x ) );
log( " Port["+str(i)+ "].y: " + str( Master_Portformats[Master_Object[me].port[i]].y ) );
log( "Port["+str(i)+ "].state: " + str( Master_Portformats[Master_Object[me].port[i]].state ) );
log( "" );
}

}



I would make accessor functions to make that junk a little more tolerable, like so:



//
// This returns the x value of the nth portrait in Object #obj.
//
int get_PortX_from_Obj( REF_OBJECT obj, int n ) {

//harsh error checking!
if( obj >= Master_Object_Count || obj < 0 ) {
exit( "get_PortX_from_Obj( "+str(obj)+", "+str(n)+" ):: your object was out of bounds." );
} else if( n >= Master_Object[obj].port_count || n < 0 ) {
exit( "get_PortX_from_Obj( "+str(obj)+", "+str(n)+" ):: your portrait index was out of bounds." );
}

return Master_Portformats[ Master_Object[obj].port[n] ].x;
}


I hope that helps and I didn't confuse you. I can elaborate more later if needbe. Also, I haven't checked my code here in v3... so there may be inaccuracies, but that's the general gist.

-Grue

Posted on 2004-05-23 14:42:06

el_desconocido

Quote:Originally posted by Blues Zodiakos

If only I could get greater than and less than to work.


Ok, here's an easy way to remember how to make a few special characters:

Say: AND Less Than ;
&lt; = <

AND Greater Than ;
&gt; = >

AND AMPersand ;
&amp; = &

Try it also with tm, copy, nbsp (Non Breaking SPace).

El

Posted on 2004-05-23 16:29:17

mcgrue

I really need to get a better deal that just auto-escapes everything inside of a pre. :/

Someone find me such goodness! ;_;

Posted on 2004-05-23 16:45:45

blues_zodiakos

Hmm. Looks rather complicated. I guess I'll try it out. I'm desparately trying to reduce for loops in my code. I have a rather big problem in that it is imperative that absolutely EVERY object in the level is checked on a timer. The original game ran at about 8 fps, so it probably wasn't as big a deal back then. But I think people would notice if a verge game was running 8 fps.

Posted on 2004-05-25 10:49:50

mcgrue

It's really not that complicated. It's just a poor-man's reference.

It does, however, require complete understanding for effective use.

Posted on 2004-05-25 12:08:40

blues_zodiakos

Hehe, the port variable wasn't intended for portraits, but rather for input and output ports. :D Mwa ha ha.

I understand vaguely what's going on, the port[blah] value in the struct is an integer reference to a value inside the master port array. I guess the difficult part will be making sure those references are valid and making the functions to check/set them.

-edit

That's odd, the message board told me this message was edited... before I edited it.

-edit 2

Oh wait, I get it now! I could just have a for loop initialize those references at the beginning of the game. That way, I'll always pretty much know what reference goes to what array.

Posted on 2004-05-26 16:47:23 (last edited on 2004-05-26 16:50:56)

Omni

Any chance of ever having nested structs working?

Posted on 2004-06-09 01:39:57

blues_zodiakos

Probably around the time that we get multiple HookRetraces. :D Which is to say... say... say...

YOU HAVE PERFORMED AN ILLEGAL OPERATION. USE SOME DETERGENT AND TAKE THAT SHOE OUT OF YOUR HAIR.

Posted on 2004-06-09 12:02:53

Omni

Well, there's a workaround for that, too...

Curse workarounds. Why do they have to do their job so well?

Posted on 2004-06-09 15:11:58 (last edited on 2004-06-09 15:12:19)

blues_zodiakos

There's a workaround for using a Hookretrace to blit on different layers and not have to create your own render loop? I'd like to be able to paint both over AND under the entitiy layer with one retrace. I don't think you can do that without doing a custom render loop. :(

Posted on 2004-06-09 22:01:33


Displaying 1-11 of 11 total.
1
 
Newest messages

Ben McGraw's lovingly crafted this website from scratch for years.
It's a lot prettier this go around because of Jon Wofford.
Verge-rpg.com is a member of the lunarnet irc network, and would like to take this opportunity to remind you that regardless how babies taste, it is wrong to eat them.