-
Notifications
You must be signed in to change notification settings - Fork 14
6. Settlement Spots and Region Entities
This page is created to provide some more theoretical background on challenges and their solutions regarding the interaction with the world. Make sure to read the well written World Generator Tutorial if you haven't already in order to understand the things talked about here.
To get a meaningful simulation running one needs information about the world, such as the resources/blocks or height of relevant regions. Currently most of the world information created during world generation, such as the specific facet values are discarded after world generation and the only thing left are the blocks and their positions. Although sampling the terrain for relevant features might make sense in specific situations, scanning huge areas would be way too costly. Instead, the important values are saved to memory and thus can be quickly looked up.
However, care has to be taken of ram usage, proper serialization and easy access of the information.
It turned out that making use of the entity system and adding the facets as component to region entities provided a solid solution to that problems. Adding a location component to those entities also makes sure that they get loaded/unloaded whenever they are needed (as soon as a player is in the relevant radius). This also provides the benefit of the already existing serialization system for entities and their components and thus most of the problems got solved. The RegionEntityManager
keeps track of the whereabouts of those entities and provides methods to retrieve them in various ways. Thus the simulation has a wide variety of information about the environment available.
To preserve memory, the facets originate from GridFacets. Essentially, they split the the relevant region into smaller parts. This allows to wrap up the values of a lot of individual positions into one value and easily access that. A configurable grid size enables control about the detail of the information. In most cases one value per chunk was enough, especially for resource values.
During world generation the SiteFacetProvider filters the world for suitable spots. Then, with the terrain information now available after world generation, the SettlementEntitySystem
is able to determine which part of the world is a suitable spot to place a settlement. At the moment the system looks for a low roughness value (roughness = standard deviation of height), the amount of grass in that region and that no other settlement is too close. When enough regions around that site fulfill the conditions, a settlement is spawned. This will most likely be subject of change to allow more advanced filtering in the future.