]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - prvm_exec.c
fix q1bsp detection of stuck entities (needed some more parentheses)
[xonotic/darkplaces.git] / prvm_exec.c
index e7fb591a04550789d74c5e709c6d699aa842d70b..1d05c082bec6c675eaaa375be276fe18bbc4583e 100644 (file)
@@ -266,31 +266,12 @@ void PRVM_StackTrace (void)
 }
 
 
-/*
-============
-PRVM_Profile_f
-
-============
-*/
-void PRVM_Profile_f (void)
+void PRVM_Profile (int maxfunctions, int mininstructions)
 {
        mfunction_t *f, *best;
-       int i, num, howmany;
+       int i, num;
        double max;
 
-       howmany = 1<<30;
-       if (Cmd_Argc() == 3)
-               howmany = atoi(Cmd_Argv(2));
-       else if (Cmd_Argc() != 2)
-       {
-               Con_Print("prvm_profile <program name>\n");
-               return;
-       }
-
-       PRVM_Begin;
-       if(!PRVM_SetProgFromString(Cmd_Argv(1)))
-               return;
-
        Con_Printf( "%s Profile:\n[CallCount] [Statements] [BuiltinCost]\n", PRVM_NAME );
 
        num = 0;
@@ -309,7 +290,7 @@ void PRVM_Profile_f (void)
                }
                if (best)
                {
-                       if (num < howmany)
+                       if (num < maxfunctions && max >= mininstructions)
                        {
                                if (best->first_statement < 0)
                                        Con_Printf("%9.0f ----- builtin ----- %s\n", best->callcount, PRVM_GetString(best->s_name));
@@ -322,6 +303,32 @@ void PRVM_Profile_f (void)
                        best->callcount = 0;
                }
        } while (best);
+}
+
+/*
+============
+PRVM_Profile_f
+
+============
+*/
+void PRVM_Profile_f (void)
+{
+       int howmany;
+
+       howmany = 1<<30;
+       if (Cmd_Argc() == 3)
+               howmany = atoi(Cmd_Argv(2));
+       else if (Cmd_Argc() != 2)
+       {
+               Con_Print("prvm_profile <program name>\n");
+               return;
+       }
+
+       PRVM_Begin;
+       if(!PRVM_SetProgFromString(Cmd_Argv(1)))
+               return;
+
+       PRVM_Profile(howmany, 1);
 
        PRVM_End;
 }
@@ -356,7 +363,8 @@ void PRVM_PrintState(void)
        PRVM_StackTrace ();
 }
 
-void PRVM_Crash()
+extern sizebuf_t vm_tempstringsbuf;
+void PRVM_Crash(void)
 {
        if (prog == NULL)
                return;
@@ -371,6 +379,9 @@ void PRVM_Crash()
        prog->depth = 0;
        prog->localstack_used = 0;
 
+       // delete all tempstrings (FIXME: is this safe in VM->engine->VM recursion?)
+       vm_tempstringsbuf.cursize = 0;
+
        // reset the prog pointer
        prog = NULL;
 }
@@ -479,6 +490,7 @@ extern cvar_t prvm_traceqc;
 extern cvar_t prvm_statementprofiling;
 extern int             PRVM_ED_FindFieldOffset (const char *field);
 extern ddef_t* PRVM_ED_FindGlobal(const char *name);
+extern sizebuf_t vm_tempstringsbuf;
 void PRVM_ExecuteProgram (func_t fnum, const char *errormessage)
 {
        dstatement_t    *st, *startst;
@@ -486,6 +498,7 @@ void PRVM_ExecuteProgram (func_t fnum, const char *errormessage)
        prvm_edict_t    *ed;
        prvm_eval_t     *ptr;
        int             jumpcount, cachedpr_trace, exitdepth;
+       int             restorevm_tempstringsbuf_cursize;
 
        if (!fnum || fnum >= (unsigned int)prog->progs->numfunctions)
        {
@@ -496,6 +509,9 @@ void PRVM_ExecuteProgram (func_t fnum, const char *errormessage)
 
        f = &prog->functions[fnum];
 
+       // after executing this function, delete all tempstrings it created
+       restorevm_tempstringsbuf_cursize = vm_tempstringsbuf.cursize;
+
        prog->trace = prvm_traceqc.integer;
 
        // we know we're done when pr_depth drops to this
@@ -578,4 +594,10 @@ chooseexecprogram:
                        }
                }
        }
+
+cleanup:
+       if (developer.integer >= 200 && vm_tempstringsbuf.cursize > restorevm_tempstringsbuf_cursize)
+               Con_Printf("PRVM_ExecuteProgram: %s used %i bytes of tempstrings\n", PRVM_GetString(prog->functions[fnum].s_name), vm_tempstringsbuf.cursize - restorevm_tempstringsbuf_cursize);
+       // delete tempstrings created by this function
+       vm_tempstringsbuf.cursize = restorevm_tempstringsbuf_cursize;
 }