ref: cc29e0fd789e058666110fec345d012cb7741615
parent: 75337e4ed54550f215145991517b0139fe7ce5c1
author: Simon Howard <[email protected]>
date: Tue Jan 10 20:37:53 EST 2006
ticcmd diffs: allow compare and patching ticcmds, and reading/writing ticdiffs to packets. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 281
--- 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;
@@ -144,6 +149,19 @@
int map;
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 */
--- 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)
@@ -50,5 +57,125 @@
&& NET_ReadInt8(packet, (unsigned int *) &settings->episode)
&& NET_ReadInt8(packet, (unsigned int *) &settings->map)
&& 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;
}
--- 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 */