Grindstone Game Engine v0.2.0
An open source game engine and toolkit.
Loading...
Searching...
No Matches
ECS: Components

Note
Return to the ECS page for an overview.

A component is a grouping of data and utility functions that exist on an entity. It is typically operated on by Systems. All components of an entity are shown in the Grindstone Editor's Inspector panel when that entity is selected.

Component Functionality

If components have some specific static functions, those will be used by the ECS system.

  • static void Construct(Grindstone::WorldContextSet& worldContextSet, entt::entity entity) is used when a component is added to an entity.
  • static void Destroy(Grindstone::WorldContextSet& worldContextSet, entt::entity entity) is used when a component is removed from an entity.

Example

Here is an example of how an entity can be defined. The MeshRendererComponent allows for rendering of Meshes.

As you can see, it contains a vector of Materials by which to render the submeshes of a MeshComponent. A typical pattern is to have multiple components work together when used in a System.

Furthermore, you can see the static functions Construct and Destroy, which provide the ECS logic referenced above.

namespace Grindstone {
struct MeshRendererComponent {
std::vector<Grindstone::AssetReference<Grindstone::MaterialAsset>> materials;
static void Construct(Grindstone::WorldContextSet& worldContextSet, entt::entity entity);
static void Destroy(Grindstone::WorldContextSet& worldContextSet, entt::entity entity);
Grindstone::GraphicsAPI::Buffer* perDrawUniformBuffer = nullptr;
Grindstone::GraphicsAPI::DescriptorSet* perDrawDescriptorSet = nullptr;
REFLECT("MeshRenderer")
};
}
Definition Buffer.hpp:49
Definition DescriptorSet.hpp:15
Definition WorldContextSet.hpp:11
Definition ArchiveContentFile.hpp:8