From 905763004afd29ab6cee2f824f9485e564466113 Mon Sep 17 00:00:00 2001 From: wraitii Date: Sat, 4 May 2019 13:49:08 +0000 Subject: [PATCH] Slight cleanup of fogging OnDestroy and some comments Following b56f7f39d4 I dwelled in the fogging code. Some confusion could have been avoided by some comments. Also early-exit the loop to avoid doing un-necessary js->c++ transitions. Reviewed By: Itms Differential Revision: https://code.wildfiregames.com/D1737 This was SVN commit r22247. --- .../public/simulation/components/Fogging.js | 27 +++++++++++-------- .../public/simulation/components/Mirage.js | 1 + 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/binaries/data/mods/public/simulation/components/Fogging.js b/binaries/data/mods/public/simulation/components/Fogging.js index 0ffd102bd0..a31e5cca11 100644 --- a/binaries/data/mods/public/simulation/components/Fogging.js +++ b/binaries/data/mods/public/simulation/components/Fogging.js @@ -182,30 +182,35 @@ Fogging.prototype.WasSeen = function(player) return this.seen[player]; }; -Fogging.prototype.OnDestroy = function(msg) +Fogging.prototype.OnOwnershipChanged = function(msg) { - var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); - for (var player = 0; player < this.mirages.length; ++player) + // Always activate fogging for non-Gaia entities + if (msg.to > 0) + this.Activate(); + + if (msg.to != -1) + return; + + let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); + for (let player in this.mirages) { + if (this.mirages[player] == INVALID_ENTITY) + continue; + + // When this.entity is in the line of sight of the player, its mirage is hidden, rather than destroyed, to save on performance. + // All hidden mirages can be destroyed now (they won't be needed again), and other mirages will destroy themselves when they get out of the fog. if (cmpRangeManager.GetLosVisibility(this.mirages[player], player) == "hidden") { Engine.DestroyEntity(this.mirages[player]); continue; } - var cmpMirage = Engine.QueryInterface(this.mirages[player], IID_Mirage); + let cmpMirage = Engine.QueryInterface(this.mirages[player], IID_Mirage); if (cmpMirage) cmpMirage.SetParent(INVALID_ENTITY); } }; -Fogging.prototype.OnOwnershipChanged = function(msg) -{ - // Always activate fogging for non-Gaia entities - if (msg.to > 0) - this.Activate(); -}; - Fogging.prototype.OnVisibilityChanged = function(msg) { if (msg.player < 0 || msg.player >= this.mirages.length) diff --git a/binaries/data/mods/public/simulation/components/Mirage.js b/binaries/data/mods/public/simulation/components/Mirage.js index cd85c6a2ff..25b10477c8 100644 --- a/binaries/data/mods/public/simulation/components/Mirage.js +++ b/binaries/data/mods/public/simulation/components/Mirage.js @@ -208,6 +208,7 @@ Mirage.prototype.UpdateTraders = function(msg) Mirage.prototype.OnVisibilityChanged = function(msg) { + // Mirages get VIS_HIDDEN when the original entity becomes VIS_VISIBLE. if (msg.player != this.player || msg.newVisibility != VIS_HIDDEN) return;