Skip to content

Instantly share code, notes, and snippets.

@IDragonfire
Created September 16, 2014 01:23
Show Gist options
  • Save IDragonfire/1a8d631dd5ea261d4378 to your computer and use it in GitHub Desktop.
Save IDragonfire/1a8d631dd5ea261d4378 to your computer and use it in GitHub Desktop.
// Represents a thing in the game world
interface GameObject {
int getID();
}
// Store data
public abstract class Component extends GameObject {
private static Class<? extends Component>[] idArray = new Class<? extends Component>[10];
@Override
public int getID() {
return idArray[getClass()];
}
}
// Manages a single component
interface ComponentSystem<T extends GameObject, C extends Component> {
C add(T obj);
C get(T obj);
C remove(T obj);
boolean has(T obj);
}
// Manages a set of bodies
interface ComponentContext<T extends GameObject> {
int create(T obj);
T destroy(int id);
List<T> getAll();
}
// Finally: Manages a set of ComponentSystems, as well as the ComponentContext they act on
interface ComponentManager<T extends GameObject> {
void add(ComponentSystem<T, ? extends Component> system);
void remove(ComponentSystem<T, ? extends Component> system);
public ComponentContext<T> getContext();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment