Thread Problem

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
oldrider
Posts: 4
Joined: Tue Oct 09, 2007 10:40 pm
Contact:

Thread Problem

Post by oldrider »

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: Select all

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: Select all

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.
oldrider
Posts: 4
Joined: Tue Oct 09, 2007 10:40 pm
Contact:

i´m trying...

Post by oldrider »

I´m try this code below

Code: Select all

#include <oslib/oslib.h>
#include <pspthreadman.h>

PSP_MODULE_INFO&#40;"THExample", 0, 1, 1&#41;;
PSP_MAIN_THREAD_ATTR&#40;THREAD_ATTR_USER | THREAD_ATTR_VFPU&#41;;

bool loaded;
OSL_IMAGE* Image;

int user_main&#40;SceSize args, void *argp&#41; &#123;
		
    Image = oslCreateImage&#40;50, 74, OSL_IN_RAM, OSL_PF_8888&#41;;
	oslPrintf&#40;"create\n"&#41;;
    Image = oslLoadImageFile&#40;"anjo1.png", OSL_IN_RAM, OSL_PF_8888&#41;;
	oslPrintf&#40;"loaded\n"&#41;;
	if &#40;Image == NULL&#41; &#123;
         oslFatalError&#40;"Error <#300>"&#41;;
         return -1;
     &#125;
    loaded = true;
	return 0;
&#125;

int main&#40;SceSize args, void *argp&#41; &#123;
    loaded = false;
    
    oslInit&#40;0&#41;;
    oslInitGfx&#40;OSL_PF_8888, 0&#41;;
	oslInitConsole&#40;&#41;; 
	oslPrintf&#40;"Loading images..."&#41;; 
    
   SceUID thid = sceKernelCreateThread&#40;"User Mode Thread", user_main, 
            0x11, // default priority 
            256*1024, // stack size &#40;256KB is regular default&#41; 
            PSP_THREAD_ATTR_USER, NULL&#41;; 
	
    sceKernelStartThread&#40;thid, 0, NULL&#41;; 
    sceKernelWaitThreadEnd&#40;thid, NULL&#41;; 

	while &#40;!osl_quit&#41; &#123;
        oslStartDrawing&#40;&#41;;
        
        if &#40;loaded&#41; oslDrawImage&#40;Image&#41;;
        
        oslReadKeys&#40;&#41;;
        if &#40;osl_pad.pressed.start&#41; oslQuit&#40;&#41;;
		
        
        oslEndDrawing&#40;&#41;;
    &#125;	
    
    oslEndGfx&#40;&#41;;
    oslQuit&#40;&#41;;
    
    return 0;
&#125;
oslPrintf is displayed but Image is not drawing.
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

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: Select all

    sceKernelDelayThread&#40;100000&#41;;
oldrider
Posts: 4
Joined: Tue Oct 09, 2007 10:40 pm
Contact:

Post by oldrider »

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: Select all

    sceKernelDelayThread&#40;100000&#41;;
I'm try, but Image not loaded.

How to make a thread with loading images??
Post Reply