Skip to content

Commit 8993172

Browse files
committed
- fix timestep, camera speed & add FPS counter
1 parent 543d194 commit 8993172

3 files changed

Lines changed: 38 additions & 12 deletions

File tree

DriverLevelTool/viewer/camera.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ const float Z_NEAR = 0.01f;
1515
const float Z_FAR = 100.0f;
1616
const float CAMERA_FOV = 75.0f;
1717

18-
const float CAMERA_MOVEMENT_SPEED_FACTOR = 140 * RENDER_SCALING;
19-
const float CAMERA_MOVEMENT_ACCELERATION = 15 * RENDER_SCALING;
20-
const float CAMERA_MOVEMENT_DECELERATION = 450 * RENDER_SCALING;
18+
const float CAMERA_MOVEMENT_SPEED_FACTOR = 8.0f; // in-game units per second (one unit is 4096)
19+
const float CAMERA_MOVEMENT_ACCELERATION = 10;
20+
const float CAMERA_MOVEMENT_DECELERATION = 40;
2121

2222
Vector3D g_cameraVelocity(0);
2323
Vector3D g_cameraPosition(0);

DriverLevelTool/viewer/renderlevel.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ void DrawLevelDriver2(const Vector3D& cameraPos, float cameraAngleY, const Volum
157157

158158
ppco = levMapDriver2->GetFirstPackedCop(&ci, icell);
159159

160+
if (ppco)
161+
g_drawnCells++;
162+
160163
// walk each cell object in cell
161164
while (ppco)
162165
{
@@ -172,9 +175,6 @@ void DrawLevelDriver2(const Vector3D& cameraPos, float cameraAngleY, const Volum
172175

173176
ppco = levMapDriver2->GetNextPackedCop(&ci);
174177
}
175-
176-
if(ppco)
177-
g_drawnCells++;
178178
}
179179
}
180180

@@ -351,7 +351,8 @@ void DrawLevelDriver1(const Vector3D& cameraPos, float cameraAngleY, const Volum
351351

352352
pco = levMapDriver1->GetFirstCop(&ci, icell.x, icell.z);
353353

354-
g_drawnCells++;
354+
if(pco)
355+
g_drawnCells++;
355356

356357
// walk each cell object in cell
357358
while (pco)

DriverLevelTool/viewer/viewer.cpp

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,29 @@ void SpoolAllAreaDatas()
301301
MsgError("Unable to spool area datas!\n");
302302
}
303303

304+
//-------------------------------------------------------------
305+
// Updates frames per second counter and returns a number
306+
//-------------------------------------------------------------
307+
int UpdateFPSCounter(float deltaTime)
308+
{
309+
// Engine frames status
310+
static float accumTime = 0.1f;
311+
static int framesPerSecond = 0;
312+
static int numFrames = 0;
313+
314+
if (accumTime > 0.1f)
315+
{
316+
framesPerSecond = (int)((float)numFrames / accumTime + 0.5f);
317+
numFrames = 0;
318+
accumTime = 0;
319+
}
320+
321+
accumTime += deltaTime;
322+
numFrames++;
323+
324+
return framesPerSecond;
325+
}
326+
304327
//-------------------------------------------------------------
305328

306329
char g_modelSearchNameBuffer[64];
@@ -418,7 +441,7 @@ extern int g_drawnPolygons;
418441
//-------------------------------------------------------------
419442
// Displays Main menu bar, stats and child windows
420443
//-------------------------------------------------------------
421-
void DisplayUI()
444+
void DisplayUI(float deltaTime)
422445
{
423446
if(ImGui::BeginMainMenuBar())
424447
{
@@ -515,6 +538,8 @@ void DisplayUI()
515538
{
516539
ImGui::SetWindowPos(ImVec2(0, 24));
517540

541+
ImGui::TextColored(ImVec4(1.0f, 1.0f, 1.0f, 0.5f), "FPS: %d", UpdateFPSCounter(deltaTime));
542+
518543
if(g_viewerMode == 0)
519544
{
520545
ImGui::SetWindowSize(ImVec2(400, 120));
@@ -535,7 +560,7 @@ void DisplayUI()
535560
MODEL* model = ref->model;
536561

537562
ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.0f, 1.5f), "Use arrows to change models");
538-
563+
539564
if(model)
540565
{
541566
ImGui::TextColored(ImVec4(1.0f, 1.0f, 1.0f, 0.5f), "Polygons: %d", model->num_polys);
@@ -767,11 +792,11 @@ void ViewerMainLoop()
767792
do
768793
{
769794
// compute time
770-
const float ticks_to_ms = 1.0f / 10000.0f;
795+
const double ticks_to_ms = 1.0 / 1000000.0;
771796
int64 curTicks = Time::microTicks();
772797

773798
float deltaTime = double(curTicks - oldTicks) * ticks_to_ms;
774-
799+
775800
oldTicks = curTicks;
776801

777802
ImGui_ImplOpenGL3_NewFrame();
@@ -808,7 +833,7 @@ void ViewerMainLoop()
808833
DebugOverlay_Draw();
809834

810835
// Do ImGUI interface
811-
DisplayUI();
836+
DisplayUI(deltaTime);
812837

813838
// draw stuff
814839
ImGui::Render();

0 commit comments

Comments
 (0)