]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - pr_exec.c
changed a debugging notice about texture loading
[xonotic/darkplaces.git] / pr_exec.c
index 113941a9d1567dee06e7c49b31308c05b1d58941..259b5cbd9ac4256a0abb720c8942d17fe9e8a849 100644 (file)
--- a/pr_exec.c
+++ b/pr_exec.c
@@ -27,7 +27,7 @@ typedef struct
        dfunction_t             *f;
 } prstack_t;
 
-#define        MAX_STACK_DEPTH         32
+#define        MAX_STACK_DEPTH         256
 prstack_t      pr_stack[MAX_STACK_DEPTH];
 int                    pr_depth = 0;
 
@@ -36,7 +36,7 @@ int                   localstack[LOCALSTACK_SIZE];
 int                    localstack_used;
 
 
-qboolean       pr_trace;
+int                    pr_trace;
 dfunction_t    *pr_xfunction;
 int                    pr_xstatement;
 
@@ -146,7 +146,7 @@ PR_PrintStatement
 void PR_PrintStatement (dstatement_t *s)
 {
        int             i;
-       
+
        if ( (unsigned)s->op < sizeof(pr_opnames)/sizeof(pr_opnames[0]))
        {
                Con_Printf ("%s ",  pr_opnames[s->op]);
@@ -154,7 +154,7 @@ void PR_PrintStatement (dstatement_t *s)
                for ( ; i<10 ; i++)
                        Con_Printf (" ");
        }
-               
+
        if (s->op == OP_IF || s->op == OP_IFNOT)
                Con_Printf ("%sbranch %i",PR_GlobalString((unsigned short) s->a),s->b);
        else if (s->op == OP_GOTO)
@@ -163,15 +163,15 @@ void PR_PrintStatement (dstatement_t *s)
        }
        else if ( (unsigned)(s->op - OP_STORE_F) < 6)
        {
-               Con_Printf ("%s",PR_GlobalString((unsigned short) s->a));
+               Con_Printf ("%s", PR_GlobalString((unsigned short) s->a));
                Con_Printf ("%s", PR_GlobalStringNoContents((unsigned short) s->b));
        }
        else
        {
                if (s->a)
-                       Con_Printf ("%s",PR_GlobalString((unsigned short) s->a));
+                       Con_Printf ("%s", PR_GlobalString((unsigned short) s->a));
                if (s->b)
-                       Con_Printf ("%s",PR_GlobalString((unsigned short) s->b));
+                       Con_Printf ("%s", PR_GlobalString((unsigned short) s->b));
                if (s->c)
                        Con_Printf ("%s", PR_GlobalStringNoContents((unsigned short) s->c));
        }
@@ -197,7 +197,7 @@ void PR_StackTrace (void)
                if (!f)
                        Con_Printf ("<NULL FUNCTION>\n");
                else
-                       Con_Printf ("%12s : %s : statement %i\n", pr_strings + f->s_file, pr_strings + f->s_name, pr_stack[i].s - f->first_statement);
+                       Con_Printf ("%12s : %s : statement %i\n", PR_GetString(f->s_file), PR_GetString(f->s_name), pr_stack[i].s - f->first_statement);
        }
 }
 
@@ -232,7 +232,7 @@ void PR_Profile_f (void)
                if (best)
                {
                        if (num < 10)
-                               Con_Printf ("%7i %s\n", best->profile, pr_strings+best->s_name);
+                               Con_Printf ("%7i %s\n", best->profile, PR_GetString(best->s_name));
                        num++;
                        best->profile = 0;
                }
@@ -240,23 +240,18 @@ void PR_Profile_f (void)
 }
 
 
