brenocq / atta

Simulator for multi-robot systems
https://atta.brenocq.com
MIT License
19 stars 4 forks source link

Component module refactor #34

Closed brenocq closed 2 years ago

brenocq commented 2 years ago

Some changes to make the component module easier to use:

Expected usage:

namespace rsc = atta::resource;
namespace cmp = atta::component;

// Create material resource
rsc::Material::CreateInfo info = {.color = {1,0,0}};
rsc::Material* rmat = rsc::create<rsc::Material>("CubeMaterial", info);

// Create cube
cmp::Entity cube = cmp::createEntity();
cube.add<cmp::Name>()->set("Cube");
cube.add<cmp::Mesh>()->set("meshes/cube.obj");
cube.add<cmp::Transform>();
cube.add<cmp::Material>()->set(rmat);

// Create cube2 by copying
cmp::Entity cube2 = cmp::copyEntity(cube);
cube2.get<cmp::Transform>()->position = {1,0,0};
cube2.get<cmp::Material>()->getResource()->color = {0,1,0};

// Delete cube
cmp::deleteEntity(cube);