Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/maps/random/pathfinder_pertest_triggers.js
- This file was added.
warn("Setting up test"); | |||||
let cmpTrigger = Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger); | |||||
cmpTrigger.DoAfterDelay(1000, "TestUnobstructedShortDistance", {}); | |||||
cmpTrigger.DoAfterDelay(10000, "KillAll", {}); | |||||
cmpTrigger.DoAfterDelay(11000, "TestShortRunIntoEachOther", {}); | |||||
cmpTrigger.DoAfterDelay(20000, "KillAll", {}); | |||||
cmpTrigger.DoAfterDelay(21000, "TestLongDiagonalpath", {}); | |||||
const TEST_TEMPLATE_REGULAR = "units/cart_support_female_citizen"; | |||||
const TEST_TEMPLATE_OBELISK = "other/obelisk"; | |||||
Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager).SetLosRevealAll(1, true); | |||||
Trigger.prototype.KillAll = function() | |||||
{ | |||||
let ents = Engine.GetEntitiesWithInterface(IID_Position); | |||||
for (let ent of ents) | |||||
Engine.DestroyEntity(ent); | |||||
} | |||||
Trigger.prototype.TestUnobstructedShortDistance = function() | |||||
{ | |||||
warn("Starting TestUnobstructedShortDistance"); | |||||
// here we will plop units and make them walk in a straight, unobstructed, short line. | |||||
// in principle the largest cost here is the unit move order | |||||
let cmpTerrain = Engine.QueryInterface(SYSTEM_ENTITY, IID_Terrain); | |||||
let mapSize = 4*cmpTerrain.GetTilesPerSide(); | |||||
let mapCenter = new Vector2D(mapSize/2.0, mapSize/2.0); | |||||
let testSquareSize = mapSize / 5; | |||||
// create units | |||||
for (let z = mapCenter.y - testSquareSize; z <= mapCenter.y + testSquareSize; z += 20) | |||||
for (let x = mapCenter.x - testSquareSize; x <= mapCenter.x + testSquareSize;x += 4) | |||||
{ | |||||
let ent = Engine.AddEntity(TEST_TEMPLATE_REGULAR); | |||||
let component = Engine.QueryInterface(ent, IID_Position); | |||||
component.JumpTo(x, z); | |||||
component = Engine.QueryInterface(ent, IID_Ownership); | |||||
component.SetOwnerQuiet(1); | |||||
component = Engine.QueryInterface(ent, IID_UnitAI); | |||||
for (let i = 0; i < 10; ++i) | |||||
{ | |||||
component.Walk(x, z + 15, true); | |||||
component.Walk(x, z, true); | |||||
} | |||||
} | |||||
} | |||||
Trigger.prototype.TestShortRunIntoEachOther = function() | |||||
{ | |||||
warn("Starting TestShortRunIntoEachOther"); | |||||
// Same principle but units will run into each other. | |||||
// highlights slowness of hort-range pathfinder | |||||
let cmpTerrain = Engine.QueryInterface(SYSTEM_ENTITY, IID_Terrain); | |||||
let mapSize = 4*cmpTerrain.GetTilesPerSide(); | |||||
let mapCenter = new Vector2D(mapSize/2.0, mapSize/2.0); | |||||
let testSquareSize = mapSize / 5; | |||||
let dir = false; | |||||
// create units | |||||
for (let z = mapCenter.y - testSquareSize; z <= mapCenter.y + testSquareSize; z += 20) | |||||
{ | |||||
for (let x = mapCenter.x - testSquareSize; x <= mapCenter.x + testSquareSize;x += 4) | |||||
{ | |||||
let ent = Engine.AddEntity(TEST_TEMPLATE_REGULAR); | |||||
let component = Engine.QueryInterface(ent, IID_Position); | |||||
component.JumpTo(x, z); | |||||
component = Engine.QueryInterface(ent, IID_Ownership); | |||||
component.SetOwnerQuiet(1); | |||||
component = Engine.QueryInterface(ent, IID_UnitAI); | |||||
for (let i = 0; i < 10; ++i) | |||||
{ | |||||
component.Walk(x, z + (dir ? 40 : -40), true); | |||||
component.Walk(x, z, true); | |||||
} | |||||
} | |||||
dir = !dir; | |||||
} | |||||
} | |||||
Trigger.prototype.TestLongDiagonalpath = function() | |||||
{ | |||||
warn("Starting TestLongDiagonalpath"); | |||||
// stress-test long-range pathfinder. This is a diagonal move in the wrong direction on an largely empty map | |||||
// which means that JPS will basically loop over the whole map but also run in a ton of jump points. | |||||
// and generally speaking this is a worst case of some kind. | |||||
// units will then start moving. | |||||
// this scales poorly, on a medium map it's OK, but on a large map with more units and stuff it's just horribly slow. | |||||
// the movement will stress-test TestLine() but it's a bit of an atypical case to say the least. | |||||
let cmpTerrain = Engine.QueryInterface(SYSTEM_ENTITY, IID_Terrain); | |||||
let mapSize = 4*cmpTerrain.GetTilesPerSide(); | |||||
let mapCenter = new Vector2D(mapSize/2.0, mapSize/2.0); | |||||
let testSquareSize = mapSize / 5; | |||||
// create blocking obelisks | |||||
for (let z = mapCenter.y-testSquareSize; z <= mapCenter.y + testSquareSize*2; z += 8) | |||||
for (let x = mapCenter.x-testSquareSize; x <= mapCenter.x + testSquareSize*2;x += 8) | |||||
{ | |||||
let ent = Engine.AddEntity(TEST_TEMPLATE_OBELISK); | |||||
let component = Engine.QueryInterface(ent, IID_Position); | |||||
component.JumpTo(x, z); | |||||
} | |||||
// create units | |||||
for (let z = mapCenter.y - testSquareSize*2; z <= mapCenter.y; z += 8) | |||||
for (let x = mapCenter.x - testSquareSize*2; x <= mapCenter.x;x += 8) | |||||
{ | |||||
let ent = Engine.AddEntity(TEST_TEMPLATE_REGULAR); | |||||
let component = Engine.QueryInterface(ent, IID_Position); | |||||
component.JumpTo(x, z); | |||||
component = Engine.QueryInterface(ent, IID_Ownership); | |||||
component.SetOwnerQuiet(1); | |||||
component = Engine.QueryInterface(ent, IID_UnitAI); | |||||
component.Walk(x + testSquareSize*2, z + testSquareSize*2); | |||||
} | |||||
} | |||||
No newline at end of file |
Wildfire Games · Phabricator