 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
jojojoris
Joined: 30 Mar 2008 Posts: 261
|
Posted: Sat Aug 23, 2008 6:10 pm Post subject: Setupcallbacks |
|
|
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 |
|
 |
Raphael

Joined: 17 Jan 2006 Posts: 646 Location: Germany
|
Posted: Sat Aug 23, 2008 6:24 pm Post subject: |
|
|
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 |
|
 |
jean

Joined: 05 Jan 2008 Posts: 489
|
Posted: Sat Aug 23, 2008 6:30 pm Post subject: |
|
|
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 |
|
 |
|
|
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
|