Changeset 2344 for code/branches/objecthierarchy2/src
- Timestamp:
- Dec 4, 2008, 8:28:14 PM (16 years ago)
- Location:
- code/branches/objecthierarchy2/src
- Files:
-
- 36 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchy2/src/core/CommandExecutor.cc
r1784 r2344 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/objecthierarchy2/src/core/CommandExecutor.h
r1771 r2344 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/objecthierarchy2/src/core/CommandLine.cc
r2105 r2344 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/objecthierarchy2/src/core/CommandLine.h
r2103 r2344 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/objecthierarchy2/src/core/ConsoleCommand.h
r2087 r2344 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/objecthierarchy2/src/core/Core.cc
r2171 r2344 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(singletonRef_s == 0); 59 singletonRef_s = this; 60 55 61 this->setConfigValues(); 56 isCreatingCoreSettings() = false;57 62 } 58 63 … … 62 67 Core::~Core() 63 68 { 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; 69 assert(singletonRef_s); 70 singletonRef_s = 0; 95 71 } 96 72 … … 140 116 int Core::getSoftDebugLevel(OutputHandler::OutputDevice device) 141 117 { 142 if (!Core::isCreatingCoreSettings())118 switch (device) 143 119 { 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 } 120 case OutputHandler::LD_All: 121 return Core::getInstance().softDebugLevel_; 122 case OutputHandler::LD_Console: 123 return Core::getInstance().softDebugLevelConsole_; 124 case OutputHandler::LD_Logfile: 125 return Core::getInstance().softDebugLevelLogfile_; 126 case OutputHandler::LD_Shell: 127 return Core::getInstance().softDebugLevelShell_; 128 default: 129 assert(0); 130 return 2; 157 131 } 158 159 // Return a constant value while we're creating the object160 return 2;161 132 } 162 133 … … 168 139 void Core::setSoftDebugLevel(OutputHandler::OutputDevice device, int level) 169 140 { 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; 141 if (device == OutputHandler::LD_All) 142 Core::getInstance().softDebugLevel_ = level; 143 else if (device == OutputHandler::LD_Console) 144 Core::getInstance().softDebugLevelConsole_ = level; 145 else if (device == OutputHandler::LD_Logfile) 146 Core::getInstance().softDebugLevelLogfile_ = level; 147 else if (device == OutputHandler::LD_Shell) 148 Core::getInstance().softDebugLevelShell_ = level; 180 149 181 OutputHandler::setSoftDebugLevel(device, level); 182 } 150 OutputHandler::setSoftDebugLevel(device, level); 183 151 } 184 152 … … 188 156 const std::string& Core::getLanguage() 189 157 { 190 if (!Core::isCreatingCoreSettings()) 191 return Core::getInstance().language_; 192 193 return Language::getLanguage().defaultLanguage_; 158 return Core::getInstance().language_; 194 159 } 195 160 -
code/branches/objecthierarchy2/src/core/Core.h
r2171 r2344 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(singletonRef_s); return *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 80 81 81 int softDebugLevel_; //!< The debug level … … 90 90 static bool bIsStandalone_s; 91 91 static bool bIsMaster_s; 92 93 static Core* singletonRef_s; 92 94 }; 93 95 } -
code/branches/objecthierarchy2/src/core/CorePrereqs.h
r2173 r2344 133 133 class LanguageEntry; 134 134 class Loader; 135 class LuaBind; 135 136 class MetaObjectList; 136 137 class MetaObjectListElement; -
code/branches/objecthierarchy2/src/core/Identifier.cc
r2171 r2344 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/objecthierarchy2/src/core/Identifier.h
r2171 r2344 257 257 void initializeClassHierarchy(std::set<const Identifier*>* parents, bool bRootClass); 258 258 259 static void destroyAllIdentifiers(); 260 259 261 protected: 260 262 Identifier(); … … 299 301 } 300 302 303 static std::map<std::string, Identifier*>& getTypeIDIdentifierMap(); 304 301 305 void initialize(std::set<const Identifier*>* parents); 302 303 static void destroyAllIdentifiers();304 306 305 307 std::set<const Identifier*> parents_; //!< The parents of the class the Identifier belongs to -
code/branches/objecthierarchy2/src/core/Language.cc
r2171 r2344 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/objecthierarchy2/src/core/Language.h
r2171 r2344 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/objecthierarchy2/src/core/Loader.cc
r2171 r2344 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/objecthierarchy2/src/core/LuaBind.cc
r2087 r2344 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/objecthierarchy2/src/core/LuaBind.h
r2087 r2344 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/objecthierarchy2/src/core/RootGameState.cc
r2103 r2344 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" … … 137 136 Clock clock; 138 137 139 // create the Core settings to configure the output level140 Core::getInstance();141 142 138 this->activate(); 143 139 -
code/branches/objecthierarchy2/src/core/RootGameState.h
r2103 r2344 48 48 void gotoState(const std::string& name); 49 49 50 std::string 50 std::string stateRequest_; 51 51 }; 52 52 } -
code/branches/objecthierarchy2/src/core/XMLPort.h
r2173 r2344 43 43 #include "CorePrereqs.h" 44 44 45 #include <cassert> 45 46 #include "util/Debug.h" 46 47 #include "util/Exception.h" … … 327 328 this->loadexecutor_ = loadexecutor; 328 329 this->saveexecutor_ = saveexecutor; 330 } 331 332 ~XMLPortClassParamContainer() 333 { 334 assert(this->loadexecutor_); 335 delete this->loadexecutor_; 336 if (this->saveexecutor_) 337 delete this->saveexecutor_; 329 338 } 330 339 … … 471 480 this->bApplyLoaderMask_ = bApplyLoaderMask; 472 481 this->bLoadBefore_ = bLoadBefore; 482 } 483 484 ~XMLPortClassObjectContainer() 485 { 486 assert(this->loadexecutor_); 487 delete this->loadexecutor_; 488 if (this->saveexecutor_) 489 delete this->saveexecutor_; 473 490 } 474 491 -
code/branches/objecthierarchy2/src/core/input/Button.cc
r2103 r2344 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/objecthierarchy2/src/core/input/InputBuffer.cc
r1755 r2344 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/objecthierarchy2/src/core/input/InputBuffer.h
r1887 r2344 79 79 public: 80 80 InputBuffer(); 81 ~InputBuffer(); 81 82 InputBuffer(const std::string allowedChars); 82 83 -
code/branches/objecthierarchy2/src/orxonox/LevelManager.cc
r2173 r2344 42 42 assert(singletonRef_s == 0); 43 43 singletonRef_s = this; 44 45 PlayerManager::getInstance(); // ensure existence of PlayerManager46 44 } 47 45 -
code/branches/objecthierarchy2/src/orxonox/Main.cc
r2103 r2344 43 43 #include "core/ConfigFileManager.h" 44 44 #include "core/CommandLine.h" 45 #include "core/CommandExecutor.h" 46 #include "core/Identifier.h" 47 #include "core/Core.h" 48 #include "core/Language.h" 45 49 46 50 #include "gamestates/GSRoot.h" … … 92 96 93 97 // create a signal handler (only works for linux) 94 SignalHandler::getInstance()->doCatch(argv[0], "orxonox.log"); 98 SignalHandler signalHandler; 99 signalHandler.doCatch(argv[0], "orxonox.log"); 95 100 96 101 // Parse command line arguments … … 109 114 ConfigFileManager* configFileManager = new ConfigFileManager(); 110 115 configFileManager->setFilename(ConfigFileType::Settings, CommandLine::getValue("settingsFile").getString()); 116 // create the Core settings to configure the output level 117 Language* language = new Language(); 118 Core* core = new Core(); 111 119 112 // create the gamestates 113 GSRoot root; 114 GSGraphics graphics; 115 GSStandalone standalone; 116 GSServer server; 117 GSClient client; 118 GSDedicated dedicated; 119 GSGUI gui; 120 GSIOConsole ioConsole; 120 // put GameStates in its own scope so we can destroy the identifiers at the end of main(). 121 { 122 // create the gamestates 123 GSRoot root; 124 GSGraphics graphics; 125 GSStandalone standalone; 126 GSServer server; 127 GSClient client; 128 GSDedicated dedicated; 129 GSGUI gui; 130 GSIOConsole ioConsole; 121 131 122 // make the hierarchy123 root.addChild(&graphics);124 graphics.addChild(&standalone);125 graphics.addChild(&server);126 graphics.addChild(&client);127 graphics.addChild(&gui);128 root.addChild(&ioConsole);129 root.addChild(&dedicated);132 // make the hierarchy 133 root.addChild(&graphics); 134 graphics.addChild(&standalone); 135 graphics.addChild(&server); 136 graphics.addChild(&client); 137 graphics.addChild(&gui); 138 root.addChild(&ioConsole); 139 root.addChild(&dedicated); 130 140 131 // Here happens the game 132 root.start(); 141 // Here happens the game 142 root.start(); 143 } 133 144 134 // Destroy ConfigFileManager again. 145 // destroy singletons 146 delete core; 147 delete language; 135 148 delete configFileManager; 149 150 // Clean up class hierarchy stuff (identifiers, xmlport, configvalue, consolecommand) 151 Identifier::destroyAllIdentifiers(); 152 // destroy command line arguments 153 CommandLine::destroyAllArguments(); 154 // Also delete external console command that don't belong to an Identifier 155 CommandExecutor::destroyExternalCommands(); 136 156 137 157 return 0; -
code/branches/objecthierarchy2/src/orxonox/PlayerManager.cc
r2171 r2344 38 38 namespace orxonox 39 39 { 40 PlayerManager* PlayerManager::singletonRef_s = 0; 41 40 42 PlayerManager::PlayerManager() 41 43 { 42 44 RegisterRootObject(PlayerManager); 45 46 assert(singletonRef_s == 0); 47 singletonRef_s = this; 43 48 44 49 this->getConnectedClients(); … … 47 52 PlayerManager::~PlayerManager() 48 53 { 49 } 50 51 PlayerManager& PlayerManager::getInstance() 52 { 53 static PlayerManager instance; 54 return instance; 54 assert(singletonRef_s); 55 singletonRef_s = 0; 55 56 } 56 57 -
code/branches/objecthierarchy2/src/orxonox/PlayerManager.h
r2171 r2344 43 43 virtual ~PlayerManager(); 44 44 45 static PlayerManager& getInstance(); 45 static PlayerManager& getInstance() 46 { assert(singletonRef_s); return *singletonRef_s; } 46 47 47 48 PlayerInfo* getClient(unsigned int clientID) const; … … 54 55 55 56 std::map<unsigned int, PlayerInfo*> clients_; 57 58 static PlayerManager* singletonRef_s; 56 59 }; 57 60 } -
code/branches/objecthierarchy2/src/orxonox/Settings.cc
r2087 r2344 83 83 } 84 84 85 LuaBind::getInstance() ->setIncludePath(this->dataPath_);85 LuaBind::getInstance().setIncludePath(this->dataPath_); 86 86 } 87 87 -
code/branches/objecthierarchy2/src/orxonox/gamestates/GSGraphics.cc
r2171 r2344 164 164 FunctorMember<GSGraphics>* functor1 = createFunctor(&GSGraphics::printScreen); 165 165 functor1->setObject(this); 166 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor1, "printScreen")); 166 ccPrintScreen_ = createConsoleCommand(functor1, "printScreen"); 167 CommandExecutor::addConsoleCommandShortcut(ccPrintScreen_); 167 168 } 168 169 … … 170 171 { 171 172 using namespace Ogre; 173 174 delete this->ccPrintScreen_; 172 175 173 176 // remove our WindowEventListener first to avoid bad calls after the window has been destroyed -
code/branches/objecthierarchy2/src/orxonox/gamestates/GSGraphics.h
r2103 r2344 112 112 unsigned int detailLevelParticle_; //!< Detail level of particle effects (0: off, 1: low, 2: normal, 3: high) 113 113 std::string defaultMasterKeybindings_; //!< Filename of default master keybindings. 114 115 // console commands 116 ConsoleCommand* ccPrintScreen_; 114 117 }; 115 118 } -
code/branches/objecthierarchy2/src/orxonox/gamestates/GSLevel.cc
r2173 r2344 47 47 #include "CameraManager.h" 48 48 #include "LevelManager.h" 49 #include "PlayerManager.h" 49 50 #include "Settings.h" 50 51 … … 99 100 // create the global LevelManager 100 101 this->levelManager_ = new LevelManager(); 102 this->playerManager_ = new PlayerManager(); 101 103 102 104 // reset game speed to normal … … 114 116 FunctorMember<GSLevel>* functor1 = createFunctor(&GSLevel::keybind); 115 117 functor1->setObject(this); 116 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor1, "keybind")); 118 ccKeybind_ = createConsoleCommand(functor1, "keybind"); 119 CommandExecutor::addConsoleCommandShortcut(ccKeybind_); 117 120 FunctorMember<GSLevel>* functor2 = createFunctor(&GSLevel::tkeybind); 118 121 functor2->setObject(this); 119 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor2, "tkeybind")); 122 ccTkeybind_ = createConsoleCommand(functor2, "tkeybind"); 123 CommandExecutor::addConsoleCommandShortcut(ccTkeybind_); 120 124 // set our console command as callback for the key detector 121 125 InputManager::getInstance().setKeyDetectorCallback(std::string("keybind ") + keyDetectorCallbackCode_); … … 130 134 FunctorMember<GSLevel>* functor = createFunctor(&GSLevel::setTimeFactor); 131 135 functor->setObject(this); 132 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor, "setTimeFactor")).accessLevel(AccessLevel::Offline).defaultValue(0, 1.0);; 136 ccSetTimeFactor_ = createConsoleCommand(functor, "setTimeFactor"); 137 CommandExecutor::addConsoleCommandShortcut(ccSetTimeFactor_).accessLevel(AccessLevel::Offline).defaultValue(0, 1.0);; 133 138 } 134 139 } … … 136 141 void GSLevel::leave() 137 142 { 143 // destroy console commands 144 delete this->ccKeybind_; 145 delete this->ccSetTimeFactor_; 146 delete this->ccTkeybind_; 147 138 148 // this call will delete every BaseObject! 139 149 // But currently this will call methods of objects that exist no more … … 156 166 if (this->levelManager_) 157 167 delete this->levelManager_; 168 169 if (this->playerManager_) 170 delete this->playerManager_; 158 171 159 172 if (Core::showsGraphics()) -
code/branches/objecthierarchy2/src/orxonox/gamestates/GSLevel.h
r2103 r2344 70 70 CameraManager* cameraManager_; 71 71 LevelManager* levelManager_; 72 PlayerManager* playerManager_; 72 73 73 74 //##### ConfigValues ##### … … 75 76 //! Filename of default keybindings. 76 77 std::string defaultKeybindings_; 78 79 // console commands 80 ConsoleCommand* ccKeybind_; 81 ConsoleCommand* ccTkeybind_; 82 ConsoleCommand* ccSetTimeFactor_; 77 83 78 84 private: -
code/branches/objecthierarchy2/src/orxonox/gamestates/GSRoot.cc
r2171 r2344 40 40 #include "core/TclBind.h" 41 41 #include "core/TclThreadManager.h" 42 #include "core/LuaBind.h" 42 43 #include "tools/Timer.h" 43 44 #include "objects/Tickable.h" … … 87 88 // creates the class hierarchy for all classes with factories 88 89 Factory::createClassHierarchy(); 90 91 // Create the lua interface 92 this->luaBind_ = new LuaBind(); 89 93 90 94 // instantiate Settings class … … 117 121 FunctorMember<GSRoot>* functor1 = createFunctor(&GSRoot::exitGame); 118 122 functor1->setObject(this); 119 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor1, "exit")); 123 ccExit_ = createConsoleCommand(functor1, "exit"); 124 CommandExecutor::addConsoleCommandShortcut(ccExit_); 120 125 121 126 // add console commands 122 127 FunctorMember01<GameStateBase, const std::string&>* functor2 = createFunctor(&GameStateBase::requestState); 123 128 functor2->setObject(this); 124 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor2, "selectGameState")); 129 ccSelectGameState_ = createConsoleCommand(functor2, "selectGameState"); 130 CommandExecutor::addConsoleCommandShortcut(ccSelectGameState_); 125 131 } 126 132 127 133 void GSRoot::leave() 128 134 { 129 // TODO: remove and destroy console commands 135 // destroy console commands 136 delete this->ccExit_; 137 delete this->ccSelectGameState_; 130 138 131 139 delete this->shell_; … … 133 141 delete this->tclBind_; 134 142 135 delete settings_;136 143 delete this->settings_; 144 delete this->luaBind_; 137 145 } 138 146 -
code/branches/objecthierarchy2/src/orxonox/gamestates/GSRoot.h
r1891 r2344 59 59 TclThreadManager* tclThreadManager_; 60 60 Shell* shell_; 61 LuaBind* luaBind_; 62 63 // console commands 64 ConsoleCommand* ccExit_; 65 ConsoleCommand* ccSelectGameState_; 61 66 }; 62 67 } -
code/branches/objecthierarchy2/src/orxonox/gui/GUIManager.cc
r2087 r2344 96 96 { 97 97 // destroy our own tolua interfaces 98 //lua_pushnil(luaState_);99 //lua_setglobal(luaState_, "Orxonox");100 //lua_pushnil(luaState_);101 //lua_setglobal(luaState_, "Core");98 lua_pushnil(luaState_); 99 lua_setglobal(luaState_, "Orxonox"); 100 lua_pushnil(luaState_); 101 lua_setglobal(luaState_, "Core"); 102 102 // TODO: deleting the script module fails an assertation. 103 103 // However there is not much we can do about it since it occurs too when 104 104 // we don't open Core or Orxonox. Might be a CEGUI issue. 105 105 // The memory leak is not a problem anyway.. 106 //delete scriptModule_;106 delete scriptModule_; 107 107 } 108 108 -
code/branches/objecthierarchy2/src/orxonox/objects/Script.cc
r2087 r2344 64 64 void Script::execute() 65 65 { 66 LuaBind *lua = LuaBind::getInstance();67 lua ->loadString(this->code_);68 lua ->run();66 LuaBind& lua = LuaBind::getInstance(); 67 lua.loadString(this->code_); 68 lua.run(); 69 69 } 70 70 } -
code/branches/objecthierarchy2/src/util/SignalHandler.cc
r2171 r2344 35 35 #include "Debug.h" 36 36 37 #include <cassert>38 37 #include <iostream> 39 38 #include <cstdlib> … … 42 41 namespace orxonox 43 42 { 44 SignalHandler * SignalHandler::singletonRef= NULL;43 SignalHandler* SignalHandler::singletonRef_s = NULL; 45 44 } 46 45 … … 133 132 void SignalHandler::sigHandler( int sig ) 134 133 { 135 for ( SignalCallbackList::iterator it = SignalHandler::getInstance() ->callbackList.begin(); it != SignalHandler::getInstance()->callbackList.end(); it++ )134 for ( SignalCallbackList::iterator it = SignalHandler::getInstance().callbackList.begin(); it != SignalHandler::getInstance().callbackList.end(); it++ ) 136 135 { 137 136 (*(it->cb))( it->someData ); … … 184 183 if ( sigPid == 0 ) 185 184 { 186 getInstance() ->dontCatch();185 getInstance().dontCatch(); 187 186 // wait for message from parent when it has attached gdb 188 187 int someData; … … 237 236 238 237 char cmd[256]; 239 snprintf( cmd, 256, "file %s\nattach %d\nc\n", getInstance() ->appName.c_str(), sigPid );238 snprintf( cmd, 256, "file %s\nattach %d\nc\n", getInstance().appName.c_str(), sigPid ); 240 239 write( gdbIn[1], cmd, strlen(cmd) ); 241 240 … … 331 330 bt.insert(0, timeString); 332 331 333 FILE * f = fopen( getInstance() ->filename.c_str(), "a" );332 FILE * f = fopen( getInstance().filename.c_str(), "a" ); 334 333 335 334 if ( !f ) 336 335 { 337 perror( ( std::string( "could not append to " ) + getInstance() ->filename ).c_str() );336 perror( ( std::string( "could not append to " ) + getInstance().filename ).c_str() ); 338 337 exit(EXIT_FAILURE); 339 338 } … … 341 340 if ( fwrite( bt.c_str(), 1, bt.length(), f ) != bt.length() ) 342 341 { 343 COUT(0) << "could not write " << bt.length() << " byte to " << getInstance() ->filename << std::endl;342 COUT(0) << "could not write " << bt.length() << " byte to " << getInstance().filename << std::endl; 344 343 exit(EXIT_FAILURE); 345 344 } -
code/branches/objecthierarchy2/src/util/SignalHandler.h
r2171 r2344 37 37 #include "UtilPrereqs.h" 38 38 39 #include <cassert> 39 40 #include <list> 40 41 #include <string> … … 68 69 class SignalHandler 69 70 { 70 private:71 SignalHandler();72 71 public: 73 inline static SignalHandler* getInstance() { if (!SignalHandler::singletonRef) SignalHandler::singletonRef = new SignalHandler(); return SignalHandler::singletonRef; } 74 ~SignalHandler(){ SignalHandler::singletonRef = NULL; } 72 SignalHandler() { assert(SignalHandler::singletonRef_s == 0); SignalHandler::singletonRef_s = this; } 73 ~SignalHandler() { assert(SignalHandler::singletonRef_s != 0); SignalHandler::singletonRef_s = NULL; } 74 inline static SignalHandler& getInstance() { assert(SignalHandler::singletonRef_s); return *SignalHandler::singletonRef_s; } 75 75 76 76 void registerCallback( SignalCallback cb, void * someData ); … … 87 87 SignalCallbackList callbackList; 88 88 89 static SignalHandler * singletonRef;89 static SignalHandler* singletonRef_s; 90 90 91 91 std::string appName; … … 104 104 { 105 105 public: 106 inline static SignalHandler* getInstance() { if (!SignalHandler::singletonRef) SignalHandler::singletonRef = new SignalHandler(); return SignalHandler::singletonRef; }; 107 void doCatch( const std::string & appName, const std::string & filename ) {}; 108 void dontCatch() {}; 109 void registerCallback( SignalCallback cb, void * someData ) {}; 106 SignalHandler() { assert(SignalHandler::singletonRef_s == 0); SignalHandler::singletonRef_s = this; } 107 ~SignalHandler() { assert(SignalHandler::singletonRef_s != 0); SignalHandler::singletonRef_s = 0; } 108 inline static SignalHandler& getInstance() { assert(SignalHandler::singletonRef_s); return *SignalHandler::singletonRef_s; } 109 void doCatch( const std::string & appName, const std::string & filename ) {} 110 void dontCatch() {} 111 void registerCallback( SignalCallback cb, void * someData ) {} 110 112 111 113 private: 112 static SignalHandler * singletonRef;114 static SignalHandler* singletonRef_s; 113 115 }; 114 116 }
Note: See TracChangeset
for help on using the changeset viewer.