mirror of
https://github.com/enduro2d/enduro2d.git
synced 2025-12-13 23:58:18 +07:00
new disabled<T> component
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<behaviour::started> 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<behaviour::disabled> 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
|
||||
|
||||
18
headers/enduro2d/high/components/disabled.hpp
Normal file
18
headers/enduro2d/high/components/disabled.hpp
Normal file
@@ -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;
|
||||
};
|
||||
}
|
||||
@@ -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<material_asset::ptr>& materials() noexcept;
|
||||
const vector<material_asset::ptr>& materials() const noexcept;
|
||||
private:
|
||||
bool enabled_ = true;
|
||||
render::property_block properties_;
|
||||
vector<material_asset::ptr> 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;
|
||||
|
||||
@@ -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<T>::owner() const noexcept {
|
||||
gobject gcomponent<T>::owner() const noexcept {
|
||||
return owner_;
|
||||
}
|
||||
|
||||
@@ -283,7 +283,7 @@ namespace e2d
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
const gobject& const_gcomponent<T>::owner() const noexcept {
|
||||
gobject const_gcomponent<T>::owner() const noexcept {
|
||||
return owner_;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<Ts...>(
|
||||
[&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>(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<Ts...>(
|
||||
[&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>(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<std::tuple<
|
||||
ecs::entity,
|
||||
std::reference_wrapper<Ts>...>> components;
|
||||
static thread_local vector<
|
||||
std::tuple<ecs::entity, Ts...>> components;
|
||||
try {
|
||||
extract_components<Ts...>(owner, std::back_inserter(components));
|
||||
extract_components<Ts...>(
|
||||
owner,
|
||||
std::back_inserter(components),
|
||||
std::forward<Opts>(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<std::tuple<
|
||||
ecs::const_entity,
|
||||
std::reference_wrapper<const Ts>...>> components;
|
||||
static thread_local vector<
|
||||
std::tuple<ecs::const_entity, Ts...>> components;
|
||||
try {
|
||||
extract_components<Ts...>(owner, std::back_inserter(components));
|
||||
extract_components<Ts...>(
|
||||
owner,
|
||||
std::back_inserter(components),
|
||||
std::forward<Opts>(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<std::tuple<
|
||||
ecs::entity,
|
||||
std::reference_wrapper<Ts>...>> components;
|
||||
static thread_local vector<
|
||||
std::tuple<ecs::entity, Ts...>> components;
|
||||
try {
|
||||
extract_components<Ts...>(owner, std::back_inserter(components));
|
||||
extract_components<Ts...>(
|
||||
owner,
|
||||
std::back_inserter(components),
|
||||
std::forward<Opts>(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<std::tuple<
|
||||
ecs::const_entity,
|
||||
std::reference_wrapper<const Ts>...>> components;
|
||||
static thread_local vector<
|
||||
std::tuple<ecs::const_entity, Ts...>> components;
|
||||
try {
|
||||
extract_components<Ts...>(owner, std::back_inserter(components));
|
||||
extract_components<Ts...>(
|
||||
owner,
|
||||
std::back_inserter(components),
|
||||
std::forward<Opts>(opts)...);
|
||||
std::sort(components.begin(), components.end(), comp);
|
||||
for ( const auto& t : components ) {
|
||||
std::apply(f, t);
|
||||
|
||||
@@ -50,55 +50,3 @@ namespace e2d
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
namespace e2d
|
||||
{
|
||||
const char* factory_loader<behaviour::started>::schema_source = R"json({
|
||||
"type" : "object",
|
||||
"required" : [],
|
||||
"additionalProperties" : false,
|
||||
"properties" : {}
|
||||
})json";
|
||||
|
||||
bool factory_loader<behaviour::started>::operator()(
|
||||
behaviour::started& component,
|
||||
const fill_context& ctx) const
|
||||
{
|
||||
E2D_UNUSED(component, ctx);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool factory_loader<behaviour::started>::operator()(
|
||||
asset_dependencies& dependencies,
|
||||
const collect_context& ctx) const
|
||||
{
|
||||
E2D_UNUSED(dependencies, ctx);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
namespace e2d
|
||||
{
|
||||
const char* factory_loader<behaviour::disabled>::schema_source = R"json({
|
||||
"type" : "object",
|
||||
"required" : [],
|
||||
"additionalProperties" : false,
|
||||
"properties" : {}
|
||||
})json";
|
||||
|
||||
bool factory_loader<behaviour::disabled>::operator()(
|
||||
behaviour::disabled& component,
|
||||
const fill_context& ctx) const
|
||||
{
|
||||
E2D_UNUSED(component, ctx);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool factory_loader<behaviour::disabled>::operator()(
|
||||
asset_dependencies& dependencies,
|
||||
const collect_context& ctx) const
|
||||
{
|
||||
E2D_UNUSED(dependencies, ctx);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
11
sources/enduro2d/high/components/disabled.cpp
Normal file
11
sources/enduro2d/high/components/disabled.cpp
Normal file
@@ -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 <enduro2d/high/components/disabled.hpp>
|
||||
|
||||
namespace e2d
|
||||
{
|
||||
}
|
||||
@@ -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<debug>().error("FLIPBOOK_PLAYER: Incorrect formatting of 'enabled' property");
|
||||
return false;
|
||||
}
|
||||
component.enabled(enabled);
|
||||
}
|
||||
|
||||
if ( ctx.root.HasMember("properties") ) {
|
||||
//TODO(BlackMat): add properties parsing
|
||||
}
|
||||
|
||||
@@ -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_;
|
||||
}
|
||||
|
||||
|
||||
@@ -178,8 +178,6 @@ namespace e2d
|
||||
safe_module_initialize<factory>()
|
||||
.register_component<actor>("actor")
|
||||
.register_component<behaviour>("behaviour")
|
||||
.register_component<behaviour::started>("behaviour.started")
|
||||
.register_component<behaviour::disabled>("behaviour.disabled")
|
||||
.register_component<camera>("camera")
|
||||
.register_component<flipbook_player>("flipbook_player")
|
||||
.register_component<label>("label")
|
||||
|
||||
@@ -207,7 +207,8 @@ namespace
|
||||
f32 kerning{0.f};
|
||||
};
|
||||
|
||||
static vector<glyph_desc> glyphs;
|
||||
//TODO(BlackMat): replace it to frame allocator
|
||||
static thread_local vector<glyph_desc> glyphs;
|
||||
glyphs.clear();
|
||||
glyphs.reserve(text.size());
|
||||
|
||||
@@ -244,7 +245,8 @@ namespace
|
||||
: start(start) {}
|
||||
};
|
||||
|
||||
static vector<string_desc> strings;
|
||||
//TODO(BlackMat): replace it to frame allocator
|
||||
static thread_local vector<string_desc> strings;
|
||||
strings.clear();
|
||||
strings.reserve(calculate_string_count(text));
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include <enduro2d/high/components/actor.hpp>
|
||||
#include <enduro2d/high/components/camera.hpp>
|
||||
#include <enduro2d/high/components/disabled.hpp>
|
||||
#include <enduro2d/high/components/scene.hpp>
|
||||
|
||||
#include "render_system_impl/render_system_base.hpp"
|
||||
@@ -21,7 +22,7 @@ namespace
|
||||
|
||||
void for_all_scenes(drawer::context& ctx, const ecs::registry& owner) {
|
||||
const auto comp = [](const auto& l, const auto& r) noexcept {
|
||||
return std::get<1>(l).get().depth() < std::get<1>(r).get().depth();
|
||||
return std::get<scene>(l).depth() < std::get<scene>(r).depth();
|
||||
};
|
||||
const auto func = [&ctx](
|
||||
const ecs::const_entity&,
|
||||
@@ -32,12 +33,16 @@ namespace
|
||||
ctx.draw(node);
|
||||
});
|
||||
};
|
||||
systems::for_extracted_components<scene, actor>(owner, comp, func);
|
||||
systems::for_extracted_sorted_components<scene, actor>(
|
||||
owner,
|
||||
comp,
|
||||
func,
|
||||
!ecs::exists<disabled<scene>>());
|
||||
}
|
||||
|
||||
void for_all_cameras(drawer& drawer, const ecs::registry& owner) {
|
||||
const auto comp = [](const auto& l, const auto& r) noexcept {
|
||||
return std::get<1>(l).get().depth() < std::get<1>(r).get().depth();
|
||||
return std::get<camera>(l).depth() < std::get<camera>(r).depth();
|
||||
};
|
||||
const auto func = [&drawer, &owner](
|
||||
const ecs::const_entity&,
|
||||
@@ -48,7 +53,11 @@ namespace
|
||||
for_all_scenes(ctx, owner);
|
||||
});
|
||||
};
|
||||
systems::for_extracted_components<camera, actor>(owner, comp, func);
|
||||
systems::for_extracted_sorted_components<camera, actor>(
|
||||
owner,
|
||||
comp,
|
||||
func,
|
||||
!ecs::exists<disabled<camera>>());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include "render_system_drawer.hpp"
|
||||
|
||||
#include <enduro2d/high/components/disabled.hpp>
|
||||
#include <enduro2d/high/components/model_renderer.hpp>
|
||||
#include <enduro2d/high/components/renderer.hpp>
|
||||
#include <enduro2d/high/components/spine_player.hpp>
|
||||
@@ -79,9 +80,7 @@ namespace e2d::render_system_impl
|
||||
batcher_.clear(true);
|
||||
}
|
||||
|
||||
void drawer::context::draw(
|
||||
const const_node_iptr& node)
|
||||
{
|
||||
void drawer::context::draw(const const_node_iptr& node) {
|
||||
if ( !node || !node->owner() ) {
|
||||
return;
|
||||
}
|
||||
@@ -89,7 +88,7 @@ namespace e2d::render_system_impl
|
||||
const gobject& owner = node->owner();
|
||||
gcomponent<renderer> node_r{owner};
|
||||
|
||||
if ( !node_r || !node_r->enabled() ) {
|
||||
if ( !node_r || owner.component<disabled<renderer>>() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -106,15 +105,15 @@ namespace e2d::render_system_impl
|
||||
}
|
||||
}
|
||||
|
||||
void drawer::context::flush() {
|
||||
batcher_.flush();
|
||||
}
|
||||
|
||||
void drawer::context::draw(
|
||||
const const_node_iptr& node,
|
||||
const renderer& node_r,
|
||||
const model_renderer& mdl_r)
|
||||
{
|
||||
if ( !node || !node_r.enabled() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !mdl_r.model() || !mdl_r.model()->content().mesh() ) {
|
||||
return;
|
||||
}
|
||||
@@ -156,12 +155,9 @@ namespace e2d::render_system_impl
|
||||
const renderer& node_r,
|
||||
const spine_player& spine_r)
|
||||
{
|
||||
static std::vector<float> temp_vertices(1000u, 0.f);
|
||||
static std::vector<batcher_type::vertex_type> batch_vertices(1000u);
|
||||
|
||||
if ( !node || !node_r.enabled() ) {
|
||||
return;
|
||||
}
|
||||
//TODO(BlackMat): replace it to frame allocator
|
||||
static thread_local std::vector<float> temp_vertices(1000u, 0.f);
|
||||
static thread_local std::vector<batcher_type::vertex_type> batch_vertices(1000u);
|
||||
|
||||
spSkeleton* skeleton = spine_r.skeleton().get();
|
||||
spSkeletonClipping* clipper = spine_r.clipper().get();
|
||||
@@ -431,10 +427,6 @@ namespace e2d::render_system_impl
|
||||
const renderer& node_r,
|
||||
const sprite_renderer& spr_r)
|
||||
{
|
||||
if ( !node || !node_r.enabled() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !spr_r.sprite() ) {
|
||||
return;
|
||||
}
|
||||
@@ -530,10 +522,6 @@ namespace e2d::render_system_impl
|
||||
property_cache_.clear();
|
||||
}
|
||||
|
||||
void drawer::context::flush() {
|
||||
batcher_.flush();
|
||||
}
|
||||
|
||||
//
|
||||
// drawer
|
||||
//
|
||||
|
||||
@@ -40,9 +40,9 @@ namespace e2d::render_system_impl
|
||||
batcher_type& batcher);
|
||||
~context() noexcept;
|
||||
|
||||
void draw(
|
||||
const const_node_iptr& node);
|
||||
|
||||
void draw(const const_node_iptr& node);
|
||||
void flush();
|
||||
private:
|
||||
void draw(
|
||||
const const_node_iptr& node,
|
||||
const renderer& node_r,
|
||||
@@ -52,13 +52,11 @@ namespace e2d::render_system_impl
|
||||
const const_node_iptr& node,
|
||||
const renderer& node_r,
|
||||
const sprite_renderer& spr_r);
|
||||
|
||||
|
||||
void draw(
|
||||
const const_node_iptr& node,
|
||||
const renderer& node_r,
|
||||
const spine_player& spine_r);
|
||||
|
||||
void flush();
|
||||
private:
|
||||
render& render_;
|
||||
batcher_type& batcher_;
|
||||
|
||||
Reference in New Issue
Block a user