コード例 #1
0
        /// <summary>
        /// Add system manually
        /// Pool will not be used, OnConstruct() call
        /// </summary>
        /// <param name="instance"></param>
        public bool AddSystem(ISystemBase instance)
        {
            if (this.world == null)
            {
                SystemGroupRegistryException.Throw();
            }

            WorldUtilities.SetWorld(this.world);

            instance.world = this.world;
            if (instance is ISystemValidation instanceValidate)
            {
                if (instanceValidate.CouldBeAdded() == false)
                {
                    instance.world = null;
                    return(false);
                }
            }

            this.runtimeSystem.Add(instance);
            instance.OnConstruct();

            if (instance is ISystemFilter systemFilter)
            {
                systemFilter.filter = systemFilter.CreateFilter();
            }

            this.world.UpdateGroup(this);

            return(true);
        }
コード例 #2
0
        static partial void Init(ref ME.ECS.StructComponentsContainer structComponentsContainer)
        {
            WorldUtilities.ResetTypeIds();

            CoreComponentsInitializer.InitTypeId();


            WorldUtilities.InitComponentTypeId <Example.Features.Logic.DestroyByTime.Components.DestroyByTime>(false, false, false, false, false);
            WorldUtilities.InitComponentTypeId <Example.Features.Logic.ForceAtPoint.Components.AddForce>(false, false, false, false, false);
            WorldUtilities.InitComponentTypeId <Example.Features.Logic.ForceAtPoint.Components.Force>(false, false, false, false, false);
            WorldUtilities.InitComponentTypeId <Example.Features.Map.Components.IsMap>(true, false, false, false, false);
            WorldUtilities.InitComponentTypeId <Example.Features.PlayerFire.Components.BulletFly>(false, false, false, false, false);
            WorldUtilities.InitComponentTypeId <Example.Features.PlayerFire.Components.FireAction>(true, false, false, false, false);
            WorldUtilities.InitComponentTypeId <Example.Features.PlayerFire.Components.IsBullet>(false, false, false, false, false);
            WorldUtilities.InitComponentTypeId <Example.Features.PlayerMovement.Components.LastMovementDirection>(false, false, false, false, false);
            WorldUtilities.InitComponentTypeId <Example.Features.PlayerMovement.Components.MoveAction>(false, false, false, false, false);
            WorldUtilities.InitComponentTypeId <Example.Features.Players.Components.IsPlayer>(true, false, false, false, false);

            ComponentsInitializerWorld.Setup(ComponentsInitializerWorldGen.Init);
            CoreComponentsInitializer.Init(ref structComponentsContainer);


            structComponentsContainer.Validate <Example.Features.Logic.DestroyByTime.Components.DestroyByTime>(false);
            structComponentsContainer.Validate <Example.Features.Logic.ForceAtPoint.Components.AddForce>(false);
            structComponentsContainer.Validate <Example.Features.Logic.ForceAtPoint.Components.Force>(false);
            structComponentsContainer.Validate <Example.Features.Map.Components.IsMap>(true);
            structComponentsContainer.Validate <Example.Features.PlayerFire.Components.BulletFly>(false);
            structComponentsContainer.Validate <Example.Features.PlayerFire.Components.FireAction>(true);
            structComponentsContainer.Validate <Example.Features.PlayerFire.Components.IsBullet>(false);
            structComponentsContainer.Validate <Example.Features.PlayerMovement.Components.LastMovementDirection>(false);
            structComponentsContainer.Validate <Example.Features.PlayerMovement.Components.MoveAction>(false);
            structComponentsContainer.Validate <Example.Features.Players.Components.IsPlayer>(true);
        }
コード例 #3
0
        public static void ReleaseWorld(ref World <State> world)
        {
            var state = world.GetState();

            WorldUtilities.ReleaseWorld(ref world);
            TestsHelper.TestStateIsClean(state);
        }
コード例 #4
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);
            }
        }
コード例 #5
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);
            }
コード例 #6
0
 public static void InitTypeId()
 {
     WorldUtilities.InitComponentTypeId <ME.ECS.Features.PhysicsDeterministic.Components.PhysicsRigidbody>(true);
     WorldUtilities.InitComponentTypeId <ME.ECS.Features.PhysicsDeterministic.Components.PhysicsOnCollisionEnter>();
     WorldUtilities.InitComponentTypeId <ME.ECS.Features.PhysicsDeterministic.Components.PhysicsOnCollisionExit>();
     WorldUtilities.InitComponentTypeId <ME.ECS.Features.PhysicsDeterministic.Components.PhysicsOnCollisionStay>();
 }
