1
0
forked from 0ad/0ad
This was SVN commit r16343.
This commit is contained in:
Nicolas Auvray 2015-02-16 14:38:13 +00:00
parent 72ff88880c
commit ba210c4d59
4 changed files with 31 additions and 0 deletions

View File

@ -21,6 +21,8 @@ Visibility.prototype.Init = function()
this.alwaysVisible = this.template.AlwaysVisible == "true";
this.preview = this.template.Preview == "true";
this.activated = false;
if (this.preview)
this.SetActivated(true);
};
@ -32,6 +34,18 @@ Visibility.prototype.SetActivated = function(status)
{
let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
cmpRangeManager.ActivateScriptedVisibility(this.entity, status);
this.activated = status;
};
/**
* This function is a fallback for some entities whose visibility status
* cannot be cached by the range manager (especially local entities like previews).
* Calling the scripts is expensive, so only call it if really needed.
*/
Visibility.prototype.IsActivated = function()
{
return this.activated;
};
/**

View File

@ -1462,6 +1462,11 @@ public:
if (it->second.scriptedVisibility == 1 && cmpVisibility)
return cmpVisibility->GetVisibility(player, los.IsVisible(i, j), los.IsExplored(i, j));
}
else
{
if (cmpVisibility && cmpVisibility->IsActivated())
return cmpVisibility->GetVisibility(player, los.IsVisible(i, j), los.IsExplored(i, j));
}
// Else, default behavior

View File

@ -30,6 +30,11 @@ class CCmpVisibilityScripted : public ICmpVisibility
public:
DEFAULT_SCRIPT_WRAPPER(VisibilityScripted)
virtual bool IsActivated()
{
return m_Script.Call<bool>("IsActivated");
}
virtual ICmpRangeManager::ELosVisibility GetVisibility(player_id_t player, bool isVisible, bool isExplored)
{
int visibility = m_Script.Call<int, player_id_t, bool, bool>("GetVisibility", player, isVisible, isExplored);

View File

@ -35,6 +35,13 @@
class ICmpVisibility : public IComponent
{
public:
/**
* This function is a fallback for some entities whose visibility status
* cannot be cached by the range manager (especially local entities like previews).
* Calling the scripts is expensive, so only call it if really needed.
*/
virtual bool IsActivated() = 0;
virtual ICmpRangeManager::ELosVisibility GetVisibility(player_id_t player, bool isVisible, bool isExplored) = 0;
virtual bool GetRetainInFog() = 0;