Skip to content

Commit

Permalink
InFIne: Started work on updating the network sync
Browse files Browse the repository at this point in the history
The engine has the low-level finale packet while fi_lib has its own.
  • Loading branch information
skyjake committed Jan 4, 2012
1 parent cf8a74f commit 527ec56
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 162 deletions.
4 changes: 3 additions & 1 deletion doomsday/engine/portable/include/cl_infine.h
Expand Up @@ -28,6 +28,8 @@
#ifndef LIBDENG_CLIENT_INFINE
#define LIBDENG_CLIENT_INFINE

void Cl_Finale(int packetType, const byte* data);
#include "reader.h"

void Cl_Finale(Reader* msg);

#endif /* LIBDENG_CLIENT_INFINE */
17 changes: 4 additions & 13 deletions doomsday/engine/portable/include/net_main.h
Expand Up @@ -64,17 +64,17 @@
#define MAX_CLMOBJS 80

// Packet types.
// PKT = sent by anybody
// PSV = sent by server
// PCL = sent by client
// PKT = sent by anyone
// PSV = only sent by server
// PCL = only sent by client
enum {
// Messages and responses.
PCL_HELLO = 0,
PKT_OK = 1,
PKT_CANCEL = 2, // unused?
PKT_PLAYER_INFO = 3,
PKT_CHAT = 4,
PKT_TICCMD = 5, // unused?
PSV_FINALE = 5,
PKT_PING = 6,
PSV_HANDSHAKE = 7,
PSV_SERVER_CLOSE = 8,
Expand All @@ -83,8 +83,6 @@ enum {
PSV_CONSOLE_TEXT = 11,
PCL_ACK_SHAKE = 12,
PSV_SYNC = 13,
//PSV_FILTER = 14, // unused?
//PKT_COMMAND = 15, // obsolete
PKT_LOGIN = 16,
PCL_ACK_SETS = 17,
PKT_COORDS = 18,
Expand All @@ -102,15 +100,8 @@ enum {
PSV_PLAYER_FIX = 30, // Fix angles/pos/mom.
PCL_GOODBYE = 31,

//PCL_COMMANDS_OBSOLETE = DDPT_COMMANDS_OBSOLETE, // 32; ticcmds (handled by game)

// Game specific events.
PKT_GAME_MARKER = DDPT_FIRST_GAME_EVENT, // 64

// Older versions put the task of interpreting InFine packet types in
// the hands of the game, hence their type ids being >= 64
PSV_FINALE = 76,
PSV_FINALE2 = 85
};

// Use the number defined in dd_share.h for sound packets.
Expand Down
74 changes: 29 additions & 45 deletions doomsday/engine/portable/src/cl_infine.c
Expand Up @@ -29,62 +29,46 @@
#include "de_network.h"
#include "de_infine.h"

static const byte* readbuffer;

// Mini-Msg routines.
static void SetReadBuffer(const byte* data)
{
readbuffer = data;
}

static byte ReadByte(void)
{
return *readbuffer++;
}

static short ReadShort(void)
{
readbuffer += 2;
return SHORT( *(const short*) (readbuffer - 2) );
}

static int ReadLong(void)
{
readbuffer += 4;
return LONG( *(const int*) (readbuffer - 4) );
}

static void Read(byte* buf, size_t len)
{
memcpy(buf, readbuffer, len);
readbuffer += len;
}
static finaleid_t currentFinale = 0;

/**
* This is where clients start their InFine sequences.
*/
void Cl_Finale(int packetType, const byte* data)
void Cl_Finale(Reader* msg)
{
byte flags;
int flags = Reader_ReadByte(msg);
byte* script = 0;
int len;

SetReadBuffer(data);
flags = ReadByte();

if(flags & (FINF_SCRIPT|FINF_BEGIN))
{ // Start the script.
#pragma message("WARNING: Cl_Finale does not presently read the state condition flags")
FI_Execute((const char*)readbuffer, FF_LOCAL);
if(flags & FINF_SCRIPT)
{
// Read the script into map-scope memory. It will be freed
// when the next map is loaded.
len = Reader_ReadUInt32(msg);
script = malloc(len + 1);
Reader_Read(msg, script, len);
script[len] = 0;
}

if(flags & FINF_END)
if((flags & FINF_SCRIPT) && (flags & FINF_BEGIN))
{
#pragma message("WARNING: Cl_Finale does not presently respond to FINF_END")
//FI_ScriptTerminate();
// Start the script.
currentFinale = FI_Execute(script, FF_LOCAL);
#ifdef _DEBUG
Con_Message("Cl_Finale: Started finale %i.\n", currentFinale);
#endif
}

if(flags & FINF_SKIP)
if((flags & FINF_END) && currentFinale)
{
#pragma message("WARNING: Cl_Finale does not presently respond to FINF_SKIP")
//FI_ScriptRequestSkip();
FI_ScriptTerminate(currentFinale);
currentFinale = 0;
}

if((flags & FINF_SKIP) && currentFinale)
{
FI_ScriptRequestSkip(currentFinale);
}

if(script) free(script);
}
3 changes: 1 addition & 2 deletions doomsday/engine/portable/src/cl_main.c
Expand Up @@ -370,8 +370,7 @@ void Cl_GetPackets(void)
break;

case PSV_FINALE:
case PSV_FINALE2:
Cl_Finale(netBuffer.msg.type, netBuffer.msg.data);
Cl_Finale(msgReader);
break;

default:
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/src/finaleinterpreter.c
Expand Up @@ -1195,7 +1195,7 @@ int FinaleInterpreter_Responder(finaleinterpreter_t* fi, const ddevent_t* ev)
if(!IS_TOGGLE_DOWN(ev))
return false;

// Servers tell clients to skip.
// Tell clients to skip.
Sv_Finale(FINF_SKIP, 0);
return FinaleInterpreter_Skip(fi);
}
Expand Down
28 changes: 14 additions & 14 deletions doomsday/engine/portable/src/sv_infine.c
Expand Up @@ -31,33 +31,33 @@
#include "de_infine.h"

/**
* The actual script is sent to the clients. 'script' can be NULL.
* The actual script is sent to the clients. @a script can be NULL.
*/
void Sv_Finale(int flags, const char* script)
{
size_t scriptLen = 0, len = 1 /* Just enough memory for the flags byte */;
byte* buffer, *ptr;
size_t scriptLen = 0;

assert(isServer);
if(isClient) return;

// How much memory do we need?
if(flags & FINF_SCRIPT)
if(script)
{
scriptLen = strlen(script) + 1;
len += scriptLen + 1; // The end null.
flags |= FINF_SCRIPT;
scriptLen = strlen(script);
}

ptr = buffer = malloc(len);

// First the flags.
*ptr++ = flags;
Msg_Begin(PSV_FINALE);
Writer_WriteByte(msgWriter, flags);

if(script)
{
memcpy(ptr, script, scriptLen + 1);
ptr[scriptLen] = '\0';
// Then the script itself.
Writer_WriteUInt32(msgWriter, scriptLen);
Writer_Write(msgWriter, script, scriptLen);
}

Net_SendPacket(DDSP_ALL_PLAYERS | DDSP_ORDERED, PSV_FINALE2, buffer, len);
Msg_End();

free(buffer);
Net_SendBuffer(NSP_BROADCAST, 0);
}
15 changes: 4 additions & 11 deletions doomsday/plugins/common/include/d_net.h
Expand Up @@ -29,15 +29,7 @@
#include "reader.h"
#include "writer.h"

#if __JDOOM__
# include "jdoom.h"
#elif __JDOOM64__
# include "jdoom64.h"
#elif __JHERETIC__
# include "jheretic.h"
#elif __JHEXEN__
# include "jhexen.h"
#endif
#include "common.h"

#define NETBUFFER_MAXMESSAGE 255

Expand Down Expand Up @@ -81,10 +73,11 @@ enum {
GPT_JUMP_POWER, // Jump power (0 = no jumping)
GPT_ACTION_REQUEST,
GPT_PLAYER_SPAWN_POSITION,
GPT_DAMAGE_REQUEST, // Client requests damage on a target.
GPT_DAMAGE_REQUEST, // Client requests damage on a target.
GPT_MOBJ_IMPULSE, // Momenum to apply on a mobj.
GPT_FLOOR_HIT_REQUEST,
GPT_MAYBE_CHANGE_WEAPON // Server suggests weapon change.
GPT_MAYBE_CHANGE_WEAPON, // Server suggests weapon change.
GPT_FINALE_STATE // State of the InFine script.
};

#if 0
Expand Down
6 changes: 5 additions & 1 deletion doomsday/plugins/common/include/fi_lib.h
Expand Up @@ -30,6 +30,8 @@
#ifndef LIBCOMMON_INFINE_LIB
#define LIBCOMMON_INFINE_LIB

#include "d_net.h"

/**
* @defgroup finaleMode Finale Mode.
*/
Expand All @@ -45,7 +47,7 @@ typedef enum {
/**
* @defgroup playsimServerFinaleFlags Play-simulation Server-side Finale Flags.
*
* Packet: PSV_FINALE Finale flags. Used with GPT_FINALE and GPT_FINALE2
* Packet: PSV_FINALE Finale flags.
*/
/*@{*/
#define FINF_AFTER 0x08 // Otherwise before.
Expand Down Expand Up @@ -95,4 +97,6 @@ boolean FI_IsMenuTrigger(void);

int FI_PrivilegedResponder(const void* ev);

void NetCl_FinaleState(Reader* msg);

#endif /* LIBCOMMON_INFINE_LIB */
8 changes: 3 additions & 5 deletions doomsday/plugins/common/src/d_net.c
Expand Up @@ -38,6 +38,7 @@
#include "p_player.h"
#include "hu_menu.h"
#include "p_start.h"
#include "fi_lib.h"
#include "doomsday.h"

// MACROS ------------------------------------------------------------------
Expand Down Expand Up @@ -536,12 +537,9 @@ void D_HandlePacket(int fromplayer, int type, void *data, size_t length)
NetCl_Intermission(reader);
break;

/*
case GPT_FINALE:
case GPT_FINALE2:
NetCl_Finale(type, reader);
case GPT_FINALE_STATE:
NetCl_FinaleState(reader);
break;
*/

case GPT_PLAYER_INFO:
NetCl_UpdatePlayerInfo(reader);
Expand Down
46 changes: 0 additions & 46 deletions doomsday/plugins/common/src/d_netcl.c
Expand Up @@ -60,54 +60,8 @@

// PRIVATE DATA DEFINITIONS ------------------------------------------------

//static byte *readbuffer;

// CODE --------------------------------------------------------------------

/*
// Mini-Msg routines.
void NetCl_SetReadBuffer(byte *data)
{
readbuffer = data;
}
byte NetCl_ReadByte(void)
{
return *readbuffer++;
}
short NetCl_ReadShort(void)
{
readbuffer += 2;
return SHORT( *(short*) (readbuffer - 2) );
}
unsigned short NetCl_ReadUShort(void)
{
readbuffer += 2;
return SHORT( *(unsigned short*) (readbuffer - 2) );
}
int NetCl_ReadLong(void)
{
readbuffer += 4;
return LONG( *(int*) (readbuffer - 4) );
}
float NetCl_ReadFloat(void)
{
int value = LONG( *(int*) readbuffer );
readbuffer += 4;
return *(float*) &value;
}
void NetCl_Read(byte *buf, int len)
{
memcpy(buf, readbuffer, len);
readbuffer += len;
}
*/

void NetCl_UpdateGameState(Reader* msg)
{
byte gsGameMode = 0;
Expand Down

0 comments on commit 527ec56

Please sign in to comment.