From 83ec5e427f9a3f61774ea767f18741c9420db4f3 Mon Sep 17 00:00:00 2001
From: Spoike <acceptthis@users.sourceforge.net>
Date: Tue, 13 Jul 2010 09:49:38 +0000
Subject: [PATCH] Things should compile again now. Reverted clipping change,
 its not stable enough. Optimised player prediction/tracing. Framerates are a
 little more competitive now.

git-svn-id: https://svn.code.sf.net/p/fteqw/code/branches/wip@3549 fc73d0e0-1445-4013-8a0c-d673dee63da5
---
 engine/client/cl_ents.c      | 14 --------
 engine/client/client.h       |  1 +
 engine/client/console.c      |  1 +
 engine/client/image.c        |  2 +-
 engine/client/menu.c         |  1 -
 engine/client/menu.h         |  3 ++
 engine/client/p_null.c       |  3 +-
 engine/client/pr_menu.c      |  1 +
 engine/client/r_part.c       |  5 +++
 engine/client/render.h       |  2 ++
 engine/common/pmovetst.c     | 62 +++++++++++++++++++-----------------
 engine/common/q1bsp.c        |  2 +-
 engine/ftequake/ftequake.dsp | 60 ----------------------------------
 engine/gl/gl_shadow.c        | 15 +++++----
 14 files changed, 58 insertions(+), 114 deletions(-)

diff --git a/engine/client/cl_ents.c b/engine/client/cl_ents.c
index 32027fb13..92e5ca253 100644
--- a/engine/client/cl_ents.c
+++ b/engine/client/cl_ents.c
@@ -3145,20 +3145,6 @@ void CL_SetUpPlayerPrediction(qboolean dopred)
 		pplayer->active = true;
 		pplayer->flags = state->flags;
 
-		/*
-		if (pplayer->frame != state->frame)
-		{
-			state->oldframe = pplayer->oldframe = pplayer->frame;
-			state->lerpstarttime = pplayer->lerptime = realtime;
-			pplayer->frame = state->frame;
-		}
-		else
-		{
-			state->lerpstarttime = pplayer->lerptime;
-			state->oldframe = pplayer->oldframe;
-		}
-		*/
-
 		// note that the local player is special, since he moves locally
 		// we use his last predicted postition
 		for (s = 0; s < cl.splitclients; s++)
diff --git a/engine/client/client.h b/engine/client/client.h
index c7a271af4..447dc99dc 100644
--- a/engine/client/client.h
+++ b/engine/client/client.h
@@ -726,6 +726,7 @@ extern float	server_version;	// version of server we connected to
 // cl_main
 //
 void CL_InitDlights(void);
+void CL_FreeDlights(void);
 dlight_t *CL_AllocDlight (int key);
 dlight_t *CL_AllocSlight (void);	//allocates a static light
 dlight_t *CL_NewDlight (int key, const vec3_t origin, float radius, float time, int type);
diff --git a/engine/client/console.c b/engine/client/console.c
index b24554373..8bbdf5e88 100644
--- a/engine/client/console.c
+++ b/engine/client/console.c
@@ -679,6 +679,7 @@ void VARGS Con_Printf (const char *fmt, ...)
 #endif
 
 // also echo to debugging console
+//	OutputDebugString(msg);	//msvc debug output
 	Sys_Printf ("%s", msg);	// also echo to debugging console
 
 // log all messages to file
diff --git a/engine/client/image.c b/engine/client/image.c
index 8fdfc2a7d..f4f62f70e 100644
--- a/engine/client/image.c
+++ b/engine/client/image.c
@@ -2105,7 +2105,7 @@ texid_t R_LoadHiResTexture(char *name, char *subpath, unsigned int flags)
 	data = W_GetTexture(name, &image_width, &image_height, &alphaed);
 	if (data)
 	{
-		tex = R_LoadTexture32 (name, image_width, image_height, (unsigned*)data, flags)
+		tex = R_LoadTexture32 (name, image_width, image_height, (unsigned*)data, flags);
 		BZ_Free(data);
 		return tex;
 	}
diff --git a/engine/client/menu.c b/engine/client/menu.c
index 9002866b3..dc4c913d0 100644
--- a/engine/client/menu.c
+++ b/engine/client/menu.c
@@ -869,7 +869,6 @@ void M_Reinit(void)
 		M_Init_Internal();
 	}
 }
-#warning ----------- move menu reload here --------------
 
 void FPS_Preset_f(void);
 
diff --git a/engine/client/menu.h b/engine/client/menu.h
index 4a8db95cb..862b2d64a 100644
--- a/engine/client/menu.h
+++ b/engine/client/menu.h
@@ -102,6 +102,8 @@ void M_SomeInitialisationFunctionCalledAtStartup(void)
 // menus
 //
 void M_Init (void);
