diff options
author | Simon Howard | 2006-01-13 02:20:12 +0000 |
---|---|---|
committer | Simon Howard | 2006-01-13 02:20:12 +0000 |
commit | baef203819ad5490809712332340f6fddf3c9f56 (patch) | |
tree | f4105c191d2d7c981d6be828297432b80c5aa9b8 | |
parent | c1e37f1955a0c546a795484acc92510e4c4dc6b2 (diff) | |
download | chocolate-doom-baef203819ad5490809712332340f6fddf3c9f56.tar.gz chocolate-doom-baef203819ad5490809712332340f6fddf3c9f56.tar.bz2 chocolate-doom-baef203819ad5490809712332340f6fddf3c9f56.zip |
Signed integer read functions. Use these when reading ticcmd diffs.
Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 287
-rw-r--r-- | src/net_packet.c | 58 | ||||
-rw-r--r-- | src/net_packet.h | 13 | ||||
-rw-r--r-- | src/net_structrw.c | 46 |
3 files changed, 104 insertions, 13 deletions
diff --git a/src/net_packet.c b/src/net_packet.c index 5144382a..14623b4e 100644 --- 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 // @@ -124,6 +127,59 @@ boolean NET_ReadInt32(net_packet_t *packet, unsigned int *data) 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 // NUL character was not found before the end of the packet. diff --git a/src/net_packet.h b/src/net_packet.h index f5583d6d..7f1f6346 100644 --- 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 */ diff --git a/src/net_structrw.c b/src/net_structrw.c index 5c77d102..1905372e 100644 --- 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 @@ boolean NET_ReadSettings(net_packet_t *packet, net_gamesettings_t *settings) && 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 @@ void NET_WriteTiccmdDiff(net_packet_t *packet, net_ticdiff_t *diff) 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 @@ void NET_WriteTiccmdDiff(net_packet_t *packet, net_ticdiff_t *diff) 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 @@ boolean NET_ReadTiccmdDiff(net_packet_t *packet, net_ticdiff_t *diff) 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) |