Flow Fields Map
- Map Hierarchy
- Modifying A Flow Field Map
- Map Creation
- Map Data
FlowFieldMap is subdivided into smaller chunks named
FlowFieldController. Each controller is subdivided into tiles.
FlowFieldMapUtility is a static helper class with useful methods like LineOfSight, converting world positions to map location, etc.
Modifying A Flow Field Map
There are two ways to modify an existing map:
- Setting original costs - used for permanent cost changes in single tiles on the map:
public void SetOriginalTileCost(Frame frame, Vector2Byte location, byte cost)
- Area cost modifiers - used for temporary changes, for example like in RTS buildings (which can be created and destroyed). It is applied to a group of tiles based on the parameterized area. Adding a modifier retrieves it's integer ID, which can further be used to easily remove the same modifier:
public int AddCostModifier(Frame frame, FPVector2 minPosition, FPVector2 maxPosition, byte cost) public bool RemoveCostModifier(Frame frame, int modifierID)
FlowFieldMap is created in runtime and stored in the FrameContext.
- Dimensions - (X, Y) size of the map. Maximum dimension supported is 256x256;
- Tile Size - size of each tile;
- Controller Size - size of the map's subdivisions (the map Dimensions must be a multiple of the Controller Size). Recommended Controller Size is between 8 and 20;
- Max Portal Length - maximum length of a portal connnecting two neighbouring controllers. If Max Portal Length is greater than Controller size, there can be multiple portals between two controllers. More portals means greater precision but it is slower CPU-wise;
- Cost Field - costs of individual tiles.
var ffMap = new FlowFieldMap(new Vector2Int(16, 16), FP._2, 8, 4, COSTS); ffMap.Initialize(frame.SimulationConfig.ThreadCount, false); frame.Context.FlowFieldMap = ffMap;
FlowFieldMap can hold lots of data in case of large maps, so it is not suitable to keep such data in the Frame.
FlowFieldMap is stored in the FrameContext which means changes to it has to be done very carefully. To prevent any desyncs between clients it is crucial to modify it only in Verified frames.
Having too big frame size can lead to lower performance and serialized data for rejoin/late join could be too big to transfer (FlowFieldMap has custom serialization which mitigates this issue).
Late Join And Reconnect
Due to the fact that
FlowFieldMap is not part of the frame, it implements custom serialization - see FlowFieldMap.Serialize().