Skip to content

Instantly share code, notes, and snippets.

@MrSmith33
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MrSmith33/e861a289d295ec4659a0 to your computer and use it in GitHub Desktop.
Save MrSmith33/e861a289d295ec4659a0 to your computer and use it in GitHub Desktop.
Data driven API
struct Transform {
float x, y, z;
}
struct Velocity {
float x, y, z;
}
enum entityCountMax = 1_000_000;
enum entityCountMin = 100_000;
HashmapComponentStorage!Transform transformStorage;
HashmapComponentStorage!Velocity velocityStorage;
foreach(index; 0..entityCountMin) {
velocityStorage.add(EntityId(index), Velocity(1, 1, 1));
}
foreach(index; 0..entityCountMax) {
transformStorage.add(EntityId(index), Transform(0, 0, 0));
}
auto query = componentQuery(transformStorage, velocityStorage);
foreach(row; query)
{
row.transform.x += row.velocity.x;
row.transform.y += row.velocity.y;
row.transform.z += row.velocity.z;
}
// Time 0.035,439 secs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment