Orxonox
0.0.5 Codename: Arcturus
|
API for ScriptableController's lua-scripts. More...
Classes | |
struct | AreaHandler |
Groups everything together that is needed to handle an area enter/leave event. More... | |
struct | NearObjectHandler |
Groups everything together that is needed to handle a near-object event. More... | |
struct | NearPointHandler |
Groups everything together that is needed to handle a near-poinb event. More... | |
Public Member Functions | |
ScriptableControllerAPI (lua_State *lua, ScriptableController *controller) | |
Constructs the API with the given lua state. More... | |
~ScriptableControllerAPI () | |
Destructs the API and closes the lua state. More... | |
void | killPawn (std::string id) |
Kill a pawn. More... | |
void | moveControllableEntity (std::string id, double x, double y, double z) |
double | myTestFunction (double x, double y) |
Set the angular velocity of an object. More... | |
void | orxPrint (std::string msg) |
Print a message. More... | |
void | registerAfterTimeout (std::function< void(void)> callback, double timeout) |
Register a function that will be called after a timeout. More... | |
void | registerAtAreaEnter (std::function< void(std::string)> callback, std::string id, int x, int y, int z, int dx, int dy, int dz) |
Register a function that will be called when an object enters a cubic area. More... | |
void | registerAtAreaLeave (std::function< void(std::string)> callback, std::string id, int x, int y, int z, int dx, int dy, int dz) |
Register a function that will be called when an object leaves a cubic area. More... | |
void | registerAtNearObject (std::function< void(std::string, std::string)> callback, std::string id1, std::string id2, double distance) |
Register a function that will be called when two object are close to eachother. More... | |
void | registerAtNearPoint (std::function< void(std::string)> callback, std::string id, double x, double y, double z, double distance) |
Register a function that will be called when an object is close to a certain point. More... | |
void | registerAtPawnHit (std::function< void(std::string, std::string, double, double)> callback, std::string id) |
Register a function that will be called when a Pawn is hit. More... | |
void | registerAtPawnKilled (std::function< void(std::string)> callback, std::string id) |
Register a function that will be called when a Pawn is killed. More... | |
void | setAngularVelocity (std::string id, double x, double y, double z) |
Set the angular velocity of an object. More... | |
void | setOrientation (std::string id, double x, double y, double z, double angle) |
Set the orientation of an object. More... | |
void | setPosition (std::string id, double x, double y, double z) |
Set the position of an object. More... | |
void | setVelocity (std::string id, double x, double y, double z) |
Set the velocity of an object. More... | |
void | spawn (std::string type, std::string id) |
Spawn an object. More... | |
void | spawnTest (std::string id) |
Private Member Functions | |
void | pawnHit (std::string target_id, std::string source_id, double new_health, double new_shield) |
Called by ScriptableController when a Pawn is hit. More... | |
void | pawnKilled (std::string id, Pawn *pawn) |
Called by ScriptableController when a pawn is killed. More... | |
void | periodic (void) |
Called every 0.5s. More... | |
Private Attributes | |
std::list< AreaHandler > | areaHandlers_ |
ScriptableController * | controller_ |
lua_State * | lua_ |
std::list< NearObjectHandler > | nearObjectHandlers_ |
std::list< NearPointHandler > | nearPointHandlers_ |
std::map< std::string, std::list< std::function< void(std::string)> > > | pawnDestroyedHandlers_ |
std::map< std::string, std::list< std::function< void(std::string, std::string, double, double)> > > | pawnHitHandlers_ |
Timer | periodicTimer |
Static Private Attributes | |
static const double | periodic_interval = 0.5 |
Friends | |
class | ScriptableController |
API for ScriptableController's lua-scripts.
Defines the interface that lua can use in the scripts to communicate with orxonox.
orxonox::ScriptableControllerAPI::ScriptableControllerAPI | ( | lua_State * | lua, |
ScriptableController * | controller | ||
) |
Constructs the API with the given lua state.
lua | The lua state |
controller | The parent controller |
This will not run any scripts, it'll just make the API visible to lua.
orxonox::ScriptableControllerAPI::~ScriptableControllerAPI | ( | ) |
Destructs the API and closes the lua state.
void orxonox::ScriptableControllerAPI::killPawn | ( | std::string | id | ) |
Kill a pawn.
id | The pawn to kill |
Note: It might up to 0.5s until the pawn is actually killed.
void orxonox::ScriptableControllerAPI::moveControllableEntity | ( | std::string | id, |
double | x, | ||
double | y, | ||
double | z | ||
) |
double orxonox::ScriptableControllerAPI::myTestFunction | ( | double | x, |
double | y | ||
) |
Set the angular velocity of an object.
id | The ID of the object |
x | The rotation velocity around the x-axis |
y | The rotation velocity around the y-axis |
z | The rotation velocity around the z-axis |
void orxonox::ScriptableControllerAPI::orxPrint | ( | std::string | msg | ) |
Print a message.
msg | The message |
Use this function instead of printing from lua directly, because that will mess up the output as it is not synchronized.
|
private |
Called by ScriptableController when a pawn is killed.
id | The dead pawn |
Calls the lua callbacks associated with this event.
Called every 0.5s.
This handles things that have to be checked periodically (like area events) but doing this in every tick would be an overkill.
void orxonox::ScriptableControllerAPI::registerAfterTimeout | ( | std::function< void(void)> | callback, |
double | timeout | ||
) |
Register a function that will be called after a timeout.
callback | The function to call after the timeout expired |
timeout | The timeout in seconds |
void orxonox::ScriptableControllerAPI::registerAtAreaEnter | ( | std::function< void(std::string)> | callback, |
std::string | id, | ||
int | x, | ||
int | y, | ||
int | z, | ||
int | dx, | ||
int | dy, | ||
int | dz | ||
) |
Register a function that will be called when an object enters a cubic area.
callback | The function to call when the object entered the area |
id | The object |
x | X-coordinate of the top-left corner |
y | Y-coordinate of the top-left corner |
z | Z-coordinate of the top-left corner |
dx | Size in X-direction of the cube |
dy | Size in Y-direction of the cube |
dz | Size in Z-direction of the cube |
Note: Distances are only checked every 0.5s!
void orxonox::ScriptableControllerAPI::registerAtAreaLeave | ( | std::function< void(std::string)> | callback, |
std::string | id, | ||
int | x, | ||
int | y, | ||
int | z, | ||
int | dx, | ||
int | dy, | ||
int | dz | ||
) |
Register a function that will be called when an object leaves a cubic area.
callback | The function to call when the object left the area |
id | The object |
x | X-coordinate of the top-left corner |
y | Y-coordinate of the top-left corner |
z | Z-coordinate of the top-left corner |
dx | Size in X-direction of the cube |
dy | Size in Y-direction of the cube |
dz | Size in Z-direction of the cube |
Note: Distances are only checked every 0.5s!
void orxonox::ScriptableControllerAPI::registerAtNearObject | ( | std::function< void(std::string, std::string)> | callback, |
std::string | id1, | ||
std::string | id2, | ||
double | distance | ||
) |
Register a function that will be called when two object are close to eachother.
callback | The function to call when the objects are close enough |
id1 | The first object |
id2 | The second object |
distance | If the distance between the two objects is smaller than this value, the function is called |
Note: Distances are only checked every 0.5s!
void orxonox::ScriptableControllerAPI::registerAtNearPoint | ( | std::function< void(std::string)> | callback, |
std::string | id, | ||
double | x, | ||
double | y, | ||
double | z, | ||
double | distance | ||
) |
Register a function that will be called when an object is close to a certain point.
callback | The function to call when the object is close enough |
id | The object |
x | X-coordinate of the point |
y | Y-coordinate of the point |
z | Z-coordinate of the point |
distance | If the distance between the object and the point is smaller than this value, the function is called. |
Note: Distances are only checked every 0.5s!
void orxonox::ScriptableControllerAPI::setAngularVelocity | ( | std::string | id, |
double | x, | ||
double | y, | ||
double | z | ||
) |
Set the angular velocity of an object.
id | The ID of the object |
x | The rotation velocity around the x-axis |
y | The rotation velocity around the y-axis |
z | The rotation velocity around the z-axis |
void orxonox::ScriptableControllerAPI::setOrientation | ( | std::string | id, |
double | x, | ||
double | y, | ||
double | z, | ||
double | angle | ||
) |
Set the orientation of an object.
id | The ID of the object |
x | The x component of the axis vector |
y | The y component of the axis vector |
z | The z component of the axis vector |
angle | The angle around the axis |
To set the orientation, you have to specify the direction that the object should be facing with the vector (x, y, z) and the rotation of the object around this axis with 'angle', which has to be given in degrees, NOT radian. The vector does not have to be normalized.
void orxonox::ScriptableControllerAPI::setPosition | ( | std::string | id, |
double | x, | ||
double | y, | ||
double | z | ||
) |
Set the position of an object.
id | The ID of the object |
x | The position on the x-axis |
y | The position on the y-axis |
z | The position on the z-axis |
void orxonox::ScriptableControllerAPI::setVelocity | ( | std::string | id, |
double | x, | ||
double | y, | ||
double | z | ||
) |
Set the velocity of an object.
id | The ID of the object |
x | The velocity in x-direction |
y | The velocity in y-direction |
z | The velocity in z-direction |
The velocity is in units per second.
void orxonox::ScriptableControllerAPI::spawn | ( | std::string | type, |
std::string | id | ||
) |
Spawn an object.
type | Name of the class of the object you want to spawn |
id | The newly created ID that can be used to access this object |
IMPORTANT: Do not use this function yet, it only has minimal functionality and is not really helpful as it is.
void orxonox::ScriptableControllerAPI::spawnTest | ( | std::string | id | ) |
|
friend |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
staticprivate |
|
private |