Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2850


Ignore:
Timestamp:
Mar 25, 2009, 11:53:04 PM (16 years ago)
Author:
rgrieder
Message:
  • Started working on cleaning up the GameState mess ;)
  • Cleaned out GUIManager
  • Renamed GSGUI to GSMainMenu
  • "—state blah" has been changed to —server, —client, —standalone, —dedicated
  • —console starts the game in the console (no level loading there yet, but "loadMenu")
  • adjusted run scripts
Location:
code/branches/gui
Files:
26 edited
2 moved

Legend:

Unmodified
Added
Removed
  • code/branches/gui/bin/client1.bat.in

    r2799 r2850  
    11title @PROJECT_NAME@
    22path @ORXONOX_RUNTIME_LIBRARY_DIRECTORY_WINDOWS@;%path%
    3 @CURRENT_RUNTIME_DIR_WINDOWS@\@ORXONOX_EXECUTABLE_NAME@ --state client --writingPathSuffix client1
     3@CURRENT_RUNTIME_DIR_WINDOWS@\@ORXONOX_EXECUTABLE_NAME@ --client --writingPathSuffix client1
    44pause
  • code/branches/gui/bin/client1.in

    r2799 r2850  
    22# convenience script for starting orxonox on Linux
    33
    4 exec @CURRENT_RUNTIME_DIR@/@ORXONOX_EXECUTABLE_NAME@ --state client --writingPathSuffix client1 $@
     4exec @CURRENT_RUNTIME_DIR@/@ORXONOX_EXECUTABLE_NAME@ --client --writingPathSuffix client1 $@
  • code/branches/gui/bin/client2.bat.in

    r2799 r2850  
    11title @PROJECT_NAME@
    22path @ORXONOX_RUNTIME_LIBRARY_DIRECTORY_WINDOWS@;%path%
    3 @CURRENT_RUNTIME_DIR_WINDOWS@\@ORXONOX_EXECUTABLE_NAME@ --state client --writingPathSuffix client2
     3@CURRENT_RUNTIME_DIR_WINDOWS@\@ORXONOX_EXECUTABLE_NAME@ --client --writingPathSuffix client2
    44pause
  • code/branches/gui/bin/client2.in

    r2799 r2850  
    22# convenience script for starting orxonox on Linux
    33
    4 exec @CURRENT_RUNTIME_DIR@/@ORXONOX_EXECUTABLE_NAME@ --state client --writingPathSuffix client2 $@
     4exec @CURRENT_RUNTIME_DIR@/@ORXONOX_EXECUTABLE_NAME@ --client --writingPathSuffix client2 $@
  • code/branches/gui/bin/dedicated.bat.in

    r2799 r2850  
    11title @PROJECT_NAME@
    22path @ORXONOX_RUNTIME_LIBRARY_DIRECTORY_WINDOWS@;%path%
    3 @CURRENT_RUNTIME_DIR_WINDOWS@\@ORXONOX_EXECUTABLE_NAME@ --state dedicated --writingPathSuffix dedicated
     3@CURRENT_RUNTIME_DIR_WINDOWS@\@ORXONOX_EXECUTABLE_NAME@ --dedicated --writingPathSuffix dedicated
    44pause
  • code/branches/gui/bin/dedicated.in

    r2799 r2850  
    22# convenience script for starting orxonox on Linux
    33
    4 exec @CURRENT_RUNTIME_DIR@/@ORXONOX_EXECUTABLE_NAME@ --state dedicated --writingPathSuffix dedicated $@
     4exec @CURRENT_RUNTIME_DIR@/@ORXONOX_EXECUTABLE_NAME@ --dedicated --writingPathSuffix dedicated $@
  • code/branches/gui/bin/server.bat.in

    r2799 r2850  
    11title @PROJECT_NAME@
    22path @ORXONOX_RUNTIME_LIBRARY_DIRECTORY_WINDOWS@;%path%
    3 @CURRENT_RUNTIME_DIR_WINDOWS@\@ORXONOX_EXECUTABLE_NAME@ --state server --writingPathSuffix server
     3@CURRENT_RUNTIME_DIR_WINDOWS@\@ORXONOX_EXECUTABLE_NAME@ --server --writingPathSuffix server
    44pause
  • code/branches/gui/bin/server.in

    r2799 r2850  
    22# convenience script for starting orxonox on Linux
    33
    4 exec @CURRENT_RUNTIME_DIR@/@ORXONOX_EXECUTABLE_NAME@ --state server --writingPathSuffix server $@
     4exec @CURRENT_RUNTIME_DIR@/@ORXONOX_EXECUTABLE_NAME@ --server --writingPathSuffix server $@
  • code/branches/gui/bin/standalone.bat.in

    r2799 r2850  
    11title @PROJECT_NAME@
    22path @ORXONOX_RUNTIME_LIBRARY_DIRECTORY_WINDOWS@;%path%
    3 @CURRENT_RUNTIME_DIR_WINDOWS@\@ORXONOX_EXECUTABLE_NAME@ --state standalone --writingPathSuffix standalone
     3@CURRENT_RUNTIME_DIR_WINDOWS@\@ORXONOX_EXECUTABLE_NAME@ --standalone --writingPathSuffix standalone
    44pause
  • code/branches/gui/bin/standalone.in

    r2799 r2850  
    22# convenience script for starting orxonox on Linux
    33
    4 exec @CURRENT_RUNTIME_DIR@/@ORXONOX_EXECUTABLE_NAME@ --state standalone --writingPathSuffix standalone $@
     4exec @CURRENT_RUNTIME_DIR@/@ORXONOX_EXECUTABLE_NAME@ --standalone --writingPathSuffix standalone $@
  • code/branches/gui/src/core/Game.cc

    r2846 r2850  
    4040#include "util/Debug.h"
    4141#include "util/Exception.h"
     42#include "util/SubString.h"
    4243#include "Clock.h"
    4344#include "CommandLine.h"
     
    247248        // Check parent and all its grand parents
    248249        GameStateTreeNode* currentNode = lastRequestedNode;
    249         while (requestedNode == NULL && currentNode->parent_ != NULL)
     250        while (requestedNode == NULL && currentNode != NULL)
    250251        {
    251252            if (currentNode->state_ == state)
     
    260261    }
    261262
     263    void Game::requestStates(const std::string& names)
     264    {
     265        SubString tokens(names, ",;", " ");
     266        for (unsigned int i = 0; i < tokens.size(); ++i)
     267            this->requestState(tokens[i]);
     268    }
     269
    262270    void Game::popState()
    263271    {
     
    270278    GameState* Game::getState(const std::string& name)
    271279    {
    272         std::map<std::string, GameState*>::const_iterator it = allStates_s.find(name);
     280        std::map<std::string, GameState*>::const_iterator it = allStates_s.find(getLowercase(name));
    273281        if (it != allStates_s.end())
    274282            return it->second;
     
    356364    void Game::loadState(GameState* state)
    357365    {
     366        if (!this->activeStates_.empty())
     367            this->activeStates_.back()->activity_.topState = false;
    358368        state->activate();
     369        state->activity_.topState = true;
    359370        this->activeStates_.push_back(state);
    360371    }
     
    362373    void Game::unloadState(orxonox::GameState* state)
    363374    {
     375        state->activity_.topState = false;
    364376        state->deactivate();
    365377        this->activeStates_.pop_back();
     378        if (!this->activeStates_.empty())
     379            this->activeStates_.back()->activity_.topState = true;
    366380    }
    367381
    368382    /*static*/ bool Game::addGameState(GameState* state)
    369383    {
    370         std::map<std::string, GameState*>::const_iterator it = allStates_s.find(state->getName());
     384        std::map<std::string, GameState*>::const_iterator it = allStates_s.find(getLowercase(state->getName()));
    371385        if (it == allStates_s.end())
    372             allStates_s[state->getName()] = state;
     386            allStates_s[getLowercase(state->getName())] = state;
    373387        else
    374388            ThrowException(GameState, "Cannot add two GameStates with the same name to 'Game'.");
  • code/branches/gui/src/core/Game.h

    r2846 r2850  
    6666
    6767        void requestState(const std::string& name);
     68        void requestStates(const std::string& names);
    6869        void popState();
    6970
  • code/branches/gui/src/core/GameState.cc

    r2844 r2850  
    4949        , parent_(0)
    5050    {
    51         State temp = {false, false, false, false, false};
    52         this->activity_ = temp;
     51        this->activity_.activating   = false;
     52        this->activity_.active       = false;
     53        this->activity_.deactivating = false;
     54        this->activity_.suspended    = false;
     55        this->activity_.topState     = false;
     56        this->activity_.updating     = false;
    5357    }
    5458
  • code/branches/gui/src/core/GameState.h

    r2844 r2850  
    7474            unsigned updating     : 1;
    7575            unsigned suspended    : 1;
     76            unsigned topState     : 1;
    7677        };
    7778
     
    8182
    8283        const std::string& getName() const { return name_; }
    83         const State getActivity() const    { return this->activity_; }
     84        State getActivity() const    { return this->activity_; }
    8485        GameState* getParent() const       { return this->parent_; }
    8586
  • code/branches/gui/src/orxonox/CameraManager.cc

    r2848 r2850  
    142142
    143143        this->viewport_->setCamera(camera);
    144         GUIManager::getInstancePtr()->setCamera(camera);
     144        GUIManager::getInstance().setCamera(camera);
    145145
    146146        // reactivate all visible compositors
  • code/branches/gui/src/orxonox/GraphicsManager.cc

    r2848 r2850  
    216216    }
    217217
     218    void GraphicsManager::setCamera(Ogre::Camera* camera)
     219    {
     220        this->viewport_->setCamera(camera);
     221    }
     222
    218223    /**
    219224    @brief
  • code/branches/gui/src/orxonox/GraphicsManager.h

    r2817 r2850  
    6666            { return this->detailLevelParticle_; }
    6767
    68         inline void setViewport(Ogre::Viewport* viewport)
    69             { this->viewport_ = viewport; }
    7068        inline Ogre::Viewport* getViewport() const
    7169            { return this->viewport_; }
     
    7371            { return this->renderWindow_; }
    7472
     73        void setCamera(Ogre::Camera* camera);
     74
    7575        static GraphicsManager& getInstance() { assert(singletonRef_s); return *singletonRef_s; }
    76 
    7776
    7877    private:
  • code/branches/gui/src/orxonox/gamestates/CMakeLists.txt

    r2710 r2850  
    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/gui/src/orxonox/gamestates/GSGraphics.cc

    r2848 r2850  
    3535#include "util/Debug.h"
    3636#include "core/ConfigValueIncludes.h"
     37#include "core/Clock.h"
    3738#include "core/Core.h"
    3839#include "core/CoreIncludes.h"
     
    146147        this->inputManager_->update(time);        // tick console
    147148        this->console_->update(time);
     149        this->guiManager_->update(time);
    148150
    149151        uint64_t timeAfterTick = time.getRealMicroseconds();
     
    152154        Game::getInstance().addTickTime(timeAfterTick - timeBeforeTick);
    153155
     156        // Render
    154157        this->graphicsManager_->update(time);
    155158    }
  • code/branches/gui/src/orxonox/gamestates/GSIOConsole.cc

    r2844 r2850  
    5353    void GSIOConsole::activate()
    5454    {
     55        {
     56            FunctorMember<GSIOConsole>* functor = createFunctor(&GSIOConsole::loadMenu);
     57            functor->setObject(this);
     58            this->ccLoadMenu_ = createConsoleCommand(functor, "loadMenu");
     59            CommandExecutor::addConsoleCommandShortcut(this->ccLoadMenu_);
     60        }
    5561    }
    5662
    5763    void GSIOConsole::deactivate()
    5864    {
     65        if (this->ccLoadMenu_)
     66        {
     67            delete this->ccLoadMenu_;
     68            this->ccLoadMenu_ = 0;
     69        }
    5970    }
    6071
    6172    void GSIOConsole::update(const Clock& time)
    6273    {
     74        std::cout << ">";
    6375        std::string command;
    6476        std::getline(std::cin, command);
    6577        CommandExecutor::execute(command, true);
    6678    }
     79
     80    void GSIOConsole::loadMenu()
     81    {
     82        Game::getInstance().popState();
     83        Game::getInstance().requestStates("graphics, mainMenu");
     84    }
    6785}
  • code/branches/gui/src/orxonox/gamestates/GSIOConsole.h

    r2844 r2850  
    4646
    4747    private:
     48        void loadMenu();
    4849
     50        // console commands
     51        ConsoleCommand* ccLoadMenu_;
    4952    };
    5053}
  • code/branches/gui/src/orxonox/gamestates/GSLevel.cc

    r2848 r2850  
    4949#include "LevelManager.h"
    5050#include "PlayerManager.h"
     51#include "gui/GUIManager.h"
    5152
    5253namespace orxonox
     
    8687        if (GameMode::showsGraphics())
    8788        {
     89            {
     90                FunctorMember<GSLevel>* functor = createFunctor(&GSLevel::toggleGUI);
     91                functor->setObject(this);
     92                this->ccToggleGUI_ = createConsoleCommand(functor, "toggleGUI");
     93                CommandExecutor::addConsoleCommandShortcut(this->ccToggleGUI_);
     94            }
     95
    8896            inputState_ = InputManager::getInstance().createInputState<SimpleInputState>("game");
    8997            keyBinder_ = new KeyBinder();
     
    110118        if (GameMode::showsGraphics())
    111119        {
    112             // TODO: insert slomo console command with
    113             // .accessLevel(AccessLevel::Offline).defaultValue(0, 1.0).axisParamIndex(0).isAxisRelative(false);
    114 
    115120            // keybind console command
    116121            FunctorMember<GSLevel>* functor1 = createFunctor(&GSLevel::keybind);
     
    125130            InputManager::getInstance().setKeyDetectorCallback(std::string("keybind ") + keyDetectorCallbackCode_);
    126131
     132            // InGame GUI test
     133            GUIManager::getInstance().showGUI("inGameTest");
     134
    127135            // level is loaded: we can start capturing the input
    128136            InputManager::getInstance().requestEnterState("game");
     
    143151            this->ccTkeybind_ = 0;
    144152        }
     153        if (this->ccToggleGUI_)
     154        {
     155            delete this->ccToggleGUI_;
     156            this->ccToggleGUI_ = 0;
     157        }
     158
    145159
    146160        // this call will delete every BaseObject!
     
    219233
    220234        delete this->startFile_;
     235    }
     236
     237    void GSLevel::toggleGUI()
     238    {
     239        if (GameMode::showsGraphics())
     240        {
     241            GUIManager::getInstance().executeCode("toggleGUI()");
     242        }
    221243    }
    222244
  • code/branches/gui/src/orxonox/gamestates/GSLevel.h

    r2844 r2850  
    4747        void update(const Clock& time);
    4848
     49        void toggleGUI();
     50
    4951    protected:
    5052        void loadLevel();
     
    7072        ConsoleCommand*       ccKeybind_;
    7173        ConsoleCommand*       ccTkeybind_;
    72 
     74        ConsoleCommand*       ccToggleGUI_;
    7375    };
    7476}
  • code/branches/gui/src/orxonox/gamestates/GSMainMenu.cc

    r2848 r2850  
    2828
    2929#include "OrxonoxStableHeaders.h"
    30 #include "GSGUI.h"
     30#include "GSMainMenu.h"
    3131
    32 #include <OgreViewport.h>
     32//#include <OgreViewport.h>
     33#include <OgreSceneManager.h>
    3334#include "core/Clock.h"
    3435#include "core/ConsoleCommand.h"
     
    3738#include "core/input/SimpleInputState.h"
    3839#include "gui/GUIManager.h"
     40#include "objects/Scene.h"
    3941#include "GraphicsManager.h"
    4042
    4143namespace orxonox
    4244{
    43     AddGameState(GSGUI, "mainMenu");
     45    AddGameState(GSMainMenu, "mainMenu");
    4446
    45     GSGUI::GSGUI(const std::string& name)
     47    GSMainMenu::GSMainMenu(const std::string& name)
    4648        : GameState(name)
     49        , inputState_(0)
    4750    {
    4851    }
    4952
    50     GSGUI::~GSGUI()
     53    GSMainMenu::~GSMainMenu()
    5154    {
    5255    }
    5356
    54     void GSGUI::activate()
     57    void GSMainMenu::activate()
    5558    {
    56         guiManager_ = GUIManager::getInstancePtr();
     59        inputState_ = InputManager::getInstance().createInputState<SimpleInputState>("mainMenu");
     60        inputState_->setHandler(GUIManager::getInstancePtr());
     61        inputState_->setJoyStickHandler(&InputManager::EMPTY_HANDLER);
     62
     63        // create an empty Scene
     64        this->scene_ = new Scene(0);
     65        // and a Camera
     66        this->camera_ = this->scene_->getSceneManager()->createCamera("mainMenu/Camera");
    5767
    5868        // show main menu
    59         //guiManager_->loadScene("MainMenu");
    60         guiManager_->showGUI("MainMenu", 0);
    61         GraphicsManager::getInstance().getViewport()->setCamera(guiManager_->getCamera());
     69        GUIManager::getInstance().showGUI("mainMenu");
     70        GUIManager::getInstance().setCamera(this->camera_);
     71        GraphicsManager::getInstance().setCamera(this->camera_);
    6272
    6373        {
    64             // time factor console command
    65             FunctorMember<GSGUI>* functor = createFunctor(&GSGUI::startGame);
     74            FunctorMember<GSMainMenu>* functor = createFunctor(&GSMainMenu::startGame);
    6675            functor->setObject(this);
    6776            this->ccStartGame_ = createConsoleCommand(functor, "startGame");
    6877            CommandExecutor::addConsoleCommandShortcut(this->ccStartGame_);
    6978        }
     79       
     80        InputManager::getInstance().requestEnterState("mainMenu");
    7081    }
    7182
    72     void GSGUI::deactivate()
     83    void GSMainMenu::deactivate()
    7384    {
     85        InputManager::getInstance().requestLeaveState("game");
     86        InputManager::getInstance().requestDestroyState("game");
     87
    7488        if (this->ccStartGame_)
    7589        {
     
    7892        }
    7993
    80         guiManager_->hideGUI();
     94        GUIManager::getInstance().executeCode("hideGUI()");
    8195    }
    8296
    83     void GSGUI::update(const Clock& time)
     97    void GSMainMenu::update(const Clock& time)
    8498    {
    85         // tick CEGUI
    86         guiManager_->update(time);
    8799    }
    88100
    89     void GSGUI::startGame()
     101    void GSMainMenu::startGame()
    90102    {
    91103        // HACK - HACK
    92104        Game::getInstance().popState();
    93         Game::getInstance().requestState("standalone");
    94         Game::getInstance().requestState("level");
     105        Game::getInstance().requestStates("standalone, level");
    95106    }
    96107}
  • code/branches/gui/src/orxonox/gamestates/GSMainMenu.h

    r2844 r2850  
    2727 */
    2828
    29 #ifndef _GSGUI_H__
    30 #define _GSGUI_H__
     29#ifndef _GSMainMenu_H__
     30#define _GSMainMenu_H__
    3131
    3232#include "OrxonoxPrereqs.h"
     33#include <OgrePrerequisites.h>
    3334#include "core/GameState.h"
    3435
    3536namespace orxonox
    3637{
    37     class _OrxonoxExport GSGUI : public GameState
     38    class _OrxonoxExport GSMainMenu : public GameState
    3839    {
    3940    public:
    40         GSGUI(const std::string& name);
    41         ~GSGUI();
     41        GSMainMenu(const std::string& name);
     42        ~GSMainMenu();
    4243
    4344        void activate();
     
    4849
    4950    private:
    50         GUIManager* guiManager_;
     51        SimpleInputState* inputState_;
     52        Scene*            scene_;
     53        Ogre::Camera*     camera_;
    5154
    5255        // console commands
     
    5558}
    5659
    57 #endif /* _GSGUI_H__ */
     60#endif /* _GSMainMenu_H__ */
  • code/branches/gui/src/orxonox/gamestates/GSRoot.cc

    r2848 r2850  
    4444{
    4545    AddGameState(GSRoot, "root");
    46     SetCommandLineSwitch(startWithConsole);
     46    SetCommandLineSwitch(console);
     47    // Shortcuts for easy direct loading
     48    SetCommandLineSwitch(server);
     49    SetCommandLineSwitch(client);
     50    SetCommandLineSwitch(dedicated);
     51    SetCommandLineSwitch(standalone);
    4752
    4853    GSRoot::GSRoot(const std::string& name)
     
    6368    {
    6469        // reset game speed to normal
    65         timeFactor_ = 1.0f;
     70        this->timeFactor_ = 1.0f;
    6671
    6772        {
     
    8186        }
    8287
     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, standalone, level");
     103            loadLevel = true;
     104        }
     105        if (CommandLine::getValue("dedicated").getBool())
     106        {
     107            Game::getInstance().requestStates("dedicated, level");
     108            loadLevel = true;
     109        }
     110       
    83111        // Determine where to start
    84         if (CommandLine::getValue("startWithConsole").getBool())
    85         {
    86             // Start the game in the console
    87             Game::getInstance().requestState("ioConsole");
    88         }
    89         else
    90         {
    91             // Start in GUI main menu
    92             Game::getInstance().requestState("graphics");
    93             Game::getInstance().requestState("mainMenu");
    94         }
    95 
     112        if (!loadLevel)
     113        {
     114            if (CommandLine::getValue("console").getBool())
     115            {
     116                // Start the game in the console without 3D graphics
     117                Game::getInstance().requestState("ioConsole");
     118            }
     119            else
     120            {
     121                // Start in GUI mode
     122                Game::getInstance().requestStates("graphics, mainMenu");
     123            }
     124        }
    96125    }
    97126
     
    113142    void GSRoot::update(const Clock& time)
    114143    {
     144        if (this->getActivity().topState)
     145        {
     146            // This state can not 'survive' on its own.
     147            // Load a user interface therefore
     148            Game::getInstance().requestState("ioConsole");
     149        }
     150
    115151        uint64_t timeBeforeTick = time.getRealMicroseconds();
    116152
     
    132168        uint64_t timeAfterTick = time.getRealMicroseconds();
    133169
    134         // Also add our tick time to the list in GSRoot
     170        // Also add our tick time
    135171        Game::getInstance().addTickTime(timeAfterTick - timeBeforeTick);
    136172    }
  • code/branches/gui/src/orxonox/gui/GUIManager.cc

    r2841 r2850  
    3636#include "GUIManager.h"
    3737
    38 #include <boost/filesystem.hpp>
     38#include <boost/filesystem/path.hpp>
    3939#include <OgreRenderWindow.h>
    40 #include <OgreRoot.h>
    4140#include <CEGUI.h>
    4241#include <CEGUIDefaultLogger.h>
     
    5049
    5150#include "util/Exception.h"
    52 #include "core/input/InputManager.h"
    53 #include "core/input/SimpleInputState.h"
    5451#include "core/ConsoleCommand.h"
    5552#include "core/Core.h"
     53#include "core/Clock.h"
    5654#include "ToluaBindCore.h"
    5755#include "ToluaBindOrxonox.h"
     
    6361namespace orxonox
    6462{
    65     SetConsoleCommandShortcut(GUIManager, toggleGUI).keybindMode(KeybindMode::OnPress);
    66 
    6763    GUIManager* GUIManager::singletonRef_s = 0;
    6864
    6965    GUIManager::GUIManager()
    70         //: emptySceneManager_(0)
    71         : backgroundSceneManager_(0)
    72         //, emptyCamera_(0)
    73         , backgroundCamera_(0)
    74         //, viewport_(0)
    75         , renderWindow_(0)
     66        : renderWindow_(0)
    7667        , guiRenderer_(0)
    7768        , resourceProvider_(0)
     
    8677    GUIManager::~GUIManager()
    8778    {
    88         if (backgroundCamera_)
    89             backgroundSceneManager_->destroyCamera(backgroundCamera_);
    90 
    91         if (backgroundSceneManager_)
    92         {
    93             // We have to make sure the SceneManager is not anymore referenced.
    94             // For the case that the target SceneManager was yet another one, it
    95             // wouldn't matter anyway since this is the destructor.
    96             guiRenderer_->setTargetSceneManager(0);
    97             Ogre::Root::getSingleton().destroySceneManager(backgroundSceneManager_);
    98         }
    99 
    100         InputManager::getInstance().requestDestroyState("gui");
    101 
    10279        if (guiSystem_)
    10380            delete guiSystem_;
     
    11087                lua_pushnil(luaState_);
    11188                lua_setglobal(luaState_, "Core");
    112             // TODO: deleting the script module fails an assertion.
    113             // However there is not much we can do about it since it occurs too when
    114             // we don't open Core or Orxonox. Might be a CEGUI issue.
    115             // The memory leak is not a problem anyway..
    11689            delete scriptModule_;
    11790        }
     
    134107                // save the render window
    135108                renderWindow_ = renderWindow;
    136 
    137                 // Full screen viewport with Z order = 0 (top most). Don't yet feed a camera (so nothing gets rendered)
    138                 //this->viewport_ = renderWindow_->addViewport(0, 3);
    139                 //this->viewport_->setOverlaysEnabled(false);
    140                 //this->viewport_->setShadowsEnabled(false);
    141                 //this->viewport_->setSkiesEnabled(false);
    142                 //this->viewport_->setClearEveryFrame(false);
    143109
    144110                // Note: No SceneManager specified yet
     
    166132                tolua_Orxonox_open(this->scriptModule_->getLuaState());
    167133
    168                 // register us as input handler
    169                 SimpleInputState* state = InputManager::getInstance().createInputState<SimpleInputState>("gui");
    170                 state->setHandler(this);
    171                 state->setJoyStickHandler(&InputManager::EMPTY_HANDLER);
    172 
    173                 // load the background scene
    174                 loadScenes();
    175                 //CEGUI::KeyEventArgs e;
    176                 //e.codepoint
     134                // initialise the basic lua code
     135                loadLuaCode();
    177136            }
    178137            catch (CEGUI::Exception& ex)
     
    187146
    188147            state_ = Ready;
    189 
    190148        }
    191149
     
    193151    }
    194152
    195     void GUIManager::loadScene(const std::string& name)
    196     {
    197         if (name.compare("IngameMenu") == 0)
    198         {
    199             try
    200             {
    201                 /*this->scriptModule_ = new LuaScriptModule();
    202                 this->luaState_ = this->scriptModule_->getLuaState();
    203                 this->guiSystem_ = new System(this->guiRenderer_, this->resourceProvider_, 0, this->scriptModule_);
    204                 tolua_Core_open(this->scriptModule_->getLuaState());
    205                 tolua_Orxonox_open(this->scriptModule_->getLuaState());
    206                 */
    207                 this->scriptModule_->executeScriptFile("loadGUI_2.lua", "GUI");
    208             }
    209             catch (CEGUI::Exception& ex)
    210             {
    211 #if CEGUI_VERSION_MINOR < 6
    212                 throw GeneralException(ex.getMessage().c_str());
    213 #else
    214                 throw GeneralException(ex.getMessage().c_str(), ex.getLine(),
    215                                        ex.getFileName().c_str(), ex.getName().c_str());
    216 #endif
    217             }
    218         }
    219         else
    220         {
    221             loadScenes();
    222         }
    223     }
    224 
    225     void GUIManager::loadScenes()
    226     {
    227         // first of all, we need to have our own SceneManager for the GUI. The reason
    228         // is that we might have multiple viewports when in play mode (e.g. the view of
    229         // a camera fixed at the back of the ship). That forces us to create our own
    230         // full screen viewport that is on top of all the others, but doesn't clear the
    231         // port before rendering, so everything from the GUI gets on top eventually.
    232         // But in order to realise that, we also need a SceneManager with an empty scene,
    233         // because the SceneManager is responsible for the render queue.
    234         //this->emptySceneManager_ = Ogre::Root::getSingleton()
    235         //    .createSceneManager(Ogre::ST_GENERIC, "GUI/EmptySceneManager");
    236 
    237         // we also need a camera or we won't see anything at all.
    238         // The camera settings don't matter at all for an empty scene since the GUI
    239         // gets rendered on top of the screen rather than into the scene.
    240         //this->emptyCamera_ = this->emptySceneManager_->createCamera("GUI/EmptyCamera");
    241 
    242         // Create another SceneManager that enables to display some 3D
    243         // scene in the background of the main menu.
    244         this->backgroundSceneManager_ = Ogre::Root::getSingleton()
    245             .createSceneManager(Ogre::ST_GENERIC, "GUI/BackgroundSceneManager");
    246         this->backgroundCamera_ = backgroundSceneManager_->createCamera("GUI/BackgroundCamera");
    247 
    248         // TODO: create something 3D
     153    void GUIManager::loadLuaCode()
     154    {
    249155        try
    250156        {
     
    264170    }
    265171
    266     void GUIManager::toggleGUI()
    267     {
    268         //COUT(0) << "********* TOGGLE TOGGLE **********" << std::endl;
    269         if (getInstance().scriptModule_->executeScriptGlobal("toggleGUI"))
    270             InputManager::getInstance().requestEnterState("gui");
    271         else
    272             InputManager::getInstance().requestLeaveState("gui");
     172    void GUIManager::update(const Clock& time)
     173    {
     174        assert(guiSystem_);
     175        guiSystem_->injectTimePulse(time.getDeltaTime());
     176    }
     177
     178    void GUIManager::executeCode(const std::string& str)
     179    {
     180        this->scriptModule_->executeString(str);
    273181    }
    274182
     
    278186    }
    279187
    280     void GUIManager::showGUI(const std::string& name, Ogre::SceneManager* sceneManager)// bool showBackground)
     188    void GUIManager::showGUI(const std::string& name)
    281189    {
    282190        if (state_ != Uninitialised)
    283191        {
    284             if (state_ == OnDisplay)
    285                 hideGUI();
    286 
    287192            COUT(3) << "Loading GUI " << name << std::endl;
    288193            try
    289194            {
    290                 // COUT (0) << "************* sceneManager: " << sceneManager << std::endl;
    291                 if (!sceneManager)
    292                 {
    293                     // currently, only an image is loaded. We could do 3D, see loadBackground.
    294                     //this->viewport_->setClearEveryFrame(true);
    295                     this->guiRenderer_->setTargetSceneManager(this->backgroundSceneManager_);
    296                     //this->viewport_->setCamera(this->backgroundCamera_);
    297 
    298                     lua_pushboolean(this->scriptModule_->getLuaState(), true);
    299                     lua_setglobal(this->scriptModule_->getLuaState(), "showBackground");
    300                 }
    301                 else
    302                 {
    303                     //this->viewport_->setClearEveryFrame(false);
    304                     this->guiRenderer_->setTargetSceneManager(sceneManager);
    305                     currentSceneManager_ = sceneManager;
    306                     //this->viewport_->setCamera(this->emptyCamera_);
    307 
    308                     lua_pushboolean(this->scriptModule_->getLuaState(), false);
    309                     lua_setglobal(this->scriptModule_->getLuaState(), "showBackground");
    310                 }
    311 
    312                 lua_pushfstring(this->scriptModule_->getLuaState(), "mainmenu.lua");
    313                 lua_setglobal(this->scriptModule_->getLuaState(), "filename");
    314 
    315                 this->scriptModule_->executeScriptGlobal("showGUI");
    316 
    317                 InputManager::getInstance().requestEnterState("gui");
    318 
    319                 this->state_ = OnDisplay;
     195                this->scriptModule_->executeString(std::string("showGUI(\"") + name + "\")");
    320196            }
    321197            catch (CEGUI::Exception& ex)
     
    332208            COUT(2) << "Warning: GUI Manager not yet initialised, cannot load a GUI" << std::endl;
    333209        }
    334     }
    335 
    336     /*void GUIManager::testFct()
    337     {
    338         //COUT(0) << "**** " << currentSceneManager_ << std::endl;
    339         this->showGUI("IngameMenu", currentSceneManager_);
    340     }
    341 
    342     void GUIManager::testOutput(const std::string& str)
    343     {
    344         COUT(0) << "***" << str << "***" << std::endl;
    345     }*/
    346 
    347     void GUIManager::hideGUI()
    348     {
    349         if (this->state_ != OnDisplay)
    350             return;
    351         //this->viewport_->setCamera(0);
    352         // has no effect since you cannot assign 0 as SceneManager
    353         //this->guiRenderer_->setTargetSceneManager(0);
    354         this->state_ = Ready;
    355         InputManager::getInstance().requestLeaveState("gui");
    356210    }
    357211
  • code/branches/gui/src/orxonox/gui/GUIManager.h

    r2840 r2850  
    4040#include <CEGUIInputEvent.h>
    4141#include <CEGUISystem.h>
    42 #include "core/Clock.h"
    4342#include "core/input/InputInterfaces.h"
    4443
     
    7170
    7271        bool initialise(Ogre::RenderWindow* renderWindow);
    73         void loadScene(const std::string& name);
    74         void update(const Clock& time)
    75         {
    76             assert(guiSystem_);
    77             guiSystem_->injectTimePulse(time.getDeltaTime());
    78         }
    79         void showGUI(const std::string& name, Ogre::SceneManager* sceneManager);// bool showBackground); // tolua_export
    80         void hideGUI(); // tolua_export
    81         //void testOutput(const std::string& str); // tolua_export
    8272
    83         static void toggleGUI();
     73        void update(const Clock& time);
     74
     75        void showGUI(const std::string& name);
     76        void executeCode(const std::string& str);
    8477
    8578        void setCamera(Ogre::Camera* camera);
    86         Ogre::Camera* getCamera() { return this->backgroundCamera_; }
    87 
    88         static void showGUI_s(const std::string& name, Ogre::SceneManager* sceneManager)//bool showBackground)
    89         {
    90             getInstance().showGUI(name, sceneManager);
    91         }
    92 
    93         // please remove
    94         //void testFct();
    9579
    9680        static GUIManager& getInstance()    { assert(singletonRef_s); return *singletonRef_s; } // tolua_export
     
    9983    private:
    10084        GUIManager(const GUIManager& instance);
     85
     86        void loadLuaCode();
    10187
    10288        void keyPressed (const KeyEvent& evt)
     
    120106        void updateMouse(float dt) { }
    121107
    122         void loadScenes();
    123 
    124         //Ogre::SceneManager*       emptySceneManager_;
    125         Ogre::SceneManager*       backgroundSceneManager_;
    126         //Ogre::Camera*             emptyCamera_;
    127         Ogre::Camera*             backgroundCamera_;
    128         //Ogre::Viewport*           viewport_;
    129108        Ogre::RenderWindow*       renderWindow_;
    130109        CEGUI::OgreCEGUIRenderer* guiRenderer_;
     
    135114        CEGUI::Imageset*          backgroundImage_;
    136115        lua_State*                luaState_;
    137         Ogre::SceneManager*         currentSceneManager_;
    138116
    139117        State state_;
Note: See TracChangeset for help on using the changeset viewer.