]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - prvm_edict.c
renamed prvm_startupreuseedicttime to prvm_reuseedicts_startuptime
[xonotic/darkplaces.git] / prvm_edict.c
index dcda2ed67a747860b7b9d455175dea35d61cf2bc..da9dec068eef78b5a2932d1eef942e33939378a7 100644 (file)
@@ -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 <program name> <edict number> <field> [<cvar>]\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 <program name> <global> [<cvar>]\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
@@ -2189,12 +2292,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 +2315,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");