Ticket #5011: rangeOp.patch

File rangeOp.patch, 3.4 KB (added by elexis, 4 years ago)

Test to visualize the difference between RangeOp and the default algorithm. They ought to compute the same result.

  • binaries/data/mods/public/maps/random/new_rms_test.js

    diff --git a/binaries/data/mods/public/maps/random/new_rms_test.js b/binaries/data/mods/public/maps/random/new_rms_test.js
    index b9d04b9..da1506d 100644
    a b Engine.LoadLibrary("rmgen-common");  
    33
    44var g_Map = new RandomMap(0, "grass1_spring");
    55
    6 placePlayerBases({
    7     "PlayerPlacement": playerPlacementCircle(fractionToTiles(0.39))
    8 });
     6var clTerrain = g_Map.createTileClass();
    97
    10 placePlayersNomad(g_Map.createTileClass());
     8clTerrain.add(g_Map.getCenter());
     9
     10for (let i = 0; i < 2; ++i)
     11    createArea(
     12        new MapBoundsPlacer(),
     13        new TerrainPainter(i == 0 ? "blue" : "red"),
     14        new NearTileClassConstraint(clTerrain, 10, i == 0));
     15
     16g_Camera = {
     17    "Position":
     18    {
     19        "x": g_Map.getCenter().x * 4,
     20        "y": 0,
     21        "z": g_Map.getCenter().y * 4
     22    },
     23    "Rotation": 0,
     24    "Declination": 0.5
     25};
    1126
    1227g_Map.ExportMap();
  • binaries/data/mods/public/maps/random/rmgen/Constraint.js

    diff --git a/binaries/data/mods/public/maps/random/rmgen/Constraint.js b/binaries/data/mods/public/maps/random/rmgen/Constraint.js
    index 46c7cef..66b4d92 100644
    a b StayInTileClassConstraint.prototype.allows = function(position)  
    128128/**
    129129 * The NearTileClassConstraint is met if at least one tile within the given radius of the tile is marked with the given TileClass.
    130130 */
    131 function NearTileClassConstraint(tileClass, distance)
     131function NearTileClassConstraint(tileClass, distance, useRangeOp)
    132132{
    133133    this.tileClass = tileClass;
    134134    this.distance = distance;
     135    this.useRangeOp = useRangeOp;
    135136}
    136137
    137138NearTileClassConstraint.prototype.allows = function(position)
    138139{
    139     return this.tileClass.countMembersInRadius(position, this.distance) > 0;
     140    return this.tileClass.countMembersInRadius(position, this.distance, this.useRangeOp) > 0;
    140141};
    141142
    142143/**
  • binaries/data/mods/public/maps/random/rmgen/TileClass.js

    diff --git a/binaries/data/mods/public/maps/random/rmgen/TileClass.js b/binaries/data/mods/public/maps/random/rmgen/TileClass.js
    index b211e36..51c2b7f 100644
    a b TileClass.prototype.remove = function(position)  
    9797        this.rangeCount[position.y].add(position.x, -1);
    9898};
    9999
    100 TileClass.prototype.countInRadius = function(position, radius, returnMembers)
     100TileClass.prototype.countInRadius = function(position, radius, returnMembers, useRangeOp)
    101101{
    102102    let members = 0;
    103103    let nonMembers = 0;
    TileClass.prototype.countInRadius = function(position, radius, returnMembers)  
    106106    for (let y = position.y - radius; y <= position.y + radius; ++y)
    107107    {
    108108        let iy = Math.floor(y);
    109         if (radius >= 27) // Switchover point before RangeOp actually performs better than a straight algorithm
     109        if (useRangeOp)
    110110        {
    111111            if (iy >= 0 && iy < this.size)
    112112            {
    TileClass.prototype.countInRadius = function(position, radius, returnMembers)  
    148148        return nonMembers;
    149149};
    150150
    151 TileClass.prototype.countMembersInRadius = function(position, radius)
     151TileClass.prototype.countMembersInRadius = function(position, radius, useRangeOp)
    152152{
    153     return this.countInRadius(position, radius, true);
     153    return this.countInRadius(position, radius, true, useRangeOp);
    154154};
    155155
    156156TileClass.prototype.countNonMembersInRadius = function(position, radius)
    157157{
    158     return this.countInRadius(position, radius, false);
     158    return this.countInRadius(position, radius, false, useRangeOp);
    159159};