From 8d8a1511a9d7e212904d7273da8f82542fc8794b Mon Sep 17 00:00:00 2001
From: Crestwave <crestwave@users.noreply.github.com>
Date: Tue, 3 Mar 2020 20:14:00 +0800
Subject: add Haiku support


diff --git a/src/RenderManagerGL2D.cpp b/src/RenderManagerGL2D.cpp
index ef16239..64b7791 100644
--- a/src/RenderManagerGL2D.cpp
+++ b/src/RenderManagerGL2D.cpp
@@ -227,12 +227,14 @@ void RenderManagerGL2D::init(int xResolution, int yResolution, bool fullscreen)
 		xResolution, yResolution,
 		screenFlags);
 
+#ifndef __HAIKU__
 	// Set icon
 	SDL_Surface* icon = loadSurface("Icon.bmp");
 	SDL_SetColorKey(icon, SDL_TRUE,
 			SDL_MapRGB(icon->format, 0, 0, 0));
 	SDL_SetWindowIcon(mWindow, icon);
 	SDL_FreeSurface(icon);
+#endif
 
 	// Create gl context
 	mGlContext = SDL_GL_CreateContext(mWindow);
diff --git a/src/RenderManagerSDL.cpp b/src/RenderManagerSDL.cpp
index 665e943..57a2f6a 100644
--- a/src/RenderManagerSDL.cpp
+++ b/src/RenderManagerSDL.cpp
@@ -125,12 +125,14 @@ void RenderManagerSDL::init(int xResolution, int yResolution, bool fullscreen)
 		xResolution, yResolution,
 		screenFlags);
 
+#ifndef __HAIKU__
 	// Set icon
 	SDL_Surface* icon = loadSurface("Icon.bmp");
 	SDL_SetColorKey(icon, SDL_TRUE,
 			SDL_MapRGB(icon->format, 0, 0, 0));
 	SDL_SetWindowIcon(mWindow, icon);
 	SDL_FreeSurface(icon);
+#endif
 
 	// Create renderer to draw in window
 	mRenderer = SDL_CreateRenderer(mWindow, -1, 0);
diff --git a/src/main.cpp b/src/main.cpp
index 6845783..cde769a 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -36,6 +36,10 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 	#endif
 #endif
 
+#ifdef __HAIKU__
+	#include <FindDirectory.h>
+#endif
+
 #if __DESKTOP__
 	#ifndef WIN32
 		#include "config.h"
@@ -83,7 +87,11 @@ void setupPHYSFS()
 	const std::string separator = fs.getDirSeparator();
 	// Game should be playable out of the source package on all
 	// relevant platforms.
-	#if __DESKTOP__
+	#ifdef __HAIKU__
+		char path[B_PATH_NAME_LENGTH];
+		find_path(B_APP_IMAGE_SYMBOL, B_FIND_PATH_DATA_DIRECTORY, "blobby/", path, B_PATH_NAME_LENGTH);
+		std::string baseSearchPath = path;
+	#elif __DESKTOP__
 		std::string baseSearchPath("data" + separator);
 	#elif (defined __ANDROID__)
 		std::string baseSearchPath(SDL_AndroidGetExternalStoragePath() + separator);
@@ -117,6 +125,9 @@ void setupPHYSFS()
 				#else
 					std::string userdir = fs.getUserDir();
 				#endif
+			#elif defined(__HAIKU__)
+				find_directory(B_USER_SETTINGS_DIRECTORY, 0, false, path, B_PATH_NAME_LENGTH);
+				std::string userdir = path + separator;
 			#else
 				// Linux
 				std::string userdir = fs.getUserDir();
@@ -129,7 +140,11 @@ void setupPHYSFS()
 				fs.addToSearchPath(BLOBBY_INSTALL_PREFIX  "/share/blobby/backgrounds.zip");
 				fs.addToSearchPath(BLOBBY_INSTALL_PREFIX  "/share/blobby/rules.zip");
 			#endif
-			std::string userAppend = ".blobby";
+			#ifndef __HAIKU__
+				std::string userAppend = ".blobby";
+			#else
+				std::string userAppend = "blobby";
+			#endif
 			std::string homedir = userdir + userAppend;
 			/// \todo please review this code and determine if we really need to add userdir to search path
 			/// only to remove it later
diff --git a/src/server/DedicatedServer.cpp b/src/server/DedicatedServer.cpp
index e2c7c59..539cd88 100644
--- a/src/server/DedicatedServer.cpp
+++ b/src/server/DedicatedServer.cpp
@@ -33,7 +33,11 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 #ifndef WIN32
 #ifndef __ANDROID__
+#ifndef __HAIKU__
 #include <sys/syslog.h>
+#else
+#include <posix/syslog.h>
+#endif
 #endif
 #endif
 
diff --git a/src/server/servermain.cpp b/src/server/servermain.cpp
index 995c181..850a9ef 100644
--- a/src/server/servermain.cpp
+++ b/src/server/servermain.cpp
@@ -44,7 +44,12 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 // platform specific
 #ifndef WIN32
+#ifndef __HAIKU__
 #include <sys/syslog.h>
+#else
+#include <FindDirectory.h>
+#include <posix/syslog.h>
+#endif
 #include <sys/wait.h>
 #else
 #include <cstdarg>
@@ -304,8 +309,15 @@ void setup_physfs(char* argv0)
 		fs.addToSearchPath(BLOBBY_INSTALL_PREFIX  "/share/blobby/rules.zip");
 	#endif
 	#endif
-	fs.addToSearchPath("data");
-	fs.addToSearchPath("data" + fs.getDirSeparator() + "rules.zip");
+	#ifndef __HAIKU__
+		fs.addToSearchPath("data");
+		fs.addToSearchPath("data" + fs.getDirSeparator() + "rules.zip");
+	#else
+		char path[B_PATH_NAME_LENGTH];
+		find_path(B_APP_IMAGE_SYMBOL, B_FIND_PATH_DATA_DIRECTORY, "blobby", path, B_PATH_NAME_LENGTH);
+		fs.addToSearchPath(path);
+		fs.addToSearchPath(std::string(path) + "/rules.zip");
+	#endif
 }
 
 
-- 
2.24.1

