Skip to content

Commit

Permalink
QVM: Support for syscall extensions.
Browse files Browse the repository at this point in the history
  • Loading branch information
dsvensson committed Jun 10, 2024
1 parent 9226685 commit 85203c0
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 38 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ set(SRC_COMMON
"${DIR_SRC}/g_spawn.c"
"${DIR_SRC}/g_userinfo.c"
"${DIR_SRC}/g_utils.c"
"${DIR_SRC}/g_syscalls_extra.c"
"${DIR_SRC}/hiprot.c"
"${DIR_SRC}/hoonymode.c"
"${DIR_SRC}/items.c"
Expand Down
6 changes: 6 additions & 0 deletions include/g_syscalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,16 @@ intptr_t trap_movetogoal(float dist);

void trap_VisibleTo(intptr_t viewer, intptr_t first, intptr_t len, byte *visible);

// Raw calls, use _i and _f helpers instead.
void trap_SetExtField(gedict_t *ed, const char *fieldname, int val);
int trap_GetExtField(gedict_t *ed, const char *fieldname);

// Checks for server support before call
void trap_SetExtField_i(gedict_t *ed, const char *fieldname, int val);
void trap_SetExtField_f(gedict_t *ed, const char *fieldname, float val);
int trap_GetExtField_i(gedict_t *ed, const char *fieldname);
float trap_GetExtField_f(gedict_t *ed, const char *fieldname);

void trap_changelevelHub(const char *name, const char *entityname, const char *startspot);
int trap_URI_Query(const char *uri, int vmentry/*GAME_...*/, void *cbcontext, const char *mimetype, const char *data, size_t datasize);
int trap_particleeffectnum(const char *effectname);
Expand Down
10 changes: 10 additions & 0 deletions src/g_syscalls.asm
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,13 @@ equ trap_SetUserInfo -92
equ trap_movetogoal -93

equ trap_VisibleTo -94

equ trap_SetExtField -257
equ trap_GetExtField -258
equ trap_changelevelHub -259
equ trap_URI_Query -260
equ trap_particleeffectnum -261
equ trap_trailparticles -262
equ trap_pointparticles -263
equ trap_clientstat -264
equ trap_pointerstat -265
42 changes: 4 additions & 38 deletions src/g_syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -466,48 +466,14 @@ void trap_VisibleTo(intptr_t viewer, intptr_t first, intptr_t len, byte *visible
syscall(G_VISIBLETO, viewer, first, len, (intptr_t) visible);
}

void trap_SetExtField_i(gedict_t *ed, const char *fieldname, int val)
void trap_SetExtField(gedict_t *ed, const char *fieldname, int val)
{
if (HAVEEXTENSION(G_SETEXTFIELD))
{
syscall(G_SETEXTFIELD, (intptr_t)ed, (intptr_t)fieldname, val);
}
else
{
G_bprint(PRINT_HIGH, "SetExtField(%s, %s, %d) not supported by server\n", ed->classname, fieldname, val);
}
syscall(G_SETEXTFIELD, (intptr_t)ed, (intptr_t)fieldname, val);
}

void trap_SetExtField_f(gedict_t *ed, const char *fieldname, float val)
int trap_GetExtField(gedict_t *ed, const char *fieldname)
{
if (HAVEEXTENSION(G_SETEXTFIELD))
{
syscall(G_SETEXTFIELD, (intptr_t)ed, (intptr_t)fieldname, PASSFLOAT(val));
}
else
{
G_bprint(PRINT_HIGH, "SetExtField(%s, %s, %f) not supported by server\n", ed->classname, fieldname, val);
}
}

int trap_GetExtField_i(gedict_t *ed, const char *fieldname)
{
int ival = -1;
if (HAVEEXTENSION(G_GETEXTFIELD))
{
ival = syscall(G_GETEXTFIELD, (intptr_t)ed, (intptr_t)fieldname);
}
return ival;
}

float trap_GetExtField_f(gedict_t *ed, const char *fieldname)
{
fi_t tmp = { ._float = -1 };
if (HAVEEXTENSION(G_GETEXTFIELD))
{
tmp._int = syscall(G_GETEXTFIELD, (intptr_t)ed, (intptr_t)fieldname);
}
return tmp._float;
return syscall(G_GETEXTFIELD, (intptr_t)ed, (intptr_t)fieldname);
}

void trap_changelevelHub(const char *name, const char *entityname, const char *startspot)
Expand Down
55 changes: 55 additions & 0 deletions src/g_syscalls_extra.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include "g_local.h"
#include "g_syscalls.h"

typedef union fi_s
{
float _float;
intptr_t _int;
} fi_t;

void trap_SetExtField_i(gedict_t *ed, const char *fieldname, int val)
{
if (HAVEEXTENSION(G_SETEXTFIELD))
{
trap_SetExtField(ed, fieldname, val);
}
else
{
G_bprint(PRINT_HIGH, "SetExtField(%s, %s, %d) not supported by server\n", ed->classname, fieldname, val);
}
}

void trap_SetExtField_f(gedict_t *ed, const char *fieldname, float val)
{
if (HAVEEXTENSION(G_SETEXTFIELD))
{
fi_t rc;
rc._float = val;
trap_SetExtField(ed, fieldname, rc._int);
}
else
{
G_bprint(PRINT_HIGH, "SetExtField(%s, %s, %f) not supported by server\n", ed->classname, fieldname, val);
}
}

int trap_GetExtField_i(gedict_t *ed, const char *fieldname)
{
int ival = -1;
if (HAVEEXTENSION(G_GETEXTFIELD))
{
ival = trap_GetExtField(ed, fieldname);
}
return ival;
}

float trap_GetExtField_f(gedict_t *ed, const char *fieldname)
{
fi_t tmp;
tmp._float = -1.0f;
if (HAVEEXTENSION(G_GETEXTFIELD))
{
tmp._int = trap_GetExtField_f(ed, fieldname);
}
return tmp._float;
}

0 comments on commit 85203c0

Please sign in to comment.