Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1642 for code


Ignore:
Timestamp:
Jul 23, 2008, 3:37:29 PM (16 years ago)
Author:
rgrieder
Message:
  • changed the static interface of the InputManager to a member one with getInstance()
  • converted InputManager and InGameConsole to Ogre Singletons (c'tor and d'tor public, but assert in c'tor to prevent multiple instances at runtime)
  • added toluabind_orxonox files to tolua folder that contains a pimped version of tolua (I'll write a little cmake project soon to automate it; Currently that only works with msvc)
  • commented out Loader::unload() from Orxonox destructor because that deleted the ParticleSpawners, which were using a method of a sceneNode that belonged to a already destroyed SpaceShip. —> Results in a memory leak. Previously Loader::unload() was called for all BaseObjects (now calling unload(level_)). And since 'P' from ParticleSpawner comes before 'S' like SpaceShip, the order was correct.
  • Added factory feature for InputStates (can now be created by string if there is Factory entry for it)
  • Created factory entries for SimpleInputState and ExtendedInputState
Location:
code/branches/gui
Files:
3 added
20 edited

Legend:

Unmodified
Added
Removed
  • code/branches/gui/src/core/Core.cc

    r1638 r1642  
    196196    {
    197197        TclThreadManager::getInstance().tick(dt);
    198         InputManager::tick(dt);
     198        InputManager::getInstance().tick(dt);
    199199    }
    200200}
  • code/branches/gui/src/core/Exception.h

    r1638 r1642  
    4040#include <string>
    4141#include <exception>
     42#include <cassert>
    4243#include "core/Debug.h"
    4344
     
    129130    throw SpecificException<Exception::type>(description, __LINE__, __FILE__, __FUNCTIONNAME__)
    130131
     132    // define an assert macro that can display a message
     133#ifndef NDEBUG
     134#define OrxAssert(condition, errorMessage) \
     135    condition ? ((void)0) : (orxonox::OutputHandler::getOutStream().setOutputLevel(ORX_ERROR) << errorMessage << std::endl); \
     136    assert(condition);
     137#else
     138#define OrxAssert(condition, errorMessage)  ((void)0)
     139#endif
     140
    131141}
    132142
  • code/branches/gui/src/core/input/ExtendedInputState.cc

    r1641 r1642  
    3737#include <assert.h>
    3838#include "core/Debug.h"
     39#include "core/CoreIncludes.h"
    3940
    4041namespace orxonox
    4142{
     43    CreateFactory(ExtendedInputState);
     44
    4245    using namespace InputDevice;
     46
     47    ExtendedInputState::ExtendedInputState()
     48    {
     49        RegisterObject(ExtendedInputState);
     50    }
    4351
    4452    void ExtendedInputState::numberOfJoySticksChanged(unsigned int n)
  • code/branches/gui/src/core/input/ExtendedInputState.h

    r1641 r1642  
    4848    {
    4949    public:
    50         ExtendedInputState() { }
     50        ExtendedInputState();
    5151        ~ExtendedInputState() { }
    5252
  • code/branches/gui/src/core/input/InputManager.cc

    r1641 r1642  
    6262    SetConsoleCommandShortcut(InputManager, calibrate);
    6363
     64    std::string InputManager::bindingCommmandString_s = "";
     65    InputManager* InputManager::singletonRef_s = 0;
     66
    6467    using namespace InputDevice;
    6568
    66     // ###############################
    67     // ###    Internal Methods     ###
    68     // ###############################
    69     // ###############################
     69    // ############################################################
     70    // #####                  Initialisation                  #####
     71    // ##########                                        ##########
     72    // ############################################################
    7073
    7174    /**
     
    8790    {
    8891        RegisterRootObject(InputManager);
    89     }
    90 
    91     /**
    92     @brief
    93         Destructor itself only called at the end of the program, after main.
    94         Instance gets registered for destruction with atexit(.).
    95     */
    96     InputManager::~InputManager()
    97     {
    98         _destroy();
    99     }
    100 
    101     /**
    102     @brief
    103         The one instance of the InputManager is stored in this function.
    104         Only for internal use. Public Interface ist static.
    105     @return
    106         A reference to the only instance of the InputManager
    107     */
    108     InputManager& InputManager::_getInstance()
    109     {
    110         static InputManager theOnlyInstance;
    111         return theOnlyInstance;
    112     }
    113 
    114 
    115     // ############################################################
    116     // #####                  Initialisation                  #####
    117     // ##########                                        ##########
    118     // ############################################################
     92
     93        assert(singletonRef_s == 0);
     94        singletonRef_s = this;
     95    }
    11996
    12097    /**
     
    129106        The height of the render window
    130107    */
    131     bool InputManager::_initialise(const size_t windowHnd, int windowWidth, int windowHeight,
     108    bool InputManager::initialise(const size_t windowHnd, int windowWidth, int windowHeight,
    132109                                   bool createKeyboard, bool createMouse, bool createJoySticks)
    133110    {
     
    431408    /**
    432409    @brief
    433         Destroys all the created input devices. InputManager will be ready for a
    434         new initialisation.
    435     */
    436     void InputManager::_destroy()
     410        Destroys all the created input devices and states.
     411    */
     412    InputManager::~InputManager()
    437413    {
    438414        if (inputSystem_)
     
    550526        Delta time
    551527    */
    552     void InputManager::_tick(float dt)
     528    void InputManager::tick(float dt)
    553529    {
    554530        if (inputSystem_ == 0)
     
    983959
    984960    // ############################################################
    985     // #####            Static Interface Methods              #####
     961    // #####         Other Public Interface Methods           #####
    986962    // ##########                                        ##########
    987963    // ############################################################
    988 
    989     std::string InputManager::bindingCommmandString_s = "";
    990 
    991     bool InputManager::initialise(const size_t windowHnd, int windowWidth, int windowHeight,
    992         bool createKeyboard, bool createMouse, bool createJoySticks)
    993     {
    994         return _getInstance()._initialise(windowHnd, windowWidth, windowHeight,
    995             createKeyboard, createMouse, createJoySticks);
    996     }
    997 
    998     int InputManager::numberOfKeyboards()
    999     {
    1000         if (_getInstance().keyboard_ != 0)
    1001             return 1;
    1002         else
    1003             return 0;
    1004     }
    1005 
    1006     int InputManager::numberOfMice()
    1007     {
    1008         if (_getInstance().mouse_ != 0)
    1009             return 1;
    1010         else
    1011             return 0;
    1012     }
    1013 
    1014     int InputManager::numberOfJoySticks()
    1015     {
    1016         return _getInstance().joySticksSize_;
    1017     }
    1018 
    1019     /*bool InputManager::isKeyDown(KeyCode::Enum key)
    1020     {
    1021     if (_getInstance().keyboard_)
    1022         return _getInstance().keyboard_->isKeyDown((OIS::KeyCode)key);
    1023     else
    1024         return false;
    1025     }*/
    1026 
    1027     /*bool InputManager::isModifierDown(KeyboardModifier::Enum modifier)
    1028     {
    1029     if (_getInstance().keyboard_)
    1030         return isModifierDown(modifier);
    1031     else
    1032         return false;
    1033     }*/
    1034 
    1035     /*const MouseState InputManager::getMouseState()
    1036     {
    1037     if (_getInstance().mouse_)
    1038         return _getInstance().mouse_->getMouseState();
    1039     else
    1040         return MouseState();
    1041     }*/
    1042 
    1043     /*const JoyStickState InputManager::getJoyStickState(unsigned int ID)
    1044     {
    1045     if (ID < _getInstance().joySticksSize_)
    1046         return JoyStickState(_getInstance().joySticks_[ID]->getJoyStickState(), ID);
    1047     else
    1048         return JoyStickState();
    1049     }*/
    1050 
    1051     void InputManager::destroy()
    1052     {
    1053         _getInstance()._destroy();
    1054     }
    1055 
    1056964
    1057965    /**
     
    1066974    void InputManager::setWindowExtents(const int width, const int height)
    1067975    {
    1068         if (_getInstance().mouse_)
     976        if (mouse_)
    1069977        {
    1070978            // Set mouse region (if window resizes, we should alter this to reflect as well)
    1071             const OIS::MouseState &mouseState = _getInstance().mouse_->getMouseState();
    1072             mouseState.width  = width;
    1073             mouseState.height = height;
    1074         }
    1075     }
    1076 
    1077     /**
    1078     @brief
    1079         Method for easily storing a string with the command executor. It is used by the
    1080         KeyDetector to get assign commands. The KeyDetector simply executes
    1081         the command 'storeKeyStroke myName' for each button/axis.
    1082     @remarks
    1083         This is only a temporary hack until we thourouhgly support multiple KeyBinders.
    1084     @param name
    1085         The name of the button/axis.
    1086     */
    1087     void InputManager::storeKeyStroke(const std::string& name)
    1088     {
    1089         requestLeaveState("detector");
    1090         COUT(0) << "Binding string \"" << bindingCommmandString_s << "\" on key '" << name << "'" << std::endl;
    1091         CommandExecutor::execute("config KeyBinder " + name + " " + bindingCommmandString_s, false);
    1092     }
    1093 
    1094     /**
    1095     @brief
    1096         Assigns a command string to a key/button/axis. The name is determined via KeyDetector
    1097         and InputManager::storeKeyStroke(.).
    1098     @param command
    1099         Command string that can be executed by the CommandExecutor
    1100     */
    1101     void InputManager::keyBind(const std::string& command)
    1102     {
    1103         bindingCommmandString_s = command;
    1104         requestEnterState("detector");
    1105         COUT(0) << "Press any button/key or move a mouse/joystick axis" << std::endl;
    1106     }
    1107 
    1108     /**
    1109     @brief
    1110         Starts joy stick calibration.
    1111     */
    1112     void InputManager::calibrate()
    1113     {
    1114         _getInstance().bCalibrating_ = true;
    1115         requestEnterState("calibrator");
    1116     }
    1117 
    1118     void InputManager::tick(float dt)
    1119     {
    1120         _getInstance()._tick(dt);
    1121     }
     979            mouse_->getMouseState().width  = width;
     980            mouse_->getMouseState().height = height;
     981        }
     982    }
     983
    1122984
    1123985    // ###### InputStates ######
     
    11391001        if (name == "")
    11401002            return false;
    1141         if (_getInstance().inputStatesByName_.find(name) == _getInstance().inputStatesByName_.end())
    1142         {
    1143             if (_getInstance().inputStatesByPriority_.find(priority)
    1144                 == _getInstance().inputStatesByPriority_.end())
    1145             {
    1146                 _getInstance().inputStatesByName_[name] = state;
    1147                 _getInstance().inputStatesByPriority_[priority] = state;
     1003        if (!state)
     1004            return false;
     1005        if (inputStatesByName_.find(name) == inputStatesByName_.end())
     1006        {
     1007            if (inputStatesByPriority_.find(priority)
     1008                == inputStatesByPriority_.end())
     1009            {
     1010                inputStatesByName_[name] = state;
     1011                inputStatesByPriority_[priority] = state;
    11481012                state->setNumOfJoySticks(numberOfJoySticks());
    11491013                state->setName(name);
     
    11721036    {
    11731037        SimpleInputState* state = new SimpleInputState();
    1174         if (_getInstance()._configureInputState(state, name, priority))
     1038        if (_configureInputState(state, name, priority))
    11751039            return state;
    11761040        else
     
    11881052    {
    11891053        ExtendedInputState* state = new ExtendedInputState();
    1190         if (_getInstance()._configureInputState(state, name, priority))
     1054        if (_configureInputState(state, name, priority))
     1055            return state;
     1056        else
     1057        {
     1058            delete state;
     1059            return 0;
     1060        }
     1061    }
     1062
     1063    /**
     1064    @brief
     1065        Returns a new InputState of type 'type' and configures it first.
     1066    @param type
     1067        String name of the class (used by the factory)
     1068    */
     1069    InputState* InputManager::createInputState(const std::string& type, const std::string &name, int priority)
     1070    {
     1071        InputState* state = dynamic_cast<InputState*>(Factory::getIdentifier(type)->fabricate());
     1072        if (_configureInputState(state, name, priority))
    11911073            return state;
    11921074        else
     
    12141096            return false;
    12151097        }
    1216         std::map<std::string, InputState*>::iterator it = _getInstance().inputStatesByName_.find(name);
    1217         if (it != _getInstance().inputStatesByName_.end())
    1218         {
    1219             _getInstance()._destroyState((*it).second);
     1098        std::map<std::string, InputState*>::iterator it = inputStatesByName_.find(name);
     1099        if (it != inputStatesByName_.end())
     1100        {
     1101            _destroyState((*it).second);
    12201102            return true;
    12211103        }
     
    12331115    InputState* InputManager::getState(const std::string& name)
    12341116    {
    1235         std::map<std::string, InputState*>::iterator it = _getInstance().inputStatesByName_.find(name);
    1236         if (it != _getInstance().inputStatesByName_.end())
     1117        std::map<std::string, InputState*>::iterator it = inputStatesByName_.find(name);
     1118        if (it != inputStatesByName_.end())
    12371119            return (*it).second;
    12381120        else
     
    12481130    InputState* InputManager::getCurrentState()
    12491131    {
    1250         return (*_getInstance().activeStates_.rbegin()).second;
     1132        return (*activeStates_.rbegin()).second;
    12511133    }
    12521134
     
    12631145    {
    12641146        // get pointer from the map with all stored handlers
    1265         std::map<std::string, InputState*>::const_iterator it = _getInstance().inputStatesByName_.find(name);
    1266         if (it != _getInstance().inputStatesByName_.end())
    1267         {
    1268             _getInstance().stateEnterRequests_.push_back((*it).second);
     1147        std::map<std::string, InputState*>::const_iterator it = inputStatesByName_.find(name);
     1148        if (it != inputStatesByName_.end())
     1149        {
     1150            stateEnterRequests_.push_back((*it).second);
    12691151            return true;
    12701152        }
     
    12831165    {
    12841166        // get pointer from the map with all stored handlers
    1285         std::map<std::string, InputState*>::const_iterator it = _getInstance().inputStatesByName_.find(name);
    1286         if (it != _getInstance().inputStatesByName_.end())
    1287         {
    1288             _getInstance().stateLeaveRequests_.push_back((*it).second);
     1167        std::map<std::string, InputState*>::const_iterator it = inputStatesByName_.find(name);
     1168        if (it != inputStatesByName_.end())
     1169        {
     1170            stateLeaveRequests_.push_back((*it).second);
    12891171            return true;
    12901172        }
    12911173        return false;
    12921174    }
     1175
     1176
     1177    // ############################################################
     1178    // #####                Console Commands                  #####
     1179    // ##########                                        ##########
     1180    // ############################################################
     1181
     1182    /**
     1183    @brief
     1184        Method for easily storing a string with the command executor. It is used by the
     1185        KeyDetector to get assign commands. The KeyDetector simply executes
     1186        the command 'storeKeyStroke myName' for each button/axis.
     1187    @remarks
     1188        This is only a temporary hack until we thourouhgly support multiple KeyBinders.
     1189    @param name
     1190        The name of the button/axis.
     1191    */
     1192    void InputManager::storeKeyStroke(const std::string& name)
     1193    {
     1194        getInstance().requestLeaveState("detector");
     1195        COUT(0) << "Binding string \"" << bindingCommmandString_s << "\" on key '" << name << "'" << std::endl;
     1196        CommandExecutor::execute("config KeyBinder " + name + " " + bindingCommmandString_s, false);
     1197    }
     1198
     1199    /**
     1200    @brief
     1201        Assigns a command string to a key/button/axis. The name is determined via KeyDetector
     1202        and InputManager::storeKeyStroke(.).
     1203    @param command
     1204        Command string that can be executed by the CommandExecutor
     1205    */
     1206    void InputManager::keyBind(const std::string& command)
     1207    {
     1208        bindingCommmandString_s = command;
     1209        getInstance().requestEnterState("detector");
     1210        COUT(0) << "Press any button/key or move a mouse/joystick axis" << std::endl;
     1211    }
     1212
     1213    /**
     1214    @brief
     1215        Starts joy stick calibration.
     1216    */
     1217    void InputManager::calibrate()
     1218    {
     1219        getInstance().bCalibrating_ = true;
     1220        getInstance().requestEnterState("calibrator");
     1221    }
    12931222}
  • code/branches/gui/src/core/input/InputManager.h

    r1641 r1642  
    8686        // --> setConfigValues is private
    8787        friend ClassIdentifier<InputManager>;
    88 
    89     public: // static functions
    90         static bool initialise(const size_t windowHnd, int windowWidth, int windowHeight,
     88        // let Core class use tick(.)
     89        friend Core;
     90
     91    public:
     92        InputManager ();
     93        ~InputManager();
     94
     95        bool initialise(const size_t windowHnd, int windowWidth, int windowHeight,
    9196                               bool createKeyboard = true, bool createMouse = true, bool createJoySticks = false);
    92         static int  numberOfKeyboards();
    93         static int  numberOfMice();
    94         static int  numberOfJoySticks();
    95 
    96         static void destroy();
    97 
    98         //static bool isModifierDown(KeyboardModifier::Enum modifier);
    99         //static bool isKeyDown(KeyCode::Enum key);
    100         //static const MouseState getMouseState();
    101         //static const JoyStickState getJoyStickState(unsigned int ID);
    102 
    103         static void setWindowExtents(const int width, const int height);
    104 
     97
     98        int  numberOfKeyboards() { return keyboard_ ? 1 : 0; }
     99        int  numberOfMice()      { return mouse_    ? 1 : 0; }
     100        int  numberOfJoySticks() { return joySticksSize_; }
     101
     102        void setWindowExtents(const int width, const int height);
     103
     104        SimpleInputState*   createSimpleInputState  (const std::string& name, int priority);
     105        ExtendedInputState* createExtendedInputState(const std::string& name, int priority);
     106        InputState*         createInputState(const std::string& type, const std::string &name, int priority);
     107        bool destroyState          (const std::string& name);
     108        InputState* getState       (const std::string& name);
     109        InputState* getCurrentState();
     110        bool requestEnterState     (const std::string& name);
     111        bool requestLeaveState     (const std::string& name);
     112
     113        static InputManager& getInstance()    { assert(singletonRef_s); return *singletonRef_s; }
     114        static InputManager* getInstancePtr() { return singletonRef_s; }
     115
     116    public: // console commands
    105117        static void storeKeyStroke(const std::string& name);
    106118        static void keyBind(const std::string& command);
    107 
    108119        static void calibrate();
    109 
    110         static void tick(float dt);
    111 
    112         static SimpleInputState*   createSimpleInputState  (const std::string& name, int priority);
    113         static ExtendedInputState* createExtendedInputState(const std::string& name, int priority);
    114         static bool destroyState (const std::string& name);
    115         static InputState* getState       (const std::string& name);
    116         static InputState* getCurrentState();
    117         static bool requestEnterState     (const std::string& name);
    118         static bool requestLeaveState     (const std::string& name);
    119120
    120121    private: // functions
    121122        // don't mess with a Singleton
    122         InputManager ();
    123123        InputManager (const InputManager&);
    124         ~InputManager();
    125124
    126125        // Intenal methods
    127         bool _initialise(const size_t, int, int, bool, bool, bool);
    128126        bool _initialiseKeyboard();
    129127        bool _initialiseMouse();
     
    131129        void _redimensionLists();
    132130
    133         void _destroy();
    134131        void _destroyKeyboard();
    135132        void _destroyMouse();
     
    142139        unsigned int _getJoystick(const OIS::JoyStickEvent& arg);
    143140
    144         void _tick(float dt);
    145 
    146141        void _updateActiveStates();
    147142        bool _configureInputState(InputState* state, const std::string& name, int priority);
     143
     144        void tick(float dt);
    148145
    149146        // input events
     
    158155        bool sliderMoved   (const OIS::JoyStickEvent &arg, int id);
    159156        bool povMoved      (const OIS::JoyStickEvent &arg, int id);
     157        // don't remove that! Or else add OIS as dependency library to orxonox.
     158        bool vector3Moved  (const OIS::JoyStickEvent &arg, int id) { return true; }
    160159
    161160        void setConfigValues();
    162 
    163         static InputManager& _getInstance();
    164161
    165162    private: // variables
     
    204201
    205202        static std::string                  bindingCommmandString_s;
    206     };
    207 
     203        static InputManager*                singletonRef_s;
     204    };
    208205}
    209206
  • code/branches/gui/src/core/input/InputState.h

    r1641 r1642  
    4040#include <vector>
    4141#include "core/Executor.h"
     42#include "core/BaseObject.h"
     43#include "core/CoreIncludes.h"
    4244#include "InputInterfaces.h"
    4345
    4446namespace orxonox
    4547{
    46     class _CoreExport InputState
     48    class _CoreExport InputState : public BaseObject
    4749    {
    4850        friend class InputManager;
    4951
    5052    public:
    51         InputState() : priority_(0), executorOnEnter_(0), executorOnLeave_(0) { }
     53        InputState() : priority_(0), executorOnEnter_(0), executorOnLeave_(0)
     54        { RegisterObject(InputState); }
    5255        virtual ~InputState() { }
    5356
  • code/branches/gui/src/core/input/SimpleInputState.cc

    r1641 r1642  
    3838#include "core/Debug.h"
    3939#include "core/Executor.h"
     40#include "core/CoreIncludes.h"
    4041
    4142namespace orxonox
    4243{
     44    CreateFactory(SimpleInputState);
     45
    4346    using namespace InputDevice;
    4447
     
    4851        , joyStickHandlerAll_(0)
    4952    {
     53        RegisterObject(SimpleInputState);
    5054    }
    5155
  • code/branches/gui/src/core/input/SimpleInputState.h

    r1641 r1642  
    4343namespace orxonox
    4444{
    45 
    4645    class _CoreExport SimpleInputState : public InputState
    4746    {
    48 
    4947    public:
    5048        SimpleInputState();
  • code/branches/gui/src/orxonox/CMakeLists.txt

    r1625 r1642  
    77  RadarViewable.cc
    88  Settings.cc
     9
     10  gui/GUIManager.cc
     11  gui/OgreCEGUIRenderer.cpp
     12  gui/OgreCEGUIResourceProvider.cpp
     13  gui/OgreCEGUITexture.cpp
    914
    1015  overlays/OrxonoxOverlay.cc
  • code/branches/gui/src/orxonox/Orxonox.cc

    r1641 r1642  
    104104   */
    105105  Orxonox::Orxonox()
    106     : ogre_(0)
    107     , startLevel_(0)
     106    : startLevel_(0)
    108107    , hud_(0)
    109     , radar_(0)
    110108    //, auMan_(0)
    111109    , timer_(0)
     
    114112    , mode_(GameMode::GM_Unspecified)
    115113    , debugRefreshTime_(0.0f)
     114    , ogre_(0)
     115    , inputManager_(0)
     116    , radar_(0)
    116117  {
    117118    RegisterRootObject(Orxonox);
    118119
    119     assert(singletonRef_s == 0);
     120    //assert(singletonRef_s == 0);
     121    OrxAssert(singletonRef_s == 0, "asdfasdfasdfasdfblahblah");
    120122    singletonRef_s = this;
    121123  }
     
    127129  {
    128130    // keep in mind: the order of deletion is very important!
    129     Loader::unload();
     131    if (this->timer_)
     132      delete this->timer_;
     133
     134    Loader::unload(startLevel_);
    130135    if (this->startLevel_)
    131136      delete this->startLevel_;
     
    138143      delete this->radar_;
    139144
    140     Loader::close();
    141145    //if (this->auMan_)
    142146    //  delete this->auMan_;
    143     InGameConsole::getInstance().destroy();
    144     if (this->timer_)
    145       delete this->timer_;
    146     InputManager::destroy();
     147
     148    if (this->console_)
     149      delete this->console_;
     150
     151    if (inputManager_)
     152      delete inputManager_;
    147153
    148154    if (this->ogre_)
     
    153159    if (server_g)
    154160      delete network::Server::getSingleton();
     161
     162    // this call will delete every BaseObject!
     163    // But currently this will call methods of objects that exist no more
     164    // The only 'memory leak' is the ParticleSpawer. They would be deleted here
     165    // and call a sceneNode method that has already been destroy by the corresponding space ship.
     166    //Loader::close();
    155167
    156168    singletonRef_s = 0;
     
    247259          // Calls the InputManager which sets up the input devices.
    248260          // The render window width and height are used to set up the mouse movement.
    249           InputManager::initialise(ogre_->getWindowHandle(),
     261          inputManager_ = new InputManager();
     262          inputManager_->initialise(ogre_->getWindowHandle(),
    250263                ogre_->getWindowWidth(), ogre_->getWindowHeight(), true, true, true);
    251264          KeyBinder* keyBinder = new KeyBinder();
    252265          keyBinder->loadBindings();
    253           InputManager::createSimpleInputState("game", 20)->setHandler(keyBinder);
     266          inputManager_->createSimpleInputState("game", 20)->setHandler(keyBinder);
    254267
    255268          // Load the InGameConsole
    256           InGameConsole::getInstance().initialise();
     269          console_ = new InGameConsole();
     270          console_->initialise();
    257271
    258272          // load the CEGUI interface
     
    342356      if (success)
    343357      {
    344         InputManager::requestEnterState("game");
     358        InputManager::getInstance().requestEnterState("game");
    345359        this->mode_ = mode;
    346360      }
  • code/branches/gui/src/orxonox/Orxonox.h

    r1638 r1642  
    8484
    8585    private:
    86       GraphicsEngine*       ogre_;          //!< our dearest graphics engine <3
    8786      Level*                startLevel_;    //!< current hard coded default level
    8887      Level*                hud_;           //!< 'level' object fo the HUD
    89       Radar*                radar_;         //!< represents the Radar (not the HUD part)
    9088      //audio::AudioManager*  auMan_;         //!< audio manager
    9189      Ogre::Timer*          timer_;         //!< Main loop timer
     
    10098      float                 debugRefreshTime_;
    10199
     100      // By Orxonox managed singleton pointers
     101      GraphicsEngine*       ogre_;          //!< our dearest graphics engine <3
     102      InputManager*         inputManager_;
     103      Radar*                radar_;         //!< represents the Radar (not the HUD part)
     104      InGameConsole*        console_;
     105
    102106      static Orxonox *singletonRef_s;
    103107  };
  • code/branches/gui/src/orxonox/gui/GUIManager.cc

    r1640 r1642  
    117117
    118118                // register us as input handler
    119                 SimpleInputState* state = InputManager::createSimpleInputState("gui", 30);
     119                SimpleInputState* state = InputManager::getInstance().createSimpleInputState("gui", 30);
    120120                state->setHandler(this);
    121121                state->setJoyStickHandler(new EmptyHandler());
     
    203203                this->scriptModule_->executeScriptGlobal("showMainMenu");
    204204
    205                 InputManager::requestEnterState("gui");
     205                InputManager::getInstance().requestEnterState("gui");
    206206
    207207                this->state_ = OnDisplay;
     
    229229        this->guiRenderer_->setTargetSceneManager(0);
    230230        this->state_ = Ready;
    231         InputManager::requestLeaveState("gui");
     231        InputManager::getInstance().requestLeaveState("gui");
    232232    }
    233233
  • code/branches/gui/src/orxonox/overlays/console/InGameConsole.cc

    r1641 r1642  
    5858    SetConsoleCommand(InGameConsole, closeConsole, true);
    5959
     60    InGameConsole* InGameConsole::singletonRef_s = 0;
     61
    6062    /**
    6163        @brief Constructor: Creates and initializes the InGameConsole.
     
    7173        RegisterObject(InGameConsole);
    7274
     75        assert(singletonRef_s == 0);
     76        singletonRef_s = this;
     77
    7378        this->bActive_ = false;
    7479        this->cursor_ = 0.0f;
     
    8792    InGameConsole::~InGameConsole(void)
    8893    {
    89         this->destroy();
    90     }
    91 
    92     /**
    93         @brief Returns a reference to the only existing instance of InGameConsole.
    94     */
    95     InGameConsole& InGameConsole::getInstance()
    96     {
    97         static InGameConsole instance;
    98         return instance;
    99     }
    100 
    101     /**
    102         @brief Sets the config values, describing the size of the console.
    103     */
    104     void InGameConsole::setConfigValues()
    105     {
    106         SetConfigValue(relativeWidth, 0.8);
    107         SetConfigValue(relativeHeight, 0.4);
    108         SetConfigValue(blinkTime, 0.5);
    109         SetConfigValue(scrollSpeed_, 3.0f);
    110         SetConfigValue(noiseSize_, 1.0f);
    111         SetConfigValue(cursorSymbol_, '|');
    112     }
    113 
    114     /**
    115         @brief Initializes the InGameConsole.
    116     */
    117     void InGameConsole::initialise()
    118     {
    119         // create the corresponding input state
    120         InputManager::createSimpleInputState("console", 40)->setKeyHandler(Shell::getInstance().getInputBuffer());
    121 
    122         // create overlay and elements
    123         Ogre::OverlayManager* ovMan = Ogre::OverlayManager::getSingletonPtr();
    124 
    125         // create actual overlay
    126         this->consoleOverlay_ = ovMan->create("InGameConsoleConsole");
    127 
    128         // create a container
    129         this->consoleOverlayContainer_ = static_cast<Ogre::OverlayContainer*>(ovMan->createOverlayElement("Panel", "InGameConsoleContainer"));
    130         this->consoleOverlayContainer_->setMetricsMode(Ogre::GMM_RELATIVE);
    131         this->consoleOverlayContainer_->setPosition((1 - this->relativeWidth) / 2, 0);
    132         this->consoleOverlayContainer_->setDimensions(this->relativeWidth, this->relativeHeight);
    133         this->consoleOverlay_->add2D(this->consoleOverlayContainer_);
    134 
    135         // create BorderPanel
    136         this->consoleOverlayBorder_ = static_cast<Ogre::BorderPanelOverlayElement*>(ovMan->createOverlayElement("BorderPanel", "InGameConsoleBorderPanel"));
    137         this->consoleOverlayBorder_->setMetricsMode(Ogre::GMM_PIXELS);
    138         this->consoleOverlayBorder_->setMaterialName("ConsoleCenter");
    139         this->consoleOverlayBorder_->setBorderSize(16, 16, 0, 16);
    140         this->consoleOverlayBorder_->setBorderMaterialName("ConsoleBorder");
    141         this->consoleOverlayBorder_->setLeftBorderUV(0.0, 0.49, 0.5, 0.51);
    142         this->consoleOverlayBorder_->setRightBorderUV(0.5, 0.49, 1.0, 0.5);
    143         this->consoleOverlayBorder_->setBottomBorderUV(0.49, 0.5, 0.51, 1.0);
    144         this->consoleOverlayBorder_->setBottomLeftBorderUV(0.0, 0.5, 0.5, 1.0);
    145         this->consoleOverlayBorder_->setBottomRightBorderUV(0.5, 0.5, 1.0, 1.0);
    146         this->consoleOverlayContainer_->addChild(this->consoleOverlayBorder_);
    147 
    148         // create a new font to match the requested size exactly
    149         Ogre::FontPtr font = static_cast<Ogre::FontPtr>
    150             (Ogre::FontManager::getSingleton().create("MonofurConsole", "General"));
    151         font->setType(Ogre::FT_TRUETYPE);
    152         font->setSource("Monofur.ttf");
    153         font->setTrueTypeSize(18);
    154         // reto: I don't know why, but setting the resolution twice as high makes the font look a lot clearer
    155         font->setTrueTypeResolution(192);
    156         font->addCodePointRange(Ogre::Font::CodePointRange(33, 126));
    157         font->addCodePointRange(Ogre::Font::CodePointRange(161, 255));
    158 
    159         // create the text lines
    160         this->consoleOverlayTextAreas_ = new Ogre::TextAreaOverlayElement*[LINES];
    161         for (int i = 0; i < LINES; i++)
    162         {
    163             this->consoleOverlayTextAreas_[i] = static_cast<Ogre::TextAreaOverlayElement*>(ovMan->createOverlayElement("TextArea", "InGameConsoleTextArea" + convertToString(i)));
    164             this->consoleOverlayTextAreas_[i]->setMetricsMode(Ogre::GMM_PIXELS);
    165             this->consoleOverlayTextAreas_[i]->setFontName("MonofurConsole");
    166             this->consoleOverlayTextAreas_[i]->setCharHeight(18);
    167             this->consoleOverlayTextAreas_[i]->setParameter("colour_top", "0.21 0.69 0.21");
    168             this->consoleOverlayTextAreas_[i]->setLeft(8);
    169             this->consoleOverlayTextAreas_[i]->setCaption("");
    170             this->consoleOverlayContainer_->addChild(this->consoleOverlayTextAreas_[i]);
    171         }
    172 
    173         // create cursor (also a text area overlay element)
    174         this->consoleOverlayCursor_ = static_cast<Ogre::TextAreaOverlayElement*>(ovMan->createOverlayElement("TextArea", "InGameConsoleCursor"));
    175         this->consoleOverlayCursor_->setMetricsMode(Ogre::GMM_PIXELS);
    176         this->consoleOverlayCursor_->setFontName("MonofurConsole");
    177         this->consoleOverlayCursor_->setCharHeight(18);
    178         this->consoleOverlayCursor_->setParameter("colour_top", "0.21 0.69 0.21");
    179         this->consoleOverlayCursor_->setLeft(7);
    180         this->consoleOverlayCursor_->setCaption(std::string(this->cursorSymbol_, 1));
    181         this->consoleOverlayContainer_->addChild(this->consoleOverlayCursor_);
    182 
    183         // create noise
    184         this->consoleOverlayNoise_ = static_cast<Ogre::PanelOverlayElement*>(ovMan->createOverlayElement("Panel", "InGameConsoleNoise"));
    185         this->consoleOverlayNoise_->setMetricsMode(Ogre::GMM_PIXELS);
    186         this->consoleOverlayNoise_->setPosition(5,0);
    187         this->consoleOverlayNoise_->setMaterialName("ConsoleNoiseSmall");
    188         // comment following line to disable noise
    189         this->consoleOverlayContainer_->addChild(this->consoleOverlayNoise_);
    190 
    191         this->windowResized(GraphicsEngine::getSingleton().getWindowWidth(), GraphicsEngine::getSingleton().getWindowHeight());
    192 
    193         // move overlay "above" the top edge of the screen
    194         // we take -1.2 because the border makes the panel bigger
    195         this->consoleOverlayContainer_->setTop(-1.2 * this->relativeHeight);
    196 
    197         Shell::getInstance().addOutputLevel(true);
    198 
    199         COUT(4) << "Info: InGameConsole initialized" << std::endl;
    200     }
    201 
    202     /**
    203         @brief Destroys all the elements if necessary.
    204     */
    205     void InGameConsole::destroy()
    206     {
    20794        this->deactivate();
    20895
    209         // destroy the input state previously created
    210         SimpleInputState * inputState = dynamic_cast<SimpleInputState*>(InputManager::getState("console"));
    211         if (inputState)
    212             InputManager::destroyState("console");
     96        // destroy the input state previously created (InputBuffer gets destroyed by the Shell)
     97        InputManager::getInstance().destroyState("console");
    21398
    21499        Ogre::OverlayManager* ovMan = Ogre::OverlayManager::getSingletonPtr();
     
    239124            this->consoleOverlayTextAreas_ = 0;
    240125        }
     126
     127        singletonRef_s = 0;
     128    }
     129
     130    /**
     131        @brief Sets the config values, describing the size of the console.
     132    */
     133    void InGameConsole::setConfigValues()
     134    {
     135        SetConfigValue(relativeWidth, 0.8);
     136        SetConfigValue(relativeHeight, 0.4);
     137        SetConfigValue(blinkTime, 0.5);
     138        SetConfigValue(scrollSpeed_, 3.0f);
     139        SetConfigValue(noiseSize_, 1.0f);
     140        SetConfigValue(cursorSymbol_, '|');
     141    }
     142
     143    /**
     144        @brief Initializes the InGameConsole.
     145    */
     146    void InGameConsole::initialise()
     147    {
     148        // create the corresponding input state
     149        InputManager::getInstance().createSimpleInputState("console", 40)
     150            ->setKeyHandler(Shell::getInstance().getInputBuffer());
     151
     152        // create overlay and elements
     153        Ogre::OverlayManager* ovMan = Ogre::OverlayManager::getSingletonPtr();
     154
     155        // create actual overlay
     156        this->consoleOverlay_ = ovMan->create("InGameConsoleConsole");
     157
     158        // create a container
     159        this->consoleOverlayContainer_ = static_cast<Ogre::OverlayContainer*>(ovMan->createOverlayElement("Panel", "InGameConsoleContainer"));
     160        this->consoleOverlayContainer_->setMetricsMode(Ogre::GMM_RELATIVE);
     161        this->consoleOverlayContainer_->setPosition((1 - this->relativeWidth) / 2, 0);
     162        this->consoleOverlayContainer_->setDimensions(this->relativeWidth, this->relativeHeight);
     163        this->consoleOverlay_->add2D(this->consoleOverlayContainer_);
     164
     165        // create BorderPanel
     166        this->consoleOverlayBorder_ = static_cast<Ogre::BorderPanelOverlayElement*>(ovMan->createOverlayElement("BorderPanel", "InGameConsoleBorderPanel"));
     167        this->consoleOverlayBorder_->setMetricsMode(Ogre::GMM_PIXELS);
     168        this->consoleOverlayBorder_->setMaterialName("ConsoleCenter");
     169        this->consoleOverlayBorder_->setBorderSize(16, 16, 0, 16);
     170        this->consoleOverlayBorder_->setBorderMaterialName("ConsoleBorder");
     171        this->consoleOverlayBorder_->setLeftBorderUV(0.0, 0.49, 0.5, 0.51);
     172        this->consoleOverlayBorder_->setRightBorderUV(0.5, 0.49, 1.0, 0.5);
     173        this->consoleOverlayBorder_->setBottomBorderUV(0.49, 0.5, 0.51, 1.0);
     174        this->consoleOverlayBorder_->setBottomLeftBorderUV(0.0, 0.5, 0.5, 1.0);
     175        this->consoleOverlayBorder_->setBottomRightBorderUV(0.5, 0.5, 1.0, 1.0);
     176        this->consoleOverlayContainer_->addChild(this->consoleOverlayBorder_);
     177
     178        // create a new font to match the requested size exactly
     179        Ogre::FontPtr font = static_cast<Ogre::FontPtr>
     180            (Ogre::FontManager::getSingleton().create("MonofurConsole", "General"));
     181        font->setType(Ogre::FT_TRUETYPE);
     182        font->setSource("Monofur.ttf");
     183        font->setTrueTypeSize(18);
     184        // reto: I don't know why, but setting the resolution twice as high makes the font look a lot clearer
     185        font->setTrueTypeResolution(192);
     186        font->addCodePointRange(Ogre::Font::CodePointRange(33, 126));
     187        font->addCodePointRange(Ogre::Font::CodePointRange(161, 255));
     188
     189        // create the text lines
     190        this->consoleOverlayTextAreas_ = new Ogre::TextAreaOverlayElement*[LINES];
     191        for (int i = 0; i < LINES; i++)
     192        {
     193            this->consoleOverlayTextAreas_[i] = static_cast<Ogre::TextAreaOverlayElement*>(ovMan->createOverlayElement("TextArea", "InGameConsoleTextArea" + convertToString(i)));
     194            this->consoleOverlayTextAreas_[i]->setMetricsMode(Ogre::GMM_PIXELS);
     195            this->consoleOverlayTextAreas_[i]->setFontName("MonofurConsole");
     196            this->consoleOverlayTextAreas_[i]->setCharHeight(18);
     197            this->consoleOverlayTextAreas_[i]->setParameter("colour_top", "0.21 0.69 0.21");
     198            this->consoleOverlayTextAreas_[i]->setLeft(8);
     199            this->consoleOverlayTextAreas_[i]->setCaption("");
     200            this->consoleOverlayContainer_->addChild(this->consoleOverlayTextAreas_[i]);
     201        }
     202
     203        // create cursor (also a text area overlay element)
     204        this->consoleOverlayCursor_ = static_cast<Ogre::TextAreaOverlayElement*>(ovMan->createOverlayElement("TextArea", "InGameConsoleCursor"));
     205        this->consoleOverlayCursor_->setMetricsMode(Ogre::GMM_PIXELS);
     206        this->consoleOverlayCursor_->setFontName("MonofurConsole");
     207        this->consoleOverlayCursor_->setCharHeight(18);
     208        this->consoleOverlayCursor_->setParameter("colour_top", "0.21 0.69 0.21");
     209        this->consoleOverlayCursor_->setLeft(7);
     210        this->consoleOverlayCursor_->setCaption(std::string(this->cursorSymbol_, 1));
     211        this->consoleOverlayContainer_->addChild(this->consoleOverlayCursor_);
     212
     213        // create noise
     214        this->consoleOverlayNoise_ = static_cast<Ogre::PanelOverlayElement*>(ovMan->createOverlayElement("Panel", "InGameConsoleNoise"));
     215        this->consoleOverlayNoise_->setMetricsMode(Ogre::GMM_PIXELS);
     216        this->consoleOverlayNoise_->setPosition(5,0);
     217        this->consoleOverlayNoise_->setMaterialName("ConsoleNoiseSmall");
     218        // comment following line to disable noise
     219        this->consoleOverlayContainer_->addChild(this->consoleOverlayNoise_);
     220
     221        this->windowResized(GraphicsEngine::getSingleton().getWindowWidth(), GraphicsEngine::getSingleton().getWindowHeight());
     222
     223        // move overlay "above" the top edge of the screen
     224        // we take -1.2 because the border makes the panel bigger
     225        this->consoleOverlayContainer_->setTop(-1.2 * this->relativeHeight);
     226
     227        Shell::getInstance().addOutputLevel(true);
     228
     229        COUT(4) << "Info: InGameConsole initialized" << std::endl;
    241230    }
    242231
     
    491480        {
    492481            this->bActive_ = true;
    493             InputManager::requestEnterState("console");
     482            InputManager::getInstance().requestEnterState("console");
    494483            Shell::getInstance().registerListener(this);
    495484
     
    513502        {
    514503            this->bActive_ = false;
    515             InputManager::requestLeaveState("console");
     504            InputManager::getInstance().requestLeaveState("console");
    516505            Shell::getInstance().unregisterListener(this);
    517506
  • code/branches/gui/src/orxonox/overlays/console/InGameConsole.h

    r1641 r1642  
    4646    {
    4747    public: // functions
     48        InGameConsole();
     49        ~InGameConsole();
     50
    4851        void initialise();
    4952        void destroy();
     
    5255        void tick(float dt);
    5356
    54         static InGameConsole& getInstance();
     57        static InGameConsole& getInstance() { assert(singletonRef_s); return *singletonRef_s; }
     58        static InGameConsole* getInstancePtr() { return singletonRef_s; }
    5559
    5660        static void openConsole();
     
    5862
    5963    private: // functions
    60         InGameConsole();
    6164        InGameConsole(const InGameConsole& other) {}
    62         ~InGameConsole();
    6365
    6466        void activate();
     
    107109        float noiseSize_;
    108110        char cursorSymbol_;
     111
     112        static InGameConsole* singletonRef_s;
    109113    };
    110114}
  • code/branches/gui/src/tolua/CMakeLists.txt

    r1582 r1642  
    1515SET (TOLUAEXE_SRC_FILES
    1616  tolua.c
    17   toluabind.c
     17  toluabind_orxonox.c
    1818)
    1919
  • code/branches/gui/visual_studio/base_properties.vsprops

    r1638 r1642  
    99                Name="VCCLCompilerTool"
    1010                AdditionalIncludeDirectories="&quot;$(RootDir)&quot;;&quot;$(RootDir)src&quot;;&quot;$(RootDir)src\orxonox&quot;;&quot;$(RootDir)src\tolua&quot;;&quot;$(RootDir)src\ois&quot;;&quot;$(LibDir)ogre-1.4.8\OgreMain\include&quot;;&quot;$(LibDir)boost-1.35.0&quot;;&quot;$(LibDir)cegui-0.6.1\include&quot;;&quot;$(LibDir)cegui-0.6.1\ScriptingModules\CEGUILua\LuaScriptModule\include&quot;;&quot;$(LibDir)enet-1.2\include&quot;;&quot;$(LibDir)libogg-1.1.3\include&quot;;&quot;$(LibDir)libvorbis-1.2.0\include&quot;;&quot;$(LibDir)lua-5.1.3\src&quot;;&quot;$(LibDir)openal-1.1\include&quot;;&quot;$(LibDir)openal-1.1\alut\include&quot;;&quot;$(LibDir)tcl-8.5.\generic&quot;;&quot;$(LibDir)zlib-1.2.3&quot;;&quot;$(LibDir)ogre-1.4.9\Samples\Common\CEGUIRenderer\include&quot;"
    11                 AdditionalOptions="/MP2"
    1211                PreprocessorDefinitions="WIN32;__WIN32__;_WIN32;BOOST_ALL_DYN_LINK;OIS_DYNAMIC_LIB; ZLIB_WINAPI"
    1312                WarningLevel="3"
  • code/branches/gui/visual_studio/core_properties.vsprops

    r1572 r1642  
    88        <Tool
    99                Name="VCCLCompilerTool"
     10                AdditionalOptions="/MP2"
    1011                PreprocessorDefinitions="CORE_SHARED_BUILD"
    1112        />
  • code/branches/gui/visual_studio/network_properties.vsprops

    r1293 r1642  
    88        <Tool
    99                Name="VCCLCompilerTool"
     10                AdditionalOptions="/MP2"
    1011                PreprocessorDefinitions="ORXONOX_NO_EXPORTS;NETWORK_STATIC_BUILD;WIN32_LEAN_AND_MEAN"
    1112        />
  • code/branches/gui/visual_studio/orxonox_properties.vsprops

    r1638 r1642  
    88        <Tool
    99                Name="VCCLCompilerTool"
     10                AdditionalOptions="/MP2"
    1011                PreprocessorDefinitions="ORXONOX_NO_EXPORTS;NETWORK_STATIC_BUILD;OGRE_GUIRENDERER_EXPORTS"
    1112                UsePrecompiledHeader="2"
Note: See TracChangeset for help on using the changeset viewer.