Free up some memory in your game
Simple, yet effective
What is a memory handler, you ask? Well, it's a way of keeping memory at a stable level and still being able to import and export lots of information. Now, take your normal RPG in QB(there's alot of 'em). Most of them load ALL of the tiles at the begining of the game, using Bload. The problem with this is that you have to create an array for each tile, and DIM it for the memory size. Now with 20-30 tiles, at 16*16 it's not too bad, but, once you start getting to about 200 or 300 tiles, 20*20 x and y size. it takes up your whole program!
Now, what can we do to fix this problem? Take away alot of tiles? But then the scenery gets repetitive and you can't have really cool giant statues and the such. We could create an easy Memory handler for the tiles....but how do we do this? It's actaully quite simple. Say you have a total of 30 tiles for each map(which is quite alot, esp if you have 10 maps), DIM arrays for only 30 tiles then. Then for each map create a tileset consisting of a list of those thirty tiles. How do I do this, you ask? Easy! Open an asii editor(notepad, edit.com or QB) and type in the list of tiles like so:
"grass.pix","mountain.pix", and etc until you reach all 30.
Remember, you need to list 30 tiles always, and have each tilename in"" and seperated by a , ...if not, you'll get an EOF error(end of file). If I write a future article, it will show a more advanced procedure useing Dynamic memory and Def Types and arrays and such so that you can have a diffrent number of tiles for each map, each varying in size and such.
In your game, change the load tiles sub so that it loads the tiles for the map seperatly then the sprites, titlescreen, etc.. Now, make it so there is a tileloading sub that loads the tiles according to the tileset like so:
(warning! untested psuedocode!)
OPEN tile$ FOR INPUT AS #1
'now you Bload the tiles, by using the varaibles above.
ie: load tile1$(the tile from the tileset listed first)
into the array known as tile1
make sure the array and the variables are both shared
OK, to use it in your program, each time you load a new map load the tileset that goes with it like so:
Alot of you might be asking yourself "but, won't that slow down my game?" not if your only loading 20 or 30 tiles, the map loading will probably slow it down more than the tileloading(for an example on the speed of the loading, download the Project S demo. It uses a variation of this technique, and loads around thirty tiles per map, without more than .03 second delay on my ancient 486 sx!). And, a little bit of slowdown for a lot more memory is worth it(esp since you can have unlimited number of tilesets without lowering the memory).
You can also use a version of this for sprite loading, this way you can have diffrent sprite classes and some neat-o special effects without wasting any extra memory.
There, simplistic but it gets the job done. This is not the one I use in the upcoming Project S, that one is a alot more complicated and handles all the arrays, not just the tiles, and will use XMS when I'm done with it. If you guys would like to see a follow up article getting more complicated but having even more usefull and intellegent automatic memory handlers, then email me at:
I am also thinking about writing an article on Object Oriented programming in QB 4.5 using user Defined Types(not only is it possible, but really easy), email me if you would like to see this tutorial(I'm not going to waste my time writing it if no one is going to read it).
Until then, remember that we are all just a dream of the Red King!
Back to Top