kodi
MovingSpeed.h
1 /*
2  * Copyright (C) 2022 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include <map>
12 #include <stdint.h>
13 #include <string_view>
14 
15 namespace UTILS
16 {
17 namespace MOVING_SPEED
18 {
19 
20 struct EventCfg
21 {
28  EventCfg(float acceleration, float maxVelocity, uint32_t resetTimeout)
29  : m_acceleration{acceleration}, m_maxVelocity{maxVelocity}, m_resetTimeout{resetTimeout}
30  {
31  }
32 
41  EventCfg(float acceleration, float maxVelocity, uint32_t resetTimeout, float delta)
42  : m_acceleration{acceleration},
43  m_maxVelocity{maxVelocity},
44  m_resetTimeout{resetTimeout},
45  m_delta{delta}
46  {
47  }
48 
49  float m_acceleration;
50  float m_maxVelocity;
51  uint32_t m_resetTimeout;
52  float m_delta{0};
53 };
54 
55 enum class EventType
56 {
57  NONE = 0,
58  UP,
59  DOWN,
60  LEFT,
61  RIGHT
62 };
63 
64 typedef std::map<EventType, EventCfg> MapEventConfig;
65 
73 {
74 public:
83  void AddEventConfig(uint32_t eventId,
84  float acceleration,
85  float maxVelocity,
86  uint32_t resetTimeout);
87 
93  void AddEventConfig(uint32_t eventId, EventCfg event);
94 
99  void AddEventMapConfig(MapEventConfig& configs);
100 
105  void Reset();
106 
111  void Reset(uint32_t eventId);
112 
118  float GetUpdatedDistance(uint32_t eventId);
119 
125  float GetUpdatedDistance(EventType eventType)
126  {
127  return GetUpdatedDistance(static_cast<uint32_t>(eventType));
128  }
129 
130 private:
131  struct EventData
132  {
133  EventData(EventCfg config) : m_config{config} {}
134 
135  EventCfg m_config;
136  float m_currentVelocity{1.0f};
137  uint32_t m_lastFrameTime{0};
138  };
139 
140  uint32_t m_currentEventId{0};
141  std::map<uint32_t, EventData> m_eventsData;
142 };
143 
149 EventType ParseEventType(std::string_view eventType);
150 
151 } // namespace MOVING_SPEED
152 } // namespace UTILS
Definition: deflate.c:123
Definition: ColorUtils.h:18
EventCfg(float acceleration, float maxVelocity, uint32_t resetTimeout, float delta)
Definition: MovingSpeed.h:41
Definition: MovingSpeed.h:20
Class to calculate the velocity for a motion effect. To ensure it works, the GetUpdatedDistance metho...
Definition: MovingSpeed.h:72
float GetUpdatedDistance(EventType eventType)
Get the updated distance based on acceleration speed.
Definition: MovingSpeed.h:125
EventCfg(float acceleration, float maxVelocity, uint32_t resetTimeout)
Definition: MovingSpeed.h:28