Esempio n. 1
0
        public void Factory()
        {
            var init = _enginesRoot.GenerateEntityFactory().BuildEntity <TestEntityDescriptor>(new EGID(0, group));

            init.Init(new UnmanagedComponent()
            {
                test = 2
            });
            _simpleEntitiesSubmissionScheduler.SubmitEntities();

            Assert.DoesNotThrow(() => _testEngine.Test());

            _enginesRoot.Dispose();
        }
Esempio n. 2
0
        public SimpleContext()
        {
            //An EnginesRoot holds all the engines created. it needs a EntitySubmissionScheduler to know when to
            //add the EntityViews generated inside the EntityDB.
            var simpleSubmissionEntityViewScheduler = new SimpleEntitiesSubmissionScheduler();

            _enginesRoot = new EnginesRoot(simpleSubmissionEntityViewScheduler);

            //an EnginesRoot must never be injected inside other classes only IEntityFactory and IEntityFunctions
            //implementation can
            var entityFactory   = _enginesRoot.GenerateEntityFactory();
            var entityFunctions = _enginesRoot.GenerateEntityFunctions();

            //Add the Engine to manage the SimpleEntities
            var behaviourForEntityClassEngine = new BehaviourForEntityClassEngine(entityFunctions);

            _enginesRoot.AddEngine(behaviourForEntityClassEngine);

            //build Entity with ID 1 in group 0
            entityFactory.BuildEntity <SimpleEntityDescriptor>(new EGID(0, ExclusiveGroups.group0));

            //as we are using a basic scheduler, we need to schedule the entity submission ourselves
            simpleSubmissionEntityViewScheduler.SubmitEntities();

            //as we don't have any ticking system for this basic example, we tick explicitly
            behaviourForEntityClassEngine.Update();

            Console.Log("Done - click any button to quit");

            System.Console.ReadKey();

            Environment.Exit(0);
        }
        public void TestSerializingWithEntityViewStructsAndFactories()
        {
            var init = _entityFactory.BuildEntity <SerializableEntityDescriptorWithViews>(
                0, NamedGroup1.Group, new[] { new Implementor(1) });

            init.Init(new EntityStructSerialized()
            {
                value = 5
            });
            init.Init(new EntityStructSerialized2()
            {
                value = 4
            });
            init.Init(new EntityStructPartiallySerialized()
            {
                value1 = 3
            });

            _simpleSubmissionEntityViewScheduler.SubmitEntities();

            FasterList <byte> bytes      = new FasterList <byte>();
            var generateEntitySerializer = _enginesRoot.GenerateEntitySerializer();
            var simpleSerializationData  = new SimpleSerializationData(bytes);

            generateEntitySerializer.SerializeEntity(new EGID(0, NamedGroup1.Group), simpleSerializationData
                                                     , (int)SerializationType.Storage);

            SimpleEntitiesSubmissionScheduler simpleSubmissionEntityViewScheduler = new SimpleEntitiesSubmissionScheduler();
            var newEnginesRoot = new EnginesRoot(simpleSubmissionEntityViewScheduler);

            _neverDoThisIsJustForTheTest = new TestEngine();

            newEnginesRoot.AddEngine(_neverDoThisIsJustForTheTest);

            simpleSerializationData.Reset();
            generateEntitySerializer = newEnginesRoot.GenerateEntitySerializer();
            DeserializationFactory factory = new DeserializationFactory();

            generateEntitySerializer.RegisterSerializationFactory <SerializableEntityDescriptorWithViews>(factory);

            generateEntitySerializer.DeserializeNewEntity(new EGID(0, NamedGroup1.Group), simpleSerializationData
                                                          , (int)SerializationType.Storage);

            simpleSubmissionEntityViewScheduler.SubmitEntities();

            Assert.That(
                _neverDoThisIsJustForTheTest.entitiesDB.QueryEntity <EntityStructSerialized>(0, NamedGroup1.Group).value
                , Is.EqualTo(5));
            Assert.That(
                _neverDoThisIsJustForTheTest.entitiesDB.QueryEntity <EntityStructSerialized2>(0, NamedGroup1.Group).value
                , Is.EqualTo(4));
            Assert.That(_neverDoThisIsJustForTheTest
                        .entitiesDB.QueryEntity <EntityStructPartiallySerialized>(0, NamedGroup1.Group).value1
                        , Is.EqualTo(3));

            newEnginesRoot.Dispose();
        }
