J :
* Create the subsystem for keybindings.
This commit is contained in:
+32
-32
@@ -1,32 +1,32 @@
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
#include "../include/JApp.h"
|
||||
#include "../include/JGE.h"
|
||||
|
||||
|
||||
JApp::JApp()
|
||||
{
|
||||
//mEngine = JGE::GetInstance();
|
||||
//mEngine->SetApp(this);
|
||||
}
|
||||
|
||||
|
||||
JApp::~JApp()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// JGE* JApp::GetJGE()
|
||||
// {
|
||||
// return mEngine;
|
||||
// }
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
#include "../include/JApp.h"
|
||||
#include "../include/JGE.h"
|
||||
|
||||
|
||||
JApp::JApp()
|
||||
{
|
||||
//mEngine = JGE::GetInstance();
|
||||
//mEngine->SetApp(this);
|
||||
}
|
||||
|
||||
|
||||
JApp::~JApp()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// JGE* JApp::GetJGE()
|
||||
// {
|
||||
// return mEngine;
|
||||
// }
|
||||
|
||||
+453
-475
@@ -1,475 +1,453 @@
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#include "../include/JGE.h"
|
||||
#include "../include/JApp.h"
|
||||
#include "../include/JRenderer.h"
|
||||
#include "../include/JSoundSystem.h"
|
||||
#include "../include/Vector2D.h"
|
||||
#include "../include/JResourceManager.h"
|
||||
#include "../include/JFileSystem.h"
|
||||
//#include "../include/JParticleSystem.h"
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
#if defined (WIN32) // WIN32 specific code
|
||||
|
||||
int JGE::GetTime(void)
|
||||
{
|
||||
return (int)GetTickCount();
|
||||
}
|
||||
|
||||
u8 JGE::GetAnalogX()
|
||||
{
|
||||
if (JGEGetKeyState(VK_LEFT)) return 0;
|
||||
if (JGEGetKeyState(VK_RIGHT)) return 0xff;
|
||||
|
||||
return 0x80;
|
||||
}
|
||||
|
||||
|
||||
u8 JGE::GetAnalogY()
|
||||
{
|
||||
if (JGEGetKeyState(VK_UP)) return 0;
|
||||
if (JGEGetKeyState(VK_DOWN)) return 0xff;
|
||||
|
||||
return 0x80;
|
||||
}
|
||||
|
||||
#elif defined (LINUX) // Unix specific code
|
||||
#include <sys/time.h>
|
||||
#include "png.h"
|
||||
#include "../Dependencies/include/fmod.h"
|
||||
|
||||
int JGE::GetTime(void)
|
||||
{
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
return tv.tv_sec * 1000 + tv.tv_usec / 1000;
|
||||
}
|
||||
|
||||
u8 JGE::GetAnalogX()
|
||||
{
|
||||
/* FIXME
|
||||
if (JGEGetKeyState(VK_LEFT)) return 0;
|
||||
if (JGEGetKeyState(VK_RIGHT)) return 0xff;
|
||||
*/
|
||||
return 0x80;
|
||||
}
|
||||
|
||||
|
||||
u8 JGE::GetAnalogY()
|
||||
{
|
||||
/* FIXME
|
||||
if (JGEGetKeyState(VK_UP)) return 0;
|
||||
if (JGEGetKeyState(VK_DOWN)) return 0xff;
|
||||
*/
|
||||
|
||||
return 0x80;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#if defined (WIN32) || defined (LINUX) // Non-PSP code
|
||||
|
||||
JGE::JGE()
|
||||
{
|
||||
mApp = NULL;
|
||||
|
||||
strcpy(mDebuggingMsg, "");
|
||||
mCurrentMusic = NULL;
|
||||
Init();
|
||||
|
||||
}
|
||||
|
||||
|
||||
JGE::~JGE()
|
||||
{
|
||||
JRenderer::Destroy();
|
||||
JFileSystem::Destroy();
|
||||
JSoundSystem::Destroy();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void JGE::Init()
|
||||
{
|
||||
mDone = false;
|
||||
mPaused = false;
|
||||
mCriticalAssert = false;
|
||||
|
||||
JRenderer::GetInstance();
|
||||
JFileSystem::GetInstance();
|
||||
JSoundSystem::GetInstance();
|
||||
}
|
||||
|
||||
void JGE::Run()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void JGE::SetDelta(int delta)
|
||||
{
|
||||
mDeltaTime = (float)delta / 1000.0f; // change to second
|
||||
}
|
||||
|
||||
float JGE::GetDelta()
|
||||
{
|
||||
return mDeltaTime;
|
||||
//return hge->Timer_GetDelta()*1000;
|
||||
}
|
||||
|
||||
|
||||
float JGE::GetFPS()
|
||||
{
|
||||
//return (float)hge->Timer_GetFPS();
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
|
||||
bool JGE::GetButtonState(u32 button)
|
||||
{
|
||||
//return (gButtons&button)==button;
|
||||
return JGEGetButtonState(button);
|
||||
}
|
||||
|
||||
|
||||
bool JGE::GetButtonClick(u32 button)
|
||||
{
|
||||
//return (gButtons&button)==button && (gOldButtons&button)!=button;
|
||||
return JGEGetButtonClick(button);
|
||||
}
|
||||
|
||||
u32 JGE::ReadButton()
|
||||
{
|
||||
return JGEReadKey();
|
||||
}
|
||||
|
||||
void JGE::ResetInput()
|
||||
{
|
||||
JGEResetInput();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
#else ///// PSP specified code
|
||||
|
||||
|
||||
|
||||
#include <queue>
|
||||
static queue<u32> gKeyBuffer;
|
||||
static const int gKeyCodeList[] = {
|
||||
PSP_CTRL_SELECT, // Select button.
|
||||
PSP_CTRL_START, // Start button.
|
||||
PSP_CTRL_UP, // Up D-Pad button.
|
||||
PSP_CTRL_RIGHT, // Right D-Pad button.
|
||||
PSP_CTRL_DOWN, // Down D-Pad button.
|
||||
PSP_CTRL_LEFT, // Left D-Pad button.
|
||||
PSP_CTRL_LTRIGGER, // Left trigger.
|
||||
PSP_CTRL_RTRIGGER, // Right trigger.
|
||||
PSP_CTRL_TRIANGLE, // Triangle button.
|
||||
PSP_CTRL_CIRCLE, // Circle button.
|
||||
PSP_CTRL_CROSS, // Cross button.
|
||||
PSP_CTRL_SQUARE, // Square button.
|
||||
PSP_CTRL_HOLD, // Hold button.
|
||||
/* Do not test keys we cannot get anyway, that's just wasted proc time
|
||||
PSP_CTRL_HOME, // Home button.
|
||||
PSP_CTRL_NOTE, // Music Note button.
|
||||
PSP_CTRL_SCREEN, // Screen button.
|
||||
PSP_CTRL_VOLUP, // Volume up button.
|
||||
PSP_CTRL_VOLDOWN, // Volume down button.
|
||||
PSP_CTRL_WLAN, // _UP Wlan switch up.
|
||||
PSP_CTRL_REMOTE, // Remote hold position.
|
||||
PSP_CTRL_DISC, // Disc present.
|
||||
PSP_CTRL_MS // Memory stick present.
|
||||
*/
|
||||
};
|
||||
static u32 gHolds = 0;
|
||||
|
||||
|
||||
JGE::JGE()
|
||||
{
|
||||
mApp = NULL;
|
||||
|
||||
Init();
|
||||
|
||||
|
||||
}
|
||||
|
||||
JGE::~JGE()
|
||||
{
|
||||
JRenderer::Destroy();
|
||||
JSoundSystem::Destroy();
|
||||
JFileSystem::Destroy();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void JGE::Init()
|
||||
{
|
||||
|
||||
#ifdef DEBUG_PRINT
|
||||
mDebug = true;
|
||||
#else
|
||||
mDebug = false;
|
||||
#endif
|
||||
|
||||
if (mDebug)
|
||||
pspDebugScreenInit(); // do this so that we can use pspDebugScreenPrintf
|
||||
|
||||
strcpy(mDebuggingMsg, "");
|
||||
|
||||
sceCtrlSetSamplingCycle(0);
|
||||
sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);
|
||||
|
||||
JRenderer::GetInstance();
|
||||
JFileSystem::GetInstance();
|
||||
JSoundSystem::GetInstance();
|
||||
|
||||
mDone = false;
|
||||
mPaused = false;
|
||||
mCriticalAssert = false;
|
||||
mOldButtons = mVeryOldButtons = 0;
|
||||
|
||||
mTickFrequency = sceRtcGetTickResolution();
|
||||
sceRtcGetCurrentTick(&mLastTime);
|
||||
}
|
||||
|
||||
|
||||
// returns number of milliseconds since game started
|
||||
int JGE::GetTime(void)
|
||||
{
|
||||
|
||||
u64 curr;
|
||||
sceRtcGetCurrentTick(&curr);
|
||||
return (int)((curr * 1000) / mTickFrequency);
|
||||
}
|
||||
|
||||
|
||||
float JGE::GetDelta()
|
||||
{
|
||||
return mDelta;
|
||||
}
|
||||
|
||||
|
||||
float JGE::GetFPS()
|
||||
{
|
||||
return 1.0f / mDelta;
|
||||
}
|
||||
|
||||
|
||||
bool JGE::GetButtonState(u32 button)
|
||||
{
|
||||
return (mCtrlPad.Buttons&button)==button;
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool JGE::GetButtonClick(u32 button)
|
||||
{
|
||||
return (mCtrlPad.Buttons&button)==button && (mVeryOldButtons&button)!=button;
|
||||
}
|
||||
|
||||
u32 JGE::ReadButton()
|
||||
{
|
||||
if (gKeyBuffer.empty()) return 0;
|
||||
u32 val = gKeyBuffer.front();
|
||||
gHolds &= ~val;
|
||||
gKeyBuffer.pop();
|
||||
return val;
|
||||
}
|
||||
|
||||
void JGE::ResetInput()
|
||||
{
|
||||
while (!gKeyBuffer.empty()) gKeyBuffer.pop();
|
||||
}
|
||||
|
||||
u8 JGE::GetAnalogX()
|
||||
{
|
||||
return mCtrlPad.Lx;
|
||||
}
|
||||
|
||||
|
||||
u8 JGE::GetAnalogY()
|
||||
{
|
||||
return mCtrlPad.Ly;
|
||||
}
|
||||
|
||||
#define REPEAT_DELAY 0.5
|
||||
#define REPEAT_FREQUENCY 7
|
||||
void JGE::Run()
|
||||
{
|
||||
u64 curr;
|
||||
long long int nextInput = 0;
|
||||
|
||||
const u32 ticksPerSecond = sceRtcGetTickResolution();
|
||||
const u64 repeatDelay = REPEAT_DELAY * ticksPerSecond;
|
||||
const u64 repeatPeriod = ticksPerSecond / REPEAT_FREQUENCY;
|
||||
|
||||
while (!mDone)
|
||||
{
|
||||
if (!mPaused)
|
||||
{
|
||||
sceRtcGetCurrentTick(&curr);
|
||||
|
||||
mDelta = (curr-mLastTime) / (float)mTickFrequency;// * 1000.0f;
|
||||
|
||||
sceCtrlPeekBufferPositive(&mCtrlPad, 1);
|
||||
for (signed int i = sizeof(gKeyCodeList)/sizeof(gKeyCodeList[0]) - 1; i >= 0; --i)
|
||||
{
|
||||
if (gKeyCodeList[i] & mCtrlPad.Buttons)
|
||||
{
|
||||
if (!(gKeyCodeList[i] & mOldButtons))
|
||||
{
|
||||
if (!(gHolds & gKeyCodeList[i])) gKeyBuffer.push(gKeyCodeList[i]);
|
||||
nextInput = repeatDelay;
|
||||
gHolds |= gKeyCodeList[i];
|
||||
}
|
||||
else if (nextInput < 0)
|
||||
{
|
||||
if (!(gHolds & gKeyCodeList[i])) gKeyBuffer.push(gKeyCodeList[i]);
|
||||
nextInput = repeatPeriod;
|
||||
gHolds |= gKeyCodeList[i];
|
||||
}
|
||||
}
|
||||
if (!(gKeyCodeList[i] & mCtrlPad.Buttons))
|
||||
if (gKeyCodeList[i] & mOldButtons)
|
||||
gHolds &= ~gKeyCodeList[i];
|
||||
}
|
||||
mOldButtons = mCtrlPad.Buttons;
|
||||
|
||||
nextInput -= (curr - mLastTime);
|
||||
mLastTime = curr;
|
||||
|
||||
Update();
|
||||
Render();
|
||||
|
||||
if (mDebug)
|
||||
{
|
||||
if (strlen(mDebuggingMsg)>0)
|
||||
{
|
||||
pspDebugScreenSetXY(0, 0);
|
||||
pspDebugScreenPrintf(mDebuggingMsg);
|
||||
}
|
||||
}
|
||||
mVeryOldButtons = mCtrlPad.Buttons;
|
||||
}
|
||||
else
|
||||
{
|
||||
sceKernelDelayThread(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif ///// PSP specified code
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
JGE* JGE::mInstance = NULL;
|
||||
//static int gCount = 0;
|
||||
|
||||
JGE* JGE::GetInstance()
|
||||
{
|
||||
if (mInstance == NULL)
|
||||
{
|
||||
mInstance = new JGE();
|
||||
}
|
||||
|
||||
//gCount++;
|
||||
return mInstance;
|
||||
}
|
||||
|
||||
|
||||
void JGE::Destroy()
|
||||
{
|
||||
//gCount--;
|
||||
if (mInstance)
|
||||
{
|
||||
delete mInstance;
|
||||
mInstance = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void JGE::SetApp(JApp *app)
|
||||
{
|
||||
mApp = app;
|
||||
}
|
||||
|
||||
|
||||
void JGE::Update()
|
||||
{
|
||||
if (mApp != NULL)
|
||||
mApp->Update();
|
||||
}
|
||||
|
||||
void JGE::Render()
|
||||
{
|
||||
JRenderer* renderer = JRenderer::GetInstance();
|
||||
|
||||
renderer->BeginScene();
|
||||
|
||||
if (mApp != NULL)
|
||||
mApp->Render();
|
||||
|
||||
renderer->EndScene();
|
||||
}
|
||||
|
||||
|
||||
void JGE::End()
|
||||
{
|
||||
mDone = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void JGE::printf(const char *format, ...)
|
||||
{
|
||||
va_list list;
|
||||
|
||||
va_start(list, format);
|
||||
vsprintf(mDebuggingMsg, format, list);
|
||||
va_end(list);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void JGE::Pause()
|
||||
{
|
||||
if (mPaused) return;
|
||||
|
||||
mPaused = true;
|
||||
if (mApp != NULL)
|
||||
mApp->Pause();
|
||||
}
|
||||
|
||||
|
||||
void JGE::Resume()
|
||||
{
|
||||
if (mPaused)
|
||||
{
|
||||
mPaused = false;
|
||||
if (mApp != NULL)
|
||||
mApp->Resume();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void JGE::Assert(const char *filename, long lineNumber)
|
||||
{
|
||||
mAssertFile = filename;
|
||||
mAssertLine = lineNumber;
|
||||
mCriticalAssert = true;
|
||||
|
||||
|
||||
}
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
|
||||
#include "../include/JGE.h"
|
||||
#include "../include/JApp.h"
|
||||
#include "../include/JRenderer.h"
|
||||
#include "../include/JSoundSystem.h"
|
||||
#include "../include/Vector2D.h"
|
||||
#include "../include/JResourceManager.h"
|
||||
#include "../include/JFileSystem.h"
|
||||
//#include "../include/JParticleSystem.h"
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
#if defined (WIN32) // WIN32 specific code
|
||||
#include "../../Dependencies/include/png.h"
|
||||
#include "../../Dependencies/include/fmod.h"
|
||||
|
||||
u8 JGE::GetAnalogX()
|
||||
{
|
||||
if (JGEGetKeyState(VK_LEFT)) return 0;
|
||||
if (JGEGetKeyState(VK_RIGHT)) return 0xff;
|
||||
|
||||
return 0x80;
|
||||
}
|
||||
|
||||
|
||||
u8 JGE::GetAnalogY()
|
||||
{
|
||||
if (JGEGetKeyState(VK_UP)) return 0;
|
||||
if (JGEGetKeyState(VK_DOWN)) return 0xff;
|
||||
|
||||
return 0x80;
|
||||
}
|
||||
|
||||
#elif defined (LINUX) // Unix specific code
|
||||
#include <sys/time.h>
|
||||
#include "png.h"
|
||||
#include "../Dependencies/include/fmod.h"
|
||||
|
||||
|
||||
u8 JGE::GetAnalogX()
|
||||
{
|
||||
/* FIXME
|
||||
if (JGEGetKeyState(VK_LEFT)) return 0;
|
||||
if (JGEGetKeyState(VK_RIGHT)) return 0xff;
|
||||
*/
|
||||
return 0x80;
|
||||
}
|
||||
|
||||
|
||||
u8 JGE::GetAnalogY()
|
||||
{
|
||||
/* FIXME
|
||||
if (JGEGetKeyState(VK_UP)) return 0;
|
||||
if (JGEGetKeyState(VK_DOWN)) return 0xff;
|
||||
*/
|
||||
|
||||
return 0x80;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
static map<JButton, float> holds;
|
||||
static map<JButton, float> oldHolds;
|
||||
#define REPEAT_DELAY 0.5
|
||||
#define REPEAT_PERIOD 0.07
|
||||
|
||||
void JGE::PressKey(const LocalKeySym sym)
|
||||
{
|
||||
const pair<keycodes_it, keycodes_it> rng = keyBinds.equal_range(sym);
|
||||
for (keycodes_it it = rng.first; it != rng.second; ++it)
|
||||
keyBuffer.push(it->second);
|
||||
}
|
||||
void JGE::PressKey(const JButton sym)
|
||||
{
|
||||
keyBuffer.push(sym);
|
||||
}
|
||||
void JGE::HoldKey(const LocalKeySym sym)
|
||||
{
|
||||
const pair<keycodes_it, keycodes_it> rng = keyBinds.equal_range(sym);
|
||||
for (keycodes_it it = rng.first; it != rng.second; ++it)
|
||||
{
|
||||
keyBuffer.push(it->second);
|
||||
if (holds.end() == holds.find(it->second))
|
||||
holds[it->second] = REPEAT_DELAY;
|
||||
}
|
||||
}
|
||||
void JGE::HoldKey_NoRepeat(const LocalKeySym sym)
|
||||
{
|
||||
const pair<keycodes_it, keycodes_it> rng = keyBinds.equal_range(sym);
|
||||
for (keycodes_it it = rng.first; it != rng.second; ++it)
|
||||
{
|
||||
keyBuffer.push(it->second);
|
||||
if (holds.end() == holds.find(it->second))
|
||||
holds[it->second] = NAN;
|
||||
}
|
||||
}
|
||||
void JGE::HoldKey(const JButton sym)
|
||||
{
|
||||
keyBuffer.push(sym);
|
||||
if (holds.end() == holds.find(sym)) holds[sym] = REPEAT_DELAY;
|
||||
}
|
||||
void JGE::HoldKey_NoRepeat(const JButton sym)
|
||||
{
|
||||
keyBuffer.push(sym);
|
||||
if (holds.end() == holds.find(sym)) holds[sym] = NAN;
|
||||
}
|
||||
void JGE::ReleaseKey(const LocalKeySym sym)
|
||||
{
|
||||
const pair<keycodes_it, keycodes_it> rng = keyBinds.equal_range(sym);
|
||||
for (keycodes_it it = rng.first; it != rng.second; ++it)
|
||||
holds.erase(it->second);
|
||||
}
|
||||
void JGE::ReleaseKey(const JButton sym)
|
||||
{
|
||||
holds.erase(sym);
|
||||
}
|
||||
void JGE::Update(float dt)
|
||||
{
|
||||
for (map<JButton, float>::iterator it = holds.begin(); it != holds.end(); ++it)
|
||||
{
|
||||
if (it->second < 0) { keyBuffer.push(it->first); it->second = REPEAT_PERIOD; }
|
||||
it->second -= dt;
|
||||
}
|
||||
if (mApp != NULL) mApp->Update();
|
||||
oldHolds = holds;
|
||||
}
|
||||
|
||||
|
||||
bool JGE::GetButtonState(JButton button)
|
||||
{
|
||||
return (holds.end() != holds.find(button));
|
||||
}
|
||||
|
||||
|
||||
bool JGE::GetButtonClick(JButton button)
|
||||
{
|
||||
cout << "HOLDS : ";
|
||||
for (map<JButton, float>::iterator it = holds.begin(); it != holds.end(); ++it)
|
||||
cout << it->first << " ";
|
||||
cout << endl << "OLDHOLDS : ";
|
||||
for (map<JButton, float>::iterator it = oldHolds.begin(); it != oldHolds.end(); ++it)
|
||||
cout << it->first << " ";
|
||||
cout << endl;
|
||||
return ((holds.end() != holds.find(button)) && (oldHolds.end() == oldHolds.find(button)));
|
||||
}
|
||||
|
||||
|
||||
JButton JGE::ReadButton()
|
||||
{
|
||||
if (keyBuffer.empty()) return JGE_BTN_NONE;
|
||||
JButton val = keyBuffer.front();
|
||||
keyBuffer.pop();
|
||||
return val;
|
||||
}
|
||||
|
||||
u32 JGE::BindKey(LocalKeySym sym, JButton button)
|
||||
{
|
||||
keyBinds.insert(make_pair(sym, button));
|
||||
return keyBinds.size();
|
||||
}
|
||||
|
||||
u32 JGE::UnbindKey(LocalKeySym sym, JButton button)
|
||||
{
|
||||
for (keycodes_it it = keyBinds.begin(); it != keyBinds.end(); )
|
||||
if (sym == it->first && button == it->second)
|
||||
{
|
||||
keycodes_it er = it;
|
||||
++it;
|
||||
keyBinds.erase(er);
|
||||
}
|
||||
else ++it;
|
||||
return keyBinds.size();
|
||||
}
|
||||
|
||||
u32 JGE::UnbindKey(LocalKeySym sym)
|
||||
{
|
||||
pair<keycodes_it, keycodes_it> rng = keyBinds.equal_range(sym);
|
||||
keyBinds.erase(rng.first, rng.second);
|
||||
return keyBinds.size();
|
||||
}
|
||||
|
||||
void JGE::ClearBindings()
|
||||
{
|
||||
keyBinds.clear();
|
||||
}
|
||||
|
||||
void JGE::ResetBindings()
|
||||
{
|
||||
keyBinds.clear();
|
||||
JGECreateDefaultBindings();
|
||||
}
|
||||
|
||||
|
||||
JGE::keybindings_it JGE::KeyBindings_begin() { return keyBinds.begin(); }
|
||||
JGE::keybindings_it JGE::KeyBindings_end() { return keyBinds.end(); }
|
||||
|
||||
void JGE::ResetInput()
|
||||
{
|
||||
while (!keyBuffer.empty()) keyBuffer.pop();
|
||||
holds.clear();
|
||||
}
|
||||
|
||||
|
||||
JGE::JGE()
|
||||
{
|
||||
mApp = NULL;
|
||||
#if defined (WIN32) || defined (LINUX)
|
||||
strcpy(mDebuggingMsg, "");
|
||||
mCurrentMusic = NULL;
|
||||
#endif
|
||||
Init();
|
||||
}
|
||||
|
||||
|
||||
JGE::~JGE()
|
||||
{
|
||||
JRenderer::Destroy();
|
||||
JFileSystem::Destroy();
|
||||
JSoundSystem::Destroy();
|
||||
}
|
||||
|
||||
|
||||
|
||||
#if defined (WIN32) || defined (LINUX) // Non-PSP code
|
||||
|
||||
void JGE::Init()
|
||||
{
|
||||
mDone = false;
|
||||
mPaused = false;
|
||||
mCriticalAssert = false;
|
||||
JRenderer::GetInstance();
|
||||
JFileSystem::GetInstance();
|
||||
JSoundSystem::GetInstance();
|
||||
}
|
||||
|
||||
void JGE::SetDelta(float delta)
|
||||
{
|
||||
mDeltaTime = (float)delta;
|
||||
}
|
||||
|
||||
float JGE::GetDelta()
|
||||
{
|
||||
return mDeltaTime;
|
||||
}
|
||||
|
||||
float JGE::GetFPS()
|
||||
{
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
#else ///// PSP specific code
|
||||
|
||||
|
||||
void JGE::Init()
|
||||
{
|
||||
#ifdef DEBUG_PRINT
|
||||
mDebug = true;
|
||||
#else
|
||||
mDebug = false;
|
||||
#endif
|
||||
|
||||
#if defined (WIN32) || defined (LINUX)
|
||||
tickFrequency = 120;
|
||||
#else
|
||||
tickFrequency = sceRtcGetTickResolution();
|
||||
#endif
|
||||
|
||||
if (mDebug)
|
||||
pspDebugScreenInit(); // do this so that we can use pspDebugScreenPrintf
|
||||
|
||||
strcpy(mDebuggingMsg, "");
|
||||
|
||||
sceCtrlSetSamplingCycle(0);
|
||||
sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);
|
||||
|
||||
JRenderer::GetInstance();
|
||||
JFileSystem::GetInstance();
|
||||
JSoundSystem::GetInstance();
|
||||
|
||||
mDone = false;
|
||||
mPaused = false;
|
||||
mCriticalAssert = false;
|
||||
}
|
||||
|
||||
float JGE::GetDelta()
|
||||
{
|
||||
return mDelta;
|
||||
}
|
||||
|
||||
|
||||
float JGE::GetFPS()
|
||||
{
|
||||
return 1.0f / mDelta;
|
||||
}
|
||||
|
||||
u8 JGE::GetAnalogX()
|
||||
{
|
||||
return JGEGetAnalogX();
|
||||
}
|
||||
|
||||
u8 JGE::GetAnalogY()
|
||||
{
|
||||
return JGEGetAnalogY();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
bool JGE::GetButtonState(u32 button)
|
||||
{
|
||||
return (mCtrlPad.Buttons&button)==button;
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool JGE::GetButtonClick(u32 button)
|
||||
{
|
||||
return (mCtrlPad.Buttons&button)==button && (mVeryOldButtons&button)!=button;
|
||||
}
|
||||
|
||||
u32 JGE::ReadButton()
|
||||
{
|
||||
if (gKeyBuffer.empty()) return 0;
|
||||
u32 val = gKeyBuffer.front();
|
||||
gHolds &= ~val;
|
||||
gKeyBuffer.pop();
|
||||
return val;
|
||||
}
|
||||
|
||||
void JGE::ResetInput()
|
||||
{
|
||||
while (!gKeyBuffer.empty()) gKeyBuffer.pop();
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
#endif ///// PSP specific code
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
JGE* JGE::mInstance = NULL;
|
||||
//static int gCount = 0;
|
||||
|
||||
// returns number of milliseconds since game started
|
||||
int JGE::GetTime()
|
||||
{
|
||||
return JGEGetTime();
|
||||
}
|
||||
|
||||
|
||||
JGE* JGE::GetInstance()
|
||||
{
|
||||
if (mInstance == NULL)
|
||||
{
|
||||
mInstance = new JGE();
|
||||
}
|
||||
|
||||
//gCount++;
|
||||
return mInstance;
|
||||
}
|
||||
|
||||
|
||||
void JGE::Destroy()
|
||||
{
|
||||
//gCount--;
|
||||
if (mInstance)
|
||||
{
|
||||
delete mInstance;
|
||||
mInstance = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void JGE::SetApp(JApp *app)
|
||||
{
|
||||
mApp = app;
|
||||
}
|
||||
|
||||
void JGE::Render()
|
||||
{
|
||||
JRenderer* renderer = JRenderer::GetInstance();
|
||||
|
||||
renderer->BeginScene();
|
||||
if (mApp != NULL) mApp->Render();
|
||||
renderer->EndScene();
|
||||
}
|
||||
|
||||
|
||||
void JGE::End()
|
||||
{
|
||||
mDone = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void JGE::printf(const char *format, ...)
|
||||
{
|
||||
va_list list;
|
||||
|
||||
va_start(list, format);
|
||||
vsprintf(mDebuggingMsg, format, list);
|
||||
va_end(list);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void JGE::Pause()
|
||||
{
|
||||
if (mPaused) return;
|
||||
|
||||
mPaused = true;
|
||||
if (mApp != NULL)
|
||||
mApp->Pause();
|
||||
}
|
||||
|
||||
|
||||
void JGE::Resume()
|
||||
{
|
||||
if (mPaused)
|
||||
{
|
||||
mPaused = false;
|
||||
if (mApp != NULL)
|
||||
mApp->Resume();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void JGE::Assert(const char *filename, long lineNumber)
|
||||
{
|
||||
mAssertFile = filename;
|
||||
mAssertLine = lineNumber;
|
||||
mCriticalAssert = true;
|
||||
|
||||
|
||||
}
|
||||
|
||||
std::queue<JButton> JGE::keyBuffer;
|
||||
std::multimap<LocalKeySym, JButton> JGE::keyBinds;
|
||||
|
||||
+8
-8
@@ -75,7 +75,7 @@ JGuiController::JGuiController(int id, JGuiListener* listener) : mId(id), mListe
|
||||
mCursorY = SCREEN_HEIGHT/2;
|
||||
mShowCursor = false;
|
||||
|
||||
mActionButton = PSP_CTRL_CIRCLE;
|
||||
mActionButton = JGE_BTN_OK;
|
||||
|
||||
mStyle = JGUI_STYLE_WRAPPING;
|
||||
|
||||
@@ -98,7 +98,7 @@ void JGuiController::Render()
|
||||
if (mObjects[i]!=NULL)
|
||||
mObjects[i]->Render();
|
||||
}
|
||||
bool JGuiController::CheckUserInput(u32 key){
|
||||
bool JGuiController::CheckUserInput(JButton key){
|
||||
|
||||
if (key == mActionButton)
|
||||
{
|
||||
@@ -109,7 +109,7 @@ bool JGuiController::CheckUserInput(u32 key){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if ((PSP_CTRL_LEFT == key) || (PSP_CTRL_UP == key)) // || mEngine->GetAnalogY() < 64 || mEngine->GetAnalogX() < 64)
|
||||
else if ((JGE_BTN_LEFT == key) || (JGE_BTN_UP == key)) // || mEngine->GetAnalogY() < 64 || mEngine->GetAnalogX() < 64)
|
||||
{
|
||||
int n = mCurr;
|
||||
n--;
|
||||
@@ -121,14 +121,14 @@ bool JGuiController::CheckUserInput(u32 key){
|
||||
n = 0;
|
||||
}
|
||||
|
||||
if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(PSP_CTRL_UP))
|
||||
if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(JGE_BTN_UP))
|
||||
{
|
||||
mCurr = n;
|
||||
mObjects[mCurr]->Entering();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if ((PSP_CTRL_RIGHT == key) || (PSP_CTRL_DOWN == key)) // || mEngine->GetAnalogY()>192 || mEngine->GetAnalogX()>192)
|
||||
else if ((JGE_BTN_RIGHT == key) || (JGE_BTN_DOWN == key)) // || mEngine->GetAnalogY()>192 || mEngine->GetAnalogX()>192)
|
||||
{
|
||||
int n = mCurr;
|
||||
n++;
|
||||
@@ -140,7 +140,7 @@ bool JGuiController::CheckUserInput(u32 key){
|
||||
n = mCount-1;
|
||||
}
|
||||
|
||||
if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(PSP_CTRL_DOWN))
|
||||
if (n != mCurr && mObjects[mCurr] != NULL && mObjects[mCurr]->Leaving(JGE_BTN_DOWN))
|
||||
{
|
||||
mCurr = n;
|
||||
mObjects[mCurr]->Entering();
|
||||
@@ -155,7 +155,7 @@ void JGuiController::Update(float dt)
|
||||
if (mObjects[i]!=NULL)
|
||||
mObjects[i]->Update(dt);
|
||||
|
||||
u32 key = mEngine->ReadButton();
|
||||
JButton key = mEngine->ReadButton();
|
||||
CheckUserInput(key);
|
||||
}
|
||||
|
||||
@@ -200,7 +200,7 @@ void JGuiController::Remove(JGuiObject* ctrl)
|
||||
}
|
||||
|
||||
|
||||
void JGuiController::SetActionButton(u32 button) { mActionButton = button; }
|
||||
void JGuiController::SetActionButton(JButton button) { mActionButton = button; }
|
||||
void JGuiController::SetStyle(int style) { mStyle = style; }
|
||||
void JGuiController::SetCursor(JSprite* cursor) { mCursor = cursor; }
|
||||
bool JGuiController::IsActive() { return mActive; }
|
||||
|
||||
+55
-123
@@ -5,7 +5,8 @@
|
||||
#include <X11/XKBlib.h>
|
||||
#include <sys/time.h>
|
||||
#include <queue>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
#include "../../JGE/include/JGE.h"
|
||||
#include "../../JGE/include/JTypes.h"
|
||||
@@ -29,9 +30,9 @@ struct window_state_t
|
||||
|
||||
enum
|
||||
{
|
||||
_NET_WM_STATE_REMOVE =0,
|
||||
_NET_WM_STATE_ADD = 1,
|
||||
_NET_WM_STATE_TOGGLE =2
|
||||
_NET_WM_STATE_REMOVE =0,
|
||||
_NET_WM_STATE_ADD = 1,
|
||||
_NET_WM_STATE_TOGGLE =2
|
||||
};
|
||||
|
||||
|
||||
@@ -50,39 +51,35 @@ Display* gXDisplay = NULL;
|
||||
Window gXWindow = NULL;
|
||||
GLXWindow glxWin = NULL;
|
||||
|
||||
static queue< pair<KeySym, u32> > gKeyBuffer;
|
||||
static u32 gControllerState = 0;
|
||||
static u32 gPrevControllerState = 0;
|
||||
static u32 gHolds = 0;
|
||||
static std::multiset<JButton> gControllerState;
|
||||
static std::multiset<JButton> gPrevControllerState;
|
||||
|
||||
static const struct { KeySym keysym; u32 pspCode; } gDefaultBindings[] =
|
||||
static const struct { LocalKeySym keysym; JButton keycode; } gDefaultBindings[] =
|
||||
{
|
||||
{ XK_Escape, PSP_CTRL_START },
|
||||
{ XK_Return, PSP_CTRL_START },
|
||||
{ XK_BackSpace, PSP_CTRL_SELECT },
|
||||
{ XK_Up, PSP_CTRL_UP },
|
||||
{ XK_KP_Up, PSP_CTRL_UP },
|
||||
{ XK_Down, PSP_CTRL_DOWN },
|
||||
{ XK_KP_Down, PSP_CTRL_DOWN },
|
||||
{ XK_Left, PSP_CTRL_LEFT },
|
||||
{ XK_KP_Left, PSP_CTRL_LEFT },
|
||||
{ XK_Right, PSP_CTRL_RIGHT },
|
||||
{ XK_KP_Right, PSP_CTRL_RIGHT },
|
||||
{ XK_space, PSP_CTRL_CIRCLE },
|
||||
{ XK_Control_L, PSP_CTRL_CIRCLE },
|
||||
{ XK_Control_R, PSP_CTRL_CIRCLE },
|
||||
{ XK_Tab, PSP_CTRL_TRIANGLE },
|
||||
{ XK_Alt_L, PSP_CTRL_SQUARE },
|
||||
{ XK_Caps_Lock, PSP_CTRL_CROSS },
|
||||
{ XK_Shift_L, PSP_CTRL_LTRIGGER },
|
||||
{ XK_Shift_R, PSP_CTRL_RTRIGGER },
|
||||
{ XK_F1, PSP_CTRL_HOME },
|
||||
{ XK_F2, PSP_CTRL_HOLD },
|
||||
{ XK_F3, PSP_CTRL_NOTE }
|
||||
{ XK_Escape, JGE_BTN_MENU },
|
||||
{ XK_Return, JGE_BTN_MENU },
|
||||
{ XK_BackSpace, JGE_BTN_CTRL },
|
||||
{ XK_Up, JGE_BTN_UP },
|
||||
{ XK_KP_Up, JGE_BTN_UP },
|
||||
{ XK_Down, JGE_BTN_DOWN },
|
||||
{ XK_KP_Down, JGE_BTN_DOWN },
|
||||
{ XK_Left, JGE_BTN_LEFT },
|
||||
{ XK_KP_Left, JGE_BTN_LEFT },
|
||||
{ XK_Right, JGE_BTN_RIGHT },
|
||||
{ XK_KP_Right, JGE_BTN_RIGHT },
|
||||
{ XK_space, JGE_BTN_OK },
|
||||
{ XK_Control_L, JGE_BTN_OK },
|
||||
{ XK_Control_R, JGE_BTN_OK },
|
||||
{ XK_Tab, JGE_BTN_CANCEL },
|
||||
{ XK_Alt_L, JGE_BTN_PRI },
|
||||
{ XK_Caps_Lock, JGE_BTN_SEC },
|
||||
{ XK_Shift_L, JGE_BTN_PREV },
|
||||
{ XK_Shift_R, JGE_BTN_NEXT },
|
||||
{ XK_F1, JGE_BTN_QUIT },
|
||||
{ XK_F2, JGE_BTN_POWER },
|
||||
{ XK_F3, JGE_BTN_SOUND }
|
||||
};
|
||||
|
||||
static vector< pair<KeySym, u32> > gKeyCodes;
|
||||
|
||||
GLvoid ReSizeGLScene(GLsizei width, GLsizei height) // Resize The GL Window
|
||||
{
|
||||
|
||||
@@ -210,9 +207,6 @@ BOOL CreateGLWindow(char* title, int width, int height, int bits __attribute__((
|
||||
return false;
|
||||
}
|
||||
|
||||
for (signed int i = sizeof(gDefaultBindings)/sizeof(gDefaultBindings[0]) - 1; i >= 0; --i)
|
||||
gKeyCodes.push_back(make_pair(gDefaultBindings[i].keysym, gDefaultBindings[i].pspCode));
|
||||
|
||||
// Get a suitable framebuffer config
|
||||
int numReturned;
|
||||
GLXFBConfig *fbConfigs = glXChooseFBConfig(gXDisplay, DefaultScreen(gXDisplay), doubleBufferAttributes, &numReturned);
|
||||
@@ -266,83 +260,37 @@ BOOL CreateGLWindow(char* title, int width, int height, int bits __attribute__((
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void JGEControl()
|
||||
void Update(float dt)
|
||||
{
|
||||
gPrevControllerState = gControllerState;
|
||||
}
|
||||
|
||||
void Update(int dt)
|
||||
{
|
||||
g_engine->SetDelta(dt);
|
||||
g_engine->Update();
|
||||
JGEControl();
|
||||
g_engine->Update(dt);
|
||||
}
|
||||
|
||||
|
||||
int DrawGLScene(void) // Here's Where We Do All The Drawing
|
||||
int DrawGLScene(void)
|
||||
{
|
||||
|
||||
// glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
|
||||
// glLoadIdentity (); // Reset The Modelview Matrix
|
||||
|
||||
//if (g_app)
|
||||
// g_app->Render();
|
||||
g_engine->Render();
|
||||
|
||||
// glFlush ();
|
||||
|
||||
return true; // Everything Went OK
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool JGEGetButtonState(u32 button)
|
||||
template <typename T>
|
||||
static inline bool include(multiset<T> set, T button)
|
||||
{
|
||||
return gControllerState & button;
|
||||
return set.end() != set.find(button);
|
||||
}
|
||||
|
||||
bool JGEGetButtonClick(u32 button)
|
||||
void JGECreateDefaultBindings()
|
||||
{
|
||||
return ((gControllerState & button) && (!(gPrevControllerState & button)));
|
||||
for (signed int i = sizeof(gDefaultBindings)/sizeof(gDefaultBindings[0]) - 1; i >= 0; --i)
|
||||
g_engine->BindKey(gDefaultBindings[i].keysym, gDefaultBindings[i].keycode);
|
||||
}
|
||||
|
||||
bool JGEGetKeyState(int key __attribute__((unused)))
|
||||
int JGEGetTime()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
u32 JGEReadKey()
|
||||
{
|
||||
if (gKeyBuffer.empty()) return 0;
|
||||
u32 val = gKeyBuffer.front().second;
|
||||
gHolds &= ~val;
|
||||
gKeyBuffer.pop();
|
||||
return val;
|
||||
}
|
||||
|
||||
u32 JGEReadLocalKey()
|
||||
{
|
||||
if (gKeyBuffer.empty()) return 0;
|
||||
pair <KeyCode, u32> val = gKeyBuffer.front();
|
||||
gHolds &= ~val.second;
|
||||
gKeyBuffer.pop();
|
||||
return val.first;
|
||||
}
|
||||
|
||||
void JGEBindLocalKey(u32 localKey, u32 pspSymbol)
|
||||
{
|
||||
}
|
||||
|
||||
void JGEResetInput()
|
||||
{
|
||||
while (!gKeyBuffer.empty()) gKeyBuffer.pop();
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
return tv.tv_sec * 1000 + tv.tv_usec / 1000;
|
||||
}
|
||||
|
||||
void reshapeFunc(int width, int height)
|
||||
@@ -420,6 +368,8 @@ int main(int argc, char* argv[])
|
||||
XSelectInput(gXDisplay, gXWindow, KeyPressMask | KeyReleaseMask | StructureNotifyMask);
|
||||
XkbSetDetectableAutoRepeat(gXDisplay, true, NULL);
|
||||
|
||||
JGECreateDefaultBindings();
|
||||
|
||||
static uint64_t tickCount;
|
||||
while (!g_engine->IsDone())
|
||||
{
|
||||
@@ -430,7 +380,7 @@ int main(int argc, char* argv[])
|
||||
tickCount = tv.tv_sec * 1000 + tv.tv_usec / 1000;
|
||||
dt = (tickCount - lastTickCount);
|
||||
lastTickCount = tickCount;
|
||||
Update(dt); // Update frame
|
||||
Update((float)dt / 1000.0f); // Update frame
|
||||
|
||||
DrawGLScene(); // Draw The Scene
|
||||
glXSwapBuffers(gXDisplay, glxWin);
|
||||
@@ -438,33 +388,15 @@ int main(int argc, char* argv[])
|
||||
switch (event.type)
|
||||
{
|
||||
case KeyPress:
|
||||
{
|
||||
KeySym sym = XKeycodeToKeysym(gXDisplay, event.xkey.keycode, 1);
|
||||
if (XK_F == sym)
|
||||
fullscreen();
|
||||
for (vector< pair<KeySym, u32> >::iterator it = gKeyCodes.begin(); it != gKeyCodes.end(); ++it)
|
||||
if (sym == it->first)
|
||||
{
|
||||
if (!(gHolds & it->second))
|
||||
gKeyBuffer.push(*it);
|
||||
gControllerState |= it->second;
|
||||
gHolds |= it->second;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
{
|
||||
const KeySym sym = XKeycodeToKeysym(gXDisplay, event.xkey.keycode, 1);
|
||||
if (sym == XK_F) fullscreen();
|
||||
g_engine->HoldKey_NoRepeat(sym);
|
||||
}
|
||||
break;
|
||||
case KeyRelease:
|
||||
{
|
||||
KeySym sym = XKeycodeToKeysym(gXDisplay, event.xkey.keycode, 1);
|
||||
for (vector< pair<KeySym, u32> >::iterator it = gKeyCodes.begin(); it != gKeyCodes.end(); ++it)
|
||||
if (sym == it->first)
|
||||
{
|
||||
gControllerState &= ~it->second;
|
||||
gHolds &= ~it->second;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
g_engine->ReleaseKey(XKeycodeToKeysym(gXDisplay, event.xkey.keycode, 1));
|
||||
break;
|
||||
case ConfigureNotify:
|
||||
ReSizeGLScene(event.xconfigure.width, event.xconfigure.height);
|
||||
break;
|
||||
|
||||
+410
-301
@@ -1,301 +1,410 @@
|
||||
#include <pspkernel.h>
|
||||
#include <pspdisplay.h>
|
||||
#include <pspdebug.h>
|
||||
#include <psppower.h>
|
||||
#include <pspsdk.h>
|
||||
#include <pspaudiocodec.h>
|
||||
#include <pspaudio.h>
|
||||
#include <pspaudiolib.h>
|
||||
#include <pspmpeg.h>
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <pspctrl.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
#include "../../JGE/include/JGE.h"
|
||||
#include "../../JGE/include/JApp.h"
|
||||
#include "../../JGE/include/JGameLauncher.h"
|
||||
#include "../../JGE/include/JRenderer.h"
|
||||
|
||||
|
||||
#ifndef JGEApp_Title
|
||||
#define JGEApp_Title "JGE++"
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef DEVHOOK
|
||||
PSP_MODULE_INFO(JGEApp_Title, 0, 1, 1);
|
||||
PSP_MAIN_THREAD_ATTR(PSP_THREAD_ATTR_USER);
|
||||
//256 is not enough for the network to correctly start,
|
||||
// let's find an appropriate value the day JGE has working network
|
||||
PSP_HEAP_SIZE_KB(-256);
|
||||
|
||||
#else
|
||||
|
||||
PSP_MODULE_INFO(JGEApp_Title, 0x1000, 1, 1);
|
||||
PSP_MAIN_THREAD_ATTR(0);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
int mikModThreadID = -1;
|
||||
bool done = false;
|
||||
|
||||
JApp *game = NULL;
|
||||
JGE *engine = NULL;
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
// Exit callback
|
||||
int exit_callback(int arg1, int arg2, void *common)
|
||||
{
|
||||
if (engine != NULL)
|
||||
engine->End();
|
||||
|
||||
sceKernelExitGame();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
// Power Callback
|
||||
int power_callback(int unknown, int pwrflags, void *common)
|
||||
{
|
||||
if ((pwrflags & (PSP_POWER_CB_POWER_SWITCH | PSP_POWER_CB_STANDBY)) > 0)
|
||||
{
|
||||
// suspending
|
||||
if (engine != NULL)
|
||||
engine->Pause();
|
||||
|
||||
}
|
||||
else if ((pwrflags & PSP_POWER_CB_RESUME_COMPLETE) > 0)
|
||||
{
|
||||
sceKernelDelayThread(1500000);
|
||||
// resume complete
|
||||
if (engine != NULL)
|
||||
engine->Resume();
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
// Callback thread
|
||||
int CallbackThread(SceSize args, void *argp)
|
||||
{
|
||||
int cbid;
|
||||
|
||||
#ifdef DEVHOOK
|
||||
cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
|
||||
sceKernelRegisterExitCallback(cbid);
|
||||
#endif
|
||||
cbid = sceKernelCreateCallback("Power Callback", power_callback, NULL);
|
||||
scePowerRegisterCallback(0, 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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifdef DEVHOOK
|
||||
//code by sakya, crazyc, samuraiX
|
||||
//http://forums.ps2dev.org/viewtopic.php?t=9591&sid=2056889f6b9531194cab9b2d487df844
|
||||
PspDebugRegBlock exception_regs;
|
||||
|
||||
extern int _ftext;
|
||||
|
||||
static const char *codeTxt[32] =
|
||||
{
|
||||
"Interrupt", "TLB modification", "TLB load/inst fetch", "TLB store",
|
||||
"Address load/inst fetch", "Address store", "Bus error (instr)",
|
||||
"Bus error (data)", "Syscall", "Breakpoint", "Reserved instruction",
|
||||
"Coprocessor unusable", "Arithmetic overflow", "Unknown 14",
|
||||
"Unknown 15", "Unknown 16", "Unknown 17", "Unknown 18", "Unknown 19",
|
||||
"Unknown 20", "Unknown 21", "Unknown 22", "Unknown 23", "Unknown 24",
|
||||
"Unknown 25", "Unknown 26", "Unknown 27", "Unknown 28", "Unknown 29",
|
||||
"Unknown 31"
|
||||
};
|
||||
|
||||
static const unsigned char regName[32][5] =
|
||||
{
|
||||
"zr", "at", "v0", "v1", "a0", "a1", "a2", "a3",
|
||||
"t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
|
||||
"s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
|
||||
"t8", "t9", "k0", "k1", "gp", "sp", "fp", "ra"
|
||||
};
|
||||
|
||||
void ExceptionHandler(PspDebugRegBlock * regs)
|
||||
{
|
||||
int i;
|
||||
SceCtrlData pad;
|
||||
|
||||
pspDebugScreenInit();
|
||||
pspDebugScreenSetBackColor(0x00FF0000);
|
||||
pspDebugScreenSetTextColor(0xFFFFFFFF);
|
||||
pspDebugScreenClear();
|
||||
pspDebugScreenPrintf("Your PSP has just crashed!\n");
|
||||
pspDebugScreenPrintf("Exception details:\n\n");
|
||||
|
||||
pspDebugScreenPrintf("Exception - %s\n", codeTxt[(regs->cause >> 2) & 31]);
|
||||
pspDebugScreenPrintf("EPC - %08X / %s.text + %08X\n", (int)regs->epc, module_info.modname, (unsigned int)(regs->epc-(int)&_ftext));
|
||||
pspDebugScreenPrintf("Cause - %08X\n", (int)regs->cause);
|
||||
pspDebugScreenPrintf("Status - %08X\n", (int)regs->status);
|
||||
pspDebugScreenPrintf("BadVAddr - %08X\n", (int)regs->badvaddr);
|
||||
for(i=0; i<32; i+=4) pspDebugScreenPrintf("%s:%08X %s:%08X %s:%08X %s:%08X\n", regName[i], (int)regs->r[i], regName[i+1], (int)regs->r[i+1], regName[i+2], (int)regs->r[i+2], regName[i+3], (int)regs->r[i+3]);
|
||||
|
||||
sceKernelDelayThread(1000000);
|
||||
pspDebugScreenPrintf("\n\nPress X to dump information on file exception.log and quit");
|
||||
pspDebugScreenPrintf("\nPress O to quit");
|
||||
|
||||
for (;;){
|
||||
sceCtrlReadBufferPositive(&pad, 1);
|
||||
if (pad.Buttons & PSP_CTRL_CROSS){
|
||||
FILE *log = fopen("exception.log", "w");
|
||||
if (log != NULL){
|
||||
char testo[512];
|
||||
sprintf(testo, "Exception details:\n\n");
|
||||
fwrite(testo, 1, strlen(testo), log);
|
||||
sprintf(testo, "Exception - %s\n", codeTxt[(regs->cause >> 2) & 31]);
|
||||
fwrite(testo, 1, strlen(testo), log);
|
||||
sprintf(testo, "EPC - %08X / %s.text + %08X\n", (int)regs->epc, module_info.modname, (unsigned int)(regs->epc-(int)&_ftext));
|
||||
fwrite(testo, 1, strlen(testo), log);
|
||||
sprintf(testo, "Cause - %08X\n", (int)regs->cause);
|
||||
fwrite(testo, 1, strlen(testo), log);
|
||||
sprintf(testo, "Status - %08X\n", (int)regs->status);
|
||||
fwrite(testo, 1, strlen(testo), log);
|
||||
sprintf(testo, "BadVAddr - %08X\n", (int)regs->badvaddr);
|
||||
fwrite(testo, 1, strlen(testo), log);
|
||||
for(i=0; i<32; i+=4){
|
||||
sprintf(testo, "%s:%08X %s:%08X %s:%08X %s:%08X\n", regName[i], (int)regs->r[i], regName[i+1], (int)regs->r[i+1], regName[i+2], (int)regs->r[i+2], regName[i+3], (int)regs->r[i+3]);
|
||||
fwrite(testo, 1, strlen(testo), log);
|
||||
}
|
||||
fclose(log);
|
||||
}
|
||||
break;
|
||||
}else if (pad.Buttons & PSP_CTRL_CIRCLE){
|
||||
break;
|
||||
}
|
||||
sceKernelDelayThread(100000);
|
||||
}
|
||||
sceKernelExitGame();
|
||||
}
|
||||
|
||||
void initExceptionHandler()
|
||||
{
|
||||
SceKernelLMOption option;
|
||||
int args[2], fd, modid;
|
||||
|
||||
memset(&option, 0, sizeof(option));
|
||||
option.size = sizeof(option);
|
||||
option.mpidtext = PSP_MEMORY_PARTITION_KERNEL;
|
||||
option.mpiddata = PSP_MEMORY_PARTITION_KERNEL;
|
||||
option.position = 0;
|
||||
option.access = 1;
|
||||
|
||||
if((modid = sceKernelLoadModule("exception.prx", 0, &option)) >= 0)
|
||||
{
|
||||
args[0] = (int)ExceptionHandler;
|
||||
args[1] = (int)&exception_regs;
|
||||
sceKernelStartModule(modid, 8, args, &fd, NULL);
|
||||
}
|
||||
}
|
||||
#else
|
||||
//------------------------------------------------------------------------------------------------
|
||||
// Custom exception handler
|
||||
void MyExceptionHandler(PspDebugRegBlock *regs)
|
||||
{
|
||||
pspDebugScreenInit();
|
||||
|
||||
pspDebugScreenSetBackColor(0x00FF0000);
|
||||
pspDebugScreenSetTextColor(0xFFFFFFFF);
|
||||
pspDebugScreenClear();
|
||||
|
||||
pspDebugScreenPrintf("I regret to inform you your psp has just crashed\n");
|
||||
pspDebugScreenPrintf("Please contact Sony technical support for further information\n\n");
|
||||
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();
|
||||
|
||||
pspSdkInstallNoDeviceCheckPatch();
|
||||
pspSdkInstallNoPlainModuleCheckPatch();
|
||||
pspSdkInstallKernelLoadModulePatch();
|
||||
|
||||
pspDebugInstallErrorHandler(MyExceptionHandler);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
// The main loop
|
||||
int main()
|
||||
{
|
||||
|
||||
SetupCallbacks();
|
||||
#ifdef DEVHOOK
|
||||
initExceptionHandler();
|
||||
#endif
|
||||
engine = NULL;
|
||||
|
||||
|
||||
JGameLauncher* launcher = new JGameLauncher();
|
||||
|
||||
u32 flags = launcher->GetInitFlags();
|
||||
if ((flags&JINIT_FLAG_ENABLE3D)!=0)
|
||||
JRenderer::Set3DFlag(true);
|
||||
|
||||
engine = JGE::GetInstance();
|
||||
|
||||
game = launcher->GetGameApp();
|
||||
game->Create();
|
||||
|
||||
|
||||
engine->SetApp(game);
|
||||
engine->Run();
|
||||
|
||||
game->Destroy();
|
||||
delete game;
|
||||
game = NULL;
|
||||
|
||||
engine->SetApp(NULL);
|
||||
|
||||
done = true;
|
||||
|
||||
|
||||
delete launcher;
|
||||
|
||||
JGE::Destroy();
|
||||
engine = NULL;
|
||||
|
||||
sceKernelExitGame();
|
||||
|
||||
return 0;
|
||||
}
|
||||
#include <pspkernel.h>
|
||||
#include <pspdisplay.h>
|
||||
#include <pspdebug.h>
|
||||
#include <psppower.h>
|
||||
#include <pspsdk.h>
|
||||
#include <pspaudiocodec.h>
|
||||
#include <pspaudio.h>
|
||||
#include <pspaudiolib.h>
|
||||
#include <pspmpeg.h>
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <pspctrl.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <queue>
|
||||
|
||||
|
||||
#include "../../JGE/include/JGE.h"
|
||||
#include "../../JGE/include/JApp.h"
|
||||
#include "../../JGE/include/JGameLauncher.h"
|
||||
#include "../../JGE/include/JRenderer.h"
|
||||
|
||||
|
||||
#ifndef JGEApp_Title
|
||||
#define JGEApp_Title "JGE++"
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef DEVHOOK
|
||||
PSP_MODULE_INFO(JGEApp_Title, 0, 1, 1);
|
||||
PSP_MAIN_THREAD_ATTR(PSP_THREAD_ATTR_USER);
|
||||
//256 is not enough for the network to correctly start,
|
||||
// let's find an appropriate value the day JGE has working network
|
||||
PSP_HEAP_SIZE_KB(-256);
|
||||
|
||||
#else
|
||||
|
||||
PSP_MODULE_INFO(JGEApp_Title, 0x1000, 1, 1);
|
||||
PSP_MAIN_THREAD_ATTR(0);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
int mikModThreadID = -1;
|
||||
bool done = false;
|
||||
|
||||
JApp *game = NULL;
|
||||
JGE *g_engine = NULL;
|
||||
|
||||
u32 gTickFrequency;
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
// Exit callback
|
||||
int exit_callback(int arg1, int arg2, void *common)
|
||||
{
|
||||
if (g_engine != NULL)
|
||||
g_engine->End();
|
||||
sceKernelExitGame();
|
||||
return 0;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
// Power Callback
|
||||
int power_callback(int unknown, int pwrflags, void *common)
|
||||
{
|
||||
if ((pwrflags & (PSP_POWER_CB_POWER_SWITCH | PSP_POWER_CB_STANDBY)) > 0)
|
||||
{
|
||||
// suspending
|
||||
if (g_engine != NULL) g_engine->Pause();
|
||||
}
|
||||
else if ((pwrflags & PSP_POWER_CB_RESUME_COMPLETE) > 0)
|
||||
{
|
||||
sceKernelDelayThread(1500000);
|
||||
// resume complete
|
||||
if (g_engine != NULL)
|
||||
g_engine->Resume();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
// Callback thread
|
||||
int CallbackThread(SceSize args, void *argp)
|
||||
{
|
||||
int cbid;
|
||||
|
||||
#ifdef DEVHOOK
|
||||
cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
|
||||
sceKernelRegisterExitCallback(cbid);
|
||||
#endif
|
||||
cbid = sceKernelCreateCallback("Power Callback", power_callback, NULL);
|
||||
scePowerRegisterCallback(0, 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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifdef DEVHOOK
|
||||
//code by sakya, crazyc, samuraiX
|
||||
//http://forums.ps2dev.org/viewtopic.php?t=9591&sid=2056889f6b9531194cab9b2d487df844
|
||||
PspDebugRegBlock exception_regs;
|
||||
|
||||
extern int _ftext;
|
||||
|
||||
static const char *codeTxt[32] =
|
||||
{
|
||||
"Interrupt", "TLB modification", "TLB load/inst fetch", "TLB store",
|
||||
"Address load/inst fetch", "Address store", "Bus error (instr)",
|
||||
"Bus error (data)", "Syscall", "Breakpoint", "Reserved instruction",
|
||||
"Coprocessor unusable", "Arithmetic overflow", "Unknown 14",
|
||||
"Unknown 15", "Unknown 16", "Unknown 17", "Unknown 18", "Unknown 19",
|
||||
"Unknown 20", "Unknown 21", "Unknown 22", "Unknown 23", "Unknown 24",
|
||||
"Unknown 25", "Unknown 26", "Unknown 27", "Unknown 28", "Unknown 29",
|
||||
"Unknown 31"
|
||||
};
|
||||
|
||||
static const unsigned char regName[32][5] =
|
||||
{
|
||||
"zr", "at", "v0", "v1", "a0", "a1", "a2", "a3",
|
||||
"t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
|
||||
"s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
|
||||
"t8", "t9", "k0", "k1", "gp", "sp", "fp", "ra"
|
||||
};
|
||||
|
||||
void ExceptionHandler(PspDebugRegBlock * regs)
|
||||
{
|
||||
int i;
|
||||
SceCtrlData pad;
|
||||
|
||||
pspDebugScreenInit();
|
||||
pspDebugScreenSetBackColor(0x00FF0000);
|
||||
pspDebugScreenSetTextColor(0xFFFFFFFF);
|
||||
pspDebugScreenClear();
|
||||
pspDebugScreenPrintf("Your PSP has just crashed!\n");
|
||||
pspDebugScreenPrintf("Exception details:\n\n");
|
||||
|
||||
pspDebugScreenPrintf("Exception - %s\n", codeTxt[(regs->cause >> 2) & 31]);
|
||||
pspDebugScreenPrintf("EPC - %08X / %s.text + %08X\n", (int)regs->epc, module_info.modname, (unsigned int)(regs->epc-(int)&_ftext));
|
||||
pspDebugScreenPrintf("Cause - %08X\n", (int)regs->cause);
|
||||
pspDebugScreenPrintf("Status - %08X\n", (int)regs->status);
|
||||
pspDebugScreenPrintf("BadVAddr - %08X\n", (int)regs->badvaddr);
|
||||
for (i = 0; i < 32; i += 4) pspDebugScreenPrintf("%s:%08X %s:%08X %s:%08X %s:%08X\n", regName[i], (int)regs->r[i], regName[i+1], (int)regs->r[i+1], regName[i+2], (int)regs->r[i+2], regName[i+3], (int)regs->r[i+3]);
|
||||
|
||||
sceKernelDelayThread(1000000);
|
||||
pspDebugScreenPrintf("\n\nPress X to dump information on file exception.log and quit");
|
||||
pspDebugScreenPrintf("\nPress O to quit");
|
||||
|
||||
for (;;)
|
||||
{
|
||||
sceCtrlReadBufferPositive(&pad, 1);
|
||||
if (pad.Buttons & PSP_CTRL_CROSS)
|
||||
{
|
||||
FILE *log = fopen("exception.log", "w");
|
||||
if (log != NULL)
|
||||
{
|
||||
char testo[512];
|
||||
sprintf(testo, "Exception details:\n\n");
|
||||
fwrite(testo, 1, strlen(testo), log);
|
||||
sprintf(testo, "Exception - %s\n", codeTxt[(regs->cause >> 2) & 31]);
|
||||
fwrite(testo, 1, strlen(testo), log);
|
||||
sprintf(testo, "EPC - %08X / %s.text + %08X\n", (int)regs->epc, module_info.modname, (unsigned int)(regs->epc-(int)&_ftext));
|
||||
fwrite(testo, 1, strlen(testo), log);
|
||||
sprintf(testo, "Cause - %08X\n", (int)regs->cause);
|
||||
fwrite(testo, 1, strlen(testo), log);
|
||||
sprintf(testo, "Status - %08X\n", (int)regs->status);
|
||||
fwrite(testo, 1, strlen(testo), log);
|
||||
sprintf(testo, "BadVAddr - %08X\n", (int)regs->badvaddr);
|
||||
fwrite(testo, 1, strlen(testo), log);
|
||||
for (i = 0; i < 32; i += 4)
|
||||
{
|
||||
sprintf(testo, "%s:%08X %s:%08X %s:%08X %s:%08X\n", regName[i], (int)regs->r[i], regName[i+1], (int)regs->r[i+1], regName[i+2], (int)regs->r[i+2], regName[i+3], (int)regs->r[i+3]);
|
||||
fwrite(testo, 1, strlen(testo), log);
|
||||
}
|
||||
fclose(log);
|
||||
}
|
||||
break;
|
||||
}
|
||||
else if (pad.Buttons & PSP_CTRL_CIRCLE)
|
||||
break;
|
||||
sceKernelDelayThread(100000);
|
||||
}
|
||||
sceKernelExitGame();
|
||||
}
|
||||
|
||||
void initExceptionHandler()
|
||||
{
|
||||
SceKernelLMOption option;
|
||||
int args[2], fd, modid;
|
||||
|
||||
memset(&option, 0, sizeof(option));
|
||||
option.size = sizeof(option);
|
||||
option.mpidtext = PSP_MEMORY_PARTITION_KERNEL;
|
||||
option.mpiddata = PSP_MEMORY_PARTITION_KERNEL;
|
||||
option.position = 0;
|
||||
option.access = 1;
|
||||
|
||||
if ((modid = sceKernelLoadModule("exception.prx", 0, &option)) >= 0)
|
||||
{
|
||||
args[0] = (int)ExceptionHandler;
|
||||
args[1] = (int)&exception_regs;
|
||||
sceKernelStartModule(modid, 8, args, &fd, NULL);
|
||||
}
|
||||
}
|
||||
#else
|
||||
//------------------------------------------------------------------------------------------------
|
||||
// Custom exception handler
|
||||
void MyExceptionHandler(PspDebugRegBlock *regs)
|
||||
{
|
||||
pspDebugScreenInit();
|
||||
|
||||
pspDebugScreenSetBackColor(0x00FF0000);
|
||||
pspDebugScreenSetTextColor(0xFFFFFFFF);
|
||||
pspDebugScreenClear();
|
||||
|
||||
pspDebugScreenPrintf("I regret to inform you your psp has just crashed\n");
|
||||
pspDebugScreenPrintf("Please contact Sony technical support for further information\n\n");
|
||||
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();
|
||||
|
||||
pspSdkInstallNoDeviceCheckPatch();
|
||||
pspSdkInstallNoPlainModuleCheckPatch();
|
||||
pspSdkInstallKernelLoadModulePatch();
|
||||
|
||||
pspDebugInstallErrorHandler(MyExceptionHandler);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
static const struct { LocalKeySym keysym; JButton keycode; } gDefaultBindings[] =
|
||||
{
|
||||
{ PSP_CTRL_HOME, JGE_BTN_QUIT },
|
||||
{ PSP_CTRL_START, JGE_BTN_MENU },
|
||||
{ PSP_CTRL_SELECT, JGE_BTN_CTRL },
|
||||
{ PSP_CTRL_HOLD, JGE_BTN_POWER },
|
||||
{ PSP_CTRL_NOTE, JGE_BTN_SOUND },
|
||||
{ PSP_CTRL_RIGHT, JGE_BTN_RIGHT },
|
||||
{ PSP_CTRL_LEFT, JGE_BTN_LEFT },
|
||||
{ PSP_CTRL_UP, JGE_BTN_UP },
|
||||
{ PSP_CTRL_DOWN, JGE_BTN_DOWN },
|
||||
{ PSP_CTRL_CIRCLE, JGE_BTN_OK },
|
||||
{ PSP_CTRL_TRIANGLE, JGE_BTN_CANCEL },
|
||||
{ PSP_CTRL_SQUARE, JGE_BTN_PRI },
|
||||
{ PSP_CTRL_CROSS, JGE_BTN_SEC },
|
||||
{ PSP_CTRL_LTRIGGER, JGE_BTN_PREV },
|
||||
{ PSP_CTRL_RTRIGGER, JGE_BTN_NEXT }
|
||||
};
|
||||
void JGECreateDefaultBindings()
|
||||
{
|
||||
for (signed int i = sizeof(gDefaultBindings)/sizeof(gDefaultBindings[0]) - 1; i >= 0; --i)
|
||||
g_engine->BindKey(gDefaultBindings[i].keysym, gDefaultBindings[i].keycode);
|
||||
}
|
||||
int JGEGetTime()
|
||||
{
|
||||
u64 curr;
|
||||
sceRtcGetCurrentTick(&curr);
|
||||
return (int)((curr * 1000) / gTickFrequency);
|
||||
}
|
||||
|
||||
static SceCtrlData gCtrlPad;
|
||||
|
||||
u8 JGEGetAnalogX() { return gCtrlPad.Lx; }
|
||||
u8 JGEGetAnalogY() { return gCtrlPad.Ly; }
|
||||
|
||||
void Run()
|
||||
{
|
||||
static const int keyCodeList[] = {
|
||||
PSP_CTRL_SELECT, // Select button.
|
||||
PSP_CTRL_START, // Start button.
|
||||
PSP_CTRL_UP, // Up D-Pad button.
|
||||
PSP_CTRL_RIGHT, // Right D-Pad button.
|
||||
PSP_CTRL_DOWN, // Down D-Pad button.
|
||||
PSP_CTRL_LEFT, // Left D-Pad button.
|
||||
PSP_CTRL_LTRIGGER, // Left trigger.
|
||||
PSP_CTRL_RTRIGGER, // Right trigger.
|
||||
PSP_CTRL_TRIANGLE, // Triangle button.
|
||||
PSP_CTRL_CIRCLE, // Circle button.
|
||||
PSP_CTRL_CROSS, // Cross button.
|
||||
PSP_CTRL_SQUARE, // Square button.
|
||||
PSP_CTRL_HOLD, // Hold button.
|
||||
/* Do not test keys we cannot get anyway, that's just wasted proc time
|
||||
PSP_CTRL_HOME, // Home button.
|
||||
PSP_CTRL_NOTE, // Music Note button.
|
||||
PSP_CTRL_SCREEN, // Screen button.
|
||||
PSP_CTRL_VOLUP, // Volume up button.
|
||||
PSP_CTRL_VOLDOWN, // Volume down button.
|
||||
PSP_CTRL_WLAN, // _UP Wlan switch up.
|
||||
PSP_CTRL_REMOTE, // Remote hold position.
|
||||
PSP_CTRL_DISC, // Disc present.
|
||||
PSP_CTRL_MS // Memory stick present.
|
||||
*/
|
||||
};
|
||||
|
||||
u64 curr;
|
||||
long long int nextInput = 0;
|
||||
u64 lastTime;
|
||||
u32 oldButtons;
|
||||
u32 veryOldButtons;
|
||||
|
||||
sceRtcGetCurrentTick(&lastTime);
|
||||
oldButtons = veryOldButtons = 0;
|
||||
JGECreateDefaultBindings();
|
||||
|
||||
while (!g_engine->mDone)
|
||||
{
|
||||
if (!g_engine->mPaused)
|
||||
{
|
||||
sceRtcGetCurrentTick(&curr);
|
||||
float dt = (curr - lastTime) / (float)gTickFrequency;
|
||||
g_engine->mDelta = dt;
|
||||
|
||||
sceCtrlPeekBufferPositive(&gCtrlPad, 1);
|
||||
for (signed int i = sizeof(keyCodeList)/sizeof(keyCodeList[0]) - 1; i >= 0; --i)
|
||||
{
|
||||
if (keyCodeList[i] & gCtrlPad.Buttons)
|
||||
{
|
||||
if (!(keyCodeList[i] & oldButtons))
|
||||
g_engine->HoldKey(keyCodeList[i]);
|
||||
}
|
||||
else
|
||||
if (keyCodeList[i] & oldButtons)
|
||||
g_engine->ReleaseKey(keyCodeList[i]);
|
||||
}
|
||||
oldButtons = gCtrlPad.Buttons;
|
||||
|
||||
g_engine->Update(dt);
|
||||
g_engine->Render();
|
||||
|
||||
if (g_engine->mDebug)
|
||||
{
|
||||
if (strlen(g_engine->mDebuggingMsg)>0)
|
||||
{
|
||||
pspDebugScreenSetXY(0, 0);
|
||||
pspDebugScreenPrintf(g_engine->mDebuggingMsg);
|
||||
}
|
||||
}
|
||||
veryOldButtons = gCtrlPad.Buttons;
|
||||
}
|
||||
else
|
||||
sceKernelDelayThread(1);
|
||||
lastTime = curr;
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
// The main loop
|
||||
int main()
|
||||
{
|
||||
SetupCallbacks();
|
||||
#ifdef DEVHOOK
|
||||
initExceptionHandler();
|
||||
#endif
|
||||
g_engine = NULL;
|
||||
|
||||
JGameLauncher* launcher = new JGameLauncher();
|
||||
|
||||
u32 flags = launcher->GetInitFlags();
|
||||
if ((flags&JINIT_FLAG_ENABLE3D) != 0)
|
||||
JRenderer::Set3DFlag(true);
|
||||
|
||||
gTickFrequency = sceRtcGetTickResolution();
|
||||
g_engine = JGE::GetInstance();
|
||||
|
||||
game = launcher->GetGameApp();
|
||||
game->Create();
|
||||
|
||||
g_engine->SetApp(game);
|
||||
Run();
|
||||
|
||||
game->Destroy();
|
||||
delete game;
|
||||
game = NULL;
|
||||
|
||||
g_engine->SetApp(NULL);
|
||||
|
||||
done = true;
|
||||
|
||||
delete launcher;
|
||||
|
||||
JGE::Destroy();
|
||||
g_engine = NULL;
|
||||
|
||||
sceKernelExitGame();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
+13
-81
@@ -158,7 +158,6 @@ JGameLauncher* g_launcher = NULL;
|
||||
|
||||
static u32 gButtons = 0;
|
||||
static u32 gOldButtons = 0;
|
||||
static queue< pair<u32, u32> > gKeyBuffer;
|
||||
|
||||
static const struct { WPARAM keysym; u32 pspCode; } gDefaultBindings[] =
|
||||
{
|
||||
@@ -185,45 +184,23 @@ static const struct { WPARAM keysym; u32 pspCode; } gDefaultBindings[] =
|
||||
{ VK_F3, PSP_CTRL_NOTE }
|
||||
};
|
||||
|
||||
static vector< pair<WPARAM, u32> > gKeyCodes;
|
||||
|
||||
void JGEControl()
|
||||
void JGECreateDefaultBindings()
|
||||
{
|
||||
gOldButtons = gButtons;
|
||||
|
||||
gButtons = 0;
|
||||
for (vector< pair<WPARAM, u32> >::iterator it = gKeyCodes.begin(); it != gKeyCodes.end(); ++it)
|
||||
if (g_keys[it->first])
|
||||
gButtons |= it->second;
|
||||
for (signed int i = sizeof(gDefaultBindings)/sizeof(gDefaultBindings[0]) - 1; i >= 0; --i)
|
||||
g_engine->BindKey(gDefaultBindings[i].keysym, gDefaultBindings[i].keycode);
|
||||
}
|
||||
|
||||
|
||||
BOOL JGEGetKeyState(int key)
|
||||
int JGEGetTime()
|
||||
{
|
||||
return (g_keys[key]);
|
||||
return (int)GetTickCount();
|
||||
}
|
||||
|
||||
|
||||
bool JGEGetButtonState(u32 button)
|
||||
{
|
||||
return (gButtons&button)==button;
|
||||
}
|
||||
|
||||
|
||||
bool JGEGetButtonClick(u32 button)
|
||||
{
|
||||
return (gButtons&button)==button && (gOldButtons&button)!=button;
|
||||
}
|
||||
|
||||
|
||||
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); // Declaration For WndProc
|
||||
|
||||
GLvoid ReSizeGLScene(GLsizei width, GLsizei height) // Resize And Initialize The GL Window
|
||||
{
|
||||
if (height==0) // Prevent A Divide By Zero By
|
||||
{
|
||||
height=1; // Making Height Equal One
|
||||
}
|
||||
|
||||
actualWidth = width;
|
||||
actualHeight = height;
|
||||
@@ -327,15 +304,9 @@ int DrawGLScene(void) // Here's Where We Do All The Drawing
|
||||
|
||||
void Update(int dt)
|
||||
{
|
||||
JGEControl();
|
||||
|
||||
gPrevControllerState = gControllerState;
|
||||
g_engine->SetDelta(dt);
|
||||
|
||||
//if (g_app)
|
||||
// g_app->Update();
|
||||
|
||||
g_engine->Update();
|
||||
|
||||
g_engine->Update(dt);
|
||||
}
|
||||
|
||||
void KillGLWindow(void) // Properly Kill The Window
|
||||
@@ -351,14 +322,9 @@ void KillGLWindow(void) // Properly Kill The Window
|
||||
if (hRC) // Do We Have A Rendering Context?
|
||||
{
|
||||
if (!wglMakeCurrent(NULL,NULL)) // Are We Able To Release The DC And RC Contexts?
|
||||
{
|
||||
MessageBox(NULL,"Release Of DC And RC Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
|
||||
}
|
||||
|
||||
MessageBox(NULL,"Release Of DC And RC Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
|
||||
if (!wglDeleteContext(hRC)) // Are We Able To Delete The RC?
|
||||
{
|
||||
MessageBox(NULL,"Release Rendering Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
|
||||
}
|
||||
MessageBox(NULL,"Release Rendering Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
|
||||
hRC=NULL; // Set RC To NULL
|
||||
}
|
||||
|
||||
@@ -573,29 +539,6 @@ BOOL CreateGLWindow(char* title, int width, int height, int bits, bool fullscree
|
||||
return TRUE; // Success
|
||||
}
|
||||
|
||||
u32 JGEReadKey()
|
||||
{
|
||||
if (gKeyBuffer.empty()) return 0;
|
||||
pair<u32, u32> val = gKeyBuffer.front();
|
||||
g_holds[val.first] = false;
|
||||
gKeyBuffer.pop();
|
||||
return val.second;
|
||||
}
|
||||
|
||||
u32 JGEReadLocalKey()
|
||||
{
|
||||
if (gKeyBuffer.empty()) return 0;
|
||||
u32 val = gKeyBuffer.front().first;
|
||||
g_holds[val] = false;
|
||||
gKeyBuffer.pop();
|
||||
return val;
|
||||
}
|
||||
|
||||
void JGEResetInput()
|
||||
{
|
||||
while (!gKeyBuffer.empty()) gKeyBuffer.pop();
|
||||
}
|
||||
|
||||
LRESULT CALLBACK WndProc( HWND hWnd, // Handle For This Window
|
||||
UINT uMsg, // Message For This Window
|
||||
WPARAM wParam, // Additional Message Information
|
||||
@@ -641,14 +584,7 @@ LRESULT CALLBACK WndProc( HWND hWnd, // Handle For This Window
|
||||
case WM_KEYDOWN: // Update Keyboard Buffers For Keys Pressed
|
||||
if ((wParam >= 0) && (wParam <= 255)) // Is Key (wParam) In A Valid Range?
|
||||
{
|
||||
g_keys[wParam] = true; // Set The Selected Key (wParam) To True
|
||||
if (false == g_holds[wParam])
|
||||
{
|
||||
g_holds[wParam] = true;
|
||||
for (vector< pair<WPARAM, u32> >::iterator it = gKeyCodes.begin(); it != gKeyCodes.end(); ++it)
|
||||
if (it->first == wParam)
|
||||
gKeyBuffer.push(*it);
|
||||
}
|
||||
g_engine->HoldKey_NoRepeat(wParam);
|
||||
return 0;
|
||||
}
|
||||
break; // Break
|
||||
@@ -656,8 +592,7 @@ LRESULT CALLBACK WndProc( HWND hWnd, // Handle For This Window
|
||||
case WM_KEYUP: // Update Keyboard Buffers For Keys Released
|
||||
if ((wParam >= 0) && (wParam <= 255)) // Is Key (wParam) In A Valid Range?
|
||||
{
|
||||
g_keys[wParam] = FALSE; // Set The Selected Key (wParam) To False
|
||||
g_holds[wParam] = FALSE;
|
||||
g_engine->ReleaseKey(wParam);
|
||||
return 0; // Return
|
||||
}
|
||||
break;
|
||||
@@ -721,8 +656,7 @@ int WINAPI WinMain( HINSTANCE hInstance, // Instance
|
||||
|
||||
u32 flags = g_launcher->GetInitFlags();
|
||||
|
||||
for (signed int i = sizeof(gDefaultBindings)/sizeof(gDefaultBindings[0]) - 1; i >= 0; --i)
|
||||
gKeyCodes.push_back(make_pair(gDefaultBindings[i].keysym, gDefaultBindings[i].pspCode));
|
||||
JGECreateDefaultBindings();
|
||||
|
||||
if ((flags&JINIT_FLAG_ENABLE3D)!=0)
|
||||
JRenderer::Set3DFlag(true);
|
||||
@@ -753,9 +687,7 @@ int WINAPI WinMain( HINSTANCE hInstance, // Instance
|
||||
if (active) // Program Active?
|
||||
{
|
||||
if (g_engine->IsDone())
|
||||
{
|
||||
done=TRUE; // ESC Signalled A Quit
|
||||
}
|
||||
done=TRUE; // ESC Signalled A Quit
|
||||
else // Not Time To Quit, Update Screen
|
||||
{
|
||||
tickCount = GetTickCount(); // Get The Tick Count
|
||||
|
||||
Reference in New Issue
Block a user