29 lines
597 B
C++
29 lines
597 B
C++
|
|
#include "../../HEADERS/UTILS/ClockIterator.hpp"
|
||
|
|
#include <stdexcept>
|
||
|
|
|
||
|
|
ClockIterator::ClockIterator(unsigned int loopMillis) {
|
||
|
|
if(loopMillis == 0)
|
||
|
|
throw std::invalid_argument("ClockIterator: loop period must be greater than zero");
|
||
|
|
reset();
|
||
|
|
max = loopMillis;
|
||
|
|
}
|
||
|
|
|
||
|
|
void ClockIterator::reset() {
|
||
|
|
counter = 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
unsigned int ClockIterator::step(unsigned int millis) {
|
||
|
|
counter += millis;
|
||
|
|
unsigned int res = counter / max;
|
||
|
|
counter %= max;
|
||
|
|
return res;
|
||
|
|
}
|
||
|
|
|
||
|
|
float ClockIterator::getPercentage() {
|
||
|
|
return (100.0f * counter) / max;
|
||
|
|
}
|
||
|
|
|
||
|
|
unsigned int ClockIterator::getPosition() {
|
||
|
|
return counter;
|
||
|
|
}
|