Changeset 1993 for code/branches/objecthierarchy/src/orxonox
- Timestamp:
- Oct 22, 2008, 5:25:01 AM (16 years ago)
- Location:
- code/branches/objecthierarchy/src/orxonox
- Files:
-
- 10 added
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchy/src/orxonox/CMakeLists.txt
r1989 r1993 47 47 objects/worldentities/MovableEntity.cc 48 48 objects/worldentities/ControllableEntity.cc 49 50 objects/worldentities/Model.cc 51 49 52 # objects/Backlight.cc 50 53 objects/Camera.cc … … 59 62 objects/Trigger.cc 60 63 objects/DistanceTrigger.cc 64 65 objects/worldentities/pawns/Spectator.cc 66 67 objects/controllers/Controller.cc 68 objects/controllers/HumanController.cc 61 69 62 70 objects/infos/Info.cc -
code/branches/objecthierarchy/src/orxonox/OrxonoxPrereqs.h
r1989 r1993 86 86 class ControllableEntity; 87 87 88 class Model; 89 90 class Spectator; 91 92 class Controller; 93 class HumanController; 94 88 95 class Backlight; 89 96 class Camera; -
code/branches/objecthierarchy/src/orxonox/objects/Camera.cc
r1989 r1993 47 47 namespace orxonox 48 48 { 49 CreateUnloadableFactory(Camera); 50 49 51 Camera::Camera() 50 52 { … … 68 70 void Camera::tick(float dt) 69 71 { 72 SUPER(Camera, tick, dt); 73 70 74 // this stuff here may need some adjustments 71 75 float coeff = (this->bDrag_) ? min(1.0f, 15.0f * dt) : (1.0f); -
code/branches/objecthierarchy/src/orxonox/objects/Camera.h
r1989 r1993 36 36 #include "OrxonoxPrereqs.h" 37 37 #include "objects/worldentities/PositionableEntity.h" 38 #include "objects/Tickable.h" 38 39 39 40 namespace orxonox 40 41 { 41 class _OrxonoxExport Camera : public PositionableEntity 42 class _OrxonoxExport Camera : public PositionableEntity//, public Tickable 42 43 { 43 44 friend class CameraHandler; 45 44 46 public: 45 47 Camera(); 46 48 virtual ~Camera(); 47 49 48 v oid tick(float dt);50 virtual void tick(float dt); 49 51 void update(); 50 52 -
code/branches/objecthierarchy/src/orxonox/objects/CameraHandler.h
r1505 r1993 44 44 #include "core/BaseObject.h" 45 45 46 #include "Camera.h"47 48 46 namespace orxonox 49 47 { -
code/branches/objecthierarchy/src/orxonox/objects/gametypes/Gametype.cc
r1989 r1993 33 33 #include "core/ConsoleCommand.h" 34 34 #include "objects/infos/PlayerInfo.h" 35 #include "objects/worldentities/pawns/Spectator.h" 35 36 36 37 #include "network/Host.h" … … 46 47 RegisterObject(Gametype); 47 48 49 this->defaultPawn_ = Class(Spectator); 48 50 this->getConnectedClients(); 49 51 -
code/branches/objecthierarchy/src/orxonox/objects/infos/PlayerInfo.cc
r1989 r1993 42 42 #include "objects/gametypes/Gametype.h" 43 43 #include "objects/worldentities/ControllableEntity.h" 44 #include "objects/controllers/HumanController.h" 44 45 45 46 namespace orxonox … … 53 54 this->ping_ = -1; 54 55 this->clientID_ = network::CLIENTID_UNKNOWN; 55 this->bLocalPlayer_ = Core::isStandalone();56 56 this->bLocalPlayer_ = false; 57 57 this->bHumanPlayer_ = false; … … 60 60 this->pawn_ = 0; 61 61 this->pawnID_ = network::OBJECTID_UNKNOWN; 62 this->controller_ = 0; 63 this->setDefaultController(Class(HumanController)); 62 64 63 65 this->setConfigValues(); 64 66 this->registerVariables(); 65 66 //COUT(0) << "created PlayerInfo (" << this->getObjectID() << ")" << std::endl;67 67 } 68 68 69 69 PlayerInfo::~PlayerInfo() 70 70 { 71 Gametype* gametype = Gametype::getCurrentGametype(); 72 if (gametype) 73 gametype->removePlayer(this); 74 //COUT(0) << "destroyed PlayerInfo (" << this->getObjectID() << ")" << std::endl; 71 if (this->isInitialized()) 72 { 73 Gametype* gametype = Gametype::getCurrentGametype(); 74 if (gametype) 75 gametype->removePlayer(this); 76 77 if (this->controller_) 78 delete this->controller_; 79 80 if (this->pawn_) 81 this->pawn_->removePlayer(); 82 } 75 83 } 76 84 … … 82 90 void PlayerInfo::checkNick() 83 91 { 84 //std::cout << "# PI(" << this->getObjectID() << "): checkName: " << this->bLocalPlayer_ << std::endl;85 92 if (this->bLocalPlayer_) 86 93 { … … 94 101 void PlayerInfo::changedName() 95 102 { 96 //std::cout << "# PI(" << this->getObjectID() << "): changedName to " << this->getName() << std::endl;97 103 Gametype* gametype = Gametype::getCurrentGametype(); 98 104 if (gametype) … … 113 119 void PlayerInfo::clientChangedName() 114 120 { 115 //std::cout << "# PI(" << this->getObjectID() << "): clientChangedName() from " << this->getName() << " to " << this->playerName_ << std::endl;116 121 this->setName(this->playerName_); 117 122 } … … 119 124 void PlayerInfo::checkClientID() 120 125 { 121 //std::cout << "# PI(" << this->getObjectID() << "): checkClientID()" << std::endl;122 126 this->bHumanPlayer_ = true; 123 127 124 128 if (this->clientID_ == network::Host::getPlayerID()) 125 129 { 126 //std::cout << "# PI(" << this->getObjectID() << "): checkClientID(): it's the client's ID" << std::endl; 127 this->bLocalPlayer_ = true; 128 this->playerName_ = this->nick_; 129 //std::cout << "# PI(" << this->getObjectID() << "): checkClientID(): name: " << this->getName() << std::endl; 130 this->takeLocalControl(); 130 131 131 132 if (Core::isClient()) 132 {133 //std::cout << "# PI(" << this->getObjectID() << "): checkClientID(): we're on a client: set object mode to bidirectional" << std::endl;134 133 this->setObjectMode(network::direction::bidirectional); 135 //std::cout << "# PI(" << this->getObjectID() << "): checkClientID(): proposed name: " << this->playerName_ << std::endl;136 }137 134 else 138 135 { 139 //std::cout << "# PI(" << this->getObjectID() << "): checkClientID(): we're not on a client: finish setup" << std::endl;140 136 this->clientChangedName(); 141 137 this->bFinishedSetup_ = true; … … 147 143 void PlayerInfo::finishedSetup() 148 144 { 149 //std::cout << "# PI(" << this->getObjectID() << "): finishedSetup(): " << this->bFinishedSetup_ << std::endl;150 145 if (Core::isClient()) 151 {152 //std::cout << "# PI(" << this->getObjectID() << "): finishedSetup(): we're a client: finish setup" << std::endl;153 146 this->bFinishedSetup_ = true; 154 }155 147 else if (this->bFinishedSetup_) 156 148 { 157 //std::cout << "# PI(" << this->getObjectID() << "): finishedSetup(): we're a server: add player" << std::endl;158 149 Gametype* gametype = Gametype::getCurrentGametype(); 159 150 if (gametype) 160 151 gametype->addPlayer(this); 161 }162 else163 {164 //std::cout << "# PI(" << this->getObjectID() << "): finishedSetup(): we're a server: client not yet finished" << std::endl;165 152 } 166 153 } … … 171 158 this->pawn_ = pawn; 172 159 this->pawnID_ = pawn->getObjectID(); 160 161 if (this->controller_) 162 this->controller_->setPawn(this->pawn_); 173 163 } 174 164 … … 180 170 } 181 171 172 void PlayerInfo::takeLocalControl() 173 { 174 this->bLocalPlayer_ = true; 175 this->playerName_ = this->nick_; 176 this->createController(); 177 } 178 179 void PlayerInfo::createController() 180 { 181 this->controller_ = this->defaultController_.fabricate(); 182 this->controller_->setPawn(this->pawn_); 183 } 184 182 185 void PlayerInfo::updatePawn() 183 186 { -
code/branches/objecthierarchy/src/orxonox/objects/infos/PlayerInfo.h
r1989 r1993 33 33 34 34 #include "Info.h" 35 #include "core/Identifier.h" 36 #include "objects/controllers/Controller.h" 35 37 36 38 namespace orxonox … … 58 60 { return this->bLocalPlayer_; } 59 61 60 v oid startControl(ControllableEntity* pawn);61 v oid stopControl();62 virtual void startControl(ControllableEntity* pawn); 63 virtual void stopControl(); 62 64 63 65 inline ControllableEntity* getPawn() const 64 66 { return this->pawn_; } 67 /* 68 inline void setController(Controller* controller) 69 { this->controller_ = controller; } 70 inline Controller* getController() const 71 { return this->controller_; } 72 */ 73 protected: 74 inline void setDefaultController(Identifier* identifier) 75 { this->defaultController_ = identifier; } 65 76 66 77 private: 78 virtual void createController(); 79 virtual void takeLocalControl(); 80 67 81 void checkClientID(); 68 82 void finishedSetup(); … … 82 96 ControllableEntity* pawn_; 83 97 unsigned int pawnID_; 98 Controller* controller_; 99 SubclassIdentifier<Controller> defaultController_; 84 100 }; 85 101 } -
code/branches/objecthierarchy/src/orxonox/objects/worldentities/ControllableEntity.cc
r1989 r1993 53 53 this->hud_ = 0; 54 54 this->camera_ = 0; 55 55 this->bDestroyWhenPlayerLeft_ = false; 56 56 57 57 this->velocity_ = Vector3::ZERO; … … 94 94 95 95 if (this->bControlled_) 96 { 96 97 this->startLocalControl(); 98 this->setObjectMode(network::direction::bidirectional); 99 } 97 100 } 98 101 … … 105 108 this->playerID_ = network::OBJECTID_UNKNOWN; 106 109 this->bControlled_ = false; 110 this->setObjectMode(network::direction::toclient); 111 112 if (this->bDestroyWhenPlayerLeft_) 113 delete this; 107 114 } 108 115 109 116 void ControllableEntity::updatePlayer() 110 117 { 111 this->player_ = dynamic_cast<PlayerInfo*>(network::Synchronisable::getSynchronisable(this->playerID_)); 112 if (this->player_ && (this->player_->getPawn() != this)) 113 this->player_->startControl(this); 118 if (this->playerID_ != network::OBJECTID_UNKNOWN) 119 { 120 this->player_ = dynamic_cast<PlayerInfo*>(network::Synchronisable::getSynchronisable(this->playerID_)); 121 if (this->player_ && (this->player_->getPawn() != this)) 122 this->player_->startControl(this); 123 } 114 124 } 115 125 116 126 void ControllableEntity::startLocalControl() 117 127 { 128 std::cout << "###### start local control" << std::endl; 118 129 this->camera_ = new Camera(); 119 130 this->camera_->requestFocus(); 120 121 this->hud_ = new OverlayGroup(); 122 this->hud_->addTemplate(this->hudtemplate_); 131 this->attach(this->camera_); 132 133 if (this->hudtemplate_ != "") 134 { 135 this->hud_ = new OverlayGroup(); 136 this->hud_->addTemplate(this->hudtemplate_); 137 } 123 138 } 124 139 125 140 void ControllableEntity::stopLocalControl() 126 141 { 142 std::cout << "###### stop local control" << std::endl; 143 this->detach(this->camera_); 127 144 delete this->camera_; 128 145 this->camera_ = 0; … … 137 154 { 138 155 this->velocity_ += (dt * this->acceleration_); 139 this->node_->translate(dt * this->velocity_ );156 this->node_->translate(dt * this->velocity_, Ogre::Node::TS_PARENT); 140 157 141 158 if (Core::isMaster()) … … 150 167 } 151 168 } 152 153 // std::cout << this->getPosition() << std::endl;154 169 } 155 170 -
code/branches/objecthierarchy/src/orxonox/objects/worldentities/ControllableEntity.h
r1989 r1993 52 52 { return this->player_; } 53 53 54 inline void setDestroyWhenPlayerLeft(bool bDestroy) 55 { this->bDestroyWhenPlayerLeft_ = bDestroy; } 56 inline bool getDestroyWhenPlayerLeft() const 57 { return this->bDestroyWhenPlayerLeft_; } 58 54 59 virtual void startLocalControl(); 55 60 virtual void stopLocalControl(); … … 70 75 virtual void switchCamera() {} 71 76 77 inline const Vector3& getVelocity() const 78 { return this->velocity_; } 79 inline const Vector3& getAcceleration() const 80 { return this->acceleration_; } 81 inline const std::string& getHudTemplate() const 82 { return this->hudtemplate_; } 83 72 84 protected: 73 85 using WorldEntity::setPosition; … … 75 87 using WorldEntity::setOrientation; 76 88 using WorldEntity::rotate; 89 using WorldEntity::yaw; 90 using WorldEntity::pitch; 91 using WorldEntity::roll; 77 92 using WorldEntity::lookAt; 78 93 using WorldEntity::setDirection; … … 91 106 inline void setVelocity(float x, float y, float z) 92 107 { this->velocity_.x = x; this->velocity_.y = y; this->velocity_.z = z; } 93 inline const Vector3& getVelocity() const94 { return this->velocity_; }95 108 96 109 inline void setAcceleration(const Vector3& acceleration) … … 98 111 inline void setAcceleration(float x, float y, float z) 99 112 { this->acceleration_.x = x; this->acceleration_.y = y; this->acceleration_.z = z; } 100 inline const Vector3& getAcceleration() const 101 { return this->acceleration_; } 113 114 inline void setHudTemplate(const std::string& name) 115 { this->hudtemplate_ = name; } 102 116 103 117 private: 104 inline void setHudTemplate(const std::string& name)105 { this->hudtemplate_ = name; }106 inline const std::string& getHudTemplate() const107 { return this->hudtemplate_; }108 109 118 void overwrite(); 110 119 void processOverwrite(); … … 139 148 OverlayGroup* hud_; 140 149 Camera* camera_; 150 bool bDestroyWhenPlayerLeft_; 141 151 }; 142 152 } -
code/branches/objecthierarchy/src/orxonox/objects/worldentities/MovableEntity.cc
r1989 r1993 79 79 this->node_->rotate(this->rotationAxis_, this->rotationRate_ * dt); 80 80 } 81 82 std::cout << this->getPosition() << std::endl;83 81 } 84 82 -
code/branches/objecthierarchy/src/orxonox/objects/worldentities/MovableEntity.h
r1989 r1993 52 52 using WorldEntity::setOrientation; 53 53 using WorldEntity::rotate; 54 using WorldEntity::yaw; 55 using WorldEntity::pitch; 56 using WorldEntity::roll; 54 57 using WorldEntity::lookAt; 55 58 using WorldEntity::setDirection; -
code/branches/objecthierarchy/src/orxonox/objects/worldentities/PositionableEntity.cc
r1960 r1993 57 57 REGISTERDATA(this->getOrientation().z, network::direction::toclient); 58 58 } 59 60 void PositionableEntity::tick(float dt) 61 { 62 // I don't know why but this has to be done to update the position if attached to another Entity 63 this->node_->translate(Vector3::ZERO); 64 std::cout << this->getWorldPosition() << std::endl; 65 } 59 66 } -
code/branches/objecthierarchy/src/orxonox/objects/worldentities/PositionableEntity.h
r1989 r1993 32 32 #include "OrxonoxPrereqs.h" 33 33 #include "WorldEntity.h" 34 #include "objects/Tickable.h" 34 35 35 36 namespace orxonox 36 37 { 37 class _OrxonoxExport PositionableEntity : public WorldEntity 38 class _OrxonoxExport PositionableEntity : public WorldEntity, public Tickable 38 39 { 39 40 public: … … 42 43 43 44 void registerVariables(); 45 virtual void tick(float dt); 44 46 45 47 using WorldEntity::setPosition; … … 47 49 using WorldEntity::setOrientation; 48 50 using WorldEntity::rotate; 51 using WorldEntity::yaw; 52 using WorldEntity::pitch; 53 using WorldEntity::roll; 49 54 using WorldEntity::lookAt; 50 55 using WorldEntity::setDirection; -
code/branches/objecthierarchy/src/orxonox/objects/worldentities/WorldEntity.cc
r1989 r1993 34 34 #include "core/CoreIncludes.h" 35 35 #include "core/XMLPort.h" 36 #include "util/Convert.h" 36 37 37 38 #include "GraphicsEngine.h" … … 110 111 if (object->getParent()) 111 112 object->detachFromParent(); 113 else 114 { 115 Ogre::Node* parent = object->node_->getParent(); 116 if (parent) 117 parent->removeChild(object->node_); 118 } 112 119 113 120 this->node_->addChild(object->node_); … … 123 130 object->parent_ = 0; 124 131 object->parentID_ = (unsigned int)-1; 132 133 GraphicsEngine::getInstance().getLevelSceneManager()->getRootSceneNode()->addChild(object->node_); 125 134 } 126 135 -
code/branches/objecthierarchy/src/orxonox/overlays/OverlayGroup.cc
r1854 r1993 100 100 } 101 101 else 102 { 102 103 hudElements_[element->getName()] = element; 104 element->setVisible(this->isVisible()); 105 } 103 106 } 104 107 -
code/branches/objecthierarchy/src/orxonox/overlays/OverlayText.cc
r1784 r1993 31 31 32 32 #include <OgreOverlayManager.h> 33 #include <OgreTextAreaOverlayElement.h>34 33 #include <OgrePanelOverlayElement.h> 35 34 … … 68 67 69 68 XMLPortParam(OverlayText, "font", setFont, getFont, xmlElement, mode).defaultValues("Monofur"); 69 XMLPortParam(OverlayText, "colour", setColour, getColour, xmlElement, mode).defaultValues(ColourValue(1.0, 1.0, 1.0, 1.0)); 70 70 XMLPortParam(OverlayText, "caption", setCaption, getCaption, xmlElement, mode).defaultValues(""); 71 71 XMLPortParam(OverlayText, "textSize", setTextSize, getTextSize, xmlElement, mode).defaultValues(1.0f); 72 XMLPortParamTemplate(OverlayText, "align", setAlignment, getAlignment, xmlElement, mode, const std::string&).defaultValues("left"); 72 73 } 73 74 … … 84 85 else 85 86 return blankString; 87 } 88 89 void OverlayText::setColour(const ColourValue& colour) 90 { 91 if (this->text_) 92 this->text_->setColour(colour); 93 } 94 95 const ColourValue& OverlayText::getColour() const 96 { 97 if (this->text_) 98 return this->text_->getColour(); 99 else 100 return ColourValue::White; 101 } 102 103 void OverlayText::setAlignment(Ogre::TextAreaOverlayElement::Alignment alignment) 104 { 105 if (this->text_) 106 this->text_->setAlignment(alignment); 107 } 108 109 void OverlayText::setAlignment(const std::string& alignment) 110 { 111 if (alignment == "right") 112 this->setAlignment(Ogre::TextAreaOverlayElement::Right); 113 else if (alignment == "center") 114 this->setAlignment(Ogre::TextAreaOverlayElement::Center); 115 else // "left" and default 116 this->setAlignment(Ogre::TextAreaOverlayElement::Left); 117 } 118 119 std::string OverlayText::getAlignment() const 120 { 121 if (this->text_) 122 { 123 Ogre::TextAreaOverlayElement::Alignment alignment = this->text_->getAlignment(); 124 125 switch (alignment) 126 { 127 case Ogre::TextAreaOverlayElement::Right: 128 return "right"; 129 case Ogre::TextAreaOverlayElement::Center: 130 return "center"; 131 case Ogre::TextAreaOverlayElement::Left: 132 default:; 133 } 134 } 135 return "left"; 136 } 137 138 void OverlayText::setCaption(const std::string& caption) 139 { 140 this->caption_ = caption; 141 this->text_->setCaption(caption); 86 142 } 87 143 -
code/branches/objecthierarchy/src/orxonox/overlays/OverlayText.h
r1625 r1993 34 34 #include <string> 35 35 #include <OgrePrerequisites.h> 36 #include <OgreTextAreaOverlayElement.h> 36 37 #include "OrxonoxOverlay.h" 37 38 … … 49 50 virtual void sizeChanged(); 50 51 51 void setCaption(const std::string& caption) { this->caption_ = caption; }52 void setCaption(const std::string& caption); 52 53 const std::string& getCaption() const { return this->caption_; } 53 54 54 55 void setFont(const std::string& font); 55 56 const std::string& getFont() const; 57 58 void setColour(const ColourValue& colour); 59 const ColourValue& getColour() const; 60 61 void setAlignment(Ogre::TextAreaOverlayElement::Alignment alignment); 62 void setAlignment(const std::string& alignment); 63 std::string getAlignment() const; 56 64 57 65 void setTextSize(float size) { this->setSize(Vector2(size, size)); } -
code/branches/objecthierarchy/src/orxonox/overlays/hud/HUDNavigation.cc
r1916 r1993 41 41 #include "core/XMLPort.h" 42 42 #include "objects/Radar.h" 43 #include "objects/CameraHandler.h"44 43 45 44 namespace orxonox -
code/branches/objecthierarchy/src/orxonox/tools/Mesh.cc
r1949 r1993 32 32 #include <sstream> 33 33 #include <OgreSceneManager.h> 34 34 35 #include "core/Core.h" 35 36 #include "GraphicsEngine.h" 37 #include "util/Convert.h" 38 #include "util/String.h" 36 39 37 40 namespace orxonox … … 39 42 unsigned int Mesh::meshCounter_s = 0; 40 43 41 Mesh::Mesh() : 42 entity_(0) 44 Mesh::Mesh() 43 45 { 44 } 45 46 void Mesh::setMesh(const std::string& file) 47 { 48 std::ostringstream name; 49 name << (Mesh::meshCounter_s++); 50 if (Core::showsGraphics()) 51 this->entity_ = GraphicsEngine::getInstance().getLevelSceneManager()->createEntity("Mesh" + name.str(), file); 46 this->entity_ = 0; 52 47 } 53 48 … … 57 52 GraphicsEngine::getInstance().getLevelSceneManager()->destroyEntity(this->entity_); 58 53 } 54 55 void Mesh::setMeshSource(const std::string& meshsource) 56 { 57 if (Core::showsGraphics()) 58 { 59 if (this->entity_) 60 GraphicsEngine::getInstance().getLevelSceneManager()->destroyEntity(this->entity_); 61 this->entity_ = GraphicsEngine::getInstance().getLevelSceneManager()->createEntity("Mesh" + convertToString(Mesh::meshCounter_s++), meshsource); 62 } 63 } 64 65 const std::string& Mesh::getName() const 66 { 67 if (this->entity_) 68 return this->entity_->getName(); 69 else 70 return blankString; 71 } 72 73 void Mesh::setVisible(bool bVisible) 74 { 75 if (this->entity_) 76 this->entity_->setVisible(bVisible); 77 } 78 79 bool Mesh::isVisible() const 80 { 81 if (this->entity_) 82 return this->entity_->getVisible(); 83 else 84 return false; 85 } 59 86 } -
code/branches/objecthierarchy/src/orxonox/tools/Mesh.h
r1627 r1993 33 33 34 34 #include <string> 35 36 35 #include <OgreEntity.h> 37 36 … … 43 42 Mesh(); 44 43 ~Mesh(); 45 void setMesh(const std::string& file); 44 45 void setMeshSource(const std::string& file); 46 46 47 47 inline Ogre::Entity* getEntity() 48 48 { return this->entity_; } 49 49 50 inline const std::string& getName() const 51 { return this->entity_->getName(); } 50 const std::string& getName() const; 52 51 53 inline void setVisible(bool visible) 54 { if (this->entity_) this->entity_->setVisible(visible); } 55 inline bool getVisible() const 56 { if (this->entity_) return this->entity_->getVisible(); else return false; } 52 void setVisible(bool bVisible); 53 bool isVisible() const; 57 54 58 55 private:
Note: See TracChangeset
for help on using the changeset viewer.