Example #1
0
        public static void UpdateViewAngles(ref Common.PlayerState ps, Input.UserCommand cmd)
        {
            if (ps.pm_type == Common.PMType.INTERMISSION || ps.pm_type == Common.PMType.SPINTERMISSION)
            {
                return;
            }

            //if (ps.pm_type != Common.PMType.SPECTATOR )//&& ps.stats[0] <= 0)
            //{
            //    return;
            //}

            // circularly clamp the angles with deltas
            short temp = (short)(cmd.anglex + ps.delta_angles[0]);
            // don't let the player look up or down more than 90 degrees
            if (temp > 16000)
            {
                ps.delta_angles[0] = 16000 - cmd.anglex;
                temp = 16000;
            }
            else if (temp < -16000)
            {
                ps.delta_angles[0] = -16000 - cmd.anglex;
                temp = -16000;
            }

            ps.viewangles[0] = temp * (360.0f / 65536);
            temp = (short)(cmd.angley + ps.delta_angles[1]);
            ps.viewangles[1] = temp * (360.0f / 65536);
            temp = (short)(cmd.anglez + ps.delta_angles[2]);
            ps.viewangles[2] = temp * (360.0f / 65536);
            //Common.Instance.WriteLine(ps.viewangles[0] + "\t:\t" + ps.viewangles[1]);
        }
Example #2
0
        /*
        ==================
        CL_DeltaEntity

        Parses deltas from the given base and adds the resulting entity
        to the current frame
        ==================
        */
        void DeltaEntity(NetBuffer msg, clSnapshot_t frame, int newnum, Common.entityState_t old, bool unchanged)
        {
            // save the parsed entity state into the big circular buffer so
            // it can be used as the source for a later delta
            Common.entityState_t state = cl.parseEntities[cl.parseEntitiesNum & 2047];
            if (unchanged)
                state = old;
            else
                Net.Instance.MSG_ReadDeltaEntity(msg, ref old, ref state, newnum);

            cl.parseEntities[cl.parseEntitiesNum & 2047] = state;

            if (state.number == 1023)
                return; // entity was delta removed

            cl.parseEntitiesNum++;
            frame.numEntities++;
        }
Example #3
0
        public static void PlayerStateToEntityState(Common.PlayerState ps, Common.entityState_t s, bool snap)
        {
            if (ps.pm_type == Common.PMType.INTERMISSION || ps.pm_type == Common.PMType.SPECTATOR)
                s.eType = 10; // ET_INVISIBLE
            else
                s.eType = 1; // ET_PLAYER

            s.number = ps.clientNum;
            s.pos.trType = Common.trType_t.TR_INTERPOLATE;
            s.pos.trBase = ps.origin;
            if (snap)
            {
                s.pos.trBase = SnapVector(s.pos.trBase);
            }

            // set the trDelta for flag direction
            s.pos.trDelta = ps.velocity;

            s.apos.trType = Common.trType_t.TR_INTERPOLATE;
            s.apos.trBase = ps.viewangles;
            if (snap)
            {
                s.apos.trBase = SnapVector(s.apos.trBase);
            }

            s.angles2[1] = ps.movementDir;
            //s.legsAnim = ps.legsAnim;
            //s.torsoAnim = ps.torsoAnim;
            s.clientNum = ps.clientNum; // ET_PLAYER looks here instead of at number
            // so corpses can also reference the proper config
            s.eFlags = ps.eFlags;

            // FIX: Add event

            //s.weapon = ps.weapon;
            s.groundEntityNum = ps.groundEntityNum;
            //s.powerups = 0;
            //s.loopSound = ps.loopSound;
            //s.generic1 = ps.generic1;
        }
Example #4
0
        void TransitionPlayerState(Common.PlayerState ps, Common.PlayerState ops)
        {
            // check for changing follow mode
            if (ps.clientNum != ops.clientNum)
            {
                cg.thisFrameTeleport = true;
                // make sure we don't get any unwanted transition effects
                ops = ps;
            }

            // damage events (player is getting wounded)
            //if (ps.damageEvent != ops.damageEvent && ps.damageCount != 0)
            {
                // Todo: DamageFeedback
            }

            // respawning
            if (ps.persistant[4] != ops.persistant[4])
            {
                // Todo: Respawn
                Respawn();
            }

            if (cg.snap.ps.pm_type != Common.PMType.INTERMISSION && ps.persistant[3] != 3)
            {
                // ? Check localsounds
            }

            // Check ammo

            // run events

            // smooth the ducking viewheight change
            if (ps.viewheight != ops.viewheight)
            {
                cg.duckChange = ps.viewheight - ops.viewheight;
                cg.duckTime = cg.time;
            }
        }
