public void Test_FieldValueFactory_With_Single_Value_Produces_Correct_FieldValueUpdate([EntityDataCollectionTestRange] int index, [Values(1, 2, 3, 4, 5, 6, 7, 8)] int value) { //arrange ChangeTrackingEntityFieldDataCollectionDecorator <TestFieldType> collection = new ChangeTrackingEntityFieldDataCollectionDecorator <TestFieldType>(new EntityFieldDataCollection <TestFieldType>()); FieldValueUpdateFactory updateFactory = new FieldValueUpdateFactory(); //act collection.SetFieldValue <int>(index, value); FieldValueUpdate fieldValueUpdate = updateFactory.Create(new EntityFieldUpdateCreationContext(collection, collection.ChangeTrackingArray)); //assert Assert.AreEqual(1, fieldValueUpdate.FieldValueUpdateMask.EnumerateSetBitsByIndex().Count(), $"Found more than 1 set bit."); Assert.AreEqual(value, fieldValueUpdate.FieldValueUpdates.First(), $"Serialized value was not expected value."); Assert.AreEqual(index, fieldValueUpdate.FieldValueUpdateMask.EnumerateSetBitsByIndex().First(), $"Index: {index} was expected to be in the update but was not."); }
public void Test_FieldValueFactory_With_Multiple_Value_Produces_Correct_FieldValueUpdate() { //arrange ChangeTrackingEntityFieldDataCollectionDecorator <TestFieldType> collection = new ChangeTrackingEntityFieldDataCollectionDecorator <TestFieldType>(new EntityFieldDataCollection <TestFieldType>()); FieldValueUpdateFactory updateFactory = new FieldValueUpdateFactory(); //act collection.SetFieldValue <int>(1, 5); collection.SetFieldValue <int>(2, 4); collection.SetFieldValue <int>(3, 7); FieldValueUpdate fieldValueUpdate = updateFactory.Create(new EntityFieldUpdateCreationContext(collection, collection.ChangeTrackingArray)); //assert Assert.AreEqual(3, fieldValueUpdate.FieldValueUpdateMask.EnumerateSetBitsByIndex().Count(), $"Found more than 1 set bit."); Assert.AreEqual(5, fieldValueUpdate.FieldValueUpdates.First(), $"Serialized value was not expected value."); Assert.AreEqual(1, fieldValueUpdate.FieldValueUpdateMask.EnumerateSetBitsByIndex().First(), $"Index: {1} was expected to be first index."); }
/// <inheritdoc /> public GameObject Create(TCreationContext context) { if (Logger.IsDebugEnabled) { Logger.Debug($"Creating entity. Type: {context.EntityGuid.EntityType} Id: {context.EntityGuid.EntityId}"); } //load the entity's prefab from the factory GameObject prefab = PrefabFactory.Create(context.PrefabType); GameObject entityGameObject = GameObject.Instantiate(prefab, context.MovementData.InitialPosition, Quaternion.Euler(0, 0, 0)); if (context.EntityGuid.EntityType == EntityType.Player) { CharacterControllerMappable[context.EntityGuid] = entityGameObject.GetComponent <CharacterController>(); } GameObjectToEntityMap.ObjectToEntityMap.Add(entityGameObject, context.EntityGuid); //TODO: Better handle initial movement/position data GuidToMovementInfoMappable.Add(context.EntityGuid, context.MovementData); GuidToGameObjectMappable.Add(context.EntityGuid, entityGameObject); //TODO: Is it best to do this here? if (!MovementHandlerService.TryHandleMovement(context.EntityGuid, context.MovementData)) { throw new InvalidOperationException($"Cannot handle MovementType: {context.MovementData.GetType().Name} for Entity: {context.EntityGuid}"); } //TODO: We need a better way to handle the entity data collection, we're casting and downcasting in afew spots //Entity data needs to be change trackable var changeTrackableEntityDataCollection = new ChangeTrackingEntityFieldDataCollectionDecorator <EntityDataFieldType>((IEntityDataFieldContainer <EntityDataFieldType>)context.EntityData); //Now we should add the entity data to the mappable collection //This lets it be looked up in both ways FieldDataContainers.Add(context.EntityGuid, changeTrackableEntityDataCollection); ChangeTrackableEntityDataFieldContainers.Add(context.EntityGuid, changeTrackableEntityDataCollection); EntityAsyncLockMap.Add(new KeyValuePair <NetworkEntityGuid, AsyncReaderWriterLock>(context.EntityGuid, new AsyncReaderWriterLock())); return(entityGameObject); }