From 964acc1dafc8dbf527f1af8afdba1b3f995ac025 Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Thu, 21 Jan 2021 12:26:08 +1000
Subject: Add Haiku support


diff --git a/CMakeLists.txt b/CMakeLists.txt
index c4d8582..68defec 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -813,6 +813,8 @@ elseif(SWITCH_BUILD)
         COMMAND ${DEVKITPRO}/tools/bin/nacptool --create "${SHORT_NAME}" "rsn8887" ${SWITCH_VERSION} ${SHORT_NAME}.nacp
         COMMAND ${DEVKITPRO}/tools/bin/elf2nro ${SHORT_NAME} ${SHORT_NAME}.nro --icon=${CMAKE_SOURCE_DIR}/res/switch/icon0.jpg --nacp=${SHORT_NAME}.nacp
     )
+elseif (HAIKU_BUILD)
+	target_link_libraries (${SHORT_NAME} ${SDL2_LIBRARY} ${SDL2_MIXER_LIBRARY})
 else()
     if (UNIX AND NOT APPLE AND (CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID STREQUAL "Clang"))
         target_link_libraries(${SHORT_NAME} m)
diff --git a/src/core/backtrace.c b/src/core/backtrace.c
index 75f35fe..374fcdd 100644
--- a/src/core/backtrace.c
+++ b/src/core/backtrace.c
@@ -2,7 +2,7 @@
 
 #include "core/log.h"
 
-#if defined(__GNUC__) && !defined(__MINGW32__) && !defined(__OpenBSD__) && !defined(__vita__) && !defined(__SWITCH__) && !defined(__ANDROID__)
+#if defined(__GNUC__) && !defined(__MINGW32__) && !defined(__OpenBSD__) && !defined(__vita__) && !defined(__SWITCH__) && !defined(__ANDROID__) && !defined(__HAIKU__)
 
 #include <execinfo.h>
 
diff --git a/src/game/settings.c b/src/game/settings.c
index 074c6b7..8a67224 100644
--- a/src/game/settings.c
+++ b/src/game/settings.c
@@ -41,7 +41,7 @@ static struct {
 
 static void load_default_settings(void)
 {
-    data.fullscreen = 1;
+    data.fullscreen = 0;
     data.window_width = 800;
     data.window_height = 600;
 
@@ -70,7 +70,7 @@ static void load_default_settings(void)
 static void load_settings(buffer *buf)
 {
     buffer_skip(buf, 4);
-    data.fullscreen = buffer_read_i32(buf);
+    data.fullscreen = 0;
     buffer_skip(buf, 3);
     data.sound_effects.enabled = buffer_read_u8(buf);
     data.sound_music.enabled = buffer_read_u8(buf);
@@ -127,7 +127,7 @@ void settings_load(void)
     buffer_init(&buf, data.inf_file, size);
     load_settings(&buf);
 
-    if (data.window_width + data.window_height < 500) {
+    if (data.window_width < 800 || data.window_height < 600) {
         // most likely migration from Caesar 3
         data.window_width = 800;
         data.window_height = 600;
diff --git a/src/platform/cursor.c b/src/platform/cursor.c
index cde3ba2..04d65cb 100644
--- a/src/platform/cursor.c
+++ b/src/platform/cursor.c
@@ -4,6 +4,7 @@
 #include "graphics/color.h"
 #include "input/cursor.h"
 #include "platform/screen.h"
+#include "platform/haiku/haiku.h"
 #include "platform/switch/switch.h"
 #include "platform/vita/vita.h"
 
diff --git a/src/platform/haiku/haiku.h b/src/platform/haiku/haiku.h
new file mode 100644
index 0000000..e4f9d40
--- /dev/null
+++ b/src/platform/haiku/haiku.h
@@ -0,0 +1,6 @@
+#ifndef PLATFORM_HAIKU_H
+#define PLATFORM_HAIKU_H
+
+#define PLATFORM_USE_SOFTWARE_CURSOR
+
+#endif
diff --git a/src/platform/screen.c b/src/platform/screen.c
index 071dbb8..840f9e7 100644
--- a/src/platform/screen.c
+++ b/src/platform/screen.c
@@ -11,6 +11,7 @@
 #include "platform/cursor.h"
 #include "platform/switch/switch.h"
 #include "platform/vita/vita.h"
+#include "platform/haiku/haiku.h"
 
 #include "SDL.h"
 
-- 
2.30.0

