Example #1
0
void UpdateInputState(u32 port)
{
  static char key = 0;

  kcode[port] = x11_dc_buttons;
  rt[port] = 0;
  lt[port] = 0;

  #if defined(TARGET_EMSCRIPTEN)
    return;
  #endif

  HandleJoystick(port);
  HandleKb(port);

  #if defined(TARGET_GCW0) || defined(TARGET_PANDORA)
    return;
  #endif

  for(;;)
  {
    key = 0;
    read(STDIN_FILENO, &key, 1);

    if (0  == key || EOF == key) { break; }
    if ('k' == key) { KillTex=true; }

    #ifdef TARGET_PANDORA
        if (' ' == key) { kcode[port] &= ~Btn_C; }
        if ('6' == key) { kcode[port] &= ~Btn_A; }
        if ('O' == key) { kcode[port] &= ~Btn_B; }
        if ('5' == key) { kcode[port] &= ~Btn_Y; }
        if ('H' == key) { kcode[port] &= ~Btn_X; }
        if ('A' == key) { kcode[port] &= ~DPad_Up; }
        if ('B' == key) { kcode[port] &= ~DPad_Down; }
        if ('D' == key) { kcode[port] &= ~DPad_Left; }
        if ('C' == key) { kcode[port] &= ~DPad_Right; }

        if ('q' == key) { die("death by escape key"); }
    #endif
    //if (0x1b == key){ die("death by escape key"); } //this actually quits when i press left for some reason

    if ('a' == key) { rt[port] = 255; }
    if ('s' == key) { lt[port] = 255; }

    #if FEAT_SHREC != DYNAREC_NONE
      if ('b' == key) { emit_WriteCodeCache(); }
      if ('n' == key) { bm_Reset(); }
      if ('m' == key) { bm_Sort(); }
      if (',' == key)
      {
        emit_WriteCodeCache();
        bm_Sort();
      }
    #endif
  }
}
void HandleNoEvent()
{
  if (button_status && game_status != GAME_MODE_PLAYING)
  {
    HandleButton(0, 0, -button_status, button_status);

    return;
  }

#if defined(NETWORK_AVALIABLE)
  if (options.network)
    HandleNetworking();
#endif

  HandleJoystick();
}
Example #3
0
void UpdateInputState(u32 port)
{
    static char key = 0;

    kcode[port]= x11_dc_buttons[port];
    rt[port]=0;
    lt[port]=0;

#if defined(TARGET_GCW0) || defined(TARGET_PANDORA)
    HandleJoystick(port);
    HandleKb(port);
return;
#elif defined(SUPPORT_X11)
    // kcode[port] = 0xFFFF;
    // Attempt to get input from a controller
    if (!HandleJoystick(port))
    {
        // Fallback to keyboard if no controller found
        HandleKb(port);
    }
    // Report the current buttons to the emulator
    report_controller_state(port);
    return;
#endif
    for(;;)
    {
        key = 0;
        read(STDIN_FILENO, &key, 1);

        if (0  == key || EOF == key) break;
        if ('k' == key) KillTex=true;

#ifdef TARGET_PANDORA
        if (' ' == key) { kcode[port] &= ~Btn_C; }
        if ('6' == key) { kcode[port] &= ~Btn_A; }
        if ('O' == key) { kcode[port] &= ~Btn_B; }
        if ('5' == key) { kcode[port] &= ~Btn_Y; }
        if ('H' == key) { kcode[port] &= ~Btn_X; }
        if ('A' == key) { kcode[port] &= ~DPad_Up;    }
        if ('B' == key) { kcode[port] &= ~DPad_Down;  }
        if ('D' == key) { kcode[port] &= ~DPad_Left;  }
        if ('C' == key) { kcode[port] &= ~DPad_Right; }
#else
        if ('b' == key) { kcode[port] &= ~Btn_C; }
        if ('v' == key) { kcode[port] &= ~Btn_A; }
        if ('c' == key) { kcode[port] &= ~Btn_B; }
        if ('x' == key) { kcode[port] &= ~Btn_Y; }
        if ('z' == key) { kcode[port] &= ~Btn_X; }
        if ('i' == key) { kcode[port] &= ~DPad_Up;    }
        if ('k' == key) { kcode[port] &= ~DPad_Down;  }
        if ('j' == key) { kcode[port] &= ~DPad_Left;  }
        if ('l' == key) { kcode[port] &= ~DPad_Right; }
#endif
        if (0x0A== key) { kcode[port] &= ~Btn_Start;  }
#ifdef TARGET_PANDORA
        if ('q' == key){ die("death by escape key"); }
#endif
        //if (0x1b == key){ die("death by escape key"); } //this actually quits when i press left for some reason

        if ('a' == key) rt[port]=255;
        if ('s' == key) lt[port]=255;
#if !defined(HOST_NO_REC)
        if ('b' == key) emit_WriteCodeCache();
        if ('n' == key) bm_Reset();
        if ('m' == key) bm_Sort();
        if (',' == key) { emit_WriteCodeCache(); bm_Sort(); }
#endif
    }
}
void HandleKey(Key key, int key_status)
{
  boolean anyTextGadgetActiveOrJustFinished = anyTextGadgetActive();
  static struct SetupKeyboardInfo ski;
  static struct SetupShortcutInfo ssi;
  static struct
  {
    Key *key_custom;
    Key *key_snap;
    Key key_default;
    byte action;
  } key_info[] =
  {
    { &ski.left,  &ssi.snap_left,  DEFAULT_KEY_LEFT,  JOY_LEFT        },
    { &ski.right, &ssi.snap_right, DEFAULT_KEY_RIGHT, JOY_RIGHT       },
    { &ski.up,    &ssi.snap_up,    DEFAULT_KEY_UP,    JOY_UP          },
    { &ski.down,  &ssi.snap_down,  DEFAULT_KEY_DOWN,  JOY_DOWN        },
    { &ski.snap,  NULL,            DEFAULT_KEY_SNAP,  JOY_BUTTON_SNAP },
    { &ski.drop,  NULL,            DEFAULT_KEY_DROP,  JOY_BUTTON_DROP }
  };
  int joy = 0;
  int i;

  if (game_status == GAME_MODE_PLAYING)
  {
    /* only needed for single-step tape recording mode */
    static boolean clear_button_2[MAX_PLAYERS] = { FALSE,FALSE,FALSE,FALSE };
    static boolean element_dropped[MAX_PLAYERS] = { FALSE,FALSE,FALSE,FALSE };
    int pnr;

    ssi = setup.shortcut;

    for (pnr = 0; pnr < MAX_PLAYERS; pnr++)
    {
      byte key_action = 0;

      if (setup.input[pnr].use_joystick)
	continue;

      ski = setup.input[pnr].key;

      for (i = 0; i < NUM_PLAYER_ACTIONS; i++)
	if (key == *key_info[i].key_custom)
	  key_action |= key_info[i].action;

      for (i = 0; i < NUM_DIRECTIONS; i++)
	if (key == *key_info[i].key_snap)
	  key_action |= key_info[i].action | JOY_BUTTON_SNAP;

      if (tape.single_step && clear_button_2[pnr])
      {
	stored_player[pnr].action &= ~KEY_BUTTON_2;
	clear_button_2[pnr] = FALSE;
      }

      if (key_status == KEY_PRESSED)
	stored_player[pnr].action |= key_action;
      else
	stored_player[pnr].action &= ~key_action;

      if (tape.single_step && tape.recording && tape.pausing)
      {
	if (key_status == KEY_PRESSED &&
	    (key_action & (KEY_MOTION | KEY_BUTTON_1)))
	{
	  TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);

	  if (key_action & KEY_MOTION)
	  {
	    if (stored_player[pnr].action & KEY_BUTTON_2)
	      element_dropped[pnr] = TRUE;
	  }
	}
	else if (key_status == KEY_RELEASED &&
		 (key_action & KEY_BUTTON_2))
	{
	  if (!element_dropped[pnr])
	  {
	    TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);

	    stored_player[pnr].action |= KEY_BUTTON_2;
	    clear_button_2[pnr] = TRUE;
	  }

	  element_dropped[pnr] = FALSE;
	}
      }
#if 1
      else if (tape.recording && tape.pausing)
      {
	/* prevent key release events from un-pausing a paused game */
	if (key_status == KEY_PRESSED &&
	    (key_action & KEY_ACTION))
	  TapeTogglePause(TAPE_TOGGLE_MANUAL);
      }
#else
      else if (tape.recording && tape.pausing && (key_action & KEY_ACTION))
	TapeTogglePause(TAPE_TOGGLE_MANUAL);
#endif
    }
  }
  else
  {
    for (i = 0; i < NUM_PLAYER_ACTIONS; i++)
      if (key == key_info[i].key_default)
	joy |= key_info[i].action;
  }

  if (joy)
  {
    if (key_status == KEY_PRESSED)
      key_joystick_mapping |= joy;
    else
      key_joystick_mapping &= ~joy;

    HandleJoystick();
  }

  if (game_status != GAME_MODE_PLAYING)
    key_joystick_mapping = 0;

  if (key_status == KEY_RELEASED)
    return;

  if ((key == KSYM_Return || key == KSYM_KP_Enter) &&
      (GetKeyModState() & KMOD_Alt) && video.fullscreen_available)
  {
    setup.fullscreen = !setup.fullscreen;

    ToggleFullscreenIfNeeded();

    if (game_status == GAME_MODE_SETUP)
      RedrawSetupScreenAfterFullscreenToggle();

    return;
  }

