Exemplo n.º 1
0
        /// <inheritdoc />
        public NetworkEntityNowVisibleEventArgs Create(EntityCreationData context)
        {
            NetworkEntityGuid guid = context.EntityGuid;

            IEntityDataFieldContainer container = CreateInitialEntityFieldContainer(context.InitialFieldValues);
            ChangeTrackingEntityFieldDataCollectionDecorator trackingEntityFieldDataCollectionDecorator = new ChangeTrackingEntityFieldDataCollectionDecorator(container, context.InitialFieldValues.FieldValueUpdateMask);

            ChangeTrackableCollection.AddObject(guid, trackingEntityFieldDataCollectionDecorator);
            MovementBlockMappable.AddObject(guid, context.InitialMovementData);

            return(new NetworkEntityNowVisibleEventArgs(guid));
        }
Exemplo n.º 2
0
        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 collection = new ChangeTrackingEntityFieldDataCollectionDecorator(new EntityFieldDataCollection(8));
            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.");
        }
Exemplo n.º 3
0
        public void Test_ChangeTracker_With_Multiple_Value_Indicates_No_Changes_After_Clearing_FieldValueUpdate()
        {
            //arrange
            ChangeTrackingEntityFieldDataCollectionDecorator collection = new ChangeTrackingEntityFieldDataCollectionDecorator(new EntityFieldDataCollection(8));
            FieldValueUpdateFactory updateFactory = new FieldValueUpdateFactory();

            //act
            collection.SetFieldValue <int>(1, 5);
            collection.SetFieldValue <int>(2, 4);
            collection.SetFieldValue <int>(3, 7);
            collection.ClearTrackedChanges();
            FieldValueUpdate fieldValueUpdate = updateFactory.Create(new EntityFieldUpdateCreationContext(collection, collection.ChangeTrackingArray));


            //assert
            Assert.AreEqual(0, fieldValueUpdate.FieldValueUpdateMask.EnumerateSetBitsByIndex().Count(), $"Found more than 1 set bit.");
            Assert.AreEqual(0, fieldValueUpdate.FieldValueUpdates.Count, $"Field updates should be empty due to no changes..");
        }
Exemplo n.º 4
0
        public void Test_FieldValueFactory_With_Multiple_Value_Produces_Correct_FieldValueUpdate()
        {
            //arrange
            ChangeTrackingEntityFieldDataCollectionDecorator collection = new ChangeTrackingEntityFieldDataCollectionDecorator(new EntityFieldDataCollection(8));
            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.");
        }
Exemplo n.º 5
0
        public void Test_ChangeTracker_Doesnt_Set_Change_Bits_On_Same_Value_After_Clear_FieldValueUpdate()
        {
            //arrange
            WireReadyBitArray bitArray = new WireReadyBitArray(1328);

            bitArray.Set(1, true);
            bitArray.Set(2, true);
            bitArray.Set(4, true);

            //Reference the actual client's visibile field update computation.
            IEntityDataFieldContainer dataCollection = NetworkVisibilityCreationBlockToVisibilityEventFactory.CreateInitialEntityFieldContainer(new FieldValueUpdate(bitArray, new int[] { 5, 4, 7 }));

            ChangeTrackingEntityFieldDataCollectionDecorator collection = new ChangeTrackingEntityFieldDataCollectionDecorator(dataCollection, bitArray);
            FieldValueUpdateFactory updateFactory = new FieldValueUpdateFactory();

            //act
            FieldValueUpdate fieldValueUpdate = updateFactory.Create(new EntityFieldUpdateCreationContext(collection, collection.ChangeTrackingArray));

            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.");

            collection.ClearTrackedChanges();


            //Check they're event before setting them again
            Assert.AreEqual(collection.GetFieldValue <int>(1), 5, $"Values not the same.");
            Assert.AreEqual(collection.GetFieldValue <int>(2), 4, $"Values not the same.");
            collection.SetFieldValue(1, 5);
            collection.SetFieldValue(2, 4);

            fieldValueUpdate = updateFactory.Create(new EntityFieldUpdateCreationContext(collection, collection.ChangeTrackingArray));

            //assert
            Assert.AreEqual(0, fieldValueUpdate.FieldValueUpdateMask.EnumerateSetBitsByIndex().Count(), $"Found more than 1 set bit.");
            Assert.AreEqual(0, fieldValueUpdate.FieldValueUpdates.Count, $"Field updates should be empty due to no changes..");
        }