Index: twilight/TODO
diff -u twilight/TODO:1.74 twilight/TODO:1.75
--- twilight/TODO:1.74	Mon Aug 19 10:09:04 2002
+++ twilight/TODO	Tue Aug 20 18:52:18 2002
@@ -8,7 +8,6 @@
 
 Bugs we know about:
 
-  - RC: Dlights are screwed after the first map. (WAAAAY too dark.)
   - RC: When you touch the bottom of a pool, you make a splash sound.  DP
     broke this and DP has fixed it.
   - RC: Fix net_udp (line 112) so we don't resolve non-network connections.
Index: twilight/nq/gl_rlight.c
diff -u twilight/nq/gl_rlight.c:1.63 twilight/nq/gl_rlight.c:1.64
--- twilight/nq/gl_rlight.c:1.63	Tue Aug  6 10:59:07 2002
+++ twilight/nq/gl_rlight.c	Tue Aug 20 18:52:18 2002
@@ -23,7 +23,7 @@
 
 */
 static const char rcsid[] =
-    "$Id: gl_rlight.c,v 1.63 2002/08/06 14:59:07 warp Exp $";
+    "$Id: gl_rlight.c,v 1.64 2002/08/20 22:52:18 warp Exp $";
 
 #include "twiconfig.h"
 
@@ -43,7 +43,6 @@
 
 rdlight_t r_dlight[MAX_DLIGHTS];
 int r_numdlights = 0;
-Uint r_dlightframecount;
 
 static int corona_texture;
 
@@ -204,7 +203,6 @@
 
 		rd->cullradius2 = rd->cullradius * rd->cullradius;
 		rd->lightsubtract = 1.0f / rd->cullradius2;
-		r_numdlights++;
 	}
 }
 
@@ -394,8 +392,6 @@
 		return;
 	}
 
-	r_dlightframecount++;
-
 	radius = light->cullradius;
 
 	// for comparisons to maximum light distance
