use haiku native threads

This commit is contained in:
Li
2026-04-20 09:02:13 +00:00
parent 1effcd1e6d
commit 9ba3fabfb6
7 changed files with 96 additions and 8 deletions

26
project/haiku/createpkg.sh Executable file
View File

@@ -0,0 +1,26 @@
#!/bin/bash
mkdir build-haiku
cd build-haiku
cmake ..
make -j10
rm -rf pkg
mkdir pkg
mkdir -p ./pkg/apps/
mkdir -p ./pkg/data/minecraftpe
mkdir -p ./pkg/settings/minecraftpe
mkdir -p ./pkg/data/deskbar/menu/Applications/
mkdir -p ./pkg/data/deskbar/menu/Games/
cp -rv ../project/haiku/pkg ./
cp -v MinecraftPE ./pkg/apps/minecraftpe
cp -v MinecraftPE-server ./pkg/apps/minecraftpe-server
cp -rv data ./pkg/data/minecraftpe
ln -s ../../../../apps/minecraftpe ./pkg/data/deskbar/menu/Applications/minecraftpe
ln -s ../../../../apps/minecraftpe ./pkg/data/deskbar/menu/Games/minecraftpe
package create -C pkg minecraftpe-0.6.1-x86_64.hpkg

View File

@@ -0,0 +1,27 @@
name minecraftpe
version 0.6.1-1
architecture x86_64
summary "Minecraft Pocket Edition"
description "A port of minecraft pocket edition to Haiku"
packager "Li <li@silica.codes>"
vendor "Mojang"
copyrights {
"Copyright (C) 2026 by Mojang"
}
licenses {
"MIT"
}
provides {
minecraftpe = 0.6.1-1
app:minecraftpe = 0.6.1-1
}
requires {
glfw >= 3.3.7-1
openal >= 1.21.1-5
}
global-writable-files {
"settings/minecraftpe" directory keep-old
}
urls {
"https://gitea.sffempire.ru/Kolyah35/minecraft-pe-0.6.1/"
}

View File

