Changeset 11673 for code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/scriptable_controller_api.cc
- Timestamp:
- Dec 14, 2017, 4:04:14 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/scriptable_controller_api.cc
r11662 r11673 18 18 this->controller_ = controller; 19 19 20 // Haven't found a shorter way yet to write that... 20 // Haven't found a shorter way yet to write that... We need C++17! 21 21 LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::orxPrint)>::registerFunction<&ScriptableControllerAPI::orxPrint>(this, lua, "orxPrint"); 22 22 … … 101 101 void ScriptableControllerAPI::killPawn(std::string id) 102 102 { 103 // We don't kill the pawn here directly, because this function is called from LUA and thus 104 // runs in a different thread. So we schedule the kill for later in the main thread 105 // (in 'periodic'). 106 this->pawnsToKill_.push_back(id); 103 Pawn *pawn = this->controller_->getPawnByID(id); 104 if(pawn == nullptr) 105 orxout(user_warning) << "Trying to kill an unknown pawn" << std::endl; 106 else 107 pawn->kill(); 107 108 } 108 109 … … 168 169 const Vector3 &old = entity->getPosition(); 169 170 171 // If one of the values is NaN, don't change that value 170 172 x = std::isnan(x) ? old.x : x; 171 173 y = std::isnan(y) ? old.y : y; … … 189 191 entity->getOrientation().ToAngleAxis(old_angle, old_axis); 190 192 193 // If one of the values is NaN, don't change that value 191 194 x = std::isnan(x) ? old_axis.x : x; 192 195 y = std::isnan(y) ? old_axis.y : y; … … 194 197 angle = std::isnan(x) ? old_angle.valueDegrees() : angle; 195 198 199 196 200 entity->setOrientation(Vector3(x, y, z), Degree(angle)); 197 201 } … … 208 212 const Vector3 &old = entity->getVelocity(); 209 213 214 // If one of the values is NaN, don't change that value 210 215 x = std::isnan(x) ? old.x : x; 211 216 y = std::isnan(y) ? old.y : y; … … 226 231 const Vector3 &old = entity->getAngularVelocity(); 227 232 233 // If one of the values is NaN, don't change that value 228 234 x = std::isnan(x) ? old.x : x; 229 235 y = std::isnan(y) ? old.y : y; … … 248 254 else 249 255 near_obj_handler++; 256 } 257 258 auto near_point_handler = this->nearPointHandlers_.begin(); 259 while(near_point_handler != this->nearPointHandlers_.end()) 260 { 261 if(near_point_handler->entity_ == pawn) 262 near_point_handler = this->nearPointHandlers_.erase(near_point_handler); 263 else 264 near_point_handler++; 265 } 266 267 auto area_handler = this->areaHandlers_.begin(); 268 while(area_handler != this->areaHandlers_.end()) 269 { 270 if(area_handler->entity_ == pawn) 271 area_handler = this->areaHandlers_.erase(area_handler); 272 else 273 area_handler++; 250 274 } 251 275 } … … 319 343 } 320 344 } 321 322 // Pawns to kill 323 // TODO Possible race condidtion when the player destroys the pawn 324 // between the callback and the next periodic call. 325 for(auto &pawn : this->pawnsToKill_) 326 this->controller_->killPawn(pawn); 327 328 this->pawnsToKill_.clear(); 329 } 330 331 } 345 } 346 347 }
Note: See TracChangeset
for help on using the changeset viewer.