
| · Forums and IRC Rules · Portal |
Help
Search
Members
Calendar
|
| Welcome Guest ( Log In | Register ) | Resend Validation Email |
| Today's Top 10 Posters · My Last 10 Posts | Board and IRC Rules · Help · Members · Calendar |
| Forum | Topics | Replies | Last Post Info | |
|---|---|---|---|---|
![]() |
Older topics Here you can access all topics posted from May 12th 2005 to Apr 9th 2006 (In read only mode). |
1126 | 15694 | 9 Apr, 2006, 11:06 In: [GAME]Learn how to count to...By: DJ Omnimaga |
![]() ![]() ![]() |
| Liazon |
Posted: 19 Apr, 2006, 14:41
|
|
Staff Group: Coders Of Tomorrow Posts: 1491 Member No.: 24 Joined: 11 Apr, 2006 |
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? -------------------- Projects: In need of sprites...
|
| saubue |
Posted: 19 Apr, 2006, 15:22
|
||||
![]() member of boolsoft Group: Members Posts: 160 Member No.: 19 Joined: 11 Apr, 2006 |
Since your the only person who has got the source expect of me, I will answer 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:
EDIT: Oh, I nearly forgot your question about the global variable:
In fact, I try to put global arrays (which are not changed during the execution) like graphics in headers with their access macros and include the headers whenever I need them. If a program gets too large, I store them in seperate files (like in Shadow Falls alpha3: sfgfx.data and sfmaps.data) Zeljko also says that every apperance of the variable reults in more size - I'm not sure if this is true when using macros... -------------------- |
||||
![]() |
![]() ![]() ![]() |