Changeset 2662 for code/trunk/src/core
- Timestamp:
- Feb 14, 2009, 10:17:35 PM (16 years ago)
- Location:
- code/trunk
- Files:
-
- 45 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/core/BaseObject.cc
r2171 r2662 36 36 #include "CoreIncludes.h" 37 37 #include "EventIncludes.h" 38 #include "Functor.h" 38 39 #include "XMLPort.h" 39 40 #include "XMLFile.h" … … 60 61 this->oldGametype_ = 0; 61 62 63 this->lastLoadedXMLElement_ = 0; 64 65 this->functorSetMainState_ = 0; 66 this->functorGetMainState_ = 0; 67 62 68 this->setCreator(creator); 63 69 if (this->creator_) … … 82 88 BaseObject::~BaseObject() 83 89 { 84 for (std::list<BaseObject*>::const_iterator it = this->events_.begin(); it != this->events_.end(); ++it) 85 (*it)->unregisterEventListener(this); 86 87 for (std::map<BaseObject*, std::string>::const_iterator it = this->eventListeners_.begin(); it != this->eventListeners_.end(); ++it) 88 it->first->removeEvent(this); 90 if (this->isInitialized()) 91 { 92 for (std::list<BaseObject*>::const_iterator it = this->events_.begin(); it != this->events_.end(); ++it) 93 (*it)->unregisterEventListener(this); 94 95 for (std::map<BaseObject*, std::string>::const_iterator it = this->eventListeners_.begin(); it != this->eventListeners_.end(); ++it) 96 it->first->removeEvent(this); 97 98 if (this->functorSetMainState_) 99 delete this->functorSetMainState_; 100 if (this->functorGetMainState_) 101 delete this->functorGetMainState_; 102 } 89 103 } 90 104 … … 100 114 XMLPortParam(BaseObject, "visible", setVisible, isVisible, xmlelement, mode); 101 115 XMLPortParam(BaseObject, "active", setActive, isActive, xmlelement, mode); 116 XMLPortParam(BaseObject, "mainstate", setMainStateName, getMainStateName, xmlelement, mode); 102 117 103 118 XMLPortObjectTemplate(BaseObject, Template, "templates", addTemplate, getTemplate, xmlelement, mode, Template*); … … 109 124 std::list<std::string> eventnames; 110 125 111 if (mode == XMLPort::LoadObject )126 if (mode == XMLPort::LoadObject || mode == XMLPort::ExpandObject) 112 127 { 113 128 for (ticpp::Iterator<ticpp::Element> child = events->FirstChildElement(false); child != child.end(); child++) … … 279 294 SetEvent(BaseObject, "visibility", setVisible, event); 280 295 } 296 297 void BaseObject::setMainStateName(const std::string& name) 298 { 299 if (this->mainStateName_ != name) 300 { 301 this->mainStateName_ = name; 302 if (this->functorSetMainState_) 303 delete this->functorSetMainState_; 304 if (this->functorGetMainState_) 305 delete this->functorGetMainState_; 306 this->changedMainState(); 307 if (!this->functorSetMainState_) 308 COUT(2) << "Warning: \"" << name << "\" is not a valid MainState." << std::endl; 309 } 310 } 311 312 void BaseObject::setMainState(bool state) 313 { 314 if (this->functorSetMainState_) 315 (*this->functorSetMainState_)(state); 316 else 317 COUT(2) << "Warning: No MainState defined in object \"" << this->getName() << "\" (" << this->getIdentifier()->getName() << ")" << std::endl; 318 } 319 320 bool BaseObject::getMainState() const 321 { 322 if (this->functorGetMainState_) 323 { 324 (*this->functorGetMainState_)(); 325 return this->functorGetMainState_->getReturnvalue(); 326 } 327 else 328 { 329 COUT(2) << "Warning: No MainState defined in object \"" << this->getName() << "\" (" << this->getIdentifier()->getName() << ")" << std::endl; 330 return false; 331 } 332 } 333 334 void BaseObject::changedMainState() 335 { 336 SetMainState(BaseObject, "activity", setActive, isActive); 337 SetMainState(BaseObject, "visibility", setVisible, isVisible); 338 } 281 339 } -
code/trunk/src/core/BaseObject.h
r2171 r2662 36 36 #ifndef _BaseObject_H__ 37 37 #define _BaseObject_H__ 38 39 #define SetMainState(classname, statename, setfunction, getfunction) \ 40 if (this->getMainStateName() == statename) \ 41 { \ 42 this->functorSetMainState_ = createFunctor(&classname::setfunction)->setObject(this); \ 43 this->functorGetMainState_ = createFunctor(&classname::getfunction)->setObject(this); \ 44 } 38 45 39 46 #include <map> … … 55 62 class _CoreExport BaseObject : virtual public OrxonoxClass 56 63 { 64 template <class T> friend class XMLPortClassParamContainer; 65 57 66 public: 58 67 BaseObject(BaseObject* creator); … … 100 109 virtual void changedVisibility() {} 101 110 111 void setMainState(bool state); 112 bool getMainState() const; 113 114 void setMainStateName(const std::string& name); 115 inline const std::string& getMainStateName() const { return this->mainStateName_; } 116 virtual void changedMainState(); 117 102 118 /** @brief Sets a pointer to the xml file that loaded this object. @param file The pointer to the XMLFile */ 103 119 inline void setFile(const XMLFile* file) { this->file_ = file; } … … 121 137 inline Scene* getScene() const { return this->scene_; } 122 138 123 inline void setGametype(Gametype* gametype) { this->oldGametype_ = this->gametype_; this->gametype_ = gametype; this->changedGametype(); } 139 inline void setGametype(Gametype* gametype) 140 { 141 if (gametype != this->gametype_) 142 { 143 this->oldGametype_ = this->gametype_; 144 this->gametype_ = gametype; 145 this->changedGametype(); 146 } 147 } 124 148 inline Gametype* getGametype() const { return this->gametype_; } 125 149 inline Gametype* getOldGametype() const { return this->oldGametype_; } 126 virtual inlinevoid changedGametype() {}150 virtual void changedGametype() {} 127 151 128 152 void fireEvent(); … … 151 175 152 176 protected: 153 std::string name_; //!< The name of the object 154 std::string oldName_; //!< The old name of the object 155 mbool bActive_; //!< True = the object is active 156 mbool bVisible_; //!< True = the object is visible 177 std::string name_; //!< The name of the object 178 std::string oldName_; //!< The old name of the object 179 mbool bActive_; //!< True = the object is active 180 mbool bVisible_; //!< True = the object is visible 181 std::string mainStateName_; 182 Functor* functorSetMainState_; 183 Functor* functorGetMainState_; 157 184 158 185 private: … … 160 187 Template* getTemplate(unsigned int index) const; 161 188 162 bool bInitialized_; //!< True if the object was initialized (passed the object registration) 163 const XMLFile* file_; //!< The XMLFile that loaded this object 164 std::string loaderIndentation_; //!< Indentation of the debug output in the Loader 165 Namespace* namespace_; 166 BaseObject* creator_; 167 Scene* scene_; 168 Gametype* gametype_; 169 Gametype* oldGametype_; 170 std::set<Template*> templates_; 171 std::map<BaseObject*, std::string> eventListeners_; 189 bool bInitialized_; //!< True if the object was initialized (passed the object registration) 190 const XMLFile* file_; //!< The XMLFile that loaded this object 191 Element* lastLoadedXMLElement_; //!< Non 0 if the TinyXML attributes have already been copied to our own lowercase map 192 std::map<std::string, std::string> xmlAttributes_; //!< Lowercase XML attributes 193 std::string loaderIndentation_; //!< Indentation of the debug output in the Loader 194 Namespace* namespace_; 195 BaseObject* creator_; 196 Scene* scene_; 197 Gametype* gametype_; 198 Gametype* oldGametype_; 199 std::set<Template*> templates_; 200 std::map<BaseObject*, std::string> eventListeners_; 172 201 std::list<BaseObject*> events_; 173 202 std::map<std::string, EventContainer*> eventContainers_; … … 178 207 SUPER_FUNCTION(3, BaseObject, changedVisibility, false); 179 208 SUPER_FUNCTION(4, BaseObject, processEvent, false); 209 SUPER_FUNCTION(6, BaseObject, changedMainState, false); 210 SUPER_FUNCTION(9, BaseObject, changedName, false); 211 SUPER_FUNCTION(10, BaseObject, changedGametype, false); 180 212 } 181 213 -
code/trunk/src/core/CommandExecutor.cc
r1784 r2662 53 53 } 54 54 55 ConsoleCommand& CommandExecutor::addConsoleCommandShortcut(ConsoleCommand* command )55 ConsoleCommand& CommandExecutor::addConsoleCommandShortcut(ConsoleCommand* command, bool bDeleteAtExit) 56 56 { 57 57 std::map<std::string, ConsoleCommand*>::const_iterator it = CommandExecutor::getInstance().consoleCommandShortcuts_.find(command->getName()); … … 61 61 } 62 62 63 // Make sure we can also delete the external ConsoleCommands that don't belong to an Identifier 64 if (command && bDeleteAtExit) 65 { 66 CommandExecutor::getInstance().consoleCommandExternals_.insert(command); 67 } 63 68 64 69 CommandExecutor::getInstance().consoleCommandShortcuts_[command->getName()] = command; … … 647 652 } 648 653 } 654 655 void CommandExecutor::destroyExternalCommands() 656 { 657 for (std::set<ConsoleCommand*>::const_iterator it = CommandExecutor::getInstance().consoleCommandExternals_.begin(); 658 it != CommandExecutor::getInstance().consoleCommandExternals_.end(); ++it) 659 delete *it; 660 } 649 661 } -
code/trunk/src/core/CommandExecutor.h
r1771 r2662 51 51 static const CommandEvaluation& getLastEvaluation(); 52 52 53 static ConsoleCommand& addConsoleCommandShortcut(ConsoleCommand* command );53 static ConsoleCommand& addConsoleCommandShortcut(ConsoleCommand* command, bool bDeleteAtExit = false); 54 54 static ConsoleCommand* getConsoleCommandShortcut(const std::string& name); 55 55 static ConsoleCommand* getLowercaseConsoleCommandShortcut(const std::string& name); … … 68 68 /** @brief Returns a const_iterator to the end of the map that stores all console commands with their names in lowercase. @return The const_iterator */ 69 69 static inline std::map<std::string, ConsoleCommand*>::const_iterator getLowercaseConsoleCommandShortcutMapEnd() { return CommandExecutor::getInstance().consoleCommandShortcuts_LC_.end(); } 70 71 static void destroyExternalCommands(); 70 72 71 73 private: … … 101 103 std::map<std::string, ConsoleCommand*> consoleCommandShortcuts_; 102 104 std::map<std::string, ConsoleCommand*> consoleCommandShortcuts_LC_; 105 std::set<ConsoleCommand*> consoleCommandExternals_; 103 106 }; // tolua_export 104 107 } // tolua_export -
code/trunk/src/core/CommandLine.cc
r2105 r2662 83 83 CommandLine::~CommandLine() 84 84 { 85 for (std::map<std::string, CommandLineArgument*>::const_iterator it = cmdLineArgs_.begin(); 86 it != cmdLineArgs_.end(); ++it) 87 { 88 delete it->second; 89 } 85 CommandLine::destroyAllArguments(); 90 86 } 91 87 … … 98 94 static CommandLine instance; 99 95 return instance; 96 } 97 98 /** 99 @brief 100 Destroys all command line arguments. This should be called at the end 101 of main. Do not use before that. 102 */ 103 void CommandLine::destroyAllArguments() 104 { 105 for (std::map<std::string, CommandLineArgument*>::const_iterator it = _getInstance().cmdLineArgs_.begin(); 106 it != _getInstance().cmdLineArgs_.end(); ++it) 107 delete it->second; 108 _getInstance().cmdLineArgs_.clear(); 100 109 } 101 110 -
code/trunk/src/core/CommandLine.h
r2103 r2662 155 155 } 156 156 157 static void destroyAllArguments(); 157 158 158 159 private: … … 179 180 //! Holds all pointers to the arguments and serves as a search map by name. 180 181 std::map<std::string, CommandLineArgument*> cmdLineArgs_; 181 //! Search map by chortcut for the arguments.182 //! Search map by shortcut for the arguments. 182 183 std::map<std::string, CommandLineArgument*> cmdLineArgsShortcut_; 183 184 }; -
code/trunk/src/core/ConfigFileManager.cc
r2103 r2662 160 160 if ((*it)->getIndex() > size) 161 161 size = (*it)->getIndex(); 162 return (size + 1); 162 if (size == 0) 163 return 0; 164 else 165 return (size + 1); 163 166 } 164 167 -
code/trunk/src/core/ConfigFileManager.h
r2103 r2662 38 38 39 39 #include "util/Math.h" 40 #include "util/OrxEnum.h" 40 41 41 42 namespace orxonox 42 43 { 43 // Use unsigned int as config file type to have an arbitrary number of files 44 class ConfigFileType 45 { 46 public: 47 ConfigFileType() { } 48 ConfigFileType(unsigned int type) { type_ = type; } 49 ConfigFileType(const ConfigFileType& instance) { type_ = instance.type_; } 50 51 operator unsigned int() { return type_; } 52 ConfigFileType& operator =(unsigned int type) { type_ = type; return *this; } 53 bool operator <(const ConfigFileType& right) const { return (type_ < right.type_); } 54 55 /* *** Put the different config file types here *** */ 56 static const unsigned int NoType = 0; 57 static const unsigned int Settings = 1; 58 static const unsigned int JoyStickCalibration = 2; 59 60 static const unsigned int numberOfReservedTypes = 1024; 61 62 private: 63 unsigned int type_; 44 // Use int as config file type to have an arbitrary number of files 45 struct ConfigFileType : OrxEnum<ConfigFileType> 46 { 47 OrxEnumConstructors(ConfigFileType); 48 49 static const int NoType = 0; 50 static const int Settings = 1; 51 static const int JoyStickCalibration = 2; 52 53 static const int numberOfReservedTypes = 1024; 64 54 }; 65 55 -
code/trunk/src/core/ConfigValueContainer.cc
r2171 r2662 273 273 { 274 274 this->valueVector_.clear(); 275 for (unsigned int i = 0; i < ConfigFileManager::getInstance().getVectorSize(this->type_, this->sectionname_, this->varname_); i++) 275 unsigned int vectorSize = ConfigFileManager::getInstance().getVectorSize(this->type_, this->sectionname_, this->varname_); 276 for (unsigned int i = 0; i < vectorSize; i++) 276 277 { 277 278 if (i < this->defvalueStringVector_.size()) -
code/trunk/src/core/ConfigValueContainer.h
r2171 r2662 109 109 { 110 110 this->init(type, identifier, sectionname, varname); 111 this->initValue( (V)defvalue);111 this->initValue(static_cast<V>(defvalue)); 112 112 } 113 113 … … 217 217 inline const std::string& getName() const 218 218 { return this->varname_; } 219 /** @brief Retuns the name of the section this config value is in. */ 220 inline const std::string& getSectionName() const 221 { return this->sectionname_; } 219 222 /** @brief Returns true if this config-value is a vector */ 220 223 inline bool isVector() const -
code/trunk/src/core/ConsoleCommand.h
r2087 r2662 64 64 65 65 #define SetConsoleCommandShortcutGeneric(fakevariable, command) \ 66 orxonox::ConsoleCommand& fakevariable = orxonox::CommandExecutor::addConsoleCommandShortcut(command )66 orxonox::ConsoleCommand& fakevariable = orxonox::CommandExecutor::addConsoleCommandShortcut(command, true) 67 67 68 68 -
code/trunk/src/core/Core.cc
r2171 r2662 46 46 bool Core::bIsMaster_s = false; 47 47 48 Core* Core::singletonRef_s = 0; 49 48 50 /** 49 51 @brief Constructor: Registers the object and sets the config-values. … … 53 55 { 54 56 RegisterRootObject(Core); 57 58 assert(Core::singletonRef_s == 0); 59 Core::singletonRef_s = this; 60 this->bInitializeRandomNumberGenerator_ = false; 61 55 62 this->setConfigValues(); 56 isCreatingCoreSettings() = false;57 63 } 58 64 … … 62 68 Core::~Core() 63 69 { 64 isCreatingCoreSettings() = true; 65 } 66 67 /** 68 @brief Returns true if the Core instance is not yet ready and the static functions have to return a default value. 69 */ 70 bool& Core::isCreatingCoreSettings() 71 { 72 static bool bCreatingCoreSettings = true; 73 return bCreatingCoreSettings; 74 } 75 76 /** 77 @brief Returns a unique instance of Core. 78 @return The instance 79 */ 80 Core& Core::getInstance() 81 { 82 // If bCreatingSoftDebugLevelObject is true, we're just about to create an instance of the DebugLevel class 83 //if (Core::isCreatingCoreSettings()) 84 //{ 85 // isCreatingCoreSettings() = false; 86 // //instance.setConfigValues(); 87 //} 88 89 static bool firstTime = true; 90 if (firstTime) 91 isCreatingCoreSettings() = true; 92 93 static Core instance; 94 return instance; 70 assert(Core::singletonRef_s); 71 Core::singletonRef_s = 0; 95 72 } 96 73 … … 104 81 SetConfigValue(softDebugLevelShell_, 1).description("The maximal level of debug output shown in the ingame shell").callback(this, &Core::debugLevelChanged); 105 82 SetConfigValue(language_, Language::getLanguage().defaultLanguage_).description("The language of the ingame text").callback(this, &Core::languageChanged); 83 SetConfigValue(bInitializeRandomNumberGenerator_, true).description("If true, all random actions are different each time you start the game").callback(this, &Core::initializeRandomNumberGenerator); 106 84 } 107 85 … … 140 118 int Core::getSoftDebugLevel(OutputHandler::OutputDevice device) 141 119 { 142 if (!Core::isCreatingCoreSettings())120 switch (device) 143 121 { 144 switch (device) 145 { 146 case OutputHandler::LD_All: 147 return Core::getInstance().softDebugLevel_; 148 case OutputHandler::LD_Console: 149 return Core::getInstance().softDebugLevelConsole_; 150 case OutputHandler::LD_Logfile: 151 return Core::getInstance().softDebugLevelLogfile_; 152 case OutputHandler::LD_Shell: 153 return Core::getInstance().softDebugLevelShell_; 154 default: 155 assert(0); 156 } 122 case OutputHandler::LD_All: 123 return Core::getInstance().softDebugLevel_; 124 case OutputHandler::LD_Console: 125 return Core::getInstance().softDebugLevelConsole_; 126 case OutputHandler::LD_Logfile: 127 return Core::getInstance().softDebugLevelLogfile_; 128 case OutputHandler::LD_Shell: 129 return Core::getInstance().softDebugLevelShell_; 130 default: 131 assert(0); 132 return 2; 157 133 } 158 159 // Return a constant value while we're creating the object160 return 2;161 134 } 162 135 … … 168 141 void Core::setSoftDebugLevel(OutputHandler::OutputDevice device, int level) 169 142 { 170 if (!Core::isCreatingCoreSettings()) 171 { 172 if (device == OutputHandler::LD_All) 173 Core::getInstance().softDebugLevel_ = level; 174 else if (device == OutputHandler::LD_Console) 175 Core::getInstance().softDebugLevelConsole_ = level; 176 else if (device == OutputHandler::LD_Logfile) 177 Core::getInstance().softDebugLevelLogfile_ = level; 178 else if (device == OutputHandler::LD_Shell) 179 Core::getInstance().softDebugLevelShell_ = level; 143 if (device == OutputHandler::LD_All) 144 Core::getInstance().softDebugLevel_ = level; 145 else if (device == OutputHandler::LD_Console) 146 Core::getInstance().softDebugLevelConsole_ = level; 147 else if (device == OutputHandler::LD_Logfile) 148 Core::getInstance().softDebugLevelLogfile_ = level; 149 else if (device == OutputHandler::LD_Shell) 150 Core::getInstance().softDebugLevelShell_ = level; 180 151 181 OutputHandler::setSoftDebugLevel(device, level); 182 } 152 OutputHandler::setSoftDebugLevel(device, level); 183 153 } 184 154 … … 188 158 const std::string& Core::getLanguage() 189 159 { 190 if (!Core::isCreatingCoreSettings()) 191 return Core::getInstance().language_; 192 193 return Language::getLanguage().defaultLanguage_; 160 return Core::getInstance().language_; 194 161 } 195 162 … … 209 176 ResetConfigValue(language_); 210 177 } 178 179 void Core::initializeRandomNumberGenerator() 180 { 181 static bool bInitialized = false; 182 if (!bInitialized && this->bInitializeRandomNumberGenerator_) 183 { 184 srand(time(0)); 185 rand(); 186 bInitialized = true; 187 } 188 } 211 189 } -
code/trunk/src/core/Core.h
r2171 r2662 40 40 #include "CorePrereqs.h" 41 41 42 #include <cassert> 42 43 #include "OrxonoxClass.h" 43 44 #include "util/OutputHandler.h" … … 49 50 { 50 51 public: 51 static Core& getInstance();52 static bool& isCreatingCoreSettings();52 Core(); 53 ~Core(); 53 54 void setConfigValues(); 54 55 void debugLevelChanged(); 55 56 void languageChanged(); 56 57 57 static int getSoftDebugLevel(OutputHandler::OutputDevice device = OutputHandler::LD_All); 58 static void setSoftDebugLevel(OutputHandler::OutputDevice device, int level); 58 static Core& getInstance() { assert(Core::singletonRef_s); return *Core::singletonRef_s; } 59 60 static int getSoftDebugLevel(OutputHandler::OutputDevice device = OutputHandler::LD_All); 61 static void setSoftDebugLevel(OutputHandler::OutputDevice device, int level); 59 62 static const std::string& getLanguage(); 60 static void resetLanguage();63 static void resetLanguage(); 61 64 62 65 // fast access global variables. … … 73 76 74 77 private: 78 Core(const Core&); 75 79 void resetLanguageIntern(); 76 77 Core(); 78 Core(const Core& other); 79 virtual ~Core(); 80 void initializeRandomNumberGenerator(); 80 81 81 82 int softDebugLevel_; //!< The debug level … … 84 85 int softDebugLevelShell_; //!< The debug level for the ingame shell 85 86 std::string language_; //!< The language 87 bool bInitializeRandomNumberGenerator_; //!< If true, srand(time(0)) is called 86 88 87 89 static bool bShowsGraphics_s; //!< global variable that tells whether to show graphics … … 90 92 static bool bIsStandalone_s; 91 93 static bool bIsMaster_s; 94 95 static Core* singletonRef_s; 92 96 }; 93 97 } -
code/trunk/src/core/CorePrereqs.h
r2087 r2662 69 69 { 70 70 LoadObject, 71 SaveObject 71 SaveObject, 72 ExpandObject 72 73 }; 73 74 } … … 132 133 class LanguageEntry; 133 134 class Loader; 135 class LuaBind; 134 136 class MetaObjectList; 135 137 class MetaObjectListElement; -
code/trunk/src/core/Factory.cc
r2171 r2662 58 58 @return The Identifier 59 59 */ 60 Identifier* Factory::getIdentifier(const u nsigned int id)60 Identifier* Factory::getIdentifier(const uint32_t id) 61 61 { 62 std::map<u nsigned int, Identifier*>::const_iterator it = getFactoryPointer()->identifierNetworkIDMap_.find(id);62 std::map<uint32_t, Identifier*>::const_iterator it = getFactoryPointer()->identifierNetworkIDMap_.find(id); 63 63 if (it != getFactoryPointer()->identifierNetworkIDMap_.end()) 64 64 return it->second; … … 85 85 @param newID The new networkID 86 86 */ 87 void Factory::changeNetworkID(Identifier* identifier, const u nsigned int oldID, const unsigned int newID)87 void Factory::changeNetworkID(Identifier* identifier, const uint32_t oldID, const uint32_t newID) 88 88 { 89 89 getFactoryPointer()->identifierNetworkIDMap_.erase(oldID); -
code/trunk/src/core/Factory.h
r2171 r2662 49 49 #include <map> 50 50 #include <string> 51 #include "util/Integers.h" 51 52 52 53 namespace orxonox … … 60 61 public: 61 62 static Identifier* getIdentifier(const std::string& name); 62 static Identifier* getIdentifier(const u nsigned int id);63 static Identifier* getIdentifier(const uint32_t id); 63 64 static void add(const std::string& name, Identifier* identifier); 64 static void changeNetworkID(Identifier* identifier, const u nsigned int oldID, const unsigned int newID);65 static void changeNetworkID(Identifier* identifier, const uint32_t oldID, const uint32_t newID); 65 66 static void createClassHierarchy(); 66 67 … … 83 84 84 85 std::map<std::string, Identifier*> identifierStringMap_; //!< The map, mapping the name with the Identifier 85 std::map<u nsigned int, Identifier*> identifierNetworkIDMap_; //!< The map, mapping the network ID with the Identifier86 std::map<uint32_t, Identifier*> identifierNetworkIDMap_; //!< The map, mapping the network ID with the Identifier 86 87 }; 87 88 -
code/trunk/src/core/Functor.h
r2087 r2662 167 167 } 168 168 169 FunctorMember * setObject(T* object)169 FunctorMember<T>* setObject(T* object) 170 170 { 171 171 this->bConstObject_ = false; … … 174 174 } 175 175 176 FunctorMember * setObject(const T* object)176 FunctorMember<T>* setObject(const T* object) 177 177 { 178 178 this->bConstObject_ = true; -
code/trunk/src/core/Identifier.cc
r2171 r2662 93 93 for (std::map<std::string, XMLPortObjectContainer*>::iterator it = this->xmlportObjectContainers_.begin(); it != this->xmlportObjectContainers_.end(); ++it) 94 94 delete (it->second); 95 for (std::vector<Functor*>::iterator it = this->constructionCallbacks_.begin(); it != this->constructionCallbacks_.end(); ++it) 96 delete *it; 97 } 98 99 /** 100 @brief Returns the identifier map with the names as received by typeid(). This is only used internally. 101 */ 102 std::map<std::string, Identifier*>& Identifier::getTypeIDIdentifierMap() 103 { 104 static std::map<std::string, Identifier*> identifiers; //!< The map to store all Identifiers. 105 return identifiers; 95 106 } 96 107 … … 103 114 Identifier* Identifier::getIdentifierSingleton(const std::string& name, Identifier* proposal) 104 115 { 105 static std::map<std::string, Identifier*> identifiers; //!< The map to store all Identifiers. 106 std::map<std::string, Identifier*>::const_iterator it = identifiers.find(name); 107 108 if (it != identifiers.end()) 116 std::map<std::string, Identifier*>::const_iterator it = getTypeIDIdentifierMap().find(name); 117 118 if (it != getTypeIDIdentifierMap().end()) 109 119 { 110 120 // There is already an entry: return it and delete the proposal … … 115 125 { 116 126 // There is no entry: put the proposal into the map and return it 117 identifiers[name] = proposal;127 getTypeIDIdentifierMap()[name] = proposal; 118 128 return proposal; 119 129 } … … 192 202 void Identifier::destroyAllIdentifiers() 193 203 { 194 for (std::map<std::string, Identifier*>::iterator it = Identifier::get IdentifierMapIntern().begin(); it != Identifier::getIdentifierMapIntern().end(); ++it)204 for (std::map<std::string, Identifier*>::iterator it = Identifier::getTypeIDIdentifierMap().begin(); it != Identifier::getTypeIDIdentifierMap().end(); ++it) 195 205 delete (it->second); 196 206 } … … 235 245 @param id The new network ID 236 246 */ 237 void Identifier::setNetworkID(u nsigned int id)247 void Identifier::setNetworkID(uint32_t id) 238 248 { 239 249 Factory::changeNetworkID(this, this->classID_, id); -
code/trunk/src/core/Identifier.h
r2171 r2662 68 68 #include "Super.h" 69 69 #include "Functor.h" 70 #include "util/Integers.h" 70 71 #include "util/Debug.h" 71 72 #include "util/String.h" … … 230 231 231 232 /** @brief Returns the network ID to identify a class through the network. @return the network ID */ 232 inline const u nsigned int getNetworkID() const { return this->classID_; }233 inline const uint32_t getNetworkID() const { return this->classID_; } 233 234 234 235 /** @brief Sets the network ID to a new value. @param id The new value */ 235 void setNetworkID(u nsigned int id);236 void setNetworkID(uint32_t id); 236 237 237 238 void addConfigValueContainer(const std::string& varname, ConfigValueContainer* container); … … 256 257 257 258 void initializeClassHierarchy(std::set<const Identifier*>* parents, bool bRootClass); 259 260 static void destroyAllIdentifiers(); 258 261 259 262 protected: … … 299 302 } 300 303 304 static std::map<std::string, Identifier*>& getTypeIDIdentifierMap(); 305 301 306 void initialize(std::set<const Identifier*>* parents); 302 303 static void destroyAllIdentifiers();304 307 305 308 std::set<const Identifier*> parents_; //!< The parents of the class the Identifier belongs to … … 315 318 BaseFactory* factory_; //!< The Factory, able to create new objects of the given class (if available) 316 319 static int hierarchyCreatingCounter_s; //!< Bigger than zero if at least one Identifier stores its parents (its an int instead of a bool to avoid conflicts with multithreading) 317 u nsigned int classID_;//!< The network ID to identify a class through the network320 uint32_t classID_; //!< The network ID to identify a class through the network 318 321 319 322 bool bHasConfigValues_; //!< True if this class has at least one assigned config value -
code/trunk/src/core/Iterator.h
r2171 r2662 96 96 inline Iterator(ObjectListElement<O>* element) 97 97 { 98 this->element_ = (element) ? (ObjectListBaseElement*)element: 0;98 this->element_ = (element) ? static_cast<ObjectListBaseElement*>(element) : 0; 99 99 this->list_ = ClassIdentifier<O>::getIdentifier()->getObjects(); 100 100 this->iterator_ = this->list_->registerIterator(this); … … 108 108 inline Iterator(const ObjectListIterator<O>& other) 109 109 { 110 this->element_ = (other.element_) ? (ObjectListBaseElement*)other.element_: 0;110 this->element_ = (other.element_) ? static_cast<ObjectListBaseElement*>(other.element_) : 0; 111 111 this->list_ = ClassIdentifier<O>::getIdentifier()->getObjects(); 112 112 this->iterator_ = this->list_->registerIterator(this); … … 163 163 this->list_->unregisterIterator(this->iterator_); 164 164 165 this->element_ = (element) ? (ObjectListBaseElement*)element: 0;165 this->element_ = (element) ? static_cast<ObjectListBaseElement*>(element) : 0; 166 166 this->list_ = ClassIdentifier<O>::getIdentifier()->getObjects(); 167 167 this->iterator_ = this->list_->registerIterator(this); -
code/trunk/src/core/Language.cc
r2171 r2662 87 87 // ### Language ### 88 88 // ############################### 89 90 Language* Language::singletonRef_s = 0; 91 89 92 /** 90 93 @brief Constructor: Reads the default language file and sets some values. … … 92 95 Language::Language() 93 96 { 97 assert(singletonRef_s == 0); 98 singletonRef_s = this; 99 94 100 this->defaultLanguage_ = "default"; 95 101 this->defaultLocalisation_ = "ERROR: LANGUAGE ENTRY DOESN'T EXIST!"; … … 106 112 for (std::map<std::string, LanguageEntry*>::iterator it = this->languageEntries_.begin(); it != this->languageEntries_.end(); ++it) 107 113 delete (it->second); 108 } 109 110 /** 111 @brief Returns a reference to the only existing instance of the Language class and calls the setConfigValues() function. 112 @return The reference to the only existing instance 113 */ 114 Language& Language::getLanguage() 115 { 116 static Language instance = Language(); 117 return instance; 114 115 assert(singletonRef_s); 116 singletonRef_s = 0; 118 117 } 119 118 … … 233 232 if ((lineString != "") && (lineString.size() > 0)) 234 233 { 235 unsigned int pos = lineString.find('=');234 size_t pos = lineString.find('='); 236 235 237 236 // Check if the length is at least 3 and if there's an entry before and behind the = … … 279 278 if ((lineString != "") && (lineString.size() > 0)) 280 279 { 281 unsigned int pos = lineString.find('=');280 size_t pos = lineString.find('='); 282 281 283 282 // Check if the length is at least 3 and if there's an entry before and behind the = -
code/trunk/src/core/Language.h
r2171 r2662 50 50 #include <map> 51 51 #include <string> 52 #include <cassert> 52 53 53 54 #define AddLanguageEntry(label, fallbackstring) \ … … 116 117 117 118 public: 118 static Language& getLanguage(); 119 Language(); 120 ~Language(); 121 122 static Language& getLanguage() { assert(singletonRef_s); return *singletonRef_s; } 119 123 void addEntry(const LanguageEntryLabel& label, const std::string& entry); 120 124 const std::string& getLocalisation(const LanguageEntryLabel& label) const; 121 125 122 126 private: 123 Language(); 124 Language(const Language& language); // don't copy 125 virtual ~Language(); 127 Language(const Language&); 126 128 127 129 void readDefaultLanguageFile(); … … 134 136 std::string defaultLocalisation_; //!< The returned string, if an entry unavailable entry is requested 135 137 std::map<std::string, LanguageEntry*> languageEntries_; //!< A map to store all LanguageEntry objects and their labels 138 139 static Language* singletonRef_s; 136 140 }; 137 141 } -
code/trunk/src/core/Loader.cc
r2171 r2662 120 120 121 121 // let Lua work this out: 122 LuaBind *lua = LuaBind::getInstance();123 lua ->clearLuaOutput();124 lua ->loadFile(file->getFilename(), true);125 lua ->run();122 LuaBind& lua = LuaBind::getInstance(); 123 lua.clearLuaOutput(); 124 lua.loadFile(file->getFilename(), true); 125 lua.run(); 126 126 127 127 try … … 135 135 ticpp::Document xmlfile; 136 136 //xmlfile.ToDocument(); 137 xmlfile.Parse(lua ->getLuaOutput(), true);137 xmlfile.Parse(lua.getLuaOutput(), true); 138 138 139 139 ticpp::Element rootElement; -
code/trunk/src/core/LuaBind.cc
r2508 r2662 40 40 namespace orxonox 41 41 { 42 LuaBind* LuaBind::singletonRef = NULL;42 LuaBind* LuaBind::singletonRef_s = NULL; 43 43 44 44 LuaBind::LuaBind() 45 45 { 46 assert(LuaBind::singletonRef_s == 0); 47 LuaBind::singletonRef_s = this; 48 46 49 luaState_ = lua_open(); 47 50 luaSource_ = ""; -
code/trunk/src/core/LuaBind.h
r2087 r2662 42 42 } 43 43 44 #include <cassert> 44 45 #include <list> 45 46 #include <string> … … 58 59 59 60 public: 60 inline static LuaBind* getInstance() { if (!LuaBind::singletonRef) LuaBind::singletonRef = new LuaBind(); return LuaBind::singletonRef; } // tolua_export 61 inline ~LuaBind() { LuaBind::singletonRef = NULL; }; 61 LuaBind(); 62 inline ~LuaBind() { assert(singletonRef_s); LuaBind::singletonRef_s = NULL; }; 63 64 inline static LuaBind& getInstance() { assert(singletonRef_s); return *LuaBind::singletonRef_s; } // tolua_export 62 65 63 66 void loadFile(std::string filename, bool luaTags); … … 83 86 84 87 private: 85 LuaBind(); 86 static LuaBind* singletonRef; 88 static LuaBind* singletonRef_s; 87 89 88 90 std::string luaSource_; -
code/trunk/src/core/ObjectListIterator.h
r1747 r2662 123 123 { 124 124 if (this->element_) 125 this->element_ = (ObjectListElement<T>*)this->element_->next_;125 this->element_ = static_cast<ObjectListElement<T>*>(this->element_->next_); 126 126 return *this; 127 127 } … … 135 135 ObjectListIterator<T> copy = *this; 136 136 if (this->element_) 137 this->element_ = (ObjectListElement<T>*)this->element_->next_;137 this->element_ = static_cast<ObjectListElement<T>*>(this->element_->next_); 138 138 return copy; 139 139 } … … 146 146 { 147 147 if (this->element_) 148 this->element_ = (ObjectListElement<T>*)this->element_->prev_;148 this->element_ = static_cast<ObjectListElement<T>*>(this->element_->prev_); 149 149 return *this; 150 150 } … … 158 158 ObjectListIterator<T> copy = *this; 159 159 if (this->element_) 160 this->element_ = (ObjectListElement<T>*)this->element_->prev_;160 this->element_ = static_cast<ObjectListElement<T>*>(this->element_->prev_); 161 161 return copy; 162 162 } -
code/trunk/src/core/RootGameState.cc
r2103 r2662 31 31 #include "util/Debug.h" 32 32 #include "util/Exception.h" 33 #include "Core.h"34 33 #include "Clock.h" 35 34 #include "CommandLine.h" … … 123 122 /** 124 123 @brief 124 Main loop of the orxonox game. 125 125 Starts the game. The little 'while' denotes the main loop. 126 126 Whenever the root state is selected, the game ends. 127 127 @param name 128 128 State to start with (usually main menu or specified by command line) 129 @note 130 We use the Ogre::Timer to measure time since it uses the most precise 131 method an a platform (however the windows timer lacks time when under 132 heavy kernel load!). 129 133 */ 130 134 void RootGameState::start() 131 135 { 132 #ifdef NDEBUG 136 // Don't catch errors when having a debugger in msvc 137 #if ORXONOX_COMPILER != ORXONOX_COMPILER_MSVC || defined(NDEBUG) 133 138 try 134 139 { … … 136 141 // start global orxonox time 137 142 Clock clock; 138 139 // create the Core settings to configure the output level140 Core::getInstance();141 143 142 144 this->activate(); … … 156 158 157 159 this->deactivate(); 158 #if def NDEBUG160 #if ORXONOX_COMPILER != ORXONOX_COMPILER_MSVC || defined(NDEBUG) 159 161 } 160 162 // Note: These are all unhandled exceptions that should not have made its way here! … … 162 164 catch (std::exception& ex) 163 165 { 164 COUT(1) << ex.what() << std::endl; 165 COUT(1) << "Program aborted." << std::endl; 166 COUT(0) << ex.what() << std::endl; 167 COUT(0) << "Program aborted." << std::endl; 168 abort(); 166 169 } 167 170 // anything that doesn't inherit from std::exception 168 171 catch (...) 169 172 { 170 COUT(1) << "An unidentifiable exception has occured. Program aborted." << std::endl; 173 COUT(0) << "An unidentifiable exception has occured. Program aborted." << std::endl; 174 abort(); 171 175 } 172 176 #endif -
code/trunk/src/core/RootGameState.h
r2103 r2662 48 48 void gotoState(const std::string& name); 49 49 50 std::string 50 std::string stateRequest_; 51 51 }; 52 52 } -
code/trunk/src/core/Shell.cc
r1792 r2662 75 75 76 76 this->outputBuffer_.registerListener(this); 77 OutputHandler::getOutStream().setOutputBuffer( this->outputBuffer_);77 OutputHandler::getOutStream().setOutputBuffer(&this->outputBuffer_); 78 78 79 79 this->setConfigValues(); … … 84 84 Shell::~Shell() 85 85 { 86 OutputHandler::getOutStream().setOutputBuffer(0); 86 87 if (this->inputBuffer_) 87 88 delete this->inputBuffer_; -
code/trunk/src/core/Super.h
r2171 r2662 99 99 \ 100 100 static void apply(void* temp) {} \ 101 \ 101 102 static void apply(baseclass* temp) \ 102 103 { \ … … 104 105 for (std::set<const Identifier*>::iterator it = identifier->getDirectChildrenIntern().begin(); it != identifier->getDirectChildrenIntern().end(); ++it) \ 105 106 { \ 107 if (((ClassIdentifier<T>*)(*it))->bSuperFunctionCaller_##functionname##_isFallback_ && ((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_) \ 108 { \ 109 delete ((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_; \ 110 ((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_ = 0; \ 111 ((ClassIdentifier<T>*)(*it))->bSuperFunctionCaller_##functionname##_isFallback_ = false; \ 112 } \ 113 \ 106 114 if (!((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_) \ 107 115 { \ … … 163 171 for (std::set<const Identifier*>::iterator it = identifier->getDirectChildrenIntern().begin(); it != identifier->getDirectChildrenIntern().end(); ++it) 164 172 { 173 // Check if the caller is a fallback-caller 174 if (((ClassIdentifier<T>*)(*it))->bSuperFunctionCaller_##functionname##_isFallback_ && ((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_) 175 { 176 // Delete the fallback caller an prepare to get a real caller 177 delete ((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_; 178 ((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_ = 0; 179 ((ClassIdentifier<T>*)(*it))->bSuperFunctionCaller_##functionname##_isFallback_ = false; 180 } 181 165 182 // Check if there's not already a caller 166 183 if (!((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_) … … 183 200 struct SuperFunctionCondition<functionnumber, baseclass, 0, templatehack2> \ 184 201 { \ 185 // The check function just behaves like the fallback - it advances to the check for the next super-function (functionnumber + 1)202 // The check function acts like the fallback - it advances to the check for the next super-function (functionnumber + 1) 186 203 static void check() \ 187 204 { \ … … 233 250 #define SUPER_processEvent(classname, functionname, ...) \ 234 251 SUPER_ARGS(classname, functionname, __VA_ARGS__) 252 253 #define SUPER_changedScale(classname, functionname, ...) \ 254 SUPER_NOARGS(classname, functionname) 255 256 #define SUPER_changedMainState(classname, functionname, ...) \ 257 SUPER_NOARGS(classname, functionname) 258 259 #define SUPER_changedOwner(classname, functionname, ...) \ 260 SUPER_NOARGS(classname, functionname) 261 262 #define SUPER_changedOverlayGroup(classname, functionname, ...) \ 263 SUPER_NOARGS(classname, functionname) 264 265 #define SUPER_changedName(classname, functionname, ...) \ 266 SUPER_NOARGS(classname, functionname) 267 268 #define SUPER_changedGametype(classname, functionname, ...) \ 269 SUPER_NOARGS(classname, functionname) 235 270 // (1/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- 236 271 … … 292 327 }; \ 293 328 \ 329 class _CoreExport SuperFunctionCaller_##functionname \ 330 { \ 331 public: \ 332 virtual void operator()( SUPER_CALL_ARGUMENTS##hasarguments(__VA_ARGS__) ) = 0; \ 333 virtual ~SuperFunctionCaller_##functionname () {} \ 334 }; \ 335 \ 336 template <class T> \ 337 class SuperFunctionClassCaller_purevirtualfallback_##functionname : public SuperFunctionCaller_##functionname \ 338 { \ 339 public: \ 340 inline void operator()( SUPER_CALL_ARGUMENTS##hasarguments(__VA_ARGS__) ) \ 341 { \ 342 } \ 343 }; \ 344 \ 294 345 template <class T> \ 295 346 struct SuperFunctionInitialization<functionnumber, T> \ … … 297 348 static void initialize(ClassIdentifier<T>* identifier) \ 298 349 { \ 299 identifier->superFunctionCaller_##functionname##_ = 0; \ 350 identifier->superFunctionCaller_##functionname##_ = new SuperFunctionClassCaller_purevirtualfallback_##functionname <T>; \ 351 identifier->bSuperFunctionCaller_##functionname##_isFallback_ = true; \ 300 352 SuperFunctionInitialization<functionnumber + 1, T>::initialize(identifier); \ 301 353 } \ … … 313 365 }; \ 314 366 \ 315 class _CoreExport SuperFunctionCaller_##functionname \316 { \317 public: \318 virtual void operator()( SUPER_CALL_ARGUMENTS##hasarguments(__VA_ARGS__) ) = 0; \319 virtual ~SuperFunctionCaller_##functionname () {} \320 }; \321 \322 367 template <class T> \ 323 368 class SuperFunctionClassCaller_##functionname : public SuperFunctionCaller_##functionname \ … … 366 411 }; 367 412 368 // Initializes the SuperFunctionCaller-pointer with zero. 413 // Baseclass of the super-function caller. The real call will be done by a 414 // templatized subclass through the virtual () operator. 415 class _CoreExport SuperFunctionCaller_##functionname 416 { 417 public: 418 virtual void operator()( SUPER_CALL_ARGUMENTS##hasarguments(__VA_ARGS__) ) = 0; 419 virtual ~SuperFunctionCaller_##functionname () {} 420 }; 421 422 // Fallback if the base is pure virtual 423 template <class T> 424 class SuperFunctionClassCaller_purevirtualfallback_##functionname : public SuperFunctionCaller_##functionname 425 { 426 public: 427 // Fallback does nothing 428 inline void operator()( SUPER_CALL_ARGUMENTS##hasarguments(__VA_ARGS__) ) 429 { 430 } 431 }; 432 433 // Initializes the SuperFunctionCaller-pointer with a fallback caller in case the base function is pure virtual 369 434 template <class T> 370 435 struct SuperFunctionInitialization<functionnumber, T> … … 372 437 static void initialize(ClassIdentifier<T>* identifier) 373 438 { 374 identifier->superFunctionCaller_##functionname##_ = 0; 439 identifier->superFunctionCaller_##functionname##_ = new SuperFunctionClassCaller_purevirtualfallback_##functionname <T>; 440 identifier->bSuperFunctionCaller_##functionname##_isFallback_ = true; 375 441 376 442 // Calls the initialization of the next super-function (functionnumber + 1) … … 391 457 SuperFunctionDestruction<functionnumber + 1, T>::destroy(identifier); 392 458 } 393 };394 395 // Baseclass of the super-function caller. The real call will be done by a396 // templatized subclass through the virtual () operator.397 class _CoreExport SuperFunctionCaller_##functionname398 {399 public:400 virtual void operator()( SUPER_CALL_ARGUMENTS##hasarguments(__VA_ARGS__) ) = 0;401 virtual ~SuperFunctionCaller_##functionname () {}402 459 }; 403 460 … … 441 498 (event) 442 499 SUPER_FUNCTION_GLOBAL_DECLARATION_PART2; 500 501 SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(5, changedScale, false) 502 () 503 SUPER_FUNCTION_GLOBAL_DECLARATION_PART2; 504 505 SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(6, changedMainState, false) 506 () 507 SUPER_FUNCTION_GLOBAL_DECLARATION_PART2; 508 509 SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(7, changedOwner, false) 510 () 511 SUPER_FUNCTION_GLOBAL_DECLARATION_PART2; 512 513 SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(8, changedOverlayGroup, false) 514 () 515 SUPER_FUNCTION_GLOBAL_DECLARATION_PART2; 516 517 SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(9, changedName, false) 518 () 519 SUPER_FUNCTION_GLOBAL_DECLARATION_PART2; 520 521 SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(10, changedGametype, false) 522 () 523 SUPER_FUNCTION_GLOBAL_DECLARATION_PART2; 443 524 // (2/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- 444 525 … … 476 557 #ifndef SUPER_INTRUSIVE_DECLARATION 477 558 #define SUPER_INTRUSIVE_DECLARATION(functionname) \ 478 SuperFunctionCaller_##functionname * superFunctionCaller_##functionname##_ 559 SuperFunctionCaller_##functionname * superFunctionCaller_##functionname##_; \ 560 bool bSuperFunctionCaller_##functionname##_isFallback_ 479 561 #endif 480 562 … … 488 570 SUPER_INTRUSIVE_DECLARATION(changedVisibility); 489 571 SUPER_INTRUSIVE_DECLARATION(processEvent); 572 SUPER_INTRUSIVE_DECLARATION(changedScale); 573 SUPER_INTRUSIVE_DECLARATION(changedMainState); 574 SUPER_INTRUSIVE_DECLARATION(changedOwner); 575 SUPER_INTRUSIVE_DECLARATION(changedOverlayGroup); 576 SUPER_INTRUSIVE_DECLARATION(changedName); 577 SUPER_INTRUSIVE_DECLARATION(changedGametype); 490 578 // (3/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- 491 579 -
code/trunk/src/core/Template.cc
- Property svn:mergeinfo changed
/code/branches/network/src/core/Template.cc (added) merged: 2356 /code/branches/objecthierarchy2/src/core/Template.cc (added) merged: 2173,2369 /code/branches/physics_merge/src/core/Template.cc (added) merged: 2442 /code/branches/presentation/src/core/Template.cc (added) merged: 2371,2420,2459,2485,2492-2493,2500
r2261 r2662 43 43 44 44 this->bIsLink_ = false; 45 this->bLoadDefaults_ = true; 45 46 this->bIsReturningXMLElement_ = false; 46 47 this->baseclassIdentifier_ = 0; … … 56 57 SUPER(Template, XMLPort, xmlelement, mode); 57 58 58 XMLPortParam(Template, "link", setLink, getLink, xmlelement, mode); 59 XMLPortParam(Template, "baseclass", setBaseclass, getBaseclass, xmlelement, mode); 59 XMLPortParam(Template, "link", setLink, getLink, xmlelement, mode); 60 XMLPortParam(Template, "baseclass", setBaseclass, getBaseclass, xmlelement, mode); 61 XMLPortParam(Template, "defaults", setLoadDefaults, getLoadDefaults, xmlelement, mode).defaultValues(true); 60 62 61 63 Element* element = xmlelement.FirstChildElement(false); … … 70 72 void Template::changedName() 71 73 { 74 SUPER(Template, changedName); 75 72 76 if (this->getName() != "") 73 77 { … … 134 138 135 139 Element temp = ((TiXmlElement*)&this->getXMLElement()); 136 object->XMLPort(temp, XMLPort::LoadObject); 140 141 if (this->bLoadDefaults_) 142 object->XMLPort(temp, XMLPort::LoadObject); 143 else 144 object->XMLPort(temp, XMLPort::ExpandObject); 137 145 } 138 146 - Property svn:mergeinfo changed
-
code/trunk/src/core/Template.h
- Property svn:mergeinfo changed
/code/branches/network/src/core/Template.h (added) merged: 2356 /code/branches/objecthierarchy2/src/core/Template.h (added) merged: 2173 /code/branches/physics_merge/src/core/Template.h (added) merged: 2442 /code/branches/presentation/src/core/Template.h (added) merged: 2371,2420,2459,2485,2492-2493,2500
r2261 r2662 53 53 { return this->link_; } 54 54 55 inline void setLoadDefaults(bool bLoadDefaults) 56 { this->bLoadDefaults_ = bLoadDefaults; } 57 inline bool getLoadDefaults() const 58 { return this->bLoadDefaults_; } 59 55 60 inline void setXMLElement(const TiXmlElement& xmlelement) 56 61 { this->xmlelement_ = xmlelement; } … … 75 80 Identifier* baseclassIdentifier_; 76 81 bool bIsLink_; 82 bool bLoadDefaults_; 77 83 mutable bool bIsReturningXMLElement_; 78 84 }; - Property svn:mergeinfo changed
-
code/trunk/src/core/XMLFile.h
- Property svn:mergeinfo changed
/code/branches/network/src/core/XMLFile.h (added) merged: 2356 /code/branches/physics_merge/src/core/XMLFile.h (added) merged: 2442 /code/branches/presentation/src/core/XMLFile.h (added) merged: 2371,2420,2459,2485,2492-2493,2500 /code/trunk/src/core/XMLFile.h (added) merged: 2-2085
- Property svn:mergeinfo changed
-
code/trunk/src/core/XMLIncludes.h
- Property svn:mergeinfo changed
/code/branches/network/src/core/XMLIncludes.h (added) merged: 2356 /code/branches/physics/src/core/XMLIncludes.h (added) merged: 2192 /code/branches/physics_merge/src/core/XMLIncludes.h (added) merged: 2442 /code/branches/pickups2/src/core/XMLIncludes.h (added) merged: 2136 /code/branches/presentation/src/core/XMLIncludes.h (added) merged: 2371,2420,2459,2485,2492-2493,2500,2539
r2261 r2662 64 64 namespace orxonox 65 65 { 66 typedef ticpp::DocumentDocument;67 typedef ticpp::ElementElement;68 typedef ticpp::DeclarationDeclaration;69 typedef ticpp::StylesheetReferenceStylesheetReference;70 typedef ticpp::TextText;71 typedef ticpp::CommentComment;72 typedef ticpp::AttributeAttribute;66 using ticpp::Document; 67 using ticpp::Element; 68 using ticpp::Declaration; 69 using ticpp::StylesheetReference; 70 using ticpp::Text; 71 using ticpp::Comment; 72 using ticpp::Attribute; 73 73 } - Property svn:mergeinfo changed
-
code/trunk/src/core/XMLPort.h
r2171 r2662 43 43 #include "CorePrereqs.h" 44 44 45 #include <cassert> 45 46 #include "util/Debug.h" 46 47 #include "util/Exception.h" … … 74 75 static ExecutorMember<classname>* xmlcontainer##loadfunction##savefunction##saveexecutor = orxonox::createExecutor(orxonox::createFunctor(&classname::savefunction), std::string( #classname ) + "::" + #savefunction); \ 75 76 XMLPortParamGeneric(xmlcontainer##loadfunction##savefunction, classname, classname, this, paramname, xmlcontainer##loadfunction##savefunction##loadexecutor, xmlcontainer##loadfunction##savefunction##saveexecutor, xmlelement, mode) 77 78 /** 79 @brief Declares an XML attribute with a name, which will be set through a variable. 80 @param classname The name of the class owning this param 81 @param paramname The name of the attribute 82 @param variable Name of the variable used to save and load the value 83 @param xmlelement The XMLElement, you get this from the XMLPort function 84 @param mode The mode (load or save), you get this from the XMLPort function 85 86 In the XML file, a param or attribute will be set like this: 87 <classname paramname="value" /> 88 89 The macro will then store "value" in the variable or read it when saving. 90 */ 91 #define XMLPortParamVariable(classname, paramname, variable, xmlelement, mode) \ 92 XMLPortVariableHelperClass xmlcontainer##variable##dummy((void*)&variable); \ 93 static ExecutorMember<orxonox::XMLPortVariableHelperClass>* xmlcontainer##variable##loadexecutor = static_cast<ExecutorMember<orxonox::XMLPortVariableHelperClass>*>(orxonox::createExecutor(orxonox::createFunctor(orxonox::XMLPortVariableHelperClass::getLoader(variable)), std::string( #classname ) + "::" + #variable + "loader")); \ 94 static ExecutorMember<orxonox::XMLPortVariableHelperClass>* xmlcontainer##variable##saveexecutor = static_cast<ExecutorMember<orxonox::XMLPortVariableHelperClass>*>(orxonox::createExecutor(orxonox::createFunctor(orxonox::XMLPortVariableHelperClass::getSaver (variable)), std::string( #classname ) + "::" + #variable + "saver" )); \ 95 XMLPortParamGeneric(xmlcontainer##variable, classname, orxonox::XMLPortVariableHelperClass, &xmlcontainer##variable##dummy, paramname, xmlcontainer##variable##loadexecutor, xmlcontainer##variable##saveexecutor, xmlelement, mode) 96 76 97 /** 77 98 @brief This is the same as XMLPortParam, but you can set the template arguments needed to store the loadfunction. … … 161 182 ClassIdentifier<classname>::getIdentifier()->addXMLPortParamContainer(paramname, containername); \ 162 183 } \ 163 containername->port( (BaseObject*)this, object, xmlelement, mode)184 containername->port(static_cast<BaseObject*>(this), object, xmlelement, mode) 164 185 165 186 // -------------------- … … 175 196 @param xmlelement The XMLElement (recieved through the XMLPort function) 176 197 @param mode The mode (load/save) (received through the XMLPort function) 177 @param bApplyLoaderMask If this is true, an added sub-object only gets loadedif it's class is included in the Loaders ClassTreeMask (this is usually false)178 @param bLoadBefore If this is true, the sub- cobject gets loaded (through XMLPort) BEFORE it gets added to the main class (this is usually true)198 @param bApplyLoaderMask If this is true, an added sub-object gets loaded only if it's class is included in the Loaders ClassTreeMask (this is usually false) 199 @param bLoadBefore If this is true, the sub-object gets loaded (through XMLPort) BEFORE it gets added to the main class (this is usually true) 179 200 180 201 bApplyLoaderMask is usually false for the following reason: … … 183 204 Of course, if there are "standalone" weapons in the level, they wont be loaded. 184 205 185 If bLoadBefore , an added object already has all attributes set (like it's name). This is most206 If bLoadBefore is true, an added object already has all attributes set (like it's name). This is most 186 207 likely the best option, so this is usually true. 187 208 … … 222 243 Note that "weapons" is the subsection. This allows you to add more types of sub-objects. In our example, 223 244 you could add pilots, blinking lights or other stuff. If you don't want a subsection, just use "" (an 224 empty string). The you can add sub-objects directly into the mainclass.245 empty string). Then you can add sub-objects directly into the mainclass. 225 246 */ 226 247 #define XMLPortObjectExtended(classname, objectclass, sectionname, loadfunction, savefunction, xmlelement, mode, bApplyLoaderMask, bLoadBefore) \ … … 329 350 } 330 351 352 ~XMLPortClassParamContainer() 353 { 354 assert(this->loadexecutor_); 355 delete this->loadexecutor_; 356 if (this->saveexecutor_) 357 delete this->saveexecutor_; 358 } 359 331 360 XMLPortParamContainer& port(BaseObject* owner, T* object, Element& xmlelement, XMLPort::Mode mode) 332 361 { 362 OrxAssert(owner, "XMLPortParamContainer must have a BaseObject as owner."); 333 363 this->owner_ = owner; 334 364 this->parseParams_.object = object; … … 336 366 this->parseParams_.mode = mode; 337 367 338 if ( mode == XMLPort::LoadObject)368 if ((mode == XMLPort::LoadObject) || (mode == XMLPort::ExpandObject)) 339 369 { 340 370 try 341 371 { 342 std::string attribute = xmlelement.GetAttribute(this->paramname_); 343 if ((attribute.size() > 0) || (this->loadexecutor_->allDefaultValuesSet())) 372 if (this->owner_->lastLoadedXMLElement_ != &xmlelement) 373 { 374 this->owner_->xmlAttributes_.clear(); 375 // Iterate through the attributes manually in order to make them case insensitive 376 Attribute* attribute = xmlelement.FirstAttribute(false); 377 while (attribute != 0) 378 { 379 this->owner_->xmlAttributes_[getLowercase(attribute->Name())] = attribute->Value(); 380 attribute = attribute->Next(false); 381 } 382 this->owner_->lastLoadedXMLElement_ = &xmlelement; 383 } 384 std::map<std::string, std::string>::const_iterator it = this->owner_->xmlAttributes_.find(getLowercase(this->paramname_)); 385 std::string attributeValue(""); 386 if (it != this->owner_->xmlAttributes_.end()) 387 attributeValue = it->second; 388 389 // TODO: Checking the iterator would be better since then we can have strings with value "" as well. 390 // Unfortunately this does not seem to work with the Executor parser yet. 391 if ((!attributeValue.empty()) || ((mode != XMLPort::ExpandObject) && this->loadexecutor_->allDefaultValuesSet())) 344 392 { 345 393 COUT(5) << this->owner_->getLoaderIndentation() << "Loading parameter " << this->paramname_ << " in " << this->identifier_->getName() << " (objectname " << this->owner_->getName() << ")." << std::endl << this->owner_->getLoaderIndentation(); 346 if (this->loadexecutor_->parse(object, attribute , ","))394 if (this->loadexecutor_->parse(object, attributeValue, ",") || (mode == XMLPort::ExpandObject)) 347 395 this->parseResult_ = PR_finished; 348 396 else 349 397 this->parseResult_ = PR_waiting_for_default_values; 350 398 } 399 else if (mode == XMLPort::ExpandObject) 400 this->parseResult_ = PR_finished; 351 401 else 352 402 this->parseResult_ = PR_waiting_for_default_values; … … 471 521 } 472 522 523 ~XMLPortClassObjectContainer() 524 { 525 assert(this->loadexecutor_); 526 delete this->loadexecutor_; 527 if (this->saveexecutor_) 528 delete this->saveexecutor_; 529 } 530 473 531 XMLPortObjectContainer& port(T* object, Element& xmlelement, XMLPort::Mode mode) 474 532 { 475 if ( mode == XMLPort::LoadObject)533 if ((mode == XMLPort::LoadObject) || (mode == XMLPort::ExpandObject)) 476 534 { 477 535 try … … 588 646 ExecutorMember<T>* saveexecutor_; 589 647 }; 648 649 650 // #################################### 651 // ### XMLPortVariableHelperClass ### 652 // #################################### 653 /** 654 @brief 655 Helper class to load and save simple variables with XMLPort. 656 657 getLoader and getSaver were necessary to get the type T with 658 the help of template function type deduction (const T& is unused). 659 These functions return the adress of save<T> or load<T>. 660 */ 661 class XMLPortVariableHelperClass 662 { 663 public: 664 XMLPortVariableHelperClass(void* var) 665 : variable_(var) 666 { } 667 668 template <class T> 669 void load(const T& value) 670 { *((T*)this->variable_) = value; } 671 672 template <class T> 673 const T& save() 674 { return *((T*)this->variable_); } 675 676 template <class T> 677 static void (XMLPortVariableHelperClass::*getLoader(const T& var))(const T& value) 678 { return &XMLPortVariableHelperClass::load<T>; } 679 680 template <class T> 681 static const T& (XMLPortVariableHelperClass::*getSaver(const T& var))() 682 { return &XMLPortVariableHelperClass::save<T>; } 683 684 private: 685 void* variable_; 686 }; 590 687 } 591 688 -
code/trunk/src/core/input/Button.cc
r2103 r2662 59 59 nCommands_[1]=0; 60 60 nCommands_[2]=0; 61 this->configContainer_ = 0; 61 62 clear(); 63 } 64 65 Button::~Button() 66 { 67 this->clear(); 68 69 if (this->configContainer_) 70 delete this->configContainer_; 62 71 } 63 72 -
code/trunk/src/core/input/Button.h
r2103 r2662 49 49 public: 50 50 Button(); 51 virtual ~Button() { clear(); }51 virtual ~Button(); 52 52 virtual void clear(); 53 53 virtual bool addParamCommand(ParamCommand* command) { return false; } -
code/trunk/src/core/input/InputBuffer.cc
r1755 r2662 73 73 } 74 74 75 InputBuffer::~InputBuffer() 76 { 77 for (std::list<BaseInputBufferListenerTuple*>::const_iterator it = this->listeners_.begin(); 78 it != this->listeners_.end(); ++it) 79 delete *it; 80 } 81 75 82 void InputBuffer::setConfigValues() 76 83 { -
code/trunk/src/core/input/InputBuffer.h
r1887 r2662 79 79 public: 80 80 InputBuffer(); 81 ~InputBuffer(); 81 82 InputBuffer(const std::string allowedChars); 82 83 -
code/trunk/src/core/input/InputInterfaces.h
r1887 r2662 378 378 const char* const ByString[] = 379 379 { 380 "Button0 ", "Button1", "Button2", "Button3",381 "Button 4", "Button5", "Button6", "Button7",382 "Button 8", "Button9","Button10", "Button11",380 "Button00", "Button01", "Button02", "Button03", 381 "Button04", "Button05", "Button06", "Button07", 382 "Button08", "Button09", "Button10", "Button11", 383 383 "Button12", "Button13", "Button14", "Button15", 384 384 "Button16", "Button17", "Button18", "Button19", … … 416 416 "Slider0", "Slider1", "Slider2", "Slider3", 417 417 "Slider4", "Slider5", "Slider6", "Slider7", 418 "Axis0 ", "Axis1", "Axis2", "Axis3",419 "Axis 4", "Axis5", "Axis6", "Axis7",420 "Axis 8", "Axis9","Axis10", "Axis11",418 "Axis00", "Axis01", "Axis02", "Axis03", 419 "Axis04", "Axis05", "Axis06", "Axis07", 420 "Axis08", "Axis09", "Axis10", "Axis11", 421 421 "Axis12", "Axis13", "Axis14", "Axis15" 422 422 }; -
code/trunk/src/core/input/InputManager.cc
r2103 r2662 65 65 SetCommandLineSwitch(keyboard_no_grab); 66 66 67 std::string InputManager::bindingCommmandString_s = "";68 67 EmptyHandler InputManager::EMPTY_HANDLER; 69 68 InputManager* InputManager::singletonRef_s = 0; … … 112 111 , keyDetector_(0) 113 112 , calibratorCallbackBuffer_(0) 114 , bCalibrating_(false)115 113 , keyboardModifiers_(0) 116 114 { … … 119 117 assert(singletonRef_s == 0); 120 118 singletonRef_s = this; 119 120 setConfigValues(); 121 } 122 123 /** 124 @brief 125 Sets the configurable values. 126 */ 127 void InputManager::setConfigValues() 128 { 129 SetConfigValue(calibrationFilename_, "joystick_calibration.ini") 130 .description("Ini filename for the the joy stick calibration data.") 131 .callback(this, &InputManager::_calibrationFileCallback); 132 } 133 134 /** 135 @brief 136 Callback for the joy stick calibration config file. @see setConfigValues. 137 */ 138 void InputManager::_calibrationFileCallback() 139 { 140 ConfigFileManager::getInstance().setFilename(ConfigFileType::JoyStickCalibration, calibrationFilename_); 121 141 } 122 142 … … 174 194 if (joyStickSupport) 175 195 _initialiseJoySticks(); 176 // Do this anyway to also inform every one ifa joystick was detached.177 _configure NumberOfJoySticks();196 // Do this anyway to also inform everything when a joystick was detached. 197 _configureJoySticks(); 178 198 179 199 // Set mouse/joystick region … … 183 203 // clear all buffers 184 204 _clearBuffers(); 185 186 // load joy stick calibration187 setConfigValues();188 205 189 206 internalState_ |= OISReady; … … 335 352 /** 336 353 @brief 354 Helper function that loads the config value vector of one coefficient 355 */ 356 void loadCalibration(std::vector<int>& list, const std::string& sectionName, const std::string& valueName, size_t size, int defaultValue) 357 { 358 list.resize(size); 359 unsigned int configValueVectorSize = ConfigFileManager::getInstance().getVectorSize(ConfigFileType::JoyStickCalibration, sectionName, valueName); 360 if (configValueVectorSize > size) 361 configValueVectorSize = size; 362 363 for (unsigned int i = 0; i < configValueVectorSize; ++i) 364 { 365 list[i] = omni_cast<int>(ConfigFileManager::getInstance().getValue( 366 ConfigFileType::JoyStickCalibration, sectionName, valueName, i, omni_cast<std::string>(defaultValue), false)); 367 } 368 369 // fill the rest with default values 370 for (unsigned int i = configValueVectorSize; i < size; ++i) 371 { 372 list[i] = defaultValue; 373 } 374 } 375 376 /** 377 @brief 337 378 Sets the size of all the different lists that are dependent on the number 338 of joy stick devices created .379 of joy stick devices created and loads the joy stick calibration. 339 380 @remarks 340 381 No matter whether there are a mouse and/or keyboard, they will always 341 382 occupy 2 places in the device number dependent lists. 342 383 */ 343 void InputManager::_configure NumberOfJoySticks()384 void InputManager::_configureJoySticks() 344 385 { 345 386 joySticksSize_ = joySticks_.size(); 346 devicesNum_ = 2 + joySticksSize_; 387 devicesNum_ = 2 + joySticksSize_; 388 joyStickIDs_ .resize(joySticksSize_); 347 389 joyStickButtonsDown_ .resize(joySticksSize_); 348 390 povStates_ .resize(joySticksSize_); 349 391 sliderStates_ .resize(joySticksSize_); 350 joySticksCalibration_.resize(joySticksSize_); 392 joyStickMinValues_ .resize(joySticksSize_); 393 joyStickMaxValues_ .resize(joySticksSize_); 394 joyStickMiddleValues_.resize(joySticksSize_); 395 joyStickCalibrations_.resize(joySticksSize_); 351 396 352 397 for (unsigned int iJoyStick = 0; iJoyStick < joySticksSize_; iJoyStick++) 353 398 { 354 // reset the calibration with default values 355 for (unsigned int i = 0; i < 24; i++) 356 { 357 joySticksCalibration_[iJoyStick].negativeCoeff[i] = 1.0f/32767.0f; 358 joySticksCalibration_[iJoyStick].positiveCoeff[i] = 1.0f/32768.0f; 359 joySticksCalibration_[iJoyStick].zeroStates[i] = 0; 360 } 361 } 399 // Generate some sort of execution unique id per joy stick 400 std::string id = "JoyStick_"; 401 id += omni_cast<std::string>(joySticks_[iJoyStick]->getNumberOfComponents(OIS::OIS_Button)) + "_"; 402 id += omni_cast<std::string>(joySticks_[iJoyStick]->getNumberOfComponents(OIS::OIS_Axis)) + "_"; 403 id += omni_cast<std::string>(joySticks_[iJoyStick]->getNumberOfComponents(OIS::OIS_Slider)) + "_"; 404 id += omni_cast<std::string>(joySticks_[iJoyStick]->getNumberOfComponents(OIS::OIS_POV)) + "_"; 405 id += omni_cast<std::string>(joySticks_[iJoyStick]->getNumberOfComponents(OIS::OIS_Vector3)) + "_"; 406 id += joySticks_[iJoyStick]->vendor(); 407 for (unsigned int i = 0; i < iJoyStick; ++i) 408 { 409 if (id == joyStickIDs_[i]) 410 { 411 // Two joysticks are probably equal --> add the index as well 412 id += "_" + omni_cast<std::string>(iJoyStick); 413 } 414 } 415 joyStickIDs_[iJoyStick] = id; 416 417 size_t axes = sliderAxes + (size_t)this->joySticks_[iJoyStick]->getNumberOfComponents(OIS::OIS_Axis); 418 loadCalibration(joyStickMinValues_[iJoyStick], id, "MinValue", axes, -32768); 419 loadCalibration(joyStickMaxValues_[iJoyStick], id, "MaxValue", axes, 32768); 420 loadCalibration(joyStickMiddleValues_[iJoyStick], id, "MiddleValue", axes, 0); 421 } 422 423 _evaluateCalibration(); 362 424 363 425 // state management … … 380 442 } 381 443 382 /** 383 @brief 384 Sets the configurable values. 385 This mainly concerns joy stick calibrations. 386 */ 387 void InputManager::setConfigValues() 388 { 389 if (joySticksSize_ > 0) 390 { 391 std::vector<double> coeffPos; 392 std::vector<double> coeffNeg; 393 std::vector<int> zero; 394 coeffPos.resize(24); 395 coeffNeg.resize(24); 396 zero.resize(24); 397 for (unsigned int i = 0; i < 24; i++) 398 { 399 coeffPos[i] = 1.0f/32767.0f; 400 coeffNeg[i] = 1.0f/32768.0f; 401 zero[i] = 0; 402 } 403 404 ConfigValueContainer* cont = getIdentifier()->getConfigValueContainer("CoeffPos"); 405 if (!cont) 406 { 407 cont = new ConfigValueContainer(ConfigFileType::Settings, getIdentifier(), getIdentifier()->getName(), "CoeffPos", coeffPos); 408 getIdentifier()->addConfigValueContainer("CoeffPos", cont); 409 } 410 cont->getValue(&coeffPos, this); 411 412 cont = getIdentifier()->getConfigValueContainer("CoeffNeg"); 413 if (!cont) 414 { 415 cont = new ConfigValueContainer(ConfigFileType::Settings, getIdentifier(), getIdentifier()->getName(), "CoeffNeg", coeffNeg); 416 getIdentifier()->addConfigValueContainer("CoeffNeg", cont); 417 } 418 cont->getValue(&coeffNeg, this); 419 420 cont = getIdentifier()->getConfigValueContainer("Zero"); 421 if (!cont) 422 { 423 cont = new ConfigValueContainer(ConfigFileType::Settings, getIdentifier(), getIdentifier()->getName(), "Zero", zero); 424 getIdentifier()->addConfigValueContainer("Zero", cont); 425 } 426 cont->getValue(&zero, this); 427 428 // copy values to our own variables 429 for (unsigned int i = 0; i < 24; i++) 430 { 431 joySticksCalibration_[0].positiveCoeff[i] = coeffPos[i]; 432 joySticksCalibration_[0].negativeCoeff[i] = coeffNeg[i]; 433 joySticksCalibration_[0].zeroStates[i] = zero[i]; 434 } 435 } 436 } 437 444 void InputManager::_evaluateCalibration() 445 { 446 for (unsigned int iJoyStick = 0; iJoyStick < this->joySticksSize_; ++iJoyStick) 447 { 448 for (unsigned int i = 0; i < this->joyStickMinValues_[iJoyStick].size(); i++) 449 { 450 this->joyStickCalibrations_[iJoyStick].middleValue[i] = this->joyStickMiddleValues_[iJoyStick][i]; 451 this->joyStickCalibrations_[iJoyStick].negativeCoeff[i] = - 1.0f / (this->joyStickMinValues_[iJoyStick][i] - this->joyStickMiddleValues_[iJoyStick][i]); 452 this->joyStickCalibrations_[iJoyStick].positiveCoeff[i] = 1.0f / (this->joyStickMaxValues_[iJoyStick][i] - this->joyStickMiddleValues_[iJoyStick][i]); 453 } 454 } 455 } 456 457 void InputManager::_startCalibration() 458 { 459 for (unsigned int iJoyStick = 0; iJoyStick < this->joySticksSize_; ++iJoyStick) 460 { 461 // Set initial values 462 for (unsigned int i = 0; i < this->joyStickMinValues_[iJoyStick].size(); ++i) 463 this->joyStickMinValues_[iJoyStick][i] = INT_MAX; 464 for (unsigned int i = 0; i < this->joyStickMaxValues_[iJoyStick].size(); ++i) 465 this->joyStickMaxValues_[iJoyStick][i] = INT_MIN; 466 for (unsigned int i = 0; i < this->joyStickMiddleValues_[iJoyStick].size(); ++i) 467 this->joyStickMiddleValues_[iJoyStick][i] = 0; 468 } 469 470 getInstance().internalState_ |= Calibrating; 471 getInstance().requestEnterState("calibrator"); 472 } 473 474 void InputManager::_completeCalibration() 475 { 476 for (unsigned int iJoyStick = 0; iJoyStick < this->joySticksSize_; ++iJoyStick) 477 { 478 // Get the middle positions now 479 unsigned int iAxis = 0; 480 for (unsigned int i = 0; i < sliderAxes/2; ++i) 481 { 482 this->joyStickMiddleValues_[iJoyStick][iAxis++] = this->joySticks_[iJoyStick]->getJoyStickState().mSliders[i].abX; 483 this->joyStickMiddleValues_[iJoyStick][iAxis++] = this->joySticks_[iJoyStick]->getJoyStickState().mSliders[i].abY; 484 } 485 // Note: joyStickMiddleValues_[iJoyStick] was already correctly resized in _configureJoySticks() 486 assert(joySticks_[iJoyStick]->getJoyStickState().mAxes.size() == joyStickMiddleValues_[iJoyStick].size() - sliderAxes); 487 for (unsigned int i = 0; i < joyStickMiddleValues_[iJoyStick].size() - sliderAxes; ++i) 488 { 489 this->joyStickMiddleValues_[iJoyStick][iAxis++] = this->joySticks_[iJoyStick]->getJoyStickState().mAxes[i].abs; 490 } 491 492 for (unsigned int i = 0; i < joyStickMinValues_[iJoyStick].size(); ++i) 493 { 494 // Minimum values 495 if (joyStickMinValues_[iJoyStick][i] == INT_MAX) 496 joyStickMinValues_[iJoyStick][i] = -32768; 497 ConfigFileManager::getInstance().setValue(ConfigFileType::JoyStickCalibration, 498 this->joyStickIDs_[iJoyStick], "MinValue", i, omni_cast<std::string>(joyStickMinValues_[iJoyStick][i]), false); 499 500 // Maximum values 501 if (joyStickMaxValues_[iJoyStick][i] == INT_MIN) 502 joyStickMaxValues_[iJoyStick][i] = 32767; 503 ConfigFileManager::getInstance().setValue(ConfigFileType::JoyStickCalibration, 504 this->joyStickIDs_[iJoyStick], "MaxValue", i, omni_cast<std::string>(joyStickMaxValues_[iJoyStick][i]), false); 505 506 // Middle values 507 ConfigFileManager::getInstance().setValue(ConfigFileType::JoyStickCalibration, 508 this->joyStickIDs_[iJoyStick], "MiddleValue", i, omni_cast<std::string>(joyStickMiddleValues_[iJoyStick][i]), false); 509 } 510 } 511 512 _evaluateCalibration(); 513 514 // restore old input state 515 requestLeaveState("calibrator"); 516 internalState_ &= ~Calibrating; 517 } 438 518 439 519 // ############################################################ … … 492 572 } 493 573 } 494 singletonRef_s = 0; 574 575 singletonRef_s = 0; 495 576 } 496 577 … … 660 741 /** 661 742 @brief 662 Updates the InputManager. Tick is called by the Core class.743 Updates the states and the InputState situation. 663 744 @param dt 664 745 Delta time … … 676 757 677 758 // check for states to leave 678 for (std::set<InputState*>::reverse_iterator rit = stateLeaveRequests_.rbegin(); 679 rit != stateLeaveRequests_.rend(); ++rit) 680 { 681 (*rit)->onLeave(); 682 // just to be sure that the state actually is registered 683 assert(inputStatesByName_.find((*rit)->getName()) != inputStatesByName_.end()); 684 685 activeStates_.erase((*rit)->getPriority()); 686 _updateActiveStates(); 687 } 688 stateLeaveRequests_.clear(); 759 if (!stateLeaveRequests_.empty()) 760 { 761 for (std::set<InputState*>::reverse_iterator rit = stateLeaveRequests_.rbegin(); 762 rit != stateLeaveRequests_.rend(); ++rit) 763 { 764 (*rit)->onLeave(); 765 // just to be sure that the state actually is registered 766 assert(inputStatesByName_.find((*rit)->getName()) != inputStatesByName_.end()); 767 768 activeStates_.erase((*rit)->getPriority()); 769 _updateActiveStates(); 770 } 771 stateLeaveRequests_.clear(); 772 } 689 773 690 774 // check for states to enter 691 for (std::set<InputState*>::reverse_iterator rit = stateEnterRequests_.rbegin(); 692 rit != stateEnterRequests_.rend(); ++rit) 693 { 694 // just to be sure that the state actually is registered 695 assert(inputStatesByName_.find((*rit)->getName()) != inputStatesByName_.end()); 696 697 activeStates_[(*rit)->getPriority()] = (*rit); 698 _updateActiveStates(); 699 (*rit)->onEnter(); 700 } 701 stateEnterRequests_.clear(); 775 if (!stateEnterRequests_.empty()) 776 { 777 for (std::set<InputState*>::reverse_iterator rit = stateEnterRequests_.rbegin(); 778 rit != stateEnterRequests_.rend(); ++rit) 779 { 780 // just to be sure that the state actually is registered 781 assert(inputStatesByName_.find((*rit)->getName()) != inputStatesByName_.end()); 782 783 activeStates_[(*rit)->getPriority()] = (*rit); 784 _updateActiveStates(); 785 (*rit)->onEnter(); 786 } 787 stateEnterRequests_.clear(); 788 } 702 789 703 790 // check for states to destroy 704 for (std::set<InputState*>::reverse_iterator rit = stateDestroyRequests_.rbegin(); 705 rit != stateDestroyRequests_.rend(); ++rit) 706 { 707 _destroyState((*rit)); 708 } 709 stateDestroyRequests_.clear(); 791 if (!stateDestroyRequests_.empty()) 792 { 793 for (std::set<InputState*>::reverse_iterator rit = stateDestroyRequests_.rbegin(); 794 rit != stateDestroyRequests_.rend(); ++rit) 795 { 796 _destroyState((*rit)); 797 } 798 stateDestroyRequests_.clear(); 799 } 710 800 711 801 // check whether a state has changed its EMPTY_HANDLER situation … … 733 823 joySticks_[i]->capture(); 734 824 735 if (! bCalibrating_)825 if (!(internalState_ & Calibrating)) 736 826 { 737 827 // call all the handlers for the held key events … … 804 894 /** 805 895 @brief 806 Processes the accumultated data for the joy stick calibration. 807 */ 808 void InputManager::_completeCalibration() 809 { 810 for (unsigned int i = 0; i < 24; i++) 811 { 812 // positive coefficient 813 if (marginalsMax_[i] == INT_MIN) 814 marginalsMax_[i] = 32767; 815 // coefficients 816 if (marginalsMax_[i] - joySticksCalibration_[0].zeroStates[i]) 817 { 818 joySticksCalibration_[0].positiveCoeff[i] 819 = 1.0f/(marginalsMax_[i] - joySticksCalibration_[0].zeroStates[i]); 820 } 821 else 822 joySticksCalibration_[0].positiveCoeff[i] = 1.0f; 823 824 // config value 825 ConfigValueContainer* cont = getIdentifier()->getConfigValueContainer("CoeffPos"); 826 assert(cont); 827 cont->set(i, joySticksCalibration_[0].positiveCoeff[i]); 828 829 // negative coefficient 830 if (marginalsMin_[i] == INT_MAX) 831 marginalsMin_[i] = -32768; 832 // coefficients 833 if (marginalsMin_[i] - joySticksCalibration_[0].zeroStates[i]) 834 { 835 joySticksCalibration_[0].negativeCoeff[i] = -1.0f 836 / (marginalsMin_[i] - joySticksCalibration_[0].zeroStates[i]); 837 } 838 else 839 joySticksCalibration_[0].negativeCoeff[i] = 1.0f; 840 // config value 841 cont = getIdentifier()->getConfigValueContainer("CoeffNeg"); 842 assert(cont); 843 cont->set(i, joySticksCalibration_[0].negativeCoeff[i]); 844 845 // zero states 846 if (i < 8) 847 { 848 if (!(i & 1)) 849 joySticksCalibration_[0].zeroStates[i] = joySticks_[0]->getJoyStickState().mSliders[i/2].abX; 850 else 851 joySticksCalibration_[0].zeroStates[i] = joySticks_[0]->getJoyStickState().mSliders[i/2].abY; 852 } 853 else 854 { 855 if (i - 8 < joySticks_[0]->getJoyStickState().mAxes.size()) 856 joySticksCalibration_[0].zeroStates[i] = joySticks_[0]->getJoyStickState().mAxes[i - 8].abs; 857 else 858 joySticksCalibration_[0].zeroStates[i] = 0; 859 } 860 // config value 861 cont = getIdentifier()->getConfigValueContainer("Zero"); 862 assert(cont); 863 cont->set(i, joySticksCalibration_[0].zeroStates[i]); 864 } 865 866 // restore old input state 867 requestLeaveState("calibrator"); 868 bCalibrating_ = false; 869 } 870 896 Clears all buffers that store what keys/buttons are being pressed at the moment. 897 */ 871 898 void InputManager::clearBuffers() 872 899 { … … 1099 1126 void InputManager::_fireAxis(unsigned int iJoyStick, int axis, int value) 1100 1127 { 1101 if ( bCalibrating_)1102 { 1103 if (value > marginalsMax_[axis])1104 marginalsMax_[axis] = value;1105 if (value < marginalsMin_[axis])1106 marginalsMin_[axis] = value;1128 if (internalState_ & Calibrating) 1129 { 1130 if (value < joyStickMinValues_[iJoyStick][axis]) 1131 joyStickMinValues_[iJoyStick][axis] = value; 1132 if (value > joyStickMaxValues_[iJoyStick][axis]) 1133 joyStickMaxValues_[iJoyStick][axis] = value; 1107 1134 } 1108 1135 else 1109 1136 { 1110 float fValue = value - joyStick sCalibration_[iJoyStick].zeroStates[axis];1137 float fValue = value - joyStickCalibrations_[iJoyStick].middleValue[axis]; 1111 1138 if (fValue > 0.0f) 1112 fValue *= joyStick sCalibration_[iJoyStick].positiveCoeff[axis];1139 fValue *= joyStickCalibrations_[iJoyStick].positiveCoeff[axis]; 1113 1140 else 1114 fValue *= joyStick sCalibration_[iJoyStick].negativeCoeff[axis];1141 fValue *= joyStickCalibrations_[iJoyStick].negativeCoeff[axis]; 1115 1142 1116 1143 activeStatesTop_[2 + iJoyStick]->joyStickAxisMoved(iJoyStick, axis, fValue); … … 1124 1151 1125 1152 // keep in mind that the first 8 axes are reserved for the sliders 1126 _fireAxis(iJoyStick, axis + 8, arg.state.mAxes[axis].abs);1153 _fireAxis(iJoyStick, axis + sliderAxes, arg.state.mAxes[axis].abs); 1127 1154 1128 1155 return true; … … 1390 1417 void InputManager::calibrate() 1391 1418 { 1392 getInstance().bCalibrating_ = true; 1393 getInstance().requestEnterState("calibrator"); 1419 COUT(0) << "Move all joy stick axes fully in all directions." << std::endl 1420 << "When done, put the axex in the middle position and press enter." << std::endl; 1421 1422 getInstance()._startCalibration(); 1394 1423 } 1395 1424 -
code/trunk/src/core/input/InputManager.h
r2102 r2662 71 71 struct JoyStickCalibration 72 72 { 73 int zeroStates[24];73 int middleValue[24]; 74 74 float positiveCoeff[24]; 75 75 float negativeCoeff[24]; … … 136 136 public: // variables 137 137 static EmptyHandler EMPTY_HANDLER; 138 static const unsigned int sliderAxes = 8; 138 139 139 140 private: // functions … … 145 146 void _initialiseMouse(); 146 147 void _initialiseJoySticks(); 147 void _configureNumberOfJoySticks(); 148 void _configureJoySticks(); 149 150 void _loadCalibration(); 151 void _startCalibration(); 152 void _completeCalibration(); 153 void _evaluateCalibration(); 148 154 149 155 void _destroyKeyboard(); … … 154 160 155 161 void _reload(bool joyStickSupport); 156 157 void _completeCalibration();158 162 159 163 void _fireAxis(unsigned int iJoyStick, int axis, int value); … … 178 182 179 183 void setConfigValues(); 184 void _calibrationFileCallback(); 180 185 181 186 private: // variables … … 185 190 std::vector<OIS::JoyStick*> joySticks_; //!< OIS joy sticks 186 191 unsigned int joySticksSize_; 192 std::vector<std::string> joyStickIDs_; //!< Execution unique identification strings for the joy sticks 187 193 unsigned int devicesNum_; 188 194 size_t windowHnd_; //!< Render window handle … … 192 198 SimpleInputState* stateEmpty_; 193 199 ExtendedInputState* stateMaster_; //!< Always active master input state 194 KeyDetector* keyDetector_; //!< KeyDetector instance200 KeyDetector* keyDetector_; //!< KeyDetector instance 195 201 InputBuffer* calibratorCallbackBuffer_; 196 202 … … 207 213 208 214 // joystick calibration 209 //std::vector<int> marginalsMaxConfig_; 210 //std::vector<int> marginalsMinConfig_; 211 int marginalsMax_[24]; 212 int marginalsMin_[24]; 213 bool bCalibrated_; 214 bool bCalibrating_; 215 std::vector<std::vector<int> > joyStickMinValues_; 216 std::vector<std::vector<int> > joyStickMaxValues_; 217 std::vector<std::vector<int> > joyStickMiddleValues_; 218 std::vector<ConfigValueContainer*> calibrationConfigValueContainers_; 219 std::vector<JoyStickCalibration> joyStickCalibrations_; 215 220 216 221 unsigned int keyboardModifiers_; //!< Bit mask representing keyboard modifiers. 217 222 std::vector<POVStates> povStates_; //!< Keeps track of the joy stick POV states. 218 223 std::vector<SliderStates> sliderStates_; //!< Keeps track of the possibly two slider axes. 219 std::vector<JoyStickCalibration> joySticksCalibration_;220 224 221 225 std::vector<Key> keysDown_; … … 223 227 std::vector<std::vector<JoyStickButtonCode::ByEnum> > joyStickButtonsDown_; 224 228 225 static std::string bindingCommmandString_s; 229 // ConfigValues 230 std::string calibrationFilename_; //!< Joy stick calibration ini filename 231 226 232 static InputManager* singletonRef_s; 227 233 }; -
code/trunk/src/core/input/KeyBinder.cc
r2103 r2662 33 33 34 34 #include "KeyBinder.h" 35 35 36 #include <fstream> 36 37 #include <string> 38 37 39 #include "util/Convert.h" 38 40 #include "util/Debug.h" … … 66 68 std::string keyname = KeyCode::ByString[i]; 67 69 if (!keyname.empty()) 68 {69 70 keys_[i].name_ = std::string("Key") + keyname; 70 }71 71 else 72 { 73 // some keys have name "" because the code is not occupied by OIS 74 // Use "Key_" plus the number as name to put it at the end of the config file section 75 std::string number = convertToString(i); 76 if (i < 100) 77 number.insert(0, "0"); 78 keys_[i].name_ = std::string("Key_") + number; 79 } 72 keys_[i].name_ = ""; 80 73 keys_[i].paramCommandBuffer_ = ¶mCommandBuffer_; 81 74 keys_[i].groupName_ = "Keys"; … … 97 90 for (unsigned int i = 0; i < MouseAxisCode::numberOfAxes * 2; i++) 98 91 { 99 mouseAxes_[i].name_ = std::string("Mouse") + MouseAxisCode::ByString[i >> 1];92 mouseAxes_[i].name_ = std::string("Mouse") + MouseAxisCode::ByString[i / 2]; 100 93 if (i & 1) 101 94 mouseAxes_[i].name_ += "Pos"; … … 224 217 allHalfAxes_.clear(); 225 218 219 // Note: Don't include the dummy keys which don't actually exist in OIS but have a number 226 220 for (unsigned int i = 0; i < KeyCode::numberOfKeys; i++) 227 allButtons_[keys_[i].name_] = keys_ + i; 221 if (!keys_[i].name_.empty()) 222 allButtons_[keys_[i].name_] = keys_ + i; 228 223 for (unsigned int i = 0; i < numberOfMouseButtons_; i++) 229 224 allButtons_[mouseButtons_[i].name_] = mouseButtons_ + i; … … 327 322 if (bDeriveMouseInput_) 328 323 { 329 // only update when deriv edt has passed324 // only update when derivation dt has passed 330 325 if (deriveTime_ > derivePeriod_) 331 326 { 332 327 for (int i = 0; i < 2; i++) 333 328 { 334 if (mouseRelative_[i] >0)329 if (mouseRelative_[i] < 0) 335 330 { 336 331 mouseAxes_[2*i + 0].absVal_ 337 = 332 = -mouseRelative_[i] / deriveTime_ * 0.0005 * mouseSensitivityDerived_; 338 333 mouseAxes_[2*i + 1].absVal_ = 0.0f; 339 334 } 340 else if (mouseRelative_[i] <0)335 else if (mouseRelative_[i] > 0) 341 336 { 342 337 mouseAxes_[2*i + 0].absVal_ = 0.0f; 343 338 mouseAxes_[2*i + 1].absVal_ 344 = -mouseRelative_[i] / deriveTime_ * 0.0005 * mouseSensitivityDerived_;339 = mouseRelative_[i] / deriveTime_ * 0.0005 * mouseSensitivityDerived_; 345 340 } 346 341 else … … 363 358 // Why dividing relative value by dt? The reason lies in the simple fact, that when you 364 359 // press a button that has relative movement, that value has to be multiplied by dt to be 365 // frame rate independ ant. This can easily (and only) be done in tickInput(float).360 // frame rate independent. This can easily (and only) be done in tickInput(float). 366 361 // Hence we need to divide by dt here for the mouse to compensate, because the relative 367 362 // move movements have nothing to do with dt. … … 441 436 for (int i = 0; i < 2; i++) 442 437 { 443 if (rel[i]) // performance opt. ifrel[i] == 0438 if (rel[i]) // performance opt. for the case that rel[i] == 0 444 439 { 445 440 // write absolute values … … 454 449 mousePosition_[i] = -mouseClippingSize_; 455 450 456 if (mousePosition_[i] >=0)451 if (mousePosition_[i] < 0) 457 452 { 458 mouseAxes_[2*i + 0].absVal_ = 453 mouseAxes_[2*i + 0].absVal_ = -mousePosition_[i]/(float)mouseClippingSize_ * mouseSensitivity_; 459 454 mouseAxes_[2*i + 1].absVal_ = 0.0f; 460 455 } … … 462 457 { 463 458 mouseAxes_[2*i + 0].absVal_ = 0.0f; 464 mouseAxes_[2*i + 1].absVal_ = -mousePosition_[i]/(float)mouseClippingSize_ * mouseSensitivity_;459 mouseAxes_[2*i + 1].absVal_ = mousePosition_[i]/(float)mouseClippingSize_ * mouseSensitivity_; 465 460 } 466 461 } … … 471 466 for (int i = 0; i < 2; i++) 472 467 { 473 if (rel[i] >0)474 mouseAxes_[0 + 2*i].relVal_ = 468 if (rel[i] < 0) 469 mouseAxes_[0 + 2*i].relVal_ = -((float)rel[i])/(float)mouseClippingSize_ * mouseSensitivity_; 475 470 else 476 mouseAxes_[1 + 2*i].relVal_ = -((float)rel[i])/(float)mouseClippingSize_ * mouseSensitivity_;471 mouseAxes_[1 + 2*i].relVal_ = ((float)rel[i])/(float)mouseClippingSize_ * mouseSensitivity_; 477 472 } 478 473 } … … 484 479 void KeyBinder::mouseScrolled(int abs, int rel) 485 480 { 486 if (rel >0)487 for (int i = 0; i < rel/mouseWheelStepSize_; i++)481 if (rel < 0) 482 for (int i = 0; i < -rel/mouseWheelStepSize_; i++) 488 483 mouseButtons_[8].execute(KeybindMode::OnPress, ((float)abs)/mouseWheelStepSize_); 489 484 else 490 for (int i = 0; i < -rel/mouseWheelStepSize_; i++)485 for (int i = 0; i < rel/mouseWheelStepSize_; i++) 491 486 mouseButtons_[9].execute(KeybindMode::OnPress, ((float)abs)/mouseWheelStepSize_); 492 487 } … … 495 490 { 496 491 int i = axis * 2; 497 if (value >=0)498 { 499 joyStickAxes_[joyStickID][i].absVal_ = value;500 joyStickAxes_[joyStickID][i].relVal_ = value;492 if (value < 0) 493 { 494 joyStickAxes_[joyStickID][i].absVal_ = -value; 495 joyStickAxes_[joyStickID][i].relVal_ = -value; 501 496 joyStickAxes_[joyStickID][i].hasChanged_ = true; 502 497 if (joyStickAxes_[joyStickID][i + 1].absVal_ > 0.0f) … … 509 504 else 510 505 { 511 joyStickAxes_[joyStickID][i + 1].absVal_ = -value;512 joyStickAxes_[joyStickID][i + 1].relVal_ = -value;506 joyStickAxes_[joyStickID][i + 1].absVal_ = value; 507 joyStickAxes_[joyStickID][i + 1].relVal_ = value; 513 508 joyStickAxes_[joyStickID][i + 1].hasChanged_ = true; 514 509 if (joyStickAxes_[joyStickID][i].absVal_ > 0.0f) -
code/trunk/src/core/input/KeyBinder.h
r2103 r2662 39 39 40 40 #include <vector> 41 #include <cassert> 42 41 43 #include "InputInterfaces.h" 42 44 #include "Button.h" … … 44 46 #include "InputCommands.h" 45 47 #include "JoyStickDeviceNumberListener.h" 46 #include "core/ConfigFileManager.h"47 48 48 49 namespace orxonox … … 171 172 172 173 inline void KeyBinder::keyPressed (const KeyEvent& evt) 173 { keys_[evt.key].execute(KeybindMode::OnPress); }174 { assert(!keys_[evt.key].name_.empty()); keys_[evt.key].execute(KeybindMode::OnPress); } 174 175 175 176 inline void KeyBinder::keyReleased(const KeyEvent& evt) 176 { keys_[evt.key].execute(KeybindMode::OnRelease); }177 { assert(!keys_[evt.key].name_.empty()); keys_[evt.key].execute(KeybindMode::OnRelease); } 177 178 178 179 inline void KeyBinder::keyHeld (const KeyEvent& evt) 179 { keys_[evt.key].execute(KeybindMode::OnHold); }180 { assert(!keys_[evt.key].name_.empty()); keys_[evt.key].execute(KeybindMode::OnHold); } 180 181 181 182
Note: See TracChangeset
for help on using the changeset viewer.