]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - progsvm.h
Reworked VM_CL_PolygonBegin/Vertex/End functions to do the commit to the mesh in...
[xonotic/darkplaces.git] / progsvm.h
index acaf6df0e35f1ad9f5dfbe98f7676e2f9ada84c7..676aa67e606d40436c0a39571688cf220013eb26 100644 (file)
--- a/progsvm.h
+++ b/progsvm.h
@@ -70,7 +70,7 @@ typedef struct prvm_required_field_s
 typedef struct prvm_edict_private_s
 {
        qboolean free;
-       float freetime;
+       float freetime; // realtime of last change to "free" (i.e. also set on allocation)
        int mark; // used during leaktest (0 = unref, >0 = referenced); special values during server physics:
 #define PRVM_EDICT_MARK_WAIT_FOR_SETORIGIN -1
 #define PRVM_EDICT_MARK_SETORIGIN_CAUGHT -2
@@ -116,43 +116,6 @@ typedef struct prvm_edict_s
        } fields;
 } prvm_edict_t;
 
-#define VMPOLYGONS_MAXPOINTS 64
-
-typedef struct vmpolygons_triangle_s
-{
-       rtexture_t              *texture;
-       int                             drawflag;
-       qboolean hasalpha;
-       unsigned short  elements[3];
-} vmpolygons_triangle_t;
-
-typedef struct vmpolygons_s
-{
-       mempool_t               *pool;
-       qboolean                initialized;
-
-       int                             max_vertices;
-       int                             num_vertices;
-       float                   *data_vertex3f;
-       float                   *data_color4f;
-       float                   *data_texcoord2f;
-
-       int                             max_triangles;
-       int                             num_triangles;
-       vmpolygons_triangle_t *data_triangles;
-       unsigned short  *data_sortedelement3s;
-
-       qboolean                begin_active;
-       int     begin_draw2d;
-       rtexture_t              *begin_texture;
-       int                             begin_drawflag;
-       int                             begin_vertices;
-       float                   begin_vertex[VMPOLYGONS_MAXPOINTS][3];
-       float                   begin_color[VMPOLYGONS_MAXPOINTS][4];
-       float                   begin_texcoord[VMPOLYGONS_MAXPOINTS][2];
-       qboolean                begin_texture_hasalpha;
-} vmpolygons_t;
-
 extern prvm_eval_t prvm_badvalue;
 
 #define PRVM_alledictfloat(ed, fieldname)    (PRVM_EDICTFIELDFLOAT(ed, prog->fieldoffsets.fieldname))
@@ -526,21 +489,47 @@ typedef struct prvm_stringbuffer_s
 }
 prvm_stringbuffer_t;
 
