public static void Main(string[] args) { IWorldContext worldContext = new WorldContextFactory().CreateNewWorldInstance(); ISystemManager systemManager = new SystemManager(worldContext); systemManager.RegisterSystem(new PureInitSystemAdapter(worldContext, (world) => { // worldContext's variable is available here Console.WriteLine("call Init()"); var e = worldContext.GetEntityById(worldContext.CreateEntity()); e.AddComponent <TestComponent>(); })); systemManager.RegisterSystem(new PureUpdateSystemAdapter(worldContext, (world, dt) => { var entitiesArray = worldContext.GetEntitiesWithAll(typeof(TestComponent)); // worldContext's variable is available here Console.WriteLine("call Update(float)"); })); systemManager.RegisterSystem(new PureReactiveSystemAdapter(worldContext, entity => { return(entity.HasComponent <AnotherComponent>()); } , (world, entities, dt) => { worldContext.CreateDisposableEntity("TestDisposableEntity"); // worldContext's variable is available here Console.WriteLine("call ReactiveUpdate(entities, float)"); })); systemManager.Init(); for (int i = 0; i < 5; ++i) { IEntity entity = worldContext.GetEntityById(worldContext.CreateEntity()); Debug.Assert(entity != null); entity.AddComponent <TestComponent>(); } worldContext.GetEntityById(worldContext.CreateEntity()).AddComponent <AnotherComponent>(); for (int i = 0; i < 10; ++i) { systemManager.Update(0.0f); } Console.WriteLine("Finished"); Console.ReadKey(); }
public static void Main(string[] args) { IWorldContext worldContext = new WorldContextFactory().CreateNewWorldInstance(); ISystemManager systemManager = new SystemManager(worldContext); // register our classes that implement systems systemManager.RegisterSystem(new PrintHelloWorldSystem()); systemManager.RegisterSystem(new ReactivePrintHelloWorldSystem()); // another way of doing the same things is to use adapters and lambdas instead of classes systemManager.RegisterSystem(new PureInitSystemAdapter(worldContext, (world) => { // worldContext's variable is available here Console.WriteLine("PureInitSystem: Hello, World!"); })); systemManager.RegisterSystem(new PureReactiveSystemAdapter(worldContext, entity => entity.HasComponent <THelloWorldComponent>(), (world, entities, dt) => { // worldContext's variable is available here Console.WriteLine("PureReactiveSystem: Hello, World!"); })); systemManager.Init(); bool isRunning = true; while (isRunning) { if (Console.ReadLine() != string.Empty) { EntityId entityId = worldContext.CreateEntity(); IEntity entity = worldContext.GetEntityById(entityId); entity.AddComponent <THelloWorldComponent>(); isRunning = false; } systemManager.Update(0.0f); } Console.ReadKey(); }