X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=prvm_edict.c;h=123052e4b80b7cbc40efb5e1a1f19943cb63f208;hb=6309ef89ca851837c91d9aec4bb7786a70a84117;hp=456ffb5bedc7dcacd1e30cabadaaa3bc1d714c26;hpb=321a67123284c38c22f8edd418913615ee0c2682;p=xonotic%2Fdarkplaces.git diff --git a/prvm_edict.c b/prvm_edict.c index 456ffb5b..123052e4 100644 --- a/prvm_edict.c +++ b/prvm_edict.c @@ -39,6 +39,8 @@ cvar_t prvm_backtraceforwarnings = {0, "prvm_backtraceforwarnings", "0", "print cvar_t prvm_leaktest = {0, "prvm_leaktest", "0", "try to detect memory leaks in strings or entities"}; cvar_t prvm_leaktest_ignore_classnames = {0, "prvm_leaktest_ignore_classnames", "", "classnames of entities to NOT leak check because they are found by find(world, classname, ...) but are actually spawned by QC code (NOT map entities)"}; cvar_t prvm_errordump = {0, "prvm_errordump", "0", "write a savegame on crash to crash-server.dmp"}; +cvar_t prvm_reuseedicts_startuptime = {0, "prvm_reuseedicts_startuptime", "2", "allows immediate re-use of freed entity slots during start of new level (value in seconds)"}; +cvar_t prvm_reuseedicts_neverinsameframe = {0, "prvm_reuseedicts_neverinsameframe", "1", "never allows re-use of freed entity slots during same frame"}; qboolean prvm_runawaycheck = true; @@ -247,7 +249,9 @@ qboolean PRVM_ED_CanAlloc(prvm_edict_t *e) { if(!e->priv.required->free) return false; - if(e->priv.required->freetime < prog->starttime + 2) + if(realtime <= e->priv.required->freetime && prvm_reuseedicts_neverinsameframe.integer) + return false; // never allow reuse in same frame (causes networking trouble) + if(e->priv.required->freetime < prog->starttime + prvm_reuseedicts_startuptime.value) return true; if(realtime > e->priv.required->freetime + 1) return true; @@ -1148,6 +1152,105 @@ void PRVM_GameCommand_Menu_f(void) PRVM_GameCommand("menu", "menu_cmd"); } +/* +============= +PRVM_ED_EdictGet_f + +Console command to load a field of a specified edict +============= +*/ +void PRVM_ED_EdictGet_f(void) +{ + prvm_edict_t *ed; + ddef_t *key; + const char *s; + prvm_eval_t *v; + + if(Cmd_Argc() != 4 && Cmd_Argc() != 5) + { + Con_Print("prvm_edictget []\n"); + return; + } + + PRVM_Begin; + if(!PRVM_SetProgFromString(Cmd_Argv(1))) + { + Con_Printf("Wrong program name %s !\n", Cmd_Argv(1)); + return; + } + + ed = PRVM_EDICT_NUM(atoi(Cmd_Argv(2))); + + if((key = PRVM_ED_FindField(Cmd_Argv(3))) == 0) + { + Con_Printf("Key %s not found !\n", Cmd_Argv(3)); + goto fail; + } + + v = (prvm_eval_t *)((char *)ed->fields.vp + key->ofs*4); + s = PRVM_UglyValueString(key->type, v); + if(Cmd_Argc() == 5) + { + cvar_t *cvar = Cvar_FindVar(Cmd_Argv(4)); + if (cvar && cvar->flags & CVAR_READONLY) + { + Con_Printf("prvm_edictget: %s is read-only\n", cvar->name); + goto fail; + } + Cvar_Get(Cmd_Argv(4), s, 0, NULL); + } + else + Con_Printf("%s\n", s); + +fail: + PRVM_End; +} + +void PRVM_ED_GlobalGet_f(void) +{ + ddef_t *key; + const char *s; + prvm_eval_t *v; + + if(Cmd_Argc() != 3 && Cmd_Argc() != 4) + { + Con_Print("prvm_globalget []\n"); + return; + } + + PRVM_Begin; + if(!PRVM_SetProgFromString(Cmd_Argv(1))) + { + Con_Printf("Wrong program name %s !\n", Cmd_Argv(1)); + return; + } + + key = PRVM_ED_FindGlobal(Cmd_Argv(2)); + if(!key) + { + Con_Printf( "No global '%s' in %s!\n", Cmd_Argv(2), Cmd_Argv(1) ); + goto fail; + } + + v = (prvm_eval_t *) &prog->globals.generic[key->ofs]; + s = PRVM_UglyValueString(key->type, v); + if(Cmd_Argc() == 4) + { + cvar_t *cvar = Cvar_FindVar(Cmd_Argv(3)); + if (cvar && cvar->flags & CVAR_READONLY) + { + Con_Printf("prvm_globalget: %s is read-only\n", cvar->name); + goto fail; + } + Cvar_Get(Cmd_Argv(3), s, 0, NULL); + } + else + Con_Printf("%s\n", s); + +fail: + PRVM_End; +} + /* ============= PRVM_ED_EdictSet_f @@ -1493,6 +1596,7 @@ void PRVM_FindOffsets(void) prog->fieldoffsets.glow_color = PRVM_ED_FindFieldOffset("glow_color"); prog->fieldoffsets.glow_size = PRVM_ED_FindFieldOffset("glow_size"); prog->fieldoffsets.glow_trail = PRVM_ED_FindFieldOffset("glow_trail"); + prog->fieldoffsets.glowmod = PRVM_ED_FindFieldOffset("glowmod"); prog->fieldoffsets.gravity = PRVM_ED_FindFieldOffset("gravity"); prog->fieldoffsets.groundentity = PRVM_ED_FindFieldOffset("groundentity"); prog->fieldoffsets.hull = PRVM_ED_FindFieldOffset("hull"); @@ -1531,6 +1635,26 @@ void PRVM_FindOffsets(void) prog->fieldoffsets.yaw_speed = PRVM_ED_FindFieldOffset("yaw_speed"); prog->fieldoffsets.bouncefactor = PRVM_ED_FindFieldOffset("bouncefactor"); prog->fieldoffsets.bouncestop = PRVM_ED_FindFieldOffset("bouncestop"); + + prog->fieldoffsets.solid = PRVM_ED_FindFieldOffset("solid"); + prog->fieldoffsets.movetype = PRVM_ED_FindFieldOffset("movetype"); + prog->fieldoffsets.modelindex = PRVM_ED_FindFieldOffset("modelindex"); + prog->fieldoffsets.mins = PRVM_ED_FindFieldOffset("mins"); + prog->fieldoffsets.maxs = PRVM_ED_FindFieldOffset("maxs"); + prog->fieldoffsets.mass = PRVM_ED_FindFieldOffset("mass"); + prog->fieldoffsets.origin = PRVM_ED_FindFieldOffset("origin"); + prog->fieldoffsets.velocity = PRVM_ED_FindFieldOffset("velocity"); + //prog->fieldoffsets.axis_forward = PRVM_ED_FindFieldOffset("axis_forward"); + //prog->fieldoffsets.axis_left = PRVM_ED_FindFieldOffset("axis_left"); + //prog->fieldoffsets.axis_up = PRVM_ED_FindFieldOffset("axis_up"); + //prog->fieldoffsets.spinvelocity = PRVM_ED_FindFieldOffset("spinvelocity"); + prog->fieldoffsets.angles = PRVM_ED_FindFieldOffset("angles"); + prog->fieldoffsets.avelocity = PRVM_ED_FindFieldOffset("avelocity"); + prog->fieldoffsets.aiment = PRVM_ED_FindFieldOffset("aiment"); + prog->fieldoffsets.enemy = PRVM_ED_FindFieldOffset("enemy"); + prog->fieldoffsets.jointtype = PRVM_ED_FindFieldOffset("jointtype"); + prog->fieldoffsets.movedir = PRVM_ED_FindFieldOffset("movedir"); + prog->funcoffsets.CSQC_ConsoleCommand = PRVM_ED_FindFunctionOffset("CSQC_ConsoleCommand"); prog->funcoffsets.CSQC_Ent_Remove = PRVM_ED_FindFunctionOffset("CSQC_Ent_Remove"); prog->funcoffsets.CSQC_Ent_Spawn = PRVM_ED_FindFunctionOffset("CSQC_Ent_Spawn"); @@ -1571,6 +1695,7 @@ void PRVM_FindOffsets(void) prog->globaloffsets.gettaginfo_parent = PRVM_ED_FindGlobalOffset("gettaginfo_parent"); prog->globaloffsets.gettaginfo_right = PRVM_ED_FindGlobalOffset("gettaginfo_right"); prog->globaloffsets.gettaginfo_up = PRVM_ED_FindGlobalOffset("gettaginfo_up"); + prog->globaloffsets.transparent_offset = PRVM_ED_FindGlobalOffset("transparent_offset"); prog->globaloffsets.intermission = PRVM_ED_FindGlobalOffset("intermission"); prog->globaloffsets.require_spawnfunc_prefix = PRVM_ED_FindGlobalOffset("require_spawnfunc_prefix"); prog->globaloffsets.sb_showscores = PRVM_ED_FindGlobalOffset("sb_showscores"); @@ -2189,12 +2314,15 @@ void PRVM_Init (void) Cmd_AddCommand ("prvm_edicts", PRVM_ED_PrintEdicts_f, "prints all data about all entities in the selected VM (server, client, menu)"); Cmd_AddCommand ("prvm_edictcount", PRVM_ED_Count_f, "prints number of active entities in the selected VM (server, client, menu)"); Cmd_AddCommand ("prvm_profile", PRVM_Profile_f, "prints execution statistics about the most used QuakeC functions in the selected VM (server, client, menu)"); + Cmd_AddCommand ("prvm_childprofile", PRVM_ChildProfile_f, "prints execution statistics about the most used QuakeC functions in the selected VM (server, client, menu), sorted by time taken in function with child calls"); Cmd_AddCommand ("prvm_callprofile", PRVM_CallProfile_f, "prints execution statistics about the most time consuming QuakeC calls from the engine in the selected VM (server, client, menu)"); Cmd_AddCommand ("prvm_fields", PRVM_Fields_f, "prints usage statistics on properties (how many entities have non-zero values) in the selected VM (server, client, menu)"); Cmd_AddCommand ("prvm_globals", PRVM_Globals_f, "prints all global variables in the selected VM (server, client, menu)"); Cmd_AddCommand ("prvm_global", PRVM_Global_f, "prints value of a specified global variable in the selected VM (server, client, menu)"); Cmd_AddCommand ("prvm_globalset", PRVM_GlobalSet_f, "sets value of a specified global variable in the selected VM (server, client, menu)"); Cmd_AddCommand ("prvm_edictset", PRVM_ED_EdictSet_f, "changes value of a specified property of a specified entity in the selected VM (server, client, menu)"); + Cmd_AddCommand ("prvm_edictget", PRVM_ED_EdictGet_f, "retrieves the value of a specified property of a specified entity in the selected VM (server, client menu) into a cvar or to the console"); + Cmd_AddCommand ("prvm_globalget", PRVM_ED_GlobalGet_f, "retrieves the value of a specified global variable in the selected VM (server, client menu) into a cvar or to the console"); Cmd_AddCommand ("prvm_printfunction", PRVM_PrintFunction_f, "prints a disassembly (QuakeC instructions) of the specified function in the selected VM (server, client, menu)"); Cmd_AddCommand ("cl_cmd", PRVM_GameCommand_Client_f, "calls the client QC function GameCommand with the supplied string as argument"); Cmd_AddCommand ("menu_cmd", PRVM_GameCommand_Menu_f, "calls the menu QC function GameCommand with the supplied string as argument"); @@ -2209,6 +2337,8 @@ void PRVM_Init (void) Cvar_RegisterVariable (&prvm_leaktest); Cvar_RegisterVariable (&prvm_leaktest_ignore_classnames); Cvar_RegisterVariable (&prvm_errordump); + Cvar_RegisterVariable (&prvm_reuseedicts_startuptime); + Cvar_RegisterVariable (&prvm_reuseedicts_neverinsameframe); // COMMANDLINEOPTION: PRVM: -norunaway disables the runaway loop check (it might be impossible to exit DarkPlaces if used!) prvm_runawaycheck = !COM_CheckParm("-norunaway"); @@ -2235,7 +2365,7 @@ void PRVM_InitProg(int prognr) prog->starttime = Sys_DoubleTime(); prog->error_cmd = Host_Error; - prog->leaktest_active = prvm_leaktest.integer; + prog->leaktest_active = prvm_leaktest.integer != 0; } int PRVM_GetProgNr(void)