Last active
June 2, 2017 00:56
-
-
Save nariakiiwatani/bc018b62d9c10ab06497481dab30805c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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