mirror of
https://github.com/Show-maket/Tween.git
synced 2025-09-13 03:12:51 +00:00
common frameRate Timer was detected
This commit is contained in:
17
Tween.h
17
Tween.h
@ -50,7 +50,6 @@ class Tween {
|
||||
private:
|
||||
static inline Tween* head = nullptr;
|
||||
static inline Tween* last = nullptr;
|
||||
static inline uint32_t frameRateTimer;
|
||||
Tween* next;
|
||||
|
||||
TweenListener* listener = nullptr;
|
||||
@ -58,6 +57,7 @@ private:
|
||||
public:
|
||||
Tween(uint16_t fps = 30) {
|
||||
setFps(fps);
|
||||
frameRateTimer = millis();
|
||||
if (Tween::head == nullptr) {
|
||||
Tween::head = this;
|
||||
}
|
||||
@ -68,9 +68,10 @@ public:
|
||||
}
|
||||
|
||||
static void tick() {
|
||||
uint32_t now = millis();
|
||||
Tween* current = Tween::head;
|
||||
while (current != nullptr) {
|
||||
current->update();
|
||||
current->update(now);
|
||||
current = current->next;
|
||||
}
|
||||
}
|
||||
@ -84,6 +85,7 @@ private:
|
||||
uint16_t frameTime;
|
||||
float dt;
|
||||
uint32_t oldMillis;
|
||||
uint32_t frameRateTimer;
|
||||
|
||||
float from;
|
||||
float to;
|
||||
@ -102,9 +104,8 @@ public:
|
||||
oldMillis = loopStartTime;
|
||||
}
|
||||
|
||||
void update() {
|
||||
if (millis() - frameRateTimer > frameTime) {
|
||||
uint32_t now = millis();
|
||||
void update(uint32_t now) {
|
||||
if (now - frameRateTimer > frameTime) {
|
||||
dt = (now - oldMillis) / 1000.0;
|
||||
oldMillis = now;
|
||||
|
||||
@ -130,7 +131,7 @@ public:
|
||||
|
||||
if (listener != nullptr) listener->onTweenUpdate(*this);
|
||||
|
||||
frameRateTimer = millis();
|
||||
frameRateTimer = now;
|
||||
}
|
||||
}
|
||||
|
||||
@ -147,7 +148,9 @@ public:
|
||||
duration = durationMs / 1000.0f;
|
||||
progress = 0;
|
||||
current = from;
|
||||
oldMillis = millis();
|
||||
uint32_t now = millis();
|
||||
oldMillis = now;
|
||||
frameRateTimer = now;
|
||||
isPlayingF = true;
|
||||
triggerLastTick = false;
|
||||
}
|
||||
|
Reference in New Issue
Block a user