Remove floating points from map generation
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).
This commit is contained in:
committed by
Gustas Kažukauskas
parent
04e9cef38e
commit
037326024b
@@ -268,14 +268,14 @@ namespace OpenRA.Mods.Common.MapGenerator
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Uniformally add to or subtract from all matrix cells such that the given quantile,
|
||||
/// fraction, has the given target value.
|
||||
/// Uniformally add to or subtract from all cells such that count out of every outOf cells,
|
||||
/// are no greater than the given target value.
|
||||
/// </summary>
|
||||
public static void CalibrateQuantileInPlace(CellLayer<float> cellLayer, float target, float fraction)
|
||||
public static void CalibrateQuantileInPlace(CellLayer<int> cellLayer, int target, int count, int outOf)
|
||||
{
|
||||
var sorted = Entries(cellLayer);
|
||||
Array.Sort(sorted);
|
||||
var adjustment = target - MatrixUtils.ArrayQuantile(sorted, fraction);
|
||||
var adjustment = target - sorted[(sorted.Length - 1) * count / outOf];
|
||||
foreach (var mpos in cellLayer.CellRegion.MapCoords)
|
||||
cellLayer[mpos] += adjustment;
|
||||
}
|
||||
@@ -394,12 +394,15 @@ namespace OpenRA.Mods.Common.MapGenerator
|
||||
FromMatrix(output, roominess);
|
||||
}
|
||||
|
||||
/// <summary>Wrapper around MatrixUtils.WalkingDistance in CPos space.</summary>
|
||||
/// <summary>
|
||||
/// Wrapper around MatrixUtils.WalkingDistance in CPos space.
|
||||
/// Returns world distances (1024ths).
|
||||
/// </summary>
|
||||
public static void WalkingDistances(
|
||||
CellLayer<float> distances,
|
||||
CellLayer<int> distances,
|
||||
CellLayer<bool> passable,
|
||||
IEnumerable<CPos> seeds,
|
||||
float maxDistance)
|
||||
int maxDistance)
|
||||
{
|
||||
var passableMatrix = ToMatrix(passable, false);
|
||||
var cellBounds = CellBounds(passable);
|
||||
@@ -441,7 +444,7 @@ namespace OpenRA.Mods.Common.MapGenerator
|
||||
/// Pick a random MPos position in a CellLayer where each cell is a
|
||||
/// selection weight.
|
||||
/// </summary>
|
||||
public static MPos PickWeighted(CellLayer<float> weights, MersenneTwister random)
|
||||
public static MPos PickWeighted(CellLayer<int> weights, MersenneTwister random)
|
||||
{
|
||||
var entries = Entries(weights);
|
||||
var choice = random.PickWeighted(entries);
|
||||
|
||||
Reference in New Issue
Block a user