From daa112e2ac8c963befd07cfa7cb3284183271e55 Mon Sep 17 00:00:00 2001
From: "alexey.lysiuk" <alexey.lysiuk@gmail.com>
Date: Sat, 9 Apr 2016 10:51:19 +0300
Subject: [PATCH 1/8] Fixed OS X compilation after floating point merge

Header files from Carbon framework caused a few symbol conflicts
---
 src/CMakeLists.txt | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 9f1fb8a7d..17229da39 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -169,6 +169,12 @@ else()
 		set( FMOD_INC_PATH_SUFFIXES PATH_SUFFIXES inc )
 		set( FMOD_LIB_PATH_SUFFIXES PATH_SUFFIXES lib )
 		set( NO_GTK ON )
+
+		# Prevent inclusion of fp.h and FixMath.h from Carbon framework
+		# Declarations from these files are not used but cause the following conflicts:
+		#  - redefinition of 'FixedToFloat' and 'FloatToFixed' macros
+		#  - redefinition of 'pi' as different kind of symbol
+		add_definitions( -D__FP__ -D__FIXMATH__ )
 	else()
 		option( NO_GTK "Disable GTK+ dialogs (Not applicable to Windows)" )
 		option( VALGRIND "Add special Valgrind sequences to self-modifying code" )

From bcebeadedc639e51cd5657e1149f4400d0270a40 Mon Sep 17 00:00:00 2001
From: Christoph Oelckers <c.oelckers@zdoom.fake>
Date: Sat, 9 Apr 2016 21:44:09 +0200
Subject: [PATCH 2/8] - fixed: ACS's GetActorPitch needs to convert to a signed
 angle.

---
 src/p_acs.cpp | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/p_acs.cpp b/src/p_acs.cpp
index 186e9c3d4..bdc13357e 100644
--- a/src/p_acs.cpp
+++ b/src/p_acs.cpp
@@ -178,6 +178,11 @@ inline int AngleToACS(DAngle ang)
 	return ang.BAMs() >> 16;
 }
 
