Erstmal der Code:
|
C-/C++-Quelltext
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
CalculateFrameRate()
{
static float lastTime = 0.0f;
static float Time = 0.0f;
static unsigned int FrameCounter= 0;
float currentTime = timeGetTime() * 0.001f; //->Frametime*1=1 pro sekunde
Game.FrameTime = (currentTime - Time);
if(Game.FrameTime<0)
Game.FrameTime=-Game.FrameTime;
if(Game.FrameTime>1.f)
Game.FrameTime=0;
Time = currentTime;
FrameCounter++;
if( currentTime - lastTime > 1.0f )
{
lastTime = currentTime;
Game.FPS=FrameCounter;
FrameCounter = 0;
}
}
|
Meistens funktioniert er auch. aber manchmal-auf anderen computern öfter- läuft alles dreimal so schnell, oder langsamer! timegettime scheint aber zu funktionieren! da muss man doch auch nichts initialisieren oder?
wenn der counter einmal korrekt läuft, tut er dass auch die restliche windows-sitzung, also bis zum neustart. manchmal ändert sichs dann halt wieder.
ich rufe die funktion einmal pro frame-loop auf. was kann man da denn falsch machen?