diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/net_defs.h | 20 | ||||
-rw-r--r-- | src/net_structrw.c | 129 | ||||
-rw-r--r-- | src/net_structrw.h | 10 |
3 files changed, 156 insertions, 3 deletions
diff --git a/src/net_defs.h b/src/net_defs.h index 6a8e20cb..940e6540 100644 --- a/src/net_defs.h +++ b/src/net_defs.h @@ -1,7 +1,7 @@ // Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // -// $Id: net_defs.h 279 2006-01-10 19:59:26Z fraggle $ +// $Id: net_defs.h 281 2006-01-11 01:37:53Z fraggle $ // // Copyright(C) 2005 Simon Howard // @@ -21,6 +21,10 @@ // 02111-1307, USA. // // $Log$ +// Revision 1.8 2006/01/11 01:37:53 fraggle +// ticcmd diffs: allow compare and patching ticcmds, and reading/writing +// ticdiffs to packets. +// // Revision 1.7 2006/01/10 19:59:26 fraggle // Reliable packet transport mechanism // @@ -56,6 +60,7 @@ #define NET_DEFS_H #include "doomtype.h" +#include "d_ticcmd.h" typedef struct _net_module_s net_module_t; typedef struct _net_packet_s net_packet_t; @@ -145,5 +150,18 @@ typedef struct int skill; } net_gamesettings_t; +#define NET_TICDIFF_FORWARD (1 << 0) +#define NET_TICDIFF_SIDE (1 << 1) +#define NET_TICDIFF_TURN (1 << 2) +#define NET_TICDIFF_BUTTONS (1 << 3) +#define NET_TICDIFF_CONSISTANCY (1 << 4) +#define NET_TICDIFF_CHATCHAR (1 << 5) + +typedef struct +{ + unsigned int diff; + ticcmd_t cmd; +} net_ticdiff_t; + #endif /* #ifndef NET_DEFS_H */ diff --git a/src/net_structrw.c b/src/net_structrw.c index 070da747..5c77d102 100644 --- a/src/net_structrw.c +++ b/src/net_structrw.c @@ -1,7 +1,7 @@ // Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // -// $Id: net_structrw.c 235 2005-12-30 18:58:22Z fraggle $ +// $Id: net_structrw.c 281 2006-01-11 01:37:53Z fraggle $ // // Copyright(C) 2005 Simon Howard // @@ -21,6 +21,10 @@ // 02111-1307, USA. // // $Log$ +// Revision 1.2 2006/01/11 01:37:53 fraggle +// ticcmd diffs: allow compare and patching ticcmds, and reading/writing +// ticdiffs to packets. +// // Revision 1.1 2005/12/30 18:58:22 fraggle // Fix client code to correctly send reply to server on connection. // Add "waiting screen" while waiting for the game to start. @@ -30,6 +34,9 @@ // Reading and writing various structures into packets // +#include <stdlib.h> +#include <string.h> + #include "net_packet.h" void NET_WriteSettings(net_packet_t *packet, net_gamesettings_t *settings) @@ -52,3 +59,123 @@ 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) +{ + // Header + + NET_WriteInt8(packet, diff->diff); + + // Write the fields which are enabled: + + if (diff->diff & NET_TICDIFF_FORWARD) + NET_WriteInt8(packet, diff->cmd.forwardmove); + 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 (diff->diff & NET_TICDIFF_BUTTONS) + NET_WriteInt8(packet, diff->cmd.buttons); + if (diff->diff & NET_TICDIFF_CONSISTANCY) + NET_WriteInt8(packet, diff->cmd.consistancy); + if (diff->diff & NET_TICDIFF_CHATCHAR) + NET_WriteInt8(packet, diff->cmd.chatchar); +} + +boolean NET_ReadTiccmdDiff(net_packet_t *packet, net_ticdiff_t *diff) +{ + unsigned int val; + + // Read header + + if (!NET_ReadInt8(packet, &diff->diff)) + return false; + + // Read fields + + if (diff->diff & NET_TICDIFF_FORWARD) + { + if (!NET_ReadInt8(packet, &val)) + return false; + diff->cmd.forwardmove = val; + } + + if (diff->diff & NET_TICDIFF_SIDE) + { + if (!NET_ReadInt8(packet, &val)) + return false; + diff->cmd.sidemove = val; + } + + if (diff->diff & NET_TICDIFF_TURN) + { + if (!NET_ReadInt16(packet, &val)) + return false; + diff->cmd.angleturn = val; + } + + if (diff->diff & NET_TICDIFF_BUTTONS) + { + if (!NET_ReadInt8(packet, &val)) + return false; + diff->cmd.buttons = val; + } + + if (diff->diff & NET_TICDIFF_CONSISTANCY) + { + if (!NET_ReadInt8(packet, &val)) + return false; + diff->cmd.consistancy = val; + } + + if (diff->diff & NET_TICDIFF_CHATCHAR) + { + if (!NET_ReadInt8(packet, &val)) + return false; + diff->cmd.chatchar = val; + } + + return true; +} + +void NET_TiccmdDiff(ticcmd_t *tic1, ticcmd_t *tic2, net_ticdiff_t *diff) +{ + diff->diff = 0; + diff->cmd = *tic2; + + if (tic1->forwardmove != tic2->forwardmove) + diff->diff |= NET_TICDIFF_FORWARD; + if (tic1->sidemove != tic2->sidemove) + diff->diff |= NET_TICDIFF_SIDE; + if (tic1->angleturn != tic2->angleturn) + diff->diff |= NET_TICDIFF_TURN; + if (tic1->buttons != tic2->buttons) + diff->diff |= NET_TICDIFF_BUTTONS; + if (tic1->consistancy != tic2->consistancy) + diff->diff |= NET_TICDIFF_CONSISTANCY; + if (tic2->chatchar != 0) + diff->diff |= NET_TICDIFF_CHATCHAR; +} + +void NET_TiccmdPatch(ticcmd_t *src, net_ticdiff_t *diff, ticcmd_t *dest) +{ + memcpy(dest, src, sizeof(ticcmd_t)); + + // Apply the diff + + if (diff->diff & NET_TICDIFF_FORWARD) + dest->forwardmove = diff->cmd.forwardmove; + if (diff->diff & NET_TICDIFF_SIDE) + dest->sidemove = diff->cmd.sidemove; + if (diff->diff & NET_TICDIFF_TURN) + dest->angleturn = diff->cmd.angleturn; + if (diff->diff & NET_TICDIFF_BUTTONS) + dest->buttons = diff->cmd.buttons; + if (diff->diff & NET_TICDIFF_CONSISTANCY) + dest->consistancy = diff->cmd.consistancy; + + if (diff->diff & NET_TICDIFF_CHATCHAR) + dest->chatchar = diff->cmd.chatchar; + else + dest->chatchar = 0; +} + diff --git a/src/net_structrw.h b/src/net_structrw.h index c797162b..d989e621 100644 --- a/src/net_structrw.h +++ b/src/net_structrw.h @@ -1,7 +1,7 @@ // Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // -// $Id: net_structrw.h 235 2005-12-30 18:58:22Z fraggle $ +// $Id: net_structrw.h 281 2006-01-11 01:37:53Z fraggle $ // // Copyright(C) 2005 Simon Howard // @@ -21,6 +21,10 @@ // 02111-1307, USA. // // $Log$ +// Revision 1.2 2006/01/11 01:37:53 fraggle +// ticcmd diffs: allow compare and patching ticcmds, and reading/writing +// ticdiffs to packets. +// // Revision 1.1 2005/12/30 18:58:22 fraggle // Fix client code to correctly send reply to server on connection. // Add "waiting screen" while waiting for the game to start. @@ -36,6 +40,10 @@ extern void NET_WriteSettings(net_packet_t *packet, net_gamesettings_t *settings); extern boolean NET_ReadSettings(net_packet_t *packet, net_gamesettings_t *settings); +extern void NET_WriteTiccmdDiff(net_packet_t *packet, net_ticdiff_t *diff); +extern boolean NET_ReadTiccmdDiff(net_packet_t *packet, net_ticdiff_t *diff); +extern void NET_TiccmdDiff(ticcmd_t *tic1, ticcmd_t *tic2, net_ticdiff_t *diff); +extern void NET_TiccmdPatch(ticcmd_t *src, net_ticdiff_t *diff, ticcmd_t *dest); #endif /* #ifndef NET_STRUCTRW_H */ |