From b80cdeb0e76778f35fda9c6f3b783b64a0dfb3ea Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Fri, 29 Nov 2019 09:07:25 +0700 Subject: [PATCH] dummy rigid_body component --- headers/enduro2d/high/_all.hpp | 1 + headers/enduro2d/high/_high.hpp | 1 + .../enduro2d/high/components/rigid_body.hpp | 33 ++++++++++++ .../scripts/emmy/components/rigid_body.lua | 19 +++++++ .../bin/library/scripts/emmy/high/gobject.lua | 3 ++ .../high/bindings/high_binds/_high_binds.hpp | 2 + .../components/rigid_body_binds.cpp | 54 +++++++++++++++++++ .../bindings/high_binds/gobject_binds.cpp | 2 + .../enduro2d/high/components/rigid_body.cpp | 34 ++++++++++++ sources/enduro2d/high/starter.cpp | 2 + untests/bin/library/prefab.json | 1 + untests/sources/untests_high/library.cpp | 1 + 12 files changed, 153 insertions(+) create mode 100644 headers/enduro2d/high/components/rigid_body.hpp create mode 100644 samples/bin/library/scripts/emmy/components/rigid_body.lua create mode 100644 sources/enduro2d/high/bindings/high_binds/components/rigid_body_binds.cpp create mode 100644 sources/enduro2d/high/components/rigid_body.cpp diff --git a/headers/enduro2d/high/_all.hpp b/headers/enduro2d/high/_all.hpp index d480fba8..584b4d7c 100644 --- a/headers/enduro2d/high/_all.hpp +++ b/headers/enduro2d/high/_all.hpp @@ -40,6 +40,7 @@ #include "components/model_renderer.hpp" #include "components/named.hpp" #include "components/renderer.hpp" +#include "components/rigid_body.hpp" #include "components/scene.hpp" #include "components/spine_player.hpp" #include "components/sprite_renderer.hpp" diff --git a/headers/enduro2d/high/_high.hpp b/headers/enduro2d/high/_high.hpp index 93a9f44c..df1cbc05 100644 --- a/headers/enduro2d/high/_high.hpp +++ b/headers/enduro2d/high/_high.hpp @@ -60,6 +60,7 @@ namespace e2d class model_renderer; class named; class renderer; + class rigid_body; class scene; class spine_player; class sprite_renderer; diff --git a/headers/enduro2d/high/components/rigid_body.hpp b/headers/enduro2d/high/components/rigid_body.hpp new file mode 100644 index 00000000..4d8cb1f4 --- /dev/null +++ b/headers/enduro2d/high/components/rigid_body.hpp @@ -0,0 +1,33 @@ +/******************************************************************************* + * 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" + +#include "../factory.hpp" + +namespace e2d +{ + class rigid_body final { + public: + rigid_body() = default; + }; + + template <> + class factory_loader final : factory_loader<> { + public: + static const char* schema_source; + + bool operator()( + rigid_body& component, + const fill_context& ctx) const; + + bool operator()( + asset_dependencies& dependencies, + const collect_context& ctx) const; + }; +} diff --git a/samples/bin/library/scripts/emmy/components/rigid_body.lua b/samples/bin/library/scripts/emmy/components/rigid_body.lua new file mode 100644 index 00000000..00040e2c --- /dev/null +++ b/samples/bin/library/scripts/emmy/components/rigid_body.lua @@ -0,0 +1,19 @@ +---@class rigid_body +local rigid_body = { + ---@type boolean + enabled = true, + + ---@type boolean + disabled = false +} + +---@overload fun(self: rigid_body) +---@param self rigid_body +function rigid_body.enable(self) end + +---@overload fun(self: rigid_body) +---@param self rigid_body +function rigid_body.disable(self) end + +---@type rigid_body +_G.rigid_body = _G.rigid_body or rigid_body diff --git a/samples/bin/library/scripts/emmy/high/gobject.lua b/samples/bin/library/scripts/emmy/high/gobject.lua index 91452682..d135e94b 100644 --- a/samples/bin/library/scripts/emmy/high/gobject.lua +++ b/samples/bin/library/scripts/emmy/high/gobject.lua @@ -39,6 +39,9 @@ local gobject = { ---@type renderer renderer = nil, + ---@type rigid_body + rigid_body = nil, + ---@type scene scene = nil, diff --git a/sources/enduro2d/high/bindings/high_binds/_high_binds.hpp b/sources/enduro2d/high/bindings/high_binds/_high_binds.hpp index 87d8f6af..e8645342 100644 --- a/sources/enduro2d/high/bindings/high_binds/_high_binds.hpp +++ b/sources/enduro2d/high/bindings/high_binds/_high_binds.hpp @@ -26,6 +26,7 @@ namespace e2d::bindings::high void bind_model_renderer(sol::state& l); void bind_named(sol::state& l); void bind_renderer(sol::state& l); + void bind_rigid_body(sol::state& l); void bind_scene(sol::state& l); void bind_spine_player(sol::state& l); void bind_sprite_renderer(sol::state& l); @@ -51,6 +52,7 @@ namespace e2d::bindings high::bind_model_renderer(l); high::bind_named(l); high::bind_renderer(l); + high::bind_rigid_body(l); high::bind_scene(l); high::bind_spine_player(l); high::bind_sprite_renderer(l); diff --git a/sources/enduro2d/high/bindings/high_binds/components/rigid_body_binds.cpp b/sources/enduro2d/high/bindings/high_binds/components/rigid_body_binds.cpp new file mode 100644 index 00000000..bd902c85 --- /dev/null +++ b/sources/enduro2d/high/bindings/high_binds/components/rigid_body_binds.cpp @@ -0,0 +1,54 @@ +/******************************************************************************* + * 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 "../_high_binds.hpp" + +#include +#include +#include + +namespace e2d::bindings::high +{ + void bind_rigid_body(sol::state& l) { + l.new_usertype>("rigid_body", + sol::no_constructor, + + "enable", [](gcomponent& c){ + c.owner().component>().remove(); + }, + + "disable", [](gcomponent& c){ + c.owner().component>().ensure(); + }, + + "enabled", sol::property( + [](const gcomponent& c) -> bool { + return !c.owner().component>().exists(); + }, + [](gcomponent& c, bool yesno){ + if ( yesno ) { + c.owner().component>().remove(); + } else { + c.owner().component>().ensure(); + } + } + ), + + "disabled", sol::property( + [](const gcomponent& c) -> bool { + return c.owner().component>().exists(); + }, + [](gcomponent& c, bool yesno){ + if ( yesno ) { + c.owner().component>().ensure(); + } else { + c.owner().component>().remove(); + } + } + ) + ); + } +} diff --git a/sources/enduro2d/high/bindings/high_binds/gobject_binds.cpp b/sources/enduro2d/high/bindings/high_binds/gobject_binds.cpp index c723fc27..ce6bf320 100644 --- a/sources/enduro2d/high/bindings/high_binds/gobject_binds.cpp +++ b/sources/enduro2d/high/bindings/high_binds/gobject_binds.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -51,6 +52,7 @@ namespace e2d::bindings::high "model_renderer", sol::property([](gobject& go){ return component_wrapper{go}; }), "named", sol::property([](gobject& go){ return component_wrapper{go}; }), "renderer", sol::property([](gobject& go){ return component_wrapper{go}; }), + "rigid_body", sol::property([](gobject& go){ return component_wrapper{go}; }), "scene", sol::property([](gobject& go){ return component_wrapper{go}; }), "spine_player", sol::property([](gobject& go){ return component_wrapper{go}; }), "sprite_renderer", sol::property([](gobject& go){ return component_wrapper{go}; }), diff --git a/sources/enduro2d/high/components/rigid_body.cpp b/sources/enduro2d/high/components/rigid_body.cpp new file mode 100644 index 00000000..5281fc2a --- /dev/null +++ b/sources/enduro2d/high/components/rigid_body.cpp @@ -0,0 +1,34 @@ +/******************************************************************************* + * 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 +{ + const char* factory_loader::schema_source = R"json({ + "type" : "object", + "required" : [], + "additionalProperties" : false, + "properties" : { + } + })json"; + + bool factory_loader::operator()( + rigid_body& 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/starter.cpp b/sources/enduro2d/high/starter.cpp index 4244300a..4181c016 100644 --- a/sources/enduro2d/high/starter.cpp +++ b/sources/enduro2d/high/starter.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -195,6 +196,7 @@ namespace e2d .register_component("model_renderer") .register_component("named") .register_component("renderer") + .register_component("rigid_body") .register_component("scene") .register_component("spine_player") .register_component>("spine_player_events") diff --git a/untests/bin/library/prefab.json b/untests/bin/library/prefab.json index 40d39e1d..cb3920b5 100644 --- a/untests/bin/library/prefab.json +++ b/untests/bin/library/prefab.json @@ -1,5 +1,6 @@ { "components" : { + "rigid_body" : {}, "touchable" : {}, "rect_collider" : { diff --git a/untests/sources/untests_high/library.cpp b/untests/sources/untests_high/library.cpp index e744c0b1..35b18ee6 100644 --- a/untests/sources/untests_high/library.cpp +++ b/untests/sources/untests_high/library.cpp @@ -250,6 +250,7 @@ TEST_CASE("library"){ ecs::registry w; ecs::entity e = w.create_entity(prefab_res->content().prototype()); + REQUIRE(e.exists_component()); REQUIRE(e.exists_component()); REQUIRE(e.exists_component());