Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 30, 2009, 2:10:44 PM (15 years ago)
Author:
rgrieder
Message:

Merged resource branch back to the trunk. Changes:

  • Automated graphics loading by evaluating whether a GameState requires it
  • Using native Tcl library (x3n)

Windows users: Update your dependency package!

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

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

    r3323 r3370  
    4141#include <cstdio>
    4242#include <boost/filesystem.hpp>
     43#include <OgreRenderWindow.h>
    4344
    4445#ifdef ORXONOX_PLATFORM_WINDOWS
     
    6869#include "CoreIncludes.h"
    6970#include "Factory.h"
     71#include "GameMode.h"
     72#include "GraphicsManager.h"
     73#include "GUIManager.h"
    7074#include "Identifier.h"
    7175#include "Language.h"
     
    7478#include "TclBind.h"
    7579#include "TclThreadManager.h"
     80#include "input/InputManager.h"
    7681
    7782namespace orxonox
    7883{
    7984    //! Static pointer to the singleton
    80     Core* Core::singletonRef_s  = 0;
     85    Core* Core::singletonPtr_s  = 0;
    8186
    8287    SetCommandLineArgument(mediaPath, "").information("Path to the media/data files");
     
    134139                .callback(this, &CoreConfiguration::debugLevelChanged);
    135140
    136             SetConfigValue(language_, Language::getLanguage().defaultLanguage_)
     141            SetConfigValue(language_, Language::getInstance().defaultLanguage_)
    137142                .description("The language of the ingame text")
    138143                .callback(this, &CoreConfiguration::languageChanged);
     
    141146                .callback(this, &CoreConfiguration::initializeRandomNumberGenerator);
    142147
    143             SetConfigValue(mediaPathString_, mediaPath_.string())
    144                 .description("Relative path to the game data.")
    145                 .callback(this, &CoreConfiguration::mediaPathChanged);
     148            // Only show this config value for development builds
     149            if (Core::isDevelopmentRun())
     150            {
     151                SetConfigValue(mediaPathString_, mediaPath_.string())
     152                    .description("Relative path to the game data.")
     153                    .callback(this, &CoreConfiguration::mediaPathChanged);
     154            }
    146155        }
    147156
     
    170179        {
    171180            // Read the translation file after the language was configured
    172             Language::getLanguage().readTranslatedLanguageFile();
     181            Language::getInstance().readTranslatedLanguageFile();
    173182        }
    174183
     
    198207        void tsetMediaPath(const std::string& path)
    199208        {
    200             ModifyConfigValue(mediaPathString_, tset, path);
     209            if (Core::isDevelopmentRun())
     210            {
     211                ModifyConfigValue(mediaPathString_, tset, path);
     212            }
     213            else
     214            {
     215                // Manual 'config' value without the file entry
     216                mediaPathString_ = path;
     217                this->mediaPathChanged();
     218            }
    201219        }
    202220
     
    230248
    231249    Core::Core(const std::string& cmdLine)
    232     {
    233         if (singletonRef_s != 0)
    234         {
    235             COUT(0) << "Error: The Core singleton cannot be recreated! Shutting down." << std::endl;
    236             abort();
    237         }
    238         Core::singletonRef_s = this;
    239 
    240         // We need the variables very soon. But don't configure them yet!
    241         this->configuration_ = new CoreConfiguration();
    242 
     250        // Cleanup guard for identifier destruction (incl. XMLPort, configValues, consoleCommands)
     251        : identifierDestroyer_(Identifier::destroyAllIdentifiers)
     252        // Cleanup guard for external console commands that don't belong to an Identifier
     253        , consoleCommandDestroyer_(CommandExecutor::destroyExternalCommands)
     254        , configuration_(new CoreConfiguration()) // Don't yet create config values!
     255        , bDevRun_(false)
     256        , bGraphicsLoaded_(false)
     257    {
    243258        // Parse command line arguments first
    244259        CommandLine::parseCommandLine(cmdLine);
     
    256271        // create a signal handler (only active for linux)
    257272        // This call is placed as soon as possible, but after the directories are set
    258         this->signalHandler_ = new SignalHandler();
     273        this->signalHandler_.reset(new SignalHandler());
    259274        this->signalHandler_->doCatch(configuration_->executablePath_.string(), Core::getLogPathString() + "orxonox_crash.log");
    260275
     
    275290
    276291        // Manage ini files and set the default settings file (usually orxonox.ini)
    277         this->configFileManager_ = new ConfigFileManager();
     292        this->configFileManager_.reset(new ConfigFileManager());
    278293        this->configFileManager_->setFilename(ConfigFileType::Settings,
    279294            CommandLine::getValue("settingsFile").getString());
    280295
    281296        // Required as well for the config values
    282         this->languageInstance_ = new Language();
     297        this->languageInstance_.reset(new Language());
    283298
    284299        // Do this soon after the ConfigFileManager has been created to open up the
     
    287302
    288303        // Create the lua interface
    289         this->luaBind_ = new LuaBind();
     304        this->luaBind_.reset(new LuaBind());
    290305
    291306        // initialise Tcl
    292         this->tclBind_ = new TclBind(Core::getMediaPathString());
    293         this->tclThreadManager_ = new TclThreadManager(tclBind_->getTclInterpreter());
     307        this->tclBind_.reset(new TclBind(Core::getMediaPathString()));
     308        this->tclThreadManager_.reset(new TclThreadManager(tclBind_->getTclInterpreter()));
    294309
    295310        // create a shell
    296         this->shell_ = new Shell();
     311        this->shell_.reset(new Shell());
    297312
    298313        // creates the class hierarchy for all classes with factories
     
    301316
    302317    /**
    303         @brief Sets the bool to true to avoid static functions accessing a deleted object.
     318    @brief
     319        All destruction code is handled by scoped_ptrs and SimpleScopeGuards.
    304320    */
    305321    Core::~Core()
    306322    {
    307         delete this->shell_;
    308         delete this->tclThreadManager_;
    309         delete this->tclBind_;
    310         delete this->luaBind_;
    311         delete this->configuration_;
    312         delete this->languageInstance_;
    313         delete this->configFileManager_;
    314 
    315         // Destroy command line arguments
    316         CommandLine::destroyAllArguments();
    317         // Also delete external console command that don't belong to an Identifier
    318         CommandExecutor::destroyExternalCommands();
    319         // Clean up class hierarchy stuff (identifiers, XMLPort, configValues, consoleCommand)
    320         Identifier::destroyAllIdentifiers();
    321 
    322         delete this->signalHandler_;
    323 
    324         // Don't assign singletonRef_s with NULL! Recreation is not supported
     323    }
     324
     325    void Core::loadGraphics()
     326    {
     327        if (bGraphicsLoaded_)
     328            return;
     329
     330        // Load OGRE including the render window
     331        scoped_ptr<GraphicsManager> graphicsManager(new GraphicsManager());
     332
     333        // The render window width and height are used to set up the mouse movement.
     334        size_t windowHnd = 0;
     335        graphicsManager->getRenderWindow()->getCustomAttribute("WINDOW", &windowHnd);
     336
     337        // Calls the InputManager which sets up the input devices.
     338        scoped_ptr<InputManager> inputManager(new InputManager(windowHnd));
     339
     340        // load the CEGUI interface
     341        guiManager_.reset(new GUIManager(graphicsManager->getRenderWindow()));
     342
     343        // Dismiss scoped pointers
     344        graphicsManager_.swap(graphicsManager);
     345        inputManager_.swap(inputManager);
     346
     347        bGraphicsLoaded_ = true;
     348    }
     349
     350    void Core::unloadGraphics()
     351    {
     352        if (!bGraphicsLoaded_)
     353            return;
     354
     355        this->guiManager_.reset();;
     356        this->inputManager_.reset();;
     357        this->graphicsManager_.reset();
     358
     359        bGraphicsLoaded_ = false;
    325360    }
    326361
     
    415450    }
    416451
     452    /*static*/ const boost::filesystem::path& Core::getRootPath()
     453    {
     454        return getInstance().configuration_->rootPath_;
     455    }
     456    /*static*/ std::string Core::getRootPathString()
     457    {
     458        return getInstance().configuration_->rootPath_.string() + '/';
     459    }
     460
    417461    /**
    418462    @note
     
    524568        {
    525569            COUT(1) << "Running from the build tree." << std::endl;
    526             Core::isDevBuild_ = true;
     570            Core::bDevRun_ = true;
    527571            configuration_->mediaPath_  = ORXONOX_MEDIA_DEV_PATH;
    528572            configuration_->configPath_ = ORXONOX_CONFIG_DEV_PATH;
     
    603647    }
    604648
    605     void Core::update(const Clock& time)
    606     {
    607         this->tclThreadManager_->update(time);
     649    bool Core::preUpdate(const Clock& time) throw()
     650    {
     651        std::string exceptionMessage;
     652        try
     653        {
     654            if (this->bGraphicsLoaded_)
     655            {
     656                // process input events
     657                this->inputManager_->update(time);
     658                // process gui events
     659                this->guiManager_->update(time);
     660            }
     661            // process thread commands
     662            this->tclThreadManager_->update(time);
     663        }
     664        catch (const std::exception& ex)
     665        { exceptionMessage = ex.what(); }
     666        catch (...)
     667        { exceptionMessage = "Unknown exception"; }
     668        if (!exceptionMessage.empty())
     669        {
     670            COUT(0) << "An exception occurred in the Core preUpdate: " << exceptionMessage << std::endl;
     671            COUT(0) << "This should really never happen! Closing the program." << std::endl;
     672            return false;
     673        }
     674        return true;
     675    }
     676
     677    bool Core::postUpdate(const Clock& time) throw()
     678    {
     679        std::string exceptionMessage;
     680        try
     681        {
     682            if (this->bGraphicsLoaded_)
     683            {
     684                // Render (doesn't throw)
     685                this->graphicsManager_->update(time);
     686            }
     687        }
     688        catch (const std::exception& ex)
     689        { exceptionMessage = ex.what(); }
     690        catch (...)
     691        { exceptionMessage = "Unknown exception"; }
     692        if (!exceptionMessage.empty())
     693        {
     694            COUT(0) << "An exception occurred in the Core postUpdate: " << exceptionMessage << std::endl;
     695            COUT(0) << "This should really never happen! Closing the program." << std::endl;
     696            return false;
     697        }
     698        return true;
    608699    }
    609700}
Note: See TracChangeset for help on using the changeset viewer.