+void M_Reinit(void);
+void M_Shutdown(void);
 void M_Keydown (int key, int unicode);
 void M_Keyup (int key, int unicode);
 void M_Draw (int uimenu);
@@ -390,6 +392,7 @@ void M_FindKeysForCommand (char *command, int *twokeys);
 void M_UnbindCommand (char *command);
 
 qboolean MP_Init (void);
+void MP_Shutdown (void);
 qboolean MP_Toggle(void);
 void MP_Draw(void);
 void MP_RegisterCvarsAndCmds(void);
diff --git a/engine/client/p_null.c b/engine/client/p_null.c
index 8479ee40e..30892db57 100644
--- a/engine/client/p_null.c
+++ b/engine/client/p_null.c
@@ -31,9 +31,10 @@ static void PNULL_RunParticleEffect4 (vec3_t org, float radius, int color, int e
 static void PNULL_ParticleTrailIndex (vec3_t start, vec3_t end, int color, int crnd, trailstate_t **tsk){}
 static void PNULL_EmitSkyEffectTris(model_t *mod, msurface_t 	*fa){}
 
-static void PNULL_InitParticles (void)
+static int PNULL_InitParticles (void)
 {
 	CL_RegisterParticles();
+	return true;
 }
 
 static void PNULL_ShutdownParticles(void)
diff --git a/engine/client/pr_menu.c b/engine/client/pr_menu.c
index fc7670742..3a5fddf65 100644
--- a/engine/client/pr_menu.c
+++ b/engine/client/pr_menu.c
@@ -1897,6 +1897,7 @@ qboolean MP_Init (void)
 		Con_DPrintf("Initialized menu.dat\n");
 		return true;
 	}
+	return false;
 }
 
 void MP_CoreDump_f(void)
