wavelength 1.0.0
Loading...
Searching...
No Matches
inputmgr.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4#include <memory>
5#include <vector>
6
7#include "app/msgsink.h"
9#include "game/world.h"
10#include "msg/joypadinputmsg.h"
11#include "os/mem.h"
12#include "os/timer.h"
13
22class InputMgr : public MsgSink {
23public:
30 public:
33 mRepeatTimer.SetCycles(0);
34 mRepeatTimer.SetLastMs(0.0f);
35 mRepeatTimer.SetRunning(0);
36 }
37
40 return mStick.get();
41 }
42
44 const ExpressionStick *GetStick() const {
45 return mStick.get();
46 }
47
53 void SetStick(std::unique_ptr<ExpressionStick> pStick) {
54 mStick = std::move(pStick);
55 }
56
58 void ResetStick() {
59 mStick.reset();
60 }
61
63 int GetPositionStick() const {
64 return mPositionStick;
65 }
66
72 void SetPositionStick(int nPositionStick) {
73 mPositionStick = nPositionStick;
74 }
75
78 return mRepeatTimer;
79 }
80
82 float GetRepeatMs() const {
83 return mRepeatMs;
84 }
85
91 void SetRepeatMs(float fRepeatMs) {
92 mRepeatMs = fRepeatMs;
93 }
94
96 int GetDirection() const {
97 return mDirection;
98 }
99
105 void SetDirection(int nDirection) {
106 mDirection = nDirection;
107 }
108
109 private:
110 std::unique_ptr<ExpressionStick> mStick;
111 int mPositionStick;
112 Timer mRepeatTimer;
113 float mRepeatMs;
114 int mDirection = 0;
115 };
116
124 explicit InputMgr(World *pWorld);
125
134 void *operator new(size_t nSize) {
135 return PoolMemAlloc(static_cast<int>(nSize), "InputMgr", 0);
136 }
137
144 ~InputMgr() override;
145
152 void Poll();
153
161 void RepeatRotation(int nPad);
162
174
183 bool DispatchPriv(Message *pMsg) override;
184
185private:
186 World *mWorld;
187 std::vector<ControllerData> mControllers;
188 std::vector<int> mLocalPlayers;
189 float mRepeatInitialDelayMs;
190 float mRepeatDelayMs;
191 int mDemo;
192};
Analogue stick of one controller that bends the notes a player plays.
Definition expressionstick.h:13
void ResetStick()
Release the stick at the point the destructor originally deleted it.
Definition inputmgr.h:58
void SetPositionStick(int nPositionStick)
Set the stick whose position goes to the world every frame.
Definition inputmgr.h:72
Timer & GetRepeatTimer()
Definition inputmgr.h:77
void SetRepeatMs(float fRepeatMs)
Set mRepeatTimer in milliseconds at the last repeat check.
Definition inputmgr.h:91
ControllerData()
Construct the state with a stopped repeat timer.
Definition inputmgr.h:32
float GetRepeatMs() const
Definition inputmgr.h:82
ExpressionStick * GetStick()
Definition inputmgr.h:39
int GetPositionStick() const
Definition inputmgr.h:63
const ExpressionStick * GetStick() const
Definition inputmgr.h:44
void SetStick(std::unique_ptr< ExpressionStick > pStick)
Take the stick that bends the notes of the player.
Definition inputmgr.h:53
int GetDirection() const
Definition inputmgr.h:96
void SetDirection(int nDirection)
Set the direction of the rotation that repeats.
Definition inputmgr.h:105
InputMgr(World *pWorld)
Construct a router for one world.
bool HandleButton(JoypadInputMsg *pMsg)
Turn a button of a controller into the input event of its bound action.
void RepeatRotation(int nPad)
Repeat the rotation of a controller once each repeat interval after the initial delay.
void Poll()
Route the controller input of one frame to the world.
~InputMgr() override
Release the router.
bool DispatchPriv(Message *pMsg) override
Act on a message sent to the router.
Message the controller poll sends when a button is pressed or released.
Definition joypadinputmsg.h:23
Base of every event the game passes between a MsgSource and a MsgSink.
Definition message.h:40
Receiver of engine messages.
Definition msgsink.h:21
Stopwatch on the EE cycle counter.
Definition timer.h:16
One game in progress under one rule set.
Definition world.h:31
void * PoolMemAlloc(int nSize, const char *pszTag, int nAlign)
Allocate a block from the pool heaps and bill it to a tag.