Changeset View
Changeset View
Standalone View
Standalone View
source/simulation2/components/ICmpRangeManager.h
/* Copyright (C) 2019 Wildfire Games. | /* Copyright (C) 2020 Wildfire Games. | ||||
Silier: years | |||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 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 | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
Show All 9 Lines | |||||
#define INCLUDED_ICMPRANGEMANAGER | #define INCLUDED_ICMPRANGEMANAGER | ||||
#include "maths/FixedVector3D.h" | #include "maths/FixedVector3D.h" | ||||
#include "maths/FixedVector2D.h" | #include "maths/FixedVector2D.h" | ||||
#include "simulation2/system/Interface.h" | #include "simulation2/system/Interface.h" | ||||
#include "simulation2/helpers/Position.h" | #include "simulation2/helpers/Position.h" | ||||
#include "simulation2/helpers/Player.h" | #include "simulation2/helpers/Player.h" | ||||
#include "simulation2/helpers/ArrayData.h" | |||||
#include "graphics/Terrain.h" // for TERRAIN_TILE_SIZE | #include "graphics/Terrain.h" // for TERRAIN_TILE_SIZE | ||||
class FastSpatialSubdivision; | class FastSpatialSubdivision; | ||||
/** | /** | ||||
* Provides efficient range-based queries of the game world, | * Provides efficient range-based queries of the game world, | ||||
* and also LOS-based effects (fog of war). | * and also LOS-based effects (fog of war). | ||||
▲ Show 20 Lines • Show All 210 Lines • ▼ Show 20 Lines | public: | ||||
* This *ignores* the GetLosRevealAll flag - callers should check that explicitly. | * This *ignores* the GetLosRevealAll flag - callers should check that explicitly. | ||||
*/ | */ | ||||
class CLosQuerier | class CLosQuerier | ||||
{ | { | ||||
private: | private: | ||||
friend class CCmpRangeManager; | friend class CCmpRangeManager; | ||||
friend class TestLOSTexture; | friend class TestLOSTexture; | ||||
CLosQuerier(u32 playerMask, const std::vector<u32>& data, ssize_t verticesPerSide) : | CLosQuerier(PlayersData playerMask, const std::vector<PlayersData>& data, ssize_t verticesPerSide) : | ||||
m_Data(&data[0]), m_PlayerMask(playerMask), m_VerticesPerSide(verticesPerSide) | m_Data(data), m_PlayerMask(playerMask), m_VerticesPerSide(verticesPerSide) | ||||
{ | { | ||||
} | } | ||||
const CLosQuerier& operator=(const CLosQuerier&); // not implemented | const CLosQuerier& operator=(const CLosQuerier&); // not implemented | ||||
public: | public: | ||||
/** | /** | ||||
* Returns whether the given vertex is visible (i.e. is within a unit's LOS). | * Returns whether the given vertex is visible (i.e. is within a unit's LOS). | ||||
*/ | */ | ||||
inline bool IsVisible(ssize_t i, ssize_t j) const | inline bool IsVisible(ssize_t i, ssize_t j) const | ||||
{ | { | ||||
if (!(i >= 0 && j >= 0 && i < m_VerticesPerSide && j < m_VerticesPerSide)) | if (!(i >= 0 && j >= 0 && i < m_VerticesPerSide && j < m_VerticesPerSide)) | ||||
return false; | return false; | ||||
// Check high bit of each bit-pair | // 2 bit mask VIS_VISIBLE left shift repeated 32 times | ||||
if ((m_Data[j*m_VerticesPerSide + i] & m_PlayerMask) & 0xAAAAAAAAu) | return m_Data[j * m_VerticesPerSide + i].andExpandedMask(m_PlayerMask, 0xAAAAAAAAAAAAAAAAu); | ||||
Done Inline Actionsj * m_Ver Silier: `j * m_Ver` | |||||
return true; | |||||
else | |||||
return false; | |||||
} | } | ||||
/** | /** | ||||
* Returns whether the given vertex is explored (i.e. was (or still is) within a unit's LOS). | * Returns whether the given vertex is explored (i.e. was (or still is) within a unit's LOS). | ||||
*/ | */ | ||||
inline bool IsExplored(ssize_t i, ssize_t j) const | inline bool IsExplored(ssize_t i, ssize_t j) const | ||||
{ | { | ||||
if (!(i >= 0 && j >= 0 && i < m_VerticesPerSide && j < m_VerticesPerSide)) | if (!(i >= 0 && j >= 0 && i < m_VerticesPerSide && j < m_VerticesPerSide)) | ||||
return false; | return false; | ||||
// Check low bit of each bit-pair | // 2 bit mask VIS_FOGGED left shift repeated 32 times | ||||
if ((m_Data[j*m_VerticesPerSide + i] & m_PlayerMask) & 0x55555555u) | return m_Data[j * m_VerticesPerSide + i].andExpandedMask(m_PlayerMask, 0x5555555555555555u); | ||||
Done Inline Actionsj * m_Ver Silier: `j * m_Ver` | |||||
return true; | |||||
else | |||||
return false; | |||||
} | } | ||||
/** | /** | ||||
* Returns whether the given vertex is visible (i.e. is within a unit's LOS). | * Returns whether the given vertex is visible (i.e. is within a unit's LOS). | ||||
* i and j must be in the range [0, verticesPerSide), else behaviour is undefined. | * i and j must be in the range [0, verticesPerSide), else behaviour is undefined. | ||||
*/ | */ | ||||
inline bool IsVisible_UncheckedRange(ssize_t i, ssize_t j) const | inline bool IsVisible_UncheckedRange(ssize_t i, ssize_t j) const | ||||
{ | { | ||||
#ifndef NDEBUG | #ifndef NDEBUG | ||||
ENSURE(i >= 0 && j >= 0 && i < m_VerticesPerSide && j < m_VerticesPerSide); | ENSURE(i >= 0 && j >= 0 && i < m_VerticesPerSide && j < m_VerticesPerSide); | ||||
#endif | #endif | ||||
// Check high bit of each bit-pair | // 2 bit mask VIS_VISIBLE left shift repeated 32 times | ||||
if ((m_Data[j*m_VerticesPerSide + i] & m_PlayerMask) & 0xAAAAAAAAu) | return m_Data[j * m_VerticesPerSide + i].andExpandedMask(m_PlayerMask, 0xAAAAAAAAAAAAAAAAu); | ||||
Done Inline Actionsj * m_Ver Silier: `j * m_Ver` | |||||
return true; | |||||
else | |||||
return false; | |||||
} | } | ||||
/** | /** | ||||
* Returns whether the given vertex is explored (i.e. was (or still is) within a unit's LOS). | * Returns whether the given vertex is explored (i.e. was (or still is) within a unit's LOS). | ||||
* i and j must be in the range [0, verticesPerSide), else behaviour is undefined. | * i and j must be in the range [0, verticesPerSide), else behaviour is undefined. | ||||
*/ | */ | ||||
inline bool IsExplored_UncheckedRange(ssize_t i, ssize_t j) const | inline bool IsExplored_UncheckedRange(ssize_t i, ssize_t j) const | ||||
{ | { | ||||
#ifndef NDEBUG | #ifndef NDEBUG | ||||
ENSURE(i >= 0 && j >= 0 && i < m_VerticesPerSide && j < m_VerticesPerSide); | ENSURE(i >= 0 && j >= 0 && i < m_VerticesPerSide && j < m_VerticesPerSide); | ||||
#endif | #endif | ||||
// Check low bit of each bit-pair | // 2 bit mask VIS_FOGGED left shift repeated 32 times | ||||
if ((m_Data[j*m_VerticesPerSide + i] & m_PlayerMask) & 0x55555555u) | return m_Data[j * m_VerticesPerSide + i].andExpandedMask(m_PlayerMask, 0x5555555555555555u); | ||||
Done Inline Actionsj * m_Ver Silier: `j * m_Ver` | |||||
return true; | |||||
else | |||||
return false; | |||||
} | } | ||||
private: | private: | ||||
u32 m_PlayerMask; | PlayersData m_PlayerMask; | ||||
const u32* m_Data; | const std::vector<PlayersData>& m_Data; | ||||
ssize_t m_VerticesPerSide; | ssize_t m_VerticesPerSide; | ||||
}; | }; | ||||
/** | /** | ||||
* Returns a CLosQuerier for checking whether vertex positions are visible to the given player | * Returns a CLosQuerier for checking whether vertex positions are visible to the given player | ||||
* (or other players it shares LOS with). | * (or other players it shares LOS with). | ||||
*/ | */ | ||||
virtual CLosQuerier GetLosQuerier(player_id_t player) const = 0; | virtual CLosQuerier GetLosQuerier(player_id_t player) const = 0; | ||||
▲ Show 20 Lines • Show All 77 Lines • ▼ Show 20 Lines | #endif | ||||
virtual bool GetLosCircular() const = 0; | virtual bool GetLosCircular() const = 0; | ||||
/** | /** | ||||
* Sets shared LOS data for player to the given list of players. | * Sets shared LOS data for player to the given list of players. | ||||
*/ | */ | ||||
virtual void SetSharedLos(player_id_t player, const std::vector<player_id_t>& players) = 0; | virtual void SetSharedLos(player_id_t player, const std::vector<player_id_t>& players) = 0; | ||||
/** | /** | ||||
* Returns shared LOS mask for player. | |||||
*/ | |||||
virtual u32 GetSharedLosMask(player_id_t player) const = 0; | |||||
/** | |||||
* Get percent map explored statistics for specified player. | * Get percent map explored statistics for specified player. | ||||
*/ | */ | ||||
virtual u8 GetPercentMapExplored(player_id_t player) const = 0; | virtual u8 GetPercentMapExplored(player_id_t player) const = 0; | ||||
/** | /** | ||||
* Get percent map explored statistics for specified set of players. | * Get percent map explored statistics for specified set of players. | ||||
* Note: this function computes statistics from scratch and should not be called too often. | * Note: this function computes statistics from scratch and should not be called too often. | ||||
*/ | */ | ||||
Show All 12 Lines |
Wildfire Games · Phabricator
years