diff --git a/engine/client/r_part.c b/engine/client/r_part.c
index ef17568e6..a629b60ef 100644
--- a/engine/client/r_part.c
+++ b/engine/client/r_part.c
@@ -79,10 +79,15 @@ void R_ParticleSystem_Callback(struct cvar_s *var, char *oldvalue)
 {
 	int i;
 	if (pe)
+	{
+		OutputDebugString("foo\n");
 		pe->ShutdownParticles();
+	}
 
 	if (!qrenderer)
+	{
 		pe = &pe_null;
+	}
 	else
 	{
 		pe = NULL;
diff --git a/engine/client/render.h b/engine/client/render.h
index ad2e719b5..cf0a18110 100644
--- a/engine/client/render.h
+++ b/engine/client/render.h
@@ -173,6 +173,7 @@ void Surf_AddStain(vec3_t org, float red, float green, float blue, float radius)
 void Surf_LessenStains(void);
 void Surf_WipeStains(void);
 void Surf_DeInit(void);
+void Surf_Clear(struct model_s *mod);
 void Surf_BuildLightmaps(void);
 void Surf_BuildSurfaceDisplayList (struct model_s *mod, struct msurface_s *fa);
 void Surf_RenderDynamicLightmaps (struct msurface_s *fa, int shift);
@@ -309,6 +310,7 @@ enum uploadfmt
 texid_t GL_AllocNewTexture(void);
 void GL_UploadFmt(texid_t tex, char *name, enum uploadfmt fmt, void *data, void *palette, int width, int height, unsigned int flags);
 texid_t GL_LoadTextureFmt (char *identifier, int width, int height, enum uploadfmt fmt, void *data, unsigned int flags);
+void GL_DestroyTexture(texid_t tex);
 #endif
 #ifdef D3DQUAKE
 texid_t D3D_AllocNewTexture(int width, int height);
diff --git a/engine/common/pmovetst.c b/engine/common/pmovetst.c
index 756dc7d00..21cc09ffe 100644
--- a/engine/common/pmovetst.c
+++ b/engine/common/pmovetst.c
@@ -19,7 +19,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
 #include "quakedef.h"
 
-qboolean PM_TransformedHullCheck (model_t *model, vec3_t start, vec3_t end, trace_t *trace, vec3_t origin, vec3_t angles);
+static qboolean PM_TransformedHullCheck (model_t *model, vec3_t start, vec3_t end, trace_t *trace, vec3_t origin, vec3_t angles);
 int Q1BSP_HullPointContents(hull_t *hull, vec3_t p);
 static	hull_t		box_hull;
 static	dclipnode_t	box_clipnodes[6];
@@ -174,7 +174,8 @@ int PM_ExtraBoxContents (vec3_t p)
 		{
 			if (pe->forcecontentsmask)
 			{
-				PM_TransformedHullCheck(pm, p, p, &tr, pe->origin, pe->angles);
+				if (!PM_TransformedHullCheck(pm, p, p, &tr, pe->origin, pe->angles))
+					continue;
 				if (tr.startsolid)
 					pc |= pe->forcecontentsmask;
 			}
@@ -199,20 +200,17 @@ LINE TESTING IN HULLS
 ===============================================================================
 */
 
-// 1/32 epsilon to keep floating point happy
-#define	DIST_EPSILON	(0.03125)
+static vec3_t trace_extents;
 
-vec3_t trace_extents;
-
-
-qboolean PM_TransformedHullCheck (model_t *model, vec3_t start, vec3_t end, trace_t *trace, vec3_t origin, vec3_t angles)
+/*returns if it actually did a trace*/
+static qboolean PM_TransformedHullCheck (model_t *model, vec3_t start, vec3_t end, trace_t *trace, vec3_t origin, vec3_t angles)
 {
 	vec3_t		start_l, end_l;
 	vec3_t		a;
 	vec3_t		forward, right, up;
 	vec3_t		temp;
 	qboolean	rotated;
-	qboolean	result;
+	int i;
 
 	// subtract origin offset
 	VectorSubtract (start, origin, start_l);
@@ -241,11 +239,29 @@ qboolean PM_TransformedHullCheck (model_t *model, vec3_t start, vec3_t end, trac
 	}
 	// sweep the box through the model
 
-	if (model && model->funcs.Trace)
-		result = model->funcs.Trace(model, 0, 0, start_l, end_l, player_mins, player_maxs, trace);
+	if (model)
+	{
+		for (i = 0; i < 3; i++)
+		{
+			if (start_l[i]+player_mins[i] > model->maxs[i] && end_l[i] + player_mins[i] > model->maxs[i])
+				return false;
+			if (start_l[i]+player_maxs[i] < model->mins[i] && end_l[i] + player_maxs[i] < model->mins[i])
+				return false;
+		}
+
+		model->funcs.Trace(model, 0, 0, start_l, end_l, player_mins, player_maxs, trace);
+	}
 	else
 	{
-		result = Q1BSP_RecursiveHullCheck (&box_hull, box_hull.firstclipnode, 0, 1, start_l, end_l, trace);
+		for (i = 0; i < 3; i++)
+		{
+			if (start_l[i]+player_mins[i] > box_planes[0+i*2].dist && end_l[i] + player_mins[i] > box_planes[0+i*2].dist)
+				return false;
+			if (start_l[i]+player_maxs[i] < box_planes[1+i*2].dist && end_l[i] + player_maxs[i] < box_planes[1+i*2].dist)
+				return false;
+		}
+
+		Q1BSP_RecursiveHullCheck (&box_hull, box_hull.firstclipnode, 0, 1, start_l, end_l, trace);
 	}
 
 	if (rotated)
@@ -275,8 +291,7 @@ qboolean PM_TransformedHullCheck (model_t *model, vec3_t start, vec3_t end, trac
 		trace->endpos[1] += origin[1];
 		trace->endpos[2] += origin[2];
 	}
-
-	return result;
+	return true;
 }
 
 /*
@@ -304,18 +319,8 @@ qboolean PM_TestPlayerPosition (vec3_t pos)
 	// get the clipping hull
 		if (pe->model)
 		{
-/*
-#ifdef Q2BSPS
-			if (pe->model->fromgame == fg_quake2 || pe->model->fromgame == fg_quake3)
-			{
-				trace_t trace = CM_TransformedBoxTrace(pe->model, pos, pos, player_mins, player_maxs, MASK_PLAYERSOLID, pe->origin, pe->angles);
-				if (trace.fraction == 0)
-					return false;
+			if (!PM_TransformedHullCheck (pe->model, pos, pos, &trace, pe->origin, pe->angles))
 				continue;
-			}
-#endif*/
-
-			PM_TransformedHullCheck (pe->model, pos, pos, &trace, pe->origin, pe->angles);
 			if (trace.allsolid)
 				return false;	//solid
 		}
@@ -328,9 +333,6 @@ qboolean PM_TestPlayerPosition (vec3_t pos)
 
 			if (Q1BSP_HullPointContents(hull, mins) & FTECONTENTS_SOLID)
 				return false;
-
-//			if (Q1BSP_Trace(&box_hull, 0, 0, pe->origin, pe->origin, pe->mins, pe->maxs, pos, pe->origin, pe->angles) & FTECONTENTS_SOLID)
-//				return false;
 		}
 	}
 
@@ -364,13 +366,15 @@ trace_t PM_PlayerTrace (vec3_t start, vec3_t end)
 		if (!pe->model)
 		{
 			vec3_t mins, maxs;
+
 			VectorSubtract (pe->mins, player_maxs, mins);
 			VectorSubtract (pe->maxs, player_mins, maxs);
 			PM_HullForBox (mins, maxs);
 		}
 
 	// trace a line through the apropriate clipping hull