コード例 #7
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);
        }
コード例 #8
0
        public static void InitTypeId()
        {
            WorldUtilities.InitComponentTypeId <ME.ECS.Transform.Nodes>(isVersioned: true, isSimple: true);
            WorldUtilities.InitComponentTypeId <ME.ECS.Transform.Container>(isVersioned: true, isSimple: true);

            Transform2DComponentsInitializer.InitTypeId();
            Transform3DComponentsInitializer.InitTypeId();
        }
コード例 #9
0
        public static void InitTypeId()
        {
            WorldUtilities.InitComponentTypeId <ME.ECS.Transform.Childs>();
            WorldUtilities.InitComponentTypeId <ME.ECS.Transform.Container>();

            Transform2DComponentsInitializer.InitTypeId();
            Transform3DComponentsInitializer.InitTypeId();
        }
コード例 #10
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>();
 }
コード例 #11
0
ファイル: GameState.cs プロジェクト: PushoN/ecs
    void IPoolableRecycle.OnRecycle()
    {
        WorldUtilities.Release(ref this.points);
        WorldUtilities.Release(ref this.units);

        WorldUtilities.Release(ref this.pointComponents);
        WorldUtilities.Release(ref this.unitComponents);
    }
コード例 #12
0
        public static int GetAllComponentTypeId <TComponent>()
        {
            if (AllComponentTypes <TComponent> .typeId < 0)
            {
                WorldUtilities.CacheAllComponentTypeId <TComponent>();
            }

            return(AllComponentTypes <TComponent> .typeId);
        }
コード例 #13
0
        public static void CompleteWorld(World world)
        {
            world.SaveResetState <TestState>();

            world.SetFromToTicks(0, 1);
            world.Update(1f);

            WorldUtilities.ReleaseWorld <TestState>(ref world);
        }
コード例 #14
0
        public static World <State> CreateWorld()
        {
            World <State> world = null;

            WorldUtilities.CreateWorld(ref world, 0.05f);
            world.SetState(world.CreateState());

            return(world);
        }
コード例 #15
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);
        }
コード例 #16
0
        public static int GetOneShotComponentTypeId <TComponent>()
        {
            if (OneShotComponentTypes <TComponent> .typeId < 0)
            {
                WorldUtilities.CacheOneShotComponentTypeId <TComponent>();
            }

            return(OneShotComponentTypes <TComponent> .typeId);
        }
コード例 #17
0
        public static void Init(ref ME.ECS.StructComponentsContainer structComponentsContainer)
        {
            WorldUtilities.InitComponentTypeId <ME.ECS.Views.ViewComponent>(false);
            WorldUtilities.InitComponentTypeId <ME.ECS.Views.IViewComponent>(false);

            TransformComponentsInitializer.Init(ref structComponentsContainer);
            NameComponentsInitializer.Init(ref structComponentsContainer);
            CameraComponentsInitializer.Init(ref structComponentsContainer);
            PhysicsComponentsInitializer.Init(ref structComponentsContainer);
        }
コード例 #18
0
        public static void InitTypeId()
        {
            WorldUtilities.InitComponentTypeId <ME.ECS.Views.ViewComponent>(false);
            WorldUtilities.InitComponentTypeId <ME.ECS.Views.IViewComponent>(false);

            TransformComponentsInitializer.InitTypeId();
            NameComponentsInitializer.InitTypeId();
            CameraComponentsInitializer.InitTypeId();
            PhysicsComponentsInitializer.InitTypeId();
        }
コード例 #19
0
        public void OnDestroy()
        {
            if (this.world == null || this.world.isActive == false)
            {
                return;
            }

            this.DeInitializeFeatures(this.world);
            // Release world
            WorldUtilities.ReleaseWorld <TState>(ref this.world);
        }
コード例 #20
0
        public static void InitTypeId()
        {
            WorldUtilities.InitComponentTypeId <ME.ECS.Views.ViewComponent>(false);
            WorldUtilities.InitComponentTypeId <ME.ECS.Collections.IntrusiveListNode>(false);
            WorldUtilities.InitComponentTypeId <ME.ECS.Collections.IntrusiveHashSetBucket>(false);

            ME.ECS.DataConfigs.DataConfig.InitTypeId();
            TransformComponentsInitializer.InitTypeId();
            NameComponentsInitializer.InitTypeId();
            CameraComponentsInitializer.InitTypeId();
        }
