Skip to content

Commit

Permalink
Fixed ticcmd handling
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Aug 6, 2004
1 parent 0f82ebd commit 6711154
Show file tree
Hide file tree
Showing 22 changed files with 207 additions and 305 deletions.
8 changes: 7 additions & 1 deletion doomsday/Include/Common/d_net.h
Expand Up @@ -132,7 +132,13 @@ typedef struct {
#define CMDF_BUTTONS 0x10
#define CMDF_LOOKFLY 0x20
#define CMDF_ARTI 0x40
#define CMDF_MORE_FLAGS 0x80 // Reserved for extensions.
#define CMDF_CHANGE_WEAPON 0x80

#define CMDF_BTN_ATTACK 0x01
#define CMDF_BTN_USE 0x02
#define CMDF_BTN_JUMP 0x04
#define CMDF_BTN_PAUSE 0x08
#define CMDF_BTN_SUICIDE 0x10

// Networking.
int D_NetServerOpen(int before);
Expand Down
5 changes: 5 additions & 0 deletions doomsday/Include/jDoom/d_event.h
Expand Up @@ -60,6 +60,7 @@ typedef enum {
ga_screenshot
} gameaction_t;

#if 0
//
// Button/action code definitions.
//
Expand Down Expand Up @@ -100,6 +101,7 @@ typedef enum {
BTS_PREVWEAPON = 8,

} buttoncode_t;
#endif

//
// GLOBAL VARIABLES
Expand All @@ -116,6 +118,9 @@ extern gameaction_t gameaction;
//-----------------------------------------------------------------------------
//
// $Log$
// Revision 1.5 2004/08/06 20:42:30 skyjake
// Fixed ticcmd handling
//
// Revision 1.4 2004/05/29 09:53:11 skyjake
// Consistent style (using GNU Indent)
//
Expand Down
5 changes: 4 additions & 1 deletion doomsday/Include/jDoom/d_ticcmd.h
Expand Up @@ -28,18 +28,21 @@
#pragma interface
#endif

#pragma pack(1)

#if 0
// The data sampled per tick (single player)
// and transmitted to other peers (multiplayer).
// Mainly movements/button commands per game tick,
// plus a checksum for internal state consistency.
#pragma pack(1)
typedef struct {
char forwardMove; // *2048 for move
char sideMove; // *2048 for move
short angle; // <<16 for angle delta
short pitch; // view pitch
byte actions;
} ticcmd_t;
#endif

// This'll be used for saveplayer_t, but acts only as padding.
typedef struct {
Expand Down
1 change: 1 addition & 0 deletions doomsday/Include/jDoom/doomdef.h
Expand Up @@ -34,6 +34,7 @@
#include "../dd_api.h"
#include "g_dgl.h"
#include "version.h"
#include "p_ticcmd.h"

#define Set DD_SetInteger
#define Get DD_GetInteger
Expand Down
9 changes: 4 additions & 5 deletions doomsday/Include/jHeretic/Doomdef.h
Expand Up @@ -16,6 +16,7 @@
#include "../doomsday.h"
#include "../dd_api.h"
#include "g_dgl.h"
#include "p_ticcmd.h"
#include "H_Action.h"

#define Get DD_GetInteger
Expand Down Expand Up @@ -60,11 +61,7 @@ enum { VX, VY, VZ }; // Vertex indices.
#define ANGLETOFINESHIFT 19 // 0x100000000 to 0x2000

/*
===============================================================================
GLOBAL TYPES
===============================================================================
* GLOBAL TYPES
*/

#ifdef WIN32
Expand All @@ -89,6 +86,7 @@ typedef enum {
sk_nightmare
} skill_t;

#if 0
typedef struct {
char forwardMove; // *2048 for move
char sideMove; // *2048 for move
Expand Down Expand Up @@ -116,6 +114,7 @@ typedef struct {
// The high bits of arti are used for special flags.
#define AFLAG_JUMP 0x80
#define AFLAG_MASK 0x7F
#endif

typedef enum {
GS_LEVEL,
Expand Down
2 changes: 1 addition & 1 deletion doomsday/Include/jHeretic/P_local.h
Expand Up @@ -21,7 +21,7 @@

#define FOOTCLIPSIZE 10*FRACUNIT

#define TOCENTER -8
#define TOCENTER TICCMD_FALL_DOWN
#define FLOATSPEED (FRACUNIT*4)

#define MAXHEALTH 100
Expand Down
3 changes: 3 additions & 0 deletions doomsday/Include/jHexen/h2def.h
Expand Up @@ -21,6 +21,7 @@
#include "../dd_api.h"
#include "g_dgl.h"
#include "version.h"
#include "p_ticcmd.h"

#define Set DD_SetInteger
#define Get DD_GetInteger
Expand Down Expand Up @@ -83,6 +84,7 @@ typedef enum {
sk_nightmare
} skill_t;

#if 0
typedef struct {
char forwardMove; // *2048 for move
char sideMove; // *2048 for move
Expand Down Expand Up @@ -112,6 +114,7 @@ typedef struct {
#define AFLAG_MASK 0x3F
#define AFLAG_SUICIDE 0x40
#define AFLAG_JUMP 0x80
#endif

typedef enum {
GS_LEVEL,
Expand Down
2 changes: 1 addition & 1 deletion doomsday/Include/jHexen/p_local.h
Expand Up @@ -33,7 +33,7 @@
#define NUMBONUSPALS 4
#define NUMPOISONPALS 8

#define TOCENTER -8
#define TOCENTER TICCMD_FALL_DOWN
#define FLOATSPEED (FRACUNIT*4)

#define MAXHEALTH 100
Expand Down
34 changes: 27 additions & 7 deletions doomsday/Src/Common/d_netcl.c
Expand Up @@ -662,13 +662,14 @@ void NetCl_Paused(boolean setPause)
* buffer that contains the data (kludge to work around the parameter
* passing from the engine).
*/
void *NetCl_WriteCommands(ticcmd_t * cmd, int count)
void *NetCl_WriteCommands(ticcmd_t *cmd, int count)
{
static byte msg[1024]; // A shared buffer.
ushort *size = (ushort *) msg;
byte *out = msg + 2, *flags, *start = out;
ticcmd_t prev;
int i;
byte buttons;

// Always compare against the previous command.
memset(&prev, 0, sizeof(prev));
Expand Down Expand Up @@ -699,23 +700,42 @@ void *NetCl_WriteCommands(ticcmd_t * cmd, int count)
*flags |= CMDF_LOOKDIR;
*((short *) out)++ = cmd->pitch;
}
if(cmd->actions != prev.actions)

// Compile the button flags.
buttons = 0;
if(cmd->attack)
buttons |= CMDF_BTN_ATTACK;
if(cmd->use)
buttons |= CMDF_BTN_USE;
if(cmd->jump)
buttons |= CMDF_BTN_JUMP;
if(cmd->pause)
buttons |= CMDF_BTN_PAUSE;
if(cmd->suicide)
buttons |= CMDF_BTN_SUICIDE;

// Always include nonzero buttons.
if(buttons != 0)
{
*flags |= CMDF_BUTTONS;
*out++ = cmd->actions;
*out++ = buttons;
}
#ifndef __JDOOM__
if(cmd->lookfly != prev.lookfly)

if(cmd->fly != prev.fly)
{
*flags |= CMDF_LOOKFLY;
*out++ = cmd->lookfly;
*out++ = cmd->fly;
}
if(cmd->arti != prev.arti)
{
*flags |= CMDF_ARTI;
*out++ = cmd->arti;
}
#endif
if(cmd->changeWeapon != prev.changeWeapon)
{
*flags |= CMDF_CHANGE_WEAPON;
*((short *) out)++ = cmd->changeWeapon;
}

memcpy(&prev, cmd, sizeof(*cmd));
}
Expand Down
22 changes: 17 additions & 5 deletions doomsday/Src/Common/d_netsv.c
Expand Up @@ -1281,7 +1281,7 @@ void NetSv_Ticker(void)
* buffer that contains the ticcmds (kludge to work around the parameter
* passing from the engine).
*/
void *NetSv_ReadCommands(byte *msg, uint size)
void *NetSv_ReadCommands(byte *msg, uint size)
{
#define MAX_COMMANDS 30
static byte data[2 + sizeof(ticcmd_t) * MAX_COMMANDS];
Expand Down Expand Up @@ -1314,13 +1314,25 @@ void *NetSv_ReadCommands(byte *msg, uint size)
if(flags & CMDF_LOOKDIR)
cmd->pitch = *((short *) msg)++;
if(flags & CMDF_BUTTONS)
cmd->actions = *msg++;
#ifndef __JDOOM__
{
byte buttons = *msg++;
cmd->attack = ((buttons & CMDF_BTN_ATTACK) != 0);
cmd->use = ((buttons & CMDF_BTN_USE) != 0);
cmd->jump = ((buttons & CMDF_BTN_JUMP) != 0);
cmd->pause = ((buttons & CMDF_BTN_PAUSE) != 0);
cmd->suicide = ((buttons & CMDF_BTN_SUICIDE) != 0);
}
else
{
cmd->attack = cmd->use = cmd->jump = cmd->pause =
cmd->suicide = false;
}
if(flags & CMDF_LOOKFLY)
cmd->lookfly = *msg++;
cmd->fly = *msg++;
if(flags & CMDF_ARTI)
cmd->arti = *msg++;
#endif
if(flags & CMDF_CHANGE_WEAPON)
cmd->changeWeapon = *((short *) msg)++;

// Copy to next command (only differences have been written).
memcpy(cmd + 1, cmd, sizeof(ticcmd_t));
Expand Down

0 comments on commit 6711154

Please sign in to comment.