mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-07-29 08:13:01 +00:00
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:
@@ -182,30 +182,35 @@ Fogging.prototype.WasSeen = function(player)
|
|||||||
return this.seen[player];
|
return this.seen[player];
|
||||||
};
|
};
|
||||||
|
|
||||||
Fogging.prototype.OnDestroy = function(msg)
|
Fogging.prototype.OnOwnershipChanged = function(msg)
|
||||||
{
|
{
|
||||||
var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
|
// Always activate fogging for non-Gaia entities
|
||||||
for (var player = 0; player < this.mirages.length; ++player)
|
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")
|
if (cmpRangeManager.GetLosVisibility(this.mirages[player], player) == "hidden")
|
||||||
{
|
{
|
||||||
Engine.DestroyEntity(this.mirages[player]);
|
Engine.DestroyEntity(this.mirages[player]);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var cmpMirage = Engine.QueryInterface(this.mirages[player], IID_Mirage);
|
let cmpMirage = Engine.QueryInterface(this.mirages[player], IID_Mirage);
|
||||||
if (cmpMirage)
|
if (cmpMirage)
|
||||||
cmpMirage.SetParent(INVALID_ENTITY);
|
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)
|
Fogging.prototype.OnVisibilityChanged = function(msg)
|
||||||
{
|
{
|
||||||
if (msg.player < 0 || msg.player >= this.mirages.length)
|
if (msg.player < 0 || msg.player >= this.mirages.length)
|
||||||
|
|||||||
@@ -208,6 +208,7 @@ Mirage.prototype.UpdateTraders = function(msg)
|
|||||||
|
|
||||||
Mirage.prototype.OnVisibilityChanged = 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)
|
if (msg.player != this.player || msg.newVisibility != VIS_HIDDEN)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user