From dcf0153b0c4cee132a3ce21bab2b222ed3703bc5 Mon Sep 17 00:00:00 2001 From: relnev Date: Wed, 8 Jan 2003 11:54:32 +0000 Subject: 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 --- Source/GameLoop.cpp | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 82 insertions(+), 1 deletion(-) (limited to 'Source/GameLoop.cpp') 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 -- cgit v1.2.3