Sign in to follow this  

using objects in arrays

This topic is 4551 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'm looking for advice on using the least memory for switching game levels that are objects. If I put them in an array, I would be allocating memory for all the levels. I could use enum with a switch statement and allocate memory and then delete when it returns, but I don't know if that's the best way. There could be as many as 20 or 30 levels, maybe more. Anyway, any ideas would be appreciated. Language is c++, level will have a run() function.

Share this post


Link to post
Share on other sites
Wouldn't each level be "described" externally in a file.

Whenever a new level began you would read the information, enemy types, number of enemies, terrain etc., from the file and create the appropriate game objects from it.

I don't think holding all information about each level in memory is the way to go, but I might be wrong.

Share this post


Link to post
Share on other sites
Quote:
Wouldn't each level be "described" externally in a file.

Well, I was going to use inheritance from a sort of generic level class. Of course, some information about the level would be saved that changes, but I was going to create each object and then run it. Does sound a little strange, but I already started it that way.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by fireside
Quote:
Wouldn't each level be "described" externally in a file.

Well, I was going to use inheritance from a sort of generic level class. Of course, some information about the level would be saved that changes, but I was going to create each object and then run it. Does sound a little strange, but I already started it that way.


It does not sound entirely strange. There are several games out there, that I am sure that use that kind of level strategy, World of Warcraft for instance. When you get close to the next zone, it will start loading that zone from a file into memory and remove the zone that you were in previously when you are far enough away that it knows that you wont be coming back for a while.

I can actually see this being used in Super Mario Brothers on the NES. Complete Continous Scrolling from world 1-1 - Bowser in 8-4 based on proximity to the next world level. Not sure how the timer would work in SMB but I guess it could be like those racing games that once you reach a checkpoint you get more time added to the clock.

Of course, I have no idea what kind of game you are working on but I do not see anything entirely wrong with it.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
inheritance for each different level sounds a bit foolish. Typically you create a single level object and change its data according to some kind of file.

Share this post


Link to post
Share on other sites
You can use smart pointers and an LRU garbage collector, to remove unused data from memory, and load it on demand (via the smart pointer), if it is accessed.

Share this post


Link to post
Share on other sites

This topic is 4551 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this