engine: separate tick and render functions

This commit is contained in:
2019-03-17 08:42:24 +07:00
parent c6b1df93ca
commit 7f17d235ca
10 changed files with 49 additions and 21 deletions

View File

@@ -20,6 +20,7 @@ namespace e2d
virtual bool initialize();
virtual void shutdown() noexcept;
virtual bool frame_tick();
virtual void frame_render();
};
using application_uptr = std::unique_ptr<application>;

View File

@@ -41,6 +41,7 @@ namespace e2d
void restore() noexcept;
void minimize() noexcept;
bool enabled() const noexcept;
bool visible() const noexcept;
bool focused() const noexcept;
bool minimized() const noexcept;

View File

@@ -172,8 +172,13 @@ namespace
the<dbgui>().toggle_visible(!the<dbgui>().visible());
}
return true;
}
void frame_render() final {
const auto framebuffer_size = the<window>().real_size().cast_to<f32>();
const auto projection = math::make_orthogonal_lh_matrix4(framebuffer_size, 0.f, 1.f);
const auto projection = math::make_orthogonal_lh_matrix4(
framebuffer_size, 0.f, 1.f);
material_.properties()
.property("u_time", the<engine>().time())
@@ -185,8 +190,6 @@ namespace
.add_command(render::clear_command()
.color_value({1.f, 0.4f, 0.f, 1.f}))
.add_command(render::draw_command(material_, geometry_)));
return true;
}
private:
shader_ptr shader_;

View File

@@ -228,6 +228,10 @@ namespace
the<dbgui>().toggle_visible(!the<dbgui>().visible());
}
return true;
}
void frame_render() final {
const auto framebuffer_size = the<window>().real_size().cast_to<f32>();
const auto projection = math::make_perspective_lh_matrix4(
make_deg(45.f),
@@ -252,8 +256,6 @@ namespace
.add_command(render::clear_command()
.color_value({1.f, 0.4f, 0.f, 1.f}))
.add_command(render::draw_command(material_, geometry_)));
return true;
}
private:
shader_ptr shader_;

View File

@@ -198,6 +198,10 @@ namespace
the<dbgui>().toggle_visible(!the<dbgui>().visible());
}
return true;
}
void frame_render() final {
const auto framebuffer_size = the<window>().real_size().cast_to<f32>();
const auto projection = math::make_perspective_lh_matrix4(
make_deg(45.f),
@@ -232,8 +236,6 @@ namespace
.add_command(render::clear_command()
.color_value({1.f, 0.4f, 0.f, 1.f}))
.add_command(render::draw_command(material_, geometry_, rt_props_)));
return true;
}
private:
shader_ptr shader_;

View File

@@ -118,8 +118,8 @@ namespace
bool create_systems() {
ecs::registry_filler(the<world>().registry())
.system<game_system>(world::priority_update)
.system<camera_system>(world::priority_update)
.system<rotator_system>(world::priority_update);
.system<rotator_system>(world::priority_update)
.system<camera_system>(world::priority_pre_render);
return true;
}
};

View File

@@ -55,6 +55,9 @@ namespace e2d
return true;
}
void application::frame_render() {
}
//
// engine::debug_parameters
//
@@ -431,8 +434,12 @@ namespace e2d
break;
}
if ( the<window>().enabled() ) {
app->frame_render();
the<dbgui>().frame_render();
the<window>().swap_buffers();
}
state_->calculate_end_frame_timers();
} catch ( ... ) {
app->shutdown();

View File

@@ -458,6 +458,16 @@ namespace e2d
glfwIconifyWindow(state_->window.get());
}
bool window::enabled() const noexcept {
std::lock_guard<std::recursive_mutex> guard(state_->rmutex);
if ( !state_->window || state_->window.get() != glfwGetCurrentContext() ) {
return false;
}
int w = 0, h = 0;
glfwGetWindowSize(state_->window.get(), &w, &h);
return w > 0 && h > 0;
}
bool window::visible() const noexcept {
std::lock_guard<std::recursive_mutex> guard(state_->rmutex);
E2D_ASSERT(state_->window);

View File

@@ -22,6 +22,7 @@ namespace e2d
bool fullscreen = false;
bool cursor_hidden = false;
bool should_close = false;
bool enabled = true;
bool visible = true;
bool focused = true;
bool minimized = false;
@@ -82,6 +83,11 @@ namespace e2d
}
}
bool window::enabled() const noexcept {
std::lock_guard<std::recursive_mutex> guard(state_->rmutex);
return state_->enabled;
}
bool window::visible() const noexcept {
std::lock_guard<std::recursive_mutex> guard(state_->rmutex);
return state_->visible;

View File

@@ -53,18 +53,14 @@ namespace
the<world>().registry().process_systems_in_range(
world::priority_update_section_begin,
world::priority_update_section_end);
if ( the<window>().should_close() ) {
if ( !high_application_ || high_application_->on_should_close() ) {
return false;
}
return !the<window>().should_close()
|| (high_application_ && !high_application_->on_should_close());
}
void frame_render() final {
the<world>().registry().process_systems_in_range(
world::priority_render_section_begin,
world::priority_render_section_end);
return true;
}
private:
high_application_uptr high_application_;