Ticket #2913: cpp_activation.patch
File cpp_activation.patch, 6.8 KB (added by , 9 years ago) |
---|
-
binaries/data/mods/public/simulation/components/Visibility.js
21 21 this.alwaysVisible = this.template.AlwaysVisible == "true"; 22 22 this.preview = this.template.Preview == "true"; 23 23 24 this.activated = false;25 26 24 if (this.preview) 27 this. activated = true;25 this.Activate(true); 28 26 }; 29 27 30 28 /** 31 * If this function returns true, the range manager will call the GetVisibility function 32 * instead of computing the visibility. 29 * Sets the range manager scriptedVisibility flag for this entity. 33 30 */ 34 Visibility.prototype. IsActivated = function()31 Visibility.prototype.Activate = function(status) 35 32 { 36 return this.activated; 33 let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); 34 cmpRangeManager.ActivateScriptedVisibility(this.entity, status); 37 35 }; 38 36 39 37 /** 40 * This function is called if IsActivated returns true.38 * This function is called if the range manager scriptedVisibility flag is set to true for this entity. 41 39 * If so, the return value supersedes the visibility computed by the range manager. 42 40 * isVisible: true if the entity is in the vision range of a unit, false otherwise 43 41 * isExplored: true if the entity is in explored territory, false otherwise … … 44 42 */ 45 43 Visibility.prototype.GetVisibility = function(player, isVisible, isExplored) 46 44 { 47 if (!this.activated)48 warn("The Visibility component was asked to provide a superseding visibility while not activated, this should not happen");49 50 45 if (this.preview) 51 46 { 52 47 // For the owner only, mock the "RetainInFog" behaviour -
source/simulation2/components/CCmpRangeManager.cpp
174 174 */ 175 175 struct EntityData 176 176 { 177 EntityData() : visibilities(0), retainInFog(0), owner(-1), inWorld(0), flags(1) { }177 EntityData() : visibilities(0), retainInFog(0), owner(-1), inWorld(0), flags(1), scriptedVisibility(0) { } 178 178 entity_pos_t x, z; 179 179 entity_pos_t visionRange; 180 180 u32 visibilities; // 2-bit visibility, per player … … 182 182 i8 owner; 183 183 u8 inWorld; // boolean 184 184 u8 flags; // See GetEntityFlagMask 185 u8 scriptedVisibility; // boolean, see ComputeLosVisibility 185 186 }; 186 187 187 cassert(sizeof(EntityData) == 2 0);188 cassert(sizeof(EntityData) == 24); 188 189 189 190 /** 190 191 * Serialization helper template for Query … … 1415 1416 return CLosQuerier(GetSharedLosMask(player), m_LosState, m_TerrainVerticesPerSide); 1416 1417 } 1417 1418 1419 virtual void ActivateScriptedVisibility(entity_id_t ent, bool status) 1420 { 1421 EntityMap<EntityData>::iterator it = m_EntityData.find(ent); 1422 if (it != m_EntityData.end()) 1423 it->second.scriptedVisibility = status ? 1 : 0; 1424 } 1425 1418 1426 ELosVisibility ComputeLosVisibility(CEntityHandle ent, player_id_t player) 1419 1427 { 1420 1428 // Entities not with positions in the world are never visible … … 1445 1453 // Get visible regions 1446 1454 CLosQuerier los(GetSharedLosMask(player), m_LosState, m_TerrainVerticesPerSide); 1447 1455 1448 // Ask the Visibility component about special situations1449 1456 CmpPtr<ICmpVisibility> cmpVisibility(ent); 1450 if (cmpVisibility && cmpVisibility->IsActivated())1451 return cmpVisibility->GetVisibility(player, los.IsVisible(i, j), los.IsExplored(i, j));1452 1457 1458 // Possibly ask the scripted Visibility component 1459 EntityMap<EntityData>::iterator it = m_EntityData.find(ent.GetId()); 1460 if (it != m_EntityData.end()) 1461 { 1462 if (it->second.scriptedVisibility == 1 && cmpVisibility) 1463 return cmpVisibility->GetVisibility(player, los.IsVisible(i, j), los.IsExplored(i, j)); 1464 } 1465 1453 1466 // Else, default behavior 1454 1467 1455 1468 if (los.IsVisible(i, j)) -
source/simulation2/components/ICmpRangeManager.cpp
51 51 DEFINE_INTERFACE_METHOD_2("SetLosRevealAll", void, ICmpRangeManager, SetLosRevealAll, player_id_t, bool) 52 52 DEFINE_INTERFACE_METHOD_1("GetLosRevealAll", bool, ICmpRangeManager, GetLosRevealAll, player_id_t) 53 53 DEFINE_INTERFACE_METHOD_5("GetElevationAdaptedRange", entity_pos_t, ICmpRangeManager, GetElevationAdaptedRange, CFixedVector3D, CFixedVector3D, entity_pos_t, entity_pos_t, entity_pos_t) 54 DEFINE_INTERFACE_METHOD_2("ActivateScriptedVisibility", void, ICmpRangeManager, ActivateScriptedVisibility, entity_id_t, bool) 54 55 DEFINE_INTERFACE_METHOD_2("GetLosVisibility", std::string, ICmpRangeManager, GetLosVisibility_wrapper, entity_id_t, player_id_t) 55 56 DEFINE_INTERFACE_METHOD_1("RequestVisibilityUpdate", void, ICmpRangeManager, RequestVisibilityUpdate, entity_id_t) 56 57 DEFINE_INTERFACE_METHOD_1("SetLosCircular", void, ICmpRangeManager, SetLosCircular, bool) -
source/simulation2/components/ICmpRangeManager.h
314 314 * (or other players it shares LOS with). 315 315 */ 316 316 virtual CLosQuerier GetLosQuerier(player_id_t player) = 0; 317 318 /** 319 * Toggle the scripted Visibility component activation for entity ent. 320 */ 321 virtual void ActivateScriptedVisibility(entity_id_t ent, bool status) = 0; 317 322 318 323 /** 319 324 * Returns the visibility status of the given entity, with respect to the given player. -
source/simulation2/components/ICmpVisibility.cpp
30 30 public: 31 31 DEFAULT_SCRIPT_WRAPPER(VisibilityScripted) 32 32 33 virtual bool IsActivated()34 {35 return m_Script.Call<bool>("IsActivated");36 }37 38 33 virtual ICmpRangeManager::ELosVisibility GetVisibility(player_id_t player, bool isVisible, bool isExplored) 39 34 { 40 35 int visibility = m_Script.Call<int, player_id_t, bool, bool>("GetVisibility", player, isVisible, isExplored); -
source/simulation2/components/ICmpVisibility.h
35 35 class ICmpVisibility : public IComponent 36 36 { 37 37 public: 38 virtual bool IsActivated() = 0;39 40 38 virtual ICmpRangeManager::ELosVisibility GetVisibility(player_id_t player, bool isVisible, bool isExplored) = 0; 41 39 42 40 virtual bool GetRetainInFog() = 0;