-/*
-============
-PR_RunError
-
-Aborts the currently executing function
-============
-*/
-void PR_RunError (char *error, ...)
+void PR_Crash(void)
 {
-       int                     i;
-       va_list         argptr;
-       char            string[1024];
-
-       va_start (argptr,error);
-       vsprintf (string,error,argptr);
-       va_end (argptr);
+       int i;
+       if (pr_depth < 1)
+       {
+               // kill the stack just to be sure
+               pr_depth = 0;
+               localstack_used = 0;
+               return;
+       }
 
+       Con_Printf("QuakeC crash report:\n");
        if (pr_xfunction)
        {
                for (i = -4;i <= 0;i++)
@@ -266,11 +261,10 @@ void PR_RunError (char *error, ...)
        else
                Con_Printf("null function executing??\n");
        PR_StackTrace ();
-       Con_Printf ("%s\n", string);
 
-       pr_depth = 0;           // dump the stack so host_error can shutdown functions
-
-       Host_Error ("Program error");
+       // dump the stack so host_error can shutdown functions
+       pr_depth = 0;
+       localstack_used = 0;
 }
 
 /*
@@ -293,18 +287,18 @@ int PR_EnterFunction (dfunction_t *f)
        int             i, j, c, o;
 
        if (!f)
-               PR_RunError ("PR_EnterFunction: NULL function\n");
+               Host_Error ("PR_EnterFunction: NULL function\n");
 
        pr_stack[pr_depth].s = pr_xstatement;
        pr_stack[pr_depth].f = pr_xfunction;
        pr_depth++;
        if (pr_depth >= MAX_STACK_DEPTH)
-               PR_RunError ("stack overflow");
+               Host_Error ("stack overflow");
 
 // save off any locals that the new function steps on
        c = f->locals;
        if (localstack_used + c > LOCALSTACK_SIZE)
-               PR_RunError ("PR_ExecuteProgram: locals stack overflow\n");
+               Host_Error ("PR_ExecuteProgram: locals stack overflow\n");
 
        for (i=0 ; i < c ; i++)
                localstack[localstack_used+i] = ((int *)pr_globals)[f->parm_start + i];
@@ -338,12 +332,12 @@ int PR_LeaveFunction (void)
                Host_Error ("prog stack underflow");
 
        if (!pr_xfunction)
-               PR_RunError ("PR_LeaveFunction: NULL function\n");
+               Host_Error ("PR_LeaveFunction: NULL function\n");
 // restore locals from the stack
        c = pr_xfunction->locals;
        localstack_used -= c;
        if (localstack_used < 0)
-               PR_RunError ("PR_ExecuteProgram: locals stack underflow\n");
+               Host_Error ("PR_ExecuteProgram: locals stack underflow\n");
 
        for (i=0 ; i < c ; i++)
                ((int *)pr_globals)[pr_xfunction->parm_start + i] = localstack[localstack_used+i];
@@ -354,6 +348,16 @@ int PR_LeaveFunction (void)
        return pr_stack[pr_depth].s;
 }
 
+void PR_ReInitStrings (void);
+void PR_Execute_ProgsLoaded(void)
+{
+       // dump the stack
+       pr_depth = 0;
+       localstack_used = 0;
+       // reset the string table
+       PR_ReInitStrings();
+}
+
 /*
 ====================
 PR_ExecuteProgram
@@ -364,7 +368,8 @@ PR_ExecuteProgram
 #define OPB ((eval_t *)&pr_globals[(unsigned short) st->b])
 #define OPC ((eval_t *)&pr_globals[(unsigned short) st->c])
 extern cvar_t pr_boundscheck;
-void PR_ExecuteProgram (func_t fnum, char *errormessage)
+extern cvar_t pr_traceqc;
+void PR_ExecuteProgram (func_t fnum, const char *errormessage)
 {
        dstatement_t    *st;
        dfunction_t     *f, *newf;
@@ -381,7 +386,7 @@ void PR_ExecuteProgram (func_t fnum, char *errormessage)
 
        f = &pr_functions[fnum];
 
-       pr_trace = false;
+       pr_trace = pr_traceqc.integer;
 
        // we know we're done when pr_depth drops to this
        exitdepth = pr_depth;
@@ -422,3 +427,34 @@ chooseexecprogram:
        }
 }
 
+// LordHavoc: grabbed these from QWSV, works around a gcc 2.95.3 compiler bug
+#define MAX_PRSTR 65536
+static char *pr_strtbl[MAX_PRSTR];
+static int num_prstr;
+
+char *PR_GetString (int num)
+{
+       return num >= 0 ? pr_strings + num : pr_strtbl[-num];
+}
+
+int PR_SetString (char *s)
+{
+       if (s >= pr_strings)
+               return (int) (s - pr_strings);
+       else
+       {
+               int i;
+               for (i = 0; i <= num_prstr; i++)
+                       if (pr_strtbl[i] == s)
+                               return -i;
+               if (num_prstr >= (MAX_PRSTR - 1))
+                       Host_Error ("PR_Setstring: ran out of string table slots");
+               pr_strtbl[++num_prstr] = s;
+               return -num_prstr;
+       }
+}
+
+void PR_ReInitStrings (void)
+{
+       num_prstr = 0;
+}