internal ItemList(EntityMapList <T> parent, int capacity) { this._items = new T[capacity]; this._count = 0; this._version = parent._version; this._parent = parent; }
public ReplicationDataBroker( ReplicationConfig.CapacityConfig capacityConfig, IWorldReplicationManager replicationManager) { this._replicationManager = replicationManager ?? throw new ArgumentNullException(nameof(replicationManager)); this._entityComponents = new EntityMapList <ReplicatedComponentData>( entityCapacity: capacityConfig.InitialReplicatedEntityCapacity, listCapacity: capacityConfig.InitialReplicatedComponentCapacity); }
public void AddEntityChanges( Entity entity, EntityMapList <ReplicatedComponentData> .ItemList modifiedComponents, float priority, float relevance) { bool wasUnassigned = false; int index; if (!this._entityToIndex.ContainsKey(entity)) { wasUnassigned = true; if (this._freeCount > 0) { // Use index from the free pool first. index = this._freeIndices[--this._freeCount]; } else { if (this._count == this._replicatedEntities.Length) { Array.Resize(ref this._replicatedEntities, 2 * this._count); Array.Resize(ref this._freeIndices, 2 * this._count); } index = this._count++; } this._entityToIndex[entity] = index; if (this._replicatedEntities[index].Components == null) { this._replicatedEntities[index].Components = new FixedIndexDictionary <EntityReplicationData.Component>(this._componentCapacity); this._replicatedEntities[index].LastReplicatedComponentFields = new Dictionary <ComponentId, BitField>(this._componentCapacity); } this._replicatedEntities[index].Entity = entity; } else { index = this._entityToIndex[entity]; } ref var entityReplicationData = ref this._replicatedEntities[index];
public void Tests() { var config = ReplicationConfig.Default; var pool = new PlayerReplicationDataPool(config, capacity: 2); var world = new World(EcsConfig.Default); var entity1 = world.NewEntity(); var entity2 = world.NewEntity(); var entityChangedComponents = new EntityMapList <ReplicatedComponentData>(entityCapacity: 1, listCapacity: 1); var idx1 = pool.New(); Assert.Equal(1, pool.Count); var item1 = pool.GetItem(idx1); Assert.Equal(0, item1.Count); { ref var e1c1 = ref entityChangedComponents[entity1].New(); e1c1.ComponentId = Core.ComponentId.Transform; e1c1.Transform.x = 1; e1c1.Transform.y = 2; }
public void ApplyEntityChanges(EntityMapList <ReplicatedComponentData> modifiedEntityComponents) { this._packetPriorityComponents.Clear(); // Apply changes to player entity change lists foreach (ref var player in this._players) { if (player.TryGetEntity(out Entity playerEntity)) { this._entityGridMap.GetEntitiesOfInterest( playerEntity, ref this._entityBuffer, out int entityCount); AddPacketPrioritizedEntityChangesToPlayer( playerEntity, this._entityBuffer, entityCount, modifiedEntityComponents, this._packetPriorityComponents, player.ReplicationData); } } }
public void Test() { var w = new World(EcsConfig.Default); var mapList = new EntityMapList <MyData>(entityCapacity: 1, listCapacity: 1); // capacity 1 validates array growth var entities = new Entity[1000]; for (int i = 0; i < entities.Length; i++) { entities[i] = w.NewEntity(); } // Add every even entity for (int i = 0; i < entities.Length; i += 2) { mapList[entities[i]].New(); mapList[entities[i]].Current.value = i; mapList[entities[i]].New(); mapList[entities[i]].Current.value = -i; } // Validate even entities foreach (var item in mapList) { Assert.Equal(2, item.Items.Count); // Direct access Assert.Equal(item.Entity.Id, item.Items[0].value); Assert.Equal(item.Entity.Id, -item.Items[1].value); // Loop for (int i = 0; i < item.Items.Count; i++) { Assert.Equal(i == 0 ? item.Entity.Id : -item.Entity.Id, item.Items[i].value); } } // Reset map - should keep the list pool. mapList.Clear(); Assert.Equal(0, mapList.Count); // Add every odd entity for (int i = 1; i < entities.Length; i += 2) { mapList[entities[i]].New(); mapList[entities[i]].Current.value = i; mapList[entities[i]].New(); mapList[entities[i]].Current.value = -i; } // Validate odd entities foreach (var item in mapList) { Assert.Equal(2, item.Items.Count); // Direct access Assert.Equal(item.Entity.Id, item.Items[0].value); Assert.Equal(item.Entity.Id, -item.Items[1].value); // ItemList for loop for (int i = 0; i < item.Items.Count; i++) { Assert.Equal(i == 0 ? item.Entity.Id : -item.Entity.Id, item.Items[i].value); } // ItemList foreach loop int count = 0; foreach (var subItem in item.Items) { Assert.Equal(count++ == 0 ? item.Entity.Id : -item.Entity.Id, subItem.value); } } // Validate versioning mapList.Clear(); mapList[entities[0]].New().value = 11; mapList[entities[0]].New().value = 12; Assert.Equal(2, mapList[entities[0]].Count); Assert.Equal(11, mapList[entities[0]][0].value); Assert.Equal(12, mapList[entities[0]][1].value); }
public EntityItem(EntityMapList <T> parent, int capacity) : this() { Items = new ItemList(parent, capacity); }
internal Enumerator(EntityMapList <T> mapList) { this._mapList = mapList ?? throw new ArgumentNullException(nameof(mapList)); this._current = -1; }