Changeset 2690 for code/branches/buildsystem3/src
- Timestamp:
- Feb 23, 2009, 8:57:42 PM (16 years ago)
- Location:
- code/branches/buildsystem3/src
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/buildsystem3/src/CMakeLists.txt
r2685 r2690 69 69 # which one we have to define the macros separately for each configuration 70 70 ADD_COMPILER_FLAGS("-DCMAKE_BUILD_TYPE=Debug" Debug) 71 ADD_COMPILER_FLAGS("-DCMAKE_B IULD_TYPE=Release" Release)71 ADD_COMPILER_FLAGS("-DCMAKE_BUILD_TYPE=Release" Release) 72 72 ADD_COMPILER_FLAGS("-DCMAKE_BUILD_TYPE=RelWithDebInfo" RelWithDebInfo) 73 73 ADD_COMPILER_FLAGS("-DCMAKE_BUILD_TYPE=MinSizeRel" MinSizeRel) -
code/branches/buildsystem3/src/core/CMakeLists.txt
r2685 r2690 68 68 GENERATE_TOLUA_BINDINGS(Core CORE_FILES INPUTFILES LuaBind.h CommandExecutor.h) 69 69 70 IF(GCC_NO_SYSTEM_HEADER_SUPPORT)71 # Get around displaying a few hundred lines of warning code72 SET_SOURCE_FILES_PROPERTIES(73 ArgumentCompletionFunctions.cc74 CommandLine.cc75 ConfigFileManager.cc76 Language.cc77 LuaBind.cc78 input/KeyBinder.cc79 PROPERTIES COMPILE_FLAGS "-Wno-sign-compare")80 ENDIF()81 82 70 ADD_LIBRARY(core SHARED ${CORE_FILES}) 83 71 -
code/branches/buildsystem3/src/core/ConfigFileManager.cc
r2687 r2690 223 223 void ConfigFile::load(bool bCreateIfNotExisting) 224 224 { 225 // Be sure we start from new 225 // Be sure we start from new in the memory 226 226 this->clear(); 227 227 228 boost::filesystem::path filepath(Core::getConfigPath() + "/" + this->filename_); 229 230 // This creates the config file if it's not existing 231 std::ofstream createFile; 232 createFile.open(filepath.file_string().c_str(), std::fstream::app); 233 createFile.close(); 228 // Get default file if necessary and available 229 boost::filesystem::path filepath(Core::getConfigPath()); 230 filepath /= this->filename_; 231 if (!boost::filesystem::exists(filepath)) 232 { 233 // Try to get default one from the media folder 234 boost::filesystem::path defaultFilepath(Core::getMediaPath()); 235 defaultFilepath = defaultFilepath / "defaultConfig" / this->filename_; 236 if (boost::filesystem::exists(defaultFilepath)) 237 { 238 boost::filesystem::copy_file(defaultFilepath, filepath); 239 } 240 } 234 241 235 242 // Open the file 236 243 std::ifstream file; 237 244 file.open(filepath.file_string().c_str(), std::fstream::in); 238 239 if (!file.is_open()) 240 { 241 COUT(1) << "An error occurred in ConfigFileManager.cc:" << std::endl; 242 COUT(1) << "Error: Couldn't open config-file \"" << this->filename_ << "\"." << std::endl; 243 return; 244 } 245 246 char linearray[CONFIG_FILE_MAX_LINELENGHT]; 247 248 ConfigFileSection* newsection = 0; 249 250 while (file.good() && !file.eof()) 251 { 252 file.getline(linearray, CONFIG_FILE_MAX_LINELENGHT); 253 254 std::string line = std::string(linearray); 255 256 std::string temp = getStripped(line); 257 if (!isEmpty(temp) && !isComment(temp)) 258 { 259 size_t pos1 = temp.find('['); 260 if (pos1 == 0) pos1 = line.find('['); else pos1 = std::string::npos; 261 size_t pos2 = line.find(']'); 262 263 if (pos1 != std::string::npos && pos2 != std::string::npos && pos2 > pos1 + 1) 245 if (file.is_open()) 246 { 247 248 char linearray[CONFIG_FILE_MAX_LINELENGHT]; 249 250 ConfigFileSection* newsection = 0; 251 252 while (file.good() && !file.eof()) 253 { 254 file.getline(linearray, CONFIG_FILE_MAX_LINELENGHT); 255 256 std::string line = std::string(linearray); 257 258 std::string temp = getStripped(line); 259 if (!isEmpty(temp) && !isComment(temp)) 264 260 { 265 // New section 266 std::string comment = line.substr(pos2 + 1); 267 if (isComment(comment)) 268 newsection = new ConfigFileSection(line.substr(pos1 + 1, pos2 - pos1 - 1), comment); 269 else 270 newsection = new ConfigFileSection(line.substr(pos1 + 1, pos2 - pos1 - 1)); 271 this->sections_.insert(this->sections_.end(), newsection); 272 continue; 273 } 274 } 275 276 if (newsection != 0) 277 { 278 if (isComment(line)) 279 { 280 // New comment 281 newsection->getEntries().insert(newsection->getEntries().end(), new ConfigFileEntryComment(removeTrailingWhitespaces(line))); 282 continue; 283 } 284 else 285 { 286 size_t pos1 = line.find('='); 287 288 if (pos1 != std::string::npos && pos1 > 0) 261 size_t pos1 = temp.find('['); 262 if (pos1 == 0) pos1 = line.find('['); else pos1 = std::string::npos; 263 size_t pos2 = line.find(']'); 264 265 if (pos1 != std::string::npos && pos2 != std::string::npos && pos2 > pos1 + 1) 289 266 { 290 // New entry 291 size_t pos2 = line.find('['); 292 size_t pos3 = line.find(']'); 293 size_t commentposition = getNextCommentPosition(line, pos1 + 1); 294 while (isBetweenQuotes(line, commentposition)) 295 { 296 commentposition = getNextCommentPosition(line, commentposition + 1); 297 } 298 std::string value = "", comment = ""; 299 if (commentposition == std::string::npos) 300 { 301 value = removeTrailingWhitespaces(line.substr(pos1 + 1)); 302 } 267 // New section 268 std::string comment = line.substr(pos2 + 1); 269 if (isComment(comment)) 270 newsection = new ConfigFileSection(line.substr(pos1 + 1, pos2 - pos1 - 1), comment); 303 271 else 304 { 305 value = removeTrailingWhitespaces(line.substr(pos1 + 1, commentposition - pos1 - 1)); 306 comment = removeTrailingWhitespaces(line.substr(commentposition)); 307 } 308 309 if (pos2 != std::string::npos && pos3 != std::string::npos && pos3 > pos2 + 1) 310 { 311 // There might be an array index 312 unsigned int index = 0; 313 if (ConvertValue(&index, line.substr(pos2 + 1, pos3 - pos2 - 1))) 314 { 315 // New array 316 std::list<ConfigFileEntry*>::iterator it = newsection->getEntryIterator(getStripped(line.substr(0, pos2)), index, value, false); 317 (*it)->setValue(value); 318 (*it)->setComment(comment); 319 continue; 320 } 321 } 322 323 // New value 324 newsection->getEntries().insert(newsection->getEntries().end(), new ConfigFileEntryValue(getStripped(line.substr(0, pos1)), value, false, comment)); 272 newsection = new ConfigFileSection(line.substr(pos1 + 1, pos2 - pos1 - 1)); 273 this->sections_.insert(this->sections_.end(), newsection); 325 274 continue; 326 275 } 327 276 } 328 } 329 } 330 331 file.close(); 332 333 COUT(3) << "Loaded config file \"" << this->filename_ << "\"." << std::endl; 334 335 // Save the file in case something changed (like stripped whitespaces) 336 this->save(); 337 338 // Update all ConfigValueContainers 339 this->updateConfigValues(); 277 278 if (newsection != 0) 279 { 280 if (isComment(line)) 281 { 282 // New comment 283 newsection->getEntries().insert(newsection->getEntries().end(), new ConfigFileEntryComment(removeTrailingWhitespaces(line))); 284 continue; 285 } 286 else 287 { 288 size_t pos1 = line.find('='); 289 290 if (pos1 != std::string::npos && pos1 > 0) 291 { 292 // New entry 293 size_t pos2 = line.find('['); 294 size_t pos3 = line.find(']'); 295 size_t commentposition = getNextCommentPosition(line, pos1 + 1); 296 while (isBetweenQuotes(line, commentposition)) 297 { 298 commentposition = getNextCommentPosition(line, commentposition + 1); 299 } 300 std::string value = "", comment = ""; 301 if (commentposition == std::string::npos) 302 { 303 value = removeTrailingWhitespaces(line.substr(pos1 + 1)); 304 } 305 else 306 { 307 value = removeTrailingWhitespaces(line.substr(pos1 + 1, commentposition - pos1 - 1)); 308 comment = removeTrailingWhitespaces(line.substr(commentposition)); 309 } 310 311 if (pos2 != std::string::npos && pos3 != std::string::npos && pos3 > pos2 + 1) 312 { 313 // There might be an array index 314 unsigned int index = 0; 315 if (ConvertValue(&index, line.substr(pos2 + 1, pos3 - pos2 - 1))) 316 { 317 // New array 318 std::list<ConfigFileEntry*>::iterator it = newsection->getEntryIterator(getStripped(line.substr(0, pos2)), index, value, false); 319 (*it)->setValue(value); 320 (*it)->setComment(comment); 321 continue; 322 } 323 } 324 325 // New value 326 newsection->getEntries().insert(newsection->getEntries().end(), new ConfigFileEntryValue(getStripped(line.substr(0, pos1)), value, false, comment)); 327 continue; 328 } 329 } 330 } 331 } 332 333 file.close(); 334 335 COUT(3) << "Loaded config file \"" << this->filename_ << "\"." << std::endl; 336 337 // Save the file in case something changed (like stripped whitespaces) 338 this->save(); 339 340 // Update all ConfigValueContainers 341 this->updateConfigValues(); 342 } // end file.is_open() 340 343 } 341 344 342 345 void ConfigFile::save() const 343 346 { 344 boost::filesystem::path filepath(Core::getConfigPath() + "/" + this->filename_); 347 boost::filesystem::path filepath(Core::getConfigPath()); 348 filepath /= this->filename_; 345 349 346 350 std::ofstream file; -
code/branches/buildsystem3/src/core/Core.cc
r2685 r2690 34 34 #include "Core.h" 35 35 #include <cassert> 36 #include <fstream> 37 #include <boost/filesystem.hpp> 38 39 #include "util/Exception.h" 36 40 #include "Language.h" 37 41 #include "CoreIncludes.h" … … 51 55 std::string Core::configPath_s(ORXONOX_CONFIG_INSTALL_PATH); // from OrxonoxConfig.h 52 56 std::string Core::logPath_s (ORXONOX_LOG_INSTALL_PATH); // from OrxonoxConfig.h 57 std::string Core::mediaPath_s (ORXONOX_MEDIA_INSTALL_PATH); // from OrxonoxConfig.h 53 58 54 59 Core* Core::singletonRef_s = 0; … … 119 124 defaultMediaPath = ORXONOX_MEDIA_DEV_PATH; 120 125 121 SetConfigValue(mediaPath_ , defaultMediaPath)126 SetConfigValue(mediaPath_s, defaultMediaPath) 122 127 .description("Relative path to the game data.").callback(this, &Core::mediaPathChanged); 123 128 … … 157 162 void Core::mediaPathChanged() 158 163 { 159 if (mediaPath_ != "" && mediaPath_[mediaPath_.size() - 1] != '/')160 { 161 ModifyConfigValue(mediaPath_ , set, mediaPath_+ "/");162 } 163 164 if (mediaPath_ == "")165 { 166 ModifyConfigValue(mediaPath_ , set, "/");164 if (mediaPath_s != "" && mediaPath_s[mediaPath_s.size() - 1] != '/') 165 { 166 ModifyConfigValue(mediaPath_s, set, mediaPath_s + "/"); 167 } 168 169 if (mediaPath_s == "") 170 { 171 ModifyConfigValue(mediaPath_s, set, "/"); 167 172 COUT(2) << "Warning: Data path set to \"/\", is that really correct?" << std::endl; 168 173 } … … 245 250 if (*path.end() != '/' && *path.end() != '\\') 246 251 { 247 ModifyConfigValue(mediaPath_ , tset, path + "/");252 ModifyConfigValue(mediaPath_s, tset, path + "/"); 248 253 } 249 254 else 250 255 { 251 ModifyConfigValue(mediaPath_ , tset, path);256 ModifyConfigValue(mediaPath_s, tset, path); 252 257 } 253 258 } … … 264 269 } 265 270 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; 271 /** 272 @brief 273 Checks for "orxonox_dev_build.keep_me" in the working diretory. 274 If found it means that this is not an installed run, hence we 275 don't write the logs and config files to ~/.orxonox 276 */ 277 /*static*/ void Core::checkDevBuild() 278 { 279 std::ifstream probe; 280 probe.open("orxonox_dev_build.keep_me"); 281 if (probe) 282 { 283 Core::isDevBuild_s = true; 284 // Constants are taken from OrxonoxConfig.h 285 Core::configPath_s = ORXONOX_CONFIG_DEV_PATH; 286 Core::logPath_s = ORXONOX_LOG_DEV_PATH; 287 Core::mediaPath_s = ORXONOX_MEDIA_DEV_PATH; 288 probe.close(); 289 } 290 } 291 292 /* 293 @brief 294 Checks for the log and the config directory and creates them 295 if necessary. Otherwise me might have problems opening those files. 296 */ 297 /*static*/ void Core::createDirectories() 298 { 299 std::vector<std::pair<boost::filesystem::path, std::string> > directories; 300 directories.push_back(std::pair<boost::filesystem::path, std::string> 301 (boost::filesystem::path(Core::configPath_s), "config")); 302 directories.push_back(std::pair<boost::filesystem::path, std::string> 303 (boost::filesystem::path(Core::logPath_s), "log")); 304 305 for (std::vector<std::pair<boost::filesystem::path, std::string> >::iterator it = directories.begin(); 306 it != directories.end(); ++it) 307 { 308 if (boost::filesystem::exists(it->first) && !boost::filesystem::is_directory(it->first)) 309 { 310 ThrowException(General, std::string("The ") + it->second + " directory has been preoccupied by a file! \ 311 Please remove " + it->first.file_string()); 312 } 313 if (boost::filesystem::create_directory(it->first)) // function may not return true at all (bug?) 314 { 315 COUT(4) << "Created " << it->second << " directory" << std::endl; 316 } 317 } 274 318 } 275 319 } -
code/branches/buildsystem3/src/core/Core.h
r2685 r2690 68 68 static bool isDevBuild() { return Core::isDevBuild_s; } 69 69 70 static const std::string& getMediaPath()71 { assert(singletonRef_s); return singletonRef_s->mediaPath_; }72 70 static void tsetMediaPath(const std::string& path) 73 71 { assert(singletonRef_s); singletonRef_s->_tsetMediaPath(path); } 72 static const std::string& getMediaPath() { return mediaPath_s; } 74 73 static const std::string& getConfigPath() { return configPath_s; } 75 74 static const std::string& getLogPath() { return logPath_s; } … … 96 95 void _tsetMediaPath(const std::string& path); 97 96 98 static void setDevBuild(); 97 static void createDirectories(); 98 static void checkDevBuild(); 99 99 100 100 int softDebugLevel_; //!< The debug level … … 104 104 std::string language_; //!< The language 105 105 bool bInitializeRandomNumberGenerator_; //!< If true, srand(time(0)) is called 106 std::string mediaPath_; //!< Path to the data/media file folder107 106 108 107 static bool bShowsGraphics_s; //!< global variable that tells whether to show graphics … … 115 114 static std::string configPath_s; //!< Path to the config file folder 116 115 static std::string logPath_s; //!< Path to the log file folder 116 static std::string mediaPath_s; //!< Path to the data/media file folder 117 117 118 118 static Core* singletonRef_s; -
code/branches/buildsystem3/src/core/input/KeyBinder.cc
r2687 r2690 248 248 True if loading succeeded. 249 249 */ 250 void KeyBinder::loadBindings(const std::string& filename , const std::string& defaultFilename)250 void KeyBinder::loadBindings(const std::string& filename) 251 251 { 252 252 COUT(3) << "KeyBinder: Loading key bindings..." << std::endl; … … 255 255 return; 256 256 257 boost::filesystem::path folder(Core::getConfigPath());258 boost::filesystem::path filepath(folder/filename);259 260 // get bindings from default file if filename doesn't exist.261 std::ifstream infile;262 infile.open(filepath.file_string().c_str());263 if (!infile)264 {265 ConfigFileManager::getInstance().setFilename(this->configFile_, defaultFilename);266 ConfigFileManager::getInstance().saveAs(this->configFile_, filename);267 }268 else269 infile.close();270 257 ConfigFileManager::getInstance().setFilename(this->configFile_, filename); 271 258 -
code/branches/buildsystem3/src/core/input/KeyBinder.h
r2662 r2690 61 61 virtual ~KeyBinder(); 62 62 63 void loadBindings(const std::string& filename , const std::string& defaultFilename);63 void loadBindings(const std::string& filename); 64 64 void clearBindings(); 65 65 bool setBinding(const std::string& binding, const std::string& name, bool bTemporary = false); -
code/branches/buildsystem3/src/orxonox/CMakeLists.txt
r2685 r2690 39 39 # Not using precompiled header files: Avoid dependencies 40 40 INCLUDE_DIRECTORIES(pch/nopch) 41 42 IF(GCC_NO_SYSTEM_HEADER_SUPPORT)43 # Get around displaying a few hundred lines of warning code44 SET_SOURCE_FILES_PROPERTIES(45 gamestates/GSGraphics.cc46 gui/GUIManager.cc47 PROPERTIES COMPILE_FLAGS "-Wno-sign-compare"48 )49 ENDIF()50 41 51 42 ADD_EXECUTABLE(orxonox ${ORXONOX_FILES}) -
code/branches/buildsystem3/src/orxonox/Main.cc
r2685 r2690 37 37 #include <exception> 38 38 #include <cassert> 39 #include <fstream>40 39 41 40 #include "OrxonoxConfig.h" … … 95 94 // First, determine whether we have an installed or a binary dir run 96 95 // The latter occurs when simply running from the build directory 97 std::ifstream probe; 98 probe.open("orxonox_dev_build.keep_me"); 99 if (probe) 100 { 101 Core::setDevBuild(); 102 probe.close(); 103 } 96 Core::checkDevBuild(); 97 98 // Make sure the directories we write in exist or else make them 99 Core::createDirectories(); 104 100 105 101 // create a signal handler (only active for linux) -
code/branches/buildsystem3/src/orxonox/gamestates/GSGraphics.cc
r2687 r2690 107 107 SetConfigValue(ogreLogLevelCritical_, 2) 108 108 .description("Corresponding orxonox debug level for ogre Critical"); 109 SetConfigValue(defaultMasterKeybindings_, "def_masterKeybindings.ini")110 .description("Filename of default master keybindings.");111 109 } 112 110 … … 148 146 // Configure master input state with a KeyBinder 149 147 masterKeyBinder_ = new KeyBinder(); 150 masterKeyBinder_->loadBindings("masterKeybindings.ini" , defaultMasterKeybindings_);148 masterKeyBinder_->loadBindings("masterKeybindings.ini"); 151 149 inputManager_->getMasterInputState()->addKeyHandler(masterKeyBinder_); 152 150 -
code/branches/buildsystem3/src/orxonox/gamestates/GSGraphics.h
r2664 r2690 105 105 int ogreLogLevelNormal_; //!< Corresponding Orxonx debug level for LL_NORMAL 106 106 int ogreLogLevelCritical_; //!< Corresponding Orxonx debug level for LL_CRITICAL 107 std::string defaultMasterKeybindings_; //!< Filename of default master keybindings.108 107 109 108 // console commands -
code/branches/buildsystem3/src/orxonox/gamestates/GSLevel.cc
r2685 r2690 75 75 { 76 76 SetConfigValue(keyDetectorCallbackCode_, "KeybindBindingStringKeyName="); 77 SetConfigValue(defaultKeybindings_, "def_keybindings.ini")78 .description("Filename of default keybindings.");79 77 } 80 78 … … 85 83 inputState_ = InputManager::getInstance().createInputState<SimpleInputState>("game", 20); 86 84 keyBinder_ = new KeyBinder(); 87 keyBinder_->loadBindings("keybindings.ini" , defaultKeybindings_);85 keyBinder_->loadBindings("keybindings.ini"); 88 86 inputState_->setHandler(keyBinder_); 89 87 -
code/branches/buildsystem3/src/orxonox/gamestates/GSLevel.h
r2662 r2690 66 66 //##### ConfigValues ##### 67 67 std::string keyDetectorCallbackCode_; 68 //! Filename of default keybindings.69 std::string defaultKeybindings_;70 68 71 69 // console commands
Note: See TracChangeset
for help on using the changeset viewer.