コード例 #1
0
        private unsafe void ClearState()
        {
            this.snap         = new ClientSnapshot();
            this.serverTime   = 0;
            this.newSnapshots = false;
            fixed(GameState *gs = &this.gameState)
            {
                Common.MemSet(gs, 0, sizeof(GameState));
            }

            this.parseEntitiesNum = 0;
            Common.MemSet(this.cmds, 0, sizeof(UserCommand) * UserCommand.CommandBackup);
            this.cmdNumber = 0;
            Common.MemSet(this.outPackets, 0, sizeof(OutPacket) * JKClient.PacketBackup);
            this.serverId = 0;
            Common.MemSet(this.snapshots, 0, sizeof(ClientSnapshot) * JKClient.PacketBackup);
            Common.MemSet(this.entityBaselines, 0, sizeof(EntityState) * Common.MaxGEntities);
            Common.MemSet(this.parseEntities, 0, sizeof(EntityState) * JKClient.MaxParseEntities);
            this.clientGame = null;
            this.ClientHandler.ClearState();
        }
コード例 #2
0
        private unsafe void ParseSnapshot(Message msg)
        {
            ClientSnapshot *oldSnap;
            var             oldSnapHandle = GCHandle.Alloc(this.snapshots, GCHandleType.Pinned);
            var             newSnap       = new ClientSnapshot()
            {
                ServerCommandNum = this.serverCommandSequence,
                ServerTime       = msg.ReadLong(),
                MessageNum       = this.serverMessageSequence
            };
            int deltaNum = msg.ReadByte();

            if (deltaNum == 0)
            {
                newSnap.DeltaNum = -1;
            }
            else
            {
                newSnap.DeltaNum = newSnap.MessageNum - deltaNum;
            }
            newSnap.Flags = msg.ReadByte();
            if (newSnap.DeltaNum <= 0)
            {
                newSnap.Valid = true;
                oldSnap       = null;
            }
            else
            {
                oldSnap = ((ClientSnapshot *)oldSnapHandle.AddrOfPinnedObject()) + (newSnap.DeltaNum & JKClient.PacketMask);
                if (!oldSnap->Valid)
                {
                }
                else if (oldSnap->MessageNum != newSnap.DeltaNum)
                {
                }
                else if (this.parseEntitiesNum - oldSnap->ParseEntitiesNum > JKClient.MaxParseEntities - 128)
                {
                }
                else
                {
                    newSnap.Valid = true;
                }
            }
            int len = msg.ReadByte();

            msg.ReadData(null, len);
            if (this.ClientHandler.CanParseSnapshot())
            {
                msg.ReadDeltaPlayerstate(oldSnap != null ? &oldSnap->PlayerState : null, &newSnap.PlayerState, false, this.ClientHandler);
                if (this.ClientHandler.CanParseVehicle && newSnap.PlayerState.VehicleNum != 0)
                {
                    msg.ReadDeltaPlayerstate(oldSnap != null ? &oldSnap->VehiclePlayerState : null, &newSnap.VehiclePlayerState, true, this.ClientHandler);
                }
                this.ParsePacketEntities(msg, oldSnap, &newSnap);
            }
            oldSnapHandle.Free();
            if (!newSnap.Valid)
            {
                return;
            }
            int oldMessageNum = this.snap.MessageNum + 1;

            if (newSnap.MessageNum - oldMessageNum >= JKClient.PacketBackup)
            {
                oldMessageNum = newSnap.MessageNum - JKClient.PacketMask;
            }
            for (; oldMessageNum < newSnap.MessageNum; oldMessageNum++)
            {
                this.snapshots[oldMessageNum & JKClient.PacketMask].Valid = false;
            }
            this.snap = newSnap;
            this.snapshots[this.snap.MessageNum & JKClient.PacketMask] = this.snap;
            this.newSnapshots = true;
        }