Discuss the development of new homebrew software, tools and libraries.
Moderators: cheriff , TyRaNiD
jojojoris
Posts: 255 Joined: Sun Mar 30, 2008 4:06 am
Post
by jojojoris » Sat Aug 23, 2008 6:10 pm
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: Select all
/* 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;
}
Raphael
Posts: 646 Joined: Tue Jan 17, 2006 4:54 pm
Location: Germany
Contact:
Post
by Raphael » Sat Aug 23, 2008 6:24 pm
Ever seen the screen that pops up when you press the HOME button from ingame? That's what makes that screen appear.
jean
Posts: 489 Joined: Sat Jan 05, 2008 2:44 am
Post
by jean » Sat Aug 23, 2008 6:30 pm
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: Select all
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