Upcoming Events
Unite 2010
11/10 - 11/12 @ Montréal, Canada

GDC China
12/5 - 12/7 @ Shanghai, China

Asia Game Show 2010
12/24 - 12/27  

GDC 2011
2/28 - 3/4 @ San Francisco, CA

More events...
Quick Stats
96 people currently visiting GDNet.
2406 articles in the reference section.

Help us fight cancer!
Join SETI Team GDNet!
Link to us Events 4 Gamers
Intel sponsors gamedev.net search:

Contents
 Introduction
 The Map
 Unit Data
 Structures

 RAM Considerations

 Printable version
 Discuss this article
 in the forums


RAM Considerations

By now you should have a good idea of what you require for your map cell data structure and unit data structures, and how you're going to store them. Now we do a quick overview of much RAM this is all going to take.

Your map is probably going to require the most RAM. Even a relatively small map can require a suprisingly large amount of RAM. A 100x100 map requires 10,000 map cells. If each map cell is 20 bytes, that's 200K. That's not so bad, but once you move your map to 500x250 you suddenly have 125,000 map cells at 20 bytes each using up 2.5MB of RAM. And if those maps seem small to you and what you really want is something like a 1,000x1,000 map for your mega-massive C&C clone, you'll need 20MB of RAM just for the map! For that reason, you should consider making your map cell data structure as small as you possibly can, even it costs you a minor performance hit. For instance, if a particular type of data only requires 3-bits of information try to use a bitfield (or least only 1 8-bit byte or unsigned char) instead of just allocating an "int" (32-bits) to hold it. If you simply cannot make the map cells any smaller, then you're going to need to accept a smaller map size or figure out some sort of "paging" mechanism so that you don't need the whole map in memory all at once (though you might be able to rely on virtual memory if you don't mind the performance hit).

But the map isn't the only thing you need to have in memory. There are all those units. You need room for them, as well. Unit data structures are generally going to be larger than map cells, but you're going to need far fewer of them unless you expect your players to put one or more units on every map cell. Several hundred per unit type, probably not more than several thousand, should be sufficient.

As you consider the RAM your base data structures will require, you may find that you have to do a bit of redesign work on your game. If you've set your sights on a huge map, you might want to scale down to something for reasonable. Or you might have been overestimating your needs and can now afford to scale up.

In our specific case, Artifact uses an 800x400 map (wraps horizontally), with a maximum of 35,000 facilities, 10,000 troops, and 1,000 cities. Fortunately, Artifact is a client-server game so the client software running on the player's PC generally doesn't have to deal with all of this information. The server segments the main map into "groups" and only sends those groups to the player that she has units on. Also, the information that's necessary on the client side (for rendering the map display and so on) is significantly less than is required on the server side where the actual game logic resides. Even still, the Artifact client software uses about 12MB-14MB RAM for all internal data structures and graphics and sound data.

Conclusion

Hopefully this article helps you understand the basic data needs of a game like Command & Conquer, WarCraft, or Civilization. The map is going to be your "central" data structure, with your arrays of unit data structures providing the necessary details.

Copyright © 1999 by David Michael. All Rights Reserved.



Next : NEXT_SECTION