@@ -439,9 +435,9 @@
 						do {
 							surf = *mark++;
 
-							if (surf->lightframe == r_dlightframecount)
+							if (surf->lightframe == r_framecount)
 								continue;
-							surf->lightframe = r_dlightframecount;
+							surf->lightframe = r_framecount;
 							if (surf->visframe != vis_framecount)
 								continue;
 
Index: twilight/nq/gl_rmain.c
diff -u twilight/nq/gl_rmain.c:1.126 twilight/nq/gl_rmain.c:1.127
--- twilight/nq/gl_rmain.c:1.126	Wed Aug 14 10:21:48 2002
+++ twilight/nq/gl_rmain.c	Tue Aug 20 18:52:18 2002
@@ -23,7 +23,7 @@
 
 */
 static const char rcsid[] =
-	"$Id: gl_rmain.c,v 1.126 2002/08/14 14:21:48 warp Exp $";
+	"$Id: gl_rmain.c,v 1.127 2002/08/20 22:52:18 warp Exp $";
 
 #include "twiconfig.h"
 
@@ -792,14 +792,11 @@
 R_NewMap (void)
 {
 	Uint32			i;
-	extern Sint32	r_dlightframecount;
 
 	for (i = 0; i < 256; i++)
 		d_lightstylevalue[i] = 264;		// normal light value
 
 	R_ClearParticles ();
-
-	r_dlightframecount = 0;
 
 	// some Cvars need resetting on map change
 	Cvar_Set (r_skyname, "");
Index: twilight/nq/gl_rsurf.c
diff -u twilight/nq/gl_rsurf.c:1.101 twilight/nq/gl_rsurf.c:1.102
--- twilight/nq/gl_rsurf.c:1.101	Wed Aug 14 10:21:48 2002
+++ twilight/nq/gl_rsurf.c	Tue Aug 20 18:52:19 2002
@@ -23,7 +23,7 @@
 
 */
 static const char rcsid[] =
-    "$Id: gl_rsurf.c,v 1.101 2002/08/14 14:21:48 warp Exp $";
+    "$Id: gl_rsurf.c,v 1.102 2002/08/20 22:52:19 warp Exp $";
 
 #include "twiconfig.h"
 
@@ -39,20 +39,14 @@
 #include "sky.h"
 #include "liquid.h"
 
-#define	BLOCK_WIDTH		128
-#define	BLOCK_HEIGHT	128
-#define	MAX_LIGHTMAPS	256
-
 extern int lightmap_bytes;				// 1, 3, or 4
 extern int lightmap_shift;
 
-extern Uint8 templight[BLOCK_WIDTH * BLOCK_HEIGHT * 4];
-static Uint32 blocklights[BLOCK_WIDTH * BLOCK_HEIGHT * 3];
+extern Uint8 templight[LIGHTBLOCK_WIDTH * LIGHTBLOCK_HEIGHT * 4];
+static Uint32 blocklights[LIGHTBLOCK_WIDTH * LIGHTBLOCK_HEIGHT * 3];
 
 static int dlightdivtable[32768];
 
-vec3_t modelorg;
-
 void
 R_InitSurf (void)
 {
@@ -77,10 +71,11 @@
 	int				dist2, maxdist, maxdist2, maxdist3;
 	int				impacts, impactt, subtract;
 	int				sdtable[256];
-	unsigned int	*bl;
+	Uint			*bl;
+	rdlight_t		*rd;
 	float			dist;
 	vec3_t			impact, local;
-	Sint64			k;
+	Uint64			k;
 
 	lit = false;
 
@@ -92,13 +87,15 @@
 	{
 		if (!(surf->dlightbits & (1 << (lnum & 31))))
 			continue;                   // not lit by this light
+
+		rd = &r_dlight[lnum];
 
-		VectorCopy (r_dlight[lnum].origin, local);
+		VectorCopy (rd->origin, local);
 		dist = PlaneDiff (local, surf->plane);
 		
 		// for comparisons to minimum acceptable light
 		// compensate for LIGHTOFFSET
-		maxdist = (int) r_dlight[lnum].cullradius2 + LIGHTOFFSET;
+		maxdist = (int) rd->cullradius2 + LIGHTOFFSET;
 		
 		dist2 = dist * dist;
 		dist2 += LIGHTOFFSET;
@@ -137,10 +134,10 @@
 		maxdist3 = maxdist - dist2;
 
 		// convert to 8.8 blocklights format
-		red = r_dlight[lnum].light[0];
-		green = r_dlight[lnum].light[1];
-		blue = r_dlight[lnum].light[2];
-		subtract = (int) (r_dlight[lnum].lightsubtract * 4194304.0f);
+		red = rd->light[0];
+		green = rd->light[1];
+		blue = rd->light[2];
+		subtract = (int) (rd->lightsubtract * 4194304.0f);
 		bl = blocklights;
 
 		i = impactt;
@@ -438,7 +435,7 @@
 		memset (blocklights, 0, size3 * sizeof(Uint32));
 
 		// add all the dynamic lights
-		if (surf->dlightframe == vis_framecount)
+		if (surf->dlightframe == r_framecount)
 			if (R_AddDynamicLights (surf))
 				surf->cached_dlight = 1;
 
@@ -531,7 +528,7 @@
 	if (!r_dynamic->ivalue)
 		return;
 
-	if (fa->dlightframe == vis_framecount // dynamic lighting
+	if (fa->dlightframe == r_framecount // dynamic lighting
 			|| fa->cached_dlight // previously lit
 			|| d_lightstylevalue[fa->styles[0]] != fa->cached_light[0]
 			|| d_lightstylevalue[fa->styles[1]] != fa->cached_light[1]
@@ -588,7 +585,7 @@
 R_DrawBrushDepthSkies (void)
 {
 	int			 i;
-	vec3_t		 mins, maxs;
+	vec3_t		 mins, maxs, org;
 	brushhdr_t	*brush;
 	entity_t	*e;
 
@@ -609,7 +606,7 @@
 				continue;
 
 			softwaretransformforbrushentity (e->origin, e->angles);
-			softwareuntransform(r_origin, modelorg);
+			softwareuntransform(r_origin, org);
 
 			qglPushMatrix ();
 			qglTranslatef (e->origin[0], e->origin[1], e->origin[2]);
@@ -617,7 +614,7 @@
 			qglRotatef (e->angles[0], 0, 1, 0);
 			qglRotatef (e->angles[2], 1, 0, 0);
 
-			R_Draw_Depth_Sky_Chain (&brush->sky_chain, modelorg);
+			R_Draw_Depth_Sky_Chain (&brush->sky_chain, org);
 
 			qglPopMatrix ();
 		}
@@ -867,9 +864,10 @@
 	float			 dot;
 	model_t			*mod = e->model;
 	brushhdr_t		*brush = mod->brush;
+	vec3_t			 org;
 
 	softwaretransformforbrushentity (e->origin, e->angles);
-	softwareuntransform(r_origin, modelorg);
+	softwareuntransform(r_origin, org);
 		
 	/*
 	 * LordHavoc: decide which surfs are visible and update lightmaps, then
@@ -879,7 +877,7 @@
 			i < brush->nummodelsurfaces; i++, psurf++)
 	{
 		// find which side of the node we are on
-		dot = PlaneDiff (modelorg, psurf->plane);
+		dot = PlaneDiff (org, psurf->plane);
 
 		// draw the polygon
 		if (((psurf->flags & SURF_PLANEBACK) && (dot < -BACKFACE_EPSILON))
@@ -913,9 +911,6 @@
 	model_t			*mod = e->model;
 	brushhdr_t		*brush = mod->brush;
 
-	softwaretransformforbrushentity (e->origin, e->angles);
-	softwareuntransform(r_origin, modelorg);
-
 	// calculate dynamic lighting for bmodel if it's not an instanced model
 	if (brush->firstmodelsurface != 0 && !gl_flashblend->ivalue)
 	{
@@ -946,9 +941,6 @@
 R_DrawAddBrushModel (entity_t *e)
 {
 	model_t			*mod = e->model;
-
-	softwaretransformforbrushentity (e->origin, e->angles);
-	softwareuntransform(r_origin, modelorg);
 
 	qglPushMatrix ();
 
Index: twilight/qw/gl_rlight.c
diff -u twilight/qw/gl_rlight.c:1.68 twilight/qw/gl_rlight.c:1.69
--- twilight/qw/gl_rlight.c:1.68	Tue Aug  6 10:59:08 2002
+++ twilight/qw/gl_rlight.c	Tue Aug 20 18:52:19 2002
@@ -23,7 +23,7 @@
 
 */
 static const char rcsid[] =
-    "$Id: gl_rlight.c,v 1.68 2002/08/06 14:59:08 warp Exp $";
+    "$Id: gl_rlight.c,v 1.69 2002/08/20 22:52:19 warp Exp $";
 
 #include "twiconfig.h"
 
@@ -43,9 +43,7 @@
 
 rdlight_t r_dlight[MAX_DLIGHTS];
 int r_numdlights = 0;
-Uint r_dlightframecount;
 
-
 static int corona_texture;
 
 void
@@ -205,7 +203,6 @@
 
 		rd->cullradius2 = rd->cullradius * rd->cullradius;
 		rd->lightsubtract = 1.0f / rd->cullradius2;
-		r_numdlights++;
 	}
 }
 
@@ -395,8 +392,6 @@
 		return;
 	}
 
-	r_dlightframecount++;
-
 	radius = light->cullradius;
 
 	//for comparisons to maximum light distance
@@ -440,9 +435,9 @@
 						do {
 							surf = *mark++;
 
-							if (surf->lightframe == r_dlightframecount)
+							if (surf->lightframe == r_framecount)
 								continue;
-							surf->lightframe = r_dlightframecount;
+							surf->lightframe = r_framecount;
 							if (surf->visframe != vis_framecount)
 								continue;
 
Index: twilight/qw/gl_rmain.c
diff -u twilight/qw/gl_rmain.c:1.137 twilight/qw/gl_rmain.c:1.138
--- twilight/qw/gl_rmain.c:1.137	Wed Aug 14 10:21:49 2002
+++ twilight/qw/gl_rmain.c	Tue Aug 20 18:52:19 2002
@@ -23,7 +23,7 @@
 
 */
 static const char rcsid[] =
-	"$Id: gl_rmain.c,v 1.137 2002/08/14 14:21:49 warp Exp $";
+	"$Id: gl_rmain.c,v 1.138 2002/08/20 22:52:19 warp Exp $";
 
 #include "twiconfig.h"
 
@@ -754,7 +754,6 @@
 R_NewMap (void)
 {
 	Uint32			i;
-	extern Sint32	r_dlightframecount;
 
 	for (i = 0; i < 256; i++)
 		d_lightstylevalue[i] = 264;		// normal light value
@@ -765,8 +764,6 @@
 	memset (&cl_player_entities, 0, sizeof(cl_player_entities));
 	memset (&cl_static_entities, 0, sizeof(cl_static_entities));
 	cl_num_static_entities = 0;
-
-	r_dlightframecount = 0;
 
 	// some Cvars need resetting on map change
 	Cvar_Set (r_skyname, "");
Index: twilight/qw/gl_rsurf.c
diff -u twilight/qw/gl_rsurf.c:1.119 twilight/qw/gl_rsurf.c:1.120
--- twilight/qw/gl_rsurf.c:1.119	Wed Aug 14 10:21:49 2002
+++ twilight/qw/gl_rsurf.c	Tue Aug 20 18:52:19 2002
@@ -23,7 +23,7 @@
 
 */
 static const char rcsid[] =
-    "$Id: gl_rsurf.c,v 1.119 2002/08/14 14:21:49 warp Exp $";
+    "$Id: gl_rsurf.c,v 1.120 2002/08/20 22:52:19 warp Exp $";
 
 #include "twiconfig.h"
 
@@ -39,20 +39,14 @@
 #include "sky.h"
 #include "liquid.h"
 
-#define	BLOCK_WIDTH		128
-#define	BLOCK_HEIGHT	128
-#define	MAX_LIGHTMAPS	256
-
 extern int lightmap_bytes;				// 1, 3, or 4
 extern int lightmap_shift;
 
-extern Uint8 templight[BLOCK_WIDTH * BLOCK_HEIGHT * 4];
-static Uint32 blocklights[BLOCK_WIDTH * BLOCK_HEIGHT * 3];
+extern Uint8 templight[LIGHTBLOCK_WIDTH * LIGHTBLOCK_HEIGHT * 4];
+static Uint32 blocklights[LIGHTBLOCK_WIDTH * LIGHTBLOCK_HEIGHT * 3];
 
 static int dlightdivtable[32768];
 
-vec3_t modelorg;
-
 void
 R_InitSurf (void)
 {
@@ -77,10 +71,11 @@
 	int				dist2, maxdist, maxdist2, maxdist3;
 	int				impacts, impactt, subtract;
 	int				sdtable[256];
-	unsigned int	*bl;
+	Uint			*bl;
+	rdlight_t		*rd;
 	float			dist;
 	vec3_t			impact, local;
-	Sint64			k;
+	Uint64			k;
 
 	lit = false;
 
@@ -93,12 +88,13 @@
 		if (!(surf->dlightbits & (1 << (lnum & 31))))
 			continue;                   // not lit by this light
 
-		VectorCopy (r_dlight[lnum].origin, local);
+		rd = &r_dlight[lnum];
+		VectorCopy (rd->origin, local);
 		dist = PlaneDiff (local, surf->plane);
 		
 		// for comparisons to minimum acceptable light
 		// compensate for LIGHTOFFSET
-		maxdist = (int) r_dlight[lnum].cullradius2 + LIGHTOFFSET;
+		maxdist = (int) rd->cullradius2 + LIGHTOFFSET;
 		
 		dist2 = dist * dist;
 		dist2 += LIGHTOFFSET;
@@ -137,10 +133,10 @@
 		maxdist3 = maxdist - dist2;
 
 		// convert to 8.8 blocklights format
-		red = r_dlight[lnum].light[0];
-		green = r_dlight[lnum].light[1];
-		blue = r_dlight[lnum].light[2];
-		subtract = (int) (r_dlight[lnum].lightsubtract * 4194304.0f);
+		red = rd->light[0];
+		green = rd->light[1];
+		blue = rd->light[2];
+		subtract = (int) (rd->lightsubtract * 4194304.0f);
 		bl = blocklights;
 
 		i = impactt;
@@ -438,7 +434,7 @@
 		memset (blocklights, 0, size3 * sizeof(Uint32));
 
 		// add all the dynamic lights
-		if (surf->dlightframe == vis_framecount)
+		if (surf->dlightframe == r_framecount)
 			if (R_AddDynamicLights (surf))
 				surf->cached_dlight = 1;
 
@@ -531,7 +527,7 @@
 	if (!r_dynamic->ivalue)
 		return;
 
-	if (fa->dlightframe == vis_framecount // dynamic lighting
+	if (fa->dlightframe == r_framecount // dynamic lighting
 			|| fa->cached_dlight // previously lit
 			|| d_lightstylevalue[fa->styles[0]] != fa->cached_light[0]
 			|| d_lightstylevalue[fa->styles[1]] != fa->cached_light[1]
@@ -588,7 +584,7 @@
 R_DrawBrushDepthSkies (void)
 {
 	int			 i;
-	vec3_t		 mins, maxs;
+	vec3_t		 mins, maxs, org;
 	brushhdr_t	*brush;
 	entity_t	*e;
 
@@ -609,7 +605,7 @@
 				continue;
 
 			softwaretransformforbrushentity (e->cur.origin, e->cur.angles);
-			softwareuntransform(r_origin, modelorg);
+			softwareuntransform(r_origin, org);
 
 			qglPushMatrix ();
 			qglTranslatef(e->cur.origin[0], e->cur.origin[1], e->cur.origin[2]);
@@ -617,7 +613,7 @@
 			qglRotatef (e->cur.angles[0], 0, 1, 0);
 			qglRotatef (e->cur.angles[2], 1, 0, 0);
 
-			R_Draw_Depth_Sky_Chain (&brush->sky_chain, modelorg);
+			R_Draw_Depth_Sky_Chain (&brush->sky_chain, org);
 
 			qglPopMatrix ();
 		}
@@ -867,9 +863,10 @@
 	float			 dot;
 	model_t			*mod = e->model;
 	brushhdr_t		*brush = mod->brush;
+	vec3_t			 org;
 
 	softwaretransformforbrushentity (e->cur.origin, e->cur.angles);
-	softwareuntransform(r_origin, modelorg);
+	softwareuntransform(r_origin, org);
 		
 	/*
 	 * LordHavoc: decide which surfs are visible and update lightmaps, then
@@ -879,7 +876,7 @@
 			i < brush->nummodelsurfaces; i++, psurf++)
 	{
 		// find which side of the node we are on
-		dot = PlaneDiff (modelorg, psurf->plane);
+		dot = PlaneDiff (org, psurf->plane);
 
 		// draw the polygon
 		if (((psurf->flags & SURF_PLANEBACK) && (dot < -BACKFACE_EPSILON))
@@ -913,9 +910,6 @@
 	model_t			*mod = e->model;
 	brushhdr_t		*brush = mod->brush;
 
-	softwaretransformforbrushentity (e->cur.origin, e->cur.angles);
-	softwareuntransform(r_origin, modelorg);
-
 	// calculate dynamic lighting for bmodel if it's not an instanced model
 	if (brush->firstmodelsurface != 0 && !gl_flashblend->ivalue)
 	{
@@ -946,9 +940,6 @@
 R_DrawAddBrushModel (entity_t *e)
 {
 	model_t *mod = e->model;
-
-	softwaretransformforbrushentity (e->cur.origin, e->cur.angles);
-	softwareuntransform(r_origin, modelorg);
 
 	qglPushMatrix ();
 
Index: twilight/src/renderer/light.h
diff -u twilight/src/renderer/light.h:1.5 twilight/src/renderer/light.h:1.6
--- twilight/src/renderer/light.h:1.5	Mon Jul 29 23:16:01 2002
+++ twilight/src/renderer/light.h	Tue Aug 20 18:52:19 2002
@@ -21,7 +21,7 @@
 		59 Temple Place - Suite 330
 		Boston, MA  02111-1307, USA
 
-	$Id: light.h,v 1.5 2002/07/30 03:16:01 knghtbrd Exp $
+	$Id: light.h,v 1.6 2002/08/20 22:52:19 warp Exp $
 */
 
 #ifndef __RENDERER_LIGHT_H
@@ -30,7 +30,7 @@
 #include "model.h"
 
 // Light sources are points, use this to pretend they are not
-#define LIGHTOFFSET 32 * 32
+#define LIGHTOFFSET (32 * 32)
 
 // Note that you can't simply change this value (yet)
 #define MAX_DLIGHTS 32