A* Pathfinding Project  3.1.4
The A* Pathfinding Project for Unity 3D
 All Classes Namespaces Files Functions Variables Enumerations Properties Groups Pages
Simulator Class Reference

Local Avoidance Simulator. More...

+ Collaboration diagram for Simulator:

Classes

class  Worker
 

Public Member Functions

 Simulator (int workers, bool doubleBuffering)
 Create a new simulator.
 
IAgent AddAgent (IAgent agent)
 Add a previously removed agent to the simulation.
 
IAgent AddAgent (Vector3 position)
 Add an agent at the specified position.
 
ObstacleVertex AddObstacle (ObstacleVertex v)
 Adds a previously removed obstacle.
 
ObstacleVertex AddObstacle (Vector3[] vertices, float height)
 Adds an obstacle described by the vertices.
 
ObstacleVertex AddObstacle (Vector3[] vertices, float height, Matrix4x4 matrix)
 Adds an obstacle described by the vertices.
 
ObstacleVertex AddObstacle (Vector3 a, Vector3 b, float height)
 Adds a line obstacle with a specified height.
 
void ClearAgents ()
 Removes all agents from the simulation.
 
List< AgentGetAgents ()
 Get a list of all agents.
 
List< ObstacleVertexGetObstacles ()
 Get a list of all obstacles.
 
void RemoveAgent (IAgent agent)
 Removes a specified agent from this simulation.
 
void RemoveObstacle (ObstacleVertex v)
 Removes the obstacle identified by the vertex.
 
void Update ()
 Should be called once per frame.
 
void UpdateObstacle (ObstacleVertex obstacle, Vector3[] vertices, Matrix4x4 matrix)
 Updates the vertices of an obstacle.
 
void UpdateObstacles ()
 Rebuilds the obstacle tree at next simulation frame.
 

Properties

float DeltaTime [get]
 
float DesiredDeltaTime [get, set]
 Time in seconds between each simulation step.
 
float FrameDeltaTime [get]
 
bool Interpolation [get, set]
 Use Interpolation.
 
KDTree KDTree [get]
 KDTree for this simulation.
 
bool Multithreading [get]
 Is using multithreading.
 
float PrevDeltaTime [get]
 

Private Member Functions

 ~Simulator ()
 Terminates any worker threads.
 
void CleanObstacles ()
 
void ScheduleCleanObstacles ()
 

Private Attributes

List< Agentagents
 Agents in this simulation.
 
float deltaTime
 
float desiredDeltaTime = 0.05f
 Inverse desired simulation fps.
 
bool doCleanObstacles = false
 
bool doubleBuffering = true
 Use Double Buffering.
 
bool doUpdateObstacles = false
 
float frameDeltaTime
 
float[] frameTimeBuffer = new float[5]
 
int frameTimeBufferIndex = 0
 
bool interpolation = true
 Use Interpolation.
 
KDTree kdTree
 KDTree for this simulation.
 
float lastFrame = 0
 
float lastStep = -99999
 
List< ObstacleVertexobstacles
 Obstacles in this simulation.
 
float prevDeltaTime = 0
 
Worker[] workers
 Worker threads.
 

Detailed Description

Local Avoidance Simulator.

This class handles local avoidance simulation for a number of agents using Reciprocal Velocity Obstacles (RVO) and Optimal Reciprocal Collision Avoidance (ORCA).

This class will handle calculation of velocities from desired velocities supplied by a script. It is, however, not responsible for moving any objects in a Unity Scene. For that there are other scripts (see below).

Obstacles can be added and removed from the simulation, agents can also be added and removed at any time.

See Also
RVOSimulator RVOAgent Pathfinding.RVO.IAgent

