ref: d68c16a284098755891b6c700dc4046b1c4cc808
parent: 4fe828ca722d298bcb90d8874df9c0aae6fa68cc
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Tue Nov 21 17:06:45 EST 2023
make particles drawing less complex code-wise, change size according to distance
--- a/d_iface.h
+++ b/d_iface.h
@@ -99,11 +99,9 @@
void D_DrawPoly (void);
void D_DrawSprite (void);
void D_DrawSurfaces (void);
-void D_EndParticles (void);
void D_Init (void);
void D_ViewChanged (void);
void D_SetupFrame (void);
-void D_StartParticles (void);
void D_WarpScreen (void);
void D_DrawRect (void);
--- a/d_local.h
+++ b/d_local.h
@@ -67,14 +67,11 @@
extern int d_vrectx, d_vrecty, d_vrectright_particle, d_vrectbottom_particle;
-extern int d_y_aspect_shift, d_pix_min, d_pix_max, d_pix_shift;
-
-extern pixel_t *d_viewbuffer;
-
-extern uzint *zspantable[MAXHEIGHT];
-
-extern int d_minmip;
-extern float d_scalemip[3];
+extern int d_pix_min, d_pix_max;
+extern pixel_t *d_viewbuffer;
+extern uzint *zspantable[MAXHEIGHT];
+extern int d_minmip;
+extern float d_scalemip[3];
enum {
// perhaps a bit too much, but looks ok
--- a/d_modech.c
+++ b/d_modech.c
@@ -1,60 +1,33 @@
#include "quakedef.h"
-int d_vrectx, d_vrecty, d_vrectright_particle, d_vrectbottom_particle;
+double d_pix_scale;
+int d_vrectx, d_vrecty, d_vrectright_particle, d_vrectbottom_particle;
+int d_pix_min, d_pix_max;
+int d_scantable[MAXHEIGHT];
+uzint *zspantable[MAXHEIGHT];
-int d_y_aspect_shift, d_pix_min, d_pix_max, d_pix_shift;
-
-int d_scantable[MAXHEIGHT];
-uzint *zspantable[MAXHEIGHT];
-
-/*
-================
-D_ViewChanged
-================
-*/
-void D_ViewChanged (void)
+void
+D_ViewChanged (void)
{
- int rowbytes;
+ int rowbytes, i;
- if (r_dowarp)
- rowbytes = WARP_WIDTH;
- else
- rowbytes = vid.rowbytes;
-
- scale_for_mip = xscale;
- if (yscale > xscale)
- scale_for_mip = yscale;
-
d_zwidth = vid.width;
+ rowbytes = r_dowarp ? WARP_WIDTH : vid.rowbytes;
+ scale_for_mip = max(xscale, yscale);
- d_pix_min = r_refdef.vrect.width / 320;
- if (d_pix_min < 1)
- d_pix_min = 1;
+ d_pix_scale = 90.0 / r_refdef.fov_x;
+ d_pix_min = (r_refdef.vrect.width / 320.0) * d_pix_scale;
+ d_pix_max = 0.5 + d_pix_min*4.0;
+ d_pix_max = max(d_pix_max, d_pix_min+1);
- d_pix_max = (int)(((float)r_refdef.vrect.width / (320.0 / 4.0) + 0.5) * r_part_scale.value * 90.0/r_refdef.fov_x);
- d_pix_shift = 8 - (int)((float)r_refdef.vrect.width / 320.0 + 0.5);
- if (d_pix_max < 1)
- d_pix_max = 1;
-
- if (pixelAspect > 1.4)
- d_y_aspect_shift = 1;
- else
- d_y_aspect_shift = 0;
-
d_vrectx = r_refdef.vrect.x;
d_vrecty = r_refdef.vrect.y;
d_vrectright_particle = r_refdef.vrectright - d_pix_max;
- d_vrectbottom_particle =
- r_refdef.vrectbottom - (d_pix_max << d_y_aspect_shift);
+ d_vrectbottom_particle = r_refdef.vrectbottom - d_pix_max;
- {
- int i;
-
- for (i=0 ; i<vid.height; i++)
- {
- d_scantable[i] = i*rowbytes;
- zspantable[i] = d_pzbuffer + i*d_zwidth;
- }
+ for(i = 0; i < vid.height; i++){
+ d_scantable[i] = i*rowbytes;
+ zspantable[i] = d_pzbuffer + i*d_zwidth;
}
}
--- a/d_part.c
+++ b/d_part.c
@@ -1,55 +1,31 @@
#include "quakedef.h"
-/*
-==============
-D_EndParticles
-==============
-*/
-void D_EndParticles (void)
-{
- // not used by software driver
-}
+extern double d_pix_scale;
-
-/*
-==============
-D_StartParticles
-==============
-*/
-void D_StartParticles (void)
+void
+D_DrawParticle (particle_t *pparticle)
{
- // not used by software driver
-}
+ vec3_t local, transformed;
+ double zi;
+ byte *pdest, color;
+ uzint *pz;
+ int i, izi, pix, count, u, v;
-
-/*
-==============
-D_DrawParticle
-==============
-*/
-void D_DrawParticle (particle_t *pparticle)
-{
- vec3_t local, transformed;
- float zi;
- byte *pdest;
- uzint *pz;
- int i, izi, pix, count, u, v;
-
// transform point
- VectorSubtract (pparticle->org, r_origin, local);
+ VectorSubtract(pparticle->org, r_origin, local);
transformed[0] = DotProduct(local, r_pright);
transformed[1] = DotProduct(local, r_pup);
transformed[2] = DotProduct(local, r_ppn);
- if (transformed[2] < PARTICLE_Z_CLIP)
+ if(transformed[2] < PARTICLE_Z_CLIP)
return;
// project the point
// FIXME: preadjust xcenter and ycenter
zi = 1.0 / transformed[2];
- u = (int)(xcenter + zi * transformed[0] + 0.5);
- v = (int)(ycenter - zi * transformed[1] + 0.5);
+ u = xcenter + zi * transformed[0] + 0.5;
+ v = ycenter - zi * transformed[1] + 0.5;
if ((v > d_vrectbottom_particle) ||
(u > d_vrectright_particle) ||
@@ -59,121 +35,22 @@
return;
}
- pz = d_pzbuffer + (d_zwidth * v) + u;
+ pz = d_pzbuffer + d_zwidth*v + u;
pdest = d_viewbuffer + d_scantable[v] + u;
- izi = (int)(zi * 0x8000);
+ izi = zi * 0x8000;
- pix = izi >> d_pix_shift;
+ zi = 1024.0 * d_pix_scale / Length(local);
+ pix = clamp(zi, d_pix_min, d_pix_max) * r_part_scale.value;
+ if(pix < 1)
+ pix = 1;
+ color = pparticle->color;
- if (pix < d_pix_min)
- pix = d_pix_min;
- else if (pix > d_pix_max)
- pix = d_pix_max;
-
- switch (pix)
- {
- case 1:
- count = 1 << d_y_aspect_shift;
-
- for ( ; count ; count--, pz += d_zwidth, pdest += screenwidth)
- {
- if (pz[0] <= izi)
- {
- pz[0] = izi;
- pdest[0] = pparticle->color;
+ for(count = pix; count; count--, pz += d_zwidth, pdest += screenwidth){
+ for(i = 0; i < pix; i++){
+ if(pz[i] <= izi){
+ pz[i] = izi;
+ pdest[i] = color;
}
}
- break;
-
- case 2:
- count = 2 << d_y_aspect_shift;
-
- for ( ; count ; count--, pz += d_zwidth, pdest += screenwidth)
- {
- if (pz[0] <= izi)
- {
- pz[0] = izi;
- pdest[0] = pparticle->color;
- }
-
- if (pz[1] <= izi)
- {
- pz[1] = izi;
- pdest[1] = pparticle->color;
- }
- }
- break;
-
- case 3:
- count = 3 << d_y_aspect_shift;
-
- for ( ; count ; count--, pz += d_zwidth, pdest += screenwidth)
- {
- if (pz[0] <= izi)
- {
- pz[0] = izi;
- pdest[0] = pparticle->color;
- }
-
- if (pz[1] <= izi)
- {
- pz[1] = izi;
- pdest[1] = pparticle->color;
- }
-
- if (pz[2] <= izi)
- {
- pz[2] = izi;
- pdest[2] = pparticle->color;
- }
- }
- break;
-
- case 4:
- count = 4 << d_y_aspect_shift;
-
- for ( ; count ; count--, pz += d_zwidth, pdest += screenwidth)
- {
- if (pz[0] <= izi)
- {
- pz[0] = izi;
- pdest[0] = pparticle->color;
- }
-
- if (pz[1] <= izi)
- {
- pz[1] = izi;
- pdest[1] = pparticle->color;
- }
-
- if (pz[2] <= izi)
- {
- pz[2] = izi;
- pdest[2] = pparticle->color;
- }
-
- if (pz[3] <= izi)
- {
- pz[3] = izi;
- pdest[3] = pparticle->color;
- }
- }
- break;
-
- default:
- count = pix << d_y_aspect_shift;
-
- for ( ; count ; count--, pz += d_zwidth, pdest += screenwidth)
- {
- for (i=0 ; i<pix ; i++)
- {
- if (pz[i] <= izi)
- {
- pz[i] = izi;
- pdest[i] = pparticle->color;
- }
- }
- }
- break;
}
}
--- a/r_main.c
+++ b/r_main.c
@@ -82,7 +82,7 @@
cvar_t r_numedges = {"r_numedges", "0"};
static cvar_t r_aliastransbase = {"r_aliastransbase", "200"};
static cvar_t r_aliastransadj = {"r_aliastransadj", "100"};
-cvar_t r_part_scale = {"r_part_scale", "0.75", true};
+cvar_t r_part_scale = {"r_part_scale", "1", true};
cvar_t r_wateralpha = {"r_wateralpha", "1", true};
cvar_t r_lavaalpha = {"r_lavaalpha", "1", true};
cvar_t r_slimealpha = {"r_slimealpha", "1", true};
--- a/r_part.c
+++ b/r_part.c
@@ -510,8 +510,6 @@
float dvel;
float frametime;
- D_StartParticles ();
-
VectorScale (vright, xscaleshrink, r_pright);
VectorScale (vup, yscaleshrink, r_pup);
VectorCopy (vpn, r_ppn);
@@ -608,7 +606,5 @@
break;
}
}
-
- D_EndParticles ();
}