diff --git a/src/emu/machine.cpp b/src/emu/machine.cpp index f674c3d003b..b8ef018c724 100644 --- a/src/emu/machine.cpp +++ b/src/emu/machine.cpp @@ -125,7 +125,7 @@ running_machine::running_machine(const machine_config &_config, machine_manager m_ui_active(_config.options().ui_active()), m_basename(_config.gamedrv().name), m_sample_rate(_config.options().sample_rate()), - m_saveload_schedule(SLS_NONE), + m_saveload_schedule(saveload_schedule::NONE), m_saveload_schedule_time(attotime::zero), m_saveload_searchpath(nullptr), @@ -335,7 +335,7 @@ int running_machine::run(bool quiet) soft_reset(); // handle initial load - if (m_saveload_schedule != SLS_NONE) + if (m_saveload_schedule != saveload_schedule::NONE) handle_saveload(); export_http_api(); @@ -344,7 +344,7 @@ int running_machine::run(bool quiet) // run the CPUs until a reset or exit m_hard_reset_pending = false; - while ((!m_hard_reset_pending && !m_exit_pending) || m_saveload_schedule != SLS_NONE) + while ((!m_hard_reset_pending && !m_exit_pending) || m_saveload_schedule != saveload_schedule::NONE) { g_profiler.start(PROFILER_EXTRA); @@ -361,7 +361,7 @@ int running_machine::run(bool quiet) m_video->frame_update(); // handle save/load - if (m_saveload_schedule != SLS_NONE) + if (m_saveload_schedule != saveload_schedule::NONE) handle_saveload(); g_profiler.stop(); @@ -571,7 +571,7 @@ std::string running_machine::get_statename(const char *option) const // for state loading/saving //------------------------------------------------- -std::string running_machine::compose_saveload_filename(const char *filename, const char **searchpath) +std::string running_machine::compose_saveload_filename(std::string &&filename, const char **searchpath) { std::string result; @@ -581,7 +581,7 @@ std::string running_machine::compose_saveload_filename(const char *filename, con // if so, this is easy if (searchpath != nullptr) *searchpath = nullptr; - result = filename; + result = std::move(filename); } else { @@ -603,10 +603,10 @@ std::string running_machine::compose_saveload_filename(const char *filename, con // for state loading/saving //------------------------------------------------- -void running_machine::set_saveload_filename(const char *filename) +void running_machine::set_saveload_filename(std::string &&filename) { // compose the save/load filename and persist it - m_saveload_pending_file = compose_saveload_filename(filename, &m_saveload_searchpath); + m_saveload_pending_file = compose_saveload_filename(std::move(filename), &m_saveload_searchpath); } @@ -615,13 +615,13 @@ void running_machine::set_saveload_filename(const char *filename) // soon as possible //------------------------------------------------- -void running_machine::schedule_save(const char *filename) +void running_machine::schedule_save(std::string &&filename) { // specify the filename to save or load - set_saveload_filename(filename); + set_saveload_filename(std::move(filename)); // note the start time and set a timer for the next timeslice to actually schedule it - m_saveload_schedule = SLS_SAVE; + m_saveload_schedule = saveload_schedule::SAVE; m_saveload_schedule_time = this->time(); // we can't be paused since we need to clear out anonymous timers @@ -639,7 +639,7 @@ void running_machine::immediate_save(const char *filename) set_saveload_filename(filename); // set up some parameters for handle_saveload() - m_saveload_schedule = SLS_SAVE; + m_saveload_schedule = saveload_schedule::SAVE; m_saveload_schedule_time = this->time(); // jump right into the save, anonymous timers can't hurt us! @@ -652,13 +652,13 @@ void running_machine::immediate_save(const char *filename) // soon as possible //------------------------------------------------- -void running_machine::schedule_load(const char *filename) +void running_machine::schedule_load(std::string &&filename) { // specify the filename to save or load - set_saveload_filename(filename); + set_saveload_filename(std::move(filename)); // note the start time and set a timer for the next timeslice to actually schedule it - m_saveload_schedule = SLS_LOAD; + m_saveload_schedule = saveload_schedule::LOAD; m_saveload_schedule_time = this->time(); // we can't be paused since we need to clear out anonymous timers @@ -676,7 +676,7 @@ void running_machine::immediate_load(const char *filename) set_saveload_filename(filename); // set up some parameters for handle_saveload() - m_saveload_schedule = SLS_LOAD; + m_saveload_schedule = saveload_schedule::LOAD; m_saveload_schedule_time = this->time(); // jump right into the load, anonymous timers can't hurt us @@ -860,7 +860,7 @@ void running_machine::handle_saveload() // if no name, bail if (!m_saveload_pending_file.empty()) { - const char *const opname = (m_saveload_schedule == SLS_LOAD) ? "load" : "save"; + const char *const opname = (m_saveload_schedule == saveload_schedule::LOAD) ? "load" : "save"; // if there are anonymous timers, we can't save just yet, and we can't load yet either // because the timers might overwrite data we have loaded @@ -874,17 +874,17 @@ void running_machine::handle_saveload() } else { - u32 const openflags = (m_saveload_schedule == SLS_LOAD) ? OPEN_FLAG_READ : (OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS); + u32 const openflags = (m_saveload_schedule == saveload_schedule::LOAD) ? OPEN_FLAG_READ : (OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS); // open the file emu_file file(m_saveload_searchpath, openflags); auto const filerr = file.open(m_saveload_pending_file.c_str()); if (filerr == osd_file::error::NONE) { - const char *const opnamed = (m_saveload_schedule == SLS_LOAD) ? "loaded" : "saved"; + const char *const opnamed = (m_saveload_schedule == saveload_schedule::LOAD) ? "loaded" : "saved"; // read/write the save state - save_error saverr = (m_saveload_schedule == SLS_LOAD) ? m_save.read_file(file) : m_save.write_file(file); + save_error saverr = (m_saveload_schedule == saveload_schedule::LOAD) ? m_save.read_file(file) : m_save.write_file(file); // handle the result switch (saverr) @@ -918,7 +918,7 @@ void running_machine::handle_saveload() } // close and perhaps delete the file - if (saverr != STATERR_NONE && m_saveload_schedule == SLS_SAVE) + if (saverr != STATERR_NONE && m_saveload_schedule == saveload_schedule::SAVE) file.remove_on_close(); } else @@ -929,7 +929,7 @@ void running_machine::handle_saveload() // unschedule the operation m_saveload_pending_file.clear(); m_saveload_searchpath = nullptr; - m_saveload_schedule = SLS_NONE; + m_saveload_schedule = saveload_schedule::NONE; } diff --git a/src/emu/machine.h b/src/emu/machine.h index bc35ba5958f..8b19c1a7c2c 100644 --- a/src/emu/machine.h +++ b/src/emu/machine.h @@ -257,8 +257,8 @@ public: void schedule_exit(); void schedule_hard_reset(); void schedule_soft_reset(); - void schedule_save(const char *filename); - void schedule_load(const char *filename); + void schedule_save(std::string &&filename); + void schedule_load(std::string &&filename); // date & time void base_datetime(system_time &systime); @@ -273,7 +273,7 @@ public: void strlog(const char *str) const; u32 rand(); const char *describe_context(); - std::string compose_saveload_filename(const char *base_filename, const char **searchpath = nullptr); + std::string compose_saveload_filename(std::string &&base_filename, const char **searchpath = nullptr); // CPU information cpu_device * firstcpu; // first CPU @@ -315,7 +315,7 @@ private: template struct is_null { template static bool value(U &&x) { return false; } }; template struct is_null { template static bool value(U &&x) { return !x; } }; void start(); - void set_saveload_filename(const char *filename); + void set_saveload_filename(std::string &&filename); std::string get_statename(const char *statename_opt) const; void handle_saveload(); void soft_reset(void *ptr = nullptr, s32 param = 0); @@ -374,11 +374,11 @@ private: std::unique_ptr m_logfile; // pointer to the active log file // load/save management - enum saveload_schedule + enum class saveload_schedule { - SLS_NONE, - SLS_SAVE, - SLS_LOAD + NONE, + SAVE, + LOAD }; saveload_schedule m_saveload_schedule; attotime m_saveload_schedule_time; diff --git a/src/frontend/mame/ui/ui.cpp b/src/frontend/mame/ui/ui.cpp index ebce7b1c3d0..675f8162469 100644 --- a/src/frontend/mame/ui/ui.cpp +++ b/src/frontend/mame/ui/ui.cpp @@ -1276,7 +1276,7 @@ uint32_t mame_ui_manager::handler_ingame(render_container &container) uint32_t mame_ui_manager::handler_load_save(render_container &container, uint32_t state) { - char filename[20]; + std::string filename; char file = 0; // if we're not in the middle of anything, skip @@ -1340,7 +1340,7 @@ uint32_t mame_ui_manager::handler_load_save(render_container &container, uint32_ 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); + filename = util::string_format("joy%i-%i", joy_index, id - ITEM_ID_BUTTON1 + 1); found = true; break; } @@ -1350,19 +1350,19 @@ uint32_t mame_ui_manager::handler_load_save(render_container &container, uint32_ } else { - sprintf(filename, "%c", file); + filename = util::string_format("%c", file); } // display a popup indicating that the save will proceed if (state == LOADSAVE_SAVE) { machine().popmessage(_("Save to position %s"), filename); - machine().schedule_save(filename); + machine().schedule_save(std::move(filename)); } else { machine().popmessage(_("Load from position %s"), filename); - machine().schedule_load(filename); + machine().schedule_load(std::move(filename)); } // avoid handling the name of the save state slot as a seperate input