1
0
forked from 0ad/0ad

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.
This commit is contained in:
wraitii 2019-05-04 13:49:08 +00:00
parent e4a5a8f848
commit 905763004a
2 changed files with 17 additions and 11 deletions

View File

@ -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)

View File

@ -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;