Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Body-Component-System
// Represents a thing in the game world
interface Body {
int getID();
}
// Represents a behavior
interface Component {
}
// Manages a single component
interface ComponentSystem<C extends Component> {
C add(int body, Component c);
C get(int body);
C remove(int body, C component);
boolean has(int body);
}
// Manages a set of bodies
interface ComponentContext {
Body spawn();
Body despawn(int id);
List<Body> getAllBodies();
}
// Finally: Manages a set of ComponentSystems, as well as the ComponentContext they act on
// Note: Can totally merge this with ComponentContext.
interface ComponentManager {
void add(ComponentSystem system);
void remove(ComponentSystem system);
ComponentContext getContext();
void setContext();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.