Changeset View
Changeset View
Standalone View
Standalone View
source/simulation2/components/CCmpTerritoryManager.h
- This file was added.
/* Copyright (C) 2022 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_CCMPTERRITORYMANAGER | |||||
#define INCLUDED_CCMPTERRITORYMANAGER | |||||
#include "ICmpTerritoryManager.h" | |||||
#include "graphics/Color.h" | |||||
#include "graphics/Overlay.h" | |||||
#include "graphics/TerritoryBoundary.h" | |||||
#include "renderer/Scene.h" | |||||
class TerritoryOverlay; | |||||
class CCmpTerritoryManager : public ICmpTerritoryManager | |||||
{ | |||||
public: | |||||
static constexpr int typeId{CID_TerritoryManager}; | |||||
static void ClassInit(CComponentManager& componentManager); | |||||
static IComponent* Allocate(const ScriptInterface&, JS::HandleValue); | |||||
static void Deallocate(IComponent* cmp); | |||||
int GetComponentTypeId() const override; | |||||
static std::string GetSchema(); | |||||
u8 m_ImpassableCost; | |||||
float m_BorderThickness; | |||||
float m_BorderSeparation; | |||||
// Player ID in bits 0-4 (TERRITORY_PLAYER_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; | |||||
std::vector<u16> m_TerritoryCellCounts; | |||||
u16 m_TerritoryTotalPassableCellCount; | |||||
// Saves the cost per tile (to stop territory on impassable tiles) | |||||
Grid<u8>* m_CostGrid; | |||||
// Set to true when territories change; will send a TerritoriesChanged message | |||||
// during the Update phase | |||||
bool m_TriggerEvent; | |||||
struct SBoundaryLine | |||||
{ | |||||
bool blinking; | |||||
player_id_t owner; | |||||
CColor color; | |||||
SOverlayTexturedLine overlay; | |||||
}; | |||||
std::vector<SBoundaryLine> m_BoundaryLines; | |||||
bool m_BoundaryLinesDirty; | |||||
double m_AnimTime; // time since start of rendering, in seconds | |||||
TerritoryOverlay* m_DebugOverlay; | |||||
bool m_EnableLineDebugOverlays; ///< Enable node debugging overlays for boundary lines? | |||||
std::vector<SOverlayLine> m_DebugBoundaryLineNodes; | |||||
void Init(const CParamNode& UNUSED(paramNode)) override; | |||||
void Deinit() override; | |||||
void Serialize(ISerializer& serialize) override; | |||||
void Deserialize(const CParamNode& paramNode, IDeserializer& deserialize) override; | |||||
void HandleMessage(const CMessage& msg, bool UNUSED(global)) override; | |||||
// Check whether the entity is either a settlement or territory influence; | |||||
// ignore any others | |||||
void MakeDirtyIfRelevantEntity(entity_id_t ent); | |||||
const Grid<u8>& GetTerritoryGrid() override; | |||||
player_id_t GetOwner(entity_pos_t x, entity_pos_t z) override; | |||||
std::vector<u32> GetNeighbours(entity_pos_t x, entity_pos_t z, bool filterConnected) override; | |||||
bool IsConnected(entity_pos_t x, entity_pos_t z) override; | |||||
void SetTerritoryBlinking(entity_pos_t x, entity_pos_t z, bool enable) override; | |||||
bool IsTerritoryBlinking(entity_pos_t x, entity_pos_t z) override; | |||||
// 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; | |||||
bool m_ColorChanged; | |||||
void MakeDirty(); | |||||
bool NeedUpdateTexture(size_t* dirtyID) override; | |||||
bool NeedUpdateAI(size_t* dirtyID, size_t* dirtyBlinkingID) const override; | |||||
void CalculateCostGrid(); | |||||
void CalculateTerritories(); | |||||
u8 GetTerritoryPercentage(player_id_t player) override; | |||||
std::vector<STerritoryBoundary> ComputeBoundaries(); | |||||
void UpdateBoundaryLines(); | |||||
void Interpolate(float frameTime, float frameOffset); | |||||
void RenderSubmit(SceneCollector& collector, const CFrustum& frustum, bool culling); | |||||
void SetVisibility(bool visible) override; | |||||
void UpdateColors() override; | |||||
private: | |||||
bool m_Visible; | |||||
}; | |||||
#endif // INCLUDED_CCMPTERRITORYMANAGER |
Wildfire Games · Phabricator