Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Static Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | List of all members
CCmpObstructionManager Class Reference
Inheritance diagram for CCmpObstructionManager:
ICmpObstructionManager IComponent

Public Member Functions

virtual void Init (const CParamNode &paramNode)
 
virtual void Deinit ()
 
template<typename S >
void SerializeCommon (S &serialize)
 
virtual void Serialize (ISerializer &serialize)
 
virtual void Deserialize (const CParamNode &paramNode, IDeserializer &deserialize)
 
virtual void HandleMessage (const CMessage &msg, bool global)
 
virtual void SetBounds (entity_pos_t x0, entity_pos_t z0, entity_pos_t x1, entity_pos_t z1)
 Set the bounds of the world. More...
 
void ResetSubdivisions (entity_pos_t x1, entity_pos_t z1)
 
virtual tag_t AddUnitShape (entity_id_t ent, entity_pos_t x, entity_pos_t z, entity_pos_t r, flags_t flags, entity_id_t group)
 Register a unit shape. More...
 
virtual tag_t AddStaticShape (entity_id_t ent, entity_pos_t x, entity_pos_t z, entity_angle_t a, entity_pos_t w, entity_pos_t h, flags_t flags, entity_id_t group, entity_id_t group2)
 Register a static shape. More...
 
virtual ObstructionSquare GetUnitShapeObstruction (entity_pos_t x, entity_pos_t z, entity_pos_t r)
 
virtual ObstructionSquare GetStaticShapeObstruction (entity_pos_t x, entity_pos_t z, entity_angle_t a, entity_pos_t w, entity_pos_t h)
 
virtual void MoveShape (tag_t tag, entity_pos_t x, entity_pos_t z, entity_angle_t a)
 Adjust the position and angle of an existing shape. More...
 
virtual void SetUnitMovingFlag (tag_t tag, bool moving)
 Set whether a unit shape is moving or stationary. More...
 
virtual void SetUnitControlGroup (tag_t tag, entity_id_t group)
 Set the control group of a unit shape. More...
 
virtual void SetStaticControlGroup (tag_t tag, entity_id_t group, entity_id_t group2)
 Sets the control group of a static shape. More...
 
virtual void RemoveShape (tag_t tag)
 Remove an existing shape. More...
 
virtual ObstructionSquare GetObstruction (tag_t tag)
 Get the obstruction square representing the given shape. More...
 
virtual bool TestLine (const IObstructionTestFilter &filter, entity_pos_t x0, entity_pos_t z0, entity_pos_t x1, entity_pos_t z1, entity_pos_t r)
 Collision test a flat-ended thick line against the current set of shapes. More...
 
virtual bool TestStaticShape (const IObstructionTestFilter &filter, entity_pos_t x, entity_pos_t z, entity_pos_t a, entity_pos_t w, entity_pos_t h, std::vector< entity_id_t > *out)
 Collision test a static square shape against the current set of shapes. More...
 
virtual bool TestUnitShape (const IObstructionTestFilter &filter, entity_pos_t x, entity_pos_t z, entity_pos_t r, std::vector< entity_id_t > *out)
 Collision test a unit shape against the current set of registered shapes, and optionally writes a list of the colliding shapes' entities to an output list. More...
 
virtual bool Rasterise (Grid< u8 > &grid)
 Convert the current set of shapes onto a grid. More...
 
virtual void GetObstructionsInRange (const IObstructionTestFilter &filter, entity_pos_t x0, entity_pos_t z0, entity_pos_t x1, entity_pos_t z1, std::vector< ObstructionSquare > &squares)
 Find all the obstructions that are inside (or partially inside) the given range. More...
 
virtual bool FindMostImportantObstruction (const IObstructionTestFilter &filter, entity_pos_t x, entity_pos_t z, entity_pos_t r, ObstructionSquare &square)
 Find a single obstruction that blocks a unit at the given point with the given radius. More...
 
