Advertisement

04.09 - Game States and Variable Scope

Started by June 26, 2001 12:01 PM
21 comments, last by Teej 23 years, 3 months ago
In response to the Image format question,

Bitmaps are native to windows, and are directly supported by the Win32 API. I think Teej is just using them to make it simpler to understand the workings of the actual Game without worrying about the details of image loading with other formats.

Myself, I use PNG images for most of my programming needs. If you're interested in PNG, check out http://www.libpng.org/pub/png/ (I think) I'll change that link if I'm wrong, (It's been a while since I downloaded it.)

Seriously though, if you're just wanting to learn how to make the game, just stick with bitmaps for now, since you won't need any extra libraries or any other details of loading different formats. If you're feeling up to it though, give it a shot. That's really the only way to learn, right?



Good luck,

DracosX

      // Edit:  The link was wrong.  My bad. :P    


<Edit>
<Irony>
So quickly I boast. Just today, my little brother deleted my PNGLoader library along with libpng AND my source!

I guess now, I'm forced to re-work it out.
</Irony>
</Edit>



Edited by - DracosX on July 4, 2001 3:35:57 AM
DracosX:Master of the General Protection Fault
Thanks for the info guys.
Advertisement
I have an intersting (I think) question. If we have a gif of 150k and a bmp of 400k am I right in thinking that we are only saving disk space and not memory? Unless we''re compressing to drop our overall colour depth?

Just a thought while were waiting for more instruction

I''m really enjoying doing this btw Teej and thanx to everyone else whose joining in.
Just wondering why it is we are doing everything in C and then trying to give it the "look and feel of C++ classes". I''m assuming its the classic C vs C++ performance arguement - but does it really hold and does the performance improvement justify the coding complexity? Apart from that, having a blast and keep up the great work Teej

Colba Juby Woka Peterson

You know Teej, I find putting an enum in every module that I'm going to use globals.h in to be a bit of a pain. I could make it global scope in globals, but if you do that, you get a "defined multiple times" error during linking. So, what I found worked was to put the enum definition as part of the G struct and then reference it as G.GS_INTRO. Am I overlooking something simple here? Have others had this problem as well?

videns

Edited by - videns on July 2, 2001 10:52:01 PM
EZ
Videns,

Try this:

#ifndef GLOBALS_OWNERSHIP
extern
#endif

enum GAME_STATE {GAME_NULL, GAME_INTRO, GAME_PLAY, GAME_END};

The ifndef/extern trick should solve your multiple definitions problem.
Advertisement

Videns, I think your solution is great.
It''s better to put the enum in the G struct than just globally.

You might even think of making a new Global struct of enum GAMESTATES and enum of LEVELS, INTROSCREEN, CREDITS, PAUSE, SAVE, LOAD or whatever =).
C++, C++, C++
FragLegs,
Yep I have this in Globals.h:
#ifndef GLOBALS_OWNERSHIP
extern
#endif
enum GameState {GS_INTRO, GS_GAME};

and then use the define in GameMain.cpp:
#define GLOBALS_OWNERSHIP

but here''s what I see during the link:
GameMain.obj : error LNK2005: "struct __unnamed G" (?G@@3U__unnamed@@A) already defined in Ball.obj

which I get for every module that I include a Globals.h in.
I''m beginning to wonder if my linker has an incorrect flag set.

Lowas,
That''s a cool idea. It might be nice to then put those in one .h file to simplify the whole dealie.
EZ
quote: Original post by ManOCheese
I have an intersting (I think) question. If we have a gif of 150k and a bmp of 400k am I right in thinking that we are only saving disk space and not memory? Unless we're compressing to drop our overall colour depth?


You Are correct! But then again, when you have a lot of image files, it kinda works out to be worth it though.

In my last game, I had 13 Megs of Bmp images. After switching to PNG, I only had about 600k. Nice.

quote:
FragLegs,
Yep I have this in Globals.h:
#ifndef GLOBALS_OWNERSHIP
extern
#endif
enum GameState {GS_INTRO, GS_GAME};

and then use the define in GameMain.cpp:
#define GLOBALS_OWNERSHIP

but here's what I see during the link:
GameMain.obj : error LNK2005: "struct __unnamed G" (?G@@3U__unnamed@@A) already defined in Ball.obj

which I get for every module that I include a Globals.h in.
I'm beginning to wonder if my linker has an incorrect flag set.

Lowas,
That's a cool idea. It might be nice to then put those in one .h file to simplify the whole dealie.



Check to see if you're definine GLOBALS_OWNERSHIP in your Ball.cpp file. as well as in GameMain.cpp. You only need the definition in one of your source files.


DracosX



Edited by - DracosX on July 4, 2001 3:41:47 AM
DracosX:Master of the General Protection Fault
Yey, I love being right. I've had a look at the PNG info and it looks like good idea. I'm gonna do the same with my sound files aswell by using FMOD, which I used in Quake2 to add mp3 support (bgm only tho).

Edited by - manocheese on July 4, 2001 5:43:36 AM

This topic is closed to new replies.

Advertisement