From 3bafbaac49e3d5d1d633b26f60fd4e919399819b Mon Sep 17 00:00:00 2001
From: sfan5 <sfan5@live.de>
Date: Sat, 18 Feb 2023 00:29:34 +0100
Subject: [PATCH] Remove dead code behind Irrlicht version checks

---
 src/client/game.cpp                  | 27 ---------
 src/client/mapblock_mesh.cpp         |  8 ---
 src/client/sky.cpp                   |  5 --
 src/gui/guiButton.cpp                |  2 -
 src/gui/guiButton.h                  | 88 ++++------------------------
 src/gui/guiChatConsole.cpp           |  2 -
 src/gui/guiEditBox.cpp               |  3 -
 src/irrlicht_changes/CGUITTFont.h    |  5 +-
 src/irrlicht_changes/static_text.cpp |  2 -
 src/irrlicht_changes/static_text.h   |  2 -
 src/irrlichttypes.h                  |  3 +-
 11 files changed, 14 insertions(+), 133 deletions(-)

diff --git a/src/client/game.cpp b/src/client/game.cpp
index 122e25d8c..94a09537a 100644
--- a/src/client/game.cpp
+++ b/src/client/game.cpp
@@ -1008,10 +1008,6 @@ private:
 	// this happens in pause menu in singleplayer
 	bool m_is_paused = false;
 
-#if IRRLICHT_VERSION_MT_REVISION < 5
-	int m_reset_HW_buffer_counter = 0;
-#endif
-
 #ifdef HAVE_TOUCHSCREENGUI
 	bool m_cache_hold_aux1;
 	bool m_touch_use_crosshair;
@@ -4153,29 +4149,6 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
 	/*
 		==================== End scene ====================
 	*/
-#if IRRLICHT_VERSION_MT_REVISION < 5
-	if (++m_reset_HW_buffer_counter > 500) {
-		/*
-		  Periodically remove all mesh HW buffers.
-
-		  Work around for a quirk in Irrlicht where a HW buffer is only
-		  released after 20000 iterations (triggered from endScene()).
-
-		  Without this, all loaded but unused meshes will retain their HW
-		  buffers for at least 5 minutes, at which point looking up the HW buffers
-		  becomes a bottleneck and the framerate drops (as much as 30%).
-
-		  Tests showed that numbers between 50 and 1000 are good, so picked 500.
-		  There are no other public Irrlicht APIs that allow interacting with the
-		  HW buffers without tracking the status of every individual mesh.
-
-		  The HW buffers for _visible_ meshes will be reinitialized in the next frame.
-		*/
-		infostream << "Game::updateFrame(): Removing all HW buffers." << std::endl;
-		driver->removeAllHardwareBuffers();
-		m_reset_HW_buffer_counter = 0;
-	}
-#endif
 
 	driver->endScene();
 
