CGameTimer.cpp
上传用户:snevogroup
上传日期:2008-06-06
资源大小:432k
文件大小:1k
- #include <e32svr.h>
- #include <coemain.h>
- #include "CGameTimer.h"
- #include "MGameTimerObserver.h"
- ////////////////////////////////////////////////////////////////////////////
- // construct and destruct
- // NewL()
- CGameTimer* CGameTimer::NewL(MGameTimerObserver& aObserver)
- {
- CGameTimer* self = new (ELeave) CGameTimer(aObserver);
- CleanupStack::PushL(self);
- self->ConsturctL();
- CleanupStack::Pop();
- return self;
- }
- // ConstructL()
- void CGameTimer::ConsturctL()
- {
- iTick = 100000;
- iPeriodicTimer = CPeriodic::NewL(CActive::EPriorityStandard);
- }
- // CGameTimer()
- CGameTimer::CGameTimer(MGameTimerObserver& aObserver) : iObserver( aObserver )
- {}
- // ~
- CGameTimer::~CGameTimer()
- {
- iPeriodicTimer->Cancel();
- delete iPeriodicTimer;
- iPeriodicTimer = NULL;
- }
- /////////////////////////////////////////////////////////////////////////////
- // Other Method
- // Start()
- void CGameTimer::Start()
- {
- if( !iPeriodicTimer->IsActive() )
- iPeriodicTimer->Start(iTick, iTick, TCallBack(CGameTimer::Period, this) );
- }
- // Cancel()
- void CGameTimer::Cancel()
- {
- iPeriodicTimer->Cancel();
- }
- // SetTickTime
- void CGameTimer::SetTickTime(TTimeIntervalMicroSeconds32 aTickTime)
- {
- iTick = aTickTime;
- Cancel();
- Start();
- }
- // Period()
- TInt CGameTimer::Period(TAny* aPtr)
- {
- return ((CGameTimer*)aPtr)->DoCall();
- }
- // DoCall()
- TInt CGameTimer::DoCall()
- {
- return iObserver.DoGameFrameL();
- }