resource issues...

Started by
1 comment, last by parklife 22 years, 2 months ago
I''m completely lost about resource management in games, and even simple things like keeping track of ordinary game stuff, like player position. or, rather, I do now how to keep track of things, just not how to structure the resources so I can use them whenever I need. In windows you have to check for messages at each frame, so that means the general game loop looks something like this (simplified):

while(Game)
{
	if(PeekMessage(...))
	{
		TranslateMessage(...);
		SendMessage(...);
	}
	GameMain(); //run game a frame at a time
}
 
This far I''ve been forced to use globals or static variables to not lose the things I need to keep track of (player position, enemies.. etc) and I hate it. I took a look at André LaMothe''s code for TOTWGPG and he uses globals to keep track of everything. What is the vital part of information I''m missing? Please help! /john
Advertisement
anyone?
You have a few options:

1. pass your variables as function paramaters
- this is can result in very slow performance
2. use a lot of globals
- generally what most people do - provides excellent performance
3. go to full OOP and encapsulate everything in classes
- this will usually clean everything up
- caution is required as poor style can lead to the same problems that occur in #1
- you may need to develop a few games in this style before you fully comprehend how to do it well(practise practise)

I am currently using the third method for my next game. I find it easier to debug when I program in this style. I have also learned Java in the past and this has helped me a great deal in understanding this way of doing things, as you are forced to do it this way in Java.

---
Make it work.
Make it fast.

"Commmmpuuuuterrrr.." --Scotty Star Trek IV:The Voyage Home
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][LWJGL Tutorials for NeHe][LWJGL Wiki][jMonkey Engine]

This topic is closed to new replies.

Advertisement