Index: binaries/data/mods/public/simulation/components/Player.js =================================================================== --- binaries/data/mods/public/simulation/components/Player.js +++ binaries/data/mods/public/simulation/components/Player.js @@ -394,12 +394,14 @@ } // With the real ownership change complete, send OwnershipChanged messages. + let before = new Date().getMilliseconds(); for (let entity of entities) Engine.PostMessage(entity, MT_OwnershipChanged, { "entity": entity, "from": this.playerID, "to": 0 }); + warn("Ownership change took " + (new Date().getMilliseconds() - before) + "ms"); } Engine.BroadcastMessage(won ? MT_PlayerWon : MT_PlayerDefeated, { "playerId": this.playerID }); Index: binaries/data/mods/public/simulation/components/RallyPoint.js =================================================================== --- binaries/data/mods/public/simulation/components/RallyPoint.js +++ binaries/data/mods/public/simulation/components/RallyPoint.js @@ -105,9 +105,8 @@ RallyPoint.prototype.OnOwnershipChanged = function(msg) { - // No need to reset when constructing or destructing the entity - // Don't reset upon defeat to improve performance - if (msg.from == -1 || msg.to < 1) + // No need to reset when constructing the entity + if (msg.from == -1) return; this.Reset(); Index: binaries/data/mods/public/simulation/components/tests/test_RallyPoint.js =================================================================== --- /dev/null +++ binaries/data/mods/public/simulation/components/tests/test_RallyPoint.js @@ -0,0 +1,71 @@ +Engine.LoadHelperScript("Player.js"); +Engine.LoadComponentScript("interfaces/Formation.js"); +Engine.LoadComponentScript("interfaces/Health.js"); +Engine.LoadComponentScript("interfaces/RallyPoint.js"); +Engine.LoadComponentScript("RallyPoint.js"); + +function initialRallyPointTest(test_function) +{ + ResetState(); + + let entityID = 123; + let cmpRallyPoint = ConstructComponent(entityID, "RallyPoint", {}); + + TS_ASSERT_UNEVAL_EQUALS(cmpRallyPoint.GetData(), []); + TS_ASSERT_UNEVAL_EQUALS(cmpRallyPoint.GetPositions(), []); + + cmpRallyPoint.AddPosition(3, 1415); + TS_ASSERT_UNEVAL_EQUALS(cmpRallyPoint.GetPositions(), [{ "x": 3, "z": 1415 }]); + + cmpRallyPoint.AddPosition(926, 535); + TS_ASSERT_UNEVAL_EQUALS(cmpRallyPoint.GetPositions(), [{ "x": 3, "z": 1415 }, { "x": 926, "z": 535 }]); + + let targetID = 456; + let myData = { "command": "write a unit test", "target": targetID }; + cmpRallyPoint.AddData(myData); + TS_ASSERT_UNEVAL_EQUALS(cmpRallyPoint.GetPositions(), [{ "x": 3, "z": 1415 }, { "x": 926, "z": 535 }]); + TS_ASSERT_UNEVAL_EQUALS(cmpRallyPoint.GetData(), [myData]); + + let targetID2 = 789; + let myData2 = { "command": "this time really", "target": targetID2 }; + cmpRallyPoint.AddData(myData2); + TS_ASSERT_UNEVAL_EQUALS(cmpRallyPoint.GetData(), [myData, myData2]); + + if (test_function(cmpRallyPoint)) + { + TS_ASSERT_UNEVAL_EQUALS(cmpRallyPoint.GetData(), []); + TS_ASSERT_UNEVAL_EQUALS(cmpRallyPoint.GetPositions(), []); + } + else + { + TS_ASSERT_UNEVAL_EQUALS(cmpRallyPoint.GetData(), [myData, myData2]); + TS_ASSERT_UNEVAL_EQUALS(cmpRallyPoint.GetPositions(), [{ "x": 3, "z": 1415 }, { "x": 926, "z": 535 }]); + } +} + +initialRallyPointTest((cmpRallyPoint) => {}); + +initialRallyPointTest((cmpRallyPoint) => { + cmpRallyPoint.Unset() + return true; +}); + +initialRallyPointTest((cmpRallyPoint) => { + cmpRallyPoint.Reset() + return true; +}); + +initialRallyPointTest((cmpRallyPoint) => { + cmpRallyPoint.OnOwnershipChanged({ "from": -1, "to": 1 }); + return false; +}); + +initialRallyPointTest((cmpRallyPoint) => { + cmpRallyPoint.OnOwnershipChanged({ "from": 1, "to": 2 }); + return true; +}); + +initialRallyPointTest((cmpRallyPoint) => { + cmpRallyPoint.OnOwnershipChanged({ "from": 2, "to": -1 }); + return true; +});