]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - meshqueue.c
use unsigned comparisons for most of the boundschecks in the vm
[xonotic/darkplaces.git] / meshqueue.c
index e0e1e8c7091c7765783b311010f8da3399a1e3c2..2ba5c518004de13ce324ca07dd6b11283f520525 100644 (file)
@@ -10,15 +10,13 @@ typedef struct meshqueue_s
        int surfacenumber;
        const rtlight_t *rtlight;
        float dist;
+       dptransparentsortcategory_t category;
 }
 meshqueue_t;
 
 int trans_sortarraysize;
 meshqueue_t **trans_hash = NULL;
 meshqueue_t ***trans_hashpointer = NULL;
-extern cvar_t r_transparent_sortarraysize;
-extern cvar_t r_transparent_sortmindist;
-extern cvar_t r_transparent_sortmaxdist;
 
 float mqt_viewplanedist;
 float mqt_viewmaxdist;
@@ -33,7 +31,7 @@ void R_MeshQueue_BeginScene(void)
        mqt_viewmaxdist = 0;
 }
 
-void R_MeshQueue_AddTransparent(const vec3_t center, void (*callback)(const entity_render_t *ent, const rtlight_t *rtlight, int numsurfaces, int *surfacelist), const entity_render_t *ent, int surfacenumber, const rtlight_t *rtlight)
+void R_MeshQueue_AddTransparent(dptransparentsortcategory_t category, const vec3_t center, void (*callback)(const entity_render_t *ent, const rtlight_t *rtlight, int numsurfaces, int *surfacelist), const entity_render_t *ent, int surfacenumber, const rtlight_t *rtlight)
 {
        meshqueue_t *mq;
        if (mqt_count >= mqt_total || !mqt_array)
@@ -53,10 +51,11 @@ void R_MeshQueue_AddTransparent(const vec3_t center, void (*callback)(const enti
        mq->ent = ent;
        mq->surfacenumber = surfacenumber;
        mq->rtlight = rtlight;
-       if (ent && (ent->flags & RENDER_WORLDOBJECT))
-               mq->dist = mqt_viewmaxdist;
-       else
+       mq->category = category;
+       if (r_transparent_useplanardistance.integer)
                mq->dist = DotProduct(center, r_refdef.view.forward) - mqt_viewplanedist;
+       else
+               mq->dist = VectorDistance(center, r_refdef.view.origin);
        mq->next = NULL;
        mqt_viewmaxdist = max(mqt_viewmaxdist, mq->dist);
 }
@@ -102,7 +101,20 @@ void R_MeshQueue_RenderTransparent(void)
        maxhashindex = trans_sortarraysize - 1;
        for (i = 0, mqt = mqt_array; i < mqt_count; i++, mqt++)
        {
-               hashindex = bound(0, (int)(bound(0, mqt->dist - r_transparent_sortmindist.integer, r_transparent_sortmaxdist.integer) * distscale), maxhashindex);
+               switch(mqt->category)
+               {
+               default:
+               case TRANSPARENTSORT_HUD:
+                       hashindex = 0;
+                       break;
+               case TRANSPARENTSORT_DISTANCE:
+                       // this could use a reduced range if we need more categories
+                       hashindex = bound(0, (int)(bound(0, mqt->dist - r_transparent_sortmindist.integer, r_transparent_sortmaxdist.integer) * distscale), maxhashindex);
+                       break;
+               case TRANSPARENTSORT_SKY:
+                       hashindex = maxhashindex;
+                       break;
+               }
                // link to tail of hash chain (to preserve render order)
                mqt->next = NULL;
                *trans_hashpointer[hashindex] = mqt;