Quake3World.com
https://www.quake3world.com/forum/

Quake 3 : Add a trap function ?
https://www.quake3world.com/forum/viewtopic.php?f=16&t=32037
Page 1 of 1

Author:  Alf2010 [ 06-29-2007 06:45 AM ]
Post subject:  Quake 3 : Add a trap function ?

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...

Author:  ^misantropia^ [ 06-29-2007 07:11 AM ]
Post subject:  Re: Quake 3 : Add a trap function ?

Alf2010 wrote:
in the gameImport_t enum adding the line :

EXAMPLE_TRAP_FUNCTION

I think you'll want to make that:
Code:
EXAMPLE_TRAP_FUNCTION = -600

Author:  Alf2010 [ 06-29-2007 07:38 AM ]
Post subject: 

I think you're right but there is an other mistake because now the error message is : bad game system trap -600

Author:  ^misantropia^ [ 06-29-2007 07:42 AM ]
Post subject: 

You'll also need to add it to SV_GameSystemCalls() in server/sv_game.c

Author:  Alf2010 [ 06-29-2007 08:12 AM ]
Post subject: 

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;

Page 1 of 1 All times are UTC - 8 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/