🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Structs and memory management

Started by
7 comments, last by OberonZ 24 years, 8 months ago
Unless something very strange is happening... your struct has a dword and 4 words therefore it should only be 12 bytes by my count...

David

Advertisement
All sorts of different ways to optimize this.

1) Make it per tile, instead of per space. That way, even though it's a 512x512 map, if you're only using 500 different tiles, you're only using a few K of memory. In my experience it's very rare to have 2 different attributes for the same tile picture.

2) if the attrib structs are read-only (never modified in the game), how about this: Each block on your grid has a pointer to an attrib struct... at load-time (or even better, at save-time in your tile editor), you check each block. If they've got the same attributes, you set their pointers to the same struct, thus avoiding the wasted memory associated with the duplicate struct.

I've never tried #2, but I've found that #1, combined with a VERY small set of flags for each space on the map (say, 2 bytes each), seems to work well.

And finally, a shameless advertisement. If you need a 256 color tile editor, check out MapMaker 5, at www.spin-studios.com/products/mm5.asp. Full color printing, unlimited parallax/tiles, post-it notes, and more.

Hope it helps...

Mason McCuskey
Spin Studios
www.spin-studios.com

Founder, Cuttlefish Industries
The Cuttlefish Engine lets anyone develop great games for iPad, iPhone, Android, WP7, the web, and more!
As stated by Torval, your struct is actually only 12 bytes. I guess you were counting bits
Anyway, with that in mind, your 512x512 map actually takes up ~4MB of RAM. This may still sound like a lot, but remember:
1) In the days of computers with 64MB of RAM average and 16-32MB VRAM, this really isn't THAT much.
2) Don't go thinking you need a map bigger than you really do. I had this same problem when making my game, and searched for all kinds of optimizations, only to realize that 128x128 was plenty big enough!

Anyway, good luck with the game.

------------------
Visit the homepage of my (soon to be 'net multiplayer) Tank Game at http://members.home.net/chris-man

[This message has been edited by Cromulus (edited September 28, 1999).]

Visit the homepage of my (soon to be 'net multiplayer) Tank Game at http://members.home.net/chris-man

Games like Warcraft only have maps as large as 128x128 tiles.
Which is pretty huge to explore even if those tiles are only
32x32 pixels each.

I would guess anyone who wants a map as large as 512x512 tiles
must be creating some kind of RPG world, instead of a level-by-
level game.

Good thing about levels is that you can use the same structures
over again. If you are creating a single large world map, would
it possible to split it into areas that get loaded and unloaded
using the same structures? There might be some delays, but
you could possible save memory.

-Tank

Thank you all for your answers.
Yes, (duh!) I was counting bits instead of bites *hangs his head in shame*

You have given me much to think about.
Mason, I like idea #2, it may be the most viable solution.

As for the map size, perhaps that is large. I wont really know for sure until I put something on that canvas we call a direct draw surface
I am trying to create an RPG world. I guess I could take a the same approach used in Baldur's Gate where they had smallish sections connected to each other by a "cloth" map.. Or string sections togheter, that might work.

Thanks again for all the help.
-OberonZ

---
PAGE FAULT: Please insert "Swap File, Disk 2"
and press any key to continue.
One approach used in tile based games (like good old fashioned Ultimas) was to store data in structures that are arranged in a 3 x 3 grid. The user should always be in the center of the grid. World data is loaded into each of the grid positions, and when the user moves from one grid into the other, the pointers are rearranged and in the background, the area that is two grids away is dropped and reloaded with data in the adjacent area. That way you always have the data from the surrounding area loaded, and you can load data from farther away areas more slowly, as time permits (second thread, small file reads, etc). You always could come up with a scheme that determines how much memory there is an allocate a larger grid array if more memeory is available.. Then your reloads would be less often, or could happen over a longer period of time since you have more data to walk through, and more buffer-time for loading. If any of you remember the old floppy days, the one annoying thing about walking through moongates in Ultima 3 or 4 was that it would take time to load the next section, since moongates took you outside of the 3 x 3 grid area. In Ultima 5, I think they made it so if there was a moongate in the area, it loaded the moongate map, too.

Excellent!
This is exactly what I am looking for. I should have thought of it.
Thanks a lot man! (err.. or woman...)

BTW: This is why I love GD. The interaction between game-devs and game-dev hopefulls that is otherwise difficult to achieve. To those that created it, you rock my world.

---
PAGE FAULT: Please insert "Swap File, Disk 2"
and press any key to continue.
Hi,
I have a quick question about memory management and structs.

I have a structure in my game that represents a tile. These "blocks" (original, ain't it? ) are defined as such

code:
typedef struct tagBlock{DWORD dwFlags;WORD  wTileIndex;WORD  wObjectIndex;WORD  cxObjPos, cyObjPos;} BLOCK, * PBLOCK;

A little explenation:
dwFlags = user defined flags, denote if the block is impassable, a trigger or whatnot.
w*Index are indecies (sp?) in a tile list
c?ObjPos are the x,y coordinates of the object in the tile.

This is 96 bytes. In a map 512x512 this is a wopping 24MB! This seems a tad much. Even on a smaller map, say 320x320 it's over 9MB. Maybe my understanding of memery management under Windows it tenuous (it is), but is there a better way?

I could have an insanely small map, that then it wouldn't be much fun, as for the struct, I need all that data.

Thanks,
-OberonZ

---
PAGE FAULT: Please insert "Swap File, Disk 2"
and press any key to continue.
Thanks! We love to hear that the site is serving its intended purpose

This topic is closed to new replies.

Advertisement