Example #5
0
        /*
        ==================
        MSG_WriteDeltaEntity

        Writes part of a packetentities message, including the entity number.
        Can delta from either a baseline or a previous packet_entity
        If to is NULL, a remove entity update will be sent
        If force is not set, then nothing at all will be generated if the entity is
        identical, under the assumption that the in-order delta code will catch it.
        ==================
        */
        public void MSG_WriteDeltaEntity(NetBuffer msg, ref Common.entityState_t from, ref Common.entityState_t to, bool force)
        {
            int msgStart = msg.LengthBits;
            // a NULL to is a delta remove message
            if (to == null)
            {
                if (from == null)
                    return;
                msg.Write(from.number);
                msg.Write(true);
                return;
            }

            if (to.number < 0 || to.number >= 1024)
            {
                Common.Instance.Error("MSG_WriteDeltaEntity: Bad entity number: " + to.number);
            }

            NetBuffer buf = new NetBuffer();
            //NetBuffer buf = msg;
            int lc = 0;
            //if (from.number != to.number) { lc = 1; buf.Write(true); buf.Write(to.number); } else { buf.Write(false); }
            if (from.eType != to.eType) { lc = 2; buf.Write(true); buf.Write(to.eType); } else { buf.Write(false); }
            if (from.eFlags != to.eFlags) { lc = 3; buf.Write(true); buf.Write((int)to.eFlags); } else { buf.Write(false); }
            int middle = buf.LengthBits;
            if (from.pos.trBase.X != to.pos.trBase.X) { lc = 4; buf.Write(true); buf.Write(to.pos.trBase.X); } else { buf.Write(false); }
            if (from.pos.trBase.Y != to.pos.trBase.Y) { lc = 5; buf.Write(true); buf.Write(to.pos.trBase.Y); } else { buf.Write(false); }
            if (from.pos.trBase.Z != to.pos.trBase.Z) { lc = 6; buf.Write(true); buf.Write(to.pos.trBase.Z); } else { buf.Write(false); }
            if (from.pos.trDelta.X != to.pos.trDelta.X) {
                lc = 7; buf.Write(true); buf.Write(to.pos.trDelta.X); } else { buf.Write(false); }
            if (from.pos.trDelta.Y != to.pos.trDelta.Y) { lc = 8; buf.Write(true); buf.Write(to.pos.trDelta.Y); } else { buf.Write(false); }
            if (from.pos.trDelta.Z != to.pos.trDelta.Z) { lc = 9; buf.Write(true); buf.Write(to.pos.trDelta.Z); } else { buf.Write(false); }
            if (from.pos.trDuration != to.pos.trDuration) { lc = 10; buf.Write(true); buf.Write(to.pos.trDuration); } else { buf.Write(false); }
            if (from.pos.trTime != to.pos.trTime) { lc = 11; buf.Write(true); buf.Write(to.pos.trTime); } else { buf.Write(false); }
            if (from.pos.trType != to.pos.trType) { lc = 12; buf.Write(true); buf.Write((int)to.pos.trType); } else { buf.Write(false); }

            if (from.apos.trBase.X != to.apos.trBase.X) { lc = 13; buf.Write(true); buf.Write(to.apos.trBase.X); } else { buf.Write(false); }
            if (from.apos.trBase.Y != to.apos.trBase.Y) { lc = 14; buf.Write(true); buf.Write(to.apos.trBase.Y); } else { buf.Write(false); }
            if (from.apos.trBase.Z != to.apos.trBase.Z) { lc = 15; buf.Write(true); buf.Write(to.apos.trBase.Z); } else { buf.Write(false); }
            if (from.apos.trDelta.X != to.apos.trDelta.X) { lc = 16; buf.Write(true); buf.Write(to.apos.trDelta.X); } else { buf.Write(false); }
            if (from.apos.trDelta.Y != to.apos.trDelta.Y) { lc = 17; buf.Write(true); buf.Write(to.apos.trDelta.Y); } else { buf.Write(false); }
            if (from.apos.trDelta.Z != to.apos.trDelta.Z) { lc = 18; buf.Write(true); buf.Write(to.apos.trDelta.Z); } else { buf.Write(false); }
            if (from.apos.trDuration != to.apos.trDuration) { lc = 19; buf.Write(true); buf.Write(to.apos.trDuration); } else { buf.Write(false); }
            if (from.apos.trTime != to.apos.trTime) { lc = 20; buf.Write(true); buf.Write(to.apos.trTime); } else { buf.Write(false); }
            if (from.apos.trType != to.apos.trType) { lc = 21; buf.Write(true); buf.Write((int)to.apos.trType); } else { buf.Write(false); }

            if (from.time != to.time) { lc = 22; buf.Write(true); buf.Write(to.time); } else { buf.Write(false); }
            if (from.time2 != to.time2) { lc = 23; buf.Write(true); buf.Write(to.time2); } else { buf.Write(false); }

            if (from.origin.X != to.origin.X) { lc = 24; buf.Write(true); buf.Write(to.origin.X); } else { buf.Write(false); }
            if (from.origin.Y != to.origin.Y) { lc = 25; buf.Write(true); buf.Write(to.origin.Y); } else { buf.Write(false); }
            if (from.origin.Z != to.origin.Z) { lc = 26; buf.Write(true); buf.Write(to.origin.Z); } else { buf.Write(false); }
            if (from.origin2.X != to.origin2.X) { lc = 27; buf.Write(true); buf.Write(to.origin2.X); } else { buf.Write(false); }
            if (from.origin2.Y != to.origin2.Y) { lc = 28; buf.Write(true); buf.Write(to.origin2.Y); } else { buf.Write(false); }
            if (from.origin2.Z != to.origin2.Z) { lc = 29; buf.Write(true); buf.Write(to.origin2.Z); } else { buf.Write(false); }

            if (from.angles.X != to.angles.X) { lc = 30; buf.Write(true); buf.Write(to.angles.X); } else { buf.Write(false); }
            if (from.angles.Y != to.angles.Y) { lc = 31; buf.Write(true); buf.Write(to.angles.Y); } else { buf.Write(false); }
            if (from.angles.Z != to.angles.Z) { lc = 32; buf.Write(true); buf.Write(to.angles.Z); } else { buf.Write(false); }
            if (from.angles2.X != to.angles2.X) { lc = 33; buf.Write(true); buf.Write(to.angles2.X); } else { buf.Write(false); }
            if (from.angles2.Y != to.angles2.Y) { lc = 34; buf.Write(true); buf.Write(to.angles2.Y); } else { buf.Write(false); }
            if (from.angles2.Z != to.angles2.Z) { lc = 35; buf.Write(true); buf.Write(to.angles2.Z); } else { buf.Write(false); }

            if (from.otherEntityNum != to.otherEntityNum) { lc = 36; buf.Write(true); buf.Write(to.otherEntityNum); } else { buf.Write(false); }
            if (from.otherEntityNum2 != to.otherEntityNum2) { lc = 37; buf.Write(true); buf.Write(to.otherEntityNum2); } else { buf.Write(false); }

            if (from.groundEntityNum != to.groundEntityNum) { lc = 38; buf.Write(true); buf.Write(to.groundEntityNum); } else { buf.Write(false); }

            if (from.modelindex != to.modelindex) { lc = 39; buf.Write(true); buf.Write(to.modelindex); } else { buf.Write(false); }
            if (from.clientNum != to.clientNum) { lc = 40; buf.Write(true); buf.Write(to.clientNum); } else { buf.Write(false); }
            if (from.frame != to.frame) { lc = 41; buf.Write(true); buf.Write(to.frame); } else { buf.Write(false); }

            if (from.solid != to.solid) { lc = 42; buf.Write(true); buf.Write(to.solid); } else { buf.Write(false); }
            if (from.generic1 != to.generic1) { lc = 43; buf.Write(true); buf.Write(to.generic1); } else { buf.Write(false); }

            if (lc == 0)
            {
                // nothing at all changed
                if (!force)
                {
                    return;		// nothing at all
                }
                // write two bits for no change
                msg.Write(to.number);
                msg.Write(false);   // not removed
                msg.Write(false);   // no delta
                return;
            }

            msg.Write(to.number);
            msg.Write(false);   // not removed
            msg.Write(true);    // we have a delta

            //msg.Write(lc);  // # of changes
            //msg.CopyFrom(buf);
            int msgPos = msg.LengthBits;
            //msg.Write(buf.Data);
            WriteDeltaEntityHags(msg, ref  from,ref  to);
            msg.Write(buf.LengthBits);

            //Common.Instance.WriteLine("MSG_WriteDeltaEntity: Wrote {0} bits", msg.LengthBits - msgStart);
        }
