public void TestSerialzation()
        {
            //Clientside create command, send to server
            var writer = new LiteNetLibSerializer();

            new TestCommand();

            //Serverside, gather input
            var writer2 = new LiteNetLibSerializer();
            var packer  = new InputPacker();

            packer.AddInput(writer.Data);
            packer.Pack(writer2);

            //Clientside, receive input
            var reader = new LiteNetLibDeserializer();

            reader.SetSource(writer2.Data);

            var messageTag = reader.GetByte();

            messageTag.ShouldBe((byte)MessageTag.Frame);

            var commands = new InputParser(r => new TestCommand()).DeserializeInput(reader);

            commands.ShouldNotBeNull();
            commands.Length.ShouldBe(1);
            commands.First().ShouldBeOfType <TestCommand>();
        }
Exemple #2
0
        private void Loop()
        {
            var timer = new Timer();
            var dt    = 1000.0 / TargetFps;

            var accumulatedTime = 0.0;

            _hashCodes.Clear();
            _serializer.Reset();
            _inputPacker = new InputPacker();

            Running = true;

            StartSimulationOnConnectedPeers(_serializer);

            timer.Start();

            Console.WriteLine("Simulation started");

            while (Running)
            {
                timer.Tick();

                accumulatedTime += timer.DeltaTime;

                while (accumulatedTime >= dt)
                {
                    _serializer.Reset();

                    _inputPacker.Pack(_serializer);

                    Distribute(_serializer.Data);

                    accumulatedTime -= dt;
                }

                Thread.Sleep(1);
            }

            Console.WriteLine("Simulation stopped");
        }