Changeset 2254
- Timestamp:
- Nov 24, 2008, 1:50:47 AM (16 years ago)
- Location:
- code/branches/objecthierarchy2
- Files:
-
- 10 added
- 22 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchy2/bin/def_keybindings.ini
r2103 r2254 119 119 KeySlash= 120 120 KeySleep= 121 KeySpace= 121 KeySpace=boost 122 122 KeyStop= 123 123 KeySystemRequest= -
code/branches/objecthierarchy2/src/core/BaseObject.cc
r2173 r2254 36 36 #include "CoreIncludes.h" 37 37 #include "EventIncludes.h" 38 #include "Functor.h" 38 39 #include "XMLPort.h" 39 40 #include "XMLFile.h" … … 60 61 this->oldGametype_ = 0; 61 62 63 this->functorSetMainState_ = 0; 64 this->functorGetMainState_ = 0; 65 62 66 this->setCreator(creator); 63 67 if (this->creator_) … … 82 86 BaseObject::~BaseObject() 83 87 { 84 for (std::list<BaseObject*>::const_iterator it = this->events_.begin(); it != this->events_.end(); ++it) 85 (*it)->unregisterEventListener(this); 86 87 for (std::map<BaseObject*, std::string>::const_iterator it = this->eventListeners_.begin(); it != this->eventListeners_.end(); ++it) 88 it->first->removeEvent(this); 88 if (this->isInitialized()) 89 { 90 for (std::list<BaseObject*>::const_iterator it = this->events_.begin(); it != this->events_.end(); ++it) 91 (*it)->unregisterEventListener(this); 92 93 for (std::map<BaseObject*, std::string>::const_iterator it = this->eventListeners_.begin(); it != this->eventListeners_.end(); ++it) 94 it->first->removeEvent(this); 95 96 if (this->functorSetMainState_) 97 delete this->functorSetMainState_; 98 if (this->functorGetMainState_) 99 delete this->functorGetMainState_; 100 } 89 101 } 90 102 … … 100 112 XMLPortParam(BaseObject, "visible", setVisible, isVisible, xmlelement, mode); 101 113 XMLPortParam(BaseObject, "active", setActive, isActive, xmlelement, mode); 114 XMLPortParam(BaseObject, "mainstate", setMainStateName, getMainStateName, xmlelement, mode); 102 115 103 116 XMLPortObjectTemplate(BaseObject, Template, "templates", addTemplate, getTemplate, xmlelement, mode, Template*); … … 279 292 SetEvent(BaseObject, "visibility", setVisible, event); 280 293 } 294 295 void BaseObject::setMainStateName(const std::string& name) 296 { 297 if (this->mainStateName_ != name) 298 { 299 this->mainStateName_ = name; 300 if (this->functorSetMainState_) 301 delete this->functorSetMainState_; 302 if (this->functorGetMainState_) 303 delete this->functorGetMainState_; 304 this->changedMainState(); 305 if (!this->functorSetMainState_) 306 COUT(2) << "Warning: \"" << name << "\" is not a valid MainState." << std::endl; 307 } 308 } 309 310 void BaseObject::setMainState(bool state) 311 { 312 if (this->functorSetMainState_) 313 (*this->functorSetMainState_)(state); 314 else 315 COUT(2) << "Warning: No MainState defined in object \"" << this->getName() << "\" (" << this->getIdentifier()->getName() << ")" << std::endl; 316 } 317 318 bool BaseObject::getMainState() const 319 { 320 if (this->functorGetMainState_) 321 { 322 (*this->functorGetMainState_)(); 323 return this->functorGetMainState_->getReturnvalue(); 324 } 325 else 326 { 327 COUT(2) << "Warning: No MainState defined in object \"" << this->getName() << "\" (" << this->getIdentifier()->getName() << ")" << std::endl; 328 return false; 329 } 330 } 331 332 void BaseObject::changedMainState() 333 { 334 SetMainState(BaseObject, "activity", setActive, isActive); 335 SetMainState(BaseObject, "visibility", setVisible, isVisible); 336 } 281 337 } -
code/branches/objecthierarchy2/src/core/BaseObject.h
r2171 r2254 36 36 #ifndef _BaseObject_H__ 37 37 #define _BaseObject_H__ 38 39 #define SetMainState(classname, statename, setfunction, getfunction) \ 40 if (this->getMainStateName() == statename) \ 41 { \ 42 this->functorSetMainState_ = createFunctor(&classname::setfunction)->setObject(this); \ 43 this->functorGetMainState_ = createFunctor(&classname::getfunction)->setObject(this); \ 44 } 38 45 39 46 #include <map> … … 100 107 virtual void changedVisibility() {} 101 108 109 void setMainState(bool state); 110 bool getMainState() const; 111 112 void setMainStateName(const std::string& name); 113 inline const std::string& getMainStateName() const { return this->mainStateName_; } 114 virtual void changedMainState(); 115 102 116 /** @brief Sets a pointer to the xml file that loaded this object. @param file The pointer to the XMLFile */ 103 117 inline void setFile(const XMLFile* file) { this->file_ = file; } … … 153 167 std::string name_; //!< The name of the object 154 168 std::string oldName_; //!< The old name of the object 155 mbool bActive_; //!< True = the object is active 156 mbool bVisible_; //!< True = the object is visible 169 mbool bActive_; //!< True = the object is active 170 mbool bVisible_; //!< True = the object is visible 171 std::string mainStateName_; 172 Functor* functorSetMainState_; 173 Functor* functorGetMainState_; 157 174 158 175 private: … … 160 177 Template* getTemplate(unsigned int index) const; 161 178 162 bool bInitialized_; //!< True if the object was initialized (passed the object registration)163 const XMLFile* file_; //!< The XMLFile that loaded this object164 std::string loaderIndentation_; //!< Indentation of the debug output in the Loader165 Namespace* namespace_;166 BaseObject* creator_;167 Scene* scene_;168 Gametype* gametype_;169 Gametype* oldGametype_;170 std::set<Template*> templates_;171 std::map<BaseObject*, std::string> eventListeners_;179 bool bInitialized_; //!< True if the object was initialized (passed the object registration) 180 const XMLFile* file_; //!< The XMLFile that loaded this object 181 std::string loaderIndentation_; //!< Indentation of the debug output in the Loader 182 Namespace* namespace_; 183 BaseObject* creator_; 184 Scene* scene_; 185 Gametype* gametype_; 186 Gametype* oldGametype_; 187 std::set<Template*> templates_; 188 std::map<BaseObject*, std::string> eventListeners_; 172 189 std::list<BaseObject*> events_; 173 190 std::map<std::string, EventContainer*> eventContainers_; … … 178 195 SUPER_FUNCTION(3, BaseObject, changedVisibility, false); 179 196 SUPER_FUNCTION(4, BaseObject, processEvent, false); 197 SUPER_FUNCTION(6, BaseObject, changedMainState, false); 180 198 } 181 199 -
code/branches/objecthierarchy2/src/core/Functor.h
r2087 r2254 167 167 } 168 168 169 FunctorMember * setObject(T* object)169 FunctorMember<T>* setObject(T* object) 170 170 { 171 171 this->bConstObject_ = false; … … 174 174 } 175 175 176 FunctorMember * setObject(const T* object)176 FunctorMember<T>* setObject(const T* object) 177 177 { 178 178 this->bConstObject_ = true; -
code/branches/objecthierarchy2/src/core/Super.h
r2212 r2254 236 236 #define SUPER_changedScale(classname, functionname, ...) \ 237 237 SUPER_NOARGS(classname, functionname) 238 239 #define SUPER_changedMainState(classname, functionname, ...) \ 240 SUPER_NOARGS(classname, functionname) 238 241 // (1/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- 239 242 … … 448 451 () 449 452 SUPER_FUNCTION_GLOBAL_DECLARATION_PART2; 453 454 SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(6, changedMainState, false) 455 () 456 SUPER_FUNCTION_GLOBAL_DECLARATION_PART2; 450 457 // (2/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- 451 458 … … 496 503 SUPER_INTRUSIVE_DECLARATION(processEvent); 497 504 SUPER_INTRUSIVE_DECLARATION(changedScale); 505 SUPER_INTRUSIVE_DECLARATION(changedMainState); 498 506 // (3/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- 499 507 -
code/branches/objecthierarchy2/src/orxonox/OrxonoxPrereqs.h
r2171 r2254 113 113 class Billboard; 114 114 class BlinkingBillboard; 115 class FadingBillboard; 115 116 class Light; 116 117 class Backlight; … … 125 126 class Pawn; 126 127 class SpaceShip; 128 129 class Item; 130 class Engine; 131 class MultiStateEngine; 132 class RotatingEngine; 127 133 128 134 class Trigger; -
code/branches/objecthierarchy2/src/orxonox/objects/CMakeLists.txt
r2171 r2254 16 16 ADD_SOURCE_DIRECTORY(SRC_FILES gametypes) 17 17 ADD_SOURCE_DIRECTORY(SRC_FILES infos) 18 ADD_SOURCE_DIRECTORY(SRC_FILES items) 18 19 #ADD_SOURCE_DIRECTORY(SRC_FILES pickup) 19 20 ADD_SOURCE_DIRECTORY(SRC_FILES quest) -
code/branches/objecthierarchy2/src/orxonox/objects/controllers/HumanController.cc
r2087 r2254 44 44 SetConsoleCommand(HumanController, fire, true).keybindMode(KeybindMode::OnHold); 45 45 SetConsoleCommand(HumanController, altFire, true).keybindMode(KeybindMode::OnHold); 46 SetConsoleCommand(HumanController, boost, true).keybindMode(KeybindMode::OnHold); 46 47 SetConsoleCommand(HumanController, greet, true); 47 48 SetConsoleCommand(HumanController, use, true); … … 112 113 } 113 114 115 void HumanController::boost() 116 { 117 if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) 118 HumanController::localController_s->controllableEntity_->boost(); 119 } 120 114 121 void HumanController::greet() 115 122 { -
code/branches/objecthierarchy2/src/orxonox/objects/controllers/HumanController.h
r2087 r2254 54 54 static void altFire(); 55 55 56 static void boost(); 56 57 static void greet(); 57 58 static void use(); -
code/branches/objecthierarchy2/src/orxonox/objects/worldentities/Backlight.cc
r2212 r2254 43 43 CreateFactory(Backlight); 44 44 45 Backlight::Backlight(BaseObject* creator) : Billboard(creator)45 Backlight::Backlight(BaseObject* creator) : FadingBillboard(creator) 46 46 { 47 47 RegisterObject(Backlight); … … 53 53 this->length_ = 1.0f; 54 54 this->lifetime_ = 0.001f; 55 this->turnofftime_ = 0.5f;56 this->bTurningOff_ = false;57 55 this->maxelements_ = 1; 58 56 … … 102 100 XMLPortParam(Backlight, "elements", setMaxElements, getMaxElements, xmlelement, mode).defaultValues(10); 103 101 XMLPortParam(Backlight, "lifetime", setLifetime, getLifetime, xmlelement, mode).defaultValues(1.0f); 104 XMLPortParam(Backlight, "turnofftime", setTurnOffTime, getTurnOffTime, xmlelement, mode).defaultValues(0.5f);105 102 XMLPortParam(Backlight, "trailmaterial", setTrailMaterial, getTrailMaterial, xmlelement, mode); 106 103 } … … 117 114 void Backlight::changedColour() 118 115 { 119 Billboard::changedColour();120 121 if (this->ribbonTrail_ && this-> isActive() && this->tickcount_ >= 2)122 this->ribbonTrail_->setInitialColour(0, this->get Colour());116 FadingBillboard::changedColour(); 117 118 if (this->ribbonTrail_ && this->tickcount_ >= 2) 119 this->ribbonTrail_->setInitialColour(0, this->getFadedColour()); 123 120 } 124 121 … … 165 162 } 166 163 167 void Backlight::changedActivity() 168 { 169 SUPER(Backlight, changedActivity); 164 void Backlight::startturnonoff() 165 { 166 FadingBillboard::startturnonoff(); 167 168 if (this->ribbonTrail_ && this->isActive() && this->isVisible()) 169 this->ribbonTrail_->setVisible(true); 170 } 171 172 void Backlight::stopturnonoff() 173 { 174 this->postprocessingtime_ = max(0.0f, this->lifetime_ - this->turnofftime_); 175 176 FadingBillboard::stopturnonoff(); 170 177 171 178 if (this->ribbonTrail_) 172 {173 if (this->isActive())174 this->ribbonTrail_->setInitialColour(0, this->getColour()); 175 else176 177 this->bTurningOff_ = true;178 this->turnofftimer_.setTimer(this->turnofftime_, false, this, createExecutor(createFunctor(&Backlight::stopturnoff))); 179 }180 }179 this->ribbonTrail_->setInitialColour(0, this->getFadedColour()); 180 } 181 182 void Backlight::poststopturnonoff() 183 { 184 FadingBillboard::poststopturnonoff(); 185 186 if (this->ribbonTrail_) 187 this->ribbonTrail_->setVisible(false); 181 188 } 182 189 … … 187 194 this->update_width(); 188 195 this->update_length(); 189 }190 191 void Backlight::stopturnoff()192 {193 this->bTurningOff_ = false;194 196 } 195 197 … … 212 214 } 213 215 214 if (this->bTurningOff_ && this->ribbonTrail_) 215 { 216 this->ribbonTrail_->setInitialColour(0, this->ribbonTrail_->getInitialColour(0) - this->getColour() / this->turnofftime_ * dt); 216 SUPER(Backlight, tick, dt); 217 218 if (this->ribbonTrail_ && this->changedirection_ != 0) 219 { 220 // we use alpha_blend, only adjust alpha 221 const ColourValue& colour = this->getColour(); 222 this->ribbonTrail_->setInitialColour(0, colour.r, colour.g, colour.b, this->getFadedColour().a); 217 223 } 218 224 } -
code/branches/objecthierarchy2/src/orxonox/objects/worldentities/Backlight.h
r2212 r2254 31 31 32 32 #include "OrxonoxPrereqs.h" 33 #include "Billboard.h" 34 #include "objects/Tickable.h" 35 #include "tools/Timer.h" 33 #include "FadingBillboard.h" 36 34 37 35 namespace orxonox 38 36 { 39 class _OrxonoxExport Backlight : public Billboard, public Tickable37 class _OrxonoxExport Backlight : public FadingBillboard 40 38 { 41 39 public: … … 47 45 48 46 virtual void tick(float dt); 49 virtual void changedActivity();50 47 virtual void changedVisibility(); 51 48 … … 59 56 inline float getLifetime() const 60 57 { return this->lifetime_; } 61 62 inline void setTurnOffTime(float turnofftime)63 { this->turnofftime_ = turnofftime; }64 inline float getTurnOffTime() const65 { return this->turnofftime_; }66 58 67 59 inline void setLength(float length) … … 83 75 84 76 private: 85 void stopturnoff(); 77 virtual void startturnonoff(); 78 virtual void stopturnonoff(); 79 virtual void poststopturnonoff(); 86 80 virtual void changedColour(); 87 81 void update_width(); … … 96 90 float length_; 97 91 float lifetime_; 98 float turnofftime_;99 bool bTurningOff_;100 92 size_t maxelements_; 101 93 std::string trailmaterial_; 102 94 char tickcount_; 103 Timer<Backlight> turnofftimer_;104 95 }; 105 96 } -
code/branches/objecthierarchy2/src/orxonox/objects/worldentities/Billboard.cc
r2212 r2254 94 94 if (!this->billboard_.getBillboardSet()) 95 95 { 96 /* 96 97 if (this->getScene() && this->getScene()->getSceneManager() && (this->material_ != "")) 97 98 { … … 101 102 this->billboard_.setVisible(this->isVisible()); 102 103 } 104 */ 103 105 } 104 106 else -
code/branches/objecthierarchy2/src/orxonox/objects/worldentities/Billboard.h
r2182 r2254 62 62 63 63 protected: 64 inline BillboardSet& getBillboardSet() 65 { return this->billboard_; } 66 64 67 virtual void changedColour(); 65 68 -
code/branches/objecthierarchy2/src/orxonox/objects/worldentities/CMakeLists.txt
r2182 r2254 8 8 Billboard.cc 9 9 BlinkingBillboard.cc 10 FadingBillboard.cc 10 11 Light.cc 11 12 Camera.cc -
code/branches/objecthierarchy2/src/orxonox/objects/worldentities/ControllableEntity.cc
r2171 r2254 48 48 RegisterObject(ControllableEntity); 49 49 50 this->bControlled_ = false; 50 this->bHasLocalController_ = false; 51 this->bHasHumanController_ = false; 52 51 53 this->server_overwrite_ = 0; 52 54 this->client_overwrite_ = 0; … … 74 76 if (this->isInitialized()) 75 77 { 76 if (this->b Controlled_)77 this->stopLocal Control();78 if (this->bHasLocalController_) 79 this->stopLocalHumanControl(); 78 80 79 81 if (this->hud_) … … 156 158 this->player_ = player; 157 159 this->playerID_ = player->getObjectID(); 158 this->bControlled_ = (player->isLocalPlayer() && player->isHumanPlayer()); 159 if (this->bControlled_) 160 { 161 this->startLocalControl(); 160 this->bHasLocalController_ = player->isLocalPlayer(); 161 this->bHasHumanController_ = player->isHumanPlayer(); 162 163 if (this->bHasLocalController_ && this->bHasHumanController_) 164 { 165 this->startLocalHumanControl(); 162 166 163 167 if (!Core::isMaster()) … … 172 176 void ControllableEntity::removePlayer() 173 177 { 174 if (this->b Controlled_)175 this->stopLocal Control();178 if (this->bHasLocalController_ && this->bHasHumanController_) 179 this->stopLocalHumanControl(); 176 180 177 181 this->player_ = 0; 178 182 this->playerID_ = OBJECTID_UNKNOWN; 179 this->bControlled_ = false; 183 this->bHasLocalController_ = false; 184 this->bHasHumanController_ = false; 180 185 this->setObjectMode(direction::toclient); 181 186 … … 195 200 } 196 201 197 void ControllableEntity::startLocal Control()202 void ControllableEntity::startLocalHumanControl() 198 203 { 199 204 // std::cout << this->getObjectID() << " ###### start local control" << std::endl; … … 214 219 } 215 220 216 void ControllableEntity::stopLocal Control()221 void ControllableEntity::stopLocalHumanControl() 217 222 { 218 223 // std::cout << "###### stop local control" << std::endl; … … 237 242 this->server_position_ = this->node_->getPosition(); 238 243 } 239 else if (this->b Controlled_)244 else if (this->bHasLocalController_) 240 245 { 241 246 // COUT(2) << "setting client position" << endl; … … 251 256 252 257 REGISTERDATA(this->client_overwrite_, direction::toserver); 253 258 254 259 REGISTERDATA(this->server_position_, direction::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerPosition)); 255 260 REGISTERDATA(this->server_velocity_, direction::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerVelocity)); … … 267 272 void ControllableEntity::processServerPosition() 268 273 { 269 if (!this->b Controlled_)274 if (!this->bHasLocalController_) 270 275 this->node_->setPosition(this->server_position_); 271 276 } … … 273 278 void ControllableEntity::processServerVelocity() 274 279 { 275 if (!this->b Controlled_)280 if (!this->bHasLocalController_) 276 281 this->velocity_ = this->server_velocity_; 277 282 } … … 279 284 void ControllableEntity::processServerOrientation() 280 285 { 281 if (!this->b Controlled_)286 if (!this->bHasLocalController_) 282 287 this->node_->setOrientation(this->server_orientation_); 283 288 } … … 285 290 void ControllableEntity::processOverwrite() 286 291 { 287 if (this->b Controlled_)292 if (this->bHasLocalController_) 288 293 { 289 294 this->setPosition(this->server_position_); … … 334 339 ++this->server_overwrite_; 335 340 } 336 else if (this->b Controlled_)341 else if (this->bHasLocalController_) 337 342 { 338 343 this->node_->setPosition(position); … … 349 354 ++this->server_overwrite_; 350 355 } 351 else if (this->b Controlled_)356 else if (this->bHasLocalController_) 352 357 { 353 358 this->velocity_ = velocity; … … 364 369 ++this->server_overwrite_; 365 370 } 366 else if (this->b Controlled_)371 else if (this->bHasLocalController_) 367 372 { 368 373 this->node_->translate(distance, relativeTo); … … 379 384 ++this->server_overwrite_; 380 385 } 381 else if (this->b Controlled_)386 else if (this->bHasLocalController_) 382 387 { 383 388 this->node_->setOrientation(orientation); … … 394 399 ++this->server_overwrite_; 395 400 } 396 else if (this->b Controlled_)401 else if (this->bHasLocalController_) 397 402 { 398 403 this->node_->rotate(rotation, relativeTo); … … 409 414 ++this->server_overwrite_; 410 415 } 411 else if (this->b Controlled_)416 else if (this->bHasLocalController_) 412 417 { 413 418 this->node_->yaw(angle, relativeTo); … … 424 429 ++this->server_overwrite_; 425 430 } 426 else if (this->b Controlled_)431 else if (this->bHasLocalController_) 427 432 { 428 433 this->node_->pitch(angle, relativeTo); … … 439 444 ++this->server_overwrite_; 440 445 } 441 else if (this->b Controlled_)446 else if (this->bHasLocalController_) 442 447 { 443 448 this->node_->roll(angle, relativeTo); … … 454 459 ++this->server_overwrite_; 455 460 } 456 else if (this->b Controlled_)461 else if (this->bHasLocalController_) 457 462 { 458 463 this->node_->lookAt(target, relativeTo, localDirectionVector); … … 469 474 ++this->server_overwrite_; 470 475 } 471 else if (this->b Controlled_)476 else if (this->bHasLocalController_) 472 477 { 473 478 this->node_->setDirection(direction, relativeTo, localDirectionVector); -
code/branches/objecthierarchy2/src/orxonox/objects/worldentities/ControllableEntity.h
r2087 r2254 68 68 virtual void altFire() {} 69 69 70 virtual void boost() {} 70 71 virtual void greet() {} 71 72 virtual void use() {} … … 123 124 { return this->cameraPositionTemplate_; } 124 125 126 inline bool hasLocalController() const 127 { return this->bHasLocalController_; } 128 inline bool hasHumanController() const 129 { return this->bHasHumanController_; } 130 125 131 protected: 126 virtual void startLocal Control();127 virtual void stopLocal Control();132 virtual void startLocalHumanControl(); 133 virtual void stopLocalHumanControl(); 128 134 129 135 inline void setHudTemplate(const std::string& name) 130 136 { this->hudtemplate_ = name; } 131 132 inline bool isLocallyControlled() const133 { return this->bControlled_; }134 137 135 138 Vector3 acceleration_; … … 154 157 Vector3 velocity_; 155 158 156 bool bControlled_; 159 bool bHasLocalController_; 160 bool bHasHumanController_; 161 157 162 Vector3 server_position_; 158 163 Vector3 client_position_; -
code/branches/objecthierarchy2/src/orxonox/objects/worldentities/Light.cc
r2171 r2254 163 163 void Light::changedType() 164 164 { 165 this->light_->setType(this->type_); 165 if (this->light_) 166 this->light_->setType(this->type_); 166 167 } 167 168 … … 170 171 SUPER(Light, changedVisibility); 171 172 172 this->light_->setVisible(this->isVisible()); 173 if (this->light_) 174 this->light_->setVisible(this->isVisible()); 173 175 } 174 176 } -
code/branches/objecthierarchy2/src/orxonox/objects/worldentities/WorldEntity.cc
r2213 r2254 76 76 delete (*it); 77 77 78 if (this->parent_) 79 this->detachFromParent(); 80 78 81 if (this->getScene()->getSceneManager()) 79 82 this->getScene()->getSceneManager()->destroySceneNode(this->node_->getName()); … … 100 103 void WorldEntity::registerVariables() 101 104 { 105 REGISTERSTRING(this->mainStateName_, direction::toclient, new NetworkCallback<WorldEntity>(this, &WorldEntity::changedMainState)); 106 102 107 REGISTERDATA(this->bActive_, direction::toclient, new NetworkCallback<WorldEntity>(this, &WorldEntity::changedActivity)); 103 108 REGISTERDATA(this->bVisible_, direction::toclient, new NetworkCallback<WorldEntity>(this, &WorldEntity::changedVisibility)); … … 122 127 void WorldEntity::attach(WorldEntity* object) 123 128 { 129 if (object == this) 130 { 131 COUT(2) << "Warning: Can't attach a WorldEntity to itself." << std::endl; 132 return; 133 } 134 124 135 if (object->getParent()) 125 136 object->detachFromParent(); -
code/branches/objecthierarchy2/src/orxonox/objects/worldentities/pawns/SpaceShip.cc
r2171 r2254 32 32 #include "core/CoreIncludes.h" 33 33 #include "core/ConfigValueIncludes.h" 34 #include "core/Template.h" 34 35 #include "core/XMLPort.h" 35 36 #include "util/Math.h" 37 #include "objects/items/Engine.h" 36 38 37 39 namespace orxonox … … 45 47 this->zeroDegree_ = 0; 46 48 47 this->maxSpeed_ = 0; 48 this->maxSecondarySpeed_ = 0; 49 this->bBoost_ = false; 50 this->steering_ = Vector3::ZERO; 51 this->engine_ = 0; 52 49 53 this->maxRotation_ = 0; 50 this->translationAcceleration_ = 0;51 54 this->rotationAcceleration_ = 0; 52 55 this->translationDamping_ = 0; … … 66 69 SpaceShip::~SpaceShip() 67 70 { 71 if (this->isInitialized() && this->engine_) 72 delete this->engine_; 68 73 } 69 74 … … 72 77 SUPER(SpaceShip, XMLPort, xmlelement, mode); 73 78 74 XMLPortParam(SpaceShip, "maxspeed", setMaxSpeed, getMaxSpeed, xmlelement, mode); 75 XMLPortParam(SpaceShip, "maxsecondaryspeed", setMaxSecondarySpeed, getMaxSecondarySpeed, xmlelement, mode); 79 XMLPortParam(SpaceShip, "engine", setEngineTemplate, getEngineTemplate, xmlelement, mode); 76 80 XMLPortParam(SpaceShip, "maxrotation", setMaxRotation, getMaxRotation, xmlelement, mode); 77 XMLPortParam(SpaceShip, "transacc", setTransAcc, getTransAcc, xmlelement, mode);78 81 XMLPortParam(SpaceShip, "rotacc", setRotAcc, getRotAcc, xmlelement, mode); 79 82 XMLPortParam(SpaceShip, "transdamp", setTransDamp, getTransDamp, xmlelement, mode); … … 82 85 void SpaceShip::registerVariables() 83 86 { 84 REGISTERDATA(this->maxSpeed_, direction::toclient);85 REGISTERDATA(this->maxSecondarySpeed_, direction::toclient);86 87 REGISTERDATA(this->maxRotation_, direction::toclient); 87 REGISTERDATA(this->translationAcceleration_, direction::toclient);88 88 REGISTERDATA(this->rotationAcceleration_, direction::toclient); 89 89 REGISTERDATA(this->translationDamping_, direction::toclient); … … 97 97 void SpaceShip::tick(float dt) 98 98 { 99 if (this-> isLocallyControlled())99 if (this->hasLocalController()) 100 100 { 101 101 // ##################################### … … 104 104 105 105 Vector3 velocity = this->getVelocity(); 106 if (velocity.x > this->maxSecondarySpeed_)107 velocity.x = this->maxSecondarySpeed_;108 if (velocity.x < -this->maxSecondarySpeed_)109 velocity.x = -this->maxSecondarySpeed_;110 if (velocity.y > this->maxSecondarySpeed_)111 velocity.y = this->maxSecondarySpeed_;112 if (velocity.y < -this->maxSecondarySpeed_)113 velocity.y = -this->maxSecondarySpeed_;114 if (velocity.z > this->maxSecondarySpeed_)115 velocity.z = this->maxSecondarySpeed_;116 if (velocity.z < -this->maxSpeed_)117 velocity.z = -this->maxSpeed_;118 106 119 107 // normalize velocity and acceleration … … 144 132 145 133 146 if (this-> isLocallyControlled())134 if (this->hasLocalController()) 147 135 { 148 136 this->yaw(this->yawRotation_ * dt); … … 153 141 this->roll(this->rollRotation_ * dt); 154 142 155 this->acceleration_.x = 0;156 this->acceleration_.y = 0;157 this->acceleration_.z = 0;158 159 143 this->yawRotation_ = this->zeroDegree_; 160 144 this->pitchRotation_ = this->zeroDegree_; … … 165 149 void SpaceShip::moveFrontBack(const Vector2& value) 166 150 { 167 this-> acceleration_.z = -this->translationAcceleration_ *value.x;151 this->steering_.z = -value.x; 168 152 } 169 153 170 154 void SpaceShip::moveRightLeft(const Vector2& value) 171 155 { 172 this-> acceleration_.x = this->translationAcceleration_ *value.x;156 this->steering_.x = value.x; 173 157 } 174 158 175 159 void SpaceShip::moveUpDown(const Vector2& value) 176 160 { 177 this-> acceleration_.y = this->translationAcceleration_ *value.x;161 this->steering_.y = value.x; 178 162 } 179 163 … … 211 195 { 212 196 } 197 198 void SpaceShip::boost() 199 { 200 this->bBoost_ = true; 201 } 202 203 void SpaceShip::loadEngineTemplate() 204 { 205 if (this->enginetemplate_ != "") 206 { 207 Template* temp = Template::getTemplate(this->enginetemplate_); 208 209 if (temp) 210 { 211 Identifier* identifier = temp->getBaseclassIdentifier(); 212 213 if (identifier) 214 { 215 BaseObject* object = identifier->fabricate(this); 216 this->engine_ = dynamic_cast<Engine*>(object); 217 218 if (this->engine_) 219 { 220 this->engine_->addTemplate(temp); 221 this->engine_->addToSpaceShip(this); 222 } 223 else 224 { 225 delete object; 226 } 227 } 228 } 229 } 230 } 213 231 } -
code/branches/objecthierarchy2/src/orxonox/objects/worldentities/pawns/SpaceShip.h
r2087 r2254 56 56 57 57 virtual void fire(); 58 virtual void boost(); 58 59 59 void setMaxSpeed(float value)60 { this->maxSpeed_ = value; }61 void setMaxSecondarySpeed(float value)62 { this->maxSecondarySpeed_ = value; }63 60 void setMaxRotation(const Degree& value) 64 61 { this->maxRotation_ = value; } 65 void setTransAcc(float value)66 { this->translationAcceleration_ = value; }67 62 void setRotAcc(const Degree& value) 68 63 { this->rotationAcceleration_ = value; } … … 70 65 { this->translationDamping_ = value; } 71 66 72 inline float getMaxSpeed() const73 { return this->maxSpeed_; }74 inline float getMaxSecondarySpeed() const75 { return this->maxSecondarySpeed_; }76 67 inline float getMaxRotation() const 77 68 { return this->maxRotation_.valueDegrees(); } 78 inline float getTransAcc() const79 { return this->translationAcceleration_; }80 69 inline float getRotAcc() const 81 70 { return this->rotationAcceleration_.valueDegrees(); } … … 83 72 { return this->translationDamping_; } 84 73 74 inline void setSteeringDirection(const Vector3& direction) 75 { this->steering_ = direction; } 76 inline const Vector3& getSteeringDirection() const 77 { return this->steering_; } 78 79 inline void setBoost(bool bBoost) 80 { this->bBoost_ = bBoost; } 81 inline bool getBoost() const 82 { return this->bBoost_; } 83 84 inline void setEngineTemplate(const std::string& temp) 85 { this->enginetemplate_ = temp; this->loadEngineTemplate(); } 86 inline const std::string& getEngineTemplate() const 87 { return this->enginetemplate_; } 88 85 89 protected: 86 90 bool bInvertYAxis_; 87 91 88 float maxSpeed_; 89 float maxSecondarySpeed_; 90 float translationAcceleration_; 92 bool bBoost_; 93 Vector3 steering_; 91 94 float translationDamping_; 92 95 … … 98 101 Degree yawRotation_; 99 102 Degree rollRotation_; 103 104 private: 105 void loadEngineTemplate(); 106 107 std::string enginetemplate_; 108 Engine* engine_; 100 109 }; 101 110 } -
code/branches/objecthierarchy2/src/orxonox/objects/worldentities/pawns/Spectator.cc
r2171 r2254 106 106 this->updateHUD(); 107 107 108 if (this-> isLocallyControlled())108 if (this->hasLocalController()) 109 109 { 110 110 Vector3 velocity = this->getVelocity(); … … 121 121 SUPER(Spectator, tick, dt); 122 122 123 if (this-> isLocallyControlled())123 if (this->hasLocalController()) 124 124 { 125 125 this->setVelocity(Vector3::ZERO); … … 134 134 } 135 135 136 void Spectator::startLocal Control()137 { 138 ControllableEntity::startLocal Control();139 // if (this-> isLocallyControlled())136 void Spectator::startLocalHumanControl() 137 { 138 ControllableEntity::startLocalHumanControl(); 139 // if (this->hasLocalController()) 140 140 // this->testmesh_->setVisible(false); 141 141 } -
code/branches/objecthierarchy2/src/orxonox/objects/worldentities/pawns/Spectator.h
r2087 r2254 46 46 47 47 virtual void setPlayer(PlayerInfo* player); 48 virtual void startLocal Control();48 virtual void startLocalHumanControl(); 49 49 50 50 virtual void moveFrontBack(const Vector2& value);
Note: See TracChangeset
for help on using the changeset viewer.