mirror of
https://github.com/izzy2lost/vba10.git
synced 2026-03-26 18:15:30 -07:00
42 lines
906 B
C++
42 lines
906 B
C++
#include "GameTime.h"
|
|
#include <Windows.h>
|
|
|
|
namespace VBA10
|
|
{
|
|
GameTime::GameTime(void)
|
|
{
|
|
this->frequency = Frequency();
|
|
this->startTime = Counter();
|
|
this->lastTime = this->startTime;
|
|
}
|
|
|
|
GameTime::~GameTime(void)
|
|
{ }
|
|
|
|
void GameTime::Update(void)
|
|
{
|
|
long long currentTime = Counter();
|
|
this->total = (currentTime - startTime) / (float)frequency;
|
|
this->elapsed = (currentTime - lastTime) / (float)frequency;
|
|
lastTime = currentTime;
|
|
}
|
|
|
|
void GameTime::SyncTime(void)
|
|
{
|
|
long long currentTime = Counter();
|
|
float newtimeTotal = (currentTime - startTime) / (float)frequency;
|
|
long long delta = (long long) ((newtimeTotal - this->total) * this->frequency);
|
|
startTime += delta;
|
|
lastTime += delta;
|
|
}
|
|
|
|
float GameTime::GetLastFrameElapsed(void)
|
|
{
|
|
return this->elapsed;
|
|
}
|
|
|
|
float GameTime::GetTotalElapsed(void)
|
|
{
|
|
return this->total;
|
|
}
|
|
} |