* Add key repetition.
This commit is contained in:
jean.chalard
2008-11-25 15:24:22 +00:00
parent 3b4519bbe4
commit cfea9ff2c0
+24 -8
View File
@@ -360,11 +360,16 @@ u8 JGE::GetAnalogY()
return mCtrlPad.Ly; return mCtrlPad.Ly;
} }
#define REPEAT_DELAY 1
#define REPEAT_FREQUENCY 2
void JGE::Run() void JGE::Run()
{ {
u64 curr; u64 curr;
long long int nextInput;
const u32 ticksPerSecond = sceRtcGetTickResolution();
const u64 repeatDelay = REPEAT_DELAY * ticksPerSecond;
const u64 repeatPeriod = ticksPerSecond / REPEAT_FREQUENCY;
while (!mDone) while (!mDone)
{ {
@@ -372,15 +377,26 @@ void JGE::Run()
{ {
sceRtcGetCurrentTick(&curr); sceRtcGetCurrentTick(&curr);
mDelta = (curr-mLastTime) / (float)mTickFrequency;// * 1000.0f; mDelta = (curr-mLastTime) / (float)mTickFrequency;// * 1000.0f;
mLastTime = curr;
while (0 != sceCtrlPeekBufferPositive(&mCtrlPad, 1)) while (0 != sceCtrlPeekBufferPositive(&mCtrlPad, 1))
if (mCtrlPad.Buttons != mOldButtons) for (signed int i = sizeof(gKeyCodeList)/sizeof(gKeyCodeList[0]) - 1; i >= 0; --i)
for (signed int i = sizeof(gKeyCodeList)/sizeof(gKeyCodeList[0]) - 1; i >= 0; --i) if (gKeyCodeList[i] & mCtrlPad.Buttons)
if (gKeyCodeList[i] & (mCtrlPad.Buttons ^ mOldButtons)) {
gKeyBuffer.push(gKeyCodeList[i]); if (!(gKeyCodeList[i] & mOldButtons))
{
gKeyBuffer.push(gKeyCodeList[i]);
nextInput = repeatDelay;
}
else if (nextInput < 0)
{
gKeyBuffer.push(gKeyCodeList[i]);
nextInput = repeatPeriod;
}
}
nextInput -= (curr - mLastTime);
mLastTime = curr;
Update(); Update();
Render(); Render();