shithub: choc

Download patch

ref: baef203819ad5490809712332340f6fddf3c9f56
parent: c1e37f1955a0c546a795484acc92510e4c4dc6b2
author: Simon Howard <[email protected]>
date: Thu Jan 12 21:20:12 EST 2006

Signed integer read functions. Use these when reading ticcmd diffs.

Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 287

--- a/src/net_packet.c
+++ b/src/net_packet.c
@@ -1,7 +1,7 @@
 // Emacs style mode select   -*- C++ -*- 
 //-----------------------------------------------------------------------------
 //
-// $Id: net_packet.c 236 2006-01-01 23:51:41Z fraggle $
+// $Id: net_packet.c 287 2006-01-13 02:20:12Z fraggle $
 //
 // Copyright(C) 2005 Simon Howard
 //
@@ -21,6 +21,9 @@
 // 02111-1307, USA.
 //
 // $Log$
+// Revision 1.3  2006/01/13 02:20:12  fraggle
+// Signed integer read functions.  Use these when reading ticcmd diffs.
+//
 // Revision 1.2  2006/01/01 23:51:41  fraggle
 // String read/write functions
 //
@@ -122,6 +125,59 @@
     packet->pos += 4;
     
     return true;
+}
+
+// Signed read functions
+
+boolean NET_ReadSInt8(net_packet_t *packet, signed int *data)
+{
+    if (NET_ReadInt8(packet,(unsigned int *) data))
+    {
+        if (*data & (1 << 7))
+        {
+            *data &= ~(1 << 7);
+            *data -= (1 << 7);
+        }
+        return true;
+    }
+    else
+    {
+        return false;
+    }
+}
+
+boolean NET_ReadSInt16(net_packet_t *packet, signed int *data)
+{
+    if (NET_ReadInt16(packet, (unsigned int *) data))
+    {
+        if (*data & (1 << 15))
+        {
+            *data &= ~(1 << 15);
+            *data -= (1 << 15);
+        }
+        return true;
+    }
+    else
+    {
+        return false;
+    }
+}
+
+boolean NET_ReadSInt32(net_packet_t *packet, signed int *data)
+{
+    if (NET_ReadInt32(packet, (unsigned int *) data))
+    {
+        if (*data & (1 << 31))
+        {
+            *data &= ~(1 << 31);
+            *data -= (1 << 31);
+        }
+        return true;
+    }
+    else
+    {
+        return false;
+    }
 }
 
 // Read a string from the packet.  Returns NULL if a terminating 
--- a/src/net_packet.h
+++ b/src/net_packet.h
@@ -1,7 +1,7 @@
 // Emacs style mode select   -*- C++ -*- 
 //-----------------------------------------------------------------------------
 //
-// $Id: net_packet.h 236 2006-01-01 23:51:41Z fraggle $
+// $Id: net_packet.h 287 2006-01-13 02:20:12Z fraggle $
 //
 // Copyright(C) 2005 Simon Howard
 //
@@ -21,6 +21,9 @@
 // 02111-1307, USA.
 //
 // $Log$
+// Revision 1.3  2006/01/13 02:20:12  fraggle
+// Signed integer read functions.  Use these when reading ticcmd diffs.
+//
 // Revision 1.2  2006/01/01 23:51:41  fraggle
 // String read/write functions
 //
@@ -41,13 +44,21 @@
 net_packet_t *NET_NewPacket(int initial_size);
 net_packet_t *NET_PacketDup(net_packet_t *packet);
 void NET_FreePacket(net_packet_t *packet);
+
 boolean NET_ReadInt8(net_packet_t *packet, unsigned int *data);
 boolean NET_ReadInt16(net_packet_t *packet, unsigned int *data);
 boolean NET_ReadInt32(net_packet_t *packet, unsigned int *data);
+
+boolean NET_ReadSInt8(net_packet_t *packet, signed int *data);
+boolean NET_ReadSInt16(net_packet_t *packet, signed int *data);
+boolean NET_ReadSInt32(net_packet_t *packet, signed int *data);
+
 char *NET_ReadString(net_packet_t *packet);
