You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
930 B
51 lines
930 B
|
5 years ago
|
#pragma once
|
||
|
|
|
||
|
5 years ago
|
#include <stdint.h>
|
||
|
|
|
||
|
5 years ago
|
namespace devilution {
|
||
|
5 years ago
|
|
||
|
5 years ago
|
enum AxisDirectionX : uint8_t {
|
||
|
5 years ago
|
AxisDirectionX_NONE,
|
||
|
5 years ago
|
AxisDirectionX_LEFT,
|
||
|
|
AxisDirectionX_RIGHT
|
||
|
|
};
|
||
|
5 years ago
|
enum AxisDirectionY : uint8_t {
|
||
|
5 years ago
|
AxisDirectionY_NONE,
|
||
|
5 years ago
|
AxisDirectionY_UP,
|
||
|
|
AxisDirectionY_DOWN
|
||
|
|
};
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @brief 8-way direction of a D-Pad or a thumb stick.
|
||
|
|
*/
|
||
|
|
struct AxisDirection {
|
||
|
|
AxisDirectionX x;
|
||
|
|
AxisDirectionY y;
|
||
|
|
};
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @brief Returns a non-empty AxisDirection at most once per the given time interval.
|
||
|
|
*/
|
||
|
|
class AxisDirectionRepeater {
|
||
|
|
public:
|
||
|
|
AxisDirectionRepeater(int min_interval_ms = 200)
|
||
|
|
: last_left_(0)
|
||
|
|
, last_right_(0)
|
||
|
|
, last_up_(0)
|
||
|
|
, last_down_(0)
|
||
|
|
, min_interval_ms_(min_interval_ms)
|
||
|
|
{
|
||
|
|
}
|
||
|
|
|
||
|
|
AxisDirection Get(AxisDirection axis_direction);
|
||
|
|
|
||
|
|
private:
|
||
|
|
int last_left_;
|
||
|
|
int last_right_;
|
||
|
|
int last_up_;
|
||
|
|
int last_down_;
|
||
|
|
int min_interval_ms_;
|
||
|
|
};
|
||
|
|
|
||
|
5 years ago
|
} // namespace devilution
|