Beginning to work out a system where the map is updated and moves around the player as the pan around. This is primarily for world wrap. had brought this up almost a year ago, but at the time I didn’t need the option and it seemed extremely complicated. Well now I do need the option… and it is still extremely complicated. So laying it out here in post helps me focus my thoughts, and maybe if I am lucky someone will have some good advice.
So in order to move an instance, I need to know it’s index. Each Add Instance tied to a single variable keeps a running tally of how many instances it has spawned, which each instance is referenced to. So I will need to store a separate array of these indexes, per type of mesh/material in the world. As of right now, there are 23 base tile types, of which there may be 5 or more mesh/material variations for each. So 100+ separate arrays storing instance index information, just for basic terrain. Maybe another couple hundred for units, cities, resources, etc, etc.
The basic scenario:
Player Camera moves 1 tile to the North. 1 row of tiles on the South edge need to be moved and/or replicated to the North Edge. Based on player position, we can do a small bit of math to find the indexes of the bottom row tiles. Then we can work out their new vectors and store that in an temp array.
In order to reduce the number of main map array checks to the absolute minimum, we are going to need a giant struct array:
Parent Stuct Array: Will have a member for each category of item that needs moved (Terrain, Forest, Resource, Unit, Tile Damage, Tile Improvement, River pieces(could be 3-6 per tile edge), City, Territory Info, etc.).
Member Struct Arrays: Contain the Mesh Instance Type and Instance Index. Rivers and similar members could also have additional required information.
We need to access the main struct array for each tile to be moved to find out what Mesh Instance Array each of those items belong to, as well as it’s Instance Index number, plus any other information that may be needed for certain edge cases like rivers. Then, we have to use the first piece of information to hit an Enum for the proper Mesh Instance Array, and then the second piece of information to update the transform of the tile.
So in short, worst case scenario is a 100% explored, 100% land, ultra huge 400 tile wide map:
X400
- Small bit of math. (To determine Tile Index to be moved)
- Get from Struct Array - Array Size 80,000 (To determine Mesh Instance Type, Instance Index, and other required information)
— 2.1+ Information from Struct Array is run through switches, branches, etc to determine what is moving and what additional information needs to be worked.
- Small bit of math. (To determine new vectors)
- Transform Update multiplied by the number of items on the tile(could be 15+ items to a single tile).
Only thing I am really worried about is accessing that many arrays, that often. As fast as the player can pan across the map, that is how often this has to be done. I will probably try and spread this operation across a tick if necessary.
Teleporting using the minimap will be a whole different beast, but it can be expected in most such games that that might take a second or two to load on huge maps.