Beispiel #1
0
        private void RegisterEvents(RailRegistry registry)
        {
            foreach (EventConstructionInfo eventInfo in registry.EventTypes)
            {
                IRailMemoryPool <RailEvent> statePool = new RailMemoryPool <RailEvent>(
                    new RailFactory <RailEvent>(eventInfo.Type, eventInfo.ConstructorParams));

                int typeKey = eventPools.Count + 1; // 0 is an invalid type
                eventPools.Add(typeKey, statePool);
                eventTypeToKey.Add(eventInfo.Type, typeKey);
            }
        }
Beispiel #2
0
        private void AllocateCallsFactory()
        {
            A instance = new A();

            factoryMock.Setup(f => f.Create()).Returns(instance);

            RailMemoryPool <A> pool = new RailMemoryPool <A>(factoryMock.Object);
            A allocatedObject       = pool.Allocate();

            factoryMock.Verify(f => f.Create(), Times.Once);
            Assert.Same(instance, allocatedObject);
        }
Beispiel #3
0
        private void PoolReusesInstances()
        {
            factoryMock.Setup(f => f.Create()).Returns(new A());
            RailMemoryPool <A> pool = new RailMemoryPool <A>(factoryMock.Object);
            A firstObject           = pool.Allocate();

            factoryMock.Verify(f => f.Create(), Times.Once);

            pool.Deallocate(firstObject);
            A secondObject = pool.Allocate();

            factoryMock.Verify(f => f.Create(), Times.Once);
            Assert.Same(firstObject, secondObject);
        }
Beispiel #4
0
        private void RegisterEntities(RailRegistry registry)
        {
            foreach (EntityConstructionInfo pair in registry.EntityTypes)
            {
                IRailMemoryPool <RailState> statePool = new RailMemoryPool <RailState>(
                    new RailFactory <RailState>(pair.State));
                IRailMemoryPool <RailEntityBase> entityPool = new RailMemoryPool <RailEntityBase>(
                    new RailFactory <RailEntityBase>(pair.Entity, pair.ConstructorParamsEntity));

                int typeKey = statePools.Count + 1; // 0 is an invalid type
                statePools.Add(typeKey, statePool);
                entityPools.Add(typeKey, entityPool);
                entityTypeToKey.Add(pair.Entity, typeKey);
            }
        }
Beispiel #5
0
        private void DecodeReadsTickAndCommandData(int iData)
        {
            RailMemoryPool <RailCommand> pool =
                new RailMemoryPool <RailCommand>(new RailFactory <TestUtils.Command>());
            Mock <IRailCommandConstruction> mockCreator = new Mock <IRailCommandConstruction>();

            mockCreator.Setup(m => m.CreateCommand()).Returns(pool.Allocate());

            RailBitBuffer bitBuffer   = new RailBitBuffer(2);
            Tick          writtenTick = Tick.START.GetNext();

            bitBuffer.WriteTick(writtenTick);
            bitBuffer.WriteInt(iData);

            RailCommand decodedGenericCommand = RailCommand.Decode(mockCreator.Object, bitBuffer);

            Assert.IsType <TestUtils.Command>(decodedGenericCommand);
            TestUtils.Command decodedCommand = decodedGenericCommand as TestUtils.Command;
            Assert.NotNull(decodedCommand);
            Assert.Equal(writtenTick, decodedCommand.ClientTick);
            Assert.Equal(iData, decodedCommand.Data);
        }