Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Public Types | Public Member Functions | List of all members
ICmpRangeManager Class Referenceabstract

Provides efficient range-based queries of the game world, and also LOS-based effects (fog of war). More...

#include <ICmpRangeManager.h>

Inheritance diagram for ICmpRangeManager:
IComponent CCmpRangeManager

Classes

class  CLosQuerier
 Object providing efficient abstracted access to the LOS state. More...
 

Public Types

enum  ELosState { LOS_UNEXPLORED = 0, LOS_EXPLORED = 1, LOS_VISIBLE = 2, LOS_MASK = 3 }
 
enum  ELosVisibility { VIS_HIDDEN, VIS_FOGGED, VIS_VISIBLE }
 
typedef u32 tag_t
 External identifiers for active queries. More...
 

Public Member Functions

virtual void SetBounds (entity_pos_t x0, entity_pos_t z0, entity_pos_t x1, entity_pos_t z1, ssize_t vertices)=0
 Set the bounds of the world. More...
 
virtual std::vector< entity_id_tExecuteQuery (entity_id_t source, entity_pos_t minRange, entity_pos_t maxRange, std::vector< int > owners, int requiredInterface)=0
 Execute a passive query. More...
 
virtual tag_t CreateActiveQuery (entity_id_t source, entity_pos_t minRange, entity_pos_t maxRange, std::vector< int > owners, int requiredInterface, u8 flags)=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 elevationBonus, 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 GetElevationAdaptedRange (CFixedVector3D pos, CFixedVector3D rot, entity_pos_t range, entity_pos_t elevationBonus, entity_pos_t angle)=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 std::vector< entity_id_tResetActiveQuery (tag_t tag)=0
 Immediately execute a query, and re-enable it if disabled. More...
 
virtual std::vector< entity_id_tGetEntitiesByPlayer (player_id_t player)=0
 Returns list of all entities for specific player. More...
 
virtual void SetDebugOverlay (bool enabled)=0
 Toggle the rendering of debug info. More...
 
virtual u8 GetEntityFlagMask (std::string identifier)=0
 Returns the mask for the specified identifier. More...
 
virtual void SetEntityFlag (entity_id_t ent, 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)=0
 Returns a CLosQuerier for checking whether vertex positions are visible to the given player (or other players it shares LOS with). More...
 
virtual ELosVisibility GetLosVisibility (CEntityHandle ent, player_id_t player, bool forceRetainInFog=false)=0
 Returns the visibility status of the given entity, with respect to the given player. More...
 
virtual ELosVisibility GetLosVisibility (entity_id_t ent, player_id_t player, bool forceRetainInFog=false)=0
 
std::string GetLosVisibility_wrapper (entity_id_t ent, player_id_t player, bool forceRetainInFog)
 GetLosVisibility wrapped for script calls. 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)=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 ()=0
 Returns whether the LOS is restricted to a circular map. More...
 
virtual void SetSharedLos (player_id_t player, 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)=0
 Returns shared LOS mask for player. More...
 
virtual u8 GetPercentMapExplored (player_id_t player)=0
 Get percent map explored statistics for specified player. More...
 
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 &paramNode)=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 CSimContextGetSimContext () const
 
void SetSimContext (const CSimContext &context)
 
virtual void Serialize (ISerializer &serialize)=0
 
virtual void Deserialize (const CParamNode &paramNode, IDeserializer &deserialize)=0
 
virtual JSClass * GetJSClass () const
 
virtual jsval GetJSInstance () const
 

Additional Inherited Members

- Static Public Member Functions inherited from IComponent
static std::string GetSchema ()
 
static u8 GetSerializationVersion ()
 

Detailed Description

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. It's fine to approximate an entity as a point.

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.

Definition at line 66 of file ICmpRangeManager.h.

Member Typedef Documentation

External identifiers for active queries.

Definition at line 72 of file ICmpRangeManager.h.

Member Enumeration Documentation

Enumerator
LOS_UNEXPLORED 
LOS_EXPLORED 
LOS_VISIBLE 
LOS_MASK 

Definition at line 189 of file ICmpRangeManager.h.

Enumerator
VIS_HIDDEN 
VIS_FOGGED 
VIS_VISIBLE 

