aboutsummaryrefslogtreecommitdiff
path: root/Source/GameLoop.cpp
diff options
context:
space:
mode:
authorrelnev <relnev@5198baeb-e213-0410-be47-fc2ff85ca46f>2003-01-08 11:54:32 +0000
committerrelnev <relnev@5198baeb-e213-0410-be47-fc2ff85ca46f>2003-01-08 11:54:32 +0000
commitdcf0153b0c4cee132a3ce21bab2b222ed3703bc5 (patch)
treed542a47c303632dd99df43af72eee0335e9528d1 /Source/GameLoop.cpp
parent507a7479adb2cab5218bbb64950b739dcd79b6d5 (diff)
downloadblackshades-dcf0153b0c4cee132a3ce21bab2b222ed3703bc5.tar.gz
input -- only thing that should be missing is the rest of the keysyms
git-svn-id: svn://svn.icculus.org/blackshades/trunk@46 5198baeb-e213-0410-be47-fc2ff85ca46f
Diffstat (limited to 'Source/GameLoop.cpp')
-rw-r--r--Source/GameLoop.cpp83
1 files changed, 82 insertions, 1 deletions
diff --git a/Source/GameLoop.cpp b/Source/GameLoop.cpp
index 843ed10..ff0df15 100644
--- a/Source/GameLoop.cpp
+++ b/Source/GameLoop.cpp
@@ -206,6 +206,87 @@ void Game::DoEvent( EventRecord *event )
}
#endif
+#ifndef MAC
+static int mapinit = 0;
+static int sdlkeymap[SDLK_LAST];
+
+static unsigned char ourkeys[16];
+
+static void init_sdlkeymap()
+{
+ sdlkeymap[SDLK_1] = MAC_1_KEY;
+ sdlkeymap[SDLK_2] = MAC_2_KEY;
+
+ sdlkeymap[SDLK_a] = MAC_A_KEY;
+
+ sdlkeymap[SDLK_d] = MAC_D_KEY;
+
+ sdlkeymap[SDLK_s] = MAC_S_KEY;
+
+ sdlkeymap[SDLK_w] = MAC_W_KEY;
+
+ sdlkeymap[SDLK_SPACE] = MAC_SPACE_KEY;
+
+ mapinit = 1;
+}
+
+void GetKeys(unsigned long *keys)
+{
+ /* this is just weird */
+ memcpy(keys, ourkeys, sizeof(ourkeys));
+}
+
+static void DoSDLKey(Game *g, SDL_Event *event)
+{
+ int press = (event->type == SDL_KEYDOWN) ? 1 : 0;
+ int mackey;
+ int index;
+ int mask;
+
+ if (mapinit == 0) {
+ init_sdlkeymap();
+ }
+
+ mackey = sdlkeymap[event->key.keysym.sym];
+ index = mackey / 8;
+ mask = 1 << (mackey % 8);
+
+ if (press) {
+ ourkeys[index] |= mask;
+ } else {
+ ourkeys[index] &= ~mask;
+ }
+
+ if (event->key.keysym.unicode &&
+ !(event->key.keysym.unicode & 0xFF80)) {
+
+ /* hey, at least it was aleady public */
+ g->HandleKeyDown(event->key.keysym.unicode);
+ }
+
+
+}
+
+static void ProcessSDLEvents(Game *g)
+{
+ SDL_Event event;
+
+ if (SDL_PollEvent(&event)) {
+ do {
+ switch(event.type) {
+ case SDL_KEYDOWN:
+ case SDL_KEYUP:
+ DoSDLKey(g, &event);
+ break;
+ case SDL_QUIT:
+ exit(0);
+ }
+ } while (SDL_PollEvent(&event));
+ }
+}
+
+#endif
+
/********************> EventLoop() <*****/
void Game::EventLoop( void )
@@ -233,7 +314,7 @@ void Game::EventLoop( void )
DoEvent( &event );
#else
- STUB_FUNCTION;
+ ProcessSDLEvents(this);
#endif