Timer Class Reference

Simple timer designed to be used in the update functions of objects. More...

#include <timer.hpp>

List of all members.

Public Member Functions

 Timer ()
 ~Timer ()
void start (float period, bool cyclic=false)
 start the timer with the given period (in seconds).
bool check ()
 returns true if a period (or more) passed since start call or last successful check
void stop ()
 stop the timer
float get_period () const
 returns the period of the timer or 0 if it isn't started
float get_timeleft () const
float get_timegone () const
bool started () const

Private Attributes

float period
float cycle_start
bool cyclic


Detailed Description

Simple timer designed to be used in the update functions of objects.

Definition at line 25 of file timer.hpp.


Constructor & Destructor Documentation

Timer::Timer (  ) 

Definition at line 21 of file timer.cpp.

00021              :
00022   period(0), 
00023 cycle_start(0), 
00024   cyclic(false)
00025 {
00026 }

Timer::~Timer (  ) 

Definition at line 28 of file timer.cpp.

00029 {
00030 }


Member Function Documentation

void Timer::start ( float  period,
bool  cyclic = false 
)

start the timer with the given period (in seconds).

If cyclic=true then the timer will be reset after each period. Set period to zero if you want to disable the timer.

Definition at line 33 of file timer.cpp.

References cycle_start, and game_time.

Referenced by GhostTree::activate(), FlyingSnowBall::activate(), Dispenser::activate(), DartTrap::activate(), Stalactite::active_update(), SpiderMite::active_update(), Root::active_update(), Plant::active_update(), Mole::active_update(), Kugelblitz::active_update(), GhostTree::active_update(), FlyingSnowBall::active_update(), DartTrap::active_update(), AngryStone::active_update(), Yeti::be_angry(), Snail::be_kicked(), BouncyCoin::BouncyCoin(), BrokenBrick::BrokenBrick(), Yeti::collision_solid(), MrIceBlock::collision_squished(), Dispenser::collision_squished(), Player::do_backflip(), Player::do_standup(), Player::draw(), Electrifier::Electrifier(), SecretAreaTrigger::event(), Climbable::event(), Kugelblitz::explode(), Fireworks::Fireworks(), Thunderstorm::flash(), FloatingText::FloatingText(), Player::handle_horizontal_input(), Player::handle_input(), Player::handle_vertical_input(), Kugelblitz::hit(), SpiderMite::initialize(), Player::kick(), Player::kill(), LevelIntro::LevelIntro(), Player::make_invincible(), GameSession::on_escape_press(), Particles::Particles(), Player::Player(), Toad::set_state(), SkullyHop::set_state(), MrIceBlock::set_state(), Mole::set_state(), BadGuy::set_state(), Player::set_winning(), Camera::shake(), SmokeCloud::SmokeCloud(), SnowParticleSystem::SnowParticleSystem(), Thunderstorm::start(), YetiStalactite::start_shaking(), Fish::start_waiting(), EndSequenceWalkRight::starting(), EndSequenceWalkLeft::starting(), EndSequenceFireworks::starting(), stop(), Stumpy::Stumpy(), Yeti::take_hit(), worldmap::Tux::tryContinueWalking(), WalkingBadguy::turn_around(), Igel::turn_around(), Door::update(), LevelIntro::update(), Thunderstorm::update(), SnowParticleSystem::update(), SkullTile::update(), and Fireworks::update().

00034 {
00035   this->period = period;
00036   this->cyclic = cyclic;
00037   cycle_start = game_time;
00038 }

bool Timer::check (  ) 

returns true if a period (or more) passed since start call or last successful check

Definition at line 41 of file timer.cpp.

References cycle_start, cyclic, game_time, and period.

Referenced by Yeti::active_update(), Toad::active_update(), Stumpy::active_update(), Stalactite::active_update(), SpiderMite::active_update(), Snail::active_update(), SkullyHop::active_update(), Plant::active_update(), MrIceBlock::active_update(), Mole::active_update(), Kugelblitz::active_update(), GhostTree::active_update(), FlyingSnowBall::active_update(), Fish::active_update(), Dispenser::active_update(), DartTrap::active_update(), AngryStone::active_update(), BadGuy::check_state_timer(), MrIceBlock::collision_squished(), Player::do_standup(), SecretAreaTrigger::draw(), Player::draw(), EndSequenceWalkRight::running(), EndSequenceWalkLeft::running(), EndSequenceFireworks::running(), Door::update(), LevelIntro::update(), Thunderstorm::update(), SnowParticleSystem::update(), SmokeCloud::update(), SkullTile::update(), Player::update(), Particles::update(), FloatingText::update(), Fireworks::update(), Electrifier::update(), BrokenBrick::update(), BouncyCoin::update(), and BadGuy::update().

00042 {
00043   if(period == 0)
00044     return false;
00045 
00046   if(game_time - cycle_start >= period) {
00047     if(cyclic) {
00048       cycle_start = game_time - fmodf(game_time - cycle_start, period);
00049     } else {
00050       period = 0;
00051     }
00052     return true;
00053   }
00054 
00055   return false;
00056 }

void Timer::stop (  )  [inline]

stop the timer

Definition at line 41 of file timer.hpp.

References start().

Referenced by Dispenser::deactivate(), Player::do_duck(), Player::do_standup(), Climbable::event(), Fish::freeze(), Dispenser::freeze(), Player::handle_vertical_input(), Player::kill(), Camera::reset(), MrIceBlock::set_state(), Thunderstorm::start(), Thunderstorm::stop(), and SkullTile::update().

00042   { start(0); }

float Timer::get_period (  )  const [inline]

returns the period of the timer or 0 if it isn't started

Definition at line 45 of file timer.hpp.

Referenced by Player::do_standup().

00046   { return period; }

float Timer::get_timeleft (  )  const [inline]

Definition at line 47 of file timer.hpp.

References cycle_start, and game_time.

Referenced by FloatingText::draw(), BouncyCoin::draw(), started(), GameSession::update(), SnowParticleSystem::update(), and Player::update().

00048   { return period - (game_time - cycle_start); }

float Timer::get_timegone (  )  const [inline]

Definition at line 49 of file timer.hpp.

References cycle_start, and game_time.

Referenced by SkullTile::draw(), and Camera::shake().

00050   { return game_time - cycle_start; }

bool Timer::started (  )  const [inline]

Definition at line 51 of file timer.hpp.

References get_timeleft().

Referenced by Root::active_update(), Plant::active_update(), Igel::active_update(), Player::collision(), Yeti::collision_solid(), SecretAreaTrigger::draw(), Thunderstorm::draw(), Player::draw(), Yeti::draw(), Fish::draw(), worldmap::WorldMap::draw_status(), Climbable::event(), Player::handle_horizontal_input(), Player::handle_vertical_input(), Player::is_invincible(), Player::kill(), Camera::shake(), Yeti::take_hit(), WalkingBadguy::turn_around(), GameSession::update(), SkullTile::update(), and Player::update().

00052   { return period != 0 && get_timeleft() > 0; }


Member Data Documentation

float Timer::period [private]

Definition at line 55 of file timer.hpp.

Referenced by check().

float Timer::cycle_start [private]

Definition at line 56 of file timer.hpp.

Referenced by check(), get_timegone(), get_timeleft(), and start().

bool Timer::cyclic [private]

Definition at line 57 of file timer.hpp.

Referenced by check().


The documentation for this class was generated from the following files:
Generated on Mon Jun 9 03:38:37 2014 for SuperTux by  doxygen 1.5.1