Definition at line 197 of file ICmpRangeManager.h.

Member Function Documentation

virtual tag_t ICmpRangeManager::CreateActiveParabolicQuery ( entity_id_t  source,
entity_pos_t  minRange,
entity_pos_t  maxRange,
entity_pos_t  elevationBonus,
std::vector< int >  owners,
int  requiredInterface,
u8  flags 
)
pure virtual

Construct an active query of a paraboloic form around the unit.

The query will be disabled by default.

Parameters
sourcethe entity around which the range will be computed.
minRangenon-negative minimum horizontal distance in metres (inclusive). MinRange doesn't do parabolic checks.
maxRangenon-negative maximum distance in metres (inclusive) for units on the same elevation; or -1.0 to ignore distance. For units on a different elevation, a physical correct paraboloid with height=maxRange/2 above the unit is used to query them
elevationBonusextra bonus so the source can be placed higher and shoot further
ownerslist of player IDs that matching entities may have; -1 matches entities with no owner.
requiredInterfaceif non-zero, an interface ID that matching entities must implement.
flagsif a entity in range has one of the flags set it will show up.
Returns
unique non-zero identifier of query.

Implemented in CCmpRangeManager.

virtual tag_t ICmpRangeManager::CreateActiveQuery ( entity_id_t  source,
entity_pos_t  minRange,
entity_pos_t  maxRange,
std::vector< int >  owners,
int  requiredInterface,
u8  flags 
)
pure virtual

Construct an active query.

The query will be disabled by default.

Parameters
sourcethe entity around which the range will be computed.
minRangenon-negative minimum distance in metres (inclusive).
maxRangenon-negative maximum distance in metres (inclusive); or -1.0 to ignore distance.
ownerslist of player IDs that matching entities may have; -1 matches entities with no owner.
requiredInterfaceif non-zero, an interface ID that matching entities must implement.
flagsif a entity in range has one of the flags set it will show up.
Returns
unique non-zero identifier of query.

Implemented in CCmpRangeManager.

virtual void ICmpRangeManager::DestroyActiveQuery ( tag_t  tag)
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).

Parameters
tagidentifier of query.

Implemented in CCmpRangeManager.

virtual void ICmpRangeManager::DisableActiveQuery ( tag_t  tag)
pure virtual

Disable the processing of a query (no RangeUpdate messages will be sent).

Parameters
tagidentifier of query.

Implemented in CCmpRangeManager.

virtual void ICmpRangeManager::EnableActiveQuery ( tag_t  tag)
pure virtual

Re-enable the processing of a query.

Parameters
tagidentifier of query.

Implemented in CCmpRangeManager.

virtual std::vector<entity_id_t> ICmpRangeManager::ExecuteQuery ( entity_id_t  source,
entity_pos_t  minRange,
entity_pos_t  maxRange,
std::vector< int >  owners,
int  requiredInterface 
)
pure virtual

Execute a passive query.

Parameters
sourcethe entity around which the range will be computed.
minRangenon-negative minimum distance in metres (inclusive).
maxRangenon-negative maximum distance in metres (inclusive); or -1.0 to ignore distance.
ownerslist of player IDs that matching entities may have; -1 matches entities with no owner.
requiredInterfaceif non-zero, an interface ID that matching entities must implement.
Returns
list of entities matching the query, ordered by increasing distance from the source entity.

Implemented in CCmpRangeManager.

virtual entity_pos_t ICmpRangeManager::GetElevationAdaptedRange ( CFixedVector3D  pos,
CFixedVector3D  rot,
entity_pos_t  range,
entity_pos_t  elevationBonus,
entity_pos_t  angle 
)
pure virtual

Get the average elevation over 8 points on distance range around the entity.

Parameters
idthe entity id to look around
rangethe distance to compare terrain height with
Returns
a fixed number representing the average difference. It's positive when the entity is on average higher than the terrain surrounding it.

Implemented in CCmpRangeManager.

virtual std::vector<entity_id_t> ICmpRangeManager::GetEntitiesByPlayer ( player_id_t  player)
pure virtual

Returns list of all entities for 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.

