JNGL
Controller.hpp
Go to the documentation of this file.
1 // Copyright 2017-2020 Jan Niklas Hasse <[email protected]>
2 // For conditions of distribution and use, see copyright notice in LICENSE.txt
4 #pragma once
5 
6 #include "input.hpp"
7 
8 #include <chrono>
9 
10 namespace jngl {
11 
13 class Controller : public std::enable_shared_from_this<Controller> {
14 public:
15  Controller() = default;
16  virtual ~Controller() = default;
17  Controller(const Controller&) = delete;
18  Controller& operator=(const Controller&) = delete;
19  Controller(Controller&&) = delete;
20  Controller& operator=(Controller&&) = delete;
21 
23  float state(controller::Button) const;
24 
26  virtual bool down(controller::Button) const = 0;
27 
30 
32  virtual void rumble(float, std::chrono::milliseconds);
33 
34 private:
35  virtual float stateImpl(controller::Button) const = 0;
36 
37  enum class ButtonState {
38  UNKNOWN,
39  PRESSED,
40  NOT_PRESSED,
41  WAITING_FOR_UP,
42  };
43  ButtonState buttonPressed[jngl::controller::Last] = { ButtonState::UNKNOWN };
44 };
45 
46 } // namespace jngl
jngl::Controller
Object representing one Gamepad controller.
Definition: Controller.hpp:13
jngl::controller::Button
Button
Gamepad buttons.
Definition: input.hpp:152
std::chrono::milliseconds
jngl::Controller::rumble
virtual void rumble(float, std::chrono::milliseconds)
0 = no vibration, 1 = maximum
jngl
JNGL's main namespace.
Definition: App.hpp:9
jngl::Controller::pressed
bool pressed(controller::Button)
Returns true only once per frame (until jngl::updateInput is called) for every button press.
chrono
std::enable_shared_from_this
jngl::Controller::down
virtual bool down(controller::Button) const =0
Returns true when the button is down.
input.hpp
Input related functions.
jngl::Controller::state
float state(controller::Button) const
Returns a value between 0.0f (not pressed) and 1.0f (pressed)