Page MenuHomeWildfire Games
Paste P142

rmgen a23 performance boost hack
ActivePublic

Authored by elexis on Nov 10 2018, 5:00 PM.
Index: binaries/data/mods/public/maps/random/rmgen/TileClass.js
===================================================================
--- binaries/data/mods/public/maps/random/rmgen/TileClass.js (revision 21929)
+++ binaries/data/mods/public/maps/random/rmgen/TileClass.js (working copy)
@@ -95,11 +95,11 @@ TileClass.prototype.remove = function(po
if (!this.inclusionCount[position.x][position.y])
this.rangeCount[position.y].add(position.x, -1);
};
-TileClass.prototype.countInRadius = function(position, radius, returnMembers)
+TileClass.prototype.countInRadius = function(position, radius, returnMembers, onlyTestPresence)
{
let members = 0;
let nonMembers = 0;
let radius2 = Math.square(radius);
@@ -114,13 +114,17 @@ TileClass.prototype.countInRadius = func
let minX = Math.max(Math.floor(position.x - dx), 0);
let maxX = Math.min(Math.floor(position.x + dx), this.size - 1) + 1;
let newMembers = this.rangeCount[iy].get(minX, maxX);
+ let newNonMembers = maxX - minX - newMembers;
+
+ if (onlyTestPresence && (returnMembers ? newMembers : newNonMembers))
+ return 1;
members += newMembers;
- nonMembers += maxX - minX - newMembers;
+ nonMembers += newNonMembers;
}
}
else // Simply check the tiles one by one to find the number
{
let dy = iy - position.y;
@@ -132,13 +136,21 @@ TileClass.prototype.countInRadius = func
{
let dx = ix - position.x;
if (Math.square(dx) + Math.square(dy) <= radius2)
{
if (this.inclusionCount[ix] && this.inclusionCount[ix][iy] && this.inclusionCount[ix][iy] > 0)
+ {
+ if (onlyTestPresence && returnMembers)
+ return 1;
++members;
+ }
else
+ {
+ if (onlyTestPresence && !returnMembers)
+ return 1;
++nonMembers;
+ }
}
}
}
}
@@ -146,14 +158,14 @@ TileClass.prototype.countInRadius = func
return members;
else
return nonMembers;
};
-TileClass.prototype.countMembersInRadius = function(position, radius)
+TileClass.prototype.countMembersInRadius = function(position, radius, onlyTestPresence = true)
{
- return this.countInRadius(position, radius, true);
+ return this.countInRadius(position, radius, true, onlyTestPresence);
};
-TileClass.prototype.countNonMembersInRadius = function(position, radius)
+TileClass.prototype.countNonMembersInRadius = function(position, radius, onlyTestPresence = true)
{
- return this.countInRadius(position, radius, false);
+ return this.countInRadius(position, radius, false, onlyTestPresence);
};

Event Timeline

elexis created this paste.Nov 10 2018, 5:00 PM

Keeps simstate intact, but not so much of a performance benefit as wished:

Jebel Barkal Normal:
Writing replay to /home/elexis/.local/share/0ad/replays/0.0.23/2018-11-10_0003
Total map generation time: 47.*s
Total map generation time: 50.*s

Ambush Normal:
Writing replay to /home/elexis/.local/share/0ad/replays/0.0.23/2018-11-10_0003
Total map generation time: 47.852s.
Total map generation time: 39.777s.

River Archipelago Large:
Writing replay to /home/elexis/.local/share/0ad/replays/0.0.23/2018-11-10_0004
Total map generation time: 17.511s.
Total map generation time: 20.738s.

Ambush Large:
Writing replay to /home/elexis/.local/share/0ad/replays/0.0.23/2018-11-10_0005
Total map generation time: 96.908s.
Total map generation time: 94.058s.

elexis changed the visibility from "All Users" to "Public (No Login Required)".Mar 20 2019, 4:18 PM