Avoid rendering if window is minimized + pause on minimize/losing focus

This commit is contained in:
SimoneN64
2023-07-22 19:34:57 +02:00
parent d0bccfc7e7
commit e587c31150
4 changed files with 22 additions and 13 deletions

View File

@@ -19,6 +19,7 @@ struct Core {
u32 breakpoint = 0; u32 breakpoint = 0;
bool pause = true; bool pause = true;
bool render = true;
int cycles = 0; int cycles = 0;
bool romLoaded = false; bool romLoaded = false;
std::string rom; std::string rom;

View File

@@ -12,15 +12,6 @@ void App::Run() {
n64::SI& si = core.cpu.mem.mmio.si; n64::SI& si = core.cpu.mem.mmio.si;
while (!window.done) { while (!window.done) {
if(core.romLoaded) {
if(!core.pause) {
core.Run(window.settings.GetVolumeL(), window.settings.GetVolumeR());
}
UpdateScreenParallelRdp(core, window, core.GetVI());
} else {
UpdateScreenParallelRdpNoGame(core, window);
}
SDL_Event event; SDL_Event event;
while (SDL_PollEvent(&event)) { while (SDL_PollEvent(&event)) {
ImGui_ImplSDL2_ProcessEvent(&event); ImGui_ImplSDL2_ProcessEvent(&event);
@@ -29,7 +20,7 @@ void App::Run() {
window.done = true; window.done = true;
break; break;
case SDL_WINDOWEVENT: case SDL_WINDOWEVENT:
window.onClose(event); window.handleEvents(event, core);
break; break;
case SDL_CONTROLLERDEVICEADDED: { case SDL_CONTROLLERDEVICEADDED: {
const int index = event.cdevice.which; const int index = event.cdevice.which;
@@ -61,5 +52,18 @@ void App::Run() {
} break; } break;
} }
} }
if(core.romLoaded) {
if(!core.pause) {
core.Run(window.settings.GetVolumeL(), window.settings.GetVolumeR());
}
if(core.render) {
UpdateScreenParallelRdp(core, window, core.GetVI());
}
} else {
if(core.render) {
UpdateScreenParallelRdpNoGame(core, window);
}
}
} }
} }

View File

@@ -15,9 +15,13 @@ Window::Window(n64::Core& core) : settings() {
NFD::Init(); NFD::Init();
} }
void Window::onClose(SDL_Event event) { void Window::handleEvents(SDL_Event event, n64::Core& core) {
done = event.window.event == SDL_WINDOWEVENT_CLOSE done = event.window.event == SDL_WINDOWEVENT_CLOSE
&& event.window.windowID == SDL_GetWindowID(window); && event.window.windowID == SDL_GetWindowID(window);
bool minimized = SDL_GetWindowFlags(window) & SDL_WINDOW_MINIMIZED;
core.pause = event.window.event == SDL_WINDOWEVENT_FOCUS_LOST || minimized;
core.render = !minimized;
} }
static void check_vk_result(VkResult err) { static void check_vk_result(VkResult err) {
@@ -222,7 +226,7 @@ void Window::Render(n64::Core& core) {
u32 ticks = SDL_GetTicks(); u32 ticks = SDL_GetTicks();
static u32 lastFrame = 0; static u32 lastFrame = 0;
if(!core.pause && lastFrame < ticks - 1000) { if(!core.pause && core.romLoaded && lastFrame < ticks - 1000) {
lastFrame = ticks; lastFrame = ticks;
windowTitle += fmt::format(" | {:02d} VI/s", core.cpu.mem.mmio.vi.swaps); windowTitle += fmt::format(" | {:02d} VI/s", core.cpu.mem.mmio.vi.swaps);
core.cpu.mem.mmio.vi.swaps = 0; core.cpu.mem.mmio.vi.swaps = 0;

View File

@@ -14,7 +14,7 @@ struct Window {
~Window(); ~Window();
ImDrawData* Present(n64::Core& core); ImDrawData* Present(n64::Core& core);
void onClose(SDL_Event event); void handleEvents(SDL_Event event, n64::Core&);
ImFont *uiFont{}; ImFont *uiFont{};
Settings settings; Settings settings;
void LoadROM(n64::Core& core, const std::string& path); void LoadROM(n64::Core& core, const std::string& path);