]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - prvm_edict.c
removed all 3 uses of the brown-text message prefix in the server
[xonotic/darkplaces.git] / prvm_edict.c
index e79cc5f1d8254de665c9a0d3ce93dd2905954484..29e5998a775d3e31780894c6d095b80251051a14 100644 (file)
@@ -35,6 +35,8 @@ qboolean PRVM_ED_ParseEpair(prvm_edict_t *ent, ddef_t *key, const char *s);
 cvar_t prvm_boundscheck = {0, "prvm_boundscheck", "1", "enables detection of out of bounds memory access in the QuakeC code being run (in other words, prevents really exceedingly bad QuakeC code from doing nasty things to your computer)"};
 // LordHavoc: prints every opcode as it executes - warning: this is significant spew
 cvar_t prvm_traceqc = {0, "prvm_traceqc", "0", "prints every QuakeC statement as it is executed (only for really thorough debugging!)"};
+// LordHavoc: counts usage of each QuakeC statement
+cvar_t prvm_statementprofiling = {0, "prvm_statementprofiling", "0", "counts how many times each QuakeC statement has been executed, these counts are displayed in prvm_printfunction output (if enabled)"};
 
 //============================================================================
 // mempool handling
@@ -124,6 +126,16 @@ int PRVM_ED_FindFieldOffset(const char *field)
        return d->ofs*4;
 }
 
+ddef_t*        PRVM_ED_FindGlobal(const char *name);
+int PRVM_ED_FindGlobalOffset(const char *global)
+{
+       ddef_t *d;
+       d = PRVM_ED_FindGlobal(global);
+       if (!d)
+               return 0;
+       return d->ofs*4;
+}
+
 qboolean PRVM_ProgLoaded(int prognr)
 {
        if(prognr < 0 || prognr >= PRVM_MAXPROGS)
@@ -499,7 +511,7 @@ padded to 20 field width
 char *PRVM_GlobalString (int ofs)
 {
        char    *s;
-       size_t  i;
+       //size_t        i;
        ddef_t  *def;
        void    *val;
        static char     line[128];
@@ -507,37 +519,37 @@ char *PRVM_GlobalString (int ofs)
        val = (void *)&prog->globals.generic[ofs];
        def = PRVM_ED_GlobalAtOfs(ofs);
        if (!def)
-               sprintf (line,"%i(?)", ofs);
+               sprintf (line,"GLOBAL%i", ofs);
        else
        {
                s = PRVM_ValueString ((etype_t)def->type, (prvm_eval_t *)val);
-               sprintf (line,"%i(%s)%s", ofs, PRVM_GetString(def->s_name), s);
+               sprintf (line,"%s (=%s)", PRVM_GetString(def->s_name), s);
        }
 
-       i = strlen(line);
-       for ( ; i<20 ; i++)
-               strcat (line," ");
-       strcat (line," ");
+       //i = strlen(line);
+       //for ( ; i<20 ; i++)
+       //      strcat (line," ");
+       //strcat (line," ");
 
        return line;
 }
 
 char *PRVM_GlobalStringNoContents (int ofs)
 {
-       size_t  i;
+       //size_t        i;
        ddef_t  *def;
        static char     line[128];
 
        def = PRVM_ED_GlobalAtOfs(ofs);
        if (!def)
-               sprintf (line,"%i(?)", ofs);
+               sprintf (line,"GLOBAL%i", ofs);
        else
-               sprintf (line,"%i(%s)", ofs, PRVM_GetString(def->s_name));
+               sprintf (line,"%s", PRVM_GetString(def->s_name));
 
-       i = strlen(line);
-       for ( ; i<20 ; i++)
-               strcat (line," ");
-       strcat (line," ");
+       //i = strlen(line);
+       //for ( ; i<20 ; i++)
+       //      strcat (line," ");
+       //strcat (line," ");
 
        return line;
 }
@@ -1337,6 +1349,8 @@ void PRVM_LoadProgs (const char * filename, int numrequiredfunc, char **required
 
        prog->statements = (dstatement_t *)((unsigned char *)prog->progs + prog->progs->ofs_statements);
 
+       prog->statement_profile = (int *)Mem_Alloc(prog->progs_mempool, prog->progs->numstatements * sizeof(*prog->statement_profile));
+
        // moved edict_size calculation down below field adding code
 
        //pr_global_struct = (globalvars_t *)((unsigned char *)progs + progs->ofs_globals);
@@ -1500,7 +1514,7 @@ void PRVM_LoadProgs (const char * filename, int numrequiredfunc, char **required
                                PRVM_ERROR("PRVM_LoadProgs: out of bounds global index (statement %d) in %s", i, PRVM_NAME);
                        break;
                default:
-                       Con_DPrintf("PRVM_LoadProgs: unknown opcode %d at statement %d in %s", st->op, i, PRVM_NAME);
+                       Con_DPrintf("PRVM_LoadProgs: unknown opcode %d at statement %d in %s\n", st->op, i, PRVM_NAME);
                        break;
                }
        }
@@ -1754,9 +1768,11 @@ void PRVM_Init (void)
        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_printfunction", PRVM_PrintFunction_f, "prints a disassembly (QuakeC instructions) of the specified function in the selected VM (server, client, menu)");
        // LordHavoc: optional runtime bounds checking (speed drain, but worth it for security, on by default - breaks most QCCX features (used by CRMod and others))
        Cvar_RegisterVariable (&prvm_boundscheck);
        Cvar_RegisterVariable (&prvm_traceqc);
+       Cvar_RegisterVariable (&prvm_statementprofiling);
 
        //VM_Cmd_Init();
 }
@@ -1883,7 +1899,7 @@ int PRVM_SetEngineString(const char *s)
                if (prog->knownstrings[i] == s)
                        return -1 - i;
        // new unknown engine string
-       if (developer.integer >= 3)
+       if (developer.integer >= 100)
                Con_Printf("new engine string %p\n", s);
        for (i = prog->firstfreeknownstring;i < prog->numknownstrings;i++)
                if (!prog->knownstrings[i])