diff --git a/src/client/mapblock_mesh.cpp b/src/client/mapblock_mesh.cpp
index e6ccb764f..dd663d59e 100644
--- a/src/client/mapblock_mesh.cpp
+++ b/src/client/mapblock_mesh.cpp
@@ -1395,14 +1395,6 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
 MapBlockMesh::~MapBlockMesh()
 {
 	for (scene::IMesh *m : m_mesh) {
-#if IRRLICHT_VERSION_MT_REVISION < 5
-		if (m_enable_vbo) {
-			for (u32 i = 0; i < m->getMeshBufferCount(); i++) {
-				scene::IMeshBuffer *buf = m->getMeshBuffer(i);
-				RenderingEngine::get_video_driver()->removeHardwareBuffer(buf);
-			}
-		}
-#endif
 		m->drop();
 	}
 	for (MinimapMapblock *block : m_minimap_mapblocks)
diff --git a/src/client/sky.cpp b/src/client/sky.cpp
index 0ab7398f2..aacc47250 100644
--- a/src/client/sky.cpp
+++ b/src/client/sky.cpp
@@ -39,13 +39,8 @@ static video::SMaterial baseMaterial()
 {
 	video::SMaterial mat;
 	mat.Lighting = false;
-#if IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR > 8
 	mat.ZBuffer = video::ECFN_DISABLED;
 	mat.ZWriteEnable = video::EZW_OFF;
-#else
-	mat.ZWriteEnable = false;
-	mat.ZBuffer = video::ECFN_NEVER;
-#endif
 	mat.AntiAliasing = 0;
 	mat.TextureLayer[0].TextureWrapU = video::ETC_CLAMP_TO_EDGE;
 	mat.TextureLayer[0].TextureWrapV = video::ETC_CLAMP_TO_EDGE;
diff --git a/src/gui/guiButton.cpp b/src/gui/guiButton.cpp
index be7e0c439..3a2ddde1c 100644
--- a/src/gui/guiButton.cpp
+++ b/src/gui/guiButton.cpp
@@ -499,12 +499,10 @@ video::SColor GUIButton::getOverrideColor() const
 	return OverrideColor;
 }
 
-#if IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR > 8
 video::SColor GUIButton::getActiveColor() const
 {
 	return video::SColor(0,0,0,0); // unused?
 }
-#endif
 
 void GUIButton::enableOverrideColor(bool enable)
 {
diff --git a/src/gui/guiButton.h b/src/gui/guiButton.h
index ee9bb6f21..5e379b28f 100644
--- a/src/gui/guiButton.h
+++ b/src/gui/guiButton.h
@@ -17,64 +17,8 @@
 
 using namespace irr;
 
-#if (IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR <= 8)
-	namespace irr { namespace gui {
-
-		//! State of buttons used for drawing texture images.
-		//! Note that only a single state is active at a time
-		//! Also when no image is defined for a state it will use images from another state
-		//! and if that state is not set from the replacement for that,etc.
-		//! So in many cases setting EGBIS_IMAGE_UP and EGBIS_IMAGE_DOWN is sufficient.
-		enum EGUI_BUTTON_IMAGE_STATE {
-			//! When no other states have images they will all use this one.
-					EGBIS_IMAGE_UP,
-			//! When not set EGBIS_IMAGE_UP is used.
-					EGBIS_IMAGE_UP_MOUSEOVER,
-			//! When not set EGBIS_IMAGE_UP_MOUSEOVER is used.
-					EGBIS_IMAGE_UP_FOCUSED,
-			//! When not set EGBIS_IMAGE_UP_FOCUSED is used.
-					EGBIS_IMAGE_UP_FOCUSED_MOUSEOVER,
-			//! When not set EGBIS_IMAGE_UP is used.
-					EGBIS_IMAGE_DOWN,
-			//! When not set EGBIS_IMAGE_DOWN is used.
-					EGBIS_IMAGE_DOWN_MOUSEOVER,
-			//! When not set EGBIS_IMAGE_DOWN_MOUSEOVER is used.
-					EGBIS_IMAGE_DOWN_FOCUSED,
-			//! When not set EGBIS_IMAGE_DOWN_FOCUSED is used.
-					EGBIS_IMAGE_DOWN_FOCUSED_MOUSEOVER,
-			//! When not set EGBIS_IMAGE_UP or EGBIS_IMAGE_DOWN are used (depending on button state).
-					EGBIS_IMAGE_DISABLED,
-			//! not used, counts the number of enumerated items
-					EGBIS_COUNT
-		};
-
-		//! Names for gui button image states
-		const c8 *const GUIButtonImageStateNames[EGBIS_COUNT + 1] =
-				{
-						"Image",    // not "ImageUp" as it otherwise breaks serialization of old files
-						"ImageUpOver",
-						"ImageUpFocused",
-						"ImageUpFocusedOver",
-						"PressedImage",    // not "ImageDown" as it otherwise breaks serialization of old files
-						"ImageDownOver",
-						"ImageDownFocused",
-						"ImageDownFocusedOver",
-						"ImageDisabled",
-						0    // count
-				};
-
-	}}
-
-#endif
-
 class ISimpleTextureSource;
 
-#if (IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR <= 8)
-#define OVERRIDE_19
-#else
-#define OVERRIDE_19 override
-#endif
-
 class GUIButton : public gui::IGUIButton
 {
 public:
@@ -103,27 +47,25 @@ public:
 	virtual gui::IGUIFont* getActiveFont() const override;
 
 	//! Sets another color for the button text.
-	virtual void setOverrideColor(video::SColor color) OVERRIDE_19;
+	virtual void setOverrideColor(video::SColor color) override;
 
 	//! Gets the override color
-	virtual video::SColor getOverrideColor(void) const OVERRIDE_19;
+	virtual video::SColor getOverrideColor() const override;
 
-	#if IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR > 8
 	//! Gets the currently used text color
 	virtual video::SColor getActiveColor() const override;
-	#endif
 
 	//! Sets if the button text should use the override color or the color in the gui skin.
-	virtual void enableOverrideColor(bool enable) OVERRIDE_19;
+	virtual void enableOverrideColor(bool enable) override;
 
 	//! Checks if an override color is enabled
-	virtual bool isOverrideColorEnabled(void) const OVERRIDE_19;
+	virtual bool isOverrideColorEnabled(void) const override;
 
 	// PATCH
 	//! Sets an image which should be displayed on the button when it is in the given state.
 	virtual void setImage(gui::EGUI_BUTTON_IMAGE_STATE state,
 			video::ITexture* image=nullptr,
-			const core::rect<s32>& sourceRect=core::rect<s32>(0,0,0,0)) OVERRIDE_19;
+			const core::rect<s32>& sourceRect=core::rect<s32>(0,0,0,0)) override;
 
 	//! Sets an image which should be displayed on the button when it is in normal state.
 	virtual void setImage(video::ITexture* image=nullptr) override;
@@ -152,25 +94,19 @@ public:
 	*/
 	virtual void setSprite(gui::EGUI_BUTTON_STATE state, s32 index,
 						   video::SColor color=video::SColor(255,255,255,255),
-						   bool loop=false, bool scale=false) OVERRIDE_19;
-
-#if (IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR <= 8)
-	void setSprite(gui::EGUI_BUTTON_STATE state, s32 index, video::SColor color, bool loop) override {
-		setSprite(state, index, color, loop, false);
-	}
-#endif
+						   bool loop=false, bool scale=false) override;
 
 	//! Get the sprite-index for the given state or -1 when no sprite is set
-	virtual s32 getSpriteIndex(gui::EGUI_BUTTON_STATE state) const OVERRIDE_19;
+	virtual s32 getSpriteIndex(gui::EGUI_BUTTON_STATE state) const override;
 
 	//! Get the sprite color for the given state. Color is only used when a sprite is set.
-	virtual video::SColor getSpriteColor(gui::EGUI_BUTTON_STATE state) const OVERRIDE_19;
+	virtual video::SColor getSpriteColor(gui::EGUI_BUTTON_STATE state) const override;
 
 	//! Returns if the sprite in the given state does loop
-	virtual bool getSpriteLoop(gui::EGUI_BUTTON_STATE state) const OVERRIDE_19;
+	virtual bool getSpriteLoop(gui::EGUI_BUTTON_STATE state) const override;
 
 	//! Returns if the sprite in the given state is scaled
-	virtual bool getSpriteScale(gui::EGUI_BUTTON_STATE state) const OVERRIDE_19;
+	virtual bool getSpriteScale(gui::EGUI_BUTTON_STATE state) const override;
 
 	//! Sets if the button should behave like a push button. Which means it
 	//! can be in two states: Normal or Pressed. With a click on the button,
@@ -210,13 +146,13 @@ public:
 	virtual bool isScalingImage() const override;
 
 	//! Get if the shift key was pressed in last EGET_BUTTON_CLICKED event
-	virtual bool getClickShiftState() const OVERRIDE_19
+	virtual bool getClickShiftState() const override
 	{
 		return ClickShiftState;
 	}
 
 	//! Get if the control key was pressed in last EGET_BUTTON_CLICKED event
-	virtual bool getClickControlState() const OVERRIDE_19
+	virtual bool getClickControlState() const override
 	{
 		return ClickControlState;
 	}
diff --git a/src/gui/guiChatConsole.cpp b/src/gui/guiChatConsole.cpp
index 787afed7e..df4fd466b 100644
--- a/src/gui/guiChatConsole.cpp
+++ b/src/gui/guiChatConsole.cpp
@@ -673,13 +673,11 @@ bool GUIChatConsole::OnEvent(const SEvent& event)
 			}
 		}
 	}
