From 29827743f6ff55aeef73548846dca5974f31088c Mon Sep 17 00:00:00 2001 From: lisyarus Date: Sun, 13 Sep 2020 11:11:08 +0300 Subject: [PATCH] Add app::impl::get_scene() --- libs/app/source/app.cpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/libs/app/source/app.cpp b/libs/app/source/app.cpp index be3eacba..a3d92e50 100644 --- a/libs/app/source/app.cpp +++ b/libs/app/source/app.cpp @@ -35,6 +35,8 @@ namespace psemek::app struct app::impl { + app * parent; + sdl_initializer init; SDL_Window * window = nullptr; SDL_GLContext gl_context = nullptr; @@ -47,15 +49,26 @@ namespace psemek::app clock::time_point start_time; + impl(app * parent) + : parent(parent) + {} + ~impl() { if (gl_context) SDL_GL_DeleteContext(gl_context); if (window) SDL_DestroyWindow(window); } + + scene * get_scene() + { + if (current_scene) + return current_scene; + return parent; + } }; app::app(std::string const & name) - : pimpl_{std::make_unique()} + : pimpl_{std::make_unique(this)} { impl().start_time = clock::now(); @@ -112,9 +125,7 @@ namespace psemek::app void app::poll_events() { - scene * handler = this; - if (impl().current_scene) - handler = impl().current_scene; + auto handler = impl().get_scene(); for (SDL_Event e; SDL_PollEvent(&e);) switch (e.type) { @@ -191,9 +202,7 @@ namespace psemek::app { poll_events(); - scene * handler = this; - if (impl().current_scene) - handler = impl().current_scene; + auto handler = impl().get_scene(); if (!impl().had_initial_resize) {