Representing a world in memory

Posted by user9993 on Game Development See other posts from Game Development or by user9993
Published on 2013-09-29T01:05:27Z Indexed on 2014/08/19 16:32 UTC
Read the original article Hit count: 159

Filed under:
|

I'm attempting to write a chunk based map system for a game, where as the player moves around chunks are loaded/unloaded, so that the program doesn't run out of memory by having the whole map in memory.

I have this part mostly working, however I've hit a wall regarding how to represent the contents of each chunk in memory because of my so far limited understanding of OOP languages.

The design I have currently has a ChunkManager class that uses a .NET List type to store instances of Chunk classes. The "chunks" consist of "blocks". It's similar to a Minecraft style game.

Inside the Chunk classes, I have some information such as the chunk's X/Y coordinate etc, and I also have a three dimensional array of Block objects. (Three dimensional because I need XYZ values)

Here's the problem:

The Block class has some basic properties, and I had planned on making different types of blocks inherit from this "base" class. So for example, I would have "StoneBlock", "WaterBlock" etc.

So because I have blocks of many different types, I don't know how I would create an array with different object types in each cell.

This is how I currently have the three dimensional array declared in my Chunk class:

private Block[][][] ArrayOfBlocks;

But obviously this will only accept Block objects, not any of the other classes that inherit from Block.

How would I go about creating this? Or am I doing it completely wrong and there's a better way?

© Game Development or respective owner

Related posts about c#

Related posts about maps