1
\$\begingroup\$

Suppose I have a game that operates on a procedurally generated world that is made of 2D tiles. To save computer resources a chunking algorithm is implemented that slices the entire world in chunks of 32x32 tiles and loads/unloads them based on the position of the player character. Info about chunks is serialized to files. Suppose a 3x3 grid of chunks with the player character in the middle of the grid are loaded and managed at any given time.

The player finds an animal in a forest, but it runs away. They then decide to chase the animal, but it is at least five times as fast as the player and after a while of following its tracks, the distance between becomes too large to ever catch up with it. If the distance is big enough, the animal could have moved itself out of the chunks that are loaded around the player.

Because the animal leaves tracks, it has followed a certain path, avoiding obstacles like trees and rocks, through unloaded chunks.

How is this being managed by the game? I am trying this myself but I am stumped as to coming up with a way to manage, modify and read chunks that aren't loaded so that an animal that ran off screen still moves around sensibly and leaves tracks, or a town that gets flooded while the player is away.

I know that sometimes they calculate what should have changed in a chunk since the player's last visit, but that would mean I'd have to save an incredible amount of data if, say, a pack of 5 animals ran away.

I am not sure if an answer to a question like this requires more (technical) details about my game or project but I will provide these if wanted.

\$\endgroup\$
5
  • 5
    \$\begingroup\$ There's no magic answer here. If the work you need to do depends on data in the chunk, then you need that data loaded to do the work. That leaves you with basically the options you've described: 1) load the whole chunk if there's something significant going on there. 2) load a minimal subset of data for significant non-loaded chunks (eg. precomputed nav graph data so your AI can still path through it without all the content in memory) 3) log/schedule the changes to be evaluated & applied later, once the chunk is loaded. \$\endgroup\$
    – DMGregory
    Nov 29, 2016 at 21:18
  • \$\begingroup\$ Keep in mind that, to the extent that your game's memory is finite and unable to keep track of every change in every place in your world, your player's memory is even moreso. Consider allowing some effects (like animal trails) to decay over time, so that you don't need to store them for everything everywhere, just the band of regions the player could conceivably reach within that short lifetime. Save your memory & processing for the long-term changes players are invested in (like terrain destruction/construction by the player in particular) \$\endgroup\$
    – DMGregory
    Nov 30, 2016 at 0:05
  • \$\begingroup\$ I had no intentions of tracking everything for indefinite amounts of time; I will update my question to reflect that! Thanks for the realistic answer and the suggestions you made. I might indeed go for loading a minimal subset of data, though I'm interested in knowing what other games do as well. \$\endgroup\$
    – Zimano
    Nov 30, 2016 at 14:59
  • \$\begingroup\$ You can also simulate the simulation using probabilistic generation based on last non decayed events. When you come back you basically generate plausible outcomes base on statistics and events in your history. For example the deer might have a finite spread (based on his speed) over time, which mean you can basically spawn it within that radius and generate a path which will spawn plausible tracks left by the animal. \$\endgroup\$
    – user29244
    Dec 29, 2016 at 21:07
  • \$\begingroup\$ @user29244 I like that idea, it sounds very doable. Thanks! \$\endgroup\$
    – Zimano
    Jan 1, 2017 at 15:05

2 Answers 2

1
\$\begingroup\$

Let each chunk track the last time the player observed it. The next time the player observes a chunk, calculate the delta & simulate that period of time.

In order to keep the simulation reasonably scoped, this solution requires some trade offs. First, minimize actions between chunks. Second, use hierarchical design for things like pathfinding, world simulation & AI. Finally, scale the simulation based on the order of magnitude of the time delta. For instance, with your animal tracking example, if it's been a few turns, do regular low level pathfinding. If it's been many turns, perform regional pathfinding. If it's been very many turns, randomly decide if the animal stuck around.

The basic idea is to simulate big things for big blocks of time & small things for small blocks. Don't simulate the daily weather for a region that hasn't been seen for months - instead simulate the current season. The rational is that more often than not, things the player cannot directly observe or make direct inferences about may as well have never happened.

\$\endgroup\$
0
\$\begingroup\$

Because the animal leaves tracks, it has followed a certain path, avoiding obstacles like trees and rocks, through unloaded chunks.

Basically the entity should freeze, If it is not in a loaded chunk.

You are dividing world in chunks to save resources. Also you are mentioning that Animal should path find in unloaded chunks. these 2 statements are contradictory. Because to path find in any area you need data describing surrounding area. While unloading chunks you actually delete this data from RAM. so you cannot pathfind and travel while in unloaded chunk

\$\endgroup\$
1
  • \$\begingroup\$ I know you can't pathfind and travel in unloaded chunks, that's why I asked the question! \$\endgroup\$
    – Zimano
    Nov 30, 2016 at 18:46

You must log in to answer this question.

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