+inline int PitchToACS(DAngle ang)
+{
+	return int(ang.Normalized180().Degrees * (65536. / 360));
+}
+
 struct CallReturn
 {
 	CallReturn(int pc, ScriptFunction *func, FBehavior *module, SDWORD *locals, ACSLocalArrays *arrays, bool discard, unsigned int runaway)
@@ -8751,7 +8756,7 @@ scriptwait:
 		case PCD_GETACTORPITCH:
 			{
 				AActor *actor = SingleActorFromTID(STACK(1), activator);
-				STACK(1) = actor == NULL ? 0 : AngleToACS(actor->Angles.Pitch);
+				STACK(1) = actor == NULL ? 0 : PitchToACS(actor->Angles.Pitch);
 			}
 			break;
 

From 1f1a0ca84767cb4fa116e79cf41ddbf6acb3bbbb Mon Sep 17 00:00:00 2001
From: Christoph Oelckers <c.oelckers@zdoom.fake>
Date: Sat, 9 Apr 2016 21:57:35 +0200
Subject: [PATCH 3/8] - fixed incorrect check for negative damage in
 APowerProtection::ModifyDamage.

---
 src/g_shared/a_artifacts.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/g_shared/a_artifacts.cpp b/src/g_shared/a_artifacts.cpp
index 1efb4e8ee..050a6215f 100644
--- a/src/g_shared/a_artifacts.cpp
+++ b/src/g_shared/a_artifacts.cpp
@@ -1704,7 +1704,7 @@ void APowerProtection::ModifyDamage(int damage, FName damageType, int &newdamage
 		DmgFactors *df = GetClass()->DamageFactors;
 		if (df != NULL && df->CountUsed() != 0)
 		{
-			newdam = MIN(0, df->Apply(damageType, damage));
+			newdam = MAX(0, df->Apply(damageType, damage));
 		}
 		else
 		{

From dc72e7f3c2dfda9d476793ba657b1c791380619b Mon Sep 17 00:00:00 2001
From: Christoph Oelckers <c.oelckers@zdoom.fake>
Date: Sat, 9 Apr 2016 22:07:14 +0200
Subject: [PATCH 4/8] - removed the check for VA_COPY from CMakeLists.txt.

This is because nothing uses va_copy anymore and it's a mandatory part of C++11, therefore always available.
---
 src/CMakeLists.txt | 16 ----------------
 1 file changed, 16 deletions(-)

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 17229da39..690020249 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -555,22 +555,6 @@ if( UNIX )
 	endif()
 endif()
 
-CHECK_CXX_SOURCE_COMPILES(
-	"#include <stdarg.h>
-	int main() { va_list list1, list2; va_copy(list1, list2); return 0; }"
-	HAS_VA_COPY )
-if( NOT HAS_VA_COPY )
-	CHECK_CXX_SOURCE_COMPILES(
-		"#include <stdarg.h>
-		int main() { va_list list1, list2; __va_copy(list1, list2); return 0; }"
-		HAS___VA_COPY )
-	if( HAS___VA_COPY )
-		add_definitions( -Dva_copy=__va_copy )
-	else()
-		add_definitions( -DNO_VA_COPY )
-	endif()
-endif()
-
 # Flags
 
 if( BACKPATCH )

From 8b8c879994cc33c1e251cdcfa30727163990ef14 Mon Sep 17 00:00:00 2001
From: MajorCooke <paul.growney22@gmail.com>
Date: Sat, 9 Apr 2016 14:44:17 -0500
Subject: [PATCH 5/8] - CBF_DROPOFF Fixes - Fixed: CBF_DROPOFF didn't actually
 check the coordinates passed to it for dropoff height values. It only checked
 to see if it was stuck in lines.

---
 src/p_local.h                     |  2 +-
 src/p_map.cpp                     | 13 ++++++++++++-
 src/thingdef/thingdef_codeptr.cpp |  6 ++++--
 3 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/src/p_local.h b/src/p_local.h
index 0dd0dca68..82f4580b9 100644
--- a/src/p_local.h
+++ b/src/p_local.h
@@ -221,7 +221,7 @@ void	P_FakeZMovement (AActor *mo);
 bool	P_TryMove(AActor* thing, const DVector2 &pos, int dropoff, const secplane_t * onfloor, FCheckPosition &tm, bool missileCheck = false);
 bool	P_TryMove(AActor* thing, const DVector2 &pos, int dropoff, const secplane_t * onfloor = NULL);
 
-bool	P_CheckMove(AActor *thing, const DVector2 &pos);
+bool	P_CheckMove(AActor *thing, const DVector2 &pos, bool dropoff = false);
 void	P_ApplyTorque(AActor *mo);
 
 bool	P_TeleportMove(AActor* thing, const DVector3 &pos, bool telefrag, bool modifyactor = true);	// [RH] Added z and telefrag parameters
diff --git a/src/p_map.cpp b/src/p_map.cpp
index 61e651ce6..15cd5eb5b 100644
--- a/src/p_map.cpp
+++ b/src/p_map.cpp
@@ -2410,7 +2410,7 @@ bool P_TryMove(AActor *thing, const DVector2 &pos,
 //
 //==========================================================================
 
-bool P_CheckMove(AActor *thing, const DVector2 &pos)
+bool P_CheckMove(AActor *thing, const DVector2 &pos, bool dropoff)
 {
 	FCheckPosition tm;
 	double		newz = thing->Z();
@@ -2469,6 +2469,17 @@ bool P_CheckMove(AActor *thing, const DVector2 &pos)
 					return false;
 				}
 			}
+			else if (dropoff)
+			{
+				const DVector3 oldpos = thing->Pos();
+				thing->SetOrigin(pos.X, pos.Y, newz, true);
+				bool hcheck = (newz - thing->MaxDropOffHeight > thing->floorz);
+				thing->SetOrigin(oldpos, true);
+				if (hcheck && !(thing->flags & MF_FLOAT) && !(i_compatflags & COMPATF_DROPOFF))
+				{
+					return false;
+				}
+			}
 		}
 
 		if (thing->flags2 & MF2_CANTLEAVEFLOORPIC
diff --git a/src/thingdef/thingdef_codeptr.cpp b/src/thingdef/thingdef_codeptr.cpp
index d0a157932..cc4ffd33b 100644
--- a/src/thingdef/thingdef_codeptr.cpp
+++ b/src/thingdef/thingdef_codeptr.cpp
@@ -6707,7 +6707,7 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_CheckBlock)
 	if (flags & CBF_DROPOFF)
 	{
 		mobj->SetZ(pos.Z);
-		checker = P_CheckMove(mobj, pos);
+		checker = P_CheckMove(mobj, pos, true);
 		mobj->SetZ(oldpos.Z);
 	}
 	else
@@ -6742,8 +6742,10 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_CheckBlock)
 	}
 	//[MC] I don't know why I let myself be persuaded not to include a flag.
 	//If an actor is loaded with pointers, they don't really have any options to spare.
