Description

A D port of Artemis Entity System Framework

Package Information

Version~master (2015-Jul-27)
Homepage http://github.com/elvisxzhou/artemisd
Repository https://github.com/elvisxzhou/artemisd
LicenseBSD 3-Clause
CopyrightCopyright (c) 2013, Elvis Zhou
AuthorsElvis Zhou
Registered byElvis Zhou
Dependencies none

Installation

To use this package, put the following dependency into your project's dependencies section:

dub.json
dub.sdl

Readme

ArtemisD

A D port of Artemis Entity System Framework

Artemis is a high performance Entity System framework for games.

Manual: http://gamadu.com/artemis/manual.html

Tutorial: http://gamadu.com/artemis/tutorial.html

##License New BSD license

##Example

import std.stdio;
import artemisd.all;

final class Position : Component
{
    mixin TypeDecl;

    float x;
    float y;

    this(float x, float y)
    {
        this.x = x;
        this.y = y;
    }
}

final class Velocity : Component
{
    mixin TypeDecl;

    float x;
    float y;

    this(float x, float y)
    {
        this.x = x;
        this.y = y;
    }
}

final class Renderer : Component
{
    mixin TypeDecl;
}

final class MovementSystem : EntityProcessingSystem
{
    mixin TypeDecl;

    this()
    {
        super(Aspect.getAspectForAll!(Position,Velocity));
    }

    override void process(Entity e)
    {
        Position pos = e.getComponent!Position;
        Velocity vel = e.getComponent!Velocity;
        Renderer rend = e.getComponent!Renderer;
        assert(pos !is null);
        assert(vel !is null);
        assert(rend is null);

        pos.x += vel.x * world.getDelta();
        pos.y += vel.y * world.getDelta();

        writeln(e, " move to (", pos.x, ",", pos.y, ")");
    }
}

final class RenderSystem : EntityProcessingSystem
{
    mixin TypeDecl;

    this()
    {
        super(Aspect.getAspectForAll!(Position, Renderer));
    }

    override void process(Entity e)
    {
        Renderer rend = e.getComponent!Renderer;
        Position pos = e.getComponent!Position;
        assert(pos !is null);
        assert(rend !is null);

        writeln(e, " rendered at (", pos.x, ",", pos.y, ")");
    }
}

void main(string[] argv)
{
    World world = new World();
    world.setSystem(new MovementSystem);
    world.setSystem(new RenderSystem);
    world.initialize();

    Entity e = world.createEntity();
    e.addComponent(new Position(0,0));
    e.addComponent(new Velocity(10,0));
    e.addToWorld();

    Entity e1 = world.createEntity();
    e1.addComponent(new Position(0,0));
    e1.addComponent(new Renderer);
    e1.addToWorld();

    import core.thread;
    
    while(true)
    {
        world.setDelta(1/60.0f);
        world.process();
        Thread.sleep(1000.msecs);
    }
}

Available versions

~master ~dev