forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Setupcallbacks

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
jojojoris



Joined: 30 Mar 2008
Posts: 261

PostPosted: Sat Aug 23, 2008 6:10 pm    Post subject: Setupcallbacks Reply with quote

Hello,

I'm a c/c++ beginner and i have a question about the SetupCallbacks();?

What does it exactly? A program without that code runs fine too.

Code:
/* Exit callback */
int exit_callback(int arg1, int arg2, void *common) {
   sceKernelExitGame();
    return 0;
}

/* Callback thread */
int CallbackThread(SceSize args, void *argp) {
   int cbid;

    cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
    sceKernelRegisterExitCallback(cbid);

    sceKernelSleepThreadCB();

    return 0;
}

/* Sets up the callback thread and returns its thread id */
int SetupCallbacks(void) {
    int thid = 0;

    thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
    if(thid >= 0) {
      sceKernelStartThread(thid, 0, 0);
      }

    return thid;
}
Back to top
View user's profile Send private message
Raphael



Joined: 17 Jan 2006
Posts: 646
Location: Germany

PostPosted: Sat Aug 23, 2008 6:24 pm    Post subject: Reply with quote

Ever seen the screen that pops up when you press the HOME button from ingame? That's what makes that screen appear.
_________________
<Don't push the river, it flows.>
http://wordpress.fx-world.org - my devblog
http://wiki.fx-world.org - VFPU documentation wiki

Alexander Berl
Back to top
View user's profile Send private message Visit poster's website
jean



Joined: 05 Jan 2008
Posts: 489

PostPosted: Sat Aug 23, 2008 6:30 pm    Post subject: Reply with quote

basically it is creating a thread whose function is only to register the exit callback....this means: its function is to make your app correctly react to the [home] button press. Just an advice: don't call sceKernelExitGame(); in exit callback: better setting a flag (e.g. "exitRequested=1") that other loops in your application should check against. Like

Code:
int exitRequested;

/* Exit callback */
int exit_callback(int arg1, int arg2, void *common) {
   exitRequested = 1;
   return 0;
}

/* Callback thread */
int CallbackThread(SceSize args, void *argp) {
 
    exitRequested = 0;

    int cbid;

    cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
    sceKernelRegisterExitCallback(cbid);

    sceKernelSleepThreadCB();

    return 0;
}

/* Sets up the callback thread and returns its thread id */
int SetupCallbacks(void) {
    int thid = 0;

    thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
    if(thid >= 0) {
      sceKernelStartThread(thid, 0, 0);
      }

    return thid;
}
.
.
.
// main loop
while (!exitRequested)
{
...do your stuff here
}
sceKernelExitGame(); // finally exit here
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
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