Monday, July 26, 2010

A structure

Today, let's take a look at a structure:
struct A_STRUCT {
int _screenX, _screenY; /*_00h, _02h*/
int _width, _height; /*_04h, _06h*/
unsigned char* _data; /*_08h*/
unsigned char _spriteIndex; /*_0Ch*/ /* bit15 = flag mirror, bit14_0 = object's index */
/* */
unsigned char _0Dh; /* _spriteIndex2 */
int _0Eh, _10h; /* _screenX2, _screenY2 */
unsigned int _12h, _14h; /* width2, height2 */
/* */
int _x, _y, _z; /*_16h, _18h, _1Ah*/
int _w, _h, _a; /*_1Ch, _1Eh, _20h*/
unsigned char _type; /*_22h*/
unsigned char _status; /*_23h*/
/* */
unsigned char gateIndex; /*_24h*/
unsigned char _25h;
unsigned char _26h;
unsigned char _27h; /* private counter (initialized) */
unsigned char _28h; /* private counter (uninitialized) */
};


As you can notice, some of the fields do not have an explicit name, and are referred with their offset inside the structure. Well, sorry about that, this is still a work in progress, and I hope one day it will be clean and everything.
Having say that... Well, this structure is used to represent the objects on the screen: the tank, its shadow (yes, separate object), the doors, the enemies, the platforms, ...
To get an idea of all the possible types, check those diffs I use in the code:
#define OBJECT_0         0
#define OBJECT_MGT 1
#define OBJECT_SHADOW 2
#define OBJECT_IMPACT 3
#define OBJECT_DOOR 4
#define OBJECT_ICON 5
#define OBJECT_PLATFORM 6
#define OBJECT_ELEVATOR 7
#define OBJECT_LASER 8
#define OBJECT_BRAIN 9
#define OBJECT_10 10
#define OBJECT_ROBOT 11
#define OBJECT_BUBBLE 12
#define OBJECT_LETHAL 13
#define OBJECT_POLE 14

The first fields of the structure (from _screenX to _14h are exclusively used for display.
_data is a pointer to the graphical data used to draw this object (from files DATA1.MGT and DATA2.MGT).
I didn't clearly understand the reason for the fields _0Dh to _14h, although they seem to duplicate the first fields.
For the other fields, I guess their name is explicit enough.

The remaining fields are strictly "ingame" information. For instance _x,_y and _z define the object's position in the game space. And if you have wondered in the first post what the function LORI_castSprites could do, well here you are: it takes as an argument a null-terminated array of the aforementioned structure and fills the display related fields according to these 3d coordinated.

The fields _w, _h, _a are the respective sizes of the object on the X, Y and Z axis. Their names stands for width, height, and altitude. Which, I agree, is a stupid naming, but I didn't want to have height related to Z in one system and Y on another system, which I feared would be a good source of error. We will try to fix that in time.

_type contains one the above define, according to the object's type (explicit uh ?).

And the remaining fields are game-related state variables, or related, and some of them I don't know the meaning yet. Shame on me.

Oh also, the same structure is used to display the (few) UI elements of the game: life and laser gauge, icon, ...
In the case of such objects, most of the ingame fields are ignored, and of course, the LORI_castSprites is not called.

And here is some ASCII art:

@@@@***@@
@@@*******@
@@@***....***@@@*
@@@@..@@@@@.***@*
@@*..@@@@@@.**@* @@*
@@*..@@@@@@@@.*@@* @@*
@@*..@@@@@@@.*@@@@@@* @@*
@@*..@@@@@@@.*@@***@@@@@@* * *
@@@*..@@@@@@@.*@@**.*.*@@@@@@*** *
@@*..@@@@@@@.*@@**.*.*.**.*.* **
@@****@@@@@@@.*@@*.*.*.**.*.* **
@@@@@@@****@@.*@@*.*.*.**.*.* *
@ *@@@@@****@@**.*.**.*.* * *
@*** *@@@@@@**.*.**.*.* *
@ ** * * * *@**.*.**.*.* *
@ * * * * * *.**.*.* *
@ *** * * * * * *.**.*.* *
@ ***** * * * *.**.*.* *
@ *** * * * * * **.*.* *
** @@* * * * * * **.*.* *
** @@ * * * .*.* *
* * @@* **.* *
* * @@ .* *
* * * **
* * **
*
*
*
* *

Hard to recognize, but that's one the tank's images from DATA1.MGT and transposed to ASCII with 1 pixel becoming one character.

No comments: