Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
|
Provides efficient range-based queries of the game world, and also LOS-based effects (fog of war). More...
#include <ICmpRangeManager.h>
Public Types | |
typedef u32 | tag_t |
External identifiers for active queries. More... | |
Public Types inherited from IComponent | |
using | AllocFunc = IComponent *(*)(const ScriptInterface &scriptInterface, JS::HandleValue ctor) |
using | DeallocFunc = void(*)(IComponent *) |
Public Member Functions | |
virtual FastSpatialSubdivision * | GetSubdivision ()=0 |
Access the spatial subdivision kept by the range manager. More... | |
virtual void | SetBounds (entity_pos_t x0, entity_pos_t z0, entity_pos_t x1, entity_pos_t z1)=0 |
Set the bounds of the world. More... | |
virtual std::vector< entity_id_t > | ExecuteQuery (entity_id_t source, entity_pos_t minRange, entity_pos_t maxRange, const std::vector< int > &owners, int requiredInterface, bool accountForSize)=0 |
Execute a passive query. More... | |
virtual std::vector< entity_id_t > | ExecuteQueryAroundPos (const CFixedVector2D &pos, entity_pos_t minRange, entity_pos_t maxRange, const std::vector< int > &owners, int requiredInterface, bool accountForSize)=0 |
Execute a passive query. More... | |
virtual tag_t | CreateActiveQuery (entity_id_t source, entity_pos_t minRange, entity_pos_t maxRange, const std::vector< int > &owners, int requiredInterface, u8 flags, bool accountForSize)=0 |
Construct an active query. More... | |
virtual tag_t | CreateActiveParabolicQuery (entity_id_t source, entity_pos_t minRange, entity_pos_t maxRange, entity_pos_t yOrigin, const std::vector< int > &owners, int requiredInterface, u8 flags)=0 |
Construct an active query of a paraboloic form around the unit. More... | |
virtual entity_pos_t | GetEffectiveParabolicRange (entity_id_t source, entity_id_t target, entity_pos_t range, entity_pos_t yOrigin) const =0 |
Get the effective range in a parablic range query. More... | |
virtual entity_pos_t | GetElevationAdaptedRange (const CFixedVector3D &pos, const CFixedVector3D &rot, entity_pos_t range, entity_pos_t yOrigin, entity_pos_t angle) const =0 |
Get the average elevation over 8 points on distance range around the entity. More... | |
virtual void | DestroyActiveQuery (tag_t tag)=0 |
Destroy a query and clean up resources. More... | |
virtual void | EnableActiveQuery (tag_t tag)=0 |
Re-enable the processing of a query. More... | |
virtual void | DisableActiveQuery (tag_t tag)=0 |
Disable the processing of a query (no RangeUpdate messages will be sent). More... | |
virtual bool | IsActiveQueryEnabled (tag_t tag) const =0 |
Check if the processing of a query is enabled. More... | |
virtual std::vector< entity_id_t > | ResetActiveQuery (tag_t tag)=0 |
Immediately execute a query, and re-enable it if disabled. More... | |
virtual std::vector< entity_id_t > | GetEntitiesByPlayer (player_id_t player) const =0 |
Returns a list of all entities for a specific player. More... | |
virtual std::vector< entity_id_t > | GetNonGaiaEntities () const =0 |
Returns a list of all entities of all players except gaia. More... | |
virtual std::vector< entity_id_t > | GetGaiaAndNonGaiaEntities () const =0 |
Returns a list of all entities owned by a player or gaia. More... | |
virtual void | SetDebugOverlay (bool enabled)=0 |
Toggle the rendering of debug info. More... | |
virtual u8 | GetEntityFlagMask (const std::string &identifier) const =0 |
Returns the mask for the specified identifier. More... | |
virtual void | SetEntityFlag (entity_id_t ent, const std::string &identifier, bool value)=0 |
Set the flag specified by the identifier to the supplied value for the entity. More... | |
virtual CLosQuerier | GetLosQuerier (player_id_t player) const =0 |
Returns a CLosQuerier for checking whether vertex positions are visible to the given player (or other players it shares LOS with). More... | |
virtual void | ActivateScriptedVisibility (entity_id_t ent, bool status)=0 |
Toggle the scripted Visibility component activation for entity ent. More... | |
virtual LosVisibility | GetLosVisibility (CEntityHandle ent, player_id_t player) const =0 |
Returns the visibility status of the given entity, with respect to the given player. More... | |
virtual LosVisibility | GetLosVisibility (entity_id_t ent, player_id_t player) const =0 |
virtual LosVisibility | GetLosVisibilityPosition (entity_pos_t x, entity_pos_t z, player_id_t player) const =0 |
Returns the visibility status of the given position, with respect to the given player. More... | |
virtual void | RequestVisibilityUpdate (entity_id_t ent)=0 |
Request the update of the visibility cache of ent at next turn. More... | |
std::string | GetLosVisibility_wrapper (entity_id_t ent, player_id_t player) const |
GetLosVisibility wrapped for script calls. More... | |
std::string | GetLosVisibilityPosition_wrapper (entity_pos_t x, entity_pos_t z, player_id_t player) const |
GetLosVisibilityPosition wrapped for script calls. More... | |
virtual void | ExploreMap (player_id_t p)=0 |
Explore the map (but leave it in the FoW) for player p. More... | |
virtual void | ExploreTerritories ()=0 |
Explore the tiles inside each player's territory. More... | |
virtual void | RevealShore (player_id_t p, bool enable)=0 |
Reveal the shore for specified player p. More... | |
virtual void | SetLosRevealAll (player_id_t player, bool enabled)=0 |
Set whether the whole map should be made visible to the given player. More... | |
virtual bool | GetLosRevealAll (player_id_t player) const =0 |
Returns whether the whole map has been made visible to the given player. More... | |
virtual void | SetLosCircular (bool enabled)=0 |
Set the LOS to be restricted to a circular map. More... | |
virtual bool | GetLosCircular () const =0 |
Returns whether the LOS is restricted to a circular map. More... | |
virtual void | SetSharedLos (player_id_t player, const std::vector< player_id_t > &players)=0 |
Sets shared LOS data for player to the given list of players. More... | |
virtual u32 | GetSharedLosMask (player_id_t player) const =0 |
Returns shared LOS mask for player. More... | |
virtual u8 | GetPercentMapExplored (player_id_t player) const =0 |
Get percent map explored statistics for specified player. More... | |
virtual u8 | GetUnionPercentMapExplored (const std::vector< player_id_t > &players) const =0 |
Get percent map explored statistics for specified set of players. More... | |
virtual size_t | GetVerticesPerSide () const =0 |
virtual void | Verify ()=0 |
Perform some internal consistency checks for testing/debugging. More... | |
Public Member Functions inherited from IComponent | |
virtual | ~IComponent () |
virtual void | Init (const CParamNode ¶mNode)=0 |
virtual void | Deinit ()=0 |
virtual void | HandleMessage (const CMessage &msg, bool global) |
CEntityHandle | GetEntityHandle () const |
void | SetEntityHandle (CEntityHandle ent) |
entity_id_t | GetEntityId () const |
CEntityHandle | GetSystemEntity () const |
const CSimContext & | GetSimContext () const |
void | SetSimContext (const CSimContext &context) |
virtual void | Serialize (ISerializer &serialize)=0 |
virtual void | Deserialize (const CParamNode ¶mNode, IDeserializer &deserialize)=0 |
virtual bool | NewJSObject (const ScriptInterface &scriptInterface, JS::MutableHandleObject out) const |
Returns false by default, indicating that a scripted wrapper of this IComponent is not supported. More... | |
virtual JS::Value | GetJSInstance () const |
virtual int | GetComponentTypeId () const =0 |
Additional Inherited Members | |
Static Public Member Functions inherited from IComponent | |
static std::string | GetSchema () |
static void | RegisterComponentType (CComponentManager &mgr, EInterfaceId iid, EComponentTypeId cid, AllocFunc alloc, DeallocFunc dealloc, const char *name, const std::string &schema) |
static void | RegisterComponentTypeScriptWrapper (CComponentManager &mgr, EInterfaceId iid, EComponentTypeId cid, AllocFunc alloc, DeallocFunc dealloc, const char *name, const std::string &schema) |
static u8 | GetSerializationVersion () |
Provides efficient range-based queries of the game world, and also LOS-based effects (fog of war).
(These are somewhat distinct concepts but they share a lot of the implementation, so for efficiency they're combined into this class.)
Possible use cases:
In most cases the users are event-based and want notifications when something has entered or left the range, and the query can be set up once and rarely changed. These queries have to be fast. Entities are approximated as points or circles (queries can be set up to ignore sizes because LOS currently ignores it, and mismatches are problematic).
Current design:
This class handles just the most common parts of range queries: distance, target interface, and player ownership. The caller can then apply any more complex filtering that it needs.
There are two types of query: Passive queries are performed by ExecuteQuery and immediately return the matching entities. Active queries are set up by CreateActiveQuery, and then a CMessageRangeUpdate message will be sent to the entity once per turn if anybody has entered or left the range since the last RangeUpdate. Queries can be disabled, in which case no message will be sent.
typedef u32 ICmpRangeManager::tag_t |
External identifiers for active queries.
|
pure virtual |
Toggle the scripted Visibility component activation for entity ent.
Implemented in CCmpRangeManager.
|
pure virtual |
Construct an active query of a paraboloic form around the unit.
The query will be disabled by default.
source | the entity around which the range will be computed. |
minRange | non-negative minimum horizontal distance in metres (inclusive). MinRange doesn't do parabolic checks. |
maxRange | non-negative maximum distance in metres (inclusive) for units on the same elevation; or -1.0 to ignore distance. For units on a different height positions, a physical correct paraboloid with height=maxRange/2 above the unit is used to query them |
yOrigin | extra bonus so the source can be placed higher and shoot further |
owners | list of player IDs that matching entities may have; -1 matches entities with no owner. |
requiredInterface | if non-zero, an interface ID that matching entities must implement. |
flags | if a entity in range has one of the flags set it will show up. NB: this one has no accountForSize parameter (assumed true), because we currently can only have 7 arguments for JS functions. |
Implemented in CCmpRangeManager.
|
pure virtual |
Construct an active query.
The query will be disabled by default.
source | the entity around which the range will be computed. |
minRange | non-negative minimum distance in metres (inclusive). |
maxRange | non-negative maximum distance in metres (inclusive); or -1.0 to ignore distance. |
owners | list of player IDs that matching entities may have; -1 matches entities with no owner. |
requiredInterface | if non-zero, an interface ID that matching entities must implement. |
flags | if a entity in range has one of the flags set it will show up. |
accountForSize | if true, compensate for source/target entity sizes. |
Implemented in CCmpRangeManager.
|
pure virtual |
Destroy a query and clean up resources.
This must be called when an entity no longer needs its query (e.g. when the entity is destroyed).
tag | identifier of query. |
Implemented in CCmpRangeManager.
|
pure virtual |
Disable the processing of a query (no RangeUpdate messages will be sent).
tag | identifier of query. |
Implemented in CCmpRangeManager.
|
pure virtual |
Re-enable the processing of a query.
tag | identifier of query. |
Implemented in CCmpRangeManager.
|
pure virtual |
Execute a passive query.
source | the entity around which the range will be computed. |
minRange | non-negative minimum distance in metres (inclusive). |
maxRange | non-negative maximum distance in metres (inclusive); or -1.0 to ignore distance. |
owners | list of player IDs that matching entities may have; -1 matches entities with no owner. |
requiredInterface | if non-zero, an interface ID that matching entities must implement. |
accountForSize | if true, compensate for source/target entity sizes. |
Implemented in CCmpRangeManager.
|
pure virtual |
Execute a passive query.
pos | the position around which the range will be computed. |
minRange | non-negative minimum distance in metres (inclusive). |
maxRange | non-negative maximum distance in metres (inclusive); or -1.0 to ignore distance. |
owners | list of player IDs that matching entities may have; -1 matches entities with no owner. |
requiredInterface | if non-zero, an interface ID that matching entities must implement. |
accountForSize | if true, compensate for source/target entity sizes. |
Implemented in CCmpRangeManager.
|
pure virtual |
Explore the map (but leave it in the FoW) for player p.
Implemented in CCmpRangeManager.
|
pure virtual |
Explore the tiles inside each player's territory.
This is done only at the beginning of the game.
Implemented in CCmpRangeManager.
|
pure virtual |
Get the effective range in a parablic range query.
source | The entity id at the origin of the query. |
target | A target entity id. |
range | The distance to compare terrain height with. |
yOrigin | Height the source gains over the target by default. |
Implemented in CCmpRangeManager.
|
pure virtual |
Get the average elevation over 8 points on distance range around the entity.
id | the entity id to look around |
range | the distance to compare terrain height with |
Implemented in CCmpRangeManager.
|
pure virtual |
Returns a list of all entities for a specific player.
(This is on this interface because it shares a lot of the implementation. Maybe it should be extended to be more like ExecuteQuery without the range parameter.)
Implemented in CCmpRangeManager.
|
pure virtual |
Returns the mask for the specified identifier.
Implemented in CCmpRangeManager.
|
pure virtual |
Returns a list of all entities owned by a player or gaia.
Implemented in CCmpRangeManager.
|
pure virtual |
Returns whether the LOS is restricted to a circular map.
Implemented in CCmpRangeManager.
|
pure virtual |
Returns a CLosQuerier for checking whether vertex positions are visible to the given player (or other players it shares LOS with).
Implemented in CCmpRangeManager.
|
pure virtual |
Returns whether the whole map has been made visible to the given player.
Implemented in CCmpRangeManager.
|
pure virtual |
Returns the visibility status of the given entity, with respect to the given player.
Returns LosVisibility::HIDDEN if the entity doesn't exist or is not in the world. This respects the GetLosRevealAll flag.
Implemented in CCmpRangeManager.
|
pure virtual |
Implemented in CCmpRangeManager.
std::string ICmpRangeManager::GetLosVisibility_wrapper | ( | entity_id_t | ent, |
player_id_t | player | ||
) | const |
GetLosVisibility wrapped for script calls.
Returns "hidden", "fogged" or "visible".
|
pure virtual |
Returns the visibility status of the given position, with respect to the given player.
This respects the GetLosRevealAll flag.
Implemented in CCmpRangeManager.
std::string ICmpRangeManager::GetLosVisibilityPosition_wrapper | ( | entity_pos_t | x, |
entity_pos_t | z, | ||
player_id_t | player | ||
) | const |
GetLosVisibilityPosition wrapped for script calls.
Returns "hidden", "fogged" or "visible".
|
pure virtual |
Returns a list of all entities of all players except gaia.
Implemented in CCmpRangeManager.
|
pure virtual |
Get percent map explored statistics for specified player.
Implemented in CCmpRangeManager.
|
pure virtual |
Returns shared LOS mask for player.
Implemented in CCmpRangeManager.
|
pure virtual |
Access the spatial subdivision kept by the range manager.
Implemented in CCmpRangeManager.
|
pure virtual |
Get percent map explored statistics for specified set of players.
Note: this function computes statistics from scratch and should not be called too often.
Implemented in CCmpRangeManager.
|
pure virtual |
Implemented in CCmpRangeManager.
|
pure virtual |
Check if the processing of a query is enabled.
tag | identifier of a query. |
Implemented in CCmpRangeManager.
|
pure virtual |
Request the update of the visibility cache of ent at next turn.
Typically used for fogging.
Implemented in CCmpRangeManager.
|
pure virtual |
Immediately execute a query, and re-enable it if disabled.
The next RangeUpdate message will say who has entered/left since this call, so you won't miss any notifications.
tag | identifier of query. |
Implemented in CCmpRangeManager.
|
pure virtual |
Reveal the shore for specified player p.
This works like for entities: if RevealShore is called multiple times with enabled, it will be necessary to call it the same number of times with !enabled to make the shore fall back into the FoW.
Implemented in CCmpRangeManager.
|
pure virtual |
Set the bounds of the world.
Entities should not be outside the bounds (else efficiency will suffer).
x0,z0,x1,z1 | Coordinates of the corners of the world |
Implemented in CCmpRangeManager.
|
pure virtual |
Toggle the rendering of debug info.
Implemented in CCmpRangeManager.
|
pure virtual |
Set the flag specified by the identifier to the supplied value for the entity.
ent | the entity whose flags will be modified. |
identifier | the flag to be modified. |
value | to which the flag will be set. |
Implemented in CCmpRangeManager.
|
pure virtual |
Set the LOS to be restricted to a circular map.
Implemented in CCmpRangeManager.
|
pure virtual |
Set whether the whole map should be made visible to the given player.
If player is -1, the map will be made visible to all players.
Implemented in CCmpRangeManager.
|
pure virtual |
Sets shared LOS data for player to the given list of players.
Implemented in CCmpRangeManager.
|
pure virtual |
Perform some internal consistency checks for testing/debugging.
Implemented in CCmpRangeManager.