Organizing a World

  • Thread starter Thread starter Peter Oliphant
  • Start date Start date
P

Peter Oliphant

I'm creating an application which is game-like, in that it has entities
which move in a World composed of adjacent grids.

At first, the 'natural' way to build the World object as a class is to
create a Grid class, and then create an array of Grid objects to represent
the World.

That is,

ref class Grid
{
// definition
} ;

ref class World
{
private:

int W ;
int H ;
array<Grid^> grid_array ;
} ;

And then create W x H Grid objects for the array after allocating enough
pointers for them. This method definitely works. In Theory. But it can be
very impractical in many cases.

My case turned out to be one of the impractical one. This is becuase my
world is suppose to be very big, ala 10k x 10K grids, or even bigger. If I
used the above method, I would need to create 100 million grid objects! Yes,
this is likely within memory bounds, but like I said I might want to have
even higher dimensions for the World.

So, my solution was instead to create row and column link lists, one for
each row and column in the world. I then put the link 'chain' pointers in
each entity that must move in this World. Now the World only 'exists' as a
construct in the inhbitants (the entities!).

With this method I only need (H + W) totaly link lists, and then memory
requirements are only limited by the number of entities in the World! It is
also much faster in terms of collisions and processing, since the program
need only deal with grids that have an entity in them (which it would have
to in both methods). So I find this to be cool organization method I would
share.

As a side note, I then discover that scientists recently have shown the REAL
UNIVERSE might be similar in structure! See the following article:

http://physicsweb.org/articles/news/11/4/14

So, this post isn't a question, it's more me just sharing! :)
 
I'm creating an application which is game-like, in that it has entities
which move in a World composed of adjacent grids.

So, my solution was instead to create row and column link lists, one for
each row and column in the world. I then put the link 'chain' pointers in
each entity that must move in this World. Now the World only 'exists' as a
construct in the inhbitants (the entities!).

With this method I only need (H + W) totaly link lists, and then memory
requirements are only limited by the number of entities in the World! It is
also much faster in terms of collisions and processing, since the program
need only deal with grids that have an entity in them (which it would have
to in both methods). So I find this to be cool organization method I would
share.


Have you looked into a octtree structure for your world? These are
often used in games for static world objects.
They are very fast for culling and collision checks.

Josh
 
Back
Top