* Some cosmetic cleanup.
* Have the unix version report analog control the same way the
  windows version does.
* Move back Run() into JGE::Run(). The code for ::Run() is still
  inside main.cpp.
  - This fixes the "blinking screen problem", issue 341. I think.
  - I have no idea WHY it does, but it's better than not fixing it.
  - Run() would be better in ::Run() in main.cpp than in JGE, should
    be moved back when we know more about the problem.
This commit is contained in:
jean.chalard
2010-02-24 18:28:36 +00:00
parent 39c5a3d465
commit 79d142f968
3 changed files with 89 additions and 75 deletions
+4
View File
@@ -85,6 +85,10 @@ class JGE
#if defined (WIN32) || defined (LINUX) #if defined (WIN32) || defined (LINUX)
float mDeltaTime; float mDeltaTime;
JMusic *mCurrentMusic; JMusic *mCurrentMusic;
#else
public:
void Run();
private:
#endif #endif
bool mDone; bool mDone;
+68 -52
View File
@@ -48,21 +48,16 @@ u8 JGE::GetAnalogY()
u8 JGE::GetAnalogX() u8 JGE::GetAnalogX()
{ {
/* FIXME if (GetButtonState(JGE_BTN_LEFT)) return 0;
if (JGEGetKeyState(VK_LEFT)) return 0; if (GetButtonState(JGE_BTN_RIGHT)) return 0xff;
if (JGEGetKeyState(VK_RIGHT)) return 0xff;
*/
return 0x80; return 0x80;
} }
u8 JGE::GetAnalogY() u8 JGE::GetAnalogY()
{ {
/* FIXME if (GetButtonState(JGE_BTN_UP)) return 0;
if (JGEGetKeyState(VK_UP)) return 0; if (GetButtonState(JGE_BTN_DOWN)) return 0xff;
if (JGEGetKeyState(VK_DOWN)) return 0xff;
*/
return 0x80; return 0x80;
} }
@@ -315,43 +310,78 @@ u8 JGE::GetAnalogY()
return JGEGetAnalogY(); return JGEGetAnalogY();
} }
static SceCtrlData gCtrlPad;
void JGE::Run()
/*
bool JGE::GetButtonState(u32 button)
{ {
return (mCtrlPad.Buttons&button)==button; 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.
};
u64 curr;
long long int nextInput = 0;
u64 lastTime;
u32 oldButtons;
u32 veryOldButtons;
u32 gTickFrequency = sceRtcGetTickResolution();
sceRtcGetCurrentTick(&lastTime);
oldButtons = veryOldButtons = 0;
JGECreateDefaultBindings();
while (!mDone)
{
if (!mPaused)
{
sceRtcGetCurrentTick(&curr);
float dt = (curr - lastTime) / (float)gTickFrequency;
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))
HoldKey(keyCodeList[i]);
}
else
if (keyCodeList[i] & oldButtons)
ReleaseKey(keyCodeList[i]);
}
oldButtons = gCtrlPad.Buttons;
Update(dt);
Render();
if (mDebug)
{
if (strlen(mDebuggingMsg)>0)
{
pspDebugScreenSetXY(0, 0);
pspDebugScreenPrintf(mDebuggingMsg);
}
}
veryOldButtons = gCtrlPad.Buttons;
}
else
sceKernelDelayThread(1);
lastTime = curr;
}
} }
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 #endif ///// PSP specific code
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
JGE* JGE::mInstance = NULL; JGE* JGE::mInstance = NULL;
//static int gCount = 0;
// returns number of milliseconds since game started // returns number of milliseconds since game started
int JGE::GetTime() int JGE::GetTime()
@@ -362,19 +392,13 @@ int JGE::GetTime()
JGE* JGE::GetInstance() JGE* JGE::GetInstance()
{ {
if (mInstance == NULL) if (mInstance == NULL) mInstance = new JGE();
{
mInstance = new JGE();
}
//gCount++;
return mInstance; return mInstance;
} }
void JGE::Destroy() void JGE::Destroy()
{ {
//gCount--;
if (mInstance) if (mInstance)
{ {
delete mInstance; delete mInstance;
@@ -397,14 +421,11 @@ void JGE::Render()
renderer->EndScene(); renderer->EndScene();
} }
void JGE::End() void JGE::End()
{ {
mDone = true; mDone = true;
} }
void JGE::printf(const char *format, ...) void JGE::printf(const char *format, ...)
{ {
va_list list; va_list list;
@@ -415,14 +436,12 @@ void JGE::printf(const char *format, ...)
} }
void JGE::Pause() void JGE::Pause()
{ {
if (mPaused) return; if (mPaused) return;
mPaused = true; mPaused = true;
if (mApp != NULL) if (mApp != NULL) mApp->Pause();
mApp->Pause();
} }
@@ -436,14 +455,11 @@ void JGE::Resume()
} }
} }
void JGE::Assert(const char *filename, long lineNumber) void JGE::Assert(const char *filename, long lineNumber)
{ {
mAssertFile = filename; mAssertFile = filename;
mAssertLine = lineNumber; mAssertLine = lineNumber;
mCriticalAssert = true; mCriticalAssert = true;
} }
std::queue< pair<LocalKeySym, JButton> > JGE::keyBuffer; std::queue< pair<LocalKeySym, JButton> > JGE::keyBuffer;
+17 -23
View File
@@ -326,36 +326,30 @@ void Run()
while (!g_engine->mDone) while (!g_engine->mDone)
{ {
sceRtcGetCurrentTick(&curr);
float dt = (curr - lastTime) / (float)gTickFrequency;
g_engine->mDelta = dt;
if (!g_engine->mPaused) if (!g_engine->mPaused)
{ {
sceRtcGetCurrentTick(&curr);
float dt = (curr - lastTime) / (float)gTickFrequency;
g_engine->mDelta = dt;
sceCtrlPeekBufferPositive(&gCtrlPad, 1); sceCtrlPeekBufferPositive(&gCtrlPad, 1);
for (signed int i = sizeof(keyCodeList)/sizeof(keyCodeList[0]) - 1; i >= 0; --i) for (signed int i = sizeof(keyCodeList)/sizeof(keyCodeList[0]) - 1; i >= 0; --i)
{ if (keyCodeList[i] & gCtrlPad.Buttons)
if (keyCodeList[i] & gCtrlPad.Buttons) {
{ if (!(keyCodeList[i] & oldButtons))
if (!(keyCodeList[i] & oldButtons)) g_engine->HoldKey(keyCodeList[i]);
g_engine->HoldKey(keyCodeList[i]); }
} else
else if (keyCodeList[i] & oldButtons)
if (keyCodeList[i] & oldButtons) g_engine->ReleaseKey(keyCodeList[i]);
g_engine->ReleaseKey(keyCodeList[i]);
}
oldButtons = gCtrlPad.Buttons;
oldButtons = gCtrlPad.Buttons;
g_engine->Update(dt); g_engine->Update(dt);
g_engine->Render(); g_engine->Render();
if (g_engine->mDebug) if (g_engine->mDebug && strlen(g_engine->mDebuggingMsg) > 0)
{ {
if (strlen(g_engine->mDebuggingMsg)>0) pspDebugScreenSetXY(0, 0);
{ pspDebugScreenPrintf(g_engine->mDebuggingMsg);
pspDebugScreenSetXY(0, 0);
pspDebugScreenPrintf(g_engine->mDebuggingMsg);
}
} }
veryOldButtons = gCtrlPad.Buttons; veryOldButtons = gCtrlPad.Buttons;
} }
@@ -388,7 +382,7 @@ int main()
game->Create(); game->Create();
g_engine->SetApp(game); g_engine->SetApp(game);
Run(); g_engine->Run();
game->Destroy(); game->Destroy();
delete game; delete game;