virtual void SetPassabilityCircular (bool enabled)
 Set the passability to be restricted to a circular map. More...
 
virtual void SetDebugOverlay (bool enabled)
 Toggle the rendering of debug info. More...
 
void RenderSubmit (SceneCollector &collector)
 
- Public Member Functions inherited from IComponent
virtual ~IComponent ()
 
CEntityHandle GetEntityHandle () const
 
void SetEntityHandle (CEntityHandle ent)
 
entity_id_t GetEntityId () const
 
CEntityHandle GetSystemEntity () const
 
const CSimContextGetSimContext () const
 
void SetSimContext (const CSimContext &context)
 
virtual JSClass * GetJSClass () const
 
virtual jsval GetJSInstance () const
 

Static Public Member Functions

static void ClassInit (CComponentManager &componentManager)
 
static IComponentAllocate (ScriptInterface &, jsval)
 
static void Deallocate (IComponent *cmp)
 
static std::string GetSchema ()
 
- Static Public Member Functions inherited from IComponent
static std::string GetSchema ()
 
static u8 GetSerializationVersion ()
 

Public Attributes

bool m_DebugOverlayEnabled
 
bool m_DebugOverlayDirty
 
std::vector< SOverlayLinem_DebugOverlayLines
 
SpatialSubdivision m_UnitSubdivision
 
SpatialSubdivision m_StaticSubdivision
 
std::map< u32, UnitShapem_UnitShapes
 
std::map< u32, StaticShapem_StaticShapes
 
u32 m_UnitShapeNext
 
u32 m_StaticShapeNext
 
bool m_PassabilityCircular
 
entity_pos_t m_WorldX0
 
entity_pos_t m_WorldZ0
 
entity_pos_t m_WorldX1
 
entity_pos_t m_WorldZ1
 

Private Member Functions

void MakeDirtyAll ()
 Mark all previous Rasterise()d grids as dirty, and the debug display. More...
 
void MakeDirtyDebug ()
 Mark the debug display as dirty. More...
 
void MakeDirtyStatic (flags_t flags)
 Mark all previous Rasterise()d grids as dirty, if they depend on this shape. More...
 
void MakeDirtyUnit (flags_t flags)
 Mark all previous Rasterise()d grids as dirty, if they depend on this shape. More...
 
template<typename T >
bool IsDirty (const Grid< T > &grid)
 Test whether a Rasterise()d grid is dirty and needs updating. More...
 
bool IsInWorld (entity_pos_t x, entity_pos_t z, entity_pos_t r)
 Return whether the given point is within the world bounds by at least r. More...
 
bool IsInWorld (CFixedVector2D p)
 Return whether the given point is within the world bounds. More...
 

Private Attributes

size_t m_DirtyID
 

Additional Inherited Members

- Public Types inherited from ICmpObstructionManager
enum  EFlags {
  FLAG_BLOCK_MOVEMENT = (1 << 0), FLAG_BLOCK_FOUNDATION = (1 << 1), FLAG_BLOCK_CONSTRUCTION = (1 << 2), FLAG_BLOCK_PATHFINDING = (1 << 3),
  FLAG_MOVING = (1 << 4)
}
 Boolean flags affecting the obstruction behaviour of a shape. More...
 
enum  TileObstruction { TILE_OBSTRUCTED_PATHFINDING = (1 << 0), TILE_OBSTRUCTED_FOUNDATION = (1 << 1), TILE_OUTOFBOUNDS = (1 << 2) }
 Bit-flags for Rasterise. More...
 
typedef u8 flags_t
 Bitmask of EFlag values. More...
 

Detailed Description

Definition at line 113 of file CCmpObstructionManager.cpp.

Member Function Documentation

virtual tag_t CCmpObstructionManager::AddStaticShape ( entity_id_t  ent,
entity_pos_t  x,
entity_pos_t  z,
entity_angle_t  a,
entity_pos_t  w,
entity_pos_t  h,
flags_t  flags,
entity_id_t  group,
entity_id_t  group2 
)
inlinevirtual

