diff options
author | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-10-01 17:59:04 +0200 |
---|---|---|
committer | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-10-08 21:01:45 +0200 |
commit | 59a7d5c58f8b3af21b3e19d4e78f5653bf011bfb (patch) | |
tree | 536f6b80e359922172e671fbbbeb2b7bc5d3f165 /src/being.cpp | |
parent | e115390f18734d9e3e0e2fc5e1ed05f44c9fdb60 (diff) | |
download | mana-59a7d5c58f8b3af21b3e19d4e78f5653bf011bfb.tar.gz mana-59a7d5c58f8b3af21b3e19d4e78f5653bf011bfb.tar.bz2 mana-59a7d5c58f8b3af21b3e19d4e78f5653bf011bfb.tar.xz mana-59a7d5c58f8b3af21b3e19d4e78f5653bf011bfb.zip |
Added convenient and efficient Timer class
The Timer is efficient because it does not depend on incrementing a
counter to keep track of time, nor does it call SDL_GetTicks every time
its state is checked (this happens once per frame instead).
Along with global functions Time::absoluteTimeMs() and
Time::deltaTimeMs(), this replaces previous globals tick_time, cur_time
and get_elapsed_time().
For now, there is still a fixed 100 times per second logic call rate,
but the new Time::deltaTimeMs() function should allow getting rid of
this.
Diffstat (limited to 'src/being.cpp')
-rw-r--r-- | src/being.cpp | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/src/being.cpp b/src/being.cpp index 95f7c0d5..88104d74 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -643,7 +643,7 @@ void Being::setAction(Action action, int attackId) } if (currentAction != SpriteAction::MOVE) - mActionTime = tick_time; + mActionTimer.set(); } void Being::lookAt(const Vector &destPos) @@ -865,13 +865,9 @@ void Being::logic() // Remove it after 1.5 secs if the dead animation isn't long enough, // or simply play it until it's finished. - if (!isAlive() && Net::getGameHandler()->removeDeadBeings() && - get_elapsed_time(mActionTime) > std::max(getDuration(), 1500)) - { - - if (getType() != PLAYER) + if (!isAlive() && Net::getGameHandler()->removeDeadBeings() && getType() != PLAYER) + if (mActionTimer.elapsed() > std::max(getDuration(), 1500)) actorSpriteManager->scheduleDelete(this); - } } void Being::drawSpeech(int offsetX, int offsetY) |