The implementation is based on the RVO2 Library (http://gamma.cs.unc.edu/RVO2/) extended with many new features.

Constructor & Destructor Documentation

Simulator ( int  workers,
bool  doubleBuffering 
)

Create a new simulator.

Parameters
workersUse the specified number of worker threads.
When the number zero is specified, no multithreading will be used. A good number is the number of cores on the machine.
doubleBufferingUse Double Buffering for calculations. Testing done with 5000 agents and 0.1 desired delta time showed that with double buffering enabled the game ran at 50 fps for most frames, dropping to 10 fps during calculation frames. But without double buffering it ran at around 10 fps all the time.
This will let threads calculate while the game progresses instead of waiting for the calculations to finish.
Note
Will only have effect if using multithreading
See Also
Multithreading

Member Function Documentation

IAgent AddAgent ( IAgent  agent)

Add a previously removed agent to the simulation.

An agent can only be in one simulation at a time, any attempt to add an agent to two simulations or multiple times to the same simulation will result in an exception being thrown.

See Also
RemoveAgent

+ Here is the caller graph for this function:

IAgent AddAgent ( Vector3  position)

Add an agent at the specified position.

You can use the returned interface to read several parameters such as position and velocity and set for example radius and desired velocity.

See Also
RemoveAgent
ObstacleVertex AddObstacle ( ObstacleVertex  v)

Adds a previously removed obstacle.

This does not check if the obstacle is already added to the simulation, so please do not add an obstacle multiple times.

It is assumed that this is a valid obstacle.

+ Here is the caller graph for this function:

ObstacleVertex AddObstacle ( Vector3[]  vertices,
float  height 
)

Adds an obstacle described by the vertices.

See Also
RemoveObstacle
ObstacleVertex AddObstacle ( Vector3[]  vertices,
float  height,
Matrix4x4  matrix 
)

Adds an obstacle described by the vertices.

See Also
RemoveObstacle

+ Here is the call graph for this function:

ObstacleVertex AddObstacle ( Vector3  a,
Vector3  b,
float  height 
)

Adds a line obstacle with a specified height.

See Also
RemoveObstacle
List<Agent> GetAgents ( )

Get a list of all agents.

This is an internal list. I'm not going to be restrictive so you may access it since it is better for performance but please do not modify it since that can cause errors in the simulation.

Warning
Do not modify this list!
List<ObstacleVertex> GetObstacles ( )

Get a list of all obstacles.

This is a list of obstacle vertices. Each vertex is part of a doubly linked list loop forming an obstacle polygon.

Warning
Do not modify this list!
See Also
AddObstacle
RemoveObstacle
void RemoveAgent ( IAgent  agent)

Removes a specified agent from this simulation.

The agent can be added again later by using AddAgent.

See Also
AddAgent(IAgent)
ClearAgents
void RemoveObstacle ( ObstacleVertex  v)

Removes the obstacle identified by the vertex.

This must be the same vertex as the one returned by the AddObstacle call.

See Also
AddObstacle

+ Here is the caller graph for this function:

void UpdateObstacle ( ObstacleVertex  obstacle,
Vector3[]  vertices,
Matrix4x4  matrix 
)

Updates the vertices of an obstacle.

Parameters
obstacleObstacle to update
verticesNew vertices for the obstacle, must have at least the number of vertices in the original obstacle
matrixMatrix to multiply vertices with before updating obstacle

The number of vertices in an obstacle cannot be changed, existing vertices can only be moved.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void UpdateObstacles ( )

Rebuilds the obstacle tree at next simulation frame.

Add and remove obstacle functions call this automatically.

Member Data Documentation

float desiredDeltaTime = 0.05f
private

Inverse desired simulation fps.

See Also
DesiredDeltaTime
bool doubleBuffering = true
private

Use Double Buffering.

See Also
DoubleBuffering
bool interpolation = true
private

Use Interpolation.

See Also
Interpolation

Property Documentation

float DesiredDeltaTime
getset

Time in seconds between each simulation step.

This is the desired delta time, the simulation will never run at a higher fps than the rate at which the Update function is called.

bool Interpolation
getset

Use Interpolation.

If interpolation is enabled, agent positions will be interpolated on frames when no rvo calculation is done. This has a very small overhead, but usually yields much smoother looking movement.

KDTree for this simulation.

Used internally by the simulation. Please only read from this tree, do not rebuild it since that can interfere with the simulation. It is rebuilt when needed.


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