Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

#ActualServant of the Lord

Posted 27 March 2012 - 11:11 AM

For my own game, each area in the game is is split into 'chunks'. I just load the chunks around the player.
Each chunk is 'x by x' tiles wide/high (where I made 'x' to be 20 for my game, so 20 by 20 tiles), and an unbound number of layers.

For storing the tiles, basically I just use a std::vector, and dynamically allocate each tile in the vector. Tiles share images if they happen to be the same.
I could have just as easily used an array, since the size of the layer is constant.
Lists and maps wouldn't be good, because your priority is speed of traversal, and you don't ever remove/insert elements into the container (if you want to change/add/remove a tile, you just alter the Tile object in the container, but you never remove the element itself).

So either use an array or a vector of pointers pointing to a small compact dynamically initialized class that shares the images between each other.
'No' on lists, 'no' on maps in this situation.

If you need fast seamless loading of chunks, there's lots of great optimizations you can do - but you'll cross that bridge when you get there.

[Edit:] Going off of colinhect's point, I'm assuming you are talking about tile-based maps since you mentioned "tiles" and "Cartesian coordinates". If you are going for sporadically placed images, then a list would be preferred.


#3Servant of the Lord

Posted 27 March 2012 - 11:11 AM

For my own game, each area in the game is is split into 'chunks'. I just load the chunks around the player.
Each chunk is 'x by x' tiles wide/high (where I made 'x' to be 20 for my game, so 20 by 20 tiles), and an unbound number of layers.

For storing the tiles, basically I just use a std::vector, and dynamically allocate each tile in the vector. Tiles share images if they happen to be the same.
I could have just as easily used an array, since the size of the layer is constant.
Lists and maps wouldn't be good, because your priority is speed of traversal, and you don't ever remove/insert elements into the container (if you want to change/add/remove a tile, you just alter the Tile object in the container, but you never remove the element itself).

So either use an array or a vector of pointers pointing to a small compact dynamically initialized class that shares the images between each other.
'No' on lists, 'no' on maps in this situation.

If you need fast seamless loading of chunks, there's lots of great optimizations you can do - but you'll cross that bridge when you get there.

[Edit:] Going off of colinhect's point, I'm assuming you are talking about tile-based maps since you mentioned "

tiles" and "Cartesian coordinates". If you are going for sporadically placed images, then a list would be preferred.

#2Servant of the Lord

Posted 27 March 2012 - 11:11 AM

For my own game, each area in the game is is split into 'chunks'. I just load the chunks around the player.
Each chunk is 'x by x' tiles wide/high (where I made 'x' to be 20 for my game, so 20 by 20 tiles), and an unbound number of layers.

For storing the tiles, basically I just use a std::vector, and dynamically allocate each tile in the vector. Tiles share images if they happen to be the same.
I could have just as easily used an array, since the size of the layer is constant.
Lists and maps wouldn't be good, because your priority is speed of traversal, and you don't ever remove/insert elements into the container (if you want to change/add/remove a tile, you just alter the Tile object in the container, but you never remove the element itself).

So either use an array or a vector of pointers pointing to a small compact dynamically initialized class that shares the images between each other.
'No' on lists, 'no' on maps in this situation.

If you need fast seamless loading of chunks, there's lots of great optimizations you can do - but you'll cross that bridge when you get there.

[Edit:] Going off of colinhect's point, I'm assuming you are talking about tile-based maps since you mentioned "

tiles" and "

[left]Cartesian coordinates". If you are going for sporadically placed images, then a list would be preferred.


#1Servant of the Lord

Posted 27 March 2012 - 11:08 AM

For my own game, each area in the game is is split into 'chunks'. I just load the chunks around the player.
Each chunk is 'x by x' tiles wide/high (where I made 'x' to be 20 for my game, so 20 by 20 tiles), and an unbound number of layers.

For storing the tiles, basically I just use a std::vector, and dynamically allocate each tile in the vector. Tiles share images if they happen to be the same.
I could have just as easily used an array, since the size of the layer is constant.
Lists and maps wouldn't be good, because your priority is speed of traversal, and you don't ever remove/insert elements into the container (if you want to change/add/remove a tile, you just alter the Tile object in the container, but you never remove the element itself).

So either use an array or a vector of pointers pointing to a small compact dynamically initialized class that shares the images between each other.
'No' on lists, 'no' on maps in this situation.

If you need fast seamless loading of chunks, there's lots of great optimizations you can do - but you'll cross that bridge when you get there.

PARTNERS