2001-02-19 21:15:25 +00:00
|
|
|
/*
|
|
|
|
pr_edict.c
|
|
|
|
|
|
|
|
entity dictionary
|
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
2001-09-28 06:26:31 +00:00
|
|
|
static const char rcsid[] =
|
|
|
|
"$Id$";
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
2001-03-28 17:17:56 +00:00
|
|
|
#include <stdarg.h>
|
2001-04-10 20:07:11 +00:00
|
|
|
#include <stdio.h>
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-03-27 20:33:07 +00:00
|
|
|
#include "QF/cmd.h"
|
2001-05-31 05:33:13 +00:00
|
|
|
#include "compat.h"
|
2001-03-27 20:33:07 +00:00
|
|
|
#include "QF/crc.h"
|
|
|
|
#include "QF/cvar.h"
|
|
|
|
#include "QF/hash.h"
|
|
|
|
#include "QF/progs.h"
|
|
|
|
#include "QF/qdefs.h"
|
|
|
|
#include "QF/qendian.h"
|
2001-09-21 04:22:46 +00:00
|
|
|
#include "QF/sys.h"
|
2001-03-27 20:33:07 +00:00
|
|
|
#include "QF/zone.h"
|
|
|
|
#include "QF/va.h"
|
2001-05-30 04:34:06 +00:00
|
|
|
#include "QF/vfs.h"
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-28 02:25:03 +00:00
|
|
|
cvar_t *pr_boundscheck;
|
2001-09-23 00:36:21 +00:00
|
|
|
cvar_t *pr_deadbeef_ents;
|
|
|
|
cvar_t *pr_deadbeef_locals;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-11-12 23:56:46 +00:00
|
|
|
int pr_type_size[ev_type_count] = {
|
|
|
|
1,
|
2001-02-19 21:15:25 +00:00
|
|
|
1,
|
|
|
|
1,
|
|
|
|
3,
|
|
|
|
1,
|
|
|
|
1,
|
2001-11-12 23:56:46 +00:00
|
|
|
1,
|
|
|
|
1,
|
|
|
|
4,
|
|
|
|
1,
|
|
|
|
1,
|
2001-02-19 21:15:25 +00:00
|
|
|
};
|
|
|
|
|
2001-10-28 04:38:24 +00:00
|
|
|
const char *type_name[ev_type_count] = {
|
2001-03-27 03:57:17 +00:00
|
|
|
"void",
|
|
|
|
"string",
|
|
|
|
"float",
|
|
|
|
"vector",
|
|
|
|
"entity",
|
|
|
|
"field",
|
|
|
|
"function",
|
|
|
|
"pointer",
|
2001-07-23 01:31:22 +00:00
|
|
|
"quaternion",
|
|
|
|
"integer",
|
2001-11-09 01:03:35 +00:00
|
|
|
"uinteger",
|
2001-03-27 03:57:17 +00:00
|
|
|
};
|
|
|
|
|
2001-02-28 02:25:03 +00:00
|
|
|
ddef_t *ED_FieldAtOfs (progs_t * pr, int ofs);
|
2001-07-15 07:04:17 +00:00
|
|
|
qboolean ED_ParseEpair (progs_t * pr, pr_type_t *base, ddef_t *key, const char *s);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
#define MAX_FIELD_LEN 64
|
|
|
|
#define GEFV_CACHESIZE 2
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
ddef_t *pcache;
|
|
|
|
char field[MAX_FIELD_LEN];
|
|
|
|
} gefv_cache;
|
|
|
|
|
|
|
|
static gefv_cache gefvCache[GEFV_CACHESIZE] = { {NULL, ""}, {NULL, ""} };
|
|
|
|
|
|
|
|
/*
|
|
|
|
ED_ClearEdict
|
|
|
|
|
|
|
|
Sets everything to NULL
|
|
|
|
*/
|
|
|
|
void
|
2001-04-19 22:42:01 +00:00
|
|
|
ED_ClearEdict (progs_t * pr, edict_t *e, int val)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-04-19 22:42:01 +00:00
|
|
|
int i;
|
|
|
|
|
2001-03-02 19:18:04 +00:00
|
|
|
if (NUM_FOR_EDICT(pr,e)<*pr->reserved_edicts)
|
2001-10-18 16:42:14 +00:00
|
|
|
Sys_Printf("clearing reserved edict %d\n", NUM_FOR_EDICT(pr,e));
|
2001-04-19 22:42:01 +00:00
|
|
|
for (i=0; i < pr->progs->entityfields; i++)
|
2001-07-22 20:20:46 +00:00
|
|
|
e->v[i].integer_var = val;
|
2001-04-19 22:42:01 +00:00
|
|
|
//memset (&e->v, 0, pr->progs->entityfields * 4);
|
2001-02-19 21:15:25 +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.
|
|
|
|
*/
|
2001-02-28 02:25:03 +00:00
|
|
|
edict_t *
|
|
|
|
ED_Alloc (progs_t * pr)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
edict_t *e;
|
2001-02-28 09:12:01 +00:00
|
|
|
int start = pr->reserved_edicts ? *pr->reserved_edicts : 0;
|
2001-03-04 05:42:26 +00:00
|
|
|
int max_edicts = pr->pr_edictareasize / pr->pr_edict_size;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-28 09:12:01 +00:00
|
|
|
for (i = start + 1; i < *(pr)->num_edicts; i++) {
|
2001-02-19 21:15:25 +00:00
|
|
|
e = EDICT_NUM (pr, i);
|
|
|
|
// the first couple seconds of server time can involve a lot of
|
|
|
|
// freeing and allocating, so relax the replacement policy
|
|
|
|
if (e->free && (e->freetime < 2 || *(pr)->time - e->freetime > 0.5)) {
|
2001-04-19 22:42:01 +00:00
|
|
|
ED_ClearEdict (pr, e, 0);
|
2001-02-19 21:15:25 +00:00
|
|
|
return e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-03-04 05:42:26 +00:00
|
|
|
if (i == max_edicts) {
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("WARNING: ED_Alloc: no free edicts\n");
|
2001-02-19 21:15:25 +00:00
|
|
|
i--; // step on whatever is the last edict
|
|
|
|
e = EDICT_NUM (pr, i);
|
|
|
|
if (pr->unlink)
|
|
|
|
pr->unlink (e);
|
|
|
|
} else
|
|
|
|
(*(pr)->num_edicts)++;
|
|
|
|
e = EDICT_NUM (pr, i);
|
2001-04-19 22:42:01 +00:00
|
|
|
ED_ClearEdict (pr, e, 0);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
2001-06-03 05:54:43 +00:00
|
|
|
/*
|
|
|
|
ED_FreeRefs
|
|
|
|
|
|
|
|
NULLs all references to entity
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ED_FreeRefs (progs_t * pr, edict_t *ed)
|
|
|
|
{
|
|
|
|
int i, j, k;
|
|
|
|
ddef_t *def;
|
|
|
|
for (i = 0; i < pr->progs->numglobaldefs; i++) {
|
|
|
|
def = &pr->pr_globaldefs[i];
|
|
|
|
if ((def->type & ~DEF_SAVEGLOBAL) == ev_entity) {
|
|
|
|
if (ed == G_EDICT (pr, def->ofs)) {
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("Reference found to free'd edict: %p\n", ed);
|
2001-06-03 05:54:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (i = 0; i < pr->progs->numfielddefs; i++) {
|
|
|
|
def = &pr->pr_fielddefs[i];
|
|
|
|
if ((def->type & ~DEF_SAVEGLOBAL) == ev_entity) {
|
|
|
|
for (j = 0; j < *pr->num_edicts; j++) {
|
|
|
|
k = E_var (EDICT_NUM (pr, j), def->ofs, entity);
|
|
|
|
if (ed == PROG_TO_EDICT (pr, k))
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("Reference found to free'd edict: %p\n", ed);
|
2001-06-03 05:54:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
/*
|
|
|
|
ED_Free
|
|
|
|
|
|
|
|
Marks the edict as free
|
|
|
|
FIXME: walk all entities and NULL out references to this entity
|
|
|
|
*/
|
|
|
|
void
|
2001-02-28 02:25:03 +00:00
|
|
|
ED_Free (progs_t * pr, edict_t *ed)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
if (pr->unlink)
|
|
|
|
pr->unlink (ed); // unlink from world bsp
|
|
|
|
|
2001-09-23 00:36:21 +00:00
|
|
|
if (pr_deadbeef_ents->int_val) {
|
2001-04-22 04:58:33 +00:00
|
|
|
ED_ClearEdict (pr, ed, 0xdeadbeef);
|
|
|
|
} else {
|
2001-08-12 04:14:25 +00:00
|
|
|
if (pr->free_edict)
|
|
|
|
pr->free_edict (pr, ed);
|
|
|
|
else
|
|
|
|
ED_ClearEdict (pr, ed, 0);
|
2001-04-22 04:58:33 +00:00
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
ed->free = true;
|
|
|
|
ed->freetime = *(pr)->time;
|
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
/*
|
|
|
|
ED_GlobalAtOfs
|
|
|
|
*/
|
2001-02-28 02:25:03 +00:00
|
|
|
ddef_t *
|
|
|
|
ED_GlobalAtOfs (progs_t * pr, int ofs)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
ddef_t *def;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < pr->progs->numglobaldefs; i++) {
|
|
|
|
def = &pr->pr_globaldefs[i];
|
|
|
|
if (def->ofs == ofs)
|
|
|
|
return def;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
ED_FieldAtOfs
|
|
|
|
*/
|
2001-02-28 02:25:03 +00:00
|
|
|
ddef_t *
|
|
|
|
ED_FieldAtOfs (progs_t * pr, int ofs)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
ddef_t *def;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < pr->progs->numfielddefs; i++) {
|
|
|
|
def = &pr->pr_fielddefs[i];
|
|
|
|
if (def->ofs == ofs)
|
|
|
|
return def;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
ED_FindField
|
|
|
|
*/
|
2001-02-28 02:25:03 +00:00
|
|
|
ddef_t *
|
2001-03-27 03:57:17 +00:00
|
|
|
ED_FindField (progs_t * pr, const char *name)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-03-05 05:11:26 +00:00
|
|
|
return Hash_Find (pr->field_hash, name);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-03-02 19:18:04 +00:00
|
|
|
int
|
2001-07-15 07:04:17 +00:00
|
|
|
ED_GetFieldIndex (progs_t *pr, const char *name)
|
2001-03-02 19:18:04 +00:00
|
|
|
{
|
|
|
|
ddef_t *def;
|
|
|
|
|
|
|
|
def = ED_FindField (pr, name);
|
|
|
|
if (def)
|
|
|
|
return def->ofs;
|
|
|
|
return -1;
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
/*
|
2001-02-28 09:12:01 +00:00
|
|
|
PR_FindGlobal
|
2001-02-19 21:15:25 +00:00
|
|
|
*/
|
2001-02-28 02:25:03 +00:00
|
|
|
ddef_t *
|
2001-02-28 09:12:01 +00:00
|
|
|
PR_FindGlobal (progs_t * pr, const char *name)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-03-05 05:11:26 +00:00
|
|
|
return Hash_Find (pr->global_hash, name);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-06-08 00:13:06 +00:00
|
|
|
pr_type_t *
|
2001-03-02 19:18:04 +00:00
|
|
|
PR_GetGlobalPointer (progs_t *pr, const char *name)
|
|
|
|
{
|
|
|
|
ddef_t *def;
|
|
|
|
|
|
|
|
def = PR_FindGlobal (pr, name);
|
|
|
|
if (def)
|
2001-06-08 00:13:06 +00:00
|
|
|
return &pr->pr_globals[def->ofs];
|
2001-03-27 03:57:17 +00:00
|
|
|
PR_Error (pr, "undefined global %s", name);
|
2001-03-02 19:18:04 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-03-27 03:57:17 +00:00
|
|
|
func_t
|
|
|
|
PR_GetFunctionIndex (progs_t *pr, const char *name)
|
|
|
|
{
|
|
|
|
dfunction_t *func = ED_FindFunction (pr, name);
|
|
|
|
if (func)
|
|
|
|
return func - pr->pr_functions;
|
|
|
|
PR_Error (pr, "undefined function %s", name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
PR_GetFieldOffset (progs_t *pr, const char *name)
|
|
|
|
{
|
|
|
|
ddef_t *def = ED_FindField (pr, name);
|
|
|
|
if (def)
|
|
|
|
return def->ofs;
|
|
|
|
PR_Error (pr, "undefined field %s", name);
|
|
|
|
return -1;
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
ED_FindFunction
|
|
|
|
*/
|
|
|
|
dfunction_t *
|
2001-03-27 03:57:17 +00:00
|
|
|
ED_FindFunction (progs_t * pr, const char *name)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-03-05 05:11:26 +00:00
|
|
|
return Hash_Find (pr->function_hash, name);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-06-08 00:13:06 +00:00
|
|
|
pr_type_t *
|
2001-07-15 07:04:17 +00:00
|
|
|
GetEdictFieldValue (progs_t * pr, edict_t *ed, const char *field)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
ddef_t *def = NULL;
|
|
|
|
int i;
|
|
|
|
static int rep = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < GEFV_CACHESIZE; i++) {
|
|
|
|
if (!strcmp (field, gefvCache[i].field)) {
|
|
|
|
def = gefvCache[i].pcache;
|
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
def = ED_FindField (pr, field);
|
|
|
|
|
|
|
|
if (strlen (field) < MAX_FIELD_LEN) {
|
|
|
|
gefvCache[rep].pcache = def;
|
|
|
|
strcpy (gefvCache[rep].field, field);
|
|
|
|
rep ^= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
Done:
|
|
|
|
if (!def)
|
|
|
|
return NULL;
|
|
|
|
|
2001-06-08 00:13:06 +00:00
|
|
|
return &ed->v[def->ofs];
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
PR_ValueString
|
|
|
|
|
|
|
|
Returns a string describing *data in a type specific manner
|
|
|
|
*/
|
2001-02-28 02:25:03 +00:00
|
|
|
char *
|
2001-03-02 19:18:04 +00:00
|
|
|
PR_ValueString (progs_t * pr, etype_t type, pr_type_t *val)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
static char line[256];
|
|
|
|
ddef_t *def;
|
|
|
|
dfunction_t *f;
|
|
|
|
|
|
|
|
type &= ~DEF_SAVEGLOBAL;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case ev_string:
|
2001-02-28 02:25:03 +00:00
|
|
|
snprintf (line, sizeof (line), "%s",
|
2001-03-02 19:18:04 +00:00
|
|
|
PR_GetString (pr, val->string_var));
|
2001-02-19 21:15:25 +00:00
|
|
|
break;
|
|
|
|
case ev_entity:
|
|
|
|
snprintf (line, sizeof (line), "entity %i",
|
2001-09-23 01:29:52 +00:00
|
|
|
NUM_FOR_BAD_EDICT (pr, PROG_TO_EDICT (pr, val->entity_var)));
|
2001-02-19 21:15:25 +00:00
|
|
|
break;
|
2001-03-01 23:03:40 +00:00
|
|
|
case ev_func:
|
2001-03-02 19:18:04 +00:00
|
|
|
f = pr->pr_functions + val->func_var;
|
2001-02-28 02:25:03 +00:00
|
|
|
snprintf (line, sizeof (line), "%s()",
|
|
|
|
PR_GetString (pr, f->s_name));
|
2001-02-19 21:15:25 +00:00
|
|
|
break;
|
|
|
|
case ev_field:
|
2001-07-22 20:20:46 +00:00
|
|
|
def = ED_FieldAtOfs (pr, val->integer_var);
|
2001-02-28 02:25:03 +00:00
|
|
|
snprintf (line, sizeof (line), ".%s",
|
|
|
|
PR_GetString (pr, def->s_name));
|
2001-02-19 21:15:25 +00:00
|
|
|
break;
|
|
|
|
case ev_void:
|
|
|
|
strcpy (line, "void");
|
|
|
|
break;
|
|
|
|
case ev_float:
|
2001-03-02 19:18:04 +00:00
|
|
|
snprintf (line, sizeof (line), "%5.1f", val->float_var);
|
2001-02-19 21:15:25 +00:00
|
|
|
break;
|
|
|
|
case ev_vector:
|
|
|
|
snprintf (line, sizeof (line), "'%5.1f %5.1f %5.1f'",
|
2001-07-23 01:31:22 +00:00
|
|
|
val->vector_var[0], val->vector_var[1],
|
|
|
|
val->vector_var[2]);
|
2001-02-19 21:15:25 +00:00
|
|
|
break;
|
|
|
|
case ev_pointer:
|
|
|
|
strcpy (line, "pointer");
|
|
|
|
break;
|
2001-07-23 01:31:22 +00:00
|
|
|
case ev_quaternion:
|
|
|
|
snprintf (line, sizeof (line), "'%5.1f %5.1f %5.1f %5.1f'",
|
|
|
|
val->vector_var[0], val->vector_var[1],
|
|
|
|
val->vector_var[2], val->vector_var[3]);
|
|
|
|
break;
|
|
|
|
case ev_integer:
|
|
|
|
snprintf (line, sizeof (line), "%d", val->integer_var);
|
|
|
|
break;
|
2001-11-13 18:04:55 +00:00
|
|
|
case ev_uinteger:
|
|
|
|
snprintf (line, sizeof (line), "%u", val->uinteger_var);
|
|
|
|
break;
|
2001-02-19 21:15:25 +00:00
|
|
|
default:
|
|
|
|
snprintf (line, sizeof (line), "bad type %i", type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return line;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
PR_UglyValueString
|
|
|
|
|
|
|
|
Returns a string describing *data in a type specific manner
|
|
|
|
Easier to parse than PR_ValueString
|
|
|
|
*/
|
2001-02-28 02:25:03 +00:00
|
|
|
char *
|
2001-06-08 00:13:06 +00:00
|
|
|
PR_UglyValueString (progs_t * pr, etype_t type, pr_type_t *val)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
static char line[256];
|
|
|
|
ddef_t *def;
|
|
|
|
dfunction_t *f;
|
|
|
|
|
|
|
|
type &= ~DEF_SAVEGLOBAL;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case ev_string:
|
2001-02-28 02:25:03 +00:00
|
|
|
snprintf (line, sizeof (line), "%s",
|
2001-06-08 00:13:06 +00:00
|
|
|
PR_GetString (pr, val->string_var));
|
2001-02-19 21:15:25 +00:00
|
|
|
break;
|
|
|
|
case ev_entity:
|
|
|
|
snprintf (line, sizeof (line), "%i",
|
2001-09-23 01:29:52 +00:00
|
|
|
NUM_FOR_BAD_EDICT (pr, PROG_TO_EDICT (pr, val->entity_var)));
|
2001-02-19 21:15:25 +00:00
|
|
|
break;
|
2001-03-01 23:03:40 +00:00
|
|
|
case ev_func:
|
2001-06-08 00:13:06 +00:00
|
|
|
f = pr->pr_functions + val->func_var;
|
2001-02-19 21:15:25 +00:00
|
|
|
snprintf (line, sizeof (line), "%s", PR_GetString (pr, f->s_name));
|
|
|
|
break;
|
|
|
|
case ev_field:
|
2001-07-22 20:20:46 +00:00
|
|
|
def = ED_FieldAtOfs (pr, val->integer_var);
|
2001-02-28 02:25:03 +00:00
|
|
|
snprintf (line, sizeof (line), "%s",
|
|
|
|
PR_GetString (pr, def->s_name));
|
2001-02-19 21:15:25 +00:00
|
|
|
break;
|
|
|
|
case ev_void:
|
|
|
|
strcpy (line, "void");
|
|
|
|
break;
|
|
|
|
case ev_float:
|
2001-06-08 00:13:06 +00:00
|
|
|
snprintf (line, sizeof (line), "%f", val->float_var);
|
2001-02-19 21:15:25 +00:00
|
|
|
break;
|
|
|
|
case ev_vector:
|
2001-06-08 00:13:06 +00:00
|
|
|
snprintf (line, sizeof (line), "%f %f %f", val->vector_var[0],
|
|
|
|
val->vector_var[1], val->vector_var[2]);
|
2001-02-19 21:15:25 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
snprintf (line, sizeof (line), "bad type %i", type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return line;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
PR_GlobalString
|
|
|
|
|
|
|
|
Returns a string with a description and the contents of a global,
|
|
|
|
padded to 20 field width
|
|
|
|
*/
|
2001-02-28 02:25:03 +00:00
|
|
|
char *
|
2001-08-13 23:49:04 +00:00
|
|
|
PR_GlobalString (progs_t * pr, int ofs, etype_t type)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
char *s;
|
|
|
|
int i;
|
2001-07-19 07:27:14 +00:00
|
|
|
ddef_t *def = 0;
|
2001-02-19 21:15:25 +00:00
|
|
|
void *val;
|
|
|
|
static char line[128];
|
|
|
|
|
2001-07-19 07:27:14 +00:00
|
|
|
if (pr_debug->int_val && pr->debug)
|
|
|
|
def = PR_Get_Local_Def (pr, ofs);
|
2001-02-19 21:15:25 +00:00
|
|
|
val = (void *) &pr->pr_globals[ofs];
|
2001-07-19 07:27:14 +00:00
|
|
|
if (!def)
|
|
|
|
def = ED_GlobalAtOfs (pr, ofs);
|
2001-08-13 23:49:04 +00:00
|
|
|
if (!def && type == ev_void)
|
2001-02-19 21:15:25 +00:00
|
|
|
snprintf (line, sizeof (line), "%i(?)", ofs);
|
|
|
|
else {
|
2001-08-13 23:49:04 +00:00
|
|
|
char *name = "?";
|
|
|
|
char *oi = "";
|
|
|
|
if (def) {
|
|
|
|
if (type == ev_void)
|
|
|
|
type = def->type;
|
|
|
|
name = PR_GetString (pr, def->s_name);
|
|
|
|
if (type != def->type)
|
|
|
|
oi = "!";
|
|
|
|
}
|
|
|
|
s = PR_ValueString (pr, type, val);
|
|
|
|
snprintf (line, sizeof (line), "%i(%s%s)%s", ofs, oi, name, s);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
i = strlen (line);
|
|
|
|
for (; i < 20; i++)
|
|
|
|
strncat (line, " ", sizeof (line) - strlen (line));
|
|
|
|
strncat (line, " ", sizeof (line) - strlen (line));
|
|
|
|
|
|
|
|
return line;
|
|
|
|
}
|
|
|
|
|
2001-02-28 02:25:03 +00:00
|
|
|
char *
|
|
|
|
PR_GlobalStringNoContents (progs_t * pr, int ofs)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
int i;
|
2001-07-19 07:27:14 +00:00
|
|
|
ddef_t *def = 0;
|
2001-02-19 21:15:25 +00:00
|
|
|
static char line[128];
|
|
|
|
|
2001-07-19 07:27:14 +00:00
|
|
|
if (pr_debug->int_val && pr->debug)
|
|
|
|
def = PR_Get_Local_Def (pr, ofs);
|
|
|
|
if (!def)
|
|
|
|
def = ED_GlobalAtOfs (pr, ofs);
|
2001-02-19 21:15:25 +00:00
|
|
|
if (!def)
|
|
|
|
snprintf (line, sizeof (line), "%i(?)", ofs);
|
|
|
|
else
|
|
|
|
snprintf (line, sizeof (line), "%i(%s)", ofs,
|
|
|
|
PR_GetString (pr, def->s_name));
|
|
|
|
|
|
|
|
i = strlen (line);
|
|
|
|
for (; i < 20; i++)
|
|
|
|
strncat (line, " ", sizeof (line) - strlen (line));
|
|
|
|
strncat (line, " ", sizeof (line) - strlen (line));
|
|
|
|
|
|
|
|
return line;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
ED_Print
|
|
|
|
|
|
|
|
For debugging
|
|
|
|
*/
|
|
|
|
void
|
2001-02-28 02:25:03 +00:00
|
|
|
ED_Print (progs_t * pr, edict_t *ed)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
int l;
|
|
|
|
ddef_t *d;
|
2001-03-02 19:18:04 +00:00
|
|
|
pr_type_t *v;
|
2001-08-22 21:07:06 +00:00
|
|
|
int i;
|
2001-02-19 21:15:25 +00:00
|
|
|
char *name;
|
|
|
|
int type;
|
|
|
|
|
|
|
|
if (ed->free) {
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("FREE\n");
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-09-23 01:29:52 +00:00
|
|
|
Sys_Printf ("\nEDICT %i:\n", NUM_FOR_BAD_EDICT (pr, ed));
|
2001-02-19 21:15:25 +00:00
|
|
|
for (i = 1; i < pr->progs->numfielddefs; i++) {
|
|
|
|
d = &pr->pr_fielddefs[i];
|
|
|
|
name = PR_GetString (pr, d->s_name);
|
|
|
|
if (name[strlen (name) - 2] == '_')
|
|
|
|
continue; // skip _x, _y, _z vars
|
|
|
|
|
2001-03-02 19:18:04 +00:00
|
|
|
v = ed->v + d->ofs;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// if the value is still all 0, skip the field
|
|
|
|
type = d->type & ~DEF_SAVEGLOBAL;
|
|
|
|
|
2001-08-22 21:07:06 +00:00
|
|
|
switch (type) {
|
|
|
|
case ev_entity:
|
|
|
|
case ev_integer:
|
|
|
|
case ev_func:
|
|
|
|
case ev_field:
|
|
|
|
if (!v->integer_var)
|
|
|
|
continue;
|
2001-02-19 21:15:25 +00:00
|
|
|
break;
|
2001-08-22 21:07:06 +00:00
|
|
|
case ev_string:
|
|
|
|
if (!PR_GetString (pr, v->string_var)[0])
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
case ev_float:
|
|
|
|
if (!v->float_var)
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
case ev_vector:
|
|
|
|
if (!v[0].float_var && !v[1].float_var && !v[2].float_var)
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
PR_Error (pr, "ED_Print: Unhandled type %d\n", type);
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("%s", name);
|
2001-02-19 21:15:25 +00:00
|
|
|
l = strlen (name);
|
|
|
|
while (l++ < 15)
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf (" ");
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("%s\n", PR_ValueString (pr, d->type, v));
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
ED_Write
|
|
|
|
|
|
|
|
For savegames
|
|
|
|
*/
|
|
|
|
void
|
2001-05-30 03:21:19 +00:00
|
|
|
ED_Write (progs_t * pr, VFile *f, edict_t *ed)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
ddef_t *d;
|
2001-06-08 00:13:06 +00:00
|
|
|
pr_type_t *v;
|
2001-02-19 21:15:25 +00:00
|
|
|
int i, j;
|
|
|
|
char *name;
|
|
|
|
int type;
|
|
|
|
|
|
|
|
Qprintf (f, "{\n");
|
|
|
|
|
|
|
|
if (ed->free) {
|
|
|
|
Qprintf (f, "}\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 1; i < pr->progs->numfielddefs; i++) {
|
|
|
|
d = &pr->pr_fielddefs[i];
|
|
|
|
name = PR_GetString (pr, d->s_name);
|
|
|
|
if (name[strlen (name) - 2] == '_')
|
|
|
|
continue; // skip _x, _y, _z vars
|
|
|
|
|
2001-06-08 00:13:06 +00:00
|
|
|
v = &ed->v[d->ofs];
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// if the value is still all 0, skip the field
|
|
|
|
type = d->type & ~DEF_SAVEGLOBAL;
|
2001-11-12 23:56:46 +00:00
|
|
|
for (j = 0; j < pr_type_size[type]; j++)
|
2001-07-22 20:20:46 +00:00
|
|
|
if (v[j].integer_var)
|
2001-02-19 21:15:25 +00:00
|
|
|
break;
|
2001-11-12 23:56:46 +00:00
|
|
|
if (j == pr_type_size[type])
|
2001-02-19 21:15:25 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
Qprintf (f, "\"%s\" ", name);
|
2001-06-08 00:13:06 +00:00
|
|
|
Qprintf (f, "\"%s\"\n", PR_UglyValueString (pr, d->type, v));
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Qprintf (f, "}\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-02-28 02:25:03 +00:00
|
|
|
ED_PrintNum (progs_t * pr, int ent)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
ED_Print (pr, EDICT_NUM (pr, ent));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
ED_PrintEdicts
|
|
|
|
|
|
|
|
For debugging, prints all the entities in the current server
|
|
|
|
*/
|
|
|
|
void
|
2001-07-19 03:18:11 +00:00
|
|
|
ED_PrintEdicts (progs_t *pr, const char *fieldval)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-07-19 03:18:11 +00:00
|
|
|
int i;
|
|
|
|
int count;
|
|
|
|
ddef_t *def;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-07-19 03:18:11 +00:00
|
|
|
def = ED_FindField(pr, "classname");
|
|
|
|
|
|
|
|
if (fieldval && fieldval[0] && def) {
|
|
|
|
count = 0;
|
|
|
|
for (i = 0; i < *(pr)->num_edicts; i++)
|
|
|
|
if (strequal(fieldval, E_STRING (pr, EDICT_NUM(pr, i), def->ofs))) {
|
|
|
|
ED_PrintNum (pr, i);
|
|
|
|
count++;
|
|
|
|
}
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("%i entities\n", count);
|
2001-07-19 03:18:11 +00:00
|
|
|
} else {
|
|
|
|
for (i = 0; i < *(pr)->num_edicts; i++)
|
|
|
|
ED_PrintNum (pr, i);
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("%i entities\n", *(pr)->num_edicts);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
ED_Count
|
|
|
|
|
|
|
|
For debugging
|
|
|
|
*/
|
|
|
|
void
|
2001-02-28 02:25:03 +00:00
|
|
|
ED_Count (progs_t * pr)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
edict_t *ent;
|
2001-09-20 19:34:02 +00:00
|
|
|
int active, models, solid, step, zombie;
|
2001-02-28 09:12:01 +00:00
|
|
|
ddef_t *solid_def;
|
|
|
|
ddef_t *model_def;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-28 09:12:01 +00:00
|
|
|
solid_def = ED_FindField (pr, "solid");
|
|
|
|
model_def = ED_FindField (pr, "model");
|
2001-09-20 19:34:02 +00:00
|
|
|
active = models = solid = step = zombie = 0;
|
2001-02-19 21:15:25 +00:00
|
|
|
for (i = 0; i < *(pr)->num_edicts; i++) {
|
|
|
|
ent = EDICT_NUM (pr, i);
|
2001-09-20 19:34:02 +00:00
|
|
|
if (ent->free) {
|
|
|
|
if (*(pr)->time - ent->freetime <= 0.5)
|
|
|
|
zombie++;
|
2001-02-19 21:15:25 +00:00
|
|
|
continue;
|
2001-09-20 19:34:02 +00:00
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
active++;
|
2001-02-28 09:12:01 +00:00
|
|
|
if (solid_def && ent->v[solid_def->ofs].float_var)
|
2001-02-19 21:15:25 +00:00
|
|
|
solid++;
|
2001-02-28 09:12:01 +00:00
|
|
|
if (model_def && ent->v[model_def->ofs].float_var)
|
2001-02-19 21:15:25 +00:00
|
|
|
models++;
|
|
|
|
}
|
|
|
|
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("num_edicts:%3i\n", *(pr)->num_edicts);
|
|
|
|
Sys_Printf ("active :%3i\n", active);
|
|
|
|
Sys_Printf ("view :%3i\n", models);
|
|
|
|
Sys_Printf ("touch :%3i\n", solid);
|
|
|
|
Sys_Printf ("zombie :%3i\n", zombie);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
ARCHIVING GLOBALS
|
|
|
|
|
|
|
|
FIXME: need to tag constants, doesn't really work
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
ED_WriteGlobals
|
|
|
|
*/
|
|
|
|
void
|
2001-05-30 03:21:19 +00:00
|
|
|
ED_WriteGlobals (progs_t * pr, VFile *f)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
ddef_t *def;
|
|
|
|
int i;
|
|
|
|
char *name;
|
|
|
|
int type;
|
|
|
|
|
|
|
|
Qprintf (f, "{\n");
|
|
|
|
for (i = 0; i < pr->progs->numglobaldefs; i++) {
|
|
|
|
def = &pr->pr_globaldefs[i];
|
|
|
|
type = def->type;
|
|
|
|
if (!(def->type & DEF_SAVEGLOBAL))
|
|
|
|
continue;
|
|
|
|
type &= ~DEF_SAVEGLOBAL;
|
|
|
|
|
|
|
|
if (type != ev_string && type != ev_float && type != ev_entity)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
name = PR_GetString (pr, def->s_name);
|
|
|
|
Qprintf (f, "\"%s\" ", name);
|
|
|
|
Qprintf (f, "\"%s\"\n",
|
2001-06-08 00:13:06 +00:00
|
|
|
PR_UglyValueString (pr, type, &pr->pr_globals[def->ofs]));
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
Qprintf (f, "}\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
ED_ParseGlobals
|
|
|
|
*/
|
|
|
|
void
|
2001-07-15 07:04:17 +00:00
|
|
|
ED_ParseGlobals (progs_t * pr, const char *data)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
char keyname[64];
|
|
|
|
ddef_t *key;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
// parse key
|
|
|
|
data = COM_Parse (data);
|
|
|
|
if (com_token[0] == '}')
|
|
|
|
break;
|
|
|
|
if (!data)
|
2001-02-28 02:25:03 +00:00
|
|
|
PR_Error (pr, "ED_ParseEntity: EOF without closing brace");
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
strcpy (keyname, com_token);
|
|
|
|
|
|
|
|
// parse value
|
|
|
|
data = COM_Parse (data);
|
|
|
|
if (!data)
|
2001-02-28 02:25:03 +00:00
|
|
|
PR_Error (pr, "ED_ParseEntity: EOF without closing brace");
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (com_token[0] == '}')
|
2001-02-28 02:25:03 +00:00
|
|
|
PR_Error (pr, "ED_ParseEntity: closing brace without data");
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-28 09:12:01 +00:00
|
|
|
key = PR_FindGlobal (pr, keyname);
|
2001-02-19 21:15:25 +00:00
|
|
|
if (!key) {
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("'%s' is not a global\n", keyname);
|
2001-02-19 21:15:25 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2001-02-28 09:12:01 +00:00
|
|
|
if (!ED_ParseEpair (pr, pr->pr_globals, key, com_token))
|
2001-02-28 02:25:03 +00:00
|
|
|
PR_Error (pr, "ED_ParseGlobals: parse error");
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
ED_NewString
|
|
|
|
*/
|
2001-02-28 02:25:03 +00:00
|
|
|
char *
|
2001-07-15 07:04:17 +00:00
|
|
|
ED_NewString (progs_t * pr, const char *string)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
char *new, *new_p;
|
|
|
|
int i, l;
|
|
|
|
|
|
|
|
l = strlen (string) + 1;
|
|
|
|
new = Hunk_Alloc (l);
|
|
|
|
new_p = new;
|
|
|
|
|
|
|
|
for (i = 0; i < l; i++) {
|
|
|
|
if (string[i] == '\\' && i < l - 1) {
|
|
|
|
i++;
|
|
|
|
if (string[i] == 'n')
|
|
|
|
*new_p++ = '\n';
|
|
|
|
else
|
|
|
|
*new_p++ = '\\';
|
|
|
|
} else
|
|
|
|
*new_p++ = string[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
return new;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
ED_ParseEval
|
|
|
|
|
|
|
|
Can parse either fields or globals
|
|
|
|
returns false if error
|
|
|
|
*/
|
|
|
|
qboolean
|
2001-07-15 07:04:17 +00:00
|
|
|
ED_ParseEpair (progs_t * pr, pr_type_t *base, ddef_t *key, const char *s)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char string[128];
|
|
|
|
ddef_t *def;
|
|
|
|
char *v, *w;
|
2001-06-08 00:13:06 +00:00
|
|
|
pr_type_t *d;
|
2001-02-19 21:15:25 +00:00
|
|
|
dfunction_t *func;
|
|
|
|
|
2001-06-08 00:13:06 +00:00
|
|
|
d = &base[key->ofs];
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
switch (key->type & ~DEF_SAVEGLOBAL) {
|
|
|
|
case ev_string:
|
2001-06-08 00:13:06 +00:00
|
|
|
d->string_var = PR_SetString (pr, ED_NewString (pr, s));
|
2001-02-19 21:15:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ev_float:
|
2001-06-08 00:13:06 +00:00
|
|
|
d->float_var = atof (s);
|
2001-02-19 21:15:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ev_vector:
|
|
|
|
strcpy (string, s);
|
|
|
|
v = string;
|
|
|
|
w = string;
|
|
|
|
for (i = 0; i < 3; i++) {
|
|
|
|
while (*v && *v != ' ')
|
|
|
|
v++;
|
|
|
|
*v = 0;
|
2001-06-08 00:13:06 +00:00
|
|
|
d->vector_var[i] = atof (w);
|
2001-02-19 21:15:25 +00:00
|
|
|
w = v = v + 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ev_entity:
|
2001-06-08 00:13:06 +00:00
|
|
|
d->entity_var = EDICT_TO_PROG (pr, EDICT_NUM (pr, atoi (s)));
|
2001-02-19 21:15:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ev_field:
|
|
|
|
def = ED_FindField (pr, s);
|
|
|
|
if (!def) {
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("Can't find field %s\n", s);
|
2001-02-19 21:15:25 +00:00
|
|
|
return false;
|
|
|
|
}
|
2001-07-22 20:20:46 +00:00
|
|
|
d->integer_var = G_INT (pr, def->ofs);
|
2001-02-19 21:15:25 +00:00
|
|
|
break;
|
|
|
|
|
2001-03-01 23:03:40 +00:00
|
|
|
case ev_func:
|
2001-02-19 21:15:25 +00:00
|
|
|
func = ED_FindFunction (pr, s);
|
|
|
|
if (!func) {
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("Can't find function %s\n", s);
|
2001-02-19 21:15:25 +00:00
|
|
|
return false;
|
|
|
|
}
|
2001-06-08 00:13:06 +00:00
|
|
|
d->func_var = func - pr->pr_functions;
|
2001-02-19 21:15:25 +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.
|
|
|
|
*/
|
2001-07-15 07:04:17 +00:00
|
|
|
const char *
|
|
|
|
ED_ParseEdict (progs_t * pr, const char *data, edict_t *ent)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
ddef_t *key;
|
|
|
|
qboolean anglehack;
|
|
|
|
qboolean init;
|
|
|
|
char keyname[256];
|
2001-02-28 00:56:03 +00:00
|
|
|
int n;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
init = false;
|
|
|
|
|
|
|
|
// clear it
|
2001-02-28 02:25:03 +00:00
|
|
|
if (ent != *(pr)->edicts) // hack
|
2001-02-19 21:15:25 +00:00
|
|
|
memset (&ent->v, 0, pr->progs->entityfields * 4);
|
|
|
|
|
|
|
|
// go through all the dictionary pairs
|
|
|
|
while (1) {
|
|
|
|
// parse key
|
|
|
|
data = COM_Parse (data);
|
|
|
|
if (com_token[0] == '}')
|
|
|
|
break;
|
|
|
|
if (!data)
|
2001-02-28 02:25:03 +00:00
|
|
|
PR_Error (pr, "ED_ParseEntity: EOF without closing brace");
|
2001-02-19 21:15:25 +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
|
|
|
|
|
|
|
|
strcpy (keyname, com_token);
|
|
|
|
|
2001-02-28 00:56:03 +00:00
|
|
|
// another hack to fix heynames with trailing spaces
|
|
|
|
n = strlen (keyname);
|
|
|
|
while (n && keyname[n - 1] == ' ') {
|
2001-02-28 02:25:03 +00:00
|
|
|
keyname[n - 1] = 0;
|
|
|
|
n--;
|
2001-02-28 00:56:03 +00:00
|
|
|
}
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
// parse value
|
|
|
|
data = COM_Parse (data);
|
|
|
|
if (!data)
|
2001-02-28 02:25:03 +00:00
|
|
|
PR_Error (pr, "ED_ParseEntity: EOF without closing brace");
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (com_token[0] == '}')
|
2001-02-28 02:25:03 +00:00
|
|
|
PR_Error (pr, "ED_ParseEntity: closing brace without data");
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
init = true;
|
|
|
|
|
|
|
|
// keynames with a leading underscore are used for utility comments,
|
|
|
|
// and are immediately discarded by quake
|
|
|
|
if (keyname[0] == '_')
|
|
|
|
continue;
|
|
|
|
|
|
|
|
key = ED_FindField (pr, keyname);
|
|
|
|
if (!key) {
|
2001-03-27 22:39:21 +00:00
|
|
|
if (!pr->parse_field || !pr->parse_field (pr, keyname, com_token)) {
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("'%s' is not a field\n", keyname);
|
2001-02-19 21:15:25 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else {
|
2001-02-28 02:25:03 +00:00
|
|
|
int ret;
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
if (anglehack) {
|
2001-02-28 09:12:01 +00:00
|
|
|
ret = ED_ParseEpair (pr, ent->v, key, va ("0 %s 0", com_token));
|
2001-02-28 00:56:03 +00:00
|
|
|
} else {
|
2001-02-28 09:12:01 +00:00
|
|
|
ret = ED_ParseEpair (pr, ent->v, key, com_token);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2001-02-28 00:56:03 +00:00
|
|
|
if (!ret)
|
2001-02-28 02:25:03 +00:00
|
|
|
PR_Error (pr, "ED_ParseEdict: parse error");
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
void
|
2001-07-15 07:04:17 +00:00
|
|
|
ED_LoadFromFile (progs_t * pr, const char *data)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
edict_t *ent;
|
|
|
|
int inhibit;
|
|
|
|
dfunction_t *func;
|
2001-06-08 00:13:06 +00:00
|
|
|
pr_type_t *classname;
|
2001-02-28 23:33:16 +00:00
|
|
|
ddef_t *def;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
ent = NULL;
|
|
|
|
inhibit = 0;
|
|
|
|
|
2001-03-01 08:34:30 +00:00
|
|
|
*pr->globals.time = *(pr)->time;
|
2001-02-28 09:12:01 +00:00
|
|
|
|
|
|
|
// parse ents
|
2001-02-19 21:15:25 +00:00
|
|
|
while (1) {
|
2001-02-28 09:12:01 +00:00
|
|
|
// parse the opening brace
|
2001-02-19 21:15:25 +00:00
|
|
|
data = COM_Parse (data);
|
|
|
|
if (!data)
|
|
|
|
break;
|
|
|
|
if (com_token[0] != '{')
|
2001-02-28 02:25:03 +00:00
|
|
|
PR_Error (pr, "ED_LoadFromFile: found %s when expecting {", com_token);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (!ent)
|
|
|
|
ent = EDICT_NUM (pr, 0);
|
|
|
|
else
|
|
|
|
ent = ED_Alloc (pr);
|
|
|
|
data = ED_ParseEdict (pr, data, ent);
|
|
|
|
|
2001-02-28 09:12:01 +00:00
|
|
|
// remove things from different skill levels or deathmatch
|
2001-03-27 22:39:21 +00:00
|
|
|
if (pr->prune_edict && pr->prune_edict (pr, ent)) {
|
2001-02-19 21:15:25 +00:00
|
|
|
ED_Free (pr, ent);
|
|
|
|
inhibit++;
|
|
|
|
continue;
|
|
|
|
}
|
2001-02-28 09:12:01 +00:00
|
|
|
//
|
|
|
|
// immediately call spawn function
|
|
|
|
//
|
2001-02-28 23:33:16 +00:00
|
|
|
def = ED_FindField (pr, "classname");
|
|
|
|
if (!def) {
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("No classname for:\n");
|
2001-02-19 21:15:25 +00:00
|
|
|
ED_Print (pr, ent);
|
|
|
|
ED_Free (pr, ent);
|
|
|
|
continue;
|
|
|
|
}
|
2001-06-08 00:13:06 +00:00
|
|
|
classname = &ent->v[def->ofs];
|
2001-02-19 21:15:25 +00:00
|
|
|
// look for the spawn function
|
2001-06-08 00:13:06 +00:00
|
|
|
func = ED_FindFunction (pr, PR_GetString (pr, classname->string_var));
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (!func) {
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("No spawn function for:\n");
|
2001-02-19 21:15:25 +00:00
|
|
|
ED_Print (pr, ent);
|
|
|
|
ED_Free (pr, ent);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2001-03-01 08:34:30 +00:00
|
|
|
*pr->globals.self = EDICT_TO_PROG (pr, ent);
|
2001-02-19 21:15:25 +00:00
|
|
|
PR_ExecuteProgram (pr, func - pr->pr_functions);
|
|
|
|
if (pr->flush)
|
|
|
|
pr->flush ();
|
|
|
|
}
|
|
|
|
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_DPrintf ("%i entities inhibited\n", inhibit);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-06-04 04:52:14 +00:00
|
|
|
static const char *
|
2001-03-05 05:11:26 +00:00
|
|
|
function_get_key (void *f, void *_pr)
|
|
|
|
{
|
|
|
|
progs_t *pr = (progs_t*)_pr;
|
|
|
|
dfunction_t *func = (dfunction_t*)f;
|
|
|
|
return PR_GetString (pr, func->s_name);
|
|
|
|
}
|
|
|
|
|
2001-06-04 04:52:14 +00:00
|
|
|
static const char *
|
2001-03-05 05:11:26 +00:00
|
|
|
var_get_key (void *d, void *_pr)
|
|
|
|
{
|
|
|
|
progs_t *pr = (progs_t*)_pr;
|
|
|
|
ddef_t *def = (ddef_t*)d;
|
|
|
|
return PR_GetString (pr, def->s_name);
|
|
|
|
}
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
void
|
2001-07-18 02:21:57 +00:00
|
|
|
PR_LoadProgsFile (progs_t * pr, const char *progsname)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2001-06-01 21:14:50 +00:00
|
|
|
if (progsname)
|
|
|
|
pr->progs = (dprograms_t *) COM_LoadHunkFile (progsname);
|
|
|
|
else
|
|
|
|
progsname = "(preloaded)";
|
2001-02-19 21:15:25 +00:00
|
|
|
if (!pr->progs)
|
|
|
|
return;
|
|
|
|
|
2001-07-18 02:21:57 +00:00
|
|
|
pr->progs_size = com_filesize;
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_DPrintf ("Programs occupy %iK.\n", com_filesize / 1024);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-28 09:12:01 +00:00
|
|
|
// store prog crc
|
2001-02-19 21:15:25 +00:00
|
|
|
pr->crc = CRC_Block ((byte *) pr->progs, com_filesize);
|
|
|
|
|
2001-02-28 09:12:01 +00:00
|
|
|
// byte swap the header
|
2001-02-19 21:15:25 +00:00
|
|
|
for (i = 0; i < sizeof (*pr->progs) / 4; i++)
|
|
|
|
((int *) pr->progs)[i] = LittleLong (((int *) pr->progs)[i]);
|
|
|
|
|
2001-06-09 06:25:33 +00:00
|
|
|
if (pr->progs->version != PROG_VERSION
|
2001-11-13 08:58:54 +00:00
|
|
|
&& pr->progs->version != PROG_ID_VERSION) {
|
|
|
|
if (pr->progs->version < 0x00fff000) {
|
|
|
|
PR_Error (pr, "%s has unrecognised version number (%d)",
|
|
|
|
progsname, pr->progs->version);
|
|
|
|
} else {
|
|
|
|
PR_Error (pr,
|
|
|
|
"%s has unrecognised version number (%02x.%03x.%03x)"
|
|
|
|
" [%02x.%03x.%03x expected]",
|
|
|
|
progsname,
|
|
|
|
pr->progs->version >> 24,
|
|
|
|
(pr->progs->version >> 12) & 0xfff,
|
|
|
|
pr->progs->version & 0xfff,
|
|
|
|
PROG_VERSION >> 24,
|
|
|
|
(PROG_VERSION >> 12) & 0xfff,
|
|
|
|
PROG_VERSION & 0xfff);
|
|
|
|
}
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-07-14 23:53:59 +00:00
|
|
|
pr->progs_name = progsname; //XXX is this safe?
|
|
|
|
|
2001-02-28 02:25:03 +00:00
|
|
|
pr->pr_functions =
|
|
|
|
(dfunction_t *) ((byte *) pr->progs + pr->progs->ofs_functions);
|
2001-02-19 21:15:25 +00:00
|
|
|
pr->pr_strings = (char *) pr->progs + pr->progs->ofs_strings;
|
2001-03-03 09:09:39 +00:00
|
|
|
pr->pr_stringsize = LittleLong (pr->progs->numstrings);
|
2001-02-28 02:25:03 +00:00
|
|
|
pr->pr_globaldefs =
|
|
|
|
(ddef_t *) ((byte *) pr->progs + pr->progs->ofs_globaldefs);
|
|
|
|
pr->pr_fielddefs =
|
|
|
|
(ddef_t *) ((byte *) pr->progs + pr->progs->ofs_fielddefs);
|
|
|
|
pr->pr_statements =
|
|
|
|
(dstatement_t *) ((byte *) pr->progs + pr->progs->ofs_statements);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-28 02:25:03 +00:00
|
|
|
pr->pr_globals =
|
|
|
|
(pr_type_t *) ((byte *) pr->progs + pr->progs->ofs_globals);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-11-17 04:32:00 +00:00
|
|
|
// size of edict ascked for by progs
|
|
|
|
pr->pr_edict_size = pr->progs->entityfields * 4;
|
|
|
|
// size of engine data
|
|
|
|
pr->pr_edict_size += sizeof (edict_t) - sizeof (pr_type_t);
|
|
|
|
// round off to next highest whole word address (esp for Alpha)
|
|
|
|
// this ensures that pointers in the engine data area are always
|
|
|
|
// properly aligned
|
|
|
|
pr->pr_edict_size += sizeof (void*) - 1;
|
|
|
|
pr->pr_edict_size &= ~(sizeof (void*) - 1);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-28 22:44:38 +00:00
|
|
|
pr->pr_edictareasize = 0;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-03-05 05:11:26 +00:00
|
|
|
if (pr->function_hash) {
|
|
|
|
Hash_FlushTable (pr->function_hash);
|
|
|
|
} else {
|
|
|
|
pr->function_hash = Hash_NewTable (1021, function_get_key, 0, pr);
|
|
|
|
}
|
|
|
|
if (pr->global_hash) {
|
|
|
|
Hash_FlushTable (pr->global_hash);
|
|
|
|
} else {
|
|
|
|
pr->global_hash = Hash_NewTable (1021, var_get_key, 0, pr);
|
|
|
|
}
|
|
|
|
if (pr->field_hash) {
|
|
|
|
Hash_FlushTable (pr->field_hash);
|
|
|
|
} else {
|
|
|
|
pr->field_hash = Hash_NewTable (1021, var_get_key, 0, pr);
|
|
|
|
}
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
// byte swap the lumps
|
|
|
|
for (i = 0; i < pr->progs->numstatements; i++) {
|
|
|
|
pr->pr_statements[i].op = LittleShort (pr->pr_statements[i].op);
|
|
|
|
pr->pr_statements[i].a = LittleShort (pr->pr_statements[i].a);
|
|
|
|
pr->pr_statements[i].b = LittleShort (pr->pr_statements[i].b);
|
|
|
|
pr->pr_statements[i].c = LittleShort (pr->pr_statements[i].c);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < pr->progs->numfunctions; i++) {
|
|
|
|
pr->pr_functions[i].first_statement =
|
|
|
|
LittleLong (pr->pr_functions[i].first_statement);
|
2001-02-28 02:25:03 +00:00
|
|
|
pr->pr_functions[i].parm_start =
|
|
|
|
LittleLong (pr->pr_functions[i].parm_start);
|
2001-02-19 21:15:25 +00:00
|
|
|
pr->pr_functions[i].s_name = LittleLong (pr->pr_functions[i].s_name);
|
|
|
|
pr->pr_functions[i].s_file = LittleLong (pr->pr_functions[i].s_file);
|
2001-02-28 02:25:03 +00:00
|
|
|
pr->pr_functions[i].numparms =
|
|
|
|
LittleLong (pr->pr_functions[i].numparms);
|
2001-02-19 21:15:25 +00:00
|
|
|
pr->pr_functions[i].locals = LittleLong (pr->pr_functions[i].locals);
|
2001-03-05 05:11:26 +00:00
|
|
|
Hash_Add (pr->function_hash, &pr->pr_functions[i]);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < pr->progs->numglobaldefs; i++) {
|
|
|
|
pr->pr_globaldefs[i].type = LittleShort (pr->pr_globaldefs[i].type);
|
|
|
|
pr->pr_globaldefs[i].ofs = LittleShort (pr->pr_globaldefs[i].ofs);
|
|
|
|
pr->pr_globaldefs[i].s_name = LittleLong (pr->pr_globaldefs[i].s_name);
|
2001-03-05 05:11:26 +00:00
|
|
|
Hash_Add (pr->global_hash, &pr->pr_globaldefs[i]);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < pr->progs->numfielddefs; i++) {
|
|
|
|
pr->pr_fielddefs[i].type = LittleShort (pr->pr_fielddefs[i].type);
|
|
|
|
if (pr->pr_fielddefs[i].type & DEF_SAVEGLOBAL)
|
2001-02-28 02:25:03 +00:00
|
|
|
PR_Error (pr, "PR_LoadProgs: pr_fielddefs[i].type & DEF_SAVEGLOBAL");
|
2001-02-19 21:15:25 +00:00
|
|
|
pr->pr_fielddefs[i].ofs = LittleShort (pr->pr_fielddefs[i].ofs);
|
|
|
|
pr->pr_fielddefs[i].s_name = LittleLong (pr->pr_fielddefs[i].s_name);
|
2001-03-05 05:11:26 +00:00
|
|
|
Hash_Add (pr->field_hash, &pr->pr_fielddefs[i]);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < pr->progs->numglobals; i++)
|
|
|
|
((int *) pr->pr_globals)[i] = LittleLong (((int *) pr->pr_globals)[i]);
|
2001-07-16 07:13:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
PR_LoadProgs
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
PR_LoadProgs (progs_t * pr, const char *progsname)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2001-07-18 02:21:57 +00:00
|
|
|
PR_LoadProgsFile (pr, progsname);
|
2001-07-16 07:13:10 +00:00
|
|
|
if (!pr->progs)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!progsname)
|
|
|
|
progsname = "(preloaded)";
|
|
|
|
|
|
|
|
// flush the non-C variable lookup cache
|
|
|
|
for (i = 0; i < GEFV_CACHESIZE; i++)
|
|
|
|
gefvCache[i].field[0] = 0;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-03-02 19:18:04 +00:00
|
|
|
if (!(pr->globals.time = (float*)PR_GetGlobalPointer (pr, "time")))
|
2001-02-28 09:12:01 +00:00
|
|
|
PR_Error (pr, "%s: undefined symbol: time", progsname);
|
2001-03-02 19:18:04 +00:00
|
|
|
if (!(pr->globals.self = (int*)PR_GetGlobalPointer (pr, "self")))
|
2001-02-28 09:12:01 +00:00
|
|
|
PR_Error (pr, "%s: undefined symbol: self", progsname);
|
2001-03-02 19:18:04 +00:00
|
|
|
if ((pr->fields.nextthink = ED_GetFieldIndex (pr, "nextthink")) == -1)
|
2001-02-28 09:12:01 +00:00
|
|
|
PR_Error (pr, "%s: undefined field: nextthink", progsname);
|
2001-03-02 19:18:04 +00:00
|
|
|
if ((pr->fields.frame = ED_GetFieldIndex (pr, "frame")) == -1)
|
2001-02-28 09:12:01 +00:00
|
|
|
PR_Error (pr, "%s: undefined field: frame", progsname);
|
2001-03-02 19:18:04 +00:00
|
|
|
if ((pr->fields.think = ED_GetFieldIndex (pr, "think")) == -1)
|
2001-02-28 22:44:38 +00:00
|
|
|
PR_Error (pr, "%s: undefined field: think", progsname);
|
2001-02-28 09:12:01 +00:00
|
|
|
|
2001-03-06 04:22:33 +00:00
|
|
|
// initialise the strings managment code
|
|
|
|
PR_LoadStrings (pr);
|
|
|
|
|
2001-07-14 23:53:59 +00:00
|
|
|
PR_LoadDebug (pr);
|
|
|
|
|
2001-11-02 22:41:11 +00:00
|
|
|
PR_Check_Opcodes (pr);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-04-20 17:51:57 +00:00
|
|
|
edict_t *
|
|
|
|
PR_InitEdicts (progs_t *pr, int num_edicts)
|
|
|
|
{
|
|
|
|
edict_t *edicts;
|
|
|
|
edict_t *e;
|
|
|
|
int i, j;
|
|
|
|
pr->pr_edictareasize = pr->pr_edict_size * num_edicts;
|
|
|
|
edicts = Hunk_AllocName (pr->pr_edictareasize, "edicts");
|
|
|
|
(*pr->edicts) = edicts;
|
2001-09-23 00:36:21 +00:00
|
|
|
if (pr_deadbeef_ents->int_val) {
|
2001-04-22 04:58:33 +00:00
|
|
|
memset (edicts, 0, *pr->reserved_edicts * pr->pr_edict_size);
|
|
|
|
for (j = *pr->reserved_edicts; j < num_edicts; j++) {
|
|
|
|
e = EDICT_NUM (pr, j);
|
|
|
|
for (i=0; i < pr->progs->entityfields; i++)
|
2001-07-22 20:20:46 +00:00
|
|
|
e->v[i].integer_var = 0xdeadbeef;
|
2001-04-22 04:58:33 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
memset (edicts, 0, pr->pr_edictareasize);
|
2001-04-20 17:51:57 +00:00
|
|
|
}
|
|
|
|
return edicts;
|
|
|
|
}
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
void
|
|
|
|
PR_Init_Cvars (void)
|
|
|
|
{
|
|
|
|
pr_boundscheck =
|
2001-04-10 23:39:30 +00:00
|
|
|
Cvar_Get ("pr_boundscheck", "1", CVAR_NONE, NULL,
|
2001-02-19 21:15:25 +00:00
|
|
|
"Server progs bounds checking");
|
2001-09-23 00:36:21 +00:00
|
|
|
pr_deadbeef_ents = Cvar_Get ("pr_deadbeef_ents", "0", CVAR_NONE, NULL,
|
2001-08-13 20:29:33 +00:00
|
|
|
"set to clear unallocated memory to 0xdeadbeef");
|
2001-09-23 00:36:21 +00:00
|
|
|
pr_deadbeef_locals = Cvar_Get ("pr_deadbeef_locals", "0", CVAR_NONE, NULL,
|
|
|
|
"set to clear uninitialized local vars to "
|
|
|
|
"0xdeadbeef");
|
2001-07-14 23:53:59 +00:00
|
|
|
PR_Debug_Init_Cvars ();
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PR_Init (void)
|
|
|
|
{
|
2001-07-14 02:34:16 +00:00
|
|
|
PR_Opcode_Init ();
|
2001-07-14 23:53:59 +00:00
|
|
|
PR_Debug_Init ();
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-08-04 23:44:50 +00:00
|
|
|
#define PR_AUTOBUILTIN 120
|
2001-08-03 06:40:28 +00:00
|
|
|
void
|
|
|
|
PR_AddBuiltin (progs_t *pr, const char *name, builtin_proc builtin, int num)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
if (pr->numbuiltins == 0) {
|
|
|
|
pr->builtins = malloc (PR_AUTOBUILTIN * sizeof (builtin_t));
|
|
|
|
pr->numbuiltins = PR_AUTOBUILTIN;
|
|
|
|
if (!pr->builtins)
|
|
|
|
PR_Error (pr, "PR_AddBuiltin: memory allocation error!\n");
|
|
|
|
for (i = 0; i < pr->numbuiltins; i++) {
|
|
|
|
pr->builtins[i].proc = 0;
|
|
|
|
pr->builtins[i].name = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (num < 0) {
|
|
|
|
for (i = PR_AUTOBUILTIN; i < pr->numbuiltins && pr->builtins[i].proc; i++)
|
|
|
|
;
|
|
|
|
if (i >= pr->numbuiltins) {
|
|
|
|
pr->numbuiltins++;
|
|
|
|
pr->builtins = realloc (pr->builtins, pr->numbuiltins * sizeof (builtin_t));
|
|
|
|
if (!pr->builtins)
|
|
|
|
PR_Error (pr, "PR_AddBuiltin: memory allocation error!\n");
|
|
|
|
}
|
|
|
|
j = i;
|
|
|
|
} else {
|
|
|
|
if (num >= PR_AUTOBUILTIN || num == 0)
|
|
|
|
PR_Error (pr, "PR_AddBuiltin: invalid builtin number.\n");
|
|
|
|
if (pr->builtins[num].proc)
|
|
|
|
PR_Error (pr, "PR_AddBuiltin: builtin number already exists.\n");
|
|
|
|
j = num;
|
|
|
|
}
|
|
|
|
pr->builtins[j].proc = builtin;
|
|
|
|
pr->builtins[j].name = name;
|
|
|
|
}
|
|
|
|
|
2001-08-04 23:44:50 +00:00
|
|
|
int
|
|
|
|
PR_FindBuiltin (progs_t *pr, const char *name)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < pr->numbuiltins; i++)
|
|
|
|
if (pr->builtins[i].name && strequal (pr->builtins[i].name, name))
|
|
|
|
return i;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-02-28 02:25:03 +00:00
|
|
|
edict_t *
|
|
|
|
EDICT_NUM (progs_t * pr, int n)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-03-04 05:42:26 +00:00
|
|
|
int offs = n * pr->pr_edict_size;
|
|
|
|
if (offs < 0 || n >= pr->pr_edictareasize)
|
2001-09-23 01:29:52 +00:00
|
|
|
PR_RunError (pr, "EDICT_NUM: bad number %i", n);
|
2001-10-08 03:46:44 +00:00
|
|
|
|
2001-03-04 05:42:26 +00:00
|
|
|
return PROG_TO_EDICT (pr, offs);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-09-23 01:29:52 +00:00
|
|
|
NUM_FOR_BAD_EDICT (progs_t *pr, edict_t *e)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
int b;
|
|
|
|
|
2001-02-28 02:25:03 +00:00
|
|
|
b = (byte *) e - (byte *) * (pr)->edicts;
|
2001-02-19 21:15:25 +00:00
|
|
|
b = b / pr->pr_edict_size;
|
|
|
|
|
2001-09-23 01:29:52 +00:00
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
NUM_FOR_EDICT (progs_t *pr, edict_t *e)
|
|
|
|
{
|
|
|
|
int b;
|
|
|
|
|
|
|
|
b = NUM_FOR_BAD_EDICT (pr, e);
|
|
|
|
|
2001-06-06 00:38:05 +00:00
|
|
|
if (b && (b < 0 || b >= *(pr)->num_edicts))
|
2001-09-23 01:29:52 +00:00
|
|
|
PR_RunError (pr, "NUM_FOR_EDICT: bad pointer %d %p %p", b, e, * (pr)->edicts);
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
return b;
|
|
|
|
}
|
2001-02-28 22:44:38 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
PR_Error (progs_t *pr, const char *error, ...)
|
|
|
|
{
|
|
|
|
va_list argptr;
|
|
|
|
char string[1024];
|
|
|
|
|
|
|
|
va_start (argptr, error);
|
|
|
|
vsnprintf (string, sizeof (string), error, argptr);
|
|
|
|
va_end (argptr);
|
|
|
|
|
|
|
|
Sys_Error ("%s", string);
|
|
|
|
}
|
2001-03-27 03:57:17 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
PR_AccessField (progs_t *pr, const char *name, etype_t type,
|
|
|
|
const char *file, int line)
|
|
|
|
{
|
|
|
|
ddef_t *def = ED_FindField (pr, name);
|
|
|
|
|
|
|
|
if (!def)
|
|
|
|
PR_Error (pr, "undefined field %s accessed at %s:%d", name, file, line);
|
|
|
|
if (def->type != type)
|
|
|
|
PR_Error (pr, "bad type access to %s as %s (should be %s) at %s:%d",
|
|
|
|
name, type_name[type], type_name[def->type], file, line);
|
|
|
|
return def->ofs;
|
|
|
|
}
|