Skip to content

Instantly share code, notes, and snippets.

@nariakiiwatani
Last active June 2, 2017 00:56
Show Gist options
  • Save nariakiiwatani/bc018b62d9c10ab06497481dab30805c to your computer and use it in GitHub Desktop.
Save nariakiiwatani/bc018b62d9c10ab06497481dab30805c to your computer and use it in GitHub Desktop.
class Stepper
{
public:
void setFps(float fps) { step_time_ = 1/fps; }
void play() { is_playing_ = true; }
void step() { time_counter_+=step_time_; }
void stop() { is_playing_=false; time_counter_=0; }
void update(float elapsed_time) {
steps_past_ = 0;
if(isPlaying()) {
time_counter_ += elapsed_time;
}
while(time_counter_ >= step_time_) {
time_counter_ -= step_time_;
++steps_past_;
}
}
int getNumPastSteps() const { return steps_past_; }
bool isPlaying() const { return is_playing_; }
private:
bool is_playing_=false;
int steps_past_=0;
float step_time_=1/30.;
float time_counter_=0;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment