"The seasoned programmer may have also noticed that we changed the Tile from a class to a struct. This is a very important change, because we no longer need a memory reference to the Tile, since it's stored on the Stack memory segment. That's another 4 bytes of savings, or 500 MB total. "
Since we are on it, I'd also like to question you about that paragraph. You said that changing from a class to a struct makes a difference in the size of the data, I don't find this to be true, as a c++ programmer, but I am not absolutely sure you are using something else than c++, right?
In this case, I am using C#. As far as my knowledge of memory management goes, doesn't this also apply to C++?
In both cases, when we create a new object, the object data sits on the heap, while a reference to that data goes on the stack. When we change over to a struct, all of the data is stored on one segment and we no longer need a reference variable for it, it's essentially "inlined."
All of those memory references add up over a few million tiles.
The seasoned programmer may have also noticed that we changed the Tile from a class to a struct. This is a very important change, because we no longer need a memory reference to the Tile, since it's stored on the Stack memory segment. That's another 4 bytes of savings, or 500 MB total.
I'm assuming this is C# then? Presumably you have an array of Tile structs, in which case they exist in the heap (but in one single allocation, not millions of individual allocations), not the stack.
And now, a question for you:
How do you deal with world simulation of parts of the world that are outside the currently loaded section? Or, say, if an NPC near the edge of the loaded section, chasing the player, and then that section gets unloaded? Obviously what you need here depends on your gameplay, but it seems like it would be interesting to talk about.
You're correct.
This is actually a complex question, as I handle different things in different ways.
For free roaming creatures, if they are not within a 5 tile buffer of the viewport edge, they don't do anything. This is never an issue because adjacent chunks are never loaded unless the player is within 10 tiles of the boundary, so 5 will always be safely loaded already.
This essentially means that the player's computer has 10 tiles to load a chunk before they start seeing white space and the game crashes.
For path faring creatures, they are always simulated, because they need to make their way through the towers and to the center of the map. I don't deal with rendering anything they do, that includes damage numbers, animations, names, health bars, etc.
For towers, they are also always simulated so they can fire on path creatures. If they aren't visible to the player, no projectile is launched, and no animations are dealth with. The damage is simply subtracted from the target(s).
For NPC's they are similiar to free roaming creatures, they are not simulated outside of the viewport.