gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > Gamestates problem

#22020 - ProblemBaby - Fri Jun 11, 2004 11:34 am

Hi

Iam doing a quite big game and it have many states (Intro, menu, game1 etc). First i made structure for every state that contained all data that was needed for that state. But after a while it took much space so I wonder
if someone have a good idea how to do this.

Hope you understand my prob.

/a

#22021 - poslundc - Fri Jun 11, 2004 2:16 pm

Are you sure it's taking up too much space? 32K of IWRAM isn't so little as long as you are responsible with it.

If so, you may choose to move some of your stuff into EWRAM, which you have 256K of. Access times will be slower, but this is a good place to put game-state variables you only need to access a few times per frame.

The other alternative is to use the same address space for the different various "modes" you are in, so long as you don't need to preserve, say, the data from game1 when the player returns to the menu, so that you've still got it when they return to game1. You can do this using malloc() and free() if you have those features in your devkit (I think I'm probably one of the only people out there that doesn't) to accomplish this, although you may have to check to see whether it's using IWRAM or EWRAM. Alternatively you can just do what I do, which is declare a global array the size that I want to keep reserved and do the memory-managment myself.

Dan.

#22033 - Daniel Andersen - Fri Jun 11, 2004 5:36 pm

Yes, indeed, 32kb is much memory; just think of the C64 which had only 64kb in total but produced big games like Pirates!

I wonder what you're using the memory for except for state variables? If you're using memory for big maps etc. it takes up quite a deal, though. But as said, try using EWRAM for variables not accessed often.

Regarding storage of maps, if you're having a big stage which you're not modifying in memory, you could:

1) Store it in ROM only.
2) For achieving speed you could copy portions of this map from ROM to RAM while moving.

But then you cannot modify it...
_________________
In a world without fences and walls you will never need gates and windows.