Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 27, 2008, 10:56:51 PM (16 years ago)
Author:
rgrieder
Message:
  • Added support for dedicated server. Could not network test it yet, client still segfaults me.
  • Also kicked GraphicsEngine::levelSceneManager_, there are only the statistic methods left.
  • GSDedicated also derives from GSLevel, but GSLevel is not anymore a real GameState.
  • CameraHandler and LevelManager get created in GSLevel now.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/objecthierarchy/src/orxonox/gamestates/GSLevel.cc

    r2010 r2023  
    3030#include "GSLevel.h"
    3131
    32 #include <OgreSceneManager.h>
    33 #include <OgreRoot.h>
    3432#include "core/input/InputManager.h"
    3533#include "core/input/SimpleInputState.h"
     
    4139#include "core/ConfigValueIncludes.h"
    4240#include "core/CoreIncludes.h"
     41#include "core/Core.h"
    4342//#include "objects/Backlight.h"
     43#include "objects/CameraHandler.h"
    4444#include "objects/Tickable.h"
    4545#include "objects/Radar.h"
    4646//#include "tools/ParticleInterface.h"
    47 #include "GraphicsEngine.h"
     47#include "LevelManager.h"
    4848#include "Settings.h"
    4949
    5050namespace orxonox
    5151{
    52     GSLevel::GSLevel(const std::string& name)
    53         : GameState<GSGraphics>(name)
    54         , timeFactor_(1.0f)
    55         , sceneManager_(0)
     52    GSLevel::GSLevel()
     53//        : GameState<GSGraphics>(name)
     54        : timeFactor_(1.0f)
    5655        , keyBinder_(0)
    5756        , inputState_(0)
    5857        , radar_(0)
    5958        , startFile_(0)
     59        , cameraHandler_(0)
     60        , levelManager_(0)
    6061    {
    6162        RegisterObject(GSLevel);
     
    7273    }
    7374
    74     void GSLevel::enter()
    75     {
    76         inputState_ = InputManager::getInstance().createInputState<SimpleInputState>("game", 20);
    77         keyBinder_ = new KeyBinder();
    78         keyBinder_->loadBindings("keybindings.ini");
    79         inputState_->setHandler(keyBinder_);
    80 
    81         // create Ogre SceneManager for the level
    82         this->sceneManager_ = Ogre::Root::getSingleton().createSceneManager(Ogre::ST_GENERIC, "LevelSceneManager");
    83         COUT(4) << "Created SceneManager: " << sceneManager_->getName() << std::endl;
    84 
    85         this->sceneManager_->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_ADDITIVE);
    86 
    87         // temporary hack
    88         GraphicsEngine::getInstance().setLevelSceneManager(this->sceneManager_);
    89 
    90         // Start the Radar
    91         this->radar_ = new Radar();
    92 
    93         // reset game speed to normal
    94         timeFactor_ = 1.0f;
    95 
    96         // TODO: insert slomo console command with
    97         // .accessLevel(AccessLevel::Offline).defaultValue(0, 1.0).axisParamIndex(0).isAxisRelative(false);
    98 
    99         // keybind console command
    100         FunctorMember<GSLevel>* functor1 = createFunctor(&GSLevel::keybind);
    101         functor1->setObject(this);
    102         CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor1, "keybind"));
    103         FunctorMember<GSLevel>* functor2 = createFunctor(&GSLevel::tkeybind);
    104         functor2->setObject(this);
    105         CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor2, "tkeybind"));
    106         // set our console command as callback for the key detector
    107         InputManager::getInstance().setKeyDetectorCallback(std::string("keybind ") + keyDetectorCallbackCode_);
     75    void GSLevel::enter(Ogre::Viewport* viewport)
     76    {
     77        if (Core::showsGraphics())
     78        {
     79            inputState_ = InputManager::getInstance().createInputState<SimpleInputState>("game", 20);
     80            keyBinder_ = new KeyBinder();
     81            keyBinder_->loadBindings("keybindings.ini");
     82            inputState_->setHandler(keyBinder_);
     83
     84            // create the global CameraHandler
     85            assert(viewport);
     86            this->cameraHandler_ = new CameraHandler(viewport);
     87
     88            // Start the Radar
     89            this->radar_ = new Radar();
     90        }
     91
     92        if (Core::isMaster())
     93        {
     94            // create the global LevelManager
     95            this->levelManager_ = new LevelManager();
     96
     97            // reset game speed to normal
     98            timeFactor_ = 1.0f;
     99
     100            this->loadLevel();
     101        }
     102
     103        if (Core::showsGraphics())
     104        {
     105            // TODO: insert slomo console command with
     106            // .accessLevel(AccessLevel::Offline).defaultValue(0, 1.0).axisParamIndex(0).isAxisRelative(false);
     107
     108            // keybind console command
     109            FunctorMember<GSLevel>* functor1 = createFunctor(&GSLevel::keybind);
     110            functor1->setObject(this);
     111            CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor1, "keybind"));
     112            FunctorMember<GSLevel>* functor2 = createFunctor(&GSLevel::tkeybind);
     113            functor2->setObject(this);
     114            CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor2, "tkeybind"));
     115            // set our console command as callback for the key detector
     116            InputManager::getInstance().setKeyDetectorCallback(std::string("keybind ") + keyDetectorCallbackCode_);
     117
     118            // level is loaded: we can start capturing the input
     119            InputManager::getInstance().requestEnterState("game");
     120        }
     121
     122        if (Core::isMaster())
     123        {
     124            // time factor console command
     125            FunctorMember<GSLevel>* functor = createFunctor(&GSLevel::setTimeFactor);
     126            functor->setObject(this);
     127            CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor, "setTimeFactor")).accessLevel(AccessLevel::Offline).defaultValue(0, 1.0);;
     128        }
    108129    }
    109130
     
    116137        //Loader::close();
    117138
    118         delete this->radar_;
    119 
    120         Ogre::Root::getSingleton().destroySceneManager(this->sceneManager_);
    121 
    122         inputState_->setHandler(0);
    123         InputManager::getInstance().requestDestroyState("game");
    124         delete this->keyBinder_;
     139        if (Core::showsGraphics())
     140            InputManager::getInstance().requestLeaveState("game");
     141
     142        if (Core::isMaster())
     143            this->unloadLevel();
     144
     145        if (this->radar_)
     146            delete this->radar_;
     147
     148        if (this->cameraHandler_)
     149            delete this->cameraHandler_;
     150
     151        if (this->levelManager_)
     152            delete this->levelManager_;
     153
     154        if (Core::showsGraphics())
     155        {
     156            inputState_->setHandler(0);
     157            InputManager::getInstance().requestDestroyState("game");
     158            if (this->keyBinder_)
     159                delete this->keyBinder_;
     160        }
    125161    }
    126162
     
    185221    void GSLevel::keybindInternal(const std::string& command, bool bTemporary)
    186222    {
    187         static std::string bindingString = "";
    188         static bool bTemporarySaved = false;
    189         static bool bound = true;
    190         // note: We use a long name to make 'sure' that the user doesn't use it accidentally.
    191         // Howerver there will be no real issue if it happens anyway.
    192         if (command.find(keyDetectorCallbackCode_) != 0)
    193         {
    194             if (bound)
     223        if (Core::showsGraphics())
     224        {
     225            static std::string bindingString = "";
     226            static bool bTemporarySaved = false;
     227            static bool bound = true;
     228            // note: We use a long name to make 'sure' that the user doesn't use it accidentally.
     229            // Howerver there will be no real issue if it happens anyway.
     230            if (command.find(keyDetectorCallbackCode_) != 0)
    195231            {
    196                 COUT(0) << "Press any button/key or move a mouse/joystick axis" << std::endl;
    197                 InputManager::getInstance().requestEnterState("detector");
    198                 bindingString = command;
    199                 bTemporarySaved = bTemporary;
    200                 bound = false;
     232                if (bound)
     233                {
     234                    COUT(0) << "Press any button/key or move a mouse/joystick axis" << std::endl;
     235                    InputManager::getInstance().requestEnterState("detector");
     236                    bindingString = command;
     237                    bTemporarySaved = bTemporary;
     238                    bound = false;
     239                }
     240                //else:  We're still in a keybind command. ignore this call.
    201241            }
    202             //else:  We're still in a keybind command. ignore this call.
    203         }
    204         else
    205         {
    206             if (!bound)
     242            else
    207243            {
    208                 // user has pressed the key
    209                 std::string name = command.substr(this->keyDetectorCallbackCode_.size());
    210                 COUT(0) << "Binding string \"" << bindingString << "\" on key '" << name << "'" << std::endl;
    211                 this->keyBinder_->setBinding(bindingString, name, bTemporarySaved);
    212                 InputManager::getInstance().requestLeaveState("detector");
    213                 bound = true;
     244                if (!bound)
     245                {
     246                    // user has pressed the key
     247                    std::string name = command.substr(this->keyDetectorCallbackCode_.size());
     248                    COUT(0) << "Binding string \"" << bindingString << "\" on key '" << name << "'" << std::endl;
     249                    this->keyBinder_->setBinding(bindingString, name, bTemporarySaved);
     250                    InputManager::getInstance().requestLeaveState("detector");
     251                    bound = true;
     252                }
     253                // else: A key was pressed within the same tick, ignore it.
    214254            }
    215             // else: A key was pressed within the same tick, ignore it.
    216255        }
    217256    }
Note: See TracChangeset for help on using the changeset viewer.