Pyrogenesis trunk
|
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) , FLAG_DELETE_UPON_CONSTRUCTION = (1 << 5) } |
Boolean flags affecting the obstruction behaviour of a shape. More... | |
typedef u8 | flags_t |
Bitmask of EFlag values. More... | |
Public Types inherited from IComponent | |
using | AllocFunc = IComponent *(*)(const ScriptInterface &scriptInterface, JS::HandleValue ctor) |
using | DeallocFunc = void(*)(IComponent *) |
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_pos_t clearance, 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 fixed | DistanceToPoint (entity_id_t ent, entity_pos_t px, entity_pos_t pz) const =0 |
Returns the distance from the obstruction to the point (px, pz), or -1 if the entity is out of the world. More... | |
virtual fixed | MaxDistanceToPoint (entity_id_t ent, entity_pos_t px, entity_pos_t pz) const =0 |
Calculate the largest straight line distance between the entity and the point. More... | |
virtual fixed | DistanceToTarget (entity_id_t ent, entity_id_t target) const =0 |
Calculate the shortest distance between the entity and the target. More... | |
virtual fixed | MaxDistanceToTarget (entity_id_t ent, entity_id_t target) const =0 |
Calculate the largest straight line distance between the entity and the target. More... | |
virtual fixed | DistanceBetweenShapes (const ObstructionSquare &source, const ObstructionSquare &target) const =0 |
Calculate the shortest straight line distance between the source and the target. More... | |
virtual fixed | MaxDistanceBetweenShapes (const ObstructionSquare &source, const ObstructionSquare &target) const =0 |
Calculate the largest straight line distance between the source and the target. More... | |
virtual bool | IsInPointRange (entity_id_t ent, entity_pos_t px, entity_pos_t pz, entity_pos_t minRange, entity_pos_t maxRange, bool opposite) const =0 |
Check if the given entity is in range of the other point given those parameters. More... | |
virtual bool | IsInTargetRange (entity_id_t ent, entity_id_t target, entity_pos_t minRange, entity_pos_t maxRange, bool opposite) const =0 |
Check if the given entity is in range of the target given those parameters. More... | |
virtual bool | IsInTargetParabolicRange (entity_id_t ent, entity_id_t target, entity_pos_t minRange, entity_pos_t maxRange, entity_pos_t yOrigin, bool opposite) const =0 |
Check if the given entity is in parabolic range of the target given those parameters. More... | |
virtual bool | IsPointInPointRange (entity_pos_t x, entity_pos_t z, entity_pos_t px, entity_pos_t pz, entity_pos_t minRange, entity_pos_t maxRange) const =0 |
Check if the given point is in range of the other point given those parameters. More... | |
virtual bool | AreShapesInRange (const ObstructionSquare &source, const ObstructionSquare &target, entity_pos_t minRange, entity_pos_t maxRange, bool opposite) const =0 |
Check if the given shape is in range of the target shape given those parameters. 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, bool relaxClearanceForUnits) const =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) const =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 clearance, std::vector< entity_id_t > *out) const =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 void | Rasterize (Grid< NavcellData > &grid, const std::vector< PathfinderPassability > &passClasses, bool fullUpdate)=0 |
Convert the current set of shapes onto a navcell grid, for all passability classes contained in passClasses . More... | |
virtual void | UpdateInformations (GridUpdateInformation &informations)=0 |
Gets dirtiness information and resets it afterwards. 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) const =0 |
Find all the obstructions that are inside (or partially inside) the given range. More... | |
virtual void | GetStaticObstructionsInRange (const IObstructionTestFilter &filter, entity_pos_t x0, entity_pos_t z0, entity_pos_t x1, entity_pos_t z1, std::vector< ObstructionSquare > &squares) const =0 |
virtual void | GetUnitObstructionsInRange (const IObstructionTestFilter &filter, entity_pos_t x0, entity_pos_t z0, entity_pos_t x1, entity_pos_t z1, std::vector< ObstructionSquare > &squares) const =0 |
virtual void | GetStaticObstructionsOnObstruction (const ObstructionSquare &square, std::vector< entity_id_t > &out, const IObstructionTestFilter &filter) const =0 |
virtual void | GetUnitsOnObstruction (const ObstructionSquare &square, std::vector< entity_id_t > &out, const IObstructionTestFilter &filter, bool strict=false) const =0 |
Returns the entity IDs of all unit shapes that intersect the given obstruction square, filtering out using the given filter. More... | |
virtual ObstructionSquare | GetObstruction (tag_t tag) const =0 |
Get the obstruction square representing the given shape. More... | |
virtual ObstructionSquare | GetUnitShapeObstruction (entity_pos_t x, entity_pos_t z, entity_pos_t clearance) const =0 |
virtual ObstructionSquare | GetStaticShapeObstruction (entity_pos_t x, entity_pos_t z, entity_angle_t a, entity_pos_t w, entity_pos_t h) const =0 |
virtual void | SetPassabilityCircular (bool enabled)=0 |
Set the passability to be restricted to a circular map. More... | |
virtual bool | GetPassabilityCircular () const =0 |
virtual void | SetDebugOverlay (bool enabled)=0 |
Toggle the rendering of debug info. 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 () |
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 Rasterize
function approximates the current set of shapes onto a 2D grid, for use with tile-based pathfinding.
typedef u8 ICmpObstructionManager::flags_t |
Bitmask of EFlag values.
|
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 |
clearance | pathfinding clearance of the unit (works as a radius) |
flags | a set of EFlags values |
group | control group (typically the owner entity, or a formation controller entity
|
Implemented in CCmpObstructionManager.
|
pure virtual |
Check if the given shape is in range of the target shape given those parameters.
maxRange | - Can be a nonnegative decimal, ALWAYS_IN_RANGE or NEVER_IN_RANGE. |
Implemented in CCmpObstructionManager.
|
pure virtual |
Calculate the shortest straight line distance between the source and the target.
Implemented in CCmpObstructionManager.
|
pure virtual |
Returns the distance from the obstruction to the point (px, pz), or -1 if the entity is out of the world.
Implemented in CCmpObstructionManager.
|
pure virtual |
Calculate the shortest distance between the entity and the target.
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 |
Implemented in CCmpObstructionManager.
|
pure virtual |
Implemented in CCmpObstructionManager.
|
pure virtual |
Implemented in CCmpObstructionManager.
|
pure virtual |
Implemented in CCmpObstructionManager.
|
pure virtual |
Returns the entity IDs of all unit shapes that intersect the given obstruction square, filtering out using the given filter.
square | the Obstruction squre we want to compare with. |
out | output list of obstructions |
filter | filter for the obstructing units |
strict | whether to be strict in the check or more permissive (ie rasterize more or less). Default false. |
Implemented in CCmpObstructionManager.
|
pure virtual |
Check if the given entity is in range of the other point given those parameters.
maxRange | - Can be a nonnegative decimal, ALWAYS_IN_RANGE or NEVER_IN_RANGE. |
Implemented in CCmpObstructionManager.
|
pure virtual |
Check if the given entity is in parabolic range of the target given those parameters.
maxRange | - Can be a nonnegative decimal, ALWAYS_IN_RANGE or NEVER_IN_RANGE. |
Implemented in CCmpObstructionManager.
|
pure virtual |
Check if the given entity is in range of the target given those parameters.
maxRange | - Can be a nonnegative decimal, ALWAYS_IN_RANGE or NEVER_IN_RANGE. |
Implemented in CCmpObstructionManager.
|
pure virtual |
Check if the given point is in range of the other point given those parameters.
maxRange | - Can be a nonnegative decimal, ALWAYS_IN_RANGE or NEVER_IN_RANGE. |
Implemented in CCmpObstructionManager.
|
pure virtual |
Calculate the largest straight line distance between the source and the target.
Implemented in CCmpObstructionManager.
|
pure virtual |
Calculate the largest straight line distance between the entity and the point.
Implemented in CCmpObstructionManager.
|
pure virtual |
Calculate the largest straight line distance between the entity and the target.
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.
|
pure virtual |
Convert the current set of shapes onto a navcell grid, for all passability classes contained in passClasses
.
If fullUpdate
is false, the function will only go through dirty shapes. Shapes are expanded by the passClasses
clearances, by ORing their masks onto the grid
.
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 |
relaxClearanceForUnits | whether unit-unit collisions should be more permissive. |
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 |
clearance | clearance of the shape's unit |
out | if non-NULL, all colliding shapes' entities will be added to this list |
Implemented in CCmpObstructionManager.
|
pure virtual |
Gets dirtiness information and resets it afterwards.
Then it's the role of CCmpPathfinder to pass the information to other components if needed. (AIs, etc.) The return value is false if an update is unnecessary.
Implemented in CCmpObstructionManager.