Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 8, 2009, 12:36:08 AM (16 years ago)
Author:
dafrick
Message:

Merging of the current QuestSystem branch.

Location:
code/branches/questsystem5
Files:
2 added
2 deleted
18 edited

Legend:

Unmodified
Added
Removed
  • code/branches/questsystem5

  • code/branches/questsystem5/src/orxonox/gamestates/CMakeLists.txt

    r2710 r2907  
    11ADD_SOURCE_FILES(ORXONOX_SRC_FILES
     2  GSClient.cc
    23  GSDedicated.cc
    3   GSClient.cc
    44  GSGraphics.cc
    5   GSGUI.cc
    65  GSIOConsole.cc
    76  GSLevel.cc
     7  GSMainMenu.cc
    88  GSRoot.cc
    99  GSServer.cc
  • code/branches/questsystem5/src/orxonox/gamestates/GSClient.cc

    r2171 r2907  
    3131
    3232#include "core/input/InputManager.h"
     33#include "core/Clock.h"
    3334#include "core/CommandLine.h"
    34 #include "core/Core.h"
     35#include "core/Game.h"
     36#include "core/GameMode.h"
    3537#include "network/Client.h"
    3638
    3739namespace orxonox
    3840{
     41    AddGameState(GSClient, "client");
     42
    3943    SetCommandLineArgument(ip, "127.0.0.1").information("#.#.#.#");
    4044
    41     GSClient::GSClient()
    42         : GameState<GSGraphics>("client")
     45    GSClient::GSClient(const std::string& name)
     46        : GameState(name)
    4347        , client_(0)
    4448    {
     
    4953    }
    5054
    51     void GSClient::enter()
     55    void GSClient::activate()
    5256    {
    53         Core::setIsClient(true);
     57        GameMode::setIsClient(true);
    5458
    5559        this->client_ = new Client(CommandLine::getValue("ip").getString(), CommandLine::getValue("port"));
     
    5862            ThrowException(InitialisationFailed, "Could not establish connection with server.");
    5963
    60         GSLevel::enter(this->getParent()->getViewport());
    61 
    62         client_->tick(0);
     64        client_->update(Game::getInstance().getGameClock());
    6365    }
    6466
    65     void GSClient::leave()
     67    void GSClient::deactivate()
    6668    {
    67         GSLevel::leave();
    68 
    6969        client_->closeConnection();
    7070
     
    7272        delete this->client_;
    7373
    74         Core::setIsClient(false);
     74        GameMode::setIsClient(false);
    7575    }
    7676
    77     void GSClient::ticked(const Clock& time)
     77    void GSClient::update(const Clock& time)
    7878    {
    79         GSLevel::ticked(time);
    80         client_->tick(time.getDeltaTime());
    81 
    82         this->tickChild(time);
     79        client_->update(time);
    8380    }
    8481}
  • code/branches/questsystem5/src/orxonox/gamestates/GSClient.h

    r2171 r2907  
    3131
    3232#include "OrxonoxPrereqs.h"
     33#include "core/GameState.h"
    3334#include "network/NetworkPrereqs.h"
    34 #include "GSLevel.h"
    35 #include "GSGraphics.h"
    3635
    3736namespace orxonox
    3837{
    39     class _OrxonoxExport GSClient : public GameState<GSGraphics>, public GSLevel
     38    class _OrxonoxExport GSClient : public GameState
    4039    {
    4140    public:
    42         GSClient();
     41        GSClient(const std::string& name);
    4342        ~GSClient();
    4443
     44        void activate();
     45        void deactivate();
     46        void update(const Clock& time);
    4547
    4648    private:
    47         void enter();
    48         void leave();
    49         void ticked(const Clock& time);
    50 
    5149        Client* client_;
    5250    };
  • code/branches/questsystem5/src/orxonox/gamestates/GSDedicated.cc

    r2662 r2907  
    3030#include "GSDedicated.h"
    3131
     32#include "core/Clock.h"
    3233#include "core/CommandLine.h"
    33 #include "core/Core.h"
     34#include "core/Game.h"
     35#include "core/GameMode.h"
    3436#include "core/Iterator.h"
    3537#include "network/Server.h"
     
    3941namespace orxonox
    4042{
    41     GSDedicated::GSDedicated()
    42         : GameState<GSRoot>("dedicated")
     43    AddGameState(GSDedicated, "dedicated");
     44
     45    GSDedicated::GSDedicated(const std::string& name)
     46        : GameState(name)
    4347        , server_(0)
    4448        , timeSinceLastUpdate_(0)
     
    5054    }
    5155
    52     void GSDedicated::enter()
     56    void GSDedicated::activate()
    5357    {
    54         Core::setHasServer(true);
     58        GameMode::setHasServer(true);
    5559
    5660        this->server_ = new Server(CommandLine::getValue("port"));
    5761        COUT(0) << "Loading scene in server mode" << std::endl;
    5862
    59         GSLevel::enter(0);
    60 
    6163        server_->open();
    6264    }
    6365
    64     void GSDedicated::leave()
     66    void GSDedicated::deactivate()
    6567    {
    66         GSLevel::leave();
    67 
    6868        this->server_->close();
    6969        delete this->server_;
    7070
    71         Core::setHasServer(false);
     71        GameMode::setHasServer(false);
    7272    }
    7373
    74     void GSDedicated::ticked(const Clock& time)
     74    void GSDedicated::update(const Clock& time)
    7575    {
    7676//        static float startTime = time.getSecondsPrecise();
     
    8282//            COUT(0) << "estimated ticks/sec: " << nrOfTicks/(time.getSecondsPrecise()-startTime) << endl;
    8383            timeSinceLastUpdate_ -= static_cast<unsigned int>(timeSinceLastUpdate_ / NETWORK_PERIOD) * NETWORK_PERIOD;
    84             GSLevel::ticked(time);
    85             server_->tick(time.getDeltaTime());
    86             this->tickChild(time);
     84            server_->update(time);
    8785        }
    8886        else
  • code/branches/questsystem5/src/orxonox/gamestates/GSDedicated.h

    r2662 r2907  
    3131
    3232#include "OrxonoxPrereqs.h"
     33#include "core/GameState.h"
    3334#include "network/NetworkPrereqs.h"
    34 #include "GSLevel.h"
    35 #include "GSRoot.h"
    3635
    3736namespace orxonox
    3837{
    39     class _OrxonoxExport GSDedicated : public GameState<GSRoot>, public GSLevel
     38    class _OrxonoxExport GSDedicated : public GameState
    4039    {
    4140    public:
    42         GSDedicated();
     41        GSDedicated(const std::string& name);
    4342        ~GSDedicated();
    4443
     44        void activate();
     45        void deactivate();
     46        void update(const Clock& time);
     47
    4548    private:
    46         void enter();
    47         void leave();
    48         void ticked(const Clock& time);
    49 
    50         Server*      server_;
    51         float        timeSinceLastUpdate_;
     49        Server* server_;
     50        float   timeSinceLastUpdate_;
    5251    };
    5352}
  • code/branches/questsystem5/src/orxonox/gamestates/GSGraphics.cc

    r2759 r2907  
    2323 *      Reto Grieder
    2424 *   Co-authors:
    25  *      ...
    26  *
     25 *      Benjamin Knecht
     26 *
     27 */
     28
     29/**
     30    @file
     31    @brief Implementation of Graphics GameState class.
    2732 */
    2833
     
    3035#include "GSGraphics.h"
    3136
    32 #include <fstream>
    3337#include <boost/filesystem.hpp>
    34 
    35 #include <OgreCompositorManager.h>
    36 #include <OgreConfigFile.h>
    37 #include <OgreFrameListener.h>
    38 #include <OgreRoot.h>
    39 #include <OgreLogManager.h>
    40 #include <OgreException.h>
    4138#include <OgreRenderWindow.h>
    42 #include <OgreRenderSystem.h>
    43 #include <OgreTextureManager.h>
    44 #include <OgreViewport.h>
    45 #include <OgreWindowEventUtilities.h>
    46 
    47 #include "SpecialConfig.h"
     39
    4840#include "util/Debug.h"
    49 #include "util/Exception.h"
    50 #include "util/String.h"
    51 #include "util/SubString.h"
     41#include "core/ConfigValueIncludes.h"
     42#include "core/Clock.h"
    5243#include "core/ConsoleCommand.h"
    53 #include "core/ConfigValueIncludes.h"
     44#include "core/Core.h"
    5445#include "core/CoreIncludes.h"
    55 #include "core/Core.h"
     46#include "core/Game.h"
     47#include "core/GameMode.h"
    5648#include "core/input/InputManager.h"
    5749#include "core/input/KeyBinder.h"
    58 #include "core/input/ExtendedInputState.h"
     50#include "core/input/SimpleInputState.h"
    5951#include "core/Loader.h"
    6052#include "core/XMLFile.h"
    6153#include "overlays/console/InGameConsole.h"
    6254#include "gui/GUIManager.h"
    63 #include "tools/WindowEventListener.h"
    64 
    65 // for compatibility
    66 #include "GraphicsEngine.h"
     55#include "GraphicsManager.h"
    6756
    6857namespace orxonox
    6958{
    70     GSGraphics::GSGraphics()
    71         : GameState<GSRoot>("graphics")
    72         , renderWindow_(0)
    73         , viewport_(0)
    74         , bWindowEventListenerUpdateRequired_(false)
     59    AddGameState(GSGraphics, "graphics");
     60
     61    GSGraphics::GSGraphics(const std::string& name)
     62        : GameState(name)
    7563        , inputManager_(0)
    7664        , console_(0)
    7765        , guiManager_(0)
    78         , ogreRoot_(0)
    79         , ogreLogger_(0)
    80         , graphicsEngine_(0)
     66        , graphicsManager_(0)
    8167        , masterKeyBinder_(0)
     68        , masterInputState_(0)
    8269        , debugOverlay_(0)
    8370    {
    8471        RegisterRootObject(GSGraphics);
     72    }
     73
     74    GSGraphics::~GSGraphics()
     75    {
     76    }
     77
     78    /**
     79    @brief
     80        this function does nothing
     81
     82        Indeed. Here goes nothing.
     83    */
     84    void GSGraphics::setConfigValues()
     85    {
     86    }
     87
     88    /**
     89    @brief
     90        This function is called when we enter this game state.
     91
     92        Since graphics is very important for our game this function does quite a lot:
     93        \li starts graphics manager
     94        \li loads debug overlay
     95        \li manages render window
     96        \li creates input manager
     97        \li loads master key bindings
     98        \li loads ingame console
     99        \li loads GUI interface (GUIManager)
     100        \li creates console command to toggle GUI
     101    */
     102    void GSGraphics::activate()
     103    {
     104        GameMode::setShowsGraphics(true);
     105
    85106        setConfigValues();
    86     }
    87 
    88     GSGraphics::~GSGraphics()
    89     {
    90     }
    91 
    92     void GSGraphics::setConfigValues()
    93     {
    94         SetConfigValue(resourceFile_,    "resources.cfg")
    95             .description("Location of the resources file in the data path.");
    96         SetConfigValue(ogreConfigFile_,  "ogre.cfg")
    97             .description("Location of the Ogre config file");
    98         SetConfigValue(ogrePluginsFolder_, ORXONOX_OGRE_PLUGINS_FOLDER)
    99             .description("Folder where the Ogre plugins are located.");
    100         SetConfigValue(ogrePlugins_, ORXONOX_OGRE_PLUGINS)
    101             .description("Comma separated list of all plugins to load.");
    102         SetConfigValue(ogreLogFile_,     "ogre.log")
    103             .description("Logfile for messages from Ogre. Use \"\" to suppress log file creation.");
    104         SetConfigValue(ogreLogLevelTrivial_ , 5)
    105             .description("Corresponding orxonox debug level for ogre Trivial");
    106         SetConfigValue(ogreLogLevelNormal_  , 4)
    107             .description("Corresponding orxonox debug level for ogre Normal");
    108         SetConfigValue(ogreLogLevelCritical_, 2)
    109             .description("Corresponding orxonox debug level for ogre Critical");
    110     }
    111 
    112     void GSGraphics::enter()
    113     {
    114         Core::setShowsGraphics(true);
    115 
    116         // initialise graphics engine. Doesn't load the render window yet!
    117         graphicsEngine_ = new GraphicsEngine();
    118 
    119         // Ogre setup procedure
    120         setupOgre();
    121         // load all the required plugins for Ogre
    122         loadOgrePlugins();
    123         // read resource declaration file
    124         this->declareResources();
    125         // Reads ogre config and creates the render window
    126         this->loadRenderer();
    127 
    128         // TODO: Spread this so that this call only initialises things needed for the Console and GUI
    129         this->initialiseResources();
    130 
    131         // We want to get informed whenever an object of type WindowEventListener is created
    132         // in order to later update the window size.
    133         bWindowEventListenerUpdateRequired_ = false;
    134         RegisterConstructionCallback(GSGraphics, orxonox::WindowEventListener, requestWindowEventListenerUpdate);
     107
     108        // initialise graphics manager. Doesn't load the render window yet!
     109        this->graphicsManager_ = new GraphicsManager();
     110        this->graphicsManager_->initialise();
    135111
    136112        // load debug overlay
     
    139115        Loader::open(debugOverlay_);
    140116
     117        // The render window width and height are used to set up the mouse movement.
     118        size_t windowHnd = 0;
     119        Ogre::RenderWindow* renderWindow = GraphicsManager::getInstance().getRenderWindow();
     120        renderWindow->getCustomAttribute("WINDOW", &windowHnd);
     121
    141122        // Calls the InputManager which sets up the input devices.
    142         // The render window width and height are used to set up the mouse movement.
    143123        inputManager_ = new InputManager();
    144         size_t windowHnd = 0;
    145         this->renderWindow_->getCustomAttribute("WINDOW", &windowHnd);
    146         inputManager_->initialise(windowHnd, renderWindow_->getWidth(), renderWindow_->getHeight(), true);
    147         // Configure master input state with a KeyBinder
     124        inputManager_->initialise(windowHnd, renderWindow->getWidth(), renderWindow->getHeight(), true);
     125
     126        // load master key bindings
     127        masterInputState_ = InputManager::getInstance().createInputState<SimpleInputState>("master", true);
    148128        masterKeyBinder_ = new KeyBinder();
    149129        masterKeyBinder_->loadBindings("masterKeybindings.ini");
    150         inputManager_->getMasterInputState()->addKeyHandler(masterKeyBinder_);
     130        masterInputState_->setKeyHandler(masterKeyBinder_);
    151131
    152132        // Load the InGameConsole
    153133        console_ = new InGameConsole();
    154         console_->initialise(this->renderWindow_->getWidth(), this->renderWindow_->getHeight());
     134        console_->initialise(renderWindow->getWidth(), renderWindow->getHeight());
    155135
    156136        // load the CEGUI interface
    157137        guiManager_ = new GUIManager();
    158         guiManager_->initialise(this->renderWindow_);
    159 
    160         // add console commands
    161         FunctorMember<GSGraphics>* functor1 = createFunctor(&GSGraphics::printScreen);
    162         functor1->setObject(this);
    163         ccPrintScreen_ = createConsoleCommand(functor1, "printScreen");
    164         CommandExecutor::addConsoleCommandShortcut(ccPrintScreen_);
    165     }
    166 
    167     void GSGraphics::leave()
    168     {
    169         using namespace Ogre;
    170 
    171         delete this->ccPrintScreen_;
    172 
    173         // remove our WindowEventListener first to avoid bad calls after the window has been destroyed
    174         Ogre::WindowEventUtilities::removeWindowEventListener(this->renderWindow_, this);
     138        guiManager_->initialise(renderWindow);
     139
     140        // add console command to toggle GUI
     141        FunctorMember<GSGraphics>* functor = createFunctor(&GSGraphics::toggleGUI);
     142        functor->setObject(this);
     143        this->ccToggleGUI_ = createConsoleCommand(functor, "toggleGUI");
     144        CommandExecutor::addConsoleCommandShortcut(this->ccToggleGUI_);
     145
     146        // enable master input
     147        InputManager::getInstance().requestEnterState("master");
     148    }
     149
     150    /**
     151    @brief
     152        This function is called when the game state is left
     153
     154        Created references, input states and console commands are deleted.
     155    */
     156    void GSGraphics::deactivate()
     157    {
     158
     159        if (this->ccToggleGUI_)
     160        {
     161            delete this->ccToggleGUI_;
     162            this->ccToggleGUI_ = 0;
     163        }
     164
     165        masterInputState_->setHandler(0);
     166        InputManager::getInstance().requestDestroyState("master");
     167        delete this->masterKeyBinder_;
    175168
    176169        delete this->guiManager_;
    177 
    178170        delete this->console_;
    179 
    180         //inputManager_->getMasterInputState()->removeKeyHandler(this->masterKeyBinder_);
    181         delete this->masterKeyBinder_;
    182         delete this->inputManager_;
    183171
    184172        Loader::unload(this->debugOverlay_);
    185173        delete this->debugOverlay_;
    186174
    187         // unload all compositors
    188         Ogre::CompositorManager::getSingleton().removeAll();
    189 
    190         // destroy render window
    191         RenderSystem* renderer = this->ogreRoot_->getRenderSystem();
    192         renderer->destroyRenderWindow("Orxonox");
    193 
    194         /*** CODE SNIPPET, UNUSED ***/
    195         // Does the opposite of initialise()
    196         //ogreRoot_->shutdown();
    197         // Remove all resources and resource groups
    198         //StringVector groups = ResourceGroupManager::getSingleton().getResourceGroups();
    199         //for (StringVector::iterator it = groups.begin(); it != groups.end(); ++it)
    200         //{
    201         //    ResourceGroupManager::getSingleton().destroyResourceGroup(*it);
    202         //}
    203 
    204         //ParticleSystemManager::getSingleton().removeAllTemplates();
    205 
    206         // Shutdown the render system
    207         //this->ogreRoot_->setRenderSystem(0);
    208 
    209         delete this->ogreRoot_;
    210 
    211         // delete the ogre log and the logManager (since we have created it).
    212         this->ogreLogger_->getDefaultLog()->removeListener(this);
    213         this->ogreLogger_->destroyLog(Ogre::LogManager::getSingleton().getDefaultLog());
    214         delete this->ogreLogger_;
    215 
    216         delete graphicsEngine_;
    217 
    218         Core::setShowsGraphics(false);
     175        delete this->inputManager_;
     176        this->inputManager_ = 0;
     177
     178        delete graphicsManager_;
     179
     180        GameMode::setShowsGraphics(false);
     181    }
     182
     183    /**
     184    @brief
     185        Toggles the visibility of the current GUI
     186
     187        This function just executes a Lua function in the main script of the GUI by accessing the GUIManager.
     188        For more details on this function check out the Lua code.
     189    */
     190    void GSGraphics::toggleGUI()
     191    {
     192            GUIManager::getInstance().executeCode("toggleGUI()");
    219193    }
    220194
     
    227201        need the time. So we shouldn't run into problems.
    228202    */
    229     void GSGraphics::ticked(const Clock& time)
    230     {
     203    void GSGraphics::update(const Clock& time)
     204    {
     205        if (this->getActivity().topState)
     206        {
     207            // This state can not 'survive' on its own.
     208            // Load a user interface therefore
     209            Game::getInstance().requestState("mainMenu");
     210        }
     211
    231212        uint64_t timeBeforeTick = time.getRealMicroseconds();
    232213
    233         float dt = time.getDeltaTime();
    234 
    235         this->inputManager_->tick(dt);
    236         // tick console
    237         this->console_->tick(dt);
    238         this->tickChild(time);
    239 
    240         if (this->bWindowEventListenerUpdateRequired_)
    241         {
    242             // Update all WindowEventListeners for the case a new one was created.
    243             this->windowResized(this->renderWindow_);
    244             this->bWindowEventListenerUpdateRequired_ = false;
    245         }
     214        this->inputManager_->update(time);        // tick console
     215        this->console_->update(time);
     216        this->guiManager_->update(time);
    246217
    247218        uint64_t timeAfterTick = time.getRealMicroseconds();
    248219
    249         // Also add our tick time to the list in GSRoot
    250         this->getParent()->addTickTime(timeAfterTick - timeBeforeTick);
    251 
    252         // Update statistics overlay. Note that the values only change periodically in GSRoot.
    253         GraphicsEngine::getInstance().setAverageFramesPerSecond(this->getParent()->getAvgFPS());
    254         GraphicsEngine::getInstance().setAverageTickTime(this->getParent()->getAvgTickTime());
    255 
    256         // don't forget to call _fireFrameStarted in ogre to make sure
    257         // everything goes smoothly
    258         Ogre::FrameEvent evt;
    259         evt.timeSinceLastFrame = dt;
    260         evt.timeSinceLastEvent = dt; // note: same time, but shouldn't matter anyway
    261         ogreRoot_->_fireFrameStarted(evt);
    262 
    263         // Pump messages in all registered RenderWindows
    264         // This calls the WindowEventListener objects.
    265         Ogre::WindowEventUtilities::messagePump();
    266         // make sure the window stays active even when not focused
    267         // (probably only necessary on windows)
    268         this->renderWindow_->setActive(true);
    269 
    270         // render
    271         ogreRoot_->_updateAllRenderTargets();
    272 
    273         // again, just to be sure ogre works fine
    274         ogreRoot_->_fireFrameEnded(evt); // note: uses the same time as _fireFrameStarted
    275     }
    276 
    277     /**
    278     @brief
    279         Creates the Ogre Root object and sets up the ogre log.
    280     */
    281     void GSGraphics::setupOgre()
    282     {
    283         COUT(3) << "Setting up Ogre..." << std::endl;
    284 
    285         if (ogreConfigFile_ == "")
    286         {
    287             COUT(2) << "Warning: Ogre config file set to \"\". Defaulting to config.cfg" << std::endl;
    288             ModifyConfigValue(ogreConfigFile_, tset, "config.cfg");
    289         }
    290         if (ogreLogFile_ == "")
    291         {
    292             COUT(2) << "Warning: Ogre log file set to \"\". Defaulting to ogre.log" << std::endl;
    293             ModifyConfigValue(ogreLogFile_, tset, "ogre.log");
    294         }
    295 
    296         boost::filesystem::path ogreConfigFilepath(Core::getConfigPath() / this->ogreConfigFile_);
    297         boost::filesystem::path ogreLogFilepath(Core::getLogPath() / this->ogreLogFile_);
    298 
    299         // create a new logManager
    300         // Ogre::Root will detect that we've already created a Log
    301         ogreLogger_ = new Ogre::LogManager();
    302         COUT(4) << "Ogre LogManager created" << std::endl;
    303 
    304         // create our own log that we can listen to
    305         Ogre::Log *myLog;
    306         myLog = ogreLogger_->createLog(ogreLogFilepath.string(), true, false, false);
    307         COUT(4) << "Ogre Log created" << std::endl;
    308 
    309         myLog->setLogDetail(Ogre::LL_BOREME);
    310         myLog->addListener(this);
    311 
    312         COUT(4) << "Creating Ogre Root..." << std::endl;
    313 
    314         // check for config file existence because Ogre displays (caught) exceptions if not
    315         if (!boost::filesystem::exists(ogreConfigFilepath))
    316         {
    317             // create a zero sized file
    318             std::ofstream creator;
    319             creator.open(ogreConfigFilepath.string().c_str());
    320             creator.close();
    321         }
    322 
    323         // Leave plugins file empty. We're going to do that part manually later
    324         ogreRoot_ = new Ogre::Root("", ogreConfigFilepath.string(), ogreLogFilepath.string());
    325 
    326         COUT(3) << "Ogre set up done." << std::endl;
    327     }
    328 
    329     void GSGraphics::loadOgrePlugins()
    330     {
    331         // just to make sure the next statement doesn't segfault
    332         if (ogrePluginsFolder_ == "")
    333             ogrePluginsFolder_ = ".";
    334 
    335         boost::filesystem::path folder(ogrePluginsFolder_);
    336         // Do some SubString magic to get the comma separated list of plugins
    337         SubString plugins(ogrePlugins_, ",", " ", false, 92, false, 34, false, 40, 41, false, '\0');
    338         // Use backslash paths on Windows! file_string() already does that though.
    339         for (unsigned int i = 0; i < plugins.size(); ++i)
    340             ogreRoot_->loadPlugin((folder / plugins[i]).file_string());
    341     }
    342 
    343     void GSGraphics::declareResources()
    344     {
    345         CCOUT(4) << "Declaring Resources" << std::endl;
    346         //TODO: Specify layout of data file and maybe use xml-loader
    347         //TODO: Work with ressource groups (should be generated by a special loader)
    348 
    349         if (resourceFile_ == "")
    350         {
    351             COUT(2) << "Warning: Ogre resource file set to \"\". Defaulting to resources.cfg" << std::endl;
    352             ModifyConfigValue(resourceFile_, tset, "resources.cfg");
    353         }
    354 
    355         // Load resource paths from data file using configfile ressource type
    356         Ogre::ConfigFile cf;
    357         try
    358         {
    359             cf.load((Core::getMediaPath() / resourceFile_).string());
    360         }
    361         catch (...)
    362         {
    363             //COUT(1) << ex.getFullDescription() << std::endl;
    364             COUT(0) << "Have you forgotten to set the data path in orxnox.ini?" << std::endl;
    365             throw;
    366         }
    367 
    368         // Go through all sections & settings in the file
    369         Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();
    370 
    371         std::string secName, typeName, archName;
    372         while (seci.hasMoreElements())
    373         {
    374             try
    375             {
    376                 secName = seci.peekNextKey();
    377                 Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
    378                 Ogre::ConfigFile::SettingsMultiMap::iterator i;
    379                 for (i = settings->begin(); i != settings->end(); ++i)
    380                 {
    381                     typeName = i->first; // for instance "FileSystem" or "Zip"
    382                     archName = i->second; // name (and location) of archive
    383 
    384                     Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
    385                         (Core::getMediaPath() / archName).string(), typeName, secName);
    386                 }
    387             }
    388             catch (Ogre::Exception& ex)
    389             {
    390                 COUT(1) << ex.getFullDescription() << std::endl;
    391             }
    392         }
    393     }
    394 
    395     void GSGraphics::loadRenderer()
    396     {
    397         CCOUT(4) << "Configuring Renderer" << std::endl;
    398 
    399         if (!ogreRoot_->restoreConfig())
    400             if (!ogreRoot_->showConfigDialog())
    401                 ThrowException(InitialisationFailed, "Could not show Ogre configuration dialogue.");
    402 
    403         CCOUT(4) << "Creating render window" << std::endl;
    404 
    405         this->renderWindow_ = ogreRoot_->initialise(true, "Orxonox");
    406 
    407         Ogre::WindowEventUtilities::addWindowEventListener(this->renderWindow_, this);
    408 
    409         Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(0);
    410 
    411         // create a full screen default viewport
    412         this->viewport_ = this->renderWindow_->addViewport(0, 0);
    413 
    414         if (this->graphicsEngine_)
    415             this->graphicsEngine_->setViewport(this->viewport_);
    416     }
    417 
    418     void GSGraphics::initialiseResources()
    419     {
    420         CCOUT(4) << "Initialising resources" << std::endl;
    421         //TODO: Do NOT load all the groups, why are we doing that? And do we really do that? initialise != load...
    422         //try
    423         //{
    424             Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
    425             /*Ogre::StringVector str = Ogre::ResourceGroupManager::getSingleton().getResourceGroups();
    426             for (unsigned int i = 0; i < str.size(); i++)
    427             {
    428             Ogre::ResourceGroupManager::getSingleton().loadResourceGroup(str[i]);
    429             }*/
    430         //}
    431         //catch (...)
    432         //{
    433         //    CCOUT(2) << "Error: There was a serious error when initialising the resources." << std::endl;
    434         //    throw;
    435         //}
    436     }
    437 
    438     /**
    439     @brief
    440         Method called by the LogListener interface from Ogre.
    441         We use it to capture Ogre log messages and handle it ourselves.
    442     @param message
    443         The message to be logged
    444     @param lml
    445         The message level the log is using
    446     @param maskDebug
    447         If we are printing to the console or not
    448     @param logName
    449         The name of this log (so you can have several listeners
    450         for different logs, and identify them)
    451     */
    452     void GSGraphics::messageLogged(const std::string& message,
    453         Ogre::LogMessageLevel lml, bool maskDebug, const std::string& logName)
    454     {
    455         int orxonoxLevel;
    456         switch (lml)
    457         {
    458         case Ogre::LML_TRIVIAL:
    459             orxonoxLevel = this->ogreLogLevelTrivial_;
    460             break;
    461         case Ogre::LML_NORMAL:
    462             orxonoxLevel = this->ogreLogLevelNormal_;
    463             break;
    464         case Ogre::LML_CRITICAL:
    465             orxonoxLevel = this->ogreLogLevelCritical_;
    466             break;
    467         default:
    468             orxonoxLevel = 0;
    469         }
    470         OutputHandler::getOutStream().setOutputLevel(orxonoxLevel)
    471             << "Ogre: " << message << std::endl;
    472     }
    473 
    474     /**
    475     @brief
    476         Window has moved.
    477     @param rw
    478         The render window it occured in
    479     */
    480     void GSGraphics::windowMoved(Ogre::RenderWindow *rw)
    481     {
    482         for (ObjectList<orxonox::WindowEventListener>::iterator it = ObjectList<orxonox::WindowEventListener>::begin(); it; ++it)
    483             it->windowMoved();
     220        // Also add our tick time
     221        Game::getInstance().addTickTime(timeAfterTick - timeBeforeTick);
     222
     223        // Render
     224        this->graphicsManager_->update(time);
    484225    }
    485226
     
    490231        The render window it occured in
    491232    @note
    492         GraphicsEngine has a render window stored itself. This is the same
     233        GraphicsManager has a render window stored itself. This is the same
    493234        as rw. But we have to be careful when using multiple render windows!
    494235    */
    495     void GSGraphics::windowResized(Ogre::RenderWindow *rw)
    496     {
    497         for (ObjectList<orxonox::WindowEventListener>::iterator it = ObjectList<orxonox::WindowEventListener>::begin(); it; ++it)
    498             it->windowResized(this->renderWindow_->getWidth(), this->renderWindow_->getHeight());
    499 
     236    void GSGraphics::windowResized(unsigned int newWidth, unsigned int newHeight)
     237    {
    500238        // OIS needs this under linux even if we only use relative input measurement.
    501239        if (this->inputManager_)
    502             this->inputManager_->setWindowExtents(renderWindow_->getWidth(), renderWindow_->getHeight());
     240            this->inputManager_->setWindowExtents(newWidth, newHeight);
    503241    }
    504242
     
    509247        The render window it occured in
    510248    */
    511     void GSGraphics::windowFocusChange(Ogre::RenderWindow *rw)
    512     {
    513         for (ObjectList<orxonox::WindowEventListener>::iterator it = ObjectList<orxonox::WindowEventListener>::begin(); it; ++it)
    514             it->windowFocusChanged();
    515 
     249    void GSGraphics::windowFocusChanged()
     250    {
    516251        // instruct InputManager to clear the buffers (core library so we cannot use the interface)
    517252        if (this->inputManager_)
     
    519254    }
    520255
    521     /**
    522     @brief
    523         Window was closed.
    524     @param rw
    525         The render window it occured in
    526     */
    527     void GSGraphics::windowClosed(Ogre::RenderWindow *rw)
    528     {
    529         this->requestState("root");
    530     }
    531 
    532     void GSGraphics::printScreen()
    533     {
    534         if (this->renderWindow_)
    535         {
    536             this->renderWindow_->writeContentsToTimestampedFile("shot_", ".jpg");
    537         }
    538     }
    539256}
  • code/branches/questsystem5/src/orxonox/gamestates/GSGraphics.h

    r2756 r2907  
    2323 *      Reto Grieder
    2424 *   Co-authors:
    25  *      ...
     25 *      Benjamin Knecht (documentation)
    2626 *
    2727 */
     28
     29 /**
     30    @file
     31    @brief Declaration of the Graphics GameState class.
     32  */
    2833
    2934#ifndef _GSGraphics_H__
     
    3136
    3237#include "OrxonoxPrereqs.h"
    33 #include <OgrePrerequisites.h>
    34 #define NOMINMAX // required to stop windows.h screwing up std::min definition
    35 #include <OgreWindowEventUtilities.h>
    3638#include "core/GameState.h"
    37 #include "core/OrxonoxClass.h"
    38 #include "GSRoot.h"
     39#include "tools/WindowEventListener.h"
    3940
    4041namespace orxonox
    4142{
    42     class _OrxonoxExport GSGraphics : public GameState<GSRoot>, public OrxonoxClass,
    43                                       public Ogre::WindowEventListener, public Ogre::LogListener
     43    /**
     44    @class GSGraphics
     45    @brief
     46        Game state used when displaying graphics of any kind
     47
     48        This game state is only left out if we start a dedicated server where no graphics are present.
     49    */
     50    class _OrxonoxExport GSGraphics : public GameState, public WindowEventListener
    4451    {
    45         friend class ClassIdentifier<GSGraphics>;
    46 
    4752    public:
    48         GSGraphics();
     53        GSGraphics(const std::string& name);
    4954        ~GSGraphics();
    50 
    51         Ogre::Root*     getOgreRoot()   { return this->ogreRoot_  ; }
    52         Ogre::Viewport* getViewport()   { return this->viewport_  ; }
    53         GUIManager*     getGUIManager() { return this->guiManager_; }
    54 
    55     private: // functions
    56         void enter();
    57         void leave();
    58         void ticked(const Clock& time);
    59 
    6055        void setConfigValues();
    6156
    62         void setupOgre();
    63         void loadOgrePlugins();
    64         void declareResources();
    65         void loadRenderer();
    66         void initialiseResources();
     57        void activate();
     58        void deactivate();
     59        void update(const Clock& time);
    6760
    68         // console commands
    69         void printScreen();
     61        void toggleGUI();
    7062
    71         // event from Ogre::LogListener
    72         void messageLogged(const std::string& message, Ogre::LogMessageLevel lml,
    73             bool maskDebug, const std::string& logName);
    74 
    75         // window events from Ogre::WindowEventListener
    76         void windowMoved       (Ogre::RenderWindow* rw);
    77         void windowResized     (Ogre::RenderWindow* rw);
    78         void windowFocusChange (Ogre::RenderWindow* rw);
    79         void windowClosed      (Ogre::RenderWindow* rw);
    80 
    81         void requestWindowEventListenerUpdate() { this->bWindowEventListenerUpdateRequired_ = true; }
    82 
    83     private: // variables
    84         Ogre::RenderWindow*   renderWindow_;          //!< the current render window
    85         Ogre::Viewport*       viewport_;              //!< default full size viewport
    86         bool bWindowEventListenerUpdateRequired_;     //!< True if a new WindowEventListener was created but not yet updated.
     63    private:
     64        // Window events from WindowEventListener
     65        void windowResized(unsigned int newWidth, unsigned int newHeight);
     66        void windowFocusChanged();
    8767
    8868        // managed singletons
    89         InputManager*         inputManager_;
     69        InputManager*         inputManager_;        //!< Reference to input management
    9070        InGameConsole*        console_;
    91         GUIManager*           guiManager_;
    92         Ogre::Root*           ogreRoot_;                  //!< Ogre's root
    93         Ogre::LogManager*     ogreLogger_;
    94         GraphicsEngine*       graphicsEngine_;   //!< Interface to Ogre
     71        GUIManager*           guiManager_;          //!< Interface to GUI
     72        GraphicsManager*      graphicsManager_;     //!< Interface to Ogre
    9573
    96         KeyBinder*            masterKeyBinder_;
     74        KeyBinder*            masterKeyBinder_;     //!< Key binder for master key bindings
     75        SimpleInputState*     masterInputState_;    //!< Special input state for master input
    9776        XMLFile*              debugOverlay_;
    98 
    99         // config values
    100         std::string           resourceFile_;             //!< resources file name
    101         std::string           ogreConfigFile_;           //!< ogre config file name
    102         std::string           ogrePluginsFolder_;        //!< Folder where the Ogre plugins are located
    103         std::string           ogrePlugins_;              //!< Comma separated list of all plugins to load
    104         std::string           ogreLogFile_;              //!< log file name for Ogre log messages
    105         int                   ogreLogLevelTrivial_;      //!< Corresponding Orxonx debug level for LL_TRIVIAL
    106         int                   ogreLogLevelNormal_;       //!< Corresponding Orxonx debug level for LL_NORMAL
    107         int                   ogreLogLevelCritical_;     //!< Corresponding Orxonx debug level for LL_CRITICAL
    108 
    109         // console commands
    110         ConsoleCommand*       ccPrintScreen_;
     77        ConsoleCommand*       ccToggleGUI_;         //!< Console command to toggle GUI
    11178    };
    11279}
  • code/branches/questsystem5/src/orxonox/gamestates/GSIOConsole.cc

    r2087 r2907  
    3636
    3737#include "core/ConsoleCommand.h"
     38#include "core/Game.h"
    3839
    3940namespace orxonox
    4041{
    41     GSIOConsole::GSIOConsole()
    42         : GameState<GSRoot>("ioConsole")
     42    AddGameState(GSIOConsole, "ioConsole");
     43
     44    GSIOConsole::GSIOConsole(const std::string& name)
     45        : GameState(name)
    4346    {
    4447    }
     
    4851    }
    4952
    50     void GSIOConsole::enter()
     53    void GSIOConsole::activate()
    5154    {
     55        {
     56            FunctorMember<GSIOConsole>* functor = createFunctor(&GSIOConsole::loadMenu);
     57            functor->setObject(this);
     58            this->ccLoadMenu_ = createConsoleCommand(functor, "loadMenu");
     59            CommandExecutor::addConsoleCommandShortcut(this->ccLoadMenu_);
     60        }
    5261    }
    5362
    54     void GSIOConsole::leave()
     63    void GSIOConsole::deactivate()
    5564    {
     65        if (this->ccLoadMenu_)
     66        {
     67            delete this->ccLoadMenu_;
     68            this->ccLoadMenu_ = 0;
     69        }
    5670    }
    5771
    58     void GSIOConsole::ticked(const Clock& time)
     72    void GSIOConsole::update(const Clock& time)
    5973    {
     74        std::cout << ">";
    6075        std::string command;
    6176        std::getline(std::cin, command);
    6277        CommandExecutor::execute(command, true);
    63        
    64         tickChild(time);
     78    }
     79
     80    void GSIOConsole::loadMenu()
     81    {
     82        Game::getInstance().popState();
     83        Game::getInstance().requestStates("graphics, mainMenu");
    6584    }
    6685}
  • code/branches/questsystem5/src/orxonox/gamestates/GSIOConsole.h

    r1755 r2907  
    3131
    3232#include "OrxonoxPrereqs.h"
    33 #include <OgrePrerequisites.h>
    3433#include "core/GameState.h"
    35 #include "GSRoot.h"
    3634
    3735namespace orxonox
    3836{
    39     class _OrxonoxExport GSIOConsole : public GameState<GSRoot>
     37    class _OrxonoxExport GSIOConsole : public GameState
    4038    {
    4139    public:
    42         GSIOConsole();
     40        GSIOConsole(const std::string& name);
    4341        ~GSIOConsole();
    4442
     43        void activate();
     44        void deactivate();
     45        void update(const Clock& time);
     46
    4547    private:
    46         void enter();
    47         void leave();
    48         void ticked(const Clock& time);
     48        void loadMenu();
     49
     50        // console commands
     51        ConsoleCommand* ccLoadMenu_;
    4952    };
    5053}
  • code/branches/questsystem5/src/orxonox/gamestates/GSLevel.cc

    r2788 r2907  
    2424 *   Co-authors:
    2525 *      Fabian 'x3n' Landau
     26 *      Benjamin Knecht
    2627 *
    2728 */
     
    3940#include "core/CommandLine.h"
    4041#include "core/ConfigValueIncludes.h"
     42#include "core/Core.h"
    4143#include "core/CoreIncludes.h"
    42 #include "core/Core.h"
     44#include "core/Game.h"
     45#include "core/GameMode.h"
    4346#include "objects/Tickable.h"
    4447#include "objects/Radar.h"
    4548#include "CameraManager.h"
     49#include "GraphicsManager.h"
    4650#include "LevelManager.h"
    4751#include "PlayerManager.h"
    48 #include "objects/quest/QuestManager.h"
    49 #include "overlays/notifications/NotificationManager.h"
     52#include "orxonox/objects/quest/QuestManager.h"
     53#include "orxonox/overlays/notifications/NotificationManager.h"
     54#include "gui/GUIManager.h"
    5055
    5156namespace orxonox
    5257{
    53     SetCommandLineArgument(level, "presentation.oxw").shortcut("l");
    54 
    55     GSLevel::GSLevel()
    56 //        : GameState<GSGraphics>(name)
    57         : keyBinder_(0)
    58         , inputState_(0)
     58    AddGameState(GSLevel, "level");
     59
     60    SetCommandLineArgument(level, "presentation_dm.oxw").shortcut("l");
     61    SetConsoleCommand(GSLevel, showIngameGUI, true);
     62
     63    GSLevel::GSLevel(const std::string& name)
     64        : GameState(name)
     65        , keyBinder_(0)
     66        , gameInputState_(0)
     67        , guiMouseOnlyInputState_(0)
     68        , guiKeysOnlyInputState_(0)
    5969        , radar_(0)
    6070        , startFile_(0)
     
    6676        this->ccKeybind_ = 0;
    6777        this->ccTkeybind_ = 0;
    68 
     78    }
     79
     80    GSLevel::~GSLevel()
     81    {
     82    }
     83
     84    void GSLevel::setConfigValues()
     85    {
     86        SetConfigValue(keyDetectorCallbackCode_, "KeybindBindingStringKeyName=");
     87    }
     88
     89    void GSLevel::activate()
     90    {
    6991        setConfigValues();
    70     }
    71 
    72     GSLevel::~GSLevel()
    73     {
    74     }
    75 
    76     void GSLevel::setConfigValues()
    77     {
    78         SetConfigValue(keyDetectorCallbackCode_, "KeybindBindingStringKeyName=");
    79     }
    80 
    81     void GSLevel::enter(Ogre::Viewport* viewport)
    82     {
    83         if (Core::showsGraphics())
    84         {
    85             inputState_ = InputManager::getInstance().createInputState<SimpleInputState>("game", 20);
     92
     93        if (GameMode::showsGraphics())
     94        {
     95            gameInputState_ = InputManager::getInstance().createInputState<SimpleInputState>("game");
    8696            keyBinder_ = new KeyBinder();
    8797            keyBinder_->loadBindings("keybindings.ini");
    88             inputState_->setHandler(keyBinder_);
     98            gameInputState_->setHandler(keyBinder_);
     99
     100            guiMouseOnlyInputState_ = InputManager::getInstance().createInputState<SimpleInputState>("guiMouseOnly");
     101            guiMouseOnlyInputState_->setMouseHandler(GUIManager::getInstancePtr());
     102
     103            guiKeysOnlyInputState_ = InputManager::getInstance().createInputState<SimpleInputState>("guiKeysOnly");
     104            guiKeysOnlyInputState_->setKeyHandler(GUIManager::getInstancePtr());
    89105
    90106            // create the global CameraManager
    91             assert(viewport);
    92             this->cameraManager_ = new CameraManager(viewport);
     107            this->cameraManager_ = new CameraManager(GraphicsManager::getInstance().getViewport());
    93108
    94109            // Start the Radar
     
    102117        this->notificationManager_ = new NotificationManager();
    103118
    104         if (Core::isMaster())
     119        if (GameMode::isMaster())
    105120        {
    106121            // create the global LevelManager
     
    110125        }
    111126
    112         if (Core::showsGraphics())
    113         {
    114             // TODO: insert slomo console command with
    115             // .accessLevel(AccessLevel::Offline).defaultValue(0, 1.0).axisParamIndex(0).isAxisRelative(false);
    116 
     127        if (GameMode::showsGraphics())
     128        {
    117129            // keybind console command
    118130            FunctorMember<GSLevel>* functor1 = createFunctor(&GSLevel::keybind);
     
    132144    }
    133145
    134     void GSLevel::leave()
     146    void GSLevel::showIngameGUI(bool show)
     147    {
     148        if (show)
     149        {
     150            GUIManager::getInstancePtr()->showGUI("inGameTest");
     151            GUIManager::getInstancePtr()->executeCode("showCursor()");
     152            InputManager::getInstance().requestEnterState("guiMouseOnly");
     153        }
     154        else
     155        {
     156            GUIManager::getInstancePtr()->executeCode("hideGUI(\"inGameTest\")");
     157            GUIManager::getInstancePtr()->executeCode("hideCursor()");
     158            InputManager::getInstance().requestLeaveState("guiMouseOnly");
     159        }
     160    }
     161
     162    void GSLevel::deactivate()
    135163    {
    136164        // destroy console commands
     
    145173            this->ccTkeybind_ = 0;
    146174        }
     175
    147176
    148177        // this call will delete every BaseObject!
     
    152181        //Loader::close();
    153182
    154         if (Core::showsGraphics())
     183        if (GameMode::showsGraphics())
    155184            InputManager::getInstance().requestLeaveState("game");
    156185
    157         if (Core::isMaster())
     186        if (GameMode::isMaster())
    158187            this->unloadLevel();
    159188
     
    194223        }
    195224
    196         if (Core::showsGraphics())
    197         {
    198             inputState_->setHandler(0);
     225        if (GameMode::showsGraphics())
     226        {
     227            gameInputState_->setHandler(0);
     228            guiMouseOnlyInputState_->setHandler(0);
     229            guiKeysOnlyInputState_->setHandler(0);
    199230            InputManager::getInstance().requestDestroyState("game");
    200231            if (this->keyBinder_)
     
    206237    }
    207238
    208     void GSLevel::ticked(const Clock& time)
    209     {
    210         // Commented by 1337: Temporarily moved to GSGraphics.
     239    void GSLevel::update(const Clock& time)
     240    {
     241        // Note: Temporarily moved to GSGraphics.
    211242        //// Call the scene objects
    212243        //for (ObjectList<Tickable>::iterator it = ObjectList<Tickable>::begin(); it; ++it)
     
    251282        Command string that can be executed by the CommandExecutor
    252283        OR: Internal string "KeybindBindingStringKeyName=" used for the second call to identify
    253         the key/button/axis that has been activated. This is configured above in enter().
     284        the key/button/axis that has been activated. This is configured above in activate().
    254285    */
    255286    void GSLevel::keybindInternal(const std::string& command, bool bTemporary)
    256287    {
    257         if (Core::showsGraphics())
     288        if (GameMode::showsGraphics())
    258289        {
    259290            static std::string bindingString = "";
  • code/branches/questsystem5/src/orxonox/gamestates/GSLevel.h

    r2786 r2907  
    2323 *      Reto Grieder
    2424 *   Co-authors:
    25  *      ...
     25 *      Benjamin Knecht
    2626 *
    2727 */
     
    3131
    3232#include "OrxonoxPrereqs.h"
    33 #include <OgrePrerequisites.h>
    3433#include "core/OrxonoxClass.h"
     34#include "core/GameState.h"
    3535
    3636namespace orxonox
    3737{
    38     class _OrxonoxExport GSLevel : public OrxonoxClass
     38    class _OrxonoxExport GSLevel : public GameState, public OrxonoxClass
    3939    {
    40         friend class ClassIdentifier<GSLevel>;
    4140    public:
    42         GSLevel();
     41        GSLevel(const std::string& name);
    4342        ~GSLevel();
     43        void setConfigValues();
     44
     45        void activate();
     46        void deactivate();
     47        void update(const Clock& time);
     48
     49        static void showIngameGUI(bool show);
    4450
    4551    protected:
    46         void enter(Ogre::Viewport* viewport);
    47         void leave();
    48         void ticked(const Clock& time);
    49 
    5052        void loadLevel();
    5153        void unloadLevel();
     
    5658        void keybindInternal(const std::string& command, bool bTemporary);
    5759
    58         KeyBinder*            keyBinder_;        //!< tool that loads and manages the input bindings
    59         SimpleInputState*     inputState_;
    60         Radar*                radar_;            //!< represents the Radar (not the HUD part)
    61         XMLFile*              startFile_;        //!< current hard coded default level
    62         CameraManager*        cameraManager_;
    63         LevelManager*         levelManager_;
    64         PlayerManager*        playerManager_;
    65         QuestManager*          questManager_;
    66         NotificationManager*  notificationManager_;
     60        KeyBinder*            keyBinder_;               //!< tool that loads and manages the input bindings
     61        SimpleInputState*     gameInputState_;          //!< input state for normal ingame playing
     62        SimpleInputState*     guiMouseOnlyInputState_;  //!< input state if we only need the mouse to use the GUI
     63        SimpleInputState*     guiKeysOnlyInputState_;   //!< input state if we only need the keys to use the GUI
     64        Radar*                radar_;                   //!< represents the Radar (not the HUD part)
     65        XMLFile*              startFile_;               //!< current hard coded default level
     66        CameraManager*        cameraManager_;           //!< camera manager for this level
     67        LevelManager*         levelManager_;            //!< global level manager
     68        PlayerManager*        playerManager_;           //!< player manager for this level
     69        QuestManager*         questManager_;            //!< quest manager for this level
     70        NotificationManager*  notificationManager_;     //!< notification manager for this level
    6771
    6872        //##### ConfigValues #####
     
    7276        ConsoleCommand*       ccKeybind_;
    7377        ConsoleCommand*       ccTkeybind_;
    74 
    75     private:
    76         void setConfigValues();
    77 
    7878    };
    7979}
  • code/branches/questsystem5/src/orxonox/gamestates/GSRoot.cc

    r2759 r2907  
    3232#include "util/Exception.h"
    3333#include "util/Debug.h"
    34 #include "core/Core.h"
    35 #include "core/Factory.h"
    36 #include "core/ConfigValueIncludes.h"
    37 #include "core/CoreIncludes.h"
     34#include "core/Clock.h"
     35#include "core/Game.h"
     36#include "core/GameMode.h"
     37#include "core/CommandLine.h"
    3838#include "core/ConsoleCommand.h"
    39 #include "core/CommandLine.h"
    40 #include "core/Shell.h"
    41 #include "core/TclBind.h"
    42 #include "core/TclThreadManager.h"
    43 #include "core/LuaBind.h"
     39#include "tools/TimeFactorListener.h"
    4440#include "tools/Timer.h"
    4541#include "objects/Tickable.h"
    4642
    47 #ifdef ORXONOX_PLATFORM_WINDOWS
    48 #  ifndef WIN32_LEAN_AND_MEAN
    49 #    define WIN32_LEAN_AND_MEAN
    50 #  endif
    51 #  define NOMINMAX // required to stop windows.h screwing up std::min definition
    52 #  include "windows.h"
    53 #endif
    54 
    5543namespace orxonox
    5644{
    57     SetCommandLineArgument(limitToCPU, 1).information("0: off | #cpu");
    58 
    59     GSRoot::GSRoot()
    60         : RootGameState("root")
     45    AddGameState(GSRoot, "root");
     46    SetCommandLineSwitch(console);
     47    // Shortcuts for easy direct loading
     48    SetCommandLineSwitch(server);
     49    SetCommandLineSwitch(client);
     50    SetCommandLineSwitch(dedicated);
     51    SetCommandLineSwitch(standalone);
     52
     53    GSRoot::GSRoot(const std::string& name)
     54        : GameState(name)
    6155        , timeFactor_(1.0f)
    6256        , bPaused_(false)
    6357        , timeFactorPauseBackup_(1.0f)
    64         , tclBind_(0)
    65         , tclThreadManager_(0)
    66         , shell_(0)
    67     {
    68         RegisterRootObject(GSRoot);
    69         setConfigValues();
    70 
     58    {
    7159        this->ccSetTimeFactor_ = 0;
    7260        this->ccPause_ = 0;
     
    7765    }
    7866
    79     void GSRoot::setConfigValues()
    80     {
    81         SetConfigValue(statisticsRefreshCycle_, 250000)
    82             .description("Sets the time in microseconds interval at which average fps, etc. get updated.");
    83         SetConfigValue(statisticsAvgLength_, 1000000)
    84             .description("Sets the time in microseconds interval at which average fps, etc. gets calculated.");
    85     }
    86 
    87     void GSRoot::enter()
    88     {
    89         // creates the class hierarchy for all classes with factories
    90         Factory::createClassHierarchy();
    91 
     67    void GSRoot::activate()
     68    {
    9269        // reset game speed to normal
    93         timeFactor_ = 1.0f;
    94 
    95         // reset frame counter
    96         this->statisticsStartTime_ = 0;
    97         this->statisticsTickTimes_.clear();
    98         this->periodTickTime_ = 0;
    99         this->avgFPS_ = 0.0f;
    100         this->avgTickTime_ = 0.0f;
    101 
    102         // Create the lua interface
    103         this->luaBind_ = new LuaBind();
    104 
    105         // initialise TCL
    106         this->tclBind_ = new TclBind(Core::getMediaPathString());
    107         this->tclThreadManager_ = new TclThreadManager(tclBind_->getTclInterpreter());
    108 
    109         // create a shell
    110         this->shell_ = new Shell();
    111 
    112         // limit the main thread to the first core so that QueryPerformanceCounter doesn't jump
    113         // do this after ogre has initialised. Somehow Ogre changes the settings again (not through
    114         // the timer though).
    115         int limitToCPU = CommandLine::getValue("limitToCPU");
    116         if (limitToCPU > 0)
    117             setThreadAffinity((unsigned int)(limitToCPU - 1));
    118 
    119         {
    120             // add console commands
    121             FunctorMember<GSRoot>* functor = createFunctor(&GSRoot::exitGame);
    122             functor->setObject(this);
    123             this->ccExit_ = createConsoleCommand(functor, "exit");
    124             CommandExecutor::addConsoleCommandShortcut(this->ccExit_);
    125         }
    126 
    127         {
    128             // add console commands
    129             FunctorMember01<GameStateBase, const std::string&>* functor = createFunctor(&GameStateBase::requestState);
    130             functor->setObject(this);
    131             this->ccSelectGameState_ = createConsoleCommand(functor, "selectGameState");
    132             CommandExecutor::addConsoleCommandShortcut(this->ccSelectGameState_);
    133         }
     70        this->timeFactor_ = 1.0f;
    13471
    13572        {
     
    14885            CommandExecutor::addConsoleCommandShortcut(this->ccPause_).accessLevel(AccessLevel::Offline);
    14986        }
    150     }
    151 
    152     void GSRoot::leave()
    153     {
    154         // destroy console commands
    155         delete this->ccExit_;
    156         delete this->ccSelectGameState_;
    157 
    158         delete this->shell_;
    159         delete this->tclThreadManager_;
    160         delete this->tclBind_;
    161 
    162         delete this->luaBind_;
    163 
     87
     88        // Load level directly?
     89        bool loadLevel = false;
     90        if (CommandLine::getValue("standalone").getBool())
     91        {
     92            Game::getInstance().requestStates("graphics, standalone, level");
     93            loadLevel = true;
     94        }
     95        if (CommandLine::getValue("server").getBool())
     96        {
     97            Game::getInstance().requestStates("graphics, server, level");
     98            loadLevel = true;
     99        }
     100        if (CommandLine::getValue("client").getBool())
     101        {
     102            Game::getInstance().requestStates("graphics, client, level");
     103            loadLevel = true;
     104        }
     105        if (CommandLine::getValue("dedicated").getBool())
     106        {
     107            Game::getInstance().requestStates("dedicated, level");
     108            loadLevel = true;
     109        }
     110       
     111        // Determine where to start otherwise
     112        if (!loadLevel && !CommandLine::getValue("console").getBool())
     113        {
     114            // Also load graphics
     115            Game::getInstance().requestState("graphics");
     116        }
     117    }
     118
     119    void GSRoot::deactivate()
     120    {
    164121        if (this->ccSetTimeFactor_)
    165122        {
     
    175132    }
    176133
    177     void GSRoot::ticked(const Clock& time)
    178     {
     134    void GSRoot::update(const Clock& time)
     135    {
     136        if (this->getActivity().topState)
     137        {
     138            // This state can not 'survive' on its own.
     139            // Load a user interface therefore
     140            Game::getInstance().requestState("ioConsole");
     141        }
     142
    179143        uint64_t timeBeforeTick = time.getRealMicroseconds();
    180 
    181         TclThreadManager::getInstance().tick(time.getDeltaTime());
    182144
    183145        for (ObjectList<TimerBase>::iterator it = ObjectList<TimerBase>::begin(); it; ++it)
     
    198160        uint64_t timeAfterTick = time.getRealMicroseconds();
    199161
    200         // STATISTICS
    201         assert(timeAfterTick - timeBeforeTick >= 0 );
    202         statisticsTickInfo tickInfo = {timeAfterTick, timeAfterTick - timeBeforeTick};
    203         statisticsTickTimes_.push_back(tickInfo);
    204         assert(statisticsTickTimes_.back().tickLength==tickInfo.tickLength);
    205         this->periodTickTime_ += tickInfo.tickLength;
    206 
    207         // Ticks GSGraphics or GSDedicated
    208         this->tickChild(time);
    209 
    210         if (timeAfterTick > statisticsStartTime_ + statisticsRefreshCycle_)
    211         {
    212             std::list<statisticsTickInfo>::iterator it = this->statisticsTickTimes_.begin();
    213             assert(it != this->statisticsTickTimes_.end());
    214             int64_t lastTime = timeAfterTick - statisticsAvgLength_;
    215             if ((int64_t)it->tickTime < lastTime)
    216             {
    217                 do
    218                 {
    219                     assert(this->periodTickTime_ > it->tickLength);
    220                     this->periodTickTime_ -= it->tickLength;
    221                     ++it;
    222                     assert(it != this->statisticsTickTimes_.end());
    223                 } while ((int64_t)it->tickTime < lastTime);
    224                 this->statisticsTickTimes_.erase(this->statisticsTickTimes_.begin(), it);
    225             }
    226 
    227             uint32_t framesPerPeriod = this->statisticsTickTimes_.size();
    228             this->avgFPS_ = (float)framesPerPeriod / (timeAfterTick - this->statisticsTickTimes_.front().tickTime) * 1000000.0;
    229             this->avgTickTime_ = (float)this->periodTickTime_ / framesPerPeriod / 1000.0;
    230 
    231             statisticsStartTime_ = timeAfterTick;
    232         }
    233 
    234     }
    235 
    236     /**
    237     @note
    238         The code of this function has been copied and adjusted from OGRE, an open source graphics engine.
    239             (Object-oriented Graphics Rendering Engine)
    240         For the latest info, see http://www.ogre3d.org/
    241 
    242         Copyright (c) 2000-2008 Torus Knot Software Ltd
    243 
    244         OGRE is licensed under the LGPL. For more info, see OGRE license.
    245     */
    246     void GSRoot::setThreadAffinity(unsigned int limitToCPU)
    247     {
    248 #ifdef ORXONOX_PLATFORM_WINDOWS
    249         // Get the current process core mask
    250         DWORD procMask;
    251         DWORD sysMask;
    252 #  if _MSC_VER >= 1400 && defined (_M_X64)
    253         GetProcessAffinityMask(GetCurrentProcess(), (PDWORD_PTR)&procMask, (PDWORD_PTR)&sysMask);
    254 #  else
    255         GetProcessAffinityMask(GetCurrentProcess(), &procMask, &sysMask);
    256 #  endif
    257 
    258         // If procMask is 0, consider there is only one core available
    259         // (using 0 as procMask will cause an infinite loop below)
    260         if (procMask == 0)
    261             procMask = 1;
    262 
    263         // if the core specified with limitToCPU is not available, take the lowest one
    264         if (!(procMask & (1 << limitToCPU)))
    265             limitToCPU = 0;
    266 
    267         // Find the lowest core that this process uses and limitToCPU suggests
    268         DWORD threadMask = 1;
    269         while ((threadMask & procMask) == 0 || (threadMask < (1u << limitToCPU)))
    270             threadMask <<= 1;
    271 
    272         // Set affinity to the first core
    273         SetThreadAffinityMask(GetCurrentThread(), threadMask);
    274 #endif
     162        // Also add our tick time
     163        Game::getInstance().addTickTime(timeAfterTick - timeBeforeTick);
    275164    }
    276165
     
    281170    void GSRoot::setTimeFactor(float factor)
    282171    {
    283         if (Core::isMaster())
     172        if (GameMode::isMaster())
    284173        {
    285174            if (!this->bPaused_)
     
    299188    void GSRoot::pause()
    300189    {
    301         if (Core::isMaster())
     190        if (GameMode::isMaster())
    302191        {
    303192            if (!this->bPaused_)
     
    314203        }
    315204    }
    316 
    317     ////////////////////////
    318     // TimeFactorListener //
    319     ////////////////////////
    320     float TimeFactorListener::timefactor_s = 1.0f;
    321 
    322     TimeFactorListener::TimeFactorListener()
    323     {
    324         RegisterRootObject(TimeFactorListener);
    325     }
    326205}
  • code/branches/questsystem5/src/orxonox/gamestates/GSRoot.h

    r2710 r2907  
    3131
    3232#include "OrxonoxPrereqs.h"
    33 
    34 #include <list>
    35 #include <OgreLog.h>
    36 #include "core/RootGameState.h"
     33#include "core/GameState.h"
    3734#include "core/OrxonoxClass.h"
    3835
    3936namespace orxonox
    4037{
    41     class _OrxonoxExport GSRoot : public RootGameState, public OrxonoxClass
     38    class _OrxonoxExport GSRoot : public GameState
    4239    {
    43         friend class ClassIdentifier<GSRoot>;
    44 
    4540    public:
    46         struct statisticsTickInfo
    47         {
    48             uint64_t    tickTime;
    49             uint32_t    tickLength;
    50         };
    51    
    52     public:
    53         GSRoot();
     41        GSRoot(const std::string& name);
    5442        ~GSRoot();
    5543
    56         void exitGame()
    57         { requestState("root"); }
     44        void activate();
     45        void deactivate();
     46        void update(const Clock& time);
    5847
    5948        // this has to be public because proteced triggers a bug in msvc
     
    6352        float getTimeFactor() { return this->timeFactor_; }
    6453
    65         float getAvgTickTime() { return this->avgTickTime_; }
    66         float getAvgFPS()      { return this->avgFPS_; }
    67 
    68         inline void addTickTime(uint32_t length)
    69             { assert(!this->statisticsTickTimes_.empty()); this->statisticsTickTimes_.back().tickLength += length;
    70               this->periodTickTime_+=length; }
    71 
    7254    private:
    73         void enter();
    74         void leave();
    75         void ticked(const Clock& time);
    76 
    77         void setConfigValues();
    78         void setThreadAffinity(unsigned int limitToCPU);
    79 
    8055        float                 timeFactor_;       //!< A factor that sets the gamespeed. 1 is normal.
    8156        bool                  bPaused_;
    8257        float                 timeFactorPauseBackup_;
    83         TclBind*              tclBind_;
    84         TclThreadManager*     tclThreadManager_;
    85         Shell*                shell_;
    86         LuaBind*              luaBind_;
    87 
    88         // variables for time statistics
    89         uint64_t              statisticsStartTime_;
    90         std::list<statisticsTickInfo>
    91                               statisticsTickTimes_;
    92         uint32_t              periodTickTime_;
    93         float                 avgFPS_;
    94         float                 avgTickTime_;
    95 
    96         // config values
    97         unsigned int          statisticsRefreshCycle_;
    98         unsigned int          statisticsAvgLength_;
    9958
    10059        // console commands
    101         ConsoleCommand*       ccExit_;
    102         ConsoleCommand*       ccSelectGameState_;
    10360        ConsoleCommand*       ccSetTimeFactor_;
    10461        ConsoleCommand*       ccPause_;
    105     };
    106 
    107     class _OrxonoxExport TimeFactorListener : virtual public OrxonoxClass
    108     {
    109         friend class GSRoot;
    110 
    111         public:
    112             TimeFactorListener();
    113             virtual ~TimeFactorListener() {}
    114 
    115         protected:
    116             virtual void changedTimeFactor(float factor_new, float factor_old) {}
    117             inline float getTimeFactor() const
    118                 { return TimeFactorListener::timefactor_s; }
    119 
    120         private:
    121             static float timefactor_s;
    12262    };
    12363}
  • code/branches/questsystem5/src/orxonox/gamestates/GSServer.cc

    r2171 r2907  
    3131
    3232#include "core/CommandLine.h"
    33 #include "core/Core.h"
     33#include "core/Game.h"
     34#include "core/GameMode.h"
    3435#include "network/Server.h"
    3536
    3637namespace orxonox
    3738{
     39    AddGameState(GSServer, "server");
     40
    3841    SetCommandLineArgument(port, 55556).shortcut("p").information("0-65535");
    3942
    40     GSServer::GSServer()
    41         : GameState<GSGraphics>("server")
     43    GSServer::GSServer(const std::string& name)
     44        : GameState(name)
    4245        , server_(0)
    4346    {
     
    4851    }
    4952
    50     void GSServer::enter()
     53    void GSServer::activate()
    5154    {
    52         Core::setHasServer(true);
     55        GameMode::setHasServer(true);
    5356
    5457        this->server_ = new Server(CommandLine::getValue("port"));
    5558        COUT(0) << "Loading scene in server mode" << std::endl;
    5659
    57         GSLevel::enter(this->getParent()->getViewport());
    58 
    5960        server_->open();
    6061    }
    6162
    62     void GSServer::leave()
     63    void GSServer::deactivate()
    6364    {
    64         GSLevel::leave();
    65 
    6665        this->server_->close();
    6766        delete this->server_;
    6867
    69         Core::setHasServer(false);
     68        GameMode::setHasServer(false);
    7069    }
    7170
    72     void GSServer::ticked(const Clock& time)
     71    void GSServer::update(const Clock& time)
    7372    {
    74         GSLevel::ticked(time);
    75         server_->tick(time.getDeltaTime());
    76         this->tickChild(time);
     73        server_->update(time);
    7774    }
    7875}
  • code/branches/questsystem5/src/orxonox/gamestates/GSServer.h

    r2171 r2907  
    3131
    3232#include "OrxonoxPrereqs.h"
     33#include "core/GameState.h"
    3334#include "network/NetworkPrereqs.h"
    34 #include "GSLevel.h"
    35 #include "GSGraphics.h"
    3635
    3736namespace orxonox
    3837{
    39     class _OrxonoxExport GSServer : public GameState<GSGraphics>, public GSLevel
     38    class _OrxonoxExport GSServer : public GameState
    4039    {
    4140    public:
    42         GSServer();
     41        GSServer(const std::string& name);
    4342        ~GSServer();
    4443
     44        void activate();
     45        void deactivate();
     46        void update(const Clock& time);
     47
    4548    private:
    46         void enter();
    47         void leave();
    48         void ticked(const Clock& time);
    49 
    50         Server*      server_;
     49        Server* server_;
    5150    };
    5251}
  • code/branches/questsystem5/src/orxonox/gamestates/GSStandalone.cc

    r2087 r2907  
    3030#include "GSStandalone.h"
    3131
    32 #include "core/Core.h"
     32#include <OgreViewport.h>
     33#include <OgreCamera.h>
     34#include "core/Game.h"
     35#include "core/GameMode.h"
     36#include "core/ConsoleCommand.h"
     37#include "gui/GUIManager.h"
     38#include "GraphicsManager.h"
    3339
    3440namespace orxonox
    3541{
    36     GSStandalone::GSStandalone()
    37         : GameState<GSGraphics>("standalone")
     42    AddGameState(GSStandalone, "standalone");
     43
     44    GSStandalone::GSStandalone(const std::string& name)
     45        : GameState(name)
    3846    {
    3947    }
     
    4351    }
    4452
    45     void GSStandalone::enter()
     53
     54    void GSStandalone::activate()
    4655    {
    47         Core::setIsStandalone(true);
    48 
    49         GSLevel::enter(this->getParent()->getViewport());
     56        GameMode::setIsStandalone(true);
    5057    }
    5158
    52     void GSStandalone::leave()
     59    void GSStandalone::deactivate()
    5360    {
    54         GSLevel::leave();
    55 
    56         Core::setIsStandalone(false);
     61        GameMode::setIsStandalone(false);
    5762    }
    5863
    59     void GSStandalone::ticked(const Clock& time)
     64    void GSStandalone::update(const Clock& time)
    6065    {
    61         GSLevel::ticked(time);
    62         this->tickChild(time);
    6366    }
    6467}
  • code/branches/questsystem5/src/orxonox/gamestates/GSStandalone.h

    r2087 r2907  
    3131
    3232#include "OrxonoxPrereqs.h"
    33 #include "GSLevel.h"
    34 #include "GSGraphics.h"
     33#include "core/GameState.h"
    3534
    3635namespace orxonox
    3736{
    38     class _OrxonoxExport GSStandalone : public GameState<GSGraphics>, public GSLevel
     37    class _OrxonoxExport GSStandalone : public GameState
    3938    {
    4039    public:
    41         GSStandalone();
     40        GSStandalone(const std::string& name);
    4241        ~GSStandalone();
    4342
     43        void activate();
     44        void deactivate();
     45        void update(const Clock& time);
     46
    4447    private:
    45         void enter();
    46         void leave();
    47         void ticked(const Clock& time);
    4848    };
    4949}
Note: See TracChangeset for help on using the changeset viewer.