[Orxonox-commit 6962] r11583 - in code/branches/ScriptableController_HS17/src: libraries/core orxonox orxonox/gamestates orxonox/infos orxonox/scriptablecontroller orxonox/worldentities

kohlia at orxonox.net kohlia at orxonox.net
Mon Nov 20 16:48:03 CET 2017


Author: kohlia
Date: 2017-11-20 16:48:03 +0100 (Mon, 20 Nov 2017)
New Revision: 11583

Modified:
   code/branches/ScriptableController_HS17/src/libraries/core/BaseObject.h
   code/branches/ScriptableController_HS17/src/orxonox/Level.cc
   code/branches/ScriptableController_HS17/src/orxonox/Level.h
   code/branches/ScriptableController_HS17/src/orxonox/gamestates/GSLevel.cc
   code/branches/ScriptableController_HS17/src/orxonox/infos/GametypeInfo.cc
   code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/scriptable_controller.cc
   code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/scriptable_controller.h
   code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/scriptable_controller_api.cc
   code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/scriptable_controller_api.h
   code/branches/ScriptableController_HS17/src/orxonox/worldentities/ControllableEntity.cc
   code/branches/ScriptableController_HS17/src/orxonox/worldentities/ControllableEntity.h
   code/branches/ScriptableController_HS17/src/orxonox/worldentities/MobileEntity.cc
   code/branches/ScriptableController_HS17/src/orxonox/worldentities/WorldEntity.cc
   code/branches/ScriptableController_HS17/src/orxonox/worldentities/WorldEntity.h
Log:
Near object, near point and at area work!



Modified: code/branches/ScriptableController_HS17/src/libraries/core/BaseObject.h
===================================================================
--- code/branches/ScriptableController_HS17/src/libraries/core/BaseObject.h	2017-11-20 15:30:24 UTC (rev 11582)
+++ code/branches/ScriptableController_HS17/src/libraries/core/BaseObject.h	2017-11-20 15:48:03 UTC (rev 11583)
@@ -192,7 +192,6 @@
 
             static void loadAllEventStates(Element& xmlelement, XMLPort::Mode mode, BaseObject* object, Identifier* identifier);
 
-            virtual void registerToScriptableController(ScriptableController *controller) {}
 
         protected:
             void addEventState(const std::string& name, EventState* container);

Modified: code/branches/ScriptableController_HS17/src/orxonox/Level.cc
===================================================================
--- code/branches/ScriptableController_HS17/src/orxonox/Level.cc	2017-11-20 15:30:24 UTC (rev 11582)
+++ code/branches/ScriptableController_HS17/src/orxonox/Level.cc	2017-11-20 15:48:03 UTC (rev 11583)
@@ -171,7 +171,6 @@
     void Level::addObject(BaseObject* object)
     {
         this->objects_.push_back(object);
-        object->registerToScriptableController(this->controller_.get());
     }
 
     BaseObject* Level::getObject(unsigned int index) const
@@ -207,12 +206,6 @@
     {
         orxout(internal_info) << "player entered level (id: " << player->getClientID() << ", name: " << player->getName() << ')' << endl;
         player->switchGametype(this->getGametype());
-
-        if(player->isHumanPlayer() && player->isLocalPlayer())
-        {
-            this->getScriptableController()->setPlayer(player);
-            this->controller_->runScript(this->level_script_);
-        }
     }
 
     void Level::playerLeft(PlayerInfo* player)

Modified: code/branches/ScriptableController_HS17/src/orxonox/Level.h
===================================================================
--- code/branches/ScriptableController_HS17/src/orxonox/Level.h	2017-11-20 15:30:24 UTC (rev 11582)
+++ code/branches/ScriptableController_HS17/src/orxonox/Level.h	2017-11-20 15:48:03 UTC (rev 11583)
@@ -59,7 +59,10 @@
             inline ScriptableController *getScriptableController(void)
                 { return this->controller_.get(); }
 
+            inline const std::string &getScript(void)
+                { return this->level_script_; }
 
