Changeset 8729 for code/trunk/src/libraries/core
- Timestamp:
- Jul 4, 2011, 2:47:44 AM (13 years ago)
- Location:
- code/trunk
- Files:
-
- 1 deleted
- 37 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
-
code/trunk/src/libraries/core/CMakeLists.txt
r8351 r8729 19 19 20 20 SET_SOURCE_FILES(CORE_SRC_FILES 21 22 #BUILD_UNIT CoreStableBuildUnit.cc 23 ClassTreeMask.cc 21 24 CommandLineParser.cc 22 25 ConfigValueContainer.cc 23 Core.cc24 26 DynLib.cc 25 27 DynLibManager.cc … … 28 30 GameMode.cc 29 31 GameState.cc 30 GraphicsManager.cc 31 GUIManager.cc 32 Identifier.cc 32 33 Language.cc 34 Loader.cc 33 35 LuaState.cc 36 MetaObjectList.cc 37 Namespace.cc 38 NamespaceNode.cc 34 39 ObjectListBase.cc 35 40 OrxonoxClass.cc 36 Resource.cc37 38 # hierarchy39 Identifier.cc40 MetaObjectList.cc41 42 # level43 BaseObject.cc44 ClassTreeMask.cc45 Loader.cc46 Namespace.cc47 NamespaceNode.cc48 41 Template.cc 49 XMLPort.cc50 51 COMPILATION_BEGIN ListenerCompilation.cc52 42 ViewportEventListener.cc 53 43 WindowEventListener.cc 54 44 XMLNameListener.cc 55 COMPILATION_END 45 XMLPort.cc 46 #END_BUILD_UNIT 56 47 57 COMPILATION_BEGIN FilesystemCompilation.cc 48 BaseObject.cc 49 Core.cc 50 51 BUILD_UNIT OgreBuildUnit.cc 52 GraphicsManager.cc 53 GUIManager.cc 54 Resource.cc 55 END_BUILD_UNIT 56 57 BUILD_UNIT FilesystemBuildUnit.cc 58 58 command/ArgumentCompletionFunctions.cc 59 59 ConfigFileManager.cc 60 60 PathConfig.cc 61 COMPILATION_END 61 END_BUILD_UNIT 62 62 63 # multithreading 64 ThreadPool.cc 65 COMPILATION_BEGIN ThreadCompilation.cc 63 BUILD_UNIT ThreadBuildUnit.cc 66 64 command/TclThreadManager.cc 67 65 Thread.cc 68 COMPILATION_END 66 ThreadPool.cc 67 END_BUILD_UNIT 69 68 ) 70 69 -
code/trunk/src/libraries/core/CommandLineParser.cc
r7401 r8729 41 41 namespace orxonox 42 42 { 43 SetCommandLineOnlyArgument(optionsFile, "start.ini").shortcut("o");44 45 43 /** 46 44 @brief … … 50 48 so that you can have simple command line switches. 51 49 */ 52 void CommandLineArgument::parse(const std::string& value, bool bParsingFile) 53 { 54 if (bParsingFile && this->bCommandLineOnly_) 55 ThrowException(Argument, "Command line argument '" + getName() + "' is not allowed in files."); 50 void CommandLineArgument::parse(const std::string& value) 51 { 56 52 if (value_.getType() == MT_Type::Bool) 57 53 { … … 116 112 } 117 113 118 /** 119 @brief 120 Reads the command line parses the values of each argument. 121 It is then stored in the corresponding CommandLineArgument. 114 /** Parses the command line string for arguments and stores these. 122 115 @note 123 116 The reason that you have to provide the string to be parsed as 124 space separ ted list is because of argc and argv. If you only have117 space separated list is because of argc and argv. If you only have 125 118 a whole string, simply use getAllStrings() of SubString. 126 @param arguments 127 Vector of space separated strings. 128 @param bParsingFile 129 Parsing a file or the command line itself 130 */ 131 void CommandLineParser::_parse(const std::vector<std::string>& arguments, bool bParsingFile) 132 { 119 @param cmdLine 120 Command line string WITHOUT the execution path. 121 */ 122 void CommandLineParser::_parse(const std::string& cmdLine) 123 { 124 std::vector<std::string> arguments; 125 SubString tokens(cmdLine, " ", " ", false, '\\', true, '"', true, '\0', '\0', false); 126 for (unsigned i = 0; i < tokens.size(); ++i) 127 arguments.push_back(tokens[i]); 128 133 129 try 134 130 { … … 177 173 if (!name.empty()) 178 174 { 179 checkFullArgument(name, value , bParsingFile);175 checkFullArgument(name, value); 180 176 name.clear(); 181 177 assert(shortcut.empty()); … … 183 179 else if (!shortcut.empty()) 184 180 { 185 checkShortcut(shortcut, value , bParsingFile);181 checkShortcut(shortcut, value); 186 182 shortcut.clear(); 187 183 assert(name.empty()); … … 222 218 if (!name.empty()) 223 219 { 224 checkFullArgument(name, value , bParsingFile);220 checkFullArgument(name, value); 225 221 assert(shortcut.empty()); 226 222 } 227 223 else if (!shortcut.empty()) 228 224 { 229 checkShortcut(shortcut, value , bParsingFile);225 checkShortcut(shortcut, value); 230 226 assert(name.empty()); 231 227 } … … 233 229 catch (const ArgumentException& ex) 234 230 { 235 COUT(0) << "Could not parse command line (including additional files): " << ex.what() << std::endl;231 COUT(0) << "Could not parse command line: " << ex.what() << std::endl; 236 232 COUT(0) << CommandLineParser::getUsageInformation() << std::endl; 237 233 throw GeneralException(""); … … 249 245 Parsing a file or the command line itself 250 246 */ 251 void CommandLineParser::checkFullArgument(const std::string& name, const std::string& value , bool bParsingFile)247 void CommandLineParser::checkFullArgument(const std::string& name, const std::string& value) 252 248 { 253 249 std::map<std::string, CommandLineArgument*>::const_iterator it = cmdLineArgs_.find(name); … … 255 251 ThrowException(Argument, "Command line argument '" + name + "' does not exist."); 256 252 257 it->second->parse(value , bParsingFile);253 it->second->parse(value); 258 254 } 259 255 … … 268 264 Parsing a file or the command line itself 269 265 */ 270 void CommandLineParser::checkShortcut(const std::string& shortcut, const std::string& value , bool bParsingFile)266 void CommandLineParser::checkShortcut(const std::string& shortcut, const std::string& value) 271 267 { 272 268 std::map<std::string, CommandLineArgument*>::const_iterator it = cmdLineArgsShortcut_.find(shortcut); … … 274 270 ThrowException(Argument, "Command line shortcut '" + shortcut + "' does not exist."); 275 271 276 it->second->parse(value , bParsingFile);272 it->second->parse(value); 277 273 } 278 274 … … 342 338 } 343 339 } 344 345 /**346 @brief347 Parses only the command line for CommandLineArguments.348 */349 void CommandLineParser::_parseCommandLine(const std::string& cmdLine)350 {351 std::vector<std::string> args;352 SubString tokens(cmdLine, " ", " ", false, '\\', true, '"', true, '\0', '\0', false);353 for (unsigned i = 0; i < tokens.size(); ++i)354 args.push_back(tokens[i]);355 this->_parse(args, false);356 }357 358 /**359 @brief360 Parses start.ini (or the file specified with --optionsFile) for CommandLineArguments.361 */362 void CommandLineParser::_parseFile()363 {364 const std::string& filename = CommandLineParser::getValue("optionsFile").getString();365 366 // look for additional arguments in given file or start.ini as default367 // They will not overwrite the arguments given directly368 std::ifstream file;369 file.open((PathConfig::getConfigPathString() + filename).c_str());370 std::vector<std::string> args;371 if (file)372 {373 while (!file.eof())374 {375 std::string line;376 std::getline(file, line);377 line = removeTrailingWhitespaces(line);378 //if (!(line[0] == '#' || line[0] == '%'))379 //{380 SubString tokens(line, " ", " ", false, '\\', true, '"', true, '\0', '\0', false, '#');381 for (unsigned i = 0; i < tokens.size(); ++i)382 if (tokens[i][0] != '#')383 args.push_back(tokens[i]);384 //args.insert(args.end(), tokens.getAllStrings().begin(), tokens.getAllStrings().end());385 //}386 }387 file.close();388 }389 390 _parse(args, true);391 }392 340 } -
code/trunk/src/libraries/core/CommandLineParser.h
r7401 r8729 51 51 #define SetCommandLineArgument(name, defaultValue) \ 52 52 orxonox::CommandLineArgument& CmdArgumentDummyBoolVar##name \ 53 = orxonox::CommandLineParser::addArgument(#name, defaultValue, false) 54 #define SetCommandLineOnlyArgument(name, defaultValue) \ 55 orxonox::CommandLineArgument& CmdArgumentDummyBoolVar##name \ 56 = orxonox::CommandLineParser::addArgument(#name, defaultValue, true) 53 = orxonox::CommandLineParser::addArgument(#name, defaultValue) 57 54 #define SetCommandLineSwitch(name) \ 58 55 orxonox::CommandLineArgument& CmdArgumentDummyBoolVar##name \ 59 = orxonox::CommandLineParser::addArgument(#name, false, false) 60 #define SetCommandLineOnlySwitch(name) \ 61 orxonox::CommandLineArgument& CmdArgumentDummyBoolVar##name \ 62 = orxonox::CommandLineParser::addArgument(#name, false, true) 63 56 = orxonox::CommandLineParser::addArgument(#name, false) 64 57 65 58 namespace orxonox … … 106 99 107 100 //! Returns the actual value of the argument. Can be equal to default value. 108 MultiTypegetValue() const { return value_; }101 const MultiType& getValue() const { return value_; } 109 102 //! Returns the given default value as type T. 110 MultiTypegetDefaultValue() const { return defaultValue_; }103 const MultiType& getDefaultValue() const { return defaultValue_; } 111 104 112 105 private: 113 106 //! Constructor initialises both value_ and defaultValue_ with defaultValue. 114 CommandLineArgument(const std::string& name, const MultiType& defaultValue , bool bCommandLineOnly)107 CommandLineArgument(const std::string& name, const MultiType& defaultValue) 115 108 : bHasDefaultValue_(true) 116 109 , name_(name) 117 110 , value_(defaultValue) 118 111 , defaultValue_(defaultValue) 119 , bCommandLineOnly_(bCommandLineOnly)120 112 { } 121 113 … … 125 117 126 118 //! Parses the value string of a command line argument. 127 void parse(const std::string& value , bool bParsingFile);119 void parse(const std::string& value); 128 120 129 121 //! Tells whether the value has been changed by the command line. … … 137 129 MultiType value_; //!< The actual value 138 130 MultiType defaultValue_; //!< Default value. Should not be changed. 139 bool bCommandLineOnly_; //!< Whether you cannot specify the value in a text file140 131 }; 141 132 … … 155 146 156 147 //! Parse redirection to internal member method. 157 static void parse CommandLine(const std::string& cmdLine) { _getInstance()._parseCommandLine(cmdLine); }158 static void parseFile() { _getInstance()._parseFile(); }148 static void parse(const std::string& cmdLine) 149 { _getInstance()._parse(cmdLine); } 159 150 160 151 static std::string getUsageInformation(); … … 165 156 static void getValue(const std::string& name, T* value) 166 157 { *value = (T)(getArgument(name)->getValue()); } 167 static MultiTypegetValue(const std::string& name)158 static const MultiType& getValue(const std::string& name) 168 159 { return getArgument(name)->getValue(); } 169 160 template <class T> 170 static CommandLineArgument& addArgument(const std::string& name, T defaultValue , bool bCommandLineOnly);161 static CommandLineArgument& addArgument(const std::string& name, T defaultValue); 171 162 172 163 static bool existsArgument(const std::string& name) … … 189 180 static CommandLineParser& _getInstance(); 190 181 191 void _parseCommandLine(const std::string& cmdLine); 192 void _parseFile(); 193 void _parse(const std::vector<std::string>& arguments, bool bParsingFile); 194 void checkFullArgument(const std::string& name, const std::string& value, bool bParsingFile); 195 void checkShortcut(const std::string& shortcut, const std::string& value, bool bParsingFile); 182 void _parse(const std::string& cmdLine); 183 void checkFullArgument(const std::string& name, const std::string& value); 184 void checkShortcut(const std::string& shortcut, const std::string& value); 196 185 197 186 /** … … 222 211 @param defaultValue 223 212 Default value that is used when argument was not given. 224 @param bCommandLineOnly225 Parsing a file or the command line itself226 213 */ 227 214 template <class T> 228 CommandLineArgument& CommandLineParser::addArgument(const std::string& name, T defaultValue , bool bCommandLineOnly)215 CommandLineArgument& CommandLineParser::addArgument(const std::string& name, T defaultValue) 229 216 { 230 217 OrxAssert(!_getInstance().existsArgument(name), … … 234 221 << "Please use SetCommandLineSwitch and adjust your argument: " << name); 235 222 236 return *(_getInstance().cmdLineArgs_[name] = new CommandLineArgument(name, defaultValue , bCommandLineOnly));223 return *(_getInstance().cmdLineArgs_[name] = new CommandLineArgument(name, defaultValue)); 237 224 } 238 225 } -
code/trunk/src/libraries/core/ConfigValueIncludes.h
r7401 r8729 255 255 ModifyConfigValueGeneric(this, &varname, #varname, modifier, __VA_ARGS__) 256 256 257 /** Modifies a runtime configurable value by using a modifier and some arguments. 258 If the container for the value doesn't yet exist, a warning is displayed. 259 Also, the @a variable argument will be modified and set to the current value. 260 @param variable 261 Pointer to the variable where the value should be written to 262 @param entryName 263 Name of the entry in the ini file (e.g. [MySection] myValue) 264 @param modifier 265 On of these functions: set, tset, add, remove, reset, update 266 @param ... 267 Arguments for the modifier function 268 */ 269 #define ModifyConfigValueExternal(variable, entryName, modifier, ...) \ 270 ModifyConfigValueGeneric(this, &variable, entryName, modifier, __VA_ARGS__) 271 257 272 #endif /* _ConfigValueIncludes_H__ */ -
code/trunk/src/libraries/core/Core.cc
r8505 r8729 69 69 #include "Language.h" 70 70 #include "LuaState.h" 71 #include "ObjectList.h" 71 72 #include "command/ConsoleCommand.h" 72 73 #include "command/IOConsole.h" … … 131 132 132 133 // Parse command line arguments AFTER the modules have been loaded (static code!) 133 CommandLineParser::parse CommandLine(cmdLine);134 CommandLineParser::parse(cmdLine); 134 135 135 136 // Set configurable paths like log, config and media … … 143 144 // Set the correct log path. Before this call, /tmp (Unix) or %TEMP% (Windows) was used 144 145 OutputHandler::getInstance().setLogPath(PathConfig::getLogPathString()); 145 146 // Parse additional options file now that we know its path147 CommandLineParser::parseFile();148 146 149 147 #ifdef ORXONOX_PLATFORM_WINDOWS … … 168 166 RegisterRootObject(Core); 169 167 this->setConfigValues(); 168 // Rewrite the log file with the correct log levels 169 OutputHandler::getInstance().rewriteLogFile(); 170 170 171 171 #if !defined(ORXONOX_PLATFORM_APPLE) && !defined(ORXONOX_USE_WINMAIN) … … 230 230 } 231 231 232 namespace DefaultLevelLogFile 233 { 234 const OutputLevel::Value Dev = OutputLevel::Debug; 235 const OutputLevel::Value User = OutputLevel::Info; 236 } 237 232 238 //! Function to collect the SetConfigValue-macro calls. 233 239 void Core::setConfigValues() 234 240 { 235 #ifdef ORXONOX_RELEASE 236 const unsigned int defaultLevelLogFile = 3; 237 #else 238 const unsigned int defaultLevelLogFile = 4; 239 #endif 240 SetConfigValueExternal(softDebugLevelLogFile_, "OutputHandler", "softDebugLevelLogFile", defaultLevelLogFile) 241 .description("The maximum level of debug output shown in the log file"); 242 OutputHandler::getInstance().setSoftDebugLevel(OutputHandler::logFileOutputListenerName_s, this->softDebugLevelLogFile_); 241 // Choose the default level according to the path Orxonox was started (build directory or not) 242 OutputLevel::Value defaultLogLevel = (PathConfig::buildDirectoryRun() ? DefaultLevelLogFile::Dev : DefaultLevelLogFile::User); 243 244 SetConfigValueExternal(debugLevelLogFile_, "OutputHandler", "debugLevelLogFile", defaultLogLevel) 245 .description("The maximum level of debug output written to the log file"); 246 OutputHandler::getInstance().setSoftDebugLevel("LogFile", debugLevelLogFile_); 243 247 244 248 SetConfigValue(bDevMode_, PathConfig::buildDirectoryRun()) 245 .description("Developer mode. If not set, hides some things from the user to not confuse him."); 249 .description("Developer mode. If not set, hides some things from the user to not confuse him.") 250 .callback(this, &Core::devModeChanged); 246 251 SetConfigValue(language_, Language::getInstance().defaultLanguage_) 247 252 .description("The language of the in game text") … … 258 263 } 259 264 265 /** Callback function for changes in the dev mode that affect debug levels. 266 The function behaves according to these rules: 267 - 'normal' mode is defined based on where the program was launched: if 268 the launch path was the build directory, development mode \c on is 269 normal, otherwise normal means development mode \c off. 270 - Debug levels should not be hard configured (\c config instead of 271 \c tconfig) in non 'normal' mode to avoid strange behaviour. 272 - Changing the development mode from 'normal' to the other state will 273 immediately change the debug levels to predefined values which can be 274 reconfigured with \c tconfig. 275 @note 276 The debug levels for the IOConsole and the InGameConsole can be found 277 in the Shell class. The same rules apply. 278 */ 279 void Core::devModeChanged() 280 { 281 bool isNormal = (bDevMode_ == PathConfig::buildDirectoryRun()); 282 if (isNormal) 283 { 284 ModifyConfigValueExternal(debugLevelLogFile_, "debugLevelLogFile", update); 285 } 286 else 287 { 288 OutputLevel::Value level = (bDevMode_ ? DefaultLevelLogFile::Dev : DefaultLevelLogFile::User); 289 ModifyConfigValueExternal(debugLevelLogFile_, "debugLevelLogFile", tset, level); 290 } 291 292 // Inform listeners 293 ObjectList<DevModeListener>::iterator it = ObjectList<DevModeListener>::begin(); 294 for (; it != ObjectList<DevModeListener>::end(); ++it) 295 it->devModeChanged(bDevMode_); 296 } 297 260 298 //! Callback function if the language has changed. 261 299 void Core::languageChanged() … … 440 478 ModifyConfigValue(ogreConfigTimestamp_, set, static_cast<long long>(time(NULL))); 441 479 } 480 481 482 DevModeListener::DevModeListener() 483 { 484 RegisterRootObject(DevModeListener); 485 } 442 486 } -
code/trunk/src/libraries/core/Core.h
r8423 r8729 45 45 46 46 #include <string> 47 #include <loki/ScopeGuard.h>48 49 47 #include "util/DestructionHelper.h" 50 48 #include "util/Singleton.h" … … 53 51 namespace orxonox 54 52 { 53 //! Informs about changes in the Development Mode. 54 class DevModeListener : virtual public OrxonoxClass 55 { 56 public: 57 DevModeListener(); 58 virtual ~DevModeListener() {} 59 virtual void devModeChanged(bool value) = 0; 60 }; 61 55 62 /** 56 63 @brief … … 101 108 Core(const Core&); //!< Don't use (undefined symbol) 102 109 110 void devModeChanged(); 103 111 void languageChanged(); 104 112 void initRandomNumberGenerator(); … … 128 136 129 137 bool bGraphicsLoaded_; 130 int softDebugLevelLogFile_;//!< The debug level for the log file (belongs to OutputHandler)138 int debugLevelLogFile_; //!< The debug level for the log file (belongs to OutputHandler) 131 139 std::string language_; //!< The language 132 140 bool bInitRandomNumberGenerator_; //!< If true, srand(time(0)) is called -
code/trunk/src/libraries/core/CoreIncludes.h
r8706 r8729 80 80 #include "util/Debug.h" 81 81 #include "Identifier.h" 82 #include "SubclassIdentifier.h"83 82 #include "ClassFactory.h" 84 83 #include "ObjectList.h" -
code/trunk/src/libraries/core/EventIncludes.h
r7401 r8729 37 37 38 38 #include "CorePrereqs.h" 39 40 #include "Event.h" 39 41 #include "XMLPort.h" 40 42 #include "command/Executor.h" -
code/trunk/src/libraries/core/GUIManager.cc
r8706 r8729 490 490 } 491 491 492 const std::string& GUIManager::createInputState(const std::string& name, TriBool::Value showCursor, TriBool::ValueuseKeyboard, bool bBlockJoyStick)492 const std::string& GUIManager::createInputState(const std::string& name, tribool showCursor, tribool useKeyboard, bool bBlockJoyStick) 493 493 { 494 494 InputState* state = InputManager::getInstance().createInputState(name); … … 506 506 #ifdef ORXONOX_PLATFORM_APPLE 507 507 // There is no non exclusive mode on OS X yet 508 state->setMouseExclusive( TriBool::True);509 #else 510 if (showCursor == TriBool::Dontcare)511 state->setMouseExclusive( TriBool::Dontcare);512 else if (GraphicsManager::getInstance().isFullScreen() || showCursor == TriBool::False)513 state->setMouseExclusive( TriBool::True);508 state->setMouseExclusive(true); 509 #else 510 if (showCursor == dontcare) 511 state->setMouseExclusive(dontcare); 512 else if (GraphicsManager::getInstance().isFullScreen() || showCursor == false) 513 state->setMouseExclusive(true); 514 514 else 515 state->setMouseExclusive( TriBool::False);516 #endif 517 518 if (showCursor == TriBool::True)515 state->setMouseExclusive(false); 516 #endif 517 518 if (showCursor == true) 519 519 state->setMouseHandler(this); 520 else if (showCursor == TriBool::False)520 else if (showCursor == false) 521 521 state->setMouseHandler(&InputHandler::EMPTY); 522 522 523 if (useKeyboard == TriBool::True)523 if (useKeyboard == true) 524 524 state->setKeyHandler(this); 525 else if (useKeyboard == TriBool::False)525 else if (useKeyboard == false) 526 526 state->setKeyHandler(&InputHandler::EMPTY); 527 527 … … 717 717 } 718 718 719 /** Helper method to get the developer's mode without having to export Core.h. 720 @see Core::inDevMode 721 */ 722 /*static*/ bool GUIManager::inDevMode() 723 { 724 return Core::getInstance().inDevMode(); 725 } 726 719 727 /** 720 728 @brief Callback of window event listener, called if the window is resized. Sets the display size of CEGUI. -
code/trunk/src/libraries/core/GUIManager.h
r8706 r8729 39 39 40 40 #include <map> 41 #include <set>42 41 #include <string> 43 42 #include <CEGUIForwardRefs.h> … … 47 46 #include "util/DestructionHelper.h" 48 47 #include "util/OgreForwardRefs.h" 49 #include "util/ TriBool.h"48 #include "util/tribool.h" 50 49 #include "util/Singleton.h" 51 50 #include "input/InputHandler.h" 52 #include "Core.h"53 51 #include "OrxonoxClass.h" 54 52 #include "WindowEventListener.h" 55 56 // Tolua includes (have to be relative to the current directory)57 /*58 $cfile "../util/TriBool.h" // tolua_export59 */60 53 61 54 #if CEGUI_VERSION_MAJOR < 1 && CEGUI_VERSION_MINOR < 7 … … 66 59 { // tolua_export 67 60 class PlayerInfo; // Forward declaration 61 62 // Acquaint Tolua with tribool 63 /* tolua_begin 64 struct dontcare_keyword_t 65 { 66 dontcare_keyword_t(); 67 }; 68 class tribool 69 { 70 tribool(bool value); 71 tribool(dontcare_keyword_t); 72 bool operator==(tribool); 73 }; 74 tolua_end */ 68 75 69 76 /** … … 104 111 void setBackgroundImage(const std::string& image); 105 112 106 /** 107 @brief Helper method to get the developer's mode without having to export Core.h. 108 @see Core::inDevMode 109 */ 110 static bool inDevMode(void) { return Core::getInstance().inDevMode(); } // tolua_export 113 static bool inDevMode(void); // tolua_export 111 114 112 115 //! Creates a new InputState to be used with a GUI Sheet 113 const std::string& createInputState(const std::string& name, TriBool::Value showCursor = TriBool::True, TriBool::Value useKeyboard = TriBool::True, bool bBlockJoyStick = false); // tolua_export116 const std::string& createInputState(const std::string& name, tribool showCursor = tribool(true), tribool useKeyboard = tribool(true), bool bBlockJoyStick = false); // tolua_export 114 117 LuaState* getLuaState(void) 115 118 { return this->luaState_; } -
code/trunk/src/libraries/core/Game.cc
r8706 r8729 109 109 110 110 // Do this after the Core creation! 111 ClassIdentifier<Game>::getIdentifier("Game")->initialiseObject(this, "Game", true);111 RegisterRootObject(Game); 112 112 this->setConfigValues(); 113 113 -
code/trunk/src/libraries/core/LuaState.cc
r8351 r8729 40 40 #include "util/Exception.h" 41 41 #include "Resource.h" 42 #include "ToluaBindCore.h"43 42 #include "command/IOConsole.h" 44 43 45 44 namespace orxonox 46 45 { 47 LuaState::ToluaInterfaceMap LuaState::toluaInterfaces_s;48 std::vector<LuaState*> LuaState::instances_s;49 50 46 const std::string LuaState::ERROR_HANDLER_NAME = "errorHandler"; 51 52 // Do this after declaring toluaInterfaces_s and instances_s to avoid larger problems53 DeclareToluaInterface(Core);54 47 55 48 LuaState::LuaState() … … 277 270 } 278 271 272 /*static*/ LuaState::ToluaInterfaceMap& LuaState::getToluaInterfaces() 273 { 274 static ToluaInterfaceMap p; 275 return p; 276 } 277 278 /*static*/ std::vector<LuaState*>& LuaState::getInstances() 279 { 280 static std::vector<LuaState*> p; 281 return p; 282 } 283 279 284 /*static*/ bool LuaState::addToluaInterface(int (*function)(lua_State*), const std::string& name) 280 285 { 281 for (ToluaInterfaceMap::const_iterator it = toluaInterfaces_s.begin(); it != toluaInterfaces_s.end(); ++it)286 for (ToluaInterfaceMap::const_iterator it = getToluaInterfaces().begin(); it != getToluaInterfaces().end(); ++it) 282 287 { 283 288 if (it->first == name || it->second == function) … … 287 292 } 288 293 } 289 toluaInterfaces_s[name] = function;294 getToluaInterfaces()[name] = function; 290 295 291 296 // Open interface in all LuaStates 292 for (std::vector<LuaState*>::const_iterator it = instances_s.begin(); it != instances_s.end(); ++it)297 for (std::vector<LuaState*>::const_iterator it = getInstances().begin(); it != getInstances().end(); ++it) 293 298 (*function)((*it)->luaState_); 294 299 … … 299 304 /*static*/ bool LuaState::removeToluaInterface(const std::string& name) 300 305 { 301 ToluaInterfaceMap::iterator it = toluaInterfaces_s.find(name);302 if (it == toluaInterfaces_s.end())306 ToluaInterfaceMap::iterator it = getToluaInterfaces().find(name); 307 if (it == getToluaInterfaces().end()) 303 308 { 304 309 COUT(2) << "Warning: Cannot remove Tolua interface '" << name << "': Not found" << std::endl; … … 307 312 308 313 // Close interface in all LuaStates 309 for (std::vector<LuaState*>::const_iterator itState = instances_s.begin(); itState != instances_s.end(); ++itState)314 for (std::vector<LuaState*>::const_iterator itState = getInstances().begin(); itState != getInstances().end(); ++itState) 310 315 { 311 316 lua_pushnil((*itState)->luaState_); … … 314 319 315 320 // Remove entry 316 toluaInterfaces_s.erase(it);321 getToluaInterfaces().erase(it); 317 322 318 323 // Return dummy bool … … 322 327 /*static*/ void LuaState::openToluaInterfaces(lua_State* state) 323 328 { 324 for (ToluaInterfaceMap::const_iterator it = toluaInterfaces_s.begin(); it != toluaInterfaces_s.end(); ++it)329 for (ToluaInterfaceMap::const_iterator it = getToluaInterfaces().begin(); it != getToluaInterfaces().end(); ++it) 325 330 (*it->second)(state); 326 331 } … … 328 333 /*static*/ void LuaState::closeToluaInterfaces(lua_State* state) 329 334 { 330 for (ToluaInterfaceMap::const_iterator it = toluaInterfaces_s.begin(); it != toluaInterfaces_s.end(); ++it)335 for (ToluaInterfaceMap::const_iterator it = getToluaInterfaces().begin(); it != getToluaInterfaces().end(); ++it) 331 336 { 332 337 lua_pushnil(state); -
code/trunk/src/libraries/core/LuaState.h
r8351 r8729 48 48 #include <vector> 49 49 #include <boost/shared_ptr.hpp> 50 #include <loki/ScopeGuard.h>51 52 #include "ToluaInterface.h"53 50 54 51 namespace orxonox // tolua_export … … 121 118 122 119 typedef std::map<std::string, int (*)(lua_State *L)> ToluaInterfaceMap; 123 static ToluaInterfaceMap toluaInterfaces_s;124 static std::vector<LuaState*> instances_s;120 static ToluaInterfaceMap& getToluaInterfaces(); 121 static std::vector<LuaState*>& getInstances(); 125 122 }; // tolua_export 123 124 125 //! Helper class that registers/unregisters tolua bindings 126 class ToluaBindingsHelper 127 { 128 public: 129 ToluaBindingsHelper(int (*function)(lua_State*), const std::string& libraryName) 130 : libraryName_(libraryName) 131 { 132 LuaState::addToluaInterface(function, libraryName_); 133 } 134 ~ToluaBindingsHelper() 135 { 136 LuaState::removeToluaInterface(libraryName_); 137 } 138 private: 139 std::string libraryName_; 140 }; 126 141 } // tolua_export 127 142 -
code/trunk/src/libraries/core/ObjectListBase.h
r7401 r8729 41 41 42 42 #include "CorePrereqs.h" 43 44 43 #include <vector> 45 #include "OrxonoxClass.h"46 44 47 45 namespace orxonox -
code/trunk/src/libraries/core/OrxonoxClass.h
r8351 r8729 45 45 46 46 #include "CorePrereqs.h" 47 #include "Super.h"48 47 49 48 #include <set> 50 49 #include <vector> 50 #include "Super.h" 51 51 52 52 /** -
code/trunk/src/libraries/core/PathConfig.cc
r8366 r8729 74 74 75 75 SetCommandLineArgument(externalDataPath, "").information("Path to the external data files"); 76 SetCommandLine OnlyArgument(writingPathSuffix, "").information("Additional subfolder for config and log files");76 SetCommandLineArgument(writingPathSuffix, "").information("Additional subfolder for config and log files"); 77 77 78 78 PathConfig::PathConfig() -
code/trunk/src/libraries/core/Super.h
r8706 r8729 73 73 74 74 #include "CorePrereqs.h" 75 76 75 #include "util/Debug.h" 77 #include "Event.h"78 76 79 77 /////////////////////// -
code/trunk/src/libraries/core/ViewportEventListener.h
r8079 r8729 30 30 #define _ViewportEventListener_H__ 31 31 32 #include "CorePrereqs.h" 33 32 34 #include "util/OgreForwardRefs.h" 33 34 #include "CorePrereqs.h"35 35 #include "OrxonoxClass.h" 36 36 -
code/trunk/src/libraries/core/command/Functor.h
r8706 r8729 114 114 #define _Functor_H__ 115 115 116 #include "core/CorePrereqs.h" 117 116 118 #include <typeinfo> 117 118 #include "core/CorePrereqs.h"119 119 120 120 #include "util/Debug.h" -
code/trunk/src/libraries/core/command/IOConsolePOSIX.cc
r7422 r8729 236 236 void IOConsole::printOutputLine(const std::string& text, Shell::LineType type) 237 237 { 238 /*239 238 // Colour line 240 239 switch (type) 241 240 { 242 case Shell::None: this->cout_ << "\033[37m"; break;243 241 case Shell::Error: this->cout_ << "\033[91m"; break; 244 case Shell::Warning: this->cout_ << "\033[31m"; break; 245 case Shell::Info: this->cout_ << "\033[34m"; break; 246 case Shell::Debug: this->cout_ << "\033[36m"; break; 247 case Shell::Verbose: this->cout_ << "\033[35m"; break; 248 case Shell::Ultra: this->cout_ << "\033[37m"; break; 242 case Shell::Warning: this->cout_ << "\033[93m"; break; 243 case Shell::Info: this->cout_ << "\033[90m"; break; 244 case Shell::Debug: this->cout_ << "\033[90m"; break; 245 case Shell::Verbose: this->cout_ << "\033[90m"; break; 246 case Shell::Ultra: this->cout_ << "\033[90m"; break; 247 case Shell::Command: this->cout_ << "\033[36m"; break; 248 case Shell::Hint: this->cout_ << "\033[33m"; break; 249 case Shell::TDebug: this->cout_ << "\033[95m"; break; 249 250 default: break; 250 251 } 251 */252 252 253 253 // Print output line 254 254 this->cout_ << text; 255 255 256 // Reset colour to white257 // this->cout_ << "\033[37m";256 // Reset colour atributes 257 this->cout_ << "\033[0m"; 258 258 } 259 259 -
code/trunk/src/libraries/core/command/IOConsoleWindows.cc
r7287 r8729 208 208 case Shell::Command: colour = FOREGROUND_GREEN | FOREGROUND_BLUE; break; 209 209 case Shell::Hint: colour = FOREGROUND_GREEN | FOREGROUND_RED ; break; 210 case Shell::TDebug: colour = FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_BLUE; break; 210 211 default: colour = FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE; break; 211 212 } -
code/trunk/src/libraries/core/command/IOConsoleWindows.h
r7401 r8729 39 39 #include <sstream> 40 40 #include <string> 41 #include <vector>42 41 #include "util/Singleton.h" 43 42 #include "Shell.h" -
code/trunk/src/libraries/core/command/Shell.cc
r8706 r8729 34 34 #include "Shell.h" 35 35 36 #include "util/Math.h" 36 37 #include "util/OutputHandler.h" 37 38 #include "util/StringUtils.h" … … 40 41 #include "core/ConfigFileManager.h" 41 42 #include "core/ConfigValueIncludes.h" 43 #include "core/PathConfig.h" 44 #include "core/input/InputBuffer.h" 42 45 #include "CommandExecutor.h" 43 46 #include "ConsoleCommand.h" … … 84 87 85 88 // Get the previous output and add it to the Shell 86 for (OutputHandler::OutputVectorIterator it = OutputHandler::getInstance().getOutputVectorBegin();87 it != OutputHandler::getInstance().getOutputVectorEnd(); ++it)88 { 89 if (it->first <= this->getSoftDebugLevel())89 OutputHandler::OutputVector::const_iterator it = OutputHandler::getInstance().getOutput().begin(); 90 for (;it != OutputHandler::getInstance().getOutput().end(); ++it) 91 { 92 if (it->first <= debugLevel_) 90 93 { 91 94 this->outputBuffer_ << it->second; … … 96 99 // Register the shell as output listener 97 100 OutputHandler::getInstance().registerOutputListener(this); 101 OutputHandler::getInstance().setSoftDebugLevel(consoleName_, debugLevel_); 98 102 } 99 103 … … 105 109 OutputHandler::getInstance().unregisterOutputListener(this); 106 110 this->inputBuffer_->destroy(); 111 } 112 113 namespace DefaultLogLevel 114 { 115 const OutputLevel::Value Dev = OutputLevel::Info; 116 const OutputLevel::Value User = OutputLevel::Error; 107 117 } 108 118 … … 119 129 SetConfigValue(cacheSize_s, 32); 120 130 121 #ifdef ORXONOX_RELEASE 122 const unsigned int defaultLevel = 1; 123 #else 124 const unsigned int defaultLevel = 3; 125 #endif 126 SetConfigValueExternal(softDebugLevel_, "OutputHandler", "softDebugLevel" + this->consoleName_, defaultLevel) 127 .description("The maximal level of debug output shown in the Shell"); 128 this->setSoftDebugLevel(this->softDebugLevel_); 131 // Choose the default level according to the path Orxonox was started (build directory or not) 132 OutputLevel::Value defaultDebugLevel = (PathConfig::buildDirectoryRun() ? DefaultLogLevel::Dev : DefaultLogLevel::User); 133 SetConfigValueExternal(debugLevel_, "OutputHandler", "debugLevel" + consoleName_, defaultDebugLevel) 134 .description("The maximum level of debug output shown in the " + consoleName_); 135 OutputHandler::getInstance().setSoftDebugLevel(consoleName_, debugLevel_); 129 136 } 130 137 … … 150 157 this->commandHistory_.erase(this->commandHistory_.begin() + index); 151 158 ModifyConfigValue(commandHistory_, remove, index); 159 } 160 } 161 162 /** Called upon changes in the development mode (by Core) 163 Behaviour details see Core::devModeChanged. 164 */ 165 void Shell::devModeChanged(bool value) 166 { 167 bool isNormal = (value == PathConfig::buildDirectoryRun()); 168 if (isNormal) 169 { 170 ModifyConfigValueExternal(debugLevel_, "debugLevel" + consoleName_, update); 171 } 172 else 173 { 174 OutputLevel::Value level = (value ? DefaultLogLevel::Dev : DefaultLogLevel::User); 175 ModifyConfigValueExternal(debugLevel_, "debugLevel" + consoleName_, tset, level); 152 176 } 153 177 } … … 215 239 } 216 240 241 /// Returns the current position of the cursor in the input buffer. 242 unsigned int Shell::getCursorPosition() const 243 { 244 return this->inputBuffer_->getCursorPosition(); 245 } 246 247 /// Returns the current content of the input buffer (the text which was entered by the user) 248 const std::string& Shell::getInput() const 249 { 250 return this->inputBuffer_->get(); 251 } 252 217 253 /** 218 254 @brief Sends output to the internal output buffer. -
code/trunk/src/libraries/core/command/Shell.h
r7401 r8729 49 49 50 50 #include "util/OutputHandler.h" 51 #include "core/Core.h" 51 52 #include "core/OrxonoxClass.h" 52 #include "core/input/InputBuffer.h"53 53 54 54 namespace orxonox … … 85 85 Different graphical consoles build upon a Shell, for example InGameConsole and IOConsole. 86 86 */ 87 class _CoreExport Shell : virtual public OrxonoxClass, public OutputListener87 class _CoreExport Shell : public OutputListener, public DevModeListener 88 88 { 89 89 public: … … 91 91 enum LineType 92 92 { 93 TDebug = OutputLevel::TDebug, 93 94 None = OutputLevel::None, 94 95 Warning = OutputLevel::Warning, … … 118 119 119 120 void setCursorPosition(unsigned int cursor); 120 /// Returns the current position of the cursor in the input buffer. 121 inline unsigned int getCursorPosition() const 122 { return this->inputBuffer_->getCursorPosition(); } 123 124 /// Returns the current content of the input buffer (the text which was entered by the user) 125 inline const std::string& getInput() const 126 { return this->inputBuffer_->get(); } 121 unsigned int getCursorPosition() const; 122 123 const std::string& getInput() const; 127 124 128 125 typedef std::list<std::pair<std::string, LineType> > LineList; … … 146 143 private: 147 144 Shell(const Shell& other); 145 146 // DevModeListener 147 void devModeChanged(bool value); 148 148 149 149 void addToHistory(const std::string& command); … … 197 197 unsigned int historyOffset_; ///< The command history is a circular buffer, this variable defines the current write-offset 198 198 std::vector<std::string> commandHistory_; ///< The history of commands that were entered by the user 199 int softDebugLevel_; ///< The maximum level of output that is displayed in the shell (will be passed to OutputListener to filter output)199 int debugLevel_; //!< The maximum level of output that is displayed in the shell (will be passed to OutputListener to filter output) 200 200 static unsigned int cacheSize_s; ///< The maximum cache size of the CommandExecutor - this is stored here for better readability of the config file and because CommandExecutor is no OrxonoxClass 201 201 }; -
code/trunk/src/libraries/core/input/InputHandler.h
r6746 r8729 31 31 32 32 #include "InputPrereqs.h" 33 #include "util/Math.h"34 33 35 34 namespace orxonox 36 35 { 36 /// A Vector class containing two integers @a x and @a y. 37 class IntVector2 38 { 39 public: 40 IntVector2() : x(0), y(0) { } 41 IntVector2(int _x, int _y) : x(_x), y(_y) { } 42 int x; 43 int y; 44 }; 45 37 46 namespace ButtonEvent 38 47 { -
code/trunk/src/libraries/core/input/InputManager.cc
r8351 r8729 94 94 , oisInputManager_(0) 95 95 , devices_(2) 96 , exclusiveMouse_( TriBool::False)96 , exclusiveMouse_(false) 97 97 , emptyState_(0) 98 98 , calibratorCallbackHandler_(0) … … 108 108 109 109 if (GraphicsManager::getInstance().isFullScreen()) 110 exclusiveMouse_ = TriBool::True;110 exclusiveMouse_ = true; 111 111 this->loadDevices(); 112 112 … … 161 161 paramList.insert(StringPair("w32_keyboard", "DISCL_FOREGROUND")); 162 162 paramList.insert(StringPair("w32_mouse", "DISCL_FOREGROUND")); 163 if (exclusiveMouse_ == TriBool::True|| GraphicsManager::getInstance().isFullScreen())163 if (exclusiveMouse_ || GraphicsManager::getInstance().isFullScreen()) 164 164 { 165 165 // Disable Windows key plus special keys (like play, stop, next, etc.) … … 174 174 paramList.insert(StringPair("XAutoRepeatOn", "true")); 175 175 176 if (exclusiveMouse_ == TriBool::True|| GraphicsManager::getInstance().isFullScreen())176 if (exclusiveMouse_ || GraphicsManager::getInstance().isFullScreen()) 177 177 { 178 178 if (CommandLineParser::getValue("keyboard_no_grab").getBool()) … … 447 447 448 448 // Check whether we have to change the mouse mode 449 TriBool::Value requestedMode = TriBool::Dontcare;449 tribool requestedMode = dontcare; 450 450 std::vector<InputState*>& mouseStates = devices_[InputDeviceEnumerator::Mouse]->getStateListRef(); 451 451 if (mouseStates.empty()) 452 requestedMode = TriBool::False;452 requestedMode = false; 453 453 else 454 454 requestedMode = mouseStates.front()->getMouseExclusive(); 455 if (requestedMode != TriBool::Dontcare && exclusiveMouse_ != requestedMode) 456 { 457 exclusiveMouse_ = requestedMode; 455 if (requestedMode != dontcare && exclusiveMouse_ != requestedMode) 456 { 457 assert(requestedMode != dontcare); 458 exclusiveMouse_ = (requestedMode == true); 458 459 if (!GraphicsManager::getInstance().isFullScreen()) 459 460 this->reloadInternal(); … … 644 645 } 645 646 646 bool InputManager::setMouseExclusive(const std::string& name, TriBool::Valuevalue)647 bool InputManager::setMouseExclusive(const std::string& name, tribool value) 647 648 { 648 649 if (name == "empty") -
code/trunk/src/libraries/core/input/InputManager.h
r8079 r8729 33 33 34 34 #include <map> 35 #include <set>36 35 #include <string> 37 36 #include <vector> … … 39 38 40 39 #include "util/Singleton.h" 41 #include "util/ TriBool.h"40 #include "util/tribool.h" 42 41 #include "core/WindowEventListener.h" 43 42 … … 169 168 True if the call was successful, fals if the name was not found 170 169 */ 171 bool setMouseExclusive(const std::string& name, TriBool::Valuevalue); // tolua_export170 bool setMouseExclusive(const std::string& name, tribool value); // tolua_export 172 171 173 172 //------------------------------- … … 215 214 OIS::InputManager* oisInputManager_; //!< OIS input manager 216 215 std::vector<InputDevice*> devices_; //!< List of all input devices (keyboard, mouse, joy sticks) 217 TriBool::ValueexclusiveMouse_; //!< Currently applied mouse mode216 bool exclusiveMouse_; //!< Currently applied mouse mode 218 217 219 218 // some internally handled states and handlers -
code/trunk/src/libraries/core/input/InputPrereqs.h
r6746 r8729 41 41 #include <ois/OISKeyboard.h> 42 42 #include <ois/OISMouse.h> 43 #include <ois/OISJoyStick.h>44 43 #include "util/OrxEnum.h" 45 44 -
code/trunk/src/libraries/core/input/InputState.cc
r7284 r8729 37 37 , bAlwaysGetsInput_(bAlwaysGetsInput) 38 38 , bTransparent_(bTransparent) 39 , exclusiveMouse_( TriBool::Dontcare)39 , exclusiveMouse_(dontcare) 40 40 , bExpired_(true) 41 41 , handlers_(2) -
code/trunk/src/libraries/core/input/InputState.h
r8351 r8729 38 38 #include <boost/bind.hpp> 39 39 40 #include "util/ TriBool.h"40 #include "util/tribool.h" 41 41 #include "InputHandler.h" 42 42 #include "InputManager.h" … … 112 112 void setHandler (InputHandler* handler); 113 113 114 void setMouseExclusive( TriBool::Valuevalue) { exclusiveMouse_ = value; this->bExpired_ = true; }115 TriBool::ValuegetMouseExclusive() const { return exclusiveMouse_; }114 void setMouseExclusive(tribool value) { exclusiveMouse_ = value; this->bExpired_ = true; } 115 tribool getMouseExclusive() const { return exclusiveMouse_; } 116 116 117 117 //! Returns the name of the state (which is unique!) … … 166 166 const bool bAlwaysGetsInput_; //!< See class declaration for explanation 167 167 const bool bTransparent_; //!< See class declaration for explanation 168 TriBool::ValueexclusiveMouse_; //!< See class declaration for explanation168 tribool exclusiveMouse_; //!< See class declaration for explanation 169 169 int priority_; //!< Current priority (might change) 170 170 bool bExpired_; //!< See hasExpired() -
code/trunk/src/libraries/core/input/JoyStick.h
r7809 r8729 34 34 #include <string> 35 35 #include <vector> 36 #include <ois/OISJoyStick.h> 36 37 #include "InputDevice.h" 37 38 -
code/trunk/src/libraries/core/input/JoyStickQuantityListener.h
r6417 r8729 36 36 37 37 #include "InputPrereqs.h" 38 39 #include <vector> 38 40 #include "core/OrxonoxClass.h" 39 41 -
code/trunk/src/libraries/core/input/KeyBinderManager.h
r7284 r8729 34 34 #include <map> 35 35 #include <string> 36 #include <boost/shared_ptr.hpp>37 36 38 37 #include "util/Singleton.h" -
code/trunk/src/libraries/core/input/KeyDetector.h
r7284 r8729 32 32 #include "InputPrereqs.h" 33 33 34 #include <boost/shared_ptr.hpp>35 34 #include "util/Singleton.h" 36 35 #include "KeyBinder.h" -
code/trunk/src/libraries/core/input/Keyboard.h
r8079 r8729 31 31 32 32 #include "InputPrereqs.h" 33 34 #include "InputHandler.h"35 33 #include "InputDevice.h" 36 34 -
code/trunk/src/libraries/core/input/Mouse.cc
r7284 r8729 37 37 // include this as last, X11 seems to define some macros... 38 38 #include <ois/linux/LinuxMouse.h> 39 #undef Success 39 40 #endif 40 41
Note: See TracChangeset
for help on using the changeset viewer.