]> 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 41c755d6358231fe245253950d26dea17509b195..676aa67e606d40436c0a39571688cf220013eb26 100644 (file)
--- a/progsvm.h
+++ b/progsvm.h
@@ -489,6 +489,31 @@ 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
@@ -547,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]
 
@@ -598,8 +626,13 @@ typedef struct prvm_prog_s
        // buffer for storing all tempstrings created during one invocation of ExecuteProgram
        sizebuf_t                       tempstringsbuf;
 
-       // in csqc the polygonbegin,polygonvertex,polygonend sequencing is
-       // stateful, so this tracks the last polygonbegin's choice of
+       // 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
@@ -609,6 +642,13 @@ typedef struct prvm_prog_s
        // 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;
@@ -621,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
@@ -767,6 +811,7 @@ 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);