2010-02-15 23:26:55 +00:00
/*
Copyright ( C ) 1996 - 2001 Id Software , Inc .
Copyright ( C ) 2002 - 2009 John Fitzgibbons and others
2014-09-22 08:55:46 +00:00
Copyright ( C ) 2010 - 2014 QuakeSpasm developers
2010-02-15 23:26:55 +00:00
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 the Free Software
Foundation , Inc . , 59 Temple Place - Suite 330 , Boston , MA 02111 - 1307 , USA .
*/
// sv_edict.c -- entity dictionary
# include "quakedef.h"
2010-02-17 07:28:44 +00:00
int type_size [ 8 ] = {
1 , // ev_void
1 , // sizeof(string_t) / 4 // ev_string
1 , // ev_float
3 , // ev_vector
1 , // ev_entity
1 , // ev_field
1 , // sizeof(func_t) / 4 // ev_function
1 // sizeof(void *) / 4 // ev_pointer
} ;
2010-02-15 23:26:55 +00:00
2011-12-12 08:56:25 +00:00
static ddef_t * ED_FieldAtOfs ( int ofs ) ;
2010-02-15 23:26:55 +00:00
2011-12-28 22:01:33 +00:00
cvar_t nomonsters = { " nomonsters " , " 0 " , CVAR_NONE } ;
cvar_t gamecfg = { " gamecfg " , " 0 " , CVAR_NONE } ;
cvar_t scratch1 = { " scratch1 " , " 0 " , CVAR_NONE } ;
cvar_t scratch2 = { " scratch2 " , " 0 " , CVAR_NONE } ;
cvar_t scratch3 = { " scratch3 " , " 0 " , CVAR_NONE } ;
cvar_t scratch4 = { " scratch4 " , " 0 " , CVAR_NONE } ;
cvar_t savedgamecfg = { " savedgamecfg " , " 0 " , CVAR_ARCHIVE } ;
cvar_t saved1 = { " saved1 " , " 0 " , CVAR_ARCHIVE } ;
cvar_t saved2 = { " saved2 " , " 0 " , CVAR_ARCHIVE } ;
cvar_t saved3 = { " saved3 " , " 0 " , CVAR_ARCHIVE } ;
cvar_t saved4 = { " saved4 " , " 0 " , CVAR_ARCHIVE } ;
2010-02-15 23:26:55 +00:00
/*
= = = = = = = = = = = = = = = = =
ED_ClearEdict
Sets everything to NULL
= = = = = = = = = = = = = = = = =
*/
void ED_ClearEdict ( edict_t * e )
{
2018-05-01 00:35:14 +00:00
memset ( & e - > v , 0 , qcvm - > progs - > entityfields * 4 ) ;
2010-02-15 23:26:55 +00:00
e - > free = false ;
}
/*
= = = = = = = = = = = = = = = = =
ED_Alloc
Either finds a free edict , or allocates a new one .
Try to avoid reusing an entity that was recently freed , because it
can cause the client to think the entity morphed into something else
instead of being removed and recreated , which can cause interpolated
angles and bad trails .
= = = = = = = = = = = = = = = = =
*/
edict_t * ED_Alloc ( void )
{
int i ;
edict_t * e ;
2018-05-01 00:35:14 +00:00
for ( i = qcvm - > reserved_edicts ; i < qcvm - > num_edicts ; i + + )
2010-02-15 23:26:55 +00:00
{
e = EDICT_NUM ( i ) ;
// the first couple seconds of server time can involve a lot of
// freeing and allocating, so relax the replacement policy
2018-05-01 00:35:14 +00:00
if ( e - > free & & ( e - > freetime < 2 | | qcvm - > time - e - > freetime > 0.5 ) )
2010-02-15 23:26:55 +00:00
{
ED_ClearEdict ( e ) ;
return e ;
}
}
2018-05-01 00:35:14 +00:00
if ( i = = qcvm - > max_edicts ) //johnfitz -- use sv.max_edicts instead of MAX_EDICTS
Host_Error ( " ED_Alloc: no free edicts (max_edicts is %i) " , qcvm - > max_edicts ) ;
2010-02-15 23:26:55 +00:00
2018-05-01 00:35:14 +00:00
qcvm - > num_edicts + + ;
2010-02-15 23:26:55 +00:00
e = EDICT_NUM ( i ) ;
2018-05-01 00:35:14 +00:00
memset ( e , 0 , qcvm - > edict_size ) ; // ericw -- switched sv.edicts to malloc(), so we are accessing uninitialized memory and must fully zero it, not just ED_ClearEdict
2022-08-11 19:38:36 +00:00
e - > baseline = nullentitystate ;
2010-02-15 23:26:55 +00:00
return e ;
}
/*
= = = = = = = = = = = = = = = = =
ED_Free
Marks the edict as free
FIXME : walk all entities and NULL out references to this entity
= = = = = = = = = = = = = = = = =
*/
void ED_Free ( edict_t * ed )
{
SV_UnlinkEdict ( ed ) ; // unlink from world bsp
ed - > free = true ;
ed - > v . model = 0 ;
ed - > v . takedamage = 0 ;
ed - > v . modelindex = 0 ;
ed - > v . colormap = 0 ;
ed - > v . skin = 0 ;
ed - > v . frame = 0 ;
VectorCopy ( vec3_origin , ed - > v . origin ) ;
VectorCopy ( vec3_origin , ed - > v . angles ) ;
ed - > v . nextthink = - 1 ;
ed - > v . solid = 0 ;
ed - > alpha = ENTALPHA_DEFAULT ; //johnfitz -- reset alpha for next entity
2018-05-01 00:35:14 +00:00
ed - > freetime = qcvm - > time ;
2010-02-15 23:26:55 +00:00
}
//===========================================================================
/*
= = = = = = = = = = = =
ED_GlobalAtOfs
= = = = = = = = = = = =
*/
2011-12-12 08:56:25 +00:00
static ddef_t * ED_GlobalAtOfs ( int ofs )
2010-02-15 23:26:55 +00:00
{
ddef_t * def ;
int i ;
2018-05-01 00:35:14 +00:00
for ( i = 0 ; i < qcvm - > progs - > numglobaldefs ; i + + )
2010-02-15 23:26:55 +00:00
{
2018-05-01 00:35:14 +00:00
def = & qcvm - > globaldefs [ i ] ;
2010-02-15 23:26:55 +00:00
if ( def - > ofs = = ofs )
return def ;
}
return NULL ;
}
/*
= = = = = = = = = = = =
ED_FieldAtOfs
= = = = = = = = = = = =
*/
2011-12-12 08:56:25 +00:00
static ddef_t * ED_FieldAtOfs ( int ofs )
2010-02-15 23:26:55 +00:00
{
ddef_t * def ;
int i ;
2018-05-01 00:35:14 +00:00
for ( i = 0 ; i < qcvm - > progs - > numfielddefs ; i + + )
2010-02-15 23:26:55 +00:00
{
2018-05-01 00:35:14 +00:00
def = & qcvm - > fielddefs [ i ] ;
2010-02-15 23:26:55 +00:00
if ( def - > ofs = = ofs )
return def ;
}
return NULL ;
}
/*
= = = = = = = = = = = =
ED_FindField
= = = = = = = = = = = =
*/
2017-09-17 02:12:53 +00:00
ddef_t * ED_FindField ( const char * name )
2010-02-15 23:26:55 +00:00
{
ddef_t * def ;
int i ;
2018-05-01 00:35:14 +00:00
for ( i = 0 ; i < qcvm - > progs - > numfielddefs ; i + + )
2010-02-15 23:26:55 +00:00
{
2018-05-01 00:35:14 +00:00
def = & qcvm - > fielddefs [ i ] ;
2011-12-12 08:56:25 +00:00
if ( ! strcmp ( PR_GetString ( def - > s_name ) , name ) )
2010-02-15 23:26:55 +00:00
return def ;
}
return NULL ;
}
2017-09-17 02:12:53 +00:00
/*
*/
int ED_FindFieldOffset ( const char * name )
{
ddef_t * def = ED_FindField ( name ) ;
if ( ! def )
return - 1 ;
return def - > ofs ;
}
2010-02-15 23:26:55 +00:00
/*
= = = = = = = = = = = =
ED_FindGlobal
= = = = = = = = = = = =
*/
2017-09-17 02:12:53 +00:00
ddef_t * ED_FindGlobal ( const char * name )
2010-02-15 23:26:55 +00:00
{
ddef_t * def ;
int i ;
2018-05-01 00:35:14 +00:00
for ( i = 0 ; i < qcvm - > progs - > numglobaldefs ; i + + )
2010-02-15 23:26:55 +00:00
{
2018-05-01 00:35:14 +00:00
def = & qcvm - > globaldefs [ i ] ;
2011-12-12 08:56:25 +00:00
if ( ! strcmp ( PR_GetString ( def - > s_name ) , name ) )
2010-02-15 23:26:55 +00:00
return def ;
}
return NULL ;
}
/*
= = = = = = = = = = = =
ED_FindFunction
= = = = = = = = = = = =
*/
2017-09-17 02:12:53 +00:00
dfunction_t * ED_FindFunction ( const char * fn_name )
2010-02-15 23:26:55 +00:00
{
dfunction_t * func ;
int i ;
2018-05-01 00:35:14 +00:00
for ( i = 0 ; i < qcvm - > progs - > numfunctions ; i + + )
2010-02-15 23:26:55 +00:00
{
2018-05-01 00:35:14 +00:00
func = & qcvm - > functions [ i ] ;
2011-12-12 08:56:25 +00:00
if ( ! strcmp ( PR_GetString ( func - > s_name ) , fn_name ) )
2010-02-15 23:26:55 +00:00
return func ;
}
return NULL ;
}
/*
= = = = = = = = = = = =
GetEdictFieldValue
= = = = = = = = = = = =
*/
2017-09-17 02:12:53 +00:00
eval_t * GetEdictFieldValue ( edict_t * ed , int fldofs )
2010-02-15 23:26:55 +00:00
{
2017-09-17 02:12:53 +00:00
if ( fldofs < 0 )
2010-02-15 23:26:55 +00:00
return NULL ;
2017-09-17 02:12:53 +00:00
return ( eval_t * ) ( ( char * ) & ed - > v + fldofs * 4 ) ;
2010-02-15 23:26:55 +00:00
}
/*
= = = = = = = = = = = =
PR_ValueString
2010-08-29 12:36:03 +00:00
( etype_t type , eval_t * val )
2010-02-15 23:26:55 +00:00
Returns a string describing * data in a type specific manner
= = = = = = = = = = = = =
*/
2011-12-12 08:56:25 +00:00
static const char * PR_ValueString ( int type , eval_t * val )
2010-02-15 23:26:55 +00:00
{
2012-12-11 10:11:22 +00:00
static char line [ 512 ] ;
2010-02-15 23:26:55 +00:00
ddef_t * def ;
dfunction_t * f ;
type & = ~ DEF_SAVEGLOBAL ;
switch ( type )
{
case ev_string :
2022-04-23 14:23:10 +00:00
q_snprintf ( line , sizeof ( line ) , " %s " , PR_GetString ( val - > string ) ) ;
2010-02-15 23:26:55 +00:00
break ;
case ev_entity :
2022-04-23 14:23:10 +00:00
q_snprintf ( line , sizeof ( line ) , " entity %i " , NUM_FOR_EDICT ( PROG_TO_EDICT ( val - > edict ) ) ) ;
2010-02-15 23:26:55 +00:00
break ;
case ev_function :
2018-05-01 00:35:14 +00:00
f = qcvm - > functions + val - > function ;
2022-04-23 14:23:10 +00:00
q_snprintf ( line , sizeof ( line ) , " %s() " , PR_GetString ( f - > s_name ) ) ;
2010-02-15 23:26:55 +00:00
break ;
case ev_field :
def = ED_FieldAtOfs ( val - > _int ) ;
2022-04-23 14:23:10 +00:00
q_snprintf ( line , sizeof ( line ) , " .%s " , PR_GetString ( def - > s_name ) ) ;
2010-02-15 23:26:55 +00:00
break ;
case ev_void :
2022-04-23 14:23:10 +00:00
q_snprintf ( line , sizeof ( line ) , " void " ) ;
2010-02-15 23:26:55 +00:00
break ;
case ev_float :
2022-04-23 14:23:10 +00:00
q_snprintf ( line , sizeof ( line ) , " %5.1f " , val - > _float ) ;
2010-02-15 23:26:55 +00:00
break ;
2023-07-06 04:16:32 +00:00
case ev_ext_double :
q_snprintf ( line , sizeof ( line ) , " %5.1f " , val - > _double ) ;
break ;
2017-09-17 02:12:53 +00:00
case ev_ext_integer :
sprintf ( line , " %i " , val - > _int ) ;
break ;
2023-07-06 04:16:32 +00:00
case ev_ext_uint32 :
sprintf ( line , " %u " , val - > _uint32 ) ;
break ;
case ev_ext_sint64 :
sprintf ( line , " % " PRIi64 , val - > _sint64 ) ;
break ;
case ev_ext_uint64 :
sprintf ( line , " % " PRIu64 , val - > _uint64 ) ;
break ;
2010-02-15 23:26:55 +00:00
case ev_vector :
2022-04-23 14:23:10 +00:00
q_snprintf ( line , sizeof ( line ) , " '%5.1f %5.1f %5.1f' " , val - > vector [ 0 ] , val - > vector [ 1 ] , val - > vector [ 2 ] ) ;
2010-02-15 23:26:55 +00:00
break ;
case ev_pointer :
2022-04-23 14:23:10 +00:00
q_snprintf ( line , sizeof ( line ) , " pointer " ) ;
2010-02-15 23:26:55 +00:00
break ;
default :
2022-04-23 14:23:10 +00:00
q_snprintf ( line , sizeof ( line ) , " bad type %i " , type ) ;
2010-02-15 23:26:55 +00:00
break ;
}
return line ;
}
/*
= = = = = = = = = = = =
PR_UglyValueString
2010-08-29 12:36:03 +00:00
( etype_t type , eval_t * val )
2010-02-15 23:26:55 +00:00
Returns a string describing * data in a type specific manner
Easier to parse than PR_ValueString
= = = = = = = = = = = = =
*/
2017-09-17 02:12:53 +00:00
const char * PR_UglyValueString ( int type , eval_t * val )
2010-02-15 23:26:55 +00:00
{
2018-12-30 05:24:36 +00:00
static char line [ 1024 ] ;
2010-02-15 23:26:55 +00:00
ddef_t * def ;
dfunction_t * f ;
type & = ~ DEF_SAVEGLOBAL ;
switch ( type )
{
case ev_string :
2018-12-30 05:24:36 +00:00
q_snprintf ( line , sizeof ( line ) , " %s " , PR_GetString ( val - > string ) ) ;
2010-02-15 23:26:55 +00:00
break ;
case ev_entity :
2018-12-30 05:24:36 +00:00
q_snprintf ( line , sizeof ( line ) , " %i " , NUM_FOR_EDICT ( PROG_TO_EDICT ( val - > edict ) ) ) ;
2010-02-15 23:26:55 +00:00
break ;
case ev_function :
2018-05-01 00:35:14 +00:00
f = qcvm - > functions + val - > function ;
2018-12-30 05:24:36 +00:00
q_snprintf ( line , sizeof ( line ) , " %s " , PR_GetString ( f - > s_name ) ) ;
2010-02-15 23:26:55 +00:00
break ;
case ev_field :
def = ED_FieldAtOfs ( val - > _int ) ;
2018-12-30 05:24:36 +00:00
q_snprintf ( line , sizeof ( line ) , " %s " , PR_GetString ( def - > s_name ) ) ;
2010-02-15 23:26:55 +00:00
break ;
case ev_void :
2018-12-30 05:24:36 +00:00
q_snprintf ( line , sizeof ( line ) , " void " ) ;
2010-02-15 23:26:55 +00:00
break ;
case ev_float :
2018-12-30 05:24:36 +00:00
q_snprintf ( line , sizeof ( line ) , " %f " , val - > _float ) ;
2010-02-15 23:26:55 +00:00
break ;
2017-09-17 02:12:53 +00:00
case ev_ext_integer :
sprintf ( line , " %i " , val - > _int ) ;
break ;
2023-07-06 04:16:32 +00:00
case ev_ext_uint32 :
sprintf ( line , " %u " , val - > _uint32 ) ;
break ;
case ev_ext_sint64 :
sprintf ( line , " % " PRIi64 , val - > _sint64 ) ;
break ;
case ev_ext_uint64 :
sprintf ( line , " % " PRIu64 , val - > _uint64 ) ;
break ;
case ev_ext_double :
q_snprintf ( line , sizeof ( line ) , " %f " , val - > _double ) ;
break ;
2010-02-15 23:26:55 +00:00
case ev_vector :
2018-12-30 05:24:36 +00:00
q_snprintf ( line , sizeof ( line ) , " %f %f %f " , val - > vector [ 0 ] , val - > vector [ 1 ] , val - > vector [ 2 ] ) ;
2010-02-15 23:26:55 +00:00
break ;
default :
2018-12-30 05:24:36 +00:00
q_snprintf ( line , sizeof ( line ) , " bad type %i " , type ) ;
2010-02-15 23:26:55 +00:00
break ;
}
return line ;
}
/*
= = = = = = = = = = = =
PR_GlobalString
Returns a string with a description and the contents of a global ,
padded to 20 field width
= = = = = = = = = = = =
*/
2010-08-29 02:22:55 +00:00
const char * PR_GlobalString ( int ofs )
2010-02-15 23:26:55 +00:00
{
2012-12-11 10:11:22 +00:00
static char line [ 512 ] ;
2010-08-29 02:22:55 +00:00
const char * s ;
2010-02-15 23:26:55 +00:00
int i ;
2011-12-12 08:56:25 +00:00
ddef_t * def ;
void * val ;
2010-02-15 23:26:55 +00:00
2018-05-01 00:35:14 +00:00
val = ( void * ) & qcvm - > globals [ ofs ] ;
2010-02-15 23:26:55 +00:00
def = ED_GlobalAtOfs ( ofs ) ;
if ( ! def )
2022-04-23 14:23:10 +00:00
q_snprintf ( line , sizeof ( line ) , " %i(?) " , ofs ) ;
2010-02-15 23:26:55 +00:00
else
{
64 bit compatibility effort, 4/nn: x86_64 works just fine now, yey!
the QuakeC interpreter used to use string pointer offsets from pr_strings
even when the pointers lead to engine data which is often well out of
32bit range on a 64bit architecture and they lead to crashes. they now
go through the new PR_SetEngineString and PR_GetString functions which
turn any address outside the pr_strings area into an index into a table
of engine string addresses, adding new string addresses to the table as
needed. the engine strings table is allocated with 256 entries at first
(see the PR_STRING_ALLOCSLOTS definition in pr_edict.c) and its size is
incremented by 256 as needed and re-allocated on the zone. managing that
allocation and reallocation is accomplished by the recently added Z_Realloc
function. implementation based on the uhexen2 (hexen2: hammer of thyrion)
engine which, in turn, is loosely based on twilight and quakeforge engines.
pr_strings range check is from tyrquake.
pr_edict.c: added the new PR_SetEngineString, PR_GetString, PR_AllocString
public functions and the new private PR_AllocStringSlots function. made
ED_NewString private to pr_edict.c and reworked it to return an index to a
newly allocated string.
progs.h: added prototypes for the new public PR_SetEngineString, PR_GetString
and PR_AllocString functions.
host_cmd.c, pr_cmds.c, pr_edict.c, pr_exec.c, progs.h, sv_main.c, sv_phys.c:
modifed to use the new PR_SetEngineString and PR_GetString functions.
git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@38 af15c1b1-3010-417e-b628-4374ebc0bcbd
2010-02-17 15:04:50 +00:00
s = PR_ValueString ( def - > type , ( eval_t * ) val ) ;
2022-04-23 14:23:10 +00:00
q_snprintf ( line , sizeof ( line ) , " %i(%s)%s " , ofs , PR_GetString ( def - > s_name ) , s ) ;
2010-02-15 23:26:55 +00:00
}
i = strlen ( line ) ;
2011-12-12 08:56:25 +00:00
for ( ; i < 20 ; i + + )
strcat ( line , " " ) ;
strcat ( line , " " ) ;
2010-02-15 23:26:55 +00:00
return line ;
}
2010-08-29 02:22:55 +00:00
const char * PR_GlobalStringNoContents ( int ofs )
2010-02-15 23:26:55 +00:00
{
2012-12-11 10:11:22 +00:00
static char line [ 512 ] ;
2010-02-15 23:26:55 +00:00
int i ;
2011-12-12 08:56:25 +00:00
ddef_t * def ;
2010-02-15 23:26:55 +00:00
def = ED_GlobalAtOfs ( ofs ) ;
if ( ! def )
2022-04-23 14:23:10 +00:00
q_snprintf ( line , sizeof ( line ) , " %i(?) " , ofs ) ;
2010-02-15 23:26:55 +00:00
else
2022-04-23 14:23:10 +00:00
q_snprintf ( line , sizeof ( line ) , " %i(%s) " , ofs , PR_GetString ( def - > s_name ) ) ;
2010-02-15 23:26:55 +00:00
i = strlen ( line ) ;
2011-12-12 08:56:25 +00:00
for ( ; i < 20 ; i + + )
strcat ( line , " " ) ;
strcat ( line , " " ) ;
2010-02-15 23:26:55 +00:00
return line ;
}
/*
= = = = = = = = = = = = =
ED_Print
For debugging
= = = = = = = = = = = = =
*/
void ED_Print ( edict_t * ed )
{
ddef_t * d ;
int * v ;
64 bit compatibility effort, 4/nn: x86_64 works just fine now, yey!
the QuakeC interpreter used to use string pointer offsets from pr_strings
even when the pointers lead to engine data which is often well out of
32bit range on a 64bit architecture and they lead to crashes. they now
go through the new PR_SetEngineString and PR_GetString functions which
turn any address outside the pr_strings area into an index into a table
of engine string addresses, adding new string addresses to the table as
needed. the engine strings table is allocated with 256 entries at first
(see the PR_STRING_ALLOCSLOTS definition in pr_edict.c) and its size is
incremented by 256 as needed and re-allocated on the zone. managing that
allocation and reallocation is accomplished by the recently added Z_Realloc
function. implementation based on the uhexen2 (hexen2: hammer of thyrion)
engine which, in turn, is loosely based on twilight and quakeforge engines.
pr_strings range check is from tyrquake.
pr_edict.c: added the new PR_SetEngineString, PR_GetString, PR_AllocString
public functions and the new private PR_AllocStringSlots function. made
ED_NewString private to pr_edict.c and reworked it to return an index to a
newly allocated string.
progs.h: added prototypes for the new public PR_SetEngineString, PR_GetString
and PR_AllocString functions.
host_cmd.c, pr_cmds.c, pr_edict.c, pr_exec.c, progs.h, sv_main.c, sv_phys.c:
modifed to use the new PR_SetEngineString and PR_GetString functions.
git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@38 af15c1b1-3010-417e-b628-4374ebc0bcbd
2010-02-17 15:04:50 +00:00
int i , j , l ;
2010-08-29 02:22:55 +00:00
const char * name ;
2010-02-15 23:26:55 +00:00
int type ;
if ( ed - > free )
{
Con_Printf ( " FREE \n " ) ;
return ;
}
Con_SafePrintf ( " \n EDICT %i: \n " , NUM_FOR_EDICT ( ed ) ) ; //johnfitz -- was Con_Printf
2018-05-01 00:35:14 +00:00
for ( i = 1 ; i < qcvm - > progs - > numfielddefs ; i + + )
2010-02-15 23:26:55 +00:00
{
2018-05-01 00:35:14 +00:00
d = & qcvm - > fielddefs [ i ] ;
64 bit compatibility effort, 4/nn: x86_64 works just fine now, yey!
the QuakeC interpreter used to use string pointer offsets from pr_strings
even when the pointers lead to engine data which is often well out of
32bit range on a 64bit architecture and they lead to crashes. they now
go through the new PR_SetEngineString and PR_GetString functions which
turn any address outside the pr_strings area into an index into a table
of engine string addresses, adding new string addresses to the table as
needed. the engine strings table is allocated with 256 entries at first
(see the PR_STRING_ALLOCSLOTS definition in pr_edict.c) and its size is
incremented by 256 as needed and re-allocated on the zone. managing that
allocation and reallocation is accomplished by the recently added Z_Realloc
function. implementation based on the uhexen2 (hexen2: hammer of thyrion)
engine which, in turn, is loosely based on twilight and quakeforge engines.
pr_strings range check is from tyrquake.
pr_edict.c: added the new PR_SetEngineString, PR_GetString, PR_AllocString
public functions and the new private PR_AllocStringSlots function. made
ED_NewString private to pr_edict.c and reworked it to return an index to a
newly allocated string.
progs.h: added prototypes for the new public PR_SetEngineString, PR_GetString
and PR_AllocString functions.
host_cmd.c, pr_cmds.c, pr_edict.c, pr_exec.c, progs.h, sv_main.c, sv_phys.c:
modifed to use the new PR_SetEngineString and PR_GetString functions.
git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@38 af15c1b1-3010-417e-b628-4374ebc0bcbd
2010-02-17 15:04:50 +00:00
name = PR_GetString ( d - > s_name ) ;
2011-12-12 08:56:25 +00:00
l = strlen ( name ) ;
64 bit compatibility effort, 4/nn: x86_64 works just fine now, yey!
the QuakeC interpreter used to use string pointer offsets from pr_strings
even when the pointers lead to engine data which is often well out of
32bit range on a 64bit architecture and they lead to crashes. they now
go through the new PR_SetEngineString and PR_GetString functions which
turn any address outside the pr_strings area into an index into a table
of engine string addresses, adding new string addresses to the table as
needed. the engine strings table is allocated with 256 entries at first
(see the PR_STRING_ALLOCSLOTS definition in pr_edict.c) and its size is
incremented by 256 as needed and re-allocated on the zone. managing that
allocation and reallocation is accomplished by the recently added Z_Realloc
function. implementation based on the uhexen2 (hexen2: hammer of thyrion)
engine which, in turn, is loosely based on twilight and quakeforge engines.
pr_strings range check is from tyrquake.
pr_edict.c: added the new PR_SetEngineString, PR_GetString, PR_AllocString
public functions and the new private PR_AllocStringSlots function. made
ED_NewString private to pr_edict.c and reworked it to return an index to a
newly allocated string.
progs.h: added prototypes for the new public PR_SetEngineString, PR_GetString
and PR_AllocString functions.
host_cmd.c, pr_cmds.c, pr_edict.c, pr_exec.c, progs.h, sv_main.c, sv_phys.c:
modifed to use the new PR_SetEngineString and PR_GetString functions.
git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@38 af15c1b1-3010-417e-b628-4374ebc0bcbd
2010-02-17 15:04:50 +00:00
if ( l > 1 & & name [ l - 2 ] = = ' _ ' )
2010-02-15 23:26:55 +00:00
continue ; // skip _x, _y, _z vars
v = ( int * ) ( ( char * ) & ed - > v + d - > ofs * 4 ) ;
// if the value is still all 0, skip the field
type = d - > type & ~ DEF_SAVEGLOBAL ;
2011-12-12 08:56:25 +00:00
for ( j = 0 ; j < type_size [ type ] ; j + + )
{
2010-02-15 23:26:55 +00:00
if ( v [ j ] )
break ;
2011-12-12 08:56:25 +00:00
}
2010-02-15 23:26:55 +00:00
if ( j = = type_size [ type ] )
continue ;
2011-12-12 08:56:25 +00:00
Con_SafePrintf ( " %s " , name ) ; //johnfitz -- was Con_Printf
2010-02-15 23:26:55 +00:00
while ( l + + < 15 )
Con_SafePrintf ( " " ) ; //johnfitz -- was Con_Printf
Con_SafePrintf ( " %s \n " , PR_ValueString ( d - > type , ( eval_t * ) v ) ) ; //johnfitz -- was Con_Printf
}
}
/*
= = = = = = = = = = = = =
ED_Write
For savegames
= = = = = = = = = = = = =
*/
void ED_Write ( FILE * f , edict_t * ed )
{
ddef_t * d ;
int * v ;
int i , j ;
2010-08-29 02:22:55 +00:00
const char * name ;
2010-02-15 23:26:55 +00:00
int type ;
fprintf ( f , " { \n " ) ;
if ( ed - > free )
{
fprintf ( f , " } \n " ) ;
return ;
}
2018-05-01 00:35:14 +00:00
for ( i = 1 ; i < qcvm - > progs - > numfielddefs ; i + + )
2010-02-15 23:26:55 +00:00
{
2018-05-01 00:35:14 +00:00
d = & qcvm - > fielddefs [ i ] ;
64 bit compatibility effort, 4/nn: x86_64 works just fine now, yey!
the QuakeC interpreter used to use string pointer offsets from pr_strings
even when the pointers lead to engine data which is often well out of
32bit range on a 64bit architecture and they lead to crashes. they now
go through the new PR_SetEngineString and PR_GetString functions which
turn any address outside the pr_strings area into an index into a table
of engine string addresses, adding new string addresses to the table as
needed. the engine strings table is allocated with 256 entries at first
(see the PR_STRING_ALLOCSLOTS definition in pr_edict.c) and its size is
incremented by 256 as needed and re-allocated on the zone. managing that
allocation and reallocation is accomplished by the recently added Z_Realloc
function. implementation based on the uhexen2 (hexen2: hammer of thyrion)
engine which, in turn, is loosely based on twilight and quakeforge engines.
pr_strings range check is from tyrquake.
pr_edict.c: added the new PR_SetEngineString, PR_GetString, PR_AllocString
public functions and the new private PR_AllocStringSlots function. made
ED_NewString private to pr_edict.c and reworked it to return an index to a
newly allocated string.
progs.h: added prototypes for the new public PR_SetEngineString, PR_GetString
and PR_AllocString functions.
host_cmd.c, pr_cmds.c, pr_edict.c, pr_exec.c, progs.h, sv_main.c, sv_phys.c:
modifed to use the new PR_SetEngineString and PR_GetString functions.
git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@38 af15c1b1-3010-417e-b628-4374ebc0bcbd
2010-02-17 15:04:50 +00:00
name = PR_GetString ( d - > s_name ) ;
2011-12-12 08:56:25 +00:00
j = strlen ( name ) ;
64 bit compatibility effort, 4/nn: x86_64 works just fine now, yey!
the QuakeC interpreter used to use string pointer offsets from pr_strings
even when the pointers lead to engine data which is often well out of
32bit range on a 64bit architecture and they lead to crashes. they now
go through the new PR_SetEngineString and PR_GetString functions which
turn any address outside the pr_strings area into an index into a table
of engine string addresses, adding new string addresses to the table as
needed. the engine strings table is allocated with 256 entries at first
(see the PR_STRING_ALLOCSLOTS definition in pr_edict.c) and its size is
incremented by 256 as needed and re-allocated on the zone. managing that
allocation and reallocation is accomplished by the recently added Z_Realloc
function. implementation based on the uhexen2 (hexen2: hammer of thyrion)
engine which, in turn, is loosely based on twilight and quakeforge engines.
pr_strings range check is from tyrquake.
pr_edict.c: added the new PR_SetEngineString, PR_GetString, PR_AllocString
public functions and the new private PR_AllocStringSlots function. made
ED_NewString private to pr_edict.c and reworked it to return an index to a
newly allocated string.
progs.h: added prototypes for the new public PR_SetEngineString, PR_GetString
and PR_AllocString functions.
host_cmd.c, pr_cmds.c, pr_edict.c, pr_exec.c, progs.h, sv_main.c, sv_phys.c:
modifed to use the new PR_SetEngineString and PR_GetString functions.
git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@38 af15c1b1-3010-417e-b628-4374ebc0bcbd
2010-02-17 15:04:50 +00:00
if ( j > 1 & & name [ j - 2 ] = = ' _ ' )
2010-02-15 23:26:55 +00:00
continue ; // skip _x, _y, _z vars
v = ( int * ) ( ( char * ) & ed - > v + d - > ofs * 4 ) ;
// if the value is still all 0, skip the field
type = d - > type & ~ DEF_SAVEGLOBAL ;
2011-12-12 08:56:25 +00:00
for ( j = 0 ; j < type_size [ type ] ; j + + )
{
2010-02-15 23:26:55 +00:00
if ( v [ j ] )
break ;
2011-12-12 08:56:25 +00:00
}
2010-02-15 23:26:55 +00:00
if ( j = = type_size [ type ] )
continue ;
2011-12-12 08:56:25 +00:00
fprintf ( f , " \" %s \" " , name ) ;
fprintf ( f , " \" %s \" \n " , PR_UglyValueString ( d - > type , ( eval_t * ) v ) ) ;
2010-02-15 23:26:55 +00:00
}
//johnfitz -- save entity alpha manually when progs.dat doesn't know about alpha
2018-05-01 00:35:14 +00:00
if ( qcvm - > extfields . alpha < 0 & & ed - > alpha ! = ENTALPHA_DEFAULT )
2011-12-12 08:56:25 +00:00
fprintf ( f , " \" alpha \" \" %f \" \n " , ENTALPHA_TOSAVE ( ed - > alpha ) ) ;
2010-02-15 23:26:55 +00:00
//johnfitz
fprintf ( f , " } \n " ) ;
}
void ED_PrintNum ( int ent )
{
ED_Print ( EDICT_NUM ( ent ) ) ;
}
/*
= = = = = = = = = = = = =
ED_PrintEdicts
For debugging , prints all the entities in the current server
= = = = = = = = = = = = =
*/
void ED_PrintEdicts ( void )
{
int i ;
2012-11-15 17:30:43 +00:00
if ( ! sv . active )
return ;
2018-05-01 00:35:14 +00:00
PR_SwitchQCVM ( & sv . qcvm ) ;
Con_Printf ( " %i entities \n " , qcvm - > num_edicts ) ;
for ( i = 0 ; i < qcvm - > num_edicts ; i + + )
2010-02-15 23:26:55 +00:00
ED_PrintNum ( i ) ;
2018-05-01 00:35:14 +00:00
PR_SwitchQCVM ( NULL ) ;
2010-02-15 23:26:55 +00:00
}
/*
= = = = = = = = = = = = =
ED_PrintEdict_f
For debugging , prints a single edicy
= = = = = = = = = = = = =
*/
2011-12-12 08:56:25 +00:00
static void ED_PrintEdict_f ( void )
2010-02-15 23:26:55 +00:00
{
int i ;
2012-11-15 17:30:43 +00:00
if ( ! sv . active )
return ;
2010-02-15 23:26:55 +00:00
i = Q_atoi ( Cmd_Argv ( 1 ) ) ;
2018-05-01 00:35:14 +00:00
PR_SwitchQCVM ( & sv . qcvm ) ;
if ( i < 0 | | i > = qcvm - > num_edicts )
2010-02-15 23:26:55 +00:00
Con_Printf ( " Bad edict number \n " ) ;
2018-05-01 00:35:14 +00:00
else
2020-04-06 23:54:29 +00:00
{
if ( Cmd_Argc ( ) = = 2 | | svs . maxclients ! = 1 ) //edict N
ED_PrintNum ( i ) ;
else //edict N FLD ...
{
ddef_t * def = ED_FindField ( Cmd_Argv ( 2 ) ) ;
if ( ! def )
Con_Printf ( " Field %s not defined \n " , Cmd_Argv ( 2 ) ) ;
else if ( Cmd_Argc ( ) < 4 )
Con_Printf ( " Edict %u.%s==%s \n " , i , PR_GetString ( def - > s_name ) , PR_UglyValueString ( def - > type & ~ DEF_SAVEGLOBAL , ( eval_t * ) ( ( char * ) & EDICT_NUM ( i ) - > v + def - > ofs * 4 ) ) ) ;
else
2020-07-19 00:47:06 +00:00
ED_ParseEpair ( ( void * ) & EDICT_NUM ( i ) - > v , def , Cmd_Argv ( 3 ) , false ) ;
2020-04-06 23:54:29 +00:00
}
}
2018-05-01 00:35:14 +00:00
PR_SwitchQCVM ( NULL ) ;
2010-02-15 23:26:55 +00:00
}
/*
= = = = = = = = = = = = =
ED_Count
For debugging
= = = = = = = = = = = = =
*/
2011-12-12 08:56:25 +00:00
static void ED_Count ( void )
2010-02-15 23:26:55 +00:00
{
edict_t * ent ;
2012-11-15 17:30:43 +00:00
int i , active , models , solid , step ;
if ( ! sv . active )
return ;
2010-02-15 23:26:55 +00:00
2018-05-01 00:35:14 +00:00
PR_SwitchQCVM ( & sv . qcvm ) ;
2010-02-15 23:26:55 +00:00
active = models = solid = step = 0 ;
2018-05-01 00:35:14 +00:00
for ( i = 0 ; i < qcvm - > num_edicts ; i + + )
2010-02-15 23:26:55 +00:00
{
ent = EDICT_NUM ( i ) ;
if ( ent - > free )
continue ;
active + + ;
if ( ent - > v . solid )
solid + + ;
if ( ent - > v . model )
models + + ;
if ( ent - > v . movetype = = MOVETYPE_STEP )
step + + ;
}
2018-05-01 00:35:14 +00:00
Con_Printf ( " num_edicts:%3i \n " , qcvm - > num_edicts ) ;
2010-02-15 23:26:55 +00:00
Con_Printf ( " active :%3i \n " , active ) ;
Con_Printf ( " view :%3i \n " , models ) ;
Con_Printf ( " touch :%3i \n " , solid ) ;
Con_Printf ( " step :%3i \n " , step ) ;
2018-05-01 00:35:14 +00:00
PR_SwitchQCVM ( NULL ) ;
2010-02-15 23:26:55 +00:00
}
2011-12-12 08:56:25 +00:00
2010-02-15 23:26:55 +00:00
/*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
2011-12-12 08:56:25 +00:00
ARCHIVING GLOBALS
2010-02-15 23:26:55 +00:00
FIXME : need to tag constants , doesn ' t really work
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
/*
= = = = = = = = = = = = =
ED_WriteGlobals
= = = = = = = = = = = = =
*/
void ED_WriteGlobals ( FILE * f )
{
ddef_t * def ;
int i ;
2010-08-29 02:22:55 +00:00
const char * name ;
2010-02-15 23:26:55 +00:00
int type ;
2011-12-12 08:56:25 +00:00
fprintf ( f , " { \n " ) ;
2018-05-01 00:35:14 +00:00
for ( i = 0 ; i < qcvm - > progs - > numglobaldefs ; i + + )
2010-02-15 23:26:55 +00:00
{
2018-05-01 00:35:14 +00:00
def = & qcvm - > globaldefs [ i ] ;
2010-02-15 23:26:55 +00:00
type = def - > type ;
if ( ! ( def - > type & DEF_SAVEGLOBAL ) )
continue ;
type & = ~ DEF_SAVEGLOBAL ;
2023-07-06 04:16:32 +00:00
if ( type ! = ev_string & & type ! = ev_float & & type ! = ev_ext_double & & type ! = ev_ext_integer & & type ! = ev_ext_uint32 & & type ! = ev_ext_sint64 & & type ! = ev_ext_uint64 & & type ! = ev_entity )
2010-02-15 23:26:55 +00:00
continue ;
64 bit compatibility effort, 4/nn: x86_64 works just fine now, yey!
the QuakeC interpreter used to use string pointer offsets from pr_strings
even when the pointers lead to engine data which is often well out of
32bit range on a 64bit architecture and they lead to crashes. they now
go through the new PR_SetEngineString and PR_GetString functions which
turn any address outside the pr_strings area into an index into a table
of engine string addresses, adding new string addresses to the table as
needed. the engine strings table is allocated with 256 entries at first
(see the PR_STRING_ALLOCSLOTS definition in pr_edict.c) and its size is
incremented by 256 as needed and re-allocated on the zone. managing that
allocation and reallocation is accomplished by the recently added Z_Realloc
function. implementation based on the uhexen2 (hexen2: hammer of thyrion)
engine which, in turn, is loosely based on twilight and quakeforge engines.
pr_strings range check is from tyrquake.
pr_edict.c: added the new PR_SetEngineString, PR_GetString, PR_AllocString
public functions and the new private PR_AllocStringSlots function. made
ED_NewString private to pr_edict.c and reworked it to return an index to a
newly allocated string.
progs.h: added prototypes for the new public PR_SetEngineString, PR_GetString
and PR_AllocString functions.
host_cmd.c, pr_cmds.c, pr_edict.c, pr_exec.c, progs.h, sv_main.c, sv_phys.c:
modifed to use the new PR_SetEngineString and PR_GetString functions.
git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@38 af15c1b1-3010-417e-b628-4374ebc0bcbd
2010-02-17 15:04:50 +00:00
name = PR_GetString ( def - > s_name ) ;
2011-12-12 08:56:25 +00:00
fprintf ( f , " \" %s \" " , name ) ;
2018-05-01 00:35:14 +00:00
fprintf ( f , " \" %s \" \n " , PR_UglyValueString ( type , ( eval_t * ) & qcvm - > globals [ def - > ofs ] ) ) ;
2010-02-15 23:26:55 +00:00
}
2011-12-12 08:56:25 +00:00
fprintf ( f , " } \n " ) ;
2010-02-15 23:26:55 +00:00
}
/*
= = = = = = = = = = = = =
ED_ParseGlobals
= = = = = = = = = = = = =
*/
2017-04-16 02:53:06 +00:00
const char * ED_ParseGlobals ( const char * data )
2010-02-15 23:26:55 +00:00
{
char keyname [ 64 ] ;
ddef_t * key ;
while ( 1 )
{
// parse key
data = COM_Parse ( data ) ;
if ( com_token [ 0 ] = = ' } ' )
break ;
if ( ! data )
2012-11-15 17:30:43 +00:00
Host_Error ( " ED_ParseEntity: EOF without closing brace " ) ;
2010-02-15 23:26:55 +00:00
2017-04-15 22:18:41 +00:00
q_strlcpy ( keyname , com_token , sizeof ( keyname ) ) ;
2010-02-15 23:26:55 +00:00
// parse value
data = COM_Parse ( data ) ;
if ( ! data )
2012-11-15 17:30:43 +00:00
Host_Error ( " ED_ParseEntity: EOF without closing brace " ) ;
2010-02-15 23:26:55 +00:00
if ( com_token [ 0 ] = = ' } ' )
2012-11-15 17:30:43 +00:00
Host_Error ( " ED_ParseEntity: closing brace without data " ) ;
2010-02-15 23:26:55 +00:00
key = ED_FindGlobal ( keyname ) ;
if ( ! key )
{
Con_Printf ( " '%s' is not a global \n " , keyname ) ;
continue ;
}
2020-07-19 00:47:06 +00:00
if ( ! ED_ParseEpair ( ( void * ) qcvm - > globals , key , com_token , false ) )
2010-02-15 23:26:55 +00:00
Host_Error ( " ED_ParseGlobals: parse error " ) ;
}
2017-04-16 02:53:06 +00:00
return data ;
2010-02-15 23:26:55 +00:00
}
//============================================================================
/*
= = = = = = = = = = = = =
ED_NewString
= = = = = = = = = = = = =
*/
64 bit compatibility effort, 4/nn: x86_64 works just fine now, yey!
the QuakeC interpreter used to use string pointer offsets from pr_strings
even when the pointers lead to engine data which is often well out of
32bit range on a 64bit architecture and they lead to crashes. they now
go through the new PR_SetEngineString and PR_GetString functions which
turn any address outside the pr_strings area into an index into a table
of engine string addresses, adding new string addresses to the table as
needed. the engine strings table is allocated with 256 entries at first
(see the PR_STRING_ALLOCSLOTS definition in pr_edict.c) and its size is
incremented by 256 as needed and re-allocated on the zone. managing that
allocation and reallocation is accomplished by the recently added Z_Realloc
function. implementation based on the uhexen2 (hexen2: hammer of thyrion)
engine which, in turn, is loosely based on twilight and quakeforge engines.
pr_strings range check is from tyrquake.
pr_edict.c: added the new PR_SetEngineString, PR_GetString, PR_AllocString
public functions and the new private PR_AllocStringSlots function. made
ED_NewString private to pr_edict.c and reworked it to return an index to a
newly allocated string.
progs.h: added prototypes for the new public PR_SetEngineString, PR_GetString
and PR_AllocString functions.
host_cmd.c, pr_cmds.c, pr_edict.c, pr_exec.c, progs.h, sv_main.c, sv_phys.c:
modifed to use the new PR_SetEngineString and PR_GetString functions.
git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@38 af15c1b1-3010-417e-b628-4374ebc0bcbd
2010-02-17 15:04:50 +00:00
static string_t ED_NewString ( const char * string )
2010-02-15 23:26:55 +00:00
{
64 bit compatibility effort, 4/nn: x86_64 works just fine now, yey!
the QuakeC interpreter used to use string pointer offsets from pr_strings
even when the pointers lead to engine data which is often well out of
32bit range on a 64bit architecture and they lead to crashes. they now
go through the new PR_SetEngineString and PR_GetString functions which
turn any address outside the pr_strings area into an index into a table
of engine string addresses, adding new string addresses to the table as
needed. the engine strings table is allocated with 256 entries at first
(see the PR_STRING_ALLOCSLOTS definition in pr_edict.c) and its size is
incremented by 256 as needed and re-allocated on the zone. managing that
allocation and reallocation is accomplished by the recently added Z_Realloc
function. implementation based on the uhexen2 (hexen2: hammer of thyrion)
engine which, in turn, is loosely based on twilight and quakeforge engines.
pr_strings range check is from tyrquake.
pr_edict.c: added the new PR_SetEngineString, PR_GetString, PR_AllocString
public functions and the new private PR_AllocStringSlots function. made
ED_NewString private to pr_edict.c and reworked it to return an index to a
newly allocated string.
progs.h: added prototypes for the new public PR_SetEngineString, PR_GetString
and PR_AllocString functions.
host_cmd.c, pr_cmds.c, pr_edict.c, pr_exec.c, progs.h, sv_main.c, sv_phys.c:
modifed to use the new PR_SetEngineString and PR_GetString functions.
git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@38 af15c1b1-3010-417e-b628-4374ebc0bcbd
2010-02-17 15:04:50 +00:00
char * new_p ;
int i , l ;
string_t num ;
2010-02-15 23:26:55 +00:00
l = strlen ( string ) + 1 ;
64 bit compatibility effort, 4/nn: x86_64 works just fine now, yey!
the QuakeC interpreter used to use string pointer offsets from pr_strings
even when the pointers lead to engine data which is often well out of
32bit range on a 64bit architecture and they lead to crashes. they now
go through the new PR_SetEngineString and PR_GetString functions which
turn any address outside the pr_strings area into an index into a table
of engine string addresses, adding new string addresses to the table as
needed. the engine strings table is allocated with 256 entries at first
(see the PR_STRING_ALLOCSLOTS definition in pr_edict.c) and its size is
incremented by 256 as needed and re-allocated on the zone. managing that
allocation and reallocation is accomplished by the recently added Z_Realloc
function. implementation based on the uhexen2 (hexen2: hammer of thyrion)
engine which, in turn, is loosely based on twilight and quakeforge engines.
pr_strings range check is from tyrquake.
pr_edict.c: added the new PR_SetEngineString, PR_GetString, PR_AllocString
public functions and the new private PR_AllocStringSlots function. made
ED_NewString private to pr_edict.c and reworked it to return an index to a
newly allocated string.
progs.h: added prototypes for the new public PR_SetEngineString, PR_GetString
and PR_AllocString functions.
host_cmd.c, pr_cmds.c, pr_edict.c, pr_exec.c, progs.h, sv_main.c, sv_phys.c:
modifed to use the new PR_SetEngineString and PR_GetString functions.
git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@38 af15c1b1-3010-417e-b628-4374ebc0bcbd
2010-02-17 15:04:50 +00:00
num = PR_AllocString ( l , & new_p ) ;
2010-02-15 23:26:55 +00:00
2011-12-12 08:56:25 +00:00
for ( i = 0 ; i < l ; i + + )
2010-02-15 23:26:55 +00:00
{
if ( string [ i ] = = ' \\ ' & & i < l - 1 )
{
i + + ;
if ( string [ i ] = = ' n ' )
* new_p + + = ' \n ' ;
else
* new_p + + = ' \\ ' ;
}
else
* new_p + + = string [ i ] ;
}
64 bit compatibility effort, 4/nn: x86_64 works just fine now, yey!
the QuakeC interpreter used to use string pointer offsets from pr_strings
even when the pointers lead to engine data which is often well out of
32bit range on a 64bit architecture and they lead to crashes. they now
go through the new PR_SetEngineString and PR_GetString functions which
turn any address outside the pr_strings area into an index into a table
of engine string addresses, adding new string addresses to the table as
needed. the engine strings table is allocated with 256 entries at first
(see the PR_STRING_ALLOCSLOTS definition in pr_edict.c) and its size is
incremented by 256 as needed and re-allocated on the zone. managing that
allocation and reallocation is accomplished by the recently added Z_Realloc
function. implementation based on the uhexen2 (hexen2: hammer of thyrion)
engine which, in turn, is loosely based on twilight and quakeforge engines.
pr_strings range check is from tyrquake.
pr_edict.c: added the new PR_SetEngineString, PR_GetString, PR_AllocString
public functions and the new private PR_AllocStringSlots function. made
ED_NewString private to pr_edict.c and reworked it to return an index to a
newly allocated string.
progs.h: added prototypes for the new public PR_SetEngineString, PR_GetString
and PR_AllocString functions.
host_cmd.c, pr_cmds.c, pr_edict.c, pr_exec.c, progs.h, sv_main.c, sv_phys.c:
modifed to use the new PR_SetEngineString and PR_GetString functions.
git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@38 af15c1b1-3010-417e-b628-4374ebc0bcbd
2010-02-17 15:04:50 +00:00
return num ;
2010-02-15 23:26:55 +00:00
}
2020-07-19 00:47:06 +00:00
static void ED_RezoneString ( string_t * ref , const char * str )
{
char * buf ;
size_t len = strlen ( str ) + 1 ;
size_t id ;
if ( * ref )
{ //if the reference is already a zoned string then free it first.
id = - 1 - * ref ;
if ( id < qcvm - > knownzonesize & & ( qcvm - > knownzone [ id > > 3 ] & ( 1u < < ( id & 7 ) ) ) )
{ //okay, it was zoned.
qcvm - > knownzone [ id > > 3 ] & = ~ ( 1u < < ( id & 7 ) ) ;
buf = ( char * ) PR_GetString ( * ref ) ;
PR_ClearEngineString ( * ref ) ;
Z_Free ( buf ) ;
}
// else
// Con_Warning("ED_RezoneString: string wasn't strzoned\n"); //warnings would trigger from the default cvar value that autocvars are initialised with
}
2010-02-15 23:26:55 +00:00
2020-07-19 00:47:06 +00:00
buf = Z_Malloc ( len ) ;
memcpy ( buf , str , len ) ;
id = - 1 - ( * ref = PR_SetEngineString ( buf ) ) ;
//make sure its flagged as zoned so we can clean up properly after.
if ( id > = qcvm - > knownzonesize )
{
qcvm - > knownzonesize = ( id + 32 ) & ~ 7 ;
qcvm - > knownzone = Z_Realloc ( qcvm - > knownzone , ( qcvm - > knownzonesize + 7 ) > > 3 ) ;
}
qcvm - > knownzone [ id > > 3 ] | = 1u < < ( id & 7 ) ;
}
2010-02-15 23:26:55 +00:00
/*
= = = = = = = = = = = = =
ED_ParseEval
Can parse either fields or globals
returns false if error
= = = = = = = = = = = = =
*/
2020-07-19 00:47:06 +00:00
qboolean ED_ParseEpair ( void * base , ddef_t * key , const char * s , qboolean zoned )
2010-02-15 23:26:55 +00:00
{
int i ;
char string [ 128 ] ;
ddef_t * def ;
char * v , * w ;
2017-11-07 21:49:32 +00:00
char * end ;
2010-02-15 23:26:55 +00:00
void * d ;
dfunction_t * func ;
d = ( void * ) ( ( int * ) base + key - > ofs ) ;
switch ( key - > type & ~ DEF_SAVEGLOBAL )
{
case ev_string :
2020-07-19 00:47:06 +00:00
if ( zoned ) //zoned version allows us to change the strings more freely
ED_RezoneString ( ( string_t * ) d , s ) ;
else
* ( string_t * ) d = ED_NewString ( s ) ;
2010-02-15 23:26:55 +00:00
break ;
case ev_float :
* ( float * ) d = atof ( s ) ;
break ;
2023-07-06 04:16:32 +00:00
case ev_ext_double :
* ( qcdouble_t * ) d = atof ( s ) ;
break ;
2017-09-17 02:12:53 +00:00
case ev_ext_integer :
2023-07-06 04:16:32 +00:00
* ( int32_t * ) d = atoi ( s ) ;
break ;
case ev_ext_uint32 :
* ( uint32_t * ) d = atoi ( s ) ;
break ;
case ev_ext_sint64 :
* ( qcsint64_t * ) d = strtoll ( s , NULL , 0 ) ; //if longlong is 128bit then no real harm done for 64bit quantities...
break ;
case ev_ext_uint64 :
* ( qcuint64_t * ) d = strtoull ( s , NULL , 0 ) ;
2017-09-17 02:12:53 +00:00
break ;
2010-02-15 23:26:55 +00:00
case ev_vector :
2018-05-30 15:01:22 +00:00
q_strlcpy ( string , s , sizeof ( string ) ) ;
2017-11-07 21:49:32 +00:00
end = ( char * ) string + strlen ( string ) ;
2010-02-15 23:26:55 +00:00
v = string ;
w = string ;
2017-11-10 05:55:04 +00:00
2017-11-07 21:49:32 +00:00
for ( i = 0 ; i < 3 & & ( w < = end ) ; i + + ) // ericw -- added (w <= end) check
2010-02-15 23:26:55 +00:00
{
2018-05-30 15:01:22 +00:00
// set v to the next space (or 0 byte), and change that char to a 0 byte
2010-02-15 23:26:55 +00:00
while ( * v & & * v ! = ' ' )
v + + ;
* v = 0 ;
( ( float * ) d ) [ i ] = atof ( w ) ;
w = v = v + 1 ;
}
2018-05-30 15:01:22 +00:00
// ericw -- fill remaining elements to 0 in case we hit the end of string
// before reading 3 floats.
2017-11-07 21:49:32 +00:00
if ( i < 3 )
{
2018-05-30 15:01:22 +00:00
Con_DWarning ( " Avoided reading garbage for \" %s \" \" %s \" \n " , PR_GetString ( key - > s_name ) , s ) ;
2017-11-07 21:49:32 +00:00
for ( ; i < 3 ; i + + )
( ( float * ) d ) [ i ] = 0.0f ;
}
2010-02-15 23:26:55 +00:00
break ;
case ev_entity :
2018-05-05 15:18:07 +00:00
if ( ! strncmp ( s , " entity " , 7 ) ) //Spike: putentityfieldstring/etc should be able to cope with etos's weirdness.
s + = 7 ;
2010-02-15 23:26:55 +00:00
* ( int * ) d = EDICT_TO_PROG ( EDICT_NUM ( atoi ( s ) ) ) ;
break ;
case ev_field :
def = ED_FindField ( s ) ;
if ( ! def )
{
//johnfitz -- HACK -- suppress error becuase fog/sky fields might not be mentioned in defs.qc
if ( strncmp ( s , " sky " , 3 ) & & strcmp ( s , " fog " ) )
Con_DPrintf ( " Can't find field %s \n " , s ) ;
return false ;
}
* ( int * ) d = G_INT ( def - > ofs ) ;
break ;
case ev_function :
func = ED_FindFunction ( s ) ;
if ( ! func )
{
Con_Printf ( " Can't find function %s \n " , s ) ;
return false ;
}
2018-05-01 00:35:14 +00:00
* ( func_t * ) d = func - qcvm - > functions ;
2010-02-15 23:26:55 +00:00
break ;
default :
break ;
}
return true ;
}
/*
= = = = = = = = = = = = = = = = = = = =
ED_ParseEdict
Parses an edict out of the given string , returning the new position
ed should be a properly initialized empty edict .
Used for initial level load and for savegames .
= = = = = = = = = = = = = = = = = = = =
*/
2010-08-29 02:22:55 +00:00
const char * ED_ParseEdict ( const char * data , edict_t * ent )
2010-02-15 23:26:55 +00:00
{
ddef_t * key ;
char keyname [ 256 ] ;
2012-11-15 17:30:43 +00:00
qboolean anglehack , init ;
int n ;
2010-02-15 23:26:55 +00:00
init = false ;
2011-12-12 08:56:25 +00:00
// clear it
2018-05-01 00:35:14 +00:00
if ( ent ! = qcvm - > edicts ) // hack
memset ( & ent - > v , 0 , qcvm - > progs - > entityfields * 4 ) ;
2010-02-15 23:26:55 +00:00
2011-12-12 08:56:25 +00:00
// go through all the dictionary pairs
2010-02-15 23:26:55 +00:00
while ( 1 )
{
2011-12-12 08:56:25 +00:00
// parse key
2010-02-15 23:26:55 +00:00
data = COM_Parse ( data ) ;
if ( com_token [ 0 ] = = ' } ' )
break ;
if ( ! data )
2012-11-15 17:30:43 +00:00
Host_Error ( " ED_ParseEntity: EOF without closing brace " ) ;
2010-02-15 23:26:55 +00:00
// anglehack is to allow QuakeEd to write single scalar angles
// and allow them to be turned into vectors. (FIXME...)
if ( ! strcmp ( com_token , " angle " ) )
{
strcpy ( com_token , " angles " ) ;
anglehack = true ;
}
else
anglehack = false ;
// FIXME: change light to _light to get rid of this hack
if ( ! strcmp ( com_token , " light " ) )
strcpy ( com_token , " light_lev " ) ; // hack for single light def
2018-05-30 15:01:22 +00:00
q_strlcpy ( keyname , com_token , sizeof ( keyname ) ) ;
2010-02-15 23:26:55 +00:00
// another hack to fix keynames with trailing spaces
n = strlen ( keyname ) ;
while ( n & & keyname [ n - 1 ] = = ' ' )
{
keyname [ n - 1 ] = 0 ;
n - - ;
}
// parse value
data = COM_Parse ( data ) ;
if ( ! data )
2012-11-15 17:30:43 +00:00
Host_Error ( " ED_ParseEntity: EOF without closing brace " ) ;
2010-02-15 23:26:55 +00:00
if ( com_token [ 0 ] = = ' } ' )
2012-11-15 17:30:43 +00:00
Host_Error ( " ED_ParseEntity: closing brace without data " ) ;
2010-02-15 23:26:55 +00:00
init = true ;
// keynames with a leading underscore are used for utility comments,
// and are immediately discarded by quake
if ( keyname [ 0 ] = = ' _ ' )
2017-09-17 02:12:53 +00:00
{
//spike -- hacks to support func_illusionary with all sorts of mdls, and various particle effects
2020-09-03 10:39:38 +00:00
if ( qcvm = = & sv . qcvm )
{
if ( ! strcmp ( keyname , " _precache_model " ) & & sv . state = = ss_loading )
SV_Precache_Model ( PR_GetString ( ED_NewString ( com_token ) ) ) ;
else if ( ! strcmp ( keyname , " _precache_sound " ) & & sv . state = = ss_loading )
SV_Precache_Sound ( PR_GetString ( ED_NewString ( com_token ) ) ) ;
}
2017-09-17 02:12:53 +00:00
//spike
2010-02-15 23:26:55 +00:00
continue ;
2017-09-17 02:12:53 +00:00
}
2010-02-15 23:26:55 +00:00
//johnfitz -- hack to support .alpha even when progs.dat doesn't know about it
if ( ! strcmp ( keyname , " alpha " ) )
2022-06-12 11:32:28 +00:00
ent - > alpha = ENTALPHA_ENCODE ( Q_atof ( com_token ) ) ;
2010-02-15 23:26:55 +00:00
//johnfitz
2017-09-17 02:12:53 +00:00
//spike -- hacks to support func_illusionary/info_notnull with all sorts of mdls, and various particle effects
2020-09-03 10:39:38 +00:00
if ( ! strcmp ( keyname , " modelindex " ) & & qcvm = = & sv . qcvm & & sv . state = = ss_loading )
2017-09-17 02:12:53 +00:00
{
//"model" "progs/foobar.mdl"
//"modelindex" "progs/foobar.mdl"
//"mins" "-16 -16 -16"
//"maxs" "16 16 16"
char * e ;
strtol ( com_token , & e , 0 ) ;
if ( e ! = com_token & & * e )
ent - > v . modelindex = SV_Precache_Model ( PR_GetString ( ED_NewString ( com_token ) ) ) ;
}
//spike
2010-02-15 23:26:55 +00:00
key = ED_FindField ( keyname ) ;
if ( ! key )
{
2017-09-17 02:12:53 +00:00
# ifdef PSET_SCRIPT
eval_t * val ;
2020-09-03 10:39:38 +00:00
if ( ! strcmp ( keyname , " traileffect " ) & & qcvm = = & sv . qcvm & & sv . state = = ss_loading )
2017-09-17 02:12:53 +00:00
{
2018-05-01 00:35:14 +00:00
if ( ( val = GetEdictFieldValue ( ent , qcvm - > extfields . traileffectnum ) ) )
2017-09-17 02:12:53 +00:00
val - > _float = PF_SV_ForceParticlePrecache ( com_token ) ;
}
2020-09-03 10:39:38 +00:00
else if ( ! strcmp ( keyname , " emiteffect " ) & & qcvm = = & sv . qcvm & & sv . state = = ss_loading )
2017-09-17 02:12:53 +00:00
{
2018-05-01 00:35:14 +00:00
if ( ( val = GetEdictFieldValue ( ent , qcvm - > extfields . emiteffectnum ) ) )
2017-09-17 02:12:53 +00:00
val - > _float = PF_SV_ForceParticlePrecache ( com_token ) ;
}
2010-02-15 23:26:55 +00:00
//johnfitz -- HACK -- suppress error becuase fog/sky/alpha fields might not be mentioned in defs.qc
2017-09-17 02:12:53 +00:00
else
# endif
if ( strncmp ( keyname , " sky " , 3 ) & & strcmp ( keyname , " fog " ) & & strcmp ( keyname , " alpha " ) )
2010-02-15 23:26:55 +00:00
Con_DPrintf ( " \" %s \" is not a field \n " , keyname ) ; //johnfitz -- was Con_Printf
continue ;
}
if ( anglehack )
{
char temp [ 32 ] ;
strcpy ( temp , com_token ) ;
sprintf ( com_token , " 0 %s 0 " , temp ) ;
}
2020-09-03 10:39:38 +00:00
if ( ! ED_ParseEpair ( ( void * ) & ent - > v , key , com_token , qcvm ! = & sv . qcvm ) )
2010-02-15 23:26:55 +00:00
Host_Error ( " ED_ParseEdict: parse error " ) ;
}
if ( ! init )
ent - > free = true ;
return data ;
}
/*
= = = = = = = = = = = = = = = =
ED_LoadFromFile
The entities are directly placed in the array , rather than allocated with
ED_Alloc , because otherwise an error loading the map would have entity
number references out of order .
Creates a server ' s entity / program execution context by
parsing textual entity definitions out of an ent file .
Used for both fresh maps and savegame loads . A fresh map would also need
to call ED_CallSpawnFunctions ( ) to let the objects initialize themselves .
= = = = = = = = = = = = = = = =
*/
2010-08-29 02:22:55 +00:00
void ED_LoadFromFile ( const char * data )
2010-02-15 23:26:55 +00:00
{
2011-12-12 08:56:25 +00:00
dfunction_t * func ;
64 bit compatibility effort, 4/nn: x86_64 works just fine now, yey!
the QuakeC interpreter used to use string pointer offsets from pr_strings
even when the pointers lead to engine data which is often well out of
32bit range on a 64bit architecture and they lead to crashes. they now
go through the new PR_SetEngineString and PR_GetString functions which
turn any address outside the pr_strings area into an index into a table
of engine string addresses, adding new string addresses to the table as
needed. the engine strings table is allocated with 256 entries at first
(see the PR_STRING_ALLOCSLOTS definition in pr_edict.c) and its size is
incremented by 256 as needed and re-allocated on the zone. managing that
allocation and reallocation is accomplished by the recently added Z_Realloc
function. implementation based on the uhexen2 (hexen2: hammer of thyrion)
engine which, in turn, is loosely based on twilight and quakeforge engines.
pr_strings range check is from tyrquake.
pr_edict.c: added the new PR_SetEngineString, PR_GetString, PR_AllocString
public functions and the new private PR_AllocStringSlots function. made
ED_NewString private to pr_edict.c and reworked it to return an index to a
newly allocated string.
progs.h: added prototypes for the new public PR_SetEngineString, PR_GetString
and PR_AllocString functions.
host_cmd.c, pr_cmds.c, pr_edict.c, pr_exec.c, progs.h, sv_main.c, sv_phys.c:
modifed to use the new PR_SetEngineString and PR_GetString functions.
git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@38 af15c1b1-3010-417e-b628-4374ebc0bcbd
2010-02-17 15:04:50 +00:00
edict_t * ent = NULL ;
int inhibit = 0 ;
2017-09-17 02:12:53 +00:00
int usingspawnfunc = 0 ;
2010-02-15 23:26:55 +00:00
2018-05-01 00:35:14 +00:00
pr_global_struct - > time = qcvm - > time ;
2010-02-15 23:26:55 +00:00
2011-12-12 08:56:25 +00:00
// parse ents
2010-02-15 23:26:55 +00:00
while ( 1 )
{
2011-12-12 08:56:25 +00:00
// parse the opening brace
2010-02-15 23:26:55 +00:00
data = COM_Parse ( data ) ;
if ( ! data )
break ;
if ( com_token [ 0 ] ! = ' { ' )
2012-11-15 17:30:43 +00:00
Host_Error ( " ED_LoadFromFile: found %s when expecting { " , com_token ) ;
2010-02-15 23:26:55 +00:00
if ( ! ent )
ent = EDICT_NUM ( 0 ) ;
else
ent = ED_Alloc ( ) ;
data = ED_ParseEdict ( data , ent ) ;
2011-12-12 08:56:25 +00:00
// remove things from different skill levels or deathmatch
2010-02-15 23:26:55 +00:00
if ( deathmatch . value )
{
if ( ( ( int ) ent - > v . spawnflags & SPAWNFLAG_NOT_DEATHMATCH ) )
{
ED_Free ( ent ) ;
inhibit + + ;
continue ;
}
}
else if ( ( current_skill = = 0 & & ( ( int ) ent - > v . spawnflags & SPAWNFLAG_NOT_EASY ) )
| | ( current_skill = = 1 & & ( ( int ) ent - > v . spawnflags & SPAWNFLAG_NOT_MEDIUM ) )
| | ( current_skill > = 2 & & ( ( int ) ent - > v . spawnflags & SPAWNFLAG_NOT_HARD ) ) )
{
ED_Free ( ent ) ;
inhibit + + ;
continue ;
}
//
// immediately call spawn function
//
if ( ! ent - > v . classname )
{
Con_SafePrintf ( " No classname for: \n " ) ; //johnfitz -- was Con_Printf
ED_Print ( ent ) ;
ED_Free ( ent ) ;
continue ;
}
// look for the spawn function
2017-09-17 02:12:53 +00:00
//
func = ED_FindFunction ( va ( " spawnfunc_%s " , PR_GetString ( ent - > v . classname ) ) ) ;
if ( func )
{
if ( ! usingspawnfunc + + )
Con_DPrintf2 ( " Using DP_SV_SPAWNFUNC_PREFIX \n " ) ;
}
else
func = ED_FindFunction ( PR_GetString ( ent - > v . classname ) ) ;
2010-02-15 23:26:55 +00:00
if ( ! func )
{
2017-09-17 02:12:53 +00:00
const char * classname = PR_GetString ( ent - > v . classname ) ;
if ( ! strcmp ( classname , " misc_model " ) )
PR_spawnfunc_misc_model ( ent ) ;
else
{
Con_SafePrintf ( " No spawn function for: \n " ) ; //johnfitz -- was Con_Printf
ED_Print ( ent ) ;
ED_Free ( ent ) ;
}
2010-02-15 23:26:55 +00:00
continue ;
}
pr_global_struct - > self = EDICT_TO_PROG ( ent ) ;
2018-05-01 00:35:14 +00:00
PR_ExecuteProgram ( func - qcvm - > functions ) ;
2010-02-15 23:26:55 +00:00
}
Con_DPrintf ( " %i entities inhibited \n " , inhibit ) ;
}
2018-05-01 00:35:14 +00:00
# ifndef PR_SwitchQCVM
qcvm_t * qcvm ;
globalvars_t * pr_global_struct ;
void PR_SwitchQCVM ( qcvm_t * nvm )
{
if ( qcvm & & nvm )
Sys_Error ( " PR_SwitchQCVM: A qcvm was already active " ) ;
qcvm = nvm ;
if ( qcvm )
pr_global_struct = ( globalvars_t * ) qcvm - > globals ;
else
pr_global_struct = NULL ;
}
# endif
void PR_ClearProgs ( qcvm_t * vm )
{
qcvm_t * oldvm = qcvm ;
if ( ! vm - > progs )
return ; //wasn't loaded.
qcvm = NULL ;
PR_SwitchQCVM ( vm ) ;
PR_ShutdownExtensions ( ) ;
if ( qcvm - > knownstrings )
Z_Free ( ( void * ) qcvm - > knownstrings ) ;
free ( qcvm - > edicts ) ; // ericw -- sv.edicts switched to use malloc()
2021-03-08 00:23:12 +00:00
if ( qcvm - > fielddefs ! = ( ddef_t * ) ( ( byte * ) qcvm - > progs + qcvm - > progs - > ofs_fielddefs ) )
free ( qcvm - > fielddefs ) ;
2020-07-02 19:05:51 +00:00
free ( qcvm - > progs ) ; // spike -- pr_progs switched to use malloc (so menuqc doesn't end up stuck on the early hunk nor wiped on every map change)
2018-05-01 00:35:14 +00:00
memset ( qcvm , 0 , sizeof ( * qcvm ) ) ;
qcvm = NULL ;
PR_SwitchQCVM ( oldvm ) ;
}
2021-03-08 00:23:12 +00:00
//makes sure extension fields are actually registered so they can be used for mappers without qc changes. eg so scale can be used.
static void PR_MergeEngineFieldDefs ( void )
{
struct {
const char * fname ;
etype_t type ;
int newidx ;
} extrafields [ ] =
{ //table of engine fields to add. we'll be using ED_FindFieldOffset for these later.
//this is useful for fields that should be defined for mappers which are not defined by the mod.
//future note: mutators will need to edit the mutator's globaldefs table too. remember to handle vectors and their 3 globals too.
{ " alpha " , ev_float } , //just because we can (though its already handled in a weird hacky way)
{ " scale " , ev_float } , //hurrah for being able to rescale entities.
{ " emiteffectnum " , ev_float } , //constantly emitting particles, even without moving.
{ " traileffectnum " , ev_float } , //custom effect for trails
//{"glow_size", ev_float}, //deprecated particle trail rubbish
//{"glow_color", ev_float}, //deprecated particle trail rubbish
{ " tag_entity " , ev_float } , //for setattachment to not bug out when omitted.
{ " tag_index " , ev_float } , //for setattachment to not bug out when omitted.
{ " modelflags " , ev_float } , //deprecated rubbish to fill the high 8 bits of effects.
//{"vw_index", ev_float}, //modelindex2
//{"pflags", ev_float}, //for rtlights
//{"drawflags", ev_float}, //hexen2 compat
//{"abslight", ev_float}, //hexen2 compat
{ " colormod " , ev_vector } , //lighting tints
//{"glowmod", ev_vector}, //fullbright tints
//{"fatness", ev_float}, //bloated rendering...
//{"gravitydir", ev_vector}, //says which direction gravity should act for this ent...
2023-07-22 16:40:33 +00:00
{ " pmove_flags " , ev_float } , //if runstandardplayerphysics is to work, it needs somewhere to track a couple of flags.
2021-03-08 00:23:12 +00:00
} ;
int maxofs = qcvm - > progs - > entityfields ;
int maxdefs = qcvm - > progs - > numfielddefs ;
unsigned int j , a ;
//figure out where stuff goes
for ( j = 0 ; j < countof ( extrafields ) ; j + + )
{
extrafields [ j ] . newidx = ED_FindFieldOffset ( extrafields [ j ] . fname ) ;
if ( extrafields [ j ] . newidx < 0 )
{
extrafields [ j ] . newidx = maxofs ;
maxdefs + + ;
if ( extrafields [ j ] . type = = ev_vector )
maxdefs + = 3 ;
maxofs + = type_size [ extrafields [ j ] . type ] ;
}
}
if ( maxdefs ! = qcvm - > progs - > numfielddefs )
{ //we now know how many entries we need to add...
ddef_t * olddefs = qcvm - > fielddefs ;
qcvm - > fielddefs = malloc ( maxdefs * sizeof ( * qcvm - > fielddefs ) ) ;
memcpy ( qcvm - > fielddefs , olddefs , qcvm - > progs - > numfielddefs * sizeof ( * qcvm - > fielddefs ) ) ;
if ( olddefs ! = ( ddef_t * ) ( ( byte * ) qcvm - > progs + qcvm - > progs - > ofs_fielddefs ) )
free ( olddefs ) ;
//allocate the extra defs
for ( j = 0 ; j < countof ( extrafields ) ; j + + )
{
if ( extrafields [ j ] . newidx > = qcvm - > progs - > entityfields & & extrafields [ j ] . newidx < maxofs )
{ //looks like its new. make sure ED_FindField can find it.
qcvm - > fielddefs [ qcvm - > progs - > numfielddefs ] . ofs = extrafields [ j ] . newidx ;
qcvm - > fielddefs [ qcvm - > progs - > numfielddefs ] . type = extrafields [ j ] . type ;
qcvm - > fielddefs [ qcvm - > progs - > numfielddefs ] . s_name = ED_NewString ( extrafields [ j ] . fname ) ;
qcvm - > progs - > numfielddefs + + ;
if ( extrafields [ j ] . type = = ev_vector )
{ //vectors are weird and annoying.
for ( a = 0 ; a < 3 ; a + + )
{
qcvm - > fielddefs [ qcvm - > progs - > numfielddefs ] . ofs = extrafields [ j ] . newidx + a ;
qcvm - > fielddefs [ qcvm - > progs - > numfielddefs ] . type = ev_float ;
qcvm - > fielddefs [ qcvm - > progs - > numfielddefs ] . s_name = ED_NewString ( va ( " %s_%c " , extrafields [ j ] . fname , ' x ' + a ) ) ;
qcvm - > progs - > numfielddefs + + ;
}
}
}
}
qcvm - > progs - > entityfields = maxofs ;
}
}
2010-02-15 23:26:55 +00:00
/*
= = = = = = = = = = = = = = =
PR_LoadProgs
= = = = = = = = = = = = = = =
*/
2022-07-15 12:24:04 +00:00
qboolean PR_LoadProgs ( const char * filename , qboolean fatal , unsigned int needcrc , const builtin_t * builtins , size_t numbuiltins )
2010-02-15 23:26:55 +00:00
{
2011-12-12 08:56:25 +00:00
int i ;
2010-02-15 23:26:55 +00:00
2018-05-01 00:35:14 +00:00
PR_ClearProgs ( qcvm ) ; //just in case.
2010-02-15 23:26:55 +00:00
2020-07-02 19:05:51 +00:00
qcvm - > progs = ( dprograms_t * ) COM_LoadMallocFile ( filename , NULL ) ;
2018-05-01 00:35:14 +00:00
if ( ! qcvm - > progs )
return false ;
2010-02-15 23:26:55 +00:00
2020-09-03 10:39:38 +00:00
qcvm - > progssize = com_filesize ;
CRC_Init ( & qcvm - > progscrc ) ;
2011-12-12 08:56:25 +00:00
for ( i = 0 ; i < com_filesize ; i + + )
2020-09-03 10:39:38 +00:00
CRC_ProcessByte ( & qcvm - > progscrc , ( ( byte * ) qcvm - > progs ) [ i ] ) ;
qcvm - > progshash = Com_BlockChecksum ( qcvm - > progs , com_filesize ) ;
2010-02-15 23:26:55 +00:00
2011-12-12 08:56:25 +00:00
// byte swap the header
2018-05-01 00:35:14 +00:00
for ( i = 0 ; i < ( int ) sizeof ( * qcvm - > progs ) / 4 ; i + + )
( ( int * ) qcvm - > progs ) [ i ] = LittleLong ( ( ( int * ) qcvm - > progs ) [ i ] ) ;
2011-12-12 08:56:25 +00:00
2018-05-01 00:35:14 +00:00
if ( qcvm - > progs - > version ! = PROG_VERSION )
{
if ( fatal )
Host_Error ( " %s has wrong version number (%i should be %i) " , filename , qcvm - > progs - > version , PROG_VERSION ) ;
else
{
2018-07-07 14:05:34 +00:00
Con_Printf ( " %s ABI set not supported \n " , filename ) ;
2018-05-01 00:35:14 +00:00
qcvm - > progs = NULL ;
return false ;
}
}
2020-07-02 19:05:51 +00:00
if ( qcvm - > progs - > crc ! = needcrc )
2018-05-01 00:35:14 +00:00
{
if ( fatal )
Host_Error ( " %s system vars have been modified, progdefs.h is out of date " , filename ) ;
else
{
2018-07-07 14:05:34 +00:00
switch ( qcvm - > progs - > crc )
{
case 22390 : //full csqc
Con_Printf ( " %s - full csqc is not supported \n " , filename ) ;
break ;
case 52195 : //dp csqc
Con_Printf ( " %s - obsolete csqc is not supported \n " , filename ) ;
break ;
case 54730 : //quakeworld
Con_Printf ( " %s - quakeworld gamecode is not supported \n " , filename ) ;
break ;
case 26940 : //prerelease
Con_Printf ( " %s - prerelease gamecode is not supported \n " , filename ) ;
break ;
case 32401 : //tenebrae
Con_Printf ( " %s - tenebrae gamecode is not supported \n " , filename ) ;
break ;
case 38488 : //hexen2 release
case 26905 : //hexen2 mission pack
case 14046 : //hexen2 demo
Con_Printf ( " %s - hexen2 gamecode is not supported \n " , filename ) ;
break ;
//case 5927: //nq PROGHEADER_CRC as above. shouldn't happen, obviously.
default :
Con_Printf ( " %s system vars are not supported \n " , filename ) ;
break ;
}
2018-05-01 00:35:14 +00:00
qcvm - > progs = NULL ;
return false ;
}
}
2021-07-10 19:13:56 +00:00
Con_DPrintf ( " %s occupies %uK. \n " , filename , ( unsigned ) ( com_filesize / 1024u ) ) ;
2018-05-01 00:35:14 +00:00
qcvm - > functions = ( dfunction_t * ) ( ( byte * ) qcvm - > progs + qcvm - > progs - > ofs_functions ) ;
qcvm - > strings = ( char * ) qcvm - > progs + qcvm - > progs - > ofs_strings ;
if ( qcvm - > progs - > ofs_strings + qcvm - > progs - > numstrings > = com_filesize )
Host_Error ( " %s strings go past end of file \n " , filename ) ;
qcvm - > globaldefs = ( ddef_t * ) ( ( byte * ) qcvm - > progs + qcvm - > progs - > ofs_globaldefs ) ;
qcvm - > fielddefs = ( ddef_t * ) ( ( byte * ) qcvm - > progs + qcvm - > progs - > ofs_fielddefs ) ;
qcvm - > statements = ( dstatement_t * ) ( ( byte * ) qcvm - > progs + qcvm - > progs - > ofs_statements ) ;
qcvm - > globals = ( float * ) ( ( byte * ) qcvm - > progs + qcvm - > progs - > ofs_globals ) ;
pr_global_struct = ( globalvars_t * ) qcvm - > globals ;
2010-02-15 23:26:55 +00:00
2018-05-01 00:35:14 +00:00
qcvm - > stringssize = qcvm - > progs - > numstrings ;
2010-02-15 23:26:55 +00:00
2011-12-12 08:56:25 +00:00
// byte swap the lumps
2018-05-01 00:35:14 +00:00
for ( i = 0 ; i < qcvm - > progs - > numstatements ; i + + )
2010-02-15 23:26:55 +00:00
{
2018-05-01 00:35:14 +00:00
qcvm - > statements [ i ] . op = LittleShort ( qcvm - > statements [ i ] . op ) ;
qcvm - > statements [ i ] . a = LittleShort ( qcvm - > statements [ i ] . a ) ;
qcvm - > statements [ i ] . b = LittleShort ( qcvm - > statements [ i ] . b ) ;
qcvm - > statements [ i ] . c = LittleShort ( qcvm - > statements [ i ] . c ) ;
2010-02-15 23:26:55 +00:00
}
2018-05-01 00:35:14 +00:00
for ( i = 0 ; i < qcvm - > progs - > numfunctions ; i + + )
2010-02-15 23:26:55 +00:00
{
2018-05-01 00:35:14 +00:00
qcvm - > functions [ i ] . first_statement = LittleLong ( qcvm - > functions [ i ] . first_statement ) ;
qcvm - > functions [ i ] . parm_start = LittleLong ( qcvm - > functions [ i ] . parm_start ) ;
qcvm - > functions [ i ] . s_name = LittleLong ( qcvm - > functions [ i ] . s_name ) ;
qcvm - > functions [ i ] . s_file = LittleLong ( qcvm - > functions [ i ] . s_file ) ;
qcvm - > functions [ i ] . numparms = LittleLong ( qcvm - > functions [ i ] . numparms ) ;
qcvm - > functions [ i ] . locals = LittleLong ( qcvm - > functions [ i ] . locals ) ;
2010-02-15 23:26:55 +00:00
}
2018-05-01 00:35:14 +00:00
for ( i = 0 ; i < qcvm - > progs - > numglobaldefs ; i + + )
2010-02-15 23:26:55 +00:00
{
2018-05-01 00:35:14 +00:00
qcvm - > globaldefs [ i ] . type = LittleShort ( qcvm - > globaldefs [ i ] . type ) ;
qcvm - > globaldefs [ i ] . ofs = LittleShort ( qcvm - > globaldefs [ i ] . ofs ) ;
qcvm - > globaldefs [ i ] . s_name = LittleLong ( qcvm - > globaldefs [ i ] . s_name ) ;
2010-02-15 23:26:55 +00:00
}
2018-05-01 00:35:14 +00:00
for ( i = 0 ; i < qcvm - > progs - > numfielddefs ; i + + )
2010-02-15 23:26:55 +00:00
{
2018-05-01 00:35:14 +00:00
qcvm - > fielddefs [ i ] . type = LittleShort ( qcvm - > fielddefs [ i ] . type ) ;
if ( qcvm - > fielddefs [ i ] . type & DEF_SAVEGLOBAL )
2012-11-15 17:30:43 +00:00
Host_Error ( " PR_LoadProgs: pr_fielddefs[i].type & DEF_SAVEGLOBAL " ) ;
2018-05-01 00:35:14 +00:00
qcvm - > fielddefs [ i ] . ofs = LittleShort ( qcvm - > fielddefs [ i ] . ofs ) ;
qcvm - > fielddefs [ i ] . s_name = LittleLong ( qcvm - > fielddefs [ i ] . s_name ) ;
2010-02-15 23:26:55 +00:00
}
2018-05-01 00:35:14 +00:00
for ( i = 0 ; i < qcvm - > progs - > numglobals ; i + + )
( ( int * ) qcvm - > globals ) [ i ] = LittleLong ( ( ( int * ) qcvm - > globals ) [ i ] ) ;
memcpy ( qcvm - > builtins , builtins , numbuiltins * sizeof ( qcvm - > builtins [ 0 ] ) ) ;
qcvm - > numbuiltins = numbuiltins ;
64 bit compatibility effort, 4/nn: x86_64 works just fine now, yey!
the QuakeC interpreter used to use string pointer offsets from pr_strings
even when the pointers lead to engine data which is often well out of
32bit range on a 64bit architecture and they lead to crashes. they now
go through the new PR_SetEngineString and PR_GetString functions which
turn any address outside the pr_strings area into an index into a table
of engine string addresses, adding new string addresses to the table as
needed. the engine strings table is allocated with 256 entries at first
(see the PR_STRING_ALLOCSLOTS definition in pr_edict.c) and its size is
incremented by 256 as needed and re-allocated on the zone. managing that
allocation and reallocation is accomplished by the recently added Z_Realloc
function. implementation based on the uhexen2 (hexen2: hammer of thyrion)
engine which, in turn, is loosely based on twilight and quakeforge engines.
pr_strings range check is from tyrquake.
pr_edict.c: added the new PR_SetEngineString, PR_GetString, PR_AllocString
public functions and the new private PR_AllocStringSlots function. made
ED_NewString private to pr_edict.c and reworked it to return an index to a
newly allocated string.
progs.h: added prototypes for the new public PR_SetEngineString, PR_GetString
and PR_AllocString functions.
host_cmd.c, pr_cmds.c, pr_edict.c, pr_exec.c, progs.h, sv_main.c, sv_phys.c:
modifed to use the new PR_SetEngineString and PR_GetString functions.
git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@38 af15c1b1-3010-417e-b628-4374ebc0bcbd
2010-02-17 15:04:50 +00:00
2017-09-17 02:12:53 +00:00
//spike: detect extended fields from progs
2021-03-08 00:23:12 +00:00
PR_MergeEngineFieldDefs ( ) ;
2020-09-03 10:08:13 +00:00
# define QCEXTFIELD(n,t) qcvm->extfields.n = ED_FindFieldOffset(#n);
QCEXTFIELDS_ALL
QCEXTFIELDS_GAME
QCEXTFIELDS_CL
QCEXTFIELDS_CS
QCEXTFIELDS_SS
# undef QCEXTFIELD
2018-05-01 00:35:14 +00:00
2021-03-08 00:23:12 +00:00
qcvm - > edict_size = qcvm - > progs - > entityfields * 4 + sizeof ( edict_t ) - sizeof ( entvars_t ) ;
64 bit compatibility effort, 4/nn: x86_64 works just fine now, yey!
the QuakeC interpreter used to use string pointer offsets from pr_strings
even when the pointers lead to engine data which is often well out of
32bit range on a 64bit architecture and they lead to crashes. they now
go through the new PR_SetEngineString and PR_GetString functions which
turn any address outside the pr_strings area into an index into a table
of engine string addresses, adding new string addresses to the table as
needed. the engine strings table is allocated with 256 entries at first
(see the PR_STRING_ALLOCSLOTS definition in pr_edict.c) and its size is
incremented by 256 as needed and re-allocated on the zone. managing that
allocation and reallocation is accomplished by the recently added Z_Realloc
function. implementation based on the uhexen2 (hexen2: hammer of thyrion)
engine which, in turn, is loosely based on twilight and quakeforge engines.
pr_strings range check is from tyrquake.
pr_edict.c: added the new PR_SetEngineString, PR_GetString, PR_AllocString
public functions and the new private PR_AllocStringSlots function. made
ED_NewString private to pr_edict.c and reworked it to return an index to a
newly allocated string.
progs.h: added prototypes for the new public PR_SetEngineString, PR_GetString
and PR_AllocString functions.
host_cmd.c, pr_cmds.c, pr_edict.c, pr_exec.c, progs.h, sv_main.c, sv_phys.c:
modifed to use the new PR_SetEngineString and PR_GetString functions.
git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@38 af15c1b1-3010-417e-b628-4374ebc0bcbd
2010-02-17 15:04:50 +00:00
// round off to next highest whole word address (esp for Alpha)
// this ensures that pointers in the engine data area are always
// properly aligned
2018-05-01 00:35:14 +00:00
qcvm - > edict_size + = sizeof ( void * ) - 1 ;
qcvm - > edict_size & = ~ ( sizeof ( void * ) - 1 ) ;
PR_SetEngineString ( " " ) ;
PR_EnableExtensions ( qcvm - > globaldefs ) ;
2017-09-17 02:12:53 +00:00
2018-05-01 00:35:14 +00:00
return true ;
2010-02-15 23:26:55 +00:00
}
/*
= = = = = = = = = = = = = = =
PR_Init
= = = = = = = = = = = = = = =
*/
void PR_Init ( void )
{
Cmd_AddCommand ( " edict " , ED_PrintEdict_f ) ;
Cmd_AddCommand ( " edicts " , ED_PrintEdicts ) ;
Cmd_AddCommand ( " edictcount " , ED_Count ) ;
Cmd_AddCommand ( " profile " , PR_Profile_f ) ;
2017-09-17 02:12:53 +00:00
Cmd_AddCommand ( " pr_dumpplatform " , PR_DumpPlatform_f ) ;
2011-12-28 22:01:33 +00:00
Cvar_RegisterVariable ( & nomonsters ) ;
Cvar_RegisterVariable ( & gamecfg ) ;
Cvar_RegisterVariable ( & scratch1 ) ;
Cvar_RegisterVariable ( & scratch2 ) ;
Cvar_RegisterVariable ( & scratch3 ) ;
Cvar_RegisterVariable ( & scratch4 ) ;
Cvar_RegisterVariable ( & savedgamecfg ) ;
Cvar_RegisterVariable ( & saved1 ) ;
Cvar_RegisterVariable ( & saved2 ) ;
Cvar_RegisterVariable ( & saved3 ) ;
Cvar_RegisterVariable ( & saved4 ) ;
2018-05-01 00:35:14 +00:00
PR_InitExtensions ( ) ;
2010-02-15 23:26:55 +00:00
}
edict_t * EDICT_NUM ( int n )
{
2018-05-01 00:35:14 +00:00
if ( n < 0 | | n > = qcvm - > max_edicts )
2012-11-15 17:30:43 +00:00
Host_Error ( " EDICT_NUM: bad number %i " , n ) ;
2018-05-01 00:35:14 +00:00
return ( edict_t * ) ( ( byte * ) qcvm - > edicts + ( n ) * qcvm - > edict_size ) ;
2010-02-15 23:26:55 +00:00
}
int NUM_FOR_EDICT ( edict_t * e )
{
int b ;
2018-05-01 00:35:14 +00:00
b = ( byte * ) e - ( byte * ) qcvm - > edicts ;
b = b / qcvm - > edict_size ;
2010-02-15 23:26:55 +00:00
2018-05-01 00:35:14 +00:00
if ( b < 0 | | b > = qcvm - > num_edicts )
2012-11-15 17:30:43 +00:00
Host_Error ( " NUM_FOR_EDICT: bad pointer " ) ;
2010-02-15 23:26:55 +00:00
return b ;
}
64 bit compatibility effort, 4/nn: x86_64 works just fine now, yey!
the QuakeC interpreter used to use string pointer offsets from pr_strings
even when the pointers lead to engine data which is often well out of
32bit range on a 64bit architecture and they lead to crashes. they now
go through the new PR_SetEngineString and PR_GetString functions which
turn any address outside the pr_strings area into an index into a table
of engine string addresses, adding new string addresses to the table as
needed. the engine strings table is allocated with 256 entries at first
(see the PR_STRING_ALLOCSLOTS definition in pr_edict.c) and its size is
incremented by 256 as needed and re-allocated on the zone. managing that
allocation and reallocation is accomplished by the recently added Z_Realloc
function. implementation based on the uhexen2 (hexen2: hammer of thyrion)
engine which, in turn, is loosely based on twilight and quakeforge engines.
pr_strings range check is from tyrquake.
pr_edict.c: added the new PR_SetEngineString, PR_GetString, PR_AllocString
public functions and the new private PR_AllocStringSlots function. made
ED_NewString private to pr_edict.c and reworked it to return an index to a
newly allocated string.
progs.h: added prototypes for the new public PR_SetEngineString, PR_GetString
and PR_AllocString functions.
host_cmd.c, pr_cmds.c, pr_edict.c, pr_exec.c, progs.h, sv_main.c, sv_phys.c:
modifed to use the new PR_SetEngineString and PR_GetString functions.
git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@38 af15c1b1-3010-417e-b628-4374ebc0bcbd
2010-02-17 15:04:50 +00:00
//===========================================================================
2011-12-12 08:56:25 +00:00
64 bit compatibility effort, 4/nn: x86_64 works just fine now, yey!
the QuakeC interpreter used to use string pointer offsets from pr_strings
even when the pointers lead to engine data which is often well out of
32bit range on a 64bit architecture and they lead to crashes. they now
go through the new PR_SetEngineString and PR_GetString functions which
turn any address outside the pr_strings area into an index into a table
of engine string addresses, adding new string addresses to the table as
needed. the engine strings table is allocated with 256 entries at first
(see the PR_STRING_ALLOCSLOTS definition in pr_edict.c) and its size is
incremented by 256 as needed and re-allocated on the zone. managing that
allocation and reallocation is accomplished by the recently added Z_Realloc
function. implementation based on the uhexen2 (hexen2: hammer of thyrion)
engine which, in turn, is loosely based on twilight and quakeforge engines.
pr_strings range check is from tyrquake.
pr_edict.c: added the new PR_SetEngineString, PR_GetString, PR_AllocString
public functions and the new private PR_AllocStringSlots function. made
ED_NewString private to pr_edict.c and reworked it to return an index to a
newly allocated string.
progs.h: added prototypes for the new public PR_SetEngineString, PR_GetString
and PR_AllocString functions.
host_cmd.c, pr_cmds.c, pr_edict.c, pr_exec.c, progs.h, sv_main.c, sv_phys.c:
modifed to use the new PR_SetEngineString and PR_GetString functions.
git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@38 af15c1b1-3010-417e-b628-4374ebc0bcbd
2010-02-17 15:04:50 +00:00
# define PR_STRING_ALLOCSLOTS 256
static void PR_AllocStringSlots ( void )
{
2018-05-01 00:35:14 +00:00
qcvm - > maxknownstrings + = PR_STRING_ALLOCSLOTS ;
Con_DPrintf2 ( " PR_AllocStringSlots: realloc'ing for %d slots \n " , qcvm - > maxknownstrings ) ;
qcvm - > knownstrings = ( const char * * ) Z_Realloc ( ( void * ) qcvm - > knownstrings , qcvm - > maxknownstrings * sizeof ( char * ) ) ;
64 bit compatibility effort, 4/nn: x86_64 works just fine now, yey!
the QuakeC interpreter used to use string pointer offsets from pr_strings
even when the pointers lead to engine data which is often well out of
32bit range on a 64bit architecture and they lead to crashes. they now
go through the new PR_SetEngineString and PR_GetString functions which
turn any address outside the pr_strings area into an index into a table
of engine string addresses, adding new string addresses to the table as
needed. the engine strings table is allocated with 256 entries at first
(see the PR_STRING_ALLOCSLOTS definition in pr_edict.c) and its size is
incremented by 256 as needed and re-allocated on the zone. managing that
allocation and reallocation is accomplished by the recently added Z_Realloc
function. implementation based on the uhexen2 (hexen2: hammer of thyrion)
engine which, in turn, is loosely based on twilight and quakeforge engines.
pr_strings range check is from tyrquake.
pr_edict.c: added the new PR_SetEngineString, PR_GetString, PR_AllocString
public functions and the new private PR_AllocStringSlots function. made
ED_NewString private to pr_edict.c and reworked it to return an index to a
newly allocated string.
progs.h: added prototypes for the new public PR_SetEngineString, PR_GetString
and PR_AllocString functions.
host_cmd.c, pr_cmds.c, pr_edict.c, pr_exec.c, progs.h, sv_main.c, sv_phys.c:
modifed to use the new PR_SetEngineString and PR_GetString functions.
git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@38 af15c1b1-3010-417e-b628-4374ebc0bcbd
2010-02-17 15:04:50 +00:00
}
2010-08-29 02:22:55 +00:00
const char * PR_GetString ( int num )
64 bit compatibility effort, 4/nn: x86_64 works just fine now, yey!
the QuakeC interpreter used to use string pointer offsets from pr_strings
even when the pointers lead to engine data which is often well out of
32bit range on a 64bit architecture and they lead to crashes. they now
go through the new PR_SetEngineString and PR_GetString functions which
turn any address outside the pr_strings area into an index into a table
of engine string addresses, adding new string addresses to the table as
needed. the engine strings table is allocated with 256 entries at first
(see the PR_STRING_ALLOCSLOTS definition in pr_edict.c) and its size is
incremented by 256 as needed and re-allocated on the zone. managing that
allocation and reallocation is accomplished by the recently added Z_Realloc
function. implementation based on the uhexen2 (hexen2: hammer of thyrion)
engine which, in turn, is loosely based on twilight and quakeforge engines.
pr_strings range check is from tyrquake.
pr_edict.c: added the new PR_SetEngineString, PR_GetString, PR_AllocString
public functions and the new private PR_AllocStringSlots function. made
ED_NewString private to pr_edict.c and reworked it to return an index to a
newly allocated string.
progs.h: added prototypes for the new public PR_SetEngineString, PR_GetString
and PR_AllocString functions.
host_cmd.c, pr_cmds.c, pr_edict.c, pr_exec.c, progs.h, sv_main.c, sv_phys.c:
modifed to use the new PR_SetEngineString and PR_GetString functions.
git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@38 af15c1b1-3010-417e-b628-4374ebc0bcbd
2010-02-17 15:04:50 +00:00
{
2018-05-01 00:35:14 +00:00
if ( num > = 0 & & num < qcvm - > stringssize )
return qcvm - > strings + num ;
else if ( num < 0 & & num > = - qcvm - > numknownstrings )
64 bit compatibility effort, 4/nn: x86_64 works just fine now, yey!
the QuakeC interpreter used to use string pointer offsets from pr_strings
even when the pointers lead to engine data which is often well out of
32bit range on a 64bit architecture and they lead to crashes. they now
go through the new PR_SetEngineString and PR_GetString functions which
turn any address outside the pr_strings area into an index into a table
of engine string addresses, adding new string addresses to the table as
needed. the engine strings table is allocated with 256 entries at first
(see the PR_STRING_ALLOCSLOTS definition in pr_edict.c) and its size is
incremented by 256 as needed and re-allocated on the zone. managing that
allocation and reallocation is accomplished by the recently added Z_Realloc
function. implementation based on the uhexen2 (hexen2: hammer of thyrion)
engine which, in turn, is loosely based on twilight and quakeforge engines.
pr_strings range check is from tyrquake.
pr_edict.c: added the new PR_SetEngineString, PR_GetString, PR_AllocString
public functions and the new private PR_AllocStringSlots function. made
ED_NewString private to pr_edict.c and reworked it to return an index to a
newly allocated string.
progs.h: added prototypes for the new public PR_SetEngineString, PR_GetString
and PR_AllocString functions.
host_cmd.c, pr_cmds.c, pr_edict.c, pr_exec.c, progs.h, sv_main.c, sv_phys.c:
modifed to use the new PR_SetEngineString and PR_GetString functions.
git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@38 af15c1b1-3010-417e-b628-4374ebc0bcbd
2010-02-17 15:04:50 +00:00
{
2018-05-01 00:35:14 +00:00
if ( ! qcvm - > knownstrings [ - 1 - num ] )
64 bit compatibility effort, 4/nn: x86_64 works just fine now, yey!
the QuakeC interpreter used to use string pointer offsets from pr_strings
even when the pointers lead to engine data which is often well out of
32bit range on a 64bit architecture and they lead to crashes. they now
go through the new PR_SetEngineString and PR_GetString functions which
turn any address outside the pr_strings area into an index into a table
of engine string addresses, adding new string addresses to the table as
needed. the engine strings table is allocated with 256 entries at first
(see the PR_STRING_ALLOCSLOTS definition in pr_edict.c) and its size is
incremented by 256 as needed and re-allocated on the zone. managing that
allocation and reallocation is accomplished by the recently added Z_Realloc
function. implementation based on the uhexen2 (hexen2: hammer of thyrion)
engine which, in turn, is loosely based on twilight and quakeforge engines.
pr_strings range check is from tyrquake.
pr_edict.c: added the new PR_SetEngineString, PR_GetString, PR_AllocString
public functions and the new private PR_AllocStringSlots function. made
ED_NewString private to pr_edict.c and reworked it to return an index to a
newly allocated string.
progs.h: added prototypes for the new public PR_SetEngineString, PR_GetString
and PR_AllocString functions.
host_cmd.c, pr_cmds.c, pr_edict.c, pr_exec.c, progs.h, sv_main.c, sv_phys.c:
modifed to use the new PR_SetEngineString and PR_GetString functions.
git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@38 af15c1b1-3010-417e-b628-4374ebc0bcbd
2010-02-17 15:04:50 +00:00
{
Host_Error ( " PR_GetString: attempt to get a non-existant string %d \n " , num ) ;
return " " ;
}
2018-05-01 00:35:14 +00:00
return qcvm - > knownstrings [ - 1 - num ] ;
64 bit compatibility effort, 4/nn: x86_64 works just fine now, yey!
the QuakeC interpreter used to use string pointer offsets from pr_strings
even when the pointers lead to engine data which is often well out of
32bit range on a 64bit architecture and they lead to crashes. they now
go through the new PR_SetEngineString and PR_GetString functions which
turn any address outside the pr_strings area into an index into a table
of engine string addresses, adding new string addresses to the table as
needed. the engine strings table is allocated with 256 entries at first
(see the PR_STRING_ALLOCSLOTS definition in pr_edict.c) and its size is
incremented by 256 as needed and re-allocated on the zone. managing that
allocation and reallocation is accomplished by the recently added Z_Realloc
function. implementation based on the uhexen2 (hexen2: hammer of thyrion)
engine which, in turn, is loosely based on twilight and quakeforge engines.
pr_strings range check is from tyrquake.
pr_edict.c: added the new PR_SetEngineString, PR_GetString, PR_AllocString
public functions and the new private PR_AllocStringSlots function. made
ED_NewString private to pr_edict.c and reworked it to return an index to a
newly allocated string.
progs.h: added prototypes for the new public PR_SetEngineString, PR_GetString
and PR_AllocString functions.
host_cmd.c, pr_cmds.c, pr_edict.c, pr_exec.c, progs.h, sv_main.c, sv_phys.c:
modifed to use the new PR_SetEngineString and PR_GetString functions.
git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@38 af15c1b1-3010-417e-b628-4374ebc0bcbd
2010-02-17 15:04:50 +00:00
}
else
{
2018-05-01 00:35:14 +00:00
return qcvm - > strings ;
64 bit compatibility effort, 4/nn: x86_64 works just fine now, yey!
the QuakeC interpreter used to use string pointer offsets from pr_strings
even when the pointers lead to engine data which is often well out of
32bit range on a 64bit architecture and they lead to crashes. they now
go through the new PR_SetEngineString and PR_GetString functions which
turn any address outside the pr_strings area into an index into a table
of engine string addresses, adding new string addresses to the table as
needed. the engine strings table is allocated with 256 entries at first
(see the PR_STRING_ALLOCSLOTS definition in pr_edict.c) and its size is
incremented by 256 as needed and re-allocated on the zone. managing that
allocation and reallocation is accomplished by the recently added Z_Realloc
function. implementation based on the uhexen2 (hexen2: hammer of thyrion)
engine which, in turn, is loosely based on twilight and quakeforge engines.
pr_strings range check is from tyrquake.
pr_edict.c: added the new PR_SetEngineString, PR_GetString, PR_AllocString
public functions and the new private PR_AllocStringSlots function. made
ED_NewString private to pr_edict.c and reworked it to return an index to a
newly allocated string.
progs.h: added prototypes for the new public PR_SetEngineString, PR_GetString
and PR_AllocString functions.
host_cmd.c, pr_cmds.c, pr_edict.c, pr_exec.c, progs.h, sv_main.c, sv_phys.c:
modifed to use the new PR_SetEngineString and PR_GetString functions.
git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@38 af15c1b1-3010-417e-b628-4374ebc0bcbd
2010-02-17 15:04:50 +00:00
Host_Error ( " PR_GetString: invalid string offset %d \n " , num ) ;
return " " ;
}
}
2017-09-17 02:12:53 +00:00
void PR_ClearEngineString ( int num )
{
2018-05-01 00:35:14 +00:00
if ( num < 0 & & num > = - qcvm - > numknownstrings )
2017-09-17 02:12:53 +00:00
{
num = - 1 - num ;
2018-05-01 00:35:14 +00:00
qcvm - > knownstrings [ num ] = NULL ;
if ( qcvm - > freeknownstrings > num )
qcvm - > freeknownstrings = num ;
2017-09-17 02:12:53 +00:00
}
}
2010-08-29 02:22:55 +00:00
int PR_SetEngineString ( const char * s )
64 bit compatibility effort, 4/nn: x86_64 works just fine now, yey!
the QuakeC interpreter used to use string pointer offsets from pr_strings
even when the pointers lead to engine data which is often well out of
32bit range on a 64bit architecture and they lead to crashes. they now
go through the new PR_SetEngineString and PR_GetString functions which
turn any address outside the pr_strings area into an index into a table
of engine string addresses, adding new string addresses to the table as
needed. the engine strings table is allocated with 256 entries at first
(see the PR_STRING_ALLOCSLOTS definition in pr_edict.c) and its size is
incremented by 256 as needed and re-allocated on the zone. managing that
allocation and reallocation is accomplished by the recently added Z_Realloc
function. implementation based on the uhexen2 (hexen2: hammer of thyrion)
engine which, in turn, is loosely based on twilight and quakeforge engines.
pr_strings range check is from tyrquake.
pr_edict.c: added the new PR_SetEngineString, PR_GetString, PR_AllocString
public functions and the new private PR_AllocStringSlots function. made
ED_NewString private to pr_edict.c and reworked it to return an index to a
newly allocated string.
progs.h: added prototypes for the new public PR_SetEngineString, PR_GetString
and PR_AllocString functions.
host_cmd.c, pr_cmds.c, pr_edict.c, pr_exec.c, progs.h, sv_main.c, sv_phys.c:
modifed to use the new PR_SetEngineString and PR_GetString functions.
git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@38 af15c1b1-3010-417e-b628-4374ebc0bcbd
2010-02-17 15:04:50 +00:00
{
int i ;
if ( ! s )
return 0 ;
#if 0 /* can't: sv.model_precache & sv.sound_precache points to pr_strings */
2018-05-01 00:35:14 +00:00
if ( s > = qcvm - > strings & & s < = qcvm - > strings + qcvm - > stringssize )
64 bit compatibility effort, 4/nn: x86_64 works just fine now, yey!
the QuakeC interpreter used to use string pointer offsets from pr_strings
even when the pointers lead to engine data which is often well out of
32bit range on a 64bit architecture and they lead to crashes. they now
go through the new PR_SetEngineString and PR_GetString functions which
turn any address outside the pr_strings area into an index into a table
of engine string addresses, adding new string addresses to the table as
needed. the engine strings table is allocated with 256 entries at first
(see the PR_STRING_ALLOCSLOTS definition in pr_edict.c) and its size is
incremented by 256 as needed and re-allocated on the zone. managing that
allocation and reallocation is accomplished by the recently added Z_Realloc
function. implementation based on the uhexen2 (hexen2: hammer of thyrion)
engine which, in turn, is loosely based on twilight and quakeforge engines.
pr_strings range check is from tyrquake.
pr_edict.c: added the new PR_SetEngineString, PR_GetString, PR_AllocString
public functions and the new private PR_AllocStringSlots function. made
ED_NewString private to pr_edict.c and reworked it to return an index to a
newly allocated string.
progs.h: added prototypes for the new public PR_SetEngineString, PR_GetString
and PR_AllocString functions.
host_cmd.c, pr_cmds.c, pr_edict.c, pr_exec.c, progs.h, sv_main.c, sv_phys.c:
modifed to use the new PR_SetEngineString and PR_GetString functions.
git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@38 af15c1b1-3010-417e-b628-4374ebc0bcbd
2010-02-17 15:04:50 +00:00
Host_Error ( " PR_SetEngineString: \" %s \" in pr_strings area \n " , s ) ;
# else
2018-05-01 00:35:14 +00:00
if ( s > = qcvm - > strings & & s < = qcvm - > strings + qcvm - > stringssize - 2 )
return ( int ) ( s - qcvm - > strings ) ;
64 bit compatibility effort, 4/nn: x86_64 works just fine now, yey!
the QuakeC interpreter used to use string pointer offsets from pr_strings
even when the pointers lead to engine data which is often well out of
32bit range on a 64bit architecture and they lead to crashes. they now
go through the new PR_SetEngineString and PR_GetString functions which
turn any address outside the pr_strings area into an index into a table
of engine string addresses, adding new string addresses to the table as
needed. the engine strings table is allocated with 256 entries at first
(see the PR_STRING_ALLOCSLOTS definition in pr_edict.c) and its size is
incremented by 256 as needed and re-allocated on the zone. managing that
allocation and reallocation is accomplished by the recently added Z_Realloc
function. implementation based on the uhexen2 (hexen2: hammer of thyrion)
engine which, in turn, is loosely based on twilight and quakeforge engines.
pr_strings range check is from tyrquake.
pr_edict.c: added the new PR_SetEngineString, PR_GetString, PR_AllocString
public functions and the new private PR_AllocStringSlots function. made
ED_NewString private to pr_edict.c and reworked it to return an index to a
newly allocated string.
progs.h: added prototypes for the new public PR_SetEngineString, PR_GetString
and PR_AllocString functions.
host_cmd.c, pr_cmds.c, pr_edict.c, pr_exec.c, progs.h, sv_main.c, sv_phys.c:
modifed to use the new PR_SetEngineString and PR_GetString functions.
git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@38 af15c1b1-3010-417e-b628-4374ebc0bcbd
2010-02-17 15:04:50 +00:00
# endif
2018-05-01 00:35:14 +00:00
for ( i = 0 ; i < qcvm - > numknownstrings ; i + + )
64 bit compatibility effort, 4/nn: x86_64 works just fine now, yey!
the QuakeC interpreter used to use string pointer offsets from pr_strings
even when the pointers lead to engine data which is often well out of
32bit range on a 64bit architecture and they lead to crashes. they now
go through the new PR_SetEngineString and PR_GetString functions which
turn any address outside the pr_strings area into an index into a table
of engine string addresses, adding new string addresses to the table as
needed. the engine strings table is allocated with 256 entries at first
(see the PR_STRING_ALLOCSLOTS definition in pr_edict.c) and its size is
incremented by 256 as needed and re-allocated on the zone. managing that
allocation and reallocation is accomplished by the recently added Z_Realloc
function. implementation based on the uhexen2 (hexen2: hammer of thyrion)
engine which, in turn, is loosely based on twilight and quakeforge engines.
pr_strings range check is from tyrquake.
pr_edict.c: added the new PR_SetEngineString, PR_GetString, PR_AllocString
public functions and the new private PR_AllocStringSlots function. made
ED_NewString private to pr_edict.c and reworked it to return an index to a
newly allocated string.
progs.h: added prototypes for the new public PR_SetEngineString, PR_GetString
and PR_AllocString functions.
host_cmd.c, pr_cmds.c, pr_edict.c, pr_exec.c, progs.h, sv_main.c, sv_phys.c:
modifed to use the new PR_SetEngineString and PR_GetString functions.
git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@38 af15c1b1-3010-417e-b628-4374ebc0bcbd
2010-02-17 15:04:50 +00:00
{
2018-05-01 00:35:14 +00:00
if ( qcvm - > knownstrings [ i ] = = s )
64 bit compatibility effort, 4/nn: x86_64 works just fine now, yey!
the QuakeC interpreter used to use string pointer offsets from pr_strings
even when the pointers lead to engine data which is often well out of
32bit range on a 64bit architecture and they lead to crashes. they now
go through the new PR_SetEngineString and PR_GetString functions which
turn any address outside the pr_strings area into an index into a table
of engine string addresses, adding new string addresses to the table as
needed. the engine strings table is allocated with 256 entries at first
(see the PR_STRING_ALLOCSLOTS definition in pr_edict.c) and its size is
incremented by 256 as needed and re-allocated on the zone. managing that
allocation and reallocation is accomplished by the recently added Z_Realloc
function. implementation based on the uhexen2 (hexen2: hammer of thyrion)
engine which, in turn, is loosely based on twilight and quakeforge engines.
pr_strings range check is from tyrquake.
pr_edict.c: added the new PR_SetEngineString, PR_GetString, PR_AllocString
public functions and the new private PR_AllocStringSlots function. made
ED_NewString private to pr_edict.c and reworked it to return an index to a
newly allocated string.
progs.h: added prototypes for the new public PR_SetEngineString, PR_GetString
and PR_AllocString functions.
host_cmd.c, pr_cmds.c, pr_edict.c, pr_exec.c, progs.h, sv_main.c, sv_phys.c:
modifed to use the new PR_SetEngineString and PR_GetString functions.
git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@38 af15c1b1-3010-417e-b628-4374ebc0bcbd
2010-02-17 15:04:50 +00:00
return - 1 - i ;
}
// new unknown engine string
//Con_DPrintf ("PR_SetEngineString: new engine string %p\n", s);
2018-05-01 00:35:14 +00:00
for ( i = qcvm - > freeknownstrings ; ; i + + )
64 bit compatibility effort, 4/nn: x86_64 works just fine now, yey!
the QuakeC interpreter used to use string pointer offsets from pr_strings
even when the pointers lead to engine data which is often well out of
32bit range on a 64bit architecture and they lead to crashes. they now
go through the new PR_SetEngineString and PR_GetString functions which
turn any address outside the pr_strings area into an index into a table
of engine string addresses, adding new string addresses to the table as
needed. the engine strings table is allocated with 256 entries at first
(see the PR_STRING_ALLOCSLOTS definition in pr_edict.c) and its size is
incremented by 256 as needed and re-allocated on the zone. managing that
allocation and reallocation is accomplished by the recently added Z_Realloc
function. implementation based on the uhexen2 (hexen2: hammer of thyrion)
engine which, in turn, is loosely based on twilight and quakeforge engines.
pr_strings range check is from tyrquake.
pr_edict.c: added the new PR_SetEngineString, PR_GetString, PR_AllocString
public functions and the new private PR_AllocStringSlots function. made
ED_NewString private to pr_edict.c and reworked it to return an index to a
newly allocated string.
progs.h: added prototypes for the new public PR_SetEngineString, PR_GetString
and PR_AllocString functions.
host_cmd.c, pr_cmds.c, pr_edict.c, pr_exec.c, progs.h, sv_main.c, sv_phys.c:
modifed to use the new PR_SetEngineString and PR_GetString functions.
git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@38 af15c1b1-3010-417e-b628-4374ebc0bcbd
2010-02-17 15:04:50 +00:00
{
2018-05-01 00:35:14 +00:00
if ( i < qcvm - > numknownstrings )
2017-09-17 02:12:53 +00:00
{
2018-05-01 00:35:14 +00:00
if ( qcvm - > knownstrings [ i ] )
2017-09-17 02:12:53 +00:00
continue ;
}
else
{
2018-05-01 00:35:14 +00:00
if ( i > = qcvm - > maxknownstrings )
2017-09-17 02:12:53 +00:00
PR_AllocStringSlots ( ) ;
2018-05-01 00:35:14 +00:00
qcvm - > numknownstrings + + ;
2017-09-17 02:12:53 +00:00
}
break ;
64 bit compatibility effort, 4/nn: x86_64 works just fine now, yey!
the QuakeC interpreter used to use string pointer offsets from pr_strings
even when the pointers lead to engine data which is often well out of
32bit range on a 64bit architecture and they lead to crashes. they now
go through the new PR_SetEngineString and PR_GetString functions which
turn any address outside the pr_strings area into an index into a table
of engine string addresses, adding new string addresses to the table as
needed. the engine strings table is allocated with 256 entries at first
(see the PR_STRING_ALLOCSLOTS definition in pr_edict.c) and its size is
incremented by 256 as needed and re-allocated on the zone. managing that
allocation and reallocation is accomplished by the recently added Z_Realloc
function. implementation based on the uhexen2 (hexen2: hammer of thyrion)
engine which, in turn, is loosely based on twilight and quakeforge engines.
pr_strings range check is from tyrquake.
pr_edict.c: added the new PR_SetEngineString, PR_GetString, PR_AllocString
public functions and the new private PR_AllocStringSlots function. made
ED_NewString private to pr_edict.c and reworked it to return an index to a
newly allocated string.
progs.h: added prototypes for the new public PR_SetEngineString, PR_GetString
and PR_AllocString functions.
host_cmd.c, pr_cmds.c, pr_edict.c, pr_exec.c, progs.h, sv_main.c, sv_phys.c:
modifed to use the new PR_SetEngineString and PR_GetString functions.
git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@38 af15c1b1-3010-417e-b628-4374ebc0bcbd
2010-02-17 15:04:50 +00:00
}
2018-05-01 00:35:14 +00:00
qcvm - > freeknownstrings = i + 1 ;
qcvm - > knownstrings [ i ] = s ;
64 bit compatibility effort, 4/nn: x86_64 works just fine now, yey!
the QuakeC interpreter used to use string pointer offsets from pr_strings
even when the pointers lead to engine data which is often well out of
32bit range on a 64bit architecture and they lead to crashes. they now
go through the new PR_SetEngineString and PR_GetString functions which
turn any address outside the pr_strings area into an index into a table
of engine string addresses, adding new string addresses to the table as
needed. the engine strings table is allocated with 256 entries at first
(see the PR_STRING_ALLOCSLOTS definition in pr_edict.c) and its size is
incremented by 256 as needed and re-allocated on the zone. managing that
allocation and reallocation is accomplished by the recently added Z_Realloc
function. implementation based on the uhexen2 (hexen2: hammer of thyrion)
engine which, in turn, is loosely based on twilight and quakeforge engines.
pr_strings range check is from tyrquake.
pr_edict.c: added the new PR_SetEngineString, PR_GetString, PR_AllocString
public functions and the new private PR_AllocStringSlots function. made
ED_NewString private to pr_edict.c and reworked it to return an index to a
newly allocated string.
progs.h: added prototypes for the new public PR_SetEngineString, PR_GetString
and PR_AllocString functions.
host_cmd.c, pr_cmds.c, pr_edict.c, pr_exec.c, progs.h, sv_main.c, sv_phys.c:
modifed to use the new PR_SetEngineString and PR_GetString functions.
git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@38 af15c1b1-3010-417e-b628-4374ebc0bcbd
2010-02-17 15:04:50 +00:00
return - 1 - i ;
}
int PR_AllocString ( int size , char * * ptr )
{
int i ;
if ( ! size )
return 0 ;
2018-05-01 00:35:14 +00:00
for ( i = 0 ; i < qcvm - > numknownstrings ; i + + )
64 bit compatibility effort, 4/nn: x86_64 works just fine now, yey!
the QuakeC interpreter used to use string pointer offsets from pr_strings
even when the pointers lead to engine data which is often well out of
32bit range on a 64bit architecture and they lead to crashes. they now
go through the new PR_SetEngineString and PR_GetString functions which
turn any address outside the pr_strings area into an index into a table
of engine string addresses, adding new string addresses to the table as
needed. the engine strings table is allocated with 256 entries at first
(see the PR_STRING_ALLOCSLOTS definition in pr_edict.c) and its size is
incremented by 256 as needed and re-allocated on the zone. managing that
allocation and reallocation is accomplished by the recently added Z_Realloc
function. implementation based on the uhexen2 (hexen2: hammer of thyrion)
engine which, in turn, is loosely based on twilight and quakeforge engines.
pr_strings range check is from tyrquake.
pr_edict.c: added the new PR_SetEngineString, PR_GetString, PR_AllocString
public functions and the new private PR_AllocStringSlots function. made
ED_NewString private to pr_edict.c and reworked it to return an index to a
newly allocated string.
progs.h: added prototypes for the new public PR_SetEngineString, PR_GetString
and PR_AllocString functions.
host_cmd.c, pr_cmds.c, pr_edict.c, pr_exec.c, progs.h, sv_main.c, sv_phys.c:
modifed to use the new PR_SetEngineString and PR_GetString functions.
git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@38 af15c1b1-3010-417e-b628-4374ebc0bcbd
2010-02-17 15:04:50 +00:00
{
2018-05-01 00:35:14 +00:00
if ( ! qcvm - > knownstrings [ i ] )
64 bit compatibility effort, 4/nn: x86_64 works just fine now, yey!
the QuakeC interpreter used to use string pointer offsets from pr_strings
even when the pointers lead to engine data which is often well out of
32bit range on a 64bit architecture and they lead to crashes. they now
go through the new PR_SetEngineString and PR_GetString functions which
turn any address outside the pr_strings area into an index into a table
of engine string addresses, adding new string addresses to the table as
needed. the engine strings table is allocated with 256 entries at first
(see the PR_STRING_ALLOCSLOTS definition in pr_edict.c) and its size is
incremented by 256 as needed and re-allocated on the zone. managing that
allocation and reallocation is accomplished by the recently added Z_Realloc
function. implementation based on the uhexen2 (hexen2: hammer of thyrion)
engine which, in turn, is loosely based on twilight and quakeforge engines.
pr_strings range check is from tyrquake.
pr_edict.c: added the new PR_SetEngineString, PR_GetString, PR_AllocString
public functions and the new private PR_AllocStringSlots function. made
ED_NewString private to pr_edict.c and reworked it to return an index to a
newly allocated string.
progs.h: added prototypes for the new public PR_SetEngineString, PR_GetString
and PR_AllocString functions.
host_cmd.c, pr_cmds.c, pr_edict.c, pr_exec.c, progs.h, sv_main.c, sv_phys.c:
modifed to use the new PR_SetEngineString and PR_GetString functions.
git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@38 af15c1b1-3010-417e-b628-4374ebc0bcbd
2010-02-17 15:04:50 +00:00
break ;
}
// if (i >= pr_numknownstrings)
// {
2018-05-01 00:35:14 +00:00
if ( i > = qcvm - > maxknownstrings )
64 bit compatibility effort, 4/nn: x86_64 works just fine now, yey!
the QuakeC interpreter used to use string pointer offsets from pr_strings
even when the pointers lead to engine data which is often well out of
32bit range on a 64bit architecture and they lead to crashes. they now
go through the new PR_SetEngineString and PR_GetString functions which
turn any address outside the pr_strings area into an index into a table
of engine string addresses, adding new string addresses to the table as
needed. the engine strings table is allocated with 256 entries at first
(see the PR_STRING_ALLOCSLOTS definition in pr_edict.c) and its size is
incremented by 256 as needed and re-allocated on the zone. managing that
allocation and reallocation is accomplished by the recently added Z_Realloc
function. implementation based on the uhexen2 (hexen2: hammer of thyrion)
engine which, in turn, is loosely based on twilight and quakeforge engines.
pr_strings range check is from tyrquake.
pr_edict.c: added the new PR_SetEngineString, PR_GetString, PR_AllocString
public functions and the new private PR_AllocStringSlots function. made
ED_NewString private to pr_edict.c and reworked it to return an index to a
newly allocated string.
progs.h: added prototypes for the new public PR_SetEngineString, PR_GetString
and PR_AllocString functions.
host_cmd.c, pr_cmds.c, pr_edict.c, pr_exec.c, progs.h, sv_main.c, sv_phys.c:
modifed to use the new PR_SetEngineString and PR_GetString functions.
git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@38 af15c1b1-3010-417e-b628-4374ebc0bcbd
2010-02-17 15:04:50 +00:00
PR_AllocStringSlots ( ) ;
2018-05-01 00:35:14 +00:00
qcvm - > numknownstrings + + ;
64 bit compatibility effort, 4/nn: x86_64 works just fine now, yey!
the QuakeC interpreter used to use string pointer offsets from pr_strings
even when the pointers lead to engine data which is often well out of
32bit range on a 64bit architecture and they lead to crashes. they now
go through the new PR_SetEngineString and PR_GetString functions which
turn any address outside the pr_strings area into an index into a table
of engine string addresses, adding new string addresses to the table as
needed. the engine strings table is allocated with 256 entries at first
(see the PR_STRING_ALLOCSLOTS definition in pr_edict.c) and its size is
incremented by 256 as needed and re-allocated on the zone. managing that
allocation and reallocation is accomplished by the recently added Z_Realloc
function. implementation based on the uhexen2 (hexen2: hammer of thyrion)
engine which, in turn, is loosely based on twilight and quakeforge engines.
pr_strings range check is from tyrquake.
pr_edict.c: added the new PR_SetEngineString, PR_GetString, PR_AllocString
public functions and the new private PR_AllocStringSlots function. made
ED_NewString private to pr_edict.c and reworked it to return an index to a
newly allocated string.
progs.h: added prototypes for the new public PR_SetEngineString, PR_GetString
and PR_AllocString functions.
host_cmd.c, pr_cmds.c, pr_edict.c, pr_exec.c, progs.h, sv_main.c, sv_phys.c:
modifed to use the new PR_SetEngineString and PR_GetString functions.
git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@38 af15c1b1-3010-417e-b628-4374ebc0bcbd
2010-02-17 15:04:50 +00:00
// }
2018-05-01 00:35:14 +00:00
qcvm - > knownstrings [ i ] = ( char * ) Hunk_AllocName ( size , " string " ) ;
64 bit compatibility effort, 4/nn: x86_64 works just fine now, yey!
the QuakeC interpreter used to use string pointer offsets from pr_strings
even when the pointers lead to engine data which is often well out of
32bit range on a 64bit architecture and they lead to crashes. they now
go through the new PR_SetEngineString and PR_GetString functions which
turn any address outside the pr_strings area into an index into a table
of engine string addresses, adding new string addresses to the table as
needed. the engine strings table is allocated with 256 entries at first
(see the PR_STRING_ALLOCSLOTS definition in pr_edict.c) and its size is
incremented by 256 as needed and re-allocated on the zone. managing that
allocation and reallocation is accomplished by the recently added Z_Realloc
function. implementation based on the uhexen2 (hexen2: hammer of thyrion)
engine which, in turn, is loosely based on twilight and quakeforge engines.
pr_strings range check is from tyrquake.
pr_edict.c: added the new PR_SetEngineString, PR_GetString, PR_AllocString
public functions and the new private PR_AllocStringSlots function. made
ED_NewString private to pr_edict.c and reworked it to return an index to a
newly allocated string.
progs.h: added prototypes for the new public PR_SetEngineString, PR_GetString
and PR_AllocString functions.
host_cmd.c, pr_cmds.c, pr_edict.c, pr_exec.c, progs.h, sv_main.c, sv_phys.c:
modifed to use the new PR_SetEngineString and PR_GetString functions.
git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@38 af15c1b1-3010-417e-b628-4374ebc0bcbd
2010-02-17 15:04:50 +00:00
if ( ptr )
2018-05-01 00:35:14 +00:00
* ptr = ( char * ) qcvm - > knownstrings [ i ] ;
64 bit compatibility effort, 4/nn: x86_64 works just fine now, yey!
the QuakeC interpreter used to use string pointer offsets from pr_strings
even when the pointers lead to engine data which is often well out of
32bit range on a 64bit architecture and they lead to crashes. they now
go through the new PR_SetEngineString and PR_GetString functions which
turn any address outside the pr_strings area into an index into a table
of engine string addresses, adding new string addresses to the table as
needed. the engine strings table is allocated with 256 entries at first
(see the PR_STRING_ALLOCSLOTS definition in pr_edict.c) and its size is
incremented by 256 as needed and re-allocated on the zone. managing that
allocation and reallocation is accomplished by the recently added Z_Realloc
function. implementation based on the uhexen2 (hexen2: hammer of thyrion)
engine which, in turn, is loosely based on twilight and quakeforge engines.
pr_strings range check is from tyrquake.
pr_edict.c: added the new PR_SetEngineString, PR_GetString, PR_AllocString
public functions and the new private PR_AllocStringSlots function. made
ED_NewString private to pr_edict.c and reworked it to return an index to a
newly allocated string.
progs.h: added prototypes for the new public PR_SetEngineString, PR_GetString
and PR_AllocString functions.
host_cmd.c, pr_cmds.c, pr_edict.c, pr_exec.c, progs.h, sv_main.c, sv_phys.c:
modifed to use the new PR_SetEngineString and PR_GetString functions.
git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@38 af15c1b1-3010-417e-b628-4374ebc0bcbd
2010-02-17 15:04:50 +00:00
return - 1 - i ;
}