Absolutely
test.cpp
#include <DarkGDK.h>
#include "jgc_clock.h"
#include "jgc_timer.h"
void DarkGDK ( void ){
JGC_CLOCK *Clock = new JGC_CLOCK();
int DelayInMilliSec = 200;
JGC_TIMER *Timer = new JGC_TIMER();
Timer->Set(DelayInMilliSec, Clock->Time_New);
while ( LoopGDK ( ) ){
Clock->Update();
dbCLS();
if(Timer->DelayPassed(Clock->Time_New)){
dbPrint("Hi Mom");
};
dbSync();
};
delete Timer;
delete Clock;
};
Something like that should work.
jgc_clock.h
/*============================================================================
| _________ _______ _______ ______ _______ Jegas, LLC |
| /___ ___// _____/ / _____/ / __ / / _____/ [email protected] |
| / / / /__ / / ___ / /_/ / / /____ |
| / / / ____/ / / / / / __ / /____ / |
|____/ / / /___ / /__/ / / / / / _____/ / |
/_____/ /______/ /______/ /_/ /_/ /______/ |
| Under the Hood |
==============================================================================
Copyright(c)2008 Jegas, LLC
============================================================================*/
#pragma once
//---------------------------------------------------------------------
class JGC_CLOCK{
//---------------------------------------------------------------------
public:
int Time_New;
int Time_Old;
int Time_Elapsed;
float Time_ElapsedFloat;
void Update(void);
JGC_CLOCK();
~JGC_CLOCK();
};
//---------------------------------------------------------------------
jgc_clock.cpp
/*============================================================================
| _________ _______ _______ ______ _______ Jegas, LLC |
| /___ ___// _____/ / _____/ / __ / / _____/ [email protected] |
| / / / /__ / / ___ / /_/ / / /____ |
| / / / ____/ / / / / / __ / /____ / |
|____/ / / /___ / /__/ / / / / / _____/ / |
/_____/ /______/ /______/ /_/ /_/ /______/ |
| Under the Hood |
==============================================================================
Copyright(c)2008 Jegas, LLC
============================================================================*/
#include <DarkGDK.h>
#include "jgc_clock.h"
//============================================================================
// Begin JGC_CLOCK
//============================================================================
//----------------------------------------------------------------------------
JGC_CLOCK::JGC_CLOCK(){
//----------------------------------------------------------------------------
this->Time_New=dbTimer();
this->Time_Old=this->Time_New-1; // force i millisec elapsed to start
this->Time_Elapsed = this->Time_New - this->Time_Old; // Self documenting
// not necessary - Not Harmful.
this->Time_ElapsedFloat = (float)this->Time_Elapsed;
};
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
JGC_CLOCK::~JGC_CLOCK(){
//----------------------------------------------------------------------------
};
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
void JGC_CLOCK::Update(void){
//----------------------------------------------------------------------------
int TempTime = dbTimer();
this->Time_Old = this->Time_New;
this->Time_New=TempTime;
// PREVENT HUGE Time spans (1000=second)
if((this->Time_Elapsed = (this->Time_New - this->Time_Old))>1000){
this->Time_Old=this->Time_New-1;
this->Time_Elapsed=1;
};
this->Time_ElapsedFloat = (float)this->Time_Elapsed;
};
//----------------------------------------------------------------------------
//============================================================================
// End JGC_CLOCK
//============================================================================
jgc_timer.h
/*============================================================================
| _________ _______ _______ ______ _______ Jegas, LLC |
| /___ ___// _____/ / _____/ / __ / / _____/ [email protected] |
| / / / /__ / / ___ / /_/ / / /____ |
| / / / ____/ / / / / / __ / /____ / |
|____/ / / /___ / /__/ / / / / / _____/ / |
/_____/ /______/ /______/ /_/ /_/ /______/ |
| Under the Hood |
==============================================================================
Copyright(c)2008 Jegas, LLC
============================================================================*/
#pragma once
//============================================================================
class JGC_TIMER{
//============================================================================
public:
int DelayInMSec;// How Long a Duration
int TimesUp;// WHEN This Timer Goes Off Next
bool DelayPassed(int p_iTimer);
JGC_TIMER();
~JGC_TIMER();
void Set(int p_iDelayInMSec, int p_iTimer);
};
//============================================================================
jgc_timer.cpp
/*============================================================================
| _________ _______ _______ ______ _______ Jegas, LLC |
| /___ ___// _____/ / _____/ / __ / / _____/ [email protected] |
| / / / /__ / / ___ / /_/ / / /____ |
| / / / ____/ / / / / / __ / /____ / |
|____/ / / /___ / /__/ / / / / / _____/ / |
/_____/ /______/ /______/ /_/ /_/ /______/ |
| Under the Hood |
==============================================================================
Copyright(c)2008 Jegas, LLC
============================================================================*/
#include <DarkGDK.h>
#include "jgc_timer.h"
//============================================================================
// begin JGC_TIMER
//============================================================================
//----------------------------------------------------------------------------
JGC_TIMER::JGC_TIMER(){
//----------------------------------------------------------------------------
this->DelayInMSec=0;
this->TimesUp=0;
};
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
JGC_TIMER::~JGC_TIMER(){
//----------------------------------------------------------------------------
};
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
void JGC_TIMER::Set(int p_iDelayInMSec,int p_iTimer){
//----------------------------------------------------------------------------
this->DelayInMSec=p_iDelayInMSec;
this->TimesUp=p_iTimer+this->DelayInMSec;
};
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
bool JGC_TIMER::DelayPassed(int p_iTimer){
//----------------------------------------------------------------------------
bool bResult;
if(bResult=(p_iTimer>=this->TimesUp)){
// Reset THIS DELAY For Next Go Round
this->TimesUp=p_iTimer+this->DelayInMSec;
};
return bResult;
};
//----------------------------------------------------------------------------
//============================================================================
// end JGC_TIMER
//============================================================================
Does this help?