The map generator is already performant, but we can remove a few rough edges from infrastructure it interacts with.
- Add TypeDictionary constructor to clone from an existing copy. The map editor infrastructure relies heavily on cloning ActorReferences and the underlying dictionaries. A dedicated clone method avoids reflection overhead for CreateTypeContainer on a fresh instance.
- Use ThrowIndexOutOfRangeException helper. This allows the Index method to be inlined.
- Reuse lists in FloodFill. This avoids allocating and resizing new lists on each loop when we can reuse the existing capacity.
- Manage CellEntryChanged at the layer rather than individual previews. We only need to attach/detach from the delegate once at the layer, rather than many times as previews are added and removed.
Under some inputs, MatrixUtils.PointsChirality could enter into an
infinite loop consuming memory until an OOM occurs. This was due to
the FloodFill-based operation endlessly propagate zero values.
This adds a defensive check to prevent propagating zero values.
This change lifts large portions of ExperimentalMapGenerator's logic
into a new "Terraformer" class with highly documented methods that can
theoretically be used by alternative map generator classes. Some
additional refactoring may occur in future, subject to the practical
needs of additional map generators. ClearMapGenerator is also
simplified.
This is not a pure refactor and contains some algorithmic and
behavioral changes, as well as few minor bug fixes. Notably:
- The logic for obstructing unreachable water has been somewhat
replaced.
- In CnC, where water is already unplayable, EMG no longer obstructs
water. (RA still does, as water is playable there.)
- Mountain (cliff) generation is now somewhat more effective. This
increases the number of cliffs seen on many presets. Settings should
no longer use "Mountains: 1000".
- PlayableSpace logic has been consolidated into Terraformer.
- PlayableSpace.Playability no longer exists as PartiallyPlayable
became redundant. Its uses have been replaced with a simple
boolean. Consequently, some defunct code and configuration has been
removed.
- Adjust MultiBrush replaceability contract painting behavior to be
more intuitive.
- Fix off-by-one error in map bounds computation.
- Fix some usages of mixed up MersenneTwisters.
- Converts OpenRA.Mods.Common/MapGenerator/Direction.cs over to using
Direction and DirectionMask enums
- Moves direction-related utilities into Exts classes.
- Simplifies some direction utility logic.
Only very small numerical precision behavioral changes.
Whilst TilingPath has always allowed deviating from the path points
between the start and end point, it didn't allow deviation from the
start or end points themselves. This change allows the end point to
deviate if the tiling would otherwise fail. The start point remains
strictly positioned, as before. Loop end points (which must necessarily
match the start) also remain strict.
The ExperimentalMapGenerator is modified to benefit from the relaxed
tiling constraints. As a result, failed map generation due to tiling
failures is much rarer, and will make some otherwise very inflexible
template categories viable for tiling.
Includes some impure refactoring around the treatment of start,
intermediate, and end segments. As such, this changes map generation
output, even for maps which already tiled perfectly.
A previous workaround used for CnC road templates, whereby additional
segments were defined for road ending templates, is now redundant and
cleaned up.
Fixes a crash which happens when trying to generate very large maps,
such as 256x256.
```
Exception of type `System.IndexOutOfRangeException`: Index was outside the bounds of the array.
at OpenRA.Mods.Common.MapGenerator.MatrixUtils.CalibrateQuantileInPlace(Matrix`1 matrix, Int32 target, Int32 count, Int32 outOf) in /home/ashley/devel/OpenRA/OpenRA.Mods.Common/MapGenerator/MatrixUtils.cs:line 719
at OpenRA.Mods.Common.Traits.RaMapGenerator.Generate(Map map, MiniYaml settings) in /home/ashley/devel/OpenRA/OpenRA.Mods.Common/Traits/World/RaMapGenerator.cs:line 755
...
```
Removes all use of floating point from the RaMapGenerator map generator
and its dependencies.
Floating point behavior is potentially non-portable across client
hardware. Removing them should make the map generation logic
consistent even across clients with different floating point hardware
or compiler behavior. This may be useful for sync-safe multiplayer map
generation where clients independently generate the map from settings.
Most previously fractional public-facing settings are now represented
as numbers out of 1000, with some exceptions using 1000000. Most
internal logic which relies on fixed-point concepts now uses 1024ths,
though some floating point mechanisms have been replaced with
alternative discrete approximations (e.g. gaussian to binomial).
Updates the random map generator to produce more elaborate roads:
- Roads extend beyond map bounds.
- Shorter, unviable roads are pruned and merged to create longer roads.
- Roads can loop.
Add an experimental procedural map generator for the Red Alert mod,
along with supporting code that may assist in the development of map
generators for other mods.
Map generation may be accessed as a tool in the Map Editor. This change
does not presently introduce direct lobby options for generated maps.
Features:
- Terrain with land, water, beaches, cliffs, roads, debris, and trees.
- Placement of mpspawns, neutral buildings, and resources.
- Rotational and mirror symmetry options.
- Various configurable parameters with presets.
- Deterministic with configurable seed.
- Performant.