Fix for #29 for lightstyles

This commit is contained in:
Ryan Baldwin 2022-08-04 23:58:59 -07:00
parent 9ce4438cb5
commit 66884a2876
15 changed files with 172 additions and 96 deletions

BIN
.DS_Store vendored

Binary file not shown.

View file

@ -67,6 +67,7 @@ COMMON_OBJS = chase.c \
cl_main.c \
cl_parse.c \
cl_tent.c \
bsp_strlcpy.c \
cmd.c \
common.c \
console.c \

Binary file not shown.

Binary file not shown.

54
source/bsp_strlcpy.c Normal file
View file

@ -0,0 +1,54 @@
/* $OpenBSD: strlcpy.c,v 1.11 2006/05/05 15:27:38 millert Exp $ */
/*
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <sys/types.h>
#include <string.h>
#include "strl_fn.h"
/*
* Copy src to string dst of size siz. At most siz-1 characters
* will be copied. Always NUL terminates (unless siz == 0).
* Returns strlen(src); if retval >= siz, truncation occurred.
*/
size_t
q_strlcpy (char *dst, const char *src, size_t siz)
{
char *d = dst;
const char *s = src;
size_t n = siz;
/* Copy as many bytes as will fit */
if (n != 0) {
while (--n != 0) {
if ((*d++ = *s++) == '\0')
break;
}
}
/* Not enough room in dst, add NUL and traverse rest of src */
if (n == 0) {
if (siz != 0)
*d = '\0'; /* NUL-terminate dst */
while (*s++)
;
}
return(s - src - 1); /* count does not include NUL */
}

View file

