/* $Id: counter.hpp,v 1.1 2005/10/20 19:46:52 chfreund Exp $ */ #ifndef _COUNTER_HPP_ #define _COUNTER_HPP_ #include "serializable.hpp" #include "global.hpp" class Counter : public Serializable { private: real m_timeToLive; public: Counter( real timeToLive = 0.0 ) : m_timeToLive( timeToLive ) { } void setTimeToLive( real timeToLive ) { m_timeToLive = timeToLive; } real getTimeToLive() const { return m_timeToLive; } bool isElapsed() const { return ( m_timeToLive <= 0.0 ); } bool countDown( real dt ) { m_timeToLive -= dt; return ( m_timeToLive <= 0.0 ); } Uint32 getSerializeBufferSize() const; void serialize( Uint8*& bufferPointer ) const; void deserialize( Uint8*& bufferPointer ); }; class SignalCounter : public Counter { private: real m_timeToSignal; real m_signalCounter; bool m_signal; public: SignalCounter( real timeToLive = 0.0, real timeToSignal = 0.0 ) : Counter( timeToLive ), m_timeToSignal( timeToSignal ), m_signalCounter( timeToSignal ), m_signal( false ) { } void setTimeToSignal( real timeToSignal ) { m_timeToSignal = timeToSignal; m_signalCounter = timeToSignal; } bool hasSignal() const { return m_signal; } bool countDown( real dt ) { m_signalCounter -= dt; m_signal = false; if ( m_signalCounter <= 0.0 ) { m_signalCounter += m_timeToSignal; m_signal = true; } return Counter::countDown( dt ); } Uint32 getSerializeBufferSize() const; void serialize( Uint8*& bufferPointer ) const; void deserialize( Uint8*& bufferPointer ); }; #endif // _COUNTER_HPP_