mirror of
https://github.com/ReactionQuake3/reaction.git
synced 2024-11-22 20:31:11 +00:00
Script interpreter (work in progress)
This commit is contained in:
parent
aa2177d8b9
commit
ff3f8c5ccf
4 changed files with 158 additions and 9 deletions
131
reaction/game/g_scripts.c
Normal file
131
reaction/game/g_scripts.c
Normal file
|
@ -0,0 +1,131 @@
|
|||
#include "g_parser.h"
|
||||
|
||||
#define BUFFER_SIZE (32 * 1024)
|
||||
static char scriptBuffer[BUFFER_SIZE];
|
||||
|
||||
// Parser states //////////////////////////////////////////////
|
||||
|
||||
TParseState STATE_Base;
|
||||
TParseState STATE_Main;
|
||||
TParseState STATE_Restrictions;
|
||||
TParseState STATE_Rotation;
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// BASE STATE /////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Functions //////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////
|
||||
SCRIPT_FUNC(Base_To_Main)
|
||||
{
|
||||
SCRIPT_PUSH_STATE(STATE_Main);
|
||||
return 0;
|
||||
}
|
||||
END_SCRIPT_FUNC()
|
||||
///////////////////////////////////////////////////////////////
|
||||
SCRIPT_FUNC(Base_To_Restrictions)
|
||||
{
|
||||
SCRIPT_PUSH_STATE(STATE_Restrictions);
|
||||
return 0;
|
||||
}
|
||||
END_SCRIPT_FUNC()
|
||||
///////////////////////////////////////////////////////////////
|
||||
SCRIPT_FUNC(Base_To_Rotation)
|
||||
{
|
||||
SCRIPT_PUSH_STATE(STATE_Rotation);
|
||||
return 0;
|
||||
}
|
||||
END_SCRIPT_FUNC()
|
||||
///////////////////////////////////////////////////////////////
|
||||
// State definition ///////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////
|
||||
SCRIPT_STATE(STATE_Base, NO_DATA)
|
||||
{
|
||||
ADD_RULE("[main]", Base_To_Main)
|
||||
ADD_RULE("[restrictions]", Base_To_Restrictions)
|
||||
ADD_RULE("[rotation]", Base_To_Rotation)
|
||||
ADD_RULE("/*", SFN_SkipComment)
|
||||
ADD_RULE("//", SFN_SkipLineComment)
|
||||
END_STATE_MARKER
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// MAIN STATE /////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Functions //////////////////////////////////////////////////
|
||||
|
||||
SCRIPT_FUNC(Main_Cvar)
|
||||
{
|
||||
NEEDS_TOKENS(1, tokens);
|
||||
G_Printf("Cvar: %s = %s\n", tokens[0], tokens[1]);
|
||||
return 0;
|
||||
}
|
||||
END_SCRIPT_FUNC()
|
||||
|
||||
// State definition ///////////////////////////////////////////
|
||||
|
||||
SCRIPT_STATE(STATE_Main, NO_DATA)
|
||||
{
|
||||
ADD_RULE("[/main]", SFN_PopState)
|
||||
ADD_RULE("cvar", Main_Cvar)
|
||||
ADD_RULE("/*", SFN_SkipComment)
|
||||
ADD_RULE("//", SFN_SkipLineComment)
|
||||
END_STATE_MARKER
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// ROTATION STATE /////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Functions //////////////////////////////////////////////////
|
||||
|
||||
// State definition ///////////////////////////////////////////
|
||||
|
||||
SCRIPT_STATE(STATE_Rotation, NO_DATA)
|
||||
{
|
||||
ADD_RULE("[/rotation]", SFN_PopState)
|
||||
ADD_RULE("/*", SFN_SkipComment)
|
||||
ADD_RULE("//", SFN_SkipLineComment)
|
||||
END_STATE_MARKER
|
||||
};
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// RESTRICTIONS STATE /////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Functions //////////////////////////////////////////////////
|
||||
|
||||
SCRIPT_FUNC(Restrictions_Cvar)
|
||||
{
|
||||
NEEDS_TOKENS(1, tokens);
|
||||
G_Printf("Cvar: %s = %s\n", tokens[0], tokens[1]);
|
||||
return 0;
|
||||
}
|
||||
END_SCRIPT_FUNC()
|
||||
|
||||
|
||||
SCRIPT_STATE(STATE_Restrictions, NO_DATA)
|
||||
{
|
||||
ADD_RULE("[/restrictions]", SFN_PopState)
|
||||
ADD_RULE("cvar", Restrictions_Cvar)
|
||||
ADD_RULE("/*", SFN_SkipComment)
|
||||
ADD_RULE("//", SFN_SkipLineComment)
|
||||
END_STATE_MARKER
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////
|
||||
|
||||
void G_ParseScript(const char *fname)
|
||||
{
|
||||
fileHandle_t file;
|
||||
int len = trap_FS_FOpenFile(fname, &file, FS_READ);
|
||||
|
||||
if (!file)
|
||||
return;
|
||||
|
||||
trap_FS_Read(scriptBuffer, len, file);
|
||||
scriptBuffer[len] = 0;
|
||||
|
||||
trap_FS_FCloseFile(file);
|
||||
|
||||
Script_ParseString(scriptBuffer, &STATE_Base);
|
||||
}
|
2
reaction/game/g_scripts.h
Normal file
2
reaction/game/g_scripts.h
Normal file
|
@ -0,0 +1,2 @@
|
|||
|
||||
void G_ParseScript(const char *fname);
|
|
@ -195,6 +195,14 @@ SOURCE=.\g_mover.c
|
|||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\g_parser.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\g_scripts.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\g_session.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
@ -359,6 +367,10 @@ SOURCE=.\g_public.h
|
|||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\g_scripts.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\g_team.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
|
|
@ -6,13 +6,14 @@
|
|||
--------------------Configuration: game - Win32 Debug--------------------
|
||||
</h3>
|
||||
<h3>Command Lines</h3>
|
||||
Creating temporary file "C:\DOCUME~1\Andrei\LOCALS~1\Temp\RSP312.tmp" with contents
|
||||
Creating temporary file "C:\DOCUME~1\Andrei\LOCALS~1\Temp\RSP451.tmp" with contents
|
||||
[
|
||||
/nologo /G5 /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "BUILDING_REF_GL" /D "DEBUG" /FR"Debug/" /Fp"Debug/game.pch" /YX /Fo"Debug/" /Fd"Debug/" /FD /c
|
||||
"D:\Work\rq3source\reaction\game\g_parser.c"
|
||||
"D:\Work\rq3source\reaction\game\g_scripts.c"
|
||||
]
|
||||
Creating command line "cl.exe @C:\DOCUME~1\Andrei\LOCALS~1\Temp\RSP312.tmp"
|
||||
Creating temporary file "C:\DOCUME~1\Andrei\LOCALS~1\Temp\RSP313.tmp" with contents
|
||||
Creating command line "cl.exe @C:\DOCUME~1\Andrei\LOCALS~1\Temp\RSP451.tmp"
|
||||
Creating temporary file "C:\DOCUME~1\Andrei\LOCALS~1\Temp\RSP452.tmp" with contents
|
||||
[
|
||||
kernel32.lib user32.lib winmm.lib /nologo /base:"0x20000000" /subsystem:windows /dll /incremental:yes /pdb:"d:\games\quake3\reaction/qagamex86.pdb" /map:"Debug/qagamex86.map" /debug /machine:I386 /def:".\game.def" /out:"D:\Work\rq3source\reaction\Release\qagamex86.dll" /implib:"d:\games\quake3\reaction/qagamex86.lib"
|
||||
.\Debug\ai_chat.obj
|
||||
|
@ -39,6 +40,8 @@ kernel32.lib user32.lib winmm.lib /nologo /base:"0x20000000" /subsystem:windows
|
|||
.\Debug\g_misc.obj
|
||||
.\Debug\g_missile.obj
|
||||
.\Debug\g_mover.obj
|
||||
.\Debug\g_parser.obj
|
||||
.\Debug\g_scripts.obj
|
||||
.\Debug\g_session.obj
|
||||
.\Debug\g_spawn.obj
|
||||
.\Debug\g_svcmds.obj
|
||||
|
@ -55,14 +58,14 @@ kernel32.lib user32.lib winmm.lib /nologo /base:"0x20000000" /subsystem:windows
|
|||
.\Debug\rxn_game.obj
|
||||
.\Debug\zcam.obj
|
||||
.\Debug\zcam_target.obj
|
||||
.\Debug\g_parser.obj
|
||||
]
|
||||
Creating command line "link.exe @C:\DOCUME~1\Andrei\LOCALS~1\Temp\RSP313.tmp"
|
||||
Creating command line "link.exe @C:\DOCUME~1\Andrei\LOCALS~1\Temp\RSP452.tmp"
|
||||
<h3>Output Window</h3>
|
||||
Compiling...
|
||||
g_parser.c
|
||||
g_scripts.c
|
||||
Linking...
|
||||
Creating temporary file "C:\DOCUME~1\Andrei\LOCALS~1\Temp\RSP314.tmp" with contents
|
||||
Creating temporary file "C:\DOCUME~1\Andrei\LOCALS~1\Temp\RSP453.tmp" with contents
|
||||
[
|
||||
/nologo /o"d:\games\quake3\reaction/game.bsc"
|
||||
.\Debug\ai_chat.sbr
|
||||
|
@ -89,6 +92,8 @@ Creating temporary file "C:\DOCUME~1\Andrei\LOCALS~1\Temp\RSP314.tmp" with conte
|
|||
.\Debug\g_misc.sbr
|
||||
.\Debug\g_missile.sbr
|
||||
.\Debug\g_mover.sbr
|
||||
.\Debug\g_parser.sbr
|
||||
.\Debug\g_scripts.sbr
|
||||
.\Debug\g_session.sbr
|
||||
.\Debug\g_spawn.sbr
|
||||
.\Debug\g_svcmds.sbr
|
||||
|
@ -104,9 +109,8 @@ Creating temporary file "C:\DOCUME~1\Andrei\LOCALS~1\Temp\RSP314.tmp" with conte
|
|||
.\Debug\q_shared.sbr
|
||||
.\Debug\rxn_game.sbr
|
||||
.\Debug\zcam.sbr
|
||||
.\Debug\zcam_target.sbr
|
||||
.\Debug\g_parser.sbr]
|
||||
Creating command line "bscmake.exe @C:\DOCUME~1\Andrei\LOCALS~1\Temp\RSP314.tmp"
|
||||
.\Debug\zcam_target.sbr]
|
||||
Creating command line "bscmake.exe @C:\DOCUME~1\Andrei\LOCALS~1\Temp\RSP453.tmp"
|
||||
Creating browse info file...
|
||||
<h3>Output Window</h3>
|
||||
|
||||
|
|
Loading…
Reference in a new issue