common frameRate Timer was detected

This commit is contained in:
2025-09-04 16:41:56 +03:00
parent 3a46538696
commit c4995cf075

17
Tween.h
View File

@ -50,7 +50,6 @@ class Tween {
private: private:
static inline Tween* head = nullptr; static inline Tween* head = nullptr;
static inline Tween* last = nullptr; static inline Tween* last = nullptr;
static inline uint32_t frameRateTimer;
Tween* next; Tween* next;
TweenListener* listener = nullptr; TweenListener* listener = nullptr;
@ -58,6 +57,7 @@ private:
public: public:
Tween(uint16_t fps = 30) { Tween(uint16_t fps = 30) {
setFps(fps); setFps(fps);
frameRateTimer = millis();
if (Tween::head == nullptr) { if (Tween::head == nullptr) {
Tween::head = this; Tween::head = this;
} }
@ -68,9 +68,10 @@ public:
} }
static void tick() { static void tick() {
uint32_t now = millis();
Tween* current = Tween::head; Tween* current = Tween::head;
while (current != nullptr) { while (current != nullptr) {
current->update(); current->update(now);
current = current->next; current = current->next;
} }
} }
@ -84,6 +85,7 @@ private:
uint16_t frameTime; uint16_t frameTime;
float dt; float dt;
uint32_t oldMillis; uint32_t oldMillis;
uint32_t frameRateTimer;
float from; float from;
float to; float to;
@ -102,9 +104,8 @@ public:
oldMillis = loopStartTime; oldMillis = loopStartTime;
} }
void update() { void update(uint32_t now) {
if (millis() - frameRateTimer > frameTime) { if (now - frameRateTimer > frameTime) {
uint32_t now = millis();
dt = (now - oldMillis) / 1000.0; dt = (now - oldMillis) / 1000.0;
oldMillis = now; oldMillis = now;
@ -130,7 +131,7 @@ public:
if (listener != nullptr) listener->onTweenUpdate(*this); if (listener != nullptr) listener->onTweenUpdate(*this);
frameRateTimer = millis(); frameRateTimer = now;
} }
} }
@ -147,7 +148,9 @@ public:
duration = durationMs / 1000.0f; duration = durationMs / 1000.0f;
progress = 0; progress = 0;
current = from; current = from;
oldMillis = millis(); uint32_t now = millis();
oldMillis = now;
frameRateTimer = now;
isPlayingF = true; isPlayingF = true;
triggerLastTick = false; triggerLastTick = false;
} }