Пример #1
0
        public void TestUniverseCanFindAllEntitiesIncludingAComponent()
        {
            var unexpectedEntity = new Entity();

            Universe.AddEntity(unexpectedEntity);

            Entity.AddComponent(new NamedEntity("Name"));

            var foundEntities = Universe.FindAllEntitiesWithComponent(ComponentTypes.Name);

            Assert.AreEqual(1, foundEntities.Count);
            Assert.AreSame(Entity, foundEntities[0]);
        }
Пример #2
0
        public static Entity Spawn(Vector3I location, Tile tile, Universe facade)
        {
            var entity = new Entity(facade.AllocateNewEntityId(), false, KindCode, true);

            var blob = BlobAllocator.Blob(true);

            blob.SetString("tile", tile.Configuration.Code);
            blob.SetLong("variant", tile.Variant());
            blob.FetchBlob("location").SetVector3I(location);
            blob.FetchBlob("velocity").SetVector3D(Vector3D.Zero);

            entity.Construct(blob, facade);

            facade.AddEntity(entity);

            return(entity);
        }
Пример #3
0
        private static void Main()
        {
            var rand = new Random();

            for (var i = 0; i < 100000; i++)
            {
                Universe.AddEntity(new TreeEntity($"{i+1}", (ulong)rand.Next(500), (byte)rand.Next(5), rand.NextDouble() * 3 + 1));
            }

            Universe.AddSystem(new AgingSystem(Universe));
            Universe.AddSystem(new BranchingSystem(Universe));
            //Universe.AddSystem(new PrintSystem(Universe));
            Universe.AddSystem(new LumberjackSystem(Universe));

            //Console.WriteLine("System primed and ready.");
            //Console.ReadLine();

            //var rounds = 0;
            var count = 1;
            var tdata = new TriggerData(rand);

            //var sw = new Stopwatch();
            while (count > 0)
            {
                //rounds++;
                //sw.Restart();
                Universe.Trigger(TriggerEnum.PreTick, tdata);
                Universe.Trigger(TriggerEnum.Tick, tdata);
                Universe.Trigger(TriggerEnum.PostTick, tdata);
                //sw.Stop();
                count = Universe.GetEntities().Count();
                //Console.WriteLine($"{count,6:N0} trees remain, updated took {sw.ElapsedMilliseconds,6:N0}ms.\t{new string('|', (int) Math.Log(sw.ElapsedMilliseconds, 2))}");
            }
            //Console.WriteLine($"Finished in {rounds:N0} rounds");
            //Console.ReadKey();
        }
Пример #4
0
 public void SetUp()
 {
     Universe = new Universe();
     Entity   = new Entity();
     Universe.AddEntity(Entity);
 }
Пример #5
0
 public Entity(Universe universe)
     : base(universe.Messenger)
 {
     Universe = universe;
     universe.AddEntity(this);
 }