mirror of
https://github.com/enduro2d/enduro2d.git
synced 2025-12-16 14:08:59 +07:00
engine: separate tick and render functions
This commit is contained in:
@@ -20,6 +20,7 @@ namespace e2d
|
|||||||
virtual bool initialize();
|
virtual bool initialize();
|
||||||
virtual void shutdown() noexcept;
|
virtual void shutdown() noexcept;
|
||||||
virtual bool frame_tick();
|
virtual bool frame_tick();
|
||||||
|
virtual void frame_render();
|
||||||
};
|
};
|
||||||
using application_uptr = std::unique_ptr<application>;
|
using application_uptr = std::unique_ptr<application>;
|
||||||
|
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ namespace e2d
|
|||||||
void restore() noexcept;
|
void restore() noexcept;
|
||||||
void minimize() noexcept;
|
void minimize() noexcept;
|
||||||
|
|
||||||
|
bool enabled() const noexcept;
|
||||||
bool visible() const noexcept;
|
bool visible() const noexcept;
|
||||||
bool focused() const noexcept;
|
bool focused() const noexcept;
|
||||||
bool minimized() const noexcept;
|
bool minimized() const noexcept;
|
||||||
|
|||||||
@@ -172,8 +172,13 @@ namespace
|
|||||||
the<dbgui>().toggle_visible(!the<dbgui>().visible());
|
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 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()
|
material_.properties()
|
||||||
.property("u_time", the<engine>().time())
|
.property("u_time", the<engine>().time())
|
||||||
@@ -185,8 +190,6 @@ namespace
|
|||||||
.add_command(render::clear_command()
|
.add_command(render::clear_command()
|
||||||
.color_value({1.f, 0.4f, 0.f, 1.f}))
|
.color_value({1.f, 0.4f, 0.f, 1.f}))
|
||||||
.add_command(render::draw_command(material_, geometry_)));
|
.add_command(render::draw_command(material_, geometry_)));
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
shader_ptr shader_;
|
shader_ptr shader_;
|
||||||
|
|||||||
@@ -228,6 +228,10 @@ namespace
|
|||||||
the<dbgui>().toggle_visible(!the<dbgui>().visible());
|
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 framebuffer_size = the<window>().real_size().cast_to<f32>();
|
||||||
const auto projection = math::make_perspective_lh_matrix4(
|
const auto projection = math::make_perspective_lh_matrix4(
|
||||||
make_deg(45.f),
|
make_deg(45.f),
|
||||||
@@ -240,7 +244,7 @@ namespace
|
|||||||
math::make_rotation_matrix4(make_rad(the<engine>().time()), 0.f, 1.f, 0.f) *
|
math::make_rotation_matrix4(make_rad(the<engine>().time()), 0.f, 1.f, 0.f) *
|
||||||
math::make_rotation_matrix4(make_rad(the<engine>().time()), 0.f, 0.f, 1.f) *
|
math::make_rotation_matrix4(make_rad(the<engine>().time()), 0.f, 0.f, 1.f) *
|
||||||
math::make_translation_matrix4(0.f, 0.f, 0.f) *
|
math::make_translation_matrix4(0.f, 0.f, 0.f) *
|
||||||
math::make_loot_at_lh_matrix4({0.f,0.f,-3.f}, v3f::zero(), v3f::unit_y()) *
|
math::make_loot_at_lh_matrix4({0.f, 0.f, -3.f}, v3f::zero(), v3f::unit_y()) *
|
||||||
projection;
|
projection;
|
||||||
|
|
||||||
material_.properties()
|
material_.properties()
|
||||||
@@ -252,8 +256,6 @@ namespace
|
|||||||
.add_command(render::clear_command()
|
.add_command(render::clear_command()
|
||||||
.color_value({1.f, 0.4f, 0.f, 1.f}))
|
.color_value({1.f, 0.4f, 0.f, 1.f}))
|
||||||
.add_command(render::draw_command(material_, geometry_)));
|
.add_command(render::draw_command(material_, geometry_)));
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
shader_ptr shader_;
|
shader_ptr shader_;
|
||||||
|
|||||||
@@ -198,6 +198,10 @@ namespace
|
|||||||
the<dbgui>().toggle_visible(!the<dbgui>().visible());
|
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 framebuffer_size = the<window>().real_size().cast_to<f32>();
|
||||||
const auto projection = math::make_perspective_lh_matrix4(
|
const auto projection = math::make_perspective_lh_matrix4(
|
||||||
make_deg(45.f),
|
make_deg(45.f),
|
||||||
@@ -210,7 +214,7 @@ namespace
|
|||||||
math::make_rotation_matrix4(make_rad(the<engine>().time()), 0.f, 1.f, 0.f) *
|
math::make_rotation_matrix4(make_rad(the<engine>().time()), 0.f, 1.f, 0.f) *
|
||||||
math::make_rotation_matrix4(make_rad(the<engine>().time()), 0.f, 0.f, 1.f) *
|
math::make_rotation_matrix4(make_rad(the<engine>().time()), 0.f, 0.f, 1.f) *
|
||||||
math::make_translation_matrix4(0.f, 0.f, 0.f) *
|
math::make_translation_matrix4(0.f, 0.f, 0.f) *
|
||||||
math::make_loot_at_lh_matrix4({0.f,0.f,-2.f}, v3f::zero(), v3f::unit_y()) *
|
math::make_loot_at_lh_matrix4({0.f, 0.f, -2.f}, v3f::zero(), v3f::unit_y()) *
|
||||||
projection;
|
projection;
|
||||||
|
|
||||||
material_.properties()
|
material_.properties()
|
||||||
@@ -232,8 +236,6 @@ namespace
|
|||||||
.add_command(render::clear_command()
|
.add_command(render::clear_command()
|
||||||
.color_value({1.f, 0.4f, 0.f, 1.f}))
|
.color_value({1.f, 0.4f, 0.f, 1.f}))
|
||||||
.add_command(render::draw_command(material_, geometry_, rt_props_)));
|
.add_command(render::draw_command(material_, geometry_, rt_props_)));
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
shader_ptr shader_;
|
shader_ptr shader_;
|
||||||
|
|||||||
@@ -118,8 +118,8 @@ namespace
|
|||||||
bool create_systems() {
|
bool create_systems() {
|
||||||
ecs::registry_filler(the<world>().registry())
|
ecs::registry_filler(the<world>().registry())
|
||||||
.system<game_system>(world::priority_update)
|
.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;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -55,6 +55,9 @@ namespace e2d
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void application::frame_render() {
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// engine::debug_parameters
|
// engine::debug_parameters
|
||||||
//
|
//
|
||||||
@@ -431,8 +434,12 @@ namespace e2d
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
the<dbgui>().frame_render();
|
if ( the<window>().enabled() ) {
|
||||||
the<window>().swap_buffers();
|
app->frame_render();
|
||||||
|
the<dbgui>().frame_render();
|
||||||
|
the<window>().swap_buffers();
|
||||||
|
}
|
||||||
|
|
||||||
state_->calculate_end_frame_timers();
|
state_->calculate_end_frame_timers();
|
||||||
} catch ( ... ) {
|
} catch ( ... ) {
|
||||||
app->shutdown();
|
app->shutdown();
|
||||||
|
|||||||
@@ -458,6 +458,16 @@ namespace e2d
|
|||||||
glfwIconifyWindow(state_->window.get());
|
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 {
|
bool window::visible() const noexcept {
|
||||||
std::lock_guard<std::recursive_mutex> guard(state_->rmutex);
|
std::lock_guard<std::recursive_mutex> guard(state_->rmutex);
|
||||||
E2D_ASSERT(state_->window);
|
E2D_ASSERT(state_->window);
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ namespace e2d
|
|||||||
bool fullscreen = false;
|
bool fullscreen = false;
|
||||||
bool cursor_hidden = false;
|
bool cursor_hidden = false;
|
||||||
bool should_close = false;
|
bool should_close = false;
|
||||||
|
bool enabled = true;
|
||||||
bool visible = true;
|
bool visible = true;
|
||||||
bool focused = true;
|
bool focused = true;
|
||||||
bool minimized = false;
|
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 {
|
bool window::visible() const noexcept {
|
||||||
std::lock_guard<std::recursive_mutex> guard(state_->rmutex);
|
std::lock_guard<std::recursive_mutex> guard(state_->rmutex);
|
||||||
return state_->visible;
|
return state_->visible;
|
||||||
|
|||||||
@@ -53,18 +53,14 @@ namespace
|
|||||||
the<world>().registry().process_systems_in_range(
|
the<world>().registry().process_systems_in_range(
|
||||||
world::priority_update_section_begin,
|
world::priority_update_section_begin,
|
||||||
world::priority_update_section_end);
|
world::priority_update_section_end);
|
||||||
|
return !the<window>().should_close()
|
||||||
|
|| (high_application_ && !high_application_->on_should_close());
|
||||||
|
}
|
||||||
|
|
||||||
if ( the<window>().should_close() ) {
|
void frame_render() final {
|
||||||
if ( !high_application_ || high_application_->on_should_close() ) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
the<world>().registry().process_systems_in_range(
|
the<world>().registry().process_systems_in_range(
|
||||||
world::priority_render_section_begin,
|
world::priority_render_section_begin,
|
||||||
world::priority_render_section_end);
|
world::priority_render_section_end);
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
high_application_uptr high_application_;
|
high_application_uptr high_application_;
|
||||||
|
|||||||
Reference in New Issue
Block a user