From a9e70c0bdcf20528a2a22552d507270a217bc814 Mon Sep 17 00:00:00 2001 From: "jean.chalard" Date: Mon, 24 Nov 2008 08:00:02 +0000 Subject: [PATCH] J : * Use iterators on vectors instead of indexes. --- JGE/src/Xmain.cpp | 22 +++++++++++----------- JGE/src/winmain.cpp | 17 +++++++---------- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/JGE/src/Xmain.cpp b/JGE/src/Xmain.cpp index e9dab0f68..e3587f2f5 100644 --- a/JGE/src/Xmain.cpp +++ b/JGE/src/Xmain.cpp @@ -210,7 +210,7 @@ BOOL CreateGLWindow(char* title, int width, int height, int bits __attribute__(( } for (signed int i = sizeof(gDefaultBindings)/sizeof(gDefaultBindings[0]) - 1; i >= 0; --i) - gKeyCodes[i] = make_pair(XKeysymToKeycode(gXDisplay, gDefaultBindings[i].keysym), gDefaultBindings[i].pspCode); + gKeyCodes.push_back(make_pair(XKeysymToKeycode(gXDisplay, gDefaultBindings[i].keysym), gDefaultBindings[i].pspCode)); // Get a suitable framebuffer config int numReturned; @@ -436,22 +436,22 @@ int main(int argc, char* argv[]) case KeyPress: if (XKeycodeToKeysym(gXDisplay, event.xkey.keycode, 1) == XK_F) fullscreen(); - for (signed int i = gKeyCodes.size() - 1; i >= 0; --i) - if (event.xkey.keycode == gKeyCodes[i].first) + for (vector< pair >::iterator it = gKeyCodes.begin(); it != gKeyCodes.end(); ++it) + if (event.xkey.keycode == it->first) { - if (!(gHolds & gKeyCodes[i].second)) - gKeyBuffer.push(gKeyCodes[i]); - gControllerState |= gKeyCodes[i].second; - gHolds |= gKeyCodes[i].second; + if (!(gHolds & it->second)) + gKeyBuffer.push(*it); + gControllerState |= it->second; + gHolds |= it->second; break; } break; case KeyRelease: - for (signed int i = sizeof(gKeyCodes)/sizeof(gKeyCodes[0]) - 1; i >= 0; --i) - if (event.xkey.keycode == gKeyCodes[i].first) + for (vector< pair >::iterator it = gKeyCodes.begin(); it != gKeyCodes.end(); ++it) + if (event.xkey.keycode == it->first) { - gControllerState &= ~gKeyCodes[i].second; - gHolds &= ~gKeyCodes[i].second; + gControllerState &= ~it->second; + gHolds &= ~it->second; break; } break; diff --git a/JGE/src/winmain.cpp b/JGE/src/winmain.cpp index e68a96deb..5219706f0 100644 --- a/JGE/src/winmain.cpp +++ b/JGE/src/winmain.cpp @@ -190,11 +190,9 @@ void JGEControl() gOldButtons = gButtons; gButtons = 0; - for (int i = gKeyCodes.size() - 1; i >= 0; --i) - { - if (g_keys[gKeyCodes[i].first]) - gButtons |= gKeyCodes[i].second; - } + for (vector< pair >::iterator it = gKeyCodes.begin(); it != gKeyCodes.end(); ++it) + if (g_keys[it->first]) + gButtons |= it->second; } @@ -601,9 +599,8 @@ LRESULT CALLBACK WndProc( HWND hWnd, // Handle For This Window WPARAM wParam, // Additional Message Information LPARAM lParam) // Additional Message Information { - gKeyCodes.reserve(sizeof(gDefaultBindings)/sizeof(gDefaultBindings[0])); for (signed int i = sizeof(gDefaultBindings)/sizeof(gDefaultBindings[0]) - 1; i >= 0; --i) - gKeyCodes[i] = make_pair(gDefaultBindings[i].keysym, gDefaultBindings[i].pspCode); + gKeyCodes.push_back(make_pair(gDefaultBindings[i].keysym, gDefaultBindings[i].pspCode)); switch (uMsg) // Check For Windows Messages { @@ -649,9 +646,9 @@ LRESULT CALLBACK WndProc( HWND hWnd, // Handle For This Window if (false == g_holds[wParam]) { g_holds[wParam] = true; - for (signed int i = gKeyCodes.size() - 1; i >= 0; --i) - if (gKeyCodes[i].first == wParam) - gKeyBuffer.push(gKeyCodes[i]); + for (vector< pair >::iterator it = gKeyCodes.begin(); it != gKeyCodes.end(); ++it) + if (it->first == wParam) + gKeyBuffer.push(*it); } return 0; }