From 147221cf6e67f8d0a4260a265127030efbd880b3 Mon Sep 17 00:00:00 2001
From: Monster Iestyn <iestynjealous@ntlworld.com>
Date: Mon, 25 Mar 2019 18:54:47 +0000
Subject: [PATCH 01/13] R_RenderThickSideRange: clamp lights that fail overflow
 test, rather than skipping them.

---
 src/r_segs.c | 37 ++++++++++++++++++++-----------------
 1 file changed, 20 insertions(+), 17 deletions(-)

diff --git a/src/r_segs.c b/src/r_segs.c
index 748365264..7495d7889 100644
--- a/src/r_segs.c
+++ b/src/r_segs.c
@@ -862,16 +862,18 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor)
 			leftheight -= viewz;
 			rightheight -= viewz;
 
-#define OVERFLOWTEST(height, scale) \
-	overflow_test = (INT64)centeryfrac - (((INT64)height*scale)>>FRACBITS); \
-	if (overflow_test < 0) overflow_test = -overflow_test; \
-	if ((UINT64)overflow_test&0xFFFFFFFF80000000ULL) continue;
+#define CLAMPMAX INT32_MAX
+#define CLAMPMIN (-INT32_MAX) // This is not INT32_MIN on purpose! INT32_MIN makes the drawers freak out.
+			// Monster Iestyn (25/03/18): do not skip these lights if they fail overflow test, just clamp them instead so they behave.
+			overflow_test = (INT64)centeryfrac - (((INT64)leftheight*ds->scale1)>>FRACBITS);
+			if      (overflow_test > (INT64)CLAMPMAX) rlight->height = CLAMPMAX;
+			else if (overflow_test > (INT64)CLAMPMIN) rlight->height = (fixed_t)overflow_test;
+			else                                      rlight->height = CLAMPMIN;
 
-			OVERFLOWTEST(leftheight, ds->scale1)
-			OVERFLOWTEST(rightheight, ds->scale2)
-
-			rlight->height = (centeryfrac) - FixedMul(leftheight, ds->scale1);
-			rlight->heightstep = (centeryfrac) - FixedMul(rightheight, ds->scale2);
+			overflow_test = (INT64)centeryfrac - (((INT64)rightheight*ds->scale2)>>FRACBITS);
+			if      (overflow_test > (INT64)CLAMPMAX) rlight->heightstep = CLAMPMAX;
+			else if (overflow_test > (INT64)CLAMPMIN) rlight->heightstep = (fixed_t)overflow_test;
+			else                                      rlight->heightstep = CLAMPMIN;
 			rlight->heightstep = (rlight->heightstep-rlight->height)/(range);
 #else
 			if (light->height < *pfloor->bottomheight)
@@ -893,12 +895,16 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor)
 				leftheight -= viewz;
 				rightheight -= viewz;
 
-				OVERFLOWTEST(leftheight, ds->scale1)
-				OVERFLOWTEST(rightheight, ds->scale2)
-#undef OVERFLOWTEST
+				// Monster Iestyn (25/03/18): do not skip these lights if they fail overflow test, just clamp them instead so they behave.
+				overflow_test = (INT64)centeryfrac - (((INT64)leftheight*ds->scale1)>>FRACBITS);
+				if      (overflow_test > (INT64)CLAMPMAX) rlight->botheight = CLAMPMAX;
+				else if (overflow_test > (INT64)CLAMPMIN) rlight->botheight = (fixed_t)overflow_test;
+				else                                      rlight->botheight = CLAMPMIN;
 
-				rlight->botheight = (centeryfrac) - FixedMul(leftheight, ds->scale1);
-				rlight->botheightstep = (centeryfrac) - FixedMul(rightheight, ds->scale2);
+				overflow_test = (INT64)centeryfrac - (((INT64)rightheight*ds->scale2)>>FRACBITS);
+				if      (overflow_test > (INT64)CLAMPMAX) rlight->botheightstep = CLAMPMAX;
+				else if (overflow_test > (INT64)CLAMPMIN) rlight->botheightstep = (fixed_t)overflow_test;
+				else                                      rlight->botheightstep = CLAMPMIN;
 				rlight->botheightstep = (rlight->botheightstep-rlight->botheight)/(range);
 #else
 				lheight = *light->caster->bottomheight;// > *pfloor->topheight ? *pfloor->topheight + FRACUNIT : *light->caster->bottomheight;
@@ -1071,9 +1077,6 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor)
 	}
 #endif
 