@ -1024,6 +1024,7 @@ void CL_ParseServerMessage (void)
{
int cmd;
int i;
int total, j, lastcmd; //johnfitz
//
// if recording demos, copy the message out
@ -1130,8 +1131,23 @@ void CL_ParseServerMessage (void)
i = MSG_ReadByte ();
if (i >= MAX_LIGHTSTYLES)
Sys_Error ("svc_lightstyle > MAX_LIGHTSTYLES");
Q_strcpy (cl_lightstyle[i].map, MSG_ReadString());
q_strlcpy (cl_lightstyle[i].map, MSG_ReadString(), MAX_STYLESTRING);
cl_lightstyle[i].length = Q_strlen(cl_lightstyle[i].map);
//johnfitz -- save extra info
if (cl_lightstyle[i].length)
{
total = 0;
cl_lightstyle[i].peak = 'a';
for (j=0; j<cl_lightstyle[i].length; j++)
{
total += cl_lightstyle[i].map[j] - 'a';
cl_lightstyle[i].peak = max(cl_lightstyle[i].peak, cl_lightstyle[i].map[j]);
}
cl_lightstyle[i].average = total / cl_lightstyle[i].length + 'a';
}
else
cl_lightstyle[i].average = cl_lightstyle[i].peak = 'm';
//johnfitz
break;
case svc_sound:

View file

@ -36,6 +36,8 @@ typedef struct
{
int length;
char map[MAX_STYLESTRING];
char average; //johnfitz
char peak; //johnfitz
} lightstyle_t;
typedef struct

View file

@ -155,7 +155,8 @@ typedef struct msurface_s
// lighting info
int dlightframe;
int dlightbits;
unsigned int dlightbits[(MAX_DLIGHTS + 31) >> 5];
// int is 32 bits, need an array for MAX_DLIGHTS > 32
int lightmaptexturenum;
byte styles[MAXLIGHTMAPS];

View file

@ -1,5 +1,7 @@
/*
Copyright (C) 1996-1997 Id Software, Inc.
Copyright (C) 1996-2001 Id Software, Inc.
Copyright (C) 2002-2009 John Fitzgibbons and others
Copyright (C) 2010-2014 QuakeSpasm developers
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@ -23,7 +25,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
int r_dlightframecount;
vec3_t lightcolor; //johnfitz -- lit support via lordhavoc
extern cvar_t r_flatlightstyles; //johnfitz
/*
==================
@ -45,17 +47,25 @@ void R_AnimateLight (void)
d_lightstylevalue[j] = 256;
continue;
}
//johnfitz -- r_flatlightstyles
if (r_flatlightstyles.value == 2)
k = cl_lightstyle[j].peak - 'a';
else if (r_flatlightstyles.value == 1)
k = cl_lightstyle[j].average - 'a';
else
{
k = i % cl_lightstyle[j].length;
k = cl_lightstyle[j].map[k] - 'a';
k = k*22;
d_lightstylevalue[j] = k;
}
d_lightstylevalue[j] = k*22;
//johnfitz
}
}
/*
=============================================================================
DYNAMIC LIGHTS BLEND RENDERING
DYNAMIC LIGHTS BLEND RENDERING (gl_flashblend 1)
=============================================================================
*/
@ -83,14 +93,14 @@ void R_RenderDlight (dlight_t *light)
rad = light->radius * 0.35;
VectorSubtract (light->origin, r_origin, v);
if (Length (v) < rad)
if (VectorLength (v) < rad)
{ // view is inside the dlight
AddLightBlend (1, 0.5, 0, light->radius * 0.0003);
return;
}
glBegin (GL_TRIANGLE_FAN);
glColor3f (0.2,0.1,0.0);
glColor3f (light->color[0],light->color[1],light->color[2]);
for (i=0 ; i<3 ; i++)
v[i] = light->origin[i] - vpn[i]*rad;
glVertex3fv (v);
@ -153,56 +163,44 @@ DYNAMIC LIGHTS
/*
=============
R_MarkLights
R_MarkLights -- johnfitz -- rewritten to use LordHavoc's lighting speedup
=============
*/
void R_MarkLights (dlight_t *light, int bit, mnode_t *node)
void R_MarkLights (dlight_t *light, int num, mnode_t *node)
{
mplane_t *splitplane;
float dist;
msurface_t *surf;
int i;
// LordHavoc: .lit support begin (actually this is just a major lighting speedup, no relation to color :)
float l, maxdist;
int j, s, t;
vec3_t impact;
loc0:
// LordHavoc: .lit support end
float dist, l, maxdist;
int i, j, s, t;
start:
if (node->contents < 0)
return;
splitplane = node->plane; // LordHavoc: original code
// LordHavoc: .lit support (actually this is just a major lighting speedup, no relation to color :)
splitplane = node->plane;
if (splitplane->type < 3)
dist = light->origin[splitplane->type] - splitplane->dist;
else
dist = DotProduct (light->origin, splitplane->normal) - splitplane->dist; // LordHavoc: original code
// LordHavoc: .lit support end
dist = DotProduct (light->origin, splitplane->normal) - splitplane->dist;
if (dist > light->radius)
{
// LordHavoc: .lit support begin (actually this is just a major lighting speedup, no relation to color :)
node = node->children[0];
goto loc0;
// LordHavoc: .lit support end
goto start;
}
if (dist < -light->radius)
{
// LordHavoc: .lit support begin (actually this is just a major lighting speedup, no relation to color :)
node = node->children[1];
goto loc0;
// LordHavoc: .lit support end
goto start;
}
maxdist = light->radius*light->radius; // LordHavoc: .lit support (actually this is just a major lighting speedup, no relation to color :)
maxdist = light->radius*light->radius;
// mark the polygons
surf = cl.worldmodel->surfaces + node->firstsurface;
for (i=0 ; i<node->numsurfaces ; i++, surf++)
{
// LordHavoc: .lit support begin (actually this is just a major lighting speedup, no relation to color :)
// LordHavoc: MAJOR dynamic light speedup here, eliminates marking of surfaces that are too far away from light, thus preventing unnecessary renders and uploads
for (j=0 ; j<3 ; j++)
impact[j] = light->origin[j] - surf->plane->normal[j]*dist;
// clamp center of light to corner and check brightness
@ -217,24 +215,20 @@ loc0:
{
if (surf->dlightframe != r_dlightframecount) // not dynamic until now
{
surf->dlightbits = bit;
surf->dlightbits[num >> 5] = 1U << (num & 31);
surf->dlightframe = r_dlightframecount;
}
else // already dynamic
surf->dlightbits |= bit;
surf->dlightbits[num >> 5] |= 1U << (num & 31);
}
// LordHavoc: .lit support end
}
// LordHavoc: .lit support begin (actually this is just a major lighting speedup, no relation to color :)
if (node->children[0]->contents >= 0)
R_MarkLights (light, bit, node->children[0]); // LordHavoc: original code
R_MarkLights (light, num, node->children[0]);
if (node->children[1]->contents >= 0)
R_MarkLights (light, bit, node->children[1]); // LordHavoc: original code
// LordHavoc: .lit support end
R_MarkLights (light, num, node->children[1]);
}
/*
=============
R_PushDlights
@ -256,14 +250,16 @@ void R_PushDlights (void)
{
if (l->die < cl.time || !l->radius)
continue;
R_MarkLights ( l, 1<<i, cl.worldmodel->nodes );
R_MarkLights (l, i, cl.worldmodel->nodes);
}
}
/*
=============================================================================
LIGHT SAMPLING
=============================================================================
*/
@ -271,8 +267,11 @@ mplane_t *lightplane;
vec3_t lightspot;
vec3_t lightcolor; //johnfitz -- lit support via lordhavoc
// LordHavoc: .lit support begin
// LordHavoc: original code replaced entirely
/*
=============
RecursiveLightPoint -- johnfitz -- replaced entire function for lit support via lordhavoc
=============
*/
int RecursiveLightPoint (vec3_t color, mnode_t *node, vec3_t start, vec3_t end)
{
float front, back, frac;
@ -324,8 +323,11 @@ loc0:
if (surf->flags & SURF_DRAWTILED)
continue; // no lightmaps
ds = (int) ((float) DotProduct (mid, surf->texinfo->vecs[0]) + surf->texinfo->vecs[0][3]);
dt = (int) ((float) DotProduct (mid, surf->texinfo->vecs[1]) + surf->texinfo->vecs[1][3]);
// ericw -- added double casts to force 64-bit precision.
// Without them the zombie at the start of jam3_ericw.bsp was
// incorrectly being lit up in SSE builds.
ds = (int) ((double) DoublePrecisionDotProduct (mid, surf->texinfo->vecs[0]) + surf->texinfo->vecs[0][3]);
dt = (int) ((double) DoublePrecisionDotProduct (mid, surf->texinfo->vecs[1]) + surf->texinfo->vecs[1][3]);
if (ds < surf->texturemins[0] || dt < surf->texturemins[1])
continue;
@ -368,10 +370,15 @@ loc0:
}
}
vec3_t lightcolor; // LordHavoc: used by model rendering
/*
=============
R_LightPoint -- johnfitz -- replaced entire function for lit support via lordhavoc
=============
*/
int R_LightPoint (vec3_t p)
{
vec3_t end;
if (!cl.worldmodel->lightdata)
{
lightcolor[0] = lightcolor[1] = lightcolor[2] = 255;
@ -381,9 +388,8 @@ int R_LightPoint (vec3_t p)
end[0] = p[0];
end[1] = p[1];
end[2] = p[2] - 8192; //johnfitz -- was 2048
lightcolor[0] = lightcolor[1] = lightcolor[2] = 0;
RecursiveLightPoint (lightcolor, cl.worldmodel->nodes, p, end);
return ((lightcolor[0] + lightcolor[1] + lightcolor[2]) * (1.0f / 3.0f));
}
// LordHavoc: .lit support end

View file

@ -123,6 +123,8 @@ cvar_t r_model_brightness = { "r_model_brightness", "1", qtrue}; // Toggle h
cvar_t r_farclip = {"r_farclip", "4096"}; //far cliping for q3 models
cvar_t r_flatlightstyles = {"r_flatlightstyles", "0", qfalse};
//johnfitz -- struct for passing lerp information to drawing functions
typedef struct {
short pose1;

View file

@ -21,7 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "quakedef.h"
extern cvar_t r_flatlightstyles;
/*
==================
@ -230,6 +230,8 @@ void R_Init (void)
Cvar_RegisterVariable (&r_flametype);
//Cvar_RegisterVariable (&r_model_brightness);
Cvar_RegisterVariable (&r_flatlightstyles);
R_InitParticles ();
R_InitParticleTexture ();
Fog_Init ();

View file

@ -67,10 +67,6 @@ R_AddDynamicLights
*/
void R_AddDynamicLights (msurface_t *surf)
{
// LordHavoc: .lit support begin
float cred, cgreen, cblue, brightness;
unsigned *bl;
// LordHavoc: .lit support end
int lnum;
int sd, td;
float dist, rad, minlight;
@ -79,6 +75,10 @@ void R_AddDynamicLights (msurface_t *surf)
int i;
int smax, tmax;
mtexinfo_t *tex;
//johnfitz -- lit support via lordhavoc
float cred, cgreen, cblue, brightness;
unsigned *bl;
//johnfitz
smax = (surf->extents[0]>>4)+1;
tmax = (surf->extents[1]>>4)+1;
@ -86,7 +86,7 @@ void R_AddDynamicLights (msurface_t *surf)
for (lnum=0 ; lnum<MAX_DLIGHTS ; lnum++)
{
if ( !(surf->dlightbits & (1<<lnum) ) )
if (! (surf->dlightbits[lnum >> 5] & (1U << (lnum & 31))))
continue; // not lit by this light
rad = cl_dlights[lnum].radius;
@ -110,13 +110,12 @@ void R_AddDynamicLights (msurface_t *surf)
local[0] -= surf->texturemins[0];
local[1] -= surf->texturemins[1];
// LordHavoc: .lit support begin
//johnfitz -- lit support via lordhavoc
bl = blocklights;
cred = cl_dlights[lnum].color[0] * 256.0f;
cgreen = cl_dlights[lnum].color[1] * 256.0f;
cblue = cl_dlights[lnum].color[2] * 256.0f;
// LordHavoc: .lit support end
//johnfitz
for (t = 0 ; t<tmax ; t++)
{
td = local[1] - t*16;
@ -131,33 +130,16 @@ void R_AddDynamicLights (msurface_t *surf)
dist = sd + (td>>1);
else
dist = td + (sd>>1);
if (dist < minlight){
brightness = rad - dist;
if (!cl_dlights[lnum].dark)
if (dist < minlight)
//johnfitz -- lit support via lordhavoc
{
brightness = rad - dist;
bl[0] += (int) (brightness * cred);
bl[1] += (int) (brightness * cgreen);
bl[2] += (int) (brightness * cblue);
}
else
{
if(bl[0] > (int) (brightness * cred))
bl[0] -= (int) (brightness * cred);
else
bl[0] = 0;
if(bl[1] > (int) (brightness * cgreen))
bl[1] -= (int) (brightness * cgreen);
else
bl[1] = 0;
if(bl[2] > (int) (brightness * cblue))
bl[2] -= (int) (brightness * cblue);
else
bl[2] = 0;
}
}
bl += 3;
//johnfitz
}
}
}

View file

@ -42,6 +42,7 @@ extern int nanmask;
#define Q_rint(x) ((x) > 0 ? (int)((x) + 0.5) : (int)((x) - 0.5)) //johnfitz -- from joequake
#define DotProduct(x,y) (x[0]*y[0]+x[1]*y[1]+x[2]*y[2])
#define DoublePrecisionDotProduct(x,y) ((double)x[0]*y[0]+(double)x[1]*y[1]+(double)x[2]*y[2])
#define VectorSubtract(a,b,c) {c[0]=a[0]-b[0];c[1]=a[1]-b[1];c[2]=a[2]-b[2];}
#define VectorAdd(a,b,c) {c[0]=a[0]+b[0];c[1]=a[1]+b[1];c[2]=a[2]+b[2];}
#define VectorCopy(a,b) {b[0]=a[0];b[1]=a[1];b[2]=a[2];}

View file

@ -322,6 +322,7 @@ typedef struct
#ifdef GLQUAKE
#include "gl_model.h"
#include "gl_decal.h"
#else
#include "model.h"
#include "d_iface.h"
@ -342,8 +343,6 @@ typedef struct
#include "cl_hud.h"
#include "gl_decal.h"
//=============================================================================
// the host system specifies the base of the directory tree, the

10
source/strl_fn.h Normal file
View file

@ -0,0 +1,10 @@
/* header file for BSD strlcat and strlcpy */
#ifndef __STRLFUNCS_H
#define __STRLFUNCS_H
/* use our own copies of strlcpy and strlcat taken from OpenBSD */
extern size_t q_strlcpy (char *dst, const char *src, size_t size);
extern size_t q_strlcat (char *dst, const char *src, size_t size);
#endif /* __STRLFUNCS_H */