Skip to main content
gamedev.net
🔒 Locked

A simple problem

Started by The C modest god Jul 10, 2006 at 2:09 AM 0 replies 600+ views
Original Post
The C modest god
The C modest god
I am drawing an FPS graph in my game. For that I go over an array and get the last stored FPS values. However, there is something weird. If I use the following code:


DWORD
FPSTimer::GetFPSHistory(DWORD Backward)
{
	double Time;

	Time = this->CycleTime[(this->CycleCounter-Backward)%this->CycleTime.GetObjectsAmount()]; // <= HERE
				
	double FPSCalc;

	FPSCalc = ceil((1/Time)-0.5);
	return static_cast<DWORD>(FPSCalc);
}

void 
FPSTimer::UpdatedFPS()
{
	// TODO: Non exclude here
	this->CycleTime[this->CycleCounter] = this->pTimer->GetLastDelta();
	this->CycleCounter=(this->CycleCounter+1)%this->CycleTime.GetObjectsAmount();
}


Then I get a small jump ni the drawing of the FPS about every cycle of the array. As if it doesnt advance the drawing of the FPS graph in one frame, once in every full cycle of the array. However, if I use the following code, then it works fine:

DWORD
FPSTimer::GetFPSHistory(DWORD Backward)
{
	double Time;

	Time = this->CycleTime[(this->CycleTime.GetObjectsAmount()+this->CycleCounter-Backward)%this->CycleTime.GetObjectsAmount()]; // <= Here
				
	double FPSCalc;

	FPSCalc = ceil((1/Time)-0.5);
	return static_cast<DWORD>(FPSCalc);
}

It's all about the wheel.Never blindly trust technoligy.I love my internal organs.Real men don't shower. Quote: Original post by Toolmaker Quote:
Zahlman
Zahlman
The modulo operator doesn't behave the way you currently want it to for negative values. Rather it behaves the way that certain other contexts want it to ;) Actually, I'm not sure if this behaviour is rigidly defined or not. But in any case, adding the divisor to the dividend in your case ensures a positive dividend, yielding an OK result.

That said:

- What are 'CycleTime' and 'CycleCounter' exactly, anyway (in terms of types)? It looks as though you're using an array and could gain some benefit from a standard library container. And what's the value of 'Backward'? Something tricky is happening here...

- What's with all the explicit this->'s? Not having to specify the this-object explicitly is supposed to be a free bonus for putting your functionality in the correct places ;)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.