X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fdarkplaces.git;a=blobdiff_plain;f=pr_edict.c;h=2a77bac1d4df77add0a2927f635045d3f2c6103d;hp=db12799b4d7e5d8df22354c22ce31d90b3690f1d;hb=456bdec8d560cc7fd8ccdd8bae33fdf35bc4a51b;hpb=57252d1b300d96b2353bf9d564b0de281552d2c5 diff --git a/pr_edict.c b/pr_edict.c index db12799b..2a77bac1 100644 --- a/pr_edict.c +++ b/pr_edict.c @@ -39,10 +39,10 @@ mempool_t *edictstring_mempool; int type_size[8] = {1,sizeof(string_t)/4,1,3,1,1,sizeof(func_t)/4,sizeof(void *)/4}; -ddef_t *ED_FieldAtOfs (int ofs); -qboolean ED_ParseEpair (void *base, ddef_t *key, const char *s); +ddef_t *ED_FieldAtOfs(int ofs); +qboolean ED_ParseEpair(edict_t *ent, ddef_t *key, const char *s); -cvar_t pr_checkextension = {0, "pr_checkextension", "1"}; +cvar_t pr_checkextension = {CVAR_READONLY, "pr_checkextension", "1"}; cvar_t nomonsters = {0, "nomonsters", "0"}; cvar_t gamecfg = {0, "gamecfg", "0"}; cvar_t scratch1 = {0, "scratch1", "0"}; @@ -119,9 +119,14 @@ int eval_movement; int eval_pmodel; int eval_punchvector; int eval_viewzoom; +int eval_clientcolors; +int eval_tag_entity; +int eval_tag_index; mfunction_t *SV_PlayerPhysicsQC; mfunction_t *EndFrameQC; +//KrimZon - SERVER COMMANDS IN QUAKEC +mfunction_t *SV_ParseClientCommandQC; int FindFieldOffset(const char *field) { @@ -168,11 +173,16 @@ void FindEdictFieldOffsets(void) eval_pmodel = FindFieldOffset("pmodel"); eval_punchvector = FindFieldOffset("punchvector"); eval_viewzoom = FindFieldOffset("viewzoom"); + eval_clientcolors = FindFieldOffset("clientcolors"); + eval_tag_entity = FindFieldOffset("tag_entity"); + eval_tag_index = FindFieldOffset("tag_index"); // LordHavoc: allowing QuakeC to override the player movement code SV_PlayerPhysicsQC = ED_FindFunction ("SV_PlayerPhysics"); // LordHavoc: support for endframe EndFrameQC = ED_FindFunction ("EndFrame"); + //KrimZon - SERVER COMMANDS IN QUAKEC + SV_ParseClientCommandQC = ED_FindFunction ("SV_ParseClientCommand"); } /* @@ -184,8 +194,17 @@ Sets everything to NULL */ void ED_ClearEdict (edict_t *e) { + int num; memset (e->v, 0, progs->entityfields * 4); - e->free = false; + e->e->free = false; + // LordHavoc: for consistency set these here + num = NUM_FOR_EDICT(e) - 1; + if (num >= 0 && num < svs.maxclients) + { + e->v->colormap = num + 1; + e->v->team = (svs.clients[num].colors & 15) + 1; + e->v->netname = PR_SetString(svs.clients[num].name); + } } /* @@ -204,22 +223,24 @@ edict_t *ED_Alloc (void) int i; edict_t *e; - for ( i=svs.maxclients+1 ; ifree && ( e->freetime < 2 || sv.time - e->freetime > 0.5 ) ) + if (e->e->free && ( e->e->freetime < 2 || sv.time - e->e->freetime > 0.5 ) ) { ED_ClearEdict (e); return e; } } - + if (i == MAX_EDICTS) Host_Error ("ED_Alloc: no free edicts"); - + sv.num_edicts++; + if (sv.num_edicts >= sv.max_edicts) + SV_IncreaseEdicts(); e = EDICT_NUM(i); ED_ClearEdict (e); @@ -238,7 +259,7 @@ void ED_Free (edict_t *ed) { SV_UnlinkEdict (ed); // unlink from world bsp - ed->free = true; + ed->e->free = true; ed->v->model = 0; ed->v->takedamage = 0; ed->v->modelindex = 0; @@ -249,8 +270,8 @@ void ED_Free (edict_t *ed) VectorClear(ed->v->angles); ed->v->nextthink = -1; ed->v->solid = 0; - - ed->freetime = sv.time; + + ed->e->freetime = sv.time; } //=========================================================================== @@ -264,7 +285,7 @@ ddef_t *ED_GlobalAtOfs (int ofs) { ddef_t *def; int i; - + for (i=0 ; inumglobaldefs ; i++) { def = &pr_globaldefs[i]; @@ -283,7 +304,7 @@ ddef_t *ED_FieldAtOfs (int ofs) { ddef_t *def; int i; - + for (i=0 ; inumfielddefs ; i++) { def = &pr_fielddefs[i]; @@ -359,7 +380,7 @@ PR_ValueString Returns a string describing *data in a type specific manner ============= */ -int NoCrash_NUM_FOR_EDICT(edict_t *e); +//int NoCrash_NUM_FOR_EDICT(edict_t *e); char *PR_ValueString (etype_t type, eval_t *val) { static char line[1024]; // LordHavoc: enlarged a bit (was 256) @@ -372,39 +393,40 @@ char *PR_ValueString (etype_t type, eval_t *val) switch (type) { case ev_string: - sprintf (line, "%s", PR_GetString(val->string)); + snprintf (line, sizeof (line), "%s", PR_GetString(val->string)); break; case ev_entity: - n = NoCrash_NUM_FOR_EDICT(PROG_TO_EDICT(val->edict)); + //n = NoCrash_NUM_FOR_EDICT(PROG_TO_EDICT(val->edict)); + n = val->edict; if (n < 0 || n >= MAX_EDICTS) - sprintf (line, "entity %i (invalid!)", n); + snprintf (line, sizeof (line), "entity %i (invalid!)", n); else - sprintf (line, "entity %i", n); + snprintf (line, sizeof (line), "entity %i", n); break; case ev_function: f = pr_functions + val->function; - sprintf (line, "%s()", PR_GetString(f->s_name)); + snprintf (line, sizeof (line), "%s()", PR_GetString(f->s_name)); break; case ev_field: def = ED_FieldAtOfs ( val->_int ); - sprintf (line, ".%s", PR_GetString(def->s_name)); + snprintf (line, sizeof (line), ".%s", PR_GetString(def->s_name)); break; case ev_void: - sprintf (line, "void"); + snprintf (line, sizeof (line), "void"); break; case ev_float: // LordHavoc: changed from %5.1f to %10.4f - sprintf (line, "%10.4f", val->_float); + snprintf (line, sizeof (line), "%10.4f", val->_float); break; case ev_vector: // LordHavoc: changed from %5.1f to %10.4f - sprintf (line, "'%10.4f %10.4f %10.4f'", val->vector[0], val->vector[1], val->vector[2]); + snprintf (line, sizeof (line), "'%10.4f %10.4f %10.4f'", val->vector[0], val->vector[1], val->vector[2]); break; case ev_pointer: - sprintf (line, "pointer"); + snprintf (line, sizeof (line), "pointer"); break; default: - sprintf (line, "bad type %i", type); + snprintf (line, sizeof (line), "bad type %i", type); break; } @@ -432,23 +454,11 @@ char *PR_UglyValueString (etype_t type, eval_t *val) switch (type) { case ev_string: - sprintf (line, "%s", PR_GetString(val->string)); - break; - case ev_entity: - sprintf (line, "%i", NUM_FOR_EDICT(PROG_TO_EDICT(val->edict))); - break; - case ev_function: - f = pr_functions + val->function; - sprintf (line, "%s", PR_GetString(f->s_name)); - break; - case ev_field: - def = ED_FieldAtOfs ( val->_int ); - // LordHavoc: parse the string a bit to turn special characters + // Parse the string a bit to turn special characters // (like newline, specifically) into escape codes, // this fixes saving games from various mods - //sprintf (line, "%s", PR_GetString(def->s_name)); - s = PR_GetString(def->s_name); - for (i = 0;i < 4095 && *s;) + s = PR_GetString (val->string); + for (i = 0;i < (int)sizeof(line) - 2 && *s;) { if (*s == '\n') { @@ -461,22 +471,33 @@ char *PR_UglyValueString (etype_t type, eval_t *val) line[i++] = 'r'; } else - line[i] = *s; + line[i++] = *s; s++; } - line[i++] = 0; + line[i] = '\0'; + break; + case ev_entity: + snprintf (line, sizeof (line), "%i", NUM_FOR_EDICT(PROG_TO_EDICT(val->edict))); + break; + case ev_function: + f = pr_functions + val->function; + snprintf (line, sizeof (line), "%s", PR_GetString(f->s_name)); + break; + case ev_field: + def = ED_FieldAtOfs ( val->_int ); + snprintf (line, sizeof (line), ".%s", PR_GetString(def->s_name)); break; case ev_void: - sprintf (line, "void"); + snprintf (line, sizeof (line), "void"); break; case ev_float: - sprintf (line, "%f", val->_float); + snprintf (line, sizeof (line), "%f", val->_float); break; case ev_vector: - sprintf (line, "%f %f %f", val->vector[0], val->vector[1], val->vector[2]); + snprintf (line, sizeof (line), "%f %f %f", val->vector[0], val->vector[1], val->vector[2]); break; default: - sprintf (line, "bad type %i", type); + snprintf (line, sizeof (line), "bad type %i", type); break; } @@ -502,17 +523,17 @@ char *PR_GlobalString (int ofs) val = (void *)&pr_globals[ofs]; def = ED_GlobalAtOfs(ofs); if (!def) - sprintf (line,"%i(?)", ofs); + snprintf (line, sizeof (line), "%i(?)", ofs); else { s = PR_ValueString (def->type, val); - sprintf (line,"%i(%s)%s", ofs, PR_GetString(def->s_name), s); + snprintf (line, sizeof (line), "%i(%s)%s", ofs, PR_GetString(def->s_name), s); } i = strlen(line); for ( ; i<20 ; i++) - strcat (line," "); - strcat (line," "); + strlcat (line, " ", sizeof (line)); + strlcat (line, " ", sizeof (line)); return line; } @@ -525,14 +546,14 @@ char *PR_GlobalStringNoContents (int ofs) def = ED_GlobalAtOfs(ofs); if (!def) - sprintf (line,"%i(?)", ofs); + snprintf (line, sizeof (line), "%i(?)", ofs); else - sprintf (line,"%i(%s)", ofs, PR_GetString(def->s_name)); + snprintf (line, sizeof (line), "%i(%s)", ofs, PR_GetString(def->s_name)); i = strlen(line); for ( ; i<20 ; i++) - strcat (line," "); - strcat (line," "); + strlcat (line, " ", sizeof (line)); + strlcat (line, " ", sizeof (line)); return line; } @@ -557,14 +578,14 @@ void ED_Print (edict_t *ed) int type; char tempstring[8192], tempstring2[260]; // temporary string buffers - if (ed->free) + if (ed->e->free) { Con_Printf ("FREE\n"); return; } tempstring[0] = 0; - sprintf(tempstring, "\nEDICT %i:\n", NUM_FOR_EDICT(ed)); + snprintf (tempstring, sizeof (tempstring), "\nEDICT %i:\n", NUM_FOR_EDICT(ed)); for (i=1 ; inumfielddefs ; i++) { d = &pr_fielddefs[i]; @@ -590,7 +611,7 @@ void ED_Print (edict_t *ed) tempstring2[259] = 0; name = tempstring2; } - strcat(tempstring, name); + strlcat (tempstring, name, sizeof (tempstring)); for (l = strlen(name);l < 14;l++) strcat(tempstring, " "); strcat(tempstring, " "); @@ -603,8 +624,8 @@ void ED_Print (edict_t *ed) tempstring2[259] = 0; name = tempstring2; } - strcat(tempstring, name); - strcat(tempstring, "\n"); + strlcat (tempstring, name, sizeof (tempstring)); + strlcat (tempstring, "\n", sizeof (tempstring)); if (strlen(tempstring) >= 4096) { Con_Printf("%s", tempstring); @@ -632,7 +653,7 @@ void ED_Write (qfile_t *f, edict_t *ed) FS_Printf (f, "{\n"); - if (ed->free) + if (ed->e->free) { FS_Printf (f, "}\n"); return; @@ -720,7 +741,7 @@ void ED_Count (void) for (i=0 ; ifree) + if (ent->e->free) continue; active++; if (ent->v->solid) @@ -774,11 +795,39 @@ void ED_WriteGlobals (qfile_t *f) name = PR_GetString(def->s_name); FS_Printf (f,"\"%s\" ", name); - FS_Printf (f,"\"%s\"\n", PR_UglyValueString(type, (eval_t *)&pr_globals[def->ofs])); + FS_Printf (f,"\"%s\"\n", PR_UglyValueString(type, (eval_t *)&pr_globals[def->ofs])); } FS_Printf (f,"}\n"); } +/* +============= +ED_EdictSet_f + +Console command to set a field of a specified edict +============= +*/ +void ED_EdictSet_f(void) +{ + edict_t *ed; + ddef_t *key; + + if(Cmd_Argc() != 4) + { + Con_Printf("edictset \n"); + return; + } + ed = EDICT_NUM(atoi(Cmd_Argv(1))); + + if((key = ED_FindField(Cmd_Argv(2))) == 0) + { + Con_Printf("Key %s not found !\n", Cmd_Argv(2)); + return; + } + + ED_ParseEpair(ed, key, Cmd_Argv(3)); +} + /* ============= ED_ParseGlobals @@ -792,7 +841,7 @@ void ED_ParseGlobals (const char *data) while (1) { // parse key - if (!COM_ParseToken (&data)) + if (!COM_ParseToken(&data, false)) Host_Error ("ED_ParseEntity: EOF without closing brace"); if (com_token[0] == '}') break; @@ -800,7 +849,7 @@ void ED_ParseGlobals (const char *data) strcpy (keyname, com_token); // parse value - if (!COM_ParseToken (&data)) + if (!COM_ParseToken(&data, false)) Host_Error ("ED_ParseEntity: EOF without closing brace"); if (com_token[0] == '}') @@ -813,7 +862,7 @@ void ED_ParseGlobals (const char *data) continue; } - if (!ED_ParseEpair ((void *)pr_globals, key, com_token)) + if (!ED_ParseEpair(NULL, key, com_token)) Host_Error ("ED_ParseGlobals: parse error"); } } @@ -861,69 +910,81 @@ Can parse either fields or globals returns false if error ============= */ -qboolean ED_ParseEpair (void *base, ddef_t *key, const char *s) +qboolean ED_ParseEpair(edict_t *ent, ddef_t *key, const char *s) { - int i; - char string[128]; - ddef_t *def; - char *v, *w; - void *d; - mfunction_t *func; - - d = (void *)((int *)base + key->ofs); + int i; + ddef_t *def; + eval_t *val; + mfunction_t *func; + if (ent) + val = (eval_t *)((int *)ent->v + key->ofs); + else + val = (eval_t *)((int *)pr_globals + key->ofs); switch (key->type & ~DEF_SAVEGLOBAL) { case ev_string: - *(string_t *)d = PR_SetString(ED_NewString(s)); + val->string = PR_SetString(ED_NewString(s)); break; - + case ev_float: - *(float *)d = atof (s); + while (*s && *s <= ' ') + s++; + val->_float = atof(s); break; - + case ev_vector: - strcpy (string, s); - v = string; - w = string; - for (i=0 ; i<3 ; i++) + for (i = 0;i < 3;i++) { - while (*v && *v != ' ') - v++; - *v = 0; - ((float *)d)[i] = atof (w); - w = v = v+1; + while (*s && *s <= ' ') + s++; + if (!*s) + break; + val->vector[i] = atof(s); + while (*s > ' ') + s++; + if (!*s) + break; } break; case ev_entity: - *(int *)d = EDICT_TO_PROG(EDICT_NUM(atoi (s))); + while (*s && *s <= ' ') + s++; + i = atoi(s); + if (i < 0 || i >= MAX_EDICTS) + Con_Printf("ED_ParseEpair: ev_entity reference too large (edict %i >= MAX_EDICTS %i)\n", i, MAX_EDICTS); + while (i >= sv.max_edicts) + SV_IncreaseEdicts(); + // if SV_IncreaseEdicts was called the base pointer needs to be updated + if (ent) + val = (eval_t *)((int *)ent->v + key->ofs); + val->edict = EDICT_TO_PROG(EDICT_NUM(i)); break; case ev_field: - def = ED_FindField (s); + def = ED_FindField(s); if (!def) { - // LordHavoc: don't warn about worldspawn sky/fog fields because they don't require mod support - if (strcmp(s, "sky") && strcmp(s, "fog") && strncmp(s, "fog_", 4) && strcmp(s, "farclip")) - Con_DPrintf ("Can't find field %s\n", s); + Con_DPrintf("ED_ParseEpair: Can't find field %s\n", s); return false; } - *(int *)d = G_INT(def->ofs); + val->_int = G_INT(def->ofs); break; case ev_function: - func = ED_FindFunction (s); + func = ED_FindFunction(s); if (!func) { - Con_DPrintf ("Can't find function %s\n", s); + Con_Printf ("ED_ParseEpair: Can't find function %s\n", s); return false; } - *(func_t *)d = func - pr_functions; + val->function = func - pr_functions; break; default: - break; + Con_Printf("ED_ParseEpair: Unknown key->type %i for key \"%s\"\n", key->type, PR_GetString(key->s_name)); + return false; } return true; } @@ -955,26 +1016,22 @@ const char *ED_ParseEdict (const char *data, edict_t *ent) while (1) { // parse key - if (!COM_ParseToken (&data)) + if (!COM_ParseToken(&data, false)) Host_Error ("ED_ParseEntity: EOF without closing brace"); if (com_token[0] == '}') break; // 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; + anglehack = !strcmp (com_token, "angle"); + if (anglehack) + strlcpy (com_token, "angles", sizeof (com_token)); // 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 + strlcpy (com_token, "light_lev", sizeof (com_token)); // hack for single light def - strcpy (keyname, com_token); + strlcpy (keyname, com_token, sizeof (keyname)); // another hack to fix heynames with trailing spaces n = strlen(keyname); @@ -985,7 +1042,7 @@ const char *ED_ParseEdict (const char *data, edict_t *ent) } // parse value - if (!COM_ParseToken (&data)) + if (!COM_ParseToken(&data, false)) Host_Error ("ED_ParseEntity: EOF without closing brace"); if (com_token[0] == '}') @@ -1008,16 +1065,16 @@ const char *ED_ParseEdict (const char *data, edict_t *ent) if (anglehack) { char temp[32]; - strcpy (temp, com_token); - sprintf (com_token, "0 %s 0", temp); + strlcpy (temp, com_token, sizeof (temp)); + snprintf (com_token, sizeof (com_token), "0 %s 0", temp); } - if (!ED_ParseEpair ((void *)ent->v, key, com_token)) + if (!ED_ParseEpair(ent, key, com_token)) Host_Error ("ED_ParseEdict: parse error"); } if (!init) - ent->free = true; + ent->e->free = true; return data; } @@ -1041,18 +1098,21 @@ to call ED_CallSpawnFunctions () to let the objects initialize themselves. void ED_LoadFromFile (const char *data) { edict_t *ent; - int inhibit; + int parsed, inhibited, spawned, died; mfunction_t *func; ent = NULL; - inhibit = 0; + parsed = 0; + inhibited = 0; + spawned = 0; + died = 0; pr_global_struct->time = sv.time; - + // parse ents while (1) { // parse the opening brace - if (!COM_ParseToken (&data)) + if (!COM_ParseToken(&data, false)) break; if (com_token[0] != '{') Host_Error ("ED_LoadFromFile: found %s when expecting {",com_token); @@ -1062,14 +1122,15 @@ void ED_LoadFromFile (const char *data) else ent = ED_Alloc (); data = ED_ParseEdict (data, ent); + parsed++; // remove things from different skill levels or deathmatch if (deathmatch.integer) { if (((int)ent->v->spawnflags & SPAWNFLAG_NOT_DEATHMATCH)) { - ED_Free (ent); - inhibit++; + ED_Free (ent); + inhibited++; continue; } } @@ -1078,7 +1139,7 @@ void ED_LoadFromFile (const char *data) || (current_skill >= 2 && ((int)ent->v->spawnflags & SPAWNFLAG_NOT_HARD ))) { ED_Free (ent); - inhibit++; + inhibited++; continue; } @@ -1109,9 +1170,12 @@ void ED_LoadFromFile (const char *data) pr_global_struct->self = EDICT_TO_PROG(ent); PR_ExecuteProgram (func - pr_functions, ""); + spawned++; + if (ent->e->free) + died++; } - Con_DPrintf ("%i entities inhibited\n", inhibit); + Con_DPrintf ("%i entities parsed, %i inhibited, %i spawned (%i removed self, %i stayed)\n", parsed, inhibited, spawned, died, spawned - died); } @@ -1158,7 +1222,10 @@ dpfield_t dpfields[] = {ev_float, "ping"}, {ev_vector, "movement"}, {ev_float, "pmodel"}, - {ev_vector, "punchvector"} + {ev_vector, "punchvector"}, + {ev_float, "clientcolors"}, + {ev_entity, "tag_entity"}, + {ev_float, "tag_index"} }; /* @@ -1166,6 +1233,7 @@ dpfield_t dpfields[] = PR_LoadProgs =============== */ +extern void PR_Cmd_Reset (void); void PR_LoadProgs (void) { int i; @@ -1380,6 +1448,7 @@ void PR_LoadProgs (void) FindEdictFieldOffsets(); // LordHavoc: update field offset list PR_Execute_ProgsLoaded(); + PR_Cmd_Reset(); } @@ -1397,10 +1466,10 @@ void PR_Fields_f (void) return; } counts = Mem_Alloc(tempmempool, progs->numfielddefs * sizeof(int)); - for (ednum = 0;ednum < MAX_EDICTS;ednum++) + for (ednum = 0;ednum < sv.max_edicts;ednum++) { ed = EDICT_NUM(ednum); - if (ed->free) + if (ed->e->free) continue; for (i = 1;i < progs->numfielddefs;i++) { @@ -1432,32 +1501,32 @@ void PR_Fields_f (void) switch(d->type & ~DEF_SAVEGLOBAL) { case ev_string: - strcat(tempstring, "string "); + strlcat (tempstring, "string ", sizeof (tempstring)); break; case ev_entity: - strcat(tempstring, "entity "); + strlcat (tempstring, "entity ", sizeof (tempstring)); break; case ev_function: - strcat(tempstring, "function "); + strlcat (tempstring, "function ", sizeof (tempstring)); break; case ev_field: - strcat(tempstring, "field "); + strlcat (tempstring, "field ", sizeof (tempstring)); break; case ev_void: - strcat(tempstring, "void "); + strlcat (tempstring, "void ", sizeof (tempstring)); break; case ev_float: - strcat(tempstring, "float "); + strlcat (tempstring, "float ", sizeof (tempstring)); break; case ev_vector: - strcat(tempstring, "vector "); + strlcat (tempstring, "vector ", sizeof (tempstring)); break; case ev_pointer: - strcat(tempstring, "pointer "); + strlcat (tempstring, "pointer ", sizeof (tempstring)); break; default: - sprintf (tempstring2, "bad type %i ", d->type & ~DEF_SAVEGLOBAL); - strcat(tempstring, tempstring2); + snprintf (tempstring2, sizeof (tempstring2), "bad type %i ", d->type & ~DEF_SAVEGLOBAL); + strlcat (tempstring, tempstring2, sizeof (tempstring)); break; } if (strlen(name) > 256) @@ -1467,12 +1536,12 @@ void PR_Fields_f (void) tempstring2[259] = 0; name = tempstring2; } - strcat(tempstring, name); + strcat (tempstring, name); for (j = strlen(name);j < 25;j++) strcat(tempstring, " "); - sprintf(tempstring2, "%5d", counts[i]); - strcat(tempstring, tempstring2); - strcat(tempstring, "\n"); + snprintf (tempstring2, sizeof (tempstring2), "%5d", counts[i]); + strlcat (tempstring, tempstring2, sizeof (tempstring)); + strlcat (tempstring, "\n", sizeof (tempstring)); if (strlen(tempstring) >= 4096) { Con_Printf("%s", tempstring); @@ -1485,7 +1554,7 @@ void PR_Fields_f (void) } } Mem_Free(counts); - Con_Printf("%i entity fields (%i in use), totalling %i bytes per edict (%i in use), %i edicts, %i bytes total spent on edict fields (%i needed)\n", progs->entityfields, used, progs->entityfields * 4, usedamount * 4, MAX_EDICTS, progs->entityfields * 4 * MAX_EDICTS, usedamount * 4 * MAX_EDICTS); + Con_Printf("%i entity fields (%i in use), totalling %i bytes per edict (%i in use), %i edicts allocated, %i bytes total spent on edict fields (%i needed)\n", progs->entityfields, used, progs->entityfields * 4, usedamount * 4, sv.max_edicts, progs->entityfields * 4 * sv.max_edicts, usedamount * 4 * sv.max_edicts); } void PR_Globals_f (void) @@ -1506,11 +1575,13 @@ void PR_Globals_f (void) PR_Init =============== */ +extern void PR_Cmd_Init(void); void PR_Init (void) { Cmd_AddCommand ("edict", ED_PrintEdict_f); Cmd_AddCommand ("edicts", ED_PrintEdicts); Cmd_AddCommand ("edictcount", ED_Count); + Cmd_AddCommand ("edictset", ED_EdictSet_f); Cmd_AddCommand ("profile", PR_Profile_f); Cmd_AddCommand ("pr_fields", PR_Fields_f); Cmd_AddCommand ("pr_globals", PR_Globals_f); @@ -1549,15 +1620,24 @@ void PR_Init (void) progs_mempool = Mem_AllocPool("progs.dat"); edictstring_mempool = Mem_AllocPool("edict strings"); + + PR_Cmd_Init(); } // LordHavoc: turned EDICT_NUM into a #define for speed reasons -edict_t *EDICT_NUM_ERROR(int n) +edict_t *EDICT_NUM_ERROR(int n, char *filename, int fileline) { - Host_Error ("EDICT_NUM: bad number %i", n); + Host_Error ("EDICT_NUM: bad number %i (called at %s:%i)", n, filename, fileline); return NULL; } +/* +int NUM_FOR_EDICT_ERROR(edict_t *e) +{ + Host_Error ("NUM_FOR_EDICT: bad pointer %p (world is %p, entity number would be %i)", e, sv.edicts, e - sv.edicts); + return 0; +} + int NUM_FOR_EDICT(edict_t *e) { int n; @@ -1567,13 +1647,13 @@ int NUM_FOR_EDICT(edict_t *e) return n; } -int NoCrash_NUM_FOR_EDICT(edict_t *e) -{ - return e - sv.edicts; -} +//int NoCrash_NUM_FOR_EDICT(edict_t *e) +//{ +// return e - sv.edicts; +//} //#define EDICT_TO_PROG(e) ((qbyte *)(((edict_t *)e)->v) - (qbyte *)(sv.edictsfields)) -//#define PROG_TO_EDICT(e) (sv.edictstable[(e) / (progs->entityfields * 4)]) +//#define PROG_TO_EDICT(e) (sv.edicts + ((e) / (progs->entityfields * 4))) int EDICT_TO_PROG(edict_t *e) { int n; @@ -1587,7 +1667,8 @@ edict_t *PROG_TO_EDICT(int n) { if ((unsigned int)n >= (unsigned int)sv.max_edicts) Host_Error("PROG_TO_EDICT: invalid edict number %i\n", n); - return sv.edictstable[n]; // EXPERIMENTAL - //return sv.edictstable[(n) / (progs->entityfields * 4)]; + return sv.edicts + n; // EXPERIMENTAL + //return sv.edicts + ((n) / (progs->entityfields * 4)); } +*/