Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/gui/src/core/input/InputState.h @ 1645

Last change on this file since 1645 was 1642, checked in by rgrieder, 17 years ago
  • 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
  • Property svn:eol-style set to native
File size: 4.3 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Reto Grieder
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29/**
30@file
31@brief
32*/
33
34#ifndef _InputState_H__
35#define _InputState_H__
36
37#include "core/CorePrereqs.h"
38
39#include <string>
40#include <vector>
41#include "core/Executor.h"
42#include "core/BaseObject.h"
43#include "core/CoreIncludes.h"
44#include "InputInterfaces.h"
45
46namespace orxonox
47{
48    class _CoreExport InputState : public BaseObject
49    {
50        friend class InputManager;
51
52    public:
53        InputState() : priority_(0), executorOnEnter_(0), executorOnLeave_(0)
54        { RegisterObject(InputState); }
55        virtual ~InputState() { }
56
57        const std::string& getName() const { return name_; }
58        int getPriority()            const { return priority_; }
59
60        bool isInputDeviceEnabled(unsigned int device)
61        {
62            if (device < bInputDeviceEnabled_.size())
63                return bInputDeviceEnabled_[device];
64            else
65                return false;
66        }
67
68        virtual void onEnter() { if (executorOnEnter_) (*executorOnEnter_)(); }
69        virtual void onLeave() { if (executorOnLeave_) (*executorOnLeave_)(); }
70
71        virtual void registerOnEnter(Executor* executor)      { executorOnEnter_ = executor; }
72        virtual void unRegisterOnEnter()                      { executorOnEnter_ = 0; }
73        virtual void registerOnLeave(Executor* executor)      { executorOnLeave_ = executor; }
74        virtual void unRegisterOnLeave()                      { executorOnLeave_ = 0; }
75
76        virtual void tickInput(float dt, unsigned int device) = 0;
77        virtual void tickInput(float dt) = 0;
78
79        virtual void keyPressed (const KeyEvent& evt) = 0;
80        virtual void keyReleased(const KeyEvent& evt) = 0;
81        virtual void keyHeld    (const KeyEvent& evt) = 0;
82
83        virtual void mouseButtonPressed (MouseButton::Enum id) = 0;
84        virtual void mouseButtonReleased(MouseButton::Enum id) = 0;
85        virtual void mouseButtonHeld    (MouseButton::Enum id) = 0;
86        virtual void mouseMoved         (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize) = 0;
87        virtual void mouseScrolled      (int abs, int rel) = 0;
88
89        virtual void joyStickButtonPressed (unsigned int joyStickID, JoyStickButton::Enum id) = 0;
90        virtual void joyStickButtonReleased(unsigned int joyStickID, JoyStickButton::Enum id) = 0;
91        virtual void joyStickButtonHeld    (unsigned int joyStickID, JoyStickButton::Enum id) = 0;
92        virtual void joyStickAxisMoved     (unsigned int joyStickID, unsigned int axis, float value) = 0;
93
94    protected:
95        virtual void numberOfJoySticksChanged(unsigned int n) = 0;
96        void setInputDeviceEnabled(unsigned int device, bool bEnabled)
97        {
98            if (device < bInputDeviceEnabled_.size())
99                bInputDeviceEnabled_[device] = bEnabled;
100        }
101
102    private:
103        void setNumOfJoySticks(unsigned int n)
104        {
105            bInputDeviceEnabled_.resize(n + 2);
106            numberOfJoySticksChanged(n);
107        }
108        void setName(const std::string& name)  { name_ = name; }
109        void setPriority(int priority)         { priority_ = priority; }
110
111        std::string                                 name_;
112        int                                         priority_;
113        std::vector<bool>                           bInputDeviceEnabled_;
114
115        Executor*                                   executorOnEnter_;
116        Executor*                                   executorOnLeave_;
117    };
118}
119
120#endif /* _InputState_H__ */
Note: See TracBrowser for help on using the repository browser.