+	//Also, fail if a dropoff or a step is too great to pass over when checking for dropoffs.
 
-	if ((!(flags & CBF_NOACTORS) && (mobj->BlockingMobj)) || (!(flags & CBF_NOLINES) && mobj->BlockingLine != NULL))
+	if ((!(flags & CBF_NOACTORS) && (mobj->BlockingMobj)) || (!(flags & CBF_NOLINES) && mobj->BlockingLine != NULL) ||
+		((flags & CBF_DROPOFF) && !checker))
 	{
 		ACTION_RETURN_STATE(block);
 	}

From c79a1b6a45126d5326299a7003d53993222f4ed0 Mon Sep 17 00:00:00 2001
From: MajorCooke <paul.growney22@gmail.com>
Date: Sat, 9 Apr 2016 15:04:44 -0500
Subject: [PATCH 6/8] thing->floorz --> thing->dropoffz

---
 src/p_map.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/p_map.cpp b/src/p_map.cpp
index 15cd5eb5b..73aa3f73f 100644
--- a/src/p_map.cpp
+++ b/src/p_map.cpp
@@ -2473,7 +2473,7 @@ bool P_CheckMove(AActor *thing, const DVector2 &pos, bool dropoff)
 			{
 				const DVector3 oldpos = thing->Pos();
 				thing->SetOrigin(pos.X, pos.Y, newz, true);
-				bool hcheck = (newz - thing->MaxDropOffHeight > thing->floorz);
+				bool hcheck = (newz - thing->MaxDropOffHeight > thing->dropoffz);
 				thing->SetOrigin(oldpos, true);
 				if (hcheck && !(thing->flags & MF_FLOAT) && !(i_compatflags & COMPATF_DROPOFF))
 				{

From 9a48adf81a48a9b450424ac13baf90ef8cf44ccc Mon Sep 17 00:00:00 2001
From: Christoph Oelckers <c.oelckers@zdoom.fake>
Date: Sat, 9 Apr 2016 22:56:12 +0200
Subject: [PATCH 7/8] - fixed: The software 2D drawer expected its translation
 pointer to be initialized by ParseDrawTextureTags. Removed the variable from
 DrawParms and made it and its initialization local to the software rendering
 code.

---
 src/v_draw.cpp | 18 +++++++++---------
 src/v_text.cpp |  3 ---
 src/v_video.h  |  1 -
 3 files changed, 9 insertions(+), 13 deletions(-)

diff --git a/src/v_draw.cpp b/src/v_draw.cpp
index 3897cd9b4..6cfb8aa41 100644
--- a/src/v_draw.cpp
+++ b/src/v_draw.cpp
@@ -127,6 +127,7 @@ void DCanvas::DrawTextureParms(FTexture *img, DrawParms &parms)
 	FTexture::Span unmaskedSpan[2];
 	const FTexture::Span **spanptr, *spans;
 	static short bottomclipper[MAXWIDTH], topclipper[MAXWIDTH];
+	const BYTE *translation = NULL;
 
 	if (parms.masked)
 	{
@@ -155,12 +156,16 @@ void DCanvas::DrawTextureParms(FTexture *img, DrawParms &parms)
 		// Note that this overrides DTA_Translation in software, but not in hardware.
 		FDynamicColormap *colormap = GetSpecialLights(MAKERGB(255,255,255),
 			parms.colorOverlay & MAKEARGB(0,255,255,255), 0);
-		parms.translation = &colormap->Maps[(APART(parms.colorOverlay)*NUMCOLORMAPS/255)*256];
+		translation = &colormap->Maps[(APART(parms.colorOverlay)*NUMCOLORMAPS/255)*256];
+	}
+	else if (parms.remap != NULL)
+	{
+		translation = parms.remap->Remap;
 	}
 
-	if (parms.translation != NULL)
+	if (translation != NULL)
 	{
-		dc_colormap = (lighttable_t *)parms.translation;
+		dc_colormap = (lighttable_t *)translation;
 	}
 	else
 	{
@@ -421,6 +426,7 @@ bool DCanvas::SetTextureParms(DrawParms *parms, FTexture *img, double xx, double
 				parms->virtWidth, parms->virtHeight, parms->virtBottom, !parms->keepratio);
 		}
 	}
+
 	return false;
 }
 