-#if (IRRLICHT_VERSION_MT_REVISION >= 2)
 	else if(event.EventType == EET_STRING_INPUT_EVENT)
 	{
 		prompt.input(std::wstring(event.StringInput.Str->c_str()));
 		return true;
 	}
-#endif
 
 	return Parent ? Parent->OnEvent(event) : false;
 }
diff --git a/src/gui/guiEditBox.cpp b/src/gui/guiEditBox.cpp
index 4a0f5013d..e25c9ace3 100644
--- a/src/gui/guiEditBox.cpp
+++ b/src/gui/guiEditBox.cpp
@@ -200,7 +200,6 @@ void GUIEditBox::sendGuiEvent(EGUI_EVENT_TYPE type)
 bool GUIEditBox::OnEvent(const SEvent &event)
 {
 	if (isEnabled()) {
-
 		switch (event.EventType) {
 		case EET_GUI_EVENT:
 			if (event.GUIEvent.EventType == EGET_ELEMENT_FOCUS_LOST) {
@@ -218,11 +217,9 @@ bool GUIEditBox::OnEvent(const SEvent &event)
 			if (processMouse(event))
 				return true;
 			break;
-#if (IRRLICHT_VERSION_MT_REVISION >= 2)
 		case EET_STRING_INPUT_EVENT:
 			inputString(*event.StringInput.Str);
 			return true;
-#endif
 		default:
 			break;
 		}
diff --git a/src/irrlicht_changes/CGUITTFont.h b/src/irrlicht_changes/CGUITTFont.h
index 2721364f5..ebbdf4cf4 100644
--- a/src/irrlicht_changes/CGUITTFont.h
+++ b/src/irrlicht_changes/CGUITTFont.h
@@ -138,10 +138,8 @@ namespace gui
 
 				bool flgmip = driver->getTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS);
 				driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, false);
-#if IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR > 8
 				bool flgcpy = driver->getTextureCreationFlag(video::ETCF_ALLOW_MEMORY_COPY);
 				driver->setTextureCreationFlag(video::ETCF_ALLOW_MEMORY_COPY, true);
-#endif
 
 				// Set the texture color format.
 				switch (pixel_mode)
@@ -157,9 +155,8 @@ namespace gui
 
 				// Restore our texture creation flags.
 				driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, flgmip);