Example #6
0
        /*
        ==================
        MSG_ReadDeltaEntity

        The entity number has already been read from the message, which
        is how the from state is identified.

        If the delta removes the entity, entityState_t->number will be set to MAX_GENTITIES-1

        Can go from either a baseline or a previous packet_entity
        ==================
        */
        public void MSG_ReadDeltaEntity(NetBuffer msg, ref Common.entityState_t from, ref Common.entityState_t to, int number)
        {
            int startBit = msg.Position-32;
            if (number < 0 || number >= 1024)
            {
                Common.Instance.Error("ReadDeltaEntity: number < 0 || number >= 1024");
            }

            // Check for remove
            if (msg.ReadBoolean())
            {
                to = new Common.entityState_t();
                to.number = 1023;
                Common.Instance.WriteLine("Removed entity: {0}", number);
                return;
            }

            // Check for no delta
            if (!msg.ReadBoolean())
            {
                to = from;
                to.number = number;
                return;
            }

            to.number = number;
            int dataStart = msg.Position;
            to.eType = msg.ReadBoolean() ? msg.ReadInt32() : from.eType;
            to.eFlags = msg.ReadBoolean() ? (Common.EntityFlags)msg.ReadInt32() : from.eFlags;
            int middle = msg.Position;
            to.pos.trBase.X = msg.ReadBoolean() ? msg.ReadFloat() : from.pos.trBase.X;
            to.pos.trBase.Y = msg.ReadBoolean() ? msg.ReadFloat() : from.pos.trBase.Y;
            to.pos.trBase.Z = msg.ReadBoolean() ? msg.ReadFloat() : from.pos.trBase.Z;
            to.pos.trDelta.X = msg.ReadBoolean() ? msg.ReadFloat() : from.pos.trDelta.X;
            to.pos.trDelta.Y = msg.ReadBoolean() ? msg.ReadFloat() : from.pos.trDelta.Y;
            to.pos.trDelta.Z = msg.ReadBoolean() ? msg.ReadFloat() : from.pos.trDelta.Z;
            to.pos.trDuration = msg.ReadBoolean() ? msg.ReadInt32() : from.pos.trDuration;
            to.pos.trTime = msg.ReadBoolean() ? msg.ReadInt32() : from.pos.trTime;
            to.pos.trType = msg.ReadBoolean() ? (Common.trType_t)msg.ReadInt32() : from.pos.trType;

            to.apos.trBase.X = msg.ReadBoolean() ? msg.ReadFloat() : from.apos.trBase.X;
            to.apos.trBase.Y = msg.ReadBoolean() ? msg.ReadFloat() : from.apos.trBase.Y;
            to.apos.trBase.Z = msg.ReadBoolean() ? msg.ReadFloat() : from.apos.trBase.Z;
            to.apos.trDelta.X = msg.ReadBoolean() ? msg.ReadFloat() : from.apos.trDelta.X;
            to.apos.trDelta.Y = msg.ReadBoolean() ? msg.ReadFloat() : from.apos.trDelta.Y;
            to.apos.trDelta.Z = msg.ReadBoolean() ? msg.ReadFloat() : from.apos.trDelta.Z;
            to.apos.trDuration = msg.ReadBoolean() ? msg.ReadInt32() : from.apos.trDuration;
            to.apos.trTime = msg.ReadBoolean() ? msg.ReadInt32() : from.apos.trTime;
            to.apos.trType = msg.ReadBoolean() ? (Common.trType_t)msg.ReadInt32() : from.apos.trType;

            to.time = msg.ReadBoolean() ? msg.ReadInt32() : from.time;
            to.time2 = msg.ReadBoolean() ? msg.ReadInt32() : from.time2;

            to.origin.X = msg.ReadBoolean() ? msg.ReadFloat() : from.origin.X;
            to.origin.Y = msg.ReadBoolean() ? msg.ReadFloat() : from.origin.Y;
            to.origin.Z = msg.ReadBoolean() ? msg.ReadFloat() : from.origin.Z;
            to.origin2.X = msg.ReadBoolean() ? msg.ReadFloat() : from.origin2.X;
            to.origin2.Y = msg.ReadBoolean() ? msg.ReadFloat() : from.origin2.Y;
            to.origin2.Z = msg.ReadBoolean() ? msg.ReadFloat() : from.origin2.Z;

            to.angles.X = msg.ReadBoolean() ? msg.ReadFloat() : from.angles.X;
            to.angles.Y = msg.ReadBoolean() ? msg.ReadFloat() : from.angles.Y;
            to.angles.Z = msg.ReadBoolean() ? msg.ReadFloat() : from.angles.Z;
            to.angles2.X = msg.ReadBoolean() ? msg.ReadFloat() : from.angles2.X;
            to.angles2.Y = msg.ReadBoolean() ? msg.ReadFloat() : from.angles2.Y;
            to.angles2.Z = msg.ReadBoolean() ? msg.ReadFloat() : from.angles2.Z;

            to.otherEntityNum = msg.ReadBoolean() ? msg.ReadInt32() : from.otherEntityNum;
            to.otherEntityNum2 = msg.ReadBoolean() ? msg.ReadInt32() : from.otherEntityNum2;
            to.groundEntityNum = msg.ReadBoolean() ? msg.ReadInt32() : from.groundEntityNum;

            to.modelindex = msg.ReadBoolean() ? msg.ReadInt32() : from.modelindex;
            to.clientNum = msg.ReadBoolean() ? msg.ReadInt32() : from.clientNum;
            to.frame = msg.ReadBoolean() ? msg.ReadInt32() : from.frame;
            to.solid = msg.ReadBoolean() ? msg.ReadInt32() : from.solid;
            to.generic1 = msg.ReadBoolean() ? msg.ReadInt32() : from.generic1;
            int lenghtBits = msg.ReadInt32();

            dataStart = msg.Position - dataStart;
            lenghtBits -= dataStart;
            for (int i = 0; i < lenghtBits; i++)
            {
                msg.ReadBoolean();
            }
            middle = msg.Position - middle;

            //Common.Instance.WriteLine("MSG_ReadDeltaEntity: Read {0} bits", msg.Position - startBit);
        }