@@ -461,7 +467,6 @@ bool DCanvas::ParseDrawTextureTags (FTexture *img, double x, double y, DWORD tag
 	parms->Alpha = 1.f;
 	parms->fillcolor = -1;
 	parms->remap = NULL;
-	parms->translation = NULL;
 	parms->colorOverlay = 0;
 	parms->alphaChannel = false;
 	parms->flipX = false;
@@ -826,11 +831,6 @@ bool DCanvas::ParseDrawTextureTags (FTexture *img, double x, double y, DWORD tag
 		}
 	}
 
-	if (parms->remap != NULL)
-	{
-		parms->translation = parms->remap->Remap;
-	}
-
 	if (parms->style.BlendOp == 255)
 	{
 		if (fillcolorset)
diff --git a/src/v_text.cpp b/src/v_text.cpp
index 7c97b0e6a..b2ecb8d2c 100644
--- a/src/v_text.cpp
+++ b/src/v_text.cpp
@@ -86,9 +86,6 @@ void STACK_ARGS DCanvas::DrawChar (FFont *font, int normalcolor, int x, int y, B
 //
 void STACK_ARGS DCanvas::DrawText(FFont *font, int normalcolor, int x, int y, const char *string, int tag_first, ...)
 {
-	INTBOOL boolval;
-	uint32 tag;
-
 	int 		w;
 	const BYTE *ch;
 	int 		c;
diff --git a/src/v_video.h b/src/v_video.h
index ef6efc218..3af56513c 100644
--- a/src/v_video.h
+++ b/src/v_video.h
@@ -158,7 +158,6 @@ struct DrawParms
 	float Alpha;
 	uint32 fillcolor;
 	FRemapTable *remap;
-	const BYTE *translation;
 	uint32 colorOverlay;
 	INTBOOL alphaChannel;
 	INTBOOL flipX;

From 84c8f38038c625026b46608b62be76ef40a60ad8 Mon Sep 17 00:00:00 2001
From: Christoph Oelckers <coelckers@zdoom.fake>
Date: Sun, 10 Apr 2016 00:45:48 +0200
Subject: [PATCH 8/8] - fixed: The divisions in FTexCoordInfo::TextureOffset
 and RowOffset were turned into multiplications when converting to floating
 point.

---
 src/gl/textures/gl_material.cpp | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/gl/textures/gl_material.cpp b/src/gl/textures/gl_material.cpp
index 40e2931a6..60a53fda3 100644
--- a/src/gl/textures/gl_material.cpp
+++ b/src/gl/textures/gl_material.cpp
@@ -332,12 +332,12 @@ float FTexCoordInfo::RowOffset(float rowoffset) const
 	if (mTempScale.Y == 1.f)
 	{
 		if (mScale.Y == 1.f || mWorldPanning) return rowoffset;
-		else return rowoffset * mScale.Y;
+		else return rowoffset / mScale.Y;
 	}
 	else
 	{
-		if (mWorldPanning) return rowoffset * mTempScale.Y;
-		else return rowoffset * mScale.Y;
+		if (mWorldPanning) return rowoffset / mTempScale.Y;
+		else return rowoffset / mScale.Y;
 	}
 }
 
@@ -352,12 +352,12 @@ float FTexCoordInfo::TextureOffset(float textureoffset) const
 	if (mTempScale.X == 1.f)
 	{
 		if (mScale.X == 1.f || mWorldPanning) return textureoffset;
-		else return textureoffset * mScale.X;
+		else return textureoffset / mScale.X;
 	}
 	else
 	{
-		if (mWorldPanning) return textureoffset * mTempScale.X;
-		else return textureoffset * mScale.X;
+		if (mWorldPanning) return textureoffset / mTempScale.X;
+		else return textureoffset / mScale.X;
 	}
 }