-#define CLAMPMAX INT32_MAX
-#define CLAMPMIN (-INT32_MAX) // This is not INT32_MIN on purpose! INT32_MIN makes the drawers freak out.
-
 	// draw the columns
 	for (dc_x = x1; dc_x <= x2; dc_x++)
 	{

From 9a8d36b822839252059701dd4824d3fbafe45e04 Mon Sep 17 00:00:00 2001
From: Alam Ed Arias <alam@srb2.org>
Date: Mon, 25 Mar 2019 15:16:43 -0400
Subject: [PATCH 02/13] Travis-CI: use a new version of xcode and use homebrew
 add-on to install packages

---
 .travis.yml | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 4bfc58860..07640f837 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -222,7 +222,16 @@ matrix:
 #          osx_image: xcode7.2
 #          #Apple LLVM version 7.0.2 (clang-700.1.81)
         - os: osx
-          osx_image: xcode7.3
+          #osx_image: xcode7.3
+          addons:
+            homebrew:
+              packages:
+              - sdl2
+              - sdl2_mixer
+              - game-music-emu
+              - p7zip
+              - cmake
+            update: false
           #Apple LLVM version 7.3.0 (clang-703.0.31)
     allow_failures:
       - compiler: clang-3.5
@@ -258,9 +267,6 @@ before_script:
   - cmake .. -DCMAKE_BUILD_TYPE=Release
 
 before_install:
-  - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update ; fi
-  - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install sdl2 sdl2_mixer game-music-emu p7zip; fi
-  - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install cmake||true; fi
   - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then curl -O -L https://www.libsdl.org/release/SDL2-2.0.6.dmg; hdiutil attach SDL2-2.0.6.dmg; sudo cp -a /Volumes/SDL2/SDL2.framework /Library/Frameworks/; fi
   - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then curl -O -L https://www.libsdl.org/projects/SDL_mixer/release/SDL2_mixer-2.0.1.dmg; hdiutil attach SDL2_mixer-2.0.1.dmg; sudo cp -a /Volumes/SDL2_mixer/SDL2_mixer.framework /Library/Frameworks/; fi
   - mkdir -p $HOME/srb2_cache

From c4e8a601127d205ff9b36e26cf8b2b61a911700c Mon Sep 17 00:00:00 2001
From: Alam Ed Arias <alam@srb2.org>
Date: Mon, 25 Mar 2019 15:21:52 -0400
Subject: [PATCH 03/13] CircleCI: also test compiling without BLUA support

---
 .circleci/config.yml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/.circleci/config.yml b/.circleci/config.yml
index c3674a9e5..e5892b7c7 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -43,8 +43,8 @@ jobs:
             - /var/cache/apt/archives
       - checkout
       - run:
-          name: Compile without network support
-          command: make -C src LINUX=1 ERRORMODE=1 -k NONET=1
+          name: Compile without network support and BLUA
+          command: make -C src LINUX=1 ERRORMODE=1 -k NONET=1 NO_LUA=1
       - run:
           name: Clean build
           command: make -C src LINUX=1 clean

From fe22fdc5a36fb2769ee83b880a873aa6375a6319 Mon Sep 17 00:00:00 2001
From: Alam Ed Arias <alam@srb2.org>
Date: Mon, 25 Mar 2019 15:30:25 -0400
Subject: [PATCH 04/13] P_SuperDamage() is too big for inlining

---
 src/p_inter.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/p_inter.c b/src/p_inter.c
index 009a2be1f..29450f6e1 100644
--- a/src/p_inter.c
+++ b/src/p_inter.c
@@ -2643,7 +2643,7 @@ static void P_KillPlayer(player_t *player, mobj_t *source, INT32 damage)
 	}
 }
 
