Skip to content

Commit

Permalink
Add counter to the Timer class
Browse files Browse the repository at this point in the history
  • Loading branch information
satoruhiga committed Feb 21, 2014
1 parent 3d7d30b commit f232012
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/ofxAnimationPrimitives/Pattern.h
Expand Up @@ -40,7 +40,7 @@ class ListPattern : public Pattern

bool valid() const { return num > 0 || num == -1; }

//protected:
protected:

int num;
void tick() { if (num > 0) num--; }
Expand Down
21 changes: 14 additions & 7 deletions src/ofxAnimationPrimitives/Timer.h
Expand Up @@ -19,16 +19,18 @@ class Timer : protected Ticker
{
public:

ofEvent<ofEventArgs> timerEvent;
ofEvent<int> timerEvent;

Timer() : remain(0), duration(0), repeat(false) {}
Timer() : remain(0), duration(0), repeat(0) {}

void start(float duration, bool repeat = true)
void start(float duration, int repeat = -1)
{
this->duration = duration;
this->remain = duration;
this->repeat = repeat;

count = 0;

Ticker::play();
}

Expand All @@ -37,21 +39,26 @@ class Timer : protected Ticker
Ticker::stop();
}

int getCount() const { return count; }

protected:

float remain, duration;
bool repeat;
int repeat, count;

void tick(float delta)
{
remain -= delta;

if (remain > 0) return;

static ofEventArgs args;
ofNotifyEvent(timerEvent, args, this);
int N = count;
ofNotifyEvent(timerEvent, N, this);

count++;

if (repeat)
if (repeat < 0
|| count < repeat)
{
remain += duration;
}
Expand Down

0 comments on commit f232012

Please sign in to comment.