virtual u8 ICmpRangeManager::GetEntityFlagMask ( std::string  identifier)
pure virtual

Returns the mask for the specified identifier.

Implemented in CCmpRangeManager.

virtual bool ICmpRangeManager::GetLosCircular ( )
pure virtual

Returns whether the LOS is restricted to a circular map.

Implemented in CCmpRangeManager.

virtual CLosQuerier ICmpRangeManager::GetLosQuerier ( player_id_t  player)
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.

virtual bool ICmpRangeManager::GetLosRevealAll ( player_id_t  player)
pure virtual

Returns whether the whole map has been made visible to the given player.

Implemented in CCmpRangeManager.

virtual ELosVisibility ICmpRangeManager::GetLosVisibility ( CEntityHandle  ent,
player_id_t  player,
bool  forceRetainInFog = false 
)
pure virtual

Returns the visibility status of the given entity, with respect to the given player.

Returns VIS_HIDDEN if the entity doesn't exist or is not in the world. This respects the GetLosRevealAll flag. If forceRetainInFog is true, the visibility acts as if CCmpVision's RetainInFog flag were set. TODO: This is a hack to allow preview entities in FoW to return fogged instead of hidden, see http://trac.wildfiregames.com/ticket/958

Implemented in CCmpRangeManager.

virtual ELosVisibility ICmpRangeManager::GetLosVisibility ( entity_id_t  ent,
player_id_t  player,
bool  forceRetainInFog = false 
)
pure virtual

Implemented in CCmpRangeManager.

std::string ICmpRangeManager::GetLosVisibility_wrapper ( entity_id_t  ent,
player_id_t  player,
bool  forceRetainInFog 
)

GetLosVisibility wrapped for script calls.

Returns "hidden", "fogged" or "visible".

Definition at line 24 of file ICmpRangeManager.cpp.

virtual u8 ICmpRangeManager::GetPercentMapExplored ( player_id_t  player)
pure virtual

Get percent map explored statistics for specified player.

Implemented in CCmpRangeManager.

virtual u32 ICmpRangeManager::GetSharedLosMask ( player_id_t  player)
pure virtual

Returns shared LOS mask for player.

Implemented in CCmpRangeManager.

virtual std::vector<entity_id_t> ICmpRangeManager::ResetActiveQuery ( tag_t  tag)
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.

Parameters
tagidentifier of query.
Returns
list of entities matching the query, ordered by increasing distance from the source entity.

Implemented in CCmpRangeManager.

virtual void ICmpRangeManager::SetBounds ( entity_pos_t  x0,
entity_pos_t  z0,
entity_pos_t  x1,
entity_pos_t  z1,
ssize_t  vertices 
)
pure virtual

Set the bounds of the world.

Entities should not be outside the bounds (else efficiency will suffer).

Parameters
x0,z0,x1,z1Coordinates of the corners of the world
verticesNumber of terrain vertices per side

Implemented in CCmpRangeManager.

virtual void ICmpRangeManager::SetDebugOverlay ( bool  enabled)
pure virtual

Toggle the rendering of debug info.

Implemented in CCmpRangeManager.

virtual void ICmpRangeManager::SetEntityFlag ( entity_id_t  ent,
std::string  identifier,
bool  value 
)
pure virtual

Set the flag specified by the identifier to the supplied value for the entity.

Parameters
entthe entity whose flags will be modified.
identifierthe flag to be modified.
valueto which the flag will be set.

Implemented in CCmpRangeManager.

virtual void ICmpRangeManager::SetLosCircular ( bool  enabled)
pure virtual

Set the LOS to be restricted to a circular map.

Implemented in CCmpRangeManager.

virtual void ICmpRangeManager::SetLosRevealAll ( player_id_t  player,
bool  enabled 
)
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.

virtual void ICmpRangeManager::SetSharedLos ( player_id_t  player,
std::vector< player_id_t players 
)
pure virtual

Sets shared LOS data for player to the given list of players.

Implemented in CCmpRangeManager.

virtual void ICmpRangeManager::Verify ( )
pure virtual

Perform some internal consistency checks for testing/debugging.

Implemented in CCmpRangeManager.


The documentation for this class was generated from the following files: