mirror of
https://github.com/enduro2d/enduro2d.git
synced 2026-01-04 17:21:01 +07:00
engine: separate tick and render functions
This commit is contained in:
@@ -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>;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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_;
|
||||
|
||||
@@ -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_;
|
||||
|
||||
@@ -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_;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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_;
|
||||
|
||||
Reference in New Issue
Block a user