/* Copyright (C) 1996-2001 Id Software, Inc. Copyright (C) 2002-2009 John Fitzgibbons and others Copyright (C) 2010-2014 QuakeSpasm developers 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. */ #ifndef spingle__progs_h #define spingle__progs_h #include "pr_comp.h" /* defs shared with qcc */ #define PROGHEADER_CRC 5927 typedef union eval_s { string_t string; float _float; float vector[3]; func_t function; int32_t _int; int32_t edict; } eval_t; #define MAX_ENT_LEAFS 32 typedef struct edict_s { bool free; link_t area; /* linked to a division node or leaf */ int32_t num_leafs; int32_t leafnums[MAX_ENT_LEAFS]; entity_state_t baseline; uint8_t alpha; bool sendinterval; /* johnfitz -- send time until nextthink to client for better lerp timing */ float freetime; /* sv.time when the object was freed */ byte fields[]; } edict_t; #define EDICT_FROM_AREA(l) (edict_t *)((byte *)(l) - offsetof(edict_t, area)) #define ED_VARS(e) ((entvars_t *)e->fields) #define ED_FLOAT(e, o) (((float *)e->fields)[o]) #define ED_INT(e, o) (((int32_t *)e->fields)[o]) #define ED_VECTOR(e, o) (&ED_FLOAT(e, o)) #define ED_EVAL(e, o) ((eval_t *)&ED_FLOAT(e, o)) #define ED_RSTRING(e, o) (*(string_t *)&ED_INT(e, o)) #define ED_FUNC(e, o) (*(func_t *)&ED_INT(e, o)) //============================================================================ extern dprograms_t progs; extern dfunction_t *pr_functions; extern dstatement_t *pr_statements; extern byte *pr_global_data; extern ddef_t *pr_fielddefs; extern int32_t pr_edict_size; extern char const *pr_strings; extern char const **pr_knownstrings; extern int32_t pr_maxknownstrings; extern int32_t pr_numknownstrings; extern ddef_t *pr_globaldefs; const char *PR_ValueString(int32_t type, eval_t *val); const char *PR_UglyValueString(int32_t type, eval_t *val); void PR_Init(void); void PR_ExecuteProgram(func_t fnum); void PR_LoadProgs(void); const char *PR_GetString(int32_t num); int32_t PR_SetEngineString(const char *s); int32_t PR_AllocString(int32_t bufferlength, char **ptr); void PR_Profile_f(void); edict_t *ED_Alloc(void); void ED_Free(edict_t *ed); void ED_Print(edict_t *ed); void ED_Write(FILE *f, edict_t *ed); const char *ED_ParseEdict(const char *data, edict_t *ent); void ED_WriteGlobals(FILE *f); const char *ED_ParseGlobals(const char *data); void ED_LoadFromFile(const char *data); ddef_t *ED_GlobalAtOfs(int32_t ofs); ddef_t *ED_FieldAtOfs(int32_t ofs); bool ED_ParseEpair(void *base, ddef_t *key, const char *s); void ED_Init(void); void ED_Load(void); edict_t *EDICT_NUM(int32_t n); int32_t NUM_FOR_EDICT(edict_t *e); #define NEXT_EDICT(e) ((edict_t *)((byte *)(e) + pr_edict_size)) #define EDICT_TO_PROG(e) ((byte *)(e) - (byte *)sv.edicts) #define PROG_TO_EDICT(e) ((edict_t *)((byte *)sv.edicts + (e))) #define G_FLOAT(o) (((float *)pr_global_data)[o]) #define G_INT(o) (((int32_t *)pr_global_data)[o]) #define G_EDICT(o) ((edict_t *)(&((byte *)sv.edicts)[G_INT(o)])) #define G_EDICTNUM(o) NUM_FOR_EDICT(G_EDICT(o)) #define G_VECTOR(o) (&G_FLOAT(o)) #define G_STRING(o) (PR_GetString(G_RSTRING(o))) #define G_RSTRING(o) (*(string_t *)&G_INT(o)) #define G_FUNC(o) (*(func_t *)&G_INT(o)) #define G_EVAL(o) ((eval_t *)&G_FLOAT(o)) #define G_VOID(o) ((void *)&G_FLOAT(o)) typedef void (*builtin_t)(void); extern builtin_t pr_builtins[]; extern int32_t pr_numbuiltins; extern int32_t pr_argc; extern bool pr_trace; extern dfunction_t *pr_xfunction; extern int32_t pr_xstatement; extern uint16_t pr_crc; extern bool pr_alpha_supported; //johnfitz noreturn void PR_RunError(const char *error, ...) FUNC_PRINTF(1, 2); void ED_PrintEdicts(void); void ED_PrintNum(int32_t ent); eval_t *GetEdictFieldValue(edict_t *ed, const char *field); #endif