18#include <toml++/toml.hpp>
25class TOAST_API IModifier {
27 IModifier() =
default;
28 IModifier(
const IModifier&) =
default;
29 auto operator=(
const IModifier&) -> IModifier& =
default;
30 virtual ~IModifier() =
default;
41 virtual auto name() const -> std::string_view = 0;
48 static auto
fromToml(const toml::table& table) -> std::shared_ptr<IModifier>;
54 return (mask & key) == key;
62class DeadzoneModifier :
public IModifier {
64 explicit DeadzoneModifier(
const toml::table& t)
65 : m_lower(parse::number(t[
"lower_threshold"], 0.2f)),
66 m_upper(parse::number(t[
"upper_threshold"], 1.0f)) { }
69 value.data.x = remap(value.data.x);
70 value.data.y = remap(value.data.y);
74 auto name() const -> std::string_view
override {
80 auto remap(
float v)
const ->
float {
81 const float mag = std::abs(v);
85 const float span = std::max(m_upper - m_lower, 0.0001f);
86 const float t = glm::clamp((mag - m_lower) / span, 0.0f, 1.0f);
87 return std::copysign(t, v);
97class InvertModifier :
public IModifier {
99 explicit InvertModifier(
const toml::table& t) : m_x(parse::boolean(t[
"x"],
true)), m_y(parse::boolean(t[
"y"],
false)) { }
103 value.data.x *= -1.0f;
106 value.data.y *= -1.0f;
111 auto name() const -> std::string_view
override {
123class ExponentialModifier :
public IModifier {
125 explicit ExponentialModifier(
const toml::table& t) : m_power(parse::number(t[
"power"], 2.0f)) { }
128 value.data.x = curve(value.data.x);
129 value.data.y = curve(value.data.y);
133 auto name() const -> std::string_view
override {
134 return "exponential";
139 auto curve(
float v)
const ->
float {
140 return std::copysign(std::pow(std::abs(v), m_power), v);
143 float m_power = 2.0f;
149class ScaleModifier :
public IModifier {
151 explicit ScaleModifier(
const toml::table& t) : m_x(parse::number(t[
"x"], 1.0f)), m_y(parse::number(t[
"y"], 1.0f)) { }
159 auto name() const -> std::string_view
override {
171class ScaleByDeltaTimeModifier :
public IModifier {
173 explicit ScaleByDeltaTimeModifier(
const toml::table& t)
174 : m_x(parse::boolean(t[
"x"],
true)),
175 m_y(parse::boolean(t[
"y"],
true)) { }
180 value.data.x *= delta;
183 value.data.y *= delta;
188 auto name() const -> std::string_view
override {
189 return "scale_by_deltatime";
200class SmoothModifier :
public IModifier {
202 explicit SmoothModifier(
const toml::table& t)
203 : m_x(parse::boolean(t[
"x"],
true)),
204 m_y(parse::boolean(t[
"y"],
true)),
205 m_speed(parse::number(t[
"speed"], 10.0f)) { }
209 const float t = glm::clamp(m_speed * delta, 0.0f, 1.0f);
211 m_current.x = glm::mix(m_current.x, value.data.x, t);
212 value.data.x = m_current.x;
215 m_current.y = glm::mix(m_current.y, value.data.y, t);
216 value.data.y = m_current.y;
221 auto name() const -> std::string_view
override {
228 float m_speed = 10.0f;
229 glm::vec2 m_current {0.0f};
235class KeyModifier :
public IModifier {
237 explicit KeyModifier(
const toml::table& t)
238 : m_control(parse::boolean(t[
"control"],
false)),
239 m_shift(parse::boolean(t[
"shift"],
false)),
240 m_alt(parse::boolean(t[
"alt"],
false)) { }
243 const bool ok = (!m_control || detail::modifierHeld(ctx.
mods, ModifierKey::control)) &&
244 (!m_shift || detail::modifierHeld(ctx.
mods, ModifierKey::shift)) &&
245 (!m_alt || detail::modifierHeld(ctx.
mods, ModifierKey::alt));
247 value.data = glm::vec2 {0.0f};
252 auto name() const -> std::string_view
override {
257 bool m_control =
false;
258 bool m_shift =
false;
static auto delta() noexcept -> double
Definition time.cpp:68
ModifierKey
Bit flags for the keyboard modifier keys held during an input.
Definition keycodes.hpp:28
Small helpers shared by the TOML parsing paths of triggers, modifiers and binds.
Per-frame context passed down to triggers and modifiers during evaluation.
Definition value.hpp:140
ModifierKey mods
keyboard modifier keys held this frame
Definition value.hpp:142
Controls the time of the application.
Value type shared by triggers, modifiers and actionsg.