/** * @brief Check call to SDL_GetScancodeFromName * * @sa http://wiki.libsdl.org/moin.cgi/SDL_GetScancodeFromName * @sa http://wiki.libsdl.org/moin.cgi/SDL_Keycode */ int keyboard_getScancodeFromName(void *arg) { SDL_Scancode scancode; /* Regular key, 1 character, first name in list */ scancode = SDL_GetScancodeFromName("A"); SDLTest_AssertPass("Call to SDL_GetScancodeFromName('A')"); SDLTest_AssertCheck(scancode == SDL_SCANCODE_A, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_A, scancode); /* Regular key, 1 character */ scancode = SDL_GetScancodeFromName("4"); SDLTest_AssertPass("Call to SDL_GetScancodeFromName('4')"); SDLTest_AssertCheck(scancode == SDL_SCANCODE_4, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_4, scancode); /* Regular key, 2 characters */ scancode = SDL_GetScancodeFromName("F1"); SDLTest_AssertPass("Call to SDL_GetScancodeFromName('F1')"); SDLTest_AssertCheck(scancode == SDL_SCANCODE_F1, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_F1, scancode); /* Regular key, 3 characters */ scancode = SDL_GetScancodeFromName("End"); SDLTest_AssertPass("Call to SDL_GetScancodeFromName('End')"); SDLTest_AssertCheck(scancode == SDL_SCANCODE_END, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_END, scancode); /* Regular key, 4 characters */ scancode = SDL_GetScancodeFromName("Find"); SDLTest_AssertPass("Call to SDL_GetScancodeFromName('Find')"); SDLTest_AssertCheck(scancode == SDL_SCANCODE_FIND, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_FIND, scancode); /* Regular key, several characters */ scancode = SDL_GetScancodeFromName("Backspace"); SDLTest_AssertPass("Call to SDL_GetScancodeFromName('Backspace')"); SDLTest_AssertCheck(scancode == SDL_SCANCODE_BACKSPACE, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_BACKSPACE, scancode); /* Regular key, several characters with space */ scancode = SDL_GetScancodeFromName("Keypad Enter"); SDLTest_AssertPass("Call to SDL_GetScancodeFromName('Keypad Enter')"); SDLTest_AssertCheck(scancode == SDL_SCANCODE_KP_ENTER, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_KP_ENTER, scancode); /* Regular key, last name in list */ scancode = SDL_GetScancodeFromName("Sleep"); SDLTest_AssertPass("Call to SDL_GetScancodeFromName('Sleep')"); SDLTest_AssertCheck(scancode == SDL_SCANCODE_SLEEP, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_SLEEP, scancode); return TEST_COMPLETED; }
SDLKey SDL_GetKeyFromName(const char *name) { int key; /* Check input */ if (name == NULL) return SDLK_UNKNOWN; /* If it's a single UTF-8 character, then that's the keycode itself */ key = *reinterpret_cast<const unsigned char *>(name); if (key >= 0xF0) { if (SDL_strlen(name) == 4) { int i = 0; key = static_cast<Uint16>((name[i]&0x07) << 18); key |= static_cast<Uint16>((name[++i]&0x3F) << 12); key |= static_cast<Uint16>((name[++i]&0x3F) << 6); key |= static_cast<Uint16>((name[++i]&0x3F)); return static_cast<SDLKey>(key); } return SDLK_UNKNOWN; } else if (key >= 0xE0) { if (SDL_strlen(name) == 3) { int i = 0; key = static_cast<Uint16>((name[i]&0x0F) << 12); key |= static_cast<Uint16>((name[++i]&0x3F) << 6); key |= static_cast<Uint16>((name[++i]&0x3F)); return static_cast<SDLKey>(key); } return SDLK_UNKNOWN; } else if (key >= 0xC0) { if (SDL_strlen(name) == 2) { int i = 0; key = static_cast<Uint16>((name[i]&0x1F) << 6); key |= static_cast<Uint16>((name[++i]&0x3F)); return static_cast<SDLKey>(key); } return SDLK_UNKNOWN; } else { if (SDL_strlen(name) == 1) { if (key >= 'A' && key <= 'Z') { key += 32; } return static_cast<SDLKey>(key); } /* Get the scancode for this name, and the associated keycode */ return static_cast<SDLKey>(SDL_default_keymap[SDL_GetScancodeFromName(name)]); } }
PIN_KeyboardKeyComboSet* PIN_KeyboardManager::BuildComboSet(PIN_String comboData) { std::string strData(comboData); std::string::const_iterator start, end; start = strData.begin(); end = strData.end(); boost::match_results<std::string::const_iterator> what; boost::match_flag_type flags = boost::match_default; PIN_KeyboardKeyComboSet* newSet = new PIN_KeyboardKeyComboSet(); std::string strComboString(""); while(regex_search(start, end, what, _keyListRegex, flags)) { std::string strX = what[0].str(); SDL_Scancode code = SDL_GetScancodeFromName(strX.c_str()); strComboString+=std::string(start,what[0].first) + PIN_KEYFORMAT; newSet->ComboKeys.push_back(code); // update search position: start = what[0].second; // update flags: flags |= boost::match_prev_avail; flags |= boost::match_not_bob; } strComboString+=std::string(start,end); newSet->ComboString = new char[PIN_MAXBUFFER_SIZE]; memset(newSet->ComboString,0,PIN_MAXBUFFER_SIZE); strcat(newSet->ComboString,strComboString.c_str()); if(newSet->ComboKeys.size() > 0) { return newSet; } else { return NULL; } }
KeyboardFilter MODIFIER(std::initializer_list<std::string> modifiers) { std::set<SDL_Scancode> modifierset; for (std::string modifier : modifiers) { SDL_Scancode modifiercode = SDL_GetScancodeFromName(modifier.c_str()); if (modifiercode == SDL_SCANCODE_UNKNOWN) { throw std::runtime_error("unrecognized modifier: " + modifier); } modifierset.insert(modifiercode); } return [modifierset] (KeyboardInputEvent event) { for (auto modifiercode : modifierset) { if (event.manager->is_scan_down(modifiercode)) { return true; } } return false; }; }
void input_set_default() { // Set default input config player[0].u = SDL_GetScancodeFromName("Up"); player[0].d = SDL_GetScancodeFromName("Down"); player[0].l = SDL_GetScancodeFromName("Left"); player[0].r = SDL_GetScancodeFromName("Right"); player[0].select = SDL_GetScancodeFromName("Right Shift"); player[0].start = SDL_GetScancodeFromName("Right Ctrl"); player[0].a = SDL_GetScancodeFromName("Z"); player[0].b = SDL_GetScancodeFromName("A"); player[0].ta = SDL_GetScancodeFromName("X"); player[0].tb = SDL_GetScancodeFromName("S"); player[0].ju = input_translate_string("j0h01"); player[0].jd = input_translate_string("j0h04"); player[0].jl = input_translate_string("j0h08"); player[0].jr = input_translate_string("j0h02"); player[0].jselect = input_translate_string("j0b8"); player[0].jstart = input_translate_string("j0b9"); player[0].ja = input_translate_string("j0b1"); player[0].jb = input_translate_string("j0b0"); player[0].jta = input_translate_string("j0b2"); player[0].jtb = input_translate_string("j0b3"); player[1].u = SDL_GetScancodeFromName("I"); player[1].d = SDL_GetScancodeFromName("K"); player[1].l = SDL_GetScancodeFromName("J"); player[1].r = SDL_GetScancodeFromName("L"); player[1].select = SDL_GetScancodeFromName("Left Shift"); player[1].start = SDL_GetScancodeFromName("Left Ctrl"); player[1].a = SDL_GetScancodeFromName("M"); player[1].b = SDL_GetScancodeFromName("N"); player[1].ta = SDL_GetScancodeFromName("B"); player[1].tb = SDL_GetScancodeFromName("V"); player[1].ju = input_translate_string("j1h01"); player[1].jd = input_translate_string("j1h04"); player[1].jl = input_translate_string("j1h08"); player[1].jr = input_translate_string("j1h02"); player[1].jselect = input_translate_string("j1b8"); player[1].jstart = input_translate_string("j1b9"); player[1].ja = input_translate_string("j1b1"); player[1].jb = input_translate_string("j1b0"); player[1].jta = input_translate_string("j1b2"); player[1].jtb = input_translate_string("j1b3"); }
void input_config_read() { // Read the input config file snprintf(inputconfpath, sizeof(inputconfpath), "%sinput.conf", nstpaths.nstdir); if (ini_parse(inputconfpath, input_config_match, &inputconf) < 0) { fprintf(stderr, "Failed to load input config file %s: Using defaults.\n", inputconfpath); } else { // Map the input settings from the config file // Player 1 player[0].u = SDL_GetScancodeFromName(inputconf.kb_p1u); player[0].d = SDL_GetScancodeFromName(inputconf.kb_p1d); player[0].l = SDL_GetScancodeFromName(inputconf.kb_p1l); player[0].r = SDL_GetScancodeFromName(inputconf.kb_p1r); player[0].select = SDL_GetScancodeFromName(inputconf.kb_p1select); player[0].start = SDL_GetScancodeFromName(inputconf.kb_p1start); player[0].a = SDL_GetScancodeFromName(inputconf.kb_p1a); player[0].b = SDL_GetScancodeFromName(inputconf.kb_p1b); player[0].ta = SDL_GetScancodeFromName(inputconf.kb_p1ta); player[0].tb = SDL_GetScancodeFromName(inputconf.kb_p1tb); player[0].ju = input_translate_string(inputconf.js_p1u); player[0].jd = input_translate_string(inputconf.js_p1d); player[0].jl = input_translate_string(inputconf.js_p1l); player[0].jr = input_translate_string(inputconf.js_p1r); player[0].jselect = input_translate_string(inputconf.js_p1select); player[0].jstart = input_translate_string(inputconf.js_p1start); player[0].ja = input_translate_string(inputconf.js_p1a); player[0].jb = input_translate_string(inputconf.js_p1b); player[0].jta = input_translate_string(inputconf.js_p1ta); player[0].jtb = input_translate_string(inputconf.js_p1tb); // Player 2 player[1].u = SDL_GetScancodeFromName(inputconf.kb_p2u); player[1].d = SDL_GetScancodeFromName(inputconf.kb_p2d); player[1].l = SDL_GetScancodeFromName(inputconf.kb_p2l); player[1].r = SDL_GetScancodeFromName(inputconf.kb_p2r); player[1].select = SDL_GetScancodeFromName(inputconf.kb_p2select); player[1].start = SDL_GetScancodeFromName(inputconf.kb_p2start); player[1].a = SDL_GetScancodeFromName(inputconf.kb_p2a); player[1].b = SDL_GetScancodeFromName(inputconf.kb_p2b); player[1].ta = SDL_GetScancodeFromName(inputconf.kb_p2ta); player[1].tb = SDL_GetScancodeFromName(inputconf.kb_p2tb); player[1].ju = input_translate_string(inputconf.js_p2u); player[1].jd = input_translate_string(inputconf.js_p2d); player[1].jl = input_translate_string(inputconf.js_p2l); player[1].jr = input_translate_string(inputconf.js_p2r); player[1].jselect = input_translate_string(inputconf.js_p2select); player[1].jstart = input_translate_string(inputconf.js_p2start); player[1].ja = input_translate_string(inputconf.js_p2a); player[1].jb = input_translate_string(inputconf.js_p2b); player[1].jta = input_translate_string(inputconf.js_p2ta); player[1].jtb = input_translate_string(inputconf.js_p2tb); } }
void menu_listen_tick(component *c) { listen_menu_data *local = menu_get_userdata(c); game_state *gs = local->s->gs; if(local->host) { ENetEvent event; if(enet_host_service(local->host, &event, 0) > 0 && event.type == ENET_EVENT_TYPE_CONNECT) { ENetPacket * packet = enet_packet_create("0", 2, ENET_PACKET_FLAG_RELIABLE); enet_peer_send(event.peer, 0, packet); enet_host_flush(local->host); DEBUG("client connected!"); controller *player1_ctrl, *player2_ctrl; keyboard_keys *keys; game_player *p1 = game_state_get_player(gs, 0); game_player *p2 = game_state_get_player(gs, 1); // force the speed to 3 game_state_set_speed(gs, 10); p1->har_id = HAR_JAGUAR; p1->pilot_id = 0; p2->har_id = HAR_JAGUAR; p2->pilot_id = 0; player1_ctrl = malloc(sizeof(controller)); controller_init(player1_ctrl); player1_ctrl->har = p1->har; player2_ctrl = malloc(sizeof(controller)); controller_init(player2_ctrl); player2_ctrl->har = p2->har; // Player 1 controller -- Keyboard settings_keyboard *k = &settings_get()->keys; keys = malloc(sizeof(keyboard_keys)); keys->jump_up = SDL_GetScancodeFromName(k->key1_jump_up); keys->jump_right = SDL_GetScancodeFromName(k->key1_jump_right); keys->walk_right = SDL_GetScancodeFromName(k->key1_walk_right); keys->duck_forward = SDL_GetScancodeFromName(k->key1_duck_forward); keys->duck = SDL_GetScancodeFromName(k->key1_duck); keys->duck_back = SDL_GetScancodeFromName(k->key1_duck_back); keys->walk_back = SDL_GetScancodeFromName(k->key1_walk_back); keys->jump_left = SDL_GetScancodeFromName(k->key1_jump_left); keys->punch = SDL_GetScancodeFromName(k->key1_punch); keys->kick = SDL_GetScancodeFromName(k->key1_kick); keys->escape = SDL_GetScancodeFromName(k->key1_escape); keyboard_create(player1_ctrl, keys, 0); game_player_set_ctrl(p1, player1_ctrl); // Player 2 controller -- Network net_controller_create(player2_ctrl, local->host, event.peer, ROLE_SERVER); game_player_set_ctrl(p2, player2_ctrl); game_player_set_selectable(p2, 1); chr_score_set_difficulty(game_player_get_score(game_state_get_player(gs, 0)), AI_DIFFICULTY_CHAMPION); chr_score_set_difficulty(game_player_get_score(game_state_get_player(gs, 1)), AI_DIFFICULTY_CHAMPION); } game_player *p2 = game_state_get_player(gs, 1); controller *c2 = game_player_get_ctrl(p2); if (c2->type == CTRL_TYPE_NETWORK && net_controller_ready(c2) == 1) { DEBUG("network peer is ready, tick offset is %d and rtt is %d", net_controller_tick_offset(c2), c2->rtt); local->host = NULL; game_state_set_next(gs, SCENE_MELEE); } } }
C4KeyCode C4KeyCodeEx::String2KeyCode(const StdStrBuf &sName) { // direct key code? if (sName.getLength() > 2) { unsigned int dwRVal; if (sscanf(sName.getData(), "\\x%x", &dwRVal) == 1) return dwRVal; // scan code if (*sName.getData() == '$') return GetKeyByScanCode(sName.getData()); // direct gamepad code #ifdef _WIN32 if (!strnicmp(sName.getData(), "Joy", 3)) #else if (!strncasecmp(sName.getData(), "Joy", 3)) #endif { int iGamepad; if (sscanf(sName.getData(), "Joy%d", &iGamepad) == 1) { // skip Joy[number] const char *key_str = sName.getData()+4; while (isdigit(*key_str)) ++key_str; // check for button (single, uppercase letter) (e.g. Joy1A) if (*key_str && !key_str[1]) { char cGamepadButton = toupper(*key_str); if (Inside(cGamepadButton, 'A', 'Z')) { cGamepadButton = cGamepadButton - 'A'; return KEY_Gamepad(iGamepad-1, KEY_JOY_Button(cGamepadButton)); } } else { // check for standard axis (e.g. Joy1Left) if (!stricmp(key_str, "Left")) return KEY_Gamepad(iGamepad-1, KEY_JOY_Left); if (!stricmp(key_str, "Up")) return KEY_Gamepad(iGamepad-1, KEY_JOY_Up); if (!stricmp(key_str, "Down")) return KEY_Gamepad(iGamepad-1, KEY_JOY_Down); if (!stricmp(key_str, "Right")) return KEY_Gamepad(iGamepad-1, KEY_JOY_Right); // check for specific axis (e.g. Joy1Axis1Min) int iAxis; if (sscanf(key_str, "Axis%d", &iAxis) == 1 && iAxis>0) { --iAxis; // axis is 0-based internally but written 1-based in config key_str += 5; while (isdigit(*key_str)) ++key_str; if (!stricmp(key_str, "Min")) return KEY_Gamepad(iGamepad-1, KEY_JOY_Axis(iAxis, false)); if (!stricmp(key_str, "Max")) return KEY_Gamepad(iGamepad-1, KEY_JOY_Axis(iAxis, true)); } } } } bool is_mouse_key; #ifdef _WIN32 is_mouse_key = !strnicmp(sName.getData(), "Mouse", 5); #else is_mouse_key = !strncasecmp(sName.getData(), "Mouse", 5); #endif if (is_mouse_key) { // skip Mouse/GameMouse const char *key_str = sName.getData()+5; int mouse_id; if (sscanf(key_str, "%d", &mouse_id) == 1) { // skip number while (isdigit(*key_str)) ++key_str; // check for known mouse events (e.g. Mouse1Move or GameMouse1Wheel) if (!stricmp(key_str, "Move")) return KEY_Mouse(mouse_id-1, KEY_MOUSE_Move); if (!stricmp(key_str, "Wheel1Up")) return KEY_Mouse(mouse_id-1, KEY_MOUSE_Wheel1Up); if (!stricmp(key_str, "Wheel1Down")) return KEY_Mouse(mouse_id-1, KEY_MOUSE_Wheel1Down); if (SEqualNoCase(key_str, "Button", 6)) // e.g. Mouse1ButtonLeft or GameMouse1ButtonRightDouble { // check for known mouse button events uint8_t mouseevent_id = 0; key_str += 6; if (SEqualNoCase(key_str, "Left",4)) { mouseevent_id=KEY_MOUSE_ButtonLeft; key_str += 4; } else if (SEqualNoCase(key_str, "Right",5)) { mouseevent_id=KEY_MOUSE_ButtonRight; key_str += 5; } else if (SEqualNoCase(key_str, "Middle",6)) { mouseevent_id=KEY_MOUSE_ButtonMiddle; key_str += 6; } else if (isdigit(*key_str)) { // indexed mouse button (e.g. Mouse1Button4 or Mouse1Button4Double) int button_index; if (sscanf(key_str, "%d", &button_index) == 1) { mouseevent_id=static_cast<uint8_t>(KEY_MOUSE_Button1+button_index-1); while (isdigit(*key_str)) ++key_str; } } if (mouseevent_id) { // valid event if finished or followed by "Double" if (!*key_str) return KEY_Mouse(mouse_id-1, mouseevent_id); if (!stricmp(key_str, "Double")) return KEY_Mouse(mouse_id-1, mouseevent_id+(KEY_MOUSE_Button1Double-KEY_MOUSE_Button1)); // invalid mouse key... } } } } } // query map const C4KeyCodeMapEntry *pCheck = KeyCodeMap; while (pCheck->szName) { if (SEqualNoCase(sName.getData(), pCheck->szName)) { return(pCheck->wCode); } ++pCheck; } #if defined(USE_SDL_MAINLOOP) SDL_Scancode s = SDL_GetScancodeFromName(sName.getData()); if (s != SDL_SCANCODE_UNKNOWN) return s; #endif return KEY_Undefined; }
uint8 input_keydown (const char *key) { return !!input_keys [SDL_GetScancodeFromName (key)]; }
hotkey_ptr load_from_config(const config& cfg) { hotkey_ptr base = hotkey_ptr(new hotkey_void()); const std::string& mouse_cfg = cfg["mouse"]; if (!mouse_cfg.empty()) { hotkey_mouse_ptr mouse(new hotkey_mouse()); base = std::dynamic_pointer_cast<hotkey_base>(mouse); mouse->set_button(cfg["button"].to_int()); } // TODO: add joystick support back #if 0 const std::string& joystick_cfg = cfg["joystick"]; if (!joystick_cfg.empty()) { joystick_ = cfg["joystick"].to_int(); } const std::string& hat = cfg["hat"]; if (!hat.empty()) { hat_ = cfg["hat"].to_int(); value_ = cfg["value"].to_int(); } const std::string& button = cfg["button"]; if (!button.empty()) { button_ = cfg["button"].to_int(); } #endif const std::string& key_cfg = cfg["key"]; if (!key_cfg.empty()) { hotkey_keyboard_ptr keyboard(new hotkey_keyboard()); base = std::dynamic_pointer_cast<hotkey_base>(keyboard); SDL_Scancode scancode = SDL_GetScancodeFromName(key_cfg.c_str()); if (scancode == SDL_SCANCODE_UNKNOWN) { ERR_G<< "Unknown key: " << key_cfg << "\n"; } keyboard->set_scancode(scancode); } if (base == hotkey_ptr()) { return base; } unsigned int mods = 0; if (cfg["shift"].to_bool()) mods |= KMOD_SHIFT; if (cfg["ctrl"].to_bool()) mods |= KMOD_CTRL; if (cfg["cmd"].to_bool()) mods |= KMOD_GUI; if (cfg["alt"].to_bool()) mods |= KMOD_ALT; base->set_mods(mods); base->set_command(cfg["command"].str()); cfg["disabled"].to_bool() ? base->disable() : base->enable(); return base; }
void input_set_default() { // Set default input config ui.qsave1 = SDL_GetScancodeFromName("F5"); ui.qsave2 = SDL_GetScancodeFromName("F6"); ui.qload1 = SDL_GetScancodeFromName("F7"); ui.qload2 = SDL_GetScancodeFromName("F8"); ui.screenshot = SDL_GetScancodeFromName("F9"); ui.fdsflip = SDL_GetScancodeFromName("F3"); ui.fdsswitch = SDL_GetScancodeFromName("F4"); ui.insertcoin1 = SDL_GetScancodeFromName("F1"); ui.insertcoin2 = SDL_GetScancodeFromName("F2"); ui.reset = SDL_GetScancodeFromName("F12"); ui.altspeed = SDL_GetScancodeFromName("`"); ui.rwstart = SDL_GetScancodeFromName("Backspace"); ui.rwstop = SDL_GetScancodeFromName("\\"); ui.fullscreen = SDL_GetScancodeFromName("F"); ui.filter = SDL_GetScancodeFromName("T"); ui.scalefactor = SDL_GetScancodeFromName("G"); player[0].u = SDL_GetScancodeFromName("Up"); player[0].d = SDL_GetScancodeFromName("Down"); player[0].l = SDL_GetScancodeFromName("Left"); player[0].r = SDL_GetScancodeFromName("Right"); player[0].select = SDL_GetScancodeFromName("Right Shift"); player[0].start = SDL_GetScancodeFromName("Return"); player[0].a = SDL_GetScancodeFromName("Z"); player[0].b = SDL_GetScancodeFromName("A"); player[0].ta = SDL_GetScancodeFromName("X"); player[0].tb = SDL_GetScancodeFromName("S"); player[0].ju = input_translate_string("j0h01"); player[0].jd = input_translate_string("j0h04"); player[0].jl = input_translate_string("j0h08"); player[0].jr = input_translate_string("j0h02"); player[0].jselect = input_translate_string("j0b8"); player[0].jstart = input_translate_string("j0b9"); player[0].ja = input_translate_string("j0b1"); player[0].jb = input_translate_string("j0b0"); player[0].jta = input_translate_string("j0b2"); player[0].jtb = input_translate_string("j0b3"); player[1].u = SDL_GetScancodeFromName("I"); player[1].d = SDL_GetScancodeFromName("K"); player[1].l = SDL_GetScancodeFromName("J"); player[1].r = SDL_GetScancodeFromName("L"); player[1].select = SDL_GetScancodeFromName("Left Shift"); player[1].start = SDL_GetScancodeFromName("Left Ctrl"); player[1].a = SDL_GetScancodeFromName("M"); player[1].b = SDL_GetScancodeFromName("N"); player[1].ta = SDL_GetScancodeFromName("B"); player[1].tb = SDL_GetScancodeFromName("V"); player[1].ju = input_translate_string("j1h01"); player[1].jd = input_translate_string("j1h04"); player[1].jl = input_translate_string("j1h08"); player[1].jr = input_translate_string("j1h02"); player[1].jselect = input_translate_string("j1b8"); player[1].jstart = input_translate_string("j1b9"); player[1].ja = input_translate_string("j1b1"); player[1].jb = input_translate_string("j1b0"); player[1].jta = input_translate_string("j1b2"); player[1].jtb = input_translate_string("j1b3"); }
void input_config_read() { // Read the input config file snprintf(inputconfpath, sizeof(inputconfpath), "%sinput.conf", nstpaths.nstdir); if (ini_parse(inputconfpath, input_config_match, &inputconf) < 0) { fprintf(stderr, "Failed to load input config file %s: Using defaults.\n", inputconfpath); } else { // Map the input settings from the config file // User Interface ui.qsave1 = SDL_GetScancodeFromName(inputconf.qsave1); ui.qsave2 = SDL_GetScancodeFromName(inputconf.qsave2); ui.qload1 = SDL_GetScancodeFromName(inputconf.qload1); ui.qload2 = SDL_GetScancodeFromName(inputconf.qload2); ui.screenshot = SDL_GetScancodeFromName(inputconf.screenshot); ui.fdsflip = SDL_GetScancodeFromName(inputconf.fdsflip); ui.fdsswitch = SDL_GetScancodeFromName(inputconf.fdsswitch); ui.insertcoin1 = SDL_GetScancodeFromName(inputconf.insertcoin1); ui.insertcoin2 = SDL_GetScancodeFromName(inputconf.insertcoin2); ui.reset = SDL_GetScancodeFromName(inputconf.reset); ui.altspeed = SDL_GetScancodeFromName(inputconf.altspeed); ui.rwstart = SDL_GetScancodeFromName(inputconf.rwstart); ui.rwstop = SDL_GetScancodeFromName(inputconf.rwstop); ui.fullscreen = SDL_GetScancodeFromName(inputconf.fullscreen); ui.filter = SDL_GetScancodeFromName(inputconf.filter); ui.scalefactor = SDL_GetScancodeFromName(inputconf.scalefactor); // Player 1 player[0].u = SDL_GetScancodeFromName(inputconf.kb_p1u); player[0].d = SDL_GetScancodeFromName(inputconf.kb_p1d); player[0].l = SDL_GetScancodeFromName(inputconf.kb_p1l); player[0].r = SDL_GetScancodeFromName(inputconf.kb_p1r); player[0].select = SDL_GetScancodeFromName(inputconf.kb_p1select); player[0].start = SDL_GetScancodeFromName(inputconf.kb_p1start); player[0].a = SDL_GetScancodeFromName(inputconf.kb_p1a); player[0].b = SDL_GetScancodeFromName(inputconf.kb_p1b); player[0].ta = SDL_GetScancodeFromName(inputconf.kb_p1ta); player[0].tb = SDL_GetScancodeFromName(inputconf.kb_p1tb); player[0].ju = input_translate_string(inputconf.js_p1u); player[0].jd = input_translate_string(inputconf.js_p1d); player[0].jl = input_translate_string(inputconf.js_p1l); player[0].jr = input_translate_string(inputconf.js_p1r); player[0].jselect = input_translate_string(inputconf.js_p1select); player[0].jstart = input_translate_string(inputconf.js_p1start); player[0].ja = input_translate_string(inputconf.js_p1a); player[0].jb = input_translate_string(inputconf.js_p1b); player[0].jta = input_translate_string(inputconf.js_p1ta); player[0].jtb = input_translate_string(inputconf.js_p1tb); // Player 2 player[1].u = SDL_GetScancodeFromName(inputconf.kb_p2u); player[1].d = SDL_GetScancodeFromName(inputconf.kb_p2d); player[1].l = SDL_GetScancodeFromName(inputconf.kb_p2l); player[1].r = SDL_GetScancodeFromName(inputconf.kb_p2r); player[1].select = SDL_GetScancodeFromName(inputconf.kb_p2select); player[1].start = SDL_GetScancodeFromName(inputconf.kb_p2start); player[1].a = SDL_GetScancodeFromName(inputconf.kb_p2a); player[1].b = SDL_GetScancodeFromName(inputconf.kb_p2b); player[1].ta = SDL_GetScancodeFromName(inputconf.kb_p2ta); player[1].tb = SDL_GetScancodeFromName(inputconf.kb_p2tb); player[1].ju = input_translate_string(inputconf.js_p2u); player[1].jd = input_translate_string(inputconf.js_p2d); player[1].jl = input_translate_string(inputconf.js_p2l); player[1].jr = input_translate_string(inputconf.js_p2r); player[1].jselect = input_translate_string(inputconf.js_p2select); player[1].jstart = input_translate_string(inputconf.js_p2start); player[1].ja = input_translate_string(inputconf.js_p2a); player[1].jb = input_translate_string(inputconf.js_p2b); player[1].jta = input_translate_string(inputconf.js_p2ta); player[1].jtb = input_translate_string(inputconf.js_p2tb); } }
inline int32_t from_string(const std::string& str) noexcept { return SDL_GetScancodeFromName(str.c_str()); }
void menu_connect_tick(component *c) { connect_menu_data *local = menu_get_userdata(c); game_state *gs = local->s->gs; if(local->host) { ENetEvent event; if(enet_host_service(local->host, &event, 0) > 0 && event.type == ENET_EVENT_TYPE_CONNECT) { ENetPacket * packet = enet_packet_create("0", 2, ENET_PACKET_FLAG_RELIABLE); enet_peer_send(event.peer, 0, packet); enet_host_flush(local->host); DEBUG("connected to server!"); controller *player1_ctrl, *player2_ctrl; keyboard_keys *keys; game_player *p1 = game_state_get_player(gs, 0); game_player *p2 = game_state_get_player(gs, 1); // force the speed to 3 game_state_set_speed(gs, 5); p1->har_id = HAR_JAGUAR; p1->pilot_id = 0; p2->har_id = HAR_JAGUAR; p2->pilot_id = 0; player1_ctrl = malloc(sizeof(controller)); controller_init(player1_ctrl); player1_ctrl->har = p1->har; player2_ctrl = malloc(sizeof(controller)); controller_init(player2_ctrl); player2_ctrl->har = p2->har; // Player 1 controller -- Network net_controller_create(player1_ctrl, local->host, event.peer, ROLE_CLIENT); game_player_set_ctrl(p1, player1_ctrl); // Player 2 controller -- Keyboard settings_keyboard *k = &settings_get()->keys; keys = malloc(sizeof(keyboard_keys)); keys->up = SDL_GetScancodeFromName(k->key1_up); keys->down = SDL_GetScancodeFromName(k->key1_down); keys->left = SDL_GetScancodeFromName(k->key1_left); keys->right = SDL_GetScancodeFromName(k->key1_right); keys->punch = SDL_GetScancodeFromName(k->key1_punch); keys->kick = SDL_GetScancodeFromName(k->key1_kick); keys->escape = SDL_GetScancodeFromName(k->key1_escape); keyboard_create(player2_ctrl, keys, 0); game_player_set_ctrl(p2, player2_ctrl); local->host = NULL; game_player_set_selectable(p2, 1); chr_score_set_difficulty(game_player_get_score(game_state_get_player(gs, 0)), AI_DIFFICULTY_CHAMPION); chr_score_set_difficulty(game_player_get_score(game_state_get_player(gs, 1)), AI_DIFFICULTY_CHAMPION); game_state_set_next(gs, SCENE_MELEE); } else { if(difftime(time(NULL), local->connect_start) > 5.0) { DEBUG("connection timed out"); menu_connect_cancel(local->cancel_button, local->s); } } } }