MCPcopy Create free account
hub / github.com/WolfireGames/overgrowth / Draw

Method Draw

Source/Main/engine.cpp:4350–5414  ·  view source on GitHub ↗

Draw the current frame

Source from the content-addressed store, hash-verified

4348
4349// Draw the current frame
4350void Engine::Draw() {
4351 Graphics* graphics = Graphics::Instance();
4352 Keyboard& keyboard = Input::Instance()->getKeyboard();
4353
4354 ++draw_frame;
4355 num_detail_object_draw_calls = 0;
4356 PROFILER_GPU_ZONE(g_profiler_ctx, "Draw frame %d", draw_frame);
4357
4358 if (user_paused) {
4359 const int kBufSize = 512;
4360 char buf[kBufSize];
4361 FormatString(buf, kBufSize, "Time is currently paused, press %s to unpause", config["bind[pause]"].str().c_str());
4362 gui.AddDebugText("paused", buf, 0.0f);
4363 }
4364
4365 if (slow_motion) {
4366 const int kBufSize = 512;
4367 char buf[kBufSize];
4368 FormatString(buf, kBufSize, "Time is currently slowed down, press %s to speed back up", config["key[slow]"].str().c_str());
4369 gui.AddDebugText("slow", buf, 0.0f);
4370 }
4371
4372 DrawImGui(graphics, scenegraph_, &gui, GetAssetManager(), Engine::Instance(), cursor.visible);
4373
4374 if (check_save_level_changes_dialog_is_showing || !scenegraph_) {
4375 // No level loaded, so draw menu instead
4376 graphics->setViewport(0, 0, graphics->window_dims[0], graphics->window_dims[1]);
4377 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
4378 graphics->Clear(true);
4379 if (scriptable_menu_) {
4380 PROFILER_GPU_ZONE(g_profiler_ctx, "Draw scriptable menu", draw_frame);
4381 scriptable_menu_->Draw();
4382 }
4383 RenderImGui();
4384 ImGui_ImplSdlGL3_RenderDrawLists(ImGui::GetDrawData());
4385 if (!WantMouseImGui()) {
4386 cursor.Draw();
4387 }
4388
4389 // Limit FPS in menus, even if limit_fps_in_game is not set to true (and thus timing code in GameMain isn't being called)
4390 if (!graphics->config_.vSync() && !graphics->config_.limit_fps_in_game()) {
4391 PROFILER_ZONE_IDLE(g_profiler_ctx, "SDL_Sleep");
4392 if (!g_draw_vr) {
4393 static uint32_t last_time = 0;
4394
4395 int max_frame_rate = graphics->config_.max_frame_rate();
4396 if (max_frame_rate < 15) {
4397 max_frame_rate = 15;
4398 }
4399 if (max_frame_rate > 500) {
4400 max_frame_rate = 500;
4401 }
4402
4403 uint32_t ticks_to_wait = (uint32_t)(1000.0f / max_frame_rate);
4404 uint32_t diff = ticks_to_wait - (SDL_TS_GetTicks() - last_time) - 1;
4405 if (diff > ticks_to_wait - 1) {
4406 diff = ticks_to_wait - 1;
4407 }

Callers 4

DrawSceneMethod · 0.45
DrawLoadScreenMethod · 0.45
DrawCubeMapMethod · 0.45
GameMainFunction · 0.45

Calls 15

FormatStringFunction · 0.85
DrawImGuiFunction · 0.85
RenderImGuiFunction · 0.85
WantMouseImGuiFunction · 0.85
SDL_TS_GetTicksFunction · 0.85
PushGPUProfileRangeFunction · 0.85
UpdateShadowCacheFunction · 0.85
UpdateShadowCascadesFunction · 0.85
CubemapMipChainFunction · 0.85
IsBeingMovedFunction · 0.85

Tested by

no test coverage detected