Skip to content

Commit

Permalink
Scr_AddEntity was using server entities list (very bad)
Browse files Browse the repository at this point in the history
  • Loading branch information
BraXi committed Sep 12, 2024
1 parent 14155a6 commit ca4c923
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 38 deletions.
2 changes: 1 addition & 1 deletion src/engine/client/cgame/cg_entities.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ static void CG_CallSpawnForEntity(clentity_t* ent)

// find spawn fuction in progs
sprintf(spawnFuncName, "SP_%s", classname);
spawnfunc = Scr_FindFunction(spawnFuncName);
spawnfunc = Scr_FindFunctionIndex(spawnFuncName);
if (spawnfunc == -1 && ent != cg.localEntities)
{
// Com_DPrintf(DP_CGAME, "%s: unknown classname '%s'\n", __FUNCTION__, classname);
Expand Down
7 changes: 3 additions & 4 deletions src/engine/script/qcvm_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ qboolean Scr_ParseEpair(void* base, ddef_t* key, char* s, int memtag)
break;

case ev_function:
func = Scr_FindFunction(s);
func = Scr_FindFunctionIndex(s);
if (func == -1)
{
Com_Error(ERR_FATAL, "Can't find function %s\n", s);
Expand Down Expand Up @@ -210,12 +210,11 @@ ddef_t* Scr_FindGlobal(char* name)

/*
============
Scr_FindFunction
Scr_FindFunctionIndex
Finds a function with specified name in active qcvm or NULL if not found
============
*/
dfunction_t* ScrInternal_FindFunction(char* name)
dfunction_t* Scr_FindFunction(const char* name)
{
dfunction_t* func;
int i;
Expand Down
6 changes: 4 additions & 2 deletions src/engine/script/qcvm_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,10 @@ extern int scr_numBuiltins;
extern qcvm_t *active_qcvm;
extern const qcvmdef_t vmDefs[NUM_SCRIPT_VMS];

extern void Scr_InitSharedBuiltins();
extern void CheckScriptVM(const char* func);
void Scr_InitSharedBuiltins();
void CheckScriptVM(const char* func);

dfunction_t* Scr_FindFunction(const char* name);


#define G_INT(o) (*(int32_t *)&active_qcvm->globals[o])
Expand Down
58 changes: 29 additions & 29 deletions src/engine/script/qcvm_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,22 @@ Copyright (C) 1997-2001 Id Software, Inc.
See the attached GNU General Public License v2 for more details.
*/
// scr_utils.c


#include "../server/server.h"
#include "qcvm_private.h"

// number of temporary strings for Scr_VarString()
#define NUM_TEMP_VARSTRINGS 12

// current temp string in Scr_VarString()
static int qcvm_vstr = 0;


/*
============
Scr_DefineBuiltin
Adds new builtin method
Adds new builtin function
============
*/
void Scr_DefineBuiltin(void (*function)(void), pb_t type, char* fname, char* qcstring)
Expand All @@ -32,7 +35,7 @@ void Scr_DefineBuiltin(void (*function)(void), pb_t type, char* fname, char* qcs
}

if (scr_numBuiltins == (SCRIPTVM_MAXBUILTINS - 1))
Com_Error(ERR_FATAL, "increase pr_maxbuiltins (%i)\n", SCRIPTVM_MAXBUILTINS);
Com_Error(ERR_FATAL, "Too manu builtins, increase SCRIPTVM_MAXBUILTINS\n");

func = &scr_builtins[scr_numBuiltins];
func->execon = type;
Expand All @@ -42,23 +45,24 @@ void Scr_DefineBuiltin(void (*function)(void), pb_t type, char* fname, char* qcs
scr_numBuiltins++;
}

dfunction_t* ScrInternal_FindFunction(char* name);


/*
============
Scr_FindFunction
Finds function in progs and returns its number (for execution), returns -1 when not found
Scr_FindFunctionIndex
Finds function in progs and returns its number (for execution), returns -1 when function was not found.
============
*/
scr_func_t Scr_FindFunction(char* funcname)
scr_func_t Scr_FindFunctionIndex(const char* funcname)
{
dfunction_t* f = NULL;

if (!funcname)
if (!funcname || !funcname[0])
{
return -1;

if((f = ScrInternal_FindFunction(funcname)) != NULL)
}

if((f = Scr_FindFunction(funcname)) != NULL)
return (scr_func_t)(f - active_qcvm->functions);

return -1;
Expand All @@ -67,20 +71,18 @@ scr_func_t Scr_FindFunction(char* funcname)
/*
============
Scr_GetString
Returns string from script
Returns string from program
============
*/
char* Scr_GetString(int32_t str)
char* Scr_GetString(int str)
{
return active_qcvm->strings + str;
}

/*
============
Scr_SetString
Sets string in script
Sets string in program
============
*/
int Scr_SetString(char* str)
Expand All @@ -91,45 +93,43 @@ int Scr_SetString(char* str)
/*
============
ScrInternal_GetParmOffset
Returns the correct offset for param number
============
*/
static int ScrInternal_GetParmOffset(unsigned int parm)
{
int ofs = OFS_PARM0 + (parm * 3);

if (ofs > OFS_PARM7 )//|| parm < OFS_PARM0)
Com_Error(ERR_FATAL, "ScrInternal_GetParmOffset: parm %i is out of range [0,7]\n", parm);

return ofs;
}

#define TEMP_VARSTRINGS 8
static int vstr = 0;

/*
============
Scr_VarString
============
*/
char* Scr_VarString(int first)
{
static char out[TEMP_VARSTRINGS][256];
static char out[NUM_TEMP_VARSTRINGS][256];
int i, param;

vstr++;
if (vstr >= TEMP_VARSTRINGS)
vstr = 0;
qcvm_vstr++;
if (qcvm_vstr >= NUM_TEMP_VARSTRINGS)
qcvm_vstr = 0;

out[vstr][0] = 0;
out[qcvm_vstr][0] = 0;

for (i = first; i < Scr_NumArgs(); i++)
{
param = ScrInternal_GetParmOffset(i);
strcat(out[vstr], G_STRING(param));
strcat(out[qcvm_vstr], G_STRING(param));
}


return out[vstr];
return out[qcvm_vstr];
}

/*
Expand Down Expand Up @@ -300,7 +300,7 @@ Add entity to call args
void Scr_AddEntity(unsigned int parm, vm_entity_t* ed)
{
int ofs = ScrInternal_GetParmOffset(parm);
G_INT(ofs) = GENT_TO_PROG(ed);
G_INT(ofs) = ENT_TO_VM(ed);
}


Expand Down
2 changes: 1 addition & 1 deletion src/engine/script/scriptvm.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ eval_t* Scr_GetEntityFieldValue(vm_entity_t* ent, char* field); // FIXME

void Scr_DefineBuiltin(void (*function)(void), pb_t type, char* fname, char* qcstring);

scr_func_t Scr_FindFunction(char* funcname);
scr_func_t Scr_FindFunctionIndex(const char* funcname);

int Scr_SetString(char* str);

Expand Down
2 changes: 1 addition & 1 deletion src/engine/server/sv_gentity.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ void SV_CallSpawnForEntity(gentity_t* ent)

// find spawn fuction in progs
sprintf(spawnFuncName, "SP_%s", classname);
spawnfunc = Scr_FindFunction(spawnFuncName);
spawnfunc = Scr_FindFunctionIndex(spawnFuncName);
if (spawnfunc == -1 && ent != sv.edicts)
{
Com_DPrintf( DP_SV, "SV_CallSpawnForEntity: unknown classname '%s'\n", classname);
Expand Down

0 comments on commit ca4c923

Please sign in to comment.