[ad_1]
I’m making a recreation with infinite terrain. Sections of the terrain are damaged up into areas of fastened measurement for dealing with (just like chunks in Minecraft). I want to load and unload them as wanted because the participant strikes so that each area inside a visibility vary is seen and the others are usually not. For simplicity the sample of loaded areas could be a sq. as an alternative of a circle approximation.
The naive manner to do that is to have a loop that runs each recreation replace which iterates all loaded areas, and people who have an X or Y or Z coordinate that’s out of vary are deleted, after which have one other loop that runs and ensures that every one areas which can be throughout the X and Y and Z coordinates are usually not empty.
Nevertheless having 2 loops each body doesn’t appear very environment friendly. A easy enchancment is to solely run these loops if the participant location adjustments. However that’s nonetheless each body whereas the participant is transferring.
I might additionally solely run the loops if the participant crosses a area boundary, however nonetheless these loops are going to go over quite a lot of areas that don’t must be up to date. In idea, solely the areas on the fringe of the loaded areas space must be iterated over, if the participant crosses a area boundary.
What’s the best algorithm to dynamically load and unload areas as wanted round a participant, in a dice/sq. style?
[ad_2]