Skip to main content
GameDev.net gamedev.net
🔒 Locked

structuring game code

Started by Triad_prague Dec 6, 2013 at 2:51 AM 0 replies 1.6k views
Original Post
Triad_prague
Triad_prague

Hi guys, I'm having a self doubt right now. But first, let me tell you the cause. It's the way I structure my game code. Specifically it's how I put my variables. Basically I have a source code for each module (gfx, sound, input, log). Thing is, I put each variable in their specific .cpp files:

for example, I put screen attributes (and any screen related function definition) in gfx.cpp

//in gfx.cpp

int screen_w, screen_h, screen_bpp;

and I put any screen related function declaration in gfx.h

//in gfx.h

int gfx_create_screen(int w, int h, int bpp);

int gfx_switch_fullscreen(int fs);

I also do the same with the logging module. I put the log function declaration in the log.h, and the definition and logfile handle in log.cpp

question:

-is what I do is right? and uh, if not, can you tell me a better way? I really really appreciate any input here. thanks!

the hardest part is the beginning...
L. Spiro
L. Spiro

is what I do is right?

Your self-doubt is heavily warranted.

First-off, globals without a cause are bad, period.
Secondly, if you are using C++, why aren’t you using classes? Even if it was C it should still be structures rather than just a junkyard of random variables.

Group related variables into structures and classes. Make instances of those class. Avoid globals/statics.


L. Spiro
I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.