Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions Source/System/SpatialPartitionGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,28 +67,27 @@ void SpatialPartitionGrid::Add(const IntRect& rect, const MovableObject& mo) {
// We handle wrapping in GetCellIdForCellCoords, so make sure we've not already been passed wrapped data...
RTEAssert(topLeftCellX <= bottomRightCellX && topLeftCellY <= bottomRightCellY, "Invalidly wrapped rect passed to spatial partitioning grid!");

std::array<bool, Activity::MaxTeamCount + 1> includedTeams;
for (int team = Activity::NoTeam; team < Activity::MaxTeamCount; ++team) {
bool teamActive = team == Activity::NoTeam || activity->TeamActive(team);
bool ignoresThisTeam = team != Activity::NoTeam && rootParentMo.IgnoresTeamHits() && team == rootParentMo.GetTeam();
if (!teamActive || ignoresThisTeam) {
continue;
}
includedTeams[team + 1] = teamActive && !ignoresThisTeam;
}

for (int x = topLeftCellX; x <= bottomRightCellX; x++) {
for (int y = topLeftCellY; y <= bottomRightCellY; y++) {
int cellId = GetCellIdForCellCoords(x, y);
for (int x = topLeftCellX; x <= bottomRightCellX; x++) {
for (int y = topLeftCellY; y <= bottomRightCellY; y++) {
int cellId = GetCellIdForCellCoords(x, y);
for (int team = Activity::NoTeam; team < Activity::MaxTeamCount; ++team) {
if (!includedTeams[team + 1]) {
continue;
}

m_Cells[team + 1][cellId].push_back(mo.GetID());
if (mo.GetsHitByMOs()) {
m_PhysicsCells[team + 1][cellId].push_back(mo.GetID());
}
}
}
}

for (int x = topLeftCellX; x <= bottomRightCellX; x++) {
for (int y = topLeftCellY; y <= bottomRightCellY; y++) {
m_UsedCellIds.insert(GetCellIdForCellCoords(x, y));
m_UsedCellIds.insert(cellId);
}
}
}
Expand Down Expand Up @@ -204,6 +203,9 @@ std::vector<MovableObject*> SpatialPartitionGrid::GetMOsAtPosition(int x, int y,

int SpatialPartitionGrid::GetCellIdForCellCoords(int cellX, int cellY) const {
// We act like we wrap, even if the Scene doesn't. The only cost is some duplicate collision checks, but that's a minor cost to pay :)
if (cellX >= 0 && cellX < m_Width && cellY >= 0 && cellY < m_Height) {
return (cellY * m_Width) + cellX;
}
int wrappedX = cellX % m_Width;
if (wrappedX < 0) {
wrappedX += m_Width;
Expand Down
10 changes: 10 additions & 0 deletions Tools/Benchmarks/PerformanceStress.rte/Activities.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
AddActivity = GAScripted
PresetName = Debris Performance Stress
Description = Fixed debris waves for local performance measurements.
TeamOfPlayer1 = 0
MinTeamsRequired = 1
SceneName = Grasslands
ScriptPath = PerformanceStress.rte/Stress.lua
LuaClassName = PerformanceStress
DefaultFogOfWar = 0
DefaultDeployUnits = 0
4 changes: 4 additions & 0 deletions Tools/Benchmarks/PerformanceStress.rte/Index.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
DataModule
SupportedGameVersion = 7.0.0
ModuleName = Performance Stress
IncludeFile = PerformanceStress.rte/Activities.ini
35 changes: 35 additions & 0 deletions Tools/Benchmarks/PerformanceStress.rte/Stress.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
function PerformanceStress:StartActivity()
self.ActivityState = Activity.RUNNING
self.ticks = 0
self.timer = Timer()
self.center = SceneMan:MovePointToGround(Vector(SceneMan.SceneWidth / 2, 0), 0, 3)
self.center.Y = self.center.Y - 100
PerformanceMan.ShowPerformanceStats = true
print("PERF_START debris_waves")
end

function PerformanceStress:UpdateActivity()
self.ticks = self.ticks + 1
CameraMan:SetScrollTarget(self.center, 1, 0)
if self.ticks % 60 == 1 and self.ticks <= 541 then
for i = 1, 400 do
local gib = CreateMOSRotating("Gib Metal Grey Small A", "Base.rte")
gib.Pos = self.center + Vector((i * 17) % 120 - 60, (i * 23) % 80 - 40)
gib.Vel = Vector((i * 7) % 30 - 15, -((i * 11) % 20))
gib.AngularVel = (i % 20) - 10
gib.HFlipped = i % 2 == 0
gib.Lifetime = 3000
gib.GetsHitByMOs = true
MovableMan:AddParticle(gib)
end
local grenade = CreateTDExplosive("Frag Grenade", "Base.rte")
grenade.Pos = self.center
grenade:GibThis()
end
if self.ticks % 60 == 0 then
print("PERF_SAMPLE ticks=" .. self.ticks .. " real_ms=" .. self.timer.ElapsedRealTimeMS .. " particles=" .. MovableMan:GetParticleCount())
end
if self.ticks == 600 then
print("PERF_DONE real_ms=" .. self.timer.ElapsedRealTimeMS)
end
end
2,881 changes: 2,881 additions & 0 deletions Tools/Benchmarks/SpatialGrid-game-results.csv

Large diffs are not rendered by default.

147 changes: 147 additions & 0 deletions Tools/Benchmarks/SpatialGrid-game-summary.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
{
"warmup_ticks": 60,
"measured_ticks_per_process": 180,
"pairs_per_scenario": 3,
"wave_size": 2000,
"particle_sequences_match": true,
"scenarios": {
"collidable": {
"baseline": {
"mean_sim_us": 9259.157407407407,
"p95_sim_us": 57324,
"max_sim_us": 130287,
"mean_travel_us": 8365.309259259258,
"mean_movable_us": 8759.75925925926,
"mean_color_us": 158.36111111111111
},
"changed": {
"mean_sim_us": 9169.366666666667,
"p95_sim_us": 55749,
"max_sim_us": 129456,
"mean_travel_us": 8260.057407407407,
"mean_movable_us": 8652.616666666667,
"mean_color_us": 156.30555555555554
},
"runs": [
{
"variant": "baseline",
"run": 1,
"mean_sim_us": 9110.922222222222,
"p95_sim_us": 53293,
"max_sim_us": 129835,
"mean_travel_us": 8228.45
},
{
"variant": "baseline",
"run": 2,
"mean_sim_us": 9314.111111111111,
"p95_sim_us": 56131,
"max_sim_us": 129691,
"mean_travel_us": 8418.611111111111
},
{
"variant": "baseline",
"run": 3,
"mean_sim_us": 9352.43888888889,
"p95_sim_us": 57324,
"max_sim_us": 130287,
"mean_travel_us": 8448.866666666667
},
{
"variant": "changed",
"run": 1,
"mean_sim_us": 9128.466666666667,
"p95_sim_us": 53165,
"max_sim_us": 127349,
"mean_travel_us": 8210.583333333334
},
{
"variant": "changed",
"run": 2,
"mean_sim_us": 9106.877777777778,
"p95_sim_us": 54233,
"max_sim_us": 125746,
"mean_travel_us": 8201.961111111112
},
{
"variant": "changed",
"run": 3,
"mean_sim_us": 9272.755555555555,
"p95_sim_us": 55749,
"max_sim_us": 129456,
"mean_travel_us": 8367.627777777778
}
],
"mean_sim_reduction_percent": 0.9697506672573297
},
"stock-default": {
"baseline": {
"mean_sim_us": 8660.514814814815,
"p95_sim_us": 10052,
"max_sim_us": 33465,
"mean_travel_us": 5976.8592592592595,
"mean_movable_us": 8138.766666666666,
"mean_color_us": 1276.7925925925927
},
"changed": {
"mean_sim_us": 8543.277777777777,
"p95_sim_us": 9943,
"max_sim_us": 34648,
"mean_travel_us": 5846.029629629629,
"mean_movable_us": 8008.32037037037,
"mean_color_us": 1280.4648148148149
},
"runs": [
{
"variant": "baseline",
"run": 1,
"mean_sim_us": 8526.783333333333,
"p95_sim_us": 9968,
"max_sim_us": 32000,
"mean_travel_us": 5858.016666666666
},
{
"variant": "baseline",
"run": 2,
"mean_sim_us": 8893.2,
"p95_sim_us": 10361,
"max_sim_us": 33465,
"mean_travel_us": 6195.527777777777
},
{
"variant": "baseline",
"run": 3,
"mean_sim_us": 8561.56111111111,
"p95_sim_us": 9825,
"max_sim_us": 33369,
"mean_travel_us": 5877.033333333334
},
{
"variant": "changed",
"run": 1,
"mean_sim_us": 8521.927777777777,
"p95_sim_us": 9876,
"max_sim_us": 33301,
"mean_travel_us": 5832.722222222223
},
{
"variant": "changed",
"run": 2,
"mean_sim_us": 8552.638888888889,
"p95_sim_us": 9952,
"max_sim_us": 33076,
"mean_travel_us": 5857.455555555555
},
{
"variant": "changed",
"run": 3,
"mean_sim_us": 8555.266666666666,
"p95_sim_us": 9910,
"max_sim_us": 34648,
"mean_travel_us": 5847.9111111111115
}
],
"mean_sim_reduction_percent": 1.3536959354481959
}
}
}
Loading