コード例 #21
0
        public void Recycle()
        {
            foreach (var item in this.data)
            {
                var st = item;
                WorldUtilities.ReleaseState(ref st);
            }

            PoolArray <TState> .Recycle(ref this.data);

            PoolArray <Tick> .Recycle(ref this.dataTicks);
        }
コード例 #22
0
ファイル: WorldUtilities.cs プロジェクト: cleancoindev/ecs
        public static void CreateWorld <TState>(ref World <TState> worldRef, float tickTime, int forcedWorldId = 0) where TState : class, IState <TState>, new()
        {
            if (worldRef != null)
            {
                WorldUtilities.ReleaseWorld(ref worldRef);
            }
            worldRef = PoolClass <World <TState> > .Spawn();

            worldRef.SetId(forcedWorldId);
            ((IWorldBase)worldRef).SetTickTime(tickTime);
            Worlds <TState> .Register(worldRef);
        }
コード例 #23
0
        static partial void InitTypeIdPartial()
        {
            WorldUtilities.ResetTypeIds();
            CoreComponentsInitializer.InitTypeId();


            WorldUtilities.InitComponentTypeId <Example.Features.Players.Components.IsPlayer>(true);
            WorldUtilities.InitComponentTypeId <Example.Features.Map.Components.IsMap>(true);
            WorldUtilities.InitComponentTypeId <Example.Features.PlayerMovement.Components.LastMovementDirection>(false);
            WorldUtilities.InitComponentTypeId <Example.Features.PlayerMovement.Components.MoveAction>(false);
            WorldUtilities.InitComponentTypeId <Example.Features.PlayerFire.Components.FireAction>(true);
            WorldUtilities.InitComponentTypeId <Example.Features.PlayerFire.Components.IsBullet>(false);
            WorldUtilities.InitComponentTypeId <Example.Features.PlayerFire.Components.BulletFly>(false);
            WorldUtilities.InitComponentTypeId <Example.Features.Logic.ForceAtPoint.Components.AddForce>(false);
            WorldUtilities.InitComponentTypeId <Example.Features.Logic.ForceAtPoint.Components.Force>(false);
            WorldUtilities.InitComponentTypeId <Example.Features.Logic.DestroyByTime.Components.DestroyByTime>(false);
        }
コード例 #24
0
        public void Initialize()
        {
            ME.ECS.Pools.current = new ME.ECS.PoolImplementation(isNull: false);
            var reg = new UnmanagedComponentsStorage();

            reg.Initialize();
            try {
                WorldUtilities.InitComponentTypeId <TestComponent>();
                reg.Validate <TestComponent>();
                for (int i = 0; i < 100; ++i)
                {
                    reg.Validate <TestComponent>(i);
                }
            } finally {
                reg.Dispose();
            }
        }
コード例 #25
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);
            }
コード例 #26
0
ファイル: WorldUtilities.cs プロジェクト: myth326/ecs
        public static void CreateWorld <TState>(ref World worldRef, float tickTime, int forcedWorldId = 0, uint seed = 1u) where TState : State, new()
        {
            if (seed <= 0u)
            {
                seed = 1u;
            }

            if (worldRef != null)
            {
                WorldUtilities.ReleaseWorld <TState>(ref worldRef);
            }
            worldRef = PoolClass <World> .Spawn();

            worldRef.SetId(forcedWorldId);
            var worldInt = worldRef;

            worldInt.SetSeed(seed);
            worldInt.SetTickTime(tickTime);
            Worlds.Register(worldRef);
        }
コード例 #27
0
        public static bool InitComponentTypeId <TComponent>(bool isTag = false, bool isSimple = false, bool isCopyable = false, bool isDisposable = false, bool isVersioned = false, bool isVersionedNoState = false, bool isShared = false, bool isOneShot = false)
        {
            var isNew = (AllComponentTypes <TComponent> .typeId == -1);

            if (isTag == true)
            {
                WorldUtilities.SetComponentAsTag <TComponent>();
            }
            if (isSimple == true)
            {
                WorldUtilities.SetComponentAsSimple <TComponent>();
            }
            if (isVersioned == true)
            {
                WorldUtilities.SetComponentAsVersioned <TComponent>();
            }
            if (isVersionedNoState == true)
            {
                WorldUtilities.SetComponentAsVersionedNoState <TComponent>();
            }
            if (isCopyable == true)
            {
                WorldUtilities.SetComponentAsCopyable <TComponent>();
            }
            if (isShared == true)
            {
                WorldUtilities.SetComponentAsShared <TComponent>();
            }
            if (isDisposable == true)
            {
                WorldUtilities.SetComponentAsDisposable <TComponent>();
            }
            if (isOneShot == true)
            {
                WorldUtilities.SetComponentAsOneShot <TComponent>();
            }

            WorldUtilities.GetAllComponentTypeId <TComponent>();

            return(isNew);
        }
