Quake 3 : Add a trap function ?

Locked
Alf2010
Posts: 3
Joined: Fri Jun 29, 2007 2:35 pm

Quake 3 : Add a trap function ?

Post by Alf2010 »

Do you know how to add your own trap function ?
I put my function in qcommon directory and I want to call it from the game directory (like for example the trap_FS_Write function).
I do the same (definition/declaration) like the other trap functions but I suppose the problem is to find the correct id for the g_syscalls.asm.

For example :

In qcommon/common.c :

void example_trap_function( void )
{
int i = 12345; // only for for debug
}


In qcommon/q_shared.h :

void example_trap_function( void );


In game/g_local.h :

void example_trap_function( void );


In game/gpublic.h :

in the gameImport_t enum adding the line :

EXAMPLE_TRAP_FUNCTION


In game/g_syscalls.c :

void example_trap_function( void )
{
syscall( EXAMPLE_TRAP_FUNCTION );
}

You have to modify the game.q3asm for compiling g_syscalls.c (replace line ../g_syscalls with g_syscalls) with ioquake3.


In game/g_syscalls.asm :

adding this line at the end of the file :

equ trap_example_trap_function -600

Is it my problem ?
How to know the number ?


In game/g_main.c :

Use the example function in G_InitGame :

trap_example_trap_function( );


Compiling is ok
After installing everything (bin and qvm) and starting the game it's ok.
When the map is launching (G_InitGame function) I have this message :

bad game system trap -582

582 is the number for the trap_BotLibSourceFileAndLine in the g_syscalls.asm file.
I add my line after it...
^misantropia^
Posts: 4022
Joined: Sat Mar 12, 2005 6:24 pm

Re: Quake 3 : Add a trap function ?

Post by ^misantropia^ »

Alf2010 wrote:in the gameImport_t enum adding the line :

EXAMPLE_TRAP_FUNCTION
I think you'll want to make that:

Code: Select all

EXAMPLE_TRAP_FUNCTION = -600
Alf2010
Posts: 3
Joined: Fri Jun 29, 2007 2:35 pm

Post by Alf2010 »

I think you're right but there is an other mistake because now the error message is : bad game system trap -600
^misantropia^
Posts: 4022
Joined: Sat Mar 12, 2005 6:24 pm

Post by ^misantropia^ »

You'll also need to add it to SV_GameSystemCalls() in server/sv_game.c
Alf2010
Posts: 3
Joined: Fri Jun 29, 2007 2:35 pm

Post by Alf2010 »

Thank's a lot :)

The modifications to have it working :

In game/gpublic.h :

in the gameImport_t enum adding the line :

EXAMPLE_TRAP_FUNCTION = 600


In server/sv_game.c :

in the SV_GameSystemCalls function adding the lines :

case EXAMPLE_TRAP_FUNCTION:
example_trap_function();
return 0;
Locked