组件模式

“允许一个单一的实体跨越多个不同域而不会导致耦合”

在ECS框架中非常常见,是最基本的东西了。

总之就像这样类似的写法

class GameObject
{
public:
    // ...

    GameObject(AComponent* aCmpt, BComponent* bCmpt, CComponent* cCmpt)
    : aCmpt(aCmpt), bCmpt(bCmpt), cCmpt(cCmpt)
    {}
    void update()
    {
        aCmpt->update();
        bCmpt->update();
        cCmpt->update();
    }
private:
    AComponent *aCmpt; 
    BComponent *bCmpt;
    CComponent *cCmpt;
};

完全可以用 BaseComponent* arr[] 数组存,update的遍历所有Cmpt调用其update。

对象如何获得组件

组件之间如何传递信息