コード例 #1
0
        public void Update()
        {
            if (this.world == null)
            {
                // Initialize world with 0.033 time step
                WorldUtilities.CreateWorld <TState>(ref this.world, 0.033f);
                {
                    #if FPS_MODULE_SUPPORT
                    this.world.AddModule <FPSModule>();
                    #endif
                    this.world.AddModule <StatesHistoryModule>();
                    this.world.AddModule <NetworkModule>();

                    // Add your custom modules here

                    // Create new state
                    this.world.SetState <TState>(WorldUtilities.CreateState <TState>());
                    ComponentsInitializer.DoInit();
                    this.Initialize(this.world);

                    // Add your custom systems here
                }
                // Save initialization state
                this.world.SaveResetState <TState>();
            }

            if (this.world != null)
            {
                var dt = Time.deltaTime;
                this.world.PreUpdate(dt);
                this.world.Update(dt);
            }
        }
コード例 #2
0
        public static void Do(
            System.Action <World> setupWorld   = null,
            System.Action <World> initSystems  = null,
            System.Action <World> beforeUpdate = null,
            System.Action <World> afterUpdate  = null,
            int from = 0,
            int to   = 2)
        {
            WorldUtilities.ResetTypeIds();

            ME.ECS.Pools.current = new ME.ECS.PoolImplementation(isNull: false);
            World world = null;

            WorldUtilities.CreateWorld <EmptyState>(ref world, 0.033f);
            {
                world.AddModule <EmptyStatesHistoryModule>();
                world.AddModule <EmptyNetworkModule>();
                world.SetState <EmptyState>(WorldUtilities.CreateState <EmptyState>());
                world.SetSeed(1u);
                {
                    ref var str = ref world.GetStructComponents();
                    CoreComponentsInitializer.InitTypeId();
                    CoreComponentsInitializer.Init(ref str);
                    setupWorld?.Invoke(world);
                }

                initSystems?.Invoke(world);
            }
コード例 #3
0
        public static World PrepareWorld()
        {
            World world = null;

            WorldUtilities.CreateWorld <TestState>(ref world, 0.033f);
            {
                world.SetState <TestState>(WorldUtilities.CreateState <TestState>());
                world.SetSeed(1u);
                {
                    WorldUtilities.InitComponentTypeId <ME.ECS.Views.ViewComponent>(false);
                    WorldUtilities.InitComponentTypeId <ME.ECS.Name.Name>(false);
                    WorldUtilities.InitComponentTypeId <ME.ECS.Transform.Childs>(false);
                    WorldUtilities.InitComponentTypeId <ME.ECS.Collections.IntrusiveListNode>(false);
                    WorldUtilities.InitComponentTypeId <ME.ECS.Collections.IntrusiveHashSetBucket>(false);
                    world.GetStructComponents().Validate <ME.ECS.Views.ViewComponent>();
                    world.GetStructComponents().Validate <ME.ECS.Name.Name>();
                    world.GetStructComponents().Validate <ME.ECS.Transform.Childs>();
                    world.GetStructComponents().Validate <ME.ECS.Collections.IntrusiveListNode>();
                    world.GetStructComponents().Validate <ME.ECS.Collections.IntrusiveHashSetBucket>();
                    ComponentsInitializerWorld.Setup((e) => {
                        e.ValidateData <ME.ECS.Views.ViewComponent>();
                        e.ValidateData <ME.ECS.Name.Name>();
                        e.ValidateData <ME.ECS.Transform.Childs>();
                        e.ValidateData <ME.ECS.Collections.IntrusiveListNode>();
                        e.ValidateData <ME.ECS.Collections.IntrusiveHashSetBucket>();
                    });
                    //world.SetEntitiesCapacity(1000);
                }
            }

            WorldUtilities.SetWorld(world);

            return(world);
        }
コード例 #4
0
 private void Initialize()
 {
     WorldUtilities.CreateWorld <TestState>(ref this.world, 0.033f);
     this.world.SetState <TestState>(WorldUtilities.CreateState <TestState>());
     this.world.AddModule <TestStatesHistoryModule>();
     this.world.SetSeed(1u);
     this.world.SaveResetState <TestState>();
 }
コード例 #5
0
        public static World <State> CreateWorld(float tickTime = 0.05f)
        {
            World <State> world = null;

            WorldUtilities.CreateWorld(ref world, tickTime);
            world.SetState(WorldUtilities.CreateState <State>());

            return(world);
        }
コード例 #6
0
        public void WorldSerialization()
        {
            World CreateWorld()
            {
                World world = null;

                WorldUtilities.CreateWorld <TestState>(ref world, 0.033f);
                {
                    world.AddModule <TestStatesHistoryModule>();
                    world.AddModule <FakeNetworkModule>();

                    world.SetState <TestState>(WorldUtilities.CreateState <TestState>());

                    //components
                    {
                        ref var sc = ref world.GetStructComponents();
                        ComponentsInitializerWorld.Setup(e => e.ValidateData <TestStructComponent>());
                        CoreComponentsInitializer.Init(ref sc);
                        sc.Validate <TestStructComponent>();
                    }
                    //settings
                    {
                        world.SetSettings(new WorldSettings {
                            useJobsForSystems = false,
                            useJobsForViews   = false,
                            turnOffViews      = false,
                            viewsSettings     = new WorldViewsSettings()
                        });
                        world.SetDebugSettings(WorldDebugSettings.Default);
                    }

                    var group = new SystemGroup(world, "GroupName");
                    group.AddSystem <TestSystem>();
                }

                var ent = new Entity("Test Entity");

                ent.SetPosition(UnityEngine.Vector3.zero);
                ent.SetData(new TestStructComponent());

                world.SaveResetState <TestState>();

                return(world);
            }
コード例 #7
0
        private void CreateWorld()
        {
            // Initialize world with 0.033 time step
            WorldUtilities.CreateWorld <TState>(ref _world, 0.033f);
            {
#if FPS_MODULE_SUPPORT
                this.world.AddModule <FPSModule>();
#endif
                _world.AddModule <StatesHistoryModule>();
                _world.AddModule <NetworkModule>();

                // Add your custom modules here

                // Create new state
                _world.SetState <TState>(WorldUtilities.CreateState <TState>());
                ComponentsInitializer.DoInit();
                Initialize(_world);
                _world.SetSeed((uint)1);
                // Add your custom systems here
            }
            // Save initialization state
            _world.SaveResetState <TState>();
        }
コード例 #8
0
        public void Update()
        {
            if (this.world == null)
            {
                // Loading level

                WorldUtilities.CreateWorld(ref this.world, 0.133f, this.worldId);
                this.world.AddModule <FPSModule>();
                this.world.AddModule <StatesHistoryModule>();
                this.world.AddModule <NetworkModule>();

                if (this.worldConnectionId > 0)
                {
                    var network = this.world.GetModule <NetworkModule>();
                    network.SetWorldConnection(this.worldConnectionId);
                    network.SetDropPercent(this.dropPercent);
                }

                this.world.SetState(WorldUtilities.CreateState <State>());
                this.world.GetState().worldPosition = this.transform.position;

                this.RegisterViewSources();

                this.pointsFeatureInitParameters.pointViewSourceId = this.pointViewSourceId;
                this.world.AddFeature <PointsFeature, PointsFeatureInitParameters>(ref this.pointsFeatureInitParameters);
                this.world.AddFeature <UnitsFeature>();
                this.world.AddFeature <InputFeature, ConstructParameters <Entity, Entity> >(new ConstructParameters <Entity, Entity>(this.pointsFeatureInitParameters.p1, this.pointsFeatureInitParameters.p2));
                this.world.SaveResetState();
            }

            if (this.world != null)
            {
                var dt = Time.deltaTime * this.deltaTimeMultiplier;
                this.world.Update(dt);
            }
        }
コード例 #9
0
 public Entry(World world)
 {
     this.isEmpty = true;
     this.state   = WorldUtilities.CreateState <TState>();
     this.state.Initialize(world, freeze: true, restore: false);
 }
コード例 #10
0
ファイル: DefaultTests.cs プロジェクト: cleancoindev/ecs
        public void CopyState()
        {
            // Initialize
            var world = TestsHelper.CreateWorld();

            // Adding items
            world.AddSystem <PointsSystem>();
            var entity = world.AddEntity(new Point()
            {
                position = Vector3.one, unitsCount = 99f, increaseRate = 1f
            });
            var entityToRemove = world.AddEntity(new Point()
            {
                position = Vector3.one, unitsCount = 1f, increaseRate = 1f
            });

            world.AddComponent <Point, PointIncreaseUnits>(entity);
            world.AddComponent <Point, PointIncreaseUnits>(entityToRemove);

            // Save state
            var state = world.GetState();

            Assert.IsTrue(state.points.Count == 2);
            Assert.IsTrue(state.units.Count == 0);
            Assert.IsTrue(state.pointComponents.Count == 2);

            world.RemoveEntity <Point>(entityToRemove);
            Assert.IsTrue(state.points.Count == 1);
            Assert.IsTrue(state.pointComponents.Count == 1);

            var savedState = (IState <State>)WorldUtilities.CreateState <State>();

            savedState.Initialize(world, freeze: true, restore: false);

            Assert.IsTrue(state.points.Count == 1);
            Assert.IsTrue(state.pointComponents.Count == 1);
            {
                var dic = TestsHelper.GetValue <Dictionary <int, IComponentsBase> >(world, "componentsCache");
                Assert.IsTrue(dic.Count == 2);
            }

            savedState.CopyFrom(state);

            world.Update(1f);
            WorldUtilities.ReleaseState(ref state);

            // Restore state
            world.SetState((State)savedState);
            //((IWorldBase)world).Simulate(savedState.tick);

            Assert.IsTrue(((State)savedState).points.Count == 1);
            Assert.IsTrue(((State)savedState).pointComponents.Count == 1);

            {
                var dic = TestsHelper.GetValue <Dictionary <int, IList> >(world, "entitiesCache");
                Assert.IsTrue(dic.Count == 1);
            }

            {
                var dic = TestsHelper.GetValue <Dictionary <int, IList> >(world, "filtersCache");
                Assert.IsTrue(dic.Count == 2);
            }

            {
                var dic = TestsHelper.GetValue <Dictionary <int, IComponentsBase> >(world, "componentsCache");
                Assert.IsTrue(dic.Count == 2);
            }

            TestsHelper.ReleaseWorld(ref world);
        }