1 #ifndef _movie__hpp__included__
2 #define _movie__hpp__included__
7 #include "controllerframe.hpp"
10 * Movie being played back or recorded
16 * Construct new empty movie.
18 * throws std::bad_alloc: Not enough memory.
20 movie() throw(std::bad_alloc
);
23 * Is the movie in readonly mode?
25 * returns: True if in read-only mode, false if in read-write mode.
27 bool readonly_mode() throw();
30 * Switches movie to read-only or read-write mode. If switching to read-write mode, the movie is truncated.
32 * parameter enable: If true, switch to read-only mode, else to read-write mode.
33 * throws std::bad_alloc: Not enough memory.
35 void readonly_mode(bool enable
) throw(std::bad_alloc
);
38 * Returns the movie rerecord count (this is not the same thing as global rerecord count).
40 * returns: The movie rerecord count
41 * throws std::bad_alloc: Not enough memory.
43 std::string
rerecord_count() throw(std::bad_alloc
);
46 * Sets the movie rerecord count (this is not the same thing as global rerecord count).
48 * parameter count: The new rerecord count
49 * throws std::bad_alloc: Not enough memory.
51 void rerecord_count(const std::string
& count
) throw(std::bad_alloc
);
56 * returns: The project ID
57 * throws std::bad_alloc: Not enough memory.
59 std::string
project_id() throw(std::bad_alloc
);
62 * brief Set project ID
64 * parameter id: New project ID.
65 * throws std::bad_alloc: Not enough memory.
67 void project_id(const std::string
& id
) throw(std::bad_alloc
);
70 * Get number of frames in movie
72 * returns: The number of frames.
74 uint64_t get_frame_count() throw();
77 * Get number of current frame in movie
79 * The first frame in movie is 1. 0 is "before first frame" value.
81 * returns: The number of frame
83 uint64_t get_current_frame() throw();
86 * Get number of lag frames so far
88 * returns: The number of lag frames.
90 uint64_t get_lag_frames() throw();
93 * This function advances to next frame in movie, discarding subframes not used. If the frame is lag frame, it is
94 * counted as lag frame and subframe entry for it is made (if in readwrite mode).
96 * throws std::bad_alloc: Not enough memory.
98 void next_frame() throw(std::bad_alloc
);
101 * Reads the data ready flag. On new frame, all data ready flags are unset. On reading control, its data ready
104 * parameter pid: Physical controller id.
105 * parameter index: Control ID.
106 * returns: The read value.
107 * throws std::logic_error: Invalid control index.
109 bool get_DRDY(unsigned port
, unsigned controller
, unsigned index
) throw(std::logic_error
);
112 * Set all data ready flags
114 void set_all_DRDY() throw();
117 * Poll a control by (port, controller, index) tuple.
119 * parameter pid: Physical controller ID.
120 * parameter index: The index of control in controller (0 to 11)
121 * returns: The read value
122 * throws std::bad_alloc: Not enough memory.
123 * throws std::logic_error: Invalid port, controller or index or before movie start.
125 short next_input(unsigned port
, unsigned controller
, unsigned index
) throw(std::bad_alloc
, std::logic_error
);
128 * Set current control values. These are read in readwrite mode.
130 * parameter controls: The new controls.
132 void set_controls(controller_frame controls
) throw();
135 * Get current control values in effect.
139 controller_frame
get_controls() throw();
142 * Loads a movie plus some other parameters. The playback pointer is positioned to start of movie and readonly
145 * parameter rerecs: Movie rerecord count.
146 * parameter project_id: Project ID of movie.
147 * parameter input: The input track.
148 * throws std::bad_alloc: Not enough memory.
149 * throws std::runtime_error: Bad movie data.
151 void load(const std::string
& rerecs
, const std::string
& project_id
, controller_frame_vector
& input
)
152 throw(std::bad_alloc
, std::runtime_error
);
155 * Saves the movie data.
157 * returns: The movie data.
158 * throws std::bad_alloc: Not enough memory.
160 controller_frame_vector
save() throw(std::bad_alloc
);
163 * This method serializes the state of movie code.
165 * Parameter proj_id: The project ID is written here.
166 * Parameter curframe: Current frame is written here.
167 * Parameter lagframes: Lag counter is written here.
168 * Parameter pcounters: Poll counters are written here.
169 * throws std::bad_alloc: Not enough memory.
171 void save_state(std::string
& proj_id
, uint64_t& curframe
, uint64_t& lagframes
,
172 std::vector
<uint32_t>& pcounters
) throw(std::bad_alloc
);
175 * Given previous serialized state from this movie, restore the state.
177 * Parameter curframe: Current frame.
178 * Parameter lagframe: Lag counter.
179 * Parameter pcounters: Poll counters.
180 * Parameter ro: If true, restore in readonly mode.
181 * Parameter old_movie: Old movie to check for compatiblity against.
182 * Parameter old_projectid: Old project ID to check against.
184 * Throws std::bad_alloc: Not enough memory.
185 * Throws std::runtime_error: Movie check failure.
187 size_t restore_state(uint64_t curframe
, uint64_t lagframe
, const std::vector
<uint32_t>& pcounters
, bool ro
,
188 controller_frame_vector
* old_movie
, const std::string
& old_projectid
) throw(std::bad_alloc
,
191 * Reset the state of movie to initial state.
193 void reset_state() throw();
195 * Get reset status for current frame.
197 * returns: -1 if current frame doesn't have a reset. Otherwise number of cycles to wait for delayed reset (0 is
200 long get_reset_status() throw();
203 * Commit a reset (writes a reset into current frame in readwrite mode).
205 * parameter delay: The number of cycles to delay the reset.
207 void commit_reset(long delay
) throw(std::bad_alloc
);
210 * Get how manyth poll in the frame next poll would be?
212 * returns: Poll number.
214 unsigned next_poll_number();
216 * Get how many subframes there are in specified frame.
218 * parameter frame: The frame number.
219 * returns: Number of subframes (0 if outside movie).
221 uint64_t frame_subframes(uint64_t frame
) throw();
223 * Read controls from specified subframe of specified frame.
225 * parameter frame: The frame number.
226 * parameter subframe: Subframe within frame (first is 0).
227 * returns: The controls for subframe. If subframe is too great, reads last present subframe. If frame is outside
228 * movie, reads all released.
230 controller_frame
read_subframe(uint64_t frame
, uint64_t subframe
) throw();
234 void fast_save(uint64_t& _frame
, uint64_t& _ptr
, uint64_t& _lagc
, std::vector
<uint32_t>& counters
);
238 void fast_load(uint64_t& _frame
, uint64_t& _ptr
, uint64_t& _lagc
, std::vector
<uint32_t>& counters
);
241 //TRUE if readonly mode is active.
243 //Movie (not global!) rerecord count.
244 std::string rerecords
;
246 std::string _project_id
;
247 //The actual controller data.
248 controller_frame_vector movie_data
;
249 //Current frame + 1 (0 before next_frame() has been called.
250 uint64_t current_frame
;
251 //First subframe in current frame (movie_data.size() if no subframes have been stored).
252 uint64_t current_frame_first_subframe
;
253 //How many times has each control been polled (bit 31 is data ready bit)?
254 pollcounter_vector pollcounters
;
255 //Current state of buttons.
256 controller_frame current_controls
;
257 //Number of known lag frames.
259 //Number of frames in movie.
260 uint64_t frames_in_movie
;
262 void clear_caches() throw();
263 uint64_t cached_frame
;
264 uint64_t cached_subframe
;
265 //Count present subframes in frame starting from first_subframe (returns 0 if out of movie).
266 uint32_t count_changes(uint64_t first_subframe
) throw();
270 * Class encapsulating bridge logic between bsnes interface and movie code.
278 movie_logic() throw();
281 * Get the movie instance associated.
283 * returns: The movie instance.
285 movie
& get_movie() throw();
288 * Notify about new frame starting.
290 * returns: Reset status for the new frame.
292 long new_frame_starting(bool dont_poll
) throw(std::bad_alloc
, std::runtime_error
);
297 * parameter port: The port number.
298 * parameter dev: The controller index.
299 * parameter id: Control id.
300 * returns: Value for polled input.
301 * throws std::bad_alloc: Not enough memory.
302 * throws std::runtime_error: Error polling for input.
304 short input_poll(unsigned port
, unsigned dev
, unsigned id
) throw(std::bad_alloc
, std::runtime_error
);
307 * Called when movie code needs new controls snapshot.
309 * parameter subframe: True if this is for subframe update, false if for frame update.
311 controller_frame
update_controls(bool subframe
) throw(std::bad_alloc
, std::runtime_error
);