#if 0
  if (game_status == GAME_MODE_PLAYING && local_player->LevelSolved_GameEnd &&
      (key == KSYM_Return || key == setup.shortcut.toggle_pause))
#else
  if (game_status == GAME_MODE_PLAYING && AllPlayersGone &&
      (key == KSYM_Return || key == setup.shortcut.toggle_pause))
#endif
  {
    GameEnd();

    return;
  }

  if (game_status == GAME_MODE_MAIN &&
      (key == setup.shortcut.toggle_pause || key == KSYM_space))
  {
    StartGameActions(options.network, setup.autorecord, level.random_seed);

    return;
  }

  if (game_status == GAME_MODE_MAIN || game_status == GAME_MODE_PLAYING)
  {
    if (key == setup.shortcut.save_game)
      TapeQuickSave();
    else if (key == setup.shortcut.load_game)
      TapeQuickLoad();
    else if (key == setup.shortcut.toggle_pause)
      TapeTogglePause(TAPE_TOGGLE_MANUAL);

    HandleTapeButtonKeys(key);
    HandleSoundButtonKeys(key);
  }

  if (game_status == GAME_MODE_PLAYING && !network_playing)
  {
    int centered_player_nr_next = -999;

    if (key == setup.shortcut.focus_player_all)
      centered_player_nr_next = -1;
    else
      for (i = 0; i < MAX_PLAYERS; i++)
	if (key == setup.shortcut.focus_player[i])
	  centered_player_nr_next = i;

    if (centered_player_nr_next != -999)
    {
      game.centered_player_nr_next = centered_player_nr_next;
      game.set_centered_player = TRUE;

      if (tape.recording)
      {
	tape.centered_player_nr_next = game.centered_player_nr_next;
	tape.set_centered_player = TRUE;
      }
    }
  }

  HandleKeysSpecial(key);

  if (HandleGadgetsKeyInput(key))
  {
    if (key != KSYM_BackSpace)	/* always allow ESC key to be handled */
      key = KSYM_UNDEFINED;
  }

  switch (game_status)
  {
    case GAME_MODE_PSEUDO_TYPENAME:
      HandleTypeName(0, key);
      break;

    case GAME_MODE_TITLE:
    case GAME_MODE_MAIN:
    case GAME_MODE_LEVELS:
    case GAME_MODE_SETUP:
    case GAME_MODE_INFO:
    case GAME_MODE_SCORES:
      switch (key)
      {
	case KSYM_space:
	case KSYM_Return:
	  if (game_status == GAME_MODE_TITLE)
	    HandleTitleScreen(0, 0, 0, 0, MB_MENU_CHOICE);
	  else if (game_status == GAME_MODE_MAIN)
	    HandleMainMenu(0, 0, 0, 0, MB_MENU_CHOICE);
          else if (game_status == GAME_MODE_LEVELS)
            HandleChooseLevel(0, 0, 0, 0, MB_MENU_CHOICE);
	  else if (game_status == GAME_MODE_SETUP)
	    HandleSetupScreen(0, 0, 0, 0, MB_MENU_CHOICE);
	  else if (game_status == GAME_MODE_INFO)
	    HandleInfoScreen(0, 0, 0, 0, MB_MENU_CHOICE);
	  else if (game_status == GAME_MODE_SCORES)
	    HandleHallOfFame(0, 0, 0, 0, MB_MENU_CHOICE);
	  break;

	case KSYM_BackSpace:
	  if (game_status != GAME_MODE_MAIN)
	    FadeSkipNextFadeIn();

	  if (game_status == GAME_MODE_TITLE)
	    HandleTitleScreen(0, 0, 0, 0, MB_MENU_LEAVE);
          else if (game_status == GAME_MODE_LEVELS)
            HandleChooseLevel(0, 0, 0, 0, MB_MENU_LEAVE);
	  else if (game_status == GAME_MODE_SETUP)
	    HandleSetupScreen(0, 0, 0, 0, MB_MENU_LEAVE);
	  else if (game_status == GAME_MODE_INFO)
	    HandleInfoScreen(0, 0, 0, 0, MB_MENU_LEAVE);
	  else if (game_status == GAME_MODE_SCORES)
	    HandleHallOfFame(0, 0, 0, 0, MB_MENU_LEAVE);
	  break;

        case KSYM_Page_Up:
          if (game_status == GAME_MODE_LEVELS)
            HandleChooseLevel(0, 0, 0, -1 * SCROLL_PAGE, MB_MENU_MARK);
	  else if (game_status == GAME_MODE_SETUP)
	    HandleSetupScreen(0, 0, 0, -1 * SCROLL_PAGE, MB_MENU_MARK);
	  else if (game_status == GAME_MODE_INFO)
	    HandleInfoScreen(0, 0, 0, -1 * SCROLL_PAGE, MB_MENU_MARK);
	  else if (game_status == GAME_MODE_SCORES)
	    HandleHallOfFame(0, 0, 0, -1 * SCROLL_PAGE, MB_MENU_MARK);
	  break;

        case KSYM_Page_Down:
          if (game_status == GAME_MODE_LEVELS)
            HandleChooseLevel(0, 0, 0, +1 * SCROLL_PAGE, MB_MENU_MARK);
	  else if (game_status == GAME_MODE_SETUP)
	    HandleSetupScreen(0, 0, 0, +1 * SCROLL_PAGE, MB_MENU_MARK);
	  else if (game_status == GAME_MODE_INFO)
	    HandleInfoScreen(0, 0, 0, +1 * SCROLL_PAGE, MB_MENU_MARK);
	  else if (game_status == GAME_MODE_SCORES)
	    HandleHallOfFame(0, 0, 0, +1 * SCROLL_PAGE, MB_MENU_MARK);
	  break;

#ifdef DEBUG
	case KSYM_0:
	  GameFrameDelay = (GameFrameDelay == 500 ? GAME_FRAME_DELAY : 500);
	  break;

	case KSYM_b:
	  setup.sp_show_border_elements = !setup.sp_show_border_elements;
	  printf("Supaplex border elements %s\n",
		 setup.sp_show_border_elements ? "enabled" : "disabled");
	  break;
#endif

	default:
	  break;
      }
      break;

    case GAME_MODE_EDITOR:
      if (!anyTextGadgetActiveOrJustFinished || key == KSYM_BackSpace)
	HandleLevelEditorKeyInput(key);
      break;

    case GAME_MODE_PLAYING:
    {
      switch (key)
      {
        case KSYM_BackSpace:
	  RequestQuitGame(setup.ask_on_escape);
	  break;

#ifdef DEBUG
	case KSYM_0:
#if 0
	case KSYM_1:
	case KSYM_2:
	case KSYM_3:
	case KSYM_4:
	case KSYM_5:
	case KSYM_6:
	case KSYM_7:
	case KSYM_8:
	case KSYM_9:
#endif
	  if (key == KSYM_0)
	  {
	    if (GameFrameDelay == 500)
	      GameFrameDelay = GAME_FRAME_DELAY;
	    else
	      GameFrameDelay = 500;
	  }
	  else
	    GameFrameDelay = (key - KSYM_0) * 10;
	  printf("Game speed == %d%% (%d ms delay between two frames)\n",
		 GAME_FRAME_DELAY * 100 / GameFrameDelay, GameFrameDelay);
	  break;

	case KSYM_d:
	  if (options.debug)
	  {
	    options.debug = FALSE;
	    printf("debug mode disabled\n");
	  }
	  else
	  {
	    options.debug = TRUE;
	    printf("debug mode enabled\n");
	  }
	  break;

	case KSYM_S:
	  if (!global.fps_slowdown)
	  {
	    global.fps_slowdown = TRUE;
	    global.fps_slowdown_factor = 2;
	    printf("fps slowdown enabled -- display only every 2nd frame\n");
	  }
	  else if (global.fps_slowdown_factor == 2)
	  {
	    global.fps_slowdown_factor = 4;
	    printf("fps slowdown enabled -- display only every 4th frame\n");
	  }
	  else
	  {
	    global.fps_slowdown = FALSE;
	    global.fps_slowdown_factor = 1;
	    printf("fps slowdown disabled\n");
	  }
	  break;

	case KSYM_f:
	  ScrollStepSize = TILEX/8;
	  printf("ScrollStepSize == %d (1/8)\n", ScrollStepSize);
	  break;

	case KSYM_g:
	  ScrollStepSize = TILEX/4;
	  printf("ScrollStepSize == %d (1/4)\n", ScrollStepSize);
	  break;

	case KSYM_h:
	  ScrollStepSize = TILEX/2;
	  printf("ScrollStepSize == %d (1/2)\n", ScrollStepSize);
	  break;

	case KSYM_l:
	  ScrollStepSize = TILEX;
	  printf("ScrollStepSize == %d (1/1)\n", ScrollStepSize);
	  break;

	case KSYM_v:
	  printf("::: currently using game engine version %d\n",
		 game.engine_version);
	  break;
#endif

	default:
	  break;
      }
      break;
    }

    default:
      if (key == KSYM_BackSpace)
      {
	game_status = GAME_MODE_MAIN;
	DrawMainMenu();

	return;
      }
  }
}