diff --git a/source/main.cpp b/source/main.cpp index 7e16222744..d8553dcc40 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -411,7 +411,16 @@ static void Frame() if (g_SoundManager) g_SoundManager->IdleTask(); - Render(); + if (ShouldRender()) + { + Render(); + + { + PROFILE3("swap buffers"); + SDL_GL_SwapWindow(g_VideoMode.GetWindow()); + ogl_WarnIfError(); + } + } g_Profiler.Frame(); diff --git a/source/ps/Game.cpp b/source/ps/Game.cpp index 6ed28df9a7..1e711005d1 100644 --- a/source/ps/Game.cpp +++ b/source/ps/Game.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2018 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -409,12 +409,7 @@ void CGame::Update(const double deltaRealTime, bool doInterpolate) } if (doInterpolate) - { m_TurnManager->Interpolate(deltaSimTime, deltaRealTime); - - if ( g_SoundManager ) - g_SoundManager->IdleTask(); - } } void CGame::Interpolate(float simFrameLength, float realFrameLength) diff --git a/source/ps/GameSetup/GameSetup.cpp b/source/ps/GameSetup/GameSetup.cpp index 5b4786ad75..eb3d9dbf3d 100644 --- a/source/ps/GameSetup/GameSetup.cpp +++ b/source/ps/GameSetup/GameSetup.cpp @@ -198,18 +198,17 @@ void GUI_DisplayLoadProgress(int percent, const wchar_t* pending_task) g_GUI->GetActiveGUI()->SendEventToAll("GameLoadProgress", paramData); } -void SwapBuffers() +bool ShouldRender() { - PROFILE3("swap buffers"); - SDL_GL_SwapWindow(g_VideoMode.GetWindow()); - ogl_WarnIfError(); + return !g_app_minimized && (g_app_has_focus || !g_VideoMode.IsInFullscreen()); } + void Render() { // Do not render if not focused while in fullscreen or minimised, // as that triggers a difficult-to-reproduce crash on some graphic cards. - if (g_app_minimized || (!g_app_has_focus && g_VideoMode.IsInFullscreen())) + if (!ShouldRender()) return; PROFILE3("render"); @@ -347,8 +346,6 @@ void Render() g_Profiler2.RecordGPUFrameEnd(); ogl_WarnIfError(); - - SwapBuffers(); } ErrorReactionInternal psDisplayError(const wchar_t* UNUSED(text), size_t UNUSED(flags)) diff --git a/source/ps/GameSetup/GameSetup.h b/source/ps/GameSetup/GameSetup.h index 74debf2f23..4f868aa82f 100644 --- a/source/ps/GameSetup/GameSetup.h +++ b/source/ps/GameSetup/GameSetup.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2018 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -27,6 +27,8 @@ extern void GUI_DisplayLoadProgress(int percent, const wchar_t* pending_task); extern void Render(); +extern bool ShouldRender(); + /** * initialize global modules that are be needed before Init. * must be called from the very beginning of main. diff --git a/source/tools/atlas/GameInterface/View.cpp b/source/tools/atlas/GameInterface/View.cpp index 47525a4f76..6b37ac1a60 100644 --- a/source/tools/atlas/GameInterface/View.cpp +++ b/source/tools/atlas/GameInterface/View.cpp @@ -40,6 +40,7 @@ #include "simulation2/components/ICmpObstructionManager.h" #include "simulation2/components/ICmpParticleManager.h" #include "simulation2/components/ICmpPathfinder.h" +#include "soundmanager/ISoundManager.h" extern void (*Atlas_GLSwapBuffers)(void* context); @@ -211,6 +212,10 @@ void AtlasViewGame::Update(float realFrameLength) g_Game->Interpolate(actualFrameLength, realFrameLength); } + // Run sound idle tasks every frame. + if (g_SoundManager) + g_SoundManager->IdleTask(); + // Cinematic motion should be independent of simulation update, so we can // preview the cinematics by themselves g_Game->GetView()->GetCinema()->Update(realFrameLength);