+// flags for knownstrings
+#define KNOWNSTRINGFLAG_ENGINE 1
+#define KNOWNSTRINGFLAG_GCMARK 2
+#define KNOWNSTRINGFLAG_GCPRUNE 4 // cleared by GCMARK code, string is freed if prune remains after two sweeps
+
+typedef enum prvm_prog_garbagecollection_state_stage_e
+{
+       PRVM_GC_START = 0,
+       PRVM_GC_GLOBALS_MARK,
+       PRVM_GC_FIELDS_MARK,
+       PRVM_GC_KNOWNSTRINGS_SWEEP,
+       PRVM_GC_RESET,
+}
+prvm_prog_garbagecollection_state_stage_t;
+
+typedef struct prvm_prog_garbagecollection_state_s
+{
+       prvm_prog_garbagecollection_state_stage_t stage;
+       int globals_mark_progress;
+       int fields_mark_progress;
+       int fields_mark_progress_entity;
+       int knownstrings_sweep_progress;
+}
+prvm_prog_garbagecollection_state_t;
+
 // [INIT] variables flagged with this token can be initialized by 'you'
 // NOTE: external code has to create and free the mempools but everything else is done by prvm !
 typedef struct prvm_prog_s
 {
        double                          starttime; // system time when PRVM_Prog_Load was called
+       double                          inittime; // system time when QC initialization code finished (any entity created before is not a leak)
        double                          profiletime; // system time when last PRVM_CallProfile was called (or PRVM_Prog_Load initially)
-       unsigned int            id; // increasing unique id of progs instance
        mfunction_t                     *functions;
+       int                             functions_covered;
        char                            *strings;
        int                                     stringssize;
        ddef_t                          *fielddefs;
        ddef_t                          *globaldefs;
        mstatement_t            *statements;
        int                                     entityfields;                   // number of vec_t fields in progs (some variables are 3)
-       int                                     entityfieldsarea;               // LordHavoc: equal to max_edicts * entityfields (for bounds checking)
+       int                                     entityfieldsarea;               // LadyHavoc: equal to max_edicts * entityfields (for bounds checking)
 
        // loaded values from the disk format
        int                                     progs_version;
@@ -562,8 +551,13 @@ typedef struct prvm_prog_s
        int                                     numglobals;
 
        int                                     *statement_linenums; // NULL if not available
+       int                                     *statement_columnnums; // NULL if not available
 
        double                          *statement_profile; // only incremented if prvm_statementprofiling is on
+       int                             statements_covered;
+       double                          *explicit_profile; // only incremented if prvm_statementprofiling is on
+       int                             explicit_covered;
+       int                             numexplicitcoveragestatements;
 
        union {
                prvm_vec_t *fp;
@@ -578,12 +572,15 @@ typedef struct prvm_prog_s
        // (simple optimization of the free string search)
        int                                     firstfreeknownstring;
        const char                      **knownstrings;
-       unsigned char           *knownstrings_freeable;
+       unsigned char           *knownstrings_flags;
        const char          **knownstrings_origin;
        const char                      ***stringshash;
 
        memexpandablearray_t    stringbuffersarray;
 
+       // garbage collection status
+       prvm_prog_garbagecollection_state_t gc;
+
        // all memory allocations related to this vm_prog (code, edicts, strings)
        mempool_t                       *progs_mempool; // [INIT]
 
@@ -624,13 +621,34 @@ typedef struct prvm_prog_s
        fssearch_t                      *opensearches[PRVM_MAX_OPENSEARCHES];
        const char *         opensearches_origin[PRVM_MAX_OPENSEARCHES];
        skeleton_t                      *skeletons[MAX_EDICTS];
+       cmd_state_t                     *console_cmd; // points to the relevant console command interpreter for this vm (&cmd_client or &cmd_server), also used to access cvars
 
        // buffer for storing all tempstrings created during one invocation of ExecuteProgram
        sizebuf_t                       tempstringsbuf;
 
-       // LordHavoc: moved this here to clean up things that relied on prvm_prog_list too much
-       // FIXME: make VM_CL_R_Polygon functions use Debug_Polygon functions?
-       vmpolygons_t            vmpolygons;
+       // polygonbegin, polygonvertex, polygonend state
+       // the polygon is buffered here until polygonend commits it to the relevant
+       // CL_Mesh entity, because important decisions depend on the vertex data
+       // provided (e.g. whether the polygon is transparent), we can't really do much
+       // with it until we have all of the data...
+
+       // this tracks the last polygonbegin's choice of
+       // CL_Mesh_CSQC or CL_Mesh_UI for this polygon
+       dp_model_t                      *polygonbegin_model;
+       // indicates if polygonbegin should be interpreted as 2d
+       // (clearscene sets this to false, renderscene sets this to true, drawpic
+       //  also sets this to true)
+       // note that in FTEQW polygonbegin with 2 args is handled very differently,
+       // where the behavior is always 3D unless DRAWFLAG_2D is passed, but
+       // DRAWFLAG_2D conflicts with our DRAWFLAG_SCREEN.
+       qboolean                        polygonbegin_guess2d;
+       // the texture name and drawflags provided to polygonbegin
+       char                            polygonbegin_texname[MAX_QPATH];
+       int                                     polygonbegin_drawflags;
+       // the vertex data
+       int                                     polygonbegin_numvertices;
+       int                                     polygonbegin_maxvertices;
+       float                           *polygonbegin_vertexdata;
 
        // copies of some vars that were former read from sv
        int                                     num_edicts;
@@ -643,7 +661,11 @@ typedef struct prvm_prog_s
        int                                     reserved_edicts; // [INIT]
 
        prvm_edict_t            *edicts;
-       prvm_vec_t              *edictsfields;
+       union
+       {
+               prvm_vec_t *fp;
+               prvm_int_t *ip;
+       } edictsfields;
        void                            *edictprivate;
 
        // size of the engine private struct
@@ -677,6 +699,8 @@ typedef struct prvm_prog_s
        // printed together with backtraces
        const char *statestring;
 
+       struct animatemodel_cache *animatemodel_cache;
+
 //     prvm_builtin_mem_t  *mem_list;
 
 // now passed as parameter of PRVM_LoadProgs
@@ -778,15 +802,16 @@ void PRVM_ExecuteProgram (prvm_prog_t *prog, func_t fnum, const char *errormessa
 #define PRVM_Free(buffer) Mem_Free(buffer)
 
 void PRVM_Profile (prvm_prog_t *prog, int maxfunctions, double mintime, int sortby);
-void PRVM_Profile_f (void);
-void PRVM_ChildProfile_f (void);
-void PRVM_CallProfile_f (void);
-void PRVM_PrintFunction_f (void);
+void PRVM_Profile_f(cmd_state_t *cmd);
+void PRVM_ChildProfile_f(cmd_state_t *cmd);
+void PRVM_CallProfile_f(cmd_state_t *cmd);
+void PRVM_PrintFunction_f(cmd_state_t *cmd);
 
 void PRVM_PrintState(prvm_prog_t *prog, int stack_index);
 void PRVM_Crash(prvm_prog_t *prog);
 void PRVM_ShortStackTrace(prvm_prog_t *prog, char *buf, size_t bufsize);
 const char *PRVM_AllocationOrigin(prvm_prog_t *prog);
+void PRVM_GarbageCollection(prvm_prog_t *prog);
 
 ddef_t *PRVM_ED_FindField(prvm_prog_t *prog, const char *name);
 ddef_t *PRVM_ED_FindGlobal(prvm_prog_t *prog, const char *name);
@@ -851,7 +876,7 @@ extern      int             prvm_type_size[8]; // for consistency : I think a goal of this sub-p
 
 void PRVM_Init_Exec(prvm_prog_t *prog);
 
-void PRVM_ED_PrintEdicts_f (void);
+void PRVM_ED_PrintEdicts_f(cmd_state_t *cmd);
 void PRVM_ED_PrintNum (prvm_prog_t *prog, int ent, const char *wildcard_fieldname);
 
 const char *PRVM_GetString(prvm_prog_t *prog, int num);
@@ -876,7 +901,7 @@ Set up the fields marked with [INIT] in the prog struct
 Load a program with LoadProgs
 */
 // Load expects to be called right after Reset
-void PRVM_Prog_Init(prvm_prog_t *prog);
+void PRVM_Prog_Init(prvm_prog_t *prog, cmd_state_t *cmd);
 void PRVM_Prog_Load(prvm_prog_t *prog, const char *filename, unsigned char *data, fs_offset_t size, int numrequiredfunc, const char **required_func, int numrequiredfields, prvm_required_field_t *required_field, int numrequiredglobals, prvm_required_field_t *required_global);
 void PRVM_Prog_Reset(prvm_prog_t *prog);
 
@@ -891,4 +916,6 @@ void VM_FrameBlendFromFrameGroupBlend(frameblend_t *frameblend, const framegroup
 void VM_UpdateEdictSkeleton(prvm_prog_t *prog, prvm_edict_t *ed, const dp_model_t *edmodel, const frameblend_t *frameblend);
 void VM_RemoveEdictSkeleton(prvm_prog_t *prog, prvm_edict_t *ed);
 
+void PRVM_ExplicitCoverageEvent(prvm_prog_t *prog, mfunction_t *func, int statement);
+
 #endif