c++ – Workaround to bind templated capabilities to lua?

c++ – Workaround to bind templated capabilities to lua?

[ad_1]

I am making an attempt so as to add Lua for scripting to my C++ sport engine, which relies on ECS, and I’ve a tough concept of what I need to do (is it good? in all probability not) however making an attempt to really execute it has been slightly difficult. The thought I had in thoughts was permitting scripts to have the ability to entry any entity and their part, so the purpose is to have one thing like this.

native playerEntity = scene:GetEntity("Participant")
native playerMoveComponent = playerEntity.Mover

perform Replace(deltaTime)
    if enter.isKeyDown("w") then
        playerMoveComponent:SetDirection()
        -- or
        playerMoveComponent.x = 5
    finish
finish

The issue is I do not precisely know obtain this syntax with sol2 additionally, my ECS is closely templated which I simply discovered makes it tough to do bindings. For my ECS construction I’ve a EntityManager I suppose this might be my database which shops the parts, parts inherit from an interface IComponent, and entities are only a class with an id. if it helps clarify issues higher here is the EntityManager

class EntityManager {
public:
    void startUp();
    void shutDown();

    void replace(float timestep);

    Entity newEntity(const std::string& title = "unnamed entity");
    void destroyEntity(Entity entity);
    bool alive(Entity entity);
    Entity getEntityByName(const std::string& title);

    template <typename TComponent, typename... TArgs>
    void addComponent(Entity entity, TArgs&&... args);

    template <typename TComponent>
    void removeComponent(Entity entity);

    template <typename TComponent>
    TComponent& getComponent(Entity entity);

    template <typename TComponent>
    bool hasComponent(Entity entity);

    // ...
personal:
    int nextEntityId = 0;

    std::vector<std::unique_ptr<ISystem>> techniques;
    std::unordered_map<int, bool> entityAlive;
    std::unordered_map<std::type_index, std::unordered_map<int, std::shared_ptr<void>>> parts;
};
```

[ad_2]

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply