[Orxonox-commit 7240] r11854 - in code/branches/ScriptableController_HS17: data/levels/scripts src/orxonox/scriptablecontroller
adamc at orxonox.net
adamc at orxonox.net
Thu Apr 12 13:40:36 CEST 2018
Author: adamc
Date: 2018-04-12 13:40:36 +0200 (Thu, 12 Apr 2018)
New Revision: 11854
Modified:
code/branches/ScriptableController_HS17/data/levels/scripts/scriptableControllerTest.lua
code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/scriptable_controller.cc
code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/scriptable_controller_api.cc
code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/scriptable_controller_api.h
Log:
scriptablecontroller testlevel fixed
Modified: code/branches/ScriptableController_HS17/data/levels/scripts/scriptableControllerTest.lua
===================================================================
--- code/branches/ScriptableController_HS17/data/levels/scripts/scriptableControllerTest.lua 2018-04-12 11:39:58 UTC (rev 11853)
+++ code/branches/ScriptableController_HS17/data/levels/scripts/scriptableControllerTest.lua 2018-04-12 11:40:36 UTC (rev 11854)
@@ -40,8 +40,12 @@
registerAtNearObject(next_station_loc, "Player", "Station", 200)
end
-orxPrint("Script started!")
+
+
+
+orxPrint("Script started! OMG ROFL LOL WTF")
+mytestfunction(3.0, 4.0)
registerAtAreaLeave(spawn_station, "Player", -300, -100, -100, 200, 200, 200)
registerAtPawnHit(rotate_faster, "Station")
registerAtPawnKilled(kill_player_after_timeout, "Station")
Modified: code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/scriptable_controller.cc
===================================================================
--- code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/scriptable_controller.cc 2018-04-12 11:39:58 UTC (rev 11853)
+++ code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/scriptable_controller.cc 2018-04-12 11:40:36 UTC (rev 11854)
@@ -21,7 +21,7 @@
lua_State *lua = luaL_newstate();
if(lua == nullptr)
{
- orxout(internal_warning) << "ScriptableController: Falied to load script " << file_path << std::endl;
+ orxout(internal_warning) << "ScriptableController: Failed to load script " << file_path << std::endl;
return LUA_ERRMEM;
}
Modified: code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/scriptable_controller_api.cc
===================================================================
--- code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/scriptable_controller_api.cc 2018-04-12 11:39:58 UTC (rev 11853)
+++ code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/scriptable_controller_api.cc 2018-04-12 11:40:36 UTC (rev 11854)
@@ -10,338 +10,354 @@
namespace orxonox
{
-const double ScriptableControllerAPI::periodic_interval = 0.5;
+ const double ScriptableControllerAPI::periodic_interval = 0.5;
-ScriptableControllerAPI::ScriptableControllerAPI(lua_State *lua, ScriptableController *controller)
-{
- this->lua_ = lua;
- this->controller_ = controller;
+ ScriptableControllerAPI::ScriptableControllerAPI(lua_State *lua, ScriptableController *controller)
+ {
+ this->lua_ = lua;
+ this->controller_ = controller;
- // Haven't found a shorter way yet to write that... We need C++17!
- LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::orxPrint)>::registerFunction<&ScriptableControllerAPI::orxPrint>(this, lua, "orxPrint");
+ // Haven't found a shorter way yet to write that... We need C++17!
+ LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::orxPrint)>::registerFunction<&ScriptableControllerAPI::orxPrint>(this, lua, "orxPrint");
- LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::registerAfterTimeout)>::registerFunction<&ScriptableControllerAPI::registerAfterTimeout>(this, lua, "registerAfterTimeout");
- LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::registerAtNearObject)>::registerFunction<&ScriptableControllerAPI::registerAtNearObject>(this, lua, "registerAtNearObject");
- LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::registerAtNearPoint)>::registerFunction<&ScriptableControllerAPI::registerAtNearPoint>(this, lua, "registerAtNearPoint");
- LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::registerAtAreaEnter)>::registerFunction<&ScriptableControllerAPI::registerAtAreaEnter>(this, lua, "registerAtAreaEnter");
- LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::registerAtAreaLeave)>::registerFunction<&ScriptableControllerAPI::registerAtAreaLeave>(this, lua, "registerAtAreaLeave");
- LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::registerAtPawnKilled)>::registerFunction<&ScriptableControllerAPI::registerAtPawnKilled>(this, lua, "registerAtPawnKilled");
- LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::registerAtPawnHit)>::registerFunction<&ScriptableControllerAPI::registerAtPawnHit>(this, lua, "registerAtPawnHit");
+ LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::registerAfterTimeout)>::registerFunction<&ScriptableControllerAPI::registerAfterTimeout>(this, lua, "registerAfterTimeout");
+ LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::registerAtNearObject)>::registerFunction<&ScriptableControllerAPI::registerAtNearObject>(this, lua, "registerAtNearObject");
+ LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::registerAtNearPoint)>::registerFunction<&ScriptableControllerAPI::registerAtNearPoint>(this, lua, "registerAtNearPoint");
+ LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::registerAtAreaEnter)>::registerFunction<&ScriptableControllerAPI::registerAtAreaEnter>(this, lua, "registerAtAreaEnter");
+ LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::registerAtAreaLeave)>::registerFunction<&ScriptableControllerAPI::registerAtAreaLeave>(this, lua, "registerAtAreaLeave");
+ LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::registerAtPawnKilled)>::registerFunction<&ScriptableControllerAPI::registerAtPawnKilled>(this, lua, "registerAtPawnKilled");
+ LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::registerAtPawnHit)>::registerFunction<&ScriptableControllerAPI::registerAtPawnHit>(this, lua, "registerAtPawnHit");
- LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::setPosition)>::registerFunction<&ScriptableControllerAPI::setPosition>(this, lua, "setPosition");
- LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::setOrientation)>::registerFunction<&ScriptableControllerAPI::setOrientation>(this, lua, "setOrientation");
- LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::setVelocity)>::registerFunction<&ScriptableControllerAPI::setVelocity>(this, lua, "setVelocity");
- LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::setAngularVelocity)>::registerFunction<&ScriptableControllerAPI::setAngularVelocity>(this, lua, "setAngularVelocity");
+ LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::setPosition)>::registerFunction<&ScriptableControllerAPI::setPosition>(this, lua, "setPosition");
+ LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::setOrientation)>::registerFunction<&ScriptableControllerAPI::setOrientation>(this, lua, "setOrientation");
+ LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::setVelocity)>::registerFunction<&ScriptableControllerAPI::setVelocity>(this, lua, "setVelocity");
+ LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::setAngularVelocity)>::registerFunction<&ScriptableControllerAPI::setAngularVelocity>(this, lua, "setAngularVelocity");
- LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::killPawn)>::registerFunction<&ScriptableControllerAPI::killPawn>(this, lua, "killPawn");
- LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::spawn)>::registerFunction<&ScriptableControllerAPI::spawn>(this, lua, "spawn");
+ LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::killPawn)>::registerFunction<&ScriptableControllerAPI::killPawn>(this, lua, "killPawn");
+ LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::spawn)>::registerFunction<&ScriptableControllerAPI::spawn>(this, lua, "spawn");
- this->periodicTimer.setTimer(ScriptableControllerAPI::periodic_interval, true, createExecutor(createFunctor(&ScriptableControllerAPI::periodic, this)), false);
-}
-ScriptableControllerAPI::~ScriptableControllerAPI()
-{
- lua_close(this->lua_);
-}
-void ScriptableControllerAPI::orxPrint(std::string msg)
-{
- orxout(user_info) << msg << std::endl;
-}
+ LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::myTestFunction)>::registerFunction<&ScriptableControllerAPI::myTestFunction>(this, lua, "mytestfunction");
-void ScriptableControllerAPI::registerAfterTimeout(std::function<void (void)> callback, double timeout)
-{
- // Kills itself when the timer fires
- new Timer(timeout, false, callback, true);
-}
-void ScriptableControllerAPI::registerAtNearObject(std::function<void (std::string, std::string)> callback, std::string id1, std::string id2, double distance)
-{
- WorldEntity *entity1 = this->controller_->getWorldEntityByID(id1);
- WorldEntity *entity2 = this->controller_->getWorldEntityByID(id2);
- if(entity1 != nullptr && entity2 != nullptr)
- this->nearObjectHandlers_.push_front(NearObjectHandler(entity1, entity2, id1, id2, distance, callback));
-}
+ this->periodicTimer.setTimer(ScriptableControllerAPI::periodic_interval, true, createExecutor(createFunctor(&ScriptableControllerAPI::periodic, this)), false);
+ }
-void ScriptableControllerAPI::registerAtNearPoint(std::function<void (std::string)> callback, std::string id, double x, double y, double z, double distance)
-{
- WorldEntity *entity = this->controller_->getWorldEntityByID(id);
+ ScriptableControllerAPI::~ScriptableControllerAPI()
+ {
+ lua_close(this->lua_);
+ }
- if(entity != nullptr)
- this->nearPointHandlers_.push_front(NearPointHandler(entity, id, x, y, z, distance, callback));
-}
+ void ScriptableControllerAPI::orxPrint(std::string msg)
+ {
+ orxout(user_info) << msg << std::endl;
+ }
-void ScriptableControllerAPI::registerAtAreaEnter(std::function<void (std::string)> callback, std::string id, int x, int y, int z, int dx, int dy, int dz)
-{
- WorldEntity *entity = this->controller_->getWorldEntityByID(id);
+ void ScriptableControllerAPI::registerAfterTimeout(std::function<void (void)> callback, double timeout)
+ {
+ // Kills itself when the timer fires
+ new Timer(timeout, false, callback, true);
+ }
- if(entity != nullptr)
- this->areaHandlers_.push_front(AreaHandler(entity, id, x, y, z, dx, dy, dz, true, callback));
-}
+ void ScriptableControllerAPI::registerAtNearObject(std::function<void (std::string, std::string)> callback, std::string id1, std::string id2, double distance)
+ {
+ WorldEntity *entity1 = this->controller_->getWorldEntityByID(id1);
+ WorldEntity *entity2 = this->controller_->getWorldEntityByID(id2);
-void ScriptableControllerAPI::registerAtAreaLeave(std::function<void (std::string)> callback, std::string id, int x, int y, int z, int dx, int dy, int dz)
-{
- WorldEntity *entity = this->controller_->getWorldEntityByID(id);
+ if(entity1 != nullptr && entity2 != nullptr)
+ this->nearObjectHandlers_.push_front(NearObjectHandler(entity1, entity2, id1, id2, distance, callback));
+ }
- if(entity != nullptr)
- this->areaHandlers_.push_front(AreaHandler(entity, id, x, y, z, dx, dy, dz, false, callback));
-}
+ void ScriptableControllerAPI::registerAtNearPoint(std::function<void (std::string)> callback, std::string id, double x, double y, double z, double distance)
+ {
+ WorldEntity *entity = this->controller_->getWorldEntityByID(id);
-void ScriptableControllerAPI::registerAtPawnKilled(std::function<void (std::string)> callback, std::string id)
-{
- this->pawnDestroyedHandlers_[id].push_back(callback);
-}
+ if(entity != nullptr)
+ this->nearPointHandlers_.push_front(NearPointHandler(entity, id, x, y, z, distance, callback));
+ }
-void ScriptableControllerAPI::registerAtPawnHit(std::function<void (std::string, std::string, double, double)> callback, std::string id)
-{
- this->pawnHitHandlers_[id].push_back(callback);
-}
+ void ScriptableControllerAPI::registerAtAreaEnter(std::function<void (std::string)> callback, std::string id, int x, int y, int z, int dx, int dy, int dz)
+ {
+ WorldEntity *entity = this->controller_->getWorldEntityByID(id);
-void ScriptableControllerAPI::killPawn(std::string id)
-{
- Pawn *pawn = this->controller_->getPawnByID(id);
- if(pawn == nullptr)
- orxout(user_warning) << "Trying to kill an unknown pawn" << std::endl;
- else
- pawn->kill();
-}
+ if(entity != nullptr)
+ this->areaHandlers_.push_front(AreaHandler(entity, id, x, y, z, dx, dy, dz, true, callback));
+ }
-void ScriptableControllerAPI::spawn(std::string type, std::string id)
-{
- if(this->controller_->getWorldEntityByID(id) != nullptr)
+ void ScriptableControllerAPI::registerAtAreaLeave(std::function<void (std::string)> callback, std::string id, int x, int y, int z, int dx, int dy, int dz)
{
- orxout(user_warning) << "Script tried to spawn an object, but an object with the given ID exists already" << std::endl;
- return;
+ WorldEntity *entity = this->controller_->getWorldEntityByID(id);
+
+ if(entity != nullptr)
+ this->areaHandlers_.push_front(AreaHandler(entity, id, x, y, z, dx, dy, dz, false, callback));
}
- Identifier *identifier = ClassByString(type);
- if(!identifier)
+ void ScriptableControllerAPI::registerAtPawnKilled(std::function<void (std::string)> callback, std::string id)
{
- orxout(user_error) << "Script tried to spawn unknown object" << std::endl;
- return;
+ this->pawnDestroyedHandlers_[id].push_back(callback);
}
- if(!identifier->isLoadable())
+ void ScriptableControllerAPI::registerAtPawnHit(std::function<void (std::string, std::string, double, double)> callback, std::string id)
{
- orxout(user_error) << "Script tried to spawn unloadable object" << std::endl;
- return;
+ this->pawnHitHandlers_[id].push_back(callback);
}
- WorldEntity *entity;
- Identifiable *obj = identifier->fabricate(this->controller_->getWorldEntityByID("Player")->getContext());
-
- if(obj->isA(ClassIdentifier<WorldEntity>::getIdentifier()))
+ void ScriptableControllerAPI::killPawn(std::string id)
{
- entity = orxonox_cast<WorldEntity*>(obj);
+ Pawn *pawn = this->controller_->getPawnByID(id);
+ if(pawn == nullptr)
+ orxout(user_warning) << "Trying to kill an unknown pawn" << std::endl;
+ else
+ pawn->kill();
}
- else if(obj->isA(ClassIdentifier<PlayerInfo>::getIdentifier()))
+
+ void ScriptableControllerAPI::spawn(std::string type, std::string id)
{
- // TODO This does not work yet because somehow the controllable entity is not set
- // yet at this stage.
-// entity = orxonox_cast<PlayerInfo*>(obj)->getControllableEntity();
- return;
- }
- else
- {
- orxout(user_warning) << "Script tried to spawn an object that is neither a WorldEntity, nor a PlayerInfo" << std::endl;
- return;
- }
+ if(this->controller_->getWorldEntityByID(id) != nullptr)
+ {
+ orxout(user_warning) << "Script tried to spawn an object, but an object with the given ID exists already" << std::endl;
+ return;
+ }
- if(entity->isA(ClassIdentifier<MobileEntity>::getIdentifier()))
- this->controller_->registerMobileEntity(id, orxonox_cast<MobileEntity*>(entity));
+ Identifier *identifier = ClassByString(type);
+ if(!identifier)
+ {
+ orxout(user_error) << "Script tried to spawn unknown object" << std::endl;
+ return;
+ }
- if(entity->isA(ClassIdentifier<Pawn>::getIdentifier()))
- this->controller_->registerPawn(id, orxonox_cast<Pawn*>(entity));
+ if(!identifier->isLoadable())
+ {
+ orxout(user_error) << "Script tried to spawn unloadable object" << std::endl;
+ return;
+ }
- this->controller_->registerWorldEntity(id, orxonox_cast<WorldEntity*>(entity));
-}
+ WorldEntity *entity;
+ Identifiable *obj = identifier->fabricate(this->controller_->getWorldEntityByID("Player")->getContext());
-void ScriptableControllerAPI::setPosition(std::string id, double x, double y, double z)
-{
- WorldEntity *entity = this->controller_->getWorldEntityByID(id);
- if(entity == nullptr)
- {
- orxout(user_warning) << "Trying to set position of an unknown object" << std::endl;
- return;
- }
+ if(obj->isA(ClassIdentifier<WorldEntity>::getIdentifier()))
+ {
+ entity = orxonox_cast<WorldEntity*>(obj);
+ }
+ else if(obj->isA(ClassIdentifier<PlayerInfo>::getIdentifier()))
+ {
+ // TODO This does not work yet because somehow the controllable entity is not set
+ // yet at this stage.
+ // entity = orxonox_cast<PlayerInfo*>(obj)->getControllableEntity();
+ return;
+ }
+ else
+ {
+ orxout(user_warning) << "Script tried to spawn an object that is neither a WorldEntity, nor a PlayerInfo" << std::endl;
+ return;
+ }
- const Vector3 &old = entity->getPosition();
+ if(entity->isA(ClassIdentifier<MobileEntity>::getIdentifier()))
+ this->controller_->registerMobileEntity(id, orxonox_cast<MobileEntity*>(entity));
- // If one of the values is NaN, don't change that value
- x = std::isnan(x) ? old.x : x;
- y = std::isnan(y) ? old.y : y;
- z = std::isnan(z) ? old.z : z;
+ if(entity->isA(ClassIdentifier<Pawn>::getIdentifier()))
+ this->controller_->registerPawn(id, orxonox_cast<Pawn*>(entity));
- entity->setPosition(x, y, z);
-}
+ this->controller_->registerWorldEntity(id, orxonox_cast<WorldEntity*>(entity));
+ }
-void ScriptableControllerAPI::setOrientation(std::string id, double x, double y, double z, double angle)
-{
- WorldEntity *entity = this->controller_->getWorldEntityByID(id);
- if(entity == nullptr)
+ void ScriptableControllerAPI::setPosition(std::string id, double x, double y, double z)
{
- orxout(user_warning) << "Trying to set orientation of an unknown object" << std::endl;
- return;
- }
+ WorldEntity *entity = this->controller_->getWorldEntityByID(id);
+ if(entity == nullptr)
+ {
+ orxout(user_warning) << "Trying to set position of an unknown object" << std::endl;
+ return;
+ }
- Vector3 old_axis;
- Degree old_angle;
+ const Vector3 &old = entity->getPosition();
- entity->getOrientation().ToAngleAxis(old_angle, old_axis);
+ // If one of the values is NaN, don't change that value
+ x = std::isnan(x) ? old.x : x;
+ y = std::isnan(y) ? old.y : y;
+ z = std::isnan(z) ? old.z : z;
- // If one of the values is NaN, don't change that value
- x = std::isnan(x) ? old_axis.x : x;
- y = std::isnan(y) ? old_axis.y : y;
- z = std::isnan(z) ? old_axis.z : z;
- angle = std::isnan(x) ? old_angle.valueDegrees() : angle;
+ entity->setPosition(x, y, z);
+ }
+ void ScriptableControllerAPI::setOrientation(std::string id, double x, double y, double z, double angle)
+ {
+ WorldEntity *entity = this->controller_->getWorldEntityByID(id);
+ if(entity == nullptr)
+ {
+ orxout(user_warning) << "Trying to set orientation of an unknown object" << std::endl;
+ return;
+ }
- entity->setOrientation(Vector3(x, y, z), Degree(angle));
-}
+ Vector3 old_axis;
+ Degree old_angle;
-void ScriptableControllerAPI::setVelocity(std::string id, double x, double y, double z)
-{
- MobileEntity *entity = this->controller_->getMobileEntityByID(id);
- if(entity == nullptr)
- {
- orxout(user_warning) << "Trying to set velocity of an unknown object" << std::endl;
- return;
- }
+ entity->getOrientation().ToAngleAxis(old_angle, old_axis);
- const Vector3 &old = entity->getVelocity();
+ // If one of the values is NaN, don't change that value
+ x = std::isnan(x) ? old_axis.x : x;
+ y = std::isnan(y) ? old_axis.y : y;
+ z = std::isnan(z) ? old_axis.z : z;
+ angle = std::isnan(x) ? old_angle.valueDegrees() : angle;
- // If one of the values is NaN, don't change that value
- x = std::isnan(x) ? old.x : x;
- y = std::isnan(y) ? old.y : y;
- z = std::isnan(z) ? old.z : z;
- entity->setVelocity(x, y, z);
-}
+ entity->setOrientation(Vector3(x, y, z), Degree(angle));
+ }
-void ScriptableControllerAPI::setAngularVelocity(std::string id, double x, double y, double z)
-{
- MobileEntity *entity = this->controller_->getMobileEntityByID(id);
- if(entity == nullptr)
+ void ScriptableControllerAPI::setVelocity(std::string id, double x, double y, double z)
{
- orxout(user_warning) << "Trying to set angular velocity of an unknown object" << std::endl;
- return;
- }
+ MobileEntity *entity = this->controller_->getMobileEntityByID(id);
+ if(entity == nullptr)
+ {
+ orxout(user_warning) << "Trying to set velocity of an unknown object" << std::endl;
+ return;
+ }
- const Vector3 &old = entity->getAngularVelocity();
+ const Vector3 &old = entity->getVelocity();
- // If one of the values is NaN, don't change that value
- x = std::isnan(x) ? old.x : x;
- y = std::isnan(y) ? old.y : y;
- z = std::isnan(z) ? old.z : z;
+ // If one of the values is NaN, don't change that value
+ x = std::isnan(x) ? old.x : x;
+ y = std::isnan(y) ? old.y : y;
+ z = std::isnan(z) ? old.z : z;
- entity->setAngularVelocity(x, y, z);
-}
+ entity->setVelocity(x, y, z);
+ }
-void ScriptableControllerAPI::pawnKilled(std::string id, Pawn *pawn)
-{
- for(auto callback : this->pawnDestroyedHandlers_[id])
- callback(id);
+ void ScriptableControllerAPI::setAngularVelocity(std::string id, double x, double y, double z)
+ {
+ MobileEntity *entity = this->controller_->getMobileEntityByID(id);
+ if(entity == nullptr)
+ {
+ orxout(user_warning) << "Trying to set angular velocity of an unknown object" << std::endl;
+ return;
+ }
- this->pawnDestroyedHandlers_.erase(id);
+ const Vector3 &old = entity->getAngularVelocity();
- // We need to delete those handlers as well, they're no longer valid
- auto near_obj_handler = this->nearObjectHandlers_.begin();
- while(near_obj_handler != this->nearObjectHandlers_.end())
- {
- if(near_obj_handler->entity1_ == pawn || near_obj_handler->entity2_ == pawn)
- near_obj_handler = this->nearObjectHandlers_.erase(near_obj_handler);
- else
- near_obj_handler++;
- }
+ // If one of the values is NaN, don't change that value
+ x = std::isnan(x) ? old.x : x;
+ y = std::isnan(y) ? old.y : y;
+ z = std::isnan(z) ? old.z : z;
- auto near_point_handler = this->nearPointHandlers_.begin();
- while(near_point_handler != this->nearPointHandlers_.end())
- {
- if(near_point_handler->entity_ == pawn)
- near_point_handler = this->nearPointHandlers_.erase(near_point_handler);
- else
- near_point_handler++;
+ entity->setAngularVelocity(x, y, z);
}
- auto area_handler = this->areaHandlers_.begin();
- while(area_handler != this->areaHandlers_.end())
+ void ScriptableControllerAPI::pawnKilled(std::string id, Pawn *pawn)
{
- if(area_handler->entity_ == pawn)
- area_handler = this->areaHandlers_.erase(area_handler);
- else
- area_handler++;
- }
-}
+ for(auto callback : this->pawnDestroyedHandlers_[id])
+ callback(id);
-void ScriptableControllerAPI::pawnHit(std::string target_id, std::string source_id, double new_health, double new_shield)
-{
- for(auto callback : this->pawnHitHandlers_[target_id])
- callback(target_id, source_id, new_health, new_shield);
-}
+ this->pawnDestroyedHandlers_.erase(id);
-void ScriptableControllerAPI::periodic()
-{
- // Near object
- auto near_obj_handler = this->nearObjectHandlers_.begin();
- while(near_obj_handler != this->nearObjectHandlers_.end())
- {
- if((near_obj_handler->entity1_->getPosition() - near_obj_handler->entity2_->getPosition()).length() < near_obj_handler->distance_)
+ // We need to delete those handlers as well, they're no longer valid
+ auto near_obj_handler = this->nearObjectHandlers_.begin();
+ while(near_obj_handler != this->nearObjectHandlers_.end())
{
- near_obj_handler->callback_(near_obj_handler->id1_, near_obj_handler->id2_);
- near_obj_handler = this->nearObjectHandlers_.erase(near_obj_handler);
+ if(near_obj_handler->entity1_ == pawn || near_obj_handler->entity2_ == pawn)
+ near_obj_handler = this->nearObjectHandlers_.erase(near_obj_handler);
+ else
+ near_obj_handler++;
}
- else
+
+ auto near_point_handler = this->nearPointHandlers_.begin();
+ while(near_point_handler != this->nearPointHandlers_.end())
{
- near_obj_handler++;
+ if(near_point_handler->entity_ == pawn)
+ near_point_handler = this->nearPointHandlers_.erase(near_point_handler);
+ else
+ near_point_handler++;
}
- }
- // Near point
- auto near_point_handler = this->nearPointHandlers_.begin();
- while(near_point_handler != this->nearPointHandlers_.end())
- {
- if((near_point_handler->entity_->getPosition() - near_point_handler->point_).length() < near_point_handler->distance_)
+ auto area_handler = this->areaHandlers_.begin();
+ while(area_handler != this->areaHandlers_.end())
{
- near_point_handler->callback_(near_point_handler->id_);
- near_point_handler = this->nearPointHandlers_.erase(near_point_handler);
+ if(area_handler->entity_ == pawn)
+ area_handler = this->areaHandlers_.erase(area_handler);
+ else
+ area_handler++;
}
- else
- {
- near_point_handler++;
- }
}
- // Areas
- auto area_handler = this->areaHandlers_.begin();
- while(area_handler != this->areaHandlers_.end())
+ void ScriptableControllerAPI::pawnHit(std::string target_id, std::string source_id, double new_health, double new_shield)
{
- if(area_handler->entity_->getPosition() > area_handler->start_point_ &&
- area_handler->entity_->getPosition() < area_handler->end_point_)
+ for(auto callback : this->pawnHitHandlers_[target_id])
+ callback(target_id, source_id, new_health, new_shield);
+ }
+
+ void ScriptableControllerAPI::periodic()
+ {
+ // Near object
+ auto near_obj_handler = this->nearObjectHandlers_.begin();
+ while(near_obj_handler != this->nearObjectHandlers_.end())
{
- if(area_handler->atEnter_)
+ if((near_obj_handler->entity1_->getPosition() - near_obj_handler->entity2_->getPosition()).length() < near_obj_handler->distance_)
{
- area_handler->callback_(area_handler->id_);
- area_handler = this->areaHandlers_.erase(area_handler);
+ near_obj_handler->callback_(near_obj_handler->id1_, near_obj_handler->id2_);
+ near_obj_handler = this->nearObjectHandlers_.erase(near_obj_handler);
}
else
{
- area_handler++;
+ near_obj_handler++;
}
}
- else
+
+ // Near point
+ auto near_point_handler = this->nearPointHandlers_.begin();
+ while(near_point_handler != this->nearPointHandlers_.end())
{
- if(!area_handler->atEnter_)
+ if((near_point_handler->entity_->getPosition() - near_point_handler->point_).length() < near_point_handler->distance_)
{
- area_handler->callback_(area_handler->id_);
- area_handler = this->areaHandlers_.erase(area_handler);
+ near_point_handler->callback_(near_point_handler->id_);
+ near_point_handler = this->nearPointHandlers_.erase(near_point_handler);
}
else
{
- area_handler++;
+ near_point_handler++;
}
}
+
+ // Areas
+ auto area_handler = this->areaHandlers_.begin();
+ while(area_handler != this->areaHandlers_.end())
+ {
+ if(area_handler->entity_->getPosition() > area_handler->start_point_ &&
+ area_handler->entity_->getPosition() < area_handler->end_point_)
+ {
+ if(area_handler->atEnter_)
+ {
+ area_handler->callback_(area_handler->id_);
+ area_handler = this->areaHandlers_.erase(area_handler);
+ }
+ else
+ {
+ area_handler++;
+ }
+ }
+ else
+ {
+ if(!area_handler->atEnter_)
+ {
+ area_handler->callback_(area_handler->id_);
+ area_handler = this->areaHandlers_.erase(area_handler);
+ }
+ else
+ {
+ area_handler++;
+ }
+ }
+ }
+
}
-}
+
+ //// TESTTESTTESTTESTTESTTEST
+ double ScriptableControllerAPI::myTestFunction(double x, double y)
+ {
+ double z = x + y;
+ orxout(user_info) << "Result = " << z << endl;
+ return z;
+ }
+
}
Modified: code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/scriptable_controller_api.h
===================================================================
--- code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/scriptable_controller_api.h 2018-04-12 11:39:58 UTC (rev 11853)
+++ code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/scriptable_controller_api.h 2018-04-12 11:40:36 UTC (rev 11854)
@@ -195,6 +195,16 @@
*/
void setAngularVelocity(std::string id, double x, double y, double z);
+
+ /**
+ * @brief Set the angular velocity of an object
+ * @param id The ID of the object
+ * @param x The rotation velocity around the x-axis
+ * @param y The rotation velocity around the y-axis
+ * @param z The rotation velocity around the z-axis
+ */
+ double myTestFunction(double x, double y);
+
// ### API END ################################################################
private:
More information about the Orxonox-commit
mailing list