Register a static shape.

Parameters
ententity ID associated with this shape (or INVALID_ENTITY if none)
x,zcoordinates of center, in world space
aangle of rotation (clockwise from +Z direction)
wwidth (size along X axis)
hheight (size along Z axis)
flagsa set of EFlags values
groupprimary control group of the shape. Must be a valid control group ID.
group2Optional; secondary control group of the shape. Defaults to INVALID_ENTITY.
Returns
a valid tag for manipulating the shape
See Also
StaticShape

Implements ICmpObstructionManager.

Definition at line 265 of file CCmpObstructionManager.cpp.

virtual tag_t CCmpObstructionManager::AddUnitShape ( entity_id_t  ent,
entity_pos_t  x,
entity_pos_t  z,
entity_pos_t  r,
flags_t  flags,
entity_id_t  group 
)
inlinevirtual

Register a unit shape.

Parameters
ententity ID associated with this shape (or INVALID_ENTITY if none)
x,zcoordinates of center, in world space
rradius of circle or half the unit's width/height
flagsa set of EFlags values
groupcontrol group (typically the owner entity, or a formation controller entity
  • units ignore collisions with others in the same group)
Returns
a valid tag for manipulating the shape
See Also
UnitShape

Implements ICmpObstructionManager.

Definition at line 253 of file CCmpObstructionManager.cpp.

static IComponent* CCmpObstructionManager::Allocate ( ScriptInterface ,
jsval   
)
inlinestatic

Definition at line 121 of file CCmpObstructionManager.cpp.

static void CCmpObstructionManager::ClassInit ( CComponentManager componentManager)
inlinestatic

Definition at line 116 of file CCmpObstructionManager.cpp.

static void CCmpObstructionManager::Deallocate ( IComponent cmp)
inlinestatic

Definition at line 121 of file CCmpObstructionManager.cpp.

virtual void CCmpObstructionManager::Deinit ( )
inlinevirtual

Implements IComponent.

Definition at line 167 of file CCmpObstructionManager.cpp.

virtual void CCmpObstructionManager::Deserialize ( const CParamNode paramNode,
IDeserializer deserialize 
)
inlinevirtual

Implements IComponent.

Definition at line 198 of file CCmpObstructionManager.cpp.

bool CCmpObstructionManager::FindMostImportantObstruction ( const IObstructionTestFilter filter,
entity_pos_t  x,
entity_pos_t  z,
entity_pos_t  r,
ObstructionSquare square 
)
virtual

Find a single obstruction that blocks a unit at the given point with the given radius.

Static obstructions (buildings) are more important than unit obstructions, and obstructions that cover the given point are more important than those that only cover the point expanded by the radius.

Implements ICmpObstructionManager.

Definition at line 930 of file CCmpObstructionManager.cpp.

virtual ObstructionSquare CCmpObstructionManager::GetObstruction ( tag_t  tag)
inlinevirtual

Get the obstruction square representing the given shape.

Parameters
tagtag of shape (must be valid)

Implements ICmpObstructionManager.

Definition at line 414 of file CCmpObstructionManager.cpp.

void CCmpObstructionManager::GetObstructionsInRange ( const IObstructionTestFilter filter,
entity_pos_t  x0,
entity_pos_t  z0,
entity_pos_t  x1,
entity_pos_t  z1,
std::vector< ObstructionSquare > &  squares 
)
virtual

Find all the obstructions that are inside (or partially inside) the given range.

Parameters
filterfilter to restrict the shapes that are counted
x0X coordinate of left edge of range
z0Z coordinate of bottom edge of range
x1X coordinate of right edge of range
z1Z coordinate of top edge of range
squaresoutput list of obstructions

Implements ICmpObstructionManager.

Definition at line 879 of file CCmpObstructionManager.cpp.