Example #7
0
        public static void WriteDeltaPlayerstate(NetBuffer msg, Common.PlayerState from, Common.PlayerState to)
        {
            int msgStart = msg.LengthBits;
            if (from == null)
                from = new Common.PlayerState();

            if (from.commandTime != to.commandTime) { msg.Write(true); msg.Write(to.commandTime); } else { msg.Write(false); }
            if (from.pm_type != to.pm_type) { msg.Write(true); msg.Write((int)to.pm_type); } else { msg.Write(false); }
            if (from.pm_flags != to.pm_flags) { msg.Write(true); msg.Write((int)to.pm_flags); } else { msg.Write(false); }
            if (from.pm_time != to.pm_time) { msg.Write(true); msg.Write(to.pm_time); } else { msg.Write(false); }
            if (from.origin.X != to.origin.X) { msg.Write(true); msg.Write(to.origin.X); } else { msg.Write(false); }
            if (from.origin.Y != to.origin.Y)
            { msg.Write(true); msg.Write(to.origin.Y); }
            else
            { msg.Write(false); }
            if (from.origin.Z != to.origin.Z) { msg.Write(true); msg.Write(to.origin.Z); } else { msg.Write(false); }
            if (from.velocity.X != to.velocity.X) { msg.Write(true); msg.Write(to.velocity.X); } else { msg.Write(false); }
            if (from.velocity.Y != to.velocity.Y) { msg.Write(true); msg.Write(to.velocity.Y); } else { msg.Write(false); }
            if (from.velocity.Z != to.velocity.Z) { msg.Write(true); msg.Write(to.velocity.Z); } else { msg.Write(false); }

            if (from.weaponTime != to.weaponTime) { msg.Write(true); msg.Write(to.weaponTime); } else { msg.Write(false); }
            if (from.gravity != to.gravity) { msg.Write(true); msg.Write(to.gravity); } else { msg.Write(false); }
            if (from.delta_angles[0] != to.delta_angles[0]) { msg.Write(true); msg.Write(to.delta_angles[0]); } else { msg.Write(false); }
            if (from.delta_angles[1] != to.delta_angles[1]) { msg.Write(true); msg.Write(to.delta_angles[1]); } else { msg.Write(false); }
            if (from.delta_angles[2] != to.delta_angles[2]) { msg.Write(true); msg.Write(to.delta_angles[2]); } else { msg.Write(false); }
            if (from.groundEntityNum != to.groundEntityNum) { msg.Write(true); msg.Write(to.groundEntityNum); } else { msg.Write(false); }
            if (from.movementDir != to.movementDir) { msg.Write(true); msg.Write(to.movementDir); } else { msg.Write(false); }
            if (from.ladderNormal.X != to.ladderNormal.X) { msg.Write(true); msg.Write(to.ladderNormal.X); } else { msg.Write(false); }
            if (from.ladderNormal.Y != to.ladderNormal.Y) { msg.Write(true); msg.Write(to.ladderNormal.Y); } else { msg.Write(false); }
            if (from.ladderNormal.Z != to.ladderNormal.Z) { msg.Write(true); msg.Write(to.ladderNormal.Z); } else { msg.Write(false); }
            if (from.speed != to.speed) { msg.Write(true); msg.Write(from.speed); } else { msg.Write(false); }

            if (from.eFlags != to.eFlags) { msg.Write(true); msg.Write((int)to.eFlags); } else { msg.Write(false); }
            if (from.eventSequence != to.eventSequence) { msg.Write(true); msg.Write(to.eventSequence); } else { msg.Write(false); }
            if (from.events[0] != to.events[0]) { msg.Write(true); msg.Write(to.events[0]); } else { msg.Write(false); }
            if (from.events[1] != to.events[1]) { msg.Write(true); msg.Write(to.events[1]); } else { msg.Write(false); }
            if (from.eventParms[0] != to.eventParms[0]) { msg.Write(true); msg.Write(to.eventParms[0]); } else { msg.Write(false); }
            if (from.eventParms[1] != to.eventParms[1]) { msg.Write(true); msg.Write(to.eventParms[1]); } else { msg.Write(false); }
            if (from.externalEvent != to.externalEvent) { msg.Write(true); msg.Write(to.externalEvent); } else { msg.Write(false); }
            if (from.externalEventParm != to.externalEventParm) { msg.Write(true); msg.Write(to.externalEventParm); } else { msg.Write(false); }
            if (from.externalEventTime != to.externalEventTime) { msg.Write(true); msg.Write(to.externalEventTime); } else { msg.Write(false); }
            if (from.clientNum != to.clientNum) { msg.Write(true); msg.Write(to.clientNum); } else { msg.Write(false); }
            if (from.viewangles.X != to.viewangles.X) { msg.Write(true); msg.Write(to.viewangles.X); } else { msg.Write(false); }
            if (from.viewangles.Y != to.viewangles.Y) { msg.Write(true); msg.Write(to.viewangles.Y); } else { msg.Write(false); }
            if (from.viewangles.Z != to.viewangles.Z) { msg.Write(true); msg.Write(to.viewangles.Z); } else { msg.Write(false); }
            if (from.viewheight != to.viewheight) { msg.Write(true); msg.Write(to.viewheight); } else { msg.Write(false); }
            if (from.generic1 != to.generic1) { msg.Write(true); msg.Write(to.generic1); } else { msg.Write(false); }
            if (from.bobCycle != to.bobCycle) { msg.Write(true); msg.Write(to.bobCycle); } else { msg.Write(false); }

            if (from.Ducked != to.Ducked) { msg.Write(true); msg.Write(to.Ducked); } else { msg.Write(false); }
            if (from.Ducking != to.Ducking) { msg.Write(true); msg.Write(to.Ducking); } else { msg.Write(false); }
            if (from.DuckTime != to.DuckTime) { msg.Write(true); msg.Write(to.DuckTime); } else { msg.Write(false); }
            if (from.OldButtons != to.OldButtons) { msg.Write(true); msg.Write(to.OldButtons); } else { msg.Write(false); }

            //
            // send the arrays
            //
            int statbits = 0;
            for (int i = 0; i < 16; i++)
            {
                if (from.stats[i] != to.stats[i])
                    statbits |= 1 << i;
            }

            int persbits = 0;
            for (int i = 0; i < 16; i++)
            {
                if (from.persistant[i] != to.persistant[i])
                    persbits |= 1 << i;
            }

            if (persbits == statbits && statbits == 0)
            {
                // no change
                msg.Write(false);
                return;
            }
            msg.Write(true);
            if (statbits > 0)
            {
                msg.Write(true);
                msg.Write(statbits);
                for (int i = 0; i < 16; i++)
                {
                    if ((statbits & (1 << i)) == (1 << i))
                    {
                        msg.Write((short)to.stats[i]);
                    }
                }
            }
            else
                msg.Write(false);
            int msgMiddle = msg.LengthBits;
            if (persbits > 0)
            {
                msg.Write(true);
                msg.Write(persbits);
                for (int i = 0; i < 16; i++)
                {
                    if ((persbits & (1 << i)) == (1 << i))
                    {
                        msg.Write((short)to.persistant[i]);
                    }
                }
            }
            else
                msg.Write(false);

               // System.Console.WriteLine("Wrote {0}bits snapshot, {1} middle", msg.LengthBits - msgStart, msgMiddle - msgStart);
        }
