Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/*
   Copyright (c) 2017 DIVIDE-Studio
   Copyright (c) 2009 Ionut Cava

   This file is part of DIVIDE Framework.

   Permission is hereby granted, free of charge, to any person obtaining a copy
   of this software
   and associated documentation files (the "Software"), to deal in the Software
   without restriction,
   including without limitation the rights to use, copy, modify, merge, publish,
   distribute, sublicense,
   and/or sell copies of the Software, and to permit persons to whom the
   Software is furnished to do so,
   subject to the following conditions:

   The above copyright notice and this permission notice shall be included in
   all copies or substantial portions of the Software.

   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   IMPLIED,
   INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
   PARTICULAR PURPOSE AND NONINFRINGEMENT.
   IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
   DAMAGES OR OTHER LIABILITY,
   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
   IN CONNECTION WITH THE SOFTWARE
   OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

 */

#ifndef _SCENE_INPUT_H_
#define _SCENE_INPUT_H_

#include "SceneInputActions.h"
#include "Platform/Input/Headers/InputInterface.h"

namespace Divide {

// This is the callback equivalent of PressReleaseAction with IDs resolved
struct PressReleaseActionCbks {
    // key only
    DELEGATE_CBK<void, InputParams> _onPressAction;
    DELEGATE_CBK<void, InputParams> _onReleaseAction;

    DELEGATE_CBK<void, InputParams> _onLCtrlPressAction;
    DELEGATE_CBK<void, InputParams> _onLCtrlReleaseAction;
    DELEGATE_CBK<void, InputParams> _onRCtrlPressAction;
    DELEGATE_CBK<void, InputParams> _onRCtrlReleaseAction;

    DELEGATE_CBK<void, InputParams> _onLAltPressAction;
    DELEGATE_CBK<void, InputParams> _onLAltReleaseAction;
    DELEGATE_CBK<void, InputParams> _onRAltPressAction;
    DELEGATE_CBK<void, InputParams> _onRAltReleaseAction;

    void from(const PressReleaseActions& actions, const InputActionList& actionList);
};

class JoystickHasher
{
public:
    size_t operator()(const Input::JoystickElement& k) const
    {
        size_t hash = 0;
        Util::Hash_combine(hash, to_uint(k._type));
        Util::Hash_combine(hash, k._data);
        return hash;
    }
};

class SceneInput : public Input::InputAggregatorInterface {
   public:
    typedef hashMapImpl<Input::KeyCode, PressReleaseActionCbks, std::hash<I32>> KeyMapCache;
    typedef hashMapImpl<Input::MouseButton, PressReleaseActionCbks, std::hash<I32>> MouseMapCache;
    typedef hashMapImpl<Input::JoystickElement, PressReleaseActionCbks, JoystickHasher> JoystickMapCacheEntry;
    typedef hashMapImpl<Input::Joystick, JoystickMapCacheEntry> JoystickMapCache;

    typedef hashMapImpl<Input::KeyCode, PressReleaseActions, std::hash<I32>> KeyMap;
    typedef hashMapImpl<Input::MouseButton, PressReleaseActions, std::hash<I32>> MouseMap;
    typedef hashMapImpl<Input::JoystickElement, PressReleaseActions, JoystickHasher> JoystickMapEntry;
    typedef hashMapImpl<Input::Joystick, JoystickMapEntry> JoystickMap;

    typedef vectorImpl<std::pair<Input::KeyCode, Input::InputState>> KeyLog;
    typedef vectorImpl<std::tuple<Input::MouseButton, Input::InputState, vec2<I32>>> MouseBtnLog;

    explicit SceneInput(Scene &parentScene, Input::InputInterface& context);

    bool onKeyDown(const Input::KeyEvent &arg);
    bool onKeyUp(const Input::KeyEvent &arg);
    /// Joystick or Gamepad
    bool joystickButtonPressed(const Input::JoystickEvent &arg,
                               Input::JoystickButton button);
    bool joystickButtonReleased(const Input::JoystickEvent &arg,
                                Input::JoystickButton button);
    bool joystickAxisMoved(const Input::JoystickEvent &arg, I8 axis);
    bool joystickPovMoved(const Input::JoystickEvent &arg, I8 pov);
    bool joystickSliderMoved(const Input::JoystickEvent &, I8 index);
    bool joystickVector3DMoved(const Input::JoystickEvent &arg, I8 index);
    /// Mouse
    bool mouseMoved(const Input::MouseEvent &arg);
    bool mouseButtonPressed(const Input::MouseEvent &arg,
                            Input::MouseButton id);
    bool mouseButtonReleased(const Input::MouseEvent &arg,
                             Input::MouseButton id);

    /// Returns false if the key is already assigned.
    /// Call removeKeyMapping for the specified key first
    bool addKeyMapping(Input::KeyCode key, PressReleaseActions keyCbks);
    /// Returns false if the key wasn't previously assigned
    bool removeKeyMapping(Input::KeyCode key);
    /// Returns true if the key has a valid mapping and sets the callback output
    /// to the mapping's function
    bool getKeyMapping(Input::KeyCode key, PressReleaseActionCbks& keyCbkOut);

    /// Returns false if the button is already assigned.
    /// Call removeButtonMapping for the specified key first
    bool addMouseMapping(Input::MouseButton button, PressReleaseActions btnCbks);
    /// Returns false if the button wasn't previously assigned
    bool removeMouseMapping(Input::MouseButton button);
    /// Returns true if the button has a valid mapping and sets the callback
    /// output to the mapping's function
    bool getMouseMapping(Input::MouseButton button, PressReleaseActionCbks& btnCbksOut);

