resonance 1.0.1
Loading...
Searching...
No Matches
inputmap.h
Go to the documentation of this file.
1#pragma once
2
3#include <list>
4#include <map>
5#include <vector>
6
7#include "app/msgsink.h"
8#include "app/msgsource.h"
9#include "mid/tick.h"
10
11class Globals;
12class Message;
13class Player;
15
30class InputMap : public MsgSource, public MsgSink {
31public:
33 enum Action {
34 kActionRotateLeft = 0x726f744c,
35 kActionRotateRight = 0x726f7452,
36 kActionPlayback = 0x7062636b,
37 };
38
44 class Binding {
45 public:
53 delete mState;
54 }
55
56 int mSlot;
57 int mAction;
58 int mExtra;
60 int *mState;
61 };
62
71 InputMap(Globals *pGlobals, std::vector<Player *> *pPlayers);
72
79 virtual ~InputMap();
80
88 virtual void DispatchPriv(Message *pMsg);
89
97 static InputMap *shared();
98
109 static int MakeKey(int nDevice, int nPort, int nButton);
110
118
126
138 void SetEnabled(int nSlot, int nAction, int nEnabled);
139
154 void AddBinding(int nDevice, int nPort, int nButton, int nSlot, int nAction, int nExtra);
155
167 void Rebuild();
168
178
179private:
180 // The two axis actions, `powx` and `powy`, whose bindings retain an axis state, and the
181 // actions only OnControllerReading() reads.
182 enum {
183 kActionAxisX = 0x706f7778,
184 kActionAxisY = 0x706f7779,
185 kActionAdvance = 0x6164766e,
186 kActionAxisFX = 0x61786678,
187 kActionAxisRegister = 0x72656769,
188 kActionButtonPow = 0x706f7762,
189 kActionErase = 0x65726173,
190 kActionGhost = 0x67686f73,
191 kActionLoop = 0x6c6f6f70,
192 kActionPitchRiff = 0x72706368,
193 };
194
195 // The player slots and the riffs per slot mRiffActive covers.
196 enum {
197 kSlotCount = 4,
198 kRiffCount = 3,
199 };
200
211 void OnControllerReading(RawControllerMsg *pMsg);
212
223 void SendStopRiff(Sch::Tick position, Player *pPlayer, int nTrack, int nRiff);
224
231 void SendPitchRiff(Sch::Tick position, Player *pPlayer, int nTrack, int nRiff);
232
240 std::list<Binding>::iterator FindOrAddBinding(const Binding &binding);
241
250 void ClearBindingMap();
251
252 Globals *mGlobals;
253 std::list<Binding> mBindings;
254 std::map<int, std::list<Binding>::iterator> mBindingMap;
255 std::vector<Player *> *mPlayers;
256 // One word per slot and riff, cleared whenever the riffs stop. The constructor and
257 // StopAllRiffs() zero every word, and the image has no reader.
258 int mRiffActive[kSlotCount][kRiffCount];
259};
260
267extern InputMap *g_pInputMap;
Abstract owner of the process-wide services.
Definition globals.h:47
One player slot's use of one action.
Definition inputmap.h:44
int * mState
Definition inputmap.h:60
int mExtra
Definition inputmap.h:58
int mSlot
Definition inputmap.h:56
int mAction
Definition inputmap.h:57
int mEnabled
Definition inputmap.h:59
~Binding()
Release the axis state.
Definition inputmap.h:52
Translator from controller readings to the players of one game world.
Definition inputmap.h:30
virtual void DispatchPriv(Message *pMsg)
Pass a RawControllerMsg to OnControllerReading() and ignore every other message.
void StopAllRiffs()
Stop the three riffs of every player at the current song position.
static int MakeKey(int nDevice, int nPort, int nButton)
Pack a device, a port, and a button into a key of mBindingMap.
void EnableEntries()
Set the enable word of every binding.
virtual ~InputMap()
Clear g_pInputMap and release every binding.
void Rebuild()
Rebuild mBindingMap from the controller configuration.
void DisableEntries()
Clear the enable word of every binding.
InputMap(Globals *pGlobals, std::vector< Player * > *pPlayers)
Build the map with no binding and record it in g_pInputMap.
static InputMap * shared()
Report the map that exists.
Action
Actions other classes enable and disable, as four-character codes.
Definition inputmap.h:33
@ kActionRotateRight
Definition inputmap.h:35
@ kActionPlayback
Definition inputmap.h:36
@ kActionRotateLeft
Definition inputmap.h:34
void AddBinding(int nDevice, int nPort, int nButton, int nSlot, int nAction, int nExtra)
Bind one physical control to one slot's action.
void SetEnabled(int nSlot, int nAction, int nEnabled)
Set the enable word of every binding of one slot and one action.
Base of every event the game passes between a MsgSource and a MsgSink.
Definition message.h:41
Receiver of engine messages.
Definition msgsink.h:37
Sender of engine messages, which stores the list of sinks that receive them.
Definition msgsource.h:26
One participant in a session, local or remote.
Definition player.h:39
Event the game passes between a MsgSource and a MsgSink.
Definition rawcontrollermsg.h:24
InputMap * g_pInputMap
The map that exists, or null.