Changeset 11583 for code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/scriptable_controller_api.cc
- Timestamp:
- Nov 20, 2017, 4:48:03 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/ScriptableController_HS17/src/orxonox/scriptablecontroller/scriptable_controller_api.cc
r11562 r11583 17 17 LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::registerAfterTimeout)>::registerFunction<&ScriptableControllerAPI::registerAfterTimeout>(this, lua, "registerAfterTimeout"); 18 18 LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::registerAtNearObject)>::registerFunction<&ScriptableControllerAPI::registerAtNearObject>(this, lua, "registerAtNearObject"); 19 LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::registerAtNearPoint)>::registerFunction<&ScriptableControllerAPI::registerAtNearPoint>(this, lua, "registerAtNearPoint"); 19 20 LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::registerAtAreaEnter)>::registerFunction<&ScriptableControllerAPI::registerAtAreaEnter>(this, lua, "registerAtAreaEnter"); 20 21 LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::registerAtAreaLeave)>::registerFunction<&ScriptableControllerAPI::registerAtAreaLeave>(this, lua, "registerAtAreaLeave"); 21 LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::registerAtObjectDestroyed)>::registerFunction<&ScriptableControllerAPI::registerAtObjectDestroyed>(this, lua, "registerAtObjectDestroyed"); 22 LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::registerAtPickup)>::registerFunction<&ScriptableControllerAPI::registerAtPickup>(this, lua, "registerAtPickup"); 22 // LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::registerAtObjectDestroyed)>::registerFunction<&ScriptableControllerAPI::registerAtObjectDestroyed>(this, lua, "registerAtObjectDestroyed"); 23 // LuaTB<ScriptableControllerAPI, decltype(&ScriptableControllerAPI::registerAtPickup)>::registerFunction<&ScriptableControllerAPI::registerAtPickup>(this, lua, "registerAtPickup"); 24 25 // Checks for area enter, area leave and near object events 26 this->areaCheckTimer.setTimer(0.5, true, createExecutor(createFunctor(&ScriptableControllerAPI::checkAreas, this)), false); 23 27 } 24 28 … … 39 43 } 40 44 41 int ScriptableControllerAPI::registerAtNearObject(std::function<void (int, int)> callback, int obj1, int obj2, double distance)45 void ScriptableControllerAPI::registerAtNearObject(std::function<void (std::string, std::string)> callback, std::string id1, std::string id2, double distance) 42 46 { 43 //this->controller_->addNearObjectHandler(obj1, obj1, distance, callback); 47 WorldEntity *entity1 = this->controller_->getWorldEntityByID(id1); 48 WorldEntity *entity2 = this->controller_->getWorldEntityByID(id2); 49 50 if(entity1 != nullptr && entity2 != nullptr) 51 this->nearObjectHandlers_.push_front(NearObjectHandler(entity1, entity2, id1, id2, distance, callback)); 44 52 } 45 53 46 int ScriptableControllerAPI::registerAtAreaEnter(std::function<void (int)> callback, int obj, int x, int y, int z, int dx, int dy, int dz)54 void ScriptableControllerAPI::registerAtNearPoint(std::function<void (std::string)> callback, std::string id, double x, double y, double z, double distance) 47 55 { 56 WorldEntity *entity = this->controller_->getWorldEntityByID(id); 48 57 58 if(entity != nullptr) 59 this->nearPointHandlers_.push_front(NearPointHandler(entity, id, x, y, z, distance, callback)); 49 60 } 50 61 51 int ScriptableControllerAPI::registerAtAreaLeave(std::function<void (int)> callback, int obj, int x, int y, int z, int dx, int dy, int dz)62 void ScriptableControllerAPI::registerAtAreaEnter(std::function<void (std::string)> callback, std::string id, int x, int y, int z, int dx, int dy, int dz) 52 63 { 64 WorldEntity *entity = this->controller_->getWorldEntityByID(id); 53 65 66 if(entity != nullptr) 67 this->areaHandlers_.push_front(AreaHandler(entity, id, x, y, z, dx, dy, dz, true, callback)); 54 68 } 55 69 56 int ScriptableControllerAPI::registerAtObjectDestroyed(std::function<void (int)> callback, int obj)70 void ScriptableControllerAPI::registerAtAreaLeave(std::function<void (std::string)> callback, std::string id, int x, int y, int z, int dx, int dy, int dz) 57 71 { 72 WorldEntity *entity = this->controller_->getWorldEntityByID(id); 58 73 74 if(entity != nullptr) 75 this->areaHandlers_.push_front(AreaHandler(entity, id, x, y, z, dx, dy, dz, false, callback)); 59 76 } 60 77 61 int ScriptableControllerAPI::registerAtPickup(std::function<void (int)> callback, int pickup_id)78 void ScriptableControllerAPI::checkAreas() 62 79 { 80 // Near object 81 auto near_obj_handler = this->nearObjectHandlers_.begin(); 82 while(near_obj_handler != this->nearObjectHandlers_.end()) 83 { 84 if((near_obj_handler->entity1_->getPosition() - near_obj_handler->entity2_->getPosition()).length() < near_obj_handler->distance_) 85 { 86 near_obj_handler->callback_(near_obj_handler->id1_, near_obj_handler->id2_); 87 near_obj_handler = this->nearObjectHandlers_.erase(near_obj_handler); 88 } 89 else 90 { 91 near_obj_handler++; 92 } 93 } 63 94 95 // Near point 96 auto near_point_handler = this->nearPointHandlers_.begin(); 97 while(near_point_handler != this->nearPointHandlers_.end()) 98 { 99 if((near_point_handler->entity_->getPosition() - near_point_handler->point_).length() < near_point_handler->distance_) 100 { 101 near_point_handler->callback_(near_point_handler->id_); 102 near_point_handler = this->nearPointHandlers_.erase(near_point_handler); 103 } 104 else 105 { 106 near_point_handler++; 107 } 108 } 109 110 // Areas 111 auto area_handler = this->areaHandlers_.begin(); 112 while(area_handler != this->areaHandlers_.end()) 113 { 114 if(area_handler->entity_->getPosition() > area_handler->start_point_ && 115 area_handler->entity_->getPosition() < area_handler->end_point_) 116 { 117 if(area_handler->atEnter_) 118 { 119 area_handler->callback_(area_handler->id_); 120 area_handler = this->areaHandlers_.erase(area_handler); 121 } 122 else 123 { 124 area_handler++; 125 } 126 } 127 else 128 { 129 if(!area_handler->atEnter_) 130 { 131 area_handler->callback_(area_handler->id_); 132 area_handler = this->areaHandlers_.erase(area_handler); 133 } 134 else 135 { 136 area_handler++; 137 } 138 } 139 } 64 140 } 65 141
Note: See TracChangeset
for help on using the changeset viewer.