    /// Returns false if the button is already assigned.
    /// Call removeJoystickMapping for the specified key first
    bool addJoystickMapping(Input::Joystick device, Input::JoystickElement element, PressReleaseActions btnCbks);
    /// Returns false if the button wasn't previously assigned
    bool removeJoystickMapping(Input::Joystick device, Input::JoystickElement element);
    /// Returns true if the button has a valid mapping and sets the callback
    /// output to the mapping's function
    bool getJoystickMapping(Input::Joystick device, Input::JoystickElement element, PressReleaseActionCbks& btnCbksOut);

    Input::InputState getKeyState(U8 deviceIndex, Input::KeyCode key) const;
    Input::InputState getMouseButtonState(U8 deviceIndex, Input::MouseButton button) const;
    Input::InputState getJoystickButtonState(Input::Joystick deviceIndex, Input::JoystickButton button) const;

    InputActionList& actionList();

    U8 getPlayerIndexForDevice(U8 deviceIndex) const;

    void flushCache();

    void onPlayerAdd(U8 index);
    void onPlayerRemove(U8 index);

    void onSetActive();
    void onRemoveActive();

   protected:
       bool handleCallbacks(const PressReleaseActionCbks& cbks,
                            const InputParams& params,
                            bool onPress);

       bool isDeviceInUse(I32 deviceID);

   private:
    // Up to 2 devices per player: KB + Mouse or Nintendo Switch type controllers
    // If one current player only uses one device, leave pair.second to -1
    hashMapImpl<U8 /*player index*/, std::pair<I32, I32>> _playerControlDevices;

    vectorImpl<I32> _usedInputDevices;

    Input::InputInterface& _context;
    Scene &_parentScene;

    KeyMap _keyMap;
    MouseMap _mouseMap;
    JoystickMap _joystickMap;

    KeyMapCache _keyMapCache;
    MouseMapCache _mouseMapCache;
    JoystickMapCache _joystickMapCache;

    InputActionList _actionList;

    hashMapImpl<U8, KeyLog> _keyLog;
    hashMapImpl<U8, MouseBtnLog> _mouseBtnLog;

};  // SceneInput

};  // namespace Divide
#endif  //_SCENE_INPUT_H_

Commits for Divide-Framework/trunk/Source Code/Scenes/Headers/SceneInput.h

Diff revisions: vs.
Revision Author Commited Message
842 Diff Diff IonutCava picture IonutCava Wed 01 Feb, 2017 17:25:15 +0000

[IonutCava]
- Start to implement scripting support via ChaiScript: http://chaiscript.com/
- Cleanup DELEGATE_CBK alias

836 Diff Diff IonutCava picture IonutCava Fri 27 Jan, 2017 14:59:56 +0000

[IonutCava]
- Update copyright notice

817 Diff Diff IonutCava picture IonutCava Sun 15 Jan, 2017 21:29:59 +0000

[IonutCava]
- Add a new Unit component to SGNs that holds NPC/Player/etc. objects
- Add support for multiple keyboard+mouse combos and joysticks and add mapping between these and players

816 Diff Diff IonutCava picture IonutCava Fri 13 Jan, 2017 17:05:20 +0000

[IonutCava]
- Allow per player scene state and input source
— Add SceneStatePerPlayer class
— Add device index to InputParams objects.
— ToDo: map players to devide indices

801 Diff Diff IonutCava picture IonutCava Sun 27 Nov, 2016 21:28:01 +0000

[IonutCava]
- More performance analysis guided optimizations.
- Some refactoring to allow later removal of Singletons status for: GFXDevice, SFXDevice, PXDevice, GUI and Input.
— Pass a PlatformContext around objects to access these classes.

703 Diff Diff IonutCava picture IonutCava Wed 11 May, 2016 15:44:57 +0000

[IonutCava]
- Finish XML-based control bindings:
— Allow per bind input params (key id, mouse button index, joystick control data, etc)
— Allow mouse binding (with up to 7 buttons)
— Allow up to 4 joysticks (for now) with 120+ button, POV, Axis, Slider and Vector binding support for each
- Change all hashes in code from U32 to size_t for compatibility with STL/Boost

699 Diff Diff IonutCava picture IonutCava Tue 10 May, 2016 16:16:57 +0000

[IonutCava]
- Initial key binding code with external XML support
— Allow separation of actions and keys
— Specify actions in code by id
— Specify action id for each Key state
— Allow key modifiers: Left/Right Alt, Left/Right Ctrl

- Initial default scene code

648 Diff Diff IonutCava picture IonutCava Sun 21 Feb, 2016 16:32:52 +0000

[IonutCava]
- Update copyright notice
- Move BoundingBox and BoundingSphere to a new BoundsComponent
— Add a temp hack in SceneGraphNode to update these

456 Diff Diff IonutCava picture IonutCava Mon 01 Jun, 2015 16:11:31 +0000

[Ionut]
- More linux port work (does not compile)

433 IonutCava picture IonutCava Wed 13 May, 2015 15:57:17 +0000

[Ionut]
- Some code cleanup (global functions now start with a capital case)
- Some fixed timestep adjustments
- Input logging (key presses & mouse button presses with location at event time)