Add a TerritoryDecayManager component to update territoryMap with the blinking state when territories are recomputed. That's needed by the AI which was up to now not aware of blinking cells.
Differential Revision: https://code.wildfiregames.com/D910 This was SVN commit r20268.
This commit is contained in:
parent
af9c25f879
commit
b5e3b83c9e
@ -0,0 +1,12 @@
|
||||
function TerritoryDecayManager() {}
|
||||
|
||||
TerritoryDecayManager.prototype.Schema =
|
||||
"<a:component type='system'/><empty/>";
|
||||
|
||||
TerritoryDecayManager.prototype.SetBlinkingEntities = function()
|
||||
{
|
||||
for (let ent of Engine.GetEntitiesWithInterface(IID_TerritoryDecay))
|
||||
Engine.QueryInterface(ent, IID_TerritoryDecay).IsConnected();
|
||||
};
|
||||
|
||||
Engine.RegisterSystemComponentType(IID_TerritoryDecayManager, "TerritoryDecayManager", TerritoryDecayManager);
|
@ -168,6 +168,9 @@ COMPONENT(DataTemplateManagerScripted)
|
||||
INTERFACE(Terrain)
|
||||
COMPONENT(Terrain)
|
||||
|
||||
INTERFACE(TerritoryDecayManager)
|
||||
COMPONENT(TerritoryDecayManagerScripted)
|
||||
|
||||
INTERFACE(TerritoryInfluence)
|
||||
COMPONENT(TerritoryInfluence)
|
||||
|
||||
|
@ -967,6 +967,7 @@ public:
|
||||
virtual void Init(const CParamNode& UNUSED(paramNode))
|
||||
{
|
||||
m_TerritoriesDirtyID = 0;
|
||||
m_TerritoriesDirtyBlinkingID = 0;
|
||||
m_JustDeserialized = false;
|
||||
|
||||
StartLoadEntityTemplates();
|
||||
@ -1086,10 +1087,8 @@ public:
|
||||
Grid<u8> dummyGrid2;
|
||||
const Grid<u8>* territoryMap = &dummyGrid2;
|
||||
CmpPtr<ICmpTerritoryManager> cmpTerritoryManager(GetSystemEntity());
|
||||
if (cmpTerritoryManager && cmpTerritoryManager->NeedUpdate(&m_TerritoriesDirtyID))
|
||||
{
|
||||
if (cmpTerritoryManager && cmpTerritoryManager->NeedUpdate(&m_TerritoriesDirtyID, &m_TerritoriesDirtyBlinkingID))
|
||||
territoryMap = &cmpTerritoryManager->GetTerritoryGrid();
|
||||
}
|
||||
|
||||
LoadPathfinderClasses(state);
|
||||
std::map<std::string, pass_class_t> nonPathfindingPassClassMasks, pathfindingPassClassMasks;
|
||||
@ -1150,7 +1149,7 @@ public:
|
||||
// Update the territory data
|
||||
// Since getting the territory grid can trigger a recalculation, we check NeedUpdate first
|
||||
CmpPtr<ICmpTerritoryManager> cmpTerritoryManager(GetSystemEntity());
|
||||
if (cmpTerritoryManager && (cmpTerritoryManager->NeedUpdate(&m_TerritoriesDirtyID) || m_JustDeserialized))
|
||||
if (cmpTerritoryManager && (cmpTerritoryManager->NeedUpdate(&m_TerritoriesDirtyID, &m_TerritoriesDirtyBlinkingID) || m_JustDeserialized))
|
||||
{
|
||||
const Grid<u8>& territoryMap = cmpTerritoryManager->GetTerritoryGrid();
|
||||
m_Worker.UpdateTerritoryMap(territoryMap);
|
||||
@ -1190,6 +1189,7 @@ private:
|
||||
size_t m_TemplateLoadedIdx;
|
||||
std::vector<std::pair<std::string, const CParamNode*> > m_Templates;
|
||||
size_t m_TerritoriesDirtyID;
|
||||
size_t m_TerritoriesDirtyBlinkingID;
|
||||
|
||||
bool m_JustDeserialized;
|
||||
|
||||
|
@ -36,6 +36,7 @@
|
||||
#include "simulation2/components/ICmpPlayer.h"
|
||||
#include "simulation2/components/ICmpPlayerManager.h"
|
||||
#include "simulation2/components/ICmpPosition.h"
|
||||
#include "simulation2/components/ICmpTerritoryDecayManager.h"
|
||||
#include "simulation2/components/ICmpTerritoryInfluence.h"
|
||||
#include "simulation2/helpers/Grid.h"
|
||||
#include "simulation2/helpers/Render.h"
|
||||
@ -83,8 +84,8 @@ public:
|
||||
float m_BorderSeparation;
|
||||
|
||||
// Player ID in bits 0-4 (TERRITORY_PLAYER_MASK)
|
||||
// connected flag in bit 4 (TERRITORY_CONNECTED_MASK)
|
||||
// blinking flag in bit 5 (TERRITORY_BLINKING_MASK)
|
||||
// connected flag in bit 5 (TERRITORY_CONNECTED_MASK)
|
||||
// blinking flag in bit 6 (TERRITORY_BLINKING_MASK)
|
||||
// processed flag in bit 7 (TERRITORY_PROCESSED_MASK)
|
||||
Grid<u8>* m_Territories;
|
||||
|
||||
@ -125,6 +126,7 @@ public:
|
||||
m_TriggerEvent = true;
|
||||
m_EnableLineDebugOverlays = false;
|
||||
m_DirtyID = 1;
|
||||
m_DirtyBlinkingID = 1;
|
||||
m_Visible = true;
|
||||
|
||||
m_AnimTime = 0.0;
|
||||
@ -251,8 +253,10 @@ public:
|
||||
// To support lazy updates of territory render data,
|
||||
// we maintain a DirtyID here and increment it whenever territories change;
|
||||
// if a caller has a lower DirtyID then it needs to be updated.
|
||||
// We also do the same thing for blinking updates using DirtyBlinkingID.
|
||||
|
||||
size_t m_DirtyID;
|
||||
size_t m_DirtyBlinkingID;
|
||||
|
||||
void MakeDirty()
|
||||
{
|
||||
@ -272,6 +276,17 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual bool NeedUpdate(size_t* dirtyID, size_t* dirtyBlinkingID) const
|
||||
{
|
||||
if (*dirtyID != m_DirtyID || *dirtyBlinkingID != m_DirtyBlinkingID)
|
||||
{
|
||||
*dirtyID = m_DirtyID;
|
||||
*dirtyBlinkingID = m_DirtyBlinkingID;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void CalculateCostGrid();
|
||||
|
||||
void CalculateTerritories();
|
||||
@ -538,6 +553,15 @@ void CCmpTerritoryManager::CalculateTerritories()
|
||||
++m_TerritoryCellCounts[owner];
|
||||
);
|
||||
}
|
||||
|
||||
// Then recomputes the blinking tiles
|
||||
CmpPtr<ICmpTerritoryDecayManager> cmpTerritoryDecayManager(GetSystemEntity());
|
||||
if (cmpTerritoryDecayManager)
|
||||
{
|
||||
size_t dirtyBlinkingID = m_DirtyBlinkingID;
|
||||
cmpTerritoryDecayManager->SetBlinkingEntities();
|
||||
m_DirtyBlinkingID = dirtyBlinkingID;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<STerritoryBoundary> CCmpTerritoryManager::ComputeBoundaries()
|
||||
@ -766,6 +790,7 @@ void CCmpTerritoryManager::SetTerritoryBlinking(entity_pos_t x, entity_pos_t z,
|
||||
else
|
||||
continue;
|
||||
);
|
||||
++m_DirtyBlinkingID;
|
||||
m_BoundaryLinesDirty = true;
|
||||
}
|
||||
|
||||
|
40
source/simulation2/components/ICmpTerritoryDecayManager.cpp
Normal file
40
source/simulation2/components/ICmpTerritoryDecayManager.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
/* Copyright (C) 2017 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 0 A.D. is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "precompiled.h"
|
||||
|
||||
#include "ICmpTerritoryDecayManager.h"
|
||||
|
||||
#include "simulation2/system/InterfaceScripted.h"
|
||||
#include "simulation2/scripting/ScriptComponent.h"
|
||||
|
||||
BEGIN_INTERFACE_WRAPPER(TerritoryDecayManager)
|
||||
END_INTERFACE_WRAPPER(TerritoryDecayManager)
|
||||
|
||||
class CCmpTerritoryDecayManagerScripted : public ICmpTerritoryDecayManager
|
||||
{
|
||||
public:
|
||||
DEFAULT_SCRIPT_WRAPPER(TerritoryDecayManagerScripted)
|
||||
|
||||
virtual void SetBlinkingEntities()
|
||||
{
|
||||
return m_Script.CallVoid("SetBlinkingEntities");
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
REGISTER_COMPONENT_SCRIPT_WRAPPER(TerritoryDecayManagerScripted)
|
32
source/simulation2/components/ICmpTerritoryDecayManager.h
Normal file
32
source/simulation2/components/ICmpTerritoryDecayManager.h
Normal file
@ -0,0 +1,32 @@
|
||||
/* Copyright (C) 2017 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 0 A.D. is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_ICMPTERRITORYDECAYMANAGER
|
||||
#define INCLUDED_ICMPTERRITORYDECAYMANAGER
|
||||
|
||||
#include "simulation2/system/Interface.h"
|
||||
|
||||
class ICmpTerritoryDecayManager : public IComponent
|
||||
{
|
||||
public:
|
||||
|
||||
virtual void SetBlinkingEntities() = 0;
|
||||
|
||||
DECLARE_INTERFACE_TYPE(TerritoryDecayManager)
|
||||
};
|
||||
|
||||
#endif // INCLUDED_ICMPTERRITORYDECAYMANAGER
|
@ -28,6 +28,7 @@ class ICmpTerritoryManager : public IComponent
|
||||
{
|
||||
public:
|
||||
virtual bool NeedUpdate(size_t* dirtyID) const = 0;
|
||||
virtual bool NeedUpdate(size_t* dirtyID, size_t* dirtyBlinkingID) const = 0;
|
||||
|
||||
/**
|
||||
* Number of pathfinder navcells per territory tile.
|
||||
|
Loading…
Reference in New Issue
Block a user