X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=pr_edict.c;h=8b41df06bf3d109ee0e3329c3d47b95126dca9dc;hb=d6d1a3a746c459e53830bb1049b49a2f22b14e93;hp=884bff1af04d70374d2f6f3b584f0a959dd050e5;hpb=8a1bae9e4de4dbb479679b2c77765beb689e33b8;p=xonotic%2Fdarkplaces.git diff --git a/pr_edict.c b/pr_edict.c index 884bff1a..8b41df06 100644 --- a/pr_edict.c +++ b/pr_edict.c @@ -34,8 +34,7 @@ int pr_edictareasize; // LordHavoc: in bytes unsigned short pr_crc; -mempool_t *progs_mempool; -mempool_t *edictstring_mempool; +mempool_t *serverprogs_mempool; int type_size[8] = {1,sizeof(string_t)/4,1,3,1,1,sizeof(func_t)/4,sizeof(void *)/4}; @@ -134,6 +133,8 @@ int eval_cursor_trace_start; int eval_cursor_trace_endpos; int eval_cursor_trace_ent; int eval_colormod; +int eval_playermodel; +int eval_playerskin; mfunction_t *SV_PlayerPhysicsQC; mfunction_t *EndFrameQC; @@ -200,6 +201,8 @@ void FindEdictFieldOffsets(void) eval_cursor_trace_endpos = FindFieldOffset("cursor_trace_endpos"); eval_cursor_trace_ent = FindFieldOffset("cursor_trace_ent"); eval_colormod = FindFieldOffset("colormod"); + eval_playermodel = FindFieldOffset("playermodel"); + eval_playerskin = FindFieldOffset("playerskin"); // LordHavoc: allowing QuakeC to override the player movement code SV_PlayerPhysicsQC = ED_FindFunction ("SV_PlayerPhysics"); @@ -236,8 +239,10 @@ void ED_ClearEdict (edict_t *e) if ((val = GETEDICTFIELDVALUE(e, eval_clientcolors))) val->_float = svs.clients[num].colors; // NEXUIZ_PLAYERMODEL and NEXUIZ_PLAYERSKIN - e->v->playermodel = PR_SetString(svs.clients[num].playermodel); - e->v->playerskin = PR_SetString(svs.clients[num].playerskin); + if( eval_playermodel ) + GETEDICTFIELDVALUE(host_client->edict, eval_playermodel)->string = PR_SetString(svs.clients[num].playermodel); + if( eval_playerskin ) + GETEDICTFIELDVALUE(host_client->edict, eval_playerskin)->string = PR_SetString(svs.clients[num].playerskin); } } @@ -433,34 +438,34 @@ char *PR_ValueString (etype_t type, eval_t *val) //n = NoCrash_NUM_FOR_EDICT(PROG_TO_EDICT(val->edict)); n = val->edict; if (n < 0 || n >= MAX_EDICTS) - snprintf (line, sizeof (line), "entity %i (invalid!)", n); + dpsnprintf (line, sizeof (line), "entity %i (invalid!)", n); else - snprintf (line, sizeof (line), "entity %i", n); + dpsnprintf (line, sizeof (line), "entity %i", n); break; case ev_function: f = pr_functions + val->function; - snprintf (line, sizeof (line), "%s()", PR_GetString(f->s_name)); + dpsnprintf (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)); + dpsnprintf (line, sizeof (line), ".%s", PR_GetString(def->s_name)); break; case ev_void: - snprintf (line, sizeof (line), "void"); + dpsnprintf (line, sizeof (line), "void"); break; case ev_float: // LordHavoc: changed from %5.1f to %10.4f - snprintf (line, sizeof (line), "%10.4f", val->_float); + dpsnprintf (line, sizeof (line), "%10.4f", val->_float); break; case ev_vector: // LordHavoc: changed from %5.1f to %10.4f - snprintf (line, sizeof (line), "'%10.4f %10.4f %10.4f'", val->vector[0], val->vector[1], val->vector[2]); + dpsnprintf (line, sizeof (line), "'%10.4f %10.4f %10.4f'", val->vector[0], val->vector[1], val->vector[2]); break; case ev_pointer: - snprintf (line, sizeof (line), "pointer"); + dpsnprintf (line, sizeof (line), "pointer"); break; default: - snprintf (line, sizeof (line), "bad type %i", type); + dpsnprintf (line, sizeof (line), "bad type %i", type); break; } @@ -511,7 +516,7 @@ char *PR_UglyValueString (etype_t type, eval_t *val) line[i] = '\0'; break; case ev_entity: - snprintf (line, sizeof (line), "%i", NUM_FOR_EDICT(PROG_TO_EDICT(val->edict))); + dpsnprintf (line, sizeof (line), "%i", NUM_FOR_EDICT(PROG_TO_EDICT(val->edict))); break; case ev_function: f = pr_functions + val->function; @@ -519,19 +524,19 @@ char *PR_UglyValueString (etype_t type, eval_t *val) break; case ev_field: def = ED_FieldAtOfs ( val->_int ); - snprintf (line, sizeof (line), ".%s", PR_GetString(def->s_name)); + dpsnprintf (line, sizeof (line), ".%s", PR_GetString(def->s_name)); break; case ev_void: - snprintf (line, sizeof (line), "void"); + dpsnprintf (line, sizeof (line), "void"); break; case ev_float: - snprintf (line, sizeof (line), "%f", val->_float); + dpsnprintf (line, sizeof (line), "%f", val->_float); break; case ev_vector: - snprintf (line, sizeof (line), "%f %f %f", val->vector[0], val->vector[1], val->vector[2]); + dpsnprintf (line, sizeof (line), "%f %f %f", val->vector[0], val->vector[1], val->vector[2]); break; default: - snprintf (line, sizeof (line), "bad type %i", type); + dpsnprintf (line, sizeof (line), "bad type %i", type); break; } @@ -557,11 +562,11 @@ char *PR_GlobalString (int ofs) val = (void *)&pr_globals[ofs]; def = ED_GlobalAtOfs(ofs); if (!def) - snprintf (line, sizeof (line), "%i(?)", ofs); + dpsnprintf (line, sizeof (line), "%i(?)", ofs); else { s = PR_ValueString (def->type, val); - snprintf (line, sizeof (line), "%i(%s)%s", ofs, PR_GetString(def->s_name), s); + dpsnprintf (line, sizeof (line), "%i(%s)%s", ofs, PR_GetString(def->s_name), s); } i = strlen(line); @@ -580,9 +585,9 @@ char *PR_GlobalStringNoContents (int ofs) def = ED_GlobalAtOfs(ofs); if (!def) - snprintf (line, sizeof (line), "%i(?)", ofs); + dpsnprintf (line, sizeof (line), "%i(?)", ofs); else - snprintf (line, sizeof (line), "%i(%s)", ofs, PR_GetString(def->s_name)); + dpsnprintf (line, sizeof (line), "%i(%s)", ofs, PR_GetString(def->s_name)); i = strlen(line); for ( ; i<20 ; i++) @@ -619,7 +624,7 @@ void ED_Print(edict_t *ed) } tempstring[0] = 0; - snprintf (tempstring, sizeof (tempstring), "\nEDICT %i:\n", NUM_FOR_EDICT(ed)); + dpsnprintf (tempstring, sizeof (tempstring), "\nEDICT %i:\n", NUM_FOR_EDICT(ed)); for (i=1 ; inumfielddefs ; i++) { d = &pr_fielddefs[i]; @@ -915,7 +920,7 @@ char *ED_NewString (const char *string) int i,l; l = strlen(string) + 1; - new = Mem_Alloc(edictstring_mempool, l); + new = PR_Alloc(l); new_p = new; for (i=0 ; i< l ; i++) @@ -925,6 +930,8 @@ char *ED_NewString (const char *string) i++; if (string[i] == 'n') *new_p++ = '\n'; + else if (string[i] == 'r') + *new_p++ = '\r'; else *new_p++ = '\\'; } @@ -1002,7 +1009,7 @@ qboolean ED_ParseEpair(edict_t *ent, ddef_t *key, const char *s) Con_DPrintf("ED_ParseEpair: Can't find field %s\n", s); return false; } - //val->_int = G_INT(def->ofs); AK Please check this - seems to be an org. quake bug + //val->_int = G_INT(def->ofs); // AK Please check this - seems to be an org. quake bug val->_int = def->ofs; break; @@ -1100,7 +1107,7 @@ const char *ED_ParseEdict (const char *data, edict_t *ent) { char temp[32]; strlcpy (temp, com_token, sizeof (temp)); - snprintf (com_token, sizeof (com_token), "0 %s 0", temp); + dpsnprintf (com_token, sizeof (com_token), "0 %s 0", temp); } if (!ED_ParseEpair(ent, key, com_token)) @@ -1159,24 +1166,26 @@ void ED_LoadFromFile (const char *data) parsed++; // remove things from different skill levels or deathmatch - if (deathmatch.integer) + if (gamemode != GAME_TRANSFUSION) //Transfusion does this in QC { - if (((int)ent->v->spawnflags & SPAWNFLAG_NOT_DEATHMATCH)) + if (deathmatch.integer) + { + if (((int)ent->v->spawnflags & SPAWNFLAG_NOT_DEATHMATCH)) + { + ED_Free (ent); + inhibited++; + 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); inhibited++; 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); - inhibited++; - continue; - } - // // immediately call spawn function // @@ -1283,23 +1292,25 @@ PR_LoadProgs =============== */ extern void PR_Cmd_Reset (void); -void PR_LoadProgs (void) +void PR_LoadProgs (const char *progsname) { int i; dstatement_t *st; ddef_t *infielddefs; dfunction_t *dfunctions; + if (!progsname || !*progsname) + Host_Error("PR_LoadProgs: passed empty progsname"); + // flush the non-C variable lookup cache for (i=0 ; iofs_fielddefs); - pr_fielddefs = Mem_Alloc(progs_mempool, (progs->numfielddefs + DPFIELDS) * sizeof(ddef_t)); + pr_fielddefs = PR_Alloc((progs->numfielddefs + DPFIELDS) * sizeof(ddef_t)); + pr_functions = PR_Alloc(sizeof(mfunction_t) * progs->numfunctions); pr_statements = (dstatement_t *)((qbyte *)progs + progs->ofs_statements); @@ -1340,7 +1352,6 @@ void PR_LoadProgs (void) pr_statements[i].c = LittleShort(pr_statements[i].c); } - pr_functions = Mem_Alloc(progs_mempool, sizeof(mfunction_t) * progs->numfunctions); for (i = 0;i < progs->numfunctions;i++) { pr_functions[i].first_statement = LittleLong (dfunctions[i].first_statement); @@ -1568,7 +1579,7 @@ void PR_Fields_f (void) strlcat (tempstring, "pointer ", sizeof (tempstring)); break; default: - snprintf (tempstring2, sizeof (tempstring2), "bad type %i ", d->type & ~DEF_SAVEGLOBAL); + dpsnprintf (tempstring2, sizeof (tempstring2), "bad type %i ", d->type & ~DEF_SAVEGLOBAL); strlcat (tempstring, tempstring2, sizeof (tempstring)); break; } @@ -1582,7 +1593,7 @@ void PR_Fields_f (void) strcat (tempstring, name); for (j = strlen(name);j < 25;j++) strcat(tempstring, " "); - snprintf (tempstring2, sizeof (tempstring2), "%5d", counts[i]); + dpsnprintf (tempstring2, sizeof (tempstring2), "%5d", counts[i]); strlcat (tempstring, tempstring2, sizeof (tempstring)); strlcat (tempstring, "\n", sizeof (tempstring)); if (strlen(tempstring) >= 4096) @@ -1661,12 +1672,42 @@ void PR_Init (void) Cvar_RegisterVariable (&pr_boundscheck); Cvar_RegisterVariable (&pr_traceqc); - progs_mempool = Mem_AllocPool("progs.dat", 0, NULL); - edictstring_mempool = Mem_AllocPool("edict strings", 0, NULL); + serverprogs_mempool = Mem_AllocPool("server progs", 0, NULL); PR_Cmd_Init(); } +/* +=============== +PR_Shutdown +=============== +*/ +extern void PR_Cmd_Shutdown(void); +void PR_Shutdown (void) +{ + PR_Cmd_Shutdown(); + + Mem_FreePool(&serverprogs_mempool); +} + +void *PR_Alloc(size_t buffersize) +{ + return Mem_Alloc(serverprogs_mempool, buffersize); +} + +void PR_Free(void *buffer) +{ + Mem_Free(buffer); +} + +void PR_FreeAll(void) +{ + progs = NULL; + pr_fielddefs = NULL; + pr_functions = NULL; + Mem_EmptyPool(serverprogs_mempool); +} + // LordHavoc: turned EDICT_NUM into a #define for speed reasons edict_t *EDICT_NUM_ERROR(int n, char *filename, int fileline) {