From e730608dd7148dd4097c6c3950f5d903e8d0c8b0 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sat, 26 May 2012 11:06:21 +0900 Subject: [PATCH] Implement r_flatlightstyles from fitzquake. --- include/QF/render.h | 2 ++ include/r_cvar.h | 1 + libs/video/renderer/r_cvar.c | 4 ++++ libs/video/renderer/r_light.c | 13 +++++++++---- nq/source/cl_parse.c | 15 +++++++++++++++ qw/source/cl_parse.c | 15 +++++++++++++++ 6 files changed, 46 insertions(+), 4 deletions(-) diff --git a/include/QF/render.h b/include/QF/render.h index 894f90303..15e685745 100644 --- a/include/QF/render.h +++ b/include/QF/render.h @@ -75,6 +75,8 @@ typedef struct { int length; char map[MAX_STYLESTRING]; + char average; + char peak; } lightstyle_t; //=============== diff --git a/include/r_cvar.h b/include/r_cvar.h index f0d295cd7..8383f4705 100644 --- a/include/r_cvar.h +++ b/include/r_cvar.h @@ -65,6 +65,7 @@ extern struct cvar_s *r_dynamic; extern struct cvar_s *r_explosionclip; extern struct cvar_s *r_farclip; extern struct cvar_s *r_firecolor; +extern struct cvar_s *r_flatlightstyles; extern struct cvar_s *r_fullbright; extern struct cvar_s *r_graphheight; extern struct cvar_s *r_lightmap; diff --git a/libs/video/renderer/r_cvar.c b/libs/video/renderer/r_cvar.c index 0312405f3..f1d138b03 100644 --- a/libs/video/renderer/r_cvar.c +++ b/libs/video/renderer/r_cvar.c @@ -68,6 +68,7 @@ cvar_t *r_dynamic; cvar_t *r_explosionclip; cvar_t *r_farclip; cvar_t *r_firecolor; +cvar_t *r_flatlightstyles; cvar_t *r_graphheight; cvar_t *r_lightmap_components; cvar_t *r_maxedges; @@ -236,6 +237,9 @@ R_Init_Cvars (void) "player."); r_firecolor = Cvar_Get ("r_firecolor", "0.9 0.7 0.0", CVAR_ARCHIVE, NULL, "color of rocket and lava ball fires"); + r_flatlightstyles = Cvar_Get ("r_flatlightstyles", "0", CVAR_NONE, NULL, + "Disable animated lightmaps. 2 = use peak, " + "1 = use average, anything else = normal"); r_graphheight = Cvar_Get ("r_graphheight", "32", CVAR_NONE, NULL, "Set the number of lines displayed in the " "various graphs"); diff --git a/libs/video/renderer/r_light.c b/libs/video/renderer/r_light.c index 8406e62c1..ffea9afdf 100644 --- a/libs/video/renderer/r_light.c +++ b/libs/video/renderer/r_light.c @@ -132,10 +132,15 @@ R_AnimateLight (void) d_lightstylevalue[j] = 256; continue; } - k = i % vr_data.lightstyle[j].length; - k = vr_data.lightstyle[j].map[k] - 'a'; - k = k * 22; - d_lightstylevalue[j] = k; + if (r_flatlightstyles->int_val == 2) { + k = vr_data.lightstyle[j].peak - 'a'; + } else if (r_flatlightstyles->int_val == 1) { + k = vr_data.lightstyle[j].average - 'a'; + } else { + k = i % vr_data.lightstyle[j].length; + k = vr_data.lightstyle[j].map[k] - 'a'; + } + d_lightstylevalue[j] = k * 22; } } diff --git a/nq/source/cl_parse.c b/nq/source/cl_parse.c index ac83a5e71..dd6374531 100644 --- a/nq/source/cl_parse.c +++ b/nq/source/cl_parse.c @@ -974,6 +974,21 @@ CL_ParseServerMessage (void) Host_Error ("svc_lightstyle > MAX_LIGHTSTYLES"); strcpy (cl.lightstyle[i].map, MSG_ReadString (net_message)); cl.lightstyle[i].length = strlen (cl.lightstyle[i].map); + if (cl.lightstyle[i].length) { + int 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]); + } + total /= cl.lightstyle[i].length; + cl.lightstyle[i].average = total + 'a'; + } else { + cl.lightstyle[i].average = 'm'; + cl.lightstyle[i].peak = 'm'; + } break; case svc_updatename: diff --git a/qw/source/cl_parse.c b/qw/source/cl_parse.c index 29eeedb09..abb2266ac 100644 --- a/qw/source/cl_parse.c +++ b/qw/source/cl_parse.c @@ -1444,6 +1444,21 @@ CL_ParseServerMessage (void) Host_Error ("svc_lightstyle > MAX_LIGHTSTYLES"); strcpy (cl.lightstyle[i].map, MSG_ReadString (net_message)); cl.lightstyle[i].length = strlen (cl.lightstyle[i].map); + if (cl.lightstyle[i].length) { + int 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]); + } + total /= cl.lightstyle[i].length; + cl.lightstyle[i].average = total + 'a'; + } else { + cl.lightstyle[i].average = 'm'; + cl.lightstyle[i].peak = 'm'; + } break; // svc_updatename