Multiple save states (#248)
This commit is contained in:
parent
4a9c51a6c8
commit
cddb6609f1
|
@ -39,8 +39,8 @@ void dc_request_reset();
|
|||
void dc_exit();
|
||||
void dc_resume();
|
||||
void dc_step();
|
||||
void dc_savestate();
|
||||
void dc_loadstate();
|
||||
void dc_savestate(int index = 0);
|
||||
void dc_loadstate(int index = 0);
|
||||
void dc_load_game(const char *path);
|
||||
bool dc_is_load_done();
|
||||
void dc_cancel_load();
|
||||
|
|
|
@ -755,7 +755,7 @@ static void cleanup_serialize(void *data)
|
|||
free(data);
|
||||
}
|
||||
|
||||
static std::string get_savestate_file_path(bool writable)
|
||||
static std::string get_savestate_file_path(int index, bool writable)
|
||||
{
|
||||
std::string state_file = settings.imgread.ImagePath;
|
||||
size_t lastindex = state_file.find_last_of('/');
|
||||
|
@ -771,14 +771,19 @@ static std::string get_savestate_file_path(bool writable)
|
|||
lastindex = state_file.find_last_of('.');
|
||||
if (lastindex != std::string::npos)
|
||||
state_file = state_file.substr(0, lastindex);
|
||||
state_file = state_file + ".state";
|
||||
|
||||
char index_str[4] = "";
|
||||
if (index != 0) // When index is 0, use same name before multiple states is added
|
||||
sprintf(index_str, "_%d", index);
|
||||
|
||||
state_file = state_file + index_str + ".state";
|
||||
if (writable)
|
||||
return get_writable_data_path(state_file);
|
||||
else
|
||||
return get_readonly_data_path(state_file);
|
||||
}
|
||||
|
||||
void dc_savestate()
|
||||
void dc_savestate(int index)
|
||||
{
|
||||
unsigned int total_size = 0 ;
|
||||
void *data = NULL ;
|
||||
|
@ -810,7 +815,7 @@ void dc_savestate()
|
|||
return;
|
||||
}
|
||||
|
||||
std::string filename = get_savestate_file_path(true);
|
||||
std::string filename = get_savestate_file_path(index, true);
|
||||
#if 0
|
||||
FILE *f = nowide::fopen(filename.c_str(), "wb") ;
|
||||
|
||||
|
@ -849,14 +854,14 @@ void dc_savestate()
|
|||
gui_display_notification("State saved", 1000);
|
||||
}
|
||||
|
||||
void dc_loadstate()
|
||||
void dc_loadstate(int index)
|
||||
{
|
||||
u32 total_size = 0;
|
||||
FILE *f = nullptr;
|
||||
|
||||
dc_stop();
|
||||
|
||||
std::string filename = get_savestate_file_path(false);
|
||||
std::string filename = get_savestate_file_path(index, false);
|
||||
RZipFile zipFile;
|
||||
if (zipFile.Open(filename, false))
|
||||
{
|
||||
|
|
|
@ -427,14 +427,12 @@ static void gui_display_commands()
|
|||
}
|
||||
if (ImGui::Button("Load State", ImVec2(150 * scaling, 50 * scaling)))
|
||||
{
|
||||
gui_state = GuiState::Closed;
|
||||
dc_loadstate();
|
||||
gui_state = GuiState::SelectLoadingStates;
|
||||
}
|
||||
ImGui::NextColumn();
|
||||
if (ImGui::Button("Save State", ImVec2(150 * scaling, 50 * scaling)))
|
||||
{
|
||||
gui_state = GuiState::Closed;
|
||||
dc_savestate();
|
||||
gui_state = GuiState::SelectSavingStates;
|
||||
}
|
||||
if (settings.imgread.ImagePath[0] == '\0')
|
||||
{
|
||||
|
@ -1933,6 +1931,40 @@ static void gui_display_loadscreen()
|
|||
ImGui::End();
|
||||
}
|
||||
|
||||
void gui_select_save_states(bool saving) {
|
||||
centerNextWindow();
|
||||
ImGui::SetNextWindowSize(ImVec2(330 * scaling, 0));
|
||||
|
||||
ImGui::Begin("##select states", NULL, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_AlwaysAutoResize);
|
||||
|
||||
ImGui::Columns(2, "buttons", false);
|
||||
|
||||
for (int i = 0; i < SAVE_STATES_CAPACITY; i++) {
|
||||
if (i != 0)
|
||||
ImGui::NextColumn();
|
||||
|
||||
char state_button_name[32];
|
||||
sprintf(state_button_name, "State %d", i);
|
||||
if (ImGui::Button(state_button_name, ImVec2(150 * scaling, 50 * scaling)))
|
||||
{
|
||||
gui_state = GuiState::Closed;
|
||||
if (saving)
|
||||
dc_savestate(i);
|
||||
else
|
||||
dc_loadstate(i);
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::Columns(1, nullptr, false);
|
||||
if (ImGui::Button("Cancel", ImVec2(300 * scaling + ImGui::GetStyle().ColumnsMinSpacing + ImGui::GetStyle().FramePadding.x * 2 - 1,
|
||||
50 * scaling)))
|
||||
{
|
||||
gui_state = GuiState::Commands;
|
||||
}
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
void gui_display_ui()
|
||||
{
|
||||
if (gui_state == GuiState::Closed || gui_state == GuiState::VJoyEdit)
|
||||
|
@ -1989,6 +2021,12 @@ void gui_display_ui()
|
|||
case GuiState::Cheats:
|
||||
gui_cheats();
|
||||
break;
|
||||
case GuiState::SelectLoadingStates:
|
||||
gui_select_save_states(false);
|
||||
break;
|
||||
case GuiState::SelectSavingStates:
|
||||
gui_select_save_states(true);
|
||||
break;
|
||||
default:
|
||||
die("Unknown UI state");
|
||||
break;
|
||||
|
|
|
@ -48,7 +48,9 @@ enum class GuiState {
|
|||
SelectDisk,
|
||||
Loading,
|
||||
NetworkStart,
|
||||
Cheats
|
||||
Cheats,
|
||||
SelectLoadingStates,
|
||||
SelectSavingStates
|
||||
};
|
||||
extern GuiState gui_state;
|
||||
|
||||
|
@ -81,3 +83,5 @@ static inline bool crosshairsNeeded()
|
|||
}
|
||||
const u32 *getCrosshairTextureData();
|
||||
std::pair<float, float> getCrosshairPosition(int playerNum);
|
||||
|
||||
#define SAVE_STATES_CAPACITY 10
|
Loading…
Reference in New Issue