2001-02-19 21:15:25 +00:00
|
|
|
/*
|
|
|
|
progs.h
|
|
|
|
|
2010-12-09 04:35:11 +00:00
|
|
|
Progs VM Engine interface.
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2001-08-27 21:13:00 +00:00
|
|
|
#ifndef __QF_progs_h
|
|
|
|
#define __QF_progs_h
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
/** \defgroup progs QuakeC Virtual Machine (VM)
|
2011-08-23 05:31:03 +00:00
|
|
|
\image html vm-mem.svg
|
2004-11-08 23:27:00 +00:00
|
|
|
\image latex vm-mem.eps "VM memory map"
|
|
|
|
*/
|
|
|
|
|
2022-01-23 12:54:03 +00:00
|
|
|
#include "QF/math/bitop.h"
|
2022-01-08 15:26:52 +00:00
|
|
|
#include "QF/progs/pr_comp.h"
|
|
|
|
#include "QF/progs/pr_debug.h"
|
2010-12-09 05:27:36 +00:00
|
|
|
|
|
|
|
struct QFile_s;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2006-12-05 11:40:00 +00:00
|
|
|
/** \ingroup progs */
|
2020-02-11 06:20:49 +00:00
|
|
|
///@{
|
2001-02-26 20:52:14 +00:00
|
|
|
typedef struct progs_s progs_t;
|
2002-01-30 06:21:20 +00:00
|
|
|
typedef struct pr_resource_s pr_resource_t;
|
2004-11-08 23:27:00 +00:00
|
|
|
typedef struct edict_s edict_t;
|
2020-02-11 06:20:49 +00:00
|
|
|
///@}
|
2002-01-30 06:21:20 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
//============================================================================
|
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
/** \defgroup progs_misc Miscelaneous functions
|
2006-12-05 11:40:00 +00:00
|
|
|
\ingroup progs
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2020-02-11 06:20:49 +00:00
|
|
|
///@{
|
2004-11-08 23:27:00 +00:00
|
|
|
|
|
|
|
/** Initialize the progs engine.
|
2020-02-23 06:56:36 +00:00
|
|
|
|
|
|
|
The first call will initialize subsystems common to all progs instances.
|
|
|
|
|
|
|
|
\param pr The progs engine instance to initialize.
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2020-02-23 06:56:36 +00:00
|
|
|
void PR_Init (progs_t *pr);
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2022-05-12 09:23:32 +00:00
|
|
|
/** Shut down the progs engine.
|
|
|
|
|
|
|
|
Shuts down only the specified progs engine. Frees resources allocated
|
|
|
|
during progs init.
|
|
|
|
|
|
|
|
\param pr The progs engine instance to shut down.
|
|
|
|
*/
|
|
|
|
void PR_Shutdown (progs_t *pr);
|
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
/** Initialize the Cvars for the progs engine. Call before calling PR_Init().
|
|
|
|
*/
|
2001-02-26 20:52:14 +00:00
|
|
|
void PR_Init_Cvars (void);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2021-03-27 10:52:59 +00:00
|
|
|
void PR_Error (progs_t *pr, const char *error, ...) __attribute__((format(PRINTF,2,3), noreturn));
|
|
|
|
void PR_RunError (progs_t *pr, const char *error, ...) __attribute__((format(PRINTF,2,3), noreturn));
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2020-02-11 06:20:49 +00:00
|
|
|
///@}
|
2004-11-08 23:27:00 +00:00
|
|
|
|
|
|
|
/** \defgroup progs_execution Execution
|
2006-12-05 11:40:00 +00:00
|
|
|
\ingroup progs
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2020-02-11 06:20:49 +00:00
|
|
|
///@{
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2005-06-12 09:54:01 +00:00
|
|
|
/** Ensure P_* macros point to the right place for passing parameters to progs
|
|
|
|
functions.
|
2010-12-09 04:35:11 +00:00
|
|
|
\param pr pointer to ::progs_t VM struct
|
|
|
|
|
|
|
|
\warning Failure to use this macro before assigning to the P_* macros can
|
2006-12-05 11:40:00 +00:00
|
|
|
cause corruption of the VM data due to "register" based calling. Can be
|
2010-01-13 06:28:28 +00:00
|
|
|
safely ignored for parameterless functions, or forwarding parameters
|
2022-01-24 03:50:15 +00:00
|
|
|
though a builtin. However, it is ok (and encouraged) to call
|
|
|
|
PR_SetupParams instead, as this macro calls PR_SetupParams with
|
|
|
|
PR_MAX_PARAMS and 1 for the alignment.
|
2006-12-05 11:40:00 +00:00
|
|
|
|
|
|
|
\hideinitializer
|
2005-06-12 09:54:01 +00:00
|
|
|
*/
|
2022-01-24 03:50:15 +00:00
|
|
|
#define PR_RESET_PARAMS(pr) PR_SetupParams (pr, PR_MAX_PARAMS, 1)
|
2005-06-12 09:54:01 +00:00
|
|
|
|
2020-02-25 05:30:26 +00:00
|
|
|
/** \name Detouring Function Calls
|
|
|
|
|
|
|
|
These functions allow a builtin function that uses PR_CallFunction() to
|
|
|
|
safely insert a call to another VM function. The +initialize diversion
|
|
|
|
required by Objective-QuakeC uses this.
|
|
|
|
|
|
|
|
PR_PushFrame (pr);
|
|
|
|
__auto_type params = PR_SaveParams (pr);
|
|
|
|
... set up parameters to detour_function
|
|
|
|
PR_ExecuteProgram (pr, detour_function)
|
|
|
|
PR_RestoreParams (pr, params);
|
|
|
|
PR_PopFrame (pr);
|
|
|
|
|
|
|
|
*/
|
|
|
|
///@{
|
|
|
|
typedef struct pr_stashed_params_s {
|
|
|
|
pr_type_t *param_ptrs[2];
|
|
|
|
int argc;
|
|
|
|
pr_type_t params[1];
|
|
|
|
} pr_stashed_params_t;
|
|
|
|
|
|
|
|
/** Save the current parameters to the provided stash.
|
|
|
|
|
|
|
|
\warning The memory for the parameter stash is allocated using
|
|
|
|
alloca().
|
|
|
|
|
2010-12-09 04:35:11 +00:00
|
|
|
\param pr pointer to ::progs_t VM struct
|
2021-03-21 14:03:11 +00:00
|
|
|
\return Pointer to a newly allocated and initialized parameter
|
2020-02-25 05:30:26 +00:00
|
|
|
stash that has the current parameters saved to it.
|
|
|
|
\hideinitializer
|
2007-06-09 13:44:06 +00:00
|
|
|
*/
|
2020-02-25 05:30:26 +00:00
|
|
|
#define PR_SaveParams(pr) \
|
|
|
|
_PR_SaveParams((pr), \
|
|
|
|
alloca (field_offset (pr_stashed_params_t, \
|
|
|
|
params[(pr)->pr_argc \
|
|
|
|
* (pr)->pr_param_size])))
|
|
|
|
|
|
|
|
/** [INTERNAL] Save the current parameters to the provided stash.
|
|
|
|
|
|
|
|
\warning Requires \a params to be correctly allocated. Use
|
|
|
|
PR_SaveParams instead as it will create a suitable stash for
|
|
|
|
saving the parameters.
|
|
|
|
|
2010-12-09 04:35:11 +00:00
|
|
|
\param pr pointer to ::progs_t VM struct
|
2020-02-25 05:30:26 +00:00
|
|
|
\param params location to save the parameters, must be of adequade size
|
|
|
|
to hold \a pr_argc * \a pr_param_size words in \a params
|
2021-03-21 14:03:11 +00:00
|
|
|
\return \a params Allows the likes of:
|
2020-02-25 05:30:26 +00:00
|
|
|
__auto_type params = PR_SaveParams (pr);
|
2007-06-09 13:44:06 +00:00
|
|
|
*/
|
2020-02-25 05:30:26 +00:00
|
|
|
pr_stashed_params_t *_PR_SaveParams (progs_t *pr, pr_stashed_params_t *params);
|
2007-06-09 13:44:06 +00:00
|
|
|
|
|
|
|
/** Restore the parameters saved by PR_SaveParams().
|
2010-12-09 04:35:11 +00:00
|
|
|
\param pr pointer to ::progs_t VM struct
|
2020-02-25 05:30:26 +00:00
|
|
|
\param params pointer to stash created by PR_SaveParams()
|
2007-06-09 13:44:06 +00:00
|
|
|
*/
|
2020-02-25 05:30:26 +00:00
|
|
|
void PR_RestoreParams (progs_t *pr, pr_stashed_params_t *params);
|
|
|
|
///@}
|
2007-06-09 13:44:06 +00:00
|
|
|
|
2006-12-05 11:40:00 +00:00
|
|
|
/** Push an execution frame onto the VM stack. Saves current execution state.
|
2010-12-09 04:35:11 +00:00
|
|
|
\param pr pointer to ::progs_t VM struct
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2004-01-05 07:10:32 +00:00
|
|
|
void PR_PushFrame (progs_t *pr);
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2022-01-24 03:50:15 +00:00
|
|
|
/** Reserve space on the data stack and set up the param pointers.
|
|
|
|
|
|
|
|
For v6p progs, this only sets up the param pointers as v6p progs do not
|
|
|
|
have a data stack.
|
|
|
|
|
|
|
|
For Ruamoko progs, space for at least \a num_params (each being 4 words)
|
|
|
|
is created on the stack, with a minimum alignment of min_alignment words,
|
|
|
|
or 4, whichever is larger.
|
|
|
|
|
|
|
|
\param pr pointer to ::progs_t VM struct
|
|
|
|
\param num_params Number of parameter slots needed for the function call.
|
|
|
|
Each slot is 4 words. dvec4 and lvec4 parameters require
|
|
|
|
8 words and must be 8-word aligned. dvec3 and lvec3
|
|
|
|
also require 8 words due to the minimum 4 word alignment,
|
|
|
|
but have no alignment requirements themselves. Be sure to
|
|
|
|
take this into account in size calculations.
|
|
|
|
\param min_alignment Minimum number of words to which the stack will be
|
|
|
|
aligned. Must be a power of two. Note that when passing
|
|
|
|
dvec4 or lvec4 parameters, they have a hardware-enforced
|
|
|
|
requirement of 8 word alignment. This means that for
|
|
|
|
something like (int, lvec4), there will be an unused
|
|
|
|
parameter slot between the int and the lvec4.
|
|
|
|
Ignored for v6p progs.
|
|
|
|
\return Pointer to the base of the created parameter area. For
|
|
|
|
v6p progs, this is just .param_0, but for Ruamoko progs
|
|
|
|
this will be the current top of the the data stack after
|
|
|
|
adjustment for the parameter space.
|
|
|
|
\note Attempting to pass more than PR_MAX_PARAMS parameters to v6p progs
|
|
|
|
is a hard error.
|
|
|
|
*/
|
|
|
|
pr_type_t *PR_SetupParams (progs_t *pr, int num_params, int min_alignment);
|
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
/** Pop an execution frame from the VM stack. Restores execution state. Also
|
|
|
|
frees any temporary strings allocated in this frame (via
|
|
|
|
PR_FreeTempStrings()).
|
2010-12-09 04:35:11 +00:00
|
|
|
\param pr pointer to ::progs_t VM struct
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2004-01-05 07:10:32 +00:00
|
|
|
void PR_PopFrame (progs_t *pr);
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2010-12-09 04:35:11 +00:00
|
|
|
/** Run a progs function. If \p fnum is a builtin rather than a progs
|
2004-11-08 23:27:00 +00:00
|
|
|
function, PR_ExecuteProgram() will call the function and then immediately
|
|
|
|
return to the caller. Nested calls are fully supported.
|
2010-12-09 04:35:11 +00:00
|
|
|
\param pr pointer to ::progs_t VM struct
|
|
|
|
\param fnum number of the function to call
|
2022-01-22 02:38:26 +00:00
|
|
|
\note Calls PR_CallFunction()
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2022-01-18 06:32:43 +00:00
|
|
|
void PR_ExecuteProgram (progs_t *pr, pr_func_t fnum);
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2006-12-05 11:40:00 +00:00
|
|
|
/** Setup to call a function. If \p fnum is a builtin rather than a progs
|
2004-11-08 23:27:00 +00:00
|
|
|
function, then the function is called immediately. When called from a
|
2010-12-09 04:35:11 +00:00
|
|
|
builtin function, and \p fnum is not a builtin, the progs function will
|
|
|
|
execute upon return of control to PR_ExecuteProgram().
|
|
|
|
\param pr pointer to ::progs_t VM struct
|
|
|
|
\param fnum number of the function to call
|
2022-01-17 10:12:28 +00:00
|
|
|
\param return_ptr pointer to location in which return values will be
|
|
|
|
written
|
2010-12-09 04:35:11 +00:00
|
|
|
\return true if \p fnum was a progs function, false if \p fnum was
|
|
|
|
a builtin
|
2022-01-22 02:38:26 +00:00
|
|
|
\note Called by PR_ExecuteProgram, so the only time this should be called
|
|
|
|
is in a builtin function that calls a progs function and returns
|
|
|
|
immediately (eg, to implement `return progsfunc();`).
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2022-01-18 06:32:43 +00:00
|
|
|
int PR_CallFunction (progs_t *pr, pr_func_t fnum, pr_type_t *return_ptr);
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2020-02-11 06:20:49 +00:00
|
|
|
///@}
|
2004-11-08 23:27:00 +00:00
|
|
|
|
|
|
|
/** \defgroup progs_load Loading
|
2006-12-05 11:40:00 +00:00
|
|
|
\ingroup progs
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2020-02-11 06:20:49 +00:00
|
|
|
///@{
|
2004-11-08 23:27:00 +00:00
|
|
|
|
|
|
|
/** Type of functions that are called at progs load.
|
2010-12-09 04:35:11 +00:00
|
|
|
\param pr pointer to ::progs_t VM struct
|
|
|
|
\return true for success, false for failure
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
|
|
|
typedef int pr_load_func_t (progs_t *pr);
|
|
|
|
|
2006-12-05 11:40:00 +00:00
|
|
|
/** Initialize a ::progs_t VM struct from an already open file.
|
2010-12-09 04:35:11 +00:00
|
|
|
\param pr pointer to ::progs_t VM struct
|
2022-01-22 01:57:26 +00:00
|
|
|
\param file handle of file from which to read progs data
|
2010-12-09 04:35:11 +00:00
|
|
|
\param size bytes of \p file to read
|
2004-11-08 23:27:00 +00:00
|
|
|
|
|
|
|
\note \e All runtime strings (permanent or temporary) are allocated from
|
2018-10-11 01:06:48 +00:00
|
|
|
the VM's dynamic memory space, so be sure \p zone is of sufficient size
|
|
|
|
(by setting pr->zone_size prior to calling). So far, 1MB has proven more
|
|
|
|
than sufficient for Quakeword, even when using Ruamoko objects.
|
|
|
|
\note If entities are used, ensure pr->max_edicts is set appropriately
|
|
|
|
prior to calling.
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2018-10-11 01:06:48 +00:00
|
|
|
void PR_LoadProgsFile (progs_t *pr, struct QFile_s *file, int size);
|
2004-11-08 23:27:00 +00:00
|
|
|
|
|
|
|
/** Convenience wrapper for PR_LoadProgsFile() and PR_RunLoadFuncs().
|
|
|
|
Searches for the specified file in the Quake filesystem.
|
2010-12-09 04:35:11 +00:00
|
|
|
\param pr pointer to ::progs_t VM struct
|
2004-11-08 23:27:00 +00:00
|
|
|
\param progsname name of the file to load as progs data
|
|
|
|
*/
|
2018-10-11 01:06:48 +00:00
|
|
|
void PR_LoadProgs (progs_t *pr, const char *progsname);
|
2004-11-08 23:27:00 +00:00
|
|
|
|
|
|
|
/** Register a primary function to be called after the progs code has been
|
|
|
|
loaded. These functions are remembered across progs loads. They will be
|
|
|
|
called in order of registration.
|
2010-12-09 04:35:11 +00:00
|
|
|
\param pr pointer to ::progs_t VM struct
|
|
|
|
\param func function to call
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
|
|
|
void PR_AddLoadFunc (progs_t *pr, pr_load_func_t *func);
|
|
|
|
|
|
|
|
/** Register a secondary function to be called after the progs code has been
|
|
|
|
loaded. These functions will be forgotten after each load. They will be
|
2012-05-21 23:23:22 +00:00
|
|
|
called in \e reverse order of being registered.
|
2010-12-09 04:35:11 +00:00
|
|
|
\param pr pointer to ::progs_t VM struct
|
|
|
|
\param func function to call
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
|
|
|
void PR_AddLoadFinishFunc (progs_t *pr, pr_load_func_t *func);
|
|
|
|
|
|
|
|
/** Run all load functions. Any load function returning false will abort the
|
|
|
|
load operation.
|
2010-12-09 04:35:11 +00:00
|
|
|
\param pr pointer to ::progs_t VM struct
|
|
|
|
\return true for success, false for failure
|
2004-11-08 23:27:00 +00:00
|
|
|
|
|
|
|
Calls the first set of internal load functions followed by the supplied
|
2020-04-02 08:28:37 +00:00
|
|
|
symbol resolution function, if any (progs_t::resolve), then the second set
|
|
|
|
of internal load functions. After that, any primary load functions are
|
|
|
|
called in order of registration, and if there is no debug handler,
|
|
|
|
PR_RunPostLoadFuncs() is called.
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
|
|
|
int PR_RunLoadFuncs (progs_t *pr);
|
|
|
|
|
2020-04-02 08:28:37 +00:00
|
|
|
/** Run any progs-dependent load functions.
|
|
|
|
\param pr pointer to ::progs_t VM struct
|
|
|
|
\return true for success, false for failure
|
|
|
|
This means any \c .ctor functions in the progs, followed by any secondary
|
|
|
|
load functions registered by either the primary load functions or the
|
|
|
|
\.c ctor functions in \e reverse order of registration. This is called
|
|
|
|
automatically by PR_RunLoadFuncs() if there is no debug handler, otherwise
|
|
|
|
it is up to the host to call this function.
|
|
|
|
*/
|
|
|
|
int PR_RunPostLoadFuncs (progs_t *pr);
|
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
/** Validate the opcodes and statement addresses in the progs. This is an
|
|
|
|
internal load function.
|
2010-12-09 04:35:11 +00:00
|
|
|
\param pr pointer to ::progs_t VM struct
|
|
|
|
\return true for success, false for failure
|
2004-11-08 23:27:00 +00:00
|
|
|
|
|
|
|
\todo should this be elsewhere?
|
|
|
|
*/
|
2003-11-20 07:46:56 +00:00
|
|
|
int PR_Check_Opcodes (progs_t *pr);
|
2022-01-21 11:31:49 +00:00
|
|
|
int PR_Check_v6p_Opcodes (progs_t *pr);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2022-01-18 03:11:14 +00:00
|
|
|
void PR_BoundsCheckSize (progs_t *pr, pr_ptr_t addr, unsigned size);
|
2010-01-13 06:36:16 +00:00
|
|
|
void PR_BoundsCheck (progs_t *pr, int addr, etype_t type);
|
|
|
|
|
2020-02-11 06:20:49 +00:00
|
|
|
///@}
|
2004-11-08 23:27:00 +00:00
|
|
|
|
|
|
|
/** \defgroup progs_edict Edict management
|
2006-12-05 11:40:00 +00:00
|
|
|
\ingroup progs
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2020-02-11 06:20:49 +00:00
|
|
|
///@{
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
struct edict_s {
|
2023-06-13 09:06:11 +00:00
|
|
|
bool free;
|
2013-01-17 05:11:54 +00:00
|
|
|
progs_t *pr; ///< progs owning this edict
|
2022-01-16 13:15:18 +00:00
|
|
|
pr_uint_t entnum; ///< number of this entity
|
|
|
|
pr_uint_t edict; ///< offset of this entity in pr_edict_area
|
2004-11-08 23:27:00 +00:00
|
|
|
float freetime; ///< sv.time when the object was freed
|
2010-12-09 05:27:36 +00:00
|
|
|
void *edata; ///< external per-edict data
|
2004-11-08 23:27:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// pr_edict.c
|
2003-12-05 22:33:11 +00:00
|
|
|
void ED_ClearEdict (progs_t *pr, edict_t *e, int val);
|
2001-02-26 20:52:14 +00:00
|
|
|
edict_t *ED_Alloc (progs_t *pr);
|
|
|
|
void ED_Free (progs_t *pr, edict_t *ed);
|
2022-01-16 13:15:18 +00:00
|
|
|
edict_t *ED_EdictNum(progs_t *pr, pr_uint_t n) __attribute__((pure));
|
|
|
|
pr_uint_t ED_NumForEdict(progs_t *pr, edict_t *e) __attribute__((pure));
|
2004-11-08 23:27:00 +00:00
|
|
|
void ED_Count (progs_t *pr);
|
2023-06-13 09:06:11 +00:00
|
|
|
bool PR_EdictValid (progs_t *pr, pr_uint_t e) __attribute__((pure));
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
// pr_debug.c
|
2021-07-25 00:54:08 +00:00
|
|
|
void ED_Print (progs_t *pr, edict_t *ed, const char *fieldname);
|
2004-11-08 23:27:00 +00:00
|
|
|
void ED_PrintEdicts (progs_t *pr, const char *fieldval);
|
2021-07-25 00:54:08 +00:00
|
|
|
void ED_PrintNum (progs_t *pr, pr_int_t ent, const char *fieldname);
|
2001-02-26 20:52:14 +00:00
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
// pr_parse.c
|
|
|
|
struct script_s;
|
2006-12-09 00:02:57 +00:00
|
|
|
struct plitem_s;
|
2022-05-12 08:54:23 +00:00
|
|
|
struct hashctx_s;
|
2023-06-13 09:06:11 +00:00
|
|
|
bool ED_ParseEpair (progs_t *pr, pr_type_t *base, pr_def_t *key,
|
2004-11-08 23:27:00 +00:00
|
|
|
const char *s);
|
2006-12-09 02:35:44 +00:00
|
|
|
struct plitem_s *ED_EntityDict (progs_t *pr, edict_t *ed);
|
|
|
|
struct plitem_s *ED_GlobalsDict (progs_t *pr);
|
2006-12-09 00:02:57 +00:00
|
|
|
void ED_InitGlobals (progs_t *pr, struct plitem_s *globals);
|
|
|
|
void ED_InitEntity (progs_t *pr, struct plitem_s *entity, edict_t *ent);
|
2021-02-09 00:57:07 +00:00
|
|
|
struct plitem_s *ED_ConvertToPlist (struct script_s *script, int nohack,
|
2022-05-12 08:54:23 +00:00
|
|
|
struct hashctx_s **hashctx);
|
2010-12-10 03:46:54 +00:00
|
|
|
struct plitem_s *ED_Parse (progs_t *pr, const char *data);
|
2001-07-15 07:04:17 +00:00
|
|
|
void ED_LoadFromFile (progs_t *pr, const char *data);
|
2022-02-14 03:28:38 +00:00
|
|
|
void ED_EntityParseFunction (progs_t *pr, void *data);
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2013-01-17 05:11:54 +00:00
|
|
|
#define PR_edicts(p) (*(p)->pr_edicts)
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2022-02-05 01:17:57 +00:00
|
|
|
#define NEXT_EDICT(p,e) ((e) ? (e) + 1 : 0)
|
|
|
|
#define EDICT_TO_PROG(p,e) ((e) ? (e)->entnum * (p)->pr_edict_size : 0)
|
2013-01-17 05:11:54 +00:00
|
|
|
#define PROG_TO_EDICT(p,e) (&PR_edicts(p)[(e) / (p)->pr_edict_size])
|
2022-02-05 01:17:57 +00:00
|
|
|
#define NUM_FOR_BAD_EDICT(p,e) ((e) ? (e)->entnum : 0)
|
2004-11-08 23:27:00 +00:00
|
|
|
#ifndef PR_PARANOID_PROGS
|
2013-01-17 05:11:54 +00:00
|
|
|
# define EDICT_NUM(p,n) (PR_edicts (p) + (n))
|
|
|
|
# define NUM_FOR_EDICT(p,e) NUM_FOR_BAD_EDICT ((p), (e))
|
2004-11-08 23:27:00 +00:00
|
|
|
#else
|
2013-01-17 05:11:54 +00:00
|
|
|
# define EDICT_NUM(p,n) ED_EdictNum ((p), (n))
|
|
|
|
# define NUM_FOR_EDICT(p,e) ED_NumForEdict ((p), (e))
|
2004-11-08 23:27:00 +00:00
|
|
|
#endif
|
|
|
|
|
2020-02-11 06:20:49 +00:00
|
|
|
///@}
|
2004-11-08 23:27:00 +00:00
|
|
|
|
|
|
|
/** \defgroup pr_symbols Symbol Management
|
2006-12-05 11:40:00 +00:00
|
|
|
\ingroup progs
|
2004-11-08 23:27:00 +00:00
|
|
|
Lookup functions for symbol name resolution.
|
|
|
|
*/
|
2020-02-11 06:20:49 +00:00
|
|
|
///@{
|
2001-02-26 20:52:14 +00:00
|
|
|
|
2022-01-18 03:11:14 +00:00
|
|
|
pr_def_t *PR_SearchDefs (pr_def_t *defs, unsigned num_defs, pr_ptr_t offset)
|
2020-03-14 17:48:13 +00:00
|
|
|
__attribute__((pure));
|
2022-01-18 03:11:14 +00:00
|
|
|
pr_def_t *PR_FieldAtOfs (progs_t *pr, pr_ptr_t ofs) __attribute__((pure));
|
|
|
|
pr_def_t *PR_GlobalAtOfs (progs_t *pr, pr_ptr_t ofs) __attribute__((pure));
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2020-02-22 13:33:44 +00:00
|
|
|
pr_def_t *PR_FindField (progs_t *pr, const char *name);
|
|
|
|
pr_def_t *PR_FindGlobal (progs_t *pr, const char *name);
|
2004-11-05 11:49:00 +00:00
|
|
|
dfunction_t *PR_FindFunction (progs_t *pr, const char *name);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
int PR_ResolveGlobals (progs_t *pr);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
int PR_AccessField (progs_t *pr, const char *name, etype_t type,
|
|
|
|
const char *file, int line);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
void PR_Undefined (progs_t *pr, const char *type, const char *name) __attribute__((noreturn));
|
2020-02-11 06:20:49 +00:00
|
|
|
///@}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
/** \defgroup progs_data_access Data Access
|
2006-12-05 11:40:00 +00:00
|
|
|
\ingroup progs
|
2004-11-08 23:27:00 +00:00
|
|
|
Macros for accessing data in the VM address space
|
|
|
|
*/
|
2006-12-05 11:40:00 +00:00
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
/** \defgroup prda_globals Globals
|
2006-12-05 11:40:00 +00:00
|
|
|
\ingroup progs_data_access
|
2011-07-25 19:52:24 +00:00
|
|
|
Typed global access macros. No checking is done against the QC type, but
|
2006-12-05 11:40:00 +00:00
|
|
|
the appropriate C type will be used.
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2020-02-11 06:20:49 +00:00
|
|
|
///@{
|
2006-12-05 11:40:00 +00:00
|
|
|
|
2020-03-25 13:36:04 +00:00
|
|
|
/** Access a global as an arbitray type.
|
|
|
|
|
|
|
|
More direct than G_STRUCT
|
|
|
|
\par QC type:
|
|
|
|
\c struct etc small enough to fit in a single parameter
|
|
|
|
\param p pointer to ::progs_t VM struct
|
|
|
|
\param t C type of the structure
|
|
|
|
\param o offset into global data space
|
|
|
|
\return structure lvalue. use & to make a pointer of the
|
|
|
|
appropriate type.
|
|
|
|
|
|
|
|
\hideinitializer
|
|
|
|
*/
|
|
|
|
#define G_PACKED(p,t,o) (*(t *) &(p)->pr_globals[o])
|
|
|
|
|
2022-04-26 06:10:00 +00:00
|
|
|
/** \internal
|
|
|
|
\param p pointer to ::progs_t VM struct
|
|
|
|
\param o offset into global data space
|
|
|
|
\param t typename prefix (see pr_type_u)
|
|
|
|
\return lvalue of the appropriate type
|
|
|
|
|
|
|
|
\hideinitializer
|
|
|
|
*/
|
|
|
|
#define G_var(p,o,t) G_PACKED(p, pr_##t##_t, o)
|
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
/** Access a float global. Can be assigned to.
|
|
|
|
|
2006-12-04 13:08:52 +00:00
|
|
|
\par QC type:
|
|
|
|
\c float
|
2010-12-09 04:35:11 +00:00
|
|
|
\param p pointer to ::progs_t VM struct
|
|
|
|
\param o offset into global data space
|
|
|
|
\return float lvalue
|
2006-12-05 11:40:00 +00:00
|
|
|
|
|
|
|
\hideinitializer
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2003-12-06 22:49:18 +00:00
|
|
|
#define G_FLOAT(p,o) G_var (p, o, float)
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2020-02-14 07:38:37 +00:00
|
|
|
/** Access a double global. Can be assigned to.
|
|
|
|
|
|
|
|
\par QC type:
|
|
|
|
\c double
|
|
|
|
\param p pointer to ::progs_t VM struct
|
|
|
|
\param o offset into global data space
|
|
|
|
\return double lvalue
|
|
|
|
|
|
|
|
\hideinitializer
|
|
|
|
*/
|
2022-04-26 06:10:00 +00:00
|
|
|
#define G_DOUBLE(p,o) G_var (p, o, double)
|
2020-02-14 07:38:37 +00:00
|
|
|
|
2022-01-18 04:21:06 +00:00
|
|
|
/** Access an int global. Can be assigned to.
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2006-12-04 13:08:52 +00:00
|
|
|
\par QC type:
|
2022-01-18 04:21:06 +00:00
|
|
|
\c int
|
2010-12-09 04:35:11 +00:00
|
|
|
\param p pointer to ::progs_t VM struct
|
|
|
|
\param o offset into global data space
|
|
|
|
\return int lvalue
|
2006-12-05 11:40:00 +00:00
|
|
|
|
|
|
|
\hideinitializer
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2022-01-18 04:21:06 +00:00
|
|
|
#define G_INT(p,o) G_var (p, o, int)
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2022-01-18 04:21:06 +00:00
|
|
|
/** Access an unsigned int global. Can be assigned to.
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2006-12-04 13:08:52 +00:00
|
|
|
\par QC type:
|
2022-01-18 04:21:06 +00:00
|
|
|
\c uint
|
2010-12-09 04:35:11 +00:00
|
|
|
\param p pointer to ::progs_t VM struct
|
|
|
|
\param o offset into global data space
|
|
|
|
\return unsigned int lvalue
|
2006-12-05 11:40:00 +00:00
|
|
|
|
|
|
|
\hideinitializer
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2022-01-18 04:21:06 +00:00
|
|
|
#define G_UINT(p,o) G_var (p, o, uint)
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2022-04-26 08:19:47 +00:00
|
|
|
/** Access a long global. Can be assigned to.
|
|
|
|
|
|
|
|
\par QC type:
|
|
|
|
\c long
|
|
|
|
\param p pointer to ::progs_t VM struct
|
|
|
|
\param o offset into global data space
|
|
|
|
\return long lvalue
|
|
|
|
|
|
|
|
\hideinitializer
|
|
|
|
*/
|
|
|
|
#define G_LONG(p,o) G_var (p, o, long)
|
|
|
|
|
|
|
|
/** Access an unsigned long global. Can be assigned to.
|
|
|
|
|
|
|
|
\par QC type:
|
|
|
|
\c ulong
|
|
|
|
\param p pointer to ::progs_t VM struct
|
|
|
|
\param o offset into global data space
|
|
|
|
\return unsigned long lvalue
|
|
|
|
|
|
|
|
\hideinitializer
|
|
|
|
*/
|
|
|
|
#define G_ULONG(p,o) G_var (p, o, ulong)
|
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
/** Access a vector global. Can be assigned to.
|
|
|
|
|
2006-12-04 13:08:52 +00:00
|
|
|
\par QC type:
|
|
|
|
\c vector
|
2010-12-09 04:35:11 +00:00
|
|
|
\param p pointer to ::progs_t VM struct
|
|
|
|
\param o offset into global data space
|
|
|
|
\return vec3_t lvalue
|
2006-12-05 11:40:00 +00:00
|
|
|
|
|
|
|
\hideinitializer
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2022-04-26 06:10:00 +00:00
|
|
|
#define G_VECTOR(p,o) (&G_var (p, o, float))
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2011-02-12 13:57:37 +00:00
|
|
|
/** Access a quaternion global. Can be assigned to.
|
|
|
|
|
|
|
|
\par QC type:
|
|
|
|
\c quaternion
|
|
|
|
\param p pointer to ::progs_t VM struct
|
|
|
|
\param o offset into global data space
|
|
|
|
\return quat_t lvalue
|
|
|
|
|
|
|
|
\hideinitializer
|
|
|
|
*/
|
2022-04-26 06:10:00 +00:00
|
|
|
#define G_QUAT(p,o) (&G_var (p, o, float))
|
2011-02-12 13:57:37 +00:00
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
/** Access a string index global. Can be assigned to.
|
|
|
|
|
2006-12-04 13:08:52 +00:00
|
|
|
\par QC type:
|
|
|
|
\c string
|
2010-12-09 04:35:11 +00:00
|
|
|
\param p pointer to ::progs_t VM struct
|
|
|
|
\param o offset into global data space
|
2022-01-18 03:11:14 +00:00
|
|
|
\return pr_string_t lvalue
|
2006-12-05 11:40:00 +00:00
|
|
|
|
|
|
|
\hideinitializer
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2003-04-22 18:20:15 +00:00
|
|
|
#define G_STRING(p,o) G_var (p, o, string)
|
2004-11-08 23:27:00 +00:00
|
|
|
|
|
|
|
/** Access a function global. Can be assigned to.
|
|
|
|
|
2006-12-04 13:08:52 +00:00
|
|
|
\par QC type:
|
|
|
|
\c void()
|
2010-12-09 04:35:11 +00:00
|
|
|
\param p pointer to ::progs_t VM struct
|
|
|
|
\param o offset into global data space
|
2022-01-18 06:32:43 +00:00
|
|
|
\return pr_func_t lvalue
|
2006-12-05 11:40:00 +00:00
|
|
|
|
|
|
|
\hideinitializer
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2003-12-06 22:49:18 +00:00
|
|
|
#define G_FUNCTION(p,o) G_var (p, o, func)
|
2004-11-08 23:27:00 +00:00
|
|
|
|
|
|
|
/** Access a pointer global. Can be assigned to.
|
|
|
|
|
2006-12-04 13:08:52 +00:00
|
|
|
\par QC type:
|
2011-07-09 00:41:30 +00:00
|
|
|
\c void *
|
2010-12-09 04:35:11 +00:00
|
|
|
\param p pointer to ::progs_t VM struct
|
|
|
|
\param o offset into global data space
|
2022-01-18 03:11:14 +00:00
|
|
|
\return pr_ptr_t lvalue
|
2006-12-05 11:40:00 +00:00
|
|
|
|
|
|
|
\hideinitializer
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2022-04-26 06:10:00 +00:00
|
|
|
#define G_POINTER(p,o) G_var (p, o, ptr)
|
|
|
|
|
|
|
|
/** Access a field global.
|
|
|
|
|
|
|
|
\par QC type:
|
|
|
|
\c field
|
|
|
|
\param p pointer to ::progs_t VM struct
|
|
|
|
\param o offset into global data space
|
|
|
|
\return field offset
|
|
|
|
|
|
|
|
\hideinitializer
|
|
|
|
*/
|
|
|
|
#define G_FIELD(p,o) G_var (p, o, field)
|
|
|
|
|
|
|
|
/** Access an entity global.
|
|
|
|
|
|
|
|
\par QC type:
|
|
|
|
\c entity
|
|
|
|
\param p pointer to ::progs_t VM struct
|
|
|
|
\param o offset into global data space
|
|
|
|
\return entity "pointer"
|
2003-04-22 18:20:15 +00:00
|
|
|
|
2022-04-26 06:10:00 +00:00
|
|
|
\hideinitializer
|
|
|
|
*/
|
|
|
|
#define G_ENTITY(p,o) G_var (p, o, entity)
|
2004-11-08 23:27:00 +00:00
|
|
|
|
|
|
|
/** Access an entity global.
|
|
|
|
|
2006-12-04 13:08:52 +00:00
|
|
|
\par QC type:
|
|
|
|
\c entity
|
2010-12-09 04:35:11 +00:00
|
|
|
\param p pointer to ::progs_t VM struct
|
|
|
|
\param o offset into global data space
|
|
|
|
\return C pointer to the entity
|
2006-12-05 11:40:00 +00:00
|
|
|
|
|
|
|
\hideinitializer
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2013-01-17 05:11:54 +00:00
|
|
|
#define G_EDICT(p,o) PROG_TO_EDICT ((p), G_INT (p, o))
|
2004-11-08 23:27:00 +00:00
|
|
|
|
|
|
|
/** Access an entity global.
|
|
|
|
|
2006-12-04 13:08:52 +00:00
|
|
|
\par QC type:
|
|
|
|
\c entity
|
2010-12-09 04:35:11 +00:00
|
|
|
\param p pointer to ::progs_t VM struct
|
|
|
|
\param o offset into global data space
|
|
|
|
\return the entity number
|
2006-12-05 11:40:00 +00:00
|
|
|
|
|
|
|
\hideinitializer
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2003-04-22 18:20:15 +00:00
|
|
|
#define G_EDICTNUM(p,o) NUM_FOR_EDICT(p, G_EDICT (p, o))
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2008-08-01 13:54:24 +00:00
|
|
|
/** Access a string global, converting it to a C string. Kills the program
|
2004-11-08 23:27:00 +00:00
|
|
|
if the string is invalid.
|
|
|
|
|
2006-12-04 13:08:52 +00:00
|
|
|
\par QC type:
|
|
|
|
\c string
|
2010-12-09 04:35:11 +00:00
|
|
|
\param p pointer to ::progs_t VM struct
|
|
|
|
\param o offset into global data space
|
|
|
|
\return const char * to the string
|
2006-12-05 11:40:00 +00:00
|
|
|
|
|
|
|
\hideinitializer
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2003-12-06 22:49:18 +00:00
|
|
|
#define G_GSTRING(p,o) PR_GetString (p, G_STRING (p, o))
|
2004-11-08 23:27:00 +00:00
|
|
|
|
|
|
|
/** Access a dstring global. Kills the program if the dstring is invalid.
|
|
|
|
|
2006-12-04 13:08:52 +00:00
|
|
|
\par QC type:
|
|
|
|
\c string
|
2010-12-09 04:35:11 +00:00
|
|
|
\param p pointer to ::progs_t VM struct
|
|
|
|
\param o offset into global data space
|
|
|
|
\return dstring_t * to the dstring
|
2006-12-05 11:40:00 +00:00
|
|
|
|
|
|
|
\hideinitializer
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
|
|
|
#define G_DSTRING(p,o) PR_GetMutableString (p, G_STRING (p, o))
|
|
|
|
|
|
|
|
/** Access a pointer parameter.
|
|
|
|
|
2006-12-04 13:08:52 +00:00
|
|
|
\par QC type:
|
2011-07-09 00:41:30 +00:00
|
|
|
\c void *
|
2010-12-09 04:35:11 +00:00
|
|
|
\param p pointer to ::progs_t VM struct
|
|
|
|
\param o offset into global data space
|
|
|
|
\return C pointer represented by the parameter. 0 offset -> NULL
|
2006-12-05 11:40:00 +00:00
|
|
|
|
|
|
|
\hideinitializer
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2003-12-06 22:49:18 +00:00
|
|
|
#define G_GPOINTER(p,o) PR_GetPointer (p, o)
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2008-08-01 00:47:38 +00:00
|
|
|
/** Access a structure global. Can be assigned to.
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2006-12-04 13:08:52 +00:00
|
|
|
\par QC type:
|
2011-07-09 00:41:30 +00:00
|
|
|
\c void *
|
2010-12-09 04:35:11 +00:00
|
|
|
\param p pointer to ::progs_t VM struct
|
|
|
|
\param t C type of the structure
|
|
|
|
\param o offset into global data space
|
|
|
|
\return structure lvalue. use & to make a pointer of the
|
|
|
|
appropriate type.
|
2006-12-05 11:40:00 +00:00
|
|
|
|
|
|
|
\hideinitializer
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2003-12-06 22:49:18 +00:00
|
|
|
#define G_STRUCT(p,t,o) (*(t *)G_GPOINTER (p, o))
|
2020-02-11 06:20:49 +00:00
|
|
|
///@}
|
2003-04-22 18:20:15 +00:00
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
/** \defgroup prda_parameters Parameters
|
2006-12-05 11:40:00 +00:00
|
|
|
\ingroup progs_data_access
|
2011-07-25 19:52:24 +00:00
|
|
|
Typed parameter access macros. No checking is done against the QC type, but
|
2006-12-05 11:40:00 +00:00
|
|
|
the appropriate C type will be used.
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2020-02-11 06:20:49 +00:00
|
|
|
///@{
|
2006-12-05 11:40:00 +00:00
|
|
|
|
2020-03-05 15:23:44 +00:00
|
|
|
/** Access a parameter as an arbitray type.
|
|
|
|
|
|
|
|
\par QC type:
|
|
|
|
\c struct etc small enough to fit in a single parameter
|
|
|
|
\param p pointer to ::progs_t VM struct
|
|
|
|
\param t C type of the structure
|
|
|
|
\param n parameter number (0-7)
|
|
|
|
\return structure lvalue. use & to make a pointer of the
|
|
|
|
appropriate type.
|
|
|
|
|
|
|
|
\hideinitializer
|
|
|
|
*/
|
|
|
|
#define P_PACKED(p,t,n) (*(t *) (p)->pr_params[n])
|
|
|
|
|
2022-04-26 06:10:00 +00:00
|
|
|
/** \internal
|
|
|
|
\param p pointer to ::progs_t VM struct
|
|
|
|
\param n parameter number (0-7)
|
|
|
|
\param t typename prefix (see pr_type_u)
|
|
|
|
\return lvalue of the appropriate type
|
|
|
|
|
|
|
|
\hideinitializer
|
|
|
|
*/
|
|
|
|
#define P_var(p,n,t) P_PACKED(p, pr_##t##_t, n)
|
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
/** Access a float parameter. Can be assigned to.
|
|
|
|
|
2006-12-04 13:08:52 +00:00
|
|
|
\par QC type:
|
|
|
|
\c float
|
2010-12-09 04:35:11 +00:00
|
|
|
\param p pointer to ::progs_t VM struct
|
|
|
|
\param n parameter number (0-7)
|
|
|
|
\return float lvalue
|
2006-12-05 11:40:00 +00:00
|
|
|
|
|
|
|
\hideinitializer
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2002-05-22 22:35:37 +00:00
|
|
|
#define P_FLOAT(p,n) P_var (p, n, float)
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2020-02-14 07:38:37 +00:00
|
|
|
/** Access a double parameter. Can be assigned to.
|
|
|
|
|
|
|
|
\par QC type:
|
|
|
|
\c double
|
|
|
|
\param p pointer to ::progs_t VM struct
|
|
|
|
\param n parameter number (0-7)
|
|
|
|
\return double lvalue
|
|
|
|
|
|
|
|
\hideinitializer
|
|
|
|
*/
|
2022-04-26 06:10:00 +00:00
|
|
|
#define P_DOUBLE(p,n) P_var (p, n, double)
|
2020-02-14 07:38:37 +00:00
|
|
|
|
2022-01-18 04:21:06 +00:00
|
|
|
/** Access an int parameter. Can be assigned to.
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2006-12-04 13:08:52 +00:00
|
|
|
\par QC type:
|
2022-01-18 04:21:06 +00:00
|
|
|
\c int
|
2010-12-09 04:35:11 +00:00
|
|
|
\param p pointer to ::progs_t VM struct
|
|
|
|
\param n parameter number (0-7)
|
|
|
|
\return int lvalue
|
2006-12-05 11:40:00 +00:00
|
|
|
|
|
|
|
\hideinitializer
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2022-01-18 04:21:06 +00:00
|
|
|
#define P_INT(p,n) P_var (p, n, int)
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2022-01-18 04:21:06 +00:00
|
|
|
/** Access an unsigned int parameter. Can be assigned to.
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2006-12-04 13:08:52 +00:00
|
|
|
\par QC type:
|
2022-01-18 04:21:06 +00:00
|
|
|
\c uint
|
2010-12-09 04:35:11 +00:00
|
|
|
\param p pointer to ::progs_t VM struct
|
|
|
|
\param n parameter number (0-7)
|
|
|
|
\return unsigned int lvalue
|
2006-12-05 11:40:00 +00:00
|
|
|
|
|
|
|
\hideinitializer
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2022-01-18 04:21:06 +00:00
|
|
|
#define P_UINT(p,n) P_var (p, n, uint)
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2022-04-26 08:19:47 +00:00
|
|
|
/** Access a long parameter. Can be assigned to.
|
|
|
|
|
|
|
|
\par QC type:
|
|
|
|
\c long
|
|
|
|
\param p pointer to ::progs_t VM struct
|
|
|
|
\param n parameter number (0-7)
|
|
|
|
\return long lvalue
|
|
|
|
|
|
|
|
\hideinitializer
|
|
|
|
*/
|
|
|
|
#define P_LONG(p,n) P_var (p, n, long)
|
|
|
|
|
|
|
|
/** Access an unsigned long parameter. Can be assigned to.
|
|
|
|
|
|
|
|
\par QC type:
|
|
|
|
\c ulong
|
|
|
|
\param p pointer to ::progs_t VM struct
|
|
|
|
\param n parameter number (0-7)
|
|
|
|
\return unsigned long lvalue
|
|
|
|
|
|
|
|
\hideinitializer
|
|
|
|
*/
|
|
|
|
#define P_ULONG(p,n) P_var (p, n, ulong)
|
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
/** Access a vector parameter. Can be used any way a vec3_t variable can.
|
|
|
|
|
2006-12-04 13:08:52 +00:00
|
|
|
\par QC type:
|
|
|
|
\c vector
|
2010-12-09 04:35:11 +00:00
|
|
|
\param p pointer to ::progs_t VM struct
|
|
|
|
\param n parameter number (0-7)
|
|
|
|
\return vec3_t lvalue
|
2006-12-05 11:40:00 +00:00
|
|
|
|
|
|
|
\hideinitializer
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2022-04-26 06:10:00 +00:00
|
|
|
#define P_VECTOR(p,n) (&P_var (p, n, float))
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2011-02-12 13:57:37 +00:00
|
|
|
/** Access a quaterion parameter. Can be used any way a quat_t variable can.
|
|
|
|
|
|
|
|
\par QC type:
|
|
|
|
\c quaterion
|
|
|
|
\param p pointer to ::progs_t VM struct
|
|
|
|
\param n parameter number (0-7)
|
|
|
|
\return quat_t lvalue
|
|
|
|
|
|
|
|
\hideinitializer
|
|
|
|
*/
|
2022-04-26 06:10:00 +00:00
|
|
|
#define P_QUAT(p,n) (&P_var (p, n, float))
|
2011-02-12 13:57:37 +00:00
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
/** Access a string index parameter. Can be assigned to.
|
|
|
|
|
2006-12-04 13:08:52 +00:00
|
|
|
\par QC type:
|
|
|
|
\c string
|
2010-12-09 04:35:11 +00:00
|
|
|
\param p pointer to ::progs_t VM struct
|
|
|
|
\param n parameter number (0-7)
|
2022-01-18 03:11:14 +00:00
|
|
|
\return pr_string_t lvalue
|
2006-12-05 11:40:00 +00:00
|
|
|
|
|
|
|
\hideinitializer
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2003-04-22 18:20:15 +00:00
|
|
|
#define P_STRING(p,n) P_var (p, n, string)
|
2004-11-08 23:27:00 +00:00
|
|
|
|
|
|
|
/** Access a function parameter. Can be assigned to.
|
|
|
|
|
2006-12-04 13:08:52 +00:00
|
|
|
\par QC type:
|
|
|
|
\c void()
|
2010-12-09 04:35:11 +00:00
|
|
|
\param p pointer to ::progs_t VM struct
|
|
|
|
\param n parameter number (0-7)
|
2022-01-18 06:32:43 +00:00
|
|
|
\return pr_func_t lvalue
|
2006-12-05 11:40:00 +00:00
|
|
|
|
|
|
|
\hideinitializer
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2002-05-22 22:35:37 +00:00
|
|
|
#define P_FUNCTION(p,n) P_var (p, n, func)
|
2004-11-08 23:27:00 +00:00
|
|
|
|
|
|
|
/** Access a pointer parameter. Can be assigned to.
|
|
|
|
|
2006-12-04 13:08:52 +00:00
|
|
|
\par QC type:
|
2011-07-09 00:41:30 +00:00
|
|
|
\c void *
|
2010-12-09 04:35:11 +00:00
|
|
|
\param p pointer to ::progs_t VM struct
|
|
|
|
\param n parameter number (0-7)
|
2022-01-18 03:11:14 +00:00
|
|
|
\return pr_ptr_t lvalue
|
2006-12-05 11:40:00 +00:00
|
|
|
|
|
|
|
\hideinitializer
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2022-04-26 06:10:00 +00:00
|
|
|
#define P_POINTER(p,n) P_var (p, n, ptr)
|
2003-04-22 18:20:15 +00:00
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
/** Access an entity parameter.
|
|
|
|
|
2006-12-04 13:08:52 +00:00
|
|
|
\par QC type:
|
|
|
|
\c entity
|
2010-12-09 04:35:11 +00:00
|
|
|
\param p pointer to ::progs_t VM struct
|
|
|
|
\param n parameter number (0-7)
|
|
|
|
\return C pointer to the entity
|
2006-12-05 11:40:00 +00:00
|
|
|
|
|
|
|
\hideinitializer
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2013-01-17 05:11:54 +00:00
|
|
|
#define P_EDICT(p,n) PROG_TO_EDICT ((p), P_INT (p, n))
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2010-11-29 03:54:26 +00:00
|
|
|
/** Access an entity parameter.
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2006-12-04 13:08:52 +00:00
|
|
|
\par QC type:
|
|
|
|
\c entity
|
2010-12-09 04:35:11 +00:00
|
|
|
\param p pointer to ::progs_t VM struct
|
|
|
|
\param n parameter number (0-7)
|
|
|
|
\return the entity number
|
2006-12-05 11:40:00 +00:00
|
|
|
|
|
|
|
\hideinitializer
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2003-04-22 18:20:15 +00:00
|
|
|
#define P_EDICTNUM(p,n) NUM_FOR_EDICT (p, P_EDICT (p, n))
|
2004-11-08 23:27:00 +00:00
|
|
|
|
|
|
|
/** Access a string parameter, converting it to a C string. Kills the program
|
|
|
|
if the string is invalid.
|
|
|
|
|
2006-12-04 13:08:52 +00:00
|
|
|
\par QC type:
|
|
|
|
\c string
|
2010-12-09 04:35:11 +00:00
|
|
|
\param p pointer to ::progs_t VM struct
|
|
|
|
\param n parameter number (0-7)
|
|
|
|
\return const char * to the string
|
2006-12-05 11:40:00 +00:00
|
|
|
|
|
|
|
\hideinitializer
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2003-04-22 18:20:15 +00:00
|
|
|
#define P_GSTRING(p,n) PR_GetString (p, P_STRING (p, n))
|
2004-11-08 23:27:00 +00:00
|
|
|
|
|
|
|
/** Access a dstring parameter. Kills the program if the dstring is invalid.
|
|
|
|
|
2006-12-04 13:08:52 +00:00
|
|
|
\par QC type:
|
|
|
|
\c string
|
2010-12-09 04:35:11 +00:00
|
|
|
\param p pointer to ::progs_t VM struct
|
|
|
|
\param n parameter number (0-7)
|
|
|
|
\return dstring_t * to the dstring
|
2006-12-05 11:40:00 +00:00
|
|
|
|
|
|
|
\hideinitializer
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
|
|
|
#define P_DSTRING(p,n) PR_GetMutableString (p, P_STRING (p, n))
|
|
|
|
|
|
|
|
/** Access a pointer parameter.
|
|
|
|
|
2006-12-04 13:08:52 +00:00
|
|
|
\par QC type:
|
2011-07-09 00:41:30 +00:00
|
|
|
\c void *
|
2010-12-09 04:35:11 +00:00
|
|
|
\param p pointer to ::progs_t VM struct
|
|
|
|
\param n parameter number (0-7)
|
|
|
|
\return C pointer represented by the parameter. 0 offset -> NULL
|
2006-12-05 11:40:00 +00:00
|
|
|
|
|
|
|
\hideinitializer
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2003-04-22 18:20:15 +00:00
|
|
|
#define P_GPOINTER(p,n) PR_GetPointer (p, P_POINTER (p, n))
|
2004-11-08 23:27:00 +00:00
|
|
|
|
|
|
|
/** Access a structure pointer parameter.
|
|
|
|
|
2006-12-04 13:08:52 +00:00
|
|
|
\par QC type:
|
2011-07-09 00:41:30 +00:00
|
|
|
\c void *
|
2010-12-09 04:35:11 +00:00
|
|
|
\param p pointer to ::progs_t VM struct
|
|
|
|
\param t C type of the structure
|
|
|
|
\param n parameter number (0-7)
|
|
|
|
\return structure lvalue. use & to make a pointer of the
|
|
|
|
appropriate type.
|
2006-12-05 11:40:00 +00:00
|
|
|
|
|
|
|
\hideinitializer
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2003-04-22 18:20:15 +00:00
|
|
|
#define P_STRUCT(p,t,n) (*(t *)P_GPOINTER (p, n))
|
2020-02-11 06:20:49 +00:00
|
|
|
///@}
|
2002-05-22 22:35:37 +00:00
|
|
|
|
2011-07-15 17:12:26 +00:00
|
|
|
/** \defgroup prda_return Return Values
|
2006-12-05 11:40:00 +00:00
|
|
|
\ingroup progs_data_access
|
2022-05-15 03:00:14 +00:00
|
|
|
Typed return value access. These macros are used to access the value
|
|
|
|
returned by an interpreted VM function, and to return values from engine
|
|
|
|
functions into progs space (that is, builtins).
|
2011-07-15 17:12:26 +00:00
|
|
|
\warning No checking is performed against progs types; for example, if you
|
|
|
|
ask for an \c int from a function that returned a \c float, you're asking
|
|
|
|
for trouble.
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2020-02-11 06:20:49 +00:00
|
|
|
///@{
|
2006-12-05 11:40:00 +00:00
|
|
|
|
2022-04-26 06:10:00 +00:00
|
|
|
/** Access the VM function return value as an arbitray type.
|
2020-03-05 15:23:44 +00:00
|
|
|
|
|
|
|
\par QC type:
|
|
|
|
\c struct etc small enough to fit in the return slot
|
|
|
|
\param p pointer to ::progs_t VM struct
|
|
|
|
\param t C type of the structure
|
|
|
|
\return structure lvalue. use & to make a pointer of the
|
|
|
|
appropriate type.
|
|
|
|
|
|
|
|
\hideinitializer
|
|
|
|
*/
|
|
|
|
#define R_PACKED(p,t) (*(t *) (p)->pr_return)
|
|
|
|
|
2022-04-26 06:10:00 +00:00
|
|
|
/** \internal
|
|
|
|
\param p pointer to ::progs_t VM struct
|
|
|
|
\param t typename prefix (see pr_type_u)
|
|
|
|
\return lvalue of the appropriate type
|
|
|
|
|
|
|
|
\hideinitializer
|
|
|
|
*/
|
|
|
|
#define R_var(p,t) R_PACKED(p, pr_##t##_t)
|
|
|
|
|
2011-07-15 17:12:26 +00:00
|
|
|
/** Access the VM function return value as a \c float
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2006-12-04 13:08:52 +00:00
|
|
|
\par QC type:
|
|
|
|
\c float
|
2010-12-09 04:35:11 +00:00
|
|
|
\param p pointer to ::progs_t VM struct
|
|
|
|
\return float lvalue
|
2006-12-05 11:40:00 +00:00
|
|
|
|
|
|
|
\hideinitializer
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2002-05-22 22:35:37 +00:00
|
|
|
#define R_FLOAT(p) R_var (p, float)
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2020-02-14 07:38:37 +00:00
|
|
|
/** Access the VM function return value as a \c double
|
|
|
|
|
|
|
|
\par QC type:
|
|
|
|
\c double
|
|
|
|
\param p pointer to ::progs_t VM struct
|
|
|
|
\return double lvalue
|
|
|
|
|
|
|
|
\hideinitializer
|
|
|
|
*/
|
2022-04-26 06:10:00 +00:00
|
|
|
#define R_DOUBLE(p) R_var (p, double)
|
2020-02-14 07:38:37 +00:00
|
|
|
|
2011-07-15 17:12:26 +00:00
|
|
|
/** Access the VM function return value as a \c ::pr_int_t (AKA int32_t)
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2006-12-04 13:08:52 +00:00
|
|
|
\par QC type:
|
2022-01-18 04:21:06 +00:00
|
|
|
\c int
|
2010-12-09 04:35:11 +00:00
|
|
|
\param p pointer to ::progs_t VM struct
|
2011-07-15 17:12:26 +00:00
|
|
|
\return ::pr_int_t lvalue
|
2006-12-05 11:40:00 +00:00
|
|
|
|
|
|
|
\hideinitializer
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2022-01-18 04:21:06 +00:00
|
|
|
#define R_INT(p) R_var (p, int)
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2011-07-15 17:12:26 +00:00
|
|
|
/** Access the VM function return value as a \c ::pr_uint_t (AKA uint32_t)
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2006-12-04 13:08:52 +00:00
|
|
|
\par QC type:
|
2022-01-18 04:21:06 +00:00
|
|
|
\c uint
|
2010-12-09 04:35:11 +00:00
|
|
|
\param p pointer to ::progs_t VM struct
|
2011-07-15 17:12:26 +00:00
|
|
|
\return ::pr_int_t lvalue
|
2006-12-05 11:40:00 +00:00
|
|
|
|
|
|
|
\hideinitializer
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2022-01-18 04:21:06 +00:00
|
|
|
#define R_UINT(p) R_var (p, uint)
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2022-04-26 08:19:47 +00:00
|
|
|
/** Access the VM function return value as a \c ::pr_long_t (AKA int32_t)
|
|
|
|
|
|
|
|
\par QC type:
|
|
|
|
\c long
|
|
|
|
\param p pointer to ::progs_t VM struct
|
|
|
|
\return ::pr_long_t lvalue
|
|
|
|
|
|
|
|
\hideinitializer
|
|
|
|
*/
|
|
|
|
#define R_LONG(p) R_var (p, long)
|
|
|
|
|
|
|
|
/** Access the VM function return value as a \c ::pr_ulong_t (AKA uint32_t)
|
|
|
|
|
|
|
|
\par QC type:
|
|
|
|
\c ulong
|
|
|
|
\param p pointer to ::progs_t VM struct
|
|
|
|
\return ::pr_long_t lvalue
|
|
|
|
|
|
|
|
\hideinitializer
|
|
|
|
*/
|
|
|
|
#define R_ULONG(p) R_var (p, ulong)
|
|
|
|
|
2011-07-15 17:12:26 +00:00
|
|
|
/** Access the VM function return value as a \c ::vec3_t vector.
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2006-12-04 13:08:52 +00:00
|
|
|
\par QC type:
|
|
|
|
\c vector
|
2010-12-09 04:35:11 +00:00
|
|
|
\param p pointer to ::progs_t VM struct
|
2011-07-15 17:12:26 +00:00
|
|
|
\return ::vec3_t lvalue
|
2006-12-05 11:40:00 +00:00
|
|
|
|
|
|
|
\hideinitializer
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2022-04-26 06:10:00 +00:00
|
|
|
#define R_VECTOR(p) (&R_var (p, float))
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2011-07-15 17:12:26 +00:00
|
|
|
/** Access the VM function return value as a \c ::quat_t quaternion.
|
2011-02-12 13:57:37 +00:00
|
|
|
|
|
|
|
\par QC type:
|
|
|
|
\c quaternion
|
|
|
|
\param p pointer to ::progs_t VM struct
|
2011-07-15 17:12:26 +00:00
|
|
|
\return ::quat_t lvalue
|
2011-02-12 13:57:37 +00:00
|
|
|
|
|
|
|
\hideinitializer
|
|
|
|
*/
|
2022-04-26 06:10:00 +00:00
|
|
|
#define R_QUAT(p) (&R_var (p, float))
|
2011-02-12 13:57:37 +00:00
|
|
|
|
2022-01-18 03:11:14 +00:00
|
|
|
/** Access the VM function return value as a ::pr_string_t (a VM string reference).
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2006-12-04 13:08:52 +00:00
|
|
|
\par QC type:
|
|
|
|
\c string
|
2010-12-09 04:35:11 +00:00
|
|
|
\param p pointer to ::progs_t VM struct
|
2022-01-18 03:11:14 +00:00
|
|
|
\return ::pr_string_t lvalue
|
2006-12-05 11:40:00 +00:00
|
|
|
|
|
|
|
\hideinitializer
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2003-04-22 18:20:15 +00:00
|
|
|
#define R_STRING(p) R_var (p, string)
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2022-01-18 06:32:43 +00:00
|
|
|
/** Access the VM function return value as a ::pr_func_t (a VM function reference)
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2006-12-04 13:08:52 +00:00
|
|
|
\par QC type:
|
|
|
|
\c void()
|
2010-12-09 04:35:11 +00:00
|
|
|
\param p pointer to ::progs_t VM struct
|
2022-01-18 06:32:43 +00:00
|
|
|
\return ::pr_func_t lvalue
|
2006-12-05 11:40:00 +00:00
|
|
|
|
|
|
|
\hideinitializer
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2002-05-22 22:35:37 +00:00
|
|
|
#define R_FUNCTION(p) R_var (p, func)
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2022-01-18 03:11:14 +00:00
|
|
|
/** Access the VM function return value as a ::pr_ptr_t (a VM "pointer")
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2006-12-04 13:08:52 +00:00
|
|
|
\par QC type:
|
2011-07-09 00:41:30 +00:00
|
|
|
\c void *
|
2010-12-09 04:35:11 +00:00
|
|
|
\param p pointer to ::progs_t VM struct
|
2022-01-18 03:11:14 +00:00
|
|
|
\return ::pr_ptr_t lvalue
|
2006-12-05 11:40:00 +00:00
|
|
|
|
|
|
|
\hideinitializer
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2022-04-26 06:10:00 +00:00
|
|
|
#define R_POINTER(p) R_var (p, ptr)
|
2002-05-22 22:35:37 +00:00
|
|
|
|
2002-01-23 22:35:48 +00:00
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
/** Set the return value to the given C string. The returned string will
|
|
|
|
eventually be garbage collected (see PR_SetReturnString()).
|
|
|
|
|
2006-12-04 13:08:52 +00:00
|
|
|
\par QC type:
|
|
|
|
\c string
|
2010-12-09 04:35:11 +00:00
|
|
|
\param p pointer to ::progs_t VM struct
|
|
|
|
\param s C string to be returned
|
2006-12-05 11:40:00 +00:00
|
|
|
|
|
|
|
\hideinitializer
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
|
|
|
#define RETURN_STRING(p,s) (R_STRING (p) = PR_SetReturnString((p), s))
|
|
|
|
|
|
|
|
/** Set the return value to the given C entity pointer. The pointer is
|
|
|
|
converted into a progs entity address.
|
|
|
|
|
2006-12-04 13:08:52 +00:00
|
|
|
\par QC type:
|
|
|
|
\c entity
|
2010-12-09 04:35:11 +00:00
|
|
|
\param p pointer to ::progs_t VM struct
|
|
|
|
\param e C entity pointer to be returned
|
2006-12-05 11:40:00 +00:00
|
|
|
|
|
|
|
\hideinitializer
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2013-01-17 05:11:54 +00:00
|
|
|
#define RETURN_EDICT(p,e) (R_INT (p) = EDICT_TO_PROG(p, e))
|
2004-11-08 23:27:00 +00:00
|
|
|
|
|
|
|
/** Set the return value to the given C pointer. NULL is converted to 0.
|
|
|
|
|
2006-12-04 13:08:52 +00:00
|
|
|
\par QC type:
|
2011-07-09 00:41:30 +00:00
|
|
|
\c void *
|
2010-12-09 04:35:11 +00:00
|
|
|
\param p pointer to ::progs_t VM struct
|
|
|
|
\param ptr C entity pointer to be returned
|
2006-12-05 11:40:00 +00:00
|
|
|
|
|
|
|
\hideinitializer
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
|
|
|
#define RETURN_POINTER(p,ptr) (R_POINTER (p) = PR_SetPointer (p, ptr))
|
|
|
|
|
2011-02-12 13:57:37 +00:00
|
|
|
/** Set the return value to the given vector.
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2006-12-04 13:08:52 +00:00
|
|
|
\par QC type:
|
|
|
|
\c vector
|
2010-12-09 04:35:11 +00:00
|
|
|
\param p pointer to ::progs_t VM struct
|
2011-02-12 13:57:37 +00:00
|
|
|
\param v vector to be returned
|
2006-12-05 11:40:00 +00:00
|
|
|
|
|
|
|
\hideinitializer
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
|
|
|
#define RETURN_VECTOR(p,v) VectorCopy (v, R_VECTOR (p))
|
2011-02-12 13:57:37 +00:00
|
|
|
|
|
|
|
/** Set the return value to the given quaterion.
|
|
|
|
|
|
|
|
\par QC type:
|
|
|
|
\c vector
|
|
|
|
\param p pointer to ::progs_t VM struct
|
|
|
|
\param q quaternion to be returned
|
|
|
|
|
|
|
|
\hideinitializer
|
|
|
|
*/
|
2022-01-22 01:57:26 +00:00
|
|
|
#define RETURN_QUAT(p,q) QuatCopy (q, R_QUAT (p))
|
2020-02-11 06:20:49 +00:00
|
|
|
///@}
|
2004-11-08 23:27:00 +00:00
|
|
|
|
|
|
|
/** \defgroup prda_entity_fields Entity Fields
|
2006-12-05 11:40:00 +00:00
|
|
|
\ingroup progs_data_access
|
2011-07-25 19:52:24 +00:00
|
|
|
Typed entity field access macros. No checking is done against the QC type,
|
2006-12-05 11:40:00 +00:00
|
|
|
but the appropriate C type will be used.
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2020-02-11 06:20:49 +00:00
|
|
|
///@{
|
2006-12-05 11:40:00 +00:00
|
|
|
|
|
|
|
/** \internal
|
2010-12-09 04:35:11 +00:00
|
|
|
\param e pointer to the entity
|
|
|
|
\param o field offset into entity data space
|
|
|
|
\return lvalue of the appropriate type
|
2006-12-05 11:40:00 +00:00
|
|
|
|
|
|
|
\hideinitializer
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2013-01-17 05:11:54 +00:00
|
|
|
#define E_fld(e,o) ((e)->pr->pr_edict_area[(e)->edict + (o)])
|
|
|
|
|
2022-04-26 06:10:00 +00:00
|
|
|
/** Access an entity field as an arbitray type.
|
|
|
|
|
|
|
|
\par QC type:
|
|
|
|
\c struct etc small enough to fit in a single parameter
|
|
|
|
\param e pointer to the entity
|
|
|
|
\param t C type of the structure
|
|
|
|
\param o field offset into entity data space
|
|
|
|
\return structure lvalue. use & to make a pointer of the
|
|
|
|
appropriate type.
|
|
|
|
|
|
|
|
\hideinitializer
|
|
|
|
*/
|
|
|
|
#define E_PACKED(e,t,o) (*(t *) &E_fld (e, o))
|
2013-01-17 05:11:54 +00:00
|
|
|
|
|
|
|
/** \internal
|
|
|
|
\param e pointer to the entity
|
|
|
|
\param o field offset into entity data space
|
|
|
|
\param t typename prefix (see pr_type_u)
|
|
|
|
\return lvalue of the appropriate type
|
|
|
|
|
|
|
|
\hideinitializer
|
|
|
|
*/
|
2022-04-26 06:10:00 +00:00
|
|
|
#define E_var(e,o,t) E_PACKED (e, pr_##t##_t,o)
|
2001-02-26 20:52:14 +00:00
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
|
|
|
|
/** Access a float entity field. Can be assigned to.
|
|
|
|
|
2006-12-04 13:08:52 +00:00
|
|
|
\par QC type:
|
|
|
|
\c float
|
2010-12-09 04:35:11 +00:00
|
|
|
\param e pointer to the entity
|
|
|
|
\param o field offset into entity data space
|
|
|
|
\return float lvalue
|
2006-12-05 11:40:00 +00:00
|
|
|
|
|
|
|
\hideinitializer
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2003-12-06 22:49:18 +00:00
|
|
|
#define E_FLOAT(e,o) E_var (e, o, float)
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2020-02-14 07:38:37 +00:00
|
|
|
/** Access a double entity field. Can be assigned to.
|
|
|
|
|
|
|
|
\par QC type:
|
|
|
|
\c double
|
|
|
|
\param e pointer to the entity
|
|
|
|
\param o field offset into entity data space
|
|
|
|
\return double lvalue
|
|
|
|
|
|
|
|
\hideinitializer
|
|
|
|
*/
|
2022-04-26 06:10:00 +00:00
|
|
|
#define E_DOUBLE(e,o) E_var (e, o, double)
|
2020-02-14 07:38:37 +00:00
|
|
|
|
2022-01-18 04:21:06 +00:00
|
|
|
/** Access an int entity field. Can be assigned to.
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2006-12-04 13:08:52 +00:00
|
|
|
\par QC type:
|
2022-01-18 04:21:06 +00:00
|
|
|
\c int
|
2010-12-09 04:35:11 +00:00
|
|
|
\param e pointer to the entity
|
|
|
|
\param o field offset into entity data space
|
|
|
|
\return int lvalue
|
2006-12-05 11:40:00 +00:00
|
|
|
|
|
|
|
\hideinitializer
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2022-01-18 04:21:06 +00:00
|
|
|
#define E_INT(e,o) E_var (e, o, int)
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2022-01-18 04:21:06 +00:00
|
|
|
/** Access an unsigned int entity field. Can be assigned to.
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2006-12-04 13:08:52 +00:00
|
|
|
\par QC type:
|
2022-01-18 04:21:06 +00:00
|
|
|
\c uint
|
2010-12-09 04:35:11 +00:00
|
|
|
\param e pointer to the entity
|
|
|
|
\param o field offset into entity data space
|
|
|
|
\return unsigned int lvalue
|
2006-12-05 11:40:00 +00:00
|
|
|
|
|
|
|
\hideinitializer
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2022-01-18 04:21:06 +00:00
|
|
|
#define E_UINT(e,o) E_var (e, o, uint)
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2022-04-26 08:19:47 +00:00
|
|
|
/** Access a long entity field. Can be assigned to.
|
|
|
|
|
|
|
|
\par QC type:
|
|
|
|
\c long
|
|
|
|
\param e pointer to the entity
|
|
|
|
\param o field offset into entity data space
|
|
|
|
\return long lvalue
|
|
|
|
|
|
|
|
\hideinitializer
|
|
|
|
*/
|
|
|
|
#define E_LONG(e,o) E_var (e, o, long)
|
|
|
|
|
|
|
|
/** Access an unsigned long entity field. Can be assigned to.
|
|
|
|
|
|
|
|
\par QC type:
|
|
|
|
\c ulong
|
|
|
|
\param e pointer to the entity
|
|
|
|
\param o field offset into entity data space
|
|
|
|
\return unsigned long lvalue
|
|
|
|
|
|
|
|
\hideinitializer
|
|
|
|
*/
|
|
|
|
#define E_ULONG(e,o) E_var (e, o, ulong)
|
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
/** Access a vector entity field. Can be used any way a vec3_t variable can.
|
|
|
|
|
2006-12-04 13:08:52 +00:00
|
|
|
\par QC type:
|
|
|
|
\c vector
|
2010-12-09 04:35:11 +00:00
|
|
|
\param e pointer to the entity
|
|
|
|
\param o field offset into entity data space
|
|
|
|
\return vec3_t lvalue
|
2006-12-05 11:40:00 +00:00
|
|
|
|
|
|
|
\hideinitializer
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2022-04-26 06:10:00 +00:00
|
|
|
#define E_VECTOR(e,o) (&E_var (e, o, float))
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2011-02-12 13:57:37 +00:00
|
|
|
/** Access a quaternion entity field. Can be used any way a quat_t variable
|
|
|
|
can.
|
|
|
|
|
|
|
|
\par QC type:
|
|
|
|
\c quaterion
|
|
|
|
\param e pointer to the entity
|
|
|
|
\param o field offset into entity data space
|
|
|
|
\return quat_t lvalue
|
|
|
|
|
|
|
|
\hideinitializer
|
|
|
|
*/
|
2022-04-26 06:10:00 +00:00
|
|
|
#define E_QUAT(e,o) E_var (e, o, float)
|
2011-02-12 13:57:37 +00:00
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
/** Access a string index entity field. Can be assigned to.
|
|
|
|
|
2006-12-04 13:08:52 +00:00
|
|
|
\par QC type:
|
|
|
|
\c string
|
2010-12-09 04:35:11 +00:00
|
|
|
\param e pointer to the entity
|
|
|
|
\param o field offset into entity data space
|
2022-01-18 03:11:14 +00:00
|
|
|
\return pr_string_t lvalue
|
2006-12-05 11:40:00 +00:00
|
|
|
|
|
|
|
\hideinitializer
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2003-04-22 18:20:15 +00:00
|
|
|
#define E_STRING(e,o) E_var (e, o, string)
|
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
/** Access a function entity field. Can be assigned to.
|
|
|
|
|
2006-12-04 13:08:52 +00:00
|
|
|
\par QC type:
|
|
|
|
\c void()
|
2010-12-09 04:35:11 +00:00
|
|
|
\param e pointer to the entity
|
|
|
|
\param o field offset into entity data space
|
2022-01-18 06:32:43 +00:00
|
|
|
\return pr_func_t lvalue
|
2006-12-05 11:40:00 +00:00
|
|
|
|
|
|
|
\hideinitializer
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
|
|
|
#define E_FUNCTION(e,o) E_var (e, o, func)
|
|
|
|
|
|
|
|
/** Access a pointer entity field. Can be assigned to.
|
|
|
|
|
2006-12-04 13:08:52 +00:00
|
|
|
\par QC type:
|
2011-07-09 00:41:30 +00:00
|
|
|
\c void *
|
2010-12-09 04:35:11 +00:00
|
|
|
\param e pointer to the entity
|
|
|
|
\param o field offset into entity data space
|
2022-01-18 03:11:14 +00:00
|
|
|
\return pr_ptr_t lvalue
|
2006-12-05 11:40:00 +00:00
|
|
|
|
|
|
|
\hideinitializer
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2022-04-26 06:10:00 +00:00
|
|
|
#define E_POINTER(e,o) E_var (e, o, ptr)
|
2004-11-08 23:27:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
/** Access a string entity field, converting it to a C string. Kills the
|
|
|
|
program if the string is invalid.
|
|
|
|
|
2006-12-04 13:08:52 +00:00
|
|
|
\par QC type:
|
|
|
|
\c string
|
2010-12-09 04:35:11 +00:00
|
|
|
\param p pointer to ::progs_t VM struct
|
|
|
|
\param e pointer to the entity
|
|
|
|
\param o field offset into entity data space
|
|
|
|
\return const char * to the string
|
2006-12-05 11:40:00 +00:00
|
|
|
|
|
|
|
\hideinitializer
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2003-12-06 22:49:18 +00:00
|
|
|
#define E_GSTRING(p,e,o) (PR_GetString (p, E_STRING (e, o)))
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
/** Access a dstring entity field. Kills the program if the dstring is invalid.
|
|
|
|
|
2006-12-04 13:08:52 +00:00
|
|
|
\par QC type:
|
|
|
|
\c string
|
2010-12-09 04:35:11 +00:00
|
|
|
\param p pointer to ::progs_t VM struct
|
|
|
|
\param e pointer to the entity
|
|
|
|
\param o field offset into entity data space
|
|
|
|
\return dstring_t * to the dstring
|
2006-12-05 11:40:00 +00:00
|
|
|
|
|
|
|
\hideinitializer
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
|
|
|
#define E_DSTRING(p,e,o) (PR_GetMutableString (p, E_STRING (e, o)))
|
2020-02-11 06:20:49 +00:00
|
|
|
///@}
|
2004-11-08 23:27:00 +00:00
|
|
|
|
|
|
|
/** \defgroup pr_builtins VM Builtin functions
|
2006-12-05 11:40:00 +00:00
|
|
|
\ingroup progs
|
2004-11-08 23:27:00 +00:00
|
|
|
Builtin management functions.
|
|
|
|
|
2004-01-06 07:00:39 +00:00
|
|
|
Builtins are arranged into groups of 65536 to allow for diffent expantion
|
|
|
|
sets. eg, stock id is 0x0000xxxx, quakeforge is 0x000fxxxx. predefined
|
|
|
|
groups go up to 0x0fffxxxx allowing 4096 different groups. Builtins
|
|
|
|
0x10000000 to 0x7fffffff are reserved for auto-allocation. The range
|
|
|
|
0x8000000 to 0xffffffff is unavailable due to the builtin number being
|
|
|
|
a negative statement address.
|
|
|
|
*/
|
2020-02-11 06:20:49 +00:00
|
|
|
///@{
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2004-01-06 07:00:39 +00:00
|
|
|
#define PR_RANGE_SHIFT 16
|
|
|
|
#define PR_RANGE_MASK 0xffff0000
|
|
|
|
|
|
|
|
#define PR_RANGE_QF 0x000f
|
|
|
|
|
|
|
|
#define PR_RANGE_AUTO 0x1000
|
2004-11-08 23:27:00 +00:00
|
|
|
#define PR_RANGE_MAX 0x7fff
|
2004-01-06 07:00:39 +00:00
|
|
|
#define PR_RANGE_NONE 0xffff
|
|
|
|
#define PR_AUTOBUILTIN (PR_RANGE_AUTO << PR_RANGE_SHIFT)
|
|
|
|
|
2022-02-14 03:28:38 +00:00
|
|
|
typedef void (*builtin_proc) (progs_t *pr, void *data);
|
2004-11-08 23:27:00 +00:00
|
|
|
|
|
|
|
/** Create a static array of these and pass the array to PR_RegisterBuiltins()
|
|
|
|
to register the module's QC builtin functions.
|
|
|
|
*/
|
2001-08-03 06:40:28 +00:00
|
|
|
typedef struct {
|
2010-01-13 06:30:36 +00:00
|
|
|
/// QC name of the builtin. Must be an exact match for automatically
|
|
|
|
/// resolved builtins (func = \#0 in QC). NULL indicates end of array for
|
2004-11-08 23:27:00 +00:00
|
|
|
/// PR_RegisterBuiltins()
|
2001-08-03 06:40:28 +00:00
|
|
|
const char *name;
|
2004-11-08 23:27:00 +00:00
|
|
|
/// Pointer to the C implementation of the builtin function.
|
2001-08-03 06:40:28 +00:00
|
|
|
builtin_proc proc;
|
2005-07-27 12:14:35 +00:00
|
|
|
/// The number of the builtin for \#N in QC. -1 for automatic allocation.
|
2004-11-08 23:27:00 +00:00
|
|
|
/// 0 or >= ::PR_AUTOBUILTIN is invalid.
|
2007-04-04 12:30:49 +00:00
|
|
|
pr_int_t binum;
|
2022-01-23 12:54:03 +00:00
|
|
|
/// The number of parameters the builtin takes. Negative numbers mean
|
|
|
|
/// varargs with ~num_params (-num_params - 1) being the number of real
|
|
|
|
/// parameters.
|
|
|
|
pr_int_t num_params;
|
|
|
|
/// Parameter size specificiation.
|
|
|
|
///
|
|
|
|
/// Up to 8 parameters are supported for automatic parameter setup because
|
|
|
|
/// that's all that v6p progs can pass. Builtins taking more than 8
|
|
|
|
/// parameters are already Ruamoko-only and thus know how to deal with the
|
|
|
|
/// parameters being on the data stack.
|
|
|
|
///
|
|
|
|
/// The encoding is the same as for progs functions, with 3:5 for
|
|
|
|
/// alignment:size (size 0 means 32 words).
|
|
|
|
dparmsize_t params[PR_MAX_PARAMS];
|
2022-01-23 15:20:05 +00:00
|
|
|
|
|
|
|
/// Data passed to builtin functions. Set by PR_RegisterBuiltins
|
|
|
|
void *data;
|
2001-08-03 06:40:28 +00:00
|
|
|
} builtin_t;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2022-01-23 12:54:03 +00:00
|
|
|
#define PR_PARAM(type) { \
|
|
|
|
.size = PR_SIZEOF(type) & 0x1f, \
|
|
|
|
.alignment = BITOP_LOG2(PR_ALIGNOF(type)), \
|
|
|
|
}
|
|
|
|
|
2007-04-07 01:41:23 +00:00
|
|
|
/** Duplicate the dfunction_t descriptor with the addition of a pointer to the
|
2010-12-09 04:35:11 +00:00
|
|
|
builtin function. Avoids a level of indirection when calling a builtin
|
2007-04-07 01:41:23 +00:00
|
|
|
function.
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2004-01-05 08:08:46 +00:00
|
|
|
typedef struct {
|
2007-04-04 12:30:49 +00:00
|
|
|
pr_int_t first_statement;
|
2022-01-27 01:55:06 +00:00
|
|
|
pr_int_t numparams;
|
2022-02-04 12:46:40 +00:00
|
|
|
pr_ulong_t profile;
|
2022-01-23 15:13:44 +00:00
|
|
|
union {
|
|
|
|
struct {
|
2022-01-27 01:55:06 +00:00
|
|
|
dparmsize_t param_size[PR_MAX_PARAMS];
|
2022-01-23 15:13:44 +00:00
|
|
|
dfunction_t *descriptor;
|
2022-01-27 01:55:06 +00:00
|
|
|
pr_uint_t params_start;
|
2022-01-23 15:13:44 +00:00
|
|
|
pr_uint_t locals;
|
|
|
|
};
|
|
|
|
struct {
|
|
|
|
// although Ruamoko progs support more than PR_MAX_PARAMS
|
|
|
|
// arguments, only the first PR_MAX_PARAMS parameter pointers
|
|
|
|
// are initialized. This keeps builtins meant for both ISAs
|
|
|
|
// simple as they either will never accept more tha PR_MAX_PARAMS
|
|
|
|
// arugments, or they'll be modified to do the right thing.
|
|
|
|
pr_ushort_t param_offsets[PR_MAX_PARAMS];
|
|
|
|
builtin_proc func;
|
2022-01-23 15:20:05 +00:00
|
|
|
void *data; ///< extra data passed to the builtin
|
2022-01-23 15:13:44 +00:00
|
|
|
};
|
|
|
|
};
|
2004-01-05 08:08:46 +00:00
|
|
|
} bfunction_t;
|
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
/** Register a set of builtin functions with the VM. Different VMs within the
|
2010-12-09 04:35:11 +00:00
|
|
|
same program can have different builtin sets. May be called multiple times
|
|
|
|
for the same VM, but redefining a builtin is an error.
|
|
|
|
\param pr pointer to ::progs_t VM struct
|
|
|
|
\param builtins array of builtin_t builtins
|
2022-01-23 15:20:05 +00:00
|
|
|
\param data pointer to builtin-specific data. Usually the resources
|
|
|
|
struct registered with PR_Resources_Register
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2022-01-23 15:20:05 +00:00
|
|
|
void PR_RegisterBuiltins (progs_t *pr, builtin_t *builtins, void *data);
|
2001-03-27 03:57:17 +00:00
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
/** Lookup a builtin function referred by name.
|
2010-12-09 04:35:11 +00:00
|
|
|
\param pr pointer to ::progs_t VM struct
|
|
|
|
\param name name of the builtin function to lookup
|
|
|
|
\return pointer to the builtin function entry, or NULL if not found
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
|
|
|
builtin_t *PR_FindBuiltin (progs_t *pr, const char *name);
|
2001-02-26 20:52:14 +00:00
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
/** Lookup a builtin function by builtin number.
|
2010-12-09 04:35:11 +00:00
|
|
|
\param pr pointer to ::progs_t VM struct
|
|
|
|
\param num number of the builtin function to lookup
|
|
|
|
\return pointer to the builtin function entry, or NULL if not found
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2007-04-04 12:30:49 +00:00
|
|
|
builtin_t *PR_FindBuiltinNum (progs_t *pr, pr_int_t num);
|
2001-02-26 20:52:14 +00:00
|
|
|
|
2010-01-13 06:30:36 +00:00
|
|
|
/** Fixup all automatically resolved builtin functions (func = #0 in QC).
|
|
|
|
Performs any necessary builtin function number mapping. Also builds the
|
|
|
|
bfunction_t table. Called automatically during progs load.
|
2010-12-09 04:35:11 +00:00
|
|
|
\param pr pointer to ::progs_t VM struct
|
|
|
|
\return true for success, false for failure
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
|
|
|
int PR_RelocateBuiltins (progs_t *pr);
|
2001-02-26 20:52:14 +00:00
|
|
|
|
2020-02-11 06:20:49 +00:00
|
|
|
///@}
|
2001-02-26 20:52:14 +00:00
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
/** \defgroup pr_strings String Management
|
2006-12-05 11:40:00 +00:00
|
|
|
\ingroup progs
|
2004-11-08 23:27:00 +00:00
|
|
|
Strings management functions.
|
2001-08-03 06:40:28 +00:00
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
All strings accessable by the VM are stored within the VM address space.
|
2011-07-25 19:52:24 +00:00
|
|
|
These functions provide facilities to set permanent, dynamic and
|
2004-11-08 23:27:00 +00:00
|
|
|
temporary strings, as well as mutable strings using dstrings.
|
|
|
|
|
|
|
|
Permanent strings are either supplied by the progs (+ve string index) or
|
2010-01-13 06:21:29 +00:00
|
|
|
set by the main program using PR_SetString(). Permanent strings can never
|
2004-11-08 23:27:00 +00:00
|
|
|
be altered and will exist until the next progs load.
|
|
|
|
|
|
|
|
Dynamic strings can be freed at any time, but not altered.
|
|
|
|
|
|
|
|
Temporary strings are always set by the main program using
|
|
|
|
PR_SetTempString() or PR_CatStrings(). They will be freed when the
|
|
|
|
current progs stack frame is cleared. Use PR_PushFrame() and PR_PopFrame()
|
|
|
|
around the calls to PR_SetTempString() and PR_ExecuteProgram() when using
|
|
|
|
strings as parameters to a progs function.
|
|
|
|
|
|
|
|
Mutable strings are dstrings (dstring_t) mapped into the VM address space.
|
|
|
|
They can be created, altered, and destroyed at any time by the main
|
|
|
|
program (or the progs code via an appropriate builtin function).
|
|
|
|
*/
|
2020-02-11 06:20:49 +00:00
|
|
|
///@{
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2020-02-24 15:21:56 +00:00
|
|
|
/** Initialize the string management subsystem.
|
|
|
|
|
|
|
|
\param pr The VM of which the string management subsystem will be
|
|
|
|
initialized;
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2020-02-24 15:21:56 +00:00
|
|
|
void PR_Strings_Init (progs_t *pr);
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2020-04-04 05:30:50 +00:00
|
|
|
/** Initialize the string tables using the strings supplied by the progs.
|
2010-01-13 06:30:36 +00:00
|
|
|
Called automatically during progs load.
|
2010-12-09 04:35:11 +00:00
|
|
|
\param pr pointer to ::progs_t VM struct
|
|
|
|
\return true for success, false for failure
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
|
|
|
int PR_LoadStrings (progs_t *pr);
|
|
|
|
|
|
|
|
/** Check the validity of a string index.
|
2010-12-09 04:35:11 +00:00
|
|
|
\param pr pointer to ::progs_t VM struct
|
|
|
|
\param num string index to be validated
|
|
|
|
\return true if the index is valid, false otherwise
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2023-06-13 09:06:11 +00:00
|
|
|
bool PR_StringValid (progs_t *pr, pr_string_t num) __attribute__((pure));
|
2003-11-20 07:46:56 +00:00
|
|
|
|
2020-03-26 07:38:09 +00:00
|
|
|
/** Check if a string is valid and mutable.
|
|
|
|
\param pr pointer to ::progs_t VM struct
|
|
|
|
\param num string index to be checked
|
|
|
|
\return true if the string is valid and mutable, false otherwise
|
|
|
|
*/
|
2023-06-13 09:06:11 +00:00
|
|
|
bool PR_StringMutable (progs_t *pr, pr_string_t num) __attribute__((pure));
|
2003-11-20 07:46:56 +00:00
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
/** Convert a string index to a C string.
|
2010-12-09 04:35:11 +00:00
|
|
|
\param pr pointer to ::progs_t VM struct
|
|
|
|
\param num string index to be converted
|
|
|
|
\return C pointer to the string.
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2022-01-18 03:11:14 +00:00
|
|
|
const char *PR_GetString(progs_t *pr, pr_string_t num) __attribute__((pure));
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2010-01-13 06:30:36 +00:00
|
|
|
/** Retrieve the dstring_t associated with a mutable string.
|
2010-12-09 04:35:11 +00:00
|
|
|
\param pr pointer to ::progs_t VM struct
|
|
|
|
\param num string index of the mutable string
|
|
|
|
\return the dstring implementing the mutable string
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2022-01-18 03:11:14 +00:00
|
|
|
struct dstring_s *PR_GetMutableString(progs_t *pr, pr_string_t num) __attribute__((pure));
|
2004-11-08 23:27:00 +00:00
|
|
|
|
|
|
|
/** Make a permanent progs string from the given C string. Will not create a
|
|
|
|
duplicate permanent string (temporary and mutable strings are not checked).
|
2010-12-09 04:35:11 +00:00
|
|
|
\param pr pointer to ::progs_t VM struct
|
|
|
|
\param s C string to be made into a permanent progs string
|
|
|
|
\return string index of the progs string
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2022-01-18 03:11:14 +00:00
|
|
|
pr_string_t PR_SetString(progs_t *pr, const char *s);
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2020-04-04 03:32:12 +00:00
|
|
|
/** Get the progs string if it exists.
|
|
|
|
Only static strings are searched.
|
|
|
|
\param pr pointer to ::progs_t VM struct
|
|
|
|
\param s C string to be found
|
|
|
|
\return string index of the progs string if it exists, otherwise
|
|
|
|
0 (ambiguous with "").
|
|
|
|
*/
|
2022-01-18 03:11:14 +00:00
|
|
|
pr_string_t PR_FindString(progs_t *pr, const char *s);
|
2020-04-04 03:32:12 +00:00
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
/** Make a temporary progs string that will survive across function returns.
|
|
|
|
Will not duplicate a permanent string. If a new progs string is created,
|
|
|
|
it will be freed after ::PR_RS_SLOTS calls to this function. ie, up to
|
|
|
|
::PR_RS_SLOTS return strings can exist at a time.
|
2010-12-09 04:35:11 +00:00
|
|
|
\param pr pointer to ::progs_t VM struct
|
|
|
|
\param s C string to be returned to the progs code
|
|
|
|
\return string index of the progs string
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2022-01-18 03:11:14 +00:00
|
|
|
pr_string_t PR_SetReturnString(progs_t *pr, const char *s);
|
2004-11-08 23:27:00 +00:00
|
|
|
|
|
|
|
/** Make a temporary progs string that will be freed when the current progs
|
|
|
|
stack frame is exited. Will not duplicate a permantent string.
|
2010-12-09 04:35:11 +00:00
|
|
|
\param pr pointer to ::progs_t VM struct
|
|
|
|
\param s C string
|
|
|
|
\return string index of the progs string
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2022-01-18 03:11:14 +00:00
|
|
|
pr_string_t PR_SetTempString(progs_t *pr, const char *s);
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2020-03-09 13:16:19 +00:00
|
|
|
/** Make a temporary memory block that will be freed when the current progs
|
|
|
|
stack frame is exited. The contents may be anything and a new block is
|
|
|
|
returned every time, and the block is in VM addressible space. To access
|
|
|
|
the contents of the block (for reading, writing, etc), use PR_GetString()
|
|
|
|
and cast the pointer as necessary.
|
|
|
|
|
|
|
|
\param pr pointer to ::progs_t VM struct
|
|
|
|
\param size size of block in bytes
|
|
|
|
\return string index of the block
|
|
|
|
*/
|
2022-01-18 03:11:14 +00:00
|
|
|
pr_string_t PR_AllocTempBlock (progs_t *pr, size_t size);
|
2020-03-09 13:16:19 +00:00
|
|
|
|
2020-03-09 14:36:09 +00:00
|
|
|
/** Push a temporary string to the callee stack frame
|
|
|
|
|
|
|
|
This is for when the temp string needs to be freed when the called function
|
|
|
|
returns rather than the calling function. It is an error to push a non-temp
|
|
|
|
string.
|
|
|
|
|
|
|
|
\param pr pointer to ::progs_t VM struct
|
|
|
|
\param num string index of the temp string
|
|
|
|
*/
|
2022-01-18 03:11:14 +00:00
|
|
|
void PR_PushTempString (progs_t *pr, pr_string_t num);
|
2020-03-09 14:36:09 +00:00
|
|
|
|
2010-01-13 06:30:36 +00:00
|
|
|
/** Make a temporary progs string that is the concatenation of two C strings.
|
2010-12-09 04:35:11 +00:00
|
|
|
\param pr pointer to ::progs_t VM struct
|
|
|
|
\param a C string
|
|
|
|
\param b C string
|
|
|
|
\return string index of the progs string that represents the
|
2011-07-29 00:04:09 +00:00
|
|
|
concatenation of strings a and b
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2022-01-18 03:11:14 +00:00
|
|
|
pr_string_t PR_CatStrings (progs_t *pr, const char *a, const char *b);
|
2004-11-08 23:27:00 +00:00
|
|
|
|
|
|
|
/** Convert a mutable string to a temporary string.
|
2010-12-09 04:35:11 +00:00
|
|
|
\param pr pointer to ::progs_t VM struct
|
|
|
|
\param str string index of the mutable string to be converted
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2022-01-18 03:11:14 +00:00
|
|
|
void PR_MakeTempString(progs_t *pr, pr_string_t str);
|
2004-11-08 23:27:00 +00:00
|
|
|
|
|
|
|
/** Create a new mutable string.
|
2010-12-09 04:35:11 +00:00
|
|
|
\param pr pointer to ::progs_t VM struct
|
|
|
|
\return string index of the newly created mutable string
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2022-01-18 03:11:14 +00:00
|
|
|
pr_string_t PR_NewMutableString (progs_t *pr);
|
2004-11-08 23:27:00 +00:00
|
|
|
|
|
|
|
/** Make a dynamic progs string from the given C string. Will not create a
|
2011-07-25 19:52:24 +00:00
|
|
|
duplicate permanent string (temporary, dynamic and mutable strings are
|
2004-11-08 23:27:00 +00:00
|
|
|
not checked).
|
2010-12-09 04:35:11 +00:00
|
|
|
\param pr pointer to ::progs_t VM struct
|
|
|
|
\param s C string to be made into a permanent progs string
|
|
|
|
\return string index of the progs string
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2022-01-18 03:11:14 +00:00
|
|
|
pr_string_t PR_SetDynamicString (progs_t *pr, const char *s);
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2020-03-26 07:36:29 +00:00
|
|
|
/** Convert an ephemeral string to a dynamic string.
|
|
|
|
|
|
|
|
Valid strings that are not ephemeral (static, dynamic, mutable) will not
|
|
|
|
be affected, but temp and return strings will be marked dynamic, requiring
|
|
|
|
a call to PR_FreeString to return their memory.
|
|
|
|
|
2010-12-09 04:35:11 +00:00
|
|
|
\param pr pointer to ::progs_t VM struct
|
2020-03-26 07:36:29 +00:00
|
|
|
\param str The string to be "held" (made non-ephemeral). Safe to call
|
|
|
|
on any valid string, but affects only ephemeral strings.
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2022-01-18 03:11:14 +00:00
|
|
|
void PR_HoldString (progs_t *pr, pr_string_t str);
|
2004-11-08 23:27:00 +00:00
|
|
|
|
|
|
|
/** Destroy a mutable, dynamic or temporary string.
|
2010-12-09 04:35:11 +00:00
|
|
|
\param pr pointer to ::progs_t VM struct
|
|
|
|
\param str string index of the string to be destroyed
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2022-01-18 03:11:14 +00:00
|
|
|
void PR_FreeString (progs_t *pr, pr_string_t str);
|
2004-11-08 23:27:00 +00:00
|
|
|
|
|
|
|
/** Free all the temporary strings allocated in the current stack frame.
|
2010-12-09 04:35:11 +00:00
|
|
|
\param pr pointer to ::progs_t VM struct
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2004-01-03 08:43:57 +00:00
|
|
|
void PR_FreeTempStrings (progs_t *pr);
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2022-09-09 00:27:36 +00:00
|
|
|
/** Callback for handling %@ in PR_Sprintf format strings.
|
|
|
|
|
|
|
|
\param pr pointer to ::progs_t VM struct
|
|
|
|
\param at_param Parameter to be converted to a string. Usually a progs
|
|
|
|
pointer value. It is the callee's responsibility to
|
|
|
|
interpret the value as a pointer.
|
|
|
|
\param data User data pointer as passed to PR_Sprintf_SetAtHandler
|
|
|
|
\return String to be printed in place of %@
|
|
|
|
*/
|
|
|
|
typedef const char *(*prstr_at_handler_t) (progs_t *pr, pr_ptr_t at_param,
|
|
|
|
void *data);
|
|
|
|
|
|
|
|
/** Set the at_handler callback and its user data pointer.
|
|
|
|
|
|
|
|
The at_handler callback defaults to null resulting in [ptr] in the output
|
|
|
|
string. Setting the callback allows the at_handler to interpret the value
|
|
|
|
(nominally pr_ptr_t, but always a 32-bit value) as it chooses.
|
|
|
|
|
|
|
|
\param pr pointer to ::progs_t VM struct
|
|
|
|
\param at_handler Function pointer for callback to interpret the parameter
|
|
|
|
corresponding to the %@ format specifier.
|
|
|
|
\param data User data pointer, passed to \a at_handler.
|
|
|
|
*/
|
|
|
|
void PR_Sprintf_SetAtHandler (progs_t *pr, prstr_at_handler_t at_handler,
|
|
|
|
void *data);
|
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
/** Formatted printing similar to C's vsprintf, but using QC types.
|
2010-01-13 06:30:36 +00:00
|
|
|
The format string is a string of characters (other than \c \%) to be
|
|
|
|
printed that includes optional format specifiers, one for each arg to be
|
|
|
|
printed.
|
2004-11-08 23:27:00 +00:00
|
|
|
A format specifier can be one of two forms:
|
|
|
|
<ul>
|
2006-12-05 11:40:00 +00:00
|
|
|
<li>\c "%%" print a single \c '\%'
|
2004-11-08 23:27:00 +00:00
|
|
|
<li><tt>%[flags][field width][precision](conversion specifier)</tt> print a
|
|
|
|
single arg of the type specified by the conversion specifier using
|
|
|
|
the given format.
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
<ul>
|
|
|
|
<li>flags (optional)
|
|
|
|
<ul>
|
|
|
|
<li>\c '#' print the value using an alternat form
|
|
|
|
<li>\c '0' the value should be zero padded
|
|
|
|
<li>\c '-' the value is to be left adjusted on the field bondary.
|
|
|
|
<li><tt>' '</tt> A blank should be left before a positve number (or
|
|
|
|
empty string) produced by a signed conversion.
|
|
|
|
<li>\c '+' A sign (+ or -) will always be placed before a number
|
|
|
|
produced by a signed conversion.
|
|
|
|
</ul>
|
|
|
|
<li>field width (optional)
|
|
|
|
<ul>
|
|
|
|
<li>a string of decimal digits with nonzero first digit.
|
|
|
|
</ul>
|
|
|
|
<li>precision (optional)
|
|
|
|
<ul>
|
|
|
|
<li>a string consisting of <tt>'.'</tt> followed by 0 or more decimal
|
|
|
|
digits.
|
|
|
|
</ul>
|
|
|
|
<li>conversion specifier (mandatory)
|
|
|
|
<ul>
|
|
|
|
<li>\c '@' \c id Not yet implemented. Silently ignored.
|
|
|
|
<li>\c 'e' \c entity Prints the edict number of the given entity ("%i")
|
2022-01-18 04:21:06 +00:00
|
|
|
<li>\c 'i' \c int Print a int value. ("%i")
|
2004-11-08 23:27:00 +00:00
|
|
|
<li>\c 'f' \c float Print a float value. ("%f")
|
|
|
|
<li>\c 'g' \c float Print a float value. ("%f")
|
2011-07-09 00:41:30 +00:00
|
|
|
<li>\c 'p' \c void * Print a pointer value. ("%#x")
|
2006-12-05 11:40:00 +00:00
|
|
|
<li>\c 's' \c string Print a string value. ("%s")
|
2004-11-08 23:27:00 +00:00
|
|
|
<li>\c 'v' \c vector Print a vector value. ("'%g %g %g'")
|
|
|
|
<li>\c 'q' \c quaternion Print a quaternion value. ("'%g %g %g %g'")
|
2022-01-18 04:21:06 +00:00
|
|
|
<li>\c 'x' \c uint Print an unsigned int value. ("%x")
|
2004-11-08 23:27:00 +00:00
|
|
|
</ul>
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
For details, refer to the C documentation for printf.
|
|
|
|
|
2010-12-09 04:35:11 +00:00
|
|
|
\param pr pointer to ::progs_t VM struct
|
|
|
|
\param result dstring to which printing is done
|
|
|
|
\param name name to be reported in case of errors
|
|
|
|
\param format the format string
|
|
|
|
\param count number of args
|
|
|
|
\param args array of pointers to the values to be printed
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2004-01-04 07:42:43 +00:00
|
|
|
void PR_Sprintf (progs_t *pr, struct dstring_s *result, const char *name,
|
|
|
|
const char *format, int count, pr_type_t **args);
|
2001-02-26 20:52:14 +00:00
|
|
|
|
2020-02-11 06:20:49 +00:00
|
|
|
///@}
|
2004-11-08 23:27:00 +00:00
|
|
|
|
|
|
|
/** \defgroup pr_resources Resource Management
|
2006-12-05 11:40:00 +00:00
|
|
|
\ingroup progs
|
2004-11-08 23:27:00 +00:00
|
|
|
Builtin module private data management.
|
|
|
|
*/
|
2020-02-11 06:20:49 +00:00
|
|
|
///@{
|
2002-01-30 06:21:20 +00:00
|
|
|
|
2011-07-29 00:04:09 +00:00
|
|
|
/** Initialize the resource management fields.
|
|
|
|
|
|
|
|
\param pr The VM of which the resource fields will be initialized.
|
|
|
|
*/
|
2002-01-30 06:29:32 +00:00
|
|
|
void PR_Resources_Init (progs_t *pr);
|
2011-07-29 00:04:09 +00:00
|
|
|
|
2022-05-12 09:23:32 +00:00
|
|
|
void PR_Resources_Shutdown (progs_t *pr);
|
|
|
|
void PR_Builtins_Shutdown (progs_t *pr);
|
|
|
|
|
2011-07-29 00:04:09 +00:00
|
|
|
/** Clear all resources before loading a new progs.
|
|
|
|
|
|
|
|
Calls the clear() callback of all registered resources.
|
|
|
|
|
|
|
|
\param pr The VM of which the resources will be cleared.
|
|
|
|
*/
|
2002-01-30 06:21:20 +00:00
|
|
|
void PR_Resources_Clear (progs_t *pr);
|
2011-07-29 00:04:09 +00:00
|
|
|
|
|
|
|
/** Register a resource with a VM.
|
|
|
|
|
|
|
|
\param pr The VM to which the resource will be associated.
|
|
|
|
\param name The name of the resource. Used for retrieving the
|
|
|
|
resource.
|
|
|
|
\param data The resource data.
|
2022-05-12 09:23:32 +00:00
|
|
|
\param clear Callback for performing any necessary cleanup before
|
|
|
|
VM reuse. Called by PR_Resources_Clear(). The parameters
|
|
|
|
are the current VM (\p pr) and \p data.
|
|
|
|
\param destroy Callback for when the resource is about to be destryed
|
|
|
|
due to final VM shutdown. The parameters are the current
|
2011-07-29 00:04:09 +00:00
|
|
|
VM (\p pr) and \p data.
|
|
|
|
\note The name should be unique to the VM, but no checking is
|
|
|
|
done. If the name is not unique, the previous registered
|
|
|
|
resource will break. The name of the sub-system
|
|
|
|
registering the resource is a suitable name, and will
|
|
|
|
probably be unique.
|
2022-05-12 09:23:32 +00:00
|
|
|
\note During VM shutdown, \a clear is called (for all resources)
|
2022-05-15 03:00:14 +00:00
|
|
|
before \a destroy is called.
|
2011-07-29 00:04:09 +00:00
|
|
|
*/
|
2002-01-30 06:21:20 +00:00
|
|
|
void PR_Resources_Register (progs_t *pr, const char *name, void *data,
|
2022-05-12 09:23:32 +00:00
|
|
|
void (*clear)(progs_t *, void *),
|
|
|
|
void (*destroy)(progs_t *, void *));
|
2011-07-29 00:04:09 +00:00
|
|
|
|
|
|
|
/** Retrieve a resource registered with the VM.
|
|
|
|
|
|
|
|
\param pr The VM from which the resource will be retrieved.
|
|
|
|
\param name The name of the resource.
|
|
|
|
\return The resource, or NULL if \p name does not match any
|
|
|
|
resource registered with the VM.
|
|
|
|
*/
|
2002-01-30 06:21:20 +00:00
|
|
|
void *PR_Resources_Find (progs_t *pr, const char *name);
|
|
|
|
|
2011-07-29 00:04:09 +00:00
|
|
|
/** \name Resource Map support
|
|
|
|
|
|
|
|
These macros can be used to create functions for mapping C resources
|
2022-01-18 04:21:06 +00:00
|
|
|
to QuakeC int handles.
|
2011-07-29 00:04:09 +00:00
|
|
|
|
|
|
|
Valid handles are always negative.
|
|
|
|
|
|
|
|
\note \p map is the resource map itself, not a pointer to the
|
|
|
|
resource map.
|
|
|
|
*/
|
2020-02-11 06:20:49 +00:00
|
|
|
///@{
|
2011-07-29 00:04:09 +00:00
|
|
|
|
|
|
|
/** Type delcaration for the resource map.
|
|
|
|
|
|
|
|
\param type The type of the resource. The size must be at least
|
|
|
|
as large as \c sizeof(type *).
|
2021-09-25 06:42:54 +00:00
|
|
|
\note \a _size is <em>NOT</em> the number of objects in the
|
|
|
|
map. It is the number of rows in the map array (each row
|
|
|
|
has multiple objects).
|
2011-07-29 00:04:09 +00:00
|
|
|
*/
|
2004-11-08 23:27:00 +00:00
|
|
|
#define PR_RESMAP(type) struct { type *_free; type **_map; unsigned _size; }
|
|
|
|
|
2023-03-03 13:07:27 +00:00
|
|
|
#define PR_RESDELMAP(map) \
|
|
|
|
do { \
|
|
|
|
for (unsigned i = 0; i < (map)._size; i++) { \
|
|
|
|
free ((map)._map[i]); \
|
|
|
|
} \
|
|
|
|
free ((map)._map); \
|
|
|
|
} while (0)
|
|
|
|
|
2011-07-29 00:04:09 +00:00
|
|
|
/** Allocate a new resource from the resource map.
|
|
|
|
|
|
|
|
\param map The resource map.
|
|
|
|
\return A pointer to the new resource, or null if no more could
|
|
|
|
be allocated.
|
|
|
|
*/
|
2021-03-21 14:03:11 +00:00
|
|
|
#define PR_RESNEW_NC(map) \
|
2021-03-21 12:26:36 +00:00
|
|
|
({ \
|
2021-08-30 03:05:34 +00:00
|
|
|
__auto_type ret = (map)._free; \
|
|
|
|
do { \
|
2021-03-25 13:01:31 +00:00
|
|
|
if (!(map)._free) { \
|
2021-08-30 03:05:34 +00:00
|
|
|
int i, size; \
|
|
|
|
(map)._size++; \
|
|
|
|
size = (map)._size * sizeof ((map)._free); \
|
|
|
|
(map)._map = realloc ((map)._map, size); \
|
|
|
|
if (!(map)._map) { \
|
|
|
|
ret = 0; \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
(map)._free = malloc (1024 * sizeof (*(map)._free)); \
|
|
|
|
if (!(map)._free) { \
|
|
|
|
ret = 0; \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
(map)._map[(map)._size - 1] = (map)._free; \
|
|
|
|
for (i = 0; i < 1023; i++) { \
|
|
|
|
*(typeof ((map)._free) *) &(map)._free[i] \
|
|
|
|
= &(map)._free[i + 1]; \
|
|
|
|
} \
|
|
|
|
*(typeof ((map)._free) *) &(map)._free[i] = 0; \
|
2021-03-25 13:01:31 +00:00
|
|
|
} \
|
2021-08-30 03:05:34 +00:00
|
|
|
ret = (map)._free; \
|
|
|
|
(map)._free = *(typeof ((map)._free) *) ret; \
|
|
|
|
} while (0); \
|
|
|
|
ret; \
|
2021-03-21 14:03:11 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
#define PR_RESNEW(map) \
|
|
|
|
({ \
|
|
|
|
__auto_type t = PR_RESNEW_NC (map); \
|
2021-11-19 02:55:32 +00:00
|
|
|
if (t) { \
|
|
|
|
memset (t, 0, sizeof (*(map)._free)); \
|
|
|
|
} \
|
2021-03-21 12:26:36 +00:00
|
|
|
t; \
|
|
|
|
})
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2011-07-29 00:04:09 +00:00
|
|
|
/** Free a resource returning it to the resource map.
|
|
|
|
|
|
|
|
\param map The resource map.
|
|
|
|
\param t Pointer to the resource to be freed.
|
|
|
|
*/
|
2021-03-21 12:26:36 +00:00
|
|
|
#define PR_RESFREE(map,t) \
|
|
|
|
do { \
|
2021-03-25 13:01:31 +00:00
|
|
|
memset (t, 0, sizeof (*(map)._free)); \
|
|
|
|
*(typeof ((map)._free) *) t = (map)._free; \
|
|
|
|
(map)._free = t; \
|
2021-03-21 12:26:36 +00:00
|
|
|
} while (0)
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2011-07-29 00:04:09 +00:00
|
|
|
/** Free all resources in the resource map.
|
|
|
|
|
|
|
|
Any memory allocated to the resource must be freed before freeing the
|
|
|
|
resource.
|
|
|
|
|
2020-03-09 09:03:25 +00:00
|
|
|
A reset resource map is guaranteed to allocate elements sequentially.
|
|
|
|
|
2011-07-29 00:04:09 +00:00
|
|
|
\param map The resource map.
|
|
|
|
*/
|
2021-03-21 12:26:36 +00:00
|
|
|
#define PR_RESRESET(map) \
|
|
|
|
do { \
|
|
|
|
unsigned i, j; \
|
2021-03-25 13:01:31 +00:00
|
|
|
if (!(map)._size) { \
|
2021-11-14 01:07:40 +00:00
|
|
|
break; \
|
2021-03-21 12:26:36 +00:00
|
|
|
} \
|
2021-03-25 13:01:31 +00:00
|
|
|
for (i = 0; i < (map)._size; i++) { \
|
|
|
|
(map)._free = (map)._map[i]; \
|
|
|
|
for (j = 0; j < 1023; j++) { \
|
|
|
|
*(typeof ((map)._free) *) &(map)._free[j] \
|
|
|
|
= &(map)._free[j + 1]; \
|
|
|
|
} \
|
|
|
|
if (i < (map)._size - 1) { \
|
|
|
|
*(typeof ((map)._free) *) &(map)._free[j] \
|
|
|
|
= &(map)._map[i + 1][0]; \
|
|
|
|
} else { \
|
|
|
|
*(typeof ((map)._free) *) &(map)._free[j] = 0; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
(map)._free = (map)._map[0]; \
|
2021-03-21 12:26:36 +00:00
|
|
|
} while (0)
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2011-07-29 00:04:09 +00:00
|
|
|
/** Retrieve a resource from the resource map using a handle.
|
|
|
|
|
|
|
|
\param map The resource map.
|
2021-12-25 02:17:33 +00:00
|
|
|
\param ind The handle.
|
2011-07-29 00:04:09 +00:00
|
|
|
\return A pointer to the resource, or NULL if the handle is
|
|
|
|
invalid.
|
|
|
|
*/
|
2021-08-30 03:05:34 +00:00
|
|
|
#define PR_RESGET(map,ind) \
|
2021-03-21 12:26:36 +00:00
|
|
|
({ \
|
2021-08-30 03:05:34 +00:00
|
|
|
__auto_type ret = (map)._free; \
|
|
|
|
unsigned row = ~ind / 1024; \
|
|
|
|
unsigned col = ~ind % 1024; \
|
|
|
|
if (row >= (map)._size) { \
|
|
|
|
ret = 0; \
|
|
|
|
} else { \
|
|
|
|
ret = &(map)._map[row][col]; \
|
|
|
|
} \
|
|
|
|
ret; \
|
2021-03-21 12:26:36 +00:00
|
|
|
})
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2011-07-29 00:04:09 +00:00
|
|
|
/** Convert a resource pointer to a handle.
|
|
|
|
|
|
|
|
\param map The resource map.
|
|
|
|
\param ptr The resource pointer.
|
|
|
|
\return The handle or 0 if the pointer is invalid.
|
|
|
|
*/
|
2013-01-31 06:58:24 +00:00
|
|
|
#define PR_RESINDEX(map,ptr) \
|
2021-03-21 12:26:36 +00:00
|
|
|
({ \
|
|
|
|
unsigned i; \
|
|
|
|
unsigned index = 0; \
|
2021-03-25 13:01:31 +00:00
|
|
|
for (i = 0; i < (map)._size; i++) { \
|
|
|
|
long d = ptr - (map)._map[i]; \
|
2021-03-21 12:26:36 +00:00
|
|
|
if (d >= 0 && d < 1024) { \
|
|
|
|
index = ~(i * 1024 + d); \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
index; \
|
|
|
|
})
|
2020-02-11 06:20:49 +00:00
|
|
|
///@}
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2020-02-11 06:20:49 +00:00
|
|
|
///@}
|
2004-11-08 23:27:00 +00:00
|
|
|
|
|
|
|
/** \defgroup pr_zone VM memory management.
|
2006-12-05 11:40:00 +00:00
|
|
|
\ingroup progs
|
2004-11-08 23:27:00 +00:00
|
|
|
|
|
|
|
Used to allocate and free memory in the VM address space.
|
|
|
|
*/
|
2020-02-11 06:20:49 +00:00
|
|
|
///@{
|
2002-01-29 20:53:44 +00:00
|
|
|
|
|
|
|
void PR_Zone_Init (progs_t *pr);
|
|
|
|
void PR_Zone_Free (progs_t *pr, void *ptr);
|
2007-04-04 12:30:49 +00:00
|
|
|
void *PR_Zone_Malloc (progs_t *pr, pr_int_t size);
|
|
|
|
void *PR_Zone_Realloc (progs_t *pr, void *ptr, pr_int_t size);
|
2020-03-31 07:03:54 +00:00
|
|
|
void *PR_Zone_TagMalloc (progs_t *pr, int size, int tag);
|
2002-01-29 20:53:44 +00:00
|
|
|
|
2020-02-11 06:20:49 +00:00
|
|
|
///@}
|
2004-11-08 23:27:00 +00:00
|
|
|
|
|
|
|
/** \defgroup debug VM Debugging
|
2006-12-05 11:40:00 +00:00
|
|
|
\ingroup progs
|
2004-11-08 23:27:00 +00:00
|
|
|
Progs debugging support.
|
|
|
|
*/
|
2020-02-11 06:20:49 +00:00
|
|
|
/// \addtogroup debug
|
|
|
|
///@{
|
2001-07-14 23:53:59 +00:00
|
|
|
|
2020-02-23 09:56:30 +00:00
|
|
|
struct qfot_type_s;
|
|
|
|
|
|
|
|
/** Callback for viewing progs data
|
|
|
|
|
|
|
|
\param type C pointer to the type definition by which to view the
|
|
|
|
data.
|
|
|
|
\param value C pointer to the data to be viewed.
|
|
|
|
\param data User data.
|
|
|
|
*/
|
|
|
|
typedef void (*type_view_func) (struct qfot_type_s *type, pr_type_t *value,
|
|
|
|
void *data);
|
|
|
|
|
|
|
|
/** Set of callbacks for viewing progs data
|
|
|
|
|
|
|
|
Each possible type has its own callback. Basic types (those for which the
|
|
|
|
VM has specific instructions) all have separate callbacks, one for each
|
|
|
|
type, but the callbacks for compound types are expected to some
|
|
|
|
interpretation on their own, such as displaying a simple identifier or
|
|
|
|
the entire contents of the data.
|
|
|
|
*/
|
|
|
|
typedef struct type_view_s {
|
|
|
|
type_view_func struct_view;
|
|
|
|
type_view_func union_view;
|
|
|
|
type_view_func enum_view;
|
|
|
|
type_view_func array_view;
|
|
|
|
type_view_func class_view;
|
2022-01-30 01:47:37 +00:00
|
|
|
#define EV_TYPE(type) type_view_func type##_view;
|
|
|
|
#include "QF/progs/pr_type_names.h"
|
2020-02-23 09:56:30 +00:00
|
|
|
} type_view_t;
|
|
|
|
|
2020-02-23 06:56:36 +00:00
|
|
|
void PR_Debug_Init (progs_t *pr);
|
2001-07-14 23:53:59 +00:00
|
|
|
void PR_Debug_Init_Cvars (void);
|
2021-12-26 13:39:37 +00:00
|
|
|
void PR_DebugSetSym (progs_t *pr, pr_debug_header_t *debug);
|
2004-11-08 23:27:00 +00:00
|
|
|
int PR_LoadDebug (progs_t *pr);
|
2020-04-04 03:50:25 +00:00
|
|
|
const char *PR_Debug_GetBaseDirectory (progs_t *pr, const char *file);
|
2007-05-08 02:04:47 +00:00
|
|
|
void PR_Debug_Watch (progs_t *pr, const char *expr);
|
2007-09-15 07:47:31 +00:00
|
|
|
void PR_Debug_Print (progs_t *pr, const char *expr);
|
2022-09-14 10:23:59 +00:00
|
|
|
const char *PR_Debug_ValueString (progs_t *pr, pr_ptr_t offset,
|
|
|
|
struct qfot_type_s *type,
|
|
|
|
struct dstring_s *dstr);
|
2020-02-25 11:07:29 +00:00
|
|
|
pr_auxfunction_t *PR_Debug_AuxFunction (progs_t *pr, pr_uint_t func) __attribute__((pure));
|
|
|
|
pr_auxfunction_t *PR_Debug_MappedAuxFunction (progs_t *pr, pr_uint_t func) __attribute__((pure));
|
|
|
|
pr_def_t *PR_Debug_LocalDefs (progs_t *pr, pr_auxfunction_t *aux_function) __attribute__((pure));
|
|
|
|
pr_lineno_t *PR_Debug_Linenos (progs_t *pr, pr_auxfunction_t *aux_function,
|
|
|
|
pr_uint_t *num_linenos);
|
2018-10-09 03:35:01 +00:00
|
|
|
pr_auxfunction_t *PR_Get_Lineno_Func (progs_t *pr, pr_lineno_t *lineno) __attribute__((pure));
|
|
|
|
pr_uint_t PR_Get_Lineno_Addr (progs_t *pr, pr_lineno_t *lineno) __attribute__((pure));
|
|
|
|
pr_uint_t PR_Get_Lineno_Line (progs_t *pr, pr_lineno_t *lineno) __attribute__((pure));
|
|
|
|
pr_lineno_t *PR_Find_Lineno (progs_t *pr, pr_uint_t addr) __attribute__((pure));
|
2021-06-08 07:54:04 +00:00
|
|
|
pr_uint_t PR_FindSourceLineAddr (progs_t *pr, const char *file, pr_uint_t line) __attribute__((pure));
|
2018-10-09 03:35:01 +00:00
|
|
|
const char *PR_Get_Source_File (progs_t *pr, pr_lineno_t *lineno) __attribute__((pure));
|
2007-04-04 12:30:49 +00:00
|
|
|
const char *PR_Get_Source_Line (progs_t *pr, pr_uint_t addr);
|
2020-02-22 13:33:44 +00:00
|
|
|
pr_def_t *PR_Get_Param_Def (progs_t *pr, dfunction_t *func, unsigned parm) __attribute__((pure));
|
2022-01-18 03:11:14 +00:00
|
|
|
pr_def_t *PR_Get_Local_Def (progs_t *pr, pr_ptr_t *offs) __attribute__((pure));
|
2004-11-08 23:27:00 +00:00
|
|
|
void PR_PrintStatement (progs_t *pr, dstatement_t *s, int contents);
|
2001-10-08 03:46:44 +00:00
|
|
|
void PR_DumpState (progs_t *pr);
|
2003-12-05 22:33:11 +00:00
|
|
|
void PR_StackTrace (progs_t *pr);
|
2004-11-08 23:27:00 +00:00
|
|
|
void PR_Profile (progs_t *pr);
|
2001-07-14 23:53:59 +00:00
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
extern int pr_debug;
|
|
|
|
extern char *pr_source_path;
|
|
|
|
extern int pr_deadbeef_ents;
|
|
|
|
extern int pr_deadbeef_locals;
|
|
|
|
extern int pr_boundscheck;
|
|
|
|
extern int pr_faultchecks;
|
2001-02-26 20:52:14 +00:00
|
|
|
|
2020-02-11 06:20:49 +00:00
|
|
|
///@}
|
2002-01-20 03:09:03 +00:00
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
/** \defgroup pr_cmds Quake and Quakeworld common builtins
|
2006-12-05 11:40:00 +00:00
|
|
|
\ingroup progs
|
2010-01-13 06:30:36 +00:00
|
|
|
\todo This really doesn't belong in progs.
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2020-02-11 06:20:49 +00:00
|
|
|
///@{
|
2001-08-21 22:34:20 +00:00
|
|
|
|
2022-02-06 10:34:46 +00:00
|
|
|
char *PF_VarString (progs_t *pr, int first, int count);
|
2001-08-22 03:24:25 +00:00
|
|
|
void PR_Cmds_Init (progs_t *pr);
|
2001-08-21 22:34:20 +00:00
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
extern const char *pr_gametype;
|
|
|
|
|
2020-02-11 06:20:49 +00:00
|
|
|
///@}
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2001-02-26 20:52:14 +00:00
|
|
|
//============================================================================
|
|
|
|
|
2022-01-22 01:57:26 +00:00
|
|
|
#define PR_MAX_STACK_DEPTH 64
|
|
|
|
#define PR_LOCAL_STACK_SIZE 4096
|
2004-01-07 05:22:57 +00:00
|
|
|
#define PR_RS_SLOTS 16
|
[gamecode] Add a new Ruamoko instruction set
When it's finalized (most of the conversion operations will go, probably
the float bit ops, maybe (very undecided) the 3-component vector ops,
and likely the CALLN ops), this will be the actual instruction set for
Ruamoko.
Main features:
- Significant reduction in redundant instructions: no more multiple
opcodes to move the one operand size.
- load, store, push, and pop share unified addressing mode encoding
(with the exception of mode 0 for load as that is redundant with mode
0 for store, thus load mode 0 gives quick access to entity.field).
- Full support for both 32 and 64 bit signed integer, unsigned integer,
and floating point values.
- SIMD for 1, 2, (currently) 3, and 4 components. Transfers support up
to 128-bit wide operations (need two operations to transfer a full
4-component double/long vector), but all math operations support both
128-bit (32-bit components) and 256-bit (64-bit components) vectors.
- "Interpreted" operations for the various vector sizes: complex dot
and multiplication, 3d vector dot and cross product, quaternion dot
and multiplication, along with qv and vq shortcuts.
- 4-component swizzles for both sizes (not yet implemented, but the
instructions are allocated), with the option to zero or negate (thus
conjugates for complex and quaternion values) individual components.
- "Based offsets": all relevant instructions include base register
indices for all three operands allowing for direct access to any of
four areas (eg, current entity, current stack frame, Objective-QC
self, ...) instructions to set a register and push/pop the four
registers to/from the stack.
Remaining work:
- Implement swizzle operations and a few other stragglers.
= Make a decision about conversion operations (if any instructions
remain, they'll be just single-component (at 14 meaningful pairs,
that's a lot of instructions to waste on SIMD versions).
- Decide whether to keep CALL1-CALL8: probably little point in
supporting two different calling conventions, and it would free up
another eight instructions.
- Unit tests for the instructions.
- Teach qfcc to generate code for the new instruction set (hah, biggest
job, I'm sure, though hopefully not as crazy as the rewrite eleven
years ago).
2022-01-02 14:15:15 +00:00
|
|
|
#define PR_BASE_IND(o, b) (((o) & OP_##b##_BASE) >> OP_##b##_SHIFT)
|
|
|
|
#define PR_BASE(p, s, b) (p->pr_bases[PR_BASE_IND(s->op, b)])
|
2004-01-05 07:10:32 +00:00
|
|
|
|
|
|
|
typedef struct strref_s strref_t;
|
2001-02-26 20:52:14 +00:00
|
|
|
|
|
|
|
typedef struct {
|
2022-01-17 06:08:58 +00:00
|
|
|
pr_uivec4_t bases; ///< base registers on entry to function
|
2022-01-17 05:43:43 +00:00
|
|
|
pr_uint_t staddr; ///< Return statement.
|
2022-01-17 05:45:14 +00:00
|
|
|
pr_uint_t stack_ptr; ///< data stack on entry to function
|
2020-04-02 06:00:01 +00:00
|
|
|
bfunction_t *func; ///< Calling function.
|
2011-07-29 00:04:09 +00:00
|
|
|
strref_t *tstr; ///< Linked list of temporary strings.
|
2022-01-17 10:12:28 +00:00
|
|
|
pr_type_t *return_ptr; ///< Saved return address
|
2001-02-26 20:52:14 +00:00
|
|
|
} prstack_t;
|
|
|
|
|
|
|
|
struct progs_s {
|
2004-11-08 23:27:00 +00:00
|
|
|
int (*parse_field) (progs_t *pr, const char *key, const char *value);
|
|
|
|
|
|
|
|
int null_bad;
|
|
|
|
int no_exec_limit;
|
|
|
|
|
2022-05-12 08:54:23 +00:00
|
|
|
struct hashctx_s **hashctx;
|
2004-11-08 23:27:00 +00:00
|
|
|
void (*file_error) (progs_t *pr, const char *path);
|
2020-02-21 12:17:28 +00:00
|
|
|
void *(*load_file) (progs_t *pr, const char *path, off_t *size);
|
2004-11-08 23:27:00 +00:00
|
|
|
void *(*allocate_progs_mem) (progs_t *pr, int size);
|
|
|
|
void (*free_progs_mem) (progs_t *pr, void *mem);
|
|
|
|
|
|
|
|
int (*resolve) (progs_t *pr);
|
|
|
|
|
2003-12-05 22:33:11 +00:00
|
|
|
const char *progs_name;
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2003-12-05 22:33:11 +00:00
|
|
|
dprograms_t *progs;
|
|
|
|
int progs_size;
|
2004-11-08 23:27:00 +00:00
|
|
|
unsigned short crc;
|
2010-01-13 06:36:54 +00:00
|
|
|
int denorm_found;
|
2001-03-05 05:11:26 +00:00
|
|
|
|
2002-01-23 22:35:48 +00:00
|
|
|
struct memzone_s *zone;
|
2018-10-11 01:06:48 +00:00
|
|
|
int zone_size; ///< set by user
|
2002-01-23 22:35:48 +00:00
|
|
|
|
2011-07-29 00:04:09 +00:00
|
|
|
/// \name builtin functions
|
2020-02-14 07:40:38 +00:00
|
|
|
///@{
|
2001-12-14 08:15:04 +00:00
|
|
|
struct hashtab_s *builtin_hash;
|
2004-01-06 05:51:09 +00:00
|
|
|
struct hashtab_s *builtin_num_hash;
|
2021-03-21 10:56:17 +00:00
|
|
|
struct biblock_s *builtin_blocks;
|
2022-02-14 05:28:19 +00:00
|
|
|
builtin_t *bi_no_function;
|
2004-01-06 05:51:09 +00:00
|
|
|
unsigned bi_next;
|
2004-01-21 08:09:47 +00:00
|
|
|
unsigned (*bi_map) (progs_t *pr, unsigned binum);
|
2020-02-14 07:40:38 +00:00
|
|
|
///@}
|
2004-01-06 05:51:09 +00:00
|
|
|
|
2011-07-29 00:04:09 +00:00
|
|
|
/// \name symbol management
|
2020-02-14 07:40:38 +00:00
|
|
|
///@{
|
2001-03-05 05:11:26 +00:00
|
|
|
struct hashtab_s *function_hash;
|
|
|
|
struct hashtab_s *global_hash;
|
|
|
|
struct hashtab_s *field_hash;
|
2020-02-14 07:40:38 +00:00
|
|
|
///@}
|
2001-03-05 05:11:26 +00:00
|
|
|
|
2022-02-05 05:07:45 +00:00
|
|
|
/// \name type encodings
|
|
|
|
///@{
|
|
|
|
struct hashtab_s *type_hash;
|
|
|
|
pr_ptr_t type_encodings;
|
|
|
|
///@}
|
|
|
|
|
2011-07-29 00:04:09 +00:00
|
|
|
/// \name load hooks
|
2020-02-14 07:40:38 +00:00
|
|
|
///@{
|
2003-12-05 22:33:11 +00:00
|
|
|
int num_load_funcs;
|
|
|
|
int max_load_funcs;
|
2003-11-20 07:46:56 +00:00
|
|
|
pr_load_func_t **load_funcs;
|
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
/// cleared each load
|
2020-02-14 07:40:38 +00:00
|
|
|
///@{
|
2004-01-16 08:02:31 +00:00
|
|
|
int num_load_finish_funcs;
|
|
|
|
int max_load_finish_funcs;
|
|
|
|
pr_load_func_t **load_finish_funcs;
|
2020-02-14 07:40:38 +00:00
|
|
|
///@}
|
|
|
|
///@}
|
2004-01-16 08:02:31 +00:00
|
|
|
|
2011-07-29 00:04:09 +00:00
|
|
|
/// \name string management
|
2020-02-14 07:40:38 +00:00
|
|
|
///@{
|
2020-02-24 15:21:56 +00:00
|
|
|
struct prstr_resources_s *pr_string_resources;
|
2004-01-05 07:10:32 +00:00
|
|
|
strref_t *pr_xtstr;
|
2020-03-09 14:36:09 +00:00
|
|
|
strref_t *pr_pushtstr;
|
2020-02-14 07:38:37 +00:00
|
|
|
int float_promoted; ///< for PR_Sprintf
|
2020-02-14 07:40:38 +00:00
|
|
|
///@}
|
2001-03-06 04:22:33 +00:00
|
|
|
|
2011-07-29 00:04:09 +00:00
|
|
|
/// \name memory map
|
2020-02-14 07:40:38 +00:00
|
|
|
///@{
|
2003-12-05 22:33:11 +00:00
|
|
|
dfunction_t *pr_functions;
|
2007-04-07 01:41:23 +00:00
|
|
|
bfunction_t *function_table;
|
2003-12-05 22:33:11 +00:00
|
|
|
char *pr_strings;
|
|
|
|
int pr_stringsize;
|
2020-02-22 13:33:44 +00:00
|
|
|
pr_def_t *pr_globaldefs;
|
|
|
|
pr_def_t *pr_fielddefs;
|
2003-12-05 22:33:11 +00:00
|
|
|
dstatement_t *pr_statements;
|
2004-11-08 23:27:00 +00:00
|
|
|
pr_type_t *pr_globals;
|
2022-02-01 07:43:29 +00:00
|
|
|
pr_uint_t globals_size;
|
|
|
|
pr_uint_t null_size; ///< size of block considered null page
|
[gamecode] Add a new Ruamoko instruction set
When it's finalized (most of the conversion operations will go, probably
the float bit ops, maybe (very undecided) the 3-component vector ops,
and likely the CALLN ops), this will be the actual instruction set for
Ruamoko.
Main features:
- Significant reduction in redundant instructions: no more multiple
opcodes to move the one operand size.
- load, store, push, and pop share unified addressing mode encoding
(with the exception of mode 0 for load as that is redundant with mode
0 for store, thus load mode 0 gives quick access to entity.field).
- Full support for both 32 and 64 bit signed integer, unsigned integer,
and floating point values.
- SIMD for 1, 2, (currently) 3, and 4 components. Transfers support up
to 128-bit wide operations (need two operations to transfer a full
4-component double/long vector), but all math operations support both
128-bit (32-bit components) and 256-bit (64-bit components) vectors.
- "Interpreted" operations for the various vector sizes: complex dot
and multiplication, 3d vector dot and cross product, quaternion dot
and multiplication, along with qv and vq shortcuts.
- 4-component swizzles for both sizes (not yet implemented, but the
instructions are allocated), with the option to zero or negate (thus
conjugates for complex and quaternion values) individual components.
- "Based offsets": all relevant instructions include base register
indices for all three operands allowing for direct access to any of
four areas (eg, current entity, current stack frame, Objective-QC
self, ...) instructions to set a register and push/pop the four
registers to/from the stack.
Remaining work:
- Implement swizzle operations and a few other stragglers.
= Make a decision about conversion operations (if any instructions
remain, they'll be just single-component (at 14 meaningful pairs,
that's a lot of instructions to waste on SIMD versions).
- Decide whether to keep CALL1-CALL8: probably little point in
supporting two different calling conventions, and it would free up
another eight instructions.
- Unit tests for the instructions.
- Teach qfcc to generate code for the new instruction set (hah, biggest
job, I'm sure, though hopefully not as crazy as the rewrite eleven
years ago).
2022-01-02 14:15:15 +00:00
|
|
|
pr_uivec4_t pr_bases; ///< base registers (index in opcode)
|
2020-02-14 07:40:38 +00:00
|
|
|
///@}
|
2001-02-26 20:52:14 +00:00
|
|
|
|
2011-07-29 00:04:09 +00:00
|
|
|
/// \name parameter block
|
2020-02-14 07:40:38 +00:00
|
|
|
///@{
|
2003-12-05 22:33:11 +00:00
|
|
|
pr_type_t *pr_return;
|
2022-01-23 05:17:25 +00:00
|
|
|
pr_type_t *pr_params[PR_MAX_PARAMS];
|
|
|
|
pr_type_t *pr_real_params[PR_MAX_PARAMS];
|
2004-11-08 23:27:00 +00:00
|
|
|
int pr_param_size; ///< covers both params and return
|
2020-02-16 08:13:45 +00:00
|
|
|
int pr_param_alignment; ///< covers both params and return
|
2022-02-05 09:37:23 +00:00
|
|
|
pr_type_t *pr_return_buffer; ///< for discarded return values
|
|
|
|
///< or returning values to C
|
2020-02-14 07:40:38 +00:00
|
|
|
///@}
|
2003-04-22 20:11:16 +00:00
|
|
|
|
2012-07-09 06:04:12 +00:00
|
|
|
/// \name edicts
|
2020-02-25 05:57:36 +00:00
|
|
|
/// \todo FIXME should this be outside the VM?
|
2020-02-14 07:40:38 +00:00
|
|
|
///@{
|
2013-01-17 05:11:54 +00:00
|
|
|
edict_t **pr_edicts;
|
2022-01-16 13:15:18 +00:00
|
|
|
pr_uint_t max_edicts; ///< set by user
|
|
|
|
pr_uint_t *num_edicts;
|
|
|
|
pr_uint_t *reserved_edicts; ///< alloc will start at reserved_edicts+1
|
2012-07-09 06:04:12 +00:00
|
|
|
void (*unlink) (edict_t *ent);
|
|
|
|
void (*flush) (void);
|
|
|
|
int (*prune_edict) (progs_t *pr, edict_t *ent);
|
|
|
|
void (*free_edict) (progs_t *pr, edict_t *ent);
|
2013-01-17 05:11:54 +00:00
|
|
|
pr_type_t *pr_edict_area;
|
|
|
|
int pr_edict_size; ///< # of pr_type_t slots
|
2022-01-02 11:46:32 +00:00
|
|
|
pr_uint_t pr_edict_area_size; ///< for bounds checking, starts at 0
|
2022-01-18 06:32:43 +00:00
|
|
|
pr_func_t edict_parse;
|
2020-02-14 07:40:38 +00:00
|
|
|
///@}
|
2001-02-26 20:52:14 +00:00
|
|
|
|
2011-07-29 00:04:09 +00:00
|
|
|
/// \name execution state
|
2020-02-14 07:40:38 +00:00
|
|
|
///@{
|
2020-02-25 08:28:32 +00:00
|
|
|
int pr_argc; //FIXME need a good way to ensure it is correct
|
2001-02-26 20:52:14 +00:00
|
|
|
|
2023-06-13 09:06:11 +00:00
|
|
|
bool pr_trace;
|
2004-11-08 23:27:00 +00:00
|
|
|
int pr_trace_depth;
|
2007-04-07 01:41:23 +00:00
|
|
|
bfunction_t *pr_xfunction;
|
2003-12-05 22:33:11 +00:00
|
|
|
int pr_xstatement;
|
2001-02-26 20:52:14 +00:00
|
|
|
|
2022-01-22 01:57:26 +00:00
|
|
|
prstack_t pr_stack[PR_MAX_STACK_DEPTH];
|
2003-12-05 22:33:11 +00:00
|
|
|
int pr_depth;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2018-10-11 04:24:03 +00:00
|
|
|
/// \name progs visible stack
|
|
|
|
/// Usable by the progs for any purpose. Will not be accessible unless
|
|
|
|
/// a .stack global is found. Space is allocated from the top of the stack
|
|
|
|
/// (as is common for hardware). The push and pop instructions will not
|
|
|
|
/// be considered valid if there is no .stack global.
|
|
|
|
/// \note The return address and saved locals will not ever be on this
|
|
|
|
/// stack.
|
2020-02-14 07:40:38 +00:00
|
|
|
///@{
|
2018-10-11 04:24:03 +00:00
|
|
|
pr_type_t *stack;
|
2022-01-18 03:11:14 +00:00
|
|
|
pr_ptr_t stack_bottom;
|
2018-10-11 04:24:03 +00:00
|
|
|
int stack_size; ///< set by user
|
2020-02-14 07:40:38 +00:00
|
|
|
///@}
|
2018-10-11 04:24:03 +00:00
|
|
|
|
2022-01-22 01:57:26 +00:00
|
|
|
int localstack[PR_LOCAL_STACK_SIZE];
|
2003-12-05 22:33:11 +00:00
|
|
|
int localstack_used;
|
2020-02-14 07:40:38 +00:00
|
|
|
///@}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2011-07-29 00:04:09 +00:00
|
|
|
/// \name resources
|
2020-02-14 07:40:38 +00:00
|
|
|
///@{
|
2003-12-05 22:33:11 +00:00
|
|
|
pr_resource_t *resources;
|
2002-01-30 06:21:20 +00:00
|
|
|
struct hashtab_s *resource_hash;
|
2020-02-14 07:40:38 +00:00
|
|
|
///@}
|
2002-01-30 06:21:20 +00:00
|
|
|
|
2011-07-29 00:04:09 +00:00
|
|
|
/// \name obj info
|
2020-02-14 07:40:38 +00:00
|
|
|
///@{
|
2020-02-25 14:14:18 +00:00
|
|
|
struct probj_resources_s *pr_objective_resources;
|
2020-02-14 07:40:38 +00:00
|
|
|
///@}
|
2004-11-08 23:27:00 +00:00
|
|
|
|
2020-02-25 11:07:29 +00:00
|
|
|
/// \name debugging
|
2020-02-14 07:40:38 +00:00
|
|
|
///@{
|
2020-02-25 11:07:29 +00:00
|
|
|
struct prdeb_resources_s *pr_debug_resources;
|
2020-03-26 02:44:02 +00:00
|
|
|
void (*debug_handler) (prdebug_t event, void *param, void *data);
|
2020-03-24 06:35:42 +00:00
|
|
|
void *debug_data;
|
2007-05-08 02:04:47 +00:00
|
|
|
pr_type_t *watch;
|
2007-05-08 02:25:01 +00:00
|
|
|
int wp_conditional;
|
|
|
|
pr_type_t wp_val;
|
2020-02-14 07:40:38 +00:00
|
|
|
///@}
|
2001-07-14 23:53:59 +00:00
|
|
|
|
2011-07-29 00:04:09 +00:00
|
|
|
/// \name globals and fields needed by the VM
|
2020-02-14 07:40:38 +00:00
|
|
|
///@{
|
2001-03-01 08:34:30 +00:00
|
|
|
struct {
|
2022-01-16 10:32:47 +00:00
|
|
|
double *dtime; ///< required for OP_STATE d
|
|
|
|
float *ftime; ///< required for OP_STATE f
|
2022-01-16 13:15:18 +00:00
|
|
|
pr_uint_t *self; ///< required for OP_STATE
|
2022-01-22 01:57:26 +00:00
|
|
|
pr_ptr_t *stack; ///< required for OP_(PUSH|POP)*
|
2001-03-01 08:34:30 +00:00
|
|
|
} globals;
|
|
|
|
struct {
|
2010-01-13 06:30:36 +00:00
|
|
|
pr_int_t nextthink; ///< required for OP_STATE
|
|
|
|
pr_int_t frame; ///< required for OP_STATE
|
|
|
|
pr_int_t think; ///< required for OP_STATE
|
|
|
|
pr_int_t this; ///< optional for entity<->object linking
|
2001-03-01 08:34:30 +00:00
|
|
|
} fields;
|
2020-02-14 07:40:38 +00:00
|
|
|
///@}
|
2001-02-26 20:52:14 +00:00
|
|
|
};
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
/** \addtogroup progs_data_access
|
|
|
|
*/
|
2020-02-11 06:20:49 +00:00
|
|
|
///@{
|
2004-11-08 23:27:00 +00:00
|
|
|
|
|
|
|
/** Convert a progs offset/pointer to a C pointer.
|
2010-12-09 04:35:11 +00:00
|
|
|
\param pr pointer to ::progs_t VM struct
|
|
|
|
\param o offset into global data space
|
|
|
|
\return C pointer represented by the parameter. 0 offset -> NULL
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2002-05-22 21:50:24 +00:00
|
|
|
static inline pr_type_t *
|
2022-01-18 03:11:14 +00:00
|
|
|
PR_GetPointer (const progs_t *pr, pr_ptr_t o)
|
2002-05-22 21:50:24 +00:00
|
|
|
{
|
|
|
|
return o ? pr->pr_globals + o : 0;
|
|
|
|
}
|
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
/** Convert a C pointer to a progs offset/pointer.
|
2010-12-09 04:35:11 +00:00
|
|
|
\param pr pointer to ::progs_t VM struct
|
|
|
|
\param p C pointer to be converted.
|
|
|
|
\return Progs offset/pointer represented by \c p. NULL -> 0 offset
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
2022-01-18 03:11:14 +00:00
|
|
|
static inline pr_ptr_t
|
2020-02-24 02:28:43 +00:00
|
|
|
PR_SetPointer (const progs_t *pr, const void *p)
|
2002-05-22 22:35:37 +00:00
|
|
|
{
|
2020-02-24 02:28:43 +00:00
|
|
|
return p ? (const pr_type_t *) p - pr->pr_globals : 0;
|
2002-05-22 22:35:37 +00:00
|
|
|
}
|
|
|
|
|
2020-02-11 06:20:49 +00:00
|
|
|
///@}
|
2004-11-08 23:27:00 +00:00
|
|
|
|
|
|
|
/** \example vm-exec.c
|
|
|
|
*/
|
|
|
|
|
2001-08-27 21:13:00 +00:00
|
|
|
#endif//__QF_progs_h
|