Exemple #1
0
        public void Destroy(EcsWorlds worlds)
        {
            // destroy.
            foreach (var system in _allSystems)
            {
                if (system is IEcsDestroySystem destroySystem)
                {
                    destroySystem.Destroy(worlds);
#if DEBUG
                    var leaked = worlds.CheckLeaks();
                    if (leaked != null)
                    {
                        throw new System.Exception($"\"{leaked}\" in {destroySystem.GetType ().Name}.Destroy().");
                    }
#endif
                }
            }
            // post destroy.
            foreach (var system in _allSystems)
            {
                if (system is IEcsPostDestroySystem postDestroySystem)
                {
                    postDestroySystem.AfterDestroy(worlds);
#if DEBUG
                    var leaked = worlds.CheckLeaks();
                    if (leaked != null)
                    {
                        throw new System.Exception($"\"{leaked}\" in {postDestroySystem.GetType ().Name}.PreInit().");
                    }
#endif
                }
            }
        }
Exemple #2
0
 public void Destroy()
 {
     _systems?.Destroy(_worlds);
     _systems = null;
     _worlds?.Destroy();
     _worlds = null;
 }
Exemple #3
0
        public void Init(EcsWorlds worlds)
        {
            // pre init.
            foreach (var system in _allSystems)
            {
                if (system is IEcsPreInitSystem preInitSystem)
                {
                    preInitSystem.PreInit(worlds);
#if DEBUG
                    var leaked = worlds.CheckLeaks();
                    if (leaked != null)
                    {
                        throw new System.Exception($"\"{leaked}\" in {preInitSystem.GetType ().Name}.PreInit().");
                    }
#endif
                }
            }
            // init.
            foreach (var system in _allSystems)
            {
                if (system is IEcsInitSystem initSystem)
                {
                    initSystem.Init(worlds);
#if DEBUG
                    var leaked = worlds.CheckLeaks();
                    if (leaked != null)
                    {
                        throw new System.Exception($"\"{leaked}\" in {initSystem.GetType ().Name}.Init().");
                    }
#endif
                }
            }
        }
        public void Run(EcsWorlds worlds)
        {
            var world = worlds.Get();

            foreach (ref var entity in world.Query().With <Bullet>().With <Deleted>())
            {
                entity.Destroy();
            }
        }
        public void Run(EcsWorlds worlds)
        {
            var world    = worlds.Get();
            var services = worlds.Shared <Services>();

            foreach (ref var entity in world.Query().With <Bullet>().With <Position>().Without <Deleted>())
            {
                ref var bullet   = ref entity.Get <Bullet>();
                ref var position = ref entity.Get <Position>();
Exemple #6
0
        public void Run(EcsWorlds worlds)
        {
            var world = worlds.Get();

            foreach (ref var entity in world.Query().With <Movable>())
            {
                ref var movable = ref entity.Get <Movable>();
                movable.Position += Float3.Forward;
            }
Exemple #7
0
        public void Run(EcsWorlds worlds)
        {
            var world    = worlds.Get();
            var services = worlds.Shared <Services>();
            var time     = services.TimeService;

            foreach (ref var entity in world.Query().With <Position>().With <DesiredVelocity>())
            {
                ref var position    = ref entity.Get <Position>();
                ref var desVelocity = ref entity.Get <DesiredVelocity>();
Exemple #8
0
        public void Run(EcsWorlds worlds)
        {
            var world    = worlds.Get();
            var services = worlds.Shared <Services>();
            var time     = services.TimeService;

            foreach (ref var entity in world.Query()
                     .With <Actor>().With <Position>().With <Rotation>().With <TActorType>().Without <Deleted>())
            {
                ref var rotation = ref entity.Get <Rotation>();
                rotation.Value = rotation.Value.Rotate(time.DeltaTime * RotationSpeed);
            }
Exemple #9
0
        public void Init(EcsWorlds worlds)
        {
            world    = worlds.Get();
            services = worlds.Shared <Services>();

            // Instantiate actors
            for (var i = 0; i < services.SharedState.ActorsCount; i++)
            {
                CreateActorTypesByTypeCount(services.SharedState.ActorTypesCount);
            }

            world    = null;
            services = null;
        }
Exemple #10
0
        public void Run(EcsWorlds worlds)
        {
            foreach (var runSystem in _runSystems)
            {
                runSystem.Run(worlds);
#if DEBUG
                var leaked = worlds.CheckLeaks();
                if (leaked != null)
                {
                    throw new System.Exception($"\"{leaked}\" in {runSystem.GetType ().Name}.Run().");
                }
#endif
            }
        }
Exemple #11
0
        public void Run(EcsWorlds worlds)
        {
            var world    = worlds.Get();
            var services = worlds.Shared <Services>();

            foreach (ref var entity in world.Query().With <Bullet>().With <Deleted>())
            {
                ref var bullet = ref entity.Get <Bullet>();
                if (services.BulletViewService.Views.TryGetValue(bullet.Id, out var viewTransform))
                {
                    viewTransform.gameObject.SetActive(false);
                    services.BulletViewService.Pool.Return(viewTransform);
                    services.BulletViewService.Views.Remove(bullet.Id);
                }
            }
Exemple #12
0
        public void Run(EcsWorlds worlds)
        {
            var world    = worlds.Get();
            var services = worlds.Shared <Services>();
            var time     = services.TimeService;

            foreach (ref var entity in world.Query().With <Bullet>())
            {
                ref var bullet = ref entity.Get <Bullet>();

                bullet.LifeTime -= time.DeltaTime;
                if (bullet.LifeTime <= 0)
                {
                    entity.Get <Deleted>();
                }
            }
Exemple #13
0
        public void Start()
        {
            var services = CreateAllSharedState(_options);
            var worldCfg = new EcsWorldConfig()
            {
                ComponentsCount = _options.EntitiesMax,
                EntitiesCount   = _options.EntitiesMax,
            };

            _worlds = new EcsWorlds(services);
            _world  = _worlds.Create(cfg: worldCfg);
            _world
            .Register <Actor>()
            .Register <Bullet>()
            .Register <Deleted>()
            .Register <DesiredVelocity>()
            .Register <Position>()
            .Register <Rotation>()
            .Register <Weapon>()
            ;

            _systems = new EcsSystems();
            _systems
            .Add(new InitSystem())
            .Add(new TimeSystem())
            .Add(new ShootSystem())
            .Add(new BulletSystem())
            .Add(new MoveSystem())
            ;

            AddActorTypeSystemsByTypeCount();

            if (_options.IsRendering)
            {
                _systems
                .Add(new ActorViewUpdateSystem())
                .Add(new BulletViewDeleteSystem())
                .Add(new BulletViewUpdateSystem())
                ;
            }

            _systems.Add(new BulletDeleteSystem());

            _worlds.Init();
            _systems.Init(_worlds);
            _world = null;
        }
Exemple #14
0
        public void Run(EcsWorlds worlds)
        {
            var world         = worlds.Get();
            var services      = worlds.Shared <Services>();
            var time          = services.TimeService;
            var bulletService = services.BulletService;
            var sharedState   = services.SharedState;

            foreach (ref var entity in world.Query()
                     .With <Weapon>().With <Position>().With <Rotation>())
            {
                ref var weapon = ref entity.Get <Weapon>();
                weapon.FireTimeout -= time.DeltaTime;

                if (weapon.FireTimeout > 0)
                {
                    continue;
                }

                weapon.FireTimeout = sharedState.FireTimeout;
                ref var actorPosition = ref entity.Get <Position>();
        public void Start()
        {
            var lss = new LocalSharedState();

            lss.Count = _options.ComponentsCount;

            var worldCfg = new EcsWorldConfig()
            {
                ComponentsCount = lss.Count,
                EntitiesCount   = lss.Count,
            };

            _worlds = new EcsWorlds(lss);
            _worlds
            .Create(cfg: worldCfg)
            .Register <Movable>();

            _worlds.Init();
            _systems = new EcsSystems();
            _systems
            .Add(new MoveSystem())
            .Init(_worlds)
            ;
        }
Exemple #16
0
        public void Run(EcsWorlds worlds)
        {
            var services = worlds.Shared <Services>();

            services.TimeService.DeltaTime = Time.deltaTime;
        }