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
{
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<struct impl>()}
: pimpl_{std::make_unique<struct impl>(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)
{