# Updating “Inactive” Chunks

In my game, the only chunks (4x4 areas of tiles) in memory are the ones that the player is in. However, chunks need to have updates applied to them over time. A (likely) well-known example would be MineCraft: even if the player isn't in a chunk, the wheat still needs to grow over time.

My current solution is to call a method and pass in the time since the chunk was active.. but what if the chunk depends on nearby chunks for information, i.e. vines spreading or similar? Is there any reasonable solutions to this problem, or should I simply not depend on nearby chunks?

Well, first of all in Minecraft there is a "grid" with a default radius of 10 (for a total of 21x21 or 441 chunks) around the player that is basically a grid of loaded chunks. ONLY the chunks that are inside this "grid" are updated. The chunks that are out of reach, and do not get updated. So vines will not update, and items wont despawn.

http://www.minecraftwiki.net/wiki/Chunks

About the solution if you still would like to do this, maybe you could do some thing similar to block update in Minecraft, you could update the adjacent chunks aswell, and have an "age" to a vine and when updating it will update the adjacent blocks (even if different chunks) according to the age... I'm not sure how you would do this but I'm sure if you give it some thought you could figure out an efficient way. Although I would not recommend updating chunks that are outside of range too much because It could get to be a HUGE amount of chunks if you explore too much of the world. and then have a significant hit on performance.

Good luck!

• Ah, that's interesting about MineCraft's system. I'll probably do something similar then -- my chunks are cheap, especially if I don't necessarily need to create the actual bodies/rendering. I'll probably maintain a list of active chunks, and then a list of "semi"-active chunks. Thanks! – Conner Bryan Sep 6 '12 at 20:26
• It is also possible to do a fast time advancement when an inactive chunk is reactived, to simulate the passing of time. You can also do periodic updates in the background, e.g. Every X seconds load and do a batches time step for X inactive chunks. – Sean Middleditch Sep 7 '12 at 0:17

In my game I have a similar scenario, it is a city full of NPCs (10,000+) that all need to be updated at some point, but only those in the player's view are updated every frame. However, my NPCs aren't so dependent on their surroundings so they can be updated independently of other NPCs in the area.

Here's psudo-code for how my update works.

void Update(float time)
{
for (GameObject object : this.objectsNearPlayer)
{
// Always update all the objects near the player
object.Update(time);
}

// This loops over your game objects each frame and only updates 1000 of them
for (int index = this.startIndex; index < this.startIndex + 1000; i++)
{
if (index >= this.allObjects.length)
{
// We reached the end of the array, just break out of the loop
// You could improve this by start at the beginning again for the remaining
// N objects
break;
}

if (this.objectsNearPlayer.Contains(this.allObjects[index]))
{
// Don't update nearby objects twice in one frame
continue;
}

// Each game object should remember the last time they were updated
// and use the delta between updates in their logic
this.allObjects[index].Update(time);
}

// Next frame update the next 1000 objects
this.startIndex += 1000;

// If we reached the end of the object array, start over again
if (this.startIndex >= this.allObjects.length)
this.startIndex = 0;
}

• Interesting approach, I'll probably combine the incomplete update-approach with Trixmix's answer below. Thanks! – Conner Bryan Sep 6 '12 at 20:26