I'm looking for your thoughts on the best way to store map data.

I need to store data for territory ownership for each pixel on the map. The data for each pixel is as such:

Player 1 points: 24
Player 2 points: 118
Player 3 points: 78

Currently I'm testing by using an array int[width][height][3] to store the points.

I'm then looping through it every update and re-rendering depending on the points.

for (int i=0; i < screenWidth; i++) {
    for (int j=0; j < screenHeight; j++) {
        //Do stuff with array[i][j][0]
        //Do stuff with array[i][j][1]
        //Do stuff with array[i][j][2]

Iterating through a [800][600][3] array each render is expensive.

What is a better way to go about this?

  • \$\begingroup\$ How often do these values change? \$\endgroup\$
    – Philipp
    Commented Jul 3, 2014 at 21:58
  • \$\begingroup\$ Objects are to constantly raise points and lower enemy points in an area so a lot of the map data could change every frame. \$\endgroup\$
    – user48941
    Commented Jul 3, 2014 at 22:03

1 Answer 1


If changes happen in an area, then you only need to update that area (rather than updating the entire map.) You could divide the array into an 80x60 array (I'll call them 'chunks'), each with 10x10x3, sections. With some basic data on who owns each larger section. So if the raising/lowering only happens in adjacent fields, and you know that all chunks surrounding this one chunk are composed of only allies, then you can skip the one chunk entirely. Skipping a 10*10*3 array would be 300 lines of array-access code you could skip entirely.

Or, if you felt like getting fancy, you could try to divide the array into a quadtree, to help manage which sections are updated and which aren't. The above concept is basically a simplified version of a quad-tree (not dynamic, and not self-dividing.)


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .