Ferris.... I figured you didn't want to DL a big library - and Tobi's code is perfect... I thought I'd post the class I was talking about so you can see how I copy the elapsed time into a float ONE TIME, and then code can use the float version over and over versus converting the int to float repeatedly in your main loop which eats clock cycles if done frequently etc.
jgc_clock.h
/*============================================================================
| _________ _______ _______ ______ _______ Jegas, LLC |
| /___ ___// _____/ / _____/ / __ / / _____/ JasonPSage@jegas.com |
| / / / /__ / / ___ / /_/ / / /____ |
| / / / ____/ / / / / / __ / /____ / |
|____/ / / /___ / /__/ / / / / / _____/ / |
/_____/ /______/ /______/ /_/ /_/ /______/ |
| 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 |
| /___ ___// _____/ / _____/ / __ / / _____/ JasonPSage@jegas.com |
| / / / /__ / / ___ / /_/ / / /____ |
| / / / ____/ / / / / / __ / /____ / |
|____/ / / /___ / /__/ / / / / / _____/ / |
/_____/ /______/ /______/ /_/ /_/ /______/ |
| 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
//============================================================================
You basically declare it in the top of your program:
JGC_CLOCK *Clock=new JGC_CLOCK();
then in your main loop you would call this:
Clock->Update();
Then you can use either the integer or float "TimeElapsed" value as many times as you need - recycling the math and the data type conversion to float - to your advantage.
timefactor = ((Clock->TimeElapsedFloat)/ 1000.0f);
dDistance = (speed * METER)*timefactor;
If timefactor is something you use alot, you might add that to the JGC_CLOCK class so its in a contextual appropriate place - "available in the clock" LOL.
Then when your program is shutting down you would:
delete Clock;
Good Luck! Sounds like you're off and running anyways - but this is just another way to skin the proverbial... Cat.