Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/wiimote/src/libraries/core/input/InputState.cc @ 11761

Last change on this file since 11761 was 9805, checked in by smerkli, 11 years ago
  • Converted some absolute paths into relative ones
  • Increased the handlers_ vector size by 1 as a hack to get the wiimote working in this branch (This will have to be cleanly redone once I have a better concept for wiimotes and joysticks)
  • Removed a local inputStates_ variable that georgr added in wiimote, it shadowed the one from the basis class and hence never got any entries

To be discussed with georgr on monday.

  • Property svn:eol-style set to native
File size: 3.7 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#include "InputState.h"
30#include "core/command/Functor.h"
31
32namespace orxonox
33{
34    //! Sets priority of it's a high priority and resizes the handler list
35    InputState::InputState(const std::string& name, bool bAlwaysGetsInput, bool bTransparent, InputStatePriority priority)
36        : name_(name)
37        , bAlwaysGetsInput_(bAlwaysGetsInput)
38        , bTransparent_(bTransparent)
39        , exclusiveMouse_(dontcare)
40        , bExpired_(true)
41        , handlers_(2)
42        , joyStickHandlerAll_(0)
43        , enterFunctor_(0)
44        , leaveFunctor_(0)
45    {
46        if (priority >= InputStatePriority::HighPriority || priority == InputStatePriority::Empty)
47            priority_ = priority;
48        else
49            priority_ = 0;
50
51        // SANDRO HACK: make this 1 larger so we can have the wiimote read out as well
52        //handlers_.resize(InputDeviceEnumerator::FirstJoyStick + this->getJoyStickList().size(), NULL);
53        handlers_.resize(InputDeviceEnumerator::FirstJoyStick
54          + 1 +  this->getJoyStickList().size(), NULL);
55    }
56
57    bool InputState::isInputDeviceEnabled(unsigned int device)
58    {
59        if (device < handlers_.size())
60        {       orxout() << "Test we made it into the if clause" << std::endl;
61            return handlers_[device] != NULL;
62        }
63        else
64            return false;
65    }
66
67    //! Called by JoyStickQuantityListener upon joy stick adding/removal
68    void InputState::JoyStickQuantityChanged(const std::vector<JoyStick*>& joyStickList)
69    {
70        unsigned int oldSize = handlers_.size();
71        handlers_.resize(InputDeviceEnumerator::FirstJoyStick + joyStickList.size(), NULL);
72
73        for (unsigned int i = oldSize; i < handlers_.size(); ++i)
74            handlers_[i] = joyStickHandlerAll_;
75
76        bExpired_ = true;
77    }
78
79    bool InputState::setJoyStickHandler(InputHandler* handler, unsigned int joyStick)
80    {
81        unsigned device = joyStick + firstJoyStickIndex_s;
82        if (joyStick >= handlers_.size() - device)
83            return false;
84
85        handlers_[device] = handler;
86        bExpired_ = true;
87        return true;
88    }
89
90    void InputState::setJoyStickHandler(InputHandler* handler)
91    {
92        joyStickHandlerAll_ = handler;
93        for (unsigned int i = firstJoyStickIndex_s; i < handlers_.size(); ++i)
94            handlers_[i] = handler;
95        bExpired_ = true;
96    }
97
98    void InputState::setHandler(InputHandler* handler)
99    {
100        setKeyHandler(handler);
101        setMouseHandler(handler);
102        setJoyStickHandler(handler);
103        setWiiMoteHandler(handler); // SANDRO HACK
104    }
105
106    void InputState::entered()
107    {
108        if (enterFunctor_)
109            (*enterFunctor_)();
110
111    }
112
113    void InputState::left()
114    {
115        if (leaveFunctor_)
116            (*leaveFunctor_)();
117    }
118}
Note: See TracBrowser for help on using the repository browser.