Code: Select all
static int running = 1;
/* Exit callback */
int exit_callback(int arg1, int arg2, void *common)
{
running = 0;
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;
}
int main()
{
// setup the callbacks
SetupCallbacks();
while(running) {
// main loop
}
sceKernelSleepThread();
return 0;
}
I get that part, but then, things start to get trickier. The function, CallbackThread(), gets called as soon as "update_thread" is started, right? Also, does "update_thread" keeping calling Callback thread until it is put to sleep/terminated?
Then, once CallbackThread() is called, it creates a callback. Is a callback a thread? What are the differences exactly between callbacks (I'm assuming it's a type of thread) and regular threads such as update_thread? Then, it registers that callback thread to be used as an exit callback thread. All I know is that it is needed for the Home button to successfullly shut down the application. The last thing CallbackThread() does is puts the exit callback to sleep, right?
The exit callback thread function, exit_callback is called when the exit callback function is ran, right? What it does is call sceKernelExitGame(). What does sceKernelExitGame() do? Actually, when does exit_callback get called? I'm sure it has to be able to be called when inside the main loop because then running can be set to '0', terminating the loop. The idea of running was Insert_Witty_Name's advice, so I'm not sure how it works. I think exit_callback is called when 'Yes' is selected when the Home button is pressed, bringing up the exit game screen. The exit_callback does that because it was registered to do that with sceKernelRegisterExitCallback() back in CallbackThread(). After the main loop, sceKernelSleepThread() is called. That will put update_thread to sleep, right?
One other thing I was wondering is, what are the purposes of the arguments in the callback functions? CallbackThread() has two, and exit_callback has three. They look similar to the ones in main(), but I don't see what the point of them are. Maybe to be used similarly like main()'s arguments? They can be used for commandline-based debugging and such, right?