From b11f39e7a0dbccee2a69ecc96e6584b7f3536f03 Mon Sep 17 00:00:00 2001 From: Victor Vasiliev Date: Mon, 1 Feb 2016 17:29:25 -0500 Subject: [PATCH 1/4] Do not handle any UI inputs immediately after state load/save Before this change, if you try to save state to a bound which already does something as a UI button, it will save state there and then immediately execute the bound action (sometimes it would not happen). So, if you have state to P, with default button it would pause the game immediately after saving state (except sometimes it would not). --- src/emu/ui/ui.cpp | 3 +++ src/emu/uiinput.cpp | 10 ++++++++++ src/emu/uiinput.h | 2 ++ 3 files changed, 15 insertions(+) diff --git a/src/emu/ui/ui.cpp b/src/emu/ui/ui.cpp index 577a0cb015d..304c365ac6a 100644 --- a/src/emu/ui/ui.cpp +++ b/src/emu/ui/ui.cpp @@ -1755,6 +1755,9 @@ UINT32 ui_manager::handler_load_save(running_machine &machine, render_container machine.schedule_load(filename); } + // avoid handling the name of the save state slot as a seperate input + machine.ui_input().mark_all_as_pressed(); + // remove the pause and reset the state machine.resume(); return UI_HANDLER_CANCEL; diff --git a/src/emu/uiinput.cpp b/src/emu/uiinput.cpp index 6b26bb323b5..b1ee53a697b 100644 --- a/src/emu/uiinput.cpp +++ b/src/emu/uiinput.cpp @@ -324,3 +324,13 @@ void ui_input_manager::push_char_event(render_target* target, unicode_char ch) event.ch = ch; push_event(event); } + +/*------------------------------------------------- + mark_all_as_pressed - marks all buttons + as if they were already pressed once +-------------------------------------------------*/ +void ui_input_manager::mark_all_as_pressed() +{ + for (int code = IPT_UI_FIRST + 1; code < IPT_UI_LAST; code++) + m_next_repeat[code] = osd_ticks(); +} diff --git a/src/emu/uiinput.h b/src/emu/uiinput.h index 2e89a0c413a..ff4137faf74 100644 --- a/src/emu/uiinput.h +++ b/src/emu/uiinput.h @@ -86,6 +86,8 @@ public: void push_mouse_double_click_event(render_target* target, INT32 x, INT32 y); void push_char_event(render_target* target, unicode_char ch); + void mark_all_as_pressed(); + private: // internal state From c626466050146c9ddb8533222c5486dc3125e07b Mon Sep 17 00:00:00 2001 From: Victor Vasiliev Date: Mon, 1 Feb 2016 10:29:47 -0500 Subject: [PATCH 2/4] Do not read the load/save state filename while sequence is still pressed Fixes the issue where, if the save state button was bound to something that was a legal save state input, it would occasionally immediately save the state onto the same button as "save state" input itself was bound. --- src/emu/ui/ui.cpp | 19 +++++++++++++++++++ src/emu/ui/ui.h | 1 + 2 files changed, 20 insertions(+) diff --git a/src/emu/ui/ui.cpp b/src/emu/ui/ui.cpp index 304c365ac6a..df16d384ebb 100644 --- a/src/emu/ui/ui.cpp +++ b/src/emu/ui/ui.cpp @@ -1625,6 +1625,7 @@ UINT32 ui_manager::handler_ingame(running_machine &machine, render_container *co if (machine.ui_input().pressed(IPT_UI_SAVE_STATE)) { machine.pause(); + machine.ui().m_load_save_hold = true; return machine.ui().set_handler(handler_load_save, LOADSAVE_SAVE); } @@ -1632,6 +1633,7 @@ UINT32 ui_manager::handler_ingame(running_machine &machine, render_container *co if (machine.ui_input().pressed(IPT_UI_LOAD_STATE)) { machine.pause(); + machine.ui().m_load_save_hold = true; return machine.ui().set_handler(handler_load_save, LOADSAVE_LOAD); } @@ -1713,6 +1715,23 @@ UINT32 ui_manager::handler_load_save(running_machine &machine, render_container else machine.ui().draw_message_window(container, "Select position to load from"); + // if load/save state sequence is still being pressed, do not read the filename yet + if (machine.ui().m_load_save_hold) { + bool seq_in_progress = false; + const input_seq &load_save_seq = state == LOADSAVE_SAVE ? + machine.ioport().type_seq(IPT_UI_SAVE_STATE) : + machine.ioport().type_seq(IPT_UI_LOAD_STATE); + + for (int i = 0; i < load_save_seq.length(); i++) + if (machine.input().code_pressed_once(load_save_seq[i])) + seq_in_progress = true; + + if (seq_in_progress) + return state; + else + machine.ui().m_load_save_hold = false; + } + // check for cancel key if (machine.ui_input().pressed(IPT_UI_CANCEL)) { diff --git a/src/emu/ui/ui.h b/src/emu/ui/ui.h index ac68a2fb773..d0f7a28ad27 100644 --- a/src/emu/ui/ui.h +++ b/src/emu/ui/ui.h @@ -182,6 +182,7 @@ private: std::unique_ptr m_non_char_keys_down; render_texture * m_mouse_arrow_texture; bool m_mouse_show; + bool m_load_save_hold; // text generators std::string &disclaimer_string(std::string &buffer); From f6331aaf656437913eb63e7c51439505aec6571f Mon Sep 17 00:00:00 2001 From: Victor Vasiliev Date: Tue, 2 Feb 2016 15:27:21 -0500 Subject: [PATCH 3/4] Allow saved states to be bound to joystick buttons --- src/emu/ui/ui.cpp | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/emu/ui/ui.cpp b/src/emu/ui/ui.cpp index df16d384ebb..f32f35ca71a 100644 --- a/src/emu/ui/ui.cpp +++ b/src/emu/ui/ui.cpp @@ -37,6 +37,8 @@ enum LOADSAVE_SAVE }; +#define MAX_SAVED_STATE_JOYSTICK 4 + /*************************************************************************** LOCAL VARIABLES @@ -1759,18 +1761,35 @@ UINT32 ui_manager::handler_load_save(running_machine &machine, render_container if (machine.input().code_pressed_once(input_code(DEVICE_CLASS_KEYBOARD, 0, ITEM_CLASS_SWITCH, ITEM_MODIFIER_NONE, id))) file = id - ITEM_ID_0_PAD + '0'; if (file == 0) - return state; + { + bool found = false; + + for (int joy_index = 0; joy_index <= MAX_SAVED_STATE_JOYSTICK; joy_index++) + for (input_item_id id = ITEM_ID_BUTTON1; id <= ITEM_ID_BUTTON32; ++id) + if (machine.input().code_pressed_once(input_code(DEVICE_CLASS_JOYSTICK, joy_index, ITEM_CLASS_SWITCH, ITEM_MODIFIER_NONE, id))) + { + snprintf(filename, sizeof(filename), "joy%i-%i", joy_index, id - ITEM_ID_BUTTON1 + 1); + found = true; + break; + } + + if (!found) + return state; + } + else + { + sprintf(filename, "%c", file); + } // display a popup indicating that the save will proceed - sprintf(filename, "%c", file); if (state == LOADSAVE_SAVE) { - machine.popmessage("Save to position %c", file); + machine.popmessage("Save to position %s", filename); machine.schedule_save(filename); } else { - machine.popmessage("Load from position %c", file); + machine.popmessage("Load from position %s", filename); machine.schedule_load(filename); } From ccee9f7825acd7b32dd50092acc1d9f874d75940 Mon Sep 17 00:00:00 2001 From: Victor Vasiliev Date: Wed, 3 Feb 2016 02:36:17 -0500 Subject: [PATCH 4/4] Initialize m_load_save_hold --- src/emu/ui/ui.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/emu/ui/ui.cpp b/src/emu/ui/ui.cpp index f32f35ca71a..d0e432c2a21 100644 --- a/src/emu/ui/ui.cpp +++ b/src/emu/ui/ui.cpp @@ -244,6 +244,7 @@ ui_manager::ui_manager(running_machine &machine) m_popup_text_end = 0; m_use_natural_keyboard = false; m_mouse_arrow_texture = nullptr; + m_load_save_hold = false; // more initialization set_handler(handler_messagebox, 0);