From 8d0e4b67374a50088de986234361f3f76a45b357 Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Wed, 17 Feb 2021 19:01:47 +1000
Subject: Fix for Haiku


diff --git a/Aquaria/DSQ.cpp b/Aquaria/DSQ.cpp
index dc18033..4fb29c8 100644
--- a/Aquaria/DSQ.cpp
+++ b/Aquaria/DSQ.cpp
@@ -49,6 +49,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include "ttvfs.h"
 #endif
 
+#ifdef __HAIKU__
+#include <interface/Rect.h>
+#include <interface/Screen.h>
+#endif
+
 #ifdef BBGE_BUILD_UNIX
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -966,7 +971,11 @@ This build is not yet final, and as such there are a couple things lacking. They
 //	PHYSFS_addToSearchPath("gfx.zpk",0 );
 
 	bool mipmapsEnabled=true;
+#ifdef __HAIKU__
+	bool fullscreen = false;
+#else
 	bool fullscreen = true;
+#endif
 	int joystickMode = 0;
 	int dsq_filter = 0;
 	voiceOversEnabled = true;
@@ -1014,6 +1023,20 @@ This build is not yet final, and as such there are a couple things lacking. They
 	else
 		debugLog("VoiceOvers Disabled");
 
+#ifdef __HAIKU__
+	SDL_Init(SDL_INIT_VIDEO);
+
+	BScreen *scr = new BScreen(B_MAIN_SCREEN_ID);
+	if (fullscreen) {
+		user.video.resx = scr->Frame().Width() + 1;
+		user.video.resy = scr->Frame().Height() + 1;
+	} else {
+		if (user.video.resx >= scr->Frame().Width() + 1 && user.video.resy >= scr->Frame().Height() + 1) {
+			user.video.resx = 800;
+			user.video.resy = 600;
+		}
+	}
+#endif
 
 #ifdef _DEBUG
 	if (!createWindow(800, 600, user.video.bits, false, "Aquaria"))
@@ -1035,7 +1058,7 @@ This build is not yet final, and as such there are a couple things lacking. They
 	debugLog("OK");
 	*/
 
-#ifdef BBGE_BUILD_SDL
+#if defined(BBGE_BUILD_SDL) && !defined(__HAIKU__)
 	SDL_Init(SDL_INIT_VIDEO);
 	if (fullscreen && !sdlVideoModeOK(user.video.resx, user.video.resy, user.video.bits))
 	{
diff --git a/Aquaria/Game.cpp b/Aquaria/Game.cpp
index b6847f4..4df3fa1 100644
--- a/Aquaria/Game.cpp
+++ b/Aquaria/Game.cpp
@@ -40,6 +40,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 #include "ToolTip.h"
 
+#ifdef __HAIKU__
+#include <interface/Rect.h>
+#include <interface/Screen.h>
+#endif
+
 std::vector<std::string> allowedMaps;
 
 Vector worldLeftCenter(217,250), worldRightCenter(575, 250);
@@ -8752,6 +8757,18 @@ void Game::onOptionsSave()
 		|| dsq->user.video.full != dsq->user_backup.video.full
 		|| dsq->user.video.vsync != dsq->user_backup.video.vsync)
 	{
+#ifdef __HAIKU__
+		if (dsq->user.video.full != dsq->user_backup.video.full) {
+			if (dsq->user.video.full) {
+				BScreen scr(B_MAIN_SCREEN_ID);
+				dsq->user.video.resx = scr.Frame().Width() + 1;
+				dsq->user.video.resy = scr.Frame().Height() + 1;
+			} else {
+				dsq->user.video.resx = 800;
+				dsq->user.video.resy = 600;
+			}
+		}
+#endif
 		dsq->resetGraphics(dsq->user.video.resx, dsq->user.video.resy, dsq->user.video.full);
 		if (dsq->confirm("", "graphics", false, 10)) {
 		} else {
diff --git a/BBGE/Core.cpp b/BBGE/Core.cpp
index 2e3be81..450af28 100644
--- a/BBGE/Core.cpp
+++ b/BBGE/Core.cpp
@@ -39,6 +39,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include <Carbon/Carbon.h>
 #endif
 
+#ifdef __HAIKU__
+#include <interface/Rect.h>
+#include <interface/Screen.h>
+#endif
+
 #if BBGE_BUILD_WINDOWS
 #include <shlobj.h>
 #include <direct.h>
@@ -912,6 +917,8 @@ Core::Core(const std::string &filesystem, const std::string& extraDataDir, int n
 	// "/home/icculus/.Aquaria" or something. Spaces are okay.
 	#ifdef BBGE_BUILD_MACOSX
 	const std::string prefix("Library/Application Support/");
+	#elif defined(__HAIKU__)
+	const std::string prefix("config/settings/");
 	#else
 	const std::string prefix(".");
 	#endif
@@ -1975,7 +1982,7 @@ bool Core::initGraphicsLibrary(int width, int height, bool fullscreen, int vsync
 		Uint32 flags = 0;
 		flags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN;
 		if (fullscreen)
-			flags |= SDL_WINDOW_FULLSCREEN;
+			flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
 		gScreen = SDL_CreateWindow(appName.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, flags);
 		if (gScreen == NULL)
 		{
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 941fc25..5a7ae55 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -740,6 +740,10 @@ IF(WIN32)
     SET(OPTIONAL_LIBS ${OPTIONAL_LIBS} "ws2_32")
 ENDIF(WIN32)
 
+IF(HAIKU)
+    SET(OPTIONAL_LIBS ${OPTIONAL_LIBS} "be")
+ENDIF(HAIKU)
+
 IF(MACOSX)
     SET(OPTIONAL_LIBS ${OPTIONAL_LIBS} "-framework Carbon")
     SET(OPTIONAL_LIBS ${OPTIONAL_LIBS} "-framework Cocoa")
-- 
2.30.0


From f4c8f378437f172a04be100278995e71fd5bcb32 Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Wed, 17 Feb 2021 22:19:35 +1000
Subject: Use SupportDefs.h


diff --git a/BBGE/Flags.h b/BBGE/Flags.h
index 5eb304b..e8ff9ad 100644
--- a/BBGE/Flags.h
+++ b/BBGE/Flags.h
@@ -24,10 +24,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #ifdef BBGE_BUILD_WINDOWS
 	typedef unsigned __int32	uint32;
 #endif
-#ifdef BBGE_BUILD_UNIX
+#if defined(BBGE_BUILD_UNIX) && !defined(__HAIKU__)
 	#include <stdint.h>
 	typedef uint32_t			uint32;
 #endif
+#ifdef __HAIKU__
+	#include <SupportDefs.h>
+#endif
 #ifdef BBGE_BUILD_X360
 	typedef unsigned int		uint32;
 #endif
-- 
2.30.0

