Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="World"/> class.
        /// </summary>
        /// <param name="maxCapacity">The maximum number of <see cref="Entity"/> that can exist in this <see cref="World"/>.</param>
        /// <exception cref="ArgumentException"><paramref name="maxCapacity"/> cannot be negative.</exception>
        public World(int maxCapacity)
        {
            if (maxCapacity < 0)
            {
                throw new ArgumentException("Argument cannot be negative", nameof(maxCapacity));
            }

            _entityIdDispenser = new IntDispenser(-1);
            _optimizer         = new Optimizer();
            WorldId            = (short)_worldIdDispenser.GetFreeInt();

            MaxCapacity = maxCapacity;
            EntityInfos = EmptyArray <EntityInfo> .Value;

            lock (_lockObject)
            {
                ArrayExtension.EnsureLength(ref Worlds, WorldId);

                Worlds[WorldId] = this;
            }

            Subscribe <EntityDisposedMessage>(On);

            _isDisposed = false;
        }
Exemplo n.º 2
0
        static World()
        {
            _lockObject       = new object();
            _worldIdDispenser = new IntDispenser(0);

            Worlds = new World[2];

            IsAliveFlag   = ComponentFlag.GetNextFlag();
            IsEnabledFlag = ComponentFlag.GetNextFlag();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="World"/> class.
        /// </summary>
        /// <param name="maxEntityCount">The maximum number of <see cref="Entity"/> that can exist in this <see cref="World"/>.</param>
        /// <exception cref="ArgumentException"><paramref name="maxEntityCount"/> cannot be negative.</exception>
        public World(int maxEntityCount)
        {
            if (maxEntityCount < 0)
            {
                throw new ArgumentException("Argument cannot be negative", nameof(maxEntityCount));
            }

            _entityIdDispenser = new IntDispenser(-1);
            WorldId            = _worldIdDispenser.GetFreeInt();

            Info = new WorldInfo(maxEntityCount);

            lock (_lockObject)
            {
                ArrayExtension.EnsureLength(ref Infos, WorldId);

                Infos[WorldId] = Info;
            }

            this.Subscribe(this);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="World"/> class.
        /// </summary>
        /// <param name="maxEntityCount">The maximum number of <see cref="Entity"/> that can exist in this <see cref="World"/>.</param>
        /// <exception cref="ArgumentException"><paramref name="maxEntityCount"/> cannot be negative.</exception>
        public World(int maxEntityCount)
        {
            if (maxEntityCount < 0)
            {
                throw new ArgumentException("Argument cannot be negative", nameof(maxEntityCount));
            }

            _entityIdDispenser = new IntDispenser(-1);
            WorldId            = _worldIdDispenser.GetFreeInt();

            Info = new WorldInfo(maxEntityCount);

            lock (_lockObject)
            {
                ArrayExtension.EnsureLength(ref Infos, WorldId);

                Infos[WorldId] = Info;
            }

#pragma warning disable IDE0067 // Dispose objects before losing scope
            this.Subscribe(this);
#pragma warning restore IDE0067 // Dispose objects before losing scope
        }
Exemplo n.º 5
0
 static SerializationContext()
 {
     _idDispenser = new IntDispenser(-1);
 }