Skip to content

Instantly share code, notes, and snippets.

@maxov
Last active August 29, 2015 14:06
Show Gist options
  • Save maxov/3d2c7e740fa3db20f97b to your computer and use it in GitHub Desktop.
Save maxov/3d2c7e740fa3db20f97b to your computer and use it in GitHub Desktop.
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