]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - prvm_edict.c
optimized rtlighting passes by using RSurf_DrawBatch_Simple, this took a lot of code...
[xonotic/darkplaces.git] / prvm_edict.c
index f51ffcfc7592a5de7fbfb36db86633ff94172105..29e5998a775d3e31780894c6d095b80251051a14 100644 (file)
@@ -32,9 +32,11 @@ ddef_t *PRVM_ED_FieldAtOfs(int ofs);
 qboolean PRVM_ED_ParseEpair(prvm_edict_t *ent, ddef_t *key, const char *s);
 
 // 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_t prvm_boundscheck = {0, "prvm_boundscheck", "1"};
+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"};
+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;
 }
@@ -832,7 +844,7 @@ void PRVM_ED_ParseGlobals (const char *data)
        {
                // parse key
                if (!COM_ParseToken(&data, false))
-                       PRVM_ERROR ("PRVM_ED_ParseEntity: EOF without closing brace");
+                       PRVM_ERROR ("PRVM_ED_ParseGlobals: EOF without closing brace");
                if (com_token[0] == '}')
                        break;
 
@@ -840,10 +852,10 @@ void PRVM_ED_ParseGlobals (const char *data)
 
                // parse value
                if (!COM_ParseToken(&data, false))
-                       PRVM_ERROR ("PRVM_ED_ParseEntity: EOF without closing brace");
+                       PRVM_ERROR ("PRVM_ED_ParseGlobals: EOF without closing brace");
 
                if (com_token[0] == '}')
-                       PRVM_ERROR ("PRVM_ED_ParseEntity: closing brace without data");
+                       PRVM_ERROR ("PRVM_ED_ParseGlobals: closing brace without data");
 
                key = PRVM_ED_FindGlobal (keyname);
                if (!key)
@@ -1009,6 +1021,7 @@ ed should be a properly initialized empty edict.
 Used for initial level load and for savegames.
 ====================
 */
+extern cvar_t developer_entityparsing;
 const char *PRVM_ED_ParseEdict (const char *data, prvm_edict_t *ent)
 {
        ddef_t *key;
@@ -1024,7 +1037,9 @@ const char *PRVM_ED_ParseEdict (const char *data, prvm_edict_t *ent)
        {
        // parse key
                if (!COM_ParseToken(&data, false))
-                       PRVM_ERROR ("PRVM_ED_ParseEntity: EOF without closing brace");
+                       PRVM_ERROR ("PRVM_ED_ParseEdict: EOF without closing brace");
+               if (developer_entityparsing.integer)
+                       Con_Printf("Key: \"%s\"", com_token);
                if (com_token[0] == '}')
                        break;
 
@@ -1054,10 +1069,12 @@ const char *PRVM_ED_ParseEdict (const char *data, prvm_edict_t *ent)
 
        // parse value
                if (!COM_ParseToken(&data, false))
-                       PRVM_ERROR ("PRVM_ED_ParseEntity: EOF without closing brace");
+                       PRVM_ERROR ("PRVM_ED_ParseEdict: EOF without closing brace");
+               if (developer_entityparsing.integer)
+                       Con_Printf(" \"%s\"\n", com_token);
 
                if (com_token[0] == '}')
-                       PRVM_ERROR ("PRVM_ED_ParseEntity: closing brace without data");
+                       PRVM_ERROR ("PRVM_ED_ParseEdict: closing brace without data");
 
                init = true;
 
@@ -1254,7 +1271,8 @@ void PRVM_LoadLNO( const char *progname ) {
 <Spike>    SafeWrite (h, statement_linenums, numstatements*sizeof(int));
 */
        if( (unsigned) filesize < (6 + prog->progs->numstatements) * sizeof( int ) ) {
-        return;
+               Mem_Free(lno);
+               return;
        }
 
        header = (unsigned int *) lno;
@@ -1331,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);
@@ -1494,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:
-                       PRVM_ERROR("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;
                }
        }
@@ -1739,18 +1759,20 @@ PRVM_Init
 */
 void PRVM_Init (void)
 {
-       Cmd_AddCommand ("prvm_edict", PRVM_ED_PrintEdict_f);
-       Cmd_AddCommand ("prvm_edicts", PRVM_ED_PrintEdicts_f);
-       Cmd_AddCommand ("prvm_edictcount", PRVM_ED_Count_f);
-       Cmd_AddCommand ("prvm_profile", PRVM_Profile_f);
-       Cmd_AddCommand ("prvm_fields", PRVM_Fields_f);
-       Cmd_AddCommand ("prvm_globals", PRVM_Globals_f);
-       Cmd_AddCommand ("prvm_global", PRVM_Global_f);
-       Cmd_AddCommand ("prvm_globalset", PRVM_GlobalSet_f);
-       Cmd_AddCommand ("prvm_edictset", PRVM_ED_EdictSet_f);
+       Cmd_AddCommand ("prvm_edict", PRVM_ED_PrintEdict_f, "print all data about an entity number in the selected VM (server, client, menu)");
+       Cmd_AddCommand ("prvm_edicts", PRVM_ED_PrintEdicts_f, "set a property on an entity number 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_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_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();
 }
@@ -1877,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])