Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract Game::drawScene from Game::updateFrame #13967

Merged
merged 5 commits into from
Dec 17, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
91 changes: 50 additions & 41 deletions src/client/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,7 @@ class Game {
const CameraOrientation &cam);
void updateClouds(float dtime);
void updateShadows();
void drawScene(ProfilerGraph *graph, RunStats *stats, f32 dtime);

// Misc
void showOverlayMessage(const char *msg, float dtime, int percent,
Expand Down Expand Up @@ -4144,52 +4145,12 @@ 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<s32>(0, 0, screensize.X, screensize.Y),
NULL);

runData.damage_flash -= 384.0f * dtime;
}
drawScene(graph, stats, dtime);

/*
==================== End scene ====================
*/

driver->endScene();

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));
}

Expand Down Expand Up @@ -4257,6 +4218,54 @@ void Game::updateShadows()
shadow->getDirectionalLight().update_frustum(camera, client, m_camera_offset_changed);
}

void Game::drawScene(ProfilerGraph *graph, RunStats *stats, f32 dtime)
{
const video::SColor skycolor = this->sky->getSkyColor();

TimeTaker tt_draw("Draw scene", nullptr, PRECISION_MICRO);
this->driver->beginScene(true, true, skycolor);

const LocalPlayer *player = client->getEnv().getLocalPlayer();
JosiahWI marked this conversation as resolved.
Show resolved Hide resolved
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 (runData.damage_flash > 0.0f) {
JosiahWI marked this conversation as resolved.
Show resolved Hide resolved
video::SColor color(runData.damage_flash, 180, 0, 0);
JosiahWI marked this conversation as resolved.
Show resolved Hide resolved
this->driver->draw2DRectangle(color,
core::rect<s32>(0, 0, screensize.X, screensize.Y),
NULL);

runData.damage_flash -= 384.0f * dtime;
JosiahWI marked this conversation as resolved.
Show resolved Hide resolved
}

this->driver->endScene();

stats->drawtime = tt_draw.stop(true);
g_profiler->graphAdd("Draw scene [us]", stats->drawtime);

}

/****************************************************************************
Misc
****************************************************************************/
Expand Down