-update README code example (to one that compile)
-remove Entity.instance and gEM, global manager is now gEntityManager
This commit is contained in:
parent
d1c48e4c5f
commit
3b954b732b
11 changed files with 617 additions and 604 deletions
43
README.md
43
README.md
|
|
@ -101,6 +101,11 @@ Online demo support multithreading and page tries to check if client support WAS
|
|||
|
||||
```d
|
||||
|
||||
import bubel.ecs.core;
|
||||
import bubel.ecs.manager;
|
||||
import bubel.ecs.attributes;
|
||||
import std.array : staticArray;
|
||||
|
||||
struct Position
|
||||
{
|
||||
float x;
|
||||
|
|
@ -122,7 +127,7 @@ struct UpdateSystem
|
|||
{
|
||||
mixin ECS.System; //makes struct system
|
||||
|
||||
ECS.ExcludedComponents!(StaticFlag); //prevents static entities from update
|
||||
mixin ECS.ExcludedComponents!(StaticFlag); //prevents static entities from update
|
||||
|
||||
struct EntitiesData
|
||||
{
|
||||
|
|
@ -136,26 +141,31 @@ struct UpdateSystem
|
|||
{
|
||||
foreach(i; 0..data.length) //iterate over entities
|
||||
{
|
||||
data.positions[i].x += data.velocities[i].x * dt;
|
||||
data.positions[i].y += data.velocities[i].y * dt;
|
||||
data.positions[i].x += data.velocities[i].x;
|
||||
data.positions[i].y += data.velocities[i].y;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
manager.beginRegister();
|
||||
//initialize ECS
|
||||
EntityManager.initialize();
|
||||
|
||||
//begin registering process
|
||||
gEntityManager.beginRegister();
|
||||
//register components
|
||||
manager.registerComponent!Position;
|
||||
manager.registerComponent!Velocity;
|
||||
manager.registerComponent!StaticFlag;
|
||||
gEntityManager.registerComponent!Position;
|
||||
gEntityManager.registerComponent!Velocity;
|
||||
gEntityManager.registerComponent!StaticFlag;
|
||||
//register system with priority 0
|
||||
manager.registerSystem!UpdateSystem(0);
|
||||
manager.endRegister();
|
||||
gEntityManager.registerSystem!UpdateSystem(0);
|
||||
//end registering process
|
||||
gEntityManager.endRegister();
|
||||
|
||||
//allocate template
|
||||
EntityTemplate* tmpl = manager.allocateEmplate([becsID!Velocity, becsID!Position].staticArray);
|
||||
scope (exit) manager.freeTemplate(tmpl);
|
||||
EntityTemplate* tmpl = gEntityManager.allocateTemplate([becsID!Velocity, becsID!Position].staticArray);
|
||||
scope (exit) gEntityManager.freeTemplate(tmpl);
|
||||
|
||||
//gets pointer to template component data
|
||||
Position* position = tmpl.getComponent!Position;
|
||||
|
|
@ -163,12 +173,15 @@ void main()
|
|||
{
|
||||
position.x = i % 10;
|
||||
position.y = i / 10;
|
||||
manager.addEntity(tmpl);
|
||||
gEntityManager.addEntity(tmpl);
|
||||
}
|
||||
|
||||
manager.begin(); //start frame, inside system onBegin callbacks are called
|
||||
manager.update(); //update all systems, there onUpdate callbacks are called
|
||||
manager.end(); //end frame, inside system onEnd callbacks are called
|
||||
gEntityManager.begin(); //start frame, inside system onBegin callbacks are called
|
||||
gEntityManager.update(); //update all systems, there onUpdate callbacks are called
|
||||
gEntityManager.end(); //end frame, inside system onEnd callbacks are called*/
|
||||
|
||||
//free ECS data
|
||||
EntityManager.destroy();
|
||||
}
|
||||
|
||||
```
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue