Pyrogenesis
13997
|
Obstruction manager: provides efficient spatial queries over objects in the world. More...
#include <ICmpObstructionManager.h>
Classes | |
struct | ObstructionSquare |
Standard representation for all types of shapes, for use with geometry processing code. More... | |
struct | tag_t |
External identifiers for shapes. More... | |
Public Types | |
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... | |
Public Member Functions | |
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 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=INVALID_ENTITY)=0 |
Register a static shape. More... | |
virtual tag_t | AddUnitShape (entity_id_t ent, entity_pos_t x, entity_pos_t z, entity_angle_t r, flags_t flags, entity_id_t group)=0 |
Register a unit shape. More... | |
virtual void | MoveShape (tag_t tag, entity_pos_t x, entity_pos_t z, entity_angle_t a)=0 |
Adjust the position and angle of an existing shape. More... | |
virtual void | SetUnitMovingFlag (tag_t tag, bool moving)=0 |
Set whether a unit shape is moving or stationary. More... | |
virtual void | SetUnitControlGroup (tag_t tag, entity_id_t group)=0 |
Set the control group of a unit shape. More... | |
virtual void | SetStaticControlGroup (tag_t tag, entity_id_t group, entity_id_t group2)=0 |
Sets the control group of a static shape. More... | |
virtual void | RemoveShape (tag_t tag)=0 |
Remove an existing 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)=0 |
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)=0 |
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)=0 |
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)=0 |
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)=0 |
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)=0 |
Find a single obstruction that blocks a unit at the given point with the given radius. More... | |
virtual ObstructionSquare | GetObstruction (tag_t tag)=0 |
Get the obstruction square representing the given shape. More... | |
virtual ObstructionSquare | GetUnitShapeObstruction (entity_pos_t x, entity_pos_t z, entity_pos_t r)=0 |
virtual ObstructionSquare | GetStaticShapeObstruction (entity_pos_t x, entity_pos_t z, entity_angle_t a, entity_pos_t w, entity_pos_t h)=0 |
virtual void | SetPassabilityCircular (bool enabled)=0 |
Set the passability to be restricted to a circular map. More... | |
virtual void | SetDebugOverlay (bool enabled)=0 |
Toggle the rendering of debug info. More... | |
![]() | |
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 JSClass * | GetJSClass () const |
virtual jsval | GetJSInstance () const |
Additional Inherited Members | |
![]() | |
static std::string | GetSchema () |
static u8 | GetSerializationVersion () |
Obstruction manager: provides efficient spatial queries over objects in the world.
The class deals with two types of shape: "static" shapes, typically representing buildings, which are rectangles with a given width and height and angle; and "unit" shapes, representing units that can move around the world, which have a radius and no rotation. (Units sometimes act as axis-aligned squares, sometimes as approximately circles, due to the algorithm used by the short pathfinder.)
Other classes (particularly ICmpObstruction) register shapes with this interface and keep them updated.
The Test
functions provide exact collision tests. The edge of a shape counts as 'inside' the shape, for the purpose of collisions. The functions accept an IObstructionTestFilter argument, which can restrict the set of shapes that are counted as collisions.
Units can be marked as either moving or stationary, which simply determines whether certain filters include or exclude them.
The Rasterise
function approximates the current set of shapes onto a 2D grid, for use with tile-based pathfinding.
Definition at line 54 of file ICmpObstructionManager.h.
typedef u8 ICmpObstructionManager::flags_t |
Bitmask of EFlag values.
Definition at line 85 of file ICmpObstructionManager.h.
Boolean flags affecting the obstruction behaviour of a shape.
Enumerator | |
---|---|
FLAG_BLOCK_MOVEMENT | |
FLAG_BLOCK_FOUNDATION | |
FLAG_BLOCK_CONSTRUCTION | |
FLAG_BLOCK_PATHFINDING | |
FLAG_MOVING |
Definition at line 73 of file ICmpObstructionManager.h.
Bit-flags for Rasterise.
Enumerator | |
---|---|
TILE_OBSTRUCTED_PATHFINDING | |
TILE_OBSTRUCTED_FOUNDATION | |
TILE_OUTOFBOUNDS |
Definition at line 210 of file ICmpObstructionManager.h.
|
pure virtual |
Register a static shape.
ent | entity ID associated with this shape (or INVALID_ENTITY if none) |
x,z | coordinates of center, in world space |
a | angle of rotation (clockwise from +Z direction) |
w | width (size along X axis) |
h | height (size along Z axis) |
flags | a set of EFlags values |
group | primary control group of the shape. Must be a valid control group ID. |
group2 | Optional; secondary control group of the shape. Defaults to INVALID_ENTITY. |
Implemented in CCmpObstructionManager.
|
pure virtual |
Register a unit shape.
ent | entity ID associated with this shape (or INVALID_ENTITY if none) |
x,z | coordinates of center, in world space |
r | radius of circle or half the unit's width/height |
flags | a set of EFlags values |
group | control group (typically the owner entity, or a formation controller entity
|
Implemented in CCmpObstructionManager.
|
pure 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.
Implemented in CCmpObstructionManager.
|
pure virtual |
Get the obstruction square representing the given shape.
tag | tag of shape (must be valid) |
Implemented in CCmpObstructionManager.
|
pure virtual |
Find all the obstructions that are inside (or partially inside) the given range.
filter | filter to restrict the shapes that are counted |
x0 | X coordinate of left edge of range |
z0 | Z coordinate of bottom edge of range |
x1 | X coordinate of right edge of range |
z1 | Z coordinate of top edge of range |
squares | output list of obstructions |
Implemented in CCmpObstructionManager.
|
pure virtual |
Implemented in CCmpObstructionManager.
|
pure virtual |
Implemented in CCmpObstructionManager.
|
pure virtual |
Adjust the position and angle of an existing shape.
tag | tag of shape (must be valid) |
x | X coordinate of center, in world space |
z | Z coordinate of center, in world space |
a | angle of rotation (clockwise from +Z direction); ignored for unit shapes |
Implemented in CCmpObstructionManager.
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.
grid | the grid to be updated |
Implemented in CCmpObstructionManager.
|
pure virtual |
Remove an existing shape.
The tag will be made invalid and must not be used after this.
tag | tag of shape (must be valid) |
Implemented in CCmpObstructionManager.
|
pure virtual |
Set the bounds of the world.
Any point outside the bounds is considered obstructed.
x0,z0,x1,z1 | Coordinates of the corners of the world |
Implemented in CCmpObstructionManager.
|
pure virtual |
Toggle the rendering of debug info.
Implemented in CCmpObstructionManager.
|
pure virtual |
Set the passability to be restricted to a circular map.
Implemented in CCmpObstructionManager.
|
pure virtual |
Sets the control group of a static shape.
tag | Tag of the shape to set the control group for. Must be a valid and static shape tag. |
group | Control group entity ID. |
Implemented in CCmpObstructionManager.
|
pure virtual |
Set the control group of a unit shape.
tag | tag of shape (must be valid and a unit shape) |
group | control group entity ID |
Implemented in CCmpObstructionManager.
|
pure virtual |
Set whether a unit shape is moving or stationary.
tag | tag of shape (must be valid and a unit shape) |
moving | whether the unit is currently moving through the world or is stationary |
Implemented in CCmpObstructionManager.
|
pure 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.
filter | filter to restrict the shapes that are counted |
x0 | X coordinate of line's first point |
z0 | Z coordinate of line's first point |
x1 | X coordinate of line's second point |
z1 | Z coordinate of line's second point |
r | radius (half width) of line |
Implemented in CCmpObstructionManager.
|
pure virtual |
Collision test a static square shape against the current set of shapes.
filter | filter to restrict the shapes that are being tested against |
x | X coordinate of center |
z | Z coordinate of center |
a | angle of rotation (clockwise from +Z direction) |
w | width (size along X axis) |
h | height (size along Z axis) |
out | if non-NULL, all colliding shapes' entities will be added to this list |
Implemented in CCmpObstructionManager.
|
pure 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.
filter | filter to restrict the shapes that are being tested against |
x | X coordinate of shape's center |
z | Z coordinate of shape's center |
r | radius of the shape (half the unit's width/height) |
out | if non-NULL, all colliding shapes' entities will be added to this list |
Implemented in CCmpObstructionManager.