-
Notifications
You must be signed in to change notification settings - Fork 0
/
StepDivider.cpp
40 lines (35 loc) · 990 Bytes
/
StepDivider.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
* StepDevider.cpp
*
* Created on: Sep 4, 2014
* Author: bastl
*/
#include "StepDivider.h"
//#define DEBUG
#ifdef DEBUG
#include <iostream>
#endif
void StepDivider::doStep(unsigned int elapsedTimeUnits) {
if (numberOfStepsToIgnore_ == 0) {
if (stepCallback_ != 0) {
stepCallback_();
}
if (division_ != 0) {
numberOfStepsToIgnore_ = division_ - 1;
}
if (lastStepTimeUnits_ != 0) {
timeUnitsPerStep_ = elapsedTimeUnits - lastStepTimeUnits_;
}
lastStepTimeUnits_ = elapsedTimeUnits;
} else {
timeUnitsPerStep_ = ((elapsedTimeUnits - lastStepTimeUnits_) * division_) / (division_ - numberOfStepsToIgnore_);
numberOfStepsToIgnore_--;
closerToNextStep_ = numberOfStepsToIgnore_ <= (division_ / 2);
#ifdef DEBUG
printf("StepDivider::doStep - step Ignored - TimeUnitsPerStep %d\n", timeUnitsPerStep_);
#endif
}
}
unsigned int StepDivider::getTimeSinceLastStep(unsigned int elapsedTimeUnits) {
return elapsedTimeUnits - lastStepTimeUnits_;
}