main.cpp
上传用户:zhj2929
上传日期:2022-07-23
资源大小:28772k
文件大小:4k
- //-------------------------------------------------------------------------------------
- //
- // This is part of MarioDemo, a platformer demo for JGE++
- //
- // Copyright (C) 2006 James Hui (a.k.a. Dr.Watson)
- //
- // This program is free software; you can redistribute it and/or modify it
- // under the terms of the GNU General Public License as published by the Free
- // Software Foundation; either version 2 of the License, or (at your option) any
- // later version.
- //
- // This program is distributed in the hope that it will be useful, but WITHOUT
- // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
- //
- // You should have received a copy of the GNU General Public License along with
- // this program; if not, write to the Free Software Foundation, Inc., 59 Temple
- // Place, Suite 330, Boston, MA 02111-1307 USA
- //
- // Bugs and comments can be forwarded to jhkhui@yahoo.com.
- //
- //-------------------------------------------------------------------------------------
-
#include <pspkernel.h>
#include <pspdisplay.h>
#include <pspdebug.h>
- #include <psppower.h>
-
- #include "../../JGE/include/JGE.h"
- #include "../src/GameApp.h"
- #ifndef JGEApp_Title
- #define JGEApp_Title "JGE Demo"
- #endif
-
// app name and version number
PSP_MODULE_INFO(JGEApp_Title, 0x1000, 1, 1);
// optional
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER);
GameApp *game = NULL;
JGE *engine = NULL;
- //------------------------------------------------------------------------------------------------
- // Exit callback
int exit_callback(int arg1, int arg2, void *common)
{
- if (engine != NULL)
engine->End();
-
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;
}
- //------------------------------------------------------------------------------------------------
- // Custom exception handler
- void MyExceptionHandler(PspDebugRegBlock *regs)
- {
- pspDebugScreenInit();
- pspDebugScreenSetBackColor(0x00FF0000);
- pspDebugScreenSetTextColor(0xFFFFFFFF);
- pspDebugScreenClear();
- pspDebugScreenPrintf("I regret to inform you your psp has just crashedn");
- pspDebugScreenPrintf("Please contact Sony technical support for further informationnn");
- pspDebugScreenPrintf("Exception Details:n");
- pspDebugDumpException(regs);
- pspDebugScreenPrintf("nBlame the 3rd party software, it cannot possibly be our fault!n");
-
- sceKernelExitGame();
- }
- //------------------------------------------------------------------------------------------------
- // Sort of hack to install exception handler under USER THREAD
- __attribute__((constructor)) void handlerInit()
- {
- pspKernelSetKernelPC();
- pspDebugInstallErrorHandler(MyExceptionHandler);
- }
- //------------------------------------------------------------------------------------------------
- // The main loop
int main()
{
- scePowerSetClockFrequency(333, 333, 166);
- SetupCallbacks();
- engine = JGECreate();
- //engine->Init(0);
- game = new GameApp(engine);
- game->Create();
- engine->SetApp(game);
- engine->Run();
-
- game->Destroy();
- delete game;
- game = NULL;
-
- JGERelease();
-
sceKernelExitGame();
-
return 0;
}