Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 6, 2009, 1:59:00 AM (15 years ago)
Author:
landauf
Message:

Merged gui branch back to trunk.

I did 2 small changes in IngameManager.cc on line 777 and 888 (yes, really), because const_reverse_iterator strangely doesn't work on MinGW.

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

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

    r2759 r2896  
    2222 *   Author:
    2323 *      Fabian 'x3n' Landau
     24 *      Reto Grieder
    2425 *   Co-authors:
    25  *      Reto Grieder
     26 *      ...
    2627 *
    2728 */
     
    4142
    4243#ifdef ORXONOX_PLATFORM_WINDOWS
     44#  ifndef WIN32_LEAN_AND_MEAN
     45#    define WIN32_LEAN_AND_MEAN
     46#  endif
    4347#  include <windows.h>
    4448#elif defined(ORXONOX_PLATFORM_APPLE)
     
    5155
    5256#include "SpecialConfig.h"
     57#include "util/Debug.h"
    5358#include "util/Exception.h"
     59#include "util/SignalHandler.h"
     60#include "Clock.h"
     61#include "CommandExecutor.h"
     62#include "CommandLine.h"
     63#include "ConfigFileManager.h"
     64#include "ConfigValueIncludes.h"
     65#include "CoreIncludes.h"
     66#include "Factory.h"
     67#include "Identifier.h"
    5468#include "Language.h"
    55 #include "CoreIncludes.h"
    56 #include "ConfigValueIncludes.h"
    5769#include "LuaBind.h"
    58 #include "CommandLine.h"
     70#include "Shell.h"
     71#include "TclBind.h"
     72#include "TclThreadManager.h"
    5973
    6074namespace orxonox
     
    6781    static boost::filesystem::path logPath_g;                   //!< Path to the log file folder
    6882
    69     bool Core::bShowsGraphics_s = false;
    70     bool Core::bHasServer_s     = false;
    71     bool Core::bIsClient_s      = false;
    72     bool Core::bIsStandalone_s  = false;
    73     bool Core::bIsMaster_s      = false;
    74 
    75     bool Core::isDevBuild_s     = false;
    7683    Core* Core::singletonRef_s  = 0;
    7784
    7885    SetCommandLineArgument(mediaPath, "").information("PATH");
    79     SetCommandLineArgument(directory, "").information("DIR");
    80 
    81     /**
    82         @brief Constructor: Registers the object and sets the config-values.
    83         @param A reference to a global variable, used to avoid an infinite recursion in getSoftDebugLevel()
    84     */
     86    SetCommandLineArgument(writingPathSuffix, "").information("DIR");
     87    SetCommandLineArgument(settingsFile, "orxonox.ini");
     88    SetCommandLineArgument(limitToCPU, 0).information("0: off | #cpu");
     89
    8590    Core::Core()
    8691    {
     
    8994        assert(Core::singletonRef_s == 0);
    9095        Core::singletonRef_s = this;
    91 
    92         this->bInitializeRandomNumberGenerator_ = false;
    93         this->setConfigValues();
     96    }
     97
     98    void Core::initialise(int argc, char** argv)
     99    {
     100        // Parse command line arguments fist
     101        try
     102        {
     103            CommandLine::parseAll(argc, argv);
     104        }
     105        catch (ArgumentException& ex)
     106        {
     107            COUT(1) << ex.what() << std::endl;
     108            COUT(0) << "Usage:" << std::endl << "orxonox " << CommandLine::getUsageInformation() << std::endl;
     109        }
     110
     111        // limit the main thread to the first core so that QueryPerformanceCounter doesn't jump
     112        // do this after ogre has initialised. Somehow Ogre changes the settings again (not through
     113        // the timer though).
     114        int limitToCPU = CommandLine::getValue("limitToCPU");
     115        if (limitToCPU > 0)
     116            setThreadAffinity((unsigned int)limitToCPU);
     117
     118        // Determine and set the location of the executable
     119        setExecutablePath();
     120
     121        // Determine whether we have an installed or a binary dir run
     122        // The latter occurs when simply running from the build directory
     123        checkDevBuild();
     124
     125        // Make sure the directories we write in exist or else make them
     126        createDirectories();
     127
     128        // create a signal handler (only active for linux)
     129        // This call is placed as soon as possible, but after the directories are set
     130        this->signalHandler_ = new SignalHandler();
     131        this->signalHandler_->doCatch(executablePath_g.string(), Core::getLogPathString() + "orxonox_crash.log");
    94132
    95133        // Set the correct log path. Before this call, /tmp (Unix) or %TEMP% was used
    96134        OutputHandler::getOutStream().setLogPath(Core::getLogPathString());
    97135
     136        // Manage ini files and set the default settings file (usually orxonox.ini)
     137        this->configFileManager_ = new ConfigFileManager();
     138        this->configFileManager_->setFilename(ConfigFileType::Settings,
     139            CommandLine::getValue("settingsFile").getString());
     140
     141        this->languageInstance_ = new Language();
     142
     143        // Do this soon after the ConfigFileManager has been created to open up the
     144        // possibility to configure everything below here
     145        this->setConfigValues();
     146
    98147        // Possible media path override by the command line
    99148        if (!CommandLine::getArgument("mediaPath")->hasDefaultValue())
     
    102151            Core::tsetMediaPath(CommandLine::getValue("mediaPath"));
    103152        }
     153
     154        // Create the lua interface
     155        this->luaBind_ = new LuaBind();
     156
     157        // initialise Tcl
     158        this->tclBind_ = new TclBind(Core::getMediaPathString());
     159        this->tclThreadManager_ = new TclThreadManager(tclBind_->getTclInterpreter());
     160
     161        // create a shell
     162        this->shell_ = new Shell();
     163
     164        // creates the class hierarchy for all classes with factories
     165        Factory::createClassHierarchy();
     166       
     167        this->loaded_ = true;
    104168    }
    105169
     
    109173    Core::~Core()
    110174    {
     175        this->loaded_ = false;
     176
     177        delete this->shell_;
     178        delete this->tclThreadManager_;
     179        delete this->tclBind_;
     180        delete this->luaBind_;
     181        delete this->languageInstance_;
     182        delete this->configFileManager_;
     183        delete this->signalHandler_;
     184
     185        // Destroy command line arguments
     186        CommandLine::destroyAllArguments();
     187        // Also delete external console command that don't belong to an Identifier
     188        CommandExecutor::destroyExternalCommands();
     189
    111190        assert(Core::singletonRef_s);
    112191        Core::singletonRef_s = 0;
     
    292371    }
    293372
    294     /**
    295     @brief
    296         Performs the rather lower level operations just after
    297         int main() has been called.
    298     @remarks
    299         This gets called AFTER pre-main stuff like AddFactory,
    300         SetConsoleCommand, etc.
    301     */
    302     /*static*/ void Core::postMainInitialisation()
    303     {
    304         // set location of the executable
    305         Core::setExecutablePath();
    306 
    307         // Determine whether we have an installed or a binary dir run
    308         // The latter occurs when simply running from the build directory
    309         Core::checkDevBuild();
    310 
    311         // Make sure the directories we write in exist or else make them
    312         Core::createDirectories();
     373
     374    /**
     375    @note
     376        The code of this function has been copied and adjusted from OGRE, an open source graphics engine.
     377            (Object-oriented Graphics Rendering Engine)
     378        For the latest info, see http://www.ogre3d.org/
     379
     380        Copyright (c) 2000-2008 Torus Knot Software Ltd
     381
     382        OGRE is licensed under the LGPL. For more info, see OGRE license.
     383    */
     384    void Core::setThreadAffinity(int limitToCPU)
     385    {
     386        if (limitToCPU <= 0)
     387            return;
     388
     389#ifdef ORXONOX_PLATFORM_WINDOWS
     390        unsigned int coreNr = limitToCPU - 1;
     391        // Get the current process core mask
     392        DWORD procMask;
     393        DWORD sysMask;
     394#  if _MSC_VER >= 1400 && defined (_M_X64)
     395        GetProcessAffinityMask(GetCurrentProcess(), (PDWORD_PTR)&procMask, (PDWORD_PTR)&sysMask);
     396#  else
     397        GetProcessAffinityMask(GetCurrentProcess(), &procMask, &sysMask);
     398#  endif
     399
     400        // If procMask is 0, consider there is only one core available
     401        // (using 0 as procMask will cause an infinite loop below)
     402        if (procMask == 0)
     403            procMask = 1;
     404
     405        // if the core specified with coreNr is not available, take the lowest one
     406        if (!(procMask & (1 << coreNr)))
     407            coreNr = 0;
     408
     409        // Find the lowest core that this process uses and coreNr suggests
     410        DWORD threadMask = 1;
     411        while ((threadMask & procMask) == 0 || (threadMask < (1u << coreNr)))
     412            threadMask <<= 1;
     413
     414        // Set affinity to the first core
     415        SetThreadAffinityMask(GetCurrentThread(), threadMask);
     416#endif
    313417    }
    314418
     
    317421        Compares the executable path with the working directory
    318422    */
    319     /*static*/ void Core::setExecutablePath()
     423    void Core::setExecutablePath()
    320424    {
    321425#ifdef ORXONOX_PLATFORM_WINDOWS
     
    369473        don't write the logs and config files to ~/.orxonox
    370474    */
    371     /*static*/ void Core::checkDevBuild()
     475    void Core::checkDevBuild()
    372476    {
    373477        if (boost::filesystem::exists(executablePath_g / "orxonox_dev_build.keep_me"))
    374478        {
    375479            COUT(1) << "Running from the build tree." << std::endl;
    376             Core::isDevBuild_s = true;
     480            Core::isDevBuild_ = true;
    377481            mediaPath_g  = ORXONOX_MEDIA_DEV_PATH;
    378482            configPath_g = ORXONOX_CONFIG_DEV_PATH;
     
    385489            boost::filesystem::path relativeExecutablePath(ORXONOX_RUNTIME_INSTALL_PATH);
    386490            rootPath_g = executablePath_g;
    387             while (!boost::filesystem::equivalent(rootPath_g / relativeExecutablePath, executablePath_g) || rootPath_g.empty())
     491            while (!boost::filesystem::equivalent(rootPath_g / relativeExecutablePath, executablePath_g) && !rootPath_g.empty())
    388492                rootPath_g = rootPath_g.branch_path();
    389493            if (rootPath_g.empty())
     
    416520
    417521        // Option to put all the config and log files in a separate folder
    418         if (!CommandLine::getArgument("directory")->hasDefaultValue())
    419         {
    420             std::string directory(CommandLine::getValue("directory").getString());
     522        if (!CommandLine::getArgument("writingPathSuffix")->hasDefaultValue())
     523        {
     524            std::string directory(CommandLine::getValue("writingPathSuffix").getString());
    421525            configPath_g = configPath_g / directory;
    422526            logPath_g    = logPath_g    / directory;
     
    429533        if necessary. Otherwise me might have problems opening those files.
    430534    */
    431     /*static*/ void Core::createDirectories()
     535    void Core::createDirectories()
    432536    {
    433537        std::vector<std::pair<boost::filesystem::path, std::string> > directories;
     
    451555        }
    452556    }
     557
     558    void Core::update(const Clock& time)
     559    {
     560        this->tclThreadManager_->update(time);
     561    }
    453562}
Note: See TracChangeset for help on using the changeset viewer.