Changeset 2685 for code/branches/buildsystem3/src/core
- Timestamp:
- Feb 20, 2009, 5:32:04 PM (16 years ago)
- Location:
- code/branches/buildsystem3/src/core
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/buildsystem3/src/core/CMakeLists.txt
r2664 r2685 70 70 IF(GCC_NO_SYSTEM_HEADER_SUPPORT) 71 71 # Get around displaying a few hundred lines of warning code 72 SET_SOURCE_FILES_PROPERTIES(ArgumentCompletionFunctions.cc PROPERTIES COMPILE_FLAGS "-w") 72 SET_SOURCE_FILES_PROPERTIES( 73 ArgumentCompletionFunctions.cc 74 CommandLine.cc 75 ConfigFileManager.cc 76 Language.cc 77 LuaBind.cc 78 input/KeyBinder.cc 79 PROPERTIES COMPILE_FLAGS "-Wno-sign-compare") 73 80 ENDIF() 74 81 -
code/branches/buildsystem3/src/core/CommandLine.cc
r2662 r2685 29 29 #include "CommandLine.h" 30 30 31 #include <boost/filesystem.hpp> 31 32 #include "util/String.h" 32 33 #include "util/SubString.h" 34 #include "Core.h" 33 35 34 36 namespace orxonox … … 299 301 this->_parse(args); 300 302 303 std::string filename = CommandLine::getValue("optionsFile").getString(); 304 boost::filesystem::path folder(Core::getConfigPath()); 305 boost::filesystem::path filepath(folder/filename); 306 301 307 // look for additional arguments in given file or start.ini as default 302 308 // They will not overwrite the arguments given directly 303 309 std::ifstream file; 304 std::string filename = CommandLine::getValue("optionsFile").getString(); 305 file.open(filename.c_str()); 310 file.open(filepath.native_file_string().c_str()); 306 311 args.clear(); 307 312 if (file) -
code/branches/buildsystem3/src/core/ConfigFileManager.cc
r2662 r2685 30 30 31 31 #include <cassert> 32 #include <boost/filesystem.hpp> 33 32 34 #include "util/Convert.h" 33 35 #include "util/String.h" 34 36 #include "ConsoleCommand.h" 35 37 #include "ConfigValueContainer.h" 38 #include "Core.h" 36 39 37 40 namespace orxonox … … 223 226 this->clear(); 224 227 228 boost::filesystem::path filepath(Core::getConfigPath() + "/" + this->filename_); 229 225 230 // This creates the config file if it's not existing 226 231 std::ofstream createFile; 227 createFile.open( this->filename_.c_str(), std::fstream::app);232 createFile.open(filepath.native_file_string().c_str(), std::fstream::app); 228 233 createFile.close(); 229 234 230 235 // Open the file 231 236 std::ifstream file; 232 file.open( this->filename_.c_str(), std::fstream::in);237 file.open(filepath.native_file_string().c_str(), std::fstream::in); 233 238 234 239 if (!file.is_open()) … … 337 342 void ConfigFile::save() const 338 343 { 344 boost::filesystem::path filepath(Core::getConfigPath() + "/" + this->filename_); 345 339 346 std::ofstream file; 340 file.open( this->filename_.c_str(), std::fstream::out);347 file.open(filepath.native_file_string().c_str(), std::fstream::out); 341 348 file.setf(std::ios::fixed, std::ios::floatfield); 342 349 file.precision(6); -
code/branches/buildsystem3/src/core/Core.cc
r2662 r2685 37 37 #include "CoreIncludes.h" 38 38 #include "ConfigValueIncludes.h" 39 #include "LuaBind.h" 40 #include "CommandLine.h" 39 41 40 42 namespace orxonox … … 46 48 bool Core::bIsMaster_s = false; 47 49 50 bool Core::isDevBuild_s = false; 51 std::string Core::configPath_s(ORXONOX_CONFIG_INSTALL_PATH); // from OrxonoxConfig.h 52 std::string Core::logPath_s (ORXONOX_LOG_INSTALL_PATH); // from OrxonoxConfig.h 53 48 54 Core* Core::singletonRef_s = 0; 55 56 SetCommandLineArgument(mediaPath, "").information("PATH"); 49 57 50 58 /** … … 58 66 assert(Core::singletonRef_s == 0); 59 67 Core::singletonRef_s = this; 68 60 69 this->bInitializeRandomNumberGenerator_ = false; 61 62 70 this->setConfigValues(); 71 72 // Set the correct log path. Before this call, /tmp (Unix) or %TEMP% was used 73 OutputHandler::getOutStream().setLogPath(Core::logPath_s); 74 75 // Possible media path override by the command line 76 if (!CommandLine::getArgument("mediaPath")->hasDefaultValue()) 77 { 78 std::string mediaPath = CommandLine::getValue("mediaPath"); 79 Core::tsetMediaPath(mediaPath); 80 } 63 81 } 64 82 … … 77 95 void Core::setConfigValues() 78 96 { 79 SetConfigValue(softDebugLevelConsole_, 3).description("The maximal level of debug output shown in the console").callback(this, &Core::debugLevelChanged); 80 SetConfigValue(softDebugLevelLogfile_, 3).description("The maximal level of debug output shown in the logfile").callback(this, &Core::debugLevelChanged); 81 SetConfigValue(softDebugLevelShell_, 1).description("The maximal level of debug output shown in the ingame shell").callback(this, &Core::debugLevelChanged); 97 #ifdef NDEBUG 98 const unsigned int defaultLevelConsole = 1; 99 const unsigned int defaultLevelLogfile = 3; 100 const unsigned int defaultLevelShell = 1; 101 #else 102 const unsigned int defaultLevelConsole = 3; 103 const unsigned int defaultLevelLogfile = 4; 104 const unsigned int defaultLevelShell = 3; 105 #endif 106 SetConfigValue(softDebugLevelConsole_, defaultLevelConsole) 107 .description("The maximal level of debug output shown in the console").callback(this, &Core::debugLevelChanged); 108 SetConfigValue(softDebugLevelLogfile_, defaultLevelLogfile) 109 .description("The maximal level of debug output shown in the logfile").callback(this, &Core::debugLevelChanged); 110 SetConfigValue(softDebugLevelShell_, defaultLevelShell) 111 .description("The maximal level of debug output shown in the ingame shell").callback(this, &Core::debugLevelChanged); 112 82 113 SetConfigValue(language_, Language::getLanguage().defaultLanguage_).description("The language of the ingame text").callback(this, &Core::languageChanged); 83 114 SetConfigValue(bInitializeRandomNumberGenerator_, true).description("If true, all random actions are different each time you start the game").callback(this, &Core::initializeRandomNumberGenerator); 115 116 // Media path (towards config and log path) is ini-configurable 117 const char* defaultMediaPath = ORXONOX_MEDIA_INSTALL_PATH; 118 if (Core::isDevBuild()) 119 defaultMediaPath = ORXONOX_MEDIA_DEV_PATH; 120 121 SetConfigValue(mediaPath_, defaultMediaPath) 122 .description("Relative path to the game data.").callback(this, &Core::mediaPathChanged); 123 84 124 } 85 125 … … 109 149 // Read the translation file after the language was configured 110 150 Language::getLanguage().readTranslatedLanguageFile(); 151 } 152 153 /** 154 @brief 155 Callback function if the media path has changed. 156 */ 157 void Core::mediaPathChanged() 158 { 159 if (mediaPath_ != "" && mediaPath_[mediaPath_.size() - 1] != '/') 160 { 161 ModifyConfigValue(mediaPath_, set, mediaPath_ + "/"); 162 } 163 164 if (mediaPath_ == "") 165 { 166 ModifyConfigValue(mediaPath_, set, "/"); 167 COUT(2) << "Warning: Data path set to \"/\", is that really correct?" << std::endl; 168 } 111 169 } 112 170 … … 177 235 } 178 236 237 /** 238 @brief 239 Temporary sets the media path 240 @param path 241 The new media path 242 */ 243 void Core::_tsetMediaPath(const std::string& path) 244 { 245 if (*path.end() != '/' && *path.end() != '\\') 246 { 247 ModifyConfigValue(mediaPath_, tset, path + "/"); 248 } 249 else 250 { 251 ModifyConfigValue(mediaPath_, tset, path); 252 } 253 } 254 179 255 void Core::initializeRandomNumberGenerator() 180 256 { … … 187 263 } 188 264 } 265 266 /*static*/ void Core::setDevBuild() 267 { 268 // Be careful never to call this function before main()! 269 270 Core::isDevBuild_s = true; 271 // Constants taken from OrxonoxConfig.h 272 Core::configPath_s = ORXONOX_CONFIG_DEV_PATH; 273 Core::logPath_s = ORXONOX_LOG_DEV_PATH; 274 } 189 275 } -
code/branches/buildsystem3/src/core/Core.h
r2662 r2685 44 44 #include "util/OutputHandler.h" 45 45 46 // Only allow main to access setDevBuild, so we need a forward declaration 47 int main(int, char**); 48 46 49 namespace orxonox 47 50 { … … 49 52 class _CoreExport Core : public OrxonoxClass 50 53 { 54 friend int ::main(int, char**); // sets isDevBuild_s 55 51 56 public: 52 57 Core(); 53 58 ~Core(); 54 59 void setConfigValues(); 55 void debugLevelChanged();56 void languageChanged();57 60 58 61 static Core& getInstance() { assert(Core::singletonRef_s); return *Core::singletonRef_s; } … … 62 65 static const std::string& getLanguage(); 63 66 static void resetLanguage(); 67 68 static bool isDevBuild() { return Core::isDevBuild_s; } 69 70 static const std::string& getMediaPath() 71 { assert(singletonRef_s); return singletonRef_s->mediaPath_; } 72 static void tsetMediaPath(const std::string& path) 73 { assert(singletonRef_s); singletonRef_s->_tsetMediaPath(path); } 74 static const std::string& getConfigPath() { return configPath_s; } 75 static const std::string& getLogPath() { return logPath_s; } 64 76 65 77 // fast access global variables. … … 79 91 void resetLanguageIntern(); 80 92 void initializeRandomNumberGenerator(); 93 void debugLevelChanged(); 94 void languageChanged(); 95 void mediaPathChanged(); 96 void _tsetMediaPath(const std::string& path); 97 98 static void setDevBuild(); 81 99 82 100 int softDebugLevel_; //!< The debug level … … 85 103 int softDebugLevelShell_; //!< The debug level for the ingame shell 86 104 std::string language_; //!< The language 87 bool bInitializeRandomNumberGenerator_; //!< If true, srand(time(0)) is called 105 bool bInitializeRandomNumberGenerator_; //!< If true, srand(time(0)) is called 106 std::string mediaPath_; //!< Path to the data/media file folder 88 107 89 108 static bool bShowsGraphics_s; //!< global variable that tells whether to show graphics … … 93 112 static bool bIsMaster_s; 94 113 114 static bool isDevBuild_s; //!< True for builds in the build directory (not installed) 115 static std::string configPath_s; //!< Path to the config file folder 116 static std::string logPath_s; //!< Path to the log file folder 117 95 118 static Core* singletonRef_s; 96 119 }; -
code/branches/buildsystem3/src/core/Language.cc
r2662 r2685 35 35 36 36 #include <fstream> 37 #include <boost/filesystem.hpp> 37 38 38 39 #include "Core.h" … … 205 206 COUT(4) << "Read default language file." << std::endl; 206 207 208 boost::filesystem::path folder(Core::getConfigPath()); 209 boost::filesystem::path filepath(folder/getFilename(this->defaultLanguage_)); 210 207 211 // This creates the file if it's not existing 208 212 std::ofstream createFile; 209 createFile.open( getFilename(this->defaultLanguage_).c_str(), std::fstream::app);213 createFile.open(filepath.native_file_string().c_str(), std::fstream::app); 210 214 createFile.close(); 211 215 212 216 // Open the file 213 217 std::ifstream file; 214 file.open( getFilename(this->defaultLanguage_).c_str(), std::fstream::in);218 file.open(filepath.native_file_string().c_str(), std::fstream::in); 215 219 216 220 if (!file.is_open()) … … 254 258 COUT(4) << "Read translated language file (" << Core::getLanguage() << ")." << std::endl; 255 259 260 boost::filesystem::path folder(Core::getConfigPath()); 261 boost::filesystem::path filepath(folder/getFilename(Core::getLanguage())); 262 256 263 // Open the file 257 264 std::ifstream file; 258 file.open( getFilename(Core::getLanguage()).c_str(), std::fstream::in);265 file.open(filepath.native_file_string().c_str(), std::fstream::in); 259 266 260 267 if (!file.is_open()) … … 308 315 COUT(4) << "Language: Write default language file." << std::endl; 309 316 317 boost::filesystem::path folder(Core::getConfigPath()); 318 boost::filesystem::path filepath(folder/getFilename(this->defaultLanguage_)); 319 310 320 // Open the file 311 321 std::ofstream file; 312 file.open( getFilename(this->defaultLanguage_).c_str(), std::fstream::out);322 file.open(filepath.native_file_string().c_str(), std::fstream::out); 313 323 314 324 if (!file.is_open()) -
code/branches/buildsystem3/src/core/LuaBind.cc
r2664 r2685 37 37 } 38 38 #include <tolua/tolua++.h> 39 39 #include <boost/filesystem.hpp> 40 41 #include "util/String.h" 42 #include "util/Debug.h" 40 43 #include "ToluaBindCore.h" 41 #include "util/String.h" 42 #include "CoreIncludes.h" 44 #include "Core.h" 43 45 44 46 namespace orxonox … … 50 52 assert(LuaBind::singletonRef_s == 0); 51 53 LuaBind::singletonRef_s = this; 54 55 this->includePath_ = Core::getMediaPath(); 52 56 53 57 luaState_ = lua_open(); … … 82 86 void LuaBind::loadFile(std::string filename, bool luaTags) 83 87 { 88 boost::filesystem::path filepath(filename); 89 84 90 output_ = ""; 85 91 std::ifstream file; 86 file.open(file name.c_str(), std::fstream::in);92 file.open(filepath.native_file_string().c_str(), std::fstream::in); 87 93 88 94 if (!file.is_open()) -
code/branches/buildsystem3/src/core/input/KeyBinder.cc
r2662 r2685 36 36 #include <fstream> 37 37 #include <string> 38 #include <boost/filesystem.hpp> 38 39 39 40 #include "util/Convert.h" … … 42 43 #include "core/CoreIncludes.h" 43 44 #include "core/ConfigFileManager.h" 45 #include "core/Core.h" 44 46 #include "InputCommands.h" 45 47 #include "InputManager.h" … … 253 255 return; 254 256 257 boost::filesystem::path folder(Core::getConfigPath()); 258 boost::filesystem::path filepath(folder/filename); 259 255 260 // get bindings from default file if filename doesn't exist. 256 261 std::ifstream infile; 257 infile.open(file name.c_str());262 infile.open(filepath.native_file_string().c_str()); 258 263 if (!infile) 259 264 {
Note: See TracChangeset
for help on using the changeset viewer.