Tied in my recent Android flick gesture addition to a Scroll() function. GameState now has a virtual function OnScroll() call that, by default is a no-op; each game state can choose to override how to respond to flick gestures. I've added one such override in the Deck Editor so that a flick up/down acts like the psp button up/down for scrolling between color filters.

This commit is contained in:
wrenczes@gmail.com
2011-06-15 09:52:11 +00:00
parent e1dc1afa74
commit 741f662bb0
9 changed files with 298 additions and 240 deletions
+2
View File
@@ -82,6 +82,8 @@ public:
/// ///
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
virtual void Resume() = 0; virtual void Resume() = 0;
virtual void OnScroll(int inXVelocity, int inYVelocity) = 0;
}; };
+4
View File
@@ -319,6 +319,10 @@ class JGE
// Returns false if nothing has been clicked, true otherwise // Returns false if nothing has been clicked, true otherwise
bool GetLeftClickCoordinates(int& x, int& y); bool GetLeftClickCoordinates(int& x, int& y);
// Scroll events - currently triggered by SDL JOYBALL events
void Scroll(int inXVelocity, int inYVelocity);
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
/// Get if the system is ended/paused or not. /// Get if the system is ended/paused or not.
/// ///
+255 -232
View File
@@ -29,17 +29,17 @@
u8 JGE::GetAnalogX() u8 JGE::GetAnalogX()
{ {
if (GetButtonState(JGE_BTN_LEFT)) return 0; if (GetButtonState(JGE_BTN_LEFT)) return 0;
if (GetButtonState(JGE_BTN_RIGHT)) return 0xff; if (GetButtonState(JGE_BTN_RIGHT)) return 0xff;
return 0x80; return 0x80;
} }
u8 JGE::GetAnalogY() u8 JGE::GetAnalogY()
{ {
if (GetButtonState(JGE_BTN_UP)) return 0; if (GetButtonState(JGE_BTN_UP)) return 0;
if (GetButtonState(JGE_BTN_DOWN)) return 0xff; if (GetButtonState(JGE_BTN_DOWN)) return 0xff;
return 0x80; return 0x80;
} }
#elif defined (LINUX) // Unix specific code #elif defined (LINUX) // Unix specific code
@@ -49,17 +49,17 @@ u8 JGE::GetAnalogY()
u8 JGE::GetAnalogX() u8 JGE::GetAnalogX()
{ {
if (GetButtonState(JGE_BTN_LEFT)) return 0; if (GetButtonState(JGE_BTN_LEFT)) return 0;
if (GetButtonState(JGE_BTN_RIGHT)) return 0xff; if (GetButtonState(JGE_BTN_RIGHT)) return 0xff;
return 0x80; return 0x80;
} }
u8 JGE::GetAnalogY() u8 JGE::GetAnalogY()
{ {
if (GetButtonState(JGE_BTN_UP)) return 0; if (GetButtonState(JGE_BTN_UP)) return 0;
if (GetButtonState(JGE_BTN_DOWN)) return 0xff; if (GetButtonState(JGE_BTN_DOWN)) return 0xff;
return 0x80; return 0x80;
} }
#endif #endif
@@ -75,240 +75,255 @@ static inline pair<pair<LocalKeySym, JButton>, bool> triplet(pair<LocalKeySym, J
void JGE::PressKey(const LocalKeySym sym) void JGE::PressKey(const LocalKeySym sym)
{ {
const pair<keycodes_it, keycodes_it> rng = keyBinds.equal_range(sym); const pair<keycodes_it, keycodes_it> rng = keyBinds.equal_range(sym);
if (rng.first == rng.second) if (rng.first == rng.second)
keyBuffer.push(triplet(sym, JGE_BTN_NONE, false)); keyBuffer.push(triplet(sym, JGE_BTN_NONE, false));
else for (keycodes_it it = rng.first; it != rng.second; ++it) { else for (keycodes_it it = rng.first; it != rng.second; ++it)
{
#if defined (WIN32) || defined (LINUX) #if defined (WIN32) || defined (LINUX)
if (JGE_BTN_FULLSCREEN == it->second) JGEToggleFullscreen(); if (JGE_BTN_FULLSCREEN == it->second) JGEToggleFullscreen();
#endif #endif
keyBuffer.push(triplet(*it, held(it->second))); keyBuffer.push(triplet(*it, held(it->second)));
} }
} }
void JGE::PressKey(const JButton sym) void JGE::PressKey(const JButton sym)
{ {
#if defined (WIN32) || defined (LINUX) #if defined (WIN32) || defined (LINUX)
if (sym == JGE_BTN_FULLSCREEN) JGEToggleFullscreen(); if (sym == JGE_BTN_FULLSCREEN) JGEToggleFullscreen();
#endif #endif
keyBuffer.push(triplet(LOCAL_KEY_NONE, sym, held(sym))); keyBuffer.push(triplet(LOCAL_KEY_NONE, sym, held(sym)));
} }
void JGE::HoldKey(const LocalKeySym sym) void JGE::HoldKey(const LocalKeySym sym)
{ {
const pair<keycodes_it, keycodes_it> rng = keyBinds.equal_range(sym); const pair<keycodes_it, keycodes_it> rng = keyBinds.equal_range(sym);
if (rng.first == rng.second) if (rng.first == rng.second)
keyBuffer.push(triplet(sym, JGE_BTN_NONE, false)); keyBuffer.push(triplet(sym, JGE_BTN_NONE, false));
else for (keycodes_it it = rng.first; it != rng.second; ++it) else for (keycodes_it it = rng.first; it != rng.second; ++it)
{ {
#if defined (WIN32) || defined (LINUX) #if defined (WIN32) || defined (LINUX)
if (JGE_BTN_FULLSCREEN == it->second) JGEToggleFullscreen(); if (JGE_BTN_FULLSCREEN == it->second) JGEToggleFullscreen();
#endif #endif
if (!held(it->second)) if (!held(it->second))
{ {
keyBuffer.push(triplet(*it, false)); keyBuffer.push(triplet(*it, false));
holds[it->second] = REPEAT_DELAY; holds[it->second] = REPEAT_DELAY;
} }
else keyBuffer.push(triplet(*it, true)); else keyBuffer.push(triplet(*it, true));
} }
} }
void JGE::HoldKey_NoRepeat(const LocalKeySym sym) void JGE::HoldKey_NoRepeat(const LocalKeySym sym)
{ {
const pair<keycodes_it, keycodes_it> rng = keyBinds.equal_range(sym); const pair<keycodes_it, keycodes_it> rng = keyBinds.equal_range(sym);
if (rng.first == rng.second) if (rng.first == rng.second)
keyBuffer.push(triplet(sym, JGE_BTN_NONE, false)); keyBuffer.push(triplet(sym, JGE_BTN_NONE, false));
else for (keycodes_it it = rng.first; it != rng.second; ++it) else for (keycodes_it it = rng.first; it != rng.second; ++it)
{ {
#if defined (WIN32) || defined (LINUX) #if defined (WIN32) || defined (LINUX)
if (JGE_BTN_FULLSCREEN == it->second) if (JGE_BTN_FULLSCREEN == it->second)
{ {
JGEToggleFullscreen(); JGEToggleFullscreen();
return; return;
} }
#endif #endif
keyBuffer.push(triplet(*it, true)); keyBuffer.push(triplet(*it, true));
if (!held(it->second)) if (!held(it->second))
holds[it->second] = std::numeric_limits<float>::quiet_NaN(); holds[it->second] = std::numeric_limits<float>::quiet_NaN();
} }
} }
void JGE::HoldKey(const JButton sym) void JGE::HoldKey(const JButton sym)
{ {
#if defined (WIN32) || defined (LINUX) #if defined (WIN32) || defined (LINUX)
if (JGE_BTN_FULLSCREEN == sym) JGEToggleFullscreen(); if (JGE_BTN_FULLSCREEN == sym) JGEToggleFullscreen();
#endif #endif
if (!held(sym)) if (!held(sym))
{ {
keyBuffer.push(triplet(LOCAL_KEY_NONE, sym, false)); keyBuffer.push(triplet(LOCAL_KEY_NONE, sym, false));
holds[sym] = REPEAT_DELAY; holds[sym] = REPEAT_DELAY;
} }
else keyBuffer.push(triplet(LOCAL_KEY_NONE, sym, true)); else keyBuffer.push(triplet(LOCAL_KEY_NONE, sym, true));
} }
void JGE::HoldKey_NoRepeat(const JButton sym) void JGE::HoldKey_NoRepeat(const JButton sym)
{ {
#if defined (WIN32) || defined (LINUX) #if defined (WIN32) || defined (LINUX)
if (JGE_BTN_FULLSCREEN == sym) JGEToggleFullscreen(); if (JGE_BTN_FULLSCREEN == sym) JGEToggleFullscreen();
#endif #endif
keyBuffer.push(triplet(LOCAL_KEY_NONE, sym, true)); keyBuffer.push(triplet(LOCAL_KEY_NONE, sym, true));
if (!held(sym)) if (!held(sym))
holds[sym] = std::numeric_limits<float>::quiet_NaN(); holds[sym] = std::numeric_limits<float>::quiet_NaN();
} }
void JGE::ReleaseKey(const LocalKeySym sym) void JGE::ReleaseKey(const LocalKeySym sym)
{ {
set<JButton> s; set<JButton> s;
const pair<keycodes_it, keycodes_it> rng = keyBinds.equal_range(sym); const pair<keycodes_it, keycodes_it> rng = keyBinds.equal_range(sym);
for (keycodes_it it = rng.first; it != rng.second; ++it) for (keycodes_it it = rng.first; it != rng.second; ++it)
{ {
s.insert(it->second); s.insert(it->second);
holds.erase(it->second); holds.erase(it->second);
} }
queue< pair<pair<LocalKeySym, JButton>, bool> > r; queue< pair<pair<LocalKeySym, JButton>, bool> > r;
while (!keyBuffer.empty()) while (!keyBuffer.empty())
{ {
pair<pair<LocalKeySym, JButton>, bool> q = keyBuffer.front(); pair<pair<LocalKeySym, JButton>, bool> q = keyBuffer.front();
keyBuffer.pop(); keyBuffer.pop();
if ((!q.second) || (s.end() == s.find(q.first.second))) r.push(q); if ((!q.second) || (s.end() == s.find(q.first.second))) r.push(q);
} }
keyBuffer = r; keyBuffer = r;
} }
void JGE::ReleaseKey(const JButton sym) void JGE::ReleaseKey(const JButton sym)
{ {
holds.erase(sym); holds.erase(sym);
queue< pair<pair<LocalKeySym, JButton>, bool> > r; queue< pair<pair<LocalKeySym, JButton>, bool> > r;
while (!keyBuffer.empty()) while (!keyBuffer.empty())
{ {
pair<pair<LocalKeySym, JButton>, bool> q = keyBuffer.front(); pair<pair<LocalKeySym, JButton>, bool> q = keyBuffer.front();
keyBuffer.pop(); keyBuffer.pop();
if ((!q.second) || (q.first.second != sym)) r.push(q); if ((!q.second) || (q.first.second != sym)) r.push(q);
} }
keyBuffer = r; keyBuffer = r;
} }
void JGE::Update(float dt) void JGE::Update(float dt)
{ {
for (map<JButton, float>::iterator it = holds.begin(); it != holds.end(); ++it) for (map<JButton, float>::iterator it = holds.begin(); it != holds.end(); ++it)
{ {
if (it->second < 0) { keyBuffer.push(triplet(LOCAL_KEY_NONE, it->first, true)); it->second = REPEAT_PERIOD; } if (it->second < 0)
it->second -= dt; {
keyBuffer.push(triplet(LOCAL_KEY_NONE, it->first, true));
it->second = REPEAT_PERIOD;
}
it->second -= dt;
} }
if (mApp != NULL) mApp->Update();
oldHolds = holds; if (mApp != NULL)
mApp->Update();
oldHolds = holds;
} }
bool JGE::GetButtonState(JButton button) bool JGE::GetButtonState(JButton button)
{ {
return (holds.end() != holds.find(button)); return (holds.end() != holds.find(button));
} }
bool JGE::GetButtonClick(JButton button) bool JGE::GetButtonClick(JButton button)
{ {
return ((holds.end() != holds.find(button)) && (oldHolds.end() == oldHolds.find(button))); return ((holds.end() != holds.find(button)) && (oldHolds.end() == oldHolds.find(button)));
} }
JButton JGE::ReadButton() JButton JGE::ReadButton()
{ {
if (keyBuffer.empty()) return JGE_BTN_NONE; if (keyBuffer.empty()) return JGE_BTN_NONE;
JButton val = keyBuffer.front().first.second; JButton val = keyBuffer.front().first.second;
keyBuffer.pop(); keyBuffer.pop();
return val; return val;
} }
LocalKeySym JGE::ReadLocalKey() LocalKeySym JGE::ReadLocalKey()
{ {
if (keyBuffer.empty()) return LOCAL_KEY_NONE; if (keyBuffer.empty()) return LOCAL_KEY_NONE;
LocalKeySym val = keyBuffer.front().first.first; LocalKeySym val = keyBuffer.front().first.first;
keyBuffer.pop(); keyBuffer.pop();
return val; return val;
} }
u32 JGE::BindKey(LocalKeySym sym, JButton button) u32 JGE::BindKey(LocalKeySym sym, JButton button)
{ {
keyBinds.insert(make_pair(sym, button)); keyBinds.insert(make_pair(sym, button));
return keyBinds.size(); return keyBinds.size();
} }
u32 JGE::UnbindKey(LocalKeySym sym, JButton button) u32 JGE::UnbindKey(LocalKeySym sym, JButton button)
{ {
for (keycodes_it it = keyBinds.begin(); it != keyBinds.end(); ) for (keycodes_it it = keyBinds.begin(); it != keyBinds.end(); )
if (sym == it->first && button == it->second) if (sym == it->first && button == it->second)
{ {
keycodes_it er = it; keycodes_it er = it;
++it; ++it;
keyBinds.erase(er); keyBinds.erase(er);
} }
else ++it; else ++it;
return keyBinds.size(); return keyBinds.size();
} }
u32 JGE::UnbindKey(LocalKeySym sym) u32 JGE::UnbindKey(LocalKeySym sym)
{ {
pair<keycodes_it, keycodes_it> rng = keyBinds.equal_range(sym); pair<keycodes_it, keycodes_it> rng = keyBinds.equal_range(sym);
keyBinds.erase(rng.first, rng.second); keyBinds.erase(rng.first, rng.second);
return keyBinds.size(); return keyBinds.size();
} }
void JGE::ClearBindings() void JGE::ClearBindings()
{ {
keyBinds.clear(); keyBinds.clear();
} }
void JGE::ResetBindings() void JGE::ResetBindings()
{ {
keyBinds.clear(); keyBinds.clear();
JGECreateDefaultBindings(); JGECreateDefaultBindings();
} }
JGE::keybindings_it JGE::KeyBindings_begin() { return keyBinds.begin(); } JGE::keybindings_it JGE::KeyBindings_begin()
JGE::keybindings_it JGE::KeyBindings_end() { return keyBinds.end(); } {
return keyBinds.begin();
}
JGE::keybindings_it JGE::KeyBindings_end()
{
return keyBinds.end();
}
void JGE::ResetInput() void JGE::ResetInput()
{ {
while (!keyBuffer.empty()) keyBuffer.pop(); while (!keyBuffer.empty()) keyBuffer.pop();
holds.clear(); holds.clear();
LeftClickedProcessed(); LeftClickedProcessed();
} }
void JGE::LeftClicked(int x, int y) void JGE::LeftClicked(int x, int y)
{ {
mLastLeftClickX = x; mLastLeftClickX = x;
mlastLeftClickY = y; mlastLeftClickY = y;
} }
void JGE::LeftClickedProcessed() void JGE::LeftClickedProcessed()
{ {
mLastLeftClickX = -1; mLastLeftClickX = -1;
mlastLeftClickY = -1; mlastLeftClickY = -1;
} }
bool JGE::GetLeftClickCoordinates(int& x, int& y) bool JGE::GetLeftClickCoordinates(int& x, int& y)
{ {
if(mLastLeftClickX != -1 || mlastLeftClickY != -1) if(mLastLeftClickX != -1 || mlastLeftClickY != -1)
{ {
x = mLastLeftClickX; x = mLastLeftClickX;
y = mlastLeftClickY; y = mlastLeftClickY;
return true; return true;
} }
return false; return false;
} }
JGE::JGE() JGE::JGE()
{ {
mApp = NULL; mApp = NULL;
#if defined (WIN32) || defined (LINUX) #if defined (WIN32) || defined (LINUX)
strcpy(mDebuggingMsg, ""); strcpy(mDebuggingMsg, "");
mCurrentMusic = NULL; mCurrentMusic = NULL;
#endif #endif
Init(); Init();
} }
JGE::~JGE() JGE::~JGE()
{ {
JRenderer::Destroy(); JRenderer::Destroy();
JFileSystem::Destroy(); JFileSystem::Destroy();
JSoundSystem::Destroy(); JSoundSystem::Destroy();
} }
@@ -319,102 +334,102 @@ JGE::~JGE()
void JGE::Init() void JGE::Init()
{ {
#ifdef DEBUG_PRINT #ifdef DEBUG_PRINT
mDebug = true; mDebug = true;
#else #else
mDebug = false; mDebug = false;
#endif #endif
if (mDebug) if (mDebug)
pspDebugScreenInit(); // do this so that we can use pspDebugScreenPrintf pspDebugScreenInit(); // do this so that we can use pspDebugScreenPrintf
strcpy(mDebuggingMsg, ""); strcpy(mDebuggingMsg, "");
sceCtrlSetSamplingCycle(0); sceCtrlSetSamplingCycle(0);
sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG); sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);
JRenderer::GetInstance(); JRenderer::GetInstance();
JFileSystem::GetInstance(); JFileSystem::GetInstance();
//JSoundSystem::GetInstance(); let's do lazy loading //JSoundSystem::GetInstance(); let's do lazy loading
mDone = false; mDone = false;
mPaused = false; mPaused = false;
mCriticalAssert = false; mCriticalAssert = false;
} }
u8 JGE::GetAnalogX() u8 JGE::GetAnalogX()
{ {
return JGEGetAnalogX(); return JGEGetAnalogX();
} }
u8 JGE::GetAnalogY() u8 JGE::GetAnalogY()
{ {
return JGEGetAnalogY(); return JGEGetAnalogY();
} }
static SceCtrlData gCtrlPad; static SceCtrlData gCtrlPad;
void JGE::Run() void JGE::Run()
{ {
static const int keyCodeList[] = { static const int keyCodeList[] = {
PSP_CTRL_SELECT, // Select button. PSP_CTRL_SELECT, // Select button.
PSP_CTRL_START, // Start button. PSP_CTRL_START, // Start button.
PSP_CTRL_UP, // Up D-Pad button. PSP_CTRL_UP, // Up D-Pad button.
PSP_CTRL_RIGHT, // Right D-Pad button. PSP_CTRL_RIGHT, // Right D-Pad button.
PSP_CTRL_DOWN, // Down D-Pad button. PSP_CTRL_DOWN, // Down D-Pad button.
PSP_CTRL_LEFT, // Left D-Pad button. PSP_CTRL_LEFT, // Left D-Pad button.
PSP_CTRL_LTRIGGER, // Left trigger. PSP_CTRL_LTRIGGER, // Left trigger.
PSP_CTRL_RTRIGGER, // Right trigger. PSP_CTRL_RTRIGGER, // Right trigger.
PSP_CTRL_TRIANGLE, // Triangle button. PSP_CTRL_TRIANGLE, // Triangle button.
PSP_CTRL_CIRCLE, // Circle button. PSP_CTRL_CIRCLE, // Circle button.
PSP_CTRL_CROSS, // Cross button. PSP_CTRL_CROSS, // Cross button.
PSP_CTRL_SQUARE, // Square button. PSP_CTRL_SQUARE, // Square button.
PSP_CTRL_HOLD, // Hold button. PSP_CTRL_HOLD, // Hold button.
}; };
u64 curr; u64 curr;
long long int nextInput = 0; long long int nextInput = 0;
u64 lastTime; u64 lastTime;
u32 oldButtons; u32 oldButtons;
u32 veryOldButtons; u32 veryOldButtons;
u32 gTickFrequency = sceRtcGetTickResolution(); u32 gTickFrequency = sceRtcGetTickResolution();
sceRtcGetCurrentTick(&lastTime); sceRtcGetCurrentTick(&lastTime);
oldButtons = veryOldButtons = 0; oldButtons = veryOldButtons = 0;
JGECreateDefaultBindings(); JGECreateDefaultBindings();
while (!mDone) while (!mDone)
{ {
if (!mPaused) if (!mPaused)
{ {
sceRtcGetCurrentTick(&curr); sceRtcGetCurrentTick(&curr);
float dt = (curr - lastTime) / (float)gTickFrequency; float dt = (curr - lastTime) / (float)gTickFrequency;
mDeltaTime = dt; mDeltaTime = 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))
HoldKey(keyCodeList[i]); HoldKey(keyCodeList[i]);
} }
else else
if (keyCodeList[i] & oldButtons) if (keyCodeList[i] & oldButtons)
ReleaseKey(keyCodeList[i]); ReleaseKey(keyCodeList[i]);
}
oldButtons = gCtrlPad.Buttons;
Update(dt);
Render();
if (mDebug)
{
if (strlen(mDebuggingMsg)>0)
{
pspDebugScreenSetXY(0, 0);
pspDebugScreenPrintf(mDebuggingMsg);
}
} }
veryOldButtons = gCtrlPad.Buttons; oldButtons = gCtrlPad.Buttons;
Update(dt);
Render();
if (mDebug)
{
if (strlen(mDebuggingMsg)>0)
{
pspDebugScreenSetXY(0, 0);
pspDebugScreenPrintf(mDebuggingMsg);
}
}
veryOldButtons = gCtrlPad.Buttons;
} }
else else
sceKernelDelayThread(1); sceKernelDelayThread(1);
lastTime = curr; lastTime = curr;
} }
} }
@@ -423,13 +438,13 @@ void JGE::Run()
#else ///// Non PSP code #else ///// Non PSP code
void JGE::Init() void JGE::Init()
{ {
mDone = false; mDone = false;
mPaused = false; mPaused = false;
mCriticalAssert = false; mCriticalAssert = false;
JRenderer::GetInstance(); JRenderer::GetInstance();
JFileSystem::GetInstance(); JFileSystem::GetInstance();
JSoundSystem::GetInstance(); JSoundSystem::GetInstance();
LeftClickedProcessed(); LeftClickedProcessed();
} }
#endif ///// Non PSP code #endif ///// Non PSP code
@@ -441,107 +456,115 @@ JGE* JGE::mInstance = NULL;
// returns number of milliseconds since game started // returns number of milliseconds since game started
int JGE::GetTime() int JGE::GetTime()
{ {
return JGEGetTime(); return JGEGetTime();
} }
void JGE::SetDelta(float delta) void JGE::SetDelta(float delta)
{ {
mDeltaTime = delta; mDeltaTime = delta;
} }
float JGE::GetDelta() float JGE::GetDelta()
{ {
return mDeltaTime; return mDeltaTime;
} }
float JGE::GetFPS() float JGE::GetFPS()
{ {
return mDeltaTime > 0 ? 1.0f / mDeltaTime : 0; return mDeltaTime > 0 ? 1.0f / mDeltaTime : 0;
} }
JGE* JGE::GetInstance() JGE* JGE::GetInstance()
{ {
if (mInstance == NULL) mInstance = new JGE(); if (mInstance == NULL) mInstance = new JGE();
return mInstance; return mInstance;
} }
void JGE::Destroy() void JGE::Destroy()
{ {
if (mInstance) if (mInstance)
{ {
delete mInstance; delete mInstance;
mInstance = NULL; mInstance = NULL;
} }
} }
void JGE::SetARGV(int argc, char * argv[]){ void JGE::SetARGV(int argc, char * argv[])
{
for (int i = 0; i < argc; ++i){ for (int i = 0; i < argc; ++i){
string s = argv[i]; string s = argv[i];
mArgv.push_back(s); mArgv.push_back(s);
} }
} }
std::vector<std::string> JGE::GetARGV() { std::vector<std::string> JGE::GetARGV()
{
return mArgv; return mArgv;
} }
void JGE::SetApp(JApp *app) void JGE::SetApp(JApp *app)
{ {
mApp = app; mApp = app;
} }
void JGE::Render() void JGE::Render()
{ {
JRenderer* renderer = JRenderer::GetInstance(); JRenderer* renderer = JRenderer::GetInstance();
renderer->BeginScene(); renderer->BeginScene();
if (mApp != NULL) mApp->Render(); if (mApp != NULL) mApp->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;
va_start(list, format);
vsprintf(mDebuggingMsg, format, list);
va_end(list);
va_start(list, format);
vsprintf(mDebuggingMsg, format, list);
va_end(list);
} }
void JGE::Pause() void JGE::Pause()
{ {
if (mPaused) return; if (mPaused) return;
mPaused = true; mPaused = true;
if (mApp != NULL) mApp->Pause(); if (mApp != NULL) mApp->Pause();
} }
void JGE::Resume() void JGE::Resume()
{ {
if (mPaused) if (mPaused)
{ {
mPaused = false; mPaused = false;
if (mApp != NULL) if (mApp != NULL)
mApp->Resume(); mApp->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;
}
void JGE::Scroll(int inXVelocity, int inYVelocity)
{
if (mApp != NULL)
{
mApp->OnScroll(inXVelocity, inYVelocity);
}
} }
std::queue< pair< pair<LocalKeySym, JButton>, bool> > JGE::keyBuffer; std::queue< pair< pair<LocalKeySym, JButton>, bool> > JGE::keyBuffer;
+12 -8
View File
@@ -45,6 +45,17 @@ const int kHitzonePliancy = 50;
// tick value equates to ms // tick value equates to ms
const int kTapEventTimeout = 250; const int kTapEventTimeout = 250;
uint64_t lastTickCount;
JGE* g_engine = NULL;
JApp* g_app = NULL;
JGameLauncher* g_launcher = NULL;
class SdlApp;
SdlApp *g_SdlApp = NULL;
class SdlApp class SdlApp
{ {
public: /* For easy interfacing with JGE static functions */ public: /* For easy interfacing with JGE static functions */
@@ -215,6 +226,7 @@ public:
case SDL_JOYBALLMOTION: case SDL_JOYBALLMOTION:
DebugTrace("Flick gesture detected, x: " << Event->jball.xrel << ", y: " << Event->jball.yrel); DebugTrace("Flick gesture detected, x: " << Event->jball.xrel << ", y: " << Event->jball.yrel);
g_engine->Scroll(Event->jball.xrel, Event->jball.yrel);
break; break;
} }
} }
@@ -228,14 +240,6 @@ public:
} }
}; };
uint64_t lastTickCount;
JGE* g_engine = NULL;
JApp* g_app = NULL;
JGameLauncher* g_launcher = NULL;
SdlApp *g_SdlApp = NULL;
static const struct { LocalKeySym keysym; JButton keycode; } gDefaultBindings[] = static const struct { LocalKeySym keysym; JButton keycode; } gDefaultBindings[] =
{ {
/* windows controls */ /* windows controls */
+2
View File
@@ -89,6 +89,8 @@ public:
virtual void Pause(); virtual void Pause();
virtual void Resume(); virtual void Resume();
virtual void OnScroll(int inXVelocity, int inYVelocity);
void LoadGameStates(); void LoadGameStates();
void SetNextState(int state); void SetNextState(int state);
void DoTransition(int trans, int tostate, float dur = -1, bool animonly = false); void DoTransition(int trans, int tostate, float dur = -1, bool animonly = false);
+4
View File
@@ -55,6 +55,10 @@ public:
virtual void Start(){} virtual void Start(){}
virtual void End(){} virtual void End(){}
virtual void OnScroll(int inXVelocity, int inYVelocity)
{
}
virtual void Update(float dt) = 0; virtual void Update(float dt) = 0;
virtual void Render() = 0; virtual void Render() = 0;
@@ -141,6 +141,8 @@ public:
int loadDeck(int deckid); int loadDeck(int deckid);
void LoadDeckStatistics(int deckId); void LoadDeckStatistics(int deckId);
void OnScroll(int inXVelocity, int inYVelocity);
void buildEditorMenu(); void buildEditorMenu();
virtual void ButtonPressed(int controllerId, int controlId); virtual void ButtonPressed(int controllerId, int controlId);
}; };
+8
View File
@@ -424,6 +424,14 @@ void GameApp::Render()
} }
void GameApp::OnScroll(int inXVelocity, int inYVelocity)
{
if (mCurrentState != NULL)
{
mCurrentState->OnScroll(inXVelocity, inYVelocity);
}
}
void GameApp::SetNextState(int state) void GameApp::SetNextState(int state)
{ {
mNextState = mGameStates[state]; mNextState = mGameStates[state];
+9
View File
@@ -1668,3 +1668,12 @@ void GameStateDeckViewer::ButtonPressed(int controllerId, int controlId)
} }
} }
void GameStateDeckViewer::OnScroll(int inXVelocity, int inYVelocity)
{
if (abs(inYVelocity) > 300)
{
bool flickUpwards = (inYVelocity < 0);
mEngine->HoldKey_NoRepeat(flickUpwards ? JGE_BTN_DOWN : JGE_BTN_UP);
}
}