diff --git a/headers/enduro2d/high/_all.hpp b/headers/enduro2d/high/_all.hpp index b37ac2e7..0d924c07 100644 --- a/headers/enduro2d/high/_all.hpp +++ b/headers/enduro2d/high/_all.hpp @@ -31,6 +31,7 @@ #include "components/actor.hpp" #include "components/behaviour.hpp" #include "components/camera.hpp" +#include "components/disabled.hpp" #include "components/flipbook_player.hpp" #include "components/label.hpp" #include "components/model_renderer.hpp" diff --git a/headers/enduro2d/high/_high.hpp b/headers/enduro2d/high/_high.hpp index a7e28c09..3d355404 100644 --- a/headers/enduro2d/high/_high.hpp +++ b/headers/enduro2d/high/_high.hpp @@ -46,6 +46,8 @@ namespace e2d class actor; class behaviour; class camera; + template < typename T > + class disabled; class flipbook_player; class label; class model_renderer; diff --git a/headers/enduro2d/high/components/behaviour.hpp b/headers/enduro2d/high/components/behaviour.hpp index 9ba0ec11..19f5636e 100644 --- a/headers/enduro2d/high/components/behaviour.hpp +++ b/headers/enduro2d/high/components/behaviour.hpp @@ -14,9 +14,6 @@ namespace e2d { class behaviour final { - public: - class started final {}; - class disabled final {}; public: behaviour() = default; behaviour(const script_asset::ptr& script); @@ -47,34 +44,6 @@ namespace e2d asset_dependencies& dependencies, const collect_context& ctx) const; }; - - template <> - class factory_loader final : factory_loader<> { - public: - static const char* schema_source; - - bool operator()( - behaviour::started& component, - const fill_context& ctx) const; - - bool operator()( - asset_dependencies& dependencies, - const collect_context& ctx) const; - }; - - template <> - class factory_loader final : factory_loader<> { - public: - static const char* schema_source; - - bool operator()( - behaviour::disabled& component, - const fill_context& ctx) const; - - bool operator()( - asset_dependencies& dependencies, - const collect_context& ctx) const; - }; } namespace e2d diff --git a/headers/enduro2d/high/components/disabled.hpp b/headers/enduro2d/high/components/disabled.hpp new file mode 100644 index 00000000..a16dda93 --- /dev/null +++ b/headers/enduro2d/high/components/disabled.hpp @@ -0,0 +1,18 @@ +/******************************************************************************* + * This file is part of the "Enduro2D" + * For conditions of distribution and use, see copyright notice in LICENSE.md + * Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com) + ******************************************************************************/ + +#pragma once + +#include "../_high.hpp" + +namespace e2d +{ + template < typename T > + class disabled final { + public: + disabled() = default; + }; +} diff --git a/headers/enduro2d/high/components/renderer.hpp b/headers/enduro2d/high/components/renderer.hpp index 8c7931ba..0d36ea6e 100644 --- a/headers/enduro2d/high/components/renderer.hpp +++ b/headers/enduro2d/high/components/renderer.hpp @@ -17,9 +17,6 @@ namespace e2d public: renderer() = default; - renderer& enabled(bool value) noexcept; - bool enabled() const noexcept; - renderer& properties(render::property_block&& value) noexcept; renderer& properties(const render::property_block& value); @@ -32,7 +29,6 @@ namespace e2d vector& materials() noexcept; const vector& materials() const noexcept; private: - bool enabled_ = true; render::property_block properties_; vector materials_; }; @@ -54,15 +50,6 @@ namespace e2d namespace e2d { - inline renderer& renderer::enabled(bool value) noexcept { - enabled_ = value; - return *this; - } - - inline bool renderer::enabled() const noexcept { - return enabled_; - } - inline renderer& renderer::properties(render::property_block&& value) noexcept { properties_ = std::move(value); return *this; diff --git a/headers/enduro2d/high/gobject.hpp b/headers/enduro2d/high/gobject.hpp index 3bfdaf09..43f85461 100644 --- a/headers/enduro2d/high/gobject.hpp +++ b/headers/enduro2d/high/gobject.hpp @@ -71,7 +71,7 @@ namespace e2d T* operator->() noexcept; const T* operator->() const noexcept; - const gobject& owner() const noexcept; + gobject owner() const noexcept; explicit operator bool() const noexcept; private: gobject owner_; @@ -93,7 +93,7 @@ namespace e2d const T& operator*() const noexcept; const T* operator->() const noexcept; - const gobject& owner() const noexcept; + gobject owner() const noexcept; explicit operator bool() const noexcept; private: gobject owner_; @@ -228,7 +228,7 @@ namespace e2d } template < typename T > - const gobject& gcomponent::owner() const noexcept { + gobject gcomponent::owner() const noexcept { return owner_; } @@ -283,7 +283,7 @@ namespace e2d } template < typename T > - const gobject& const_gcomponent::owner() const noexcept { + gobject const_gcomponent::owner() const noexcept { return owner_; } diff --git a/headers/enduro2d/high/node.hpp b/headers/enduro2d/high/node.hpp index 245c97ce..456c1f17 100644 --- a/headers/enduro2d/high/node.hpp +++ b/headers/enduro2d/high/node.hpp @@ -42,9 +42,7 @@ namespace e2d static node_iptr create(gobject owner, const node_iptr& parent, const t3f& transform); void owner(gobject owner) noexcept; - - gobject& owner() noexcept; - const gobject& owner() const noexcept; + gobject owner() const noexcept; void transform(const t3f& transform) noexcept; const t3f& transform() const noexcept; diff --git a/headers/enduro2d/high/systems/_systems.hpp b/headers/enduro2d/high/systems/_systems.hpp index 27932620..28fae2d6 100644 --- a/headers/enduro2d/high/systems/_systems.hpp +++ b/headers/enduro2d/high/systems/_systems.hpp @@ -40,39 +40,41 @@ namespace e2d::systems namespace e2d::systems { - template < typename... Ts, typename Iter > - std::size_t extract_components(ecs::registry& owner, Iter iter) { + template < typename... Ts, typename Iter, typename... Opts > + std::size_t extract_components(ecs::registry& owner, Iter iter, Opts&&... opts) { std::size_t count{0u}; owner.for_joined_components( [&iter, &count](const ecs::entity& e, Ts&... cs){ - iter++ = std::make_tuple(e, std::ref(cs)...); + iter++ = std::make_tuple(e, cs...); ++count; - }); + }, std::forward(opts)...); return count; } - template < typename... Ts, typename Iter > - std::size_t extract_components(const ecs::registry& owner, Iter iter) { + template < typename... Ts, typename Iter, typename... Opts > + std::size_t extract_components(const ecs::registry& owner, Iter iter, Opts&&... opts) { std::size_t count{0u}; owner.for_joined_components( [&iter, &count](const ecs::const_entity& e, const Ts&... cs){ - iter++ = std::make_tuple(e, std::cref(cs)...); + iter++ = std::make_tuple(e, cs...); ++count; - }); + }, std::forward(opts)...); return count; } } namespace e2d::systems { - template < typename... Ts, typename F > - void for_extracted_components(ecs::registry& owner, F&& f) { + template < typename... Ts, typename F, typename... Opts > + void for_extracted_components(ecs::registry& owner, F&& f, Opts&&... opts) { //TODO(BlackMat): replace it to frame allocator - static thread_local vector...>> components; + static thread_local vector< + std::tuple> components; try { - extract_components(owner, std::back_inserter(components)); + extract_components( + owner, + std::back_inserter(components), + std::forward(opts)...); for ( auto& t : components ) { std::apply(f, t); } @@ -83,14 +85,16 @@ namespace e2d::systems components.clear(); } - template < typename... Ts, typename F > - void for_extracted_components(const ecs::registry& owner, F&& f) { + template < typename... Ts, typename F, typename... Opts > + void for_extracted_components(const ecs::registry& owner, F&& f, Opts&&... opts) { //TODO(BlackMat): replace it to frame allocator - static thread_local vector...>> components; + static thread_local vector< + std::tuple> components; try { - extract_components(owner, std::back_inserter(components)); + extract_components( + owner, + std::back_inserter(components), + std::forward(opts)...); for ( const auto& t : components ) { std::apply(f, t); } @@ -104,14 +108,16 @@ namespace e2d::systems namespace e2d::systems { - template < typename... Ts, typename Comp, typename F > - void for_extracted_components(ecs::registry& owner, Comp&& comp, F&& f) { + template < typename... Ts, typename Comp, typename F, typename... Opts > + void for_extracted_sorted_components(ecs::registry& owner, Comp&& comp, F&& f, Opts&&... opts) { //TODO(BlackMat): replace it to frame allocator - static thread_local vector...>> components; + static thread_local vector< + std::tuple> components; try { - extract_components(owner, std::back_inserter(components)); + extract_components( + owner, + std::back_inserter(components), + std::forward(opts)...); std::sort(components.begin(), components.end(), comp); for ( auto& t : components ) { std::apply(f, t); @@ -123,14 +129,16 @@ namespace e2d::systems components.clear(); } - template < typename... Ts, typename Comp, typename F > - void for_extracted_components(const ecs::registry& owner, Comp&& comp, F&& f) { + template < typename... Ts, typename Comp, typename F, typename... Opts > + void for_extracted_sorted_components(const ecs::registry& owner, Comp&& comp, F&& f, Opts&&... opts) { //TODO(BlackMat): replace it to frame allocator - static thread_local vector...>> components; + static thread_local vector< + std::tuple> components; try { - extract_components(owner, std::back_inserter(components)); + extract_components( + owner, + std::back_inserter(components), + std::forward(opts)...); std::sort(components.begin(), components.end(), comp); for ( const auto& t : components ) { std::apply(f, t); diff --git a/sources/enduro2d/high/components/behaviour.cpp b/sources/enduro2d/high/components/behaviour.cpp index 5bfe51cf..94678ef8 100644 --- a/sources/enduro2d/high/components/behaviour.cpp +++ b/sources/enduro2d/high/components/behaviour.cpp @@ -50,55 +50,3 @@ namespace e2d return true; } } - -namespace e2d -{ - const char* factory_loader::schema_source = R"json({ - "type" : "object", - "required" : [], - "additionalProperties" : false, - "properties" : {} - })json"; - - bool factory_loader::operator()( - behaviour::started& component, - const fill_context& ctx) const - { - E2D_UNUSED(component, ctx); - return true; - } - - bool factory_loader::operator()( - asset_dependencies& dependencies, - const collect_context& ctx) const - { - E2D_UNUSED(dependencies, ctx); - return true; - } -} - -namespace e2d -{ - const char* factory_loader::schema_source = R"json({ - "type" : "object", - "required" : [], - "additionalProperties" : false, - "properties" : {} - })json"; - - bool factory_loader::operator()( - behaviour::disabled& component, - const fill_context& ctx) const - { - E2D_UNUSED(component, ctx); - return true; - } - - bool factory_loader::operator()( - asset_dependencies& dependencies, - const collect_context& ctx) const - { - E2D_UNUSED(dependencies, ctx); - return true; - } -} diff --git a/sources/enduro2d/high/components/disabled.cpp b/sources/enduro2d/high/components/disabled.cpp new file mode 100644 index 00000000..d3c9968e --- /dev/null +++ b/sources/enduro2d/high/components/disabled.cpp @@ -0,0 +1,11 @@ +/******************************************************************************* + * This file is part of the "Enduro2D" + * For conditions of distribution and use, see copyright notice in LICENSE.md + * Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com) + ******************************************************************************/ + +#include + +namespace e2d +{ +} diff --git a/sources/enduro2d/high/components/renderer.cpp b/sources/enduro2d/high/components/renderer.cpp index 47420c6c..e32ee6ee 100644 --- a/sources/enduro2d/high/components/renderer.cpp +++ b/sources/enduro2d/high/components/renderer.cpp @@ -13,7 +13,6 @@ namespace e2d "required" : [], "additionalProperties" : false, "properties" : { - "enabled" : { "type" : "boolean" }, "materials" : { "type" : "array", "items" : { "$ref": "#/common_definitions/address" } @@ -25,15 +24,6 @@ namespace e2d renderer& component, const fill_context& ctx) const { - if ( ctx.root.HasMember("enabled") ) { - auto enabled = component.enabled(); - if ( !json_utils::try_parse_value(ctx.root["enabled"], enabled) ) { - the().error("FLIPBOOK_PLAYER: Incorrect formatting of 'enabled' property"); - return false; - } - component.enabled(enabled); - } - if ( ctx.root.HasMember("properties") ) { //TODO(BlackMat): add properties parsing } diff --git a/sources/enduro2d/high/node.cpp b/sources/enduro2d/high/node.cpp index 212fbd54..0f4dd309 100644 --- a/sources/enduro2d/high/node.cpp +++ b/sources/enduro2d/high/node.cpp @@ -69,11 +69,7 @@ namespace e2d owner_ = std::move(owner); } - gobject& node::owner() noexcept { - return owner_; - } - - const gobject& node::owner() const noexcept { + gobject node::owner() const noexcept { return owner_; } diff --git a/sources/enduro2d/high/starter.cpp b/sources/enduro2d/high/starter.cpp index 89a38626..d98310b2 100644 --- a/sources/enduro2d/high/starter.cpp +++ b/sources/enduro2d/high/starter.cpp @@ -178,8 +178,6 @@ namespace e2d safe_module_initialize() .register_component("actor") .register_component("behaviour") - .register_component("behaviour.started") - .register_component("behaviour.disabled") .register_component("camera") .register_component("flipbook_player") .register_component