From 5c41d784306266a94c8caf92c6ea2680f98a5e01 Mon Sep 17 00:00:00 2001 From: lordhavoc Date: Mon, 11 Sep 2000 19:28:30 +0000 Subject: [PATCH] clean up, r_farclip cvar, lit particles (optional), stuff git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@27 d7cf8633-e32d-0410-b094-e92efae38249 --- cl_parse.c | 24 ++++++++++++------------ cl_tent.c | 4 ++-- gl_poly.c | 48 ++++++++++++++++++++++++++++++++++++++++++------ gl_rmain.c | 6 +++--- gl_rsurf.c | 2 -- gl_warp.c | 2 +- pr_edict.c | 2 +- pr_exec.c | 6 ++++++ protocol.h | 2 +- r_light.c | 6 ++++++ r_part.c | 36 +++++++++++++++++++++++------------- 11 files changed, 97 insertions(+), 41 deletions(-) diff --git a/cl_parse.c b/cl_parse.c index 38acf24a..e7b0cb74 100644 --- a/cl_parse.c +++ b/cl_parse.c @@ -80,7 +80,7 @@ char *svc_strings[] = "?", // 47 "?", // 48 "?", // 49 - "svc_skyboxsize", // [coord] size + "svc_farclip", // [coord] size "svc_fog" // [byte] enable [short * 4096] density [byte] red [byte] green [byte] blue }; @@ -223,6 +223,7 @@ extern float fog_green; extern float fog_blue; extern void R_SetSkyBox (char *sky); extern void FOG_clear(); +extern cvar_t r_farclip; void CL_ParseEntityLump(char *entdata) { @@ -232,7 +233,7 @@ void CL_ParseEntityLump(char *entdata) int i, j, k; FOG_clear(); // LordHavoc: no fog until set skyname[0] = 0; // LordHavoc: no enviroment mapped sky until set -// r_skyboxsize.value = 4096; // LordHavoc: default skyboxsize + r_farclip.value = 6144; // LordHavoc: default farclip distance data = entdata; if (!data) return; @@ -261,12 +262,12 @@ void CL_ParseEntityLump(char *entdata) R_SetSkyBox(value); else if (!strcmp("qlsky", key)) // non-standard, introduced by QuakeLives (EEK) R_SetSkyBox(value); -// else if (!strcmp("skyboxsize", key)) -// { -// r_skyboxsize.value = atof(value); -// if (r_skyboxsize.value < 64) -// r_skyboxsize.value = 64; -// } + else if (!strcmp("farclip", key)) + { + r_farclip.value = atof(value); + if (r_farclip.value < 64) + r_farclip.value = 64; + } else if (!strcmp("fog", key)) { scanf(value, "%f %f %f %f", &fog_density, &fog_red, &fog_green, &fog_blue); @@ -1054,13 +1055,12 @@ void CL_ParseServerMessage (void) case svc_showlmp: SHOWLMP_decodeshow(); break; - // LordHavoc: extra worldspawn fields (fog, sky, skyboxsize) + // LordHavoc: extra worldspawn fields (fog, sky, farclip) case svc_skybox: R_SetSkyBox(MSG_ReadString()); break; - case svc_skyboxsize: - i = MSG_ReadCoord(); - // r_skyboxsize.value = MSG_ReadCoord(); + case svc_farclip: + r_farclip.value = MSG_ReadCoord(); break; case svc_fog: if (MSG_ReadByte()) diff --git a/cl_tent.c b/cl_tent.c index 42ed0795..e550857b 100644 --- a/cl_tent.c +++ b/cl_tent.c @@ -465,14 +465,14 @@ void CL_ParseTEnt (void) pos[2] = MSG_ReadCoord (); colorStart = MSG_ReadByte (); colorLength = MSG_ReadByte (); -// R_ParticleExplosion2 (pos, colorStart, colorLength); + R_ParticleExplosion2 (pos, colorStart, colorLength); dl = CL_AllocDlight (0); VectorCopy (pos, dl->origin); dl->radius = 350; dl->die = cl.time + 0.5; dl->decay = 700; tempcolor = (byte *)&d_8to24table[(rand()%colorLength) + colorStart]; - dl->color[0] = tempcolor[0];dl->color[1] = tempcolor[1];dl->color[2] = tempcolor[2]; + dl->color[0] = tempcolor[0] * (1.0f / 255.0f);dl->color[1] = tempcolor[1] * (1.0f / 255.0f);dl->color[2] = tempcolor[2] * (1.0f / 255.0f); S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1); break; diff --git a/gl_poly.c b/gl_poly.c index fdc8a896..0905f0c0 100644 --- a/gl_poly.c +++ b/gl_poly.c @@ -85,6 +85,9 @@ void transpolyend() } int transpolyindices; +extern qboolean isG200; + +/* void transpolyrenderminmax() { int i, j, k, lastvert; @@ -111,6 +114,7 @@ void transpolyrenderminmax() if (max < 4) // free to check here, so skip polys behind the view continue; transpoly[i].distance = average; +*/ /* transpoly[i].mindistance = min; transpoly[i].maxdistance = max; @@ -164,6 +168,7 @@ skip: ; } */ +/* // sorted insert for (j = 0;j < transpolyindices;j++) if (transpoly[transpolyindex[j]].distance < average) @@ -174,9 +179,9 @@ skip: transpolyindex[j] = i; } } - -// LordHavoc: qsort compare function +*/ /* +// LordHavoc: qsort compare function int transpolyqsort(const void *ia, const void *ib) { transpoly_t *a, *b; @@ -206,16 +211,46 @@ int transpolyqsort(const void *ia, const void *ib) return -1; // (-1) a is behind b return j == b->verts; // (1) a is infront of b (0) a and b intersect // return (transpoly[*((unsigned short *)ib)].mindistance + transpoly[*((unsigned short *)ib)].maxdistance) - (transpoly[*((unsigned short *)ia)].mindistance + transpoly[*((unsigned short *)ia)].maxdistance); + */ +/* + return ((transpoly_t*)ia)->distance - ((transpoly_t*)ib)->distance; } */ -extern qboolean isG200; +int transpolyqsort(const void *ia, const void *ib) +{ + return (transpoly[*((unsigned short *)ib)].distance - transpoly[*((unsigned short *)ia)].distance); +} -/* -void transpolysort() +void transpolyrenderminmax() { + int i, j, lastvert; + vec_t d, max, viewdist, average; + transpolyindices = 0; + viewdist = DotProduct(r_refdef.vieworg, vpn); + for (i = 0;i < currenttranspoly;i++) + { + if (transpoly[i].verts < 3) // only process valid polygons + continue; + max = -1000000; + lastvert = transpoly[i].firstvert + transpoly[i].verts; + average = 0; + for (j = transpoly[i].firstvert;j < lastvert;j++) + { + d = DotProduct(transvert[j].v, vpn)-viewdist; + average += d; + if (d > max) + max = d; + } + if (max < 4) // free to check here, so skip polys behind the view + continue; + transpoly[i].distance = average / transpoly[i].verts; + transpolyindex[transpolyindices++] = i; + } + qsort(&transpolyindex[0], transpolyindices, sizeof(unsigned short), transpolyqsort); +} +/* int i, j, a; -// qsort(&transpolyindex[0], transpolyindices, sizeof(unsigned short), transpolyqsort); a = true; while(a) { @@ -466,6 +501,7 @@ void wallpolyrender() wallvert_t *vert; if (currentwallpoly < 1) return; + c_brush_polys += currentwallpoly; // testing //Con_DPrintf("wallpolyrender: %i polys %i vertices\n", currentwallpoly, currentwallvert); if (!gl_mtexable) diff --git a/gl_rmain.c b/gl_rmain.c index 63e16255..79a5a973 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -95,6 +95,7 @@ cvar_t brightness = {"brightness", "1.0", TRUE}; // LordHavoc: a method of opera cvar_t gl_lightmode = {"gl_lightmode", "1", TRUE}; // LordHavoc: overbright lighting //cvar_t r_dynamicwater = {"r_dynamicwater", "1"}; //cvar_t r_dynamicbothsides = {"r_dynamicbothsides", "1"}; // LordHavoc: can disable dynamic lighting of backfaces, but quake maps are weird so it doesn't always work right... +cvar_t r_farclip = {"r_farclip", "6144"}; cvar_t gl_fogenable = {"gl_fogenable", "0"}; cvar_t gl_fogdensity = {"gl_fogdensity", "0.25"}; @@ -1349,8 +1350,7 @@ void R_SetupFrame (void) } -void MYgluPerspective( GLdouble fovy, GLdouble aspect, - GLdouble zNear, GLdouble zFar ) +void MYgluPerspective( GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar ) { GLdouble xmin, xmax, ymin, ymax; @@ -1412,7 +1412,7 @@ void R_SetupGL (void) // if (skyname[0]) // skybox enabled? // MYgluPerspective (r_refdef.fov_y, screenaspect, 4, r_skyboxsize.value*1.732050807569 + 256); // this is size*sqrt(3) + 256 // else - MYgluPerspective (r_refdef.fov_y, screenaspect, 4, 6144); + MYgluPerspective (r_refdef.fov_y, screenaspect, 4, r_farclip.value); glCullFace(GL_FRONT); diff --git a/gl_rsurf.c b/gl_rsurf.c index 55ab1875..9d85c898 100644 --- a/gl_rsurf.c +++ b/gl_rsurf.c @@ -504,7 +504,6 @@ void DrawTextureChains (void) { cl.worldmodel->textures[j]->texturechain = NULL; t = R_TextureAnimation (cl.worldmodel->textures[j]); - c_brush_polys++; for (;s;s = s->texturechain) { if (currentwallpoly < MAX_WALLPOLYS && currentwallvert < MAX_WALLVERTS && (currentwallvert + s->polys->numverts) <= MAX_WALLVERTS) @@ -914,7 +913,6 @@ e->angles[0] = -e->angles[0]; // stupid quake bug } continue; } - c_brush_polys++; t = R_TextureAnimation (s->texinfo->texture); v = s->polys->verts[0]; if (vertexlit || s->texinfo->texture->transparent) diff --git a/gl_warp.c b/gl_warp.c index ddedddb3..5bf52b35 100644 --- a/gl_warp.c +++ b/gl_warp.c @@ -246,7 +246,7 @@ void LoadSky_f (void) } } -extern cvar_t r_skyboxsize; +extern cvar_t r_farclip; #define R_SkyBoxPolyVec(s,t,x,y,z) \ glTexCoord2f((s) * (254.0f/256.0f) + (1.0f/256.0f), (t) * (254.0f/256.0f) + (1.0f/256.0f));\ diff --git a/pr_edict.c b/pr_edict.c index 27c924c3..93d306b6 100644 --- a/pr_edict.c +++ b/pr_edict.c @@ -880,7 +880,7 @@ qboolean ED_ParseEpair (void *base, ddef_t *key, char *s) if (!def) { // LordHavoc: don't warn about worldspawn sky/fog fields because they don't require mod support - if (strcmp(s, "sky") && strncmp(s, "fog_", 4) && strcmp(s, "skyboxsize")) + if (strcmp(s, "sky") && strcmp(s, "fog") && strncmp(s, "fog_", 4) && strcmp(s, "farclip")) Con_DPrintf ("Can't find field %s\n", s); return false; } diff --git a/pr_exec.c b/pr_exec.c index 6650aa96..4dd41a93 100644 --- a/pr_exec.c +++ b/pr_exec.c @@ -1358,6 +1358,12 @@ void PR_ExecuteProgram (func_t fnum) case OP_DIV_FI: OPC->_float = OPA->_float / (float) OPB->_int; break; + case OP_CONV_IF: + OPC->_float = OPA->_int; + break; + case OP_CONV_FI: + OPC->_int = OPA->_float; + break; case OP_BITAND_I: OPC->_int = OPA->_int & OPB->_int; break; diff --git a/protocol.h b/protocol.h index 027871ee..8d7cecfc 100644 --- a/protocol.h +++ b/protocol.h @@ -179,7 +179,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define svc_hidelmp 36 // [string] slotname #define svc_skybox 37 // [string] skyname -#define svc_skyboxsize 50 // [coord] size (default is 4096) +#define svc_farclip 50 // [coord] size (default is 6144) #define svc_fog 51 // [byte] enable [float] density [byte] red [byte] green [byte] blue // diff --git a/r_light.c b/r_light.c index 2246670c..af8003c2 100644 --- a/r_light.c +++ b/r_light.c @@ -363,6 +363,12 @@ void R_DynamicLightPointNoMask(vec3_t color, vec3_t org) } } +void R_CompleteLightPoint (vec3_t color, vec3_t p) +{ + R_LightPoint(color, p); + R_DynamicLightPointNoMask(color, p); +} + extern float *aliasvert; extern float *aliasvertnorm; extern byte *aliasvertcolor; diff --git a/r_part.c b/r_part.c index ab082e10..914e54ea 100644 --- a/r_part.c +++ b/r_part.c @@ -43,7 +43,8 @@ int r_numparticles; vec3_t r_pright, r_pup, r_ppn; -cvar_t r_particles = {"r_particles", "1", true}; +cvar_t r_particles = {"r_particles", "1"}; +cvar_t r_dynamicparticles = {"r_dynamicparticles", "1"}; void fractalnoise(char *noise, int size); void fractalnoise_zeroedge(char *noise, int size); @@ -56,7 +57,7 @@ void R_InitParticleTexture (void) vec3_t normal, light; particletexture = texture_extension_number++; - glBindTexture(GL_TEXTURE_2D, particletexture); + glBindTexture(GL_TEXTURE_2D, particletexture); for (x=0 ; x<32 ; x++) { @@ -156,7 +157,7 @@ void R_InitParticleTexture (void) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); flareparticletexture = texture_extension_number++; - glBindTexture(GL_TEXTURE_2D, flareparticletexture); + glBindTexture(GL_TEXTURE_2D, flareparticletexture); for (x=0 ; x<32 ; x++) { @@ -178,7 +179,7 @@ void R_InitParticleTexture (void) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); rainparticletexture = texture_extension_number++; - glBindTexture(GL_TEXTURE_2D, rainparticletexture); + glBindTexture(GL_TEXTURE_2D, rainparticletexture); for (x=0 ; x<32 ; x++) { @@ -209,7 +210,7 @@ void R_InitParticleTexture (void) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); bubbleparticletexture = texture_extension_number++; - glBindTexture(GL_TEXTURE_2D, bubbleparticletexture); + glBindTexture(GL_TEXTURE_2D, bubbleparticletexture); light[0] = 1;light[1] = 1;light[2] = 1; VectorNormalize(light); @@ -281,6 +282,7 @@ void R_InitParticles (void) particles = (particle_t *) Hunk_AllocName (r_numparticles * sizeof(particle_t), "particles"); Cvar_RegisterVariable (&r_particles); + Cvar_RegisterVariable (&r_dynamicparticles); R_InitParticleTexture (); } @@ -473,7 +475,7 @@ void R_ParticleExplosion (vec3_t org, int smoke) p->next = active_particles; active_particles = p; - p->texnum = smokeparticletexture[rand()&7]; + p->texnum = particletexture; p->scale = lhrandom(1,3); p->alpha = rand()&255; p->die = cl.time + 5; @@ -552,7 +554,7 @@ void R_ParticleExplosion2 (vec3_t org, int colorStart, int colorLength) for (j=0 ; j<3 ; j++) { p->org[j] = org[j] + ((rand()&15)-8); - p->vel[j] = lhrandom(-128, 128); + p->vel[j] = lhrandom(-192, 192); } } } @@ -633,15 +635,15 @@ void R_RunParticleEffect (vec3_t org, vec3_t dir, int color, int count) free_particles = p->next; p->next = active_particles; active_particles = p; - if (count & 3) + if (count & 7) { - p->alpha = (count & 3) * 16 + (rand()&15); - count &= ~3; + p->alpha = (count & 7) * 16 + (rand()&15); + count &= ~7; } else { - p->alpha = 64; - count -= 4; + p->alpha = 128; + count -= 8; } p->texnum = particletexture; @@ -1237,6 +1239,7 @@ R_DrawParticles =============== */ extern cvar_t sv_gravity; +void R_CompleteLightPoint (vec3_t color, vec3_t p); void R_DrawParticles (void) { @@ -1244,7 +1247,7 @@ void R_DrawParticles (void) int i, r,g,b,a; float grav, grav1, time1, time2, time3, dvel, frametime, scale, scale2; byte *color24; - vec3_t up, right, uprightangles, forward2, up2, right2, v; + vec3_t up, right, uprightangles, forward2, up2, right2, v, tempcolor; // LordHavoc: early out condition if (!active_particles) @@ -1311,6 +1314,13 @@ void R_DrawParticles (void) g >>= 1; b >>= 1; } + if (r_dynamicparticles.value) + { + R_CompleteLightPoint(tempcolor, p->org); + r = (r * (int) tempcolor[0]) >> 7; + g = (g * (int) tempcolor[1]) >> 7; + b = (b * (int) tempcolor[2]) >> 7; + } transpolybegin(p->texnum, 0, p->texnum, TPOLYTYPE_ALPHA); if (p->texnum == rainparticletexture) // rain streak { -- 2.39.2