I'm new to C++ and trying to make a simple update function.
I have built a "clock" which tracks time between frames as well as time since T0.
I also have a loops which every so many "clock" frames calls an update function.
void Engine::start()
{
float count = 0;
Clock clock;
clock.startClock();
while (true)
{
clock.Time(.001F);
count += clock.deltaTime();
if (count >= 1000) {
update(clock.deltaTime());
count = 0;
}
}
}
However this feels inelegant to me.
The clock code:
class Clock
{
private:
public:
float startTime=0;
float nextTime=0;
float currentTime=0;
void startClock()
{
float startTime = 0;
float currentTime = startTime;
}
float deltaTime()
{
return nextTime - currentTime;
}
void Time(float incrementTime)
{
currentTime = 0;
nextTime = incrementTime;
}
};
It works as written; I have a "counter" class which prints to the console every time the update function is called; however I'd like advice on how to improve this, to make it more elegant/efficient.