+
         private:
             void registerVariables();
             void addObject(BaseObject* object);

Modified: code/branches/ScriptableController_HS17/src/orxonox/gamestates/GSLevel.cc
===================================================================
--- code/branches/ScriptableController_HS17/src/orxonox/gamestates/GSLevel.cc	2017-11-20 15:30:24 UTC (rev 11582)
+++ code/branches/ScriptableController_HS17/src/orxonox/gamestates/GSLevel.cc	2017-11-20 15:48:03 UTC (rev 11583)
@@ -99,6 +99,7 @@
 
         if (GameMode::isMaster())
         {
+            orxout(user_info) << "Load level" << std::endl;
             this->loadLevel();
         }
 
@@ -112,6 +113,7 @@
 
             ModifyConsoleCommand(__CC_startMainMenu_name).activate();
         }
+        orxout(user_info) << "All loaded" << std::endl;
 
         if (GameMode::isStandalone())
         {

Modified: code/branches/ScriptableController_HS17/src/orxonox/infos/GametypeInfo.cc
===================================================================
--- code/branches/ScriptableController_HS17/src/orxonox/infos/GametypeInfo.cc	2017-11-20 15:30:24 UTC (rev 11582)
+++ code/branches/ScriptableController_HS17/src/orxonox/infos/GametypeInfo.cc	2017-11-20 15:48:03 UTC (rev 11583)
@@ -42,6 +42,8 @@
 #include "controllers/HumanController.h"
 #include "interfaces/GametypeMessageListener.h"
 #include "interfaces/NotificationListener.h"
+#include "scriptablecontroller/scriptable_controller.h"
+#include "Level.h"
 
 #include "PlayerInfo.h"
 
@@ -309,9 +311,14 @@
         if(GameMode::isMaster())
         {
             if(this->hasStarted() && !this->hasEnded())
-
                 this->setSpawnedHelper(player, true);
         }
+
+        if(player->isHumanPlayer() && player->isLocalPlayer())
+        {
+            this->getLevel()->getScriptableController()->setPlayer(player);
+            this-getLevel()->getScriptableController()->runScript(this->getLevel()->getScript());
+        }
     }
 
     /**

Modified: code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/scriptable_controller.cc
===================================================================
--- code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/scriptable_controller.cc	2017-11-20 15:30:24 UTC (rev 11582)
+++ code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/scriptable_controller.cc	2017-11-20 15:48:03 UTC (rev 11583)
@@ -2,6 +2,7 @@
 #include "scriptable_controller.h"
 #include "luatb.h"
 #include "infos/PlayerInfo.h"
+#include "core/command/Executor.h"
 
 namespace orxonox
 {
@@ -11,6 +12,10 @@
 {
     int ret;
 
+    // Not having a script specified at all is not an error
+    if(file_path.empty())
+        return 0;
+
     // Create a lua object
     lua_State *lua = luaL_newstate();
     if(lua == nullptr)
@@ -44,8 +49,6 @@
     // Remeber the api
     this->apis_.push_back(std::unique_ptr<ScriptableControllerAPI>(api));
 
-    // Only the caller knows, when the end-of-life of the script is reached,
-    // so we give him control over when to destroy it.
     return 0;
 }
 
@@ -54,83 +57,34 @@
     this->player_ = player;
 }
 
-void ScriptableController::registerWorldEntity(int id, WorldEntity *obj)
+void ScriptableController::registerWorldEntity(std::string id, WorldEntity *entity)
 {
-    orxout(user_info) << "WorldEntity registered (id: " << id << ")" << std::endl;
-    this->worldEntities_[id] = obj;
+    this->worldEntities_[id] = entity;
 }
 
-void ScriptableController::registerControllableEntity(int id, ControllableEntity *obj)
+void ScriptableController::registerControllableEntity(std::string id, ControllableEntity *entity)
 {
-    orxout(user_info) << "ControllableEntity registered (id: " << id << ")" << std::endl;
-    this->worldEntities_[id] = obj;
+    this->worldEntities_[id] = entity;
 }
 
-WorldEntity *ScriptableController::getWorldEntityByID(int id) const
+WorldEntity *ScriptableController::getWorldEntityByID(std::string id) const
 {
-    if(id == 0)
+    if(id == "player" || id == "Player" || id == "PLAYER")
         return this->player_->getControllableEntity();
 
-    auto obj = this->worldEntities_.find(id);
-    return obj != this->worldEntities_.end() ? obj->second : nullptr;
+    auto entity = this->worldEntities_.find(id);
+    return entity != this->worldEntities_.end() ? entity->second : nullptr;
 }
 
-ControllableEntity *ScriptableController::getControllableEntityByID(int id) const
+ControllableEntity *ScriptableController::getControllableEntityByID(std::string id) const
 {
-    if(id == 0)
+    if(id == "player" || id == "Player" || id == "PLAYER")
         return this->player_->getControllableEntity();
 
-    auto obj = this->controllabelEntities_.find(id);
-    return obj != this->controllabelEntities_.end() ? obj->second : nullptr;
+    auto entity = this->controllabelEntities_.find(id);
+    return entity != this->controllabelEntities_.end() ? entity->second : nullptr;
 }
 
-void ScriptableController::addNearObjectHandler(int obj1, int obj2, double distance, std::function<void (int,int)> callback)
-{
-    orxout(user_info) << "NearObject registering (id 1: " << obj1 << ", id 2: " << obj2 << ")" << std::endl;
-
-    WorldEntity *entity1 = this->getWorldEntityByID(obj1);
-    WorldEntity *entity2 = this->getWorldEntityByID(obj2);
-
-    NearObjectHandler *handler1 = new NearObjectHandler(entity2, distance, callback);
-    NearObjectHandler *handler2 = new NearObjectHandler(entity1, distance, callback);
-
-    this->nearObjectHandlers_[entity1].push_front(std::unique_ptr<NearObjectHandler>(handler1));
-    this->nearObjectHandlers_[entity2].push_front(std::unique_ptr<NearObjectHandler>(handler2));
-
-    handler1->otherHandler_ = this->nearObjectHandlers_[entity2].begin();
-    handler2->otherHandler_ = this->nearObjectHandlers_[entity1].begin();
-}
-
-void ScriptableController::objectMoved(WorldEntity *obj)
-{
-    // Temp
-    return;
-
-    auto &nearObjectHandlers = this->nearObjectHandlers_[obj];
-    auto handler = nearObjectHandlers.begin();
-    while(handler != nearObjectHandlers.end())
-    {
-        WorldEntity *other = (*handler)->otherObject_;
-        if((obj->getPosition() - other->getPosition()).length() < (*handler)->distance_)
-        {
-            (*handler)->callback_(obj->getID(), other->getID());
-
-            auto otherHandler = (*handler)->otherHandler_;
-            handler = nearObjectHandlers.erase(handler);
-            if(nearObjectHandlers.empty())
-                this->nearObjectHandlers_.erase(obj);
-
-            this->nearObjectHandlers_[other].erase(otherHandler);
-            if(this->nearObjectHandlers_[other].empty())
-                this->nearObjectHandlers_.erase(other);
-        }
-        else
-        {
-            handler++;
-        }
-    }
-}
-
 void ScriptableController::printLuaError(lua_State *lua)
 {
     // The error message is on top of the stack.

Modified: code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/scriptable_controller.h
===================================================================
--- code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/scriptable_controller.h	2017-11-20 15:30:24 UTC (rev 11582)
+++ code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/scriptable_controller.h	2017-11-20 15:48:03 UTC (rev 11583)
@@ -10,6 +10,7 @@
 #include "core/CoreIncludes.h"
 #include "worldentities/WorldEntity.h"
 #include "worldentities/ControllableEntity.h"
+#include "tools/Timer.h"
 
 struct lua_State;
 
@@ -19,39 +20,21 @@
 class ScriptableController
 {
 public:
-    struct NearObjectHandler
-    {
-        NearObjectHandler(WorldEntity *otherObject, double distance, std::function<void (int, int)> callback)
-            : otherObject_(otherObject), distance_(distance), callback_(callback)
-        {}
-
-        WorldEntity *otherObject_;
-        double distance_;
-        std::function<void (int, int)> callback_;
-        std::list<std::unique_ptr<NearObjectHandler> >::iterator otherHandler_;
-    };
-
     int runScript(const std::string &file_path);
 
     void setPlayer(PlayerInfo *player);
-    void registerWorldEntity(int id, WorldEntity *obj);
-    void registerControllableEntity(int id, ControllableEntity *obj);
+    void registerWorldEntity(std::string id, WorldEntity *entity);
+    void registerControllableEntity(std::string id, ControllableEntity *entity);
 
-    WorldEntity *getWorldEntityByID(int id) const;
-    ControllableEntity *getControllableEntityByID(int id) const;
+    WorldEntity *getWorldEntityByID(std::string id) const;
+    ControllableEntity *getControllableEntityByID(std::string id) const;
 
-    void addNearObjectHandler(int obj1, int obj2, double distance, std::function<void (int, int)> callback);
-
-    void objectMoved(WorldEntity *obj);
-
 private:
     std::list<std::unique_ptr<ScriptableControllerAPI> > apis_;
     PlayerInfo *player_;
-    std::map<int, WorldEntity*> worldEntities_;
-    std::map<int, ControllableEntity*> controllabelEntities_;
+    std::map<std::string, WorldEntity*> worldEntities_;
+    std::map<std::string, ControllableEntity*> controllabelEntities_;
 
-    std::map<WorldEntity*, std::list<std::unique_ptr<NearObjectHandler> > > nearObjectHandlers_;
-
     void printLuaError(lua_State *lua);
 };
 

Modified: code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/scriptable_controller_api.cc
===================================================================
--- code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/scriptable_controller_api.cc	2017-11-20 15:30:24 UTC (rev 11582)
+++ code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/scriptable_controller_api.cc	2017-11-20 15:48:03 UTC (rev 11583)
@@ -16,10 +16,14 @@
     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::registerAtObjectDestroyed)>::registerFunction<&ScriptableControllerAPI::registerAtObjectDestroyed>(this, lua, "registerAtObjectDestroyed");
-    LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::registerAtPickup)>::registerFunction<&ScriptableControllerAPI::registerAtPickup>(this, lua, "registerAtPickup");
+//    LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::registerAtObjectDestroyed)>::registerFunction<&ScriptableControllerAPI::registerAtObjectDestroyed>(this, lua, "registerAtObjectDestroyed");
+//    LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::registerAtPickup)>::registerFunction<&ScriptableControllerAPI::registerAtPickup>(this, lua, "registerAtPickup");
+
+    // Checks for area enter, area leave and near object events
+    this->areaCheckTimer.setTimer(0.5, true, createExecutor(createFunctor(&ScriptableControllerAPI::checkAreas, this)), false);
 }
 
 ScriptableControllerAPI::~ScriptableControllerAPI()
@@ -38,29 +42,101 @@
     new Timer(timeout, false, callback, true);
 }
 
-int ScriptableControllerAPI::registerAtNearObject(std::function<void (int, int)> callback, int obj1, int obj2, double distance)
+void ScriptableControllerAPI::registerAtNearObject(std::function<void (std::string, std::string)> callback, std::string id1, std::string id2, double distance)
 {
-    //this->controller_->addNearObjectHandler(obj1, obj1, distance, callback);
+    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));
 }
 
-int ScriptableControllerAPI::registerAtAreaEnter(std::function<void (int)> callback, int obj, int x, int y, int z, int dx, int dy, int dz)
+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);
 
+    if(entity != nullptr)
+        this->nearPointHandlers_.push_front(NearPointHandler(entity, id, x, y, z, distance, callback));
 }
 
-int ScriptableControllerAPI::registerAtAreaLeave(std::function<void (int)> callback, int obj, int x, int y, int z, int dx, int dy, int dz)
+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);
 
+    if(entity != nullptr)
+        this->areaHandlers_.push_front(AreaHandler(entity, id, x, y, z, dx, dy, dz, true, callback));
 }
 
-int ScriptableControllerAPI::registerAtObjectDestroyed(std::function<void (int)> callback, int obj)
+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(entity != nullptr)
+        this->areaHandlers_.push_front(AreaHandler(entity, id, x, y, z, dx, dy, dz, false, callback));
 }
 
-int ScriptableControllerAPI::registerAtPickup(std::function<void (int)> callback, int pickup_id)
+void ScriptableControllerAPI::checkAreas()
 {
+    // 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_)
+        {
+            near_obj_handler->callback_(near_obj_handler->id1_, near_obj_handler->id2_);
+            near_obj_handler = this->nearObjectHandlers_.erase(near_obj_handler);
+        }
+        else
+        {
+            near_obj_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_)
+        {
+            near_point_handler->callback_(near_point_handler->id_);
+            near_point_handler = this->nearPointHandlers_.erase(near_point_handler);
+        }
+        else
+        {
+            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++;
+            }
+        }
+    }
 }
 
 }

Modified: code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/scriptable_controller_api.h
===================================================================
--- code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/scriptable_controller_api.h	2017-11-20 15:30:24 UTC (rev 11582)
+++ code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/scriptable_controller_api.h	2017-11-20 15:48:03 UTC (rev 11583)
@@ -3,9 +3,9 @@
 
 #include <functional>
 #include "core/CoreIncludes.h"
+#include "tools/Timer.h"
+#include "OgreVector3.h"
 
-// TODO Is pos int or double?
-
 struct lua_State;
 
 namespace orxonox
@@ -12,6 +12,7 @@
 {
 
 class ScriptableController;
+class WorldEntity;
 
 class ScriptableControllerAPI
 {
@@ -23,19 +24,67 @@
 
     void orxPrint(std::string msg);
     void registerAfterTimeout(std::function<void (void)> callback, double timeout);
-    int registerAtNearObject(std::function<void(int, int)> callback, int obj1, int obj2, double distance);
-    int registerAtAreaEnter(std::function<void (int)> callback, int obj, int x, int y, int z, int dx, int dy, int dz);
-    int registerAtAreaLeave(std::function<void (int)> callback, int obj, int x, int y, int z, int dx, int dy, int dz);
-    int registerAtObjectDestroyed(std::function<void (int)> callback, int obj);
-    int registerAtPickup(std::function<void (int)> callback, int pickup_id);
 
-    int destroyObject(int obj);
-    void removeObject(int obj);
-    int setObjectPosition(int obj, double x, double y, double z);
+    void registerAtNearObject(std::function<void(std::string, std::string)> callback, std::string id1, std::string id2, double distance);
+    void registerAtNearPoint(std::function<void (std::string)> callback, std::string id, double x, double y, double z, double distance);
+    void registerAtAreaEnter(std::function<void (std::string)> callback, std::string obj, int x, int y, int z, int dx, int dy, int dz);
+    void registerAtAreaLeave(std::function<void (std::string)> callback, std::string obj, int x, int y, int z, int dx, int dy, int dz);
 
+    void registerAtObjectDestroyed(std::function<void (std::string)> callback, std::string obj);
+    void registerAtPickup(std::function<void (int)> callback, int pickup_id);
+
+    void destroyObject(std::string obj);
+    void removeObject(std::string obj);
+    void setObjectPosition(std::string obj, double x, double y, double z);
+
 private:
+    struct NearObjectHandler
+    {
+        NearObjectHandler(WorldEntity *entity1, WorldEntity *entity2, std::string id1, std::string id2, double distance, std::function<void (std::string, std::string)> callback)
+            : entity1_(entity1), entity2_(entity2), id1_(id1), id2_(id2), distance_(distance), callback_(callback)
+        {}
+
+        WorldEntity *entity1_, *entity2_;
+        std::string id1_, id2_;
+        double distance_;
+        std::function<void (std::string, std::string)> callback_;
+    };
+
+    struct NearPointHandler
+    {
+        NearPointHandler(WorldEntity *entity, std::string id, double x, double y, double z, double distance, std::function<void (std::string)> callback)
+            : entity_(entity), id_(id), point_(x, y, z), distance_(distance), callback_(callback)
+        {}
+
+        WorldEntity *entity_;
+        std::string id_;
+        Vector3 point_;
+        double distance_;
+        std::function<void (std::string)> callback_;
+    };
+
+    struct AreaHandler
+    {
+        AreaHandler(WorldEntity *entity, std::string id, double x, double y, double z, double dx, double dy, double dz, bool atEnter, std::function<void (std::string)> callback)
+            : entity_(entity), id_(id), start_point_(x, y, z), atEnter_(atEnter), callback_(callback)
+        { this-> end_point_ = this->start_point_ + Vector3(dx, dy, dz); }
+
+        WorldEntity *entity_;
+        std::string id_;
+        Vector3 start_point_, end_point_;
+        bool atEnter_;
+        std::function<void (std::string)> callback_;
+    };
+
+
     lua_State *lua_;
     ScriptableController *controller_;
+    std::list<NearObjectHandler> nearObjectHandlers_;
+    std::list<NearPointHandler> nearPointHandlers_;
+    std::list<AreaHandler> areaHandlers_;
+    Timer areaCheckTimer;
+
+    void checkAreas(void);
 };
 
 }

Modified: code/branches/ScriptableController_HS17/src/orxonox/worldentities/ControllableEntity.cc
===================================================================
--- code/branches/ScriptableController_HS17/src/orxonox/worldentities/ControllableEntity.cc	2017-11-20 15:30:24 UTC (rev 11582)
+++ code/branches/ScriptableController_HS17/src/orxonox/worldentities/ControllableEntity.cc	2017-11-20 15:48:03 UTC (rev 11583)
@@ -38,6 +38,7 @@
 #include "network/NetworkFunctionIncludes.h"
 
 #include "Scene.h"
+#include "Level.h"
 #include "infos/PlayerInfo.h"
 #include "controllers/NewHumanController.h"
 #include "graphics/Camera.h"
@@ -67,7 +68,6 @@
         this->hud_ = nullptr;
         this->camera_ = nullptr;
         this->xmlcontroller_ = nullptr;
-        //this->controller_ = nullptr;
         this->reverseCamera_ = nullptr;
         this->bDestroyWhenPlayerLeft_ = false;
         this->cameraPositionRootNode_ = this->node_->createChildSceneNode();
@@ -126,6 +126,9 @@
 
         XMLPortObject(ControllableEntity, CameraPosition, "camerapositions", addCameraPosition, getCameraPosition, xmlelement, mode);
         XMLPortObject(ControllableEntity, Controller,     "controller",      setXMLController,  getXMLController,  xmlelement, mode);
+
+        if(!this->id_.empty() && this->getLevel() != nullptr)
+            this->getLevel()->getScriptableController()->registerControllableEntity(this->id_, this);
     }
 
     void ControllableEntity::setConfigValues()
@@ -337,11 +340,6 @@
         this->setTarget( orxonox_cast<WorldEntity*>(Synchronisable::getSynchronisable(targetID)) );
     }
 
-    void ControllableEntity::registerToScriptableController(ScriptableController *controller)
-    {
-        controller->registerControllableEntity(this->id_, this);
-    }
-
     void ControllableEntity::setPlayer(PlayerInfo* player)
     {
         if (!player)

Modified: code/branches/ScriptableController_HS17/src/orxonox/worldentities/ControllableEntity.h
===================================================================
--- code/branches/ScriptableController_HS17/src/orxonox/worldentities/ControllableEntity.h	2017-11-20 15:30:24 UTC (rev 11582)
+++ code/branches/ScriptableController_HS17/src/orxonox/worldentities/ControllableEntity.h	2017-11-20 15:48:03 UTC (rev 11583)
@@ -175,7 +175,6 @@
             inline int getTeam() const
                 { return this->team_; }
 
-            virtual void registerToScriptableController(ScriptableController *controller) override;
 
         protected:
             virtual void preDestroy() override;

Modified: code/branches/ScriptableController_HS17/src/orxonox/worldentities/MobileEntity.cc
===================================================================
--- code/branches/ScriptableController_HS17/src/orxonox/worldentities/MobileEntity.cc	2017-11-20 15:30:24 UTC (rev 11582)
+++ code/branches/ScriptableController_HS17/src/orxonox/worldentities/MobileEntity.cc	2017-11-20 15:48:03 UTC (rev 11583)
@@ -114,7 +114,6 @@
         }
 
         this->node_->setPosition(position);
-        this->getLevel()->getScriptableController()->objectMoved(this);
     }
 
     void MobileEntity::setOrientation(const Quaternion& orientation)

Modified: code/branches/ScriptableController_HS17/src/orxonox/worldentities/WorldEntity.cc
===================================================================
--- code/branches/ScriptableController_HS17/src/orxonox/worldentities/WorldEntity.cc	2017-11-20 15:30:24 UTC (rev 11582)
+++ code/branches/ScriptableController_HS17/src/orxonox/worldentities/WorldEntity.cc	2017-11-20 15:48:03 UTC (rev 11583)
@@ -43,6 +43,7 @@
 #include "core/CoreIncludes.h"
 #include "core/XMLPort.h"
 #include "Scene.h"
+#include "Level.h"
 #include "collisionshapes/WorldEntityCollisionShape.h"
 #include "scriptablecontroller/scriptable_controller.h"
 
@@ -184,7 +185,8 @@
         // Attached collision shapes
         XMLPortObject(WorldEntity, CollisionShape, "collisionShapes", attachCollisionShape, getAttachedCollisionShape, xmlelement, mode);
 
-        orxout(user_info) << "ID loaded" << std::endl;
+        if(!this->id_.empty() && this->getLevel() != nullptr)
+            this->getLevel()->getScriptableController()->registerWorldEntity(this->id_, this);
     }
 
     void WorldEntity::registerVariables()
@@ -279,12 +281,6 @@
         }
     }
 
-    void WorldEntity::registerToScriptableController(ScriptableController *controller)
-    {
-        orxout(user_info) << "Registering object to SC (" << this->id_ << ")" << std::endl;
-        controller->registerWorldEntity(this->id_, this);
-    }
-
     /**
     @brief
         Network function that object this instance to its correct parent.

Modified: code/branches/ScriptableController_HS17/src/orxonox/worldentities/WorldEntity.h
===================================================================
--- code/branches/ScriptableController_HS17/src/orxonox/worldentities/WorldEntity.h	2017-11-20 15:30:24 UTC (rev 11582)
+++ code/branches/ScriptableController_HS17/src/orxonox/worldentities/WorldEntity.h	2017-11-20 15:48:03 UTC (rev 11583)
@@ -110,14 +110,12 @@
             virtual void changedActivity(void) override;
             virtual void changedVisibility(void) override;
 
-            inline int getID(void)
+            inline std::string getID(void)
                 { return this->id_; }
 
-            inline void setID(int id)
+            inline void setID(std::string id)
                 { this->id_ = id; }
 
-            virtual void registerToScriptableController(ScriptableController *controller) override;
-
             virtual void setPosition(const Vector3& position) = 0;
             inline void setPosition(float x, float y, float z)
                 { this->setPosition(Vector3(x, y, z)); }
@@ -449,7 +447,7 @@
             virtual bool isCollisionTypeLegal(CollisionType type) const = 0;
 
             btRigidBody*  physicalBody_; //!< Bullet rigid body. Everything physical is applied to this instance.
-            int           id_;           //!< Used by the ScriptableController to identify objects
+            std::string   id_;           //!< Used by the ScriptableController to identify objects
 
         private:
             void recalculateMassProps();



More information about the Orxonox-commit mailing list