mirror of
https://github.com/isledecomp/isle-portable.git
synced 2026-01-19 13:51:16 +00:00
Merge pull request #4 from AJenbo/psp
Fix threading and get the game running
This commit is contained in:
commit
209e516a6e
@ -5,7 +5,11 @@
|
|||||||
#include "mxsemaphore.h"
|
#include "mxsemaphore.h"
|
||||||
#include "mxtypes.h"
|
#include "mxtypes.h"
|
||||||
|
|
||||||
|
#ifdef PSP
|
||||||
|
#include <pspkerneltypes.h>
|
||||||
|
#else
|
||||||
#include <SDL3/SDL_thread.h>
|
#include <SDL3/SDL_thread.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
class MxCore;
|
class MxCore;
|
||||||
|
|
||||||
@ -33,9 +37,15 @@ class MxThread {
|
|||||||
virtual ~MxThread();
|
virtual ~MxThread();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
#ifdef PSP
|
||||||
|
static int ThreadProc(SceSize args, void* argp);
|
||||||
|
|
||||||
|
int m_thread;
|
||||||
|
#else
|
||||||
static int SDLCALL ThreadProc(void* p_thread);
|
static int SDLCALL ThreadProc(void* p_thread);
|
||||||
|
|
||||||
SDL_Thread* m_thread;
|
SDL_Thread* m_thread;
|
||||||
|
#endif
|
||||||
MxBool m_running; // 0x0c
|
MxBool m_running; // 0x0c
|
||||||
MxSemaphore m_semaphore; // 0x10
|
MxSemaphore m_semaphore; // 0x10
|
||||||
|
|
||||||
|
|||||||
@ -3,13 +3,20 @@
|
|||||||
#include "decomp.h"
|
#include "decomp.h"
|
||||||
|
|
||||||
#include <SDL3/SDL_timer.h>
|
#include <SDL3/SDL_timer.h>
|
||||||
|
#ifdef PSP
|
||||||
|
#include <pspkernel.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
DECOMP_SIZE_ASSERT(MxThread, 0x1c)
|
DECOMP_SIZE_ASSERT(MxThread, 0x1c)
|
||||||
|
|
||||||
// FUNCTION: LEGO1 0x100bf510
|
// FUNCTION: LEGO1 0x100bf510
|
||||||
MxThread::MxThread()
|
MxThread::MxThread()
|
||||||
{
|
{
|
||||||
|
#ifdef PSP
|
||||||
|
m_thread = 0;
|
||||||
|
#else
|
||||||
m_thread = NULL;
|
m_thread = NULL;
|
||||||
|
#endif
|
||||||
m_running = TRUE;
|
m_running = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -17,7 +24,13 @@ MxThread::MxThread()
|
|||||||
MxThread::~MxThread()
|
MxThread::~MxThread()
|
||||||
{
|
{
|
||||||
if (m_thread) {
|
if (m_thread) {
|
||||||
|
#ifdef PSP
|
||||||
|
sceKernelWaitThreadEnd(m_thread, NULL);
|
||||||
|
sceKernelDeleteThread(m_thread);
|
||||||
|
m_thread = 0;
|
||||||
|
#else
|
||||||
SDL_WaitThread(m_thread, NULL);
|
SDL_WaitThread(m_thread, NULL);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,6 +40,25 @@ MxResult MxThread::Start(MxS32 p_stackSize, MxS32 p_flag)
|
|||||||
MxResult result = FAILURE;
|
MxResult result = FAILURE;
|
||||||
|
|
||||||
if (m_semaphore.Init(0, 1) == SUCCESS) {
|
if (m_semaphore.Init(0, 1) == SUCCESS) {
|
||||||
|
#ifdef PSP
|
||||||
|
int thid = sceKernelCreateThread(
|
||||||
|
"MxThread",
|
||||||
|
ThreadProc,
|
||||||
|
0x18, // priority (0x18 is typical)
|
||||||
|
p_stackSize * 4,
|
||||||
|
0,
|
||||||
|
NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
if (thid >= 0) {
|
||||||
|
MxThread* self = this;
|
||||||
|
int start = sceKernelStartThread(thid, sizeof(MxThread*), &self);
|
||||||
|
if (start >= 0) {
|
||||||
|
result = SUCCESS;
|
||||||
|
m_thread = thid; // store thread ID if needed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
const SDL_PropertiesID props = SDL_CreateProperties();
|
const SDL_PropertiesID props = SDL_CreateProperties();
|
||||||
SDL_SetPointerProperty(props, SDL_PROP_THREAD_CREATE_ENTRY_FUNCTION_POINTER, (void*) MxThread::ThreadProc);
|
SDL_SetPointerProperty(props, SDL_PROP_THREAD_CREATE_ENTRY_FUNCTION_POINTER, (void*) MxThread::ThreadProc);
|
||||||
SDL_SetPointerProperty(props, SDL_PROP_THREAD_CREATE_USERDATA_POINTER, this);
|
SDL_SetPointerProperty(props, SDL_PROP_THREAD_CREATE_USERDATA_POINTER, this);
|
||||||
@ -37,6 +69,7 @@ MxResult MxThread::Start(MxS32 p_stackSize, MxS32 p_flag)
|
|||||||
}
|
}
|
||||||
|
|
||||||
SDL_DestroyProperties(props);
|
SDL_DestroyProperties(props);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@ -55,11 +88,19 @@ void MxThread::Terminate()
|
|||||||
m_semaphore.Wait();
|
m_semaphore.Wait();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef PSP
|
||||||
|
int MxThread::ThreadProc(SceSize args, void* argp)
|
||||||
|
{
|
||||||
|
MxThread* self = *(MxThread**) argp;
|
||||||
|
return self->Run();
|
||||||
|
}
|
||||||
|
#else
|
||||||
// FUNCTION: LEGO1 0x100bf680
|
// FUNCTION: LEGO1 0x100bf680
|
||||||
int MxThread::ThreadProc(void* p_thread)
|
int MxThread::ThreadProc(void* p_thread)
|
||||||
{
|
{
|
||||||
return static_cast<MxThread*>(p_thread)->Run();
|
return static_cast<MxThread*>(p_thread)->Run();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// FUNCTION: LEGO1 0x100bf690
|
// FUNCTION: LEGO1 0x100bf690
|
||||||
MxResult MxThread::Run()
|
MxResult MxThread::Run()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user