J :
* Make it so that only 1 keypress for each key may be accepted for a single frame.
This commit is contained in:
+69
-6
@@ -42,6 +42,7 @@ int glWindowID = 0;
|
|||||||
static u32 gButtons = 0;
|
static u32 gButtons = 0;
|
||||||
static u32 gOldButtons = 0;
|
static u32 gOldButtons = 0;
|
||||||
static u32 gKeyPresses = 0;
|
static u32 gKeyPresses = 0;
|
||||||
|
static queue< pair<u32,u32> > gKeyBuffer;
|
||||||
|
|
||||||
static u32 gPSPKeyMasks[] =
|
static u32 gPSPKeyMasks[] =
|
||||||
{
|
{
|
||||||
@@ -113,6 +114,26 @@ static const unsigned char gNonGlutKeyCodes[] =
|
|||||||
KEY_ESCAPE
|
KEY_ESCAPE
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static bool gThisFrame[17] =
|
||||||
|
{
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false
|
||||||
|
};
|
||||||
|
|
||||||
GLvoid ReSizeGLScene(GLsizei width, GLsizei height) // Resize The GL Window
|
GLvoid ReSizeGLScene(GLsizei width, GLsizei height) // Resize The GL Window
|
||||||
{
|
{
|
||||||
@@ -121,6 +142,7 @@ GLvoid ReSizeGLScene(GLsizei width, GLsizei height) // Resize The GL Window
|
|||||||
glViewport(0, -((width/ACTUAL_RATIO)-height)/2, width, width / ACTUAL_RATIO); // Reset The Current Viewport
|
glViewport(0, -((width/ACTUAL_RATIO)-height)/2, width, width / ACTUAL_RATIO); // Reset The Current Viewport
|
||||||
else
|
else
|
||||||
glViewport(-(height*ACTUAL_RATIO-width)/2, 0, height * ACTUAL_RATIO, height);
|
glViewport(-(height*ACTUAL_RATIO-width)/2, 0, height * ACTUAL_RATIO, height);
|
||||||
|
glScissor(0, 0, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
GLvoid SizeGLScene(GLsizei width, GLsizei height) // Initialize The GL Window
|
GLvoid SizeGLScene(GLsizei width, GLsizei height) // Initialize The GL Window
|
||||||
@@ -164,7 +186,6 @@ int InitGL(void) // All Setup For OpenGL Goes Here
|
|||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
glEnable(GL_SCISSOR_TEST); // Enable Clipping
|
glEnable(GL_SCISSOR_TEST); // Enable Clipping
|
||||||
//glScissor(20, 20, 320, 240);
|
|
||||||
|
|
||||||
return true; // Initialization Went OK
|
return true; // Initialization Went OK
|
||||||
}
|
}
|
||||||
@@ -246,6 +267,8 @@ BOOL CreateGLWindow(char* title, int width, int height, int bits __attribute__((
|
|||||||
|
|
||||||
void JGEControl()
|
void JGEControl()
|
||||||
{
|
{
|
||||||
|
for (int i=0;i<17;i++)
|
||||||
|
gThisFrame[i] = false;
|
||||||
gOldButtons = gButtons;
|
gOldButtons = gButtons;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -331,18 +354,37 @@ void initGlut(int* argc, char* argv[])
|
|||||||
// glutInitWindowSize(ACTUAL_SCREEN_WIDTH, ACTUAL_SCREEN_HEIGHT);
|
// glutInitWindowSize(ACTUAL_SCREEN_WIDTH, ACTUAL_SCREEN_HEIGHT);
|
||||||
// I do not know why, but obviously the thing won't draw outside of whatever size the window
|
// I do not know why, but obviously the thing won't draw outside of whatever size the window
|
||||||
// has been CREATED with, regardless of what resize calls are made later
|
// has been CREATED with, regardless of what resize calls are made later
|
||||||
glutInitWindowSize(glutGet(GLUT_SCREEN_WIDTH), glutGet(GLUT_SCREEN_HEIGHT));
|
// glutInitWindowSize(glutGet(GLUT_SCREEN_WIDTH), glutGet(GLUT_SCREEN_HEIGHT));
|
||||||
|
glutInitWindowSize(ACTUAL_SCREEN_WIDTH, ACTUAL_SCREEN_HEIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void specialKey(int key, int x __attribute__((unused)), int y __attribute((unused)))
|
void specialKey(int key, int x __attribute__((unused)), int y __attribute((unused)))
|
||||||
{
|
{
|
||||||
for (signed int i = sizeof(gGlutKeyCodes)/sizeof(gGlutKeyCodes[0]); i > 0; --i)
|
for (signed int i = sizeof(gGlutKeyCodes)/sizeof(gGlutKeyCodes[0]); i > 0; --i)
|
||||||
if (gGlutKeyCodes[i] == key) { gButtons |= gPSPKeyMasks[i]; gKeyPresses |= gPSPKeyMasks[i]; return; }
|
if (gGlutKeyCodes[i] == key)
|
||||||
|
{
|
||||||
|
if (false == gThisFrame[i])
|
||||||
|
{
|
||||||
|
gThisFrame[i] = true;
|
||||||
|
gButtons |= gPSPKeyMasks[i];
|
||||||
|
gKeyPresses |= gPSPKeyMasks[i];
|
||||||
|
gKeyBuffer.push(make_pair(gPSPKeyMasks[i],0x8000+key));
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
void specialUp(int key, int x __attribute__((unused)), int y __attribute((unused)))
|
void specialUp(int key, int x __attribute__((unused)), int y __attribute((unused)))
|
||||||
{
|
{
|
||||||
for (signed int i = sizeof(gGlutKeyCodes)/sizeof(gGlutKeyCodes[0]); i > 0; --i)
|
for (signed int i = sizeof(gGlutKeyCodes)/sizeof(gGlutKeyCodes[0]); i > 0; --i)
|
||||||
if (gGlutKeyCodes[i] == key) { gButtons &= ~gPSPKeyMasks[i]; return; }
|
if (gGlutKeyCodes[i] == key)
|
||||||
|
{
|
||||||
|
if (false == gThisFrame[i])
|
||||||
|
{
|
||||||
|
gThisFrame[i] = true;
|
||||||
|
gButtons &= ~gPSPKeyMasks[i];
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
void normalKey(unsigned char key, int x __attribute__((unused)), int y __attribute((unused)))
|
void normalKey(unsigned char key, int x __attribute__((unused)), int y __attribute((unused)))
|
||||||
{
|
{
|
||||||
@@ -366,7 +408,7 @@ void normalKey(unsigned char key, int x __attribute__((unused)), int y __attribu
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (signed int i = sizeof(gNonGlutKeyCodes)/sizeof(gNonGlutKeyCodes[0]); i > 0; --i)
|
for (signed int i = sizeof(gNonGlutKeyCodes)/sizeof(gNonGlutKeyCodes[0]); i > 0; --i)
|
||||||
if (gNonGlutKeyCodes[i] == key) { gButtons |= gPSPKeyMasks[i]; gKeyPresses |= gPSPKeyMasks[i]; return; }
|
if (gNonGlutKeyCodes[i] == key) { gButtons |= gPSPKeyMasks[i]; gKeyPresses |= gPSPKeyMasks[i]; gKeyBuffer.push(make_pair(gPSPKeyMasks[i],key)); return; }
|
||||||
}
|
}
|
||||||
void normalUp(unsigned char key, int x __attribute__((unused)), int y __attribute((unused)))
|
void normalUp(unsigned char key, int x __attribute__((unused)), int y __attribute((unused)))
|
||||||
{
|
{
|
||||||
@@ -374,6 +416,27 @@ void normalUp(unsigned char key, int x __attribute__((unused)), int y __attribut
|
|||||||
if (gNonGlutKeyCodes[i] == key) { gButtons &= ~gPSPKeyMasks[i]; return; }
|
if (gNonGlutKeyCodes[i] == key) { gButtons &= ~gPSPKeyMasks[i]; return; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
u32 JGEReadKey()
|
||||||
|
{
|
||||||
|
if (gKeyBuffer.empty()) return 0;
|
||||||
|
u32 val = gKeyBuffer.front().first;
|
||||||
|
gKeyBuffer.pop();
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
u32 JGEReadLocalKey()
|
||||||
|
{
|
||||||
|
if (gKeyBuffer.empty()) return 0;
|
||||||
|
u32 val = gKeyBuffer.front().second;
|
||||||
|
gKeyBuffer.pop();
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
void JGEResetInput()
|
||||||
|
{
|
||||||
|
while (!gKeyBuffer.empty()) gKeyBuffer.pop();
|
||||||
|
}
|
||||||
|
|
||||||
void reshapeFunc(int width, int height)
|
void reshapeFunc(int width, int height)
|
||||||
{
|
{
|
||||||
ReSizeGLScene(width, height);
|
ReSizeGLScene(width, height);
|
||||||
@@ -396,7 +459,7 @@ int main(int argc, char* argv[])
|
|||||||
|
|
||||||
glutIdleFunc(&idleCallBack);
|
glutIdleFunc(&idleCallBack);
|
||||||
glutDisplayFunc(&displayCallBack);
|
glutDisplayFunc(&displayCallBack);
|
||||||
glutSetKeyRepeat(GLUT_KEY_REPEAT_OFF);
|
// glutSetKeyRepeat(GLUT_KEY_REPEAT_OFF);
|
||||||
glutSpecialFunc(&specialKey);
|
glutSpecialFunc(&specialKey);
|
||||||
glutKeyboardFunc(&normalKey);
|
glutKeyboardFunc(&normalKey);
|
||||||
glutSpecialUpFunc(&specialUp);
|
glutSpecialUpFunc(&specialUp);
|
||||||
|
|||||||
+35
-3
@@ -107,14 +107,38 @@ static u32 gWinKeyCodes[17] =
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static bool gThisFrame[17] =
|
||||||
|
{
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false
|
||||||
|
};
|
||||||
|
|
||||||
void JGEControl()
|
void JGEControl()
|
||||||
{
|
{
|
||||||
gOldButtons = gButtons;
|
gOldButtons = gButtons;
|
||||||
|
|
||||||
gButtons = 0;
|
gButtons = 0;
|
||||||
for (int i=0;i<17;i++)
|
for (int i=0;i<17;i++)
|
||||||
if (g_keys[gWinKeyCodes[i]])
|
{
|
||||||
gButtons |= gPSPKeyMasks[i];
|
gThisFrame[i] = false;
|
||||||
|
if (g_keys[gWinKeyCodes[i]])
|
||||||
|
gButtons |= gPSPKeyMasks[i];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -560,7 +584,15 @@ LRESULT CALLBACK WndProc( HWND hWnd, // Handle For This Window
|
|||||||
{
|
{
|
||||||
g_keys[wParam] = TRUE; // Set The Selected Key (wParam) To True
|
g_keys[wParam] = TRUE; // Set The Selected Key (wParam) To True
|
||||||
for (signed int i = sizeof(gWinKeyCodes)/sizeof(gWinKeyCodes[0]); i > 0; --i)
|
for (signed int i = sizeof(gWinKeyCodes)/sizeof(gWinKeyCodes[0]); i > 0; --i)
|
||||||
if (gWinKeyCodes[i] == wParam) { gKeyBuffer.push(make_pair(gPSPKeyMasks[i],0x8000+wParam)); return 0; }
|
if (gWinKeyCodes[i] == wParam)
|
||||||
|
{
|
||||||
|
if (false == gThisFrame[i])
|
||||||
|
{
|
||||||
|
gThisFrame[i] = true;
|
||||||
|
gKeyBuffer.push(make_pair(gPSPKeyMasks[i],0x8000+wParam));
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
break; // Break
|
break; // Break
|
||||||
|
|||||||
Reference in New Issue
Block a user