static std::string CCmpObstructionManager::GetSchema ( )
inlinestatic

Definition at line 143 of file CCmpObstructionManager.cpp.

virtual ObstructionSquare CCmpObstructionManager::GetStaticShapeObstruction ( entity_pos_t  x,
entity_pos_t  z,
entity_angle_t  a,
entity_pos_t  w,
entity_pos_t  h 
)
inlinevirtual

Implements ICmpObstructionManager.

Definition at line 292 of file CCmpObstructionManager.cpp.

virtual ObstructionSquare CCmpObstructionManager::GetUnitShapeObstruction ( entity_pos_t  x,
entity_pos_t  z,
entity_pos_t  r 
)
inlinevirtual

Implements ICmpObstructionManager.

Definition at line 284 of file CCmpObstructionManager.cpp.

virtual void CCmpObstructionManager::HandleMessage ( const CMessage msg,
bool  global 
)
inlinevirtual

Reimplemented from IComponent.

Definition at line 205 of file CCmpObstructionManager.cpp.

virtual void CCmpObstructionManager::Init ( const CParamNode paramNode)
inlinevirtual

Implements IComponent.

Definition at line 148 of file CCmpObstructionManager.cpp.

template<typename T >
bool CCmpObstructionManager::IsDirty ( const Grid< T > &  grid)
inlineprivate

Test whether a Rasterise()d grid is dirty and needs updating.

Definition at line 512 of file CCmpObstructionManager.cpp.

bool CCmpObstructionManager::IsInWorld ( entity_pos_t  x,
entity_pos_t  z,
entity_pos_t  r 
)
inlineprivate

Return whether the given point is within the world bounds by at least r.

Definition at line 520 of file CCmpObstructionManager.cpp.

bool CCmpObstructionManager::IsInWorld ( CFixedVector2D  p)
inlineprivate

Return whether the given point is within the world bounds.

Definition at line 528 of file CCmpObstructionManager.cpp.

void CCmpObstructionManager::MakeDirtyAll ( )
inlineprivate

Mark all previous Rasterise()d grids as dirty, and the debug display.

Call this when the world bounds have changed.

Definition at line 469 of file CCmpObstructionManager.cpp.

void CCmpObstructionManager::MakeDirtyDebug ( )
inlineprivate

Mark the debug display as dirty.

Call this when nothing has changed except a unit's 'moving' flag.

Definition at line 479 of file CCmpObstructionManager.cpp.

void CCmpObstructionManager::MakeDirtyStatic ( flags_t  flags)
inlineprivate

Mark all previous Rasterise()d grids as dirty, if they depend on this shape.

Call this when a static shape has changed.

Definition at line 488 of file CCmpObstructionManager.cpp.

void CCmpObstructionManager::MakeDirtyUnit ( flags_t  flags)
inlineprivate

Mark all previous Rasterise()d grids as dirty, if they depend on this shape.

Call this when a unit shape has changed.

Definition at line 500 of file CCmpObstructionManager.cpp.

virtual void CCmpObstructionManager::MoveShape ( tag_t  tag,
entity_pos_t  x,
entity_pos_t  z,
entity_angle_t  a 
)
inlinevirtual

Adjust the position and angle of an existing shape.

Parameters
tagtag of shape (must be valid)
xX coordinate of center, in world space
zZ coordinate of center, in world space
aangle of rotation (clockwise from +Z direction); ignored for unit shapes

Implements ICmpObstructionManager.

Definition at line 303 of file CCmpObstructionManager.cpp.

bool CCmpObstructionManager::Rasterise ( Grid< u8 > &  grid)
virtual

Convert the current set of shapes onto a grid.

Tiles that are intersected by a pathfind-blocking shape will have TILE_OBSTRUCTED_PATHFINDING set; tiles that are intersected by a foundation-blocking shape will also have TILE_OBSTRUCTED_FOUNDATION; tiles that are outside the world bounds will also have TILE_OUTOFBOUNDS; others will be set to 0. This is very cheap if the grid has been rasterised before and the set of shapes has not changed.

