Beispiel #1
0
        /// <summary>
        /// Creates new ecs-world instance.
        /// </summary>
        /// <param name="config">Optional config for default cache sizes. On zero or negative value - default value will be used.</param>
        public EcsWorld(EcsWorldConfig config = default)
        {
            var finalConfig = new EcsWorldConfig {
                EntityComponentsCacheSize = config.EntityComponentsCacheSize <= 0
                    ? EcsWorldConfig.DefaultEntityComponentsCacheSize
                    : config.EntityComponentsCacheSize,
                FilterEntitiesCacheSize = config.FilterEntitiesCacheSize <= 0
                    ? EcsWorldConfig.DefaultFilterEntitiesCacheSize
                    : config.FilterEntitiesCacheSize,
                WorldEntitiesCacheSize = config.WorldEntitiesCacheSize <= 0
                    ? EcsWorldConfig.DefaultWorldEntitiesCacheSize
                    : config.WorldEntitiesCacheSize,
                WorldFiltersCacheSize = config.WorldFiltersCacheSize <= 0
                    ? EcsWorldConfig.DefaultWorldFiltersCacheSize
                    : config.WorldFiltersCacheSize,
                WorldComponentPoolsCacheSize = config.WorldComponentPoolsCacheSize <= 0
                    ? EcsWorldConfig.DefaultWorldComponentPoolsCacheSize
                    : config.WorldComponentPoolsCacheSize
            };

            Config       = finalConfig;
            Entities     = new EcsEntityData[Config.WorldEntitiesCacheSize];
            FreeEntities = new EcsGrowList <int> (Config.WorldEntitiesCacheSize);
            Filters      = new EcsGrowList <EcsFilter> (Config.WorldFiltersCacheSize);
            FilterByIncludedComponents = new Dictionary <int, EcsGrowList <EcsFilter> > (Config.WorldFiltersCacheSize);
            FilterByExcludedComponents = new Dictionary <int, EcsGrowList <EcsFilter> > (Config.WorldFiltersCacheSize);
            ComponentPools             = new IEcsComponentPool[Config.WorldComponentPoolsCacheSize];
            _filterCtor = new object[] { this };
        }
Beispiel #2
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;
        }
Beispiel #3
0
        void Start()
        {
            var lss = new LocalSharedState();

            lss.Count  = CountInput.CountEntities;
            lss.Prefab = _prefab;

            var worldCfg = new EcsWorldConfig()
            {
                FilterEntitiesCacheSize = lss.Count,
                WorldEntitiesCacheSize  = lss.Count,
            };

            _world   = new EcsWorld(worldCfg);
            _systems = new EcsSystems(_world);
            _systems
            .Add(new InitSystem())
            .Add(new MoveSystem())
            .Inject(lss)
            .Init();
        }
        public void Start()
        {
            var lss = new LocalSharedState();

            lss.Count = _options.ComponentsCount;

            var worldCfg = new EcsWorldConfig()
            {
                FilterEntitiesCacheSize = lss.Count,
                WorldEntitiesCacheSize  = lss.Count,
            };

            _world   = new EcsWorld(worldCfg);
            _systems = new EcsSystems(_world);
            _systems
            .Add(new InitSystem())
            .Add(new MoveSystem())
            .Inject(lss)
            ;
            _systems.ProcessInjects();
            _systems.Init();
        }
        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)
            ;
        }
Beispiel #6
0
        public void Start()
        {
            var ss       = CreateSharedState(_options);
            var worldCfg = new EcsWorldConfig()
            {
                FilterEntitiesCacheSize = _options.EntitiesMax,
                WorldEntitiesCacheSize  = _options.EntitiesMax,
            };

            _world = new EcsWorld(worldCfg);

            _systems = new EcsSystems(_world, "RUN SYSTEMS");

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

            AddActorTypeSystemsByTypeCount();

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

            _systems
            .Add(new BulletDeleteSystem())
            ;

            _systems
            .Inject(ss)
            .Inject(new TimeService())
            .Inject(new ActorService())
            .Inject(new BulletService())
            ;

            if (_isRendering)
            {
                var bullet            = _options.BulletPrefab;
                var bulletViewService = new BulletViewService()
                {
                    Pool = new Pool <Transform>(
                        () =>
                    {
                        var tr = Object.Instantiate(bullet).transform;
                        tr.gameObject.SetActive(false);
                        return(tr);
                    }, 2),
                    Views = new Dictionary <int, Transform>()
                };
                var actor = _options.ShooterPrefab;

                var actorViewService = new ActorViewService()
                {
                    Pool = new Pool <Transform>(
                        () =>
                    {
                        var tr = Object.Instantiate(actor).transform;
                        tr.gameObject.SetActive(false);
                        return(tr);
                    }, 2),
                    Views = new Dictionary <int, Transform>()
                };

                _systems
                .Inject(bulletViewService)
                .Inject(actorViewService)
                ;
            }

            _systems.ProcessInjects();
            _systems.Init();
        }