Changeset 2087 for code/trunk
- Timestamp:
- Nov 1, 2008, 7:04:09 PM (16 years ago)
- Location:
- code/trunk
- Files:
-
- 37 deleted
- 207 edited
- 95 copied
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/TODO
r1907 r2087 1 1 todo: 2 3 bidirectional 4 5 minimize synchronisableHeader 6 7 2 8 !!! check that enet does not cause a packet traffic jam when a reliable packet gets missed !!! 3 [implemented] new gamestate concept4 5 9 !!! ensure that objects get synched, when newly created, even if not their tick 6 10 … … 12 16 13 17 REMARKS: 14 try to allocatesort the bytestream before copy (putt all 0's in one place)18 try to sort the bytestream before copy (putt all 0's in one place) -
code/trunk/bin/def_keybindings.ini
r1887 r2087 1 1 [Keys] 2 KeyA="scale -1 move Lateral"2 KeyA="scale -1 moveRightLeft" 3 3 KeyABNT_C1= 4 4 KeyABNT_C2= … … 10 10 KeyBack= 11 11 KeyBackslash= 12 KeyC= 12 KeyC=switchCamera 13 13 KeyCalculator= 14 14 KeyCapsLock= … … 16 16 KeyComma= 17 17 KeyConvert= 18 KeyD="scale 1 move Lateral"18 KeyD="scale 1 moveRightLeft" 19 19 KeyDelete= 20 20 KeyDivide= 21 21 KeyDown= 22 KeyE="scale -1 moveRoll"22 KeyE="scale -1 rotateRoll" 23 23 KeyEnd= 24 24 KeyEquals= 25 25 KeyEscape="exit" 26 KeyF= 26 KeyF="scale -1 moveUpDown" 27 27 KeyF1="OverlayGroup toggleVisibility Debug" 28 28 KeyF10= … … 40 40 KeyF8= 41 41 KeyF9= 42 KeyG= 42 KeyG=greet 43 43 KeyGrave="openConsole" 44 44 KeyH= … … 105 105 KeyPower= 106 106 KeyPreviousTrack= 107 KeyQ="scale 1 moveRoll"108 KeyR= 107 KeyQ="scale 1 rotateRoll" 108 KeyR="scale 1 moveUpDown" 109 109 KeyReturn= 110 110 KeyRight= … … 114 114 KeyRightShift= 115 115 KeyRightWindows= 116 KeyS="scale -1 move Longitudinal"116 KeyS="scale -1 moveFrontBack" 117 117 KeyScrollLock= 118 118 KeySemicolon= … … 132 132 KeyVolumeDown= 133 133 KeyVolumeUp= 134 KeyW="scale 1 move Longitudinal"134 KeyW="scale 1 moveFrontBack" 135 135 KeyWake= 136 136 KeyWebBack= … … 254 254 255 255 [MouseAxes] 256 MouseXNeg="scale 1 moveYaw"257 MouseXPos="scale -1 moveYaw"258 MouseYNeg="scale 1 movePitch"259 MouseYPos="scale -1 movePitch"256 MouseXNeg="scale -1 rotateYaw" 257 MouseXPos="scale 1 rotateYaw" 258 MouseYNeg="scale 1 rotatePitch" 259 MouseYPos="scale -1 rotatePitch" 260 260 -
code/trunk/init/common/def_keybindings.ini
r1897 r2087 1 1 [Keys] 2 KeyA="scale -1 move Lateral"2 KeyA="scale -1 moveRightLeft" 3 3 KeyABNT_C1= 4 4 KeyABNT_C2= … … 16 16 KeyComma= 17 17 KeyConvert= 18 KeyD="scale 1 move Lateral"18 KeyD="scale 1 moveRightLeft" 19 19 KeyDelete= 20 20 KeyDivide= 21 21 KeyDown= 22 KeyE="scale -1 moveRoll"22 KeyE="scale -1 rotateRoll" 23 23 KeyEnd= 24 24 KeyEquals= 25 25 KeyEscape="exit" 26 KeyF= 26 KeyF="scale -1 moveUpDown" 27 27 KeyF1="OverlayGroup toggleVisibility Debug" 28 28 KeyF10= … … 40 40 KeyF8= 41 41 KeyF9= 42 KeyG= 42 KeyG=greet 43 43 KeyGrave="openConsole" 44 44 KeyH= … … 105 105 KeyPower= 106 106 KeyPreviousTrack= 107 KeyQ="scale 1 moveRoll"108 KeyR= 107 KeyQ="scale 1 rotateRoll" 108 KeyR="scale 1 moveUpDown" 109 109 KeyReturn= 110 110 KeyRight= … … 114 114 KeyRightShift= 115 115 KeyRightWindows= 116 KeyS="scale -1 move Longitudinal"116 KeyS="scale -1 moveFrontBack" 117 117 KeyScrollLock= 118 118 KeySemicolon= … … 132 132 KeyVolumeDown= 133 133 KeyVolumeUp= 134 KeyW="scale 1 move Longitudinal"134 KeyW="scale 1 moveFrontBack" 135 135 KeyWake= 136 136 KeyWebBack= … … 254 254 255 255 [MouseAxes] 256 MouseXNeg="scale 1 moveYaw"257 MouseXPos="scale -1 moveYaw"258 MouseYNeg="scale 1 movePitch"259 MouseYPos="scale -1 movePitch"256 MouseXNeg="scale -1 rotateYaw" 257 MouseXPos="scale 1 rotateYaw" 258 MouseYNeg="scale 1 rotatePitch" 259 MouseYPos="scale -1 rotatePitch" 260 260 -
code/trunk/src/core/ArgumentCompletionFunctions.cc
r1505 r2087 30 30 #include <map> 31 31 32 #include "boost/filesystem.hpp"32 #include <boost/filesystem.hpp> 33 33 34 34 #include "ArgumentCompletionFunctions.h" -
code/trunk/src/core/BaseObject.cc
r1625 r2087 35 35 #include "tinyxml/tinyxml.h" 36 36 #include "CoreIncludes.h" 37 #include "EventIncludes.h" 37 38 #include "XMLPort.h" 38 #include "Level.h" 39 #include "XMLFile.h" 40 #include "XMLNameListener.h" 41 #include "Template.h" 42 #include "util/String.h" 39 43 40 44 namespace orxonox … … 45 49 @brief Constructor: Registers the object in the BaseObject-list. 46 50 */ 47 BaseObject::BaseObject( ) : bInitialized_(false)51 BaseObject::BaseObject(BaseObject* creator) : bInitialized_(false) 48 52 { 49 53 RegisterRootObject(BaseObject); … … 53 57 this->bActive_ = true; 54 58 this->bVisible_ = true; 55 56 this->level_ = 0; 57 this->namespace_ = 0; 59 this->oldGametype_ = 0; 60 61 this->setCreator(creator); 62 if (this->creator_) 63 { 64 this->setFile(this->creator_->getFile()); 65 this->setNamespace(this->creator_->getNamespace()); 66 this->setScene(this->creator_->getScene()); 67 this->setGametype(this->creator_->getGametype()); 68 } 69 else 70 { 71 this->file_ = 0; 72 this->namespace_ = 0; 73 this->scene_ = 0; 74 this->gametype_ = 0; 75 } 58 76 } 59 77 … … 63 81 BaseObject::~BaseObject() 64 82 { 83 for (std::list<BaseObject*>::const_iterator it = this->events_.begin(); it != this->events_.end(); ++it) 84 (*it)->unregisterEventListener(this); 85 86 for (std::map<BaseObject*, std::string>::const_iterator it = this->eventListeners_.begin(); it != this->eventListeners_.end(); ++it) 87 it->first->removeEvent(this); 65 88 } 66 89 … … 73 96 void BaseObject::XMLPort(Element& xmlelement, XMLPort::Mode mode) 74 97 { 75 XMLPortParam(BaseObject, "name", set Name, getName, xmlelement, mode);98 XMLPortParam(BaseObject, "name", setXMLName, getName, xmlelement, mode); 76 99 XMLPortParam(BaseObject, "visible", setVisible, isVisible, xmlelement, mode); 77 100 XMLPortParam(BaseObject, "active", setActive, isActive, xmlelement, mode); 101 102 XMLPortObjectTemplate(BaseObject, Template, "templates", addTemplate, getTemplate, xmlelement, mode, Template*); 103 104 Element* events = xmlelement.FirstChildElement("events", false); 105 106 if (events) 107 { 108 std::list<std::string> eventnames; 109 110 if (mode == XMLPort::LoadObject) 111 { 112 for (ticpp::Iterator<ticpp::Element> child = events->FirstChildElement(false); child != child.end(); child++) 113 eventnames.push_back(child->Value()); 114 } 115 else if (mode == XMLPort::SaveObject) 116 { 117 for (std::map<std::string, XMLPortObjectContainer*>::const_iterator it = this->getIdentifier()->getXMLPortEventMapBegin(); it != this->getIdentifier()->getXMLPortEventMapEnd(); ++it) 118 eventnames.push_back(it->first); 119 } 120 121 for (std::list<std::string>::iterator it = eventnames.begin(); it != eventnames.end(); ++it) 122 { 123 std::string sectionname = (*it); 124 ExecutorMember<BaseObject>* loadexecutor = createExecutor(createFunctor(&BaseObject::addEvent), std::string( "BaseObject" ) + "::" + "addEvent"); 125 ExecutorMember<BaseObject>* saveexecutor = createExecutor(createFunctor(&BaseObject::getEvent), std::string( "BaseObject" ) + "::" + "getEvent"); 126 loadexecutor->setDefaultValue(1, sectionname); 127 128 XMLPortClassObjectContainer<BaseObject, BaseObject>* container = 0; 129 container = (XMLPortClassObjectContainer<BaseObject, BaseObject>*)(this->getIdentifier()->getXMLPortEventContainer(sectionname)); 130 if (!container) 131 { 132 container = new XMLPortClassObjectContainer<BaseObject, BaseObject>(sectionname, this->getIdentifier(), loadexecutor, saveexecutor, false, true); 133 this->getIdentifier()->addXMLPortEventContainer(sectionname, container); 134 } 135 container->port(this, *events, mode); 136 } 137 } 138 } 139 140 /** 141 @brief Loads the name of the object through XML and calls all XMLNameListener. 142 @param name The name of the object 143 */ 144 void BaseObject::setXMLName(const std::string& name) 145 { 146 this->setName(name); 147 148 for (ObjectList<XMLNameListener>::iterator it = ObjectList<XMLNameListener>::begin(); it != ObjectList<XMLNameListener>::end(); ++it) 149 it->loadedNewXMLName(this); 78 150 } 79 151 … … 82 154 @return The levelfile 83 155 */ 84 const std::string& BaseObject::getLevelfile() const 85 { 86 return this->level_->getFile(); 156 const std::string& BaseObject::getFilename() const 157 { 158 if (this->file_) 159 return this->file_->getFilename(); 160 else 161 return BLANKSTRING; 162 } 163 164 /** 165 @brief Adds a Template to the object. 166 @param name The name of the Template 167 */ 168 void BaseObject::addTemplate(const std::string& name) 169 { 170 Template* temp = Template::getTemplate(name); 171 if (temp) 172 this->addTemplate(temp); 173 else 174 COUT(1) << "Error: \"" << name << "\" is not a valid Template name (in class: " << this->getIdentifier()->getName() << ", name: " << this->getName() << ")." << std::endl; 175 } 176 177 /** 178 @brief Adds a Template to the object. 179 @param temp The Template 180 */ 181 void BaseObject::addTemplate(Template* temp) 182 { 183 this->templates_.insert(temp); 184 temp->applyOn(this); 185 } 186 187 /** 188 @brief Returns the Template with the given index. 189 @param index The index 190 */ 191 Template* BaseObject::getTemplate(unsigned int index) const 192 { 193 unsigned int i = 0; 194 for (std::set<Template*>::const_iterator it = this->templates_.begin(); it != this->templates_.end(); ++it) 195 { 196 if (i == index) 197 return (*it); 198 i++; 199 } 200 return 0; 201 } 202 203 void BaseObject::addEvent(BaseObject* event, const std::string& sectionname) 204 { 205 event->registerEventListener(this, sectionname); 206 this->events_.push_back(event); 207 } 208 209 void BaseObject::removeEvent(BaseObject* event) 210 { 211 this->events_.remove(event); 212 } 213 214 BaseObject* BaseObject::getEvent(unsigned int index) const 215 { 216 unsigned int i = 0; 217 for (std::list<BaseObject*>::const_iterator it = this->events_.begin(); it != this->events_.end(); ++it) 218 { 219 if (i == index) 220 return (*it); 221 ++i; 222 } 223 return 0; 224 } 225 226 void BaseObject::addEventContainer(const std::string& sectionname, EventContainer* container) 227 { 228 std::map<std::string, EventContainer*>::const_iterator it = this->eventContainers_.find(sectionname); 229 if (it != this->eventContainers_.end()) 230 { 231 COUT(2) << "Warning: Overwriting EventContainer in class " << this->getIdentifier()->getName() << "." << std::endl; 232 delete (it->second); 233 } 234 235 this->eventContainers_[sectionname] = container; 236 } 237 238 EventContainer* BaseObject::getEventContainer(const std::string& sectionname) const 239 { 240 std::map<std::string, EventContainer*>::const_iterator it = this->eventContainers_.find(sectionname); 241 if (it != this->eventContainers_.end()) 242 return ((*it).second); 243 else 244 return 0; 245 } 246 247 void BaseObject::fireEvent() 248 { 249 this->fireEvent(true); 250 this->fireEvent(false); 251 } 252 253 void BaseObject::fireEvent(bool activate) 254 { 255 this->fireEvent(activate, this); 256 } 257 258 void BaseObject::fireEvent(bool activate, BaseObject* originator) 259 { 260 Event event(activate, originator); 261 262 for (std::map<BaseObject*, std::string>::iterator it = this->eventListeners_.begin(); it != this->eventListeners_.end(); ++it) 263 { 264 event.sectionname_ = it->second; 265 it->first->processEvent(event); 266 } 267 } 268 269 void BaseObject::fireEvent(Event& event) 270 { 271 for (std::map<BaseObject*, std::string>::iterator it = this->eventListeners_.begin(); it != this->eventListeners_.end(); ++it) 272 it->first->processEvent(event); 273 } 274 275 void BaseObject::processEvent(Event& event) 276 { 277 SetEvent(BaseObject, "activity", setActive, event); 278 SetEvent(BaseObject, "visibility", setVisible, event); 87 279 } 88 280 } -
code/trunk/src/core/BaseObject.h
r1841 r2087 37 37 #define _BaseObject_H__ 38 38 39 #include <map> 40 39 41 #include "CorePrereqs.h" 40 42 … … 42 44 #include "OrxonoxClass.h" 43 45 #include "XMLIncludes.h" 46 #include "Event.h" 44 47 45 48 namespace orxonox 46 49 { 50 class Scene; 51 class Gametype; 52 47 53 //! The BaseObject is the parent of all classes representing an instance in the game. 48 54 class _CoreExport BaseObject : virtual public OrxonoxClass 49 55 { 50 friend class WorldEntity;51 52 56 public: 53 BaseObject( );57 BaseObject(BaseObject* creator); 54 58 virtual ~BaseObject(); 55 59 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); … … 59 63 60 64 /** @brief Sets the name of the object. @param name The name */ 61 inline void setName(const std::string& name) { this-> name_ = name; this->changedName(); }62 /** @brief Returns the name of the object. @return The name*/65 inline void setName(const std::string& name) { this->oldName_ = this->name_; this->name_ = name; this->changedName(); } 66 /** @brief Returns the name of the object. */ 63 67 inline const std::string& getName() const { return this->name_; } 68 /** @brief Returns the old name of the object. */ 69 inline const std::string& getOldName() const { return this->oldName_; } 64 70 /** @brief This function gets called if the name of the object changes. */ 65 71 virtual void changedName() {} … … 79 85 virtual void changedVisibility() {} 80 86 81 /** @brief Sets a pointer to the level that loaded this object. @param level The pointer to the level */ 82 inline void setLevel(const Level* level) { this->level_ = level; } 83 /** @brief Returns a pointer to the level that loaded this object. @return The level */ 84 inline const Level* getLevel() const { return this->level_; } 85 const std::string& getLevelfile() const; 87 /** @brief Sets a pointer to the xml file that loaded this object. @param file The pointer to the XMLFile */ 88 inline void setFile(const XMLFile* file) { this->file_ = file; } 89 /** @brief Returns a pointer to the XMLFile that loaded this object. @return The XMLFile */ 90 inline const XMLFile* getFile() const { return this->file_; } 91 const std::string& getFilename() const; 92 93 void addTemplate(const std::string& name); 94 void addTemplate(Template* temp); 95 /** @brief Returns the set of all aplied templates. */ 96 inline const std::set<Template*>& getTemplates() const 97 { return this->templates_; } 86 98 87 99 virtual inline void setNamespace(Namespace* ns) { this->namespace_ = ns; } 88 100 inline Namespace* getNamespace() const { return this->namespace_; } 101 102 inline void setCreator(BaseObject* creator) { this->creator_ = creator; } 103 inline BaseObject* getCreator() const { return this->creator_; } 104 105 inline void setScene(Scene* scene) { this->scene_ = scene; } 106 inline Scene* getScene() const { return this->scene_; } 107 108 inline void setGametype(Gametype* gametype) { this->oldGametype_ = this->gametype_; this->gametype_ = gametype; this->changedGametype(); } 109 inline Gametype* getGametype() const { return this->gametype_; } 110 inline Gametype* getOldGametype() const { return this->oldGametype_; } 111 virtual inline void changedGametype() {} 112 113 void fireEvent(); 114 void fireEvent(bool activate); 115 void fireEvent(bool activate, BaseObject* originator); 116 void fireEvent(Event& event); 117 118 virtual void processEvent(Event& event); 119 120 inline void registerEventListener(BaseObject* object, const std::string& sectionname) 121 { this->eventListeners_[object] = sectionname; } 122 inline void unregisterEventListener(BaseObject* object) 123 { this->eventListeners_.erase(object); } 124 125 void addEvent(BaseObject* event, const std::string& sectionname); 126 void removeEvent(BaseObject* event); 127 BaseObject* getEvent(unsigned int index) const; 128 129 void addEventContainer(const std::string& sectionname, EventContainer* container); 130 EventContainer* getEventContainer(const std::string& sectionname) const; 89 131 90 132 /** @brief Sets the indentation of the debug output in the Loader. @param indentation The indentation */ … … 93 135 inline const std::string& getLoaderIndentation() const { return this->loaderIndentation_; } 94 136 95 pr ivate:137 protected: 96 138 std::string name_; //!< The name of the object 97 bool bInitialized_; //!< True if the object was initialized (passed the object registration)139 std::string oldName_; //!< The old name of the object 98 140 bool bActive_; //!< True = the object is active 99 141 bool bVisible_; //!< True = the object is visible 100 const Level* level_; //!< The level that loaded this object 101 std::string loaderIndentation_; //!< Indentation of the debug output in the Loader 102 Namespace* namespace_; 142 143 private: 144 void setXMLName(const std::string& name); 145 Template* getTemplate(unsigned int index) const; 146 147 bool bInitialized_; //!< True if the object was initialized (passed the object registration) 148 const XMLFile* file_; //!< The XMLFile that loaded this object 149 std::string loaderIndentation_; //!< Indentation of the debug output in the Loader 150 Namespace* namespace_; 151 BaseObject* creator_; 152 Scene* scene_; 153 Gametype* gametype_; 154 Gametype* oldGametype_; 155 std::set<Template*> templates_; 156 std::map<BaseObject*, std::string> eventListeners_; 157 std::list<BaseObject*> events_; 158 std::map<std::string, EventContainer*> eventContainers_; 103 159 }; 104 160 … … 106 162 SUPER_FUNCTION(2, BaseObject, changedActivity, false); 107 163 SUPER_FUNCTION(3, BaseObject, changedVisibility, false); 164 SUPER_FUNCTION(4, BaseObject, processEvent, false); 108 165 } 109 166 -
code/trunk/src/core/CMakeLists.txt
r1887 r2087 4 4 ConfigValueContainer.cc 5 5 Core.cc 6 Event.cc 6 7 GameState.cc 7 8 Language.cc 9 LuaBind.cc 8 10 ObjectListBase.cc 9 11 OrxonoxClass.cc 10 12 RootGameState.cc 11 Script.cc12 13 13 14 # command … … 31 32 Namespace.cc 32 33 NamespaceNode.cc 34 Template.cc 33 35 XMLPort.cc 36 XMLNameListener.cc 34 37 35 38 # shell … … 62 65 tolua_orxonox 63 66 tolua/tolua.pkg 64 Script.h67 LuaBind.h 65 68 CommandExecutor.h 66 69 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/bin/lib -
code/trunk/src/core/ClassFactory.h
r1747 r2087 55 55 { 56 56 public: 57 static bool create(const std::string& name );58 BaseObject* fabricate( );57 static bool create(const std::string& name, bool bLoadable = true); 58 BaseObject* fabricate(BaseObject* creator); 59 59 60 60 private: … … 63 63 virtual ~ClassFactory() {} // Don't delete 64 64 65 static T* createNewObject( );65 static T* createNewObject(BaseObject* creator); 66 66 }; 67 67 68 68 /** 69 69 @brief Adds the ClassFactory to the Identifier of the same type and the Identifier to the Factory. 70 @param name The name of the class 71 @param bLoadable True if the class can be loaded through XML 70 72 @return Always true (this is needed because the compiler only allows assignments before main()) 71 73 */ 72 74 template <class T> 73 bool ClassFactory<T>::create(const std::string& name )75 bool ClassFactory<T>::create(const std::string& name, bool bLoadable) 74 76 { 75 77 COUT(4) << "*** ClassFactory: Create entry for " << name << " in Factory." << std::endl; 76 78 ClassIdentifier<T>::getIdentifier(name)->addFactory(new ClassFactory<T>); 79 ClassIdentifier<T>::getIdentifier()->setLoadable(bLoadable); 77 80 Factory::add(name, ClassIdentifier<T>::getIdentifier()); 78 81 … … 85 88 */ 86 89 template <class T> 87 BaseObject* ClassFactory<T>::fabricate( )90 BaseObject* ClassFactory<T>::fabricate(BaseObject* creator) 88 91 { 89 return ClassFactory<T>::createNewObject( );92 return ClassFactory<T>::createNewObject(creator); 90 93 } 91 94 … … 95 98 */ 96 99 template <class T> 97 T* ClassFactory<T>::createNewObject( )100 T* ClassFactory<T>::createNewObject(BaseObject* creator) 98 101 { 99 return new T ;102 return new T(creator); 100 103 } 101 104 } -
code/trunk/src/core/CommandEvaluation.cc
r1879 r2087 78 78 if (this->bEvaluatedParams_ && this->function_) 79 79 { 80 COUT( 5) << "CE_execute (evaluation): " << this->function_->getName() << " " << this->param_[0] << " " << this->param_[1] << " " << this->param_[2] << " " << this->param_[3] << " " << this->param_[4] << std::endl;80 COUT(6) << "CE_execute (evaluation): " << this->function_->getName() << " " << this->param_[0] << " " << this->param_[1] << " " << this->param_[2] << " " << this->param_[3] << " " << this->param_[4] << std::endl; 81 81 (*this->function_)(this->param_[0], this->param_[1], this->param_[2], this->param_[3], this->param_[4]); 82 82 return true; -
code/trunk/src/core/CommandLine.cc
r1755 r2087 35 35 /** 36 36 @brief 37 Parses a value string for a command line argument. 38 It simply uses convertValue(Output, Input) to do that. 39 Bools are treated specially. That is necessary 40 so that you can have simple command line switches. 41 */ 42 void CommandLineArgument::parse(const std::string& value) 43 { 44 if (value_.getType() == MT_bool) 45 { 46 // simulate command line switch 47 bool temp; 48 if (convertValue(&temp, value)) 49 { 50 this->bHasDefaultValue_ = false; 51 this->value_ = temp; 52 } 53 else if (value == "") 54 { 55 this->bHasDefaultValue_ = false; 56 this->value_ = true; 57 } 58 else 59 { 60 ThrowException(Argument, "Could not read command line argument '" + getName() + "'."); 61 } 62 } 63 else 64 { 65 if (!value_.setValue(value)) 66 { 67 value_.setValue(defaultValue_); 68 ThrowException(Argument, "Could not read command line argument '" + getName() + "'."); 69 } 70 else 71 this->bHasDefaultValue_ = false; 72 } 73 } 74 75 76 /** 77 @brief 37 78 Destructor destroys all CommandLineArguments with it. 38 79 */ 39 80 CommandLine::~CommandLine() 40 81 { 41 for (std::map<std::string, BaseCommandLineArgument*>::const_iterator it = cmdLineArgs_.begin();82 for (std::map<std::string, CommandLineArgument*>::const_iterator it = cmdLineArgs_.begin(); 42 83 it != cmdLineArgs_.end(); ++it) 43 84 { … … 73 114 { 74 115 // first shove all the shortcuts in a map 75 for (std::map<std::string, BaseCommandLineArgument*>::const_iterator it = cmdLineArgs_.begin();116 for (std::map<std::string, CommandLineArgument*>::const_iterator it = cmdLineArgs_.begin(); 76 117 it != cmdLineArgs_.end(); ++it) 77 118 { … … 178 219 void CommandLine::checkFullArgument(const std::string& name, const std::string& value) 179 220 { 180 std::map<std::string, BaseCommandLineArgument*>::const_iterator it = cmdLineArgs_.find(name);221 std::map<std::string, CommandLineArgument*>::const_iterator it = cmdLineArgs_.find(name); 181 222 if (it == cmdLineArgs_.end()) 182 223 ThrowException(Argument, "Command line argument '" + name + "' does not exist."); … … 195 236 void CommandLine::checkShortcut(const std::string& shortcut, const std::string& value) 196 237 { 197 std::map<std::string, BaseCommandLineArgument*>::const_iterator it = cmdLineArgsShortcut_.find(shortcut);238 std::map<std::string, CommandLineArgument*>::const_iterator it = cmdLineArgsShortcut_.find(shortcut); 198 239 if (it == cmdLineArgsShortcut_.end()) 199 240 ThrowException(Argument, "Command line shortcut '" + shortcut + "' does not exist."); … … 206 247 CommandLine* inst = &_getInstance(); 207 248 std::string infoStr; 208 for (std::map<std::string, BaseCommandLineArgument*>::const_iterator it = inst->cmdLineArgs_.begin();249 for (std::map<std::string, CommandLineArgument*>::const_iterator it = inst->cmdLineArgs_.begin(); 209 250 it != inst->cmdLineArgs_.end(); ++it) 210 251 { … … 214 255 } 215 256 257 /** 258 @brief 259 Retrieves a CommandLineArgument. 260 The method throws an exception if 'name' was not found or the value could not be converted. 261 @note 262 You shold of course not call this method before the command line has been parsed. 263 */ 264 const CommandLineArgument* CommandLine::getArgument(const std::string& name) 265 { 266 std::map<std::string, CommandLineArgument*>::const_iterator it = _getInstance().cmdLineArgs_.find(name); 267 if (it == _getInstance().cmdLineArgs_.end()) 268 { 269 ThrowException(Argument, "Could find command line argument '" + name + "'."); 270 } 271 else 272 { 273 return it->second; 274 } 275 } 216 276 } -
code/trunk/src/core/CommandLine.h
r1764 r2087 35 35 #include "util/Debug.h" 36 36 #include "util/Exception.h" 37 #include "util/MultiType.h" 37 38 38 39 #define SetCommandLineArgument(name, defaultValue) \ 39 BaseCommandLineArgument& CmdArgumentDummyBoolVar##name \40 CommandLineArgument& CmdArgumentDummyBoolVar##name \ 40 41 = orxonox::CommandLine::addArgument(#name, defaultValue) 41 42 #define SetCommandLineSwitch(name) \ 42 BaseCommandLineArgument& CmdArgumentDummyBoolVar##name \43 CommandLineArgument& CmdArgumentDummyBoolVar##name \ 43 44 = orxonox::CommandLine::addArgument(#name, false) 44 45 … … 48 49 /** 49 50 @brief 50 Template struct which creates a distinct type for every integer constant. 51 @note 52 This allows to select a different function depending on a boolean value 53 when creating a new CommandLineArgument. 54 From 'Modern C++ Design' (Alexandrescu 2001). 51 Container class for a command line argument of any type supported by MultiType. 52 53 Whenever you want to have an option specified by a command line switch, 54 you need to first define it with SetCommandLineArgument(name, defaultValue). 55 It is then added to a map and possibly changed when the command line is being parsed. 56 If the option was not given, you can detect this by asking hasDefaultValue(). 57 58 There is a possibility to define a short cut so you can write "-p 20" instead of "--port 20". 59 Note the difference between "-" and "--"! 60 Also, there is no restriction to the number of strings you add after --name. 61 So "--startVector (2, 4, 5)" is perfectly legal. 62 63 Retrieving an argument is possible with the getCommandLineArgument function of the 64 CommandLine class. It is a Singleton, but the public interface is static. 55 65 */ 56 template <int v> 57 struct Int2Type 58 { 59 enum { value = v }; 60 }; 61 62 /** 63 @brief 64 Base class for CommandLineArguments. 65 */ 66 class _CoreExport BaseCommandLineArgument 66 class _CoreExport CommandLineArgument 67 67 { 68 68 friend class CommandLine; … … 78 78 const std::string& getShortcut() const { return shortcut_; } 79 79 //! Sets the shortcut for the argument 80 BaseCommandLineArgument& setShortcut(const std::string& shortcut)80 CommandLineArgument& shortcut(const std::string& shortcut) 81 81 { this->shortcut_ = shortcut; return *this; } 82 82 … … 84 84 const std::string& getInformation() const { return this->usageInformation_; } 85 85 //! Sets the option information when displaying orxonox usage. 86 BaseCommandLineArgument& setInformation(const std::string& usage)86 CommandLineArgument& information(const std::string& usage) 87 87 { this->usageInformation_ = usage; return *this; } 88 88 89 protected: 90 BaseCommandLineArgument(const std::string& name) 89 //! Returns the actual value of the argument. Can be equal to default value. 90 MultiType getValue() const { return value_; } 91 //! Returns the given default value as type T. 92 MultiType getDefaultValue() const { return defaultValue_; } 93 94 private: 95 //! Constructor initialises both value_ and defaultValue_ with defaultValue. 96 CommandLineArgument(const std::string& name, const MultiType& defaultValue) 91 97 : bHasDefaultValue_(true) 92 98 , name_(name) 99 , value_(defaultValue) 100 , defaultValue_(defaultValue) 93 101 { } 94 102 95 103 //! Undefined copy constructor 96 BaseCommandLineArgument(const BaseCommandLineArgument& instance);97 virtual ~BaseCommandLineArgument() { }104 CommandLineArgument(const CommandLineArgument& instance); 105 ~CommandLineArgument() { } 98 106 99 107 //! Parses the value string of a command line argument. 100 v irtual void parse(const std::string& value) = 0;108 void parse(const std::string& value); 101 109 102 110 //! Tells whether the value has been changed by the command line. … … 107 115 std::string shortcut_; //!< Shortcut of the argument. @see getShortcut(). 108 116 std::string usageInformation_; //!< Tells about the usage of this parameter 117 118 MultiType value_; //!< The actual value 119 MultiType defaultValue_; //!< Default value. Should not be changed. 109 120 }; 110 111 112 /**113 @brief114 Container class for a command line argument of type T.115 116 Whenever you want to have an option specified by a command line switch,117 you need to first define it with SetCommandLineArgument(name, defaultValue).118 It is then added to a map and possibly changed when the command line is being parsed.119 If the option was not given, you can detect this by asking hasDefaultValue().120 121 There is a possibility to define a short cut so you can write "-p 20" instead of "--port 20".122 Note the difference between "-" and "--"!123 Also, there is no restriction to the number of strings you add after --name.124 So "--startVector (2, 4, 5)" is perfectly legal.125 126 Retrieving an argument is possible with the getCommandLineArgument function of the127 CommandLine class. It is a Singleton, but the public interface is static.128 */129 template <class T>130 class CommandLineArgument : public BaseCommandLineArgument131 {132 // Only let CommandLine change the value.133 friend class CommandLine;134 135 public:136 //! Returns the actual value of the argument. Can be equal to default value.137 T getValue() const { return value_; }138 //! Returns the given default value as type T.139 T getDefaultValue() const { return defaultValue_; }140 141 private:142 //! Constructor initialises both value_ and defaultValue_ with defaultValue.143 CommandLineArgument(const std::string& name, const T& defaultValue)144 : BaseCommandLineArgument(name)145 , value_(defaultValue)146 , defaultValue_(defaultValue)147 { }148 149 virtual void parse(const std::string& value);150 151 T value_; //!< The actual value152 T defaultValue_; //!< Default value. Should not be changed.153 };154 155 /**156 @brief157 Parses a value string for a command line argument.158 It simply uses convertValue(Output, Input) to do that.159 */160 template <class T>161 void CommandLineArgument<T>::parse(const std::string& value)162 {163 if (convertValue(&this->value_, value))164 {165 this->bHasDefaultValue_ = false;166 }167 else168 {169 ThrowException(Argument, "Could not read command line argument '" + getName() + "'.");170 }171 }172 173 /**174 @brief175 Parses a value string for a command line argument.176 It simply uses convertValue(Output, Input) to do that.177 This is a template specialisation for bool type. That is necessary178 so that you can have simple command line switches.179 */180 template <>181 inline void CommandLineArgument<bool>::parse(const std::string& value)182 {183 if (convertValue(&this->value_, value))184 {185 this->bHasDefaultValue_ = false;186 }187 else if (value == "")188 {189 this->bHasDefaultValue_ = false;190 this->value_ = true;191 }192 else193 {194 ThrowException(Argument, "Could not read command line argument '" + getName() + "'.");195 }196 }197 121 198 122 … … 215 139 static std::string getUsageInformation(); 216 140 217 template <class T> 218 static const CommandLineArgument<T>* getArgument(const std::string& name); 141 static const CommandLineArgument* getArgument(const std::string& name); 219 142 //! Writes the argument value in the given parameter. 220 143 template <class T> 221 144 static void getValue(const std::string& name, T* value) 222 { *value = getArgument<T>(name)->getValue(); } 145 { *value = (T)(getArgument(name)->getValue()); } 146 static MultiType getValue(const std::string& name) 147 { return getArgument(name)->getValue(); } 223 148 template <class T> 224 static BaseCommandLineArgument& addArgument(const std::string& name, T defaultValue); 149 static CommandLineArgument& addArgument(const std::string& name, T defaultValue); 150 151 static bool existsArgument(const std::string& name) 152 { 153 std::map<std::string, CommandLineArgument*>::const_iterator it = _getInstance().cmdLineArgs_.find(name); 154 return !(it == _getInstance().cmdLineArgs_.end()); 155 } 156 225 157 226 158 private: … … 237 169 void checkShortcut(const std::string& shortcut, const std::string& value); 238 170 239 template <class T>240 BaseCommandLineArgument* createArg(const std::string& name, T defaultValue, Int2Type<0> isString);241 template <class T>242 BaseCommandLineArgument* createArg(const std::string& name, T defaultValue, Int2Type<1> isString);243 244 171 /** 245 Tells whether we parse the first expression. The CommmandLineArguments are added before main().172 Tells whether we parsed for the first time. The CommmandLineArguments are added before main(). 246 173 So when we call parse() the first time, we need to create a map with all shortcuts since these 247 174 get added after addCommandLineArgument(). … … 250 177 251 178 //! Holds all pointers to the arguments and serves as a search map by name. 252 std::map<std::string, BaseCommandLineArgument*> cmdLineArgs_;179 std::map<std::string, CommandLineArgument*> cmdLineArgs_; 253 180 //! Search map by chortcut for the arguments. 254 std::map<std::string, BaseCommandLineArgument*> cmdLineArgsShortcut_;181 std::map<std::string, CommandLineArgument*> cmdLineArgsShortcut_; 255 182 }; 256 183 257 258 /** 259 @brief 260 Retrieves a CommandLineArgument. 261 The method throws an exception if 'name' was not found or the value could not be converted. 262 @note 263 You shold of course not call this method before the command line has been parsed. 264 */ 265 template <class T> 266 const CommandLineArgument<T>* CommandLine::getArgument(const std::string& name) 267 { 268 std::map<std::string, BaseCommandLineArgument*>::const_iterator it = _getInstance().cmdLineArgs_.find(name); 269 if (it == _getInstance().cmdLineArgs_.end()) 270 { 271 ThrowException(Argument, "Could find command line argument '" + name + "'."); 272 } 273 else 274 { 275 CommandLineArgument<T>* arg = dynamic_cast<CommandLineArgument<T>* >(it->second); 276 if (arg == 0) 277 { 278 ThrowException(Argument, "Could not convert command line argument value to requested type. " \ 279 "You should use exactly the same type as predefined."); 280 } 281 else 282 { 283 return arg; 284 } 285 } 184 template <> 185 inline void CommandLine::getValue<std::string>(const std::string& name, std::string* value) 186 { 187 *value = (std::string)(getArgument(name)->getValue().getString()); 286 188 } 287 189 … … 294 196 @param defaultValue 295 197 Default value that is used when argument was not given. 296 @note297 In order to store char* strings as std::string too, there's298 little bit of template programming involved:299 StaticConversions::exists determines whether T converts to std::string.300 Int2Type<int> is then used to call the right function. One returns301 a CommandLineArgument<T> and the other CommandLineArgument<std::string>.302 198 */ 303 199 template <class T> 304 BaseCommandLineArgument& CommandLine::addArgument(const std::string& name, T defaultValue) 305 { 306 std::map<std::string, BaseCommandLineArgument*>::const_iterator it = _getInstance().cmdLineArgs_.find(name); 307 OrxAssert(it == _getInstance().cmdLineArgs_.end(), 200 CommandLineArgument& CommandLine::addArgument(const std::string& name, T defaultValue) 201 { 202 OrxAssert(!_getInstance().existsArgument(name), 308 203 "Cannot add a command line argument with name '" + name + "' twice."); 309 204 310 return *(_getInstance().cmdLineArgs_[name] = 311 _getInstance().createArg(name, defaultValue, Int2Type<StaticConversion<T, std::string>::exists>())); 312 } 313 314 /** 315 Returns a new CommandLineArgument<T>. 316 */ 317 template <class T> 318 BaseCommandLineArgument* CommandLine::createArg(const std::string& name, T defaultValue, Int2Type<0> isPrime) 319 { 320 return new CommandLineArgument<T>(name, defaultValue); 321 } 322 323 /** 324 Returns a new CommandLineArgument<std::string>. 325 */ 326 template <class T> 327 BaseCommandLineArgument* CommandLine::createArg(const std::string& name, T defaultValue, Int2Type<1> isPrime) 328 { 329 return new CommandLineArgument<std::string>(name, defaultValue); 205 return *(_getInstance().cmdLineArgs_[name] = new CommandLineArgument(name, defaultValue)); 330 206 } 331 207 } -
code/trunk/src/core/ConfigValueContainer.h
r1887 r2087 52 52 #include "util/MultiType.h" 53 53 #include "ConfigFileManager.h" 54 #include "Identifier.h" 54 55 55 56 namespace orxonox … … 69 70 inline virtual ~ConfigValueCallback() {} 70 71 inline virtual void call(void* object) 71 { (((T*)object)->*this->function_)();}72 { if (!Identifier::isCreatingHierarchy()) { (((T*)object)->*this->function_)(); } } 72 73 73 74 private: -
code/trunk/src/core/ConsoleCommand.cc
r1755 r2087 41 41 42 42 this->keybindMode_ = KeybindMode::OnPress; 43 this->axisParamIndex_ = -1; 44 this->bAxisRelative_ = false; 43 this->inputConfiguredParam_ = -1; 45 44 } 46 45 -
code/trunk/src/core/ConsoleCommand.h
r1755 r2087 122 122 { return this->argumentList_.end(); } 123 123 124 inline ConsoleCommand& setAsInputCommand() 125 { 126 this->keybindMode(KeybindMode::OnHold); 127 this->defaultValue(0, Vector2(0.0f, 0.0f)); 128 this->inputConfiguredParam(0); 129 return *this; 130 } 131 124 132 inline ConsoleCommand& keybindMode(KeybindMode::Enum mode) 125 133 { this->keybindMode_ = mode; return *this; } … … 127 135 { return this->keybindMode_; } 128 136 129 inline ConsoleCommand& axisParamIndex(int index) 130 { this->axisParamIndex_ = index; return *this; } 131 inline int getAxisParamIndex() const 132 { return this->axisParamIndex_; } 133 134 inline ConsoleCommand& isAxisRelative(bool val) 135 { this->bAxisRelative_ = val; return *this; } 136 inline int getIsAxisRelative() const 137 { return this->bAxisRelative_; } 137 inline ConsoleCommand& inputConfiguredParam(int index) 138 { this->inputConfiguredParam_ = index; return *this; } 139 inline int getInputConfiguredParam_() const 140 { return this->inputConfiguredParam_; } 138 141 139 142 private: … … 143 146 144 147 KeybindMode::Enum keybindMode_; 145 int axisParamIndex_; 146 bool bAxisRelative_; 148 int inputConfiguredParam_; 147 149 }; 148 150 -
code/trunk/src/core/Core.cc
r1762 r2087 37 37 #include "CoreIncludes.h" 38 38 #include "ConfigValueIncludes.h" 39 //#include "input/InputManager.h"40 //#include "TclThreadManager.h"41 39 42 40 namespace orxonox 43 41 { 42 bool Core::bShowsGraphics_s = false; 43 bool Core::bHasServer_s = false; 44 bool Core::bIsClient_s = false; 45 bool Core::bIsStandalone_s = false; 46 bool Core::bIsMaster_s = false; 47 44 48 /** 45 49 @brief Constructor: Registers the object and sets the config-values. … … 205 209 ResetConfigValue(language_); 206 210 } 207 208 ///**209 // @brief Ticks every core class in a specified sequence. Has to be called210 // every Orxonox tick!211 // @param dt Delta Time212 //*/213 //void Core::tick(float dt)214 //{215 // TclThreadManager::getInstance().tick(dt);216 // InputManager::getInstance().tick(dt);217 //}218 211 } -
code/trunk/src/core/Core.h
r1755 r2087 60 60 static void resetLanguage(); 61 61 62 //static void tick(float dt); 62 // fast access global variables. 63 static bool showsGraphics() { return bShowsGraphics_s; } 64 static bool hasServer() { return bHasServer_s; } 65 static bool isClient() { return bIsClient_s; } 66 static bool isStandalone() { return bIsStandalone_s; } 67 static bool isMaster() { return bIsMaster_s; } 68 static void setShowsGraphics(bool val) { bShowsGraphics_s = val; updateIsMaster(); } 69 static void setHasServer (bool val) { bHasServer_s = val; updateIsMaster(); } 70 static void setIsClient (bool val) { bIsClient_s = val; updateIsMaster(); } 71 static void setIsStandalone (bool val) { bIsStandalone_s = val; updateIsMaster(); } 72 static void updateIsMaster () { bIsMaster_s = (bHasServer_s || bIsStandalone_s); } 63 73 64 74 private: … … 74 84 int softDebugLevelShell_; //!< The debug level for the ingame shell 75 85 std::string language_; //!< The language 86 87 static bool bShowsGraphics_s; //!< global variable that tells whether to show graphics 88 static bool bHasServer_s; //!< global variable that tells whether this is a server 89 static bool bIsClient_s; 90 static bool bIsStandalone_s; 91 static bool bIsMaster_s; 76 92 }; 77 93 } -
code/trunk/src/core/CoreIncludes.h
r1856 r2087 46 46 #include "Factory.h" 47 47 #include "ClassFactory.h" 48 #include "Functor.h" 48 49 #include "util/Debug.h" 49 50 … … 98 99 */ 99 100 #define CreateFactory(ClassName) \ 100 bool bCreated##ClassName##Factory = orxonox::ClassFactory<ClassName>::create(#ClassName) 101 bool bCreated##ClassName##Factory = orxonox::ClassFactory<ClassName>::create(#ClassName, true) 102 103 /** 104 @brief Creates the entry in the Factory for classes which should not be loaded through XML. 105 @param ClassName The name of the class 106 */ 107 #define CreateUnloadableFactory(ClassName) \ 108 bool bCreated##ClassName##Factory = orxonox::ClassFactory<ClassName>::create(#ClassName, false) 101 109 102 110 /** … … 105 113 */ 106 114 #define Class(ClassName) \ 107 ClassIdentifier<ClassName>::getIdentifier()115 orxonox::ClassIdentifier<ClassName>::getIdentifier() 108 116 109 117 /** … … 111 119 @param String The name of the class 112 120 */ 113 #define ClassBy Name(String) \121 #define ClassByString(String) \ 114 122 orxonox::Factory::getIdentifier(String) 115 123 … … 121 129 orxonox::Factory::getIdentifier(networkID) 122 130 131 /** 132 @brief Registers a member function as callback when an object of 'type' is created. 133 @param 134 */ 135 #define RegisterConstructionCallback(ThisClassName, TargetClassName, FunctionName) \ 136 orxonox::ClassIdentifier<TargetClassName>::getIdentifier()->addConstructionCallback( \ 137 createFunctor(&ThisClassName::FunctionName)->setObject(this)) 138 123 139 #endif /* _CoreIncludes_H__ */ -
code/trunk/src/core/CorePrereqs.h
r1757 r2087 103 103 class CommandExecutor; 104 104 class CommandLine; 105 class BaseCommandLineArgument;106 template <class T>107 105 class CommandLineArgument; 108 106 class ConfigFile; … … 115 113 class ConsoleCommand; 116 114 class Core; 115 struct Event; 116 class EventContainer; 117 117 class Executor; 118 118 template <class T> … … 131 131 class Language; 132 132 class LanguageEntry; 133 class Level;134 133 class Loader; 135 134 class MetaObjectList; … … 153 152 struct TclInterpreterBundle; 154 153 class TclThreadManager; 154 class Template; 155 155 class Tickable; 156 class XMLFile; 157 class XMLNameListener; 156 158 template <class T, class O> 157 159 class XMLPortClassObjectContainer; -
code/trunk/src/core/Factory.cc
r1856 r2087 46 46 Identifier* Factory::getIdentifier(const std::string& name) 47 47 { 48 return getFactoryPointer()->identifierStringMap_[name]; 48 std::map<std::string, Identifier*>::const_iterator it = getFactoryPointer()->identifierStringMap_.find(name); 49 if (it != getFactoryPointer()->identifierStringMap_.end()) 50 return it->second; 51 else 52 return 0; 49 53 } 50 54 … … 56 60 Identifier* Factory::getIdentifier(const unsigned int id) 57 61 { 58 return getFactoryPointer()->identifierNetworkIDMap_[id]; 62 std::map<unsigned int, Identifier*>::const_iterator it = getFactoryPointer()->identifierNetworkIDMap_.find(id); 63 if (it != getFactoryPointer()->identifierNetworkIDMap_.end()) 64 return it->second; 65 else 66 return 0; 59 67 } 60 68 … … 68 76 getFactoryPointer()->identifierStringMap_[name] = identifier; 69 77 getFactoryPointer()->identifierNetworkIDMap_[identifier->getNetworkID()] = identifier; 78 //std::cout << identifier->getName() << ": " << identifier->getNetworkID() << std::endl; 70 79 } 71 80 … … 80 89 getFactoryPointer()->identifierNetworkIDMap_.erase(oldID); 81 90 getFactoryPointer()->identifierNetworkIDMap_[newID] = identifier; 91 //std::cout << identifier->getName() << ": " << oldID << " -> " << newID << std::endl; 82 92 } 83 93 … … 94 104 { 95 105 // To create the new branch of the class-hierarchy, we create a new object and delete it afterwards. 96 BaseObject* temp = (*it).second->fabricate( );106 BaseObject* temp = (*it).second->fabricate(0); 97 107 delete temp; 98 108 } -
code/trunk/src/core/Factory.h
r1856 r2087 93 93 { 94 94 public: 95 virtual BaseObject* fabricate( ) = 0;95 virtual BaseObject* fabricate(BaseObject* creator) = 0; 96 96 virtual ~BaseFactory() {}; 97 97 }; -
code/trunk/src/core/Functor.h
r1889 r2087 106 106 inline const MultiType& getReturnvalue() const { return this->returnedValue_; } 107 107 108 const std::string& getTypenameParam(unsigned int param) const { return (param < 5) ? this->typeParam_[param] : blankString; }108 const std::string& getTypenameParam(unsigned int param) const { return (param < 5) ? this->typeParam_[param] : BLANKSTRING; } 109 109 const std::string& getTypenameReturnvalue() const { return this->typeReturnvalue_; } 110 110 … … 167 167 } 168 168 169 voidsetObject(T* object)169 FunctorMember* setObject(T* object) 170 170 { 171 171 this->bConstObject_ = false; 172 172 this->object_ = object; 173 return this; 173 174 } 174 175 175 voidsetObject(const T* object)176 FunctorMember* setObject(const T* object) 176 177 { 177 178 this->bConstObject_ = true; 178 179 this->constObject_ = object; 180 return this; 179 181 } 180 182 -
code/trunk/src/core/Identifier.cc
r1856 r2087 59 59 this->bSetName_ = false; 60 60 this->factory_ = 0; 61 this->bLoadable_ = true; 61 62 62 63 this->bHasConfigValues_ = false; 63 64 this->bHasConsoleCommands_ = false; 65 this->bHasConstructionCallback_ = false; 64 66 65 67 this->children_ = new std::set<const Identifier*>(); … … 213 215 @return The new object 214 216 */ 215 BaseObject* Identifier::fabricate( )217 BaseObject* Identifier::fabricate(BaseObject* creator) 216 218 { 217 219 if (this->factory_) 218 220 { 219 return this->factory_->fabricate( ); // We have to return a BaseObject, because we don't know the exact type.221 return this->factory_->fabricate(creator); // We have to return a BaseObject, because we don't know the exact type. 220 222 } 221 223 else … … 420 422 XMLPortParamContainer* Identifier::getXMLPortParamContainer(const std::string& paramname) 421 423 { 422 std::map<std::string, XMLPortParamContainer*>::const_iterator it = xmlportParamContainers_.find(paramname);423 if (it != xmlportParamContainers_.end())424 std::map<std::string, XMLPortParamContainer*>::const_iterator it = this->xmlportParamContainers_.find(paramname); 425 if (it != this->xmlportParamContainers_.end()) 424 426 return ((*it).second); 425 427 else … … 434 436 void Identifier::addXMLPortParamContainer(const std::string& paramname, XMLPortParamContainer* container) 435 437 { 438 std::map<std::string, XMLPortParamContainer*>::const_iterator it = this->xmlportParamContainers_.find(paramname); 439 if (it != this->xmlportParamContainers_.end()) 440 { 441 COUT(2) << "Warning: Overwriting XMLPortParamContainer in class " << this->getName() << "." << std::endl; 442 delete (it->second); 443 } 444 436 445 this->xmlportParamContainers_[paramname] = container; 437 446 } … … 444 453 XMLPortObjectContainer* Identifier::getXMLPortObjectContainer(const std::string& sectionname) 445 454 { 446 std::map<std::string, XMLPortObjectContainer*>::const_iterator it = xmlportObjectContainers_.find(sectionname);447 if (it != xmlportObjectContainers_.end())455 std::map<std::string, XMLPortObjectContainer*>::const_iterator it = this->xmlportObjectContainers_.find(sectionname); 456 if (it != this->xmlportObjectContainers_.end()) 448 457 return ((*it).second); 449 458 else … … 458 467 void Identifier::addXMLPortObjectContainer(const std::string& sectionname, XMLPortObjectContainer* container) 459 468 { 469 std::map<std::string, XMLPortObjectContainer*>::const_iterator it = this->xmlportObjectContainers_.find(sectionname); 470 if (it != this->xmlportObjectContainers_.end()) 471 { 472 COUT(2) << "Warning: Overwriting XMLPortObjectContainer in class " << this->getName() << "." << std::endl; 473 delete (it->second); 474 } 475 460 476 this->xmlportObjectContainers_[sectionname] = container; 477 } 478 479 /** 480 @brief Returns a XMLPortEventContainer that attaches an event to this class. 481 @param sectionname The name of the section that contains the event 482 @return The container 483 */ 484 XMLPortObjectContainer* Identifier::getXMLPortEventContainer(const std::string& eventname) 485 { 486 std::map<std::string, XMLPortObjectContainer*>::const_iterator it = this->xmlportEventContainers_.find(eventname); 487 if (it != this->xmlportEventContainers_.end()) 488 return ((*it).second); 489 else 490 return 0; 491 } 492 493 /** 494 @brief Adds a new XMLPortEventContainer that attaches an event to this class. 495 @param sectionname The name of the section that contains the event 496 @param container The container 497 */ 498 void Identifier::addXMLPortEventContainer(const std::string& eventname, XMLPortObjectContainer* container) 499 { 500 std::map<std::string, XMLPortObjectContainer*>::const_iterator it = this->xmlportEventContainers_.find(eventname); 501 if (it != this->xmlportEventContainers_.end()) 502 { 503 COUT(2) << "Warning: Overwriting XMLPortEventContainer in class " << this->getName() << "." << std::endl; 504 delete (it->second); 505 } 506 507 this->xmlportEventContainers_[eventname] = container; 508 } 509 510 /** 511 @brief Adds a construction callback functor that gets called every time an object is created. 512 @param functor Functor pointer to any function with no argument. 513 */ 514 void Identifier::addConstructionCallback(Functor* functor) 515 { 516 for (unsigned int i = 0; i < this->constructionCallbacks_.size(); ++i) 517 { 518 if (this->constructionCallbacks_[i] == functor) 519 return; 520 } 521 this->constructionCallbacks_.push_back(functor); 522 this->bHasConstructionCallback_ = true; 523 } 524 525 /** 526 @brief Removes a construction callback functor that gets called every time an object is created. 527 @param functor Functor pointer to any function with no argument. 528 */ 529 void Identifier::removeConstructionCallback(Functor* functor) 530 { 531 for (unsigned int i = 0; i < this->constructionCallbacks_.size(); ++i) 532 { 533 if (this->constructionCallbacks_[i] == functor) 534 { 535 this->constructionCallbacks_.erase(this->constructionCallbacks_.begin() + i); 536 } 537 } 538 if (constructionCallbacks_.empty()) 539 this->bHasConstructionCallback_ = false; 461 540 } 462 541 -
code/trunk/src/core/Identifier.h
r1856 r2087 57 57 #include <set> 58 58 #include <map> 59 #include <vector> 59 60 #include <string> 60 61 #include <utility> 61 62 #include <typeinfo> 62 63 #include <stdlib.h> 64 #include <cassert> 63 65 64 66 #include "MetaObjectList.h" 65 67 #include "Iterator.h" 66 68 #include "Super.h" 69 #include "Functor.h" 67 70 #include "util/Debug.h" 68 71 #include "util/String.h" … … 99 102 inline void addFactory(BaseFactory* factory) { this->factory_ = factory; } 100 103 101 BaseObject* fabricate( );104 BaseObject* fabricate(BaseObject* creator); 102 105 bool isA(const Identifier* identifier) const; 103 106 bool isExactlyA(const Identifier* identifier) const; … … 107 110 bool isDirectParentOf(const Identifier* identifier) const; 108 111 112 /** @brief Returns true if the class can be loaded through XML. */ 113 inline bool isLoadable() const { return this->bLoadable_; } 114 /** @brief Set the class to be loadable through XML or not. */ 115 inline void setLoadable(bool bLoadable) { this->bLoadable_ = bLoadable; } 116 109 117 /** @brief Returns the list of all existing objects of this class. @return The list */ 110 118 inline ObjectListBase* getObjects() const … … 204 212 inline std::map<std::string, XMLPortObjectContainer*>::const_iterator getXMLPortObjectMapEnd() const { return this->xmlportObjectContainers_.end(); } 205 213 214 /** @brief Returns the map that stores all XMLPort events. @return The const_iterator */ 215 inline const std::map<std::string, XMLPortObjectContainer*>& getXMLPortEventMap() const { return this->xmlportEventContainers_; } 216 /** @brief Returns a const_iterator to the beginning of the map that stores all XMLPort events. @return The const_iterator */ 217 inline std::map<std::string, XMLPortObjectContainer*>::const_iterator getXMLPortEventMapBegin() const { return this->xmlportEventContainers_.begin(); } 218 /** @brief Returns a const_iterator to the end of the map that stores all XMLPort events. @return The const_iterator */ 219 inline std::map<std::string, XMLPortObjectContainer*>::const_iterator getXMLPortEventMapEnd() const { return this->xmlportEventContainers_.end(); } 220 206 221 /** @brief Returns true if this class has at least one config value. @return True if this class has at least one config value */ 207 222 inline bool hasConfigValues() const { return this->bHasConfigValues_; } 208 223 /** @brief Returns true if this class has at least one console command. @return True if this class has at least one console command */ 209 224 inline bool hasConsoleCommands() const { return this->bHasConsoleCommands_; } 225 /** @brief Returns true if this class has at least one construction callback Functor registered. */ 226 inline bool hasConstructionCallback() const { return this->bHasConstructionCallback_; } 210 227 211 228 /** @brief Returns true, if a branch of the class-hierarchy is being created, causing all new objects to store their parents. @return The status of the class-hierarchy creation */ … … 228 245 XMLPortObjectContainer* getXMLPortObjectContainer(const std::string& sectionname); 229 246 247 void addXMLPortEventContainer(const std::string& eventname, XMLPortObjectContainer* container); 248 XMLPortObjectContainer* getXMLPortEventContainer(const std::string& eventname); 249 230 250 ConsoleCommand& addConsoleCommand(ConsoleCommand* command, bool bCreateShortcut); 231 251 ConsoleCommand* getConsoleCommand(const std::string& name) const; 232 252 ConsoleCommand* getLowercaseConsoleCommand(const std::string& name) const; 253 254 void addConstructionCallback(Functor* functor); 255 void removeConstructionCallback(Functor* functor); 233 256 234 257 void initializeClassHierarchy(std::set<const Identifier*>* parents, bool bRootClass); … … 252 275 inline std::set<const Identifier*>& getDirectChildrenIntern() const { return (*this->directChildren_); } 253 276 277 bool bHasConstructionCallback_; //!< True if at least one Functor is registered to get informed when an object of type T is created. 278 std::vector<Functor*> constructionCallbacks_; //!< All construction callback Functors of this class. 279 254 280 ObjectListBase* objects_; //!< The list of all objects of this class 255 281 … … 285 311 bool bCreatedOneObject_; //!< True if at least one object of the given type was created (used to determine the need of storing the parents) 286 312 bool bSetName_; //!< True if the name is set 313 bool bLoadable_; //!< False = it's not permitted to load the object through XML 287 314 std::string name_; //!< The name of the class the Identifier belongs to 288 315 BaseFactory* factory_; //!< The Factory, able to create new objects of the given class (if available) … … 300 327 std::map<std::string, XMLPortParamContainer*> xmlportParamContainers_; //!< All loadable parameters 301 328 std::map<std::string, XMLPortObjectContainer*> xmlportObjectContainers_; //!< All attachable objects 329 std::map<std::string, XMLPortObjectContainer*> xmlportEventContainers_; //!< All events 302 330 }; 303 331 … … 423 451 COUT(5) << "*** ClassIdentifier: Added object to " << this->getName() << "-list." << std::endl; 424 452 object->getMetaList().add(this->objects_, this->objects_->add(new ObjectListElement<T>(object))); 453 if (this->bHasConstructionCallback_) 454 { 455 // Call all registered callbacks that a new object of type T has been created. 456 // Do NOT deliver a T* pointer here because it's way too risky (object not yet fully created). 457 for (unsigned int i = 0; i < this->constructionCallbacks_.size(); ++i) 458 (*constructionCallbacks_[i])(); 459 } 425 460 } 426 461 … … 480 515 SubclassIdentifier<T>& operator=(Identifier* identifier) 481 516 { 482 if (!identifier ->isA(ClassIdentifier<T>::getIdentifier()))517 if (!identifier || !identifier->isA(ClassIdentifier<T>::getIdentifier())) 483 518 { 484 519 COUT(1) << "An error occurred in SubclassIdentifier (Identifier.h):" << std::endl; 485 COUT(1) << "Error: Class " << identifier->getName() << " is not a " << ClassIdentifier<T>::getIdentifier()->getName() << "!" << std::endl; 486 COUT(1) << "Error: SubclassIdentifier<" << ClassIdentifier<T>::getIdentifier()->getName() << "> = Class(" << identifier->getName() << ") is forbidden." << std::endl; 487 COUT(1) << "Aborting..." << std::endl; 488 abort(); 520 if (identifier) 521 { 522 COUT(1) << "Error: Class " << identifier->getName() << " is not a " << ClassIdentifier<T>::getIdentifier()->getName() << "!" << std::endl; 523 COUT(1) << "Error: SubclassIdentifier<" << ClassIdentifier<T>::getIdentifier()->getName() << "> = Class(" << identifier->getName() << ") is forbidden." << std::endl; 524 } 525 else 526 { 527 COUT(1) << "Error: Can't assign NULL identifier" << std::endl; 528 } 489 529 } 490 this->identifier_ = identifier; 530 else 531 { 532 this->identifier_ = identifier; 533 } 491 534 return *this; 492 535 } … … 495 538 @brief Overloading of the * operator: returns the assigned identifier. 496 539 */ 497 inline Identifier* operator*() 540 inline Identifier* operator*() const 498 541 { 499 542 return this->identifier_; … … 520 563 @return The new object 521 564 */ 522 T* fabricate( )523 { 524 BaseObject* newObject = this->identifier_->fabricate( );565 T* fabricate(BaseObject* creator) const 566 { 567 BaseObject* newObject = this->identifier_->fabricate(creator); 525 568 526 569 // Check if the creation was successful … … 546 589 } 547 590 548 abort(); 591 assert(false); 592 return 0; 549 593 } 550 594 } -
code/trunk/src/core/Loader.cc
r1755 r2087 28 28 29 29 #include "Loader.h" 30 #include " Level.h"30 #include "XMLFile.h" 31 31 #include "BaseObject.h" 32 32 #include "Identifier.h" … … 34 34 #include "ObjectList.h" 35 35 #include "CoreIncludes.h" 36 #include " Script.h"36 #include "LuaBind.h" 37 37 #include "Namespace.h" 38 38 #include "util/Debug.h" … … 42 42 namespace orxonox 43 43 { 44 std::vector<std::pair<const Level*, ClassTreeMask> > Loader::levels_s;44 std::vector<std::pair<const XMLFile*, ClassTreeMask> > Loader::files_s; 45 45 ClassTreeMask Loader::currentMask_s; 46 46 47 bool Loader::open(const Level* level, const ClassTreeMask& mask)47 bool Loader::open(const XMLFile* file, const ClassTreeMask& mask) 48 48 { 49 Loader::add( level, mask);50 return Loader::load( level, mask);49 Loader::add(file, mask); 50 return Loader::load(file, mask); 51 51 } 52 52 … … 54 54 { 55 55 Loader::unload(); 56 Loader:: levels_s.clear();56 Loader::files_s.clear(); 57 57 } 58 58 59 void Loader::close(const Level* level)59 void Loader::close(const XMLFile* file) 60 60 { 61 Loader::unload( level);62 Loader::remove( level);61 Loader::unload(file); 62 Loader::remove(file); 63 63 } 64 64 65 void Loader::add(const Level* level, const ClassTreeMask& mask)65 void Loader::add(const XMLFile* file, const ClassTreeMask& mask) 66 66 { 67 if (! level)67 if (!file) 68 68 return; 69 Loader:: levels_s.insert(Loader::levels_s.end(), std::pair<const Level*, ClassTreeMask>(level, mask));69 Loader::files_s.insert(Loader::files_s.end(), std::pair<const XMLFile*, ClassTreeMask>(file, mask)); 70 70 } 71 71 72 void Loader::remove(const Level* level)72 void Loader::remove(const XMLFile* file) 73 73 { 74 if (! level)74 if (!file) 75 75 return; 76 for (std::vector<std::pair<const Level*, ClassTreeMask> >::iterator it = Loader::levels_s.begin(); it != Loader::levels_s.end(); ++it)76 for (std::vector<std::pair<const XMLFile*, ClassTreeMask> >::iterator it = Loader::files_s.begin(); it != Loader::files_s.end(); ++it) 77 77 { 78 if ((*it).first == level)78 if ((*it).first == file) 79 79 { 80 Loader:: levels_s.erase(it);80 Loader::files_s.erase(it); 81 81 break; 82 82 } … … 87 87 { 88 88 bool success = true; 89 for (std::vector<std::pair<const Level*, ClassTreeMask> >::iterator it = Loader::levels_s.begin(); it != Loader::levels_s.end(); ++it)89 for (std::vector<std::pair<const XMLFile*, ClassTreeMask> >::iterator it = Loader::files_s.begin(); it != Loader::files_s.end(); ++it) 90 90 if (!Loader::load((*it).first, (*it).second * mask)) 91 91 success = false; … … 111 111 } 112 112 113 bool Loader::load(const Level* level, const ClassTreeMask& mask)113 bool Loader::load(const XMLFile* file, const ClassTreeMask& mask) 114 114 { 115 if (! level)115 if (!file) 116 116 return false; 117 117 118 Loader::currentMask_s = level->getMask() * mask;118 Loader::currentMask_s = file->getMask() * mask; 119 119 120 120 // let Lua work this out: 121 //Script* lua; 122 /*Script::loadFile(level->getFile(), true); 123 Script::init(Script::getLuaState()); 124 Script::run();*/ 125 Script* lua = Script::getInstance(); 121 LuaBind* lua = LuaBind::getInstance(); 126 122 lua->clearLuaOutput(); 127 lua->loadFile( level->getFile(), true);123 lua->loadFile(file->getFilename(), true); 128 124 lua->run(); 129 125 130 126 try 131 127 { 132 COUT(0) << "Start loading " << level->getFile() << "..." << std::endl;128 COUT(0) << "Start loading " << file->getFilename() << "..." << std::endl; 133 129 COUT(3) << "Mask: " << Loader::currentMask_s << std::endl; 134 130 135 //ticpp::Document xmlfile( level->getFile());131 //ticpp::Document xmlfile(file->getFilename()); 136 132 //xmlfile.LoadFile(); 137 133 //ticpp::Element myelement(*Script::getFileString()); … … 148 144 149 145 COUT(4) << " creating root-namespace..." << std::endl; 150 Namespace* rootNamespace = new Namespace( );146 Namespace* rootNamespace = new Namespace(0); 151 147 rootNamespace->setLoaderIndentation(" "); 152 rootNamespace->set Level(level);148 rootNamespace->setFile(file); 153 149 rootNamespace->setNamespace(rootNamespace); 154 150 rootNamespace->setRoot(true); 155 151 rootNamespace->XMLPort(rootElement, XMLPort::LoadObject); 156 152 157 COUT(0) << "Finished loading " << level->getFile() << "." << std::endl;153 COUT(0) << "Finished loading " << file->getFilename() << "." << std::endl; 158 154 159 155 COUT(4) << "Namespace-tree:" << std::endl << rootNamespace->toString(" ") << std::endl; … … 164 160 { 165 161 COUT(1) << std::endl; 166 COUT(1) << "An error occurred in Loader.cc while loading " << level->getFile() << ":" << std::endl;162 COUT(1) << "An error occurred in Loader.cc while loading " << file->getFilename() << ":" << std::endl; 167 163 COUT(1) << ex.what() << std::endl; 168 164 COUT(1) << "Loading aborted." << std::endl; … … 171 167 } 172 168 173 void Loader::unload(const Level* level, const ClassTreeMask& mask)169 void Loader::unload(const XMLFile* file, const ClassTreeMask& mask) 174 170 { 175 if (! level)171 if (!file) 176 172 return; 177 173 for (ObjectList<BaseObject>::iterator it = ObjectList<BaseObject>::begin(); it; ) 178 174 { 179 if ((it->get Level() == level) && mask.isIncluded(it->getIdentifier()))175 if ((it->getFile() == file) && mask.isIncluded(it->getIdentifier())) 180 176 delete (*(it++)); 181 177 else … … 184 180 } 185 181 186 bool Loader::reload(const Level* level, const ClassTreeMask& mask)182 bool Loader::reload(const XMLFile* file, const ClassTreeMask& mask) 187 183 { 188 Loader::unload( level, mask);189 return Loader::load( level, mask);184 Loader::unload(file, mask); 185 return Loader::load(file, mask); 190 186 } 191 187 } -
code/trunk/src/core/Loader.h
r1505 r2087 35 35 36 36 #include "ClassTreeMask.h" 37 #include "Level.h"38 37 39 38 namespace orxonox … … 42 41 { 43 42 public: 44 static bool open(const Level* level, const ClassTreeMask& mask = ClassTreeMask());43 static bool open(const XMLFile* file, const ClassTreeMask& mask = ClassTreeMask()); 45 44 static void close(); 46 static void close(const Level* level);45 static void close(const XMLFile* file); 47 46 48 static void add(const Level* level, const ClassTreeMask& mask = ClassTreeMask());49 static void remove(const Level* level);47 static void add(const XMLFile* file, const ClassTreeMask& mask = ClassTreeMask()); 48 static void remove(const XMLFile* file); 50 49 51 50 static bool load(const ClassTreeMask& mask = ClassTreeMask()); … … 53 52 static bool reload(const ClassTreeMask& mask = ClassTreeMask()); 54 53 55 static bool load(const Level* level, const ClassTreeMask& mask = ClassTreeMask());56 static void unload(const Level* level, const ClassTreeMask& mask = ClassTreeMask());57 static bool reload(const Level* level, const ClassTreeMask& mask = ClassTreeMask());54 static bool load(const XMLFile* file, const ClassTreeMask& mask = ClassTreeMask()); 55 static void unload(const XMLFile* file, const ClassTreeMask& mask = ClassTreeMask()); 56 static bool reload(const XMLFile* file, const ClassTreeMask& mask = ClassTreeMask()); 58 57 59 58 static ClassTreeMask currentMask_s; 60 59 61 60 private: 62 static std::vector<std::pair<const Level*, ClassTreeMask> > levels_s;61 static std::vector<std::pair<const XMLFile*, ClassTreeMask> > files_s; 63 62 }; 64 63 } -
code/trunk/src/core/Namespace.cc
r1889 r2087 37 37 CreateFactory(Namespace); 38 38 39 Namespace::Namespace( ) :39 Namespace::Namespace(BaseObject* creator) : BaseObject(creator), 40 40 bAutogeneratedFileRootNamespace_(false), 41 41 bRoot_(false), -
code/trunk/src/core/Namespace.h
r1841 r2087 42 42 { 43 43 public: 44 Namespace( );44 Namespace(BaseObject* creator); 45 45 virtual ~Namespace(); 46 46 -
code/trunk/src/core/RootGameState.cc
r1824 r2087 39 39 namespace orxonox 40 40 { 41 SetCommandLineArgument(state, "gui").s etShortcut("s");41 SetCommandLineArgument(state, "gui").shortcut("s"); 42 42 43 43 RootGameState::RootGameState(const std::string& name) … … 147 147 148 148 // get initial state from command line 149 std::string initialState; 150 CommandLine::getValue<std::string>("state", &initialState); 151 gotoState(initialState); 149 gotoState(CommandLine::getValue("state")); 152 150 153 151 while (this->activeChild_) -
code/trunk/src/core/Super.h
r1841 r2087 73 73 #include "util/Debug.h" 74 74 #include "XMLIncludes.h" 75 #include "Event.h" 75 76 76 77 /////////////////////// … … 229 230 #define SUPER_changedVisibility(classname, functionname, ...) \ 230 231 SUPER_NOARGS(classname, functionname) 232 233 #define SUPER_processEvent(classname, functionname, ...) \ 234 SUPER_ARGS(classname, functionname, __VA_ARGS__) 231 235 // (1/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- 232 236 … … 433 437 () 434 438 SUPER_FUNCTION_GLOBAL_DECLARATION_PART2; 439 440 SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(4, processEvent, true, Event& event) 441 (event) 442 SUPER_FUNCTION_GLOBAL_DECLARATION_PART2; 435 443 // (2/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- 436 444 … … 479 487 SUPER_INTRUSIVE_DECLARATION(changedActivity); 480 488 SUPER_INTRUSIVE_DECLARATION(changedVisibility); 489 SUPER_INTRUSIVE_DECLARATION(processEvent); 481 490 // (3/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- 482 491 -
code/trunk/src/core/XMLIncludes.h
- Property svn:mergeinfo changed (with no actual effect on merging)
-
code/trunk/src/core/XMLPort.h
r1889 r2087 70 70 */ 71 71 #define XMLPortParam(classname, paramname, loadfunction, savefunction, xmlelement, mode) \ 72 XMLPortParamGeneric(xmlcontainer##loadfunction##savefunction, classname, classname, this, paramname, orxonox::createExecutor(orxonox::createFunctor(&classname::loadfunction), std::string( #classname ) + "::" + #loadfunction), orxonox::createExecutor(orxonox::createFunctor(&classname::savefunction), std::string( #classname ) + "::" + #savefunction), xmlelement, mode) 72 static ExecutorMember<classname>* xmlcontainer##loadfunction##savefunction##loadexecutor = orxonox::createExecutor(orxonox::createFunctor(&classname::loadfunction), std::string( #classname ) + "::" + #loadfunction); \ 73 static ExecutorMember<classname>* xmlcontainer##loadfunction##savefunction##saveexecutor = orxonox::createExecutor(orxonox::createFunctor(&classname::savefunction), std::string( #classname ) + "::" + #savefunction); \ 74 XMLPortParamGeneric(xmlcontainer##loadfunction##savefunction, classname, classname, this, paramname, xmlcontainer##loadfunction##savefunction##loadexecutor, xmlcontainer##loadfunction##savefunction##saveexecutor, xmlelement, mode) 73 75 /** 74 76 @brief This is the same as XMLPortParam, but you can set the template arguments needed to store the loadfunction. … … 83 85 */ 84 86 #define XMLPortParamTemplate(classname, paramname, loadfunction, savefunction, xmlelement, mode, ...) \ 85 XMLPortParamGeneric(xmlcontainer##loadfunction##savefunction, classname, classname, this, paramname, orxonox::createExecutor(orxonox::createFunctor<classname, __VA_ARGS__ >(&classname::loadfunction), std::string( #classname ) + "::" + #loadfunction), orxonox::createExecutor(orxonox::createFunctor(&classname::savefunction), std::string( #classname ) + "::" + #savefunction), xmlelement, mode) 87 static ExecutorMember<classname>* xmlcontainer##loadfunction##savefunction##loadexecutor = orxonox::createExecutor(orxonox::createFunctor<classname, __VA_ARGS__ >(&classname::loadfunction), std::string( #classname ) + "::" + #loadfunction); \ 88 static ExecutorMember<classname>* xmlcontainer##loadfunction##savefunction##saveexecutor = orxonox::createExecutor(orxonox::createFunctor(&classname::savefunction), std::string( #classname ) + "::" + #savefunction); \ 89 XMLPortParamGeneric(xmlcontainer##loadfunction##savefunction, classname, classname, this, paramname, xmlcontainer##loadfunction##savefunction##loadexecutor, xmlcontainer##loadfunction##savefunction##saveexecutor, xmlelement, mode) 86 90 87 91 // -------------------- … … 100 104 */ 101 105 #define XMLPortParamLoadOnly(classname, paramname, loadfunction, xmlelement, mode) \ 102 XMLPortParamGeneric(xmlcontainer##loadfunction##0, classname, classname, this, paramname, orxonox::createExecutor(orxonox::createFunctor(&classname::loadfunction), std::string( #classname ) + "::" + #loadfunction), 0, xmlelement, mode) 106 static ExecutorMember<classname>* xmlcontainer##loadfunction##0##loadexecutor = orxonox::createExecutor(orxonox::createFunctor(&classname::loadfunction), std::string( #classname ) + "::" + #loadfunction); \ 107 XMLPortParamGeneric(xmlcontainer##loadfunction##0, classname, classname, this, paramname, xmlcontainer##loadfunction##0##loadexecutor, 0, xmlelement, mode) 103 108 /** 104 109 @brief This is the same as XMLPortParamTemplate, but for load-only attributes (see XMLPortParamLoadOnly). 105 110 */ 106 111 #define XMLPortParamLoadOnlyTemplate(classname, paramname, loadfunction, xmlelement, mode, ...) \ 107 XMLPortParamGeneric(xmlcontainer##loadfunction##0, classname, classname, this, paramname, orxonox::createExecutor(orxonox::createFunctor<classname, __VA_ARGS__ >(&classname::loadfunction), std::string( #classname ) + "::" + #loadfunction), 0, xmlelement, mode) 112 static ExecutorMember<classname>* xmlcontainer##loadfunction##0##loadexecutor = orxonox::createExecutor(orxonox::createFunctor<classname, __VA_ARGS__ >(&classname::loadfunction), std::string( #classname ) + "::" + #loadfunction); \ 113 XMLPortParamGeneric(xmlcontainer##loadfunction##0, classname, classname, this, paramname, xmlcontainer##loadfunction##0##loadexecutor, 0, xmlelement, mode) 108 114 109 115 // ------------------ … … 130 136 */ 131 137 #define XMLPortParamExtern(classname, externclass, object, paramname, loadfunction, savefunction, xmlelement, mode) \ 132 XMLPortParamGeneric(xmlcontainer##loadfunction##savefunction, classname, externclass, object, paramname, orxonox::createExecutor(orxonox::createFunctor(&externclass::loadfunction), std::string( #externclass ) + "::" + #loadfunction), orxonox::createExecutor(orxonox::createFunctor(&externclass::savefunction), std::string( #externclass ) + "::" + #savefunction), xmlelement, mode); 138 static ExecutorMember<externclass>* xmlcontainer##loadfunction##savefunction##loadexecutor = orxonox::createExecutor(orxonox::createFunctor(&externclass::loadfunction), std::string( #externclass ) + "::" + #loadfunction); \ 139 static ExecutorMember<externclass>* xmlcontainer##loadfunction##savefunction##saveexecutor = orxonox::createExecutor(orxonox::createFunctor(&externclass::savefunction), std::string( #externclass ) + "::" + #savefunction); \ 140 XMLPortParamGeneric(xmlcontainer##loadfunction##savefunction, classname, externclass, object, paramname, xmlcontainer##loadfunction##savefunction##loadexecutor, xmlcontainer##loadfunction##savefunction##saveexecutor, xmlelement, mode); 133 141 /** 134 142 @brief This is the same as XMLPortParamTemplate, but for extern attributes (see XMLPortParamExtern). 135 143 */ 136 144 #define XMLPortParamExternTemplate(classname, externclass, object, paramname, loadfunction, savefunction, xmlelement, mode, ...) \ 137 XMLPortParamGeneric(xmlcontainer##loadfunction##savefunction, classname, externclass, object, paramname, orxonox::createExecutor(orxonox::createFunctor<externclass, __VA_ARGS__ >(&externclass::loadfunction), std::string( #externclass ) + "::" + #loadfunction), orxonox::createExecutor(orxonox::createFunctor(&externclass::savefunction), std::string( #externclass ) + "::" + #savefunction), xmlelement, mode); 145 static ExecutorMember<externclass>* xmlcontainer##loadfunction##savefunction##loadexecutor = orxonox::createExecutor(orxonox::createFunctor<externclass, __VA_ARGS__ >(&externclass::loadfunction), std::string( #externclass ) + "::" + #loadfunction); \ 146 static ExecutorMember<externclass>* xmlcontainer##loadfunction##savefunction##saveexecutor = orxonox::createExecutor(orxonox::createFunctor(&externclass::savefunction), std::string( #externclass ) + "::" + #savefunction); \ 147 XMLPortParamGeneric(xmlcontainer##loadfunction##savefunction, classname, externclass, object, paramname, xmlcontainer##loadfunction##savefunction##loadexecutor, xmlcontainer##loadfunction##savefunction##saveexecutor, xmlelement, mode); 138 148 139 149 // ------------------- … … 214 224 */ 215 225 #define XMLPortObjectExtended(classname, objectclass, sectionname, loadfunction, savefunction, xmlelement, mode, bApplyLoaderMask, bLoadBefore) \ 216 XMLPortObjectGeneric(xmlcontainer##loadfunction##savefunction, classname, objectclass, sectionname, orxonox::createExecutor(orxonox::createFunctor(&classname::loadfunction), std::string( #classname ) + "::" + #loadfunction), orxonox::createExecutor(orxonox::createFunctor(&classname::savefunction), std::string( #classname ) + "::" + #savefunction), xmlelement, mode, bApplyLoaderMask, bLoadBefore) 226 static ExecutorMember<classname>* xmlcontainer##loadfunction##savefunction##loadexecutor = orxonox::createExecutor(orxonox::createFunctor(&classname::loadfunction), std::string( #classname ) + "::" + #loadfunction); \ 227 static ExecutorMember<classname>* xmlcontainer##loadfunction##savefunction##saveexecutor = orxonox::createExecutor(orxonox::createFunctor(&classname::savefunction), std::string( #classname ) + "::" + #savefunction); \ 228 XMLPortObjectGeneric(xmlcontainer##loadfunction##savefunction, classname, objectclass, sectionname, xmlcontainer##loadfunction##savefunction##loadexecutor, xmlcontainer##loadfunction##savefunction##saveexecutor, xmlelement, mode, bApplyLoaderMask, bLoadBefore) 217 229 /** 218 230 @brief This is the same as XMLPortObjectExtended, but you can specify the loadfunction by adding the param types. See XMLPortParamTemplate for more details about the types. 219 231 */ 220 232 #define XMLPortObjectExtendedTemplate(classname, objectclass, sectionname, loadfunction, savefunction, xmlelement, mode, bApplyLoaderMask, bLoadBefore, ...) \ 221 XMLPortObjectGeneric(xmlcontainer##loadfunction##savefunction, classname, objectclass, sectionname, orxonox::createExecutor(orxonox::createFunctor< __VA_ARGS__ >(&classname::loadfunction), std::string( #classname ) + "::" + #loadfunction), orxonox::createExecutor(orxonox::createFunctor(&classname::savefunction), std::string( #classname ) + "::" + #savefunction), xmlelement, mode, bApplyLoaderMask, bLoadBefore) 233 static ExecutorMember<classname>* xmlcontainer##loadfunction##savefunction##loadexecutor = orxonox::createExecutor(orxonox::createFunctor<classname, __VA_ARGS__ >(&classname::loadfunction), std::string( #classname ) + "::" + #loadfunction); \ 234 static ExecutorMember<classname>* xmlcontainer##loadfunction##savefunction##saveexecutor = orxonox::createExecutor(orxonox::createFunctor(&classname::savefunction), std::string( #classname ) + "::" + #savefunction); \ 235 XMLPortObjectGeneric(xmlcontainer##loadfunction##savefunction, classname, objectclass, sectionname, xmlcontainer##loadfunction##savefunction##loadexecutor, xmlcontainer##loadfunction##savefunction##saveexecutor, xmlelement, mode, bApplyLoaderMask, bLoadBefore) 222 236 223 237 // ------------- … … 228 242 */ 229 243 #define XMLPortObject(classname, objectclass, sectionname, loadfunction, savefunction, xmlelement, mode) \ 230 XMLPortObjectGeneric(xmlcontainer##loadfunction##savefunction, classname, objectclass, sectionname, orxonox::createExecutor(orxonox::createFunctor(&classname::loadfunction), std::string( #classname ) + "::" + #loadfunction), orxonox::createExecutor(orxonox::createFunctor(&classname::savefunction), std::string( #classname ) + "::" + #savefunction), xmlelement, mode, false, true) 244 static ExecutorMember<classname>* xmlcontainer##loadfunction##savefunction##loadexecutor = orxonox::createExecutor(orxonox::createFunctor(&classname::loadfunction), std::string( #classname ) + "::" + #loadfunction); \ 245 static ExecutorMember<classname>* xmlcontainer##loadfunction##savefunction##saveexecutor = orxonox::createExecutor(orxonox::createFunctor(&classname::savefunction), std::string( #classname ) + "::" + #savefunction); \ 246 XMLPortObjectGeneric(xmlcontainer##loadfunction##savefunction, classname, objectclass, sectionname, xmlcontainer##loadfunction##savefunction##loadexecutor, xmlcontainer##loadfunction##savefunction##saveexecutor, xmlelement, mode, false, true) 231 247 /** 232 248 @brief This is the same as XMLPortObject, but you can specify the loadfunction by adding the param types. See XMLPortParamTemplate for more details about the types. 233 249 */ 234 250 #define XMLPortObjectTemplate(classname, objectclass, sectionname, loadfunction, savefunction, xmlelement, mode, ...) \ 235 XMLPortObjectGeneric(xmlcontainer##loadfunction##savefunction, classname, objectclass, sectionname, orxonox::createExecutor(orxonox::createFunctor< __VA_ARGS__ >(&classname::loadfunction), std::string( #classname ) + "::" + #loadfunction), orxonox::createExecutor(orxonox::createFunctor(&classname::savefunction), std::string( #classname ) + "::" + #savefunction), xmlelement, mode, false, true) 251 static ExecutorMember<classname>* xmlcontainer##loadfunction##savefunction##loadexecutor = orxonox::createExecutor(orxonox::createFunctor<classname, __VA_ARGS__ >(&classname::loadfunction), std::string( #classname ) + "::" + #loadfunction); \ 252 static ExecutorMember<classname>* xmlcontainer##loadfunction##savefunction##saveexecutor = orxonox::createExecutor(orxonox::createFunctor(&classname::savefunction), std::string( #classname ) + "::" + #savefunction); \ 253 XMLPortObjectGeneric(xmlcontainer##loadfunction##savefunction, classname, objectclass, sectionname, xmlcontainer##loadfunction##savefunction##loadexecutor, xmlcontainer##loadfunction##savefunction##saveexecutor, xmlelement, mode, false, true) 236 254 237 255 // -------------------- … … 336 354 { 337 355 COUT(1) << std::endl; 338 COUT(1) << "An error occurred in XMLPort.h while loading attribute '" << this->paramname_ << "' of '" << this->identifier_->getName() << "' (objectname: " << this->owner_->getName() << ") in " << this->owner_->get Levelfile() << ":" << std::endl;356 COUT(1) << "An error occurred in XMLPort.h while loading attribute '" << this->paramname_ << "' of '" << this->identifier_->getName() << "' (objectname: " << this->owner_->getName() << ") in " << this->owner_->getFilename() << ":" << std::endl; 339 357 COUT(1) << ex.what() << std::endl; 340 358 } … … 468 486 for (ticpp::Iterator<ticpp::Element> child = xmlsubelement->FirstChildElement(false); child != child.end(); child++) 469 487 { 470 Identifier* identifier = ClassBy Name(child->Value());488 Identifier* identifier = ClassByString(child->Value()); 471 489 if (identifier) 472 490 { 473 491 if (identifier->isA(Class(O))) 474 492 { 475 if ( this->identifierIsIncludedInLoaderMask(identifier))493 if (identifier->isLoadable()) 476 494 { 477 COUT(4) << ((BaseObject*)object)->getLoaderIndentation() << "fabricating " << child->Value() << "..." << std::endl; 478 479 BaseObject* newObject = identifier->fabricate(); 480 newObject->setLoaderIndentation(((BaseObject*)object)->getLoaderIndentation() + " "); 481 newObject->setLevel(((BaseObject*)object)->getLevel()); 482 newObject->setNamespace(((BaseObject*)object)->getNamespace()); 483 484 if (this->bLoadBefore_) 495 if (this->identifierIsIncludedInLoaderMask(identifier)) 485 496 { 486 newObject->XMLPort(*child, XMLPort::LoadObject); 487 COUT(4) << ((BaseObject*)object)->getLoaderIndentation() << "assigning " << child->Value() << " (objectname " << newObject->getName() << ") to " << this->identifier_->getName() << " (objectname " << ((BaseObject*)object)->getName() << ")" << std::endl; 497 COUT(4) << ((BaseObject*)object)->getLoaderIndentation() << "fabricating " << child->Value() << "..." << std::endl; 498 499 BaseObject* newObject = identifier->fabricate((BaseObject*)object); 500 assert(newObject); 501 newObject->setLoaderIndentation(((BaseObject*)object)->getLoaderIndentation() + " "); 502 503 O* castedObject = dynamic_cast<O*>(newObject); 504 assert(castedObject); 505 506 if (this->bLoadBefore_) 507 { 508 newObject->XMLPort(*child, XMLPort::LoadObject); 509 COUT(4) << ((BaseObject*)object)->getLoaderIndentation() << "assigning " << child->Value() << " (objectname " << newObject->getName() << ") to " << this->identifier_->getName() << " (objectname " << ((BaseObject*)object)->getName() << ")" << std::endl; 510 } 511 else 512 { 513 COUT(4) << ((BaseObject*)object)->getLoaderIndentation() << "assigning " << child->Value() << " (object not yet loaded) to " << this->identifier_->getName() << " (objectname " << ((BaseObject*)object)->getName() << ")" << std::endl; 514 } 515 516 COUT(5) << ((BaseObject*)object)->getLoaderIndentation(); 517 (*this->loadexecutor_)(object, castedObject); 518 519 if (!this->bLoadBefore_) 520 newObject->XMLPort(*child, XMLPort::LoadObject); 521 522 COUT(5) << ((BaseObject*)object)->getLoaderIndentation() << "...fabricated " << child->Value() << " (objectname " << newObject->getName() << ")." << std::endl; 488 523 } 489 else 490 { 491 COUT(4) << ((BaseObject*)object)->getLoaderIndentation() << "assigning " << child->Value() << " (object not yet loaded) to " << this->identifier_->getName() << " (objectname " << ((BaseObject*)object)->getName() << ")" << std::endl; 492 } 493 494 COUT(5) << ((BaseObject*)object)->getLoaderIndentation(); 495 (*this->loadexecutor_)(object, newObject); 496 497 if (!this->bLoadBefore_) 498 newObject->XMLPort(*child, XMLPort::LoadObject); 499 500 COUT(5) << ((BaseObject*)object)->getLoaderIndentation() << "...fabricated " << child->Value() << " (objectname " << newObject->getName() << ")." << std::endl; 524 } 525 else 526 { 527 COUT(2) << ((BaseObject*)object)->getLoaderIndentation() << "Warning: '" << child->Value() << "' is not loadable." << std::endl; 501 528 } 502 529 } … … 508 535 else 509 536 { 510 COUT(2) << object->getLoaderIndentation() << "Warning: '" << child->Value() << "' is not a valid classname." << std::endl; 537 if (this->sectionname_ != "") 538 { 539 COUT(2) << object->getLoaderIndentation() << "Warning: '" << child->Value() << "' is not a valid classname." << std::endl; 540 } 541 else 542 { 543 // It's probably just another subsection 544 } 511 545 } 512 546 } … … 516 550 { 517 551 COUT(1) << std::endl; 518 COUT(1) << "An error occurred in XMLPort.h while loading a '" << Class(O)->getName() << "' in '" << this->sectionname_ << "' of '" << this->identifier_->getName() << "' (objectname: " << ((BaseObject*)object)->getName() << ") in " << object->get Levelfile() << ":" << std::endl;552 COUT(1) << "An error occurred in XMLPort.h while loading a '" << Class(O)->getName() << "' in '" << this->sectionname_ << "' of '" << this->identifier_->getName() << "' (objectname: " << ((BaseObject*)object)->getName() << ") in " << object->getFilename() << ":" << std::endl; 519 553 COUT(1) << ex.what() << std::endl; 520 554 } -
code/trunk/src/core/input/Button.cc
r1887 r2087 175 175 176 176 // check for param command 177 int paramIndex = eval.getConsoleCommand()->get AxisParamIndex();177 int paramIndex = eval.getConsoleCommand()->getInputConfiguredParam_(); 178 178 if (paramIndex >= 0) 179 179 { 180 180 // parameter supported command 181 181 ParamCommand* cmd = new ParamCommand(); 182 cmd->paramModifier_ = paramModifier; 183 cmd->bRelative_ = eval.getConsoleCommand()->getIsAxisRelative(); 182 cmd->scale_ = paramModifier; 184 183 185 184 // add command to the buffer if not yet existing 186 185 for (unsigned int iParamCmd = 0; iParamCmd < paramCommandBuffer_->size(); iParamCmd++) 187 186 { 188 if ( getLowercase((*paramCommandBuffer_)[iParamCmd]->evaluation_.getOriginalCommand())189 == getLowercase(commandStr))187 if ((*paramCommandBuffer_)[iParamCmd]->evaluation_.getConsoleCommand() 188 == eval.getConsoleCommand()) 190 189 { 191 190 // already in list -
code/trunk/src/core/input/HalfAxis.h
r1887 r2087 50 50 , paramCommands_(0) 51 51 , nParamCommands_(0) 52 , wasDown_(false)52 , pressed_(false) 53 53 , hasChanged_(false) 54 54 { } … … 65 65 66 66 // button related 67 bool wasDown_;67 bool pressed_; 68 68 bool hasChanged_; 69 69 }; -
code/trunk/src/core/input/InputCommands.cc
r1887 r2087 34 34 35 35 #include "InputCommands.h" 36 #include "util/Math.h" 36 37 #include "core/CommandExecutor.h" 37 38 … … 51 52 bool BufferedParamCommand::execute() 52 53 { 53 if ( nValuesAdded_)54 if (this->abs_ != 0.0f || this->rel_ != 0.0f) 54 55 { 55 BufferedParamCommand& cmd = *this; 56 cmd.evaluation_.setEvaluatedParameter(cmd.paramIndex_, cmd.value_); 56 evaluation_.setEvaluatedParameter(paramIndex_, Vector2(abs_, rel_)); 57 57 // reset 58 cmd.nValuesAdded_ =0;59 cmd.value_ =0;60 return cmd.evaluation_.execute();58 rel_ = 0.0; 59 abs_ = 0.0; 60 return evaluation_.execute(); 61 61 } 62 62 else … … 79 79 BufferedParamCommand& cmd = *paramCommand_; 80 80 // command has an additional parameter 81 if ( bRelative_)81 if (rel != 0.0f) 82 82 { 83 if (rel != 0.0f) 84 { 85 // we have to calculate a relative movement. 86 // paramModifier_ says how much one keystroke is 87 cmd.value_ += paramModifier_ * rel; 88 } 83 // calculate relative movement. 84 // scale_ says how much one keystroke is 85 cmd.rel_ += scale_ * rel; 89 86 } 90 else if (abs != 0.0f) 87 88 if (abs != 0.0f) 91 89 { 92 // Usually, joy sticks create 'noise' (they return values if they're in 0 position) 93 // and normally this is caught in tickInput(), but that threshold cannot be to high 94 // in order to preserve accuracy. Instead, we have to catch the problem here. An example: 95 // Someone only uses buttons with an active joystick. The joy stick value could then 96 // be 0.05 for instance and the the key value 1. Without handling the problem, the final 97 // value would be computed to (1+0.05)/2=0.5025 which is not what the user expects. 98 float absQ = abs * abs; 99 float valueQ = cmd.value_ * cmd.value_; 100 if (absQ > 50.0f * valueQ) // ease up comparison by using quadratics 101 { 102 cmd.value_ = abs * paramModifier_; 103 cmd.nValuesAdded_ = 1; 104 } 105 else if (absQ * 50.0f < valueQ) 106 { 107 // abs is too small, we just don't do anything 108 } 109 else 110 { 111 // we have to calculate the absolute position of the axis. 112 // Since there might be another axis that is affected, we have to wait and 113 // store the result in a temporary place 114 cmd.value_ = (cmd.value_ * cmd.nValuesAdded_ + paramModifier_ * abs) / ++cmd.nValuesAdded_; 115 } 90 cmd.abs_ += scale_ * abs; 91 if (cmd.abs_ > 1.0) 92 cmd.abs_ = 1.0; 93 if (cmd.abs_ < -1.0) 94 cmd.abs_ = -1.0; 116 95 } 117 96 return true; -
code/trunk/src/core/input/InputCommands.h
r1887 r2087 44 44 { 45 45 public: 46 BufferedParamCommand() : value_(0.0f), nValuesAdded_(0), paramIndex_(-1) { }46 BufferedParamCommand() : abs_(0.0f), rel_(0.0), paramIndex_(-1) { } 47 47 bool execute(); 48 48 49 float value_;50 unsigned int nValuesAdded_;49 float abs_; 50 float rel_; 51 51 int paramIndex_; 52 52 CommandEvaluation evaluation_; … … 82 82 { 83 83 public: 84 ParamCommand() : bRelative_(false), paramModifier_(1.0f), paramCommand_(0) { }84 ParamCommand() : scale_(1.0f), paramCommand_(0) { } 85 85 bool execute(float abs = 1.0f, float rel = 1.0f); 86 86 87 bool bRelative_; 88 float paramModifier_; 87 float scale_; 89 88 BufferedParamCommand* paramCommand_; 90 89 }; -
code/trunk/src/core/input/KeyBinder.cc
r1887 r2087 137 137 SetConfigValue(analogThreshold_, 0.05f) 138 138 .description("Threshold for analog axes until which the state is 0."); 139 SetConfigValue(bFilterAnalogNoise_, false) 140 .description("Specifies whether to filter small analog values like joy stick fluctuations."); 139 141 SetConfigValue(mouseSensitivity_, 1.0f) 140 142 .description("Mouse sensitivity."); … … 145 147 SetConfigValue(mouseSensitivityDerived_, 1.0f) 146 148 .description("Mouse sensitivity if mouse input is derived."); 147 SetConfigValue(mouseWheelStepSize_, 120 .0f)149 SetConfigValue(mouseWheelStepSize_, 120) 148 150 .description("Equals one step of the mousewheel."); 149 151 SetConfigValue(buttonThreshold_, 0.80f) … … 323 325 void KeyBinder::tickMouse(float dt) 324 326 { 325 tickDevices(mouseAxes_, mouseAxes_ + MouseAxisCode::numberOfAxes * 2);326 327 327 if (bDeriveMouseInput_) 328 328 { 329 // only update when derive dt has passed 329 330 if (deriveTime_ > derivePeriod_) 330 331 { … … 357 358 deriveTime_ += dt; 358 359 } 359 } 360 361 void KeyBinder::tickDevices(HalfAxis* begin, HalfAxis* end) 362 { 363 for (HalfAxis* current = begin; current < end; ++current) // pointer arithmetic 364 { 365 // button mode 366 // TODO: optimize out all the half axes that don't act as a button at the moment 367 if (current->hasChanged_) 368 { 369 if (!current->wasDown_ && current->absVal_ > current->buttonThreshold_) 370 { 371 current->wasDown_ = true; 372 if (current->nCommands_[KeybindMode::OnPress]) 373 current->execute(KeybindMode::OnPress); 374 } 375 else if (current->wasDown_ && current->absVal_ < current->buttonThreshold_) 376 { 377 current->wasDown_ = false; 378 if (current->nCommands_[KeybindMode::OnRelease]) 379 current->execute(KeybindMode::OnRelease); 380 } 381 current->hasChanged_ = false; 382 } 383 384 if (current->wasDown_) 385 { 386 if (current->nCommands_[KeybindMode::OnHold]) 387 current->execute(KeybindMode::OnHold); 388 } 389 390 // these are the actually useful axis bindings for analog input 391 if (current->relVal_ > analogThreshold_ || current->absVal_ > analogThreshold_) 392 { 393 current->execute(); 394 } 360 361 for (unsigned int i = 0; i < MouseAxisCode::numberOfAxes * 2; i++) 362 { 363 // Why dividing relative value by dt? The reason lies in the simple fact, that when you 364 // press a button that has relative movement, that value has to be multiplied by dt to be 365 // frame rate independant. This can easily (and only) be done in tickInput(float). 366 // Hence we need to divide by dt here for the mouse to compensate, because the relative 367 // move movements have nothing to do with dt. 368 if (dt != 0.0f) 369 { 370 // just ignore if dt == 0.0 because we have multiplied by 0.0 anyway.. 371 mouseAxes_[i].relVal_ /= dt; 372 } 373 374 tickHalfAxis(mouseAxes_[i]); 375 } 376 } 377 378 void KeyBinder::tickJoyStick(float dt, unsigned int joyStick) 379 { 380 for (unsigned int i = 0; i < JoyStickAxisCode::numberOfAxes * 2; i++) 381 { 382 tickHalfAxis(joyStickAxes_[joyStick][i]); 383 } 384 } 385 386 void KeyBinder::tickHalfAxis(HalfAxis& halfAxis) 387 { 388 // button mode 389 // TODO: optimize out all the half axes that don't act as a button at the moment 390 if (halfAxis.hasChanged_) 391 { 392 if (!halfAxis.pressed_ && halfAxis.absVal_ > halfAxis.buttonThreshold_) 393 { 394 // key pressed event 395 halfAxis.pressed_ = true; 396 if (halfAxis.nCommands_[KeybindMode::OnPress]) 397 halfAxis.execute(KeybindMode::OnPress); 398 } 399 else if (halfAxis.pressed_ && halfAxis.absVal_ < halfAxis.buttonThreshold_) 400 { 401 // key released event 402 halfAxis.pressed_ = false; 403 if (halfAxis.nCommands_[KeybindMode::OnRelease]) 404 halfAxis.execute(KeybindMode::OnRelease); 405 } 406 halfAxis.hasChanged_ = false; 407 } 408 409 if (halfAxis.pressed_) 410 { 411 // key held event 412 if (halfAxis.nCommands_[KeybindMode::OnHold]) 413 halfAxis.execute(KeybindMode::OnHold); 414 } 415 416 // these are the actually useful axis bindings for analog input 417 if (!bFilterAnalogNoise_ || halfAxis.relVal_ > analogThreshold_ || halfAxis.absVal_ > analogThreshold_) 418 { 419 halfAxis.execute(); 395 420 } 396 421 } … … 407 432 int rel[] = { rel_.x, -rel_.y }; 408 433 409 if (!bDeriveMouseInput_) 434 if (bDeriveMouseInput_) 435 { 436 mouseRelative_[0] += rel[0]; 437 mouseRelative_[1] += rel[1]; 438 } 439 else 410 440 { 411 441 for (int i = 0; i < 2; i++) … … 437 467 } 438 468 } 439 else440 {441 mouseRelative_[0] += rel[0];442 mouseRelative_[1] += rel[1];443 }444 469 445 470 // relative -
code/trunk/src/core/input/KeyBinder.h
r1888 r2087 71 71 void tickJoyStick(float dt, unsigned int joyStick); 72 72 // internal 73 void tick Devices(HalfAxis* begin, HalfAxis* end);73 void tickHalfAxis(HalfAxis& halfAxis); 74 74 75 75 void buttonThresholdChanged(); … … 149 149 //! Filename of default keybindings. 150 150 std::string defaultKeybindings_; 151 //! Whether to filter small value analog input 152 bool bFilterAnalogNoise_; 151 153 //! Threshold for analog triggers until which the state is 0. 152 154 float analogThreshold_; … … 162 164 float mouseSensitivityDerived_; 163 165 //! Equals one step of the mousewheel 164 float mouseWheelStepSize_;166 int mouseWheelStepSize_; 165 167 166 168 //##### Constant config variables ##### … … 198 200 { joyStickButtons_[joyStickID][id].execute(KeybindMode::OnHold); } 199 201 200 inline void KeyBinder::tickJoyStick(float dt, unsigned int joyStick)201 {202 tickDevices(&joyStickAxes_[joyStick][0], &joyStickAxes_[joyStick][JoyStickAxisCode::numberOfAxes * 2]);203 }204 205 202 inline void KeyBinder::tickInput(float dt) 206 203 { 207 204 // execute all buffered bindings (additional parameter) 208 205 for (unsigned int i = 0; i < paramCommandBuffer_.size(); i++) 206 { 207 paramCommandBuffer_[i]->rel_ *= dt; 209 208 paramCommandBuffer_[i]->execute(); 209 } 210 210 211 211 // always reset the relative movement of the mouse -
code/trunk/src/core/tolua/tolua.pkg
r1755 r2087 1 $cfile "../../src/core/ Script.h"1 $cfile "../../src/core/LuaBind.h" 2 2 $cfile "../../src/core/CommandExecutor.h" -
code/trunk/src/lua/COPYRIGHT
- Property svn:eol-style set to native
-
code/trunk/src/lua/README
- Property svn:eol-style set to native
-
code/trunk/src/network/CMakeLists.txt
r1907 r2087 1 1 SET( NETWORK_SRC_FILES 2 ChatListener.cc 2 3 Client.cc 3 4 ClientConnection.cc 4 5 ClientInformation.cc 6 ClientConnectionListener.cc 5 7 ConnectionManager.cc 6 8 GamestateManager.cc -
code/trunk/src/network/Client.cc
r1907 r2087 39 39 // 40 40 41 #include <cassert> 42 41 43 #include "Client.h" 42 44 #include "Host.h" … … 44 46 #include "core/CoreIncludes.h" 45 47 #include "packet/Packet.h" 48 46 49 // #include "packet/Acknowledgement.h" 47 50 … … 67 70 * @param port port of the application on the server 68 71 */ 69 Client::Client( std::stringaddress, int port) : client_connection(port, address){72 Client::Client(const std::string& address, int port) : client_connection(port, address){ 70 73 isConnected=false; 71 74 isSynched_=false; … … 114 117 } 115 118 116 bool Client::processChat( std::stringmessage, unsigned int playerID){117 COUT(1) << "Player " << playerID << ": " << message << std::endl;119 bool Client::processChat(const std::string& message, unsigned int playerID){ 120 // COUT(1) << "Player " << playerID << ": " << message << std::endl; 118 121 return true; 119 122 } 120 123 121 124 /** 122 125 * This function implements the method of sending a chat message to the server 123 * @param message message to be sent 126 * @param message message to be sent 124 127 * @return result(true/false) 125 128 */ 126 bool Client::chat( std::stringmessage){129 bool Client::chat(const std::string& message){ 127 130 packet::Chat *m = new packet::Chat(message, Host::getPlayerID()); 128 131 return m->send(); … … 132 135 /** 133 136 * Processes incoming packets, sends a gamestate to the server and does the cleanup 134 * @param time 137 * @param time 135 138 */ 136 139 void Client::tick(float time){ … … 152 155 COUT(5) << "tick packet size " << event->packet->dataLength << std::endl; 153 156 packet::Packet *packet = packet::Packet::createPacket(event->packet, event->peer); 157 // note: packet commits suicide here except for the GameState. That is then deleted by a GamestateHandler 154 158 bool b = packet->process(); 155 159 assert(b); -
code/trunk/src/network/Client.h
r1907 r2087 66 66 public: 67 67 Client(); 68 Client( std::stringaddress, int port);68 Client(const std::string& address, int port); 69 69 Client(const char *address, int port); 70 70 ~Client(); 71 71 72 72 bool establishConnection(); 73 73 bool closeConnection(); 74 74 bool queuePacket(ENetPacket *packet, int clientID); 75 bool processChat(std::string message, unsigned int playerID); 76 virtual bool chat(std::string message); 75 bool processChat(const std::string& message, unsigned int playerID); 76 virtual bool chat(const std::string& message); 77 virtual bool broadcast(const std::string& message) { return false; } 77 78 //bool sendChat(packet::Chat *chat); 78 79 // static void Chat( std::string message ); 80 81 //static void setShipID( unsigned int shipID){ dynamic_cast<Client *>(instance_)->shipID_=shipID; } 82 static void setClientID( unsigned int clientID){ dynamic_cast<Client *>(instance_)->clientID_=clientID; } 83 79 84 80 void tick(float time); 85 81 86 82 private: 87 83 virtual bool isServer_(){return false;} 88 84 89 85 ClientConnection client_connection; 90 86 GamestateClient gamestate; 91 87 bool isConnected; 92 88 bool isSynched_; 93 89 94 90 bool gameStateFailure_; 95 91 }; -
code/trunk/src/network/ClientConnection.cc
r1907 r2087 54 54 boost::recursive_mutex ClientConnection::enet_mutex_; 55 55 56 ClientConnection::ClientConnection(int port, std::stringaddress) {56 ClientConnection::ClientConnection(int port, const std::string& address) { 57 57 quit=false; 58 58 server=NULL; … … 72 72 bool ClientConnection::waitEstablished(int milisec) { 73 73 for(int i=0; i<=milisec && !established; i++) 74 usleep(1000);74 msleep(1); 75 75 76 76 return established; … … 184 184 case ENET_EVENT_TYPE_NONE: 185 185 //receiverThread_->yield(); 186 usleep(1000);186 msleep(1); 187 187 break; 188 188 } -
code/trunk/src/network/ClientConnection.h
r1907 r2087 60 60 61 61 62 class ClientConnection{62 class _NetworkExport ClientConnection{ 63 63 public: 64 ClientConnection(int port, std::stringaddress);64 ClientConnection(int port, const std::string& address); 65 65 ClientConnection(int port, const char* address); 66 66 ~ClientConnection(); … … 96 96 ENetPeer *server; 97 97 boost::thread *receiverThread_; 98 98 99 99 static boost::recursive_mutex enet_mutex_; 100 100 }; -
code/trunk/src/network/ClientInformation.cc
r1735 r2087 45 45 namespace network 46 46 { 47 47 48 48 ClientInformation *ClientInformation::head_=0; 49 49 50 50 ClientInformation::ClientInformation() { 51 51 if(!head_) … … 59 59 60 60 ClientInformation::~ClientInformation() { 61 if(this==head_)62 head_=next();63 61 if(prev()!=0) 64 62 prev()->setNext(this->next()); 65 63 if(next()!=0) 66 64 next()->setPrev(this->prev()); 65 if(this==head_) 66 head_=next(); 67 67 } 68 68 … … 129 129 return true; 130 130 } 131 131 132 132 bool ClientInformation::setPartialGamestateID(int id){ 133 133 if(!this) … … 137 137 } 138 138 139 int ClientInformation::getID() {139 unsigned int ClientInformation::getID() { 140 140 if(!this) 141 141 return CLIENTID_UNKNOWN; … … 150 150 return NULL; 151 151 } 152 152 153 153 int ClientInformation::getFailures(){ 154 154 return failures_; … … 160 160 failures_=0; 161 161 } 162 162 163 163 enet_uint32 ClientInformation::getRTT(){ 164 return peer_->roundTripTime;165 } 166 167 enet_uint32ClientInformation::getPacketLoss(){168 return peer_->packetLoss;169 } 170 171 int ClientInformation::getGamestateID() {164 return this->peer_->roundTripTime; 165 } 166 167 double ClientInformation::getPacketLoss(){ 168 return ((double)this->peer_->packetLoss)/ENET_PEER_PACKET_LOSS_SCALE; 169 } 170 171 unsigned int ClientInformation::getGamestateID() { 172 172 if(this) 173 173 return gamestateID_; 174 174 else 175 return -1;176 } 177 178 int ClientInformation::getPartialGamestateID() {175 return (unsigned int)-1; 176 } 177 178 unsigned int ClientInformation::getPartialGamestateID() { 179 179 if(this) 180 180 return partialGamestateID_; 181 181 else 182 return -1;182 return (unsigned int)-1; 183 183 } 184 184 185 185 ClientInformation *ClientInformation::insertBack(ClientInformation *ins) { 186 186 ClientInformation *temp = head_; 187 if(temp== head_){187 if(temp==ins){ 188 188 return head_; 189 189 } … … 196 196 } 197 197 198 bool ClientInformation::removeClient( int clientID) {199 if( clientID==CLIENTID_UNKNOWN)198 bool ClientInformation::removeClient(unsigned int clientID) { 199 if((unsigned int)clientID==CLIENTID_UNKNOWN) 200 200 return false; 201 201 ClientInformation *temp = head_; … … 229 229 * @return pointer to the last element in the list or 0 if the search was unsuccessfull 230 230 */ 231 ClientInformation *ClientInformation::findClient( int clientID, bool look_backwards) {231 ClientInformation *ClientInformation::findClient(unsigned int clientID, bool look_backwards) { 232 232 ClientInformation *temp = head_; 233 233 while(temp!=0 && temp->getID()!=clientID){ -
code/trunk/src/network/ClientInformation.h
r1735 r2087 46 46 #include <boost/thread/recursive_mutex.hpp> 47 47 48 #define GAMESTATEID_INITIAL -149 #define CLIENTID_UNKNOWN -250 51 48 // WATCH OUT: THE CLIENTINFORMATION LIST IS NOT THREADSAFE ANYMORE 52 49 53 50 namespace network 54 51 { 52 static const unsigned int GAMESTATEID_INITIAL = (unsigned int)-1; 53 static const unsigned int CLIENTID_UNKNOWN = (unsigned int)-2; 54 55 55 /** 56 56 * This class implements a list for client informations 57 57 * @author Oliver Scheuss 58 58 */ 59 class ClientInformation{59 class _NetworkExport ClientInformation{ 60 60 public: 61 61 ClientInformation(); … … 66 66 ClientInformation *prev(); 67 67 static ClientInformation *insertBack(ClientInformation *ins); 68 68 69 69 // set functions 70 70 void setID(int clientID); … … 73 73 bool setPartialGamestateID(int id); 74 74 inline void setShipID(unsigned int id){ShipID_=id;} 75 75 76 76 // get functions 77 77 inline unsigned int getShipID(){return ShipID_;} 78 int getID();79 int getGamestateID();80 int getPartialGamestateID();78 unsigned int getID(); 79 unsigned int getGamestateID(); 80 unsigned int getPartialGamestateID(); 81 81 ENetPeer *getPeer(); 82 82 83 83 int getFailures(); 84 84 void addFailure(); 85 85 void resetFailures(); 86 86 enet_uint32 getRTT(); 87 enet_uint32getPacketLoss();88 89 static bool removeClient( int clientID);87 double getPacketLoss(); 88 89 static bool removeClient(unsigned int clientID); 90 90 static bool removeClient(ENetPeer *peer); 91 static ClientInformation *findClient( int clientID, bool look_backwards=false);91 static ClientInformation *findClient(unsigned int clientID, bool look_backwards=false); 92 92 static ClientInformation *findClient(ENetAddress *address, bool look_backwards=false); 93 93 static ClientInformation *getBegin(){return head_;} … … 99 99 private: 100 100 static ClientInformation *head_; 101 101 102 102 bool setNext(ClientInformation *next); 103 103 bool setPrev(ClientInformation *prev); 104 104 ClientInformation *insertAfter(ClientInformation *ins); 105 105 ClientInformation *insertBefore(ClientInformation *ins); 106 106 107 107 ClientInformation *preve; 108 108 ClientInformation *nexte; 109 109 //actual information: 110 110 ENetPeer *peer_; 111 int clientID_;112 int gamestateID_;113 int partialGamestateID_;111 unsigned int clientID_; 112 unsigned int gamestateID_; 113 unsigned int partialGamestateID_; 114 114 unsigned int ShipID_; // this is the unique objectID 115 115 bool synched_; 116 116 unsigned short failures_; 117 117 118 118 }; 119 119 -
code/trunk/src/network/ConnectionManager.cc
r1907 r2087 49 49 #include "core/BaseObject.h" 50 50 #include "core/Iterator.h" 51 #include "objects/SpaceShip.h"52 51 #include "util/Math.h" 53 52 #include "util/Sleep.h" … … 89 88 } 90 89 91 ConnectionManager::ConnectionManager(int port, std::stringaddress) :receiverThread_(0) {90 ConnectionManager::ConnectionManager(int port, const std::string& address) :receiverThread_(0) { 92 91 assert(instance_==0); 93 92 instance_=this; … … 228 227 case ENET_EVENT_TYPE_NONE: 229 228 //receiverThread_->yield(); 230 usleep(1000);229 msleep(1); 231 230 break; 232 231 } … … 331 330 332 331 333 334 bool ConnectionManager::removeShip(ClientInformation *client){335 unsigned int id=client->getShipID();336 orxonox::ObjectList<orxonox::SpaceShip>::iterator it;337 for(it = orxonox::ObjectList<orxonox::SpaceShip>::begin(); it; ++it){338 if(it->getObjectID()!=id)339 continue;340 delete *it;341 }342 return true;343 }344 345 346 332 void ConnectionManager::disconnectClient(ClientInformation *client){ 347 333 { … … 350 336 lock.unlock(); 351 337 } 352 removeShip(client);353 338 } 354 339 -
code/trunk/src/network/ConnectionManager.h
r1785 r2087 66 66 const int NETWORK_DEFAULT_CHANNEL = 0; 67 67 68 struct ClientList{68 struct _NetworkExport ClientList{ 69 69 ENetEvent *event; 70 70 int ID; … … 72 72 }; 73 73 74 class ConnectionManager{74 class _NetworkExport ConnectionManager{ 75 75 public: 76 76 static boost::recursive_mutex enet_mutex; … … 79 79 ConnectionManager(int port); 80 80 ConnectionManager(int port, const char *address); 81 ConnectionManager(int port, std::stringaddress);81 ConnectionManager(int port, const std::string& address); 82 82 ~ConnectionManager(); 83 83 //ENetPacket *getPacket(ENetAddress &address); // thread1 … … 107 107 int getClientID(ENetAddress address); 108 108 ENetPeer *getClientPeer(int clientID); 109 //bool createShip(ClientInformation *client);110 bool removeShip(ClientInformation *client);111 109 PacketBuffer buffer; 112 110 -
code/trunk/src/network/GamestateClient.cc
r1907 r2087 29 29 #include "GamestateClient.h" 30 30 31 #include <cassert> 31 32 #include <zlib.h> 32 33 … … 40 41 namespace network 41 42 { 42 struct GameStateItem{43 struct _NetworkExport GameStateItem{ 43 44 packet::Gamestate *state; 44 int id;45 unsigned int id; 45 46 }; 46 47 … … 50 51 last_gamestate_=GAMESTATEID_INITIAL-1; 51 52 tempGamestate_=NULL; 52 myShip_=NULL;53 53 } 54 54 … … 56 56 } 57 57 58 bool GamestateClient::ack( int gamestateID,int clientID){58 bool GamestateClient::ack(unsigned int gamestateID, unsigned int clientID){ 59 59 return true; 60 60 } 61 61 62 bool GamestateClient::add(packet::Gamestate *gs, int clientID){62 bool GamestateClient::add(packet::Gamestate *gs, unsigned int clientID){ 63 63 if(tempGamestate_!=NULL){ 64 64 //delete the obsolete gamestate … … 75 75 return false; 76 76 int id = GAMESTATEID_INITIAL; 77 bool b = saveShipCache();78 77 packet::Gamestate *processed = processGamestate(tempGamestate_); 79 if(!processed){80 if(b)81 loadShipCache();82 return false;83 }84 78 // assert(processed); 79 if (!processed) 80 return false; 85 81 //successfully loaded data from gamestate. now save gamestate for diff and delete the old gs 86 82 tempGamestate_=NULL; 87 83 gamestateMap_[processed->getID()]=processed; 88 84 last_diff_ = processed->getID(); 89 if(b)90 loadShipCache();91 85 id = processed->getID(); 92 86 sendAck(id); … … 108 102 packet::Gamestate *GamestateClient::getGamestate(){ 109 103 packet::Gamestate *gs = new packet::Gamestate(); 110 gs->collectData(0); 104 if(!gs->collectData(0)){ 105 delete gs; 106 return 0; 107 } 111 108 return gs; 112 109 } 113 110 114 111 void GamestateClient::cleanup(){ 115 std::map< int, packet::Gamestate*>::iterator temp, it = gamestateMap_.begin();112 std::map<unsigned int, packet::Gamestate*>::iterator temp, it = gamestateMap_.begin(); 116 113 while(it!=gamestateMap_.end()){ 117 114 if(it->first>=last_diff_) … … 126 123 127 124 void GamestateClient::printGamestateMap(){ 128 std::map< int, packet::Gamestate*>::iterator it;125 std::map<unsigned int, packet::Gamestate*>::iterator it; 129 126 COUT(4) << "gamestates: "; 130 127 for(it=gamestateMap_.begin(); it!=gamestateMap_.end(); it++){ … … 134 131 135 132 } 136 133 137 134 bool GamestateClient::sendAck(unsigned int gamestateID){ 138 135 packet::Acknowledgement *ack = new packet::Acknowledgement(gamestateID, 0); … … 142 139 } 143 140 else{ 144 COUT( 3) << "acked a gamestate: " << gamestateID << std::endl;141 COUT(5) << "acked a gamestate: " << gamestateID << std::endl; 145 142 return true; 146 143 } 147 }148 149 bool GamestateClient::saveShipCache(){150 if(myShip_==NULL){151 myShip_ = orxonox::SpaceShip::getLocalShip();152 // COUT(2) << "myShip_: " << myShip_ << " getLocalShip(): " << orxonox::SpaceShip::getLocalShip() << std::endl;153 if(!myShip_)154 return false;155 }156 if(myShip_){157 // unsigned char *data = new unsigned char[myShip_->getSize()];158 int size=myShip_->getSize(0, 0x1);159 if(size==0)160 return false;161 shipCache_ = new unsigned char [size];162 unsigned char *temp = shipCache_;163 if(!myShip_->getData(temp, 0, 0x1))164 COUT(3) << "could not save shipCache" << std::endl;165 return true;166 }else167 return false;168 }169 170 bool GamestateClient::loadShipCache(){171 myShip_=orxonox::SpaceShip::getLocalShip(); //TODO: remove this (only a hack)172 if(myShip_ && shipCache_){173 assert(myShip_->getIdentifier());174 unsigned char *temp = shipCache_;175 myShip_->updateData(temp, 0x2);176 delete shipCache_;177 return true;178 }else179 return false;180 144 } 181 145 … … 196 160 delete gs; 197 161 gs=undiffed; 198 COUT( 3) << "successfully undiffed gamestate id: " << undiffed->getID() << std::endl;162 COUT(5) << "successfully undiffed gamestate id: " << undiffed->getID() << std::endl; 199 163 } 200 164 if(gs->spreadData()) -
code/trunk/src/network/GamestateClient.h
r1769 r2087 46 46 #include "core/CorePrereqs.h" 47 47 #include "packet/Gamestate.h" 48 #include "objects/SpaceShip.h"49 48 #include "GamestateHandler.h" 50 49 51 #define GAMESTATEID_INITIAL -1 50 const unsigned int GAMESTATEID_INITIAL = (unsigned int)-1; 52 51 53 52 namespace network 54 53 { 55 class GamestateClient: public GamestateHandler54 class _NetworkExport GamestateClient: public GamestateHandler 56 55 { 57 56 public: … … 59 58 ~GamestateClient(); 60 59 61 bool add(packet::Gamestate *gs, int clientID);62 bool ack( int gamestateID,int clientID);60 bool add(packet::Gamestate *gs, unsigned int clientID); 61 bool ack(unsigned int gamestateID, unsigned int clientID); 63 62 64 63 bool processGamestates(); … … 70 69 void printGamestateMap(); 71 70 bool sendAck(unsigned int gamestateID); 72 bool saveShipCache();73 bool loadShipCache();74 71 75 int last_diff_;76 int last_gamestate_;77 std::map< int, packet::Gamestate *> gamestateMap_;72 unsigned int last_diff_; 73 unsigned int last_gamestate_; 74 std::map<unsigned int, packet::Gamestate *> gamestateMap_; 78 75 packet::Gamestate *tempGamestate_; // we save the received gamestates here during processQueue 79 orxonox::SpaceShip *myShip_;80 76 unsigned char *shipCache_; 81 77 -
code/trunk/src/network/GamestateHandler.h
r1763 r2087 39 39 @author Oliver Scheuss 40 40 */ 41 class GamestateHandler{41 class _NetworkExport GamestateHandler{ 42 42 private: 43 virtual bool add(packet::Gamestate *gs, int clientID)=0;44 virtual bool ack( int gamestateID,int clientID)=0;43 virtual bool add(packet::Gamestate *gs, unsigned int clientID)=0; 44 virtual bool ack(unsigned int gamestateID, unsigned int clientID)=0; 45 45 46 46 static GamestateHandler *instance_; … … 52 52 53 53 public: 54 static bool addGamestate(packet::Gamestate *gs, int clientID){ return instance_->add(gs, clientID); }55 static bool ackGamestate( int gamestateID,int clientID){ return instance_->ack(gamestateID, clientID); }54 static bool addGamestate(packet::Gamestate *gs, unsigned int clientID){ return instance_->add(gs, clientID); } 55 static bool ackGamestate(unsigned int gamestateID, unsigned int clientID){ return instance_->ack(gamestateID, clientID); } 56 56 }; 57 57 -
code/trunk/src/network/GamestateManager.cc
r1907 r2087 64 64 return getSnapshot(); 65 65 } 66 67 bool GamestateManager::add(packet::Gamestate *gs, int clientID){66 67 bool GamestateManager::add(packet::Gamestate *gs, unsigned int clientID){ 68 68 assert(gs); 69 std::map< int, packet::Gamestate*>::iterator it = gamestateQueue.find(clientID);69 std::map<unsigned int, packet::Gamestate*>::iterator it = gamestateQueue.find(clientID); 70 70 if(it!=gamestateQueue.end()){ 71 71 // delete obsolete gamestate … … 75 75 return true; 76 76 } 77 77 78 78 bool GamestateManager::processGamestates(){ 79 std::map< int, packet::Gamestate*>::iterator it;79 std::map<unsigned int, packet::Gamestate*>::iterator it; 80 80 // now push only the most recent gamestates we received (ignore obsolete ones) 81 81 for(it = gamestateQueue.begin(); it!=gamestateQueue.end(); it++){ 82 assert(processGamestate(it->second)); 82 bool b = processGamestate(it->second); 83 assert(b); 83 84 delete it->second; 84 85 } … … 87 88 return true; 88 89 } 89 90 90 91 91 92 bool GamestateManager::getSnapshot(){ 92 93 reference = new packet::Gamestate(); 93 reference->collectData(++id_);94 //COUT(4) << "inserting gamestate: " << reference << std::endl;95 //gamestateMap_.insert(std::pair<int, packet::Gamestate*>(id_, reference));96 // gamestateUsed[id_]=0; 97 return true; 98 } 99 94 if(!reference->collectData(++id_)){ //we have no data to send 95 delete reference; 96 reference=0; 97 } 98 return true; 99 } 100 100 101 /** 101 102 * this function is used to keep the memory usage low 102 103 * it tries to delete all the unused gamestates 103 * 104 * 104 * 105 * 105 106 */ 106 107 /* void GamestateManager::cleanup(){ … … 126 127 }*/ 127 128 128 packet::Gamestate *GamestateManager::popGameState( int clientID) {129 packet::Gamestate *GamestateManager::popGameState(unsigned int clientID) { 129 130 //why are we searching the same client's gamestate id as we searched in 130 131 //Server::sendGameState? 131 132 packet::Gamestate *gs; 132 int gID = ClientInformation::findClient(clientID)->getGamestateID(); 133 unsigned int gID = ClientInformation::findClient(clientID)->getGamestateID(); 134 if(!reference) 135 return 0; 133 136 gs = reference->doSelection(clientID); 134 137 // gs = new packet::Gamestate(*reference); … … 139 142 packet::Gamestate *client=NULL; 140 143 if(gID != GAMESTATEID_INITIAL){ 141 std::map<unsigned int, std::map< int, packet::Gamestate*> >::iterator clientMap = gamestateMap_.find(clientID);144 std::map<unsigned int, std::map<unsigned int, packet::Gamestate*> >::iterator clientMap = gamestateMap_.find(clientID); 142 145 if(clientMap!=gamestateMap_.end()){ 143 std::map< int, packet::Gamestate*>::iterator it = clientMap->second.find(gID);146 std::map<unsigned int, packet::Gamestate*>::iterator it = clientMap->second.find(gID); 144 147 if(it!=clientMap->second.end()) 145 148 client = it->second; … … 158 161 return gs; 159 162 } 160 161 162 bool GamestateManager::ack( int gamestateID,int clientID) {163 164 165 bool GamestateManager::ack(unsigned int gamestateID, unsigned int clientID) { 163 166 ClientInformation *temp = ClientInformation::findClient(clientID); 164 167 assert(temp); 165 int curid = temp->getGamestateID();166 168 unsigned int curid = temp->getGamestateID(); 169 167 170 if(gamestateID == 0){ 168 171 temp->setGamestateID(GAMESTATEID_INITIAL); 169 172 return true; 170 173 } 171 172 assert(curid <gamestateID);174 175 assert(curid==(unsigned int)GAMESTATEID_INITIAL || curid<gamestateID); 173 176 COUT(4) << "acking gamestate " << gamestateID << " for clientid: " << clientID << " curid: " << curid << std::endl; 174 std::map< int, packet::Gamestate*>::iterator it, tempit;177 std::map<unsigned int, packet::Gamestate*>::iterator it, tempit; 175 178 for(it = gamestateMap_[clientID].begin(); it!=gamestateMap_[clientID].end() && it->first<gamestateID; it++){ 176 179 delete it->second; … … 184 187 void GamestateManager::removeClient(ClientInformation* client){ 185 188 assert(client); 186 std::map<unsigned int, std::map< int, packet::Gamestate*> >::iterator clientMap = gamestateMap_.find(client->getID());189 std::map<unsigned int, std::map<unsigned int, packet::Gamestate*> >::iterator clientMap = gamestateMap_.find(client->getID()); 187 190 // first delete all remained gamestates 188 std::map< int, packet::Gamestate*>::iterator it;191 std::map<unsigned int, packet::Gamestate*>::iterator it; 189 192 for(it=clientMap->second.begin(); it!=clientMap->second.end(); it++) 190 193 delete it->second; … … 192 195 gamestateMap_.erase(clientMap); 193 196 } 194 197 195 198 bool GamestateManager::processGamestate(packet::Gamestate *gs){ 196 199 if(gs->isCompressed()) -
code/trunk/src/network/GamestateManager.h
r1907 r2087 66 66 * @author Oliver Scheuss 67 67 */ 68 class GamestateManager: public GamestateHandler{68 class _NetworkExport GamestateManager: public GamestateHandler{ 69 69 public: 70 70 GamestateManager(); 71 71 ~GamestateManager(); 72 72 73 bool add(packet::Gamestate *gs, int clientID);73 bool add(packet::Gamestate *gs, unsigned int clientID); 74 74 bool processGamestates(); 75 75 bool update(); 76 packet::Gamestate *popGameState( int clientID);76 packet::Gamestate *popGameState(unsigned int clientID); 77 77 78 78 bool getSnapshot(); 79 79 80 bool ack( int gamestateID,int clientID);80 bool ack(unsigned int gamestateID, unsigned int clientID); 81 81 void removeClient(ClientInformation *client); 82 82 private: … … 84 84 bool processGamestate(packet::Gamestate *gs); 85 85 86 std::map<unsigned int, std::map< int, packet::Gamestate*> > gamestateMap_;86 std::map<unsigned int, std::map<unsigned int, packet::Gamestate*> > gamestateMap_; 87 87 //std::map<int, packet::Gamestate*> gamestateMap; //map gsID to gamestate* 88 88 //std::map<int, int> gamestateUsed; // save the number of clients, that use the specific gamestate 89 std::map< int, packet::Gamestate*> gamestateQueue;89 std::map<unsigned int, packet::Gamestate*> gamestateQueue; 90 90 packet::Gamestate *reference; 91 int id_;91 unsigned int id_; 92 92 }; 93 93 -
code/trunk/src/network/Host.cc
r1907 r2087 32 32 #include "core/ConsoleCommand.h" 33 33 #include "packet/Packet.h" 34 #include "ChatListener.h" 34 35 35 36 namespace network { … … 38 39 39 40 Host *Host::instance_=0; 40 41 41 42 /** 42 43 * @brief Constructor: assures that only one reference will be created and sets the pointer … … 90 91 * @return playerID 91 92 */ 92 unsigned int Host::getPlayerID(){ 93 unsigned int Host::getPlayerID(){ 93 94 if(!instance_) 94 95 return 0; … … 96 97 } 97 98 98 bool Host::Chat( std::stringmessage){99 bool Host::Chat(const std::string& message){ 99 100 if(!instance_) 100 101 return false; … … 102 103 } 103 104 104 bool Host::incomingChat(std::string message, unsigned int playerID){ 105 bool Host::Broadcast(const std::string& message){ 106 if(!instance_) 107 return false; 108 return instance_->broadcast(message); 109 } 110 111 bool Host::incomingChat(const std::string& message, unsigned int playerID){ 112 for (orxonox::ObjectList<ChatListener>::iterator it = orxonox::ObjectList<ChatListener>::begin(); it != orxonox::ObjectList<ChatListener>::end(); ++it) 113 it->incomingChat(message, playerID); 114 105 115 return instance_->processChat(message, playerID); 106 116 } -
code/trunk/src/network/Host.h
r1907 r2087 44 44 * @author Oliver Scheuss 45 45 */ 46 class Host{46 class _NetworkExport Host{ 47 47 private: 48 48 //TODO add theese functions or adequate … … 50 50 //virtual bool sendChat(packet::Chat *chat)=0; 51 51 virtual bool queuePacket(ENetPacket *packet, int clientID)=0; 52 virtual bool chat(std::string message)=0; 53 virtual bool processChat(std::string message, unsigned int playerID)=0; 52 virtual bool chat(const std::string& message)=0; 53 virtual bool broadcast(const std::string& message)=0; 54 virtual bool processChat(const std::string& message, unsigned int playerID)=0; 54 55 virtual bool isServer_()=0; 55 56 … … 72 73 static void setClientID(unsigned int id){ instance_->clientID_ = id; } 73 74 static void setShipID(unsigned int id){ instance_->shipID_ = id; } 74 static bool isServer(){ return instance_->isServer_(); } 75 static bool Chat(std::string message); 76 static bool incomingChat(std::string message, unsigned int playerID); 75 static bool isServer(){ return instance_->isServer_(); } 76 static bool Chat(const std::string& message); 77 static bool Broadcast(const std::string& message); 78 static bool incomingChat(const std::string& message, unsigned int playerID); 77 79 private: 78 80 }; -
code/trunk/src/network/NetworkCallback.h
r1536 r2087 2 2 #define _NETWORK_CALLBACK__ 3 3 4 #include "NetworkPrereqs.h" 5 4 6 namespace network{ 5 class NetworkCallbackBase7 class _NetworkExport NetworkCallbackBase 6 8 { 7 9 public: … … 9 11 virtual ~NetworkCallbackBase() {} 10 12 }; 11 13 12 14 template <class T> 13 15 class NetworkCallback: public NetworkCallbackBase … … 18 20 virtual void call() 19 21 { (this->object_->*function_)(); } 20 22 21 23 private: 22 24 T* object_; 23 25 void (T::*function_) (void); 24 }; 26 }; 25 27 26 28 -
code/trunk/src/network/NetworkPrereqs.h
r1735 r2087 63 63 class Client; 64 64 class ClientConnection; 65 class ClientConnectionListener; 65 66 class ClientFrameListener; 66 67 class ClientInformation; -
code/trunk/src/network/PacketBuffer.h
r1505 r2087 49 49 namespace network 50 50 { 51 struct PacketEnvelope{51 struct _NetworkExport PacketEnvelope{ 52 52 int length; 53 53 int data; 54 54 }; 55 55 56 struct QueueItem{56 struct _NetworkExport QueueItem{ 57 57 ENetEvent *event; 58 58 //ENetAddress address; … … 60 60 }; 61 61 62 class PacketBuffer{62 class _NetworkExport PacketBuffer{ 63 63 public: 64 64 PacketBuffer(); -
code/trunk/src/network/Server.cc
r1907 r2087 46 46 47 47 #include "ConnectionManager.h" 48 #include "ClientConnectionListener.h" 48 49 #include "GamestateManager.h" 49 50 #include "ClientInformation.h" 50 51 #include "util/Sleep.h" 51 #include "objects/SpaceShip.h"52 52 #include "core/ConsoleCommand.h" 53 53 #include "core/CoreIncludes.h" … … 58 58 #include "packet/DeleteObjects.h" 59 59 #include <util/Convert.h> 60 #include "ChatListener.h" 60 61 61 62 namespace network 62 63 { 63 const int MAX_FAILURES = 20; 64 const int NETWORK_FREQUENCY = 30; 64 const unsigned int MAX_FAILURES = 20; 65 const unsigned int NETWORK_FREQUENCY = 25; 66 const float NETWORK_PERIOD = (float)1/NETWORK_FREQUENCY; 65 67 66 68 /** … … 85 87 * @param bindAddress Address to listen on 86 88 */ 87 Server::Server(int port, std::stringbindAddress) {89 Server::Server(int port, const std::string& bindAddress) { 88 90 timeSinceLastUpdate_=0; 89 91 connection = new ConnectionManager(port, bindAddress); … … 101 103 gamestates_ = new GamestateManager(); 102 104 } 103 105 104 106 /** 105 107 * @brief Destructor … … 128 130 } 129 131 130 bool Server::processChat( std::stringmessage, unsigned int playerID){132 bool Server::processChat(const std::string& message, unsigned int playerID){ 131 133 ClientInformation *temp = ClientInformation::getBegin(); 132 134 packet::Chat *chat; … … 138 140 temp = temp->next(); 139 141 } 140 COUT(1) << "Player " << playerID << ": " << message << std::endl;142 // COUT(1) << "Player " << playerID << ": " << message << std::endl; 141 143 return true; 142 144 } … … 152 154 //this steers our network frequency 153 155 timeSinceLastUpdate_+=time; 154 if(timeSinceLastUpdate_>= (1./NETWORK_FREQUENCY)){155 timeSinceLastUpdate_ =(float)((int)(timeSinceLastUpdate_*NETWORK_FREQUENCY))/timeSinceLastUpdate_;156 if(timeSinceLastUpdate_>=NETWORK_PERIOD){ 157 timeSinceLastUpdate_ -= static_cast<unsigned int>( timeSinceLastUpdate_ / NETWORK_PERIOD ) * NETWORK_PERIOD; 156 158 gamestates_->processGamestates(); 157 159 updateGamestate(); … … 162 164 return connection->addPacket(packet, clientID); 163 165 } 164 166 167 /** 168 * @brief: returns ping time to client in milliseconds 169 */ 170 unsigned int Server::getPing(unsigned int clientID){ 171 assert(ClientInformation::findClient(clientID)); 172 return ClientInformation::findClient(clientID)->getRTT(); 173 } 174 175 /** 176 * @brief: return packet loss ratio to client (scales from 0 to 1) 177 */ 178 double Server::getPacketLoss(unsigned int clientID){ 179 assert(ClientInformation::findClient(clientID)); 180 return ClientInformation::findClient(clientID)->getPacketLoss(); 181 } 182 165 183 /** 166 184 * processes all the packets waiting in the queue … … 239 257 if(gs==NULL){ 240 258 COUT(2) << "Server: could not generate gamestate (NULL from compress)" << std::endl; 259 temp = temp->next(); 241 260 continue; 242 261 } … … 281 300 282 301 bool Server::addClient(ENetEvent *event){ 302 static unsigned int newid=1; 303 304 COUT(2) << "Server: adding client" << std::endl; 283 305 ClientInformation *temp = ClientInformation::insertBack(new ClientInformation); 284 306 if(!temp){ … … 286 308 return false; 287 309 } 288 if(temp==ClientInformation::getBegin()) { //not good if you use anything else than insertBack289 temp->setID(1);310 /*if(temp==ClientInformation::getBegin()) { //not good if you use anything else than insertBack 311 newid=1; 290 312 } 291 313 else 292 temp->setID(temp->prev()->getID()+1); 314 newid=temp->prev()->getID()+1;*/ 315 temp->setID(newid); 293 316 temp->setPeer(event->peer); 317 318 // inform all the listeners 319 orxonox::ObjectList<ClientConnectionListener>::iterator listener = orxonox::ObjectList<ClientConnectionListener>::begin(); 320 while(listener){ 321 listener->clientConnected(newid); 322 listener++; 323 } 324 325 newid++; 326 294 327 COUT(3) << "Server: added client id: " << temp->getID() << std::endl; 295 328 return createClient(temp->getID()); 296 329 } 297 330 298 331 bool Server::createClient(int clientID){ … … 304 337 COUT(4) << "Con.Man: creating client id: " << temp->getID() << std::endl; 305 338 connection->syncClassid(temp->getID()); 306 COUT(5) << "creating spaceship for clientid: " << temp->getID() << std::endl;307 // TODO: this is only a hack, untill we have a possibility to define default player-join actions308 if(!createShip(temp))309 COUT(2) << "Con.Man. could not create ship for clientid: " << clientID << std::endl;310 else311 COUT(3) << "created spaceship" << std::endl;312 339 temp->setSynched(true); 313 340 COUT(3) << "sending welcome" << std::endl; … … 319 346 g->setClientID(temp->getID()); 320 347 b = g->collectData(0); 321 assert(b); 348 if(!b) 349 return false; //no data for the client 322 350 b = g->compressData(); 323 351 assert(b); … … 327 355 } 328 356 329 bool Server::createShip(ClientInformation *client){330 if(!client)331 return false;332 orxonox::Identifier* id = ClassByName("SpaceShip");333 if(!id){334 COUT(4) << "We could not create the SpaceShip for client: " << client->getID() << std::endl;335 return false;336 }337 orxonox::SpaceShip *no = dynamic_cast<orxonox::SpaceShip *>(id->fabricate());338 no->classID = id->getNetworkID();339 client->setShipID(no->getObjectID());340 no->setPosition(orxonox::Vector3(0,0,80));341 no->setScale(10);342 //no->setYawPitchRoll(orxonox::Degree(-90),orxonox::Degree(-90),orxonox::Degree(0));343 no->setMesh("assff.mesh");344 no->setMaxSpeed(500);345 no->setMaxSideAndBackSpeed(50);346 no->setMaxRotation(1.0);347 no->setTransAcc(200);348 no->setRotAcc(3.0);349 no->setTransDamp(75);350 no->setRotDamp(1.0);351 no->setCamera(std::string("cam_") + convertToString(client->getID()));352 no->create();353 354 return true;355 }356 357 357 bool Server::disconnectClient(ENetEvent *event){ 358 358 COUT(4) << "removing client from list" << std::endl; … … 360 360 361 361 //boost::recursive_mutex::scoped_lock lock(head_->mutex_); 362 orxonox::ObjectList<orxonox::SpaceShip>::iterator it = orxonox::ObjectList<orxonox::SpaceShip>::begin();363 362 ClientInformation *client = ClientInformation::findClient(&event->peer->address); 364 363 if(!client) 365 364 return false; 366 365 gamestates_->removeClient(client); 367 while(it){ 368 if(it->getObjectID()!=client->getShipID()){ 369 ++it; 370 continue; 371 } 372 orxonox::ObjectList<orxonox::SpaceShip>::iterator temp=it; 373 ++it; 374 delete *temp; 375 return ClientInformation::removeClient(event->peer); 376 } 377 return false; 366 367 // inform all the listeners 368 orxonox::ObjectList<ClientConnectionListener>::iterator listener = orxonox::ObjectList<ClientConnectionListener>::begin(); 369 while(listener){ 370 listener->clientDisconnected(client->getID()); 371 listener++; 372 } 373 374 return ClientInformation::removeClient(event->peer); 378 375 } 379 376 … … 387 384 gamestates_->removeClient(client); 388 385 } 389 390 bool Server::chat(std::string message){ 386 387 bool Server::chat(const std::string& message){ 388 return this->sendChat(message, Host::getPlayerID()); 389 } 390 391 bool Server::broadcast(const std::string& message){ 392 return this->sendChat(message, CLIENTID_UNKNOWN); 393 } 394 395 bool Server::sendChat(const std::string& message, unsigned int clientID){ 391 396 ClientInformation *temp = ClientInformation::getBegin(); 392 397 packet::Chat *chat; 393 398 while(temp){ 394 chat = new packet::Chat(message, Host::getPlayerID());399 chat = new packet::Chat(message, clientID); 395 400 chat->setClientID(temp->getID()); 396 401 if(!chat->send()) … … 398 403 temp = temp->next(); 399 404 } 400 COUT(1) << "Player " << Host::getPlayerID() << ": " << message << std::endl; 405 // COUT(1) << "Player " << Host::getPlayerID() << ": " << message << std::endl; 406 for (orxonox::ObjectList<ChatListener>::iterator it = orxonox::ObjectList<ChatListener>::begin(); it != orxonox::ObjectList<ChatListener>::end(); ++it) 407 it->incomingChat(message, clientID); 408 401 409 return true; 402 410 } -
code/trunk/src/network/Server.h
r1907 r2087 52 52 { 53 53 const int CLIENTID_SERVER = 0; 54 54 55 55 /** 56 56 * This class is the root class of the network module for a server. … … 61 61 Server(); 62 62 Server(int port); 63 Server(int port, std::stringbindAddress);63 Server(int port, const std::string& bindAddress); 64 64 Server(int port, const char *bindAddress); 65 65 ~Server(); 66 66 67 67 void open(); 68 68 void close(); 69 bool processChat( std::stringmessage, unsigned int playerID);69 bool processChat(const std::string& message, unsigned int playerID); 70 70 bool queuePacket(ENetPacket *packet, int clientID); 71 71 void tick(float time); 72 unsigned int getPing(unsigned int clientID); 73 double getPacketLoss(unsigned int clientID); 72 74 protected: 73 75 void processQueue(); … … 77 79 unsigned int shipID(){return 0;} 78 80 unsigned int playerID(){return 0;} 79 81 80 82 bool addClient(ENetEvent *event); 81 83 bool createClient(int clientID); 82 bool createShip(ClientInformation *client);83 84 bool disconnectClient(ENetEvent *event); 84 85 void disconnectClient(int clientID); … … 87 88 bool sendGameState(); 88 89 bool sendObjectDeletes(); 89 virtual bool chat(std::string message); 90 90 virtual bool chat(const std::string& message); 91 virtual bool broadcast(const std::string& message); 92 bool sendChat(const std::string& message, unsigned int clientID); 93 91 94 //void processChat( chat *data, int clientId); 92 95 ConnectionManager *connection; 93 96 GamestateManager *gamestates_; 94 97 95 98 96 99 float timeSinceLastUpdate_; 97 100 }; -
code/trunk/src/network/Synchronisable.cc
r1907 r2087 42 42 43 43 #include <cstring> 44 #include <string> 44 45 #include <iostream> 45 46 #include <assert.h> … … 51 52 namespace network 52 53 { 53 54 54 55 55 56 std::map<unsigned int, Synchronisable *> Synchronisable::objectMap_; … … 62 63 * Initializes all Variables and sets the right objectID 63 64 */ 64 Synchronisable::Synchronisable( ){65 Synchronisable::Synchronisable(orxonox::BaseObject* creator){ 65 66 RegisterRootObject(Synchronisable); 66 67 static uint32_t idCounter=0; … … 68 69 objectMode_=0x1; // by default do not send data to server 69 70 objectID=idCounter++; 71 classID = (unsigned int)-1; 70 72 syncList = new std::list<synchronisableVariable *>; 71 } 72 73 /** 74 * Destructor: 73 74 this->creatorID = OBJECTID_UNKNOWN; 75 76 searchcreatorID: 77 if (creator) 78 { 79 Synchronisable* synchronisable_creator = dynamic_cast<Synchronisable*>(creator); 80 if (synchronisable_creator && synchronisable_creator->objectMode_) 81 { 82 this->creatorID = synchronisable_creator->getObjectID(); 83 } 84 else if (creator != creator->getCreator()) 85 { 86 creator = creator->getCreator(); 87 goto searchcreatorID; 88 } 89 } 90 } 91 92 /** 93 * Destructor: 75 94 * Delete all callback objects and remove objectID from the objectMap_ 76 95 */ … … 80 99 for(std::list<synchronisableVariable *>::iterator it = syncList->begin(); it!=syncList->end(); it++) 81 100 delete (*it)->callback; 82 deletedObjects_.push(objectID); 101 if (this->objectMode_ != 0x0) 102 deletedObjects_.push(objectID); 83 103 // COUT(3) << "destruct synchronisable +++" << objectID << " | " << classID << std::endl; 84 104 // COUT(3) << " bump ---" << objectID << " | " << &objectMap_ << std::endl; … … 96 116 this->classID = this->getIdentifier()->getNetworkID(); 97 117 // COUT(4) << "creating synchronisable: setting classid from " << this->getIdentifier()->getName() << " to: " << classID << std::endl; 98 118 99 119 // COUT(3) << "construct synchronisable +++" << objectID << " | " << classID << std::endl; 100 120 // objectMap_[objectID]=this; … … 127 147 synchronisableHeader *header = (synchronisableHeader *)mem; 128 148 129 COUT(3) << "fabricating object with id: " << header->objectID << std::endl; 149 if(!header->dataAvailable) 150 { 151 mem += header->size; 152 return 0; 153 } 154 155 COUT(4) << "fabricating object with id: " << header->objectID << std::endl; 130 156 131 157 orxonox::Identifier* id = ClassByID(header->classID); 132 158 assert(id); 133 orxonox::BaseObject *bo = id->fabricate(); 159 orxonox::BaseObject* creator = 0; 160 if (header->creatorID != OBJECTID_UNKNOWN) 161 { 162 Synchronisable* synchronisable_creator = Synchronisable::getSynchronisable(header->creatorID); 163 if (!synchronisable_creator) 164 { 165 mem += header->size; //.TODO: this suckz.... remove size from header 166 return 0; 167 } 168 else 169 creator = dynamic_cast<orxonox::BaseObject*>(synchronisable_creator); 170 } 171 orxonox::BaseObject *bo = id->fabricate(creator); 172 assert(bo); 134 173 Synchronisable *no = dynamic_cast<Synchronisable *>(bo); 135 174 assert(no); 136 175 no->objectID=header->objectID; 176 no->creatorID=header->creatorID; //TODO: remove this 137 177 no->classID=header->classID; 138 COUT( 3) << "fabricate objectID: " << no->objectID << " classID: " << no->classID << std::endl;178 COUT(4) << "fabricate objectID: " << no->objectID << " classID: " << no->classID << std::endl; 139 179 // update data and create object/entity... 140 bool b = no->updateData(mem, mode );180 bool b = no->updateData(mem, mode, true); 141 181 assert(b); 142 b = no->create(); 143 assert(b); 182 if (b) 183 { 184 b = no->create(); 185 assert(b); 186 } 144 187 return no; 145 188 } 146 189 147 190 148 191 /** 149 192 * Finds and deletes the Synchronisable with the appropriate objectID … … 164 207 return true; 165 208 } 166 209 167 210 /** 168 211 * This function looks up the objectID in the objectMap_ and returns a pointer to the right Synchronisable … … 185 228 } 186 229 187 230 188 231 /** 189 232 * This function is used to register a variable to be synchronized … … 196 239 */ 197 240 void Synchronisable::registerVar(void *var, int size, variableType t, int mode, NetworkCallbackBase *cb){ 241 assert( mode==direction::toclient || mode==direction::toserver || mode==direction::serverMaster || mode==direction::clientMaster); 198 242 // create temporary synch.Var struct 199 243 synchronisableVariable *temp = new synchronisableVariable; … … 203 247 temp->type = t; 204 248 temp->callback = cb; 249 if( ( mode & direction::bidirectional ) ) 250 { 251 temp->varBuffer = new uint8_t[size]; 252 memcpy(temp->varBuffer, temp->var, size); //now fill the buffer for the first time 253 temp->varReference = 0; 254 } 205 255 COUT(5) << "Syncronisable::registering var with size: " << temp->size << " and type: " << temp->type << std::endl; 206 256 //std::cout << "push temp to syncList (at the bottom) " << datasize << std::endl; … … 228 278 * 0x2: client->server (not recommended) 229 279 * 0x3: bidirectional 230 * @return true: if ! isMyTickor if everything was successfully saved280 * @return true: if !doSync or if everything was successfully saved 231 281 */ 232 282 bool Synchronisable::getData(uint8_t*& mem, unsigned int id, int mode){ 233 283 //if this tick is we dont synchronise, then abort now 234 if(! isMyTick(id))284 if(!doSync(id)) 235 285 return true; 236 286 //std::cout << "inside getData" << std::endl; … … 240 290 if(classID==0) 241 291 COUT(3) << "classid 0 " << this->getIdentifier()->getName() << std::endl; 292 293 if (this->classID == (unsigned int)-1) 294 this->classID = this->getIdentifier()->getNetworkID(); 295 242 296 assert(this->classID==this->getIdentifier()->getNetworkID()); 243 297 // this->classID=this->getIdentifier()->getNetworkID(); // TODO: correct this … … 250 304 header->size = size; 251 305 header->objectID = this->objectID; 306 header->creatorID = this->creatorID; 252 307 header->classID = this->classID; 253 308 header->dataAvailable = true; … … 263 318 COUT(5) << "not getting data: " << std::endl; 264 319 continue; // this variable should only be received 320 } 321 // if the variable gets synchronised bidirectional, then add the reference to the bytestream 322 if( ( (*i)->mode & direction::bidirectional ) == direction::bidirectional ) 323 { 324 *(uint8_t*)mem = (*i)->varReference; 325 mem += sizeof( (*i)->varReference ); 326 tempsize += sizeof( (*i)->varReference ); 265 327 } 266 328 switch((*i)->type){ … … 271 333 break; 272 334 case STRING: 273 memcpy( (void *)(mem), (void *)&((*i)->size), sizeof( int) );274 mem+=sizeof( int);335 memcpy( (void *)(mem), (void *)&((*i)->size), sizeof(size_t) ); 336 mem+=sizeof(size_t); 275 337 const char *data = ( ( *(std::string *) (*i)->var).c_str()); 276 338 memcpy( mem, (void*)data, (*i)->size); 277 339 COUT(5) << "synchronisable: char: " << (const char *)(mem) << " data: " << data << " string: " << *(std::string *)((*i)->var) << std::endl; 278 340 mem+=(*i)->size; 279 tempsize+=(*i)->size + 4;341 tempsize+=(*i)->size + sizeof(size_t); 280 342 break; 281 343 } … … 292 354 * @return true/false 293 355 */ 294 bool Synchronisable::updateData(uint8_t*& mem, int mode ){356 bool Synchronisable::updateData(uint8_t*& mem, int mode, bool forceCallback){ 295 357 if(mode==0x0) 296 358 mode=state_; … … 305 367 synchronisableHeader *syncHeader = (synchronisableHeader *)mem; 306 368 assert(syncHeader->objectID==this->objectID); 369 // assert(syncHeader->creatorID==this->creatorID); 307 370 if(syncHeader->dataAvailable==false){ 308 371 mem+=syncHeader->size; … … 314 377 assert(this->objectID==syncHeader->objectID); 315 378 // assert(this->classID==syncHeader->classID); //TODO: fix this!!! maybe a problem with the identifier ? 316 379 317 380 COUT(5) << "Synchronisable: objectID " << syncHeader->objectID << ", classID " << syncHeader->classID << " size: " << syncHeader->size << " synchronising data" << std::endl; 318 381 for(i=syncList->begin(); i!=syncList->end() && mem <= data+syncHeader->size; i++){ … … 325 388 switch((*i)->type){ 326 389 case DATA: 390 if( ( (*i)->mode & direction::bidirectional ) == direction::bidirectional ) 391 { 392 if( ( mode == 0x1 && (*i)->mode == direction::serverMaster ) || \ 393 ( mode == 0x2 && (*i)->mode == direction::clientMaster ) ) // if true we are master on this variable 394 { 395 uint8_t refNr = *(uint8_t *)mem; 396 if( refNr != (*i)->varReference ) 397 { 398 mem += sizeof((*i)->varReference) + (*i)->size; // the reference for this variable is not recent, discard data 399 break; 400 } 401 } 402 else //we are slave for this variable 403 { 404 (*i)->varReference = *(uint8_t *)mem; //copy the reference value for this variable 405 } 406 mem += sizeof((*i)->varReference); 407 } 327 408 if((*i)->callback) // check whether this variable changed (but only if callback was set) 328 409 if(strncmp((char *)(*i)->var, (char *)mem, (*i)->size)!=0) … … 332 413 break; 333 414 case STRING: 334 (*i)->size = *(uint32_t *)mem; 415 if( ( (*i)->mode & direction::bidirectional ) == direction::bidirectional ) 416 { 417 if( ( mode == 0x1 && (*i)->mode == direction::serverMaster ) || \ 418 ( mode == 0x2 && (*i)->mode == direction::clientMaster ) ) // if true we are master for this variable 419 { 420 uint8_t refNr = *(uint8_t *)mem; 421 mem += sizeof( (*i)->varReference ); 422 if( refNr != (*i)->varReference ){ 423 mem += sizeof(size_t) + *(size_t *)mem; // the reference for this variable is not recent, discard data 424 break; 425 } 426 } 427 else //we are slave for this variable 428 { 429 (*i)->varReference = *(uint8_t *)mem; //copy the reference value for this variable 430 } 431 mem += sizeof( (*i)->varReference ); 432 } 433 (*i)->size = *(size_t *)mem; 335 434 COUT(5) << "string size: " << (*i)->size << std::endl; 336 mem +=sizeof(int);435 mem += sizeof(size_t); 337 436 if((*i)->callback) // check whether this string changed 338 437 if( *(std::string *)((*i)->var) != std::string((char *)mem) ) … … 344 443 } 345 444 // call the callback function, if defined 346 if( callback&& (*i)->callback)445 if((callback || forceCallback) && (*i)->callback) 347 446 (*i)->callback->call(); 348 447 } … … 357 456 */ 358 457 uint32_t Synchronisable::getSize(unsigned int id, int mode){ 359 if(! isMyTick(id))458 if(!doSync(id)) 360 459 return 0; 361 460 int tsize=sizeof(synchronisableHeader); … … 377 476 break; 378 477 } 478 if( ( (*i)->mode & direction::bidirectional ) == direction::bidirectional ) 479 { 480 tsize+=sizeof( (*i)->varReference ); 481 } 379 482 } 380 483 return tsize; … … 386 489 * @return true/false 387 490 */ 388 bool Synchronisable:: isMyTick(unsigned int id){389 return ( (objectMode_&state_)!=0 );491 bool Synchronisable::doSync(unsigned int id){ 492 return ( (objectMode_&state_)!=0 && (!syncList->empty() ) ); 390 493 } 391 494 … … 413 516 */ 414 517 void Synchronisable::setObjectMode(int mode){ 415 assert(mode==0x 1 || mode==0x2 || mode==0x3);518 assert(mode==0x0 || mode==0x1 || mode==0x2 || mode==0x3); 416 519 objectMode_=mode; 417 520 } -
code/trunk/src/network/Synchronisable.h
r1910 r2087 41 41 #include "util/Integers.h" 42 42 43 #define REGISTERDATA(varname) registerVar(&varname, sizeof(varname), network::DATA) 44 #define REGISTERDATA_WITHDIR(varname, mode) registerVar(&varname, sizeof(varname), network::DATA, mode) 45 #define REGISTERSTRING(stringname) registerVar(&stringname, stringname.length()+1, network::STRING) 46 #define REGISTERSTRING_WITHDIR(stringname, mode) registerVar(&stringname, stringname.length()+1, network::STRING, mode) 47 48 //TODO: this is only a very ugly hack ... 49 namespace orxonox{ 50 class SpaceShip; 51 } 43 #define REGISTERDATA(varname, ...) \ 44 registerVar((void*)&varname, sizeof(varname), network::DATA, __VA_ARGS__) 45 #define REGISTERSTRING(stringname, ...) \ 46 registerVar(&stringname, stringname.length()+1, network::STRING, __VA_ARGS__) 52 47 53 48 namespace network 54 49 { 50 static const unsigned int OBJECTID_UNKNOWN = (unsigned int)-1; 51 55 52 namespace direction{ 56 53 enum syncdirection{ 57 54 toclient=0x1, 58 55 toserver=0x2, 59 bidirectional=0x3 56 bidirectional=0x3, 57 serverMaster=0x3, 58 clientMaster=0x7 60 59 }; 61 60 } 62 61 63 62 namespace syncmode{ 64 63 enum mode{ … … 67 66 }; 68 67 } 69 68 70 69 enum variableType{ 71 70 DATA, … … 73 72 }; 74 73 75 struct synchronisableHeader{74 struct _NetworkExport synchronisableHeader{ 76 75 uint32_t size:31; 77 76 bool dataAvailable:1; 78 77 uint32_t objectID; 78 uint32_t creatorID; 79 79 uint32_t classID; 80 80 }; 81 81 82 typedef struct synchronisableVariable{82 struct _NetworkExport synchronisableVariable{ 83 83 unsigned int size; 84 84 int mode; // this determines in which direction the variable gets synchronised … … 86 86 variableType type; 87 87 NetworkCallbackBase *callback; 88 }SYNCVAR; 88 void *varBuffer; 89 uint8_t varReference; 90 }; 89 91 90 92 /** … … 98 100 friend class GamestateClient; 99 101 friend class Server; 100 friend class orxonox::SpaceShip;101 102 virtual ~Synchronisable(); 102 103 103 104 104 105 virtual bool create(); 105 106 static void setClient(bool b); 106 107 107 108 static Synchronisable *fabricate(uint8_t*& mem, int mode=0x0); 108 109 static bool deleteObject(unsigned int objectID); … … 110 111 static unsigned int getNumberOfDeletedObject(){ return deletedObjects_.size(); } 111 112 static unsigned int popDeletedObject(){ unsigned int i = deletedObjects_.front(); deletedObjects_.pop(); return i; } 112 113 113 114 inline unsigned int getObjectID(){return objectID;} 114 115 inline unsigned int getClassID(){return classID;} 115 116 protected: 116 Synchronisable( );117 Synchronisable(orxonox::BaseObject* creator); 117 118 void registerVar(void *var, int size, variableType t, int mode=1, NetworkCallbackBase *cb=0); 118 119 void setObjectMode(int mode); 119 120 void setObjectFrequency(unsigned int freq){ objectFrequency_ = freq; } 120 virtual void registerAllVariables()=0; 121 122 121 122 123 123 private: 124 124 bool getData(uint8_t*& men, unsigned int id, int mode=0x0); 125 125 uint32_t getSize(unsigned int id, int mode=0x0); 126 bool updateData(uint8_t*& mem, int mode=0x0 );126 bool updateData(uint8_t*& mem, int mode=0x0, bool forceCallback=false); 127 127 bool isMyData(uint8_t* mem); 128 128 bool doSelection(unsigned int id); 129 bool isMyTick(unsigned int id);130 129 bool doSync(unsigned int id); 130 131 131 unsigned int objectID; 132 unsigned int creatorID; 132 133 unsigned int classID; 133 134 134 135 std::list<synchronisableVariable *> *syncList; 135 136 static int state_; // detemines wheter we are server (default) or client -
code/trunk/src/network/packet/Acknowledgement.h
r1907 r2087 29 29 #define NETWORKACKNOLEDGEMENT_H 30 30 31 #include "../NetworkPrereqs.h" 31 32 #include "Packet.h" 32 33 … … 35 36 namespace packet { 36 37 /** 37 @author 38 @author 38 39 */ 39 class Acknowledgement : public Packet40 class _NetworkExport Acknowledgement : public Packet 40 41 { 41 42 public: … … 43 44 Acknowledgement( uint8_t* data, unsigned int clientID ); 44 45 ~Acknowledgement(); 45 46 46 47 inline unsigned int getSize() const; 47 48 bool process(); 48 49 49 50 unsigned int getAckID(); 50 51 private: -
code/trunk/src/network/packet/Chat.h
r1907 r2087 2 2 #ifndef NETWORKCHAT_H 3 3 #define NETWORKCHAT_H 4 5 #include "../NetworkPrereqs.h" 4 6 5 7 #include <string> … … 11 13 namespace packet { 12 14 /** 13 @author 15 @author 14 16 */ 15 class Chat : public Packet17 class _NetworkExport Chat : public Packet 16 18 { 17 19 public: … … 19 21 Chat( uint8_t* data, unsigned int clientID ); 20 22 ~Chat(); 21 23 22 24 inline unsigned int getSize() const; 23 25 bool process(); 24 26 25 27 unsigned int getMessageLength(){ return messageLength_; }; 26 28 unsigned char *getMessage(); -
code/trunk/src/network/packet/ClassID.h
r1907 r2087 29 29 #define NETWORKCLASSID_H 30 30 31 #include "../NetworkPrereqs.h" 32 31 33 #include <string> 32 34 … … 37 39 38 40 /** 39 @author 41 @author 40 42 */ 41 class ClassID : public Packet43 class _NetworkExport ClassID : public Packet 42 44 { 43 45 public: … … 45 47 ClassID( uint8_t* data, unsigned int clientID ); 46 48 ~ClassID(); 47 49 48 50 inline unsigned int getSize() const; 49 51 bool process(); 50 52 51 53 unsigned int getClassID(); 52 54 unsigned int getClassNameLength(){ return classNameLength_; } -
code/trunk/src/network/packet/DeleteObjects.h
r1907 r2087 29 29 #define NETWORKPACKETDELETEOBJECTS_H 30 30 31 #include "../NetworkPrereqs.h" 32 31 33 #include "Packet.h" 32 34 … … 35 37 namespace packet { 36 38 /** 37 @author 39 @author 38 40 */ 39 class DeleteObjects : public Packet41 class _NetworkExport DeleteObjects : public Packet 40 42 { 41 43 public: … … 43 45 DeleteObjects( uint8_t* data, unsigned int clientID ); 44 46 ~DeleteObjects(); 45 47 46 48 bool fetchIDs(); 47 49 48 50 inline unsigned int getSize() const; 49 51 bool process(); 50 52 51 53 private: 52 54 }; -
code/trunk/src/network/packet/Gamestate.cc
r1907 r2087 46 46 #define HEADER GAMESTATE_HEADER(data_) 47 47 48 48 49 49 #define PACKET_FLAG_GAMESTATE ENET_PACKET_FLAG_RELIABLE 50 50 51 51 Gamestate::Gamestate() 52 52 { … … 85 85 return false; 86 86 } 87 87 88 88 #ifndef NDEBUG 89 89 std::list<Synchronisable*> slist; … … 115 115 slist.push_back(*it); 116 116 #endif 117 117 118 118 //if(it->doSelection(id)) 119 119 dataMap_[mem-data_]=(*it); // save the mem location of the synchronisable data … … 157 157 if(!s) 158 158 { 159 s = Synchronisable::fabricate(mem, mode); 160 assert(s); 161 // if(!s) 162 // return false; 159 Synchronisable::fabricate(mem, mode); 163 160 } 164 161 else … … 257 254 HEADER->compressed = true; 258 255 assert(HEADER->compressed); 259 COUT( 3) << "gamestate compress datasize: " << HEADER->datasize << " compsize: " << HEADER->compsize << std::endl;256 COUT(4) << "gamestate compress datasize: " << HEADER->datasize << " compsize: " << HEADER->compsize << std::endl; 260 257 return true; 261 258 } … … 264 261 assert(HEADER); 265 262 assert(HEADER->compressed); 266 COUT( 3) << "GameStateClient: uncompressing gamestate. id: " << HEADER->id << ", baseid: " << HEADER->base_id << ", datasize: " << HEADER->datasize << ", compsize: " << HEADER->compsize << std::endl;263 COUT(4) << "GameStateClient: uncompressing gamestate. id: " << HEADER->id << ", baseid: " << HEADER->base_id << ", datasize: " << HEADER->datasize << ", compsize: " << HEADER->compsize << std::endl; 267 264 unsigned int datasize = HEADER->datasize; 268 265 unsigned int compsize = HEADER->compsize; 269 266 unsigned int bufsize; 270 assert(compsize<=datasize);267 // assert(compsize<=datasize); 271 268 bufsize = datasize; 272 269 assert(bufsize!=0); … … 289 286 //copy over the header 290 287 *GAMESTATE_HEADER(ndata) = *HEADER; 291 //delete old (compressed data) 292 delete[] data_; 288 289 if (this->bDataENetAllocated_){ 290 // Memory was allocated by ENet. --> We let it be since enet_packet_destroy will 291 // deallocated it anyway. So data and packet stay together. 292 this->bDataENetAllocated_ = false; 293 } 294 else{ 295 // We allocated the memory in the first place (unlikely). So we destroy the old data 296 // and overwrite it with the new decompressed data. 297 delete[] this->data_; 298 } 299 293 300 //set new pointers 294 301 data_ = ndata; … … 339 346 assert(data_); 340 347 std::map<unsigned int, Synchronisable *>::iterator it; 341 348 342 349 // allocate memory for new data 343 350 uint8_t *gdata = new uint8_t[HEADER->datasize+sizeof(GamestateHeader)]; … … 346 353 uint8_t *newdata = gdata + sizeof(GamestateHeader); 347 354 uint8_t *origdata = GAMESTATE_START(data_); 348 355 349 356 //copy the GamestateHeader 350 357 *(GamestateHeader*)gdata = *HEADER; 351 358 352 359 synchronisableHeader *oldobjectheader, *newobjectheader; 353 360 unsigned int objectOffset; 354 361 355 362 //copy in the zeros 356 363 for(it=dataMap_.begin(); it!=dataMap_.end(); it++){ … … 360 367 assert(it->second->objectID==oldobjectheader->objectID); 361 368 *newobjectheader = *oldobjectheader; 362 objectOffset=sizeof(uint8_t)+sizeof(bool); //skip the size and the availableDat evariables in the objectheader369 objectOffset=sizeof(uint8_t)+sizeof(bool); //skip the size and the availableData variables in the objectheader 363 370 if(it->second->doSelection(HEADER->id)){ 364 371 newobjectheader->dataAvailable=true; //TODO: probably not neccessary … … 390 397 assert(!HEADER->compressed); 391 398 assert(!HEADER->diffed); 392 399 393 400 //preparations 394 401 std::map<unsigned int, Synchronisable *>::iterator it; 395 402 uint8_t *origdata, *basedata, *destdata, *ndata; 396 403 unsigned int objectOffset, streamOffset=0; //data offset 397 unsigned int minsize = (HEADER->datasize < GAMESTATE_HEADER(base->data_)->datasize) ? HEADER->datasize : GAMESTATE_HEADER(base->data_)->datasize; 404 unsigned int minsize = (HEADER->datasize < GAMESTATE_HEADER(base->data_)->datasize) ? HEADER->datasize : GAMESTATE_HEADER(base->data_)->datasize; 398 405 synchronisableHeader *origheader; 399 406 synchronisableHeader *destheader; 400 407 401 408 origdata = GAMESTATE_START(this->data_); 402 409 basedata = GAMESTATE_START(base->data_); 403 410 ndata = new uint8_t[HEADER->datasize + sizeof(GamestateHeader)]; 404 411 destdata = ndata + sizeof(GamestateHeader); 405 412 406 413 // do the diff 407 414 for(it=dataMap_.begin(); it!=dataMap_.end(); it++){ … … 410 417 origheader = (synchronisableHeader *)(origdata+streamOffset); 411 418 destheader = (synchronisableHeader *)(destdata+streamOffset); 412 419 413 420 //copy and partially diff the object header 414 421 assert(sizeof(synchronisableHeader)==3*sizeof(unsigned int)+sizeof(bool)); … … 420 427 }else{ 421 428 *(uint32_t*)(destdata+sizeof(uint32_t)+sizeof(bool)) = 0; 422 *(uint32_t*)(destdata+2*sizeof(uint32_t)+sizeof(bool)) = 0; 429 *(uint32_t*)(destdata+2*sizeof(uint32_t)+sizeof(bool)) = 0; 423 430 } 424 431 objectOffset=sizeof(synchronisableHeader); 425 432 streamOffset+=sizeof(synchronisableHeader); 426 433 427 434 //now handle the object data or fill with zeros 428 435 while(objectOffset<origheader->size ){ 429 436 430 437 if(sendData && streamOffset<minsize) 431 438 *(destdata+objectOffset)=*(basedata+objectOffset)^*(origdata+objectOffset); // do the xor … … 434 441 else 435 442 *(destdata+objectOffset)=0; // set to 0 because this object should not be transfered 436 443 437 444 objectOffset++; 438 445 streamOffset++; … … 442 449 basedata+=objectOffset; 443 450 } 444 451 445 452 //copy over the gamestate header and set the diffed flag 446 453 *(GamestateHeader *)ndata = *HEADER; //copy over the header … … 458 465 assert(!HEADER->compressed); 459 466 assert(HEADER->diffed); 460 467 461 468 //preparations 462 469 std::map<unsigned int, Synchronisable *>::iterator it; 463 470 uint8_t *origdata, *basedata, *destdata, *ndata; 464 471 unsigned int objectOffset, streamOffset=0; //data offset 465 unsigned int minsize = (HEADER->datasize < GAMESTATE_HEADER(base->data_)->datasize) ? HEADER->datasize : GAMESTATE_HEADER(base->data_)->datasize; 472 unsigned int minsize = (HEADER->datasize < GAMESTATE_HEADER(base->data_)->datasize) ? HEADER->datasize : GAMESTATE_HEADER(base->data_)->datasize; 466 473 synchronisableHeader *origheader; 467 474 synchronisableHeader *destheader; 468 475 469 476 origdata = GAMESTATE_START(this->data_); 470 477 basedata = GAMESTATE_START(base->data_); 471 478 ndata = new uint8_t[HEADER->datasize + sizeof(GamestateHeader)]; 472 479 destdata = ndata + sizeof(GamestateHeader); 473 480 474 481 // do the undiff 475 482 for(it=dataMap_.begin(); it!=dataMap_.end(); it++){ … … 478 485 destheader = (synchronisableHeader *)(destdata+streamOffset); 479 486 bool sendData; 480 487 481 488 //copy and partially diff the object header 482 489 assert(sizeof(synchronisableHeader)==3*sizeof(unsigned int)+sizeof(bool)); … … 489 496 }else{ 490 497 *(unsigned int*)(destdata+sizeof(unsigned int)+sizeof(bool)) = 0; 491 *(unsigned int*)(destdata+2*sizeof(unsigned int)+sizeof(bool)) = 0; 498 *(unsigned int*)(destdata+2*sizeof(unsigned int)+sizeof(bool)) = 0; 492 499 } 493 500 objectOffset=sizeof(synchronisableHeader); 494 501 streamOffset+=sizeof(synchronisableHeader); 495 502 496 503 //now handle the object data or fill with zeros 497 504 while(objectOffset<origheader->size ){ 498 505 499 506 if(sendData && streamOffset<minsize) 500 507 *(destdata+objectOffset)=*(basedata+objectOffset)^*(origdata+objectOffset); // do the xor … … 503 510 else 504 511 *(destdata+objectOffset)=0; // set to 0 because this object should not be transfered 505 512 506 513 objectOffset++; 507 514 streamOffset++; … … 511 518 basedata+=objectOffset; 512 519 } 513 520 514 521 //copy over the gamestate header and set the diffed flag 515 522 *(GamestateHeader *)ndata = *HEADER; //copy over the header -
code/trunk/src/network/packet/Gamestate.h
r1907 r2087 27 27 */ 28 28 29 30 #ifndef NETWORK_PACKETGAMESTATE_H 31 #define NETWORK_PACKETGAMESTATE_H 32 33 #include "../NetworkPrereqs.h" 34 29 35 #include "Packet.h" 30 36 #include "network/Synchronisable.h" … … 34 40 #endif 35 41 36 37 #ifndef NETWORK_PACKETGAMESTATE_H38 #define NETWORK_PACKETGAMESTATE_H39 40 42 namespace network { 41 43 42 44 namespace packet { 43 45 44 struct GamestateHeader{46 struct _NetworkExport GamestateHeader{ 45 47 ENUM::Type packetType; 46 48 int32_t id; // id of the gamestate … … 59 61 @author Oliver Scheuss 60 62 */ 61 class Gamestate: public Packet{63 class _NetworkExport Gamestate: public Packet{ 62 64 public: 63 65 Gamestate(); -
code/trunk/src/network/packet/Packet.cc
r1907 r2087 49 49 50 50 namespace packet{ 51 51 52 52 #define PACKET_FLAG_DEFAULT ENET_PACKET_FLAG_NO_ALLOCATE 53 53 #define _PACKETID 0 54 54 55 55 std::map<ENetPacket *, Packet *> Packet::packetMap_; 56 56 57 57 Packet::Packet(){ 58 58 flags_ = PACKET_FLAG_DEFAULT; … … 61 61 data_=0; 62 62 enetPacket_=0; 63 bDataENetAllocated_ = false; 63 64 } 64 65 … … 73 74 data_=data; 74 75 enetPacket_=0; 76 bDataENetAllocated_ = false; 75 77 } 76 78 … … 86 88 }else 87 89 data_=0; 88 } 89 90 bDataENetAllocated_ = p.bDataENetAllocated_; 91 } 92 93 /** 94 @brief 95 Destroys a packet completely. 96 97 That also means destroying the ENetPacket if one exists. There 98 */ 90 99 Packet::~Packet(){ 91 if(enetPacket_){ 92 assert(enetPacket_->freeCallback==0); 100 // Deallocate data_ memory if necessary. 101 if (this->bDataENetAllocated_){ 102 // In this case ENet allocated data_ and will destroy it. 103 } 104 else if (this->data_) { 105 // This destructor was probably called as a consequence to ENet executing our callback. 106 // It simply serves us to be able to deallocate the packet content (data_) ourselves since 107 // we have created it in the first place. 108 delete[] this->data_; 109 } 110 111 // Destroy the ENetPacket if necessary. 112 // Note: For the case ENet used the callback to destroy the packet, we have already set 113 // enetPacket_ to NULL to avoid destroying it again. 114 if (this->enetPacket_){ 115 // enetPacket_->data gets destroyed too by ENet if it was allocated by it. 93 116 enet_packet_destroy(enetPacket_); 94 117 } 95 if(data_)96 delete[] data_;97 118 } 98 119 … … 107 128 return false; 108 129 } 130 // We deliver ENet the data address so that it doesn't memcpy everything again. 131 // --> We have to delete data_ ourselves! 109 132 enetPacket_ = enet_packet_create(getData(), getSize(), getFlags()); 110 133 enetPacket_->freeCallback = &Packet::deletePacket; 111 // enetPacket_->freeCallback = &blub; 134 // Add the packet to a global list so we can access it again once enet calls our 135 // deletePacket method. We can of course only give a one argument function to the ENet C library. 112 136 packetMap_[enetPacket_] = this; 113 137 } 114 #ifndef NDEBUG 138 #ifndef NDEBUG 115 139 switch( *(ENUM::Type *)(data_ + _PACKETID) ) 116 140 { … … 127 151 } 128 152 #endif 129 ENetPacket *temp = enetPacket_;130 enetPacket_ = 0; // otherwise we have a double free because enet already handles the deallocation of the packet131 network::Host::addPacket( temp, clientID_);153 // ENetPacket *temp = enetPacket_; 154 // enetPacket_ = 0; // otherwise we have a double free because enet already handles the deallocation of the packet 155 network::Host::addPacket( enetPacket_, clientID_); 132 156 return true; 133 157 } … … 135 159 Packet *Packet::createPacket(ENetPacket *packet, ENetPeer *peer){ 136 160 uint8_t *data = packet->data; 161 assert(ClientInformation::findClient(&peer->address)->getID() != (unsigned int)-2 || !Host::isServer()); 137 162 unsigned int clientID = ClientInformation::findClient(&peer->address)->getID(); 138 163 Packet *p; … … 169 194 break; 170 195 } 196 197 // Data was created by ENet 198 p->bDataENetAllocated_ = true; 199 171 200 return p; 172 201 } 173 202 174 void Packet::deletePacket(ENetPacket *packet){ 175 assert(packetMap_[packet]); 176 assert(packetMap_[packet]->enetPacket_==0); 177 delete packetMap_[packet]; 203 /** 204 @brief 205 ENet calls this method whenever it wants to destroy a packet that contains 206 data we allocated ourselves. 207 */ 208 void Packet::deletePacket(ENetPacket *enetPacket){ 209 // Get our Packet from a gloabal map with all Packets created in the send() method of Packet. 210 std::map<ENetPacket*, Packet*>::iterator it = packetMap_.find(enetPacket); 211 assert(it != packetMap_.end()); 212 // Make sure we don't delete it again in the destructor 213 it->second->enetPacket_ = 0; 214 delete it->second; 215 //packetMap_.erase(it); 216 COUT(4) << "PacketMap size: " << packetMap_.size() << std::endl; 178 217 } 179 218 -
code/trunk/src/network/packet/Packet.h
r1907 r2087 29 29 #define NETWORKPACKET_H 30 30 31 #include "../NetworkPrereqs.h" 32 31 33 #include <map> 32 34 #include <enet/enet.h> … … 37 39 38 40 namespace packet{ 39 41 40 42 namespace ENUM{ 41 43 enum Direction{ … … 53 55 }; 54 56 } 55 57 56 58 /** 57 59 @author Oliver Scheuss <scheusso [at] ee.ethz.ch> 58 60 */ 59 class Packet{61 class _NetworkExport Packet{ 60 62 public: 61 63 Packet(const Packet &p); … … 63 65 static Packet *createPacket(ENetPacket *packet, ENetPeer *peer); 64 66 static void deletePacket(ENetPacket *packet); 65 67 66 68 virtual unsigned char *getData(){ return data_; }; 67 69 virtual unsigned int getSize() const =0; … … 73 75 void setClientID( int id ) 74 76 { clientID_ = id; } 75 77 76 78 bool send(); 77 79 protected: … … 82 84 unsigned int clientID_; 83 85 ENUM::Direction packetDirection_; 86 /** Pointer to the data. Be careful when deleting it because it might 87 point to a location that was allocated by ENet. 88 See bDataENetAllocated_ */ 84 89 uint8_t *data_; 90 /** Tells whether data_ was allocated by ENet or ourselves. 91 data_ might no correlate with enetPacket_->data. */ 92 bool bDataENetAllocated_; 85 93 private: 86 94 static std::map<ENetPacket *, Packet *> packetMap_; -
code/trunk/src/network/packet/Welcome.h
r1907 r2087 29 29 #define NETWORKWELCOME_H 30 30 31 #include "../NetworkPrereqs.h" 32 31 33 #include "Packet.h" 32 34 … … 35 37 36 38 /** 37 @author 39 @author 38 40 */ 39 class Welcome : public Packet41 class _NetworkExport Welcome : public Packet 40 42 { 41 43 public: … … 43 45 Welcome( uint8_t* data, unsigned int clientID ); 44 46 virtual ~Welcome(); 45 47 46 48 uint8_t *getData(); 47 49 inline unsigned int getSize() const; 48 50 bool process(); 49 51 50 52 private: 51 53 }; -
code/trunk/src/orxonox/CMakeLists.txt
r1844 r2087 1 1 SET( ORXONOX_SRC_FILES 2 CameraManager.cc 2 3 GraphicsEngine.cc 4 LevelManager.cc 3 5 Main.cc 4 6 Settings.cc 5 SignalHandler.cc6 7 7 8 gamestates/GSClient.cc … … 33 34 overlays/hud/HUDRadar.cc 34 35 overlays/hud/HUDSpeedBar.cc 36 overlays/hud/ChatOverlay.cc 35 37 36 38 tools/BillboardSet.cc 37 tools/Light.cc38 39 tools/Mesh.cc 39 40 tools/ParticleInterface.cc … … 42 43 tools/WindowEventListener.cc 43 44 44 objects/Ambient.cc 45 objects/Backlight.cc 46 objects/Camera.cc 47 objects/CameraHandler.cc 48 objects/Model.cc 49 objects/NPC.cc 50 objects/ParticleSpawner.cc 45 objects/EventListener.cc 46 objects/EventDispatcher.cc 47 objects/EventTarget.cc 51 48 objects/Radar.cc 52 49 objects/RadarListener.cc 53 50 objects/RadarViewable.cc 54 objects/Skybox.cc55 objects/SpaceShip.cc56 objects/SpaceShipAI.cc57 51 objects/Tickable.cc 58 objects/WorldEntity.cc 52 objects/Test.cc 53 objects/Script.cc 59 54 60 objects/Projectile.cc 61 objects/BillboardProjectile.cc 62 objects/RotatingProjectile.cc 63 objects/ParticleProjectile.cc 55 objects/Scene.cc 56 objects/worldentities/WorldEntity.cc 57 objects/worldentities/PositionableEntity.cc 58 objects/worldentities/MovableEntity.cc 59 objects/worldentities/ControllableEntity.cc 60 objects/worldentities/Model.cc 61 objects/worldentities/Billboard.cc 62 objects/worldentities/BlinkingBillboard.cc 63 objects/worldentities/Light.cc 64 objects/worldentities/Camera.cc 65 objects/worldentities/CameraPosition.cc 66 objects/worldentities/SpawnPoint.cc 67 objects/worldentities/ParticleEmitter.cc 68 objects/worldentities/ParticleSpawner.cc 69 # objects/worldentities/Backlight.cc 70 71 objects/worldentities/triggers/Trigger.cc 72 objects/worldentities/triggers/DistanceTrigger.cc 73 objects/worldentities/triggers/EventTrigger.cc 74 75 objects/worldentities/pawns/Spectator.cc 76 objects/worldentities/pawns/Pawn.cc 77 objects/worldentities/pawns/SpaceShip.cc 78 79 objects/controllers/Controller.cc 80 objects/controllers/HumanController.cc 81 82 objects/infos/Info.cc 83 objects/infos/Level.cc 84 objects/infos/PlayerInfo.cc 85 objects/infos/HumanPlayer.cc 86 87 objects/gametypes/Gametype.cc 64 88 65 89 tolua/tolua_bind.cc … … 76 100 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/bin/lib 77 101 ) 78 102 103 79 104 ADD_EXECUTABLE( orxonox ${ORXONOX_SRC_FILES} ) 80 105 … … 83 108 SET( ORXONOXS_SRC_FILES 84 109 GraphicsEngine.cc 85 objects/Ambient.cc86 110 objects/Camera.cc 87 objects/CameraHandler.cc 88 objects/Explosion.cc 89 objects/Model.cc 90 objects/NPC.cc 91 objects/Projectile.cc 92 objects/Skybox.cc 93 objects/SpaceShip.cc 94 objects/WorldEntity.cc 111 CameraManager.cc 95 112 ) 96 113 -
code/trunk/src/orxonox/GraphicsEngine.cc
r1755 r2087 68 68 */ 69 69 GraphicsEngine::GraphicsEngine() 70 : root_(0) 71 , renderWindow_(0) 72 , levelSceneManager_(0) 73 , viewport_(0) 70 // : root_(0) 71 // , renderWindow_(0) 72 // , viewport_(0) 74 73 { 75 74 RegisterObject(GraphicsEngine); … … 103 102 singletonRef_s = 0; 104 103 } 105 106 /**107 @brief108 Get the width of the render window109 @return110 The width of the render window111 */112 int GraphicsEngine::getWindowWidth() const113 {114 if (this->renderWindow_)115 return this->renderWindow_->getWidth();116 else117 return 0;118 }119 120 /**121 @brief122 Get the height of the render window123 @return124 The height of the render window125 */126 int GraphicsEngine::getWindowHeight() const127 {128 if (this->renderWindow_)129 return this->renderWindow_->getHeight();130 else131 return 0;132 }133 134 /**135 @brief136 Returns the window aspect ratio height/width.137 @return138 The window aspect ratio139 */140 float GraphicsEngine::getWindowAspectRatio() const141 {142 if (this->renderWindow_)143 return (float)this->renderWindow_->getHeight() / (float)this->renderWindow_->getWidth();144 else145 return 1.0f;146 }147 104 } -
code/trunk/src/orxonox/GraphicsEngine.h
r1755 r2087 61 61 void detailLevelParticleChanged(); 62 62 63 void setLevelSceneManager(Ogre::SceneManager* sceneMgr) { this->levelSceneManager_ = sceneMgr; }64 Ogre::SceneManager* getLevelSceneManager() { return levelSceneManager_; }65 66 Ogre::Viewport* getViewport() { return this->viewport_; }67 Ogre::Root* getOgreRoot() { return this->root_; }68 69 // several window properties70 int getWindowWidth() const;71 int getWindowHeight() const;72 float getWindowAspectRatio() const;73 63 float getAverageFramesPerSecond() const { return this->avgFramesPerSecond_; } 74 64 float getAverageTickTime() const { return this->avgTickTime_; } … … 86 76 GraphicsEngine(GraphicsEngine&); 87 77 88 Ogre::Root* root_; //!< Ogre's root89 Ogre::RenderWindow* renderWindow_; //!< the current render window90 Ogre::SceneManager* levelSceneManager_; //!< scene manager of the game91 Ogre::Viewport* viewport_; //!< default full size viewport92 93 78 // stats 94 79 float avgTickTime_; //!< time in ms to tick() one frame -
code/trunk/src/orxonox/Main.cc
r1896 r2087 40 40 #include "util/OrxonoxPlatform.h" 41 41 #include "util/Debug.h" 42 #include "util/SignalHandler.h" 42 43 #include "core/ConfigFileManager.h" 43 #include "SignalHandler.h"44 44 45 45 #include "gamestates/GSRoot.h" -
code/trunk/src/orxonox/OrxonoxPrereqs.h
r1755 r2087 80 80 class RadarListener; 81 81 82 class CameraManager; 83 class LevelManager; 84 82 85 // objects 83 class Ambient; 86 class Scene; 87 88 class WorldEntity; 89 class PositionableEntity; 90 class MovableEntity; 91 class ControllableEntity; 92 class Sublevel; 93 94 class Model; 95 class Billboard; 96 class BlinkingBillboard; 97 class Light; 84 98 class Backlight; 99 class ParticleEmitter; 100 class ParticleSpawner; 101 85 102 class Camera; 86 class Model; 87 class NPC; 88 class ParticleSpawner; 89 class Skybox; 103 class CameraPosition; 104 class SpawnPoint; 105 106 class Spectator; 107 class Pawn; 90 108 class SpaceShip; 91 class SpaceShipAI;92 class WorldEntity;93 109 94 class Projectile; 95 class BillboardProjectile; 96 class RotatingProjectile; 97 class ParticleProjectile; 110 class Trigger; 111 class DistanceTrigger; 112 class EventTrigger; 113 114 class EventListener; 115 class EventDispatcher; 116 class EventTarget; 117 118 class Controller; 119 class HumanController; 120 121 class Info; 122 class Level; 123 class PlayerInfo; 124 class HumanPlayer; 125 126 class Gametype; 127 128 class Scores; 98 129 99 130 // tools -
code/trunk/src/orxonox/OrxonoxStableHeaders.h
r1841 r2087 37 37 #include "util/OrxonoxPlatform.h" 38 38 39 #if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC && !defined(ORXONOX_DISABLE_PCH)39 #if defined(ORXONOX_ENABLE_PCH) 40 40 41 41 // including std headers here is useless since they're already precompiled … … 47 47 #include <Ogre.h> 48 48 #include <CEGUI.h> 49 #include "ois/OIS.h" 49 50 #include <boost/thread/recursive_mutex.hpp> 50 #include <boost/thread/mutex.hpp>51 #include <boost/thread/condition.hpp>52 #include <boost/thread/thread.hpp>53 51 //#include <boost/thread/mutex.hpp> 52 //#include <boost/thread/condition.hpp> 53 //#include <boost/thread/thread.hpp> 54 #include <boost/static_assert.hpp> 54 55 #include "tinyxml/ticpp.h" 55 56 #include "tinyxml/tinyxml.h" 57 #include "tolua/tolua++.h" 56 58 57 //Get around Windows hackery (windows.h is included by Ogre )59 //Get around Windows hackery (windows.h is included by Ogre.h) 58 60 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32 59 61 # ifdef max … … 67 69 //----------- Our files ---------- 68 70 //-------------------------------- 69 // only include when not debugging so that we may find issues with missing headers quicker70 #if defined(NDEBUG)71 //// only include when not debugging so that we may find issues with missing headers quicker 72 //#if defined(NDEBUG) 71 73 72 74 #include "util/Convert.h" 73 75 #include "util/Debug.h" 76 #include "util/Exception.h" 74 77 #include "util/Math.h" 75 78 #include "util/Multitype.h" 76 #include "util/OutputBuffer.h"77 #include "util/OutputHandler.h"78 79 #include "util/Sleep.h" 79 80 #include "util/String.h" … … 85 86 #include "core/ConfigValueIncludes.h" 86 87 #include "core/CommandExecutor.h" 88 #include "core/Core.h" 87 89 #include "core/Executor.h" 90 #include "core/ObjectList.h" 91 #include "core/Super.h" 88 92 #include "core/XMLIncludes.h" 89 93 #include "core/XMLPort.h" 94 #include "core/input/SimpleInputState.h" 95 #include "core/input/InputManager.h" 90 96 91 97 #include "network/Synchronisable.h" 92 98 93 //#include "tools/Mesh.h" 94 //#include "tools/Timer.h" 95 //#include "objects/Model.h" 96 //#include "objects/Tickable.h" 97 //#include "objects/WorldEntity.h" 99 #include "Settings.h" 98 100 99 #endif /* ifdef NDEBUG */101 //#endif /* ifdef NDEBUG */ 100 102 101 103 #endif /* ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC && !defined(ORXONOX_DISABLE_PCH) */ -
code/trunk/src/orxonox/Settings.cc
r1907 r2087 39 39 #include "core/CoreIncludes.h" 40 40 #include "core/ConfigValueIncludes.h" 41 #include "core/LuaBind.h" 41 42 42 43 namespace orxonox … … 49 50 */ 50 51 Settings::Settings() 51 : bShowsGraphics_(false)52 , bHasServer_(false)53 , bIsClient_(false)54 52 { 55 53 RegisterRootObject(Settings); … … 65 63 void Settings::setConfigValues() 66 64 { 67 SetConfigValue(dataPath_, "../../ Media/").description("Relative path to the game data.").callback(this, &Settings::dataPathChanged);65 SetConfigValue(dataPath_, "../../media/").description("Relative path to the game data.").callback(this, &Settings::dataPathChanged); 68 66 } 69 67 … … 84 82 COUT(2) << "Warning: Data path set to \"/\", is that really correct?" << std::endl; 85 83 } 84 85 LuaBind::getInstance()->setIncludePath(this->dataPath_); 86 86 } 87 87 -
code/trunk/src/orxonox/Settings.h
r1907 r2087 50 50 friend class ClassIdentifier<Settings>; 51 51 friend class GSRoot; 52 friend class GSGraphics;53 friend class GSServer;54 friend class GSClient;55 friend class GSDedicated;56 52 57 53 public: … … 61 57 { assert(singletonRef_s); singletonRef_s->_tsetDataPath(path); } 62 58 63 // an alternative to a global game mode variable64 static bool showsGraphics() { assert(singletonRef_s); return singletonRef_s->bShowsGraphics_; }65 static bool hasServer() { assert(singletonRef_s); return singletonRef_s->bHasServer_; }66 static bool isClient() { assert(singletonRef_s); return singletonRef_s->bIsClient_; }67 68 59 private: 69 // GSRoot has access to these70 static void setShowsGraphics(bool val) { assert(singletonRef_s); singletonRef_s->bShowsGraphics_ = val; }71 static void setHasServer (bool val) { assert(singletonRef_s); singletonRef_s->bHasServer_ = val; }72 static void setIsClient (bool val) { assert(singletonRef_s); singletonRef_s->bIsClient_ = val; }73 74 60 Settings(); 75 61 Settings(const Settings& instance); … … 82 68 void setConfigValues(); 83 69 84 bool bShowsGraphics_; //!< global variable that tells whether to show graphics85 bool bHasServer_; //!< global variable that tells whether this is a server86 bool bIsClient_;87 88 70 std::string dataPath_; //!< Path to the game data 89 71 -
code/trunk/src/orxonox/gamestates/GSClient.cc
r1907 r2087 32 32 #include "core/input/InputManager.h" 33 33 #include "core/CommandLine.h" 34 #include "core/Core.h" 34 35 #include "network/Client.h" 35 #include "Settings.h"36 36 37 37 namespace orxonox 38 38 { 39 SetCommandLineArgument(ip, "127.0.0.1"). setInformation("#.#.#.#");39 SetCommandLineArgument(ip, "127.0.0.1").information("#.#.#.#"); 40 40 41 41 GSClient::GSClient() 42 : G SLevel("client")42 : GameState<GSGraphics>("client") 43 43 , client_(0) 44 44 { … … 51 51 void GSClient::enter() 52 52 { 53 Settings::_getInstance().bIsClient_ = true;53 Core::setIsClient(true); 54 54 55 GSLevel::enter(); 56 57 int serverPort = CommandLine::getArgument<int>("port")->getValue(); 58 std::string serverIP = CommandLine::getArgument<std::string>("ip")->getValue(); 59 this->client_ = new network::Client(serverIP, serverPort); 55 this->client_ = new network::Client(CommandLine::getValue("ip").getString(), CommandLine::getValue("port")); 60 56 61 57 if(!client_->establishConnection()) 62 58 ThrowException(InitialisationFailed, "Could not establish connection with server."); 63 59 60 GSLevel::enter(this->getParent()->getViewport()); 61 64 62 client_->tick(0); 65 66 // level is loaded: we can start capturing the input67 InputManager::getInstance().requestEnterState("game");68 63 } 69 64 70 65 void GSClient::leave() 71 66 { 72 InputManager::getInstance().requestLeaveState("game"); 73 74 // TODO: How do we unload the level in client mode? 67 GSLevel::leave(); 75 68 76 69 client_->closeConnection(); … … 79 72 delete this->client_; 80 73 81 GSLevel::leave(); 82 83 Settings::_getInstance().bIsClient_ = false; 74 Core::setIsClient(false); 84 75 } 85 76 -
code/trunk/src/orxonox/gamestates/GSClient.h
r1755 r2087 33 33 #include "network/NetworkPrereqs.h" 34 34 #include "GSLevel.h" 35 #include "GSGraphics.h" 35 36 36 37 namespace orxonox 37 38 { 38 class _OrxonoxExport GSClient : public G SLevel39 class _OrxonoxExport GSClient : public GameState<GSGraphics>, public GSLevel 39 40 { 40 41 public: -
code/trunk/src/orxonox/gamestates/GSDedicated.cc
r1790 r2087 30 30 #include "GSDedicated.h" 31 31 32 #include <OgreRoot.h>33 #include <OgreSceneManager.h>34 #include "core/ConsoleCommand.h"35 32 #include "core/CommandLine.h" 36 #include "core/ Loader.h"33 #include "core/Core.h" 37 34 #include "network/Server.h" 38 #include "objects/Tickable.h"39 #include "GraphicsEngine.h"40 #include "Settings.h"41 35 42 36 namespace orxonox … … 44 38 GSDedicated::GSDedicated() 45 39 : GameState<GSRoot>("dedicated") 46 , timeFactor_(0)47 40 , server_(0) 48 , sceneManager_(0)49 , startLevel_(0)50 41 { 51 42 } … … 57 48 void GSDedicated::enter() 58 49 { 59 Settings::_getInstance().bHasServer_ = true;50 Core::setHasServer(true); 60 51 61 // create Ogre SceneManager for the level 62 this->sceneManager_ = Ogre::Root::getSingleton().createSceneManager(Ogre::ST_GENERIC, "LevelSceneManager"); 63 COUT(4) << "Created SceneManager: " << sceneManager_->getName() << std::endl; 52 this->server_ = new network::Server(CommandLine::getValue("port")); 53 COUT(0) << "Loading scene in server mode" << std::endl; 64 54 65 // temporary hack 66 GraphicsEngine::getInstance().setLevelSceneManager(this->sceneManager_); 67 68 // reset game speed to normal 69 timeFactor_ = 1.0f; 70 71 int serverPort = CommandLine::getArgument<int>("port")->getValue(); 72 this->server_ = new network::Server(serverPort); 73 74 // call the loader 75 COUT(0) << "Loading level..." << std::endl; 76 startLevel_ = new Level(Settings::getDataPath() + "levels/sample.oxw"); 77 Loader::open(startLevel_); 55 GSLevel::enter(0); 78 56 79 57 server_->open(); 80 81 // add console commands82 FunctorMember01<GSDedicated, float>* functor = createFunctor(&GSDedicated::setTimeFactor);83 functor->setObject(this);84 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor, "setTimeFactor")).accessLevel(AccessLevel::Offline).defaultValue(0, 1.0);;85 58 } 86 59 87 60 void GSDedicated::leave() 88 61 { 89 // TODO: Remove and destroy console command 90 91 Loader::unload(startLevel_); 92 delete this->startLevel_; 62 GSLevel::leave(); 93 63 94 64 this->server_->close(); 95 65 delete this->server_; 96 66 97 Ogre::Root::getSingleton().destroySceneManager(this->sceneManager_); 98 99 Settings::_getInstance().bHasServer_ = false; 67 Core::setHasServer(false); 100 68 } 101 69 102 70 void GSDedicated::ticked(const Clock& time) 103 71 { 104 // Call the scene objects 105 for (ObjectList<Tickable>::iterator it = ObjectList<Tickable>::begin(); it; ++it) 106 it->tick(time.getDeltaTime() * this->timeFactor_); 107 72 GSLevel::ticked(time); 108 73 server_->tick(time.getDeltaTime()); 109 74 this->tickChild(time); 110 75 } 111 112 /**113 @brief114 Changes the speed of Orxonox115 */116 void GSDedicated::setTimeFactor(float factor)117 {118 this->timeFactor_ = factor;119 }120 76 } -
code/trunk/src/orxonox/gamestates/GSDedicated.h
r1755 r2087 32 32 #include "OrxonoxPrereqs.h" 33 33 #include "network/NetworkPrereqs.h" 34 #include "GSLevel.h" 34 35 #include "GSRoot.h" 35 36 36 37 namespace orxonox 37 38 { 38 class _OrxonoxExport GSDedicated : public GameState<GSRoot> 39 class _OrxonoxExport GSDedicated : public GameState<GSRoot>, public GSLevel 39 40 { 40 41 public: 41 42 GSDedicated(); 42 43 ~GSDedicated(); 43 44 void setTimeFactor(float factor);45 float getTimeFactor() { return this->timeFactor_; }46 44 47 45 private: … … 50 48 void ticked(const Clock& time); 51 49 52 void loadLevel();53 void unloadLevel();54 55 float timeFactor_; //!< A factor to change the gamespeed56 50 network::Server* server_; 57 Ogre::SceneManager* sceneManager_;58 Level* startLevel_; //!< current hard coded default level59 51 }; 60 52 } -
code/trunk/src/orxonox/gamestates/GSGUI.cc
r1755 r2087 31 31 32 32 #include <OgreViewport.h> 33 #include "GraphicsEngine.h"34 33 #include "core/input/InputManager.h" 35 34 #include "core/input/SimpleInputState.h" -
code/trunk/src/orxonox/gamestates/GSGraphics.cc
r1891 r2087 47 47 #include "core/ConfigValueIncludes.h" 48 48 #include "core/CoreIncludes.h" 49 #include "core/Core.h" 49 50 #include "core/input/InputManager.h" 50 51 #include "core/input/KeyBinder.h" 51 52 #include "core/input/ExtendedInputState.h" 53 #include "core/Loader.h" 54 #include "core/XMLFile.h" 52 55 #include "overlays/console/InGameConsole.h" 53 56 #include "gui/GUIManager.h" 54 57 #include "tools/WindowEventListener.h" 58 #include "objects/Tickable.h" 55 59 #include "Settings.h" 56 60 … … 64 68 , renderWindow_(0) 65 69 , viewport_(0) 70 , bWindowEventListenerUpdateRequired_(false) 66 71 , inputManager_(0) 67 72 , console_(0) … … 76 81 , statisticsStartCount_(0) 77 82 , tickTime_(0) 83 , debugOverlay_(0) 78 84 { 79 85 RegisterRootObject(GSGraphics); … … 101 107 void GSGraphics::enter() 102 108 { 103 Settings::_getInstance().bShowsGraphics_ = true;109 Core::setShowsGraphics(true); 104 110 105 111 // initialise graphics engine. Doesn't load the render window yet! … … 113 119 this->initialiseResources(); 114 120 115 116 // HACK: temporary: 117 graphicsEngine_->renderWindow_ = this->renderWindow_; 118 graphicsEngine_->root_ = this->ogreRoot_; 119 graphicsEngine_->viewport_ = this->viewport_; 120 121 // We want to get informed whenever an object of type WindowEventListener is created 122 // in order to later update the window size. 123 bWindowEventListenerUpdateRequired_ = false; 124 RegisterConstructionCallback(GSGraphics, orxonox::WindowEventListener, requestWindowEventListenerUpdate); 125 126 // load debug overlay 127 COUT(3) << "Loading Debug Overlay..." << std::endl; 128 this->debugOverlay_ = new XMLFile(Settings::getDataPath() + "overlay/debug.oxo"); 129 Loader::open(debugOverlay_); 121 130 122 131 // Calls the InputManager which sets up the input devices. … … 133 142 // Load the InGameConsole 134 143 console_ = new InGameConsole(); 135 console_->initialise( );144 console_->initialise(this->renderWindow_->getWidth(), this->renderWindow_->getHeight()); 136 145 137 146 // load the CEGUI interface … … 165 174 //delete this->masterKeyBinder_; 166 175 delete this->inputManager_; 176 177 Loader::unload(this->debugOverlay_); 178 delete this->debugOverlay_; 167 179 168 180 // destroy render window … … 196 208 delete graphicsEngine_; 197 209 198 Settings::_getInstance().bShowsGraphics_ = false;210 Core::setShowsGraphics(false); 199 211 } 200 212 … … 221 233 this->console_->tick(dt); 222 234 this->tickChild(time); 223 235 236 /*** HACK *** HACK ***/ 237 // Call the Tickable objects 238 for (ObjectList<Tickable>::iterator it = ObjectList<Tickable>::begin(); it; ++it) 239 it->tick(time.getDeltaTime()); 240 /*** HACK *** HACK ***/ 241 242 if (this->bWindowEventListenerUpdateRequired_) 243 { 244 // Update all WindowEventListeners for the case a new one was created. 245 this->windowResized(this->renderWindow_); 246 this->bWindowEventListenerUpdateRequired_ = false; 247 } 248 224 249 unsigned long long timeAfterTick = time.getRealMicroseconds(); 225 250 … … 487 512 for (ObjectList<orxonox::WindowEventListener>::iterator it = ObjectList<orxonox::WindowEventListener>::begin(); it; ++it) 488 513 it->windowResized(this->renderWindow_->getWidth(), this->renderWindow_->getHeight()); 514 515 // OIS needs this under linux even if we only use relative input measurement. 516 if (this->inputManager_) 517 this->inputManager_->setWindowExtents(renderWindow_->getWidth(), renderWindow_->getHeight()); 489 518 } 490 519 … … 501 530 502 531 // instruct InputManager to clear the buffers (core library so we cannot use the interface) 503 InputManager::getInstance().clearBuffers(); 532 if (this->inputManager_) 533 this->inputManager_->clearBuffers(); 504 534 } 505 535 … … 512 542 void GSGraphics::windowClosed(Ogre::RenderWindow *rw) 513 543 { 514 // using CommandExecutor in order to avoid depending on Orxonox.h.515 //CommandExecutor::execute("exit", false);516 544 this->requestState("root"); 517 545 } -
code/trunk/src/orxonox/gamestates/GSGraphics.h
r1891 r2087 77 77 void windowClosed (Ogre::RenderWindow* rw); 78 78 79 void requestWindowEventListenerUpdate() { this->bWindowEventListenerUpdateRequired_ = true; } 80 79 81 private: // variables 80 82 Ogre::RenderWindow* renderWindow_; //!< the current render window 81 83 Ogre::Viewport* viewport_; //!< default full size viewport 84 bool bWindowEventListenerUpdateRequired_; //!< True if a new WindowEventListener was created but not yet updated. 82 85 83 86 // managed singletons … … 97 100 unsigned long statisticsStartCount_; 98 101 unsigned int tickTime_; 102 XMLFile* debugOverlay_; 99 103 100 104 // config values -
code/trunk/src/orxonox/gamestates/GSIOConsole.cc
r1755 r2087 36 36 37 37 #include "core/ConsoleCommand.h" 38 #include "core/TclThreadManager.h"39 #include "GraphicsEngine.h"40 38 41 39 namespace orxonox -
code/trunk/src/orxonox/gamestates/GSLevel.cc
r1934 r2087 30 30 #include "GSLevel.h" 31 31 32 #include <OgreSceneManager.h>33 #include <OgreRoot.h>34 32 #include "core/input/InputManager.h" 35 33 #include "core/input/SimpleInputState.h" 36 34 #include "core/input/KeyBinder.h" 37 35 #include "core/Loader.h" 36 #include "core/XMLFile.h" 38 37 #include "core/CommandExecutor.h" 39 38 #include "core/ConsoleCommand.h" … … 41 40 #include "core/ConfigValueIncludes.h" 42 41 #include "core/CoreIncludes.h" 43 #include "objects/Backlight.h" 42 #include "core/Core.h" 43 //#include "objects/Backlight.h" 44 44 #include "objects/Tickable.h" 45 45 #include "objects/Radar.h" 46 #include "tools/ParticleInterface.h" 46 //#include "tools/ParticleInterface.h" 47 #include "CameraManager.h" 48 #include "LevelManager.h" 47 49 #include "Settings.h" 48 #include "GraphicsEngine.h"49 50 50 51 namespace orxonox 51 52 { 52 SetCommandLineArgument(level, "sample.oxw").setShortcut("l"); 53 54 GSLevel::GSLevel(const std::string& name) 55 : GameState<GSGraphics>(name) 56 , timeFactor_(1.0f) 57 , sceneManager_(0) 53 SetCommandLineArgument(level, "sample2.oxw").shortcut("l"); 54 55 GSLevel::GSLevel() 56 // : GameState<GSGraphics>(name) 57 : timeFactor_(1.0f) 58 58 , keyBinder_(0) 59 59 , inputState_(0) 60 60 , radar_(0) 61 , startLevel_(0) 62 , hud_(0) 61 , startFile_(0) 62 , cameraManager_(0) 63 , levelManager_(0) 63 64 { 64 65 RegisterObject(GSLevel); … … 75 76 } 76 77 77 void GSLevel::enter() 78 { 79 inputState_ = InputManager::getInstance().createInputState<SimpleInputState>("game", 20); 80 keyBinder_ = new KeyBinder(); 81 keyBinder_->loadBindings("keybindings.ini"); 82 inputState_->setHandler(keyBinder_); 83 84 // create Ogre SceneManager for the level 85 this->sceneManager_ = Ogre::Root::getSingleton().createSceneManager(Ogre::ST_GENERIC, "LevelSceneManager"); 86 COUT(4) << "Created SceneManager: " << sceneManager_->getName() << std::endl; 87 88 // temporary hack 89 GraphicsEngine::getInstance().setLevelSceneManager(this->sceneManager_); 90 91 // Start the Radar 92 this->radar_ = new Radar(); 93 94 // Load the HUD 95 COUT(3) << "Orxonox: Loading HUD" << std::endl; 96 hud_ = new Level(Settings::getDataPath() + "overlay/hud.oxo"); 97 Loader::load(hud_); 98 99 // reset game speed to normal 100 timeFactor_ = 1.0f; 101 102 // TODO: insert slomo console command with 103 // .accessLevel(AccessLevel::Offline).defaultValue(0, 1.0).axisParamIndex(0).isAxisRelative(false); 104 105 // keybind console command 106 FunctorMember<GSLevel>* functor1 = createFunctor(&GSLevel::keybind); 107 functor1->setObject(this); 108 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor1, "keybind")); 109 FunctorMember<GSLevel>* functor2 = createFunctor(&GSLevel::tkeybind); 110 functor2->setObject(this); 111 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor2, "tkeybind")); 112 // set our console command as callback for the key detector 113 InputManager::getInstance().setKeyDetectorCallback(std::string("keybind ") + keyDetectorCallbackCode_); 78 void GSLevel::enter(Ogre::Viewport* viewport) 79 { 80 if (Core::showsGraphics()) 81 { 82 inputState_ = InputManager::getInstance().createInputState<SimpleInputState>("game", 20); 83 keyBinder_ = new KeyBinder(); 84 keyBinder_->loadBindings("keybindings.ini"); 85 inputState_->setHandler(keyBinder_); 86 87 // create the global CameraManager 88 assert(viewport); 89 this->cameraManager_ = new CameraManager(viewport); 90 91 // Start the Radar 92 this->radar_ = new Radar(); 93 } 94 95 if (Core::isMaster()) 96 { 97 // create the global LevelManager 98 this->levelManager_ = new LevelManager(); 99 100 // reset game speed to normal 101 timeFactor_ = 1.0f; 102 103 this->loadLevel(); 104 } 105 106 if (Core::showsGraphics()) 107 { 108 // TODO: insert slomo console command with 109 // .accessLevel(AccessLevel::Offline).defaultValue(0, 1.0).axisParamIndex(0).isAxisRelative(false); 110 111 // keybind console command 112 FunctorMember<GSLevel>* functor1 = createFunctor(&GSLevel::keybind); 113 functor1->setObject(this); 114 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor1, "keybind")); 115 FunctorMember<GSLevel>* functor2 = createFunctor(&GSLevel::tkeybind); 116 functor2->setObject(this); 117 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor2, "tkeybind")); 118 // set our console command as callback for the key detector 119 InputManager::getInstance().setKeyDetectorCallback(std::string("keybind ") + keyDetectorCallbackCode_); 120 121 // level is loaded: we can start capturing the input 122 InputManager::getInstance().requestEnterState("game"); 123 } 124 125 if (Core::isMaster()) 126 { 127 // time factor console command 128 FunctorMember<GSLevel>* functor = createFunctor(&GSLevel::setTimeFactor); 129 functor->setObject(this); 130 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor, "setTimeFactor")).accessLevel(AccessLevel::Offline).defaultValue(0, 1.0);; 131 } 114 132 } 115 133 116 134 void GSLevel::leave() 117 135 { 118 Loader::unload(hud_);119 delete this->hud_;120 121 136 // this call will delete every BaseObject! 122 137 // But currently this will call methods of objects that exist no more … … 125 140 //Loader::close(); 126 141 127 delete this->radar_; 128 129 Ogre::Root::getSingleton().destroySceneManager(this->sceneManager_); 130 131 inputState_->setHandler(0); 132 InputManager::getInstance().requestDestroyState("game"); 133 delete this->keyBinder_; 142 if (Core::showsGraphics()) 143 InputManager::getInstance().requestLeaveState("game"); 144 145 if (Core::isMaster()) 146 this->unloadLevel(); 147 148 if (this->radar_) 149 delete this->radar_; 150 151 if (this->cameraManager_) 152 delete this->cameraManager_; 153 154 if (this->levelManager_) 155 delete this->levelManager_; 156 157 if (Core::showsGraphics()) 158 { 159 inputState_->setHandler(0); 160 InputManager::getInstance().requestDestroyState("game"); 161 if (this->keyBinder_) 162 delete this->keyBinder_; 163 } 134 164 } 135 165 136 166 void GSLevel::ticked(const Clock& time) 137 167 { 138 // Call the scene objects 139 for (ObjectList<Tickable>::iterator it = ObjectList<Tickable>::begin(); it; ++it) 140 it->tick(time.getDeltaTime() * this->timeFactor_); 168 // Commented by 1337: Temporarily moved to GSGraphics. 169 //// Call the scene objects 170 //for (ObjectList<Tickable>::iterator it = ObjectList<Tickable>::begin(); it; ++it) 171 // it->tick(time.getDeltaTime() * this->timeFactor_); 141 172 } 142 173 … … 147 178 void GSLevel::setTimeFactor(float factor) 148 179 { 180 /* 149 181 float change = factor / this->timeFactor_; 182 */ 150 183 this->timeFactor_ = factor; 184 /* 151 185 for (ObjectList<ParticleInterface>::iterator it = ObjectList<ParticleInterface>::begin(); it; ++it) 152 186 it->setSpeedFactor(it->getSpeedFactor() * change); … … 154 188 for (ObjectList<Backlight>::iterator it = ObjectList<Backlight>::begin(); it; ++it) 155 189 it->setTimeFactor(timeFactor_); 190 */ 156 191 } 157 192 … … 162 197 std::string levelName; 163 198 CommandLine::getValue("level", &levelName); 164 start Level_ = new Level(Settings::getDataPath() + std::string("levels/") + levelName);165 Loader::open(start Level_);199 startFile_ = new XMLFile(Settings::getDataPath() + std::string("levels/") + levelName); 200 Loader::open(startFile_); 166 201 } 167 202 168 203 void GSLevel::unloadLevel() 169 204 { 170 Loader::unload(startLevel_); 171 delete this->startLevel_; 205 ////////////////////////////////////////////////////////////////////////////////////////// 206 // TODO // TODO // TODO // TODO // TODO // TODO // TODO // TODO // TODO // TODO // TODO // 207 ////////////////////////////////////////////////////////////////////////////////////////// 208 // Loader::unload(startFile_); // TODO: REACTIVATE THIS IF LOADER::UNLOAD WORKS PROPERLY / 209 ////////////////////////////////////////////////////////////////////////////////////////// 210 211 delete this->startFile_; 172 212 } 173 213 … … 192 232 void GSLevel::keybindInternal(const std::string& command, bool bTemporary) 193 233 { 194 static std::string bindingString = "";195 static bool bTemporarySaved = false;196 static bool bound = true;197 // note: We use a long name to make 'sure' that the user doesn't use it accidentally.198 // Howerver there will be no real issue if it happens anyway.199 if (command.find(keyDetectorCallbackCode_) != 0)200 {201 if ( bound)234 if (Core::showsGraphics()) 235 { 236 static std::string bindingString = ""; 237 static bool bTemporarySaved = false; 238 static bool bound = true; 239 // note: We use a long name to make 'sure' that the user doesn't use it accidentally. 240 // Howerver there will be no real issue if it happens anyway. 241 if (command.find(keyDetectorCallbackCode_) != 0) 202 242 { 203 COUT(0) << "Press any button/key or move a mouse/joystick axis" << std::endl; 204 InputManager::getInstance().requestEnterState("detector"); 205 bindingString = command; 206 bTemporarySaved = bTemporary; 207 bound = false; 243 if (bound) 244 { 245 COUT(0) << "Press any button/key or move a mouse/joystick axis" << std::endl; 246 InputManager::getInstance().requestEnterState("detector"); 247 bindingString = command; 248 bTemporarySaved = bTemporary; 249 bound = false; 250 } 251 //else: We're still in a keybind command. ignore this call. 208 252 } 209 //else: We're still in a keybind command. ignore this call. 210 } 211 else 212 { 213 if (!bound) 253 else 214 254 { 215 // user has pressed the key 216 std::string name = command.substr(this->keyDetectorCallbackCode_.size()); 217 COUT(0) << "Binding string \"" << bindingString << "\" on key '" << name << "'" << std::endl; 218 this->keyBinder_->setBinding(bindingString, name, bTemporarySaved); 219 InputManager::getInstance().requestLeaveState("detector"); 220 bound = true; 255 if (!bound) 256 { 257 // user has pressed the key 258 std::string name = command.substr(this->keyDetectorCallbackCode_.size()); 259 COUT(0) << "Binding string \"" << bindingString << "\" on key '" << name << "'" << std::endl; 260 this->keyBinder_->setBinding(bindingString, name, bTemporarySaved); 261 InputManager::getInstance().requestLeaveState("detector"); 262 bound = true; 263 } 264 // else: A key was pressed within the same tick, ignore it. 221 265 } 222 // else: A key was pressed within the same tick, ignore it.223 266 } 224 267 } -
code/trunk/src/orxonox/gamestates/GSLevel.h
r1887 r2087 37 37 namespace orxonox 38 38 { 39 class _OrxonoxExport GSLevel : public GameState<GSGraphics>, public OrxonoxClass39 class _OrxonoxExport GSLevel : public OrxonoxClass //,public GameState<GSGraphics> 40 40 { 41 41 friend class ClassIdentifier<GSLevel>; 42 42 public: 43 GSLevel( const std::string& name);44 virtual~GSLevel();43 GSLevel(); 44 ~GSLevel(); 45 45 46 46 // this has to be public because proteced triggers a bug in msvc … … 50 50 51 51 protected: 52 v irtual void enter();53 v irtual void leave();54 v irtual void ticked(const Clock& time);52 void enter(Ogre::Viewport* viewport); 53 void leave(); 54 void ticked(const Clock& time); 55 55 56 56 void loadLevel(); 57 57 void unloadLevel(); 58 58 59 float timeFactor_; //!< A factor t o change the gamespeed59 float timeFactor_; //!< A factor that sets the gamespeed. 1 is normal. 60 60 61 61 // console commands … … 64 64 void keybindInternal(const std::string& command, bool bTemporary); 65 65 66 Ogre::SceneManager* sceneManager_;67 66 KeyBinder* keyBinder_; //!< tool that loads and manages the input bindings 68 67 SimpleInputState* inputState_; 69 68 Radar* radar_; //!< represents the Radar (not the HUD part) 70 Level* startLevel_; //!< current hard coded default level 71 Level* hud_; //!< 'level' object fo the HUD 69 XMLFile* startFile_; //!< current hard coded default level 70 CameraManager* cameraManager_; 71 LevelManager* levelManager_; 72 72 73 73 // config values 74 74 std::string keyDetectorCallbackCode_; 75 75 76 76 private: 77 77 void setConfigValues(); -
code/trunk/src/orxonox/gamestates/GSRoot.cc
r1891 r2087 41 41 #include "core/TclThreadManager.h" 42 42 #include "tools/Timer.h" 43 #include "GraphicsEngine.h"44 43 #include "Settings.h" 45 44 … … 61 60 namespace orxonox 62 61 { 63 SetCommandLineArgument(dataPath, ""). setInformation("PATH");64 SetCommandLineArgument(limitToCPU, 1). setInformation("0: off | #cpu");62 SetCommandLineArgument(dataPath, "").information("PATH"); 63 SetCommandLineArgument(limitToCPU, 1).information("0: off | #cpu"); 65 64 66 65 GSRoot::GSRoot() … … 91 90 this->settings_ = new Settings(); 92 91 93 std::string dataPath; 94 CommandLine::getValue("dataPath", &dataPath); 92 std::string dataPath = CommandLine::getValue("dataPath"); 95 93 if (dataPath != "") 96 94 { … … 111 109 // do this after ogre has initialised. Somehow Ogre changes the settings again (not through 112 110 // the timer though). 113 int limitToCPU; 114 CommandLine::getValue("limitToCPU", &limitToCPU); 111 int limitToCPU = CommandLine::getValue("limitToCPU"); 115 112 if (limitToCPU > 0) 116 113 setThreadAffinity((unsigned int)(limitToCPU - 1)); … … 157 154 Copyright (c) 2000-2008 Torus Knot Software Ltd 158 155 159 OGRE is licensed under the LGPL. For more info, see ogre license info.156 OGRE is licensed under the LGPL. For more info, see OGRE license. 160 157 */ 161 158 void GSRoot::setThreadAffinity(unsigned int limitToCPU) -
code/trunk/src/orxonox/gamestates/GSServer.cc
r1910 r2087 30 30 #include "GSServer.h" 31 31 32 #include "core/ConsoleCommand.h"33 #include "core/input/InputManager.h"34 32 #include "core/CommandLine.h" 33 #include "core/Core.h" 35 34 #include "network/Server.h" 36 #include "Settings.h"37 35 38 36 namespace orxonox 39 37 { 40 SetCommandLineArgument(port, 55556).s etShortcut("p").setInformation("0-65535");38 SetCommandLineArgument(port, 55556).shortcut("p").information("0-65535"); 41 39 42 40 GSServer::GSServer() 43 : G SLevel("server")41 : GameState<GSGraphics>("server") 44 42 , server_(0) 45 43 { … … 52 50 void GSServer::enter() 53 51 { 54 Settings::_getInstance().bHasServer_ = true;52 Core::setHasServer(true); 55 53 56 GSLevel::enter(); 57 58 int serverPort = CommandLine::getArgument<int>("port")->getValue(); 59 this->server_ = new network::Server(serverPort); 54 this->server_ = new network::Server(CommandLine::getValue("port")); 60 55 COUT(0) << "Loading scene in server mode" << std::endl; 61 56 62 this->loadLevel();57 GSLevel::enter(this->getParent()->getViewport()); 63 58 64 59 server_->open(); 65 66 // add console commands67 FunctorMember<GSLevel>* functor = createFunctor(&GSLevel::setTimeFactor);68 functor->setObject(this);69 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor, "setTimeFactor")).accessLevel(AccessLevel::Offline).defaultValue(0, 1.0);;70 71 // level is loaded: we can start capturing the input72 InputManager::getInstance().requestEnterState("game");73 60 } 74 61 75 62 void GSServer::leave() 76 63 { 77 InputManager::getInstance().requestLeaveState("game"); 78 79 // TODO: Remove and destroy console command 80 81 this->unloadLevel(); 64 GSLevel::leave(); 82 65 83 66 this->server_->close(); 84 67 delete this->server_; 85 68 86 GSLevel::leave(); 87 88 Settings::_getInstance().bHasServer_ = false; 69 Core::setHasServer(false); 89 70 } 90 71 -
code/trunk/src/orxonox/gamestates/GSServer.h
r1755 r2087 33 33 #include "network/NetworkPrereqs.h" 34 34 #include "GSLevel.h" 35 #include "GSGraphics.h" 35 36 36 37 namespace orxonox 37 38 { 38 class _OrxonoxExport GSServer : public G SLevel39 class _OrxonoxExport GSServer : public GameState<GSGraphics>, public GSLevel 39 40 { 40 41 public: 41 42 GSServer(); 42 43 ~GSServer(); 43 44 44 45 45 private: -
code/trunk/src/orxonox/gamestates/GSStandalone.cc
r1755 r2087 30 30 #include "GSStandalone.h" 31 31 32 #include "core/input/InputManager.h" 33 #include "core/ConsoleCommand.h" 32 #include "core/Core.h" 34 33 35 34 namespace orxonox 36 35 { 37 36 GSStandalone::GSStandalone() 38 : G SLevel("standalone")37 : GameState<GSGraphics>("standalone") 39 38 { 40 39 } … … 46 45 void GSStandalone::enter() 47 46 { 48 GSLevel::enter();47 Core::setIsStandalone(true); 49 48 50 this->loadLevel(); 51 52 // add console commands 53 FunctorMember<GSLevel>* functor = createFunctor(&GSLevel::setTimeFactor); 54 functor->setObject(this); 55 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor, "setTimeFactor")).accessLevel(AccessLevel::Offline).defaultValue(0, 1.0);; 56 57 // level is loaded: we can start capturing the input 58 InputManager::getInstance().requestEnterState("game"); 49 GSLevel::enter(this->getParent()->getViewport()); 59 50 } 60 51 61 52 void GSStandalone::leave() 62 53 { 63 InputManager::getInstance().requestLeaveState("game");54 GSLevel::leave(); 64 55 65 // TODO: Remove and destroy console command 66 67 this->unloadLevel(); 68 69 GSLevel::leave(); 56 Core::setIsStandalone(false); 70 57 } 71 58 -
code/trunk/src/orxonox/gamestates/GSStandalone.h
r1755 r2087 32 32 #include "OrxonoxPrereqs.h" 33 33 #include "GSLevel.h" 34 #include "GSGraphics.h" 34 35 35 36 namespace orxonox 36 37 { 37 class _OrxonoxExport GSStandalone : public G SLevel38 class _OrxonoxExport GSStandalone : public GameState<GSGraphics>, public GSLevel 38 39 { 39 40 public: -
code/trunk/src/orxonox/gui/GUIManager.cc
r1887 r2087 47 47 #include "core/Core.h" 48 48 #include "tolua/tolua_bind.h" 49 #include "GraphicsEngine.h"50 49 #include "OgreCEGUIRenderer.h" 51 50 -
code/trunk/src/orxonox/gui/OgreCEGUIRenderer.cpp
r1755 r2087 25 25 *************************************************************************/ 26 26 27 #include "OrxonoxStableHeaders.h" 27 28 #include <CEGUIImagesetManager.h> 28 29 #include <CEGUIImageset.h> -
code/trunk/src/orxonox/gui/OgreCEGUIResourceProvider.cpp
r1755 r2087 24 24 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 25 25 *************************************************************************/ 26 #include "OrxonoxStableHeaders.h" 26 27 #include "OgreCEGUIResourceProvider.h" 27 28 -
code/trunk/src/orxonox/gui/OgreCEGUITexture.cpp
r1755 r2087 25 25 *************************************************************************/ 26 26 27 #include "OrxonoxStableHeaders.h" 27 28 #include <CEGUISystem.h> 28 29 #include <CEGUIExceptions.h> -
code/trunk/src/orxonox/objects/Radar.cc
r1818 r2087 36 36 #include <cfloat> 37 37 #include <cassert> 38 #include "objects/WorldEntity.h"39 #include "objects/SpaceShip.h"40 38 #include "core/CoreIncludes.h" 41 39 #include "core/ConsoleCommand.h" … … 114 112 for (ObjectList<RadarViewable>::iterator itElement = ObjectList<RadarViewable>::begin(); itElement; ++itElement) 115 113 { 114 /* 116 115 if ((*itElement) != SpaceShip::getLocalShip() && (*itListener)->getRadarSensitivity() > (*itElement)->getRadarObjectCamouflage()) 117 116 (*itListener)->displayObject(*itElement, *itElement == this->focus_); 117 */ 118 118 } 119 119 } … … 130 130 else 131 131 { 132 Vector3 localPosition = SpaceShip::getLocalShip()->getPosition();132 Vector3 localPosition;// = SpaceShip::getLocalShip()->getPosition(); 133 133 Vector3 targetPosition = localPosition; 134 134 if (*(this->itFocus_)) … … 143 143 for (ObjectList<RadarViewable>::iterator it = ObjectList<RadarViewable>::begin(); it; ++it) 144 144 { 145 /* 145 146 if (*it == SpaceShip::getLocalShip()) 146 147 continue; 147 148 */ 148 149 float targetDistance = localPosition.squaredDistance((*it)->getWorldPosition()); 149 150 if (targetDistance > currentDistance && targetDistance < nextDistance) -
code/trunk/src/orxonox/objects/RadarViewable.cc
r1818 r2087 31 31 #include "util/Debug.h" 32 32 #include "core/CoreIncludes.h" 33 #include "objects/WorldEntity.h"33 //#include "objects/WorldEntity.h" 34 34 #include "Radar.h" 35 35 … … 63 63 { 64 64 validate(); 65 return this->radarObject_->getWorldPosition();65 return Vector3::ZERO;//this->radarObject_->getWorldPosition(); 66 66 } 67 67 … … 69 69 { 70 70 validate(); 71 return this->radarObject_->getOrientation() * this->radarObject_->getVelocity();71 return Vector3::ZERO;//this->radarObject_->getOrientation() * this->radarObject_->getVelocity(); 72 72 } 73 73 } -
code/trunk/src/orxonox/objects/RadarViewable.h
r1818 r2087 44 44 class _OrxonoxExport RadarViewable : virtual public OrxonoxClass 45 45 { 46 class WorldEntity; 47 46 48 public: 47 49 enum Shape -
code/trunk/src/orxonox/overlays/OrxonoxOverlay.cc
r1755 r2087 44 44 #include "core/XMLPort.h" 45 45 #include "core/ConsoleCommand.h" 46 #include "GraphicsEngine.h"47 46 48 47 namespace orxonox … … 55 54 SetConsoleCommand(OrxonoxOverlay, rotateOverlay, false).accessLevel(AccessLevel::User); 56 55 57 OrxonoxOverlay::OrxonoxOverlay() 58 : overlay_(0) 59 , background_(0) 56 OrxonoxOverlay::OrxonoxOverlay(BaseObject* creator) 57 : BaseObject(creator) 60 58 { 61 59 RegisterObject(OrxonoxOverlay); 60 61 // add this overlay to the static map of OrxonoxOverlays 62 if (overlays_s.find(this->getName()) != overlays_s.end()) 63 { 64 COUT(1) << "Overlay names should be unique or you cannnot access them via console. Name: \"" << this->getName() << "\"" << std::endl; 65 } 66 overlays_s[this->getName()] = this; 67 68 // create the Ogre::Overlay 69 overlay_ = Ogre::OverlayManager::getSingleton().create("OrxonoxOverlay_overlay_" 70 + convertToString(hudOverlayCounter_s++)); 71 72 // create background panel (can be used to show any picture) 73 this->background_ = static_cast<Ogre::PanelOverlayElement*>( 74 Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", 75 "OrxonoxOverlay_background_" + convertToString(hudOverlayCounter_s++))); 76 this->overlay_->add2D(this->background_); 77 78 // We'll have to set the aspect ratio to a default value first. 79 // GSGraphics gets informed about our construction here and can update us in the next tick. 80 this->windowAspectRatio_ = 1.0; 81 this->sizeCorrectionChanged(); 82 83 this->changedVisibility(); 84 85 setSize(Vector2(1.0f, 1.0f)); 86 setPickPoint(Vector2(0.0f, 0.0f)); 87 setPosition(Vector2(0.0f, 0.0f)); 88 setRotation(Degree(0.0)); 89 setAspectCorrection(true); 90 setBackgroundMaterial(""); 62 91 } 63 92 … … 70 99 OrxonoxOverlay::~OrxonoxOverlay() 71 100 { 72 // erase ourself from the map with all overlays 73 std::map<std::string, OrxonoxOverlay*>::iterator it = overlays_s.find(this->getName()); 74 if (it != overlays_s.end()) 75 overlays_s.erase(it); 76 77 if (this->background_) 101 if (this->isInitialized()) 102 { 103 // erase ourself from the map with all overlays 104 std::map<std::string, OrxonoxOverlay*>::iterator it = overlays_s.find(this->getName()); 105 if (it != overlays_s.end()) 106 overlays_s.erase(it); 107 78 108 Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->background_); 79 if (this->overlay_)80 109 Ogre::OverlayManager::getSingleton().destroy(this->overlay_); 110 } 81 111 } 82 112 … … 94 124 SUPER(OrxonoxOverlay, XMLPort, xmlElement, mode); 95 125 96 if (mode == XMLPort::LoadObject) 97 { 98 // add this overlay to the static map of OrxonoxOverlays 99 if (overlays_s.find(this->getName()) != overlays_s.end()) 100 { 101 COUT(1) << "Overlay names should be unique or you cannnot access them via console." << std::endl; 102 } 103 overlays_s[this->getName()] = this; 104 105 // create the Ogre::Overlay 106 overlay_ = Ogre::OverlayManager::getSingleton().create("OrxonoxOverlay_overlay_" 107 + convertToString(hudOverlayCounter_s++)); 108 109 // create background panel (can be used to show any picture) 110 this->background_ = static_cast<Ogre::PanelOverlayElement*>( 111 Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", 112 "OrxonoxOverlay_background_" + convertToString(hudOverlayCounter_s++))); 113 this->overlay_->add2D(this->background_); 114 115 // We'll have to get the aspect ratio manually for the first time. Afterwards windowResized() gets 116 // called automatically by the GraphicsEngine. 117 this->windowResized(GraphicsEngine::getInstance().getWindowWidth(), 118 GraphicsEngine::getInstance().getWindowHeight()); 119 120 this->changedVisibility(); 121 } 122 123 XMLPortParam(OrxonoxOverlay, "size", setSize, getSize, xmlElement, mode) 124 .defaultValues(Vector2(1.0f, 1.0f)); 125 XMLPortParam(OrxonoxOverlay, "pickPoint", setPickPoint, getPickPoint, xmlElement, mode) 126 .defaultValues(Vector2(0.0f, 0.0f)); 127 XMLPortParam(OrxonoxOverlay, "position", setPosition, getPosition, xmlElement, mode) 128 .defaultValues(Vector2(0.0f, 0.0f)); 129 XMLPortParam(OrxonoxOverlay, "rotation", setRotation, getRotation, xmlElement, mode) 130 .defaultValues(0.0f); 131 XMLPortParam(OrxonoxOverlay, "correctAspect", setAspectCorrection, getAspectCorrection, xmlElement, mode) 132 .defaultValues(true); 133 XMLPortParam(OrxonoxOverlay, "background", setBackgroundMaterial, getBackgroundMaterial, xmlElement, mode) 134 .defaultValues(""); 126 XMLPortParam(OrxonoxOverlay, "size", setSize, getSize, xmlElement, mode); 127 XMLPortParam(OrxonoxOverlay, "pickPoint", setPickPoint, getPickPoint, xmlElement, mode); 128 XMLPortParam(OrxonoxOverlay, "position", setPosition, getPosition, xmlElement, mode); 129 XMLPortParam(OrxonoxOverlay, "rotation", setRotation, getRotation, xmlElement, mode); 130 XMLPortParam(OrxonoxOverlay, "correctAspect", setAspectCorrection, getAspectCorrection, xmlElement, mode); 131 XMLPortParam(OrxonoxOverlay, "background", setBackgroundMaterial, getBackgroundMaterial, xmlElement, mode); 132 } 133 134 void OrxonoxOverlay::changedName() 135 { 136 OrxonoxOverlay::overlays_s.erase(this->getOldName()); 137 138 if (OrxonoxOverlay::overlays_s.find(this->getName()) != OrxonoxOverlay::overlays_s.end()) 139 COUT(1) << "Overlay names should be unique or you cannnot access them via console. Name: \"" << this->getName() << "\"" << std::endl; 140 141 OrxonoxOverlay::overlays_s[this->getName()] = this; 135 142 } 136 143 … … 148 155 return this->background_->getMaterialName(); 149 156 else 150 return blankString;157 return BLANKSTRING; 151 158 } 152 159 -
code/trunk/src/orxonox/overlays/OrxonoxOverlay.h
r1747 r2087 84 84 85 85 public: 86 OrxonoxOverlay( );86 OrxonoxOverlay(BaseObject* creator); 87 87 virtual ~OrxonoxOverlay(); 88 88 89 89 virtual void XMLPort(Element& xmlElement, XMLPort::Mode mode); 90 91 virtual void changedName(); 90 92 91 93 //! Shows the overlay with an detour to BaseObject::visibility_ -
code/trunk/src/orxonox/overlays/OverlayGroup.cc
r1854 r2087 50 50 SetConsoleCommand(OverlayGroup, scrollGroup, false).accessLevel(AccessLevel::User); 51 51 52 OverlayGroup::OverlayGroup() 52 OverlayGroup::OverlayGroup(BaseObject* creator) 53 : BaseObject(creator) 53 54 { 54 55 RegisterObject(OverlayGroup); 56 57 setScale(Vector2(1.0, 1.0)); 58 setScroll(Vector2(0.0, 0.0)); 59 } 60 61 OverlayGroup::~OverlayGroup() 62 { 63 for (std::map<std::string, OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it) 64 delete it->second; 55 65 } 56 66 … … 65 75 SUPER(OverlayGroup, XMLPort, xmlElement, mode); 66 76 67 XMLPortParam(OverlayGroup, "scale", setScale, getScale, xmlElement, mode) .defaultValues(Vector2(1.0, 1.0));68 XMLPortParam(OverlayGroup, "scroll", setScroll, getScroll, xmlElement, mode) .defaultValues(Vector2(0.0, 0.0));77 XMLPortParam(OverlayGroup, "scale", setScale, getScale, xmlElement, mode); 78 XMLPortParam(OverlayGroup, "scroll", setScroll, getScroll, xmlElement, mode); 69 79 // loads all the child elements 70 80 XMLPortObject(OverlayGroup, OrxonoxOverlay, "", addElement, getElement, xmlElement, mode); … … 100 110 } 101 111 else 112 { 102 113 hudElements_[element->getName()] = element; 114 element->setVisible(this->isVisible()); 115 } 103 116 } 104 117 -
code/trunk/src/orxonox/overlays/OverlayGroup.h
r1747 r2087 54 54 { 55 55 public: 56 OverlayGroup( );56 OverlayGroup(BaseObject* creator); 57 57 //! Empty destructor. 58 ~OverlayGroup() { }58 ~OverlayGroup(); 59 59 60 60 virtual void XMLPort(Element& xmlElement, XMLPort::Mode mode); … … 63 63 static void scaleGroup(const std::string& name, float scale); 64 64 static void scrollGroup(const std::string& name, const Vector2& scroll); 65 66 inline const std::map<std::string, OrxonoxOverlay*>& getOverlays() const 67 { return this->hudElements_; } 65 68 66 69 void changedVisibility(); -
code/trunk/src/orxonox/overlays/OverlayText.cc
r1784 r2087 31 31 32 32 #include <OgreOverlayManager.h> 33 #include <OgreTextAreaOverlayElement.h>34 33 #include <OgrePanelOverlayElement.h> 35 34 … … 42 41 CreateFactory(OverlayText); 43 42 44 OverlayText::OverlayText( )45 : text_(0)43 OverlayText::OverlayText(BaseObject* creator) 44 : OrxonoxOverlay(creator) 46 45 { 47 46 RegisterObject(OverlayText); 47 48 this->text_ = static_cast<Ogre::TextAreaOverlayElement*>(Ogre::OverlayManager::getSingleton() 49 .createOverlayElement("TextArea", "OverlayText_text_" + getUniqueNumberString())); 50 this->text_->setCharHeight(1.0); 51 52 setFont("Monofur"); 53 setColour(ColourValue(1.0, 1.0, 1.0, 1.0)); 54 setCaption(""); 55 setTextSize(1.0f); 56 setAlignmentString("left"); 57 58 this->background_->addChild(this->text_); 48 59 } 49 60 50 61 OverlayText::~OverlayText() 51 62 { 52 if (this-> text_)63 if (this->isInitialized()) 53 64 Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->text_); 54 65 } … … 58 69 SUPER(OverlayText, XMLPort, xmlElement, mode); 59 70 60 if (mode == XMLPort::LoadObject) 61 { 62 this->text_ = static_cast<Ogre::TextAreaOverlayElement*>(Ogre::OverlayManager::getSingleton() 63 .createOverlayElement("TextArea", "OverlayText_text_" + getUniqueNumberStr())); 64 this->text_->setCharHeight(1.0); 65 66 this->background_->addChild(this->text_); 67 } 68 69 XMLPortParam(OverlayText, "font", setFont, getFont, xmlElement, mode).defaultValues("Monofur"); 70 XMLPortParam(OverlayText, "caption", setCaption, getCaption, xmlElement, mode).defaultValues(""); 71 XMLPortParam(OverlayText, "textSize", setTextSize, getTextSize, xmlElement, mode).defaultValues(1.0f); 71 XMLPortParam(OverlayText, "font", setFont, getFont, xmlElement, mode); 72 XMLPortParam(OverlayText, "colour", setColour, getColour, xmlElement, mode); 73 XMLPortParam(OverlayText, "caption", setCaption, getCaption, xmlElement, mode); 74 XMLPortParam(OverlayText, "textSize", setTextSize, getTextSize, xmlElement, mode); 75 XMLPortParam(OverlayText, "align", setAlignmentString, getAlignmentString, xmlElement, mode); 72 76 } 73 77 74 78 void OverlayText::setFont(const std::string& font) 75 79 { 76 if ( this->text_ &&font != "")80 if (font != "") 77 81 this->text_->setFontName(font); 78 82 } 79 83 80 const std::string& OverlayText::getFont() const84 void OverlayText::setAlignmentString(const std::string& alignment) 81 85 { 82 if (this->text_) 83 return this->text_->getFontName(); 84 else 85 return blankString; 86 if (alignment == "right") 87 this->setAlignment(Ogre::TextAreaOverlayElement::Right); 88 else if (alignment == "center") 89 this->setAlignment(Ogre::TextAreaOverlayElement::Center); 90 else // "left" and default 91 this->setAlignment(Ogre::TextAreaOverlayElement::Left); 92 } 93 94 std::string OverlayText::getAlignmentString() const 95 { 96 Ogre::TextAreaOverlayElement::Alignment alignment = this->text_->getAlignment(); 97 98 switch (alignment) 99 { 100 case Ogre::TextAreaOverlayElement::Right: 101 return "right"; 102 case Ogre::TextAreaOverlayElement::Center: 103 return "center"; 104 case Ogre::TextAreaOverlayElement::Left: 105 return "left"; 106 default: 107 assert(false); return ""; 108 } 86 109 } 87 110 88 111 void OverlayText::sizeChanged() 89 112 { 90 if (!this->overlay_)91 return;92 93 113 if (this->rotState_ == Horizontal) 94 114 this->overlay_->setScale(size_.y * sizeCorrection_.y, size_.y * sizeCorrection_.y); -
code/trunk/src/orxonox/overlays/OverlayText.h
r1625 r2087 34 34 #include <string> 35 35 #include <OgrePrerequisites.h> 36 #include <OgreTextAreaOverlayElement.h> 36 37 #include "OrxonoxOverlay.h" 37 38 … … 41 42 { 42 43 public: 43 OverlayText( );44 OverlayText(BaseObject* creator); 44 45 virtual ~OverlayText(); 45 46 46 47 virtual void XMLPort(Element& xmlElement, XMLPort::Mode mode); 47 48 49 void setCaption(const std::string& caption) { this->text_->setCaption(caption); } 50 std::string getCaption() const { return this->text_->getCaption(); } 51 52 void setFont(const std::string& font); 53 const std::string& getFont() const { return this->text_->getFontName(); } 54 55 void setColour(const ColourValue& colour) { this->text_->setColour(colour); } 56 const ColourValue& getColour() const { return this->text_->getColour(); } 57 58 void setAlignment(Ogre::TextAreaOverlayElement::Alignment alignment) { this->text_->setAlignment(alignment); } 59 Ogre::TextAreaOverlayElement::Alignment getAlignment() const { return this->text_->getAlignment(); } 60 48 61 protected: 49 62 virtual void sizeChanged(); 50 63 51 void setCaption(const std::string& caption) { this->caption_ = caption; } 52 const std::string& getCaption() const { return this->caption_; } 53 54 void setFont(const std::string& font); 55 const std::string& getFont() const; 64 void setAlignmentString(const std::string& alignment); 65 std::string getAlignmentString() const; 56 66 57 67 void setTextSize(float size) { this->setSize(Vector2(size, size)); } … … 59 69 60 70 Ogre::TextAreaOverlayElement* text_; 61 62 private:63 std::string caption_;64 71 }; 65 72 } -
code/trunk/src/orxonox/overlays/console/InGameConsole.cc
r1879 r2087 48 48 #include "core/input/SimpleInputState.h" 49 49 #include "core/input/InputBuffer.h" 50 #include "GraphicsEngine.h"51 50 52 51 namespace orxonox … … 170 169 @brief Initializes the InGameConsole. 171 170 */ 172 void InGameConsole::initialise( )171 void InGameConsole::initialise(int windowWidth, int windowHeight) 173 172 { 174 173 // create the corresponding input state … … 246 245 this->consoleOverlayContainer_->addChild(this->consoleOverlayNoise_); 247 246 248 this->windowResized( GraphicsEngine::getInstance().getWindowWidth(), GraphicsEngine::getInstance().getWindowHeight());247 this->windowResized(windowWidth, windowHeight); 249 248 250 249 // move overlay "above" the top edge of the screen … … 613 612 @return The converted string 614 613 */ 615 /*static*/ Ogre::UTFString InGameConsole::convert2UTF( std::string s)614 /*static*/ Ogre::UTFString InGameConsole::convert2UTF(const std::string& text) 616 615 { 617 616 Ogre::UTFString utf; 618 617 Ogre::UTFString::code_point cp; 619 for (unsigned int i = 0; i < s.size(); ++i)620 { 621 cp = s[i];618 for (unsigned int i = 0; i < text.size(); ++i) 619 { 620 cp = text[i]; 622 621 cp &= 0xFF; 623 622 utf.append(1, cp); -
code/trunk/src/orxonox/overlays/console/InGameConsole.h
r1879 r2087 49 49 ~InGameConsole(); 50 50 51 void initialise( );51 void initialise(int windowWidth, int windowHeight); 52 52 void destroy(); 53 53 void setConfigValues(); … … 60 60 static void openConsole(); 61 61 static void closeConsole(); 62 63 static Ogre::UTFString convert2UTF(const std::string& text); 62 64 63 65 private: // functions … … 83 85 // config value related 84 86 void bHidesAllInputChanged(); 85 86 static Ogre::UTFString convert2UTF(std::string s);87 87 88 88 private: // variables -
code/trunk/src/orxonox/overlays/debug/DebugFPSText.cc
r1755 r2087 38 38 CreateFactory(DebugFPSText); 39 39 40 DebugFPSText::DebugFPSText( )40 DebugFPSText::DebugFPSText(BaseObject* creator) : OverlayText(creator) 41 41 { 42 42 RegisterObject(DebugFPSText); … … 50 50 { 51 51 float fps = GraphicsEngine::getInstance().getAverageFramesPerSecond(); 52 this-> text_->setCaption(this->getCaption() +convertToString(fps));52 this->setCaption(convertToString(fps)); 53 53 } 54 54 } -
code/trunk/src/orxonox/overlays/debug/DebugFPSText.h
r1747 r2087 40 40 { 41 41 public: 42 DebugFPSText( );42 DebugFPSText(BaseObject* creator); 43 43 ~DebugFPSText(); 44 44 -
code/trunk/src/orxonox/overlays/debug/DebugRTRText.cc
r1755 r2087 38 38 CreateFactory(DebugRTRText); 39 39 40 DebugRTRText::DebugRTRText( )40 DebugRTRText::DebugRTRText(BaseObject* creator) : OverlayText(creator) 41 41 { 42 42 RegisterObject(DebugRTRText); … … 50 50 { 51 51 float rtr = GraphicsEngine::getInstance().getAverageTickTime(); 52 this-> text_->setCaption(this->getCaption() +convertToString(rtr));52 this->setCaption(convertToString(rtr)); 53 53 } 54 54 } -
code/trunk/src/orxonox/overlays/debug/DebugRTRText.h
r1747 r2087 40 40 { 41 41 public: 42 DebugRTRText( );42 DebugRTRText(BaseObject* creator); 43 43 ~DebugRTRText(); 44 44 -
code/trunk/src/orxonox/overlays/hud/HUDBar.cc
r1854 r2087 38 38 39 39 #include "util/Convert.h" 40 #include "util/String.h" 40 41 #include "core/CoreIncludes.h" 41 42 #include "core/XMLPort.h" … … 45 46 CreateFactory(BarColour); 46 47 47 BarColour::BarColour( )48 : position_(0.0)48 BarColour::BarColour(BaseObject* creator) 49 : BaseObject(creator) 49 50 { 50 51 RegisterObject(BarColour); 52 53 setColour(ColourValue(1.0, 1.0, 1.0, 1.0)); 54 setPosition(0.0); 51 55 } 52 56 … … 55 59 SUPER(BarColour, XMLPort, xmlElement, mode); 56 60 57 XMLPortParam(BarColour, "colour", setColour, getColour, xmlElement, mode) 58 .defaultValues(ColourValue(1.0, 1.0, 1.0, 1.0)); 59 XMLPortParam(BarColour, "position", setPosition, getPosition, xmlElement, mode).defaultValues(0.0f); 61 XMLPortParam(BarColour, "colour", setColour, getColour, xmlElement, mode); 62 XMLPortParam(BarColour, "position", setPosition, getPosition, xmlElement, mode); 60 63 } 61 64 … … 63 66 unsigned int HUDBar::materialcount_s = 0; 64 67 65 HUDBar::HUDBar() 66 : bar_(0) 67 , textureUnitState_(0) 68 HUDBar::HUDBar(BaseObject* creator) 69 : OrxonoxOverlay(creator) 68 70 { 69 71 RegisterObject(HUDBar); 72 73 // create new material 74 std::string materialname = "barmaterial" + getConvertedValue<unsigned int, std::string>(materialcount_s++); 75 Ogre::MaterialPtr material = (Ogre::MaterialPtr)Ogre::MaterialManager::getSingleton().create(materialname, "General"); 76 material->getTechnique(0)->getPass(0)->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA); 77 this->textureUnitState_ = material->getTechnique(0)->getPass(0)->createTextureUnitState(); 78 this->textureUnitState_->setTextureName("bar2.tga"); 79 // use the default colour 80 this->textureUnitState_->setColourOperationEx(Ogre::LBX_MODULATE, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, ColourValue(0.2, 0.7, 0.2)); 81 82 this->bar_ = static_cast<Ogre::PanelOverlayElement*>(Ogre::OverlayManager::getSingleton() 83 .createOverlayElement("Panel", "HUDBar_bar_" + getUniqueNumberString())); 84 this->bar_->setMaterialName(materialname); 85 86 setValue(0.4567654f); 87 setRightToLeft(false); 88 setAutoColour(true); 89 90 this->background_->addChild(bar_); 70 91 } 71 92 72 93 HUDBar::~HUDBar() 73 94 { 74 if (this-> bar_)95 if (this->isInitialized()) 75 96 Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->bar_); 76 97 } … … 80 101 SUPER(HUDBar, XMLPort, xmlElement, mode); 81 102 82 if (mode == XMLPort::LoadObject) 83 { 84 // create new material 85 std::string materialname = "barmaterial" + getConvertedValue<unsigned int, std::string>(materialcount_s++); 86 Ogre::MaterialPtr material = (Ogre::MaterialPtr)Ogre::MaterialManager::getSingleton().create(materialname, "General"); 87 material->getTechnique(0)->getPass(0)->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA); 88 this->textureUnitState_ = material->getTechnique(0)->getPass(0)->createTextureUnitState(); 89 this->textureUnitState_->setTextureName("bar2.tga"); 90 // use the default colour 91 this->textureUnitState_->setColourOperationEx(Ogre::LBX_MODULATE, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, ColourValue(0.2, 0.7, 0.2)); 92 93 this->bar_ = static_cast<Ogre::PanelOverlayElement*>(Ogre::OverlayManager::getSingleton() 94 .createOverlayElement("Panel", "HUDBar_bar_" + getUniqueNumberStr())); 95 this->bar_->setMaterialName(materialname); 96 this->background_->addChild(bar_); 97 } 98 99 XMLPortParam(HUDBar, "initialValue", setValue, getValue, xmlElement, mode).defaultValues(0.4567654f); 100 XMLPortParam(HUDBar, "rightToLeft", setRightToLeft, getRightToLeft, xmlElement, mode).defaultValues(false); 101 XMLPortParam(HUDBar, "autoColour", setAutoColour, getAutoColour, xmlElement, mode).defaultValues(true); 103 XMLPortParam(HUDBar, "initialValue", setValue, getValue, xmlElement, mode); 104 XMLPortParam(HUDBar, "rightToLeft", setRightToLeft, getRightToLeft, xmlElement, mode); 105 XMLPortParam(HUDBar, "autoColour", setAutoColour, getAutoColour, xmlElement, mode); 102 106 XMLPortObject(HUDBar, BarColour, "", addColour, getColour, xmlElement, mode); 103 107 } -
code/trunk/src/orxonox/overlays/hud/HUDBar.h
r1747 r2087 44 44 { 45 45 public: 46 BarColour( );46 BarColour(BaseObject* creator); 47 47 ~BarColour() { } 48 48 … … 64 64 { 65 65 public: 66 HUDBar( );66 HUDBar(BaseObject* creator); 67 67 virtual ~HUDBar(); 68 68 -
code/trunk/src/orxonox/overlays/hud/HUDNavigation.cc
r1819 r2087 41 41 #include "core/XMLPort.h" 42 42 #include "objects/Radar.h" 43 #include "objects/SpaceShip.h"44 #include "objects/Projectile.h"45 #include "objects/CameraHandler.h"46 43 47 44 namespace orxonox … … 49 46 CreateFactory(HUDNavigation); 50 47 51 HUDNavigation::HUDNavigation() 52 : navMarker_(0) 53 , aimMarker_(0) 54 , navText_(0) 48 HUDNavigation::HUDNavigation(BaseObject* creator) 49 : OrxonoxOverlay(creator) 55 50 { 56 51 RegisterObject(HUDNavigation); 52 53 // create nav text 54 navText_ = static_cast<Ogre::TextAreaOverlayElement*>(Ogre::OverlayManager::getSingleton() 55 .createOverlayElement("TextArea", "HUDNavigation_navText_" + getUniqueNumberString())); 56 57 // create nav marker 58 navMarker_ = static_cast<Ogre::PanelOverlayElement*>(Ogre::OverlayManager::getSingleton() 59 .createOverlayElement("Panel", "HUDNavigation_navMarker_" + getUniqueNumberString())); 60 navMarker_->setMaterialName("Orxonox/NavArrows"); 61 62 // create aim marker 63 aimMarker_ = static_cast<Ogre::PanelOverlayElement*>(Ogre::OverlayManager::getSingleton() 64 .createOverlayElement("Panel", "HUDNavigation_aimMarker_" + getUniqueNumberString())); 65 aimMarker_->setMaterialName("Orxonox/NavCrosshair"); 66 this->wasOutOfView_ = true; // Ensure the material is changed right the first time.. 67 68 setFont("Monofur"); 69 setTextSize(0.05f); 70 setNavMarkerSize(0.05f); 71 setAimMarkerSize(0.04f); 72 73 background_->addChild(navMarker_); 74 background_->addChild(aimMarker_); 75 background_->addChild(navText_); 76 77 // hide at first 78 this->setVisible(false); 57 79 } 58 80 59 81 HUDNavigation::~HUDNavigation() 60 82 { 61 if (this->navMarker_) 83 if (this->isInitialized()) 84 { 62 85 Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->navMarker_); 63 if (this->navText_)64 86 Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->navText_); 65 if (this->aimMarker_)66 87 Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->aimMarker_); 88 } 67 89 } 68 90 … … 71 93 SUPER(HUDNavigation, XMLPort, xmlElement, mode); 72 94 73 if (mode == XMLPort::LoadObject) 74 { 75 // create nav text 76 navText_ = static_cast<Ogre::TextAreaOverlayElement*>(Ogre::OverlayManager::getSingleton() 77 .createOverlayElement("TextArea", "HUDNavigation_navText_" + getUniqueNumberStr())); 78 79 // create nav marker 80 navMarker_ = static_cast<Ogre::PanelOverlayElement*>(Ogre::OverlayManager::getSingleton() 81 .createOverlayElement("Panel", "HUDNavigation_navMarker_" + getUniqueNumberStr())); 82 navMarker_->setMaterialName("Orxonox/NavArrows"); 83 wasOutOfView_ = true; // just to ensure the material is changed right the first time.. 84 85 // create aim marker 86 aimMarker_ = static_cast<Ogre::PanelOverlayElement*>(Ogre::OverlayManager::getSingleton() 87 .createOverlayElement("Panel", "HUDNavigation_aimMarker_" + getUniqueNumberStr())); 88 aimMarker_->setMaterialName("Orxonox/NavCrosshair"); 89 90 background_->addChild(navMarker_); 91 background_->addChild(aimMarker_); 92 background_->addChild(navText_); 93 94 // hide at first 95 this->setVisible(false); 96 } 97 98 XMLPortParam(HUDNavigation, "font", setFont, getFont, xmlElement, mode).defaultValues("Monofur"); 99 XMLPortParam(HUDNavigation, "textSize", setTextSize, getTextSize, xmlElement, mode).defaultValues(0.05f); 100 XMLPortParam(HUDNavigation, "navMarkerSize", setNavMarkerSize, getNavMarkerSize, xmlElement, mode) 101 .defaultValues(0.05f); 102 XMLPortParam(HUDNavigation, "aimMarkerSize", setAimMarkerSize, getAimMarkerSize, xmlElement, mode) 103 .defaultValues(0.04f); 95 XMLPortParam(HUDNavigation, "font", setFont, getFont, xmlElement, mode); 96 XMLPortParam(HUDNavigation, "textSize", setTextSize, getTextSize, xmlElement, mode); 97 XMLPortParam(HUDNavigation, "navMarkerSize", setNavMarkerSize, getNavMarkerSize, xmlElement, mode); 98 XMLPortParam(HUDNavigation, "aimMarkerSize", setAimMarkerSize, getAimMarkerSize, xmlElement, mode); 104 99 } 105 100 … … 115 110 return this->navText_->getFontName(); 116 111 else 117 return blankString;112 return BLANKSTRING; 118 113 } 119 114 … … 149 144 float textLength = convertToString(dist).size() * navText_->getCharHeight() * 0.3; 150 145 146 /* 151 147 Ogre::Camera* navCam = SpaceShip::getLocalShip()->getCamera()->cam_; 152 148 Matrix4 transformationMatrix = navCam->getProjectionMatrix() * navCam->getViewMatrix(); 149 */ 153 150 // transform to screen coordinates 154 Vector3 pos = transformationMatrix *Radar::getInstance().getFocus()->getWorldPosition();151 Vector3 pos = /*transformationMatrix * */Radar::getInstance().getFocus()->getWorldPosition(); 155 152 156 153 bool outOfView; … … 224 221 { 225 222 // object is in view 226 223 /* 227 224 Vector3 aimpos = transformationMatrix * getPredictedPosition(SpaceShip::getLocalShip()->getPosition(), 228 225 Projectile::getSpeed(), Radar::getInstance().getFocus()->getWorldPosition(), Radar::getInstance().getFocus()->getOrientedVelocity()); 229 226 */ 230 227 if (wasOutOfView_) 231 228 { … … 240 237 241 238 aimMarker_->show(); 239 /* 242 240 aimMarker_->setLeft((aimpos.x + 1.0 - aimMarker_->getWidth()) * 0.5); 243 241 aimMarker_->setTop((-aimpos.y + 1.0 - aimMarker_->getHeight()) * 0.5); 244 242 */ 245 243 navText_->setLeft((pos.x + 1.0 + navMarker_->getWidth()) * 0.5); 246 244 navText_->setTop((-pos.y + 1.0 + navMarker_->getHeight()) * 0.5); … … 250 248 float HUDNavigation::getDist2Focus() const 251 249 { 250 /* 252 251 if (Radar::getInstance().getFocus()) 253 252 return (Radar::getInstance().getFocus()->getWorldPosition() - SpaceShip::getLocalShip()->getPosition()).length(); 254 253 else 254 */ 255 255 return 0; 256 256 } -
code/trunk/src/orxonox/overlays/hud/HUDNavigation.h
r1747 r2087 41 41 { 42 42 public: 43 HUDNavigation( );43 HUDNavigation(BaseObject* creator); 44 44 ~HUDNavigation(); 45 45 -
code/trunk/src/orxonox/overlays/hud/HUDRadar.cc
r1819 r2087 35 35 36 36 #include "util/Math.h" 37 #include "util/String.h" 37 38 #include "core/ConsoleCommand.h" 38 39 #include "core/CoreIncludes.h" 39 40 #include "core/XMLPort.h" 40 #include "objects/SpaceShip.h"41 #include "objects/WorldEntity.h"42 41 #include "objects/Radar.h" 43 42 #include "tools/TextureGenerator.h" … … 47 46 CreateFactory(HUDRadar); 48 47 49 HUDRadar::HUDRadar( )50 : marker_(0)48 HUDRadar::HUDRadar(BaseObject* creator) 49 : OrxonoxOverlay(creator) 51 50 { 52 51 RegisterObject(HUDRadar); 52 53 marker_ = static_cast<Ogre::PanelOverlayElement*>(Ogre::OverlayManager::getSingleton() 54 .createOverlayElement("Panel", "HUDRadar_marker_" + getUniqueNumberString())); 55 marker_->setMaterialName("Orxonox/RadarMarker"); 56 overlay_->add2D(marker_); 57 marker_->hide(); 58 59 setRadarSensitivity(1.0f); 60 setHalfDotSizeDistance(3000.0f); 61 setMaximumDotSize(0.1f); 62 63 shapeMaterials_[RadarViewable::Dot] = "RadarSquare.tga"; 64 shapeMaterials_[RadarViewable::Triangle] = "RadarSquare.tga"; 65 shapeMaterials_[RadarViewable::Square] = "RadarSquare.tga"; 53 66 } 54 67 55 68 HUDRadar::~HUDRadar() 56 69 { 57 if (this->marker_) 70 if (this->isInitialized()) 71 { 58 72 Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->marker_); 59 for (std::vector<Ogre::PanelOverlayElement*>::iterator it = this->radarDots_.begin(); 60 it != this->radarDots_.end(); ++it) 61 { 62 Ogre::OverlayManager::getSingleton().destroyOverlayElement(*it); 73 for (std::vector<Ogre::PanelOverlayElement*>::iterator it = this->radarDots_.begin(); 74 it != this->radarDots_.end(); ++it) 75 { 76 Ogre::OverlayManager::getSingleton().destroyOverlayElement(*it); 77 } 63 78 } 64 79 } … … 68 83 SUPER(HUDRadar, XMLPort, xmlElement, mode); 69 84 70 if (mode == XMLPort::LoadObject) 71 { 72 marker_ = static_cast<Ogre::PanelOverlayElement*>(Ogre::OverlayManager::getSingleton() 73 .createOverlayElement("Panel", "HUDRadar_marker_" + getUniqueNumberStr())); 74 marker_->setMaterialName("Orxonox/RadarMarker"); 75 overlay_->add2D(marker_); 76 marker_->hide(); 77 } 78 79 XMLPortParam(HUDRadar, "sensitivity", setRadarSensitivity, getRadarSensitivity, xmlElement, mode) 80 .defaultValues(1.0f); 81 XMLPortParam(HUDRadar, "halfDotSizeDistance", setHalfDotSizeDistance, getHalfDotSizeDistance, 82 xmlElement, mode).defaultValues(3000.0f); 83 XMLPortParam(HUDRadar, "maximumDotSize", setMaximumDotSize, getMaximumDotSize, xmlElement, mode) 84 .defaultValues(0.1f); 85 86 shapeMaterials_[RadarViewable::Dot] = "RadarSquare.tga"; 87 shapeMaterials_[RadarViewable::Triangle] = "RadarSquare.tga"; 88 shapeMaterials_[RadarViewable::Square] = "RadarSquare.tga"; 85 XMLPortParam(HUDRadar, "sensitivity", setRadarSensitivity, getRadarSensitivity, xmlElement, mode); 86 XMLPortParam(HUDRadar, "halfDotSizeDistance", setHalfDotSizeDistance, getHalfDotSizeDistance, xmlElement, mode); 87 XMLPortParam(HUDRadar, "maximumDotSize", setMaximumDotSize, getMaximumDotSize, xmlElement, mode); 89 88 } 90 89 91 90 void HUDRadar::displayObject(RadarViewable* object, bool bIsMarked) 92 91 { 92 /* 93 93 const WorldEntity* wePointer = object->getWorldEntity(); 94 94 … … 100 100 return; 101 101 } 102 102 */ 103 103 // try to find a panel already created 104 104 Ogre::PanelOverlayElement* panel; … … 108 108 // we have to create a new entry 109 109 panel = static_cast<Ogre::PanelOverlayElement*>( 110 Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", "RadarDot" + getUniqueNumberStr ()));110 Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", "RadarDot" + getUniqueNumberString())); 111 111 radarDots_.push_back(panel); 112 112 // get right material … … 126 126 } 127 127 panel->show(); 128 128 /* 129 129 // set size to fit distance... 130 130 float distance = (wePointer->getWorldPosition() - SpaceShip::getLocalShip()->getPosition()).length(); … … 144 144 this->marker_->setPosition((1.0 + coord.x - size * 1.5) * 0.5, (1.0 - coord.y - size * 1.5) * 0.5); 145 145 } 146 */ 146 147 } 147 148 -
code/trunk/src/orxonox/overlays/hud/HUDRadar.h
r1819 r2087 45 45 { 46 46 public: 47 HUDRadar( );47 HUDRadar(BaseObject* creator); 48 48 ~HUDRadar(); 49 49 -
code/trunk/src/orxonox/overlays/hud/HUDSpeedBar.cc
r1755 r2087 31 31 #include "HUDSpeedBar.h" 32 32 #include "core/CoreIncludes.h" 33 #include "objects/SpaceShip.h"34 33 35 34 namespace orxonox … … 37 36 CreateFactory(HUDSpeedBar); 38 37 39 HUDSpeedBar::HUDSpeedBar() 38 HUDSpeedBar::HUDSpeedBar(BaseObject* creator) 39 : HUDBar(creator) 40 40 { 41 41 RegisterObject(HUDSpeedBar); … … 49 49 void HUDSpeedBar::tick(float dt) 50 50 { 51 /* 51 52 SpaceShip* ship = SpaceShip::getLocalShip(); 52 53 if (ship) … … 57 58 this->setValue(value); 58 59 } 60 */ 59 61 } 60 62 } -
code/trunk/src/orxonox/overlays/hud/HUDSpeedBar.h
r1747 r2087 41 41 { 42 42 public: 43 HUDSpeedBar( );43 HUDSpeedBar(BaseObject* creator); 44 44 ~HUDSpeedBar(); 45 45 -
code/trunk/src/orxonox/tools/BillboardSet.cc
r1755 r2087 31 31 32 32 #include <sstream> 33 #include <cassert> 33 34 34 35 #include <OgreSceneManager.h> 36 #include <OgreBillboard.h> 35 37 36 #include " GraphicsEngine.h"37 #include "util/ Math.h"38 #include "util/Convert.h" 39 #include "util/String.h" 38 40 39 41 namespace orxonox … … 46 48 } 47 49 48 void BillboardSet::setBillboardSet(const std::string& file, int count)50 BillboardSet::~BillboardSet() 49 51 { 50 std::ostringstream name; 51 name << (BillboardSet::billboardSetCounter_s++); 52 this->billboardSet_ = GraphicsEngine::getInstance().getLevelSceneManager()->createBillboardSet("Billboard" + name.str(), count); 53 this->billboardSet_->createBillboard(Vector3::ZERO); 54 this->billboardSet_->setMaterialName(file); 52 this->destroyBillboardSet(); 55 53 } 56 54 57 void BillboardSet::setBillboardSet( const std::string& file, const ColourValue& colour, int count)55 void BillboardSet::setBillboardSet(Ogre::SceneManager* scenemanager, const std::string& file, int count) 58 56 { 59 std::ostringstream name; 60 name << (BillboardSet::billboardSetCounter_s++); 61 this->billboardSet_ = GraphicsEngine::getInstance().getLevelSceneManager()->createBillboardSet("Billboard" + name.str(), count); 62 this->billboardSet_->createBillboard(Vector3::ZERO, colour); 63 this->billboardSet_->setMaterialName(file); 57 this->setBillboardSet(scenemanager, file, Vector3::ZERO, count); 64 58 } 65 59 66 void BillboardSet::setBillboardSet( const std::string& file, const Vector3& position, int count)60 void BillboardSet::setBillboardSet(Ogre::SceneManager* scenemanager, const std::string& file, const ColourValue& colour, int count) 67 61 { 68 std::ostringstream name; 69 name << (BillboardSet::billboardSetCounter_s++); 70 this->billboardSet_ = GraphicsEngine::getInstance().getLevelSceneManager()->createBillboardSet("Billboard" + name.str(), count); 71 this->billboardSet_->createBillboard(position); 72 this->billboardSet_->setMaterialName(file); 62 this->setBillboardSet(scenemanager, file, colour, Vector3::ZERO, count); 73 63 } 74 64 75 void BillboardSet::setBillboardSet( const std::string& file, const ColourValue& colour, const Vector3& position, int count)65 void BillboardSet::setBillboardSet(Ogre::SceneManager* scenemanager, const std::string& file, const Vector3& position, int count) 76 66 { 77 std::ostringstream name; 78 name << (BillboardSet::billboardSetCounter_s++); 79 this->billboardSet_ = GraphicsEngine::getInstance().getLevelSceneManager()->createBillboardSet("Billboard" + name.str(), count); 80 this->billboardSet_->createBillboard(position, colour); 81 this->billboardSet_->setMaterialName(file); 67 assert(scenemanager); 68 this->destroyBillboardSet(); 69 70 try 71 { 72 this->billboardSet_ = scenemanager->createBillboardSet("Billboard" + convertToString(BillboardSet::billboardSetCounter_s++), count); 73 this->billboardSet_->createBillboard(position); 74 this->billboardSet_->setMaterialName(file); 75 } 76 catch (...) 77 { 78 COUT(1) << "Error: Couln't load billboard \"" << file << "\"" << std::endl; 79 } 80 81 this->scenemanager_ = scenemanager; 82 82 } 83 83 84 BillboardSet::~BillboardSet() 84 void BillboardSet::setBillboardSet(Ogre::SceneManager* scenemanager, const std::string& file, const ColourValue& colour, const Vector3& position, int count) 85 { 86 assert(scenemanager); 87 this->destroyBillboardSet(); 88 89 try 90 { 91 this->billboardSet_ = scenemanager->createBillboardSet("Billboard" + convertToString(BillboardSet::billboardSetCounter_s++), count); 92 this->billboardSet_->createBillboard(position, colour); 93 this->billboardSet_->setMaterialName(file); 94 } 95 catch (...) 96 { 97 COUT(1) << "Error: Couln't load billboard \"" << file << "\"" << std::endl; 98 } 99 100 this->scenemanager_ = scenemanager; 101 } 102 103 void BillboardSet::destroyBillboardSet() 104 { 105 if (this->billboardSet_ && this->scenemanager_) 106 this->scenemanager_->destroyBillboardSet(this->billboardSet_); 107 } 108 109 const std::string& BillboardSet::getName() const 85 110 { 86 111 if (this->billboardSet_) 87 GraphicsEngine::getInstance().getLevelSceneManager()->destroyBillboardSet(this->billboardSet_); 112 return this->billboardSet_->getName(); 113 else 114 return BLANKSTRING; 115 } 116 117 void BillboardSet::setVisible(bool visible) 118 { 119 if (this->billboardSet_) 120 this->billboardSet_->setVisible(visible); 121 } 122 123 bool BillboardSet::getVisible() const 124 { 125 if (this->billboardSet_) 126 return this->billboardSet_->getVisible(); 127 else 128 return false; 129 } 130 131 void BillboardSet::setColour(const ColourValue& colour) 132 { 133 if (this->billboardSet_) 134 { 135 for (int i = 0; i < this->billboardSet_->getNumBillboards(); ++i) 136 this->billboardSet_->getBillboard(i)->setColour(colour); 137 } 138 } 139 140 const ColourValue& BillboardSet::getColour() const 141 { 142 if (this->billboardSet_ && this->billboardSet_->getNumBillboards() > 0) 143 { 144 return this->billboardSet_->getBillboard(0)->getColour(); 145 } 146 else 147 return ColourValue::White; 148 } 149 150 void BillboardSet::setMaterial(const std::string& material) 151 { 152 if (this->billboardSet_) 153 this->billboardSet_->setMaterialName(material); 154 } 155 156 const std::string& BillboardSet::getMaterial() const 157 { 158 if (this->billboardSet_) 159 return this->billboardSet_->getMaterialName(); 160 else 161 return BLANKSTRING; 88 162 } 89 163 } -
code/trunk/src/orxonox/tools/BillboardSet.h
r1602 r2087 44 44 BillboardSet(); 45 45 ~BillboardSet(); 46 void setBillboardSet(const std::string& file, int count = 1); 47 void setBillboardSet(const std::string& file, const ColourValue& colour, int count = 1); 48 void setBillboardSet(const std::string& file, const Vector3& position, int count = 1); 49 void setBillboardSet(const std::string& file, const ColourValue& colour, const Vector3& position, int count = 1); 46 47 void setBillboardSet(Ogre::SceneManager* scenemanager, const std::string& file, int count = 1); 48 void setBillboardSet(Ogre::SceneManager* scenemanager, const std::string& file, const ColourValue& colour, int count = 1); 49 void setBillboardSet(Ogre::SceneManager* scenemanager, const std::string& file, const Vector3& position, int count = 1); 50 void setBillboardSet(Ogre::SceneManager* scenemanager, const std::string& file, const ColourValue& colour, const Vector3& position, int count = 1); 50 51 51 52 inline Ogre::BillboardSet* getBillboardSet() 52 53 { return this->billboardSet_; } 53 54 54 inline const std::string& getName() const 55 { return this->billboardSet_->getName(); } 55 const std::string& getName() const; 56 56 57 inline void setVisible(bool visible) 58 { this->billboardSet_->setVisible(visible); } 59 inline bool getVisible() const 60 { return this->billboardSet_->getVisible(); } 57 void setVisible(bool visible); 58 bool getVisible() const; 59 60 void setColour(const ColourValue& colour); 61 const ColourValue& getColour() const; 62 63 void setMaterial(const std::string& material); 64 const std::string& getMaterial() const; 61 65 62 66 private: 67 void destroyBillboardSet(); 68 63 69 static unsigned int billboardSetCounter_s; 64 70 Ogre::BillboardSet* billboardSet_; 71 Ogre::SceneManager* scenemanager_; 65 72 }; 66 73 } -
code/trunk/src/orxonox/tools/Mesh.cc
r1755 r2087 32 32 #include <sstream> 33 33 #include <OgreSceneManager.h> 34 #include "GraphicsEngine.h" 35 #include "Settings.h" 34 #include <cassert> 35 36 #include "core/Core.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 (Settings::showsGraphics()) 51 this->entity_ = GraphicsEngine::getInstance().getLevelSceneManager()->createEntity("Mesh" + name.str(), file); 46 this->entity_ = 0; 47 this->bCastShadows_ = true; 52 48 } 53 49 54 50 Mesh::~Mesh() 55 51 { 56 if (this->entity_ && Settings::showsGraphics()) 57 GraphicsEngine::getInstance().getLevelSceneManager()->destroyEntity(this->entity_); 52 if (this->entity_ && this->scenemanager_) 53 this->scenemanager_->destroyEntity(this->entity_); 54 } 55 56 void Mesh::setMeshSource(Ogre::SceneManager* scenemanager, const std::string& meshsource) 57 { 58 assert(scenemanager); 59 60 this->scenemanager_ = scenemanager; 61 62 if (this->entity_) 63 this->scenemanager_->destroyEntity(this->entity_); 64 65 if (Core::showsGraphics()) 66 { 67 try 68 { 69 this->entity_ = this->scenemanager_->createEntity("Mesh" + convertToString(Mesh::meshCounter_s++), meshsource); 70 this->entity_->setCastShadows(this->bCastShadows_); 71 } 72 catch (...) 73 { 74 COUT(1) << "Error: Couln't load mesh \"" << meshsource << "\"" << std::endl; 75 } 76 } 77 } 78 79 void Mesh::setCastShadows(bool bCastShadows) 80 { 81 this->bCastShadows_ = bCastShadows; 82 if (this->entity_) 83 this->entity_->setCastShadows(this->bCastShadows_); 84 } 85 86 const std::string& Mesh::getName() const 87 { 88 if (this->entity_) 89 return this->entity_->getName(); 90 else 91 return BLANKSTRING; 92 } 93 94 void Mesh::setVisible(bool bVisible) 95 { 96 if (this->entity_) 97 this->entity_->setVisible(bVisible); 98 } 99 100 bool Mesh::isVisible() const 101 { 102 if (this->entity_) 103 return this->entity_->getVisible(); 104 else 105 return false; 58 106 } 59 107 } -
code/trunk/src/orxonox/tools/Mesh.h
r1627 r2087 21 21 * 22 22 * Author: 23 * ...23 * Fabian 'x3n' Landau 24 24 * Co-authors: 25 25 * ... … … 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(Ogre::SceneManager* scenemanager, 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; 54 55 void setCastShadows(bool bCastShadows); 56 inline bool getCastShadows() const 57 { return this->bCastShadows_; } 57 58 58 59 private: 59 60 static unsigned int meshCounter_s; 60 61 Ogre::Entity* entity_; 62 bool bCastShadows_; 63 Ogre::SceneManager* scenemanager_; 61 64 }; 62 65 } -
code/trunk/src/orxonox/tools/ParticleInterface.cc
r1755 r2087 1 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * 4 * 5 * License notice: 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 * Author: 22 * ... 23 * Co-authors: 24 * ... 25 * 26 */ 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 22 * Author: 23 * Fabian 'x3n' Landau 24 * Co-authors: 25 * ... 26 * 27 */ 27 28 28 29 /** … … 37 38 #include <OgreParticleEmitter.h> 38 39 #include <OgreSceneManager.h> 40 #include <cassert> 39 41 40 42 #include "GraphicsEngine.h" … … 44 46 namespace orxonox 45 47 { 46 unsigned int ParticleInterface::counter_s = 0; 47 ParticleInterface* ParticleInterface::currentParticleInterface_s = 0; 48 49 ParticleInterface::ParticleInterface(const std::string& templateName, LODParticle::LOD detaillevel) 50 { 51 RegisterRootObject(ParticleInterface); 52 53 this->sceneNode_ = 0; 54 this->bEnabled_ = true; 55 this->detaillevel_ = (unsigned int)detaillevel; 56 this->particleSystem_ = GraphicsEngine::getInstance().getLevelSceneManager()->createParticleSystem("particles" + getConvertedValue<unsigned int, std::string>(ParticleInterface::counter_s++), templateName); 57 //this->particleSystem_->setSpeedFactor(Orxonox::getInstance().getTimeFactor()); 58 this->particleSystem_->setSpeedFactor(1.0f); 59 60 if (GraphicsEngine::getInstance().getDetailLevelParticle() < (unsigned int)this->detaillevel_) 61 { 62 this->bVisible_ = false; 63 this->updateVisibility(); 64 } 65 else 66 { 67 this->bVisible_ = true; 68 } 69 } 70 71 ParticleInterface::~ParticleInterface() 72 { 73 this->particleSystem_->removeAllEmitters(); 74 GraphicsEngine::getInstance().getLevelSceneManager()->destroyParticleSystem(particleSystem_); 75 } 76 77 void ParticleInterface::addToSceneNode(Ogre::SceneNode* sceneNode) 78 { 79 this->sceneNode_ = sceneNode; 80 this->sceneNode_->attachObject(this->particleSystem_); 81 } 82 83 void ParticleInterface::detachFromSceneNode() 84 { 85 if (this->sceneNode_) 86 { 87 this->sceneNode_->detachObject(this->particleSystem_); 88 this->sceneNode_ = 0; 89 } 90 } 91 92 Ogre::ParticleEmitter* ParticleInterface::createNewEmitter() 93 { 94 if (this->particleSystem_->getNumEmitters() > 0) 95 { 96 Ogre::ParticleEmitter* newemitter = this->particleSystem_->addEmitter(this->particleSystem_->getEmitter(0)->getType()); 97 this->particleSystem_->getEmitter(0)->copyParametersTo(newemitter); 98 return newemitter; 99 } 100 else 101 return 0; 102 } 103 Ogre::ParticleEmitter* ParticleInterface::getEmitter(unsigned int emitterNr) const 104 { 105 if (emitterNr < this->particleSystem_->getNumEmitters()) 106 return this->particleSystem_->getEmitter(emitterNr); 107 else 108 return 0; 109 } 110 void ParticleInterface::removeEmitter(unsigned int emitterNr) 111 { 112 if (emitterNr < this->particleSystem_->getNumEmitters()) 113 this->particleSystem_->removeEmitter(emitterNr); 114 } 115 void ParticleInterface::removeAllEmitters() 116 { 117 this->particleSystem_->removeAllEmitters(); 118 } 119 unsigned int ParticleInterface::getNumEmitters() const 120 { 121 return this->particleSystem_->getNumEmitters(); 122 } 123 124 Ogre::ParticleAffector* ParticleInterface::addAffector(const std::string& name) 125 { 126 return this->particleSystem_->addAffector(name); 127 } 128 Ogre::ParticleAffector* ParticleInterface::getAffector(unsigned int affectorNr) const 129 { 130 if (affectorNr < this->particleSystem_->getNumAffectors()) 131 return this->particleSystem_->getAffector(affectorNr); 132 else 133 return 0; 134 } 135 void ParticleInterface::removeAffector(unsigned int affectorNr) 136 { 137 if (affectorNr < this->particleSystem_->getNumAffectors()) 138 this->particleSystem_->removeAffector(affectorNr); 139 } 140 void ParticleInterface::removeAllAffectors() 141 { 142 this->particleSystem_->removeAllAffectors(); 143 } 144 unsigned int ParticleInterface::getNumAffectors() const 145 { 146 return this->particleSystem_->getNumAffectors(); 147 } 148 149 void ParticleInterface::setEnabled(bool enable) 150 { 151 this->bEnabled_ = enable; 152 this->updateVisibility(); 153 } 154 155 void ParticleInterface::detailLevelChanged(unsigned int newlevel) 156 { 157 if (newlevel >= (unsigned int)this->detaillevel_) 158 this->bVisible_ = true; 159 else 160 this->bVisible_ = false; 161 162 this->updateVisibility(); 163 } 164 165 void ParticleInterface::updateVisibility() 166 { 167 for (unsigned int i = 0; i < this->particleSystem_->getNumEmitters(); i++) 168 this->particleSystem_->getEmitter(i)->setEnabled(this->bEnabled_ && this->bVisible_); 169 } 170 171 void ParticleInterface::setSpeedFactor(float factor) 172 { 173 //this->particleSystem_->setSpeedFactor(Orxonox::getInstance().getTimeFactor() * factor); 174 this->particleSystem_->setSpeedFactor(1.0f * factor); 175 } 176 float ParticleInterface::getSpeedFactor() const 177 { 178 //return (this->particleSystem_->getSpeedFactor() / Orxonox::getInstance().getTimeFactor()); 179 return (this->particleSystem_->getSpeedFactor() / 1.0f); 180 } 181 182 bool ParticleInterface::getKeepParticlesInLocalSpace() const 183 { 184 return this->particleSystem_->getKeepParticlesInLocalSpace(); 185 } 186 void ParticleInterface::setKeepParticlesInLocalSpace(bool keep) 187 { 188 this->particleSystem_->setKeepParticlesInLocalSpace(keep); 189 } 48 unsigned int ParticleInterface::counter_s = 0; 49 ParticleInterface* ParticleInterface::currentParticleInterface_s = 0; 50 51 ParticleInterface::ParticleInterface(Ogre::SceneManager* scenemanager, const std::string& templateName, LODParticle::LOD detaillevel) 52 { 53 RegisterRootObject(ParticleInterface); 54 55 assert(scenemanager); 56 57 this->scenemanager_ = scenemanager; 58 this->sceneNode_ = 0; 59 60 this->bEnabled_ = true; 61 this->bVisible_ = true; 62 this->bAllowedByLOD_ = true; 63 64 this->particleSystem_ = this->scenemanager_->createParticleSystem("particles" + getConvertedValue<unsigned int, std::string>(ParticleInterface::counter_s++), templateName); 65 this->particleSystem_->setSpeedFactor(1.0f); 66 //this->particleSystem_->setSpeedFactor(Orxonox::getInstance().getTimeFactor()); 67 68 this->setDetailLevel((unsigned int)detaillevel); 69 } 70 71 ParticleInterface::~ParticleInterface() 72 { 73 this->particleSystem_->removeAllEmitters(); 74 this->detachFromSceneNode(); 75 this->scenemanager_->destroyParticleSystem(particleSystem_); 76 } 77 78 void ParticleInterface::addToSceneNode(Ogre::SceneNode* sceneNode) 79 { 80 if (this->sceneNode_) 81 this->detachFromSceneNode(); 82 83 this->sceneNode_ = sceneNode; 84 this->sceneNode_->attachObject(this->particleSystem_); 85 } 86 87 void ParticleInterface::detachFromSceneNode() 88 { 89 if (this->sceneNode_) 90 { 91 this->sceneNode_->detachObject(this->particleSystem_); 92 this->sceneNode_ = 0; 93 } 94 } 95 96 Ogre::ParticleEmitter* ParticleInterface::createNewEmitter() 97 { 98 if (this->particleSystem_->getNumEmitters() > 0) 99 { 100 Ogre::ParticleEmitter* newemitter = this->particleSystem_->addEmitter(this->particleSystem_->getEmitter(0)->getType()); 101 this->particleSystem_->getEmitter(0)->copyParametersTo(newemitter); 102 return newemitter; 103 } 104 else 105 return 0; 106 } 107 Ogre::ParticleEmitter* ParticleInterface::getEmitter(unsigned int emitterNr) const 108 { 109 if (emitterNr < this->particleSystem_->getNumEmitters()) 110 return this->particleSystem_->getEmitter(emitterNr); 111 else 112 return 0; 113 } 114 void ParticleInterface::removeEmitter(unsigned int emitterNr) 115 { 116 if (emitterNr < this->particleSystem_->getNumEmitters()) 117 this->particleSystem_->removeEmitter(emitterNr); 118 } 119 void ParticleInterface::removeAllEmitters() 120 { 121 this->particleSystem_->removeAllEmitters(); 122 } 123 unsigned int ParticleInterface::getNumEmitters() const 124 { 125 return this->particleSystem_->getNumEmitters(); 126 } 127 128 Ogre::ParticleAffector* ParticleInterface::addAffector(const std::string& name) 129 { 130 return this->particleSystem_->addAffector(name); 131 } 132 Ogre::ParticleAffector* ParticleInterface::getAffector(unsigned int affectorNr) const 133 { 134 if (affectorNr < this->particleSystem_->getNumAffectors()) 135 return this->particleSystem_->getAffector(affectorNr); 136 else 137 return 0; 138 } 139 void ParticleInterface::removeAffector(unsigned int affectorNr) 140 { 141 if (affectorNr < this->particleSystem_->getNumAffectors()) 142 this->particleSystem_->removeAffector(affectorNr); 143 } 144 void ParticleInterface::removeAllAffectors() 145 { 146 this->particleSystem_->removeAllAffectors(); 147 } 148 unsigned int ParticleInterface::getNumAffectors() const 149 { 150 return this->particleSystem_->getNumAffectors(); 151 } 152 153 void ParticleInterface::setEnabled(bool enable) 154 { 155 this->bEnabled_ = enable; 156 157 for (unsigned int i = 0; i < this->particleSystem_->getNumEmitters(); i++) 158 this->particleSystem_->getEmitter(i)->setEnabled(this->bEnabled_ && this->bAllowedByLOD_); 159 } 160 161 void ParticleInterface::setVisible(bool visible) 162 { 163 this->bVisible_ = visible; 164 165 this->particleSystem_->setVisible(this->bVisible_ && this->bAllowedByLOD_); 166 } 167 168 void ParticleInterface::setDetailLevel(unsigned int level) 169 { 170 this->detaillevel_ = level; 171 this->detailLevelChanged(GraphicsEngine::getInstance().getDetailLevelParticle()); 172 } 173 174 void ParticleInterface::detailLevelChanged(unsigned int newlevel) 175 { 176 if (newlevel >= (unsigned int)this->detaillevel_) 177 this->bAllowedByLOD_ = true; 178 else 179 this->bAllowedByLOD_ = false; 180 181 this->updateVisibility(); 182 } 183 184 void ParticleInterface::updateVisibility() 185 { 186 this->setEnabled(this->isEnabled()); 187 this->setVisible(this->isVisible()); 188 } 189 190 void ParticleInterface::setSpeedFactor(float factor) 191 { 192 //this->particleSystem_->setSpeedFactor(Orxonox::getInstance().getTimeFactor() * factor); 193 this->particleSystem_->setSpeedFactor(1.0f * factor); 194 } 195 float ParticleInterface::getSpeedFactor() const 196 { 197 //return (this->particleSystem_->getSpeedFactor() / Orxonox::getInstance().getTimeFactor()); 198 return (this->particleSystem_->getSpeedFactor() / 1.0f); 199 } 200 201 bool ParticleInterface::getKeepParticlesInLocalSpace() const 202 { 203 return this->particleSystem_->getKeepParticlesInLocalSpace(); 204 } 205 void ParticleInterface::setKeepParticlesInLocalSpace(bool keep) 206 { 207 this->particleSystem_->setKeepParticlesInLocalSpace(keep); 208 } 190 209 } -
code/trunk/src/orxonox/tools/ParticleInterface.h
r1563 r2087 21 21 * 22 22 * Author: 23 * ...23 * Fabian 'x3n' Landau 24 24 * Co-authors: 25 25 * ... … … 45 45 namespace orxonox 46 46 { 47 class _OrxonoxExport ParticleInterface : public OrxonoxClass48 {49 public:50 ParticleInterface(const std::string& templateName, LODParticle::LOD detaillevel);51 ~ParticleInterface();47 class _OrxonoxExport ParticleInterface : public OrxonoxClass 48 { 49 public: 50 ParticleInterface(Ogre::SceneManager* scenemanager, const std::string& templateName, LODParticle::LOD detaillevel); 51 virtual ~ParticleInterface(); 52 52 53 inline Ogre::ParticleSystem* getParticleSystem() const54 { return this->particleSystem_; }53 inline Ogre::ParticleSystem* getParticleSystem() const 54 { return this->particleSystem_; } 55 55 56 void addToSceneNode(Ogre::SceneNode* sceneNode);57 void detachFromSceneNode();56 void addToSceneNode(Ogre::SceneNode* sceneNode); 57 void detachFromSceneNode(); 58 58 59 Ogre::ParticleEmitter* createNewEmitter();60 Ogre::ParticleEmitter* getEmitter(unsigned int emitterNr) const;61 void removeEmitter(unsigned int emitterNr);62 void removeAllEmitters();63 unsigned int getNumEmitters() const;59 Ogre::ParticleEmitter* createNewEmitter(); 60 Ogre::ParticleEmitter* getEmitter(unsigned int emitterNr) const; 61 void removeEmitter(unsigned int emitterNr); 62 void removeAllEmitters(); 63 unsigned int getNumEmitters() const; 64 64 65 Ogre::ParticleAffector* addAffector(const std::string& name);66 Ogre::ParticleAffector* getAffector(unsigned int affectorNr) const;67 void removeAffector(unsigned int affectorNr);68 void removeAllAffectors();69 unsigned int getNumAffectors() const;65 Ogre::ParticleAffector* addAffector(const std::string& name); 66 Ogre::ParticleAffector* getAffector(unsigned int affectorNr) const; 67 void removeAffector(unsigned int affectorNr); 68 void removeAllAffectors(); 69 unsigned int getNumAffectors() const; 70 70 71 float getSpeedFactor() const;72 void setSpeedFactor(float factor);73 bool getKeepParticlesInLocalSpace() const;74 void setKeepParticlesInLocalSpace(bool keep);71 float getSpeedFactor() const; 72 void setSpeedFactor(float factor); 73 bool getKeepParticlesInLocalSpace() const; 74 void setKeepParticlesInLocalSpace(bool keep); 75 75 76 void setEnabled(bool enable); 77 void detailLevelChanged(unsigned int newlevel); 76 void setEnabled(bool enable); 77 inline bool isEnabled() const 78 { return this->bEnabled_; } 78 79 79 inline void storeThisAsCurrentParticleInterface() 80 { ParticleInterface::currentParticleInterface_s = this; } 81 inline static ParticleInterface* getCurrentParticleInterface() 82 { return ParticleInterface::currentParticleInterface_s; } 80 void setVisible(bool visible); 81 inline bool isVisible() const 82 { return this->bVisible_; } 83 83 84 private:85 void updateVisibility();84 void detailLevelChanged(unsigned int newlevel); 85 void setDetailLevel(unsigned int level); 86 86 87 static ParticleInterface* currentParticleInterface_s; 88 static unsigned int counter_s; 89 Ogre::SceneNode* sceneNode_; 90 Ogre::ParticleSystem* particleSystem_; 91 bool bVisible_; 92 bool bEnabled_; 93 unsigned int detaillevel_; //!< Detail level of this particle effect (0: off, 1: low, 2: normal, 3: high) 94 }; 87 inline void storeThisAsCurrentParticleInterface() 88 { ParticleInterface::currentParticleInterface_s = this; } 89 inline static ParticleInterface* getCurrentParticleInterface() 90 { return ParticleInterface::currentParticleInterface_s; } 91 92 private: 93 void updateVisibility(); 94 95 static ParticleInterface* currentParticleInterface_s; 96 static unsigned int counter_s; 97 98 Ogre::SceneNode* sceneNode_; 99 Ogre::ParticleSystem* particleSystem_; 100 bool bVisible_; 101 bool bEnabled_; 102 bool bAllowedByLOD_; 103 unsigned int detaillevel_; //!< Detail level of this particle effect (0: off, 1: low, 2: normal, 3: high) 104 Ogre::SceneManager* scenemanager_; 105 }; 95 106 } 96 107 -
code/trunk/src/orxonox/tools/Timer.cc
r1755 r2087 92 92 this->bLoop_ = false; 93 93 this->bActive_ = false; 94 this->bKillAfterCall_ = false; 94 95 95 96 this->time_ = 0; … … 111 112 void TimerBase::run() const 112 113 { 114 bool temp = this->bKillAfterCall_; // to avoid errors with bKillAfterCall_=false and an exutors which destroy the timer 115 113 116 (*this->executor_)(); 117 118 if (temp) 119 delete this; 114 120 } 115 121 … … 136 142 { 137 143 // It's time to call the function 138 if (this->bLoop_ )144 if (this->bLoop_ && !this->bKillAfterCall_) 139 145 { 140 146 this->time_ += this->interval_; // Q: Why '+=' and not '='? A: Think about it. It's more accurate like that. Seriously. -
code/trunk/src/orxonox/tools/Timer.h
r1755 r2087 116 116 TimerBase(); 117 117 118 Executor* executor_; //!< The executor of the function that should be called when the time expires 119 120 long long interval_; //!< The time-interval in micro seconds 121 bool bLoop_; //!< If true, the function gets called every 'interval' seconds 122 bool bActive_; //!< If true, the Timer ticks and calls the function if the time's up 123 124 long long time_; //!< Internal variable, counting the time till the next function-call 118 Executor* executor_; //!< The executor of the function that should be called when the time expires 119 120 long long interval_; //!< The time-interval in micro seconds 121 bool bLoop_; //!< If true, the function gets called every 'interval' seconds 122 bool bActive_; //!< If true, the Timer ticks and calls the function if the time's up 123 bool bKillAfterCall_; //!< If true the timer gets deleted after it called the function 124 125 long long time_; //!< Internal variable, counting the time till the next function-call 125 126 }; 126 127 … … 139 140 @param exeuctor A executor of the function to call 140 141 */ 141 Timer(float interval, bool bLoop, T* object, ExecutorMember<T>* exeuctor )142 { 143 this->setTimer(interval, bLoop, object, exeuctor );142 Timer(float interval, bool bLoop, T* object, ExecutorMember<T>* exeuctor, bool bKillAfterCall = false) 143 { 144 this->setTimer(interval, bLoop, object, exeuctor, bKillAfterCall); 144 145 } 145 146 … … 151 152 @param exeuctor A executor of the function to call 152 153 */ 153 void setTimer(float interval, bool bLoop, T* object, ExecutorMember<T>* executor )154 void setTimer(float interval, bool bLoop, T* object, ExecutorMember<T>* executor, bool bKillAfterCall = false) 154 155 { 155 156 this->deleteExecutor(); … … 162 163 163 164 this->time_ = this->interval_; 165 this->bKillAfterCall_ = bKillAfterCall; 164 166 } 165 167 }; … … 177 179 @param exeuctor A executor of the function to call 178 180 */ 179 StaticTimer(float interval, bool bLoop, ExecutorStatic* executor )180 { 181 this->setTimer(interval, bLoop, executor );181 StaticTimer(float interval, bool bLoop, ExecutorStatic* executor, bool bKillAfterCall = false) 182 { 183 this->setTimer(interval, bLoop, executor, bKillAfterCall); 182 184 } 183 185 … … 189 191 @param executor A executor of the function to call 190 192 */ 191 void setTimer(float interval, bool bLoop, ExecutorStatic* executor )193 void setTimer(float interval, bool bLoop, ExecutorStatic* executor, bool bKillAfterCall = false) 192 194 { 193 195 this->deleteExecutor(); … … 199 201 200 202 this->time_ = this->interval_; 203 this->bKillAfterCall_ = bKillAfterCall; 201 204 } 202 205 }; -
code/trunk/src/tinyxml/ticpp.h
r1639 r2087 1184 1184 T* m_tiXmlPointer; /**< Internal pointer to the TiXml Class which is being wrapped */ 1185 1185 1186 public: 1186 1187 /** 1187 1188 @internal … … 1195 1196 return m_tiXmlPointer; 1196 1197 } 1198 protected: 1197 1199 1198 1200 /** -
code/trunk/src/tolua/lua/array.lua
- Property svn:eol-style set to native
-
code/trunk/src/tolua/lua/basic.lua
- Property svn:eol-style set to native
-
code/trunk/src/tolua/lua/class.lua
- Property svn:eol-style set to native
-
code/trunk/src/tolua/lua/clean.lua
- Property svn:eol-style set to native
-
code/trunk/src/tolua/lua/code.lua
- Property svn:eol-style set to native
-
code/trunk/src/tolua/lua/compat-5.1.lua
- Property svn:eol-style set to native
-
code/trunk/src/tolua/lua/compat.lua
- Property svn:eol-style set to native
-
code/trunk/src/tolua/lua/container.lua
- Property svn:eol-style set to native
-
code/trunk/src/tolua/lua/custom.lua
- Property svn:eol-style set to native
-
code/trunk/src/tolua/lua/custom_hide.lua
- Property svn:eol-style set to native
-
code/trunk/src/tolua/lua/declaration.lua
- Property svn:eol-style set to native
-
code/trunk/src/tolua/lua/define.lua
- Property svn:eol-style set to native
-
code/trunk/src/tolua/lua/doit.lua
- Property svn:eol-style set to native
-
code/trunk/src/tolua/lua/enumerate.lua
- Property svn:eol-style set to native
-
code/trunk/src/tolua/lua/feature.lua
- Property svn:eol-style set to native
-
code/trunk/src/tolua/lua/function.lua
- Property svn:eol-style set to native
-
code/trunk/src/tolua/lua/module.lua
- Property svn:eol-style set to native
-
code/trunk/src/tolua/lua/namespace.lua
- Property svn:eol-style set to native
-
code/trunk/src/tolua/lua/operator.lua
- Property svn:eol-style set to native
-
code/trunk/src/tolua/lua/package.lua
- Property svn:eol-style set to native
-
code/trunk/src/tolua/lua/typedef.lua
- Property svn:eol-style set to native
-
code/trunk/src/tolua/lua/variable.lua
- Property svn:eol-style set to native
-
code/trunk/src/tolua/lua/verbatim.lua
- Property svn:eol-style set to native
-
code/trunk/src/tolua/tolua-5.1.pkg
- Property svn:mergeinfo changed (with no actual effect on merging)
-
code/trunk/src/util
-
Property
svn:mergeinfo
set to
(toggle deleted branches)
/code/branches/ceguilua/src/util merged eligible /code/branches/script_trigger/src/util merged eligible /code/branches/core3/src/util 1572-1739,1742-2014 /code/branches/gcc43/src/util 1580 /code/branches/gui/src/util 1635-1723 /code/branches/input/src/util 1629-1636
-
Property
svn:mergeinfo
set to
(toggle deleted branches)
-
code/trunk/src/util/CMakeLists.txt
r1844 r2087 8 8 OutputBuffer.cc 9 9 OutputHandler.cc 10 SignalHandler.cc 10 11 String.cc 11 12 SubString.cc -
code/trunk/src/util/Convert.h
r1889 r2087 21 21 * 22 22 * Author: 23 * Reto Grieder 23 24 * Fabian 'x3n' Landau 24 25 * Benjamin Grauer … … 28 29 29 30 /*! 30 @file Convert.h31 @file 31 32 @brief Definition and Implementation of the Convert class. 32 33 */ 33 34 34 #ifndef _Convert _H__35 #define _Convert _H__35 #ifndef _Converter_H__ 36 #define _Converter_H__ 36 37 37 38 #include "UtilPrereqs.h" … … 39 40 #include <string> 40 41 #include <sstream> 42 #include <istream> 43 #include <ostream> 41 44 #include <typeinfo> 42 45 43 #include "Math.h"44 46 #include "Debug.h" 45 #include "SubString.h"46 47 #include "String.h" 47 48 48 // disable annoying warning about forcing value to boolean 49 // GCC generates warnings when implicitely casting from float to int for instance. 50 // This is however exactly what convertValue does, so we need to suppress these warnings. 51 // They only occur when using the ImplicitConversion template. 52 #if ORXONOX_COMPILER == ORXONOX_COMPILER_GNUC 53 # pragma GCC system_header 54 #endif 55 56 57 /////////////////////////////////////////////// 58 // Static detection for conversion functions // 59 /////////////////////////////////////////////// 60 61 /* The idea to use the sizeof() operator on return functions to determine function existance 62 is described in 'Modern C++ design' by Alexandrescu (2001). */ 63 64 // disable warnings about possible loss of data 49 65 #if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC 50 # pragma warning(push)51 # pragma warning(disable:4100 4800)66 # pragma warning(push) 67 # pragma warning(disable:4244) 52 68 #endif 53 69 54 55 ////////// 56 // MAIN // 57 ////////// 58 59 // Enum to declare the wanted conversion preference in case of equal type-levels 60 enum ConversionPreference 61 { 62 CP_PreferToType, 63 CP_PreferFromType, 64 }; 65 66 // Helper classes to determine the preferred partial template specialization 67 class _ToType_ {}; 68 class _FromType_ {}; 69 class _Explicit_ {}; 70 71 72 // The default convert functions 73 template <class FromType, class ToType, class Type> 74 struct ConverterSpecialized 75 { 76 enum { specialized = false }; 70 template <class FromType, class ToType> 71 class ImplicitConversion 72 { 73 private: 74 ImplicitConversion(); ImplicitConversion(const ImplicitConversion&); ~ImplicitConversion(); 75 // Gets chosen only if there is an implicit conversion from FromType to ToType. 76 static char test(ToType); 77 // Accepts any argument. Why do we not use a template? The reason is that with templates, 78 // the function above is only taken iff it is an exact type match. But since we want to 79 // check for implicit conversion, we have to use the ellipsis. 80 static long long test(...); 81 static FromType object; // helper object to handle private c'tor and d'tor 82 public: 83 // test(object) only has 'long long' return type iff the compiler doesn't choose test(...) 84 enum { exists = (sizeof(test(object)) == sizeof(char)) }; 85 }; 86 87 #if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC 88 # pragma warning(pop) 89 #endif 90 91 92 //////////////////////////////////// 93 //// ACTUAL CONVERSION SEQUENCE //// 94 //////////////////////////////////// 95 /* 96 There is a distinct priority when choosing the right conversion function: 97 Overwrite: 98 1. (Partial) template specialisation of ConverterExplicit::convert() 99 Fallbacks: 100 2. Any possible implicit conversion. This includes 'FooBar' --> 'int' if FooBar defines operator float(). 101 3. Global or member operators for stringstream when converting from or to std::string (or FROM const char*) 102 4. (Partial) template specialisation of ConverterFallback::convert() 103 5. Function that simply displays "Could not convert value" with type information obtained from typeid(). 104 105 Notes: 106 There has to be an exact type match when using template specialisations. 107 Template specialisations can be defined after including this file. Any implicit cast function or iostream 108 operator has to be declared BEFORE this file gets parsed. 109 110 Defining your own functions: 111 There are obviously 4 ways to specifiy a user defined conversion. What should I use? 112 113 Usually, ConverterFallback fits quite well. You won't have to deal with the conversion from 114 'MyClass' to 'MyClass' by using another explicit template specialisation to avoid ambiguities. 115 116 However if you want to overwrite an implicit conversion or an iostream operator, you really need to 117 make use of ConverterExplicit. 118 */ 119 120 namespace 121 { 122 //! Little template that maps integers to entire types (Alexandrescu 2001) 123 template <int I> 124 struct Int2Type { }; 125 } 126 127 128 /////////////////// 129 // No Conversion // 130 /////////////////// 131 132 // Default template. No conversion available at all. 133 template <class FromType, class ToType> 134 struct ConverterFallback 135 { 77 136 static bool convert(ToType* output, const FromType& input) 78 137 { 79 COUT(2) << "Warning: Couldn't convert a value: From \"" << typeid(FromType).name() << "\" to \"" << typeid(ToType).name() << "\"" << std::endl; 138 COUT(2) << "Could not convert value of type " << typeid(FromType).name() 139 << " to type " << typeid(ToType).name() << std::endl; 80 140 return false; 81 141 } 82 142 }; 83 143 84 85 // The default convert function if both types are the same 86 template <class BothTypes> 87 struct ConverterSpecialized<BothTypes, BothTypes, _Explicit_> 88 { 89 enum { specialized = true }; 90 static bool convert(BothTypes* output, const BothTypes& input) 91 { (*output) = input; return true; } 92 }; 93 94 95 // The possible levels 96 #define __low__ 0 // Everything that is or behaves like a primitive type (an can be converted with a typecast to every other low-level type) 97 #define __mid__ 1 // Everything that has overloaded << and >> operators to operate on a std::stream 98 #define __high__ 2 // Everything that doesn't fullfill the lowerlevel-requirements and therefore needs specialized conversions 99 100 // Defines the levels of all types: Default is __high__ so you don't have to define every high-level type 101 template <class T> struct ConverterLevel { enum { level = __high__ }; }; 102 template <> struct ConverterLevel<std::string> { enum { level = __mid__ }; }; 103 template <> struct ConverterLevel<orxonox::Radian> { enum { level = __mid__ }; }; 104 template <> struct ConverterLevel<orxonox::Degree> { enum { level = __mid__ }; }; 105 template <> struct ConverterLevel<int> { enum { level = __low__ }; }; 106 template <> struct ConverterLevel<unsigned int> { enum { level = __low__ }; }; 107 template <> struct ConverterLevel<char> { enum { level = __low__ }; }; 108 template <> struct ConverterLevel<unsigned char> { enum { level = __low__ }; }; 109 template <> struct ConverterLevel<short> { enum { level = __low__ }; }; 110 template <> struct ConverterLevel<unsigned short> { enum { level = __low__ }; }; 111 template <> struct ConverterLevel<long> { enum { level = __low__ }; }; 112 template <> struct ConverterLevel<unsigned long> { enum { level = __low__ }; }; 113 template <> struct ConverterLevel<long long> { enum { level = __low__ }; }; 114 template <> struct ConverterLevel<unsigned long long> { enum { level = __low__ }; }; 115 template <> struct ConverterLevel<float> { enum { level = __low__ }; }; 116 template <> struct ConverterLevel<double> { enum { level = __low__ }; }; 117 template <> struct ConverterLevel<long double> { enum { level = __low__ }; }; 118 template <> struct ConverterLevel<bool> { enum { level = __low__ }; }; 119 120 121 // Calculates the preference based on the levels of FromType and ToType 122 template <int from, int to> 123 struct ConverterPreference 124 { 125 enum 126 { 127 // The maximum of both levels: element of {0, 1, 2} 128 // max 0: Both types are primitives or have a similar behaviour 129 // max 1: At least one type is not a primitive, but both can be put on a std::stream 130 // max 2: There is at least one generic type that needs specialized conversions 131 max = (from > to) ? from : to, 132 133 // The difference between both levels limited to +-1: element of {-1, 0, 1} 134 // diff -1: The FromType has higher level than the ToType 135 // diff 0: Both types have the same level 136 // diff 1: The ToType has higher level than the FromType 137 diff = ((to - from) > 1) ? 1 : (((to - from) < -1) ? -1 : to - from) 138 }; 139 }; 140 141 142 // The default conversion: This usually does nothing 143 template <int max, class FromType, class ToType> 144 struct ConverterDefault 144 // If all else fails, try a dynamic_cast for pointer types. 145 template <class FromType, class ToType> 146 struct ConverterFallback<FromType*, ToType*> 147 { 148 static bool convert(ToType** output, FromType* const input) 149 { 150 ToType* temp = dynamic_cast<ToType*>(input); 151 if (temp) 152 { 153 *output = temp; 154 return true; 155 } 156 else 157 return false; 158 } 159 }; 160 161 162 /////////////////////// 163 // ConverterFallback // 164 /////////////////////// 165 166 // Default template for stringstream 167 template <class FromType, class ToType> 168 struct ConverterStringStream 145 169 { 146 170 static bool convert(ToType* output, const FromType& input) 147 171 { 148 COUT(2) << "Warning: Couldn't convert a value: From \"" << typeid(FromType).name() << "\" to \"" << typeid(ToType).name() << "\"" << std::endl; 149 return false; 150 } 151 }; 152 // The default conversion for primitives: A typecast (defined over two partial specialized templates to exclude all non-primitive types and classes) template <int max, class FromType, class ToType> 153 template <class FromType, class ToType> 154 struct ConverterDefault<0, FromType, ToType> 155 { 156 static bool convert(ToType* output, const FromType& input) 157 { 158 (*output) = (ToType)input; 159 return true; 160 } 161 }; 162 163 164 // Converter: Converts input of FromType into output of ToType 165 template <int diff, int max, class FromType, class ToType, ConversionPreference pref> 166 struct Converter 167 { 168 static bool convert(ToType* output, const FromType& input) 169 { 170 return false; 171 } 172 }; 173 // Converter: level{FromType} > level{ToType} 174 template <int max, class FromType, class ToType, ConversionPreference pref> 175 struct Converter<-1, max, FromType, ToType, pref> 176 { static bool convert(ToType* output, const FromType& input) 177 { return (ConverterSpecialized<FromType, ToType, _Explicit_>::specialized) ? (ConverterSpecialized<FromType, ToType, _Explicit_>::convert(output, input)) : (ConverterSpecialized<FromType, ToType, _FromType_>::specialized) ? (ConverterSpecialized<FromType, ToType, _FromType_>::convert(output, input)) : (ConverterDefault<max, FromType, ToType>::convert(output, input)); } }; 178 // Converter: level{FromType} < level{ToType} 179 template <int max, class FromType, class ToType, ConversionPreference pref> 180 struct Converter<1, max, FromType, ToType, pref> 181 { static bool convert(ToType* output, const FromType& input) 182 { return (ConverterSpecialized<FromType, ToType, _Explicit_>::specialized) ? (ConverterSpecialized<FromType, ToType, _Explicit_>::convert(output, input)) : (ConverterSpecialized<FromType, ToType, _ToType_>::specialized) ? (ConverterSpecialized<FromType, ToType, _ToType_>::convert(output, input)) : (ConverterDefault<max, FromType, ToType>::convert(output, input)); } }; 183 // Converter: level{FromType} = level{ToType} 184 // CP_PreferToType 185 template <int max, class FromType, class ToType> 186 struct Converter<0, max, FromType, ToType, CP_PreferToType> 187 { static bool convert(ToType* output, const FromType& input) 188 { return (ConverterSpecialized<FromType, ToType, _Explicit_>::specialized) ? (ConverterSpecialized<FromType, ToType, _Explicit_>::convert(output, input)) : (ConverterSpecialized<FromType, ToType, _ToType_>::specialized) ? (ConverterSpecialized<FromType, ToType, _ToType_>::convert(output, input)) : (ConverterSpecialized<FromType, ToType, _FromType_>::specialized) ? (ConverterSpecialized<FromType, ToType, _FromType_>::convert(output, input)) : (ConverterDefault<max, FromType, ToType>::convert(output, input)); } }; 189 // CP_PreferFromType 190 template <int max, class FromType, class ToType> 191 struct Converter<0, max, FromType, ToType, CP_PreferFromType> 192 { static bool convert(ToType* output, const FromType& input) 193 { return (ConverterSpecialized<FromType, ToType, _Explicit_>::specialized) ? (ConverterSpecialized<FromType, ToType, _Explicit_>::convert(output, input)) : (ConverterSpecialized<FromType, ToType, _FromType_>::specialized) ? (ConverterSpecialized<FromType, ToType, _FromType_>::convert(output, input)) : (ConverterSpecialized<FromType, ToType, _ToType_>::specialized) ? (ConverterSpecialized<FromType, ToType, _ToType_>::convert(output, input)) : (ConverterDefault<max, FromType, ToType>::convert(output, input)); } }; 194 195 196 // Calls the Converter::convertValue function with the correct template type parameters calculated by ConverterPreference 197 template <class FromType, class ToType> 198 static bool convertValue(ToType* output, const FromType& input, ConversionPreference preference = CP_PreferToType) 199 { 200 return (preference == CP_PreferToType) ? 201 Converter<ConverterPreference<ConverterLevel<FromType>::level, ConverterLevel<ToType>::level>::diff, 202 ConverterPreference<ConverterLevel<FromType>::level, ConverterLevel<ToType>::level>::max, 203 FromType, 204 ToType, 205 CP_PreferToType>::convert(output, input) 206 : Converter<ConverterPreference<ConverterLevel<FromType>::level, ConverterLevel<ToType>::level>::diff, 207 ConverterPreference<ConverterLevel<FromType>::level, ConverterLevel<ToType>::level>::max, 208 FromType, 209 ToType, 210 CP_PreferFromType>::convert(output, input); 211 } 212 213 214 ////////////////////// 215 // HELPER FUNCTIONS // 216 ////////////////////// 217 218 // Helper function: Calls convertValue with and without default value and returns true if the conversion was successful 219 template<class FromType, class ToType> 220 static bool ConvertValue(ToType* output, const FromType& input, ConversionPreference preference = CP_PreferToType) 221 { 222 return convertValue(output, input, preference); 223 } 224 template<class FromType, class ToType> 225 static bool ConvertValue(ToType* output, const FromType& input, const ToType& fallback, ConversionPreference preference = CP_PreferToType) 226 { 227 if (convertValue(output, input, preference)) 228 return true; 229 230 (*output) = fallback; 231 return false; 232 } 233 234 // Helper function: Calls convertValue with and without default value and returns the converted value 235 template<class FromType, class ToType> 236 static ToType getConvertedValue(const FromType& input, ConversionPreference preference = CP_PreferToType) 237 { 238 ToType output = ToType(); 239 ConvertValue(&output, input, preference); 240 return output; 241 } 242 template<class FromType, class ToType> 243 static ToType getConvertedValue(const FromType& input, const ToType& fallback, ConversionPreference preference = CP_PreferToType) 244 { 245 ToType output = fallback; 246 ConvertValue(&output, input, fallback, preference); 247 return output; 248 } 249 250 251 ///////////////////// 252 // SPECIALIZATIONS // 253 ///////////////////// 172 return ConverterFallback<FromType, ToType>::convert(output, input); 173 } 174 }; 175 254 176 255 177 ///////////// 256 // SAMPLES//178 // OStream // 257 179 ///////////// 258 /* 259 // convert everything to xyz 180 181 namespace fallbackTemplates 182 { 183 template <class FromType> 184 inline bool operator <<(std::ostream& outstream, const FromType& input) 185 { 186 std::string temp; 187 if (ConverterFallback<FromType, std::string>::convert(&temp, input)) 188 { 189 std::operator <<(outstream, temp); 190 return true; 191 } 192 else 193 return false; 194 } 195 } 196 197 // template that evaluates whether we can convert to std::string via ostringstream 260 198 template <class FromType> 261 struct ConverterSpecialized<FromType, xyz, _ToType_> 262 { 263 enum { specialized = true }; 264 static bool convert(xyz* output, const FromType& input) 265 { return ...; } 266 }; 267 268 // convert xyz to everything 269 template <class ToType> 270 struct ConverterSpecialized<xyz, ToType, _FromType_> 271 { 272 enum { specialized = true }; 273 static bool convert(ToType* output, const xyz& input) 274 { return ...; } 275 }; 276 277 // convert abc to xyz 278 template <> 279 struct ConverterSpecialized<abc, xyz, _Explicit_> 280 { 281 enum { specialized = true }; 282 static bool convert(xyz* output, const abc& input) 283 { return ...; } 284 }; 285 */ 286 287 //////////// 288 // STRING // 289 //////////// 290 291 // convert to string 292 template <class FromType> 293 struct ConverterSpecialized<FromType, std::string, _ToType_> 294 { 295 enum { specialized = true }; 199 struct ConverterStringStream<FromType, std::string> 200 { 296 201 static bool convert(std::string* output, const FromType& input) 297 202 { 203 using namespace fallbackTemplates; 204 // this operator call only chooses fallbackTemplates::operator<< if there's no other fitting function 298 205 std::ostringstream oss; 299 206 if (oss << input) … … 307 214 }; 308 215 216 217 ///////////// 218 // IStream // 219 ///////////// 220 221 namespace fallbackTemplates 222 { 223 template <class ToType> 224 inline bool operator >>(std::istream& instream, ToType& output) 225 { 226 return ConverterFallback<std::string, ToType> 227 ::convert(&output, static_cast<std::istringstream&>(instream).str()); 228 } 229 } 230 231 // template that evaluates whether we can convert from std::string via ostringstream 232 template <class ToType> 233 struct ConverterStringStream<std::string, ToType> 234 { 235 static bool convert(ToType* output, const std::string& input) 236 { 237 using namespace fallbackTemplates; 238 std::istringstream iss(input); 239 // this operator call only chooses fallbackTemplates::operator>> if there's no other fitting function 240 if (iss >> (*output)) 241 { 242 return true; 243 } 244 else 245 return false; 246 } 247 }; 248 249 250 /////////////////// 251 // Implicit Cast // 252 /////////////////// 253 254 // implicit cast not possible, try stringstream conversion next 255 template <class FromType, class ToType> 256 inline bool convertImplicitely(ToType* output, const FromType& input, ::Int2Type<false>) 257 { 258 return ConverterStringStream<FromType, ToType>::convert(output, input); 259 } 260 261 // We can cast implicitely 262 template <class FromType, class ToType> 263 inline bool convertImplicitely(ToType* output, const FromType& input, ::Int2Type<true>) 264 { 265 (*output) = static_cast<ToType>(input); 266 return true; 267 } 268 269 270 //////////////////////////////// 271 // ConverterExplicit Fallback // 272 //////////////////////////////// 273 274 // Default template if no specialisation is available 275 template <class FromType, class ToType> 276 struct ConverterExplicit 277 { 278 static bool convert(ToType* output, const FromType& input) 279 { 280 // Try implict cast and probe first. If a simple cast is not possible, it will not compile 281 // We therefore have to out source it into another template function 282 const bool probe = ImplicitConversion<FromType, ToType>::exists; 283 return convertImplicitely(output, input, ::Int2Type<probe>()); 284 } 285 }; 286 287 288 ////////////////////// 289 // Public Functions // 290 ////////////////////// 291 292 /** 293 @brief 294 Converts any value to any other as long as there exists a conversion. 295 Otherwise, the conversion will generate a runtime warning and return false. 296 For information about the different conversion methods (user defined too), see the section 297 'Actual conversion sequence' in this file above. 298 */ 299 template <class FromType, class ToType> 300 inline bool convertValue(ToType* output, const FromType& input) 301 { 302 return ConverterExplicit<FromType, ToType>::convert(output, input); 303 } 304 305 // For compatibility reasons. The same, but with capital ConvertValue 306 template<class FromType, class ToType> 307 inline bool ConvertValue(ToType* output, const FromType& input) 308 { 309 return convertValue(output, input); 310 } 311 312 // Calls convertValue and returns true if the conversion was successful. 313 // Otherwise the fallback is used. 314 /** 315 @brief 316 Converts any value to any other as long as there exists a conversion. 317 Otherwise, the conversion will generate a runtime warning and return false. 318 For information about the different conversion methods (user defined too), see the section 319 'Actual conversion sequence' in this file above. 320 If the conversion doesn't succeed, 'fallback' is written to '*output'. 321 @param fallback 322 A default value that gets written to '*output' if there is no conversion. 323 */ 324 template<class FromType, class ToType> 325 inline bool convertValue(ToType* output, const FromType& input, const ToType& fallback) 326 { 327 if (convertValue(output, input)) 328 return true; 329 else 330 { 331 (*output) = fallback; 332 return false; 333 } 334 } 335 336 // for compatibility reason. (capital 'c' in ConvertValue) 337 template<class FromType, class ToType> 338 inline bool ConvertValue(ToType* output, const FromType& input, const ToType& fallback) 339 { 340 return convertValue(output, input, fallback); 341 } 342 343 // Directly returns the converted value, even if the conversion was not successful. 344 template<class FromType, class ToType> 345 inline ToType getConvertedValue(const FromType& input) 346 { 347 ToType output; 348 convertValue(&output, input); 349 return output; 350 } 351 352 // Directly returns the converted value, but uses the fallback on failure. 353 template<class FromType, class ToType> 354 inline ToType getConvertedValue(const FromType& input, const ToType& fallback) 355 { 356 ToType output; 357 convertValue(&output, input, fallback); 358 return output; 359 } 360 361 // Like getConvertedValue, but the template argument order is in reverse. 362 // That means you can call it exactly like static_cast<ToType>(fromTypeValue). 363 template<class ToType, class FromType> 364 inline ToType omni_cast(const FromType& input) 365 { 366 ToType output; 367 convertValue(&output, input); 368 return output; 369 } 370 309 371 // convert to string Shortcut 310 372 template <class FromType> 311 std::string convertToString(FromType value)373 inline std::string convertToString(FromType value) 312 374 { 313 375 return getConvertedValue<FromType, std::string>(value); 314 376 } 315 377 316 // convert from string 378 // convert from string Shortcut 317 379 template <class ToType> 318 struct ConverterSpecialized<std::string, ToType, _FromType_> 319 { 320 enum { specialized = true }; 321 static bool convert(ToType* output, const std::string& input) 322 { 380 inline ToType convertFromString(std::string str) 381 { 382 return getConvertedValue<std::string, ToType>(str); 383 } 384 385 //////////////////////////////// 386 // Special string conversions // 387 //////////////////////////////// 388 389 // Delegate conversion from const char* to std::string 390 template <class ToType> 391 struct ConverterExplicit<const char*, ToType> 392 { 393 static bool convert(ToType* output, const char* input) 394 { 395 return convertValue<std::string, ToType>(output, input); 396 } 397 }; 398 399 // These conversions would exhibit ambiguous << or >> operators when using stringstream 400 template <> 401 struct ConverterExplicit<char, std::string> 402 { 403 static bool convert(std::string* output, const char input) 404 { 405 *output = std::string(1, input); 406 return true; 407 } 408 }; 409 template <> 410 struct ConverterExplicit<unsigned char, std::string> 411 { 412 static bool convert(std::string* output, const unsigned char input) 413 { 414 *output = std::string(1, input); 415 return true; 416 } 417 }; 418 template <> 419 struct ConverterExplicit<std::string, char> 420 { 421 static bool convert(char* output, const std::string input) 422 { 423 if (input != "") 424 *output = input[0]; 425 else 426 *output = '\0'; 427 return true; 428 } 429 }; 430 template <> 431 struct ConverterExplicit<std::string, unsigned char> 432 { 433 static bool convert(unsigned char* output, const std::string input) 434 { 435 if (input != "") 436 *output = input[0]; 437 else 438 *output = '\0'; 439 return true; 440 } 441 }; 442 443 444 // bool to std::string 445 template <> 446 struct ConverterExplicit<bool, std::string> 447 { 448 static bool convert(std::string* output, const bool& input) 449 { 450 if (input) 451 *output = "true"; 452 else 453 *output = "false"; 454 return false; 455 } 456 }; 457 458 // std::string to bool 459 template <> 460 struct ConverterExplicit<std::string, bool> 461 { 462 static bool convert(bool* output, const std::string& input) 463 { 464 std::string stripped = getLowercase(removeTrailingWhitespaces(input)); 465 if (stripped == "true" || stripped == "on" || stripped == "yes") 466 { 467 *output = true; 468 return true; 469 } 470 else if (stripped == "false" || stripped == "off" || stripped == "no") 471 { 472 *output = false; 473 return true; 474 } 475 323 476 std::istringstream iss(input); 324 477 if (iss >> (*output)) … … 329 482 }; 330 483 331 // convert from string Shortcut332 template <class ToType>333 ToType convertFromString(std::string str)334 {335 return getConvertedValue<std::string, ToType>(str);336 }337 338 339 //////////340 // MATH //341 //////////342 // convert everything to Degree343 template <class FromType>344 struct ConverterSpecialized<FromType, Ogre::Degree, _ToType_>345 {346 enum { specialized = true };347 static bool convert(Ogre::Degree* output, const FromType& input)348 {349 float angle = 0;350 bool success = ConvertValue<FromType, float>(&angle, input);351 (*output) = angle;352 return success;353 }354 };355 356 // convert everything to Radian357 template <class FromType>358 struct ConverterSpecialized<FromType, Ogre::Radian, _ToType_>359 {360 enum { specialized = true };361 static bool convert(Ogre::Radian* output, const FromType& input)362 {363 float angle = 0;364 bool success = ConvertValue<FromType, float>(&angle, input);365 (*output) = angle;366 return success;367 }368 };369 370 371 ////////////////////372 // MATH TO STRING //373 ////////////////////374 375 // bool to std::string376 template <>377 struct ConverterSpecialized<bool, std::string, _Explicit_>378 {379 enum { specialized = true };380 static bool convert(std::string* output, const bool& input)381 {382 if (input)383 *output = "true";384 else385 *output = "false";386 return false;387 }388 };389 390 // Vector2 to std::string391 template <>392 struct ConverterSpecialized<orxonox::Vector2, std::string, _Explicit_>393 {394 enum { specialized = true };395 static bool convert(std::string* output, const orxonox::Vector2& input)396 {397 std::ostringstream ostream;398 if (ostream << input.x << "," << input.y)399 {400 (*output) = ostream.str();401 return true;402 }403 return false;404 }405 };406 407 // Vector3 to std::string408 template <>409 struct ConverterSpecialized<orxonox::Vector3, std::string, _Explicit_>410 {411 enum { specialized = true };412 static bool convert(std::string* output, const orxonox::Vector3& input)413 {414 std::ostringstream ostream;415 if (ostream << input.x << "," << input.y << "," << input.z)416 {417 (*output) = ostream.str();418 return true;419 }420 return false;421 }422 };423 424 // Vector4 to std::string425 template <>426 struct ConverterSpecialized<orxonox::Vector4, std::string, _Explicit_>427 {428 enum { specialized = true };429 static bool convert(std::string* output, const orxonox::Vector4& input)430 {431 std::ostringstream ostream;432 if (ostream << input.x << "," << input.y << "," << input.z << "," << input.w)433 {434 (*output) = ostream.str();435 return true;436 }437 return false;438 }439 };440 441 // Quaternion to std::string442 template <>443 struct ConverterSpecialized<orxonox::Quaternion, std::string, _Explicit_>444 {445 enum { specialized = true };446 static bool convert(std::string* output, const orxonox::Quaternion& input)447 {448 std::ostringstream ostream;449 if (ostream << input.w << "," << input.x << "," << input.y << "," << input.z)450 {451 (*output) = ostream.str();452 return true;453 }454 return false;455 }456 };457 458 // ColourValue to std::string459 template <>460 struct ConverterSpecialized<orxonox::ColourValue, std::string, _Explicit_>461 {462 enum { specialized = true };463 static bool convert(std::string* output, const orxonox::ColourValue& input)464 {465 std::ostringstream ostream;466 if (ostream << input.r << "," << input.g << "," << input.b << "," << input.a)467 {468 (*output) = ostream.str();469 return true;470 }471 return false;472 }473 };474 475 476 ////////////////////477 // STRING TO MATH //478 ////////////////////479 480 // std::string to bool481 template <>482 struct ConverterSpecialized<std::string, bool, _Explicit_>483 {484 enum { specialized = true };485 static bool convert(bool* output, const std::string& input)486 {487 std::string stripped = getLowercase(removeTrailingWhitespaces(input));488 if (stripped == "true" || stripped == "on" || stripped == "yes")489 {490 *output = true;491 return true;492 }493 else if (stripped == "false" || stripped == "off" || stripped == "no")494 {495 *output = false;496 return true;497 }498 499 std::istringstream iss(input);500 if (iss >> (*output))501 return true;502 else503 return false;504 }505 };506 507 // std::string to Vector2508 template <>509 struct ConverterSpecialized<std::string, orxonox::Vector2, _Explicit_>510 {511 enum { specialized = true };512 static bool convert(orxonox::Vector2* output, const std::string& input)513 {514 size_t opening_parenthesis, closing_parenthesis = input.find(')');515 if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; }516 517 SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0');518 if (tokens.size() >= 2)519 {520 if (!ConvertValue(&(output->x), tokens[0]))521 return false;522 if (!ConvertValue(&(output->y), tokens[1]))523 return false;524 525 return true;526 }527 return false;528 }529 };530 531 // std::string to Vector3532 template <>533 struct ConverterSpecialized<std::string, orxonox::Vector3, _Explicit_>534 {535 enum { specialized = true };536 static bool convert(orxonox::Vector3* output, const std::string& input)537 {538 size_t opening_parenthesis, closing_parenthesis = input.find(')');539 if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; }540 541 SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0');542 if (tokens.size() >= 3)543 {544 if (!ConvertValue(&(output->x), tokens[0]))545 return false;546 if (!ConvertValue(&(output->y), tokens[1]))547 return false;548 if (!ConvertValue(&(output->z), tokens[2]))549 return false;550 551 return true;552 }553 return false;554 }555 };556 557 // std::string to Vector4558 template <>559 struct ConverterSpecialized<std::string, orxonox::Vector4, _Explicit_>560 {561 enum { specialized = true };562 static bool convert(orxonox::Vector4* output, const std::string& input)563 {564 size_t opening_parenthesis, closing_parenthesis = input.find(')');565 if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; }566 567 SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0');568 if (tokens.size() >= 4)569 {570 if (!ConvertValue(&(output->x), tokens[0]))571 return false;572 if (!ConvertValue(&(output->y), tokens[1]))573 return false;574 if (!ConvertValue(&(output->z), tokens[2]))575 return false;576 if (!ConvertValue(&(output->w), tokens[3]))577 return false;578 579 return true;580 }581 return false;582 }583 };584 585 // std::string to Quaternion586 template <>587 struct ConverterSpecialized<std::string, orxonox::Quaternion, _Explicit_>588 {589 enum { specialized = true };590 static bool convert(orxonox::Quaternion* output, const std::string& input)591 {592 size_t opening_parenthesis, closing_parenthesis = input.find(')');593 if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; }594 595 SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0');596 if (tokens.size() >= 4)597 {598 if (!ConvertValue(&(output->w), tokens[0]))599 return false;600 if (!ConvertValue(&(output->x), tokens[1]))601 return false;602 if (!ConvertValue(&(output->y), tokens[2]))603 return false;604 if (!ConvertValue(&(output->z), tokens[3]))605 return false;606 607 return true;608 }609 return false;610 }611 };612 613 // std::string to ColourValue614 template <>615 struct ConverterSpecialized<std::string, orxonox::ColourValue, _Explicit_>616 {617 enum { specialized = true };618 static bool convert(orxonox::ColourValue* output, const std::string& input)619 {620 size_t opening_parenthesis, closing_parenthesis = input.find(')');621 if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; }622 623 SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0');624 if (tokens.size() >= 3)625 {626 if (!ConvertValue(&(output->r), tokens[0]))627 return false;628 if (!ConvertValue(&(output->g), tokens[1]))629 return false;630 if (!ConvertValue(&(output->b), tokens[2]))631 return false;632 if (tokens.size() >= 4)633 {634 if (!ConvertValue(&(output->a), tokens[3]))635 return false;636 }637 else638 output->a = 1.0;639 640 return true;641 }642 return false;643 }644 };645 646 647 ///////////////////////////648 // Static type detection //649 ///////////////////////////650 651 /**652 Template class that determines whether type T converts implicitly to type U.653 @note654 This allows to detect type conversion at compile time.655 From 'Modern C++ Design' (Alexandrescu 2001).656 */657 template <class T, class U>658 class StaticConversion659 {660 class Small { char dummy[1]; };661 class Big { char dummy[1024]; };662 static Small Test(U);663 static Big Test(...);664 static T MakeT();665 public:666 enum { exists = sizeof(Test(MakeT())) == sizeof(Small) };667 };668 669 #if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC670 #pragma warning(pop)671 #endif672 673 484 #endif /* _Convert_H__ */ -
code/trunk/src/util/Debug.h
r1791 r2087 77 77 } 78 78 79 namespace orxonox 80 { 81 using std::endl; 82 } 79 83 80 84 // DEFINE ERROR MODES -
code/trunk/src/util/Exception.cc
- Property svn:mergeinfo changed (with no actual effect on merging)
-
code/trunk/src/util/Exception.h
- Property svn:mergeinfo changed (with no actual effect on merging)
-
code/trunk/src/util/Math.cc
r1791 r2087 28 28 29 29 /** 30 @file Math.cc30 @file 31 31 @brief Implementation of several math-functions. 32 32 */ 33 33 34 #include "Math.h" 35 34 36 #include <OgrePlane.h> 35 36 #include "Math.h" 37 #include "Convert.h" 37 #include "MathConvert.h" 38 #include "SubString.h" 38 39 39 40 /** … … 201 202 } 202 203 203 std::string getUniqueNumberStr() 204 { 205 return convertToString(getUniqueNumber()); 206 } 204 205 ////////////////////////// 206 // Conversion functions // 207 ////////////////////////// 208 209 // std::string to Vector2 210 bool ConverterFallback<std::string, orxonox::Vector2>::convert(orxonox::Vector2* output, const std::string& input) 211 { 212 size_t opening_parenthesis, closing_parenthesis = input.find(')'); 213 if ((opening_parenthesis = input.find('(')) == std::string::npos) 214 opening_parenthesis = 0; 215 else 216 opening_parenthesis++; 217 218 SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), 219 ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0'); 220 if (tokens.size() >= 2) 221 { 222 if (!ConvertValue(&(output->x), tokens[0])) 223 return false; 224 if (!ConvertValue(&(output->y), tokens[1])) 225 return false; 226 227 return true; 228 } 229 return false; 230 } 231 232 // std::string to Vector3 233 bool ConverterFallback<std::string, orxonox::Vector3>::convert(orxonox::Vector3* output, const std::string& input) 234 { 235 size_t opening_parenthesis, closing_parenthesis = input.find(')'); 236 if ((opening_parenthesis = input.find('(')) == std::string::npos) 237 opening_parenthesis = 0; 238 else 239 opening_parenthesis++; 240 241 SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), 242 ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0'); 243 if (tokens.size() >= 3) 244 { 245 if (!ConvertValue(&(output->x), tokens[0])) 246 return false; 247 if (!ConvertValue(&(output->y), tokens[1])) 248 return false; 249 if (!ConvertValue(&(output->z), tokens[2])) 250 return false; 251 252 return true; 253 } 254 return false; 255 } 256 257 // std::string to Vector4 258 bool ConverterFallback<std::string, orxonox::Vector4>::convert(orxonox::Vector4* output, const std::string& input) 259 { 260 size_t opening_parenthesis, closing_parenthesis = input.find(')'); 261 if ((opening_parenthesis = input.find('(')) == std::string::npos) 262 opening_parenthesis = 0; 263 else 264 opening_parenthesis++; 265 266 SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), 267 ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0'); 268 if (tokens.size() >= 4) 269 { 270 if (!ConvertValue(&(output->x), tokens[0])) 271 return false; 272 if (!ConvertValue(&(output->y), tokens[1])) 273 return false; 274 if (!ConvertValue(&(output->z), tokens[2])) 275 return false; 276 if (!ConvertValue(&(output->w), tokens[3])) 277 return false; 278 279 return true; 280 } 281 return false; 282 } 283 284 // std::string to Quaternion 285 bool ConverterFallback<std::string, orxonox::Quaternion>::convert(orxonox::Quaternion* output, const std::string& input) 286 { 287 size_t opening_parenthesis, closing_parenthesis = input.find(')'); 288 if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; } 289 290 SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0'); 291 if (tokens.size() >= 4) 292 { 293 if (!ConvertValue(&(output->w), tokens[0])) 294 return false; 295 if (!ConvertValue(&(output->x), tokens[1])) 296 return false; 297 if (!ConvertValue(&(output->y), tokens[2])) 298 return false; 299 if (!ConvertValue(&(output->z), tokens[3])) 300 return false; 301 302 return true; 303 } 304 return false; 305 } 306 307 // std::string to ColourValue 308 bool ConverterFallback<std::string, orxonox::ColourValue>::convert(orxonox::ColourValue* output, const std::string& input) 309 { 310 size_t opening_parenthesis, closing_parenthesis = input.find(')'); 311 if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; } 312 313 SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0'); 314 if (tokens.size() >= 3) 315 { 316 if (!ConvertValue(&(output->r), tokens[0])) 317 return false; 318 if (!ConvertValue(&(output->g), tokens[1])) 319 return false; 320 if (!ConvertValue(&(output->b), tokens[2])) 321 return false; 322 if (tokens.size() >= 4) 323 { 324 if (!ConvertValue(&(output->a), tokens[3])) 325 return false; 326 } 327 else 328 output->a = 1.0; 329 330 return true; 331 } 332 return false; 333 } -
code/trunk/src/util/Math.h
r1840 r2087 39 39 #include <ostream> 40 40 #include <string> 41 #include <boost/static_assert.hpp> 41 42 42 43 #include <OgreMath.h> … … 189 190 } 190 191 192 template <typename T> 193 inline T zeroise() 194 { 195 BOOST_STATIC_ASSERT(sizeof(T) == 0); 196 return T(); 197 } 198 199 template <> inline char zeroise<char>() { return 0; } 200 template <> inline unsigned char zeroise<unsigned char>() { return 0; } 201 template <> inline short zeroise<short>() { return 0; } 202 template <> inline unsigned short zeroise<unsigned short>() { return 0; } 203 template <> inline int zeroise<int>() { return 0; } 204 template <> inline unsigned int zeroise<unsigned int>() { return 0; } 205 template <> inline long zeroise<long>() { return 0; } 206 template <> inline unsigned long zeroise<unsigned long>() { return 0; } 207 template <> inline long long zeroise<long long>() { return 0; } 208 template <> inline unsigned long long zeroise<unsigned long long>() { return 0; } 209 template <> inline float zeroise<float>() { return 0; } 210 template <> inline double zeroise<double>() { return 0; } 211 template <> inline long double zeroise<long double>() { return 0; } 212 template <> inline bool zeroise<bool>() { return 0; } 213 template <> inline void* zeroise<void*>() { return 0; } 214 template <> inline std::string zeroise<std::string>() { return ""; } 215 template <> inline orxonox::Radian zeroise<orxonox::Radian>() { return orxonox::Radian(0.0f); } 216 template <> inline orxonox::Degree zeroise<orxonox::Degree>() { return orxonox::Degree(0.0f); } 217 template <> inline orxonox::Vector2 zeroise<orxonox::Vector2>() { return orxonox::Vector2 (0, 0) ; } 218 template <> inline orxonox::Vector3 zeroise<orxonox::Vector3>() { return orxonox::Vector3 (0, 0, 0) ; } 219 template <> inline orxonox::Vector4 zeroise<orxonox::Vector4>() { return orxonox::Vector4 (0, 0, 0, 0); } 220 template <> inline orxonox::ColourValue zeroise<orxonox::ColourValue>() { return orxonox::ColourValue(0, 0, 0, 0); } 221 template <> inline orxonox::Quaternion zeroise<orxonox::Quaternion>() { return orxonox::Quaternion (0, 0, 0, 0); } 222 191 223 /** 192 224 @brief Interpolates between two values for a time between 0 and 1. … … 243 275 244 276 _UtilExport unsigned long getUniqueNumber(); 245 _UtilExport std::string getUniqueNumberStr();246 277 247 278 class _UtilExport IntVector2 -
code/trunk/src/util/MultiType.cc
r1791 r2087 39 39 @param type The type 40 40 */ 41 voidMultiType::convert(MT_Type type)41 bool MultiType::convert(MT_Type type) 42 42 { 43 43 switch (type) 44 44 { 45 45 case MT_char: 46 this->convert<char>(); break;46 return this->convert<char>(); break; 47 47 case MT_uchar: 48 this->convert<unsigned char>(); break;48 return this->convert<unsigned char>(); break; 49 49 case MT_short: 50 this->convert<short>(); break;50 return this->convert<short>(); break; 51 51 case MT_ushort: 52 this->convert<unsigned short>(); break;52 return this->convert<unsigned short>(); break; 53 53 case MT_int: 54 this->convert<int>(); break;54 return this->convert<int>(); break; 55 55 case MT_uint: 56 this->convert<unsigned int>(); break;56 return this->convert<unsigned int>(); break; 57 57 case MT_long: 58 this->convert<long>(); break;58 return this->convert<long>(); break; 59 59 case MT_ulong: 60 this->convert<unsigned long>(); break;60 return this->convert<unsigned long>(); break; 61 61 case MT_longlong: 62 this->convert<long long>(); break;62 return this->convert<long long>(); break; 63 63 case MT_ulonglong: 64 this->convert<unsigned long long>(); break;64 return this->convert<unsigned long long>(); break; 65 65 case MT_float: 66 this->convert<float>(); break;66 return this->convert<float>(); break; 67 67 case MT_double: 68 this->convert<double>(); break;68 return this->convert<double>(); break; 69 69 case MT_longdouble: 70 this->convert<long double>(); break;70 return this->convert<long double>(); break; 71 71 case MT_bool: 72 this->convert<bool>(); break;72 return this->convert<bool>(); break; 73 73 case MT_void: 74 this->convert<void*>(); break;74 return this->convert<void*>(); break; 75 75 case MT_string: 76 this->convert<std::string>(); break;76 return this->convert<std::string>(); break; 77 77 case MT_vector2: 78 this->convert<orxonox::Vector2>(); break;78 return this->convert<orxonox::Vector2>(); break; 79 79 case MT_vector3: 80 this->convert<orxonox::Vector3>(); break;80 return this->convert<orxonox::Vector3>(); break; 81 81 case MT_vector4: 82 this->convert<orxonox::Vector4>(); break;82 return this->convert<orxonox::Vector4>(); break; 83 83 case MT_colourvalue: 84 this->convert<orxonox::ColourValue>(); break;84 return this->convert<orxonox::ColourValue>(); break; 85 85 case MT_quaternion: 86 this->convert<orxonox::Quaternion>(); break;86 return this->convert<orxonox::Quaternion>(); break; 87 87 case MT_radian: 88 this->convert<orxonox::Radian>(); break;88 return this->convert<orxonox::Radian>(); break; 89 89 case MT_degree: 90 this->convert<orxonox::Degree>(); break;90 return this->convert<orxonox::Degree>(); break; 91 91 default: 92 this->reset(); break;92 this->reset(); return false; break; 93 93 }; 94 94 } … … 168 168 MultiType::operator double() const { return (this->value_) ? ((this->value_->type_ == MT_double ) ? ((MT_Value<double> *)this->value_)->value_ : (*this->value_)) : 0; } /** @brief Returns the current value, converted to the requested type. */ 169 169 MultiType::operator long double() const { return (this->value_) ? ((this->value_->type_ == MT_longdouble ) ? ((MT_Value<long double> *)this->value_)->value_ : (*this->value_)) : 0; } /** @brief Returns the current value, converted to the requested type. */ 170 MultiType::operator bool() const { return (this->value_) ? ((this->value_->type_ == MT_bool ) ? ((MT_Value<bool> *)this->value_)->value_ : (*this->value_)) : false;} /** @brief Returns the current value, converted to the requested type. */171 MultiType::operator void*() const { return (this->value_) ? ((this->value_->type_ == MT_void ) ? ((MT_Value<void*> *)this->value_)->value_ : (*this->value_)) : (void*)0;} /** @brief Returns the current value, converted to the requested type. */172 MultiType::operator std::string() const { return (this->value_) ? ((this->value_->type_ == MT_string ) ? ((MT_Value<std::string> *)this->value_)->value_ : (*this->value_)) : std::string(); } /** @brief Returns the current value, converted to the requested type. */173 MultiType::operator orxonox::Vector2() const { return (this->value_) ? ((this->value_->type_ == MT_vector2 ) ? ((MT_Value<orxonox::Vector2> *)this->value_)->value_ : (*this->value_)) : orxonox::Vector2(); } /** @brief Returns the current value, converted to the requested type. */174 MultiType::operator orxonox::Vector3() const { return (this->value_) ? ((this->value_->type_ == MT_vector3 ) ? ((MT_Value<orxonox::Vector3> *)this->value_)->value_ : (*this->value_)) : orxonox::Vector3(); } /** @brief Returns the current value, converted to the requested type. */175 MultiType::operator orxonox::Vector4() const { return (this->value_) ? ((this->value_->type_ == MT_vector4 ) ? ((MT_Value<orxonox::Vector4> *)this->value_)->value_ : (*this->value_)) : orxonox::Vector4(); } /** @brief Returns the current value, converted to the requested type. */176 MultiType::operator orxonox::ColourValue() const { return (this->value_) ? ((this->value_->type_ == MT_colourvalue) ? ((MT_Value<orxonox::ColourValue>*)this->value_)->value_ : (*this->value_)) : orxonox::ColourValue(); } /** @brief Returns the current value, converted to the requested type. */177 MultiType::operator orxonox::Quaternion() const { return (this->value_) ? ((this->value_->type_ == MT_quaternion ) ? ((MT_Value<orxonox::Quaternion> *)this->value_)->value_ : (*this->value_)) : orxonox::Quaternion(); } /** @brief Returns the current value, converted to the requested type. */178 MultiType::operator orxonox::Radian() const { return (this->value_) ? ((this->value_->type_ == MT_radian ) ? ((MT_Value<orxonox::Radian> *)this->value_)->value_ : (*this->value_)) : orxonox::Radian(); } /** @brief Returns the current value, converted to the requested type. */179 MultiType::operator orxonox::Degree() const { return (this->value_) ? ((this->value_->type_ == MT_degree ) ? ((MT_Value<orxonox::Degree> *)this->value_)->value_ : (*this->value_)) : orxonox::Degree(); } /** @brief Returns the current value, converted to the requested type. */170 MultiType::operator bool() const { return (this->value_) ? ((this->value_->type_ == MT_bool ) ? ((MT_Value<bool> *)this->value_)->value_ : (*this->value_)) : 0; } /** @brief Returns the current value, converted to the requested type. */ 171 MultiType::operator void*() const { return (this->value_) ? ((this->value_->type_ == MT_void ) ? ((MT_Value<void*> *)this->value_)->value_ : (*this->value_)) : 0; } /** @brief Returns the current value, converted to the requested type. */ 172 MultiType::operator std::string() const { return (this->value_) ? ((this->value_->type_ == MT_string ) ? ((MT_Value<std::string> *)this->value_)->value_ : (*this->value_)) : zeroise<std::string>(); } /** @brief Returns the current value, converted to the requested type. */ 173 MultiType::operator orxonox::Vector2() const { return (this->value_) ? ((this->value_->type_ == MT_vector2 ) ? ((MT_Value<orxonox::Vector2> *)this->value_)->value_ : (*this->value_)) : zeroise<orxonox::Vector2>(); } /** @brief Returns the current value, converted to the requested type. */ 174 MultiType::operator orxonox::Vector3() const { return (this->value_) ? ((this->value_->type_ == MT_vector3 ) ? ((MT_Value<orxonox::Vector3> *)this->value_)->value_ : (*this->value_)) : zeroise<orxonox::Vector3>(); } /** @brief Returns the current value, converted to the requested type. */ 175 MultiType::operator orxonox::Vector4() const { return (this->value_) ? ((this->value_->type_ == MT_vector4 ) ? ((MT_Value<orxonox::Vector4> *)this->value_)->value_ : (*this->value_)) : zeroise<orxonox::Vector4>(); } /** @brief Returns the current value, converted to the requested type. */ 176 MultiType::operator orxonox::ColourValue() const { return (this->value_) ? ((this->value_->type_ == MT_colourvalue) ? ((MT_Value<orxonox::ColourValue>*)this->value_)->value_ : (*this->value_)) : zeroise<orxonox::ColourValue>(); } /** @brief Returns the current value, converted to the requested type. */ 177 MultiType::operator orxonox::Quaternion() const { return (this->value_) ? ((this->value_->type_ == MT_quaternion ) ? ((MT_Value<orxonox::Quaternion> *)this->value_)->value_ : (*this->value_)) : zeroise<orxonox::Quaternion>(); } /** @brief Returns the current value, converted to the requested type. */ 178 MultiType::operator orxonox::Radian() const { return (this->value_) ? ((this->value_->type_ == MT_radian ) ? ((MT_Value<orxonox::Radian> *)this->value_)->value_ : (*this->value_)) : zeroise<orxonox::Radian>(); } /** @brief Returns the current value, converted to the requested type. */ 179 MultiType::operator orxonox::Degree() const { return (this->value_) ? ((this->value_->type_ == MT_degree ) ? ((MT_Value<orxonox::Degree> *)this->value_)->value_ : (*this->value_)) : zeroise<orxonox::Degree>(); } /** @brief Returns the current value, converted to the requested type. */ 180 180 181 181 template <> void MultiType::createNewValueContainer(const char& value) { this->value_ = new MT_Value<char> (value, MT_char ); } /** @brief Creates a new value container for the given type. */ -
code/trunk/src/util/MultiType.h
r1854 r2087 58 58 a.convert<bool>(); // converts 3.14 to bool, which is true 59 59 a = false; // assigns false, this is equivalent to a.setValue(false) 60 61 @note 62 Whenever a value gets converted, there is a boolean return value telling you whether it was 63 successful or not. If it wasn't a zero value is assigned with the help of zeroise<T>(). 60 64 */ 61 65 … … 128 132 struct _UtilExport MT_ValueBase 129 133 { 130 MT_ValueBase(MT_Type type) : type_(type) {}134 MT_ValueBase(MT_Type type) : type_(type), bHasDefaultValue_(false) {} 131 135 virtual ~MT_ValueBase() {} 132 136 … … 134 138 135 139 virtual void reset() = 0; 136 virtual voidassimilate(const MultiType& other) = 0;140 virtual bool assimilate(const MultiType& other) = 0; 137 141 138 142 /** @brief Returns the type of the current value. */ 139 143 const MT_Type& getType() const { return this->type_; } 140 144 141 virtual void setValue(const char& value) = 0; 142 virtual void setValue(const unsigned char& value) = 0; 143 virtual void setValue(const short& value) = 0; 144 virtual void setValue(const unsigned short& value) = 0; 145 virtual void setValue(const int& value) = 0; 146 virtual void setValue(const unsigned int& value) = 0; 147 virtual void setValue(const long& value) = 0; 148 virtual void setValue(const unsigned long& value) = 0; 149 virtual void setValue(const long long& value) = 0; 150 virtual void setValue(const unsigned long long& value) = 0; 151 virtual void setValue(const float& value) = 0; 152 virtual void setValue(const double& value) = 0; 153 virtual void setValue(const long double& value) = 0; 154 virtual void setValue(const bool& value) = 0; 155 virtual void setValue( void* const& value) = 0; 156 virtual void setValue(const std::string& value) = 0; 157 virtual void setValue(const orxonox::Vector2& value) = 0; 158 virtual void setValue(const orxonox::Vector3& value) = 0; 159 virtual void setValue(const orxonox::Vector4& value) = 0; 160 virtual void setValue(const orxonox::ColourValue& value) = 0; 161 virtual void setValue(const orxonox::Quaternion& value) = 0; 162 virtual void setValue(const orxonox::Radian& value) = 0; 163 virtual void setValue(const orxonox::Degree& value) = 0; 145 /** @brief Checks whether the value is a default one. */ 146 bool hasDefaultValue() const { return this->bHasDefaultValue_; } 147 148 virtual bool setValue(const char& value) = 0; 149 virtual bool setValue(const unsigned char& value) = 0; 150 virtual bool setValue(const short& value) = 0; 151 virtual bool setValue(const unsigned short& value) = 0; 152 virtual bool setValue(const int& value) = 0; 153 virtual bool setValue(const unsigned int& value) = 0; 154 virtual bool setValue(const long& value) = 0; 155 virtual bool setValue(const unsigned long& value) = 0; 156 virtual bool setValue(const long long& value) = 0; 157 virtual bool setValue(const unsigned long long& value) = 0; 158 virtual bool setValue(const float& value) = 0; 159 virtual bool setValue(const double& value) = 0; 160 virtual bool setValue(const long double& value) = 0; 161 virtual bool setValue(const bool& value) = 0; 162 virtual bool setValue( void* const& value) = 0; 163 virtual bool setValue(const std::string& value) = 0; 164 virtual bool setValue(const orxonox::Vector2& value) = 0; 165 virtual bool setValue(const orxonox::Vector3& value) = 0; 166 virtual bool setValue(const orxonox::Vector4& value) = 0; 167 virtual bool setValue(const orxonox::ColourValue& value) = 0; 168 virtual bool setValue(const orxonox::Quaternion& value) = 0; 169 virtual bool setValue(const orxonox::Radian& value) = 0; 170 virtual bool setValue(const orxonox::Degree& value) = 0; 171 172 virtual bool getValue(char* value) const = 0; 173 virtual bool getValue(unsigned char* value) const = 0; 174 virtual bool getValue(short* value) const = 0; 175 virtual bool getValue(unsigned short* value) const = 0; 176 virtual bool getValue(int* value) const = 0; 177 virtual bool getValue(unsigned int* value) const = 0; 178 virtual bool getValue(long* value) const = 0; 179 virtual bool getValue(unsigned long* value) const = 0; 180 virtual bool getValue(long long* value) const = 0; 181 virtual bool getValue(unsigned long long* value) const = 0; 182 virtual bool getValue(float* value) const = 0; 183 virtual bool getValue(double* value) const = 0; 184 virtual bool getValue(long double* value) const = 0; 185 virtual bool getValue(bool* value) const = 0; 186 virtual bool getValue(void** value) const = 0; 187 virtual bool getValue(std::string* value) const = 0; 188 virtual bool getValue(orxonox::Vector2* value) const = 0; 189 virtual bool getValue(orxonox::Vector3* value) const = 0; 190 virtual bool getValue(orxonox::Vector4* value) const = 0; 191 virtual bool getValue(orxonox::ColourValue* value) const = 0; 192 virtual bool getValue(orxonox::Quaternion* value) const = 0; 193 virtual bool getValue(orxonox::Radian* value) const = 0; 194 virtual bool getValue(orxonox::Degree* value) const = 0; 164 195 165 196 virtual operator char() const = 0; … … 189 220 virtual void toString(std::ostream& outstream) const = 0; 190 221 191 MT_Type type_; //!< The type of the current value 222 MT_Type type_; //!< The type of the current value 223 bool bHasDefaultValue_; //!< True if the last conversion wasn't successful 192 224 }; 193 225 … … 229 261 inline const MultiType& operator=(MT_Type type) { this->setType(type); return (*this); } /** @brief Resets the value and changes the type. */ 230 262 231 inline voidsetValue(const char& value);232 inline voidsetValue(const unsigned char& value);233 inline voidsetValue(const short& value);234 inline voidsetValue(const unsigned short& value);235 inline voidsetValue(const int& value);236 inline voidsetValue(const unsigned int& value);237 inline voidsetValue(const long& value);238 inline voidsetValue(const unsigned long& value);239 inline voidsetValue(const long long& value);240 inline voidsetValue(const unsigned long long& value);241 inline voidsetValue(const float& value);242 inline voidsetValue(const double& value);243 inline voidsetValue(const long double& value);244 inline voidsetValue(const bool& value);245 inline voidsetValue( void* const& value);246 inline voidsetValue(const std::string& value);247 inline voidsetValue(const orxonox::Vector2& value);248 inline voidsetValue(const orxonox::Vector3& value);249 inline voidsetValue(const orxonox::Vector4& value);250 inline voidsetValue(const orxonox::ColourValue& value);251 inline voidsetValue(const orxonox::Quaternion& value);252 inline voidsetValue(const orxonox::Radian& value);253 inline voidsetValue(const orxonox::Degree& value);254 inline voidsetValue(const char* value);263 inline bool setValue(const char& value); 264 inline bool setValue(const unsigned char& value); 265 inline bool setValue(const short& value); 266 inline bool setValue(const unsigned short& value); 267 inline bool setValue(const int& value); 268 inline bool setValue(const unsigned int& value); 269 inline bool setValue(const long& value); 270 inline bool setValue(const unsigned long& value); 271 inline bool setValue(const long long& value); 272 inline bool setValue(const unsigned long long& value); 273 inline bool setValue(const float& value); 274 inline bool setValue(const double& value); 275 inline bool setValue(const long double& value); 276 inline bool setValue(const bool& value); 277 inline bool setValue( void* const& value); 278 inline bool setValue(const std::string& value); 279 inline bool setValue(const orxonox::Vector2& value); 280 inline bool setValue(const orxonox::Vector3& value); 281 inline bool setValue(const orxonox::Vector4& value); 282 inline bool setValue(const orxonox::ColourValue& value); 283 inline bool setValue(const orxonox::Quaternion& value); 284 inline bool setValue(const orxonox::Radian& value); 285 inline bool setValue(const orxonox::Degree& value); 286 inline bool setValue(const char* value); 255 287 /** @brief Assigns a pointer. */ 256 template <typename V> inline void setValue(V* value) { if (this->value_) { this->value_->setValue((void*)value); } else {this->assignValue((void*)value); } }288 template <typename V> inline bool setValue(V* value) { if (this->value_) { return this->value_->setValue((void*)value); } else { return this->assignValue((void*)value); } } 257 289 /** @brief Assigns the value of the other MultiType and converts it to the current type. */ 258 void setValue(const MultiType& other) { if (this->value_) { this->value_->assimilate(other); } else { if (other.value_) { this->value_ = other.value_->clone(); }} }290 bool setValue(const MultiType& other) { if (this->value_) { return this->value_->assimilate(other); } else { if (other.value_) { this->value_ = other.value_->clone(); } return true; } } 259 291 /** @brief Changes the type to T and assigns the new value (which might be of another type than T - it gets converted). */ 260 template <typename T, typename V> inline void setValue(const V& value) { this->setType<T>();this->setValue(value); }292 template <typename T, typename V> inline bool setValue(const V& value) { this->setType<T>(); return this->setValue(value); } 261 293 262 294 … … 264 296 inline void copy(const MultiType& other) { if (this == &other) { return; } if (this->value_) { delete this->value_; } this->value_ = (other.value_) ? other.value_->clone() : 0; } 265 297 266 template <typename T> inline void convert() {this->setValue<T>((T)(*this)); } /** @brief Converts the current value to type T. */267 inline void convert(const MultiType& other) {this->convert(other.getType()); } /** @brief Converts the current value to the type of the other MultiType. */268 voidconvert(MT_Type type);269 270 /** @brief Resets the value to the defaultvalue of the current type.*/271 inline void reset() { if (this->value_) { delete this->value_; this->value_ = 0; }}298 template <typename T> inline bool convert() { return this->setValue<T>((T)(*this)); } /** @brief Converts the current value to type T. */ 299 inline bool convert(const MultiType& other) { return this->convert(other.getType()); } /** @brief Converts the current value to the type of the other MultiType. */ 300 bool convert(MT_Type type); 301 302 /** @brief Current content gets deleted. New type is MT_null */ 303 inline void reset() { if (this->value_) this->value_->reset(); } 272 304 273 305 template <typename T> inline void setType() { this->assignValue(T()); } /** @brief Resets the value and changes the internal type to T. */ … … 282 314 template <typename T> inline bool isType() const { return false; } // Only works for specialized values - see below 283 315 std::string getTypename() const; 316 317 /** @brief Checks whether the value is a default one. */ 318 bool hasDefaultValue() const { return this->value_->hasDefaultValue(); } 284 319 285 320 operator char() const; … … 309 344 template <class T> operator T*() const { return ((T*)this->operator void*()); } 310 345 311 inline void getValue(char* value) const { if (this->value_) { (*value) = (*this->value_); }} /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */312 inline void getValue(unsigned char* value) const { if (this->value_) { (*value) = (*this->value_); }} /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */313 inline void getValue(short* value) const { if (this->value_) { (*value) = (*this->value_); }} /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */314 inline void getValue(unsigned short* value) const { if (this->value_) { (*value) = (*this->value_); }} /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */315 inline void getValue(int* value) const { if (this->value_) { (*value) = (*this->value_); }} /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */316 inline void getValue(unsigned int* value) const { if (this->value_) { (*value) = (*this->value_); }} /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */317 inline void getValue(long* value) const { if (this->value_) { (*value) = (*this->value_); }} /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */318 inline void getValue(unsigned long* value) const { if (this->value_) { (*value) = (*this->value_); }} /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */319 inline void getValue(long long* value) const { if (this->value_) { (*value) = (*this->value_); }} /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */320 inline void getValue(unsigned long long* value) const { if (this->value_) { (*value) = (*this->value_); }} /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */321 inline void getValue(float* value) const { if (this->value_) { (*value) = (*this->value_); }} /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */322 inline void getValue(double* value) const { if (this->value_) { (*value) = (*this->value_); }} /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */323 inline void getValue(long double* value) const { if (this->value_) { (*value) = (*this->value_); }} /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */324 inline void getValue(bool* value) const { if (this->value_) { (*value) = (*this->value_); }} /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */325 inline void getValue(void* value) const { if (this->value_) { value = (*this->value_); }} /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */326 inline void getValue(std::string* value) const { if (this->value_) { (*value) = this->value_->operator std::string(); }} /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */327 inline void getValue(orxonox::Vector2* value) const { if (this->value_) { (*value) = this->value_->operator orxonox::Vector2(); }} /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */328 inline void getValue(orxonox::Vector3* value) const { if (this->value_) { (*value) = this->value_->operator orxonox::Vector3(); }} /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */329 inline void getValue(orxonox::Vector4* value) const { if (this->value_) { (*value) = this->value_->operator orxonox::Vector4(); }} /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */330 inline void getValue(orxonox::ColourValue* value) const { if (this->value_) { (*value) = this->value_->operator orxonox::ColourValue(); }} /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */331 inline void getValue(orxonox::Quaternion* value) const { if (this->value_) { (*value) = this->value_->operator orxonox::Quaternion(); }} /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */332 inline void getValue(orxonox::Radian* value) const { if (this->value_) { (*value) = this->value_->operator orxonox::Radian(); }} /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */333 inline void getValue(orxonox::Degree* value) const { if (this->value_) { (*value) = this->value_->operator orxonox::Degree(); }} /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */346 inline bool getValue(char* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 347 inline bool getValue(unsigned char* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 348 inline bool getValue(short* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 349 inline bool getValue(unsigned short* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 350 inline bool getValue(int* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 351 inline bool getValue(unsigned int* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 352 inline bool getValue(long* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 353 inline bool getValue(unsigned long* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 354 inline bool getValue(long long* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 355 inline bool getValue(unsigned long long* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 356 inline bool getValue(float* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 357 inline bool getValue(double* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 358 inline bool getValue(long double* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 359 inline bool getValue(bool* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 360 inline bool getValue(void** value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 361 inline bool getValue(std::string* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 362 inline bool getValue(orxonox::Vector2* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 363 inline bool getValue(orxonox::Vector3* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 364 inline bool getValue(orxonox::Vector4* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 365 inline bool getValue(orxonox::ColourValue* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 366 inline bool getValue(orxonox::Quaternion* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 367 inline bool getValue(orxonox::Radian* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 368 inline bool getValue(orxonox::Degree* value) const { if (this->value_) { return this->value_->getValue(value); } return false; } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 334 369 335 370 inline char getChar() const { return this->operator char(); } /** @brief Returns the current value, converted to the requested type. */ … … 359 394 360 395 private: 361 inline void assignValue(const char& value) { if (this->value_ && this->value_->type_ == MT_char) { this->value_->setValue(value); } else { this->changeValueContainer<char>(value);} } /** @brief Assigns a new value by changing type and creating a new container. */362 inline void assignValue(const unsigned char& value) { if (this->value_ && this->value_->type_ == MT_uchar) { this->value_->setValue(value); } else { this->changeValueContainer<unsigned char>(value);} } /** @brief Assigns a new value by changing type and creating a new container. */363 inline void assignValue(const short& value) { if (this->value_ && this->value_->type_ == MT_short) { this->value_->setValue(value); } else { this->changeValueContainer<short>(value);} } /** @brief Assigns a new value by changing type and creating a new container. */364 inline void assignValue(const unsigned short& value) { if (this->value_ && this->value_->type_ == MT_ushort) { this->value_->setValue(value); } else { this->changeValueContainer<unsigned short>(value);} } /** @brief Assigns a new value by changing type and creating a new container. */365 inline void assignValue(const int& value) { if (this->value_ && this->value_->type_ == MT_int) { this->value_->setValue(value); } else { this->changeValueContainer<int>(value);} } /** @brief Assigns a new value by changing type and creating a new container. */366 inline void assignValue(const unsigned int& value) { if (this->value_ && this->value_->type_ == MT_uint) { this->value_->setValue(value); } else { this->changeValueContainer<unsigned int>(value);} } /** @brief Assigns a new value by changing type and creating a new container. */367 inline void assignValue(const long& value) { if (this->value_ && this->value_->type_ == MT_long) { this->value_->setValue(value); } else { this->changeValueContainer<long>(value);} } /** @brief Assigns a new value by changing type and creating a new container. */368 inline void assignValue(const unsigned long& value) { if (this->value_ && this->value_->type_ == MT_ulong) { this->value_->setValue(value); } else { this->changeValueContainer<unsigned long>(value);} } /** @brief Assigns a new value by changing type and creating a new container. */369 inline void assignValue(const long long& value) { if (this->value_ && this->value_->type_ == MT_longlong) { this->value_->setValue(value); } else { this->changeValueContainer<long long>(value);} } /** @brief Assigns a new value by changing type and creating a new container. */370 inline void assignValue(const unsigned long long& value) { if (this->value_ && this->value_->type_ == MT_ulonglong) { this->value_->setValue(value); } else { this->changeValueContainer<unsigned long long>(value);} } /** @brief Assigns a new value by changing type and creating a new container. */371 inline void assignValue(const float& value) { if (this->value_ && this->value_->type_ == MT_float) { this->value_->setValue(value); } else { this->changeValueContainer<float>(value);} } /** @brief Assigns a new value by changing type and creating a new container. */372 inline void assignValue(const double& value) { if (this->value_ && this->value_->type_ == MT_double) { this->value_->setValue(value); } else { this->changeValueContainer<double>(value);} } /** @brief Assigns a new value by changing type and creating a new container. */373 inline void assignValue(const long double& value) { if (this->value_ && this->value_->type_ == MT_longdouble) { this->value_->setValue(value); } else { this->changeValueContainer<long double>(value);} } /** @brief Assigns a new value by changing type and creating a new container. */374 inline void assignValue(const bool& value) { if (this->value_ && this->value_->type_ == MT_bool) { this->value_->setValue(value); } else { this->changeValueContainer<bool>(value);} } /** @brief Assigns a new value by changing type and creating a new container. */375 inline void assignValue( void* const& value) { if (this->value_ && this->value_->type_ == MT_void) { this->value_->setValue(value); } else { this->changeValueContainer<void*>(value);} } /** @brief Assigns a new value by changing type and creating a new container. */376 inline void assignValue(const std::string& value) { if (this->value_ && this->value_->type_ == MT_string) { this->value_->setValue(value); } else { this->changeValueContainer<std::string>(value);} } /** @brief Assigns a new value by changing type and creating a new container. */377 inline void assignValue(const orxonox::Vector2& value) { if (this->value_ && this->value_->type_ == MT_vector2) { this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Vector2>(value);} } /** @brief Assigns a new value by changing type and creating a new container. */378 inline void assignValue(const orxonox::Vector3& value) { if (this->value_ && this->value_->type_ == MT_vector3) { this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Vector3>(value);} } /** @brief Assigns a new value by changing type and creating a new container. */379 inline void assignValue(const orxonox::Vector4& value) { if (this->value_ && this->value_->type_ == MT_vector4) { this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Vector4>(value);} } /** @brief Assigns a new value by changing type and creating a new container. */380 inline void assignValue(const orxonox::ColourValue& value) { if (this->value_ && this->value_->type_ == MT_colourvalue) { this->value_->setValue(value); } else { this->changeValueContainer<orxonox::ColourValue>(value); } } /** @brief Assigns a new value by changing type and creating a new container. */381 inline void assignValue(const orxonox::Quaternion& value) { if (this->value_ && this->value_->type_ == MT_quaternion) { this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Quaternion>(value);} } /** @brief Assigns a new value by changing type and creating a new container. */382 inline void assignValue(const orxonox::Radian& value) { if (this->value_ && this->value_->type_ == MT_radian) { this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Radian>(value);} } /** @brief Assigns a new value by changing type and creating a new container. */383 inline void assignValue(const orxonox::Degree& value) { if (this->value_ && this->value_->type_ == MT_degree) { this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Degree>(value);} } /** @brief Assigns a new value by changing type and creating a new container. */396 inline bool assignValue(const char& value) { if (this->value_ && this->value_->type_ == MT_char) { return this->value_->setValue(value); } else { this->changeValueContainer<char>(value); return true; } } /** @brief Assigns a new value by changing type and creating a new container. */ 397 inline bool assignValue(const unsigned char& value) { if (this->value_ && this->value_->type_ == MT_uchar) { return this->value_->setValue(value); } else { this->changeValueContainer<unsigned char>(value); return true; } } /** @brief Assigns a new value by changing type and creating a new container. */ 398 inline bool assignValue(const short& value) { if (this->value_ && this->value_->type_ == MT_short) { return this->value_->setValue(value); } else { this->changeValueContainer<short>(value); return true; } } /** @brief Assigns a new value by changing type and creating a new container. */ 399 inline bool assignValue(const unsigned short& value) { if (this->value_ && this->value_->type_ == MT_ushort) { return this->value_->setValue(value); } else { this->changeValueContainer<unsigned short>(value); return true; } } /** @brief Assigns a new value by changing type and creating a new container. */ 400 inline bool assignValue(const int& value) { if (this->value_ && this->value_->type_ == MT_int) { return this->value_->setValue(value); } else { this->changeValueContainer<int>(value); return true; } } /** @brief Assigns a new value by changing type and creating a new container. */ 401 inline bool assignValue(const unsigned int& value) { if (this->value_ && this->value_->type_ == MT_uint) { return this->value_->setValue(value); } else { this->changeValueContainer<unsigned int>(value); return true; } } /** @brief Assigns a new value by changing type and creating a new container. */ 402 inline bool assignValue(const long& value) { if (this->value_ && this->value_->type_ == MT_long) { return this->value_->setValue(value); } else { this->changeValueContainer<long>(value); return true; } } /** @brief Assigns a new value by changing type and creating a new container. */ 403 inline bool assignValue(const unsigned long& value) { if (this->value_ && this->value_->type_ == MT_ulong) { return this->value_->setValue(value); } else { this->changeValueContainer<unsigned long>(value); return true; } } /** @brief Assigns a new value by changing type and creating a new container. */ 404 inline bool assignValue(const long long& value) { if (this->value_ && this->value_->type_ == MT_longlong) { return this->value_->setValue(value); } else { this->changeValueContainer<long long>(value); return true; } } /** @brief Assigns a new value by changing type and creating a new container. */ 405 inline bool assignValue(const unsigned long long& value) { if (this->value_ && this->value_->type_ == MT_ulonglong) { return this->value_->setValue(value); } else { this->changeValueContainer<unsigned long long>(value); return true; } } /** @brief Assigns a new value by changing type and creating a new container. */ 406 inline bool assignValue(const float& value) { if (this->value_ && this->value_->type_ == MT_float) { return this->value_->setValue(value); } else { this->changeValueContainer<float>(value); return true; } } /** @brief Assigns a new value by changing type and creating a new container. */ 407 inline bool assignValue(const double& value) { if (this->value_ && this->value_->type_ == MT_double) { return this->value_->setValue(value); } else { this->changeValueContainer<double>(value); return true; } } /** @brief Assigns a new value by changing type and creating a new container. */ 408 inline bool assignValue(const long double& value) { if (this->value_ && this->value_->type_ == MT_longdouble) { return this->value_->setValue(value); } else { this->changeValueContainer<long double>(value); return true; } } /** @brief Assigns a new value by changing type and creating a new container. */ 409 inline bool assignValue(const bool& value) { if (this->value_ && this->value_->type_ == MT_bool) { return this->value_->setValue(value); } else { this->changeValueContainer<bool>(value); return true; } } /** @brief Assigns a new value by changing type and creating a new container. */ 410 inline bool assignValue( void* const& value) { if (this->value_ && this->value_->type_ == MT_void) { return this->value_->setValue(value); } else { this->changeValueContainer<void*>(value); return true; } } /** @brief Assigns a new value by changing type and creating a new container. */ 411 inline bool assignValue(const std::string& value) { if (this->value_ && this->value_->type_ == MT_string) { return this->value_->setValue(value); } else { this->changeValueContainer<std::string>(value); return true; } } /** @brief Assigns a new value by changing type and creating a new container. */ 412 inline bool assignValue(const orxonox::Vector2& value) { if (this->value_ && this->value_->type_ == MT_vector2) { return this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Vector2>(value); return true; } } /** @brief Assigns a new value by changing type and creating a new container. */ 413 inline bool assignValue(const orxonox::Vector3& value) { if (this->value_ && this->value_->type_ == MT_vector3) { return this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Vector3>(value); return true; } } /** @brief Assigns a new value by changing type and creating a new container. */ 414 inline bool assignValue(const orxonox::Vector4& value) { if (this->value_ && this->value_->type_ == MT_vector4) { return this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Vector4>(value); return true; } } /** @brief Assigns a new value by changing type and creating a new container. */ 415 inline bool assignValue(const orxonox::ColourValue& value) { if (this->value_ && this->value_->type_ == MT_colourvalue) { return this->value_->setValue(value); } else { this->changeValueContainer<orxonox::ColourValue>(value); return true; } } /** @brief Assigns a new value by changing type and creating a new container. */ 416 inline bool assignValue(const orxonox::Quaternion& value) { if (this->value_ && this->value_->type_ == MT_quaternion) { return this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Quaternion>(value); return true; } } /** @brief Assigns a new value by changing type and creating a new container. */ 417 inline bool assignValue(const orxonox::Radian& value) { if (this->value_ && this->value_->type_ == MT_radian) { return this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Radian>(value); return true; } } /** @brief Assigns a new value by changing type and creating a new container. */ 418 inline bool assignValue(const orxonox::Degree& value) { if (this->value_ && this->value_->type_ == MT_degree) { return this->value_->setValue(value); } else { this->changeValueContainer<orxonox::Degree>(value); return true; } } /** @brief Assigns a new value by changing type and creating a new container. */ 384 419 385 420 /** @brief Changes the value container. */ 386 421 template <typename T> inline void changeValueContainer(const T& value) { if (this->value_) { delete this->value_; } this->createNewValueContainer<T>(value); } 387 422 /** @brief Creates a new value container (works only with specialized types). */ 388 template <typename T> void createNewValueContainer(const T& value) { BOOST_STATIC_ASSERT(sizeof(T) == 0); }423 template <typename T> void createNewValueContainer(const T& value) { BOOST_STATIC_ASSERT(sizeof(T) == 0); return false; } 389 424 390 425 MT_ValueBase* value_; //!< A pointer to the value container … … 419 454 420 455 // Specialization to avoid ambiguities with the conversion operator 421 template <> inline void MultiType::convert<std::string>() {this->setValue<std::string> (this->operator std::string()); } /** @brief Converts the current value to the given type. */422 template <> inline void MultiType::convert<orxonox::Vector2>() {this->setValue<orxonox::Vector2> (this->operator orxonox::Vector2()); } /** @brief Converts the current value to the given type. */423 template <> inline void MultiType::convert<orxonox::Vector3>() {this->setValue<orxonox::Vector3> (this->operator orxonox::Vector3()); } /** @brief Converts the current value to the given type. */424 template <> inline void MultiType::convert<orxonox::Vector4>() {this->setValue<orxonox::Vector4> (this->operator orxonox::Vector4()); } /** @brief Converts the current value to the given type. */425 template <> inline void MultiType::convert<orxonox::ColourValue>() {this->setValue<orxonox::ColourValue>(this->operator orxonox::ColourValue()); } /** @brief Converts the current value to the given type. */426 template <> inline void MultiType::convert<orxonox::Quaternion>() {this->setValue<orxonox::Quaternion> (this->operator orxonox::Quaternion()); } /** @brief Converts the current value to the given type. */427 template <> inline void MultiType::convert<orxonox::Radian>() {this->setValue<orxonox::Radian> (this->operator orxonox::Radian()); } /** @brief Converts the current value to the given type. */428 template <> inline void MultiType::convert<orxonox::Degree>() {this->setValue<orxonox::Degree> (this->operator orxonox::Degree()); } /** @brief Converts the current value to the given type. */456 template <> inline bool MultiType::convert<std::string>() { return this->setValue<std::string> (this->operator std::string()); } /** @brief Converts the current value to the given type. */ 457 template <> inline bool MultiType::convert<orxonox::Vector2>() { return this->setValue<orxonox::Vector2> (this->operator orxonox::Vector2()); } /** @brief Converts the current value to the given type. */ 458 template <> inline bool MultiType::convert<orxonox::Vector3>() { return this->setValue<orxonox::Vector3> (this->operator orxonox::Vector3()); } /** @brief Converts the current value to the given type. */ 459 template <> inline bool MultiType::convert<orxonox::Vector4>() { return this->setValue<orxonox::Vector4> (this->operator orxonox::Vector4()); } /** @brief Converts the current value to the given type. */ 460 template <> inline bool MultiType::convert<orxonox::ColourValue>() { return this->setValue<orxonox::ColourValue>(this->operator orxonox::ColourValue()); } /** @brief Converts the current value to the given type. */ 461 template <> inline bool MultiType::convert<orxonox::Quaternion>() { return this->setValue<orxonox::Quaternion> (this->operator orxonox::Quaternion()); } /** @brief Converts the current value to the given type. */ 462 template <> inline bool MultiType::convert<orxonox::Radian>() { return this->setValue<orxonox::Radian> (this->operator orxonox::Radian()); } /** @brief Converts the current value to the given type. */ 463 template <> inline bool MultiType::convert<orxonox::Degree>() { return this->setValue<orxonox::Degree> (this->operator orxonox::Degree()); } /** @brief Converts the current value to the given type. */ 429 464 430 465 // Specialization to avoid ambiguities with the conversion operator 431 template <> inline void MultiType::convert<const std::string&>() {this->convert<std::string>(); } /** @brief Converts the current value to the given type. */432 template <> inline void MultiType::convert<const orxonox::Vector2&>() {this->convert<orxonox::Vector2>(); } /** @brief Converts the current value to the given type. */433 template <> inline void MultiType::convert<const orxonox::Vector3&>() {this->convert<orxonox::Vector3>(); } /** @brief Converts the current value to the given type. */434 template <> inline void MultiType::convert<const orxonox::Vector4&>() {this->convert<orxonox::Vector4>(); } /** @brief Converts the current value to the given type. */435 template <> inline void MultiType::convert<const orxonox::ColourValue&>() {this->convert<orxonox::ColourValue>(); } /** @brief Converts the current value to the given type. */436 template <> inline void MultiType::convert<const orxonox::Quaternion&>() {this->convert<orxonox::Quaternion>(); } /** @brief Converts the current value to the given type. */437 template <> inline void MultiType::convert<const orxonox::Radian&>() {this->convert<orxonox::Radian>(); } /** @brief Converts the current value to the given type. */438 template <> inline void MultiType::convert<const orxonox::Degree&>() {this->convert<orxonox::Degree>(); } /** @brief Converts the current value to the given type. */466 template <> inline bool MultiType::convert<const std::string&>() { return this->convert<std::string>(); } /** @brief Converts the current value to the given type. */ 467 template <> inline bool MultiType::convert<const orxonox::Vector2&>() { return this->convert<orxonox::Vector2>(); } /** @brief Converts the current value to the given type. */ 468 template <> inline bool MultiType::convert<const orxonox::Vector3&>() { return this->convert<orxonox::Vector3>(); } /** @brief Converts the current value to the given type. */ 469 template <> inline bool MultiType::convert<const orxonox::Vector4&>() { return this->convert<orxonox::Vector4>(); } /** @brief Converts the current value to the given type. */ 470 template <> inline bool MultiType::convert<const orxonox::ColourValue&>() { return this->convert<orxonox::ColourValue>(); } /** @brief Converts the current value to the given type. */ 471 template <> inline bool MultiType::convert<const orxonox::Quaternion&>() { return this->convert<orxonox::Quaternion>(); } /** @brief Converts the current value to the given type. */ 472 template <> inline bool MultiType::convert<const orxonox::Radian&>() { return this->convert<orxonox::Radian>(); } /** @brief Converts the current value to the given type. */ 473 template <> inline bool MultiType::convert<const orxonox::Degree&>() { return this->convert<orxonox::Degree>(); } /** @brief Converts the current value to the given type. */ 439 474 440 475 template <> void MultiType::createNewValueContainer(const char& value); … … 462 497 template <> void MultiType::createNewValueContainer(const orxonox::Degree& value); 463 498 464 inline void MultiType::setValue(const char& value) { if (this->value_) { this->value_->setValue(value); } else {this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */465 inline void MultiType::setValue(const unsigned char& value) { if (this->value_) { this->value_->setValue(value); } else {this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */466 inline void MultiType::setValue(const short& value) { if (this->value_) { this->value_->setValue(value); } else {this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */467 inline void MultiType::setValue(const unsigned short& value) { if (this->value_) { this->value_->setValue(value); } else {this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */468 inline void MultiType::setValue(const int& value) { if (this->value_) { this->value_->setValue(value); } else {this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */469 inline void MultiType::setValue(const unsigned int& value) { if (this->value_) { this->value_->setValue(value); } else {this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */470 inline void MultiType::setValue(const long& value) { if (this->value_) { this->value_->setValue(value); } else {this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */471 inline void MultiType::setValue(const unsigned long& value) { if (this->value_) { this->value_->setValue(value); } else {this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */472 inline void MultiType::setValue(const long long& value) { if (this->value_) { this->value_->setValue(value); } else {this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */473 inline void MultiType::setValue(const unsigned long long& value) { if (this->value_) { this->value_->setValue(value); } else {this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */474 inline void MultiType::setValue(const float& value) { if (this->value_) { this->value_->setValue(value); } else {this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */475 inline void MultiType::setValue(const double& value) { if (this->value_) { this->value_->setValue(value); } else {this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */476 inline void MultiType::setValue(const long double& value) { if (this->value_) { this->value_->setValue(value); } else {this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */477 inline void MultiType::setValue(const bool& value) { if (this->value_) { this->value_->setValue(value); } else {this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */478 inline void MultiType::setValue( void* const& value) { if (this->value_) { this->value_->setValue(value); } else {this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */479 inline void MultiType::setValue(const std::string& value) { if (this->value_) { this->value_->setValue(value); } else {this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */480 inline void MultiType::setValue(const orxonox::Vector2& value) { if (this->value_) { this->value_->setValue(value); } else {this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */481 inline void MultiType::setValue(const orxonox::Vector3& value) { if (this->value_) { this->value_->setValue(value); } else {this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */482 inline void MultiType::setValue(const orxonox::Vector4& value) { if (this->value_) { this->value_->setValue(value); } else {this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */483 inline void MultiType::setValue(const orxonox::ColourValue& value) { if (this->value_) { this->value_->setValue(value); } else {this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */484 inline void MultiType::setValue(const orxonox::Quaternion& value) { if (this->value_) { this->value_->setValue(value); } else {this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */485 inline void MultiType::setValue(const orxonox::Radian& value) { if (this->value_) { this->value_->setValue(value); } else {this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */486 inline void MultiType::setValue(const orxonox::Degree& value) { if (this->value_) { this->value_->setValue(value); } else {this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */487 488 inline void MultiType::setValue(const char* value) { if (this->value_) { this->value_->setValue(std::string(value)); } else {this->assignValue(std::string(value)); } } /** @brief Assigns the given value and converts it to the current type. */499 inline bool MultiType::setValue(const char& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 500 inline bool MultiType::setValue(const unsigned char& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 501 inline bool MultiType::setValue(const short& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 502 inline bool MultiType::setValue(const unsigned short& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 503 inline bool MultiType::setValue(const int& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 504 inline bool MultiType::setValue(const unsigned int& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 505 inline bool MultiType::setValue(const long& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 506 inline bool MultiType::setValue(const unsigned long& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 507 inline bool MultiType::setValue(const long long& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 508 inline bool MultiType::setValue(const unsigned long long& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 509 inline bool MultiType::setValue(const float& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 510 inline bool MultiType::setValue(const double& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 511 inline bool MultiType::setValue(const long double& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 512 inline bool MultiType::setValue(const bool& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 513 inline bool MultiType::setValue( void* const& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 514 inline bool MultiType::setValue(const std::string& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 515 inline bool MultiType::setValue(const orxonox::Vector2& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 516 inline bool MultiType::setValue(const orxonox::Vector3& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 517 inline bool MultiType::setValue(const orxonox::Vector4& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 518 inline bool MultiType::setValue(const orxonox::ColourValue& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 519 inline bool MultiType::setValue(const orxonox::Quaternion& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 520 inline bool MultiType::setValue(const orxonox::Radian& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 521 inline bool MultiType::setValue(const orxonox::Degree& value) { if (this->value_) { return this->value_->setValue(value); } else { return this->assignValue(value); } } /** @brief Assigns the given value and converts it to the current type. */ 522 523 inline bool MultiType::setValue(const char* value) { if (this->value_) { return this->value_->setValue(std::string(value)); } else { return this->assignValue(std::string(value)); } } /** @brief Assigns the given value and converts it to the current type. */ 489 524 490 525 #endif /* _MultiType_H__ */ -
code/trunk/src/util/MultiTypeValue.h
r1854 r2087 38 38 39 39 #include "UtilPrereqs.h" 40 #include " Convert.h"40 #include "MathConvert.h" 41 41 #include "MultiType.h" 42 42 … … 54 54 55 55 /** @brief Resets the current value to the default. */ 56 inline void reset() { this->value_ = T(); }56 inline void reset() { this->value_ = zeroise<T>(); bHasDefaultValue_ = true; } 57 57 58 58 /** @brief Assigns the value of the other MultiType, converted to T. @param other The other MultiType */ 59 inline void assimilate(const MultiType& other) { if (other.value_) { T temp; other.getValue(&temp); this->value_ = temp; } else { this->value_ = T(); } } 59 inline bool assimilate(const MultiType& other) 60 { 61 if (other.value_) 62 { 63 return !(bHasDefaultValue_ = !other.value_->getValue(&value_)); 64 } 65 else 66 { 67 this->value_ = zeroise<T>(); 68 return !(bHasDefaultValue_ = true); 69 } 70 } 60 71 61 inline void setValue(const char& value) { this->value_ = getConvertedValue<char, T>(value); } /** @brief Assigns the value by converting it to T. */ 62 inline void setValue(const unsigned char& value) { this->value_ = getConvertedValue<unsigned char, T>(value); } /** @brief Assigns the value by converting it to T. */ 63 inline void setValue(const short& value) { this->value_ = getConvertedValue<short, T>(value); } /** @brief Assigns the value by converting it to T. */ 64 inline void setValue(const unsigned short& value) { this->value_ = getConvertedValue<unsigned short, T>(value); } /** @brief Assigns the value by converting it to T. */ 65 inline void setValue(const int& value) { this->value_ = getConvertedValue<int, T>(value); } /** @brief Assigns the value by converting it to T. */ 66 inline void setValue(const unsigned int& value) { this->value_ = getConvertedValue<unsigned int, T>(value); } /** @brief Assigns the value by converting it to T. */ 67 inline void setValue(const long& value) { this->value_ = getConvertedValue<long, T>(value); } /** @brief Assigns the value by converting it to T. */ 68 inline void setValue(const unsigned long& value) { this->value_ = getConvertedValue<unsigned long, T>(value); } /** @brief Assigns the value by converting it to T. */ 69 inline void setValue(const long long& value) { this->value_ = getConvertedValue<long long, T>(value); } /** @brief Assigns the value by converting it to T. */ 70 inline void setValue(const unsigned long long& value) { this->value_ = getConvertedValue<unsigned long long, T>(value); } /** @brief Assigns the value by converting it to T. */ 71 inline void setValue(const float& value) { this->value_ = getConvertedValue<float, T>(value); } /** @brief Assigns the value by converting it to T. */ 72 inline void setValue(const double& value) { this->value_ = getConvertedValue<double, T>(value); } /** @brief Assigns the value by converting it to T. */ 73 inline void setValue(const long double& value) { this->value_ = getConvertedValue<long double, T>(value); } /** @brief Assigns the value by converting it to T. */ 74 inline void setValue(const bool& value) { this->value_ = getConvertedValue<bool, T>(value); } /** @brief Assigns the value by converting it to T. */ 75 inline void setValue( void* const& value) { this->value_ = getConvertedValue<void*, T>(value); } /** @brief Assigns the value by converting it to T. */ 76 inline void setValue(const std::string& value) { this->value_ = getConvertedValue<std::string, T>(value); } /** @brief Assigns the value by converting it to T. */ 77 inline void setValue(const orxonox::Vector2& value) { this->value_ = getConvertedValue<orxonox::Vector2, T>(value); } /** @brief Assigns the value by converting it to T. */ 78 inline void setValue(const orxonox::Vector3& value) { this->value_ = getConvertedValue<orxonox::Vector3, T>(value); } /** @brief Assigns the value by converting it to T. */ 79 inline void setValue(const orxonox::Vector4& value) { this->value_ = getConvertedValue<orxonox::Vector4, T>(value); } /** @brief Assigns the value by converting it to T. */ 80 inline void setValue(const orxonox::ColourValue& value) { this->value_ = getConvertedValue<orxonox::ColourValue, T>(value); } /** @brief Assigns the value by converting it to T. */ 81 inline void setValue(const orxonox::Quaternion& value) { this->value_ = getConvertedValue<orxonox::Quaternion, T>(value); } /** @brief Assigns the value by converting it to T. */ 82 inline void setValue(const orxonox::Radian& value) { this->value_ = getConvertedValue<orxonox::Radian, T>(value); } /** @brief Assigns the value by converting it to T. */ 83 inline void setValue(const orxonox::Degree& value) { this->value_ = getConvertedValue<orxonox::Degree, T>(value); } /** @brief Assigns the value by converting it to T. */ 72 inline bool getValue(char* value) const { return ConvertValue<T, char >(value, value_, 0); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 73 inline bool getValue(unsigned char* value) const { return ConvertValue<T, unsigned char >(value, value_, 0); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 74 inline bool getValue(short* value) const { return ConvertValue<T, short >(value, value_, 0); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 75 inline bool getValue(unsigned short* value) const { return ConvertValue<T, unsigned short >(value, value_, 0); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 76 inline bool getValue(int* value) const { return ConvertValue<T, int >(value, value_, 0); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 77 inline bool getValue(unsigned int* value) const { return ConvertValue<T, unsigned int >(value, value_, 0); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 78 inline bool getValue(long* value) const { return ConvertValue<T, long >(value, value_, 0); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 79 inline bool getValue(unsigned long* value) const { return ConvertValue<T, unsigned long >(value, value_, 0); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 80 inline bool getValue(long long* value) const { return ConvertValue<T, long long >(value, value_, 0); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 81 inline bool getValue(unsigned long long* value) const { return ConvertValue<T, unsigned long long >(value, value_, 0); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 82 inline bool getValue(float* value) const { return ConvertValue<T, float >(value, value_, 0); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 83 inline bool getValue(double* value) const { return ConvertValue<T, double >(value, value_, 0); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 84 inline bool getValue(long double* value) const { return ConvertValue<T, long double >(value, value_, 0); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 85 inline bool getValue(bool* value) const { return ConvertValue<T, bool >(value, value_, 0); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 86 inline bool getValue(void** value) const { return ConvertValue<T, void* >(value, value_, 0); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 87 inline bool getValue(std::string* value) const { return ConvertValue<T, std::string >(value, value_, zeroise<std::string> ()); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 88 inline bool getValue(orxonox::Vector2* value) const { return ConvertValue<T, orxonox::Vector2 >(value, value_, zeroise<orxonox::Vector2> ()); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 89 inline bool getValue(orxonox::Vector3* value) const { return ConvertValue<T, orxonox::Vector3 >(value, value_, zeroise<orxonox::Vector3> ()); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 90 inline bool getValue(orxonox::Vector4* value) const { return ConvertValue<T, orxonox::Vector4 >(value, value_, zeroise<orxonox::Vector4> ()); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 91 inline bool getValue(orxonox::ColourValue* value) const { return ConvertValue<T, orxonox::ColourValue>(value, value_, zeroise<orxonox::ColourValue>()); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 92 inline bool getValue(orxonox::Quaternion* value) const { return ConvertValue<T, orxonox::Quaternion >(value, value_, zeroise<orxonox::Quaternion> ()); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 93 inline bool getValue(orxonox::Radian* value) const { return ConvertValue<T, orxonox::Radian >(value, value_, zeroise<orxonox::Radian> ()); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 94 inline bool getValue(orxonox::Degree* value) const { return ConvertValue<T, orxonox::Degree >(value, value_, zeroise<orxonox::Degree> ()); } /** @brief Assigns the value to the given pointer. The value gets converted if the types don't match. */ 95 96 inline bool setValue(const char& value) { return !(bHasDefaultValue_ = !ConvertValue<char , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */ 97 inline bool setValue(const unsigned char& value) { return !(bHasDefaultValue_ = !ConvertValue<unsigned char , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */ 98 inline bool setValue(const short& value) { return !(bHasDefaultValue_ = !ConvertValue<short , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */ 99 inline bool setValue(const unsigned short& value) { return !(bHasDefaultValue_ = !ConvertValue<unsigned short , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */ 100 inline bool setValue(const int& value) { return !(bHasDefaultValue_ = !ConvertValue<int , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */ 101 inline bool setValue(const unsigned int& value) { return !(bHasDefaultValue_ = !ConvertValue<unsigned int , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */ 102 inline bool setValue(const long& value) { return !(bHasDefaultValue_ = !ConvertValue<long , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */ 103 inline bool setValue(const unsigned long& value) { return !(bHasDefaultValue_ = !ConvertValue<unsigned long , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */ 104 inline bool setValue(const long long& value) { return !(bHasDefaultValue_ = !ConvertValue<long long , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */ 105 inline bool setValue(const unsigned long long& value) { return !(bHasDefaultValue_ = !ConvertValue<unsigned long long , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */ 106 inline bool setValue(const float& value) { return !(bHasDefaultValue_ = !ConvertValue<float , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */ 107 inline bool setValue(const double& value) { return !(bHasDefaultValue_ = !ConvertValue<double , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */ 108 inline bool setValue(const long double& value) { return !(bHasDefaultValue_ = !ConvertValue<long double , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */ 109 inline bool setValue(const bool& value) { return !(bHasDefaultValue_ = !ConvertValue<bool , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */ 110 inline bool setValue( void* const& value) { return !(bHasDefaultValue_ = !ConvertValue<void* , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */ 111 inline bool setValue(const std::string& value) { return !(bHasDefaultValue_ = !ConvertValue<std::string , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */ 112 inline bool setValue(const orxonox::Vector2& value) { return !(bHasDefaultValue_ = !ConvertValue<orxonox::Vector2 , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */ 113 inline bool setValue(const orxonox::Vector3& value) { return !(bHasDefaultValue_ = !ConvertValue<orxonox::Vector3 , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */ 114 inline bool setValue(const orxonox::Vector4& value) { return !(bHasDefaultValue_ = !ConvertValue<orxonox::Vector4 , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */ 115 inline bool setValue(const orxonox::ColourValue& value) { return !(bHasDefaultValue_ = !ConvertValue<orxonox::ColourValue, T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */ 116 inline bool setValue(const orxonox::Quaternion& value) { return !(bHasDefaultValue_ = !ConvertValue<orxonox::Quaternion , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */ 117 inline bool setValue(const orxonox::Radian& value) { return !(bHasDefaultValue_ = !ConvertValue<orxonox::Radian , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */ 118 inline bool setValue(const orxonox::Degree& value) { return !(bHasDefaultValue_ = !ConvertValue<orxonox::Degree , T>(&value_, value, zeroise<T>())); } /** @brief Assigns the value by converting it to T. */ 84 119 85 120 inline operator char() const { return getConvertedValue<T, char> (this->value_, 0); } /** @brief Returns the current value, converted to the requested type. */ … … 96 131 inline operator double() const { return getConvertedValue<T, double> (this->value_, 0); } /** @brief Returns the current value, converted to the requested type. */ 97 132 inline operator long double() const { return getConvertedValue<T, long double> (this->value_, 0); } /** @brief Returns the current value, converted to the requested type. */ 98 inline operator bool() const { return getConvertedValue<T, bool> (this->value_, false); }/** @brief Returns the current value, converted to the requested type. */133 inline operator bool() const { return getConvertedValue<T, bool> (this->value_, 0); } /** @brief Returns the current value, converted to the requested type. */ 99 134 inline operator void*() const { return getConvertedValue<T, void*> (this->value_, 0); } /** @brief Returns the current value, converted to the requested type. */ 100 inline operator std::string() const { return getConvertedValue<T, std::string> (this->value_ ); }/** @brief Returns the current value, converted to the requested type. */101 inline operator orxonox::Vector2() const { return getConvertedValue<T, orxonox::Vector2> (this->value_ ); }/** @brief Returns the current value, converted to the requested type. */102 inline operator orxonox::Vector3() const { return getConvertedValue<T, orxonox::Vector3> (this->value_ ); }/** @brief Returns the current value, converted to the requested type. */103 inline operator orxonox::Vector4() const { return getConvertedValue<T, orxonox::Vector4> (this->value_ ); }/** @brief Returns the current value, converted to the requested type. */104 inline operator orxonox::ColourValue() const { return getConvertedValue<T, orxonox::ColourValue>(this->value_ ); }/** @brief Returns the current value, converted to the requested type. */105 inline operator orxonox::Quaternion() const { return getConvertedValue<T, orxonox::Quaternion> (this->value_ ); }/** @brief Returns the current value, converted to the requested type. */106 inline operator orxonox::Radian() const { return getConvertedValue<T, orxonox::Radian> (this->value_ ); }/** @brief Returns the current value, converted to the requested type. */107 inline operator orxonox::Degree() const { return getConvertedValue<T, orxonox::Degree> (this->value_ ); }/** @brief Returns the current value, converted to the requested type. */135 inline operator std::string() const { return getConvertedValue<T, std::string> (this->value_, zeroise<std::string >()); } /** @brief Returns the current value, converted to the requested type. */ 136 inline operator orxonox::Vector2() const { return getConvertedValue<T, orxonox::Vector2> (this->value_, zeroise<orxonox::Vector2 >()); } /** @brief Returns the current value, converted to the requested type. */ 137 inline operator orxonox::Vector3() const { return getConvertedValue<T, orxonox::Vector3> (this->value_, zeroise<orxonox::Vector3 >()); } /** @brief Returns the current value, converted to the requested type. */ 138 inline operator orxonox::Vector4() const { return getConvertedValue<T, orxonox::Vector4> (this->value_, zeroise<orxonox::Vector4 >()); } /** @brief Returns the current value, converted to the requested type. */ 139 inline operator orxonox::ColourValue() const { return getConvertedValue<T, orxonox::ColourValue>(this->value_, zeroise<orxonox::ColourValue>()); } /** @brief Returns the current value, converted to the requested type. */ 140 inline operator orxonox::Quaternion() const { return getConvertedValue<T, orxonox::Quaternion> (this->value_, zeroise<orxonox::Quaternion >()); } /** @brief Returns the current value, converted to the requested type. */ 141 inline operator orxonox::Radian() const { return getConvertedValue<T, orxonox::Radian> (this->value_, zeroise<orxonox::Radian >()); } /** @brief Returns the current value, converted to the requested type. */ 142 inline operator orxonox::Degree() const { return getConvertedValue<T, orxonox::Degree> (this->value_, zeroise<orxonox::Degree >()); } /** @brief Returns the current value, converted to the requested type. */ 108 143 109 144 /** @brief Puts the current value on the stream */ -
code/trunk/src/util/OutputHandler.cc
r1791 r2087 33 33 34 34 #include "OutputHandler.h" 35 #include <time.h> 35 36 36 37 namespace orxonox … … 46 47 this->logfilename_ = logfilename; 47 48 this->logfile_.open(this->logfilename_.c_str(), std::fstream::out); 48 this->logfile_ << "Started log at yyyy/mm/dd hh:mm:ss" << std::endl; // Todo: Get date and time 49 50 time_t rawtime; 51 struct tm* timeinfo; 52 time(&rawtime); 53 timeinfo = localtime(&rawtime); 54 55 this->logfile_ << "Started log at " << asctime(timeinfo) << std::endl; 49 56 this->logfile_.flush(); 50 57 } -
code/trunk/src/util/String.cc
r1894 r2087 37 37 #include <iostream> 38 38 39 /** 40 @brief Blank string as variable so you can use const std::string& even if you have to return "". 41 */ 42 std::string blankString = ""; 39 #include "Convert.h" 40 #include "Math.h" 41 42 std::string BLANKSTRING(""); 43 44 std::string getUniqueNumberString() 45 { 46 return convertToString(getUniqueNumber()); 47 } 43 48 44 49 /** -
code/trunk/src/util/String.h
r1889 r2087 40 40 #include <sstream> 41 41 42 extern _UtilExport std::string blankString; 42 extern _UtilExport std::string BLANKSTRING; 43 _UtilExport std::string getUniqueNumberString(); 43 44 44 45 _UtilExport void strip(std::string* str); -
code/trunk/updateMedia.sh
r1506 r2087 1 1 #!/bin/bash 2 2 dir=${pwd} 3 cd ../ Media3 cd ../media 4 4 svn up 5 5 cd $dir -
code/trunk/visual_studio/vc8/audio.vcproj
- Property svn:eol-style set to native
-
code/trunk/visual_studio/vc8/audio.vsprops
- Property svn:mergeinfo changed
/code/branches/objecthierarchy/visual_studio/vc8/audio.vsprops (added) merged: 2037,2040,2085 - Property svn:eol-style set to native
- Property svn:mergeinfo changed
-
code/trunk/visual_studio/vc8/base.vsprops
- Property svn:mergeinfo changed
- Property svn:eol-style set to native
-
code/trunk/visual_studio/vc8/ceguilua.vcproj
- Property svn:eol-style set to native
-
code/trunk/visual_studio/vc8/ceguilua.vsprops
- Property svn:mergeinfo changed
/code/branches/ceguilua/visual_studio/ceguilua_properties.vsprops reverse-merged: 1804 /code/branches/objecthierarchy/visual_studio/vc8/ceguilua.vsprops (added) merged: 2037,2040,2085 - Property svn:eol-style set to native
- Property svn:mergeinfo changed
-
code/trunk/visual_studio/vc8/core.vcproj
- Property svn:eol-style set to native
r1896 r2087 165 165 </File> 166 166 <File 167 RelativePath="..\..\src\core\Event.cc" 168 > 169 </File> 170 <File 167 171 RelativePath="..\..\src\core\GameState.cc" 168 172 > … … 173 177 </File> 174 178 <File 179 RelativePath="..\..\src\core\LuaBind.cc" 180 > 181 </File> 182 <File 175 183 RelativePath="..\..\src\core\OrxonoxClass.cc" 176 184 > … … 181 189 </File> 182 190 <File 183 RelativePath="..\..\src\core\Script.cc" 191 RelativePath="..\..\src\core\Template.cc" 192 > 193 </File> 194 <File 195 RelativePath="..\..\src\core\XMLNameListener.cc" 184 196 > 185 197 </File> … … 397 409 </File> 398 410 <File 411 RelativePath="..\..\src\core\Event.h" 412 > 413 </File> 414 <File 415 RelativePath="..\..\src\core\EventIncludes.h" 416 > 417 </File> 418 <File 399 419 RelativePath="..\..\src\core\GameState.h" 400 420 > … … 405 425 </File> 406 426 <File 427 RelativePath="..\..\src\core\LuaBind.h" 428 > 429 </File> 430 <File 407 431 RelativePath="..\..\src\core\OrxonoxClass.h" 408 432 > … … 413 437 </File> 414 438 <File 415 RelativePath="..\..\src\core\Script.h"416 >417 </File>418 <File419 439 RelativePath="..\..\src\core\Super.h" 420 440 > 421 441 </File> 422 442 <File 443 RelativePath="..\..\src\core\Template.h" 444 > 445 </File> 446 <File 423 447 RelativePath="..\..\src\core\XMLIncludes.h" 424 448 > 425 449 </File> 450 <File 451 RelativePath="..\..\src\core\XMLNameListener.h" 452 > 453 </File> 426 454 <Filter 427 455 Name="input" … … 596 624 </File> 597 625 <File 598 RelativePath="..\..\src\core\Level.h"599 >600 </File>601 <File602 626 RelativePath="..\..\src\core\Loader.h" 603 627 > … … 609 633 <File 610 634 RelativePath="..\..\src\core\NamespaceNode.h" 635 > 636 </File> 637 <File 638 RelativePath="..\..\src\core\XMLFile.h" 611 639 > 612 640 </File> -
code/trunk/visual_studio/vc8/core.vsprops
- Property svn:mergeinfo changed
/code/branches/objecthierarchy/visual_studio/vc8/core.vsprops (added) merged: 2037,2040,2085 - Property svn:eol-style set to native
- Property svn:mergeinfo changed
-
code/trunk/visual_studio/vc8/cpptcl.vcproj
- Property svn:eol-style set to native
-
code/trunk/visual_studio/vc8/cpptcl.vsprops
- Property svn:mergeinfo changed
/code/branches/objecthierarchy/visual_studio/vc8/cpptcl.vsprops (added) merged: 2037,2040,2085 - Property svn:eol-style set to native
- Property svn:mergeinfo changed
-
code/trunk/visual_studio/vc8/debug.vsprops
- Property svn:mergeinfo changed
/code/branches/objecthierarchy/visual_studio/vc8/debug.vsprops (added) merged: 2037,2040,2085 - Property svn:eol-style set to native
- Property svn:mergeinfo changed
-
code/trunk/visual_studio/vc8/directories.vsprops
- Property svn:mergeinfo changed
/code/branches/objecthierarchy/visual_studio/vc8/directories.vsprops (added) merged: 2017-2018,2037,2040,2085 - Property svn:eol-style set to native
- Property svn:mergeinfo changed
-
code/trunk/visual_studio/vc8/lua.vcproj
- Property svn:eol-style set to native
-
code/trunk/visual_studio/vc8/lua.vsprops
- Property svn:mergeinfo changed
/code/branches/ceguilua/visual_studio/lua_properties.vsprops reverse-merged: 1804 /code/branches/objecthierarchy/visual_studio/vc8/lua.vsprops (added) merged: 2037,2040,2085 - Property svn:eol-style set to native
- Property svn:mergeinfo changed
-
code/trunk/visual_studio/vc8/lua_static.vcproj
- Property svn:eol-style set to native
-
code/trunk/visual_studio/vc8/lua_static.vsprops
- Property svn:eol-style set to native
-
code/trunk/visual_studio/vc8/network.vcproj
- Property svn:eol-style set to native
r1909 r2087 18 18 <Configuration 19 19 Name="Debug|Win32" 20 ConfigurationType=" 4"20 ConfigurationType="2" 21 21 InheritedPropertySheets=".\debug.vsprops;.\network.vsprops" 22 22 CharacterSet="1" … … 50 50 /> 51 51 <Tool 52 Name="VCLi brarianTool"52 Name="VCLinkerTool" 53 53 /> 54 54 <Tool … … 56 56 /> 57 57 <Tool 58 Name="VCManifestTool" 59 /> 60 <Tool 58 61 Name="VCXDCMakeTool" 59 62 /> … … 63 66 <Tool 64 67 Name="VCFxCopTool" 68 /> 69 <Tool 70 Name="VCAppVerifierTool" 71 /> 72 <Tool 73 Name="VCWebDeploymentTool" 65 74 /> 66 75 <Tool … … 70 79 <Configuration 71 80 Name="Release|Win32" 72 ConfigurationType=" 4"81 ConfigurationType="2" 73 82 InheritedPropertySheets=".\release.vsprops;.\network.vsprops" 74 83 CharacterSet="1" … … 103 112 /> 104 113 <Tool 105 Name="VCLi brarianTool"114 Name="VCLinkerTool" 106 115 /> 107 116 <Tool … … 109 118 /> 110 119 <Tool 120 Name="VCManifestTool" 121 /> 122 <Tool 111 123 Name="VCXDCMakeTool" 112 124 /> … … 116 128 <Tool 117 129 Name="VCFxCopTool" 130 /> 131 <Tool 132 Name="VCAppVerifierTool" 133 /> 134 <Tool 135 Name="VCWebDeploymentTool" 118 136 /> 119 137 <Tool … … 131 149 > 132 150 <File 151 RelativePath="..\..\src\network\ChatListener.cc" 152 > 153 </File> 154 <File 133 155 RelativePath="..\..\src\network\Client.cc" 134 156 > … … 136 158 <File 137 159 RelativePath="..\..\src\network\ClientConnection.cc" 160 > 161 </File> 162 <File 163 RelativePath="..\..\src\network\ClientConnectionListener.cc" 138 164 > 139 165 </File> … … 213 239 > 214 240 <File 241 RelativePath="..\..\src\network\ChatListener.h" 242 > 243 </File> 244 <File 215 245 RelativePath="..\..\src\network\Client.h" 216 246 > … … 218 248 <File 219 249 RelativePath="..\..\src\network\ClientConnection.h" 250 > 251 </File> 252 <File 253 RelativePath="..\..\src\network\ClientConnectionListener.h" 220 254 > 221 255 </File> -
code/trunk/visual_studio/vc8/network.vsprops
- Property svn:mergeinfo changed
/code/branches/objecthierarchy/visual_studio/vc8/network.vsprops (added) merged: 1918,2037,2040,2085 - Property svn:eol-style set to native
r1842 r2087 9 9 Name="VCCLCompilerTool" 10 10 AdditionalOptions="/MP2" 11 PreprocessorDefinitions=" ORXONOX_NO_EXPORTS;NETWORK_STATIC_BUILD"11 PreprocessorDefinitions="NETWORK_SHARED_BUILD" 12 12 /> 13 13 <Tool - Property svn:mergeinfo changed
-
code/trunk/visual_studio/vc8/ois.vcproj
- Property svn:eol-style set to native
-
code/trunk/visual_studio/vc8/ois.vsprops
- Property svn:eol-style set to native
-
code/trunk/visual_studio/vc8/orxonox.vcproj
- Property svn:eol-style set to native
r1896 r2087 39 39 <Tool 40 40 Name="VCCLCompilerTool" 41 AdditionalOptions="/Zm200"42 41 /> 43 42 <Tool … … 103 102 <Tool 104 103 Name="VCCLCompilerTool" 105 AdditionalOptions="/Zm200"106 104 /> 107 105 <Tool … … 153 151 > 154 152 <File 153 RelativePath="..\..\src\orxonox\CameraManager.cc" 154 > 155 </File> 156 <File 155 157 RelativePath="..\..\src\orxonox\GraphicsEngine.cc" 158 > 159 </File> 160 <File 161 RelativePath="..\..\src\orxonox\LevelManager.cc" 156 162 > 157 163 </File> … … 184 190 > 185 191 </File> 186 <File187 RelativePath="..\..\src\orxonox\SignalHandler.cc"188 >189 </File>190 192 <Filter 191 193 Name="objects" 192 194 > 193 195 <File 194 RelativePath="..\..\src\orxonox\objects\Ambient.cc" 195 > 196 </File> 197 <File 198 RelativePath="..\..\src\orxonox\objects\Backlight.cc" 199 > 200 </File> 201 <File 202 RelativePath="..\..\src\orxonox\objects\BillboardProjectile.cc" 203 > 204 </File> 205 <File 206 RelativePath="..\..\src\orxonox\objects\Camera.cc" 207 > 208 </File> 209 <File 210 RelativePath="..\..\src\orxonox\objects\CameraHandler.cc" 211 > 212 </File> 213 <File 214 RelativePath="..\..\src\orxonox\objects\Model.cc" 215 > 216 </File> 217 <File 218 RelativePath="..\..\src\orxonox\objects\NPC.cc" 219 > 220 </File> 221 <File 222 RelativePath="..\..\src\orxonox\objects\ParticleProjectile.cc" 223 > 224 </File> 225 <File 226 RelativePath="..\..\src\orxonox\objects\ParticleSpawner.cc" 227 > 228 </File> 229 <File 230 RelativePath="..\..\src\orxonox\objects\Projectile.cc" 196 RelativePath="..\..\src\orxonox\objects\EventDispatcher.cc" 197 > 198 </File> 199 <File 200 RelativePath="..\..\src\orxonox\objects\EventListener.cc" 201 > 202 </File> 203 <File 204 RelativePath="..\..\src\orxonox\objects\EventTarget.cc" 231 205 > 232 206 </File> … … 234 208 RelativePath="..\..\src\orxonox\objects\Radar.cc" 235 209 > 236 <FileConfiguration237 Name="Debug|Win32"238 >239 <Tool240 Name="VCCLCompilerTool"241 ObjectFile="$(IntDir)\$(InputName)1.obj"242 XMLDocumentationFileName="$(IntDir)\$(InputName)1.xdc"243 />244 </FileConfiguration>245 <FileConfiguration246 Name="Release|Win32"247 >248 <Tool249 Name="VCCLCompilerTool"250 ObjectFile="$(IntDir)\$(InputName)1.obj"251 XMLDocumentationFileName="$(IntDir)\$(InputName)1.xdc"252 />253 </FileConfiguration>254 210 </File> 255 211 <File 256 212 RelativePath="..\..\src\orxonox\objects\RadarListener.cc" 257 213 > 258 <FileConfiguration259 Name="Debug|Win32"260 >261 <Tool262 Name="VCCLCompilerTool"263 ObjectFile="$(IntDir)\$(InputName)1.obj"264 XMLDocumentationFileName="$(IntDir)\$(InputName)1.xdc"265 />266 </FileConfiguration>267 <FileConfiguration268 Name="Release|Win32"269 >270 <Tool271 Name="VCCLCompilerTool"272 ObjectFile="$(IntDir)\$(InputName)1.obj"273 XMLDocumentationFileName="$(IntDir)\$(InputName)1.xdc"274 />275 </FileConfiguration>276 214 </File> 277 215 <File … … 280 218 </File> 281 219 <File 282 RelativePath="..\..\src\orxonox\objects\RotatingProjectile.cc" 283 > 284 </File> 285 <File 286 RelativePath="..\..\src\orxonox\objects\Skybox.cc" 287 > 288 </File> 289 <File 290 RelativePath="..\..\src\orxonox\objects\SpaceShip.cc" 291 > 292 </File> 293 <File 294 RelativePath="..\..\src\orxonox\objects\SpaceShipAI.cc" 220 RelativePath="..\..\src\orxonox\objects\Scene.cc" 221 > 222 </File> 223 <File 224 RelativePath="..\..\src\orxonox\objects\Script.cc" 225 > 226 </File> 227 <File 228 RelativePath="..\..\src\orxonox\objects\Test.cc" 295 229 > 296 230 </File> … … 299 233 > 300 234 </File> 301 <File 302 RelativePath="..\..\src\orxonox\objects\WorldEntity.cc" 303 > 304 </File> 235 <Filter 236 Name="worldentities" 237 > 238 <File 239 RelativePath="..\..\src\orxonox\objects\worldentities\Backlight.cc" 240 > 241 <FileConfiguration 242 Name="Debug|Win32" 243 ExcludedFromBuild="true" 244 > 245 <Tool 246 Name="VCCLCompilerTool" 247 /> 248 </FileConfiguration> 249 <FileConfiguration 250 Name="Release|Win32" 251 ExcludedFromBuild="true" 252 > 253 <Tool 254 Name="VCCLCompilerTool" 255 /> 256 </FileConfiguration> 257 </File> 258 <File 259 RelativePath="..\..\src\orxonox\objects\worldentities\Billboard.cc" 260 > 261 </File> 262 <File 263 RelativePath="..\..\src\orxonox\objects\worldentities\BlinkingBillboard.cc" 264 > 265 </File> 266 <File 267 RelativePath="..\..\src\orxonox\objects\worldentities\Camera.cc" 268 > 269 </File> 270 <File 271 RelativePath="..\..\src\orxonox\objects\worldentities\CameraPosition.cc" 272 > 273 </File> 274 <File 275 RelativePath="..\..\src\orxonox\objects\worldentities\ControllableEntity.cc" 276 > 277 </File> 278 <File 279 RelativePath="..\..\src\orxonox\objects\worldentities\Light.cc" 280 > 281 </File> 282 <File 283 RelativePath="..\..\src\orxonox\objects\worldentities\Model.cc" 284 > 285 </File> 286 <File 287 RelativePath="..\..\src\orxonox\objects\worldentities\MovableEntity.cc" 288 > 289 </File> 290 <File 291 RelativePath="..\..\src\orxonox\objects\worldentities\ParticleEmitter.cc" 292 > 293 </File> 294 <File 295 RelativePath="..\..\src\orxonox\objects\worldentities\ParticleSpawner.cc" 296 > 297 </File> 298 <File 299 RelativePath="..\..\src\orxonox\objects\worldentities\PositionableEntity.cc" 300 > 301 </File> 302 <File 303 RelativePath="..\..\src\orxonox\objects\worldentities\SpawnPoint.cc" 304 > 305 </File> 306 <File 307 RelativePath="..\..\src\orxonox\objects\worldentities\WorldEntity.cc" 308 > 309 </File> 310 <Filter 311 Name="pawns" 312 > 313 <File 314 RelativePath="..\..\src\orxonox\objects\worldentities\pawns\Pawn.cc" 315 > 316 </File> 317 <File 318 RelativePath="..\..\src\orxonox\objects\worldentities\pawns\SpaceShip.cc" 319 > 320 </File> 321 <File 322 RelativePath="..\..\src\orxonox\objects\worldentities\pawns\Spectator.cc" 323 > 324 </File> 325 </Filter> 326 <Filter 327 Name="triggers" 328 > 329 <File 330 RelativePath="..\..\src\orxonox\objects\worldentities\triggers\DistanceTrigger.cc" 331 > 332 </File> 333 <File 334 RelativePath="..\..\src\orxonox\objects\worldentities\triggers\EventTrigger.cc" 335 > 336 </File> 337 <File 338 RelativePath="..\..\src\orxonox\objects\worldentities\triggers\Trigger.cc" 339 > 340 </File> 341 </Filter> 342 </Filter> 343 <Filter 344 Name="gametypes" 345 > 346 <File 347 RelativePath="..\..\src\orxonox\objects\gametypes\Gametype.cc" 348 > 349 </File> 350 </Filter> 351 <Filter 352 Name="infos" 353 > 354 <File 355 RelativePath="..\..\src\orxonox\objects\infos\HumanPlayer.cc" 356 > 357 </File> 358 <File 359 RelativePath="..\..\src\orxonox\objects\infos\Info.cc" 360 > 361 </File> 362 <File 363 RelativePath="..\..\src\orxonox\objects\infos\Level.cc" 364 > 365 </File> 366 <File 367 RelativePath="..\..\src\orxonox\objects\infos\PlayerInfo.cc" 368 > 369 </File> 370 </Filter> 371 <Filter 372 Name="controllers" 373 > 374 <File 375 RelativePath="..\..\src\orxonox\objects\controllers\Controller.cc" 376 > 377 </File> 378 <File 379 RelativePath="..\..\src\orxonox\objects\controllers\HumanController.cc" 380 > 381 </File> 382 </Filter> 305 383 </Filter> 306 384 <Filter … … 309 387 <File 310 388 RelativePath="..\..\src\orxonox\tools\BillboardSet.cc" 311 >312 </File>313 <File314 RelativePath="..\..\src\orxonox\tools\Light.cc"315 389 > 316 390 </File> … … 413 487 > 414 488 <File 489 RelativePath="..\..\src\orxonox\overlays\hud\ChatOverlay.cc" 490 > 491 </File> 492 <File 415 493 RelativePath="..\..\src\orxonox\overlays\hud\HUDBar.cc" 416 494 > … … 452 530 RelativePath="..\..\src\orxonox\gui\OgreCEGUIRenderer.cpp" 453 531 > 454 <FileConfiguration455 Name="Debug|Win32"456 >457 <Tool458 Name="VCCLCompilerTool"459 UsePrecompiledHeader="0"460 />461 </FileConfiguration>462 <FileConfiguration463 Name="Release|Win32"464 >465 <Tool466 Name="VCCLCompilerTool"467 UsePrecompiledHeader="0"468 />469 </FileConfiguration>470 532 </File> 471 533 <File 472 534 RelativePath="..\..\src\orxonox\gui\OgreCEGUIResourceProvider.cpp" 473 535 > 474 <FileConfiguration475 Name="Debug|Win32"476 >477 <Tool478 Name="VCCLCompilerTool"479 UsePrecompiledHeader="0"480 />481 </FileConfiguration>482 <FileConfiguration483 Name="Release|Win32"484 >485 <Tool486 Name="VCCLCompilerTool"487 UsePrecompiledHeader="0"488 />489 </FileConfiguration>490 536 </File> 491 537 <File 492 538 RelativePath="..\..\src\orxonox\gui\OgreCEGUITexture.cpp" 493 539 > 494 <FileConfiguration495 Name="Debug|Win32"496 >497 <Tool498 Name="VCCLCompilerTool"499 UsePrecompiledHeader="0"500 />501 </FileConfiguration>502 <FileConfiguration503 Name="Release|Win32"504 >505 <Tool506 Name="VCCLCompilerTool"507 UsePrecompiledHeader="0"508 />509 </FileConfiguration>510 540 </File> 511 541 </Filter> … … 557 587 > 558 588 <File 589 RelativePath="..\..\src\orxonox\CameraManager.h" 590 > 591 </File> 592 <File 559 593 RelativePath="..\..\src\orxonox\GraphicsEngine.h" 560 594 > 561 595 </File> 562 596 <File 597 RelativePath="..\..\src\orxonox\LevelManager.h" 598 > 599 </File> 600 <File 563 601 RelativePath="..\..\src\orxonox\OrxonoxPrereqs.h" 564 602 > … … 572 610 > 573 611 </File> 574 <File575 RelativePath="..\..\src\orxonox\SignalHandler.h"576 >577 </File>578 612 <Filter 579 613 Name="objects" 580 614 > 581 615 <File 582 RelativePath="..\..\src\orxonox\objects\Ambient.h" 583 > 584 </File> 585 <File 586 RelativePath="..\..\src\orxonox\objects\Backlight.h" 587 > 588 </File> 589 <File 590 RelativePath="..\..\src\orxonox\objects\BillboardProjectile.h" 591 > 592 </File> 593 <File 594 RelativePath="..\..\src\orxonox\objects\Camera.h" 595 > 596 </File> 597 <File 598 RelativePath="..\..\src\orxonox\objects\CameraHandler.h" 599 > 600 </File> 601 <File 602 RelativePath="..\..\src\orxonox\objects\Model.h" 603 > 604 </File> 605 <File 606 RelativePath="..\..\src\orxonox\objects\NPC.h" 607 > 608 </File> 609 <File 610 RelativePath="..\..\src\orxonox\objects\ParticleProjectile.h" 611 > 612 </File> 613 <File 614 RelativePath="..\..\src\orxonox\objects\ParticleSpawner.h" 615 > 616 </File> 617 <File 618 RelativePath="..\..\src\orxonox\objects\Projectile.h" 616 RelativePath="..\..\src\orxonox\objects\EventDispatcher.h" 617 > 618 </File> 619 <File 620 RelativePath="..\..\src\orxonox\objects\EventListener.h" 621 > 622 </File> 623 <File 624 RelativePath="..\..\src\orxonox\objects\EventTarget.h" 619 625 > 620 626 </File> … … 632 638 </File> 633 639 <File 634 RelativePath="..\..\src\orxonox\objects\RotatingProjectile.h" 635 > 636 </File> 637 <File 638 RelativePath="..\..\src\orxonox\objects\Skybox.h" 639 > 640 </File> 641 <File 642 RelativePath="..\..\src\orxonox\objects\SpaceShip.h" 643 > 644 </File> 645 <File 646 RelativePath="..\..\src\orxonox\objects\SpaceShipAI.h" 640 RelativePath="..\..\src\orxonox\objects\Scene.h" 641 > 642 </File> 643 <File 644 RelativePath="..\..\src\orxonox\objects\Script.h" 645 > 646 </File> 647 <File 648 RelativePath="..\..\src\orxonox\objects\Test.h" 647 649 > 648 650 </File> … … 651 653 > 652 654 </File> 653 <File 654 RelativePath="..\..\src\orxonox\objects\WorldEntity.h" 655 > 656 </File> 655 <Filter 656 Name="worldentities" 657 > 658 <File 659 RelativePath="..\..\src\orxonox\objects\worldentities\Backlight.h" 660 > 661 </File> 662 <File 663 RelativePath="..\..\src\orxonox\objects\worldentities\Billboard.h" 664 > 665 </File> 666 <File 667 RelativePath="..\..\src\orxonox\objects\worldentities\BlinkingBillboard.h" 668 > 669 </File> 670 <File 671 RelativePath="..\..\src\orxonox\objects\worldentities\Camera.h" 672 > 673 </File> 674 <File 675 RelativePath="..\..\src\orxonox\objects\worldentities\CameraPosition.h" 676 > 677 </File> 678 <File 679 RelativePath="..\..\src\orxonox\objects\worldentities\ControllableEntity.h" 680 > 681 </File> 682 <File 683 RelativePath="..\..\src\orxonox\objects\worldentities\Light.h" 684 > 685 </File> 686 <File 687 RelativePath="..\..\src\orxonox\objects\worldentities\Model.h" 688 > 689 </File> 690 <File 691 RelativePath="..\..\src\orxonox\objects\worldentities\MovableEntity.h" 692 > 693 </File> 694 <File 695 RelativePath="..\..\src\orxonox\objects\worldentities\ParticleEmitter.h" 696 > 697 </File> 698 <File 699 RelativePath="..\..\src\orxonox\objects\worldentities\ParticleSpawner.h" 700 > 701 </File> 702 <File 703 RelativePath="..\..\src\orxonox\objects\worldentities\PositionableEntity.h" 704 > 705 </File> 706 <File 707 RelativePath="..\..\src\orxonox\objects\worldentities\SpawnPoint.h" 708 > 709 </File> 710 <File 711 RelativePath="..\..\src\orxonox\objects\worldentities\WorldEntity.h" 712 > 713 </File> 714 <Filter 715 Name="pawns" 716 > 717 <File 718 RelativePath="..\..\src\orxonox\objects\worldentities\pawns\Pawn.h" 719 > 720 </File> 721 <File 722 RelativePath="..\..\src\orxonox\objects\worldentities\pawns\SpaceShip.h" 723 > 724 </File> 725 <File 726 RelativePath="..\..\src\orxonox\objects\worldentities\pawns\Spectator.h" 727 > 728 </File> 729 </Filter> 730 <Filter 731 Name="triggers" 732 > 733 <File 734 RelativePath="..\..\src\orxonox\objects\worldentities\triggers\DistanceTrigger.h" 735 > 736 </File> 737 <File 738 RelativePath="..\..\src\orxonox\objects\worldentities\triggers\EventTrigger.h" 739 > 740 </File> 741 <File 742 RelativePath="..\..\src\orxonox\objects\worldentities\triggers\Trigger.h" 743 > 744 </File> 745 </Filter> 746 </Filter> 747 <Filter 748 Name="gametypes" 749 > 750 <File 751 RelativePath="..\..\src\orxonox\objects\gametypes\Gametype.h" 752 > 753 </File> 754 </Filter> 755 <Filter 756 Name="infos" 757 > 758 <File 759 RelativePath="..\..\src\orxonox\objects\infos\Info.h" 760 > 761 </File> 762 <File 763 RelativePath="..\..\src\orxonox\objects\infos\Level.h" 764 > 765 </File> 766 <File 767 RelativePath="..\..\src\orxonox\objects\infos\PlayerInfo.h" 768 > 769 </File> 770 </Filter> 771 <Filter 772 Name="controllers" 773 > 774 <File 775 RelativePath="..\..\src\orxonox\objects\controllers\Controller.h" 776 > 777 </File> 778 <File 779 RelativePath="..\..\src\orxonox\objects\controllers\HumanController.h" 780 > 781 </File> 782 </Filter> 657 783 </Filter> 658 784 <Filter … … 664 790 </File> 665 791 <File 666 RelativePath="..\..\src\orxonox\tools\Light.h"667 >668 </File>669 <File670 792 RelativePath="..\..\src\orxonox\tools\Mesh.h" 671 793 > … … 714 836 Name="hud" 715 837 > 838 <File 839 RelativePath="..\..\src\orxonox\overlays\hud\ChatOverlay.h" 840 > 841 </File> 716 842 <File 717 843 RelativePath="..\..\src\orxonox\overlays\hud\HUDBar.h" -
code/trunk/visual_studio/vc8/orxonox.vcproj.user
- Property svn:eol-style set to native
-
code/trunk/visual_studio/vc8/orxonox.vsprops
- Property svn:mergeinfo changed
/code/branches/objecthierarchy/visual_studio/vc8/orxonox.vsprops (added) merged: 1918,2013,2037,2040,2085 - Property svn:eol-style set to native
r1897 r2087 8 8 <Tool 9 9 Name="VCCLCompilerTool" 10 AdditionalOptions="/MP2 "11 PreprocessorDefinitions="ORXONOX_NO_EXPORTS; NETWORK_STATIC_BUILD;LUA_BUILD_AS_DLL"10 AdditionalOptions="/MP2 /Zm200" 11 PreprocessorDefinitions="ORXONOX_NO_EXPORTS;ORXONOX_ENABLE_PCH;LUA_BUILD_AS_DLL" 12 12 UsePrecompiledHeader="2" 13 13 PrecompiledHeaderThrough="OrxonoxStableHeaders.h" … … 22 22 Name="VCPostBuildEventTool" 23 23 Description="Copying files from init folder..." 24 CommandLine="for %%a in ($(RootDir)\init\$(SolutionName)\$(ConfigurationName)\*) do replace %%a $(OutDir). /A >nul
for %%a in ($(RootDir)\init\common\*) do replace %%a $(OutDir). /A >nul "24 CommandLine="for %%a in ($(RootDir)\init\$(SolutionName)\$(ConfigurationName)\*) do replace %%a $(OutDir). /A >nul
for %%a in ($(RootDir)\init\common\*) do replace %%a $(OutDir). /A >nul
" 25 25 /> 26 26 </VisualStudioPropertySheet> - Property svn:mergeinfo changed
-
code/trunk/visual_studio/vc8/orxonox_vc8.sln
- Property svn:mergeinfo changed
/code/branches/objecthierarchy/visual_studio/vc8/orxonox_vc8.sln (added) merged: 2037,2040,2085 - Property svn:eol-style set to native
- Property svn:mergeinfo changed
-
code/trunk/visual_studio/vc8/release.vsprops
- Property svn:mergeinfo changed
/code/branches/objecthierarchy/visual_studio/vc8/release.vsprops (added) merged: 2037,2040,2085 - Property svn:eol-style set to native
- Property svn:mergeinfo changed
-
code/trunk/visual_studio/vc8/tinyxml.vcproj
- Property svn:mergeinfo changed
/code/branches/objecthierarchy/visual_studio/vc8/tinyxml.vcproj (added) merged: 2037,2040,2085 - Property svn:eol-style set to native
- Property svn:mergeinfo changed
-
code/trunk/visual_studio/vc8/tinyxml.vsprops
- Property svn:mergeinfo changed
/code/branches/objecthierarchy/visual_studio/vc8/tinyxml.vsprops (added) merged: 2037,2040,2085 - Property svn:eol-style set to native
- Property svn:mergeinfo changed
-
code/trunk/visual_studio/vc8/tolua.vcproj
- Property svn:eol-style set to native
-
code/trunk/visual_studio/vc8/tolua.vsprops
- Property svn:mergeinfo changed
/code/branches/objecthierarchy/visual_studio/vc8/tolua.vsprops (added) merged: 2037,2040,2085 - Property svn:eol-style set to native
- Property svn:mergeinfo changed
-
code/trunk/visual_studio/vc8/tolua_static.vcproj
- Property svn:eol-style set to native
-
code/trunk/visual_studio/vc8/tolua_static.vsprops
- Property svn:eol-style set to native
-
code/trunk/visual_studio/vc8/toluagen.vcproj
- Property svn:mergeinfo changed
/code/branches/gui/visual_studio/vc8/tolua_gen.vcproj reverse-merged: 1638 /code/branches/objecthierarchy/visual_studio/vc8/toluagen.vcproj (added) merged: 2037,2040,2085 - Property svn:eol-style set to native
- Property svn:mergeinfo changed
-
code/trunk/visual_studio/vc8/toluagen.vsprops
- Property svn:mergeinfo changed
/code/branches/gui/visual_studio/tolua_gen_properties.vsprops reverse-merged: 1638 /code/branches/objecthierarchy/visual_studio/vc8/toluagen.vsprops (added) merged: 2037,2040,2085 - Property svn:eol-style set to native
- Property svn:mergeinfo changed
-
code/trunk/visual_studio/vc8/toluagen_orxonox.vcproj
- Property svn:mergeinfo changed
/code/branches/objecthierarchy/visual_studio/vc8/toluagen_orxonox.vcproj (added) merged: 2037,2040,2085 - Property svn:eol-style set to native
- Property svn:mergeinfo changed
-
code/trunk/visual_studio/vc8/toluagen_orxonox.vsprops
- Property svn:mergeinfo changed
/code/branches/objecthierarchy/visual_studio/vc8/toluagen_orxonox.vsprops (added) merged: 2037,2040,2085 - Property svn:eol-style set to native
- Property svn:mergeinfo changed
-
code/trunk/visual_studio/vc8/util.vcproj
- Property svn:eol-style set to native
r1841 r2087 181 181 </File> 182 182 <File 183 RelativePath="..\..\src\util\SignalHandler.cc" 184 > 185 </File> 186 <File 183 187 RelativePath="..\..\src\util\String.cc" 184 188 > … … 227 231 </File> 228 232 <File 233 RelativePath="..\..\src\util\MathConvert.h" 234 > 235 </File> 236 <File 229 237 RelativePath="..\..\src\util\MultiType.h" 230 238 > … … 244 252 <File 245 253 RelativePath="..\..\src\util\OutputHandler.h" 254 > 255 </File> 256 <File 257 RelativePath="..\..\src\util\SignalHandler.h" 246 258 > 247 259 </File> -
code/trunk/visual_studio/vc8/util.vsprops
- Property svn:mergeinfo changed
/code/branches/objecthierarchy/visual_studio/vc8/util.vsprops (added) merged: 2037,2040,2085 - Property svn:eol-style set to native
- Property svn:mergeinfo changed
Note: See TracChangeset
for help on using the changeset viewer.