Example #8
0
        public static void WriteDeltaEntityHags(NetBuffer buf, ref Common.entityState_t from, ref Common.entityState_t to)
        {
            int lc = 0;
            if (from.eType != to.eType) { lc = 2; buf.Write(true); buf.Write(to.eType); } else { buf.Write(false); }
            if (from.eFlags != to.eFlags) { lc = 3; buf.Write(true); buf.Write((int)to.eFlags); } else { buf.Write(false); }
            int middle = buf.LengthBits;
            if (from.pos.trBase.X != to.pos.trBase.X) { lc = 4; buf.Write(true); buf.Write(to.pos.trBase.X); } else { buf.Write(false); }
            if (from.pos.trBase.Y != to.pos.trBase.Y) { lc = 5; buf.Write(true); buf.Write(to.pos.trBase.Y); } else { buf.Write(false); }
            if (from.pos.trBase.Z != to.pos.trBase.Z) { lc = 6; buf.Write(true); buf.Write(to.pos.trBase.Z); } else { buf.Write(false); }
            if (from.pos.trDelta.X != to.pos.trDelta.X) { lc = 7; buf.Write(true); buf.Write(to.pos.trDelta.X); } else { buf.Write(false); }
            if (from.pos.trDelta.Y != to.pos.trDelta.Y) { lc = 8; buf.Write(true); buf.Write(to.pos.trDelta.Y); } else { buf.Write(false); }
            if (from.pos.trDelta.Z != to.pos.trDelta.Z) { lc = 9; buf.Write(true); buf.Write(to.pos.trDelta.Z); } else { buf.Write(false); }
            if (from.pos.trDuration != to.pos.trDuration) { lc = 10; buf.Write(true); buf.Write(to.pos.trDuration); } else { buf.Write(false); }
            if (from.pos.trTime != to.pos.trTime) { lc = 11; buf.Write(true); buf.Write(to.pos.trTime); } else { buf.Write(false); }
            if (from.pos.trType != to.pos.trType) { lc = 12; buf.Write(true); buf.Write((int)to.pos.trType); } else { buf.Write(false); }

            if (from.apos.trBase.X != to.apos.trBase.X) { lc = 13; buf.Write(true); buf.Write(to.apos.trBase.X); } else { buf.Write(false); }
            if (from.apos.trBase.Y != to.apos.trBase.Y) { lc = 14; buf.Write(true); buf.Write(to.apos.trBase.Y); } else { buf.Write(false); }
            if (from.apos.trBase.Z != to.apos.trBase.Z) { lc = 15; buf.Write(true); buf.Write(to.apos.trBase.Z); } else { buf.Write(false); }
            if (from.apos.trDelta.X != to.apos.trDelta.X) { lc = 16; buf.Write(true); buf.Write(to.apos.trDelta.X); } else { buf.Write(false); }
            if (from.apos.trDelta.Y != to.apos.trDelta.Y) { lc = 17; buf.Write(true); buf.Write(to.apos.trDelta.Y); } else { buf.Write(false); }
            if (from.apos.trDelta.Z != to.apos.trDelta.Z) { lc = 18; buf.Write(true); buf.Write(to.apos.trDelta.Z); } else { buf.Write(false); }
            if (from.apos.trDuration != to.apos.trDuration) { lc = 19; buf.Write(true); buf.Write(to.apos.trDuration); } else { buf.Write(false); }
            if (from.apos.trTime != to.apos.trTime) { lc = 20; buf.Write(true); buf.Write(to.apos.trTime); } else { buf.Write(false); }
            if (from.apos.trType != to.apos.trType) { lc = 21; buf.Write(true); buf.Write((int)to.apos.trType); } else { buf.Write(false); }

            if (from.time != to.time) { lc = 22; buf.Write(true); buf.Write(to.time); } else { buf.Write(false); }
            if (from.time2 != to.time2) { lc = 23; buf.Write(true); buf.Write(to.time2); } else { buf.Write(false); }

            if (from.origin.X != to.origin.X) { lc = 24; buf.Write(true); buf.Write(to.origin.X); } else { buf.Write(false); }
            if (from.origin.Y != to.origin.Y) { lc = 25; buf.Write(true); buf.Write(to.origin.Y); } else { buf.Write(false); }
            if (from.origin.Z != to.origin.Z) { lc = 26; buf.Write(true); buf.Write(to.origin.Z); } else { buf.Write(false); }
            if (from.origin2.X != to.origin2.X) { lc = 27; buf.Write(true); buf.Write(to.origin2.X); } else { buf.Write(false); }
            if (from.origin2.Y != to.origin2.Y) { lc = 28; buf.Write(true); buf.Write(to.origin2.Y); } else { buf.Write(false); }
            if (from.origin2.Z != to.origin2.Z) { lc = 29; buf.Write(true); buf.Write(to.origin2.Z); } else { buf.Write(false); }

            if (from.angles.X != to.angles.X) { lc = 30; buf.Write(true); buf.Write(to.angles.X); } else { buf.Write(false); }
            if (from.angles.Y != to.angles.Y) { lc = 31; buf.Write(true); buf.Write(to.angles.Y); } else { buf.Write(false); }
            if (from.angles.Z != to.angles.Z) { lc = 32; buf.Write(true); buf.Write(to.angles.Z); } else { buf.Write(false); }
            if (from.angles2.X != to.angles2.X) { lc = 33; buf.Write(true); buf.Write(to.angles2.X); } else { buf.Write(false); }
            if (from.angles2.Y != to.angles2.Y) { lc = 34; buf.Write(true); buf.Write(to.angles2.Y); } else { buf.Write(false); }
            if (from.angles2.Z != to.angles2.Z) { lc = 35; buf.Write(true); buf.Write(to.angles2.Z); } else { buf.Write(false); }

            if (from.otherEntityNum != to.otherEntityNum) { lc = 36; buf.Write(true); buf.Write(to.otherEntityNum); } else { buf.Write(false); }
            if (from.otherEntityNum2 != to.otherEntityNum2) { lc = 37; buf.Write(true); buf.Write(to.otherEntityNum2); } else { buf.Write(false); }

            if (from.groundEntityNum != to.groundEntityNum) { lc = 38; buf.Write(true); buf.Write(to.groundEntityNum); } else { buf.Write(false); }

            if (from.modelindex != to.modelindex) { lc = 39; buf.Write(true); buf.Write(to.modelindex); } else { buf.Write(false); }
            if (from.clientNum != to.clientNum) { lc = 40; buf.Write(true); buf.Write(to.clientNum); } else { buf.Write(false); }
            if (from.frame != to.frame) { lc = 41; buf.Write(true); buf.Write(to.frame); } else { buf.Write(false); }

            if (from.solid != to.solid) { lc = 42; buf.Write(true); buf.Write(to.solid); } else { buf.Write(false); }
            if (from.generic1 != to.generic1) { lc = 43; buf.Write(true); buf.Write(to.generic1); } else { buf.Write(false); }
        }