+
 void NET_WriteInt8(net_packet_t *packet, unsigned int i);
 void NET_WriteInt16(net_packet_t *packet, unsigned int i);
 void NET_WriteInt32(net_packet_t *packet, unsigned int i);
+
 void NET_WriteString(net_packet_t *packet, char *string);
 
 #endif /* #ifndef NET_PACKET_H */
--- a/src/net_structrw.c
+++ b/src/net_structrw.c
@@ -1,7 +1,7 @@
 // Emacs style mode select   -*- C++ -*- 
 //-----------------------------------------------------------------------------
 //
-// $Id: net_structrw.c 281 2006-01-11 01:37:53Z fraggle $
+// $Id: net_structrw.c 287 2006-01-13 02:20:12Z fraggle $
 //
 // Copyright(C) 2005 Simon Howard
 //
@@ -21,6 +21,9 @@
 // 02111-1307, USA.
 //
 // $Log$
+// Revision 1.3  2006/01/13 02:20:12  fraggle
+// Signed integer read functions.  Use these when reading ticcmd diffs.
+//
 // Revision 1.2  2006/01/11 01:37:53  fraggle
 // ticcmd diffs: allow compare and patching ticcmds, and reading/writing
 // ticdiffs to packets.
@@ -59,7 +62,8 @@
         && NET_ReadInt8(packet, (unsigned int *) &settings->skill);
 }
 
-void NET_WriteTiccmdDiff(net_packet_t *packet, net_ticdiff_t *diff)
+void NET_WriteTiccmdDiff(net_packet_t *packet, net_ticdiff_t *diff, 
+                         boolean lowres_turn)
 {
     // Header
 
@@ -72,7 +76,16 @@
     if (diff->diff & NET_TICDIFF_SIDE)
         NET_WriteInt8(packet, diff->cmd.sidemove);
     if (diff->diff & NET_TICDIFF_TURN)
-        NET_WriteInt16(packet, diff->cmd.angleturn);
+    {
+        if (lowres_turn)
+        {
+            NET_WriteInt8(packet, diff->cmd.angleturn / 256);
+        }
+        else
+        {
+            NET_WriteInt16(packet, diff->cmd.angleturn);
+        }
+    }
     if (diff->diff & NET_TICDIFF_BUTTONS)
         NET_WriteInt8(packet, diff->cmd.buttons);
     if (diff->diff & NET_TICDIFF_CONSISTANCY)
@@ -81,9 +94,11 @@
         NET_WriteInt8(packet, diff->cmd.chatchar);
 }
 
-boolean NET_ReadTiccmdDiff(net_packet_t *packet, net_ticdiff_t *diff)
+boolean NET_ReadTiccmdDiff(net_packet_t *packet, net_ticdiff_t *diff,
+                           boolean lowres_turn)
 {
     unsigned int val;
+    signed int sval;
 
     // Read header
 
@@ -94,23 +109,32 @@
 
     if (diff->diff & NET_TICDIFF_FORWARD)
     {
-        if (!NET_ReadInt8(packet, &val))
+        if (!NET_ReadSInt8(packet, &sval))
             return false;
-        diff->cmd.forwardmove = val;
+        diff->cmd.forwardmove = sval;
     }
 
     if (diff->diff & NET_TICDIFF_SIDE)
     {
-        if (!NET_ReadInt8(packet, &val))
+        if (!NET_ReadSInt8(packet, &sval))
             return false;
-        diff->cmd.sidemove = val;
+        diff->cmd.sidemove = sval;
     }
 
     if (diff->diff & NET_TICDIFF_TURN)
     {
-        if (!NET_ReadInt16(packet, &val))
-            return false;
-        diff->cmd.angleturn = val;
+        if (lowres_turn)
+        {
+            if (!NET_ReadSInt8(packet, &sval))
+                return false;
+            diff->cmd.angleturn = sval * 256;
+        }
+        else
+        {
+            if (!NET_ReadSInt16(packet, &sval))
+                return false;
+            diff->cmd.angleturn = sval;
+        }
     }
 
     if (diff->diff & NET_TICDIFF_BUTTONS)