コード例 #28
0
        public void Get()
        {
            ME.ECS.Pools.current = new ME.ECS.PoolImplementation(isNull: false);
            var reg = new UnmanagedComponentsStorage();

            reg.Initialize();
            try {
                WorldUtilities.InitComponentTypeId <TestComponent>();
                reg.Validate <TestComponent>();
                for (int i = 0; i < 100; ++i)
                {
                    reg.Validate <TestComponent>(i);
                }

                ref var data = ref reg.Get <TestComponent>(1);
                NUnit.Framework.Assert.AreEqual(data.value, 0);
                var data2 = reg.Read <TestComponent>(2);
                NUnit.Framework.Assert.AreEqual(data2.value, 0);
                data.value = 123;
                var data3 = reg.Read <TestComponent>(1);
                NUnit.Framework.Assert.AreEqual(data3.value, 123);
            } finally {
コード例 #29
0
        public static void Init(ref ME.ECS.StructComponentsContainer structComponentsContainer)
        {
            WorldUtilities.InitComponentTypeId <ME.ECS.Pathfinding.Features.Pathfinding.Components.PathfindingInstance>(false, true, false, false);
            WorldUtilities.InitComponentTypeId <ME.ECS.Pathfinding.Features.Pathfinding.Components.CalculatePath>(false, false, false, false);
            WorldUtilities.InitComponentTypeId <ME.ECS.Pathfinding.Features.PathfindingAstar.Components.Path>(false, true, false, false);
            WorldUtilities.InitComponentTypeId <ME.ECS.Pathfinding.Features.PathfindingFlowField.Components.PathFlowField>(false, true, false, false);
            WorldUtilities.InitComponentTypeId <ME.ECS.Pathfinding.Features.Pathfinding.Components.IsPathfinding>(true, false, false, false);
            WorldUtilities.InitComponentTypeId <ME.ECS.Pathfinding.Features.Pathfinding.Components.BuildAllGraphs>(true, false, false, false);
            WorldUtilities.InitComponentTypeId <ME.ECS.Pathfinding.Features.Pathfinding.Components.IsAllGraphsBuilt>(true, false, false, false);
            WorldUtilities.InitComponentTypeId <ME.ECS.Pathfinding.Features.Pathfinding.Components.HasPathfindingInstance>(true, false, false, false);
            WorldUtilities.InitComponentTypeId <ME.ECS.Pathfinding.Features.Pathfinding.Components.IsPathBuilt>(true, false, false, false);

            structComponentsContainer.ValidateCopyable <ME.ECS.Pathfinding.Features.Pathfinding.Components.PathfindingInstance>(false);
            structComponentsContainer.Validate <ME.ECS.Pathfinding.Features.Pathfinding.Components.CalculatePath>();
            structComponentsContainer.ValidateCopyable <ME.ECS.Pathfinding.Features.PathfindingAstar.Components.Path>();
            structComponentsContainer.ValidateCopyable <ME.ECS.Pathfinding.Features.PathfindingFlowField.Components.PathFlowField>();
            structComponentsContainer.Validate <ME.ECS.Pathfinding.Features.Pathfinding.Components.IsPathfinding>(true);
            structComponentsContainer.Validate <ME.ECS.Pathfinding.Features.Pathfinding.Components.BuildAllGraphs>(true);
            structComponentsContainer.Validate <ME.ECS.Pathfinding.Features.Pathfinding.Components.IsAllGraphsBuilt>(true);
            structComponentsContainer.Validate <ME.ECS.Pathfinding.Features.Pathfinding.Components.HasPathfindingInstance>(true);
            structComponentsContainer.Validate <ME.ECS.Pathfinding.Features.Pathfinding.Components.IsPathBuilt>(true);
        }
コード例 #30
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>();
        }