Author Topic: [68k C] TIGCC Help  (Read 2137 times)

0 Members and 1 Guest are viewing this topic.

Liazon

  • Guest
[68k C] TIGCC Help
« on: April 19, 2006, 08:41:00 am »
Once again, I have a question about TIGCC.

When is it good to use a global variable?

Also, I noticed in the shadowfalls source code, mirogfx.h looks like this:

#define GetTilesMiro(dir,pl,nr) &(mirotiles[(((dir)+(nr))*MHEIGHT*2)+(pl*MHEIGHT)])


unsigned short mirotiles[8*MHEIGHT*2] = {
   // Tile 0
    0x07DC,0x1BF4,0x2FE8,0x1FB4,0x2F7C,0x1FF8,0x0F50,0x0E50
   ,0x1110,0x0EE0,0x0BA0,0x0CA0,0x04E0,0x0720,0x03E0,0x03A0
   ,0x07DC,0x1C2C,0x3118,0x124C,0x34D4,0x12F8,0x0950,0x0F50
   ,0x1F90,0x0FE0,0x0D60,0x0AA0,0x07A0,0x07A0,0x03E0,0x03E0
   // Tile 1
   ,0x07DC,0x1BF4,0x2FE8,0x1FB4,0x2F7C,0x1FF8,0x0F50,0x0E50
   ,0x1110,0x0EE0,0x1BA0,0x27E0,0x27E0,0x1990,0x1D28,0x0BF0
   ,0x07DC,0x1C2C,0x3118,0x124C,0x34D4,0x12F8,0x0950,0x0F50
   ,0x1F90,0x0DE0,0x1660,0x33A0,0x3C20,0x1E50,0x1DB8,0x0FF0
   // Tile 2
   ,0x07E0,0x1BD8,0x2FF4,0x3FF8,0x1FFC,0x1FF8,0x3FFC,0x5DBA
   ,0x2FF4,0x2FF2,0x1FF2,0x0E7E,0x0FFA,0x08F4,0x0FA0,0x05F0.....
};[CODE]

Why are these tiles defined in a header file, and what exactly is the macro for?  how do macros work?

saubue

  • Guest
[68k C] TIGCC Help
« Reply #1 on: April 19, 2006, 09:22:00 am »
Since your the only person who has got the source expect of me, I will answer :Dbiggrin.gif

Since diferent functions in different C-Files are needing the tiles for Miro very often, I decided to store them inside the game. I think it would be more effective if I would declare the array as an extern variable and store it inside a C-File, but I always do it that way.

Macros are just replacements. Every time I write GetTilesMiro(dir,pl,nr), the compiler replaces it with &(mirotiles[(((dir)+(nr))*MHEIGHT*2)+(pl*MHEIGHT)]), which is much more pain to write. It's the same as define HEIGHT 5 to use HEIGHT instead of the value 5 to make your code more readable. The nice thing about macros is that you can pass values. If you want to have more control (e.g. if you want to acceppt only certain types of arguments), you can also use an inline function:

c1-->
CODE
ec1inline unsigned short *GetTiles(short dir, short pl, short nr)
{