Parameters
gridthe grid to be updated
Returns
true if any changes were made to the grid, false if it was already up-to-date

Implements ICmpObstructionManager.

Definition at line 725 of file CCmpObstructionManager.cpp.

virtual void CCmpObstructionManager::RemoveShape ( tag_t  tag)
inlinevirtual

Remove an existing shape.

The tag will be made invalid and must not be used after this.

Parameters
tagtag of shape (must be valid)

Implements ICmpObstructionManager.

Definition at line 387 of file CCmpObstructionManager.cpp.

void CCmpObstructionManager::RenderSubmit ( SceneCollector collector)

Definition at line 967 of file CCmpObstructionManager.cpp.

void CCmpObstructionManager::ResetSubdivisions ( entity_pos_t  x1,
entity_pos_t  z1 
)
inline

Definition at line 231 of file CCmpObstructionManager.cpp.

virtual void CCmpObstructionManager::Serialize ( ISerializer serialize)
inlinevirtual

Implements IComponent.

Definition at line 190 of file CCmpObstructionManager.cpp.

template<typename S >
void CCmpObstructionManager::SerializeCommon ( S &  serialize)
inline

Definition at line 172 of file CCmpObstructionManager.cpp.

virtual void CCmpObstructionManager::SetBounds ( entity_pos_t  x0,
entity_pos_t  z0,
entity_pos_t  x1,
entity_pos_t  z1 
)
inlinevirtual

Set the bounds of the world.

Any point outside the bounds is considered obstructed.

Parameters
x0,z0,x1,z1Coordinates of the corners of the world

Implements ICmpObstructionManager.

Definition at line 218 of file CCmpObstructionManager.cpp.

virtual void CCmpObstructionManager::SetDebugOverlay ( bool  enabled)
inlinevirtual

Toggle the rendering of debug info.

Implements ICmpObstructionManager.

Definition at line 448 of file CCmpObstructionManager.cpp.

virtual void CCmpObstructionManager::SetPassabilityCircular ( bool  enabled)
inlinevirtual

Set the passability to be restricted to a circular map.

Implements ICmpObstructionManager.

Definition at line 442 of file CCmpObstructionManager.cpp.

virtual void CCmpObstructionManager::SetStaticControlGroup ( tag_t  tag,
entity_id_t  group,
entity_id_t  group2 
)
inlinevirtual

Sets the control group of a static shape.

Parameters
tagTag of the shape to set the control group for. Must be a valid and static shape tag.
groupControl group entity ID.

Implements ICmpObstructionManager.

Definition at line 375 of file CCmpObstructionManager.cpp.

virtual void CCmpObstructionManager::SetUnitControlGroup ( tag_t  tag,
entity_id_t  group 
)
inlinevirtual

Set the control group of a unit shape.

Parameters
tagtag of shape (must be valid and a unit shape)
groupcontrol group entity ID

Implements ICmpObstructionManager.

Definition at line 364 of file CCmpObstructionManager.cpp.

virtual void CCmpObstructionManager::SetUnitMovingFlag ( tag_t  tag,
bool  moving 
)
inlinevirtual

Set whether a unit shape is moving or stationary.

Parameters
tagtag of shape (must be valid and a unit shape)
movingwhether the unit is currently moving through the world or is stationary

Implements ICmpObstructionManager.

Definition at line 348 of file CCmpObstructionManager.cpp.

bool CCmpObstructionManager::TestLine ( const IObstructionTestFilter filter,
entity_pos_t  x0,
entity_pos_t  z0,
entity_pos_t  x1,
entity_pos_t  z1,
entity_pos_t  r 
)
virtual

Collision test a flat-ended thick line against the current set of shapes.

The line caps extend by r beyond the end points. Only intersections going from outside to inside a shape are counted.