Esempio n. 4
0
        public void Init()
        {
            _simpleSubmissionEntityViewScheduler = new SimpleEntitiesSubmissionScheduler();
            _enginesRoot = new EnginesRoot(_simpleSubmissionEntityViewScheduler);
            _testEngine  = new TestEngine();

            _enginesRoot.AddEngine(_testEngine);

            _entityFactory = _enginesRoot.GenerateEntityFactory();
            _enginesRoot.GenerateEntityFunctions();

            var id = _idStart;

            for (uint i = 0; i < _groupCount; i++)
            {
                for (int j = 0; j < _entityCountPerGroup; j++)
                {
                    _entityFactory.BuildEntity <EntityDescriptorWithComponentAndViewComponent>(
                        new EGID(id++, _group + i), new object[] { new TestFloatValue(1f), new TestIntValue(1) });

                    _entityFactory.BuildEntity <EntityDescriptorViewComponentWithString>(
                        new EGID(id++, _group + i), new object[] { new TestStringValue("test") });
                }
            }

            _simpleSubmissionEntityViewScheduler.SubmitEntities();

            foreach (var((buffer, count), _) in _testEngine.entitiesDB.QueryEntities <TestEntityViewComponent>())
            {
                for (int i = 0; i < count; i++)
                {
                    buffer[i].TestFloatValue.Value += buffer[i].ID.entityID;
                    buffer[i].TestIntValue.Value   += (int)buffer[i].ID.entityID;
                }
            }

            foreach (var((buffer, count), _) in _testEngine
                     .entitiesDB.QueryEntities <TestEntityComponent>())
            {
                for (int i = 0; i < count; i++)
                {
                    buffer[i].floatValue = 1 + buffer[i].ID.entityID;
                    buffer[i].intValue   = 1 + (int)buffer[i].ID.entityID;
                }
            }

            foreach (var((buffer, count), _) in _testEngine
                     .entitiesDB.QueryEntities <TestEntityViewComponentString>())
            {
                for (int i = 0; i < count; i++)
                {
                    buffer[i].TestStringValue.Value = (1 + buffer[i].ID.entityID).ToString();
                }
            }
        }
        public void Setup()
        {
            _defaultWorld                      = new DefaultWorld(EntityCount);
            _defaultEntitySet                  = _defaultWorld.GetEntities().With <DefaultComponent>().AsSet();
            _defaultRunner                     = new DefaultParallelRunner(Environment.ProcessorCount);
            _defaultSystem                     = new DefaultEcsSystem(_defaultWorld);
            _defaultMultiSystem                = new DefaultEcsSystem(_defaultWorld, _defaultRunner);
            _defaultEntityComponentSystem      = new DefaultEcsEntityComponentSystem(_defaultWorld);
            _defaultMultiEntityComponentSystem = new DefaultEcsEntityComponentSystem(_defaultWorld, _defaultRunner);
            _defaultComponentSystem            = new DefaultEcsComponentSystem(_defaultWorld);
            _defaultComponentMultiSystem       = new DefaultEcsComponentSystem(_defaultWorld, _defaultRunner);
            _defaultGeneratorSystem            = new DefaultEcsGeneratorSystem(_defaultWorld);
            _defaultGeneratorMultiSystem       = new DefaultEcsGeneratorSystem(_defaultWorld, _defaultRunner);

            _entitasWorld       = new Context <EntitasEntity>(1, () => new EntitasEntity());
            _entitasSystem      = new EntitasSystem(_entitasWorld);
            _entitasMultiSystem = new EntitasSystem(_entitasWorld, Environment.ProcessorCount);

            _monoWorld = new WorldBuilder().AddSystem(new MonoSystem()).Build();
            _time      = new GameTime();

            _leoWorld   = new LeoWorld();
            _leoSystem  = new LeoSystem();
            _leoSystems = new LeoSystems(_leoWorld).Add(_leoSystem);
            _leoSystems.ProcessInjects().Init();

            SimpleEntitiesSubmissionScheduler sveltoScheduler = new SimpleEntitiesSubmissionScheduler();

            _sveltoWorld  = new EnginesRoot(sveltoScheduler);
            _sveltoSystem = new SveltoSystem();
            _sveltoWorld.AddEngine(_sveltoSystem);
            IEntityFactory sveltoFactory = _sveltoWorld.GenerateEntityFactory();

            for (int i = 0; i < EntityCount; ++i)
            {
                DefaultEntity defaultEntity = _defaultWorld.CreateEntity();
                defaultEntity.Set <DefaultComponent>();

                EntitasEntity entitasEntity = _entitasWorld.CreateEntity();
                entitasEntity.AddComponent(0, new EntitasComponent());

                MonoEntity monoEntity = _monoWorld.CreateEntity();
                monoEntity.Attach(new MonoComponent());

                LeoEntity leoEntity = _leoWorld.NewEntity();
                leoEntity.Get <LeoComponent>();

                sveltoFactory.BuildEntity <SveltoEntity>((uint)i, _sveltoGroup);
            }

            sveltoScheduler.SubmitEntities();
        }
