Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2710 for code/trunk/src/core


Ignore:
Timestamp:
Feb 28, 2009, 7:46:37 PM (16 years ago)
Author:
rgrieder
Message:

Merged buildsystem3 containing buildsystem2 containing Adi's buildsystem branch back to the trunk.
Please update the media directory if you were not using buildsystem3 before.

Location:
code/trunk
Files:
1 deleted
30 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/core/ArgumentCompletionFunctions.cc

    r2087 r2710  
    2727 */
    2828
     29#include "ArgumentCompletionFunctions.h"
     30
    2931#include <iostream>
    3032#include <map>
    31 
    3233#include <boost/filesystem.hpp>
    3334
    34 #include "ArgumentCompletionFunctions.h"
    3535#include "CoreIncludes.h"
    3636#include "Identifier.h"
     
    6363                    startdirectory = ".";
    6464                }
    65 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32
     65#ifdef ORXONOX_PLATFORM_WINDOWS
    6666                else
    6767                {
    6868                    std::string dir = startdirectory.string();
    6969                    if (dir.size() > 0 && dir[dir.size() - 1] == ':')
    70                         startdirectory = dir + "/";
     70                        startdirectory = dir + CP_SLASH;
    7171                }
    7272#endif
     
    7878                {
    7979                    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() + "/"));
    8181                    else
    8282                        filelist.push_back(ArgumentCompletionListElement((*file).string(), getLowercase((*file).string()), (*file).leaf()));
  • code/trunk/src/core/BaseObject.cc

    r2662 r2710  
    3333
    3434#include "BaseObject.h"
    35 #include "tinyxml/tinyxml.h"
     35
     36#include <tinyxml/tinyxml.h>
     37
    3638#include "CoreIncludes.h"
    3739#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
     20SET_SOURCE_FILES(CORE_SRC_FILES
    221  Clock.cc
    322  ConfigFileManager.cc
     
    4160  TclBind.cc
    4261  TclThreadManager.cc
     62)
     63ADD_SUBDIRECTORY(input)
     64GET_ALL_HEADER_FILES(CORE_HDR_FILES)
     65SET(CORE_FILES ${CORE_SRC_FILES} ${CORE_HDR_FILES})
    4366
    44   tolua/tolua_bind.cc
     67GENERATE_SOURCE_GROUPS(${CORE_FILES})
     68GENERATE_TOLUA_BINDINGS(Core CORE_FILES INPUTFILES LuaBind.h CommandExecutor.h)
     69
     70ADD_LIBRARY(core SHARED ${CORE_FILES})
     71
     72SET_TARGET_PROPERTIES(core PROPERTIES DEFINE_SYMBOL "CORE_SHARED_BUILD")
     73TARGET_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
    4585)
    4686
    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 )
     87ORXONOX_INSTALL(core)
  • code/trunk/src/core/CommandExecutor.h

    r2662 r2710  
    3636#include "CommandEvaluation.h"
    3737
    38 namespace orxonox // tolua_export
    39 { // tolua_export
     38// tolua_begin
     39namespace orxonox
     40{
    4041    class _CoreExport CommandExecutor
    41     /*
    42     class CommandExecutor { // tolua_export
    43     */
    4442    {
     43// tolua_end
    4544        public:
    4645            static bool execute(const std::string& command, bool useTcl = true); // tolua_export
  • code/trunk/src/core/CommandLine.cc

    r2662 r2710  
    2929#include "CommandLine.h"
    3030
     31#include <boost/filesystem.hpp>
    3132#include "util/String.h"
    3233#include "util/SubString.h"
     34#include "Core.h"
    3335
    3436namespace orxonox
     
    299301        this->_parse(args);
    300302
     303        std::string filename = CommandLine::getValue("optionsFile").getString();
     304        boost::filesystem::path filepath(Core::getConfigPath() / filename);
     305
    301306        // look for additional arguments in given file or start.ini as default
    302307        // They will not overwrite the arguments given directly
    303308        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());
    306310        args.clear();
    307311        if (file)
  • code/trunk/src/core/ConfigFileManager.cc

    r2662 r2710  
    3030
    3131#include <cassert>
     32#include <boost/filesystem.hpp>
     33
    3234#include "util/Convert.h"
    3335#include "util/String.h"
    3436#include "ConsoleCommand.h"
    3537#include "ConfigValueContainer.h"
     38#include "Core.h"
    3639
    3740namespace orxonox
     
    220223    void ConfigFile::load(bool bCreateIfNotExisting)
    221224    {
    222         // Be sure we start from new
     225        // Be sure we start from new in the memory
    223226        this->clear();
    224227
    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        }
    229239
    230240        // Open the file
    231241        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))
    259258                {
    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)
    284264                    {
    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);
    298269                        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);
    320272                        continue;
    321273                    }
    322274                }
    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()
    335341    }
    336342
    337343    void ConfigFile::save() const
    338344    {
     345        boost::filesystem::path filepath(Core::getConfigPath() / this->filename_);
     346
    339347        std::ofstream file;
    340         file.open(this->filename_.c_str(), std::fstream::out);
     348        file.open(filepath.file_string().c_str(), std::fstream::out);
    341349        file.setf(std::ios::fixed, std::ios::floatfield);
    342350        file.precision(6);
  • code/trunk/src/core/Core.cc

    r2662 r2710  
    3333
    3434#include "Core.h"
     35
    3536#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"
    3654#include "Language.h"
    3755#include "CoreIncludes.h"
    3856#include "ConfigValueIncludes.h"
     57#include "LuaBind.h"
     58#include "CommandLine.h"
    3959
    4060namespace orxonox
    4161{
     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
    4269    bool Core::bShowsGraphics_s = false;
    4370    bool Core::bHasServer_s     = false;
     
    4673    bool Core::bIsMaster_s      = false;
    4774
    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");
    4980
    5081    /**
     
    5889        assert(Core::singletonRef_s == 0);
    5990        Core::singletonRef_s = this;
     91
    6092        this->bInitializeRandomNumberGenerator_ = false;
    61 
    6293        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        }
    63104    }
    64105
     
    77118    void Core::setConfigValues()
    78119    {
    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
    82136        SetConfigValue(language_, Language::getLanguage().defaultLanguage_).description("The language of the ingame text").callback(this, &Core::languageChanged);
    83137        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);
    84141    }
    85142
     
    109166        // Read the translation file after the language was configured
    110167        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_);
    111177    }
    112178
     
    177243    }
    178244
     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
    179296    void Core::initializeRandomNumberGenerator()
    180297    {
     
    187304        }
    188305    }
     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    }
    189466}
  • code/trunk/src/core/Core.h

    r2662 r2710  
    4444#include "util/OutputHandler.h"
    4545
     46// Only allow main to access postMainInitialisation, so we need a forward declaration
     47int main(int, char**);
     48// boost::filesystem header has quite a large tail, use forward declaration
     49namespace 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
    4656namespace orxonox
    4757{
     
    4959    class _CoreExport Core : public OrxonoxClass
    5060    {
     61        friend int ::main(int, char**); // sets isDevBuild_s
     62
    5163        public:
    5264            Core();
    5365            ~Core();
    5466            void setConfigValues();
    55             void debugLevelChanged();
    56             void languageChanged();
    5767
    5868            static Core& getInstance() { assert(Core::singletonRef_s); return *Core::singletonRef_s; }
     
    6272            static const std::string& getLanguage();
    6373            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();
    6488
    6589            // fast access global variables.
     
    79103            void resetLanguageIntern();
    80104            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();
    81114
    82115            int softDebugLevel_;                            //!< The debug level
     
    85118            int softDebugLevelShell_;                       //!< The debug level for the ingame shell
    86119            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
    88122
    89123            static bool bShowsGraphics_s;                   //!< global variable that tells whether to show graphics
     
    93127            static bool bIsMaster_s;
    94128
     129            static bool isDevBuild_s;                       //!< True for builds in the build directory (not installed)
     130
    95131            static Core* singletonRef_s;
    96132    };
  • code/trunk/src/core/CorePrereqs.h

    r2662 r2710  
    3535#define _CorePrereqs_H__
    3636
    37 #include "util/OrxonoxPlatform.h"
     37#include "OrxonoxConfig.h"
    3838
    3939#include <string>
     
    4242// Shared library settings
    4343//-----------------------------------------------------------------------
    44 #if (ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32) && !defined( CORE_STATIC_BUILD )
     44#if defined(ORXONOX_PLATFORM_WINDOWS) && !defined( CORE_STATIC_BUILD )
    4545#  ifdef CORE_SHARED_BUILD
    4646#    define _CoreExport __declspec(dllexport)
  • code/trunk/src/core/Factory.h

    r2662 r2710  
    4949#include <map>
    5050#include <string>
    51 #include "util/Integers.h"
    5251
    5352namespace orxonox
  • code/trunk/src/core/Functor.h

    r2662 r2710  
    436436
    437437// disable annoying warning about forcing value to boolean
    438 #if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC
     438#ifdef ORXONOX_COMPILER_MSVC
    439439#pragma warning(push)
    440440#pragma warning(disable:4100 4800)
     
    475475}
    476476
    477 #if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC
     477#ifdef ORXONOX_COMPILER_MSVC
    478478#pragma warning(pop)
    479479#endif
  • code/trunk/src/core/IRC.h

    r1505 r2710  
    3232#include "CorePrereqs.h"
    3333
     34#include <cpptcl/cpptcl.h>
    3435#include "OrxonoxClass.h"
    35 #include "cpptcl/CppTcl.h"
    3636
    3737namespace orxonox
  • code/trunk/src/core/Identifier.h

    r2662 r2710  
    6161#include <utility>
    6262#include <typeinfo>
    63 #include <stdlib.h>
     63#include <cstdlib>
    6464#include <cassert>
    6565
     
    6868#include "Super.h"
    6969#include "Functor.h"
    70 #include "util/Integers.h"
    7170#include "util/Debug.h"
    7271#include "util/String.h"
  • code/trunk/src/core/Language.cc

    r2662 r2710  
    3535
    3636#include <fstream>
     37#include <boost/filesystem.hpp>
    3738
    3839#include "Core.h"
     
    205206        COUT(4) << "Read default language file." << std::endl;
    206207
     208        boost::filesystem::path filepath(Core::getConfigPath() / getFilename(this->defaultLanguage_));
     209
    207210        // This creates the file if it's not existing
    208211        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);
    210213        createFile.close();
    211214
    212215        // Open the file
    213216        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);
    215218
    216219        if (!file.is_open())
     
    254257        COUT(4) << "Read translated language file (" << Core::getLanguage() << ")." << std::endl;
    255258
     259        boost::filesystem::path filepath(Core::getConfigPath() / getFilename(Core::getLanguage()));
     260
    256261        // Open the file
    257262        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);
    259264
    260265        if (!file.is_open())
     
    308313        COUT(4) << "Language: Write default language file." << std::endl;
    309314
     315        boost::filesystem::path filepath(Core::getConfigPath() / getFilename(this->defaultLanguage_));
     316
    310317        // Open the file
    311318        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);
    313320
    314321        if (!file.is_open())
  • code/trunk/src/core/Loader.cc

    r2662 r2710  
    2828
    2929#include "Loader.h"
     30
     31#include <tinyxml/ticpp.h>
     32
    3033#include "XMLFile.h"
    3134#include "BaseObject.h"
     
    3942#include "util/Exception.h"
    4043
    41 #include "tinyxml/ticpp.h"
    42 
    4344namespace orxonox
    4445{
  • code/trunk/src/core/LuaBind.cc

    r2662 r2710  
    3232#include <map>
    3333
    34 #include "lua/lua.hpp"
    35 #include "tolua/tolua++.h"
    36 #include "tolua/tolua_bind.h"
     34extern "C" {
     35#include <lua.h>
     36#include <lualib.h>
     37}
     38#include <tolua/tolua++.h>
     39#include <boost/filesystem.hpp>
     40
    3741#include "util/String.h"
    38 #include "CoreIncludes.h"
     42#include "util/Debug.h"
     43#include "ToluaBindCore.h"
     44#include "Core.h"
    3945
    4046namespace orxonox
     
    4652    assert(LuaBind::singletonRef_s == 0);
    4753    LuaBind::singletonRef_s = this;
     54
     55    this->includePath_ = Core::getMediaPathPOSIXString();
    4856
    4957    luaState_ = lua_open();
     
    7886  void LuaBind::loadFile(std::string filename, bool luaTags)
    7987  {
     88    boost::filesystem::path filepath(filename);
     89
    8090    output_ = "";
    8191    std::ifstream file;
    82     file.open(filename.c_str(), std::fstream::in);
     92    file.open(filepath.file_string().c_str(), std::fstream::in);
    8393
    8494    if (!file.is_open())
  • code/trunk/src/core/LuaBind.h

    r2662 r2710  
    3939
    4040extern "C" {
    41 #include <lua/lua.h>
     41#include <lua.h>
    4242}
    4343
     
    4646#include <string>
    4747
    48 namespace orxonox // tolua_export
    49 { // tolua_export
     48// tolua_begin
     49namespace orxonox
     50{
    5051  class _CoreExport LuaBind
    5152  {
    52   /*
    53   class LuaBind { // tolua_export
    54   */
     53
     54// tolua_end
    5555    struct LoadS {
    5656      const char *s;
  • code/trunk/src/core/RootGameState.cc

    r2662 r2710  
    135135    {
    136136        // 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)
    138138        try
    139139        {
     
    158158
    159159            this->deactivate();
    160 #if ORXONOX_COMPILER != ORXONOX_COMPILER_MSVC || defined(NDEBUG)
     160#if !defined(ORXONOX_COMPILER_MSVC) || defined(NDEBUG)
    161161        }
    162162        // Note: These are all unhandled exceptions that should not have made its way here!
  • code/trunk/src/core/TclBind.cc

    r1792 r2710  
    6262    void TclBind::setDataPath(const std::string& datapath)
    6363    {
    64         this->tclLibPath_ = datapath + "/tcl" + TCL_VERSION + "/";
     64        // String has POSIX slashes
     65        this->tclLibPath_ = datapath + "tcl" + TCL_VERSION + '/';
    6566        this->bSetTclLibPath_ = true;
    6667
  • code/trunk/src/core/TclBind.h

    r1792 r2710  
    3232#include "CorePrereqs.h"
    3333
    34 #include "cpptcl/CppTcl.h"
     34#include <cpptcl/cpptcl.h>
    3535
    3636namespace orxonox
  • code/trunk/src/core/TclThreadManager.h

    r1792 r2710  
    4040#include <boost/thread/thread.hpp>
    4141
    42 #include "cpptcl/CppTcl.h"
     42#include <cpptcl/cpptcl.h>
    4343#include "core/OrxonoxClass.h"
    4444
  • code/trunk/src/core/Template.cc

    r2662 r2710  
    2929#include "Template.h"
    3030
     31#include <tinyxml/ticpp.h>
     32
    3133#include "core/CoreIncludes.h"
    3234#include "core/XMLPort.h"
    3335#include "util/Debug.h"
    34 #include "tinyxml/ticpp.h"
    3536
    3637namespace orxonox
  • code/trunk/src/core/Template.h

    r2662 r2710  
    3434#include "CorePrereqs.h"
    3535
     36#include <tinyxml/tinyxml.h>
    3637#include "BaseObject.h"
    37 #include "tinyxml/tinyxml.h"
    3838
    3939namespace orxonox
  • code/trunk/src/core/XMLFile.h

  • code/trunk/src/core/XMLIncludes.h

  • code/trunk/src/core/XMLPort.h

    r2662 r2710  
    4444
    4545#include <cassert>
     46#include <tinyxml/ticpp.h>
    4647#include "util/Debug.h"
    4748#include "util/Exception.h"
    4849#include "util/MultiType.h"
    49 #include "tinyxml/ticpp.h"
    5050#include "XMLIncludes.h"
    5151#include "Executor.h"
  • code/trunk/src/core/input/CMakeLists.txt

    r2131 r2710  
    1 SET( SRC_FILES
     1ADD_SOURCE_FILES(CORE_SRC_FILES
    22  Button.cc
    33  CalibratorCallback.cc
     
    1212  SimpleInputState.cc
    1313)
    14 
    15 ADD_SOURCE_FILES(SRC_FILES)
  • code/trunk/src/core/input/KeyBinder.cc

    r2662 r2710  
    3636#include <fstream>
    3737#include <string>
     38#include <boost/filesystem.hpp>
    3839
    3940#include "util/Convert.h"
     
    4243#include "core/CoreIncludes.h"
    4344#include "core/ConfigFileManager.h"
     45#include "core/Core.h"
    4446#include "InputCommands.h"
    4547#include "InputManager.h"
     
    246248        True if loading succeeded.
    247249    */
    248     void KeyBinder::loadBindings(const std::string& filename, const std::string& defaultFilename)
     250    void KeyBinder::loadBindings(const std::string& filename)
    249251    {
    250252        COUT(3) << "KeyBinder: Loading key bindings..." << std::endl;
     
    253255            return;
    254256
    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         else
    264             infile.close();
    265257        ConfigFileManager::getInstance().setFilename(this->configFile_, filename);
    266258
  • code/trunk/src/core/input/KeyBinder.h

    r2662 r2710  
    6161        virtual ~KeyBinder();
    6262
    63         void loadBindings(const std::string& filename, const std::string& defaultFilename);
     63        void loadBindings(const std::string& filename);
    6464        void clearBindings();
    6565        bool setBinding(const std::string& binding, const std::string& name, bool bTemporary = false);
Note: See TracChangeset for help on using the changeset viewer.