-#if IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR > 8
 				driver->setTextureCreationFlag(video::ETCF_ALLOW_MEMORY_COPY, flgcpy);
-#endif
+
 				return texture ? true : false;
 			}
 
diff --git a/src/irrlicht_changes/static_text.cpp b/src/irrlicht_changes/static_text.cpp
index a4749bab1..4dc452349 100644
--- a/src/irrlicht_changes/static_text.cpp
+++ b/src/irrlicht_changes/static_text.cpp
@@ -239,12 +239,10 @@ video::SColor StaticText::getOverrideColor() const
 	return ColoredText.getDefaultColor();
 }
 
-#if IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR > 8
 video::SColor StaticText::getActiveColor() const
 {
 	return getOverrideColor();
 }
-#endif
 
 //! Sets if the static text should use the overide color or the
 //! color in the gui skin.
diff --git a/src/irrlicht_changes/static_text.h b/src/irrlicht_changes/static_text.h
index fc58e3e90..93a2d8643 100644
--- a/src/irrlicht_changes/static_text.h
+++ b/src/irrlicht_changes/static_text.h
@@ -135,10 +135,8 @@ namespace gui
 		//! Gets the override color
 		virtual video::SColor getOverrideColor() const;
 
-		#if IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR > 8
 		//! Gets the currently used text color
 		virtual video::SColor getActiveColor() const;
-		#endif
 
 		//! Sets if the static text should use the overide color or the
 		//! color in the gui skin.
diff --git a/src/irrlichttypes.h b/src/irrlichttypes.h
index 93c2d105b..343eba1dc 100644
--- a/src/irrlichttypes.h
+++ b/src/irrlichttypes.h
@@ -31,7 +31,7 @@ using namespace irr;
 
 namespace irr {
 
-#if (IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR >= 9)
+// Define missing constant for vector math with 16-bit numbers
 namespace core {
 	template <typename T>
 	inline T roundingError();
@@ -42,7 +42,6 @@ namespace core {
 		return 0;
 	}
 }
-#endif
 
 }