-		PM_TransformedHullCheck (pe->model, start, end, &trace, pe->origin, pe->angles);
+		if (!PM_TransformedHullCheck (pe->model, start, end, &trace, pe->origin, pe->angles))
+			continue;
 
 		if (trace.allsolid)
 			trace.startsolid = true;
diff --git a/engine/common/q1bsp.c b/engine/common/q1bsp.c
index 276ce33a1..0d3df0341 100644
--- a/engine/common/q1bsp.c
+++ b/engine/common/q1bsp.c
@@ -61,7 +61,7 @@ int VARGS Q1_HullPointContents (hull_t *hull, int num, vec3_t p);
 
 
 #define	DIST_EPSILON	(0.03125)
-#if 1
+#if 0
 enum
 {
 	rht_solid,
diff --git a/engine/ftequake/ftequake.dsp b/engine/ftequake/ftequake.dsp
index 7087cc177..5542617e3 100644
--- a/engine/ftequake/ftequake.dsp
+++ b/engine/ftequake/ftequake.dsp
@@ -2084,8 +2084,6 @@ SOURCE=..\client\p_null.c
 
 !ELSEIF  "$(CFG)" == "ftequake - Win32 GLRelease"
 
-# PROP Exclude_From_Build 1
-
 !ELSEIF  "$(CFG)" == "ftequake - Win32 MDebug"
 
 !ELSEIF  "$(CFG)" == "ftequake - Win32 MRelease"
@@ -4404,65 +4402,7 @@ SOURCE=..\common\translate.c
 # Begin Source File
 
 SOURCE=..\server\world.c
-
-!IF  "$(CFG)" == "ftequake - Win32 Release"
-
-# ADD CPP /Yu"quekdef.h"
-
-!ELSEIF  "$(CFG)" == "ftequake - Win32 Debug"
-
-# ADD CPP /Yu"quekdef.h"
-
-!ELSEIF  "$(CFG)" == "ftequake - Win32 GLDebug"
-
 # ADD CPP /Yu"quakedef.h"
-
-!ELSEIF  "$(CFG)" == "ftequake - Win32 GLRelease"
-
-# ADD CPP /Yu"quekdef.h"
-
-!ELSEIF  "$(CFG)" == "ftequake - Win32 MDebug"
-
-# ADD CPP /Yu"quekdef.h"
-
-!ELSEIF  "$(CFG)" == "ftequake - Win32 MRelease"
-
-# ADD CPP /Yu"quekdef.h"
-
-!ELSEIF  "$(CFG)" == "ftequake - Win32 MinGLDebug"
-
-# ADD CPP /Yu"quekdef.h"
-
-!ELSEIF  "$(CFG)" == "ftequake - Win32 MinGLRelease"
-
-# ADD CPP /Yu"quekdef.h"
-
-!ELSEIF  "$(CFG)" == "ftequake - Win32 Debug Dedicated Server"
-
-# ADD CPP /Yu"quekdef.h"
-
-!ELSEIF  "$(CFG)" == "ftequake - Win32 Release Dedicated Server"
-
-# ADD CPP /Yu"quekdef.h"
-
-!ELSEIF  "$(CFG)" == "ftequake - Win32 MinSW"
-
-# ADD CPP /Yu"quekdef.h"
-
-!ELSEIF  "$(CFG)" == "ftequake - Win32 GLDebugQ3"
-
-# ADD CPP /Yu"quekdef.h"
-
-!ELSEIF  "$(CFG)" == "ftequake - Win32 Debug Dedicated ServerQ3"
-
-# ADD CPP /Yu"quekdef.h"
-
-!ELSEIF  "$(CFG)" == "ftequake - Win32 D3DDebug"
-
-# ADD CPP /Yu"quekdef.h"
-
-!ENDIF 
-
 # End Source File
 # Begin Source File
 
diff --git a/engine/gl/gl_shadow.c b/engine/gl/gl_shadow.c
index 50c02eae1..cf2e87e82 100644
--- a/engine/gl/gl_shadow.c
+++ b/engine/gl/gl_shadow.c
@@ -1553,14 +1553,15 @@ static void Sh_DrawShadowMapLight(dlight_t *l, vec3_t colour, qbyte *vvis)
 		return;
 	}
 
-        if (l->worldshadowmesh)
+    if (l->worldshadowmesh)
+    {
+		lvis = l->worldshadowmesh->litleaves;
+        //fixme: check head node first?
+        if (!Sh_LeafInView(l->worldshadowmesh->litleaves, vvis))
         {
-                //fixme: check head node first?
-                if (!Sh_LeafInView(l->worldshadowmesh->litleaves, vvis))
-                {
-                        bench.numpvsculled++;
-                        return;
-                }
+                bench.numpvsculled++;
+                return;
+        }
 	}
 	else
 	{