Esempio n. 6
0
        IEnumerator MainThreadTick(FasterList <IJobifiedEngine> engines)
        {
            var       orderGroup = new SimulationExecutionOrderGroup(engines);
            JobHandle jobs       = default;

            while (true)
            {
                jobs.Complete();
                _submissionScheduler.SubmitEntities();
                jobs = orderGroup.Execute(jobs);
                yield return(Yield.It);
            }
        }
        IEnumerator MainThreadTick(FasterList <IJobifiedEngine> engines)
        {
            EnginesExecutionOrderGroup orderGroup = new EnginesExecutionOrderGroup(new FasterReadOnlyList <IJobifiedEngine>(engines));

            JobHandle jobs = default;

            while (true)
            {
                jobs.Complete();

                //Sync point on the mainthread:
                //Svelto entities are added/removed/swapped
                //callback functions are called (which may create UECS entities)
                _simpleSubmitScheduler.SubmitEntities();

                //schedule all jobs and let them run until next frame;
                jobs = orderGroup.Execute(jobs);

                yield return(Yield.It);
            }
        }
Esempio n. 8
0
        public void SetUp()
        {
            _scheduler   = new SimpleEntitiesSubmissionScheduler();
            _enginesRoot = new EnginesRoot(_scheduler);
            _factory     = _enginesRoot.GenerateEntityFactory();
            _functions   = _enginesRoot.GenerateEntityFunctions();
            _entitiesDB  = ((IUnitTestingInterface)_enginesRoot).entitiesForTesting;

            // Create entities.
            _factory.BuildEntity <EntityDescriptorWithComponents>(EgidA0);
            _factory.BuildEntity <EntityDescriptorWithComponents>(EgidA1);
            _factory.BuildEntity <EntityDescriptorWithComponents>(EgidA2);
            _factory.BuildEntity <EntityDescriptorWithComponents>(EgidA3);
            _factory.BuildEntity <EntityDescriptorWithComponents>(EgidA4);

            _factory.BuildEntity <EntityDescriptorWithComponents>(EgidB0);
            _factory.BuildEntity <EntityDescriptorWithComponents>(EgidB1);
            _factory.BuildEntity <EntityDescriptorWithComponents>(EgidB2);
            _factory.BuildEntity <EntityDescriptorWithComponents>(EgidB3);
            _factory.BuildEntity <EntityDescriptorWithComponents>(EgidB4);

            _scheduler.SubmitEntities();
        }
        public void TestSerializingToByteArrayNewEnginesRoot()
        {
            var init = _entityFactory.BuildEntity <SerializableEntityDescriptor>(0, NamedGroup1.Group);

            init.Init(new EntityStructSerialized()
            {
                value = 5
            });
            init.Init(new EntityStructSerialized2()
            {
                value = 4
            });
            init.Init(new EntityStructPartiallySerialized()
            {
                value1 = 3
            });
            init = _entityFactory.BuildEntity <SerializableEntityDescriptor>(1, NamedGroup1.Group);
            init.Init(new EntityStructSerialized()
            {
                value = 4
            });
            init.Init(new EntityStructSerialized2()
            {
                value = 3
            });
            init.Init(new EntityStructPartiallySerialized()
            {
                value1 = 2
            });

            _simpleSubmissionEntityViewScheduler.SubmitEntities();

            var generateEntitySerializer = _enginesRoot.GenerateEntitySerializer();
            var simpleSerializationData  = new SimpleSerializationData(new FasterList <byte>());

            generateEntitySerializer.SerializeEntity(new EGID(0, NamedGroup1.Group), simpleSerializationData
                                                     , (int)SerializationType.Storage);
            generateEntitySerializer.SerializeEntity(new EGID(1, NamedGroup1.Group), simpleSerializationData
                                                     , (int)SerializationType.Storage);

            var serializerSubmissionScheduler = new SimpleEntitiesSubmissionScheduler();

            var newEnginesRoot = new EnginesRoot(serializerSubmissionScheduler);

            _neverDoThisIsJustForTheTest = new TestEngine();
            newEnginesRoot.AddEngine(_neverDoThisIsJustForTheTest);

            simpleSerializationData.Reset();
            generateEntitySerializer = newEnginesRoot.GenerateEntitySerializer();

            generateEntitySerializer.DeserializeNewEntity(new EGID(0, NamedGroup1.Group), simpleSerializationData
                                                          , (int)SerializationType.Storage);
            generateEntitySerializer.DeserializeNewEntity(new EGID(1, NamedGroup1.Group), simpleSerializationData
                                                          , (int)SerializationType.Storage);
            serializerSubmissionScheduler.SubmitEntities();

            Assert.That(
                _neverDoThisIsJustForTheTest.entitiesDB.QueryEntity <EntityStructSerialized>(0, NamedGroup1.Group).value
                , Is.EqualTo(5));
            Assert.That(
                _neverDoThisIsJustForTheTest.entitiesDB.QueryEntity <EntityStructSerialized2>(0, NamedGroup1.Group).value
                , Is.EqualTo(4));
            Assert.That(
                _neverDoThisIsJustForTheTest
                .entitiesDB.QueryEntity <EntityStructPartiallySerialized>(0, NamedGroup1.Group).value1
                , Is.EqualTo(3));

            Assert.That(
                _neverDoThisIsJustForTheTest.entitiesDB.QueryEntity <EntityStructSerialized>(1, NamedGroup1.Group).value
                , Is.EqualTo(4));
            Assert.That(
                _neverDoThisIsJustForTheTest.entitiesDB.QueryEntity <EntityStructSerialized2>(1, NamedGroup1.Group).value
                , Is.EqualTo(3));
            Assert.That(
                _neverDoThisIsJustForTheTest
                .entitiesDB.QueryEntity <EntityStructPartiallySerialized>(1, NamedGroup1.Group).value1
                , Is.EqualTo(2));

            newEnginesRoot.Dispose();
        }
Esempio n. 10
0
        public void TestMegaEntitySwap()
        {
            for (int i = 0; i < 29; i++)
            {
                EGID egid = new EGID((uint)i, group1);
                _entityFactory.BuildEntity <TestDescriptorEntityView>(egid, new[] { new TestIt(2) });
            }

            Assert.IsTrue(true);

            _simpleSubmissionEntityViewScheduler.SubmitEntities();

            SwapMinNeededForException(_entityFunctions);

            _simpleSubmissionEntityViewScheduler.SubmitEntities();

            bool allFound       = true;
            bool mustNotBeFound = false;

            for (uint i = 0; i < 29; i++)
            {
                allFound &=
                    ((IUnitTestingInterface)_enginesRoot).entitiesForTesting.Exists <TestEntityViewComponent>(
                        new EGID(i, group2));
            }

            for (int i = 0; i < 29; i++)
            {
                mustNotBeFound |=
                    ((IUnitTestingInterface)_enginesRoot).entitiesForTesting.Exists <TestEntityViewComponent>(
                        new EGID((uint)i, group1));
            }

            Assert.IsTrue(allFound);
            Assert.IsTrue(mustNotBeFound == false);
        }