Changeset 2710 for code/trunk/src/core
- Timestamp:
- Feb 28, 2009, 7:46:37 PM (16 years ago)
- Location:
- code/trunk
- Files:
-
- 1 deleted
- 30 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:ignore deleted
- Property svn:mergeinfo changed
-
code/trunk/src/core/ArgumentCompletionFunctions.cc
r2087 r2710 27 27 */ 28 28 29 #include "ArgumentCompletionFunctions.h" 30 29 31 #include <iostream> 30 32 #include <map> 31 32 33 #include <boost/filesystem.hpp> 33 34 34 #include "ArgumentCompletionFunctions.h"35 35 #include "CoreIncludes.h" 36 36 #include "Identifier.h" … … 63 63 startdirectory = "."; 64 64 } 65 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN3265 #ifdef ORXONOX_PLATFORM_WINDOWS 66 66 else 67 67 { 68 68 std::string dir = startdirectory.string(); 69 69 if (dir.size() > 0 && dir[dir.size() - 1] == ':') 70 startdirectory = dir + "/";70 startdirectory = dir + CP_SLASH; 71 71 } 72 72 #endif … … 78 78 { 79 79 if (boost::filesystem::is_directory(*file)) 80 dirlist.push_back(ArgumentCompletionListElement((*file).string() + "/", getLowercase((*file).string()) + "/", (*file).leaf() + "/"));80 dirlist.push_back(ArgumentCompletionListElement((*file).string() + CP_SLASH, getLowercase((*file).string()) + "/", (*file).leaf() + "/")); 81 81 else 82 82 filelist.push_back(ArgumentCompletionListElement((*file).string(), getLowercase((*file).string()), (*file).leaf())); -
code/trunk/src/core/BaseObject.cc
r2662 r2710 33 33 34 34 #include "BaseObject.h" 35 #include "tinyxml/tinyxml.h" 35 36 #include <tinyxml/tinyxml.h> 37 36 38 #include "CoreIncludes.h" 37 39 #include "EventIncludes.h" -
code/trunk/src/core/CMakeLists.txt
r2131 r2710 1 SET(CORE_SRC_FILES 1 # 2 # ORXONOX - the hottest 3D action shooter ever to exist 3 # > www.orxonox.net < 4 # 5 # This program is free software; you can redistribute it and/or 6 # modify it under the terms of the GNU General Public License 7 # as published by the Free Software Foundation; either version 2 8 # of the License, or (at your option) any later version. 9 # 10 # This program is distributed in the hope that it will be useful, 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 # GNU General Public License for more details. 14 # 15 # You should have received a copy of the GNU General Public License along 16 # with this program; if not, write to the Free Software Foundation, 17 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 # 19 20 SET_SOURCE_FILES(CORE_SRC_FILES 2 21 Clock.cc 3 22 ConfigFileManager.cc … … 41 60 TclBind.cc 42 61 TclThreadManager.cc 62 ) 63 ADD_SUBDIRECTORY(input) 64 GET_ALL_HEADER_FILES(CORE_HDR_FILES) 65 SET(CORE_FILES ${CORE_SRC_FILES} ${CORE_HDR_FILES}) 43 66 44 tolua/tolua_bind.cc 67 GENERATE_SOURCE_GROUPS(${CORE_FILES}) 68 GENERATE_TOLUA_BINDINGS(Core CORE_FILES INPUTFILES LuaBind.h CommandExecutor.h) 69 70 ADD_LIBRARY(core SHARED ${CORE_FILES}) 71 72 SET_TARGET_PROPERTIES(core PROPERTIES DEFINE_SYMBOL "CORE_SHARED_BUILD") 73 TARGET_LINK_LIBRARIES(core 74 ${OGRE_LIBRARY} 75 ${Boost_THREAD_LIBRARY} 76 ${Boost_FILESYSTEM_LIBRARY} 77 ${Boost_SYSTEM_LIBRARY} 78 ${Boost_DATE_TIME_LIBRARY} # MSVC only 79 ${LUA_LIBRARIES} 80 cpptcl_orxonox 81 ois_orxonox 82 tinyxml++_orxonox 83 tolua++_orxonox 84 util 45 85 ) 46 86 47 ADD_SOURCE_DIRECTORY(CORE_SRC_FILES input) 48 49 GET_TARGET_PROPERTY(TOLUA_EXE tolua_orxonox LOCATION) 50 ADD_CUSTOM_COMMAND( 51 OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/tolua/tolua_bind.cc ${CMAKE_CURRENT_SOURCE_DIR}/tolua/tolua_bind.h 52 COMMAND ${TOLUA_EXE} -n Core -o ../../src/core/tolua/tolua_bind.cc -H ../../src/core/tolua/tolua_bind.h ../../src/core/tolua/tolua.pkg 53 DEPENDS 54 tolua_orxonox 55 tolua/tolua.pkg 56 LuaBind.h 57 CommandExecutor.h 58 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/bin/lib 59 ) 60 61 ADD_LIBRARY(core SHARED ${CORE_SRC_FILES}) 62 63 TARGET_LINK_LIBRARIES(core 64 ${OGRE_LIBRARIES} 65 ${Boost_thread_LIBRARIES} 66 ${Boost_filesystem_LIBRARIES} 67 lua_orxonox 68 cpptcl_orxonox 69 ois_orxonox 70 tinyxml_orxonox 71 tolualib_orxonox 72 util 73 ) 87 ORXONOX_INSTALL(core) -
code/trunk/src/core/CommandExecutor.h
r2662 r2710 36 36 #include "CommandEvaluation.h" 37 37 38 namespace orxonox // tolua_export 39 { // tolua_export 38 // tolua_begin 39 namespace orxonox 40 { 40 41 class _CoreExport CommandExecutor 41 /*42 class CommandExecutor { // tolua_export43 */44 42 { 43 // tolua_end 45 44 public: 46 45 static bool execute(const std::string& command, bool useTcl = true); // tolua_export -
code/trunk/src/core/CommandLine.cc
r2662 r2710 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 filepath(Core::getConfigPath() / filename); 305 301 306 // look for additional arguments in given file or start.ini as default 302 307 // They will not overwrite the arguments given directly 303 308 std::ifstream file; 304 std::string filename = CommandLine::getValue("optionsFile").getString(); 305 file.open(filename.c_str()); 309 file.open(filepath.file_string().c_str()); 306 310 args.clear(); 307 311 if (file) -
code/trunk/src/core/ConfigFileManager.cc
r2662 r2710 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 … … 220 223 void ConfigFile::load(bool bCreateIfNotExisting) 221 224 { 222 // Be sure we start from new 225 // Be sure we start from new in the memory 223 226 this->clear(); 224 227 225 // This creates the config file if it's not existing 226 std::ofstream createFile; 227 createFile.open(this->filename_.c_str(), std::fstream::app); 228 createFile.close(); 228 // Get default file if necessary and available 229 boost::filesystem::path filepath(Core::getConfigPath() / this->filename_); 230 if (!boost::filesystem::exists(filepath)) 231 { 232 // Try to get default one from the media folder 233 boost::filesystem::path defaultFilepath(Core::getMediaPath() / "defaultConfig" / this->filename_); 234 if (boost::filesystem::exists(defaultFilepath)) 235 { 236 boost::filesystem::copy_file(defaultFilepath, filepath); 237 } 238 } 229 239 230 240 // Open the file 231 241 std::ifstream file; 232 file.open(this->filename_.c_str(), std::fstream::in); 233 234 if (!file.is_open()) 235 { 236 COUT(1) << "An error occurred in ConfigFileManager.cc:" << std::endl; 237 COUT(1) << "Error: Couldn't open config-file \"" << this->filename_ << "\"." << std::endl; 238 return; 239 } 240 241 char linearray[CONFIG_FILE_MAX_LINELENGHT]; 242 243 ConfigFileSection* newsection = 0; 244 245 while (file.good() && !file.eof()) 246 { 247 file.getline(linearray, CONFIG_FILE_MAX_LINELENGHT); 248 249 std::string line = std::string(linearray); 250 251 std::string temp = getStripped(line); 252 if (!isEmpty(temp) && !isComment(temp)) 253 { 254 size_t pos1 = temp.find('['); 255 if (pos1 == 0) pos1 = line.find('['); else pos1 = std::string::npos; 256 size_t pos2 = line.find(']'); 257 258 if (pos1 != std::string::npos && pos2 != std::string::npos && pos2 > pos1 + 1) 242 file.open(filepath.file_string().c_str(), std::fstream::in); 243 if (file.is_open()) 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)) 259 258 { 260 // New section 261 std::string comment = line.substr(pos2 + 1); 262 if (isComment(comment)) 263 newsection = new ConfigFileSection(line.substr(pos1 + 1, pos2 - pos1 - 1), comment); 264 else 265 newsection = new ConfigFileSection(line.substr(pos1 + 1, pos2 - pos1 - 1)); 266 this->sections_.insert(this->sections_.end(), newsection); 267 continue; 268 } 269 } 270 271 if (newsection != 0) 272 { 273 if (isComment(line)) 274 { 275 // New comment 276 newsection->getEntries().insert(newsection->getEntries().end(), new ConfigFileEntryComment(removeTrailingWhitespaces(line))); 277 continue; 278 } 279 else 280 { 281 size_t pos1 = line.find('='); 282 283 if (pos1 != std::string::npos && pos1 > 0) 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) 284 264 { 285 // New entry 286 size_t pos2 = line.find('['); 287 size_t pos3 = line.find(']'); 288 size_t commentposition = getNextCommentPosition(line, pos1 + 1); 289 while (isBetweenQuotes(line, commentposition)) 290 { 291 commentposition = getNextCommentPosition(line, commentposition + 1); 292 } 293 std::string value = "", comment = ""; 294 if (commentposition == std::string::npos) 295 { 296 value = removeTrailingWhitespaces(line.substr(pos1 + 1)); 297 } 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); 298 269 else 299 { 300 value = removeTrailingWhitespaces(line.substr(pos1 + 1, commentposition - pos1 - 1)); 301 comment = removeTrailingWhitespaces(line.substr(commentposition)); 302 } 303 304 if (pos2 != std::string::npos && pos3 != std::string::npos && pos3 > pos2 + 1) 305 { 306 // There might be an array index 307 unsigned int index = 0; 308 if (ConvertValue(&index, line.substr(pos2 + 1, pos3 - pos2 - 1))) 309 { 310 // New array 311 std::list<ConfigFileEntry*>::iterator it = newsection->getEntryIterator(getStripped(line.substr(0, pos2)), index, value, false); 312 (*it)->setValue(value); 313 (*it)->setComment(comment); 314 continue; 315 } 316 } 317 318 // New value 319 newsection->getEntries().insert(newsection->getEntries().end(), new ConfigFileEntryValue(getStripped(line.substr(0, pos1)), value, false, comment)); 270 newsection = new ConfigFileSection(line.substr(pos1 + 1, pos2 - pos1 - 1)); 271 this->sections_.insert(this->sections_.end(), newsection); 320 272 continue; 321 273 } 322 274 } 323 } 324 } 325 326 file.close(); 327 328 COUT(3) << "Loaded config file \"" << this->filename_ << "\"." << std::endl; 329 330 // Save the file in case something changed (like stripped whitespaces) 331 this->save(); 332 333 // Update all ConfigValueContainers 334 this->updateConfigValues(); 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) 289 { 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 } 303 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)); 325 continue; 326 } 327 } 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(); 340 } // end file.is_open() 335 341 } 336 342 337 343 void ConfigFile::save() const 338 344 { 345 boost::filesystem::path filepath(Core::getConfigPath() / this->filename_); 346 339 347 std::ofstream file; 340 file.open( this->filename_.c_str(), std::fstream::out);348 file.open(filepath.file_string().c_str(), std::fstream::out); 341 349 file.setf(std::ios::fixed, std::ios::floatfield); 342 350 file.precision(6); -
code/trunk/src/core/Core.cc
r2662 r2710 33 33 34 34 #include "Core.h" 35 35 36 #include <cassert> 37 #include <fstream> 38 #include <cstdlib> 39 #include <cstdio> 40 #include <boost/filesystem.hpp> 41 42 #ifdef ORXONOX_PLATFORM_WINDOWS 43 # include <windows.h> 44 #elif defined(ORXONOX_PLATFORM_APPLE) 45 # include <sys/param.h> 46 # include <mach-o/dyld.h> 47 #else /* Linux */ 48 # include <sys/types.h> 49 # include <unistd.h> 50 #endif 51 52 #include "SpecialConfig.h" 53 #include "util/Exception.h" 36 54 #include "Language.h" 37 55 #include "CoreIncludes.h" 38 56 #include "ConfigValueIncludes.h" 57 #include "LuaBind.h" 58 #include "CommandLine.h" 39 59 40 60 namespace orxonox 41 61 { 62 //! Path to the parent directory of the ones above if program was installed with relativ pahts 63 static boost::filesystem::path rootPath_g; 64 static boost::filesystem::path executablePath_g; //!< Path to the executable 65 static boost::filesystem::path mediaPath_g; //!< Path to the media file folder 66 static boost::filesystem::path configPath_g; //!< Path to the config file folder 67 static boost::filesystem::path logPath_g; //!< Path to the log file folder 68 42 69 bool Core::bShowsGraphics_s = false; 43 70 bool Core::bHasServer_s = false; … … 46 73 bool Core::bIsMaster_s = false; 47 74 48 Core* Core::singletonRef_s = 0; 75 bool Core::isDevBuild_s = false; 76 Core* Core::singletonRef_s = 0; 77 78 SetCommandLineArgument(mediaPath, "").information("PATH"); 79 SetCommandLineArgument(directory, "").information("DIR"); 49 80 50 81 /** … … 58 89 assert(Core::singletonRef_s == 0); 59 90 Core::singletonRef_s = this; 91 60 92 this->bInitializeRandomNumberGenerator_ = false; 61 62 93 this->setConfigValues(); 94 95 // Set the correct log path. Before this call, /tmp (Unix) or %TEMP% was used 96 OutputHandler::getOutStream().setLogPath(Core::getLogPathString()); 97 98 // Possible media path override by the command line 99 if (!CommandLine::getArgument("mediaPath")->hasDefaultValue()) 100 { 101 //std::string mediaPath = CommandLine::getValue("mediaPath"); 102 Core::tsetMediaPath(CommandLine::getValue("mediaPath")); 103 } 63 104 } 64 105 … … 77 118 void Core::setConfigValues() 78 119 { 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); 120 #ifdef NDEBUG 121 const unsigned int defaultLevelConsole = 1; 122 const unsigned int defaultLevelLogfile = 3; 123 const unsigned int defaultLevelShell = 1; 124 #else 125 const unsigned int defaultLevelConsole = 3; 126 const unsigned int defaultLevelLogfile = 4; 127 const unsigned int defaultLevelShell = 3; 128 #endif 129 SetConfigValue(softDebugLevelConsole_, defaultLevelConsole) 130 .description("The maximal level of debug output shown in the console").callback(this, &Core::debugLevelChanged); 131 SetConfigValue(softDebugLevelLogfile_, defaultLevelLogfile) 132 .description("The maximal level of debug output shown in the logfile").callback(this, &Core::debugLevelChanged); 133 SetConfigValue(softDebugLevelShell_, defaultLevelShell) 134 .description("The maximal level of debug output shown in the ingame shell").callback(this, &Core::debugLevelChanged); 135 82 136 SetConfigValue(language_, Language::getLanguage().defaultLanguage_).description("The language of the ingame text").callback(this, &Core::languageChanged); 83 137 SetConfigValue(bInitializeRandomNumberGenerator_, true).description("If true, all random actions are different each time you start the game").callback(this, &Core::initializeRandomNumberGenerator); 138 139 SetConfigValue(mediaPathString_, Core::getMediaPathPOSIXString()) 140 .description("Relative path to the game data.").callback(this, &Core::mediaPathChanged); 84 141 } 85 142 … … 109 166 // Read the translation file after the language was configured 110 167 Language::getLanguage().readTranslatedLanguageFile(); 168 } 169 170 /** 171 @brief 172 Callback function if the media path has changed. 173 */ 174 void Core::mediaPathChanged() 175 { 176 mediaPath_g = boost::filesystem::path(this->mediaPathString_); 111 177 } 112 178 … … 177 243 } 178 244 245 /** 246 @brief 247 Temporary sets the media path 248 @param path 249 The new media path 250 */ 251 void Core::_tsetMediaPath(const std::string& path) 252 { 253 ModifyConfigValue(mediaPathString_, tset, path); 254 } 255 256 /*static*/ const boost::filesystem::path& Core::getMediaPath() 257 { 258 return mediaPath_g; 259 } 260 /*static*/ std::string Core::getMediaPathString() 261 { 262 return mediaPath_g.directory_string() + CP_SLASH; 263 } 264 /*static*/ std::string Core::getMediaPathPOSIXString() 265 { 266 return mediaPath_g.string() + '/'; 267 268 } 269 270 /*static*/ const boost::filesystem::path& Core::getConfigPath() 271 { 272 return configPath_g; 273 } 274 /*static*/ std::string Core::getConfigPathString() 275 { 276 return configPath_g.directory_string() + CP_SLASH; 277 } 278 /*static*/ std::string Core::getConfigPathPOSIXString() 279 { 280 return configPath_g.string() + '/'; 281 } 282 283 /*static*/ const boost::filesystem::path& Core::getLogPath() 284 { 285 return logPath_g; 286 } 287 /*static*/ std::string Core::getLogPathString() 288 { 289 return logPath_g.directory_string() + CP_SLASH; 290 } 291 /*static*/ std::string Core::getLogPathPOSIXString() 292 { 293 return logPath_g.string() + '/'; 294 } 295 179 296 void Core::initializeRandomNumberGenerator() 180 297 { … … 187 304 } 188 305 } 306 307 /** 308 @brief 309 Performs the rather lower level operations just after 310 int main() has been called. 311 @remarks 312 This gets called AFTER pre-main stuff like AddFactory, 313 SetConsoleCommand, etc. 314 */ 315 /*static*/ void Core::postMainInitialisation() 316 { 317 // set location of the executable 318 Core::setExecutablePath(); 319 320 // Determine whether we have an installed or a binary dir run 321 // The latter occurs when simply running from the build directory 322 Core::checkDevBuild(); 323 324 // Make sure the directories we write in exist or else make them 325 Core::createDirectories(); 326 } 327 328 /** 329 @brief 330 Compares the executable path with the working directory 331 */ 332 /*static*/ void Core::setExecutablePath() 333 { 334 #ifdef ORXONOX_PLATFORM_WINDOWS 335 // get executable module 336 TCHAR buffer[1024]; 337 if (GetModuleFileName(NULL, buffer, 1024) == 0) 338 ThrowException(General, "Could not retrieve executable path."); 339 340 #elif defined(ORXONOX_PLATFORM_APPLE) 341 char buffer[1024]; 342 unsigned long path_len = 1023; 343 if (_NSGetExecutablePath(buffer, &path_len)) 344 ThrowException(General, "Could not retrieve executable path."); 345 346 #else /* Linux */ 347 /* written by Nicolai Haehnle <prefect_@gmx.net> */ 348 349 /* Get our PID and build the name of the link in /proc */ 350 char linkname[64]; /* /proc/<pid>/exe */ 351 if (snprintf(linkname, sizeof(linkname), "/proc/%i/exe", getpid()) < 0) 352 { 353 /* This should only happen on large word systems. I'm not sure 354 what the proper response is here. 355 Since it really is an assert-like condition, aborting the 356 program seems to be in order. */ 357 assert(false); 358 } 359 360 /* Now read the symbolic link */ 361 char buffer[1024]; 362 int ret; 363 ret = readlink(linkname, buffer, 1024); 364 /* In case of an error, leave the handling up to the caller */ 365 if (ret == -1) 366 ThrowException(General, "Could not retrieve executable path."); 367 368 /* Ensure proper NUL termination */ 369 buffer[ret] = 0; 370 #endif 371 372 executablePath_g = boost::filesystem::path(buffer); 373 #ifndef ORXONOX_PLATFORM_APPLE 374 executablePath_g = executablePath_g.branch_path(); // remove executable name 375 #endif 376 } 377 378 /** 379 @brief 380 Checks for "orxonox_dev_build.keep_me" in the executable diretory. 381 If found it means that this is not an installed run, hence we 382 don't write the logs and config files to ~/.orxonox 383 */ 384 /*static*/ void Core::checkDevBuild() 385 { 386 if (boost::filesystem::exists(executablePath_g / "orxonox_dev_build.keep_me")) 387 { 388 COUT(1) << "Running from the build tree." << std::endl; 389 Core::isDevBuild_s = true; 390 mediaPath_g = ORXONOX_MEDIA_DEV_PATH; 391 configPath_g = ORXONOX_CONFIG_DEV_PATH; 392 logPath_g = ORXONOX_LOG_DEV_PATH; 393 } 394 else 395 { 396 #ifdef INSTALL_COPYABLE // --> relative paths 397 // Also set the root path 398 boost::filesystem::path relativeExecutablePath(ORXONOX_RUNTIME_INSTALL_PATH); 399 rootPath_g = executablePath_g; 400 while (!boost::filesystem::equivalent(rootPath_g / relativeExecutablePath, executablePath_g) || rootPath_g.empty()) 401 rootPath_g = rootPath_g.branch_path(); 402 if (rootPath_g.empty()) 403 ThrowException(General, "Could not derive a root directory. Might the binary installation directory contain '..' when taken relative to the installation prefix path?"); 404 405 // Using paths relative to the install prefix, complete them 406 mediaPath_g = rootPath_g / ORXONOX_MEDIA_INSTALL_PATH; 407 configPath_g = rootPath_g / ORXONOX_CONFIG_INSTALL_PATH; 408 logPath_g = rootPath_g / ORXONOX_LOG_INSTALL_PATH; 409 #else 410 // There is no root path, so don't set it at all 411 412 mediaPath_g = ORXONOX_MEDIA_INSTALL_PATH; 413 414 // Get user directory 415 # ifdef ORXONOX_PLATFORM_UNIX /* Apple? */ 416 char* userDataPathPtr(getenv("HOME")); 417 # else 418 char* userDataPathPtr(getenv("APPDATA")); 419 # endif 420 if (userDataPathPtr == NULL) 421 ThrowException(General, "Could not retrieve user data path."); 422 boost::filesystem::path userDataPath(userDataPathPtr); 423 userDataPath /= ".orxonox"; 424 425 configPath_g = userDataPath / ORXONOX_CONFIG_INSTALL_PATH; 426 logPath_g = userDataPath / ORXONOX_LOG_INSTALL_PATH; 427 #endif 428 } 429 430 // Option to put all the config and log files in a separate folder 431 if (!CommandLine::getArgument("directory")->hasDefaultValue()) 432 { 433 std::string directory(CommandLine::getValue("directory")); 434 configPath_g = configPath_g / directory; 435 logPath_g = logPath_g / directory; 436 } 437 } 438 439 /* 440 @brief 441 Checks for the log and the config directory and creates them 442 if necessary. Otherwise me might have problems opening those files. 443 */ 444 /*static*/ void Core::createDirectories() 445 { 446 std::vector<std::pair<boost::filesystem::path, std::string> > directories; 447 directories.push_back(std::pair<boost::filesystem::path, std::string> 448 (boost::filesystem::path(configPath_g), "config")); 449 directories.push_back(std::pair<boost::filesystem::path, std::string> 450 (boost::filesystem::path(logPath_g), "log")); 451 452 for (std::vector<std::pair<boost::filesystem::path, std::string> >::iterator it = directories.begin(); 453 it != directories.end(); ++it) 454 { 455 if (boost::filesystem::exists(it->first) && !boost::filesystem::is_directory(it->first)) 456 { 457 ThrowException(General, std::string("The ") + it->second + " directory has been preoccupied by a file! \ 458 Please remove " + it->first.file_string()); 459 } 460 if (boost::filesystem::create_directories(it->first)) // function may not return true at all (bug?) 461 { 462 COUT(4) << "Created " << it->second << " directory" << std::endl; 463 } 464 } 465 } 189 466 } -
code/trunk/src/core/Core.h
r2662 r2710 44 44 #include "util/OutputHandler.h" 45 45 46 // Only allow main to access postMainInitialisation, so we need a forward declaration 47 int main(int, char**); 48 // boost::filesystem header has quite a large tail, use forward declaration 49 namespace boost { namespace filesystem 50 { 51 struct path_traits; 52 template<class String, class Traits> class basic_path; 53 typedef basic_path< std::string, path_traits> path; 54 } } 55 46 56 namespace orxonox 47 57 { … … 49 59 class _CoreExport Core : public OrxonoxClass 50 60 { 61 friend int ::main(int, char**); // sets isDevBuild_s 62 51 63 public: 52 64 Core(); 53 65 ~Core(); 54 66 void setConfigValues(); 55 void debugLevelChanged();56 void languageChanged();57 67 58 68 static Core& getInstance() { assert(Core::singletonRef_s); return *Core::singletonRef_s; } … … 62 72 static const std::string& getLanguage(); 63 73 static void resetLanguage(); 74 75 static bool isDevBuild() { return Core::isDevBuild_s; } 76 77 static void tsetMediaPath(const std::string& path) 78 { assert(singletonRef_s); singletonRef_s->_tsetMediaPath(path); } 79 static const boost::filesystem::path& getMediaPath(); 80 static const boost::filesystem::path& getConfigPath(); 81 static const boost::filesystem::path& getLogPath(); 82 static std::string getMediaPathString(); 83 static std::string getConfigPathString(); 84 static std::string getLogPathString(); 85 static std::string getMediaPathPOSIXString(); 86 static std::string getConfigPathPOSIXString(); 87 static std::string getLogPathPOSIXString(); 64 88 65 89 // fast access global variables. … … 79 103 void resetLanguageIntern(); 80 104 void initializeRandomNumberGenerator(); 105 void debugLevelChanged(); 106 void languageChanged(); 107 void mediaPathChanged(); 108 void _tsetMediaPath(const std::string& path); 109 110 static void postMainInitialisation(); 111 static void checkDevBuild(); 112 static void setExecutablePath(); 113 static void createDirectories(); 81 114 82 115 int softDebugLevel_; //!< The debug level … … 85 118 int softDebugLevelShell_; //!< The debug level for the ingame shell 86 119 std::string language_; //!< The language 87 bool bInitializeRandomNumberGenerator_; //!< If true, srand(time(0)) is called 120 bool bInitializeRandomNumberGenerator_; //!< If true, srand(time(0)) is called 121 std::string mediaPathString_; //!< Path to the data/media file folder as string 88 122 89 123 static bool bShowsGraphics_s; //!< global variable that tells whether to show graphics … … 93 127 static bool bIsMaster_s; 94 128 129 static bool isDevBuild_s; //!< True for builds in the build directory (not installed) 130 95 131 static Core* singletonRef_s; 96 132 }; -
code/trunk/src/core/CorePrereqs.h
r2662 r2710 35 35 #define _CorePrereqs_H__ 36 36 37 #include " util/OrxonoxPlatform.h"37 #include "OrxonoxConfig.h" 38 38 39 39 #include <string> … … 42 42 // Shared library settings 43 43 //----------------------------------------------------------------------- 44 #if (ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32) && !defined( CORE_STATIC_BUILD )44 #if defined(ORXONOX_PLATFORM_WINDOWS) && !defined( CORE_STATIC_BUILD ) 45 45 # ifdef CORE_SHARED_BUILD 46 46 # define _CoreExport __declspec(dllexport) -
code/trunk/src/core/Factory.h
r2662 r2710 49 49 #include <map> 50 50 #include <string> 51 #include "util/Integers.h"52 51 53 52 namespace orxonox -
code/trunk/src/core/Functor.h
r2662 r2710 436 436 437 437 // disable annoying warning about forcing value to boolean 438 #if ORXONOX_COMPILER ==ORXONOX_COMPILER_MSVC438 #ifdef ORXONOX_COMPILER_MSVC 439 439 #pragma warning(push) 440 440 #pragma warning(disable:4100 4800) … … 475 475 } 476 476 477 #if ORXONOX_COMPILER ==ORXONOX_COMPILER_MSVC477 #ifdef ORXONOX_COMPILER_MSVC 478 478 #pragma warning(pop) 479 479 #endif -
code/trunk/src/core/IRC.h
r1505 r2710 32 32 #include "CorePrereqs.h" 33 33 34 #include <cpptcl/cpptcl.h> 34 35 #include "OrxonoxClass.h" 35 #include "cpptcl/CppTcl.h"36 36 37 37 namespace orxonox -
code/trunk/src/core/Identifier.h
r2662 r2710 61 61 #include <utility> 62 62 #include <typeinfo> 63 #include < stdlib.h>63 #include <cstdlib> 64 64 #include <cassert> 65 65 … … 68 68 #include "Super.h" 69 69 #include "Functor.h" 70 #include "util/Integers.h"71 70 #include "util/Debug.h" 72 71 #include "util/String.h" -
code/trunk/src/core/Language.cc
r2662 r2710 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 filepath(Core::getConfigPath() / getFilename(this->defaultLanguage_)); 209 207 210 // This creates the file if it's not existing 208 211 std::ofstream createFile; 209 createFile.open( getFilename(this->defaultLanguage_).c_str(), std::fstream::app);212 createFile.open(filepath.file_string().c_str(), std::fstream::app); 210 213 createFile.close(); 211 214 212 215 // Open the file 213 216 std::ifstream file; 214 file.open( getFilename(this->defaultLanguage_).c_str(), std::fstream::in);217 file.open(filepath.file_string().c_str(), std::fstream::in); 215 218 216 219 if (!file.is_open()) … … 254 257 COUT(4) << "Read translated language file (" << Core::getLanguage() << ")." << std::endl; 255 258 259 boost::filesystem::path filepath(Core::getConfigPath() / getFilename(Core::getLanguage())); 260 256 261 // Open the file 257 262 std::ifstream file; 258 file.open( getFilename(Core::getLanguage()).c_str(), std::fstream::in);263 file.open(filepath.file_string().c_str(), std::fstream::in); 259 264 260 265 if (!file.is_open()) … … 308 313 COUT(4) << "Language: Write default language file." << std::endl; 309 314 315 boost::filesystem::path filepath(Core::getConfigPath() / getFilename(this->defaultLanguage_)); 316 310 317 // Open the file 311 318 std::ofstream file; 312 file.open( getFilename(this->defaultLanguage_).c_str(), std::fstream::out);319 file.open(filepath.file_string().c_str(), std::fstream::out); 313 320 314 321 if (!file.is_open()) -
code/trunk/src/core/Loader.cc
r2662 r2710 28 28 29 29 #include "Loader.h" 30 31 #include <tinyxml/ticpp.h> 32 30 33 #include "XMLFile.h" 31 34 #include "BaseObject.h" … … 39 42 #include "util/Exception.h" 40 43 41 #include "tinyxml/ticpp.h"42 43 44 namespace orxonox 44 45 { -
code/trunk/src/core/LuaBind.cc
-
Property
svn:mergeinfo
set to
(toggle deleted branches)
/code/branches/buildsystem3/src/core/LuaBind.cc merged eligible /code/branches/lodfinal/src/core/LuaBind.cc merged eligible /code/branches/network/src/core/LuaBind.cc merged eligible /code/branches/objecthierarchy2/src/core/LuaBind.cc merged eligible /code/branches/pickups2/src/core/LuaBind.cc merged eligible /code/branches/presentation/src/core/LuaBind.cc merged eligible /code/branches/questsystem2/src/core/LuaBind.cc merged eligible /code/branches/weapon2/src/core/LuaBind.cc merged eligible /code/branches/buildsystem/src/core/LuaBind.cc 1874-2276,2278-2400 /code/branches/buildsystem/src/core/Script.cc 1874-2238 /code/branches/buildsystem2/src/core/LuaBind.cc 2506-2658 /code/branches/ceguilua/src/core/LuaBind.cc 1802-1808 /code/branches/core3/src/core/LuaBind.cc 1572-1739 /code/branches/gcc43/src/core/LuaBind.cc 1580 /code/branches/gui/src/core/LuaBind.cc 1635-1723 /code/branches/input/src/core/LuaBind.cc 1629-1636 /code/branches/network64/src/core/LuaBind.cc 2210-2355 /code/branches/objecthierarchy/src/core/LuaBind.cc 1911-2085,2100,2110-2169 /code/branches/overlay/src/core/LuaBind.cc 2117-2385 /code/branches/physics/src/core/LuaBind.cc 1912-2055,2107-2439 /code/branches/physics_merge/src/core/LuaBind.cc 2436-2457 /code/branches/pickups/src/core/LuaBind.cc 1926-2086,2127 /code/branches/questsystem/src/core/LuaBind.cc 1894-2088 /code/branches/script_trigger/src/core/LuaBind.cc 1295-1953,1955 /code/branches/weapon/src/core/LuaBind.cc 1925-2094
r2662 r2710 32 32 #include <map> 33 33 34 #include "lua/lua.hpp" 35 #include "tolua/tolua++.h" 36 #include "tolua/tolua_bind.h" 34 extern "C" { 35 #include <lua.h> 36 #include <lualib.h> 37 } 38 #include <tolua/tolua++.h> 39 #include <boost/filesystem.hpp> 40 37 41 #include "util/String.h" 38 #include "CoreIncludes.h" 42 #include "util/Debug.h" 43 #include "ToluaBindCore.h" 44 #include "Core.h" 39 45 40 46 namespace orxonox … … 46 52 assert(LuaBind::singletonRef_s == 0); 47 53 LuaBind::singletonRef_s = this; 54 55 this->includePath_ = Core::getMediaPathPOSIXString(); 48 56 49 57 luaState_ = lua_open(); … … 78 86 void LuaBind::loadFile(std::string filename, bool luaTags) 79 87 { 88 boost::filesystem::path filepath(filename); 89 80 90 output_ = ""; 81 91 std::ifstream file; 82 file.open(file name.c_str(), std::fstream::in);92 file.open(filepath.file_string().c_str(), std::fstream::in); 83 93 84 94 if (!file.is_open()) -
Property
svn:mergeinfo
set to
(toggle deleted branches)
-
code/trunk/src/core/LuaBind.h
-
Property
svn:mergeinfo
set to
(toggle deleted branches)
/code/branches/buildsystem3/src/core/LuaBind.h merged eligible /code/branches/lodfinal/src/core/LuaBind.h merged eligible /code/branches/network/src/core/LuaBind.h merged eligible /code/branches/objecthierarchy2/src/core/LuaBind.h merged eligible /code/branches/pickups2/src/core/LuaBind.h merged eligible /code/branches/presentation/src/core/LuaBind.h merged eligible /code/branches/questsystem2/src/core/LuaBind.h merged eligible /code/branches/weapon2/src/core/LuaBind.h merged eligible /code/branches/buildsystem/src/core/LuaBind.h 1874-2276,2278-2400 /code/branches/buildsystem/src/core/Script.h 1874-2233 /code/branches/buildsystem2/src/core/LuaBind.h 2506-2658 /code/branches/ceguilua/src/core/LuaBind.h 1802-1808 /code/branches/core3/src/core/LuaBind.h 1572-1739 /code/branches/gcc43/src/core/LuaBind.h 1580 /code/branches/gui/src/core/LuaBind.h 1635-1723 /code/branches/input/src/core/LuaBind.h 1629-1636 /code/branches/network64/src/core/LuaBind.h 2210-2355 /code/branches/objecthierarchy/src/core/LuaBind.h 1911-2085,2100,2110-2169 /code/branches/overlay/src/core/LuaBind.h 2117-2385 /code/branches/physics/src/core/LuaBind.h 1912-2055,2107-2439 /code/branches/physics_merge/src/core/LuaBind.h 2436-2457 /code/branches/pickups/src/core/LuaBind.h 1926-2086,2127 /code/branches/questsystem/src/core/LuaBind.h 1894-2088 /code/branches/script_trigger/src/core/LuaBind.h 1295-1953,1955 /code/branches/weapon/src/core/LuaBind.h 1925-2094
r2662 r2710 39 39 40 40 extern "C" { 41 #include <lua /lua.h>41 #include <lua.h> 42 42 } 43 43 … … 46 46 #include <string> 47 47 48 namespace orxonox // tolua_export 49 { // tolua_export 48 // tolua_begin 49 namespace orxonox 50 { 50 51 class _CoreExport LuaBind 51 52 { 52 /* 53 class LuaBind { // tolua_export 54 */ 53 54 // tolua_end 55 55 struct LoadS { 56 56 const char *s; -
Property
svn:mergeinfo
set to
(toggle deleted branches)
-
code/trunk/src/core/RootGameState.cc
r2662 r2710 135 135 { 136 136 // Don't catch errors when having a debugger in msvc 137 #if ORXONOX_COMPILER != ORXONOX_COMPILER_MSVC|| defined(NDEBUG)137 #if !defined(ORXONOX_COMPILER_MSVC) || defined(NDEBUG) 138 138 try 139 139 { … … 158 158 159 159 this->deactivate(); 160 #if ORXONOX_COMPILER != ORXONOX_COMPILER_MSVC|| defined(NDEBUG)160 #if !defined(ORXONOX_COMPILER_MSVC) || defined(NDEBUG) 161 161 } 162 162 // Note: These are all unhandled exceptions that should not have made its way here! -
code/trunk/src/core/TclBind.cc
r1792 r2710 62 62 void TclBind::setDataPath(const std::string& datapath) 63 63 { 64 this->tclLibPath_ = datapath + "/tcl" + TCL_VERSION + "/"; 64 // String has POSIX slashes 65 this->tclLibPath_ = datapath + "tcl" + TCL_VERSION + '/'; 65 66 this->bSetTclLibPath_ = true; 66 67 -
code/trunk/src/core/TclBind.h
r1792 r2710 32 32 #include "CorePrereqs.h" 33 33 34 #include "cpptcl/CppTcl.h"34 #include <cpptcl/cpptcl.h> 35 35 36 36 namespace orxonox -
code/trunk/src/core/TclThreadManager.h
r1792 r2710 40 40 #include <boost/thread/thread.hpp> 41 41 42 #include "cpptcl/CppTcl.h"42 #include <cpptcl/cpptcl.h> 43 43 #include "core/OrxonoxClass.h" 44 44 -
code/trunk/src/core/Template.cc
- Property svn:mergeinfo changed
/code/branches/buildsystem2/src/core/Template.cc (added) merged: 2567,2610 /code/branches/buildsystem3/src/core/Template.cc (added) merged: 2664
r2662 r2710 29 29 #include "Template.h" 30 30 31 #include <tinyxml/ticpp.h> 32 31 33 #include "core/CoreIncludes.h" 32 34 #include "core/XMLPort.h" 33 35 #include "util/Debug.h" 34 #include "tinyxml/ticpp.h"35 36 36 37 namespace orxonox - Property svn:mergeinfo changed
-
code/trunk/src/core/Template.h
- Property svn:mergeinfo changed
/code/branches/buildsystem2/src/core/Template.h (added) merged: 2567,2610 /code/branches/buildsystem3/src/core/Template.h (added) merged: 2664
r2662 r2710 34 34 #include "CorePrereqs.h" 35 35 36 #include <tinyxml/tinyxml.h> 36 37 #include "BaseObject.h" 37 #include "tinyxml/tinyxml.h"38 38 39 39 namespace orxonox - Property svn:mergeinfo changed
-
code/trunk/src/core/XMLFile.h
- Property svn:mergeinfo changed
/code/branches/buildsystem3/src/core/XMLFile.h (added) merged: 2664
- Property svn:mergeinfo changed
-
code/trunk/src/core/XMLIncludes.h
- Property svn:mergeinfo changed
/code/branches/buildsystem2/src/core/XMLIncludes.h (added) merged: 2509-2510 /code/branches/buildsystem3/src/core/XMLIncludes.h (added) merged: 2664
- Property svn:mergeinfo changed
-
code/trunk/src/core/XMLPort.h
r2662 r2710 44 44 45 45 #include <cassert> 46 #include <tinyxml/ticpp.h> 46 47 #include "util/Debug.h" 47 48 #include "util/Exception.h" 48 49 #include "util/MultiType.h" 49 #include "tinyxml/ticpp.h"50 50 #include "XMLIncludes.h" 51 51 #include "Executor.h" -
code/trunk/src/core/input/CMakeLists.txt
r2131 r2710 1 SET(SRC_FILES1 ADD_SOURCE_FILES(CORE_SRC_FILES 2 2 Button.cc 3 3 CalibratorCallback.cc … … 12 12 SimpleInputState.cc 13 13 ) 14 15 ADD_SOURCE_FILES(SRC_FILES) -
code/trunk/src/core/input/KeyBinder.cc
r2662 r2710 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" … … 246 248 True if loading succeeded. 247 249 */ 248 void KeyBinder::loadBindings(const std::string& filename , const std::string& defaultFilename)250 void KeyBinder::loadBindings(const std::string& filename) 249 251 { 250 252 COUT(3) << "KeyBinder: Loading key bindings..." << std::endl; … … 253 255 return; 254 256 255 // get bindings from default file if filename doesn't exist.256 std::ifstream infile;257 infile.open(filename.c_str());258 if (!infile)259 {260 ConfigFileManager::getInstance().setFilename(this->configFile_, defaultFilename);261 ConfigFileManager::getInstance().saveAs(this->configFile_, filename);262 }263 else264 infile.close();265 257 ConfigFileManager::getInstance().setFilename(this->configFile_, filename); 266 258 -
code/trunk/src/core/input/KeyBinder.h
r2662 r2710 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);
Note: See TracChangeset
for help on using the changeset viewer.