/*
TimeDependent.cpp
Common base class for CTDamper and CTChaser.
Forms an object that needs to perform actions
in a frequent manner, e.g. in an animation
framework. Provides a Tick(.) method that is
to be called frequently and can announce when
it needs thos method calls and when not.
Author:
Herbert Stocker
HomePage:
http://www.hersto.net/Followers
(various resources there)
License:
You may use this file in any project and
modify it as long as you keep this comment
block unchanged.
Accompanying Files:
TimeDependent.h
Documentation:
See http://www.hersto.net/Followers
*/
#include "TimeDependent.h"
#ifndef NULL
# define NULL 0
#endif
CTimeDependent::CTimeDependent()
: mpvNeedTickContext(NULL)
, mpfNeedTickCB(NULL)
{}
CTimeDependent::~CTimeDependent()
{
mfUnRegisterFromTimer();
}
void CTimeDependent::Tick(double DeltaT, double Now)
{
// To be implemented by the derived class.
}
void CTimeDependent::SetNeedTickCB(void* pvContext, double (*pfNeedTickCB) (void* pvContext, CTimeDependent* pCaller, bool bNeedTick))
{
mpvNeedTickContext= pvContext;
mpfNeedTickCB= pfNeedTickCB;
}
void CTimeDependent::mfUnRegisterFromTimer()
{
if(mpfNeedTickCB)
{
mpfNeedTickCB(mpvNeedTickContext, this, false);
mpfNeedTickCB= NULL;
}
}
/*
In its destructor the timer object should go through
its list of registered CTimeDependent objects and
call their SetNeedTickCB(.) with a NULL pointer for the call-back function,
or the destructor of the CTimeDependent objects will later try to unregister
themselves from the already dead timer object.
*/
|