From 7162b536eb43c70f41cac1403323e128e66cef19 Mon Sep 17 00:00:00 2001 From: JosiahWI <41302989+JosiahWI@users.noreply.github.com> Date: Sun, 17 Dec 2023 13:44:45 -0600 Subject: [PATCH] Extract Game::drawScene from Game::updateFrame --- src/client/game.cpp | 94 +++++++++++++++++++++++++-------------------- 1 file changed, 53 insertions(+), 41 deletions(-) diff --git a/src/client/game.cpp b/src/client/game.cpp index 7bc2c8697..f7d31bc3b 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -821,6 +821,7 @@ protected: const CameraOrientation &cam); void updateClouds(float dtime); void updateShadows(); + void drawScene(ProfilerGraph *graph, RunStats *stats); // Misc void showOverlayMessage(const char *msg, float dtime, int percent, @@ -4133,52 +4134,17 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime, /* ==================== Drawing begins ==================== */ - const video::SColor skycolor = sky->getSkyColor(); - - TimeTaker tt_draw("Draw scene", nullptr, PRECISION_MICRO); - driver->beginScene(true, true, skycolor); - - bool draw_wield_tool = (m_game_ui->m_flags.show_hud && - (player->hud_flags & HUD_FLAG_WIELDITEM_VISIBLE) && - (camera->getCameraMode() == CAMERA_MODE_FIRST)); - bool draw_crosshair = ( - (player->hud_flags & HUD_FLAG_CROSSHAIR_VISIBLE) && - (camera->getCameraMode() != CAMERA_MODE_THIRD_FRONT)); -#ifdef HAVE_TOUCHSCREENGUI - if (isNoCrosshairAllowed()) - draw_crosshair = false; -#endif - m_rendering_engine->draw_scene(skycolor, m_game_ui->m_flags.show_hud, - m_game_ui->m_flags.show_minimap, draw_wield_tool, draw_crosshair); - - /* - Profiler graph - */ - v2u32 screensize = driver->getScreenSize(); - - if (m_game_ui->m_flags.show_profiler_graph) - graph->draw(10, screensize.Y - 10, driver, g_fontengine->getFont()); - - /* - Damage flash - */ - if (runData.damage_flash > 0.0f) { - video::SColor color(runData.damage_flash, 180, 0, 0); - driver->draw2DRectangle(color, - core::rect(0, 0, screensize.X, screensize.Y), - NULL); - - runData.damage_flash -= 384.0f * dtime; - } - + drawScene(graph, stats); /* ==================== End scene ==================== */ - driver->endScene(); + // Damage flash is drawn in drawScene, but the timing update is done here to + // keep dtime out of the drawing code. + if (runData.damage_flash > 0.0f) { + runData.damage_flash -= 384.0f * dtime; + } - stats->drawtime = tt_draw.stop(true); - g_profiler->graphAdd("Draw scene [us]", stats->drawtime); g_profiler->avg("Game::updateFrame(): update frame [ms]", tt_update.stop(true)); } @@ -4246,6 +4212,52 @@ void Game::updateShadows() shadow->getDirectionalLight().update_frustum(camera, client, m_camera_offset_changed); } +void Game::drawScene(ProfilerGraph *graph, RunStats *stats) +{ + const video::SColor skycolor = this->sky->getSkyColor(); + + TimeTaker tt_draw("Draw scene", nullptr, PRECISION_MICRO); + this->driver->beginScene(true, true, skycolor); + + const LocalPlayer *player = this->client->getEnv().getLocalPlayer(); + bool draw_wield_tool = (this->m_game_ui->m_flags.show_hud && + (player->hud_flags & HUD_FLAG_WIELDITEM_VISIBLE) && + (this->camera->getCameraMode() == CAMERA_MODE_FIRST)); + bool draw_crosshair = ( + (player->hud_flags & HUD_FLAG_CROSSHAIR_VISIBLE) && + (this->camera->getCameraMode() != CAMERA_MODE_THIRD_FRONT)); +#ifdef HAVE_TOUCHSCREENGUI + if (this->isNoCrosshairAllowed()) + draw_crosshair = false; +#endif + this->m_rendering_engine->draw_scene(skycolor, this->m_game_ui->m_flags.show_hud, + this->m_game_ui->m_flags.show_minimap, draw_wield_tool, draw_crosshair); + + /* + Profiler graph + */ + v2u32 screensize = this->driver->getScreenSize(); + + if (this->m_game_ui->m_flags.show_profiler_graph) + graph->draw(10, screensize.Y - 10, driver, g_fontengine->getFont()); + + /* + Damage flash + */ + if (this->runData.damage_flash > 0.0f) { + video::SColor color(this->runData.damage_flash, 180, 0, 0); + this->driver->draw2DRectangle(color, + core::rect(0, 0, screensize.X, screensize.Y), + NULL); + } + + this->driver->endScene(); + + stats->drawtime = tt_draw.stop(true); + g_profiler->graphAdd("Draw scene [us]", stats->drawtime); + +} + /**************************************************************************** Misc ****************************************************************************/