Skip to content

Files

Latest commit

b4086c0 · Oct 15, 2022

History

History

cube-factory

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Aug 18, 2022
Sep 17, 2022
Jun 17, 2022
Oct 15, 2022

Cube Factory

This project is an introduction to atta prototypes, and they are a key feature to simulate multi-robot systems.

The whole idea behind prototypes is having multiple clones of the same thing. Because they are identical, atta can eficiently organize them in memory and paralelize the execution of their scripts.

This project create an wave animation using clones of a cube entity.

Prototype-Clone-Factory

First, let's understand the difference between prototype, clone, and factory.

Prototypes are entities used as template to create clone entities. Prototype entities don't interact with other entities during the simulation and their scripts are not executed either.

Clones are entities that were generated from a prototype entity. Each clone entity has a copy of the prototype entity's components as its components.

The factory is the responsible for creating the clones from the prototype, and providing an interface to obtain information about the clones and prototypes. For example, we need to use the factory to access the EntityId of each clone generated by a prototype.

Setting up

Now that we understand what they are, let's see how to add them to the project.

We will add a prototype component to the cube, where we can specity the number of clones (maxClones) to be created. Note that the cube will not be rendered anymore.

If we press the start button, clones should be generated. They will all be in the same positon, let's change that with the script.

Programming

Inside the clone script, we can differentiate between the clones by using the method entity.getCloneId().

void CubeScript::update(atta::Entity entity, float dt)
{
    ...
    int cloneId = entity.getCloneId();
    ...
}

The cloneId starts with 0 and goes to N 1 , where N is the number of clones generated from the prototype. Clones generated from different prototypes can have the same cloneId.

Implementation details

The components from the clones generated by the same prototype are continuously stored in the memory, which reduces cache misses and makes it possible to do only one transfer to the GPU.