Browse Source

engine: client: add support for new PARMs

Reorganize internal engine structs, carefully check structs compatibility before casting types
pull/2/head
Alibek Omarov 1 year ago
parent
commit
a3c9538d12
  1. 12
      engine/client/cl_render.c
  2. 36
      engine/client/client.h
  3. 25
      engine/client/ref_common.c
  4. 6
      engine/common/common.h

12
engine/client/cl_render.c

@ -209,6 +209,18 @@ intptr_t CL_RenderGetParm( const int parm, const int arg, const qboolean checkRe @@ -209,6 +209,18 @@ intptr_t CL_RenderGetParm( const int parm, const int arg, const qboolean checkRe
return cl.nummodels;
case PARM_WORLD_VERSION:
return world.version;
case PARM_GET_CLIENT_PTR:
return (intptr_t)&cl.time; // with the offset
case PARM_GET_HOST_PTR:
return (intptr_t)&host.realtime; // with the offset
case PARM_GET_WORLD_PTR:
return (intptr_t)&world;
case PARM_GET_MOVEVARS_PTR:
return (intptr_t)&clgame.movevars;
case PARM_GET_PALETTE_PTR:
return (intptr_t)&clgame.palette;
case PARM_GET_VIEWENT_PTR:
return (intptr_t)&clgame.viewent;
}
}
return 0;

36
engine/client/client.h

@ -174,6 +174,26 @@ typedef struct @@ -174,6 +174,26 @@ typedef struct
// at every server map change
typedef struct
{
// ==== shared through RefAPI's ref_client_t ====
double time; // this is the time value that the client
// is rendering at. always <= cls.realtime
// a lerp point for other data
double oldtime; // previous cl.time, time-oldtime is used
// to decay light values and smooth step ups
int viewentity;
// server state information
int playernum;
int maxclients;
int nummodels;
model_t *models[MAX_MODELS+1]; // precached models (plus sentinel slot)
qboolean paused;
vec3_t simorg; // predicted origin
// ==== shared through RefAPI's ref_client_t ===
int servercount; // server identification for prespawns
int validsequence; // this is the sequence number of the last good
// world snapshot/update we got. If this is 0, we can't
@ -183,7 +203,6 @@ typedef struct @@ -183,7 +203,6 @@ typedef struct
qboolean video_prepped; // false if on new level or new ref dll
qboolean audio_prepped; // false if on new level or new snd dll
qboolean paused;
int delta_sequence; // acknowledged sequence number
@ -205,11 +224,6 @@ typedef struct @@ -205,11 +224,6 @@ typedef struct
runcmd_t commands[MULTIPLAYER_BACKUP]; // each mesage will send several old cmds
local_state_t predicted_frames[MULTIPLAYER_BACKUP]; // local client state
double time; // this is the time value that the client
// is rendering at. always <= cls.realtime
// a lerp point for other data
double oldtime; // previous cl.time, time-oldtime is used
// to decay light values and smooth step ups
double timedelta; // floating delta between two updates
char serverinfo[MAX_SERVERINFO_STRING];
@ -223,7 +237,6 @@ typedef struct @@ -223,7 +237,6 @@ typedef struct
// player final info
usercmd_t *cmd; // cl.commands[outgoing_sequence].cmd
int viewentity;
vec3_t viewangles;
vec3_t viewheight;
vec3_t punchangle;
@ -236,14 +249,9 @@ typedef struct @@ -236,14 +249,9 @@ typedef struct
float addangletotal;
float prevaddangletotal;
// predicted origin and velocity
vec3_t simorg;
// predicted velocity
vec3_t simvel;
// server state information
int playernum;
int maxclients;
entity_state_t instanced_baseline[MAX_CUSTOM_BASELINES];
int instanced_baseline_count;
@ -251,8 +259,6 @@ typedef struct @@ -251,8 +259,6 @@ typedef struct
char event_precache[MAX_EVENTS][MAX_QPATH];
char files_precache[MAX_CUSTOM][MAX_QPATH];
lightstyle_t lightstyles[MAX_LIGHTSTYLES];
model_t *models[MAX_MODELS+1]; // precached models (plus sentinel slot)
int nummodels;
int numfiles;
consistency_t consistency_list[MAX_MODELS];

25
engine/client/ref_common.c

@ -18,6 +18,31 @@ CVAR_DEFINE_AUTO( r_showtree, "0", FCVAR_ARCHIVE, "build the graph of visible BS @@ -18,6 +18,31 @@ CVAR_DEFINE_AUTO( r_showtree, "0", FCVAR_ARCHIVE, "build the graph of visible BS
static CVAR_DEFINE_AUTO( r_refdll, "", FCVAR_RENDERINFO, "choose renderer implementation, if supported" );
static CVAR_DEFINE_AUTO( r_refdll_loaded, "", FCVAR_READ_ONLY, "currently loaded renderer" );
// there is no need to expose whole host and cl structs into the renderer
// but we still need to update timings accurately as possible
// this looks horrible but the only other option would be passing four
// time pointers and then it's looks even worse with dereferences everywhere
#define STATIC_OFFSET_CHECK( s1, s2, field, base, msg ) \
STATIC_ASSERT( offsetof( s1, field ) == offsetof( s2, field ) - offsetof( s2, base ), msg )
#define REF_CLIENT_CHECK( field ) \
STATIC_OFFSET_CHECK( ref_client_t, client_t, field, time, "broken ref_client_t offset" ); \
STATIC_ASSERT_( szchk_##__LINE__, sizeof(((ref_client_t *)0)->field ) == sizeof( cl.field ), "broken ref_client_t size" )
#define REF_HOST_CHECK( field ) \
STATIC_OFFSET_CHECK( ref_host_t, host_parm_t, field, realtime, "broken ref_client_t offset" ); \
STATIC_ASSERT_( szchk_##__LINE__, sizeof(((ref_host_t *)0)->field ) == sizeof( host.field ), "broken ref_client_t size" )
REF_CLIENT_CHECK( time );
REF_CLIENT_CHECK( oldtime );
REF_CLIENT_CHECK( viewentity );
REF_CLIENT_CHECK( playernum );
REF_CLIENT_CHECK( maxclients );
REF_CLIENT_CHECK( models );
REF_CLIENT_CHECK( paused );
REF_CLIENT_CHECK( simorg );
REF_HOST_CHECK( realtime );
REF_HOST_CHECK( frametime );
REF_HOST_CHECK( features );
void R_GetTextureParms( int *w, int *h, int texnum )
{
if( w ) *w = REF_GET_PARM( PARM_TEX_WIDTH, texnum );

6
engine/common/common.h

@ -302,8 +302,12 @@ typedef struct host_parm_s @@ -302,8 +302,12 @@ typedef struct host_parm_s
int argc;
char **argv;
// ==== shared through RefAPI's ref_host_t
double realtime; // host.curtime
double frametime; // time between engine frames
uint features; // custom features that enables by mod-maker request
// ==== shared through RefAPI's ref_host_t
double realframetime; // for some system events, e.g. console animations
uint framecount; // global framecount
@ -344,8 +348,6 @@ typedef struct host_parm_s @@ -344,8 +348,6 @@ typedef struct host_parm_s
poolhandle_t imagepool; // imagelib mempool
poolhandle_t soundpool; // soundlib mempool
uint features; // custom features that enables by mod-maker request
// for IN_MouseMove() easy access
int window_center_x;
int window_center_y;

Loading…
Cancel
Save