Page 1 of 1

element_info as a structure member of level?

Posted: Sun Apr 01, 2007 1:22 pm
by Zomis
I was wondering, why isn't element_info inside the level structure?

As it is now, level is a LevelInfo variable and element_info is an array of ElementInfo variable, but why isn't the element_info variable inside the LevelInfo structure?

Posted: Sun Apr 01, 2007 6:16 pm
by Holger
There's no specific reason for this. There are a lot of other variables and arrays that principally could (or should) be part of "struct LevelInfo", like Feld[][], lev_fieldx, lev_fieldy (just to name a few). In most cases, the reasons are simply historical; there might be cases where using "flat" data structures result in faster execution time when compared to more complex data structures. Also the code may be more simple and readable when often used data structures have less indirections.

But in general you are right, and especially those many playfield sized arrays (like MovDelay[][] and many more) could even benefit from a more complex structure that contains all those values and is then defined as a playfield sized array itself, like this:

Code: Select all

struct
{
  int Feld;
  int MovPos;
  ...
}
playfield[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
Parts of the code that deal with many of such fields for a single tile would benefit from such a structure; on the other hand, code that only deals with "Feld[][]" would get a little bit slower and a little bit less readable, so I would have to make some profiling and code audit to decide if the overall effect of such a change would be positive or negative...

Posted: Sun Apr 01, 2007 8:00 pm
by Zomis
Ok, I understand - I think.

Well, I wouldn't prefer that all (or most, or too many) variables would be added to the LevelInfo structure. Just the design-time ones. AFAIK, Feld is only used in gameplay (and as the current editing field in the level creator). So maybe I should say "just the ones that are stored in files". Feld is not stored in a file, only copied to level.field - which is in turn stored in a file.