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