Example #9
0
        public static void ReadDeltaPlayerstate(NetBuffer msg, Common.PlayerState from, Common.PlayerState to)
        {
            int startoffset = msg.Position;
            if (from == null)
                from = new Common.PlayerState();

            to.commandTime = msg.ReadBoolean() ? msg.ReadInt32() : from.commandTime;
            to.pm_type = msg.ReadBoolean() ? (Common.PMType)msg.ReadInt32() : from.pm_type;
            to.pm_flags = msg.ReadBoolean() ? (client.PMFlags)msg.ReadInt32() : from.pm_flags;
            to.pm_time = msg.ReadBoolean() ? msg.ReadInt32() : from.pm_time;
            to.origin.X = msg.ReadBoolean() ? msg.ReadFloat() : from.origin.X;
            to.origin.Y = msg.ReadBoolean() ? msg.ReadFloat() : from.origin.Y;
            to.origin.Z = msg.ReadBoolean() ? msg.ReadFloat() : from.origin.Z;
            to.velocity.X = msg.ReadBoolean() ? msg.ReadFloat() : from.velocity.X;
            to.velocity.Y = msg.ReadBoolean() ? msg.ReadFloat() : from.velocity.Y;
            to.velocity.Z = msg.ReadBoolean() ? msg.ReadFloat() : from.velocity.Z;
            to.weaponTime = msg.ReadBoolean() ? msg.ReadInt32() : from.weaponTime;
            to.gravity = msg.ReadBoolean() ? msg.ReadInt32() : from.gravity;
            to.delta_angles[0] = msg.ReadBoolean() ? msg.ReadInt32() : from.delta_angles[0];
            to.delta_angles[1] = msg.ReadBoolean() ? msg.ReadInt32() : from.delta_angles[1];
            to.delta_angles[2] = msg.ReadBoolean() ? msg.ReadInt32() : from.delta_angles[2];
            to.groundEntityNum = msg.ReadBoolean() ? msg.ReadInt32() : from.groundEntityNum;
            to.movementDir = msg.ReadBoolean() ? msg.ReadInt32() : from.movementDir;
            to.ladderNormal.X = msg.ReadBoolean() ? msg.ReadFloat() : from.ladderNormal.X;
            to.ladderNormal.Y = msg.ReadBoolean() ? msg.ReadFloat() : from.ladderNormal.Y;
            to.ladderNormal.Z = msg.ReadBoolean() ? msg.ReadFloat() : from.ladderNormal.Z;
            to.speed = msg.ReadBoolean() ? msg.ReadInt32() : from.speed;
            to.eFlags = msg.ReadBoolean() ? (Common.EntityFlags)Enum.Parse(typeof(Common.EntityFlags), ""+msg.ReadInt32()) : from.eFlags;
            to.eventSequence = msg.ReadBoolean() ? msg.ReadInt32() : from.eventSequence;
            to.events[0] = msg.ReadBoolean() ? msg.ReadInt32() : from.events[0];
            to.events[1] = msg.ReadBoolean() ? msg.ReadInt32() : from.events[1];
            to.eventParms[0] = msg.ReadBoolean() ? msg.ReadInt32() : from.eventParms[0];
            to.eventParms[1] = msg.ReadBoolean() ? msg.ReadInt32() : from.eventParms[1];
            to.externalEvent = msg.ReadBoolean() ? msg.ReadInt32() : from.externalEvent;
            to.externalEventParm = msg.ReadBoolean() ? msg.ReadInt32() : from.externalEventParm;
            to.externalEventTime = msg.ReadBoolean() ? msg.ReadInt32() : from.externalEventTime;
            to.clientNum = msg.ReadBoolean() ? msg.ReadInt32() : from.clientNum;
            to.viewangles.X = msg.ReadBoolean() ? msg.ReadFloat() : from.viewangles.X;
            to.viewangles.Y = msg.ReadBoolean() ? msg.ReadFloat() : from.viewangles.Y;
            to.viewangles.Z = msg.ReadBoolean() ? msg.ReadFloat() : from.viewangles.Z;
            to.viewheight = msg.ReadBoolean() ? msg.ReadInt32() : from.viewheight;
            //if (to.viewheight == 16)
            //{
            //    int test = 2;
            //}
            to.generic1 = msg.ReadBoolean() ? msg.ReadInt32() : from.generic1;
            to.bobCycle = msg.ReadBoolean() ? msg.ReadInt32() : from.bobCycle;

            to.Ducked = msg.ReadBoolean() ? msg.ReadBoolean() : from.Ducked;
            to.Ducking = msg.ReadBoolean() ? msg.ReadBoolean() : from.Ducking;
            to.DuckTime = msg.ReadBoolean() ? msg.ReadInt32() : from.DuckTime;
            to.OldButtons = msg.ReadBoolean() ? msg.ReadInt32() : from.OldButtons;

            // Got diff arrays

            int msgMiddle = 99999;
            if (msg.ReadBoolean())
            {
                if (msg.ReadBoolean())
                {
                    // stat
                    int statbits = msg.ReadInt32();
                    for (int i = 0; i < 16; i++)
                    {
                        if ((statbits & (1 << i)) == (1 << i))
                        {
                            to.stats[i] = msg.ReadInt16();
                        }
                        else
                            to.stats[i] = from.stats[i];
                    }
                }
                else
                    to.stats = from.stats;
                msgMiddle = msg.Position;
                if (msg.ReadBoolean())
                {
                    // pers
                    int persbits = msg.ReadInt32();
                    for (int i = 0; i < 16; i++)
                    {
                        if ((persbits & (1 << i)) == (1 << i))
                        {
                            to.persistant[i] = msg.ReadInt16();
                        }
                        else
                            to.persistant[i] = from.persistant[i];
                    }
                }
                else
                    to.persistant = from.persistant;
            }
            else
            {
                to.stats = from.stats;
                to.persistant = from.persistant;
            }

            //System.Console.WriteLine("Read {0}bits snapshot, {1} middle", msg.Position - startoffset, msgMiddle - startoffset);
        }
Example #10
0
 private void SendPredictableEvents(Common.PlayerState ps)
 {
     // if there are still events pending
     if (ps.entityEventSequence < ps.eventSequence)
     {
         // create a temporary entity for this event which is sent to everyone
         // except the client who generated the event
         int seq = ps.entityEventSequence & 1;
         int evt = ps.events[seq] | ((ps.entityEventSequence & 3) << 8);
         // set external event to zero before calling BG_PlayerStateToEntityState
         int extEvent = ps.externalEvent;
         ps.externalEvent = 0;
         // create temporary entity for event
         gentity_t t = TempEntity(ps.origin, evt);
         int number = t.s.number;
         CGame.PlayerStateToEntityState(ps, t.s, true);
         t.s.number = number;
         t.s.eType = 13 + evt;
         t.s.eFlags |= Common.EntityFlags.EF_BOUNCE;
         t.s.otherEntityNum = ps.clientNum;
         // send to everyone except the client who generated the event
         t.r.svFlags |= Common.svFlags.NOTSINGLECLIENT;
         t.r.singleClient = ps.clientNum;
         // set back external event
         ps.externalEvent = extEvent;
     }
 }