Changeset 11606 for code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/scriptable_controller_api.cc
- Timestamp:
- Nov 27, 2017, 4:38:50 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/scriptable_controller_api.cc
r11583 r11606 8 8 { 9 9 10 const double ScriptableControllerAPI::periodic_interval = 0.5; 11 10 12 ScriptableControllerAPI::ScriptableControllerAPI(lua_State *lua, ScriptableController *controller) 11 13 { … … 15 17 // Haven't found a shorter way yet to write that... 16 18 LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::orxPrint)>::registerFunction<&ScriptableControllerAPI::orxPrint>(this, lua, "orxPrint"); 19 17 20 LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::registerAfterTimeout)>::registerFunction<&ScriptableControllerAPI::registerAfterTimeout>(this, lua, "registerAfterTimeout"); 18 21 LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::registerAtNearObject)>::registerFunction<&ScriptableControllerAPI::registerAtNearObject>(this, lua, "registerAtNearObject"); … … 20 23 LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::registerAtAreaEnter)>::registerFunction<&ScriptableControllerAPI::registerAtAreaEnter>(this, lua, "registerAtAreaEnter"); 21 24 LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::registerAtAreaLeave)>::registerFunction<&ScriptableControllerAPI::registerAtAreaLeave>(this, lua, "registerAtAreaLeave"); 22 // LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::registerAtObjectDestroyed)>::registerFunction<&ScriptableControllerAPI::registerAtObjectDestroyed>(this, lua, "registerAtObjectDestroyed");23 // LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::registerAtPickup)>::registerFunction<&ScriptableControllerAPI::registerAtPickup>(this, lua, "registerAtPickup");25 LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::registerAtPawnKilled)>::registerFunction<&ScriptableControllerAPI::registerAtPawnKilled>(this, lua, "registerAtPawnKilled"); 26 LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::registerAtPawnHit)>::registerFunction<&ScriptableControllerAPI::registerAtPawnHit>(this, lua, "registerAtPawnHit"); 24 27 25 // Checks for area enter, area leave and near object events 26 this->areaCheckTimer.setTimer(0.5, true, createExecutor(createFunctor(&ScriptableControllerAPI::checkAreas, this)), false); 28 LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::killPawn)>::registerFunction<&ScriptableControllerAPI::killPawn>(this, lua, "killPawn"); 29 30 this->periodicTimer.setTimer(ScriptableControllerAPI::periodic_interval, true, createExecutor(createFunctor(&ScriptableControllerAPI::periodic, this)), false); 27 31 } 28 32 … … 76 80 } 77 81 78 void ScriptableControllerAPI::checkAreas() 82 void ScriptableControllerAPI::registerAtPawnKilled(std::function<void (std::string)> callback, std::string id) 83 { 84 this->pawnDestroyedHandlers_[id].push_back(callback); 85 } 86 87 void ScriptableControllerAPI::registerAtPawnHit(std::function<void (std::string, std::string, double, double)> callback, std::string id) 88 { 89 this->pawnHitHandlers_[id].push_back(callback); 90 } 91 92 void ScriptableControllerAPI::killPawn(std::string id) 93 { 94 // We don't kill the pawn here directly, because this function is called from LUA and thus 95 // runs in a different thread. So we schedule the kill for later in the main thread 96 // (in 'periodic'). 97 this->pawnsToKill_.push_back(id); 98 } 99 100 void ScriptableControllerAPI::pawnKilled(std::string id) 101 { 102 for(auto callback : this->pawnDestroyedHandlers_[id]) 103 callback(id); 104 105 this->pawnDestroyedHandlers_.erase(id); 106 } 107 108 void ScriptableControllerAPI::pawnHit(std::string target_id, std::string source_id, double new_health, double new_shield) 109 { 110 for(auto callback : this->pawnHitHandlers_[target_id]) 111 callback(target_id, source_id, new_health, new_shield); 112 } 113 114 void ScriptableControllerAPI::periodic() 79 115 { 80 116 // Near object … … 138 174 } 139 175 } 176 177 // Pawns to kill 178 for(auto &pawn : this->pawnsToKill_) 179 this->controller_->killPawn(pawn); 180 181 this->pawnsToKill_.clear(); 140 182 } 141 183
Note: See TracChangeset
for help on using the changeset viewer.