public void AddItem_should_returnAnObjectThatOnlyIteratesOverItsOwnChildren_and_doesNotMutatePreviousChildStates()
        {
            var list = new AppendOnlyList <Cat>();
            var list1 = list.AddItem(new Cat("frodo", 10));
            var list2 = list1.AddItem(new Cat("Gandalf", 25));
            var list3 = list2.AddItem(new Cat("Buttons", 13));
            var json = new[] { list, list1, list2, list3 }.ToJsons();

            Approvals.VerifyJson(json);
        }
Beispiel #2
0
        public OutgoingServerChannel(
            NetworkTransportConfig config,
            ServerUdpPacketTransport transport,
            IPacketEncryptor packetEncryption,
            ILogger logger)
        {
            this._config           = config ?? throw new ArgumentNullException(nameof(config));
            this._transport        = transport ?? throw new ArgumentNullException(nameof(transport));
            this._packetEncryption = packetEncryption ?? throw new ArgumentNullException(nameof(packetEncryption));
            this._logger           = logger ?? throw new ArgumentNullException(nameof(logger));

            this._clientEntitiesToRemove = new AppendOnlyList <Entity>(64);
        }
Beispiel #3
0
        public void ConstructorAppendRange_CorrectValuesReturned(int bitness, List <int> data)
        {
            // Arrange
            var sut = new AppendOnlyList <int>(bitness);

            // Act
            sut.AppendRange(data);

            // Assert
            Assert.AreEqual(data.Count, sut.Count);
            Assert.IsTrue(Enumerable.SequenceEqual(sut, data));
            for (int i = 0; i < data.Count; i++)
            {
                Assert.AreEqual(data[i], sut[i]);
            }
        }
Beispiel #4
0
            public static void ValidateEntityQuery <QueryType>(AppendOnlyList <QueryType> queries, Type injectedQueryType)
            {
                var queryManifest = new HashSet <Type>();

                for (int i = 0; i < queries.Count; i++)
                {
                    var itemType = queries.Items[i].GetType();

                    if (queryManifest.Contains(itemType))
                    {
                        throw new Exception($"InvarianceViolation: Multiple copies of same query type detected. ConflictingType={itemType}, InjectedQueryType={injectedQueryType}");
                    }

                    queryManifest.Add(itemType);
                }
            }
Beispiel #5
0
        public void PlayForward(int fixedFrameCount)
        {
            // Clone the snapshot inputs
            var clonedInputs = new AppendOnlyList <AppendOnlyList <SnapShot <TInput> .ClientInputFrame> >(fixedFrameCount);

            for (int i = 0; i < fixedFrameCount; i++)
            {
                SnapShot <TInput> replaySnapShot = _snapShots.Peek(i);

                clonedInputs.Add(new AppendOnlyList <SnapShot <TInput> .ClientInputFrame>(replaySnapShot.ClientInputs.Count));

                replaySnapShot.MoveInputsTo(ref clonedInputs.Items[i]);
            }

            for (int i = 0; i < fixedFrameCount; i++)
            {
                // Replay inputs and simulate.

                float tickRemaining = _config.FixedTick;

                var     query = (EntityQuery <TInput>)World.GetEntityQuery <EntityQuery <TInput> >();
                ref var input = ref query.GetSingleton();

                // Apply all inputs before this fixed update
                for (int j = 0; j < clonedInputs.Items[i].Count; j++)
                {
                    input = clonedInputs.Items[i].Items[j].Input;

                    float deltaTime = clonedInputs.Items[i].Items[j].Time - _time;

                    //Debug.WriteLine($"{i}:{_time:N1}: LDown={input.isLeftDown}, LUp={input.isLeftUp}, RDown={input.isRightDown}, RUp={input.isRightUp}");

                    Update(deltaTime);

                    tickRemaining -= deltaTime;

                    //Debug.WriteLine($"Position={position.x}");
                }

                // Run this snapshots fixed update.
                FixedUpdate(_config.FixedTick);
            }
Beispiel #6
0
        public void Test()
        {
            var list = new AppendOnlyList <SampleStructs.Foo>(2);

            list.Add(new SampleStructs.Foo {
                x = 1
            });
            list.Add(new SampleStructs.Foo {
                x = 2
            });
            list.Add(new SampleStructs.Foo {
                x = 3
            });
            list.Add(new SampleStructs.Foo {
                x = 4
            });

            Assert.Equal(4, list.Count);
            Assert.Equal(1, list.Items[0].x);
            Assert.Equal(2, list.Items[1].x);
            Assert.Equal(3, list.Items[2].x);
            Assert.Equal(4, list.Items[3].x);
        }
Beispiel #7
0
        public void MoveInputsTo(ref AppendOnlyList <ClientInputFrame> inputs)
        {
            this.ClientInputs.ShallowCopyTo(inputs);

            this.ClientInputs.Count = 0;
        }
        public void EmptyList_test()
        {
            var list = new AppendOnlyList <Cat>();

            Approvals.VerifyJson(new[] { list }.ToJsons());
        }