Support in-memory saves and use those for wxwidgets ROM loading
[lsnes.git] / include / core / moviefile.hpp
blobbfdd4637c139ead6347aa3ad9d83068a25866376
1 #ifndef _moviefile__hpp__included__
2 #define _moviefile__hpp__included__
4 #include <string>
5 #include <vector>
6 #include <stdexcept>
7 #include <map>
8 #include "core/controllerframe.hpp"
9 #include "core/rom.hpp"
10 #include "core/subtitles.hpp"
13 /**
14 * This structure gives parsed representationg of movie file, as result of decoding or for encoding.
16 struct moviefile
18 /**
19 * Brief information
21 struct brief_info
23 brief_info() { current_frame = 0; rerecords = 0; }
24 brief_info(const std::string& filename);
25 std::string sysregion;
26 std::string corename;
27 std::string projectid;
28 std::string hash[ROM_SLOT_COUNT];
29 std::string hashxml[ROM_SLOT_COUNT];
30 std::string hint[ROM_SLOT_COUNT];
31 uint64_t current_frame;
32 uint64_t rerecords;
33 private:
34 void binary_io(std::istream& s);
36 /**
37 * This constructor construct movie structure with default settings.
39 * throws std::bad_alloc: Not enough memory.
41 moviefile() throw(std::bad_alloc);
43 /**
44 * This constructor loads a movie/savestate file and fills structure accordingly.
46 * parameter filename: The file to load.
47 * parameter romtype: Type of ROM.
48 * throws std::bad_alloc: Not enough memory.
49 * throws std::runtime_error: Can't load the movie file
51 moviefile(const std::string& filename, core_type& romtype) throw(std::bad_alloc, std::runtime_error);
53 /**
54 * Reads this movie structure and saves it into file.
56 * parameter filename: The file to save to.
57 * parameter compression: The compression level 0-9. 0 is uncompressed.
58 * parameter binary: Save in binary form if true.
59 * throws std::bad_alloc: Not enough memory.
60 * throws std::runtime_error: Can't save the movie file.
62 void save(const std::string& filename, unsigned compression, bool binary) throw(std::bad_alloc,
63 std::runtime_error);
65 /**
66 * Force loading as corrupt.
68 bool force_corrupt;
69 /**
70 * What is the ROM type and region?
72 core_sysregion* gametype;
73 /**
74 * Settings.
76 std::map<std::string, std::string> settings;
77 /**
78 * Emulator Core version string.
80 std::string coreversion;
81 /**
82 * Name of the game
84 std::string gamename;
85 /**
86 * Project ID (used to identify if two movies are from the same project).
88 std::string projectid;
89 /**
90 * Rerecord count (only saved).
92 std::string rerecords;
93 /**
94 * Rerecord count (memory saves only).
96 uint64_t rerecords_mem;
97 /**
98 * SHA-256 of ROM (empty string if none).
100 std::string romimg_sha256[ROM_SLOT_COUNT];
102 * SHA-256 of ROM XML (empty string if none).
104 std::string romxml_sha256[ROM_SLOT_COUNT];
106 * ROM name hint (empty string if none).
108 std::string namehint[ROM_SLOT_COUNT];
110 * Authors of the run, first in each pair is full name, second is nickname.
112 std::vector<std::pair<std::string, std::string>> authors;
114 * Contents of SRAM on time of initial powerup.
116 std::map<std::string, std::vector<char>> movie_sram;
118 * Contents of RAM on time of initial powerup.
120 std::map<std::string, std::vector<char>> ramcontent;
122 * True if savestate, false if movie.
124 bool is_savestate;
126 * Contents of SRAM on time of savestate (if is_savestate is true).
128 std::map<std::string, std::vector<char>> sram;
130 * Core savestate (if is_savestate is true).
132 std::vector<char> savestate; //Savestate to load (if is_savestate is true).
134 * Anchoring core savestate (if not empty).
136 std::vector<char> anchor_savestate;
138 * Host memory (if is_savestate is true).
140 std::vector<char> host_memory;
142 * Screenshot (if is_savestate is true).
144 std::vector<char> screenshot;
146 * Current frame (if is_savestate is true).
148 uint64_t save_frame;
150 * Number of lagged frames (if is_savestate is true).
152 uint64_t lagged_frames;
154 * Poll counters (if is_savestate is true).
156 std::vector<uint32_t> pollcounters;
158 * Poll flag.
160 unsigned poll_flag;
162 * Compressed rrdata.
164 std::vector<char> c_rrdata;
166 * Input for each (sub)frame.
168 controller_frame_vector input; //Input for each frame.
170 * Current RTC second.
172 int64_t rtc_second;
174 * Current RTC subsecond.
176 int64_t rtc_subsecond;
178 * Movie starting RTC second.
180 int64_t movie_rtc_second;
182 * Movie starting RTC subsecond.
184 int64_t movie_rtc_subsecond;
186 * Start paused flag.
188 bool start_paused;
190 * Lazy project create flag.
192 bool lazy_project_create;
194 * Subtitles.
196 std::map<moviefile_subtiming, std::string> subtitles;
198 * Active macros at savestate.
200 std::map<std::string, uint64_t> active_macros;
202 * Get number of frames in movie.
204 * returns: Number of frames.
206 uint64_t get_frame_count() throw();
208 * Get length of the movie
210 * returns: Length of the movie in nanoseconds.
212 uint64_t get_movie_length() throw();
213 private:
214 void binary_io(std::ostream& stream) throw(std::bad_alloc, std::runtime_error);
215 void binary_io(std::istream& stream, struct core_type& romtype) throw(std::bad_alloc, std::runtime_error);
218 #endif