moviefile.cpp is friggin' large, split it up
[lsnes.git] / include / core / moviefile.hpp
blobd3c9a2a014b256786ffc32eb3ceb4e172256d263
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"
11 #include "library/rrdata.hpp"
12 #include "library/zip.hpp"
14 /**
15 * This structure gives parsed representationg of movie file, as result of decoding or for encoding.
17 struct moviefile
19 /**
20 * Brief information
22 struct brief_info
24 brief_info() { current_frame = 0; rerecords = 0; }
25 brief_info(const std::string& filename);
26 std::string sysregion;
27 std::string corename;
28 std::string projectid;
29 std::string hash[ROM_SLOT_COUNT];
30 std::string hashxml[ROM_SLOT_COUNT];
31 std::string hint[ROM_SLOT_COUNT];
32 uint64_t current_frame;
33 uint64_t rerecords;
34 private:
35 void load(zip::reader& r);
36 void binary_io(std::istream& s);
38 /**
39 * Extract branches.
41 struct branch_extractor
43 branch_extractor(const std::string& filename);
44 virtual ~branch_extractor();
45 virtual std::set<std::string> enumerate() { return real->enumerate(); }
46 virtual void read(const std::string& name, controller_frame_vector& v) { real->read(name, v); }
47 protected:
48 branch_extractor() { real = NULL; }
49 private:
50 branch_extractor* real;
52 /**
53 * This constructor construct movie structure with default settings.
55 * throws std::bad_alloc: Not enough memory.
57 moviefile() throw(std::bad_alloc);
59 /**
60 * This constructor loads a movie/savestate file and fills structure accordingly.
62 * parameter filename: The file to load.
63 * parameter romtype: Type of ROM.
64 * throws std::bad_alloc: Not enough memory.
65 * throws std::runtime_error: Can't load the movie file
67 moviefile(const std::string& filename, core_type& romtype) throw(std::bad_alloc, std::runtime_error);
69 /**
70 * Fill a stub movie with specified loaded ROM.
72 * Parameter rom: The rom.
73 * Parameter settings: The settings.
74 * Parameter rtc_sec: The RTC seconds value.
75 * Parameter rtc_subsec: The RTC subseconds value.
77 moviefile(loaded_rom& rom, std::map<std::string, std::string>& c_settings, uint64_t rtc_sec,
78 uint64_t rtc_subsec);
80 /**
81 * Reads this movie structure and saves it into file.
83 * parameter filename: The file to save to.
84 * parameter compression: The compression level 0-9. 0 is uncompressed.
85 * parameter binary: Save in binary form if true.
86 * parameter rrd: The rerecords data.
87 * throws std::bad_alloc: Not enough memory.
88 * throws std::runtime_error: Can't save the movie file.
90 void save(const std::string& filename, unsigned compression, bool binary, rrdata_set& rrd)
91 throw(std::bad_alloc, std::runtime_error);
92 /**
93 * Reads this movie structure and saves it to stream (uncompressed ZIP).
95 void save(std::ostream& outstream, rrdata_set& rrd) throw(std::bad_alloc, std::runtime_error);
96 /**
97 * Force loading as corrupt.
99 bool force_corrupt;
101 * What is the ROM type and region?
103 core_sysregion* gametype;
105 * Settings.
107 std::map<std::string, std::string> settings;
109 * Emulator Core version string.
111 std::string coreversion;
113 * Name of the game
115 std::string gamename;
117 * Project ID (used to identify if two movies are from the same project).
119 std::string projectid;
121 * Rerecord count (only saved).
123 std::string rerecords;
125 * Rerecord count (memory saves only).
127 uint64_t rerecords_mem;
129 * SHA-256 of ROM (empty string if none).
131 std::string romimg_sha256[ROM_SLOT_COUNT];
133 * SHA-256 of ROM XML (empty string if none).
135 std::string romxml_sha256[ROM_SLOT_COUNT];
137 * ROM name hint (empty string if none).
139 std::string namehint[ROM_SLOT_COUNT];
141 * Authors of the run, first in each pair is full name, second is nickname.
143 std::vector<std::pair<std::string, std::string>> authors;
145 * Contents of SRAM on time of initial powerup.
147 std::map<std::string, std::vector<char>> movie_sram;
149 * Contents of RAM on time of initial powerup.
151 std::map<std::string, std::vector<char>> ramcontent;
153 * True if savestate, false if movie.
155 bool is_savestate;
157 * Contents of SRAM on time of savestate (if is_savestate is true).
159 std::map<std::string, std::vector<char>> sram;
161 * Core savestate (if is_savestate is true).
163 std::vector<char> savestate; //Savestate to load (if is_savestate is true).
165 * Anchoring core savestate (if not empty).
167 std::vector<char> anchor_savestate;
169 * Host memory (if is_savestate is true).
171 std::vector<char> host_memory;
173 * Screenshot (if is_savestate is true).
175 std::vector<char> screenshot;
177 * Current frame (if is_savestate is true).
179 uint64_t save_frame;
181 * Number of lagged frames (if is_savestate is true).
183 uint64_t lagged_frames;
185 * Poll counters (if is_savestate is true).
187 std::vector<uint32_t> pollcounters;
189 * Poll flag.
191 unsigned poll_flag;
193 * Compressed rrdata.
195 std::vector<char> c_rrdata;
197 * Input for each (sub)frame (points to active branch).
199 controller_frame_vector* input;
201 * Branches.
203 std::map<std::string, controller_frame_vector> branches;
205 * Current RTC second.
207 int64_t rtc_second;
209 * Current RTC subsecond.
211 int64_t rtc_subsecond;
213 * Movie starting RTC second.
215 int64_t movie_rtc_second;
217 * Movie starting RTC subsecond.
219 int64_t movie_rtc_subsecond;
221 * Start paused flag.
223 bool start_paused;
225 * Lazy project create flag.
227 bool lazy_project_create;
229 * Subtitles.
231 std::map<moviefile_subtiming, std::string> subtitles;
233 * Active macros at savestate.
235 std::map<std::string, uint64_t> active_macros;
237 * Get number of frames in movie.
239 * returns: Number of frames.
241 uint64_t get_frame_count() throw();
243 * Get length of the movie
245 * returns: Length of the movie in nanoseconds.
247 uint64_t get_movie_length() throw();
249 * Return reference to memory slot.
251 static moviefile*& memref(const std::string& slot);
254 * Copy data.
256 void copy_fields(const moviefile& mv);
259 * Create a default branch.
261 void create_default_branch(port_type_set& ports);
263 * Get name of current branch.
265 const std::string& current_branch();
267 * Fork a branch.
269 void fork_branch(const std::string& oldname, const std::string& newname);
271 * Fixup input pointer post-copy.
273 void fixup_current_branch(const moviefile& mv);
274 private:
275 moviefile(const moviefile&);
276 moviefile& operator=(const moviefile&);
277 void binary_io(std::ostream& stream, rrdata_set& rrd) throw(std::bad_alloc, std::runtime_error);
278 void binary_io(std::istream& stream, struct core_type& romtype) throw(std::bad_alloc, std::runtime_error);
279 void save(zip::writer& w, rrdata_set& rrd) throw(std::bad_alloc, std::runtime_error);
280 void load(zip::reader& r, core_type& romtype) throw(std::bad_alloc, std::runtime_error);
283 void emerg_save_movie(const moviefile& mv, rrdata_set& rrd);
285 #endif