Most of the transforms kind of work now need to hook in the new timer.
This commit is contained in:
parent
20d7612f1c
commit
7f14a39edf
6 changed files with 47 additions and 27 deletions
20
animate2.cpp
20
animate2.cpp
|
|
@ -78,6 +78,7 @@ namespace animate2 {
|
|||
|
||||
void Timer::start() {
|
||||
clock.start();
|
||||
prev_time = clock.getElapsedTime().asSeconds();
|
||||
}
|
||||
|
||||
void Timer::reset() {
|
||||
|
|
@ -86,25 +87,34 @@ namespace animate2 {
|
|||
|
||||
void Timer::restart() {
|
||||
clock.restart();
|
||||
prev_time = clock.getElapsedTime().asSeconds();
|
||||
}
|
||||
|
||||
sf::Time Timer::getElapsedTime() {
|
||||
return clock.getElapsedTime();
|
||||
}
|
||||
|
||||
void Timer::begin() {
|
||||
prev_time = clock.getElapsedTime().asSeconds();
|
||||
}
|
||||
|
||||
std::pair<int, double> Timer::commit() {
|
||||
// determine frame duration based on previous time
|
||||
current_time = clock.getElapsedTime().asSeconds();
|
||||
frame_duration = current_time - prev_time;
|
||||
|
||||
// update prev_time for the next call
|
||||
prev_time = current_time;
|
||||
|
||||
// update accumulator, retaining previous errors
|
||||
accumulator += frame_duration;
|
||||
|
||||
// find the tick count based on DELTA
|
||||
double tick_count = accumulator / DELTA;
|
||||
// alpha is then the remainder/fractional part
|
||||
double alpha = modf(tick_count, &tick_count);
|
||||
accumulator -= tick_count * DELTA;
|
||||
|
||||
// reduce accumulator by the number of DELTAS
|
||||
accumulator -= tick_count * DELTA;
|
||||
// that leaves the remaining errors for next loop
|
||||
|
||||
// return the number of even DELTA ticks and the alpha
|
||||
return {int(tick_count), alpha};
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue