From fb757b9780c173d4db254818baca4a4454368019 Mon Sep 17 00:00:00 2001 From: Ilari Liusvaara Date: Fri, 13 Jan 2012 07:25:02 +0200 Subject: [PATCH] Rewind movie to beginning function --- include/core/movie.hpp | 5 ++++- include/core/moviedata.hpp | 2 ++ src/core/mainloop.cpp | 10 +++++++++- src/core/movie.cpp | 9 +++++++++ src/core/moviedata.cpp | 25 +++++++++++++++++++++++++ src/plat-wxwidgets/mainwindow.cpp | 9 +++++++-- 6 files changed, 56 insertions(+), 4 deletions(-) diff --git a/include/core/movie.hpp b/include/core/movie.hpp index a0f56df7..5fbae63f 100644 --- a/include/core/movie.hpp +++ b/include/core/movie.hpp @@ -187,7 +187,10 @@ public: size_t restore_state(uint64_t curframe, uint64_t lagframe, const std::vector& pcounters, bool ro, controller_frame_vector* old_movie, const std::string& old_projectid) throw(std::bad_alloc, std::runtime_error); - +/** + * Reset the state of movie to initial state. + */ + void reset_state() throw(); /** * Get reset status for current frame. * diff --git a/include/core/moviedata.hpp b/include/core/moviedata.hpp index 5006a6c1..fe1ef446 100644 --- a/include/core/moviedata.hpp +++ b/include/core/moviedata.hpp @@ -10,6 +10,7 @@ #define LOAD_STATE_MOVIE 3 #define LOAD_STATE_DEFAULT 4 #define LOAD_STATE_CURRENT 5 +#define LOAD_STATE_BEGINNING 6 #define SAVE_STATE 0 #define SAVE_MOVIE 1 @@ -24,6 +25,7 @@ std::pair split_author(const std::string& author) thro void do_save_state(const std::string& filename) throw(std::bad_alloc, std::runtime_error); void do_save_movie(const std::string& filename) throw(std::bad_alloc, std::runtime_error); +void do_load_beginning() throw(std::bad_alloc, std::runtime_error); void do_load_state(struct moviefile& _movie, int lmode); bool do_load_state(const std::string& filename, int lmode); diff --git a/src/core/mainloop.cpp b/src/core/mainloop.cpp index baa87b4d..6f5dc3d8 100644 --- a/src/core/mainloop.cpp +++ b/src/core/mainloop.cpp @@ -615,6 +615,12 @@ namespace messages << "Pause-on-end is now " << (newstate ? "ON" : "OFF") << std::endl; }); + function_ptr_command<> rewind_movie("rewind-movie", "Rewind movie to the beginning", + "Syntax: rewind-movie\nRewind movie to the beginning\n", + []() throw(std::bad_alloc, std::runtime_error) { + mark_pending_load("SOME NONBLANK NAME", LOAD_STATE_BEGINNING); + }); + function_ptr_command<> test1("test-1", "no description available", "No help available\n", []() throw(std::bad_alloc, std::runtime_error) { redraw_framebuffer(screen_nosignal); @@ -691,10 +697,12 @@ namespace { if(pending_load != "") { system_corrupt = false; - if(!do_load_state(pending_load, loadmode)) { + if(loadmode != LOAD_STATE_BEGINNING && !do_load_state(pending_load, loadmode)) { pending_load = ""; return -1; } + if(loadmode == LOAD_STATE_BEGINNING) + do_load_beginning(); pending_load = ""; pending_reset_cycles = -1; amode = ADVANCE_AUTO; diff --git a/src/core/movie.cpp b/src/core/movie.cpp index c16d6e16..0758e5f7 100644 --- a/src/core/movie.cpp +++ b/src/core/movie.cpp @@ -445,6 +445,15 @@ controller_frame movie::read_subframe(uint64_t frame, uint64_t subframe) throw() return movie_data[p + subframe]; } +void movie::reset_state() throw() +{ + readonly = true; + current_frame = 0; + current_frame_first_subframe = 0; + pollcounters.clear(); + lag_frames = 0; + clear_caches(); +} movie_logic::movie_logic() throw() { diff --git a/src/core/moviedata.cpp b/src/core/moviedata.cpp index 2b3b5746..2ae5f2ee 100644 --- a/src/core/moviedata.cpp +++ b/src/core/moviedata.cpp @@ -189,6 +189,31 @@ void do_save_movie(const std::string& filename) throw(std::bad_alloc, std::runti extern time_t random_seed_value; +void do_load_beginning() throw(std::bad_alloc, std::runtime_error) +{ + SNES::config.random = false; + SNES::config.expansion_port = SNES::System::ExpansionPortDevice::None; + + //Negative return. + rrdata::add_internal(); + try { + movb.get_movie().reset_state(); + random_seed_value = our_movie.movie_rtc_second; + our_rom->load(); + + load_sram(our_movie.movie_sram); + our_movie.rtc_second = our_movie.movie_rtc_second; + our_movie.rtc_subsecond = our_movie.movie_rtc_subsecond; + redraw_framebuffer(screen_nosignal); + } catch(std::bad_alloc& e) { + OOM_panic(); + } catch(std::exception& e) { + system_corrupt = true; + redraw_framebuffer(screen_corrupt, true); + throw; + } +} + //Load state from loaded movie file (does not catch errors). void do_load_state(struct moviefile& _movie, int lmode) { diff --git a/src/plat-wxwidgets/mainwindow.cpp b/src/plat-wxwidgets/mainwindow.cpp index 975bbe41..6fdf790d 100644 --- a/src/plat-wxwidgets/mainwindow.cpp +++ b/src/plat-wxwidgets/mainwindow.cpp @@ -65,7 +65,8 @@ enum wxID_SAVE_MEMORYWATCH, wxID_LOAD_MEMORYWATCH, wxID_DUMP_FIRST, - wxID_DUMP_LAST = wxID_DUMP_FIRST + 1023 + wxID_DUMP_LAST = wxID_DUMP_FIRST + 1023, + wxID_REWIND_MOVIE }; @@ -787,7 +788,7 @@ wxwin_mainwindow::wxwin_mainwindow() menu_entry(wxID_EXIT, wxT("&Quit")); menu_separator(); menu_entry(wxID_ABOUT, wxT("About")); - //File menu: (ACFOS)DELMNPRTUV + //File menu: (ACFOS)DELMNPRTUVW menu_start(wxT("&File")); menu_entry_check(wxID_READONLY_MODE, wxT("Reado&nly mode")); menu_check(wxID_READONLY_MODE, is_readonly_mode()); @@ -800,6 +801,7 @@ wxwin_mainwindow::wxwin_mainwindow() menu_entry(wxID_LOAD_STATE_RW, wxT("Load s&tate (read-write)")); menu_entry(wxID_LOAD_STATE_P, wxT("Load state (&preserve)")); menu_entry(wxID_LOAD_MOVIE, wxT("Load &movie")); + menu_entry(wxID_REWIND_MOVIE, wxT("Re&wind movie")); menu_separator(); menu_entry(wxID_SAVE_SCREENSHOT, wxT("Save sc&reenshot")); menu_separator(); @@ -935,6 +937,9 @@ void wxwin_mainwindow::handle_menu_click(wxCommandEvent& e) break; platform::queue("load-state " + filename); break; + case wxID_REWIND_MOVIE: + platform::queue("rewind-movie"); + break; case wxID_SAVE_MOVIE: d = new wxFileDialog(this, wxT("Save Movie"), wxT(".")); if(d->ShowModal() == wxID_OK) -- 2.11.4.GIT