Entity Component System (ECS) I'm currently working on my own game engine for learning purposes, so I've implemented the first iteration of an entity component system using Java 8.

For my approach, I decided to not use any entity class for the system as an entity only holds data and so there is no class required to list all the components itself. This also means that I've got a Component which holds the data and a System which can have access to multiple components (for example a movement system which required data from the position and velocity component).

My systems also have a render method available (thought render systems are the only one who uses them), because the frame rate is not the same as the ticks.

In my ExitSystem, the InputMultiplexer is just for testing purpose there.

How can I improve the code and mainly the system I've got?

The EntityManager: 

public class EntityManager {

private ArrayList&lt;Integer&gt; entities = new ArrayList&lt;&gt;();
private ArrayList&lt;ISystem&gt; componentSystems = new ArrayList&lt;&gt;();

public void addEntity(int ID, ISystem... system) {
    this.entities.add(ID);
    this.componentSystems.addAll(Arrays.asList(system));
}

public void init() {
    for(ISystem system : this.componentSystems)
        system.init();
}

public void update() {
    for(ISystem system : this.componentSystems)
        system.update();
}

public void render() {
    for(ISystem system : this.componentSystems)
        system.render();
}

public void dispose() {
    for(ISystem system : this.componentSystems)
        system.dispose();
}

public int getEntity(int id) {
    return this.entities.get(id);
}
}


The IEntityComponent:

public interface IEntityComponent {

}


The ISystem:

public interface ISystem {

public void init();

public void update();

public void render();

public void dispose();

public IEntityComponent[] get();
}


The ExitData:

public class ExitData implements IEntityComponent {

public int exit = GLFW_KEY_ESCAPE;
public int action = GLFW_REPEAT;
}


The ExitSystem:

public class ExitSystem implements ISystem {

@Override
public void init() {
    InputMultiplexer.getInput().addComponent(new InputComponent.InputKeyComponent() {

        @Override
        public boolean onKeyPress(int key, int action) {
            if(key == ((ExitData)get()[0]).exit &amp;&amp; action == ((ExitData)get()[0]).action)
                Game.windowShouldClose();
            return true;
        }
    });
}

@Override
public void update() {

}

@Override
public void render() {

}

@Override
public void dispose() {

}

@Override
public IEntityComponent[] get() {
    return new IEntityComponent[] {new ExitData()};
}
}
Components should hold information, that is / can be different from one instance to another; in your example hardcoded ExitData values with conjunction of creating new instances on each get call make it little different to just using a global field. Frankly I am not sure if Exit should even be a system as such.

Your systems should be getting components in packs (grouped by entity) from common pool (instead of creating it each for it self), and then depending on the kind of components there are in said pack, do something with them or not.

I don't understand what your entities list is supposed to do, you don't use it. Also you put values by value, but retrieve by index, which smells like a bug. 

I think your problem is that you chose a bad testing case. Something more appropriate would be: 


Make Position (with x and y fields) and Velocity (with xvel and yvel) components.
Make Velocity System, which in update loop for entities with Position and Velocity components does x += xvel; y += yvel;
Make 'Render' System, which simply prints Position values.
Add entities, which all have Position component, optionally have Velocity component, and the starting values of the components is different.


This way you would test against systems interacting on components from same pool, systems choosing to work against component set that matches criteria, grouping components by their entity. 

--

By saying Your systems should be getting components in packs (grouped by entity) from common pool (instead of creating it each for it self) I meant to say there is no composition relation between systems and components. Your systems should not have components directly attached to it. 

Here is minimal example of ECS with the position, velocity and 'rendering' components. It is not optimized, lacks encapsulation, manager misses few methods (at the very least deleteEntity), but I hope it captures the spirit in least lines of code possible.

public class Component {

    public final static int POS = 1 &lt;&lt; 0,
                            VEL = 1 &lt;&lt; 1,
                            RENDER = 1 &lt;&lt; 2;

    public static class Velocity {
        float velx, vely;
    }

    public static class Position {
        float x, y;
    }

    public static class Rendering {
        String name; // for sake of having at least one field inside.
    }
}


--

public class Systems {

    public static class Velocity {
        public void update(EntityManager manager) {
            int required_components = Component.POS | Component.VEL;
            for (int i = 0; i &lt; manager.size; i++) {
                if ((manager.flag[i] &amp; required_components) == required_components){
                    manager.pos[i].x += manager.vel[i].velx;
                    manager.pos[i].y += manager.vel[i].vely;
                }
            }
        }
    }

    public static class Render {
        public void update(EntityManager manager) {
            int required_components = Component.POS | Component.RENDER;
            for (int i = 0; i &lt; manager.size; i++) {
                if ((manager.flag[i] &amp; required_components) == required_components) {
                    System.out.println(String.format("%s: (%f x, %f y)", manager.rendering[i].name, manager.pos[i].y, manager.pos[i].y));
                }
            }
        }
    }

}


--

public class EntityManager {
    public int flag[];
    public Component.Position pos[];
    public Component.Velocity vel[];
    public Component.Rendering rendering[];
    public final int size;

    public EntityManager(int size) {
        this.size = size;
        pos = new Component.Position[size];
        vel = new Component.Velocity[size];
        rendering = new Component.Rendering[size];
        flag = new int[size];
    }

    public int createEntity(int flag) {
        for (int i = 0; i &lt; size; i++){
            if (this.flag[i] == 0) {
                this.flag[i] = flag;
                if ((flag &amp; Component.POS) &gt; 0) pos[i] = new Component.Position();
                if ((flag &amp; Component.VEL) &gt; 0) vel[i] = new Component.Velocity();
                if ((flag &amp; Component.RENDER) &gt; 0) rendering[i] = new Component.Rendering();
                return i;
            }
        }
        return -1;
    }
}


--

public class GameContainer {

    public static void main(String[] args) {
        new GameContainer();
    }

    EntityManager manager;
    Systems.Render renderingSystem;
    Systems.Velocity velocitySystem;

    GameContainer() {
        manager = new EntityManager(5);
        renderingSystem = new Systems.Render();
        velocitySystem = new Systems.Velocity();

        int id = manager.createEntity(Component.POS | Component.VEL | Component.RENDER);
        if (id &gt; -1) {
            manager.pos[id].x = 10;
            manager.pos[id].y = 10;
            manager.vel[id].velx = 1;
            manager.vel[id].vely = 1;
            manager.rendering[id].name = "player";
        }

        id = manager.createEntity(Component.POS | Component.RENDER);
        if (id &gt; -1) {
            manager.pos[id].x = 0;
            manager.pos[id].y = 0;
            manager.rendering[id].name = "tree";
        }
        startGameLoop();
    }

    void startGameLoop() {
        while(true) {
            velocitySystem.update(manager);
            renderingSystem.update(manager);
        }
    }

}