/// <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; }
/// <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); }
/// <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 }
public static int GetId() => _idDispenser.GetFreeInt();