Beispiel #1
0
        /// <summary>
        ///    Drops database and fills with predefined data. Temporary solution.
        /// </summary>
        private static void ReinitializeDatabase(WorldContextFactory worldContextFactory)
        {
            using (var context = worldContextFactory.CreateDbContext())
            {
                Console.WriteLine("Dropping database if exists");
                context.Database.EnsureDeleted();

                Console.WriteLine("Creating fresh database with dev data");
                context.Database.EnsureCreated();

                var testSpaceObject = new SpaceObject
                {
                    Id         = Guid.NewGuid(),
                    Components = new List <SpaceObjectComponent>
                    {
                        new Transform
                        {
                            Id       = Guid.NewGuid(),
                            Position = new Vector2D(1e9, 2e9),
                            Rotation = Math.PI / 3
                        }
                    }
                };
                context.SpaceObjects.Add(testSpaceObject);
                context.SaveChanges();
            }
        }
        protected TickableComponentActor(WorldContextFactory worldContextFactory, SpaceObjectComponent component)
            : base(worldContextFactory, component)
        {
            Receive <Tick>(tick => OnTick(tick));

            Context
            .System
            .Scheduler
            .ScheduleTellRepeatedly(TimeSpan.Zero, TimeSpan.FromMilliseconds(20), Self, new Tick(), Self);
        }
Beispiel #3
0
        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();
        }
Beispiel #4
0
        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();
        }
        protected SpaceObjectComponentActor(WorldContextFactory worldContextFactory, SpaceObjectComponent component) :
            base(component)
        {
            WorldContextFactory = worldContextFactory;

            using (var worldContext = worldContextFactory.CreateDbContext())
            {
                // Unlike SpaceObjectActor, it is assumed here that component is already persisted in database.
                // Adding components to already existing SpaceObject is not needed now.
                Boolean idFound = worldContext
                                  .Components
                                  .Any(c => c.Id == component.Id);

                if (!idFound)
                {
                    throw new ArgumentException("Component with given Id not found.");
                }
            }
        }
Beispiel #6
0
 public static Props Props(WorldContextFactory worldContextFactory, Transform component)
 {
     return(Akka.Actor.Props.Create(() => new TransformActor(worldContextFactory, component)));
 }
Beispiel #7
0
 public TransformActor(WorldContextFactory worldContextFactory, Transform component)
     : base(worldContextFactory, component)
 {
 }
 protected CelestialBodyActor(WorldContextFactory worldContextFactory, CelestialBody component)
     : base(worldContextFactory, component)
 {
 }