@@ -20,6 +20,7 @@
#include <shellapi.h>
#endif
#ifdef __EMSCRIPTEN__
#include <emscripten/html5.h>
#endif
@@ -31,12 +32,19 @@ static void png_funcReadFile(png_structp pngPtr, png_bytep data, png_size_t leng
class AppPlatform_glfw: public AppPlatform
{
public:
AppPlatform_glfw()
#ifdef __HAIKU__
std::string game_directory = "/system/data/minecraftpe/";
#else
std::string game_directory = "";
#endif
AppPlatform_glfw()
{
}
BinaryBlob readAssetFile(const std::string& filename) override {
FILE* fp = fopen(("data/" + filename).c_str(), "r");
FILE* fp = fopen((game_directory + "data/" + filename).c_str(), "r");
if (!fp)
return BinaryBlob();
@@ -73,7 +81,7 @@ public:
TextureData out;
std::string filename = textureFolder? "data/images/" + filename_
std::string filename = textureFolder? (game_directory + "data/images/") + filename_
: filename_;
std::ifstream source(filename.c_str(), std::ios::binary);

View File

@@ -18,6 +18,8 @@ OptionsFile::OptionsFile() {
settingsPath = "options.txt";
#elif defined(__EMSCRIPTEN__)
settingsPath = "/games/com.mojang/options.txt";
#elif defined(__HAIKU__)
settingsPath = "/system/settings/minecraftpe/options.txt";
#else
settingsPath = "options.txt";
#endif

View File

@@ -191,8 +191,13 @@ int main(void) {
App* app = new MAIN_CLASS();
g_app = app;
#ifdef __HAIKU__
((MAIN_CLASS*)g_app)->externalStoragePath = "/system/settings/minecraftpe";
((MAIN_CLASS*)g_app)->externalCacheStoragePath = "/system/settings/minecraftpe";
#else
((MAIN_CLASS*)g_app)->externalStoragePath = ".";
((MAIN_CLASS*)g_app)->externalCacheStoragePath = ".";
#endif
g_app->init(appContext);
g_app->setSize(appContext.platform->getScreenWidth(), appContext.platform->getScreenHeight());

View File

@@ -25,12 +25,19 @@
&m_threadID // pointer to receive thread ID
);
#endif
#if defined(__linux__) || defined(ANDROID) || defined(__APPLE__) || defined(POSIX) || defined(__EMSCRIPTEN__) || defined(__HAIKU__)
#if defined(__linux__) || defined(ANDROID) || defined(__APPLE__) || defined(POSIX) || defined(__EMSCRIPTEN__)
mp_threadFunc = (pthread_fn)threadFunc;
pthread_attr_init(&m_attributes);
pthread_attr_setdetachstate( &m_attributes, PTHREAD_CREATE_DETACHED );
/*int error =*/ pthread_create(&m_thread, &m_attributes, mp_threadFunc, threadParam);
#endif
#if defined(__HAIKU__)
mp_threadFunc = (thread_func)threadFunc;
m_thread = spawn_thread(mp_threadFunc, "CThread", 10, threadParam);
int res = resume_thread(m_thread);
#endif
#ifdef MACOSX
mp_threadFunc = (TaskProc) threadFunc;
@@ -53,9 +60,12 @@
#ifdef WIN32
Sleep( millis );
#endif
#if defined(LINUX) || defined(ANDROID) || defined(__APPLE__) || defined(POSIX) || defined(__HAIKU__)
#if defined(LINUX) || defined(ANDROID) || defined(__APPLE__) || defined(POSIX)
usleep(millis * 1000);
#endif
#if defined(__HAIKU__)
snooze((bigtime_t)(millis * 1000));
#endif
}
CThread::~CThread()
@@ -63,11 +73,14 @@
#ifdef WIN32
TerminateThread(m_threadHandle, 0);
#endif
#if defined(LINUX) || defined(ANDROID) || defined(__APPLE__) || defined(POSIX) || defined(__HAIKU__)
#if defined(LINUX) || defined(ANDROID) || defined(__APPLE__) || defined(POSIX)
// Thread was created detached; pthread_join on a detached thread is undefined
// and causes SIGABRT when the pthread_t is no longer valid.
pthread_attr_destroy(&m_attributes);
#endif
#if defined(__HAIKU__)
kill_thread(m_thread);
#endif
}

View File

@@ -13,7 +13,7 @@
typedef void *( * pthread_fn )( void * );
#if defined(__linux__) || defined(ANDROID) || defined(__APPLE__) || defined(POSIX) || defined(__EMSCRIPTEN__) || defined(__HAIKU__)
#if defined(__linux__) || defined(ANDROID) || defined(__APPLE__) || defined(POSIX) || defined(__EMSCRIPTEN__)
#include <pthread.h>
#include <unistd.h>
@@ -21,6 +21,9 @@ typedef void *( * pthread_fn )( void * );
#ifdef MACOSX
#include <CoreServices/CoreServices.h>
#include <unistd.h>
#endif
#ifdef __HAIKU__
#include <kernel/OS.h>
#endif
class CThread
@@ -38,11 +41,15 @@ typedef void *( * pthread_fn )( void * );
DWORD m_threadID;
HANDLE m_threadHandle;
#endif
#if defined(__linux__) || defined(ANDROID) || defined(__APPLE__) || defined(POSIX) || defined(__EMSCRIPTEN__) || defined(__HAIKU__)
#if defined(__linux__) || defined(ANDROID) || defined(__APPLE__) || defined(POSIX) || defined(__EMSCRIPTEN__)
pthread_fn mp_threadFunc;
pthread_t m_thread;
pthread_attr_t m_attributes;
#endif
#if defined(__HAIKU__)
thread_func mp_threadFunc;
thread_id m_thread;
#endif
#ifdef MACOSX
TaskProc mp_threadFunc;
MPTaskID m_threadID;