SDL_Scancode GetKey(EventHandlers *handlers) { SDL_Scancode k = SDL_SCANCODE_UNKNOWN; do { EventPoll(handlers, SDL_GetTicks()); k = KeyGetPressed(&handlers->keyboard); } while (k == SDL_SCANCODE_UNKNOWN); return k; }
SDL_Scancode EventWaitKeyOrText(EventHandlers *handlers) { SDL_Scancode k = SDL_SCANCODE_UNKNOWN; do { EventPoll(handlers, SDL_GetTicks()); k = KeyGetPressed(&handlers->keyboard); } while (k == SDL_SCANCODE_UNKNOWN && handlers->keyboard.Typed[0] == '\0'); return k; }
int GetKey(keyboard_t *keyboard) { int key_pressed = 0; do { KeyPoll(keyboard); key_pressed = KeyGetPressed(keyboard); } while (!key_pressed); return key_pressed; }
static void EditCampaign(void) { int xc = 0, yc = 0; int xcOld, ycOld; Mission scrap; memset(&scrap, 0, sizeof scrap); gCampaign.seed = 0; Setup(1); SDL_EnableKeyRepeat(0, 0); Uint32 ticksNow = SDL_GetTicks(); sTicksElapsed = 0; ticksAutosave = AUTOSAVE_INTERVAL_SECONDS * 1000; for (;;) { Uint32 ticksThen = ticksNow; ticksNow = SDL_GetTicks(); sTicksElapsed += ticksNow - ticksThen; if (sTicksElapsed < 1000 / FPS_FRAMELIMIT * 2) { SDL_Delay(1); debug(D_VERBOSE, "Delaying 1 ticksNow %u elapsed %u\n", ticksNow, sTicksElapsed); continue; } debug(D_MAX, "Polling for input\n"); EventPoll(&gEventHandlers, SDL_GetTicks()); int c = KeyGetPressed(&gEventHandlers.keyboard); int m = MouseGetPressed(&gEventHandlers.mouse); debug(D_MAX, "Handling input\n"); HandleInputResult result = HandleInput( c, m, &xc, &yc, &xcOld, &ycOld, &scrap); if (result.Done) { break; } if (result.Redraw || result.RemakeBg || sJustLoaded) { sJustLoaded = false; debug(D_MAX, "Drawing UI\n"); Display(&gGraphicsDevice, yc, result); if (result.WillDisplayAutomap) { GetKey(&gEventHandlers); } } debug(D_MAX, "End loop\n"); SDL_Delay(10); } }