diff --git a/src/binding/src/script_scene.cpp b/src/binding/src/script_scene.cpp index 40f174a..a5448bb 100644 --- a/src/binding/src/script_scene.cpp +++ b/src/binding/src/script_scene.cpp @@ -1,6 +1,9 @@ //#include "script_scene.hpp" #include "pw/scene/node.hpp" +#include "pw/scene/entity.hpp" +#include "pw/scene/scene.hpp" + #include "runtime_lua.hpp" namespace pw { @@ -8,6 +11,14 @@ namespace pw { void register_scene_function(sol::state&,sol::table &ns) { + ns.new_usertype("scene", + sol::constructors()); + + + ns.new_usertype("entity", + sol::constructors()); + + ns.new_usertype("node", sol::constructors(), "add_child",&node::add_child, diff --git a/src/runtime/CMakeLists.txt b/src/runtime/CMakeLists.txt index fed439f..772e306 100644 --- a/src/runtime/CMakeLists.txt +++ b/src/runtime/CMakeLists.txt @@ -1,6 +1,7 @@ set(scripts_demo ${CMAKE_SOURCE_DIR}/src/scripts/demos/simple_000.lua + ${CMAKE_SOURCE_DIR}/src/scripts/demos/simple_001.lua ) set(scripts_test diff --git a/src/scene/include/pw/scene/component.hpp b/src/scene/include/pw/scene/component.hpp index 59713c7..a792277 100644 --- a/src/scene/include/pw/scene/component.hpp +++ b/src/scene/include/pw/scene/component.hpp @@ -38,6 +38,7 @@ class node; /** * @brief components represent attributes of the scene nodes */ + class component { public: diff --git a/src/scene/include/pw/scene/entity.hpp b/src/scene/include/pw/scene/entity.hpp index d85abd8..fc02ba1 100644 --- a/src/scene/include/pw/scene/entity.hpp +++ b/src/scene/include/pw/scene/entity.hpp @@ -38,24 +38,42 @@ namespace pw { class entity { public: - entity() = delete; + entity() = default; + entity(const entity&) = default; entity(scene& s); ~entity(); template - auto add_component(Args&&... args) { - return _scene._registry.emplace(_entity,std::forward(args)...); + T& add_component(Args&&... args) { + return _registry->emplace(this->_entity,std::forward(args)...); + } + + template + void remove_component(entity) { + _registry->remove(_entity); } template - bool has_component(){ return _scene._registry.valid(_entity);} + T& get_component() { + return _registry->get(_entity); + } + + template + bool has_component(){ return _registry->valid(_entity);} void destroy(); + operator bool() const { return _registry && _entity != entt::null; } + + operator std::uint32_t() const { return static_cast(_entity); } + + bool valid() const { return _registry->valid(_entity); } private: - scene& _scene; + + std::shared_ptr _registry; entt::entity _entity { entt::null }; + }; } diff --git a/src/scene/include/pw/scene/scene.hpp b/src/scene/include/pw/scene/scene.hpp index e3f34dd..290948b 100644 --- a/src/scene/include/pw/scene/scene.hpp +++ b/src/scene/include/pw/scene/scene.hpp @@ -32,13 +32,14 @@ namespace pw { class entity; -class scene : public std::enable_shared_from_this { +class scene { public: - scene() = default; + + scene(); + ~scene() = default; protected: - - entt::registry _registry; + std::shared_ptr _registry; friend class entity; }; diff --git a/src/scene/src/entity.cpp b/src/scene/src/entity.cpp index cacc1f9..771d1f8 100644 --- a/src/scene/src/entity.cpp +++ b/src/scene/src/entity.cpp @@ -3,19 +3,48 @@ namespace pw { -entity::entity(scene& s) - : _scene(s) - , _entity(s._registry.create()) +namespace test { + +struct relationship { + std::vector children; + entt::entity parent { entt::null }; + + static void add_child(entt::registry& r,entt::entity p,entt::entity c) + { +// auto child_rels = r.view(c); + // remove potential parents + + + + } +}; + + +void testbed() +{ + using namespace entt; + + registry r; + + auto e = r.create(); +} + +} + +entity::entity(scene &s) + : _registry(s._registry) + , _entity(s._registry->create()) { } entity::~entity() { + this->destroy(); } void entity::destroy() { - _scene._registry.destroy(_entity); + _registry->destroy(_entity); } } diff --git a/src/scene/src/scene.cpp b/src/scene/src/scene.cpp index 7935e11..8c03e16 100644 --- a/src/scene/src/scene.cpp +++ b/src/scene/src/scene.cpp @@ -3,5 +3,10 @@ namespace pw { +scene::scene() + : _registry{ std::make_shared()} +{ +} + } diff --git a/src/scripts/demos/simple_001.lua b/src/scripts/demos/simple_001.lua new file mode 100644 index 0000000..e6e5993 --- /dev/null +++ b/src/scripts/demos/simple_001.lua @@ -0,0 +1,12 @@ +-- +-- small demonstrator for Lua binding on pixwerx +-- + +-- loading our libraries +pw.script:load_all() + +print("hello pixwerx!") + +local s = pw.scene.new() + + diff --git a/src/visual/src/texture.cpp b/src/visual/src/texture.cpp index d997e5f..8c2982a 100644 --- a/src/visual/src/texture.cpp +++ b/src/visual/src/texture.cpp @@ -66,7 +66,7 @@ struct texture::impl { // -// +// Wrapper // texture::texture()