 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
oldrider
Joined: 09 Oct 2007 Posts: 4
|
Posted: Tue Oct 09, 2007 10:50 pm Post subject: Thread Problem |
|
|
Hello, my group is developing a framework OOP for games, using OSLib.
how I can make a thread using c++ and OSLib?
I need to have a thread carrying my images, sounds, etc. To create a loading system.
This is my function Start:
| Code: |
void PSPFLoader::Start() {
LoadThread = sceKernelCreateThread("PSPFLoaderThread", ThreadMetod, 0x10, 0x10000, PSP_THREAD_ATTR_USER, NULL);
if (LoadThread >= 0) {
sceKernelStartThread(LoadThread, 0, 0);
SceKernelThreadInfo* info;
sceKernelReferThreadStatus(LoadThread, info);
oslDebug("%d", info->status);
}
else
oslDebug("Erro #501");
Started = true;
}
|
In My other class inherit Loader above:
| Code: | AngelLoader::AngelLoader() {
ThreadMetod = loa;
}
int loa(SceSize args, void *argp) {
PSPFResourceManager* r = PSPFResourceManager::getResourceManager();
oslDebug("PRE1");
PSPFImage* imagem = new PSPFImage(100, 74, OSL_PF_5551, "Anjo.png");
imagem->setFormatSheet(50, 74);
r->AddResource(imagem, "ANJO");
mywait(1000);
oslDebug("PRE1 - OK");
PSPFImage* background = new PSPFImage(500, 300, OSL_PF_5551, "fundo.jpg");
r->AddResource(background, "BACKGROUND");
mywait(1000);
PSPFSound* musica = new PSPFSound("som.wav", NONE, 1);
r->AddResource(musica, "SOM");
mywait(1000);
Mundo* fase1 = new Mundo();
PSPFWorldManager::getWorldManager()->AddPSPFWorld(fase1);
PSPFWorldManager::getWorldManager()->setWorldFocus(1);
return 1;
}
|
But this thread return status 4 (Waiting) or PSP Crash. |
|
| Back to top |
|
 |
oldrider
Joined: 09 Oct 2007 Posts: 4
|
Posted: Wed Oct 10, 2007 12:51 pm Post subject: i´m trying... |
|
|
I´m try this code below
| Code: |
#include <oslib/oslib.h>
#include <pspthreadman.h>
PSP_MODULE_INFO("THExample", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);
bool loaded;
OSL_IMAGE* Image;
int user_main(SceSize args, void *argp) {
Image = oslCreateImage(50, 74, OSL_IN_RAM, OSL_PF_8888);
oslPrintf("create\n");
Image = oslLoadImageFile("anjo1.png", OSL_IN_RAM, OSL_PF_8888);
oslPrintf("loaded\n");
if (Image == NULL) {
oslFatalError("Error <#300>");
return -1;
}
loaded = true;
return 0;
}
int main(SceSize args, void *argp) {
loaded = false;
oslInit(0);
oslInitGfx(OSL_PF_8888, 0);
oslInitConsole();
oslPrintf("Loading images...");
SceUID thid = sceKernelCreateThread("User Mode Thread", user_main,
0x11, // default priority
256*1024, // stack size (256KB is regular default)
PSP_THREAD_ATTR_USER, NULL);
sceKernelStartThread(thid, 0, NULL);
sceKernelWaitThreadEnd(thid, NULL);
while (!osl_quit) {
oslStartDrawing();
if (loaded) oslDrawImage(Image);
oslReadKeys();
if (osl_pad.pressed.start) oslQuit();
oslEndDrawing();
}
oslEndGfx();
oslQuit();
return 0;
}
|
oslPrintf is displayed but Image is not drawing. |
|
| Back to top |
|
 |
J.F.
Joined: 22 Feb 2004 Posts: 2906
|
Posted: Wed Oct 10, 2007 1:43 pm Post subject: |
|
|
Your main thread isn't waiting, so the spawned thread doesn't get time to run. The PSP does COOPERATIVE multitasking, not preemptive. Just add something like
| Code: | | sceKernelDelayThread(100000); |
|
|
| Back to top |
|
 |
oldrider
Joined: 09 Oct 2007 Posts: 4
|
Posted: Fri Oct 12, 2007 1:21 am Post subject: |
|
|
| J.F. wrote: | Your main thread isn't waiting, so the spawned thread doesn't get time to run. The PSP does COOPERATIVE multitasking, not preemptive. Just add something like
| Code: | | sceKernelDelayThread(100000); |
|
I'm try, but Image not loaded.
How to make a thread with loading images?? |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|