瀏覽代碼

Check and testing timming #865

pull/1034/head
raysan5 5 年之前
父節點
當前提交
08adb4b8c3
共有 2 個檔案被更改,包括 12 行新增9 行删除
  1. +9
    -8
      src/core.c
  2. +3
    -1
      src/text.c

+ 9
- 8
src/core.c 查看文件

@ -1265,27 +1265,29 @@ void EndDrawing(void)
SwapBuffers(); // Copy back buffer to front buffer SwapBuffers(); // Copy back buffer to front buffer
PollInputEvents(); // Poll user events PollInputEvents(); // Poll user events
// Frame time control system // Frame time control system
currentTime = GetTime(); currentTime = GetTime();
drawTime = currentTime - previousTime; drawTime = currentTime - previousTime;
previousTime = currentTime; previousTime = currentTime;
frameTime = updateTime + drawTime; frameTime = updateTime + drawTime;
// Wait for some milliseconds... // Wait for some milliseconds...
if (frameTime < targetTime) if (frameTime < targetTime)
{ {
Wait((float)(targetTime - frameTime)*1000.0f); Wait((float)(targetTime - frameTime)*1000.0f);
currentTime = GetTime(); currentTime = GetTime();
double extraTime = currentTime - previousTime;
double waitTime = currentTime - previousTime;
previousTime = currentTime; previousTime = currentTime;
frameTime += extraTime;
frameTime += waitTime; // Total frame time: update + draw + wait
//SetWindowTitle(FormatText("Update: %f, Draw: %f, Req.Wait: %f, Real.Wait: %f, Total: %f, Target: %f\n",
// (float)updateTime, (float)drawTime, (float)(targetTime - (updateTime + drawTime)),
// (float)waitTime, (float)frameTime, (float)targetTime));
} }
return;
} }
// Initialize 2D mode with custom camera (2D) // Initialize 2D mode with custom camera (2D)
@ -1588,13 +1590,12 @@ void SetTargetFPS(int fps)
// Returns current FPS // Returns current FPS
int GetFPS(void) int GetFPS(void)
{ {
return (int)(1.0f/GetFrameTime());
return (int)n">roundf(1.0f/GetFrameTime());
} }
// Returns time in seconds for last frame drawn // Returns time in seconds for last frame drawn
float GetFrameTime(void) float GetFrameTime(void)
{ {
// NOTE: We round value to milliseconds
return (float)frameTime; return (float)frameTime;
} }

+ 3
- 1
src/text.c 查看文件

@ -759,7 +759,7 @@ void UnloadFont(Font font)
// NOTE: Uses default font // NOTE: Uses default font
void DrawFPS(int posX, int posY) void DrawFPS(int posX, int posY)
{ {
// NOTE: We are rendering fps every second for better viewing on high framerates
// NOTE: We are rendering fps every certain time for better viewing on high framerates
static int fps = 0; static int fps = 0;
static int counter = 0; static int counter = 0;
@ -773,6 +773,8 @@ void DrawFPS(int posX, int posY)
counter = 0; counter = 0;
} }
// TODO: Find a better way to calculate FPS, maybe calculate the mean of multiple measures?
// NOTE: We have rounding errors every frame, so it oscillates a lot // NOTE: We have rounding errors every frame, so it oscillates a lot
DrawText(TextFormat("%2i FPS", fps), posX, posY, 20, LIME); DrawText(TextFormat("%2i FPS", fps), posX, posY, 20, LIME);
} }

Loading…
取消
儲存