Add app::impl::get_scene()

This commit is contained in:
Nikita Lisitsa 2020-09-13 11:11:08 +03:00
parent 807daf3237
commit 29827743f6

View file

@ -35,6 +35,8 @@ namespace psemek::app
struct app::impl struct app::impl
{ {
app * parent;
sdl_initializer init; sdl_initializer init;
SDL_Window * window = nullptr; SDL_Window * window = nullptr;
SDL_GLContext gl_context = nullptr; SDL_GLContext gl_context = nullptr;
@ -47,15 +49,26 @@ namespace psemek::app
clock::time_point start_time; clock::time_point start_time;
impl(app * parent)
: parent(parent)
{}
~impl() ~impl()
{ {
if (gl_context) SDL_GL_DeleteContext(gl_context); if (gl_context) SDL_GL_DeleteContext(gl_context);
if (window) SDL_DestroyWindow(window); if (window) SDL_DestroyWindow(window);
} }
scene * get_scene()
{
if (current_scene)
return current_scene;
return parent;
}
}; };
app::app(std::string const & name) app::app(std::string const & name)
: pimpl_{std::make_unique<struct impl>()} : pimpl_{std::make_unique<struct impl>(this)}
{ {
impl().start_time = clock::now(); impl().start_time = clock::now();
@ -112,9 +125,7 @@ namespace psemek::app
void app::poll_events() void app::poll_events()
{ {
scene * handler = this; auto handler = impl().get_scene();
if (impl().current_scene)
handler = impl().current_scene;
for (SDL_Event e; SDL_PollEvent(&e);) switch (e.type) for (SDL_Event e; SDL_PollEvent(&e);) switch (e.type)
{ {
@ -191,9 +202,7 @@ namespace psemek::app
{ {
poll_events(); poll_events();
scene * handler = this; auto handler = impl().get_scene();
if (impl().current_scene)
handler = impl().current_scene;
if (!impl().had_initial_resize) if (!impl().had_initial_resize)
{ {