Parameters
filterfilter to restrict the shapes that are counted
x0X coordinate of line's first point
z0Z coordinate of line's first point
x1X coordinate of line's second point
z1Z coordinate of line's second point
rradius (half width) of line
Returns
true if there is a collision

Implements ICmpObstructionManager.

Definition at line 536 of file CCmpObstructionManager.cpp.

bool CCmpObstructionManager::TestStaticShape ( const IObstructionTestFilter filter,
entity_pos_t  x,
entity_pos_t  z,
entity_pos_t  a,
entity_pos_t  w,
entity_pos_t  h,
std::vector< entity_id_t > *  out 
)
virtual

Collision test a static square shape against the current set of shapes.

Parameters
filterfilter to restrict the shapes that are being tested against
xX coordinate of center
zZ coordinate of center
aangle of rotation (clockwise from +Z direction)
wwidth (size along X axis)
hheight (size along Z axis)
outif non-NULL, all colliding shapes' entities will be added to this list
Returns
true if there is a collision

Implements ICmpObstructionManager.

Definition at line 582 of file CCmpObstructionManager.cpp.

bool CCmpObstructionManager::TestUnitShape ( const IObstructionTestFilter filter,
entity_pos_t  x,
entity_pos_t  z,
entity_pos_t  r,
std::vector< entity_id_t > *  out 
)
virtual

Collision test a unit shape against the current set of registered shapes, and optionally writes a list of the colliding shapes' entities to an output list.

Parameters
filterfilter to restrict the shapes that are being tested against
xX coordinate of shape's center
zZ coordinate of shape's center
rradius of the shape (half the unit's width/height)
outif non-NULL, all colliding shapes' entities will be added to this list
Returns
true if there is a collision

Implements ICmpObstructionManager.

Definition at line 650 of file CCmpObstructionManager.cpp.

Member Data Documentation

bool CCmpObstructionManager::m_DebugOverlayDirty

Definition at line 124 of file CCmpObstructionManager.cpp.

bool CCmpObstructionManager::m_DebugOverlayEnabled

Definition at line 123 of file CCmpObstructionManager.cpp.

std::vector<SOverlayLine> CCmpObstructionManager::m_DebugOverlayLines

Definition at line 125 of file CCmpObstructionManager.cpp.

size_t CCmpObstructionManager::m_DirtyID
private

Definition at line 463 of file CCmpObstructionManager.cpp.

bool CCmpObstructionManager::m_PassabilityCircular

Definition at line 136 of file CCmpObstructionManager.cpp.

u32 CCmpObstructionManager::m_StaticShapeNext

Definition at line 134 of file CCmpObstructionManager.cpp.

std::map<u32, StaticShape> CCmpObstructionManager::m_StaticShapes

Definition at line 132 of file CCmpObstructionManager.cpp.

SpatialSubdivision CCmpObstructionManager::m_StaticSubdivision

Definition at line 128 of file CCmpObstructionManager.cpp.

u32 CCmpObstructionManager::m_UnitShapeNext

Definition at line 133 of file CCmpObstructionManager.cpp.

std::map<u32, UnitShape> CCmpObstructionManager::m_UnitShapes

Definition at line 131 of file CCmpObstructionManager.cpp.

SpatialSubdivision CCmpObstructionManager::m_UnitSubdivision

Definition at line 127 of file CCmpObstructionManager.cpp.

entity_pos_t CCmpObstructionManager::m_WorldX0

Definition at line 138 of file CCmpObstructionManager.cpp.

entity_pos_t CCmpObstructionManager::m_WorldX1

Definition at line 140 of file CCmpObstructionManager.cpp.

entity_pos_t CCmpObstructionManager::m_WorldZ0

Definition at line 139 of file CCmpObstructionManager.cpp.

entity_pos_t CCmpObstructionManager::m_WorldZ1

Definition at line 141 of file CCmpObstructionManager.cpp.


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