initial ECS based on EnTT
This commit is contained in:
parent
2ef6af25c1
commit
cea83d06e8
9 changed files with 92 additions and 14 deletions
|
@ -1,6 +1,9 @@
|
||||||
//#include "script_scene.hpp"
|
//#include "script_scene.hpp"
|
||||||
|
|
||||||
#include "pw/scene/node.hpp"
|
#include "pw/scene/node.hpp"
|
||||||
|
#include "pw/scene/entity.hpp"
|
||||||
|
#include "pw/scene/scene.hpp"
|
||||||
|
|
||||||
#include "runtime_lua.hpp"
|
#include "runtime_lua.hpp"
|
||||||
|
|
||||||
namespace pw {
|
namespace pw {
|
||||||
|
@ -8,6 +11,14 @@ namespace pw {
|
||||||
void register_scene_function(sol::state&,sol::table &ns)
|
void register_scene_function(sol::state&,sol::table &ns)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
ns.new_usertype<scene>("scene",
|
||||||
|
sol::constructors<scene()>());
|
||||||
|
|
||||||
|
|
||||||
|
ns.new_usertype<entity>("entity",
|
||||||
|
sol::constructors<entity>());
|
||||||
|
|
||||||
|
|
||||||
ns.new_usertype<node>("node",
|
ns.new_usertype<node>("node",
|
||||||
sol::constructors<node()>(),
|
sol::constructors<node()>(),
|
||||||
"add_child",&node::add_child,
|
"add_child",&node::add_child,
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
|
|
||||||
set(scripts_demo
|
set(scripts_demo
|
||||||
${CMAKE_SOURCE_DIR}/src/scripts/demos/simple_000.lua
|
${CMAKE_SOURCE_DIR}/src/scripts/demos/simple_000.lua
|
||||||
|
${CMAKE_SOURCE_DIR}/src/scripts/demos/simple_001.lua
|
||||||
)
|
)
|
||||||
|
|
||||||
set(scripts_test
|
set(scripts_test
|
||||||
|
|
|
@ -38,6 +38,7 @@ class node;
|
||||||
/**
|
/**
|
||||||
* @brief components represent attributes of the scene nodes
|
* @brief components represent attributes of the scene nodes
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class component {
|
class component {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
|
@ -38,24 +38,42 @@ namespace pw {
|
||||||
|
|
||||||
class entity {
|
class entity {
|
||||||
public:
|
public:
|
||||||
entity() = delete;
|
entity() = default;
|
||||||
|
entity(const entity&) = default;
|
||||||
entity(scene& s);
|
entity(scene& s);
|
||||||
~entity();
|
~entity();
|
||||||
|
|
||||||
template <typename T,typename... Args>
|
template <typename T,typename... Args>
|
||||||
auto add_component(Args&&... args) {
|
T& add_component(Args&&... args) {
|
||||||
return _scene._registry.emplace<T>(_entity,std::forward<Args>(args)...);
|
return _registry->emplace<T>(this->_entity,std::forward<Args>(args)...);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void remove_component(entity) {
|
||||||
|
_registry->remove<T>(_entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
bool has_component(){ return _scene._registry.valid(_entity);}
|
T& get_component() {
|
||||||
|
return _registry->get<T>(_entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
bool has_component(){ return _registry->valid(_entity);}
|
||||||
|
|
||||||
void destroy();
|
void destroy();
|
||||||
|
|
||||||
|
operator bool() const { return _registry && _entity != entt::null; }
|
||||||
|
|
||||||
|
operator std::uint32_t() const { return static_cast<std::uint32_t>(_entity); }
|
||||||
|
|
||||||
|
bool valid() const { return _registry->valid(_entity); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
scene& _scene;
|
|
||||||
|
std::shared_ptr<entt::registry> _registry;
|
||||||
entt::entity _entity { entt::null };
|
entt::entity _entity { entt::null };
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,13 +32,14 @@ namespace pw {
|
||||||
|
|
||||||
class entity;
|
class entity;
|
||||||
|
|
||||||
class scene : public std::enable_shared_from_this<scene> {
|
class scene {
|
||||||
public:
|
public:
|
||||||
scene() = default;
|
|
||||||
|
scene();
|
||||||
|
~scene() = default;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
std::shared_ptr<entt::registry> _registry;
|
||||||
entt::registry _registry;
|
|
||||||
friend class entity;
|
friend class entity;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -3,19 +3,48 @@
|
||||||
|
|
||||||
namespace pw {
|
namespace pw {
|
||||||
|
|
||||||
entity::entity(scene& s)
|
namespace test {
|
||||||
: _scene(s)
|
|
||||||
, _entity(s._registry.create())
|
struct relationship {
|
||||||
|
std::vector<entt::entity> children;
|
||||||
|
entt::entity parent { entt::null };
|
||||||
|
|
||||||
|
static void add_child(entt::registry& r,entt::entity p,entt::entity c)
|
||||||
|
{
|
||||||
|
// auto child_rels = r.view<relationship>(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()
|
entity::~entity()
|
||||||
{
|
{
|
||||||
|
this->destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
void entity::destroy()
|
void entity::destroy()
|
||||||
{
|
{
|
||||||
_scene._registry.destroy(_entity);
|
_registry->destroy(_entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,5 +3,10 @@
|
||||||
|
|
||||||
namespace pw {
|
namespace pw {
|
||||||
|
|
||||||
|
scene::scene()
|
||||||
|
: _registry{ std::make_shared<entt::registry>()}
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
12
src/scripts/demos/simple_001.lua
Normal file
12
src/scripts/demos/simple_001.lua
Normal file
|
@ -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()
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,7 @@ struct texture::impl {
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
//
|
// Wrapper
|
||||||
//
|
//
|
||||||
|
|
||||||
texture::texture()
|
texture::texture()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue