forked from Kolyah35/minecraft-pe-0.6.1
use haiku native threads
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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());
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user