-static inline void P_SuperDamage(player_t *player, mobj_t *inflictor, mobj_t *source, INT32 damage)
+static void P_SuperDamage(player_t *player, mobj_t *inflictor, mobj_t *source, INT32 damage)
 {
 	fixed_t fallbackspeed;
 	angle_t ang;

From a8681a5b7262d013daea99250139e28d0884b4c6 Mon Sep 17 00:00:00 2001
From: Alam Ed Arias <alam@srb2.org>
Date: Mon, 25 Mar 2019 15:34:25 -0400
Subject: [PATCH 05/13] CircleCI: rebuild depend file with BLUA

---
 .circleci/config.yml | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/.circleci/config.yml b/.circleci/config.yml
index e5892b7c7..1b0cf3407 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -46,7 +46,10 @@ jobs:
           name: Compile without network support and BLUA
           command: make -C src LINUX=1 ERRORMODE=1 -k NONET=1 NO_LUA=1
       - run:
-          name: Clean build
+          name: wipe build
+          command: make -C src LINUX=1 cleandep
+      - run:
+          name: rebuild depend
           command: make -C src LINUX=1 clean
       - restore_cache:
           keys:

From 3ab0f675ecbe0d9a79ed4a0cb39c2f7903dba457 Mon Sep 17 00:00:00 2001
From: Alam Ed Arias <alam@srb2.org>
Date: Mon, 25 Mar 2019 15:44:33 -0400
Subject: [PATCH 06/13] TravisCI: move homebrew packages for all mac builds

---
 .travis.yml | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 07640f837..78a0a30dc 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -223,15 +223,6 @@ matrix:
 #          #Apple LLVM version 7.0.2 (clang-700.1.81)
         - os: osx
           #osx_image: xcode7.3
-          addons:
-            homebrew:
-              packages:
-              - sdl2
-              - sdl2_mixer
-              - game-music-emu
-              - p7zip
-              - cmake
-            update: false
           #Apple LLVM version 7.3.0 (clang-703.0.31)
     allow_failures:
       - compiler: clang-3.5
@@ -256,6 +247,14 @@ addons:
     - libgl1-mesa-dev
     - libgme-dev
     - p7zip-full
+  homebrew:
+    packages:
+    - sdl2_mixer
+    - game-music-emu
+    - p7zip
+    - cmake
+    update: false
+
 
 before_script:
   - wget --verbose --server-response -c http://rosenthalcastle.org/srb2/SRB2-v2115-assets-2.7z -O $HOME/srb2_cache/SRB2-v2115-assets-2.7z

From 594c906376293942a73ef43ef70b13f421420512 Mon Sep 17 00:00:00 2001
From: Alam Ed Arias <alam@srb2.org>
Date: Mon, 25 Mar 2019 15:48:33 -0400
Subject: [PATCH 07/13] use default osx image

---
 .travis.yml | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 78a0a30dc..f0ed0a8ec 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -221,9 +221,11 @@ matrix:
 #        - os: osx
 #          osx_image: xcode7.2
 #          #Apple LLVM version 7.0.2 (clang-700.1.81)
+#        - os: osx
+#          osx_image: xcode7.3
+#          #Apple LLVM version 7.3.0 (clang-703.0.31)
         - os: osx
-          #osx_image: xcode7.3
-          #Apple LLVM version 7.3.0 (clang-703.0.31)
+          #Default: macOS 10.13 and Xcode 9.4.1
     allow_failures:
       - compiler: clang-3.5
       - compiler: clang-3.6

From 3472bf857cab6238fcd9d77013ea97517df48967 Mon Sep 17 00:00:00 2001
From: Alam Ed Arias <alam@srb2.org>
Date: Mon, 25 Mar 2019 15:51:13 -0400
Subject: [PATCH 08/13] TravisCI: build custom sdl2_mixer build

---
 .travis.yml | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/.travis.yml b/.travis.yml
index f0ed0a8ec..7ef0127b8 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -251,7 +251,7 @@ addons:
     - p7zip-full
   homebrew:
     packages:
-    - sdl2_mixer
+    - sdl2
     - game-music-emu
     - p7zip
     - cmake
@@ -268,6 +268,7 @@ before_script:
   - cmake .. -DCMAKE_BUILD_TYPE=Release
 
 before_install:
+  - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install sdl2_mixer; fi
   - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then curl -O -L https://www.libsdl.org/release/SDL2-2.0.6.dmg; hdiutil attach SDL2-2.0.6.dmg; sudo cp -a /Volumes/SDL2/SDL2.framework /Library/Frameworks/; fi
   - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then curl -O -L https://www.libsdl.org/projects/SDL_mixer/release/SDL2_mixer-2.0.1.dmg; hdiutil attach SDL2_mixer-2.0.1.dmg; sudo cp -a /Volumes/SDL2_mixer/SDL2_mixer.framework /Library/Frameworks/; fi
   - mkdir -p $HOME/srb2_cache

From ec0afaf6c9706760428df566af790de9a9ebefe3 Mon Sep 17 00:00:00 2001
From: Alam Ed Arias <alam@srb2.org>
Date: Mon, 25 Mar 2019 16:02:30 -0400
Subject: [PATCH 09/13] TravisCI: try updating homebew

---
 .travis.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.travis.yml b/.travis.yml
index 7ef0127b8..db81b9d91 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -255,7 +255,7 @@ addons:
     - game-music-emu
     - p7zip
     - cmake
-    update: false
+    update: true
 
 
 before_script:

From 9de5055d7fadebee347fd2af173c7e97e33b35ae Mon Sep 17 00:00:00 2001
From: Alam Ed Arias <alam@srb2.org>
Date: Mon, 25 Mar 2019 16:30:02 -0400
Subject: [PATCH 10/13] TravisCI: install deps on sdl2_mixer

---
 .travis.yml | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/.travis.yml b/.travis.yml
index db81b9d91..252abe0f1 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -251,6 +251,9 @@ addons:
     - p7zip-full
   homebrew:
     packages:
+    - libmodplug
+    - liboog
+    - libvorbis
     - sdl2
     - game-music-emu
     - p7zip

From fd284f232e09562505a110817481100fabf2aaf7 Mon Sep 17 00:00:00 2001
From: Alam Ed Arias <alam@srb2.org>
Date: Mon, 25 Mar 2019 16:43:33 -0400
Subject: [PATCH 11/13] travisCI: add sdl2_mixer from mazmazz's srb2 tap

---
 .travis.yml | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 252abe0f1..b723f44e3 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -250,11 +250,10 @@ addons:
     - libgme-dev
     - p7zip-full
   homebrew:
+    taps:
+    - mazmazz/srb2
     packages:
-    - libmodplug
-    - liboog
-    - libvorbis
-    - sdl2
+    - mazmazz/srb2/sdl2_mixer
     - game-music-emu
     - p7zip
     - cmake
@@ -271,7 +270,6 @@ before_script:
   - cmake .. -DCMAKE_BUILD_TYPE=Release
 
 before_install:
-  - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install sdl2_mixer; fi
   - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then curl -O -L https://www.libsdl.org/release/SDL2-2.0.6.dmg; hdiutil attach SDL2-2.0.6.dmg; sudo cp -a /Volumes/SDL2/SDL2.framework /Library/Frameworks/; fi
   - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then curl -O -L https://www.libsdl.org/projects/SDL_mixer/release/SDL2_mixer-2.0.1.dmg; hdiutil attach SDL2_mixer-2.0.1.dmg; sudo cp -a /Volumes/SDL2_mixer/SDL2_mixer.framework /Library/Frameworks/; fi
   - mkdir -p $HOME/srb2_cache

From 73fa35baf0255a9b9fefbc8256206f8c6964e077 Mon Sep 17 00:00:00 2001
From: Alam Ed Arias <alam@srb2.org>
Date: Mon, 25 Mar 2019 16:59:47 -0400
Subject: [PATCH 12/13] TravisCI: use stock sdl2_mixer for prebuild bottle

---
 .travis.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.travis.yml b/.travis.yml
index b723f44e3..15a3c844c 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -253,7 +253,7 @@ addons:
     taps:
     - mazmazz/srb2
     packages:
-    - mazmazz/srb2/sdl2_mixer
+    - sdl2_mixer
     - game-music-emu
     - p7zip
     - cmake

From 8c1c0875a2f8dd545920cf7dc7c9bd59af2d43ae Mon Sep 17 00:00:00 2001
From: Monster Iestyn <iestynjealous@ntlworld.com>
Date: Mon, 25 Mar 2019 21:35:04 +0000
Subject: [PATCH 13/13] Fix credits gamestate in dedicated mode, by properly
 separating the timer variable code from the drawing code in a semi-hacky way

---
 src/f_finale.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/src/f_finale.c b/src/f_finale.c
index 64e371211..bcdac295a 100644
--- a/src/f_finale.c
+++ b/src/f_finale.c
@@ -1192,16 +1192,34 @@ void F_CreditDrawer(void)
 		if (FixedMul(y,vid.dupy) > vid.height)
 			break;
 	}
+}
 
+void F_CreditTicker(void)
+{
+	// "Simulate" the drawing of the credits so that dedicated mode doesn't get stuck
+	UINT16 i;
+	fixed_t y = (80<<FRACBITS) - 5*(animtimer<<FRACBITS)/8;
+
+	// Draw credits text on top
+	for (i = 0; credits[i]; i++)
+	{
+		switch(credits[i][0])
+		{
+			case 0: y += 80<<FRACBITS; break;
+			case 1: y += 30<<FRACBITS; break;
+			default: y += 12<<FRACBITS; break;
+		}
+		if (FixedMul(y,vid.dupy) > vid.height)
+			break;
+	}
+
+	// Do this here rather than in the drawer you doofus! (this is why dedicated mode broke at credits)
 	if (!credits[i] && y <= 120<<FRACBITS && !finalecount)
 	{
 		timetonext = 5*TICRATE+1;
 		finalecount = 5*TICRATE;
 	}
-}
 
-void F_CreditTicker(void)
-{
 	if (timetonext)
 		timetonext--;
 	else