elvisxzhou/artemisd — pull request #6 by Archytaus (2014-04-02 21:02:34+00:00)
Title: Added support for entity templates

Can be used by defining a template like this:
```
class BulletTemplate : EntityTemplate {
mixin TypeDecl;

static Mesh mesh;
static ShaderProgram shaderProgram;

static const float BulletSpeed = 10.0f;
static const float BulletLife = 3.0f;
static const vec3 BulletSize = vec3(3, 0.3, 0.3);

static Entity buildEntity(Entity e, World world, vec3 position, quat rotation, vec3 direction) {
e.addComponent(new Templated(TypeId));
e.addComponent(new Expirable(BulletLife));
e.addComponent(new Velocity(direction * BulletSpeed));
e.addComponent(new Transformable(position, rotation, BulletSize));
e.addComponent(new Networkable());
e.addComponent(new Renderable(mesh, shaderProgram));
return e;
}
}
```

And used like this:
```
world.createEntityFromTemplate!(BulletTemplate)(
transformable._position,
transformable._rotation,
transformable._rotation * vec3(1, 0, 0)
);
```