示例#1
0
        public void WriteDeltaEntities(BaseClient client, ClientFrame to, ClientFrame from, BufferWrite buf)
        {
            var u = new EntityWriteInfo();

            u.Buf          = buf;
            u.To           = to;
            u.ToSnapshot   = to.GetSnapshot();
            u.Baseline     = client.Baseline;
            u.FullProps    = 0;
            u.Server       = this;
            u.ClientEntity = client.EntityIndex;
            u.CullProps    = true;

            if (from != null)
            {
                u.AsDelta      = true;
                u.From         = from;
                u.FromSnapshot = from.GetSnapshot();
            }
            else
            {
                u.AsDelta      = false;
                u.From         = null;
                u.FromSnapshot = null;
            }

            u.HeaderCount = 0;

            // set from_baseline pointer if this snapshot may become a baseline update
            if (client.BaselineUpdateTick == -1)
            {
                // TODO: Clear client baselines sent
                // TODO: Set 'to' from baseline to client.BaselinesSent
            }

            u.Buf.WriteUShort((ushort)ENetCommand.SvcPacketEntities);
            u.Buf.WriteInt(u.ToSnapshot.NumEntities);

            if (u.AsDelta)
            {
                u.Buf.WriteByte(1);
                u.Buf.WriteInt(u.From.TickCount);
            }
            else
            {
                u.Buf.WriteByte(0);
            }

            u.Buf.WriteInt(client.BaselineUsed);

            // Store off current position
            var savePos = u.Buf.Position;
        }
示例#2
0
        public void CopyFrame(ClientFrame frame)
        {
            TickCount = frame.TickCount;

            SetSnapshot(frame.GetSnapshot());
        }
示例#3
0
        public virtual void SendSnapshot(ClientFrame frame)
        {
            // do not send same snapshot twice
            if (_lastSnapshot == frame.GetSnapshot())
            {
                NetChannel.Transmit();
                return;
            }

            // if we send a full snapshot (no delta-compression) before, wait until client
            // received and acknowledge that update. don't spam client with full updates
            if (_forceWaitForTick > 0)
            {
                NetChannel.Transmit();
                return;
            }

            var msg = new BufferWrite();

            var deltaFrame = GetDeltaFrame(_deltaTick);

            if (deltaFrame == null)
            {
                // We need to send a full update and reset the instanced baselines
                OnRequestFullUpdate();
            }

            var tickmsg = new NetMessageTick(frame.TickCount, Program.HostFrametimeUnbounded, Program.HostFrametimeStdDeviation);

            tickmsg.WriteToBuffer(msg);

            // send entity update, delta compressed if deltaFrame != NULL
            Server.WriteDeltaEntities(this, frame, deltaFrame, msg);

            var maxTempEnts = 255;

            Server.WriteTempEntities(this, frame.GetSnapshot(), _lastSnapshot, msg, maxTempEnts);

            _lastSnapshot = frame.GetSnapshot();

            if (NetChannel == null)
            {
                _deltaTick = frame.TickCount;
                return;
            }

            bool sendOk;

            if (deltaFrame == null)
            {
                sendOk = NetChannel.SendData(msg);
                sendOk = sendOk && NetChannel.Transmit();

                // remember this tickcount we send the reliable snapshot
                // so we can continue sending other updates if this has been acknowledged
                _forceWaitForTick = frame.TickCount;
            }
            else
            {
                sendOk = NetChannel.SendDatagram(msg) > 0;
            }

            if (!sendOk)
            {
                Disconnect("Error! Couldn't send snapshot");
            }
        }