Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generalize VM syscall arguments #158

Closed
zturtleman opened this issue Jan 3, 2014 · 2 comments
Closed

Generalize VM syscall arguments #158

zturtleman opened this issue Jan 3, 2014 · 2 comments

Comments

@zturtleman
Copy link
Member

Make QVMs use cg_syscalls.c and g_syscalls.c. (Edit: Done in e099fee.)

In *_syscalls.c pass a list of type of argument (example: SCV_ORIGIN, SCV meaning system call variable) followed by data.

#define MAX_VARIABLES 64
int scCmd;
int numScVars;
struct {
    intptr_t var;
    intptr_t data;
} scVars[MAX_VARIABLES];

#define SC_BEGIN( x ) scCmd = x; numScVars = 0;
#define SC_END( x ) syscall( scCmd, numScVars, scVars );

void SC_Var( int v, intptr_t d ) {
    if ( numScVars >= MAX_VARIABLES )
        Com_Error(ERR_DROP, "Hit MAX_VARIABLES");
    scVars[numScVars].var = v;
    scVars[numScVars++].data = d;
}

#define SC_VAR( v, i ) SC_Var( v, i );
#define SC_VARA( v, ptr ) SC_Var( v, ptr );
#define SC_VARF( v, f ) SC_Var( v, PASSFLOAT( f ) );

void    trap_R_AddLightToScene( const vec3_t org, float radius, float intensity, float r, float g, float b ) {
    SC_BEGIN( CG_R_ADDLIGHTTOSCENE )
    SC_VARA( SCV_V3_ORIGIN, org )
    SC_VARF( SCV_F_RADIUS, radius )
    SC_VARF( SCV_F_INTENSITY, intensity )
    SC_VARF( SCV_F_RED, r )
    SC_VARF( SCV_F_GREEN, g )
    SC_VARF( SCV_F_BLUE, b )
    SC_END( )
}

In engine's cl_cgame.c and sv_game.c allow getting variables (with default if not given). VMA( SCV_V3_ORIGIN, vec3_origin ), VMI( SCV_I_STARTFRAME, 0 ), VMF( SCV_F_FRAMELERP, 0.0f ).

This allows adding new variables to system calls without breaking forward or backward compatibility. Unknown variables will be ignored, may result in not working 'as intended' on older engines but will be useable. (Hmm, let VM know what variables each system call supports?)

@zturtleman
Copy link
Member Author

hmm, will need special code to fix up the passed variable list, like already done for variables passed to syscall().

@zturtleman
Copy link
Member Author

No, don't need this level of "flexibility" for function arguments. Can handle this in engine using specific API version numbers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant