Пример #1
0
    private void NetworkOnMessageReceived(MessageTag messageTag, IDeserializer reader)
    {
        switch (messageTag)
        {
        case MessageTag.StartSimulation:
            var pkt = new Init();
            pkt.Deserialize(reader);
            Time.fixedDeltaTime = 1f / pkt.TargetFPS;


            _simulation.Init(pkt.Seed);

            _simulationStarted = true;
            break;

        case MessageTag.Frame:
            //Server sends in ReliableOrdered-mode, so we only care about the latest frame
            //Also possible could be high-frequency unreliable messages and use redundant frames to fill up a framebuffer in case of frame loss during transmission
            _simulation.AddFrame(new Frame {
                Commands = _inputParser.DeserializeInput(reader)
            });

            //TODO: only for debugging, frames should be buffered & later executed in FixedUpdate
            _simulation.Simulate();

            LockstepNetwork.Instance.SendHashCode(new HashCode
            {
                FrameNumber = _simulation.FrameCounter,
                Value       = _simulation.HashCode
            });
            break;
        }
    }