Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Silly_con

Organization of code

This topic is 5739 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have much problems organizating my code, emm, not exactly organizing my code, but using the code that have organizated. My main problem comes with variables, all that declare in winmain, I can use in render, init functions and viceversa, the solution is global variables, but this is a bad programming habit ¿? Anyone knows good articles/tuts about organizing code in C/C++ for win32 plataform (WinMain is my principal problem)?

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
First look at the major components of your programs. Most people start learning a graphics package like Direc3D or something. You find that Direct3D needs some variables provided by WinMain() or at least used there. After knowing what Direct3D needs to initialize itself(hwnd, width, height), you can then determine what variables you might want to pass to the init function instead of having it be global. If the variable is used by Direct3D on a frame by frame basis(or could be used during the game other than init and shutdown), then that variable should be stored with the other Direct3D variables. Things like the interface pointer to Direct3D and the Direct3D Device are usually global or are data members in a wrapper class(OO programming). You can use globals, and I would say you''re fine doing it while learning, but make sure you know what variables are global, and consider where they would move if you want to put all of the functionality into a class.

Share this post


Link to post
Share on other sites
You''re right: avoid global data like the plague.
I''m building a game and there''s only one global variable in the whole project: a general error log (and I''m going to make it local soon ).

Just think about what objects, functions, etc. need what kinda of data and use it there locally. Then communicate these vars to other objects and functions through parameters and function returns.

Hope this helps!

Share this post


Link to post
Share on other sites
My main problem is to use shared variables in gldraw, wndproc and winmain, without using globals.
For example, declare a var in gldraw, and actualize in wndproc or winmain loop, or viceversa, and I don''t understan how people don''t make globals (without using OOP style, just plain C or CPP non OOP).

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!