Skip to content

Commit

Permalink
PROTOCOL: Support CSQC.
Browse files Browse the repository at this point in the history
Forward port of Reki's initial implementation.
  • Loading branch information
dsvensson committed Nov 27, 2024
1 parent 99b8ecf commit dafd1fc
Show file tree
Hide file tree
Showing 6 changed files with 553 additions and 1 deletion.
53 changes: 53 additions & 0 deletions src/pr2_cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
const char *pr2_ent_data_ptr;
vm_t *sv_vm = NULL;
extern gameData_t gamedata;
#ifdef FTE_PEXT_CSQC
extern sizebuf_t *csqcmsgbuffer;
#endif

static int PASSFLOAT(float f)
{
Expand All @@ -57,6 +60,9 @@ static float GETFLOAT(int i)
#endif

typedef intptr_t (*ext_syscall_t)(intptr_t *arg);
#ifdef FTE_PEXT_CSQC
static intptr_t EXT_SetSendNeeded(intptr_t *args);
#endif
static intptr_t EXT_MapExtFieldPtr(intptr_t *args);
static intptr_t EXT_SetExtFieldPtr(intptr_t *args);
static intptr_t EXT_GetExtFieldPtr(intptr_t *args);
Expand All @@ -69,6 +75,9 @@ struct
{"MapExtFieldPtr", EXT_MapExtFieldPtr},
{"SetExtFieldPtr", EXT_SetExtFieldPtr},
{"GetExtFieldPtr", EXT_GetExtFieldPtr},
#ifdef FTE_PEXT_CSQC
{"setsendneeded", EXT_SetSendNeeded},
#endif
};
ext_syscall_t ext_syscall_tbl[256];

Expand Down Expand Up @@ -1183,6 +1192,9 @@ MESSAGE WRITING
#define MSG_ALL 2 // reliable to all
#define MSG_INIT 3 // write to the init string
#define MSG_MULTICAST 4 // for multicast()
#ifdef FTE_PEXT_CSQC
#define MSG_CSQC 5 // for csqc
#endif


sizebuf_t *WriteDest2(int dest)
Expand Down Expand Up @@ -1219,6 +1231,9 @@ sizebuf_t *WriteDest2(int dest)
case MSG_MULTICAST:
return &sv.multicast;

case MSG_CSQC:
return csqcmsgbuffer;

default:
PR2_RunError ("WriteDest: bad destination");
break;
Expand Down Expand Up @@ -1996,6 +2011,36 @@ intptr_t PF2_FS_GetFileList(char *path, char *ext,
return numfiles;
}

#ifdef FTE_PEXT_CSQC
intptr_t EXT_SetSendNeeded(intptr_t *args)
{
unsigned int subject = args[1];
unsigned int fl = args[2];
unsigned int to = args[3];

if (!to)
{ //broadcast
for (to = 0; to < MAX_CLIENTS; to++)
{
svs.clients[to].csqcentitysendflags[subject] |= fl;
}
}
else
{
to--;
if (to >= MAX_CLIENTS)
{
; //some kind of error.
}
else
{
svs.clients[to].csqcentitysendflags[subject] |= fl;
}
}
return 0;
}
#endif

// To prevent mods from hardcoding field offsets which would cause engine incompatibilities.
static uint32_t GetExtFieldCookie(void)
{
Expand Down Expand Up @@ -2079,6 +2124,14 @@ static intptr_t EXT_MapExtFieldPtr(intptr_t *args)
{
return offsetof(ext_entvars_t, colourmod) | GetExtFieldCookie();
}
if (!strcmp(key, "SendEntity"))
{
return offsetof(ext_entvars_t, sendentity) | GetExtFieldCookie();
}
if (!strcmp(key, "pvsflags"))
{
return offsetof(ext_entvars_t, pvsflags) | GetExtFieldCookie();
}
}

return 0;
Expand Down
4 changes: 4 additions & 0 deletions src/progs.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ typedef struct
{
float alpha; // 0 = opaque, 1 = opaque, 0 < x < 1 translucent
float colourmod[3]; // r,g,b [0.0 .. 1.0], > 1 overbright
#ifdef FTE_PEXT_CSQC
int sendentity; // Trigger GAME_CSQCSEND indirection
float pvsflags; // CSQC pvsflags
#endif
} ext_entvars_t;

typedef struct edict_s
Expand Down
33 changes: 33 additions & 0 deletions src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ typedef struct
int static_entity_count;
#ifdef FTE_PEXT_CSQC
unsigned int csqcchecksum;
unsigned short csqcsendstates[MAX_EDICTS];
#endif
} server_t;

Expand Down Expand Up @@ -187,6 +188,24 @@ typedef struct
#define MAX_WEAPONSWITCH_OPTIONS 10
#endif

#ifdef FTE_PEXT_CSQC
// code adapted from Darkplaces
#define SCOPE_WANTREMOVE 1 // Set if a remove has been scheduled.
#define SCOPE_WANTUPDATE 2 // Set if an update has been scheduled.
#define SCOPE_WANTSEND (SCOPE_WANTREMOVE | SCOPE_WANTUPDATE)
#define SCOPE_EXISTED_ONCE 4 // Set if the entity once existed. All these get resent on a full loss.
#define SCOPE_ASSUMED_EXISTING 8 // Set if the entity is currently assumed existing and therefore needs removes.

#define NUM_CSQCENTITIES_PER_FRAME 256
typedef struct csqcentityframedb_s
{
int framenum;
int num;
unsigned short entno[NUM_CSQCENTITIES_PER_FRAME];
int sendflags[NUM_CSQCENTITIES_PER_FRAME];
} csqcentityframedb_t;
#endif

typedef struct client_s
{
sv_client_state_t state;
Expand Down Expand Up @@ -350,6 +369,16 @@ typedef struct client_s

#ifdef FTE_PEXT_CSQC
qbool csqcactive;
int csqc_framenum;
int csqc_latestverified;
int csqcnumedicts;
unsigned char csqcentityscope[MAX_EDICTS];
unsigned int csqcentitysendflags[MAX_EDICTS];

#define NUM_CSQCENTITYDB_FRAMES UPDATE_MASK//256
csqcentityframedb_t csqcentityframehistory[NUM_CSQCENTITYDB_FRAMES];
int csqcentityframehistory_next;
int csqcentityframe_lastreset;
#endif

//===== NETWORK ============
Expand Down Expand Up @@ -922,6 +951,10 @@ void SV_KickClient(client_t* client, const char* reason);
//
void SV_WriteEntitiesToClient (client_t *client, sizebuf_t *msg, qbool recorder);
void SV_SetVisibleEntitiesForBot (client_t* client);
#ifdef FTE_PEXT_CSQC
int SV_EmitCSQCUpdate(client_t *client, sizebuf_t *msg, int maxsize, int entlist_size, const unsigned short *entlist);
void EntityFrameCSQC_LostFrame(client_t *client, int framenum);
#endif

//
// sv_nchan.c
Expand Down
Loading

0 comments on commit dafd1fc

Please sign in to comment.