system priorities

This commit is contained in:
2019-03-12 03:35:43 +07:00
parent 7dcf5c1c4b
commit dd2374e45a
5 changed files with 43 additions and 17 deletions

View File

@@ -44,7 +44,7 @@ namespace e2d
model& set_materials(const vector<material_asset::ptr>& materials);
const mesh_asset::ptr& mesh() const noexcept;
const render::geometry geometry() const noexcept;
const render::geometry& geometry() const noexcept;
const material_asset::ptr& material(std::size_t index) const;
std::size_t material_count() const noexcept;
private:

View File

@@ -11,6 +11,20 @@
namespace e2d
{
class world final : public module<world> {
public:
enum priorities : ecs::priority_t {
priority_update_section_begin = 0,
priority_pre_update = 500,
priority_update = 1000,
priority_post_update = 1500,
priority_update_section_end = 2000,
priority_render_section_begin = 2500,
priority_pre_render = 3000,
priority_render = 3500,
priority_post_render = 4000,
priority_render_section_end = 4500
};
public:
world();
~world() noexcept final;

View File

@@ -48,8 +48,9 @@ namespace
if ( !create_scene() || !create_camera() ) {
return false;
}
the<world>().registry().add_system<game_system>();
the<world>().registry().add_system<rotator_system>();
ecs::registry_filler(the<world>().registry())
.system<game_system>(world::priority_update)
.system<rotator_system>(world::priority_update);
return true;
}
private:
@@ -66,27 +67,29 @@ namespace
{
ecs::entity model_e = the<world>().registry().create_entity();
model_e.assign_component<rotator>(rotator{v3f::unit_y()});
model_e.assign_component<actor>(node::create(model_e));
model_e.assign_component<renderer>();
model_e.assign_component<model_renderer>(model_res);
ecs::entity_filler(model_e)
.component<rotator>(rotator{v3f::unit_y()})
.component<actor>(node::create(model_e, scene_r))
.component<renderer>()
.component<model_renderer>(model_res);
node_iptr model_n = model_e.get_component<actor>().node();
model_n->scale(v3f{20.f});
model_n->translation(v3f{0.f,50.f,0.f});
scene_r->add_child(model_n);
}
{
ecs::entity sprite_e = the<world>().registry().create_entity();
sprite_e.assign_component<rotator>(rotator{v3f::unit_z()});
sprite_e.assign_component<actor>(node::create(sprite_e));
sprite_e.assign_component<renderer>();
sprite_e.assign_component<sprite_renderer>(sprite_res);
ecs::entity_filler(sprite_e)
.component<rotator>(rotator{v3f::unit_z()})
.component<actor>(node::create(sprite_e, scene_r))
.component<renderer>()
.component<sprite_renderer>(sprite_res);
node_iptr sprite_n = sprite_e.get_component<actor>().node();
sprite_n->translation(v3f{0,-50.f,0});
scene_r->add_child(sprite_n);
}
return true;

View File

@@ -232,7 +232,7 @@ namespace e2d
return mesh_;
}
const render::geometry model::geometry() const noexcept {
const render::geometry& model::geometry() const noexcept {
return geometry_;
}

View File

@@ -38,8 +38,9 @@ namespace
: high_application_(std::move(application)) {}
bool initialize() final {
the<world>().registry().add_system<render_system>();
return high_application_ && high_application_->initialize();
ecs::registry_filler(the<world>().registry())
.system<render_system>(world::priority_render);
return !high_application_ || high_application_->initialize();
}
void shutdown() noexcept final {
@@ -49,12 +50,20 @@ namespace
}
bool frame_tick() final {
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;
}
}
the<world>().registry().process_systems();
the<world>().registry().process_systems_in_range(
world::priority_render_section_begin,
world::priority_render_section_end);
return true;
}
private: