Changeset 2485 for code/branches/presentation/src/core
- Timestamp:
- Dec 16, 2008, 6:01:13 PM (16 years ago)
- Location:
- code/branches/presentation
- Files:
-
- 31 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation
-
code/branches/presentation/src/core/BaseObject.cc
r2171 r2485 36 36 #include "CoreIncludes.h" 37 37 #include "EventIncludes.h" 38 #include "Functor.h" 38 39 #include "XMLPort.h" 39 40 #include "XMLFile.h" … … 60 61 this->oldGametype_ = 0; 61 62 63 this->functorSetMainState_ = 0; 64 this->functorGetMainState_ = 0; 65 62 66 this->setCreator(creator); 63 67 if (this->creator_) … … 82 86 BaseObject::~BaseObject() 83 87 { 84 for (std::list<BaseObject*>::const_iterator it = this->events_.begin(); it != this->events_.end(); ++it) 85 (*it)->unregisterEventListener(this); 86 87 for (std::map<BaseObject*, std::string>::const_iterator it = this->eventListeners_.begin(); it != this->eventListeners_.end(); ++it) 88 it->first->removeEvent(this); 88 if (this->isInitialized()) 89 { 90 for (std::list<BaseObject*>::const_iterator it = this->events_.begin(); it != this->events_.end(); ++it) 91 (*it)->unregisterEventListener(this); 92 93 for (std::map<BaseObject*, std::string>::const_iterator it = this->eventListeners_.begin(); it != this->eventListeners_.end(); ++it) 94 it->first->removeEvent(this); 95 96 if (this->functorSetMainState_) 97 delete this->functorSetMainState_; 98 if (this->functorGetMainState_) 99 delete this->functorGetMainState_; 100 } 89 101 } 90 102 … … 100 112 XMLPortParam(BaseObject, "visible", setVisible, isVisible, xmlelement, mode); 101 113 XMLPortParam(BaseObject, "active", setActive, isActive, xmlelement, mode); 114 XMLPortParam(BaseObject, "mainstate", setMainStateName, getMainStateName, xmlelement, mode); 102 115 103 116 XMLPortObjectTemplate(BaseObject, Template, "templates", addTemplate, getTemplate, xmlelement, mode, Template*); … … 109 122 std::list<std::string> eventnames; 110 123 111 if (mode == XMLPort::LoadObject )124 if (mode == XMLPort::LoadObject || mode == XMLPort::ExpandObject) 112 125 { 113 126 for (ticpp::Iterator<ticpp::Element> child = events->FirstChildElement(false); child != child.end(); child++) … … 279 292 SetEvent(BaseObject, "visibility", setVisible, event); 280 293 } 294 295 void BaseObject::setMainStateName(const std::string& name) 296 { 297 if (this->mainStateName_ != name) 298 { 299 this->mainStateName_ = name; 300 if (this->functorSetMainState_) 301 delete this->functorSetMainState_; 302 if (this->functorGetMainState_) 303 delete this->functorGetMainState_; 304 this->changedMainState(); 305 if (!this->functorSetMainState_) 306 COUT(2) << "Warning: \"" << name << "\" is not a valid MainState." << std::endl; 307 } 308 } 309 310 void BaseObject::setMainState(bool state) 311 { 312 if (this->functorSetMainState_) 313 (*this->functorSetMainState_)(state); 314 else 315 COUT(2) << "Warning: No MainState defined in object \"" << this->getName() << "\" (" << this->getIdentifier()->getName() << ")" << std::endl; 316 } 317 318 bool BaseObject::getMainState() const 319 { 320 if (this->functorGetMainState_) 321 { 322 (*this->functorGetMainState_)(); 323 return this->functorGetMainState_->getReturnvalue(); 324 } 325 else 326 { 327 COUT(2) << "Warning: No MainState defined in object \"" << this->getName() << "\" (" << this->getIdentifier()->getName() << ")" << std::endl; 328 return false; 329 } 330 } 331 332 void BaseObject::changedMainState() 333 { 334 SetMainState(BaseObject, "activity", setActive, isActive); 335 SetMainState(BaseObject, "visibility", setVisible, isVisible); 336 } 281 337 } -
code/branches/presentation/src/core/BaseObject.h
r2171 r2485 36 36 #ifndef _BaseObject_H__ 37 37 #define _BaseObject_H__ 38 39 #define SetMainState(classname, statename, setfunction, getfunction) \ 40 if (this->getMainStateName() == statename) \ 41 { \ 42 this->functorSetMainState_ = createFunctor(&classname::setfunction)->setObject(this); \ 43 this->functorGetMainState_ = createFunctor(&classname::getfunction)->setObject(this); \ 44 } 38 45 39 46 #include <map> … … 100 107 virtual void changedVisibility() {} 101 108 109 void setMainState(bool state); 110 bool getMainState() const; 111 112 void setMainStateName(const std::string& name); 113 inline const std::string& getMainStateName() const { return this->mainStateName_; } 114 virtual void changedMainState(); 115 102 116 /** @brief Sets a pointer to the xml file that loaded this object. @param file The pointer to the XMLFile */ 103 117 inline void setFile(const XMLFile* file) { this->file_ = file; } … … 121 135 inline Scene* getScene() const { return this->scene_; } 122 136 123 inline void setGametype(Gametype* gametype) { this->oldGametype_ = this->gametype_; this->gametype_ = gametype; this->changedGametype(); } 137 inline void setGametype(Gametype* gametype) 138 { 139 if (gametype != this->gametype_) 140 { 141 this->oldGametype_ = this->gametype_; 142 this->gametype_ = gametype; 143 this->changedGametype(); 144 } 145 } 124 146 inline Gametype* getGametype() const { return this->gametype_; } 125 147 inline Gametype* getOldGametype() const { return this->oldGametype_; } 126 virtual inlinevoid changedGametype() {}148 virtual void changedGametype() {} 127 149 128 150 void fireEvent(); … … 153 175 std::string name_; //!< The name of the object 154 176 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 mbool bActive_; //!< True = the object is active 178 mbool bVisible_; //!< True = the object is visible 179 std::string mainStateName_; 180 Functor* functorSetMainState_; 181 Functor* functorGetMainState_; 157 182 158 183 private: … … 160 185 Template* getTemplate(unsigned int index) const; 161 186 162 bool bInitialized_; //!< True if the object was initialized (passed the object registration)163 const XMLFile* file_; //!< The XMLFile that loaded this object164 std::string loaderIndentation_; //!< Indentation of the debug output in the Loader165 Namespace* namespace_;166 BaseObject* creator_;167 Scene* scene_;168 Gametype* gametype_;169 Gametype* oldGametype_;170 std::set<Template*> templates_;171 std::map<BaseObject*, std::string> eventListeners_;187 bool bInitialized_; //!< True if the object was initialized (passed the object registration) 188 const XMLFile* file_; //!< The XMLFile that loaded this object 189 std::string loaderIndentation_; //!< Indentation of the debug output in the Loader 190 Namespace* namespace_; 191 BaseObject* creator_; 192 Scene* scene_; 193 Gametype* gametype_; 194 Gametype* oldGametype_; 195 std::set<Template*> templates_; 196 std::map<BaseObject*, std::string> eventListeners_; 172 197 std::list<BaseObject*> events_; 173 198 std::map<std::string, EventContainer*> eventContainers_; … … 178 203 SUPER_FUNCTION(3, BaseObject, changedVisibility, false); 179 204 SUPER_FUNCTION(4, BaseObject, processEvent, false); 205 SUPER_FUNCTION(6, BaseObject, changedMainState, false); 206 SUPER_FUNCTION(9, BaseObject, changedName, false); 207 SUPER_FUNCTION(10, BaseObject, changedGametype, false); 180 208 } 181 209 -
code/branches/presentation/src/core/CommandExecutor.cc
r1784 r2485 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/branches/presentation/src/core/CommandExecutor.h
r1771 r2485 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/branches/presentation/src/core/CommandLine.cc
r2105 r2485 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/branches/presentation/src/core/CommandLine.h
r2103 r2485 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/branches/presentation/src/core/ConsoleCommand.h
r2087 r2485 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/branches/presentation/src/core/Core.cc
r2171 r2485 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/branches/presentation/src/core/Core.h
r2171 r2485 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/branches/presentation/src/core/CorePrereqs.h
r2087 r2485 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/branches/presentation/src/core/Functor.h
r2087 r2485 167 167 } 168 168 169 FunctorMember * setObject(T* object)169 FunctorMember<T>* setObject(T* object) 170 170 { 171 171 this->bConstObject_ = false; … … 174 174 } 175 175 176 FunctorMember * setObject(const T* object)176 FunctorMember<T>* setObject(const T* object) 177 177 { 178 178 this->bConstObject_ = true; -
code/branches/presentation/src/core/Identifier.cc
r2371 r2485 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 } -
code/branches/presentation/src/core/Identifier.h
r2371 r2485 258 258 void initializeClassHierarchy(std::set<const Identifier*>* parents, bool bRootClass); 259 259 260 static void destroyAllIdentifiers(); 261 260 262 protected: 261 263 Identifier(); … … 300 302 } 301 303 304 static std::map<std::string, Identifier*>& getTypeIDIdentifierMap(); 305 302 306 void initialize(std::set<const Identifier*>* parents); 303 304 static void destroyAllIdentifiers();305 307 306 308 std::set<const Identifier*> parents_; //!< The parents of the class the Identifier belongs to -
code/branches/presentation/src/core/Language.cc
r2171 r2485 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 -
code/branches/presentation/src/core/Language.h
r2171 r2485 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/branches/presentation/src/core/Loader.cc
r2171 r2485 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/branches/presentation/src/core/LuaBind.cc
r2087 r2485 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/branches/presentation/src/core/LuaBind.h
r2087 r2485 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/branches/presentation/src/core/RootGameState.cc
r2459 r2485 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" … … 138 137 Clock clock; 139 138 140 // create the Core settings to configure the output level141 Core::getInstance();142 143 139 this->activate(); 144 140 -
code/branches/presentation/src/core/RootGameState.h
r2103 r2485 48 48 void gotoState(const std::string& name); 49 49 50 std::string 50 std::string stateRequest_; 51 51 }; 52 52 } -
code/branches/presentation/src/core/Shell.cc
r1792 r2485 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/branches/presentation/src/core/Super.h
r2171 r2485 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/branches/presentation/src/core/Template.cc
- Property svn:mergeinfo changed
/code/branches/objecthierarchy2/src/core/Template.cc (added) merged: 2173,2369
r2459 r2485 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/branches/presentation/src/core/Template.h
- Property svn:mergeinfo changed
/code/branches/objecthierarchy2/src/core/Template.h (added) merged: 2173
r2459 r2485 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/branches/presentation/src/core/XMLFile.h
- Property svn:mergeinfo changed
/code/trunk/src/core/XMLFile.h merged: 2-1912
- Property svn:mergeinfo changed
-
code/branches/presentation/src/core/XMLIncludes.h
- Property svn:mergeinfo changed (with no actual effect on merging)
-
code/branches/presentation/src/core/XMLPort.h
r2459 r2485 43 43 #include "CorePrereqs.h" 44 44 45 #include <cassert> 45 46 #include "util/Debug.h" 46 47 #include "util/Exception.h" … … 369 370 } 370 371 372 ~XMLPortClassParamContainer() 373 { 374 assert(this->loadexecutor_); 375 delete this->loadexecutor_; 376 if (this->saveexecutor_) 377 delete this->saveexecutor_; 378 } 379 371 380 XMLPortParamContainer& port(BaseObject* owner, T* object, Element& xmlelement, XMLPort::Mode mode) 372 381 { … … 376 385 this->parseParams_.mode = mode; 377 386 378 if ( mode == XMLPort::LoadObject)387 if ((mode == XMLPort::LoadObject) || (mode == XMLPort::ExpandObject)) 379 388 { 380 389 try 381 390 { 382 391 std::string attribute = xmlelement.GetAttribute(this->paramname_); 383 if ((attribute.size() > 0) || ( this->loadexecutor_->allDefaultValuesSet()))392 if ((attribute.size() > 0) || ((mode != XMLPort::ExpandObject) && this->loadexecutor_->allDefaultValuesSet())) 384 393 { 385 394 COUT(5) << this->owner_->getLoaderIndentation() << "Loading parameter " << this->paramname_ << " in " << this->identifier_->getName() << " (objectname " << this->owner_->getName() << ")." << std::endl << this->owner_->getLoaderIndentation(); 386 if (this->loadexecutor_->parse(object, attribute, ",") )395 if (this->loadexecutor_->parse(object, attribute, ",") || (mode == XMLPort::ExpandObject)) 387 396 this->parseResult_ = PR_finished; 388 397 else 389 398 this->parseResult_ = PR_waiting_for_default_values; 390 399 } 400 else if (mode == XMLPort::ExpandObject) 401 this->parseResult_ = PR_finished; 391 402 else 392 403 this->parseResult_ = PR_waiting_for_default_values; … … 511 522 } 512 523 524 ~XMLPortClassObjectContainer() 525 { 526 assert(this->loadexecutor_); 527 delete this->loadexecutor_; 528 if (this->saveexecutor_) 529 delete this->saveexecutor_; 530 } 531 513 532 XMLPortObjectContainer& port(T* object, Element& xmlelement, XMLPort::Mode mode) 514 533 { 515 if ( mode == XMLPort::LoadObject)534 if ((mode == XMLPort::LoadObject) || (mode == XMLPort::ExpandObject)) 516 535 { 517 536 try -
code/branches/presentation/src/core/input/Button.cc
r2103 r2485 59 59 nCommands_[1]=0; 60 60 nCommands_[2]=0; 61 this->configContainer_ = 0; 61 62 clear(); 62 63 } … … 80 81 } 81 82 } 83 84 if (this->configContainer_) 85 delete this->configContainer_; 86 this->configContainer_ = 0; 82 87 } 83 88 -
code/branches/presentation/src/core/input/InputBuffer.cc
r1755 r2485 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/branches/presentation/src/core/input/InputBuffer.h
r1887 r2485 79 79 public: 80 80 InputBuffer(); 81 ~InputBuffer(); 81 82 InputBuffer(const std::string allowedChars); 82 83
Note: See TracChangeset
for help on using the changeset viewer.