1 #ifndef _dispatch__hpp__included__
2 #define _dispatch__hpp__included__
4 #include "core/keymapper.hpp"
5 #include "library/framebuffer.hpp"
6 #include "library/dispatch.hpp"
15 * Video data region is NTSC.
17 #define VIDEO_REGION_NTSC 0
19 * Video data region is PAL.
21 #define VIDEO_REGION_PAL 1
24 * Information about run.
26 struct gameinfo_struct
30 * Construct game info.
32 gameinfo_struct() throw(std::bad_alloc
);
38 * Run length in seconds.
42 * Rerecord count (base 10 ASCII)
44 std::string rerecords
;
46 * Authors. The first components are real names, the second components are nicknames. Either (but not both) may be
49 std::vector
<std::pair
<std::string
, std::string
>> authors
;
51 * Format human-redable representation of the length.
53 * Parameter digits: Number of sub-second digits to use.
54 * Returns: The time formated.
55 * Throws std::bad_alloc: Not enough memory.
57 std::string
get_readable_time(unsigned digits
) const throw(std::bad_alloc
);
59 * Get number of authors.
61 * Returns: Number of authors.
63 size_t get_author_count() const throw();
65 * Get short name of author (nickname if present, otherwise full name).
67 * Parameter idx: Index of author (0-based).
68 * Returns: The short name.
69 * Throws std::bad_alloc: Not enough memory.
71 std::string
get_author_short(size_t idx
) const throw(std::bad_alloc
);
73 * Get rerecord count as a number. If rerecord count is too high, returns the maximum representatible count.
75 * Returns: The rerecord count.
77 uint64_t get_rerecords() const throw();
82 * Information dispatch.
84 * This class handles dispatching information between the components of the emulator.
86 * Each kind of information has virtual method on_foo() which can be overridden to handle events of that type, and
87 * static method do_foo(), which calls on_foo on all known objects.
89 * The information is delivered to each instance of this class.
91 class information_dispatch
95 * Create new object to receive information dispatch events.
97 * Parameter name: The name for the object.
98 * Throws std::bad_alloc: Not enough memory.
100 information_dispatch(const std::string
& name
) throw(std::bad_alloc
);
104 virtual ~information_dispatch() throw();
106 * A frame has been received.
108 * The default handler does nothing.
110 * Parameter _frame: The frame object.
111 * Parameter fps_n: Numerator of current video fps.
112 * Parameter fps_d: Denominator of current video fps.
114 virtual void on_frame(struct framebuffer_raw
& _frame
, uint32_t fps_n
, uint32_t fps_d
);
116 * Call all on_frame() handlers.
118 * Calls on_new_dumper() on dumpers that had that not yet called.
120 static void do_frame(struct framebuffer_raw
& _frame
, uint32_t fps_n
, uint32_t fps_d
) throw();
122 * A sample has been received.
124 * The default handler does nothing.
126 * Parameter l: The left channel sample (16 bit signed).
127 * Parameter r: The right channel sample (16 bit signed).
129 virtual void on_sample(short l
, short r
);
131 * Call all on_sample() handlers.
133 * Calls on_new_dumper() on dumpers that had that not yet called.
135 static void do_sample(short l
, short r
) throw();
139 * Calls on_new_dumper() on dumpers that had that not yet called.
141 * The default handler does nothing.
143 virtual void on_dump_end();
145 * Call all on_dump_end() handlers.
147 static void do_dump_end() throw();
149 * Sound sampling rate is changing
151 * The default handler prints warning if dumper flag is set.
153 * Parameter rate_n: Numerator of the new sampling rate in Hz.
154 * Parameter rate_d: Denominator of the new sampling rate in Hz.
156 virtual void on_sound_rate(uint32_t rate_n
, uint32_t rate_d
);
158 * Call all on_sound_rate() methods and save the parameters.
160 * Calls on_new_dumper() on dumpers that had that not yet called.
162 static void do_sound_rate(uint32_t rate_n
, uint32_t rate_d
) throw();
164 * Get the sound rate most recently set by on_sound_rate().
166 * Returns: The first component is the numerator, the second is the denominator.
168 static std::pair
<uint32_t, uint32_t> get_sound_rate() throw();
170 * Game information is changing.
172 * The default handler does nothing.
174 * Parameter gi: The new game info.
176 virtual void on_gameinfo(const struct gameinfo_struct
& gi
);
178 * Call all on_gameinfo() handlers and save the gameinfo.
180 static void do_gameinfo(const struct gameinfo_struct
& gi
) throw();
182 * Get the gameinfo most recently set by do_gameinfo().
184 * Returns: The gameinfo.
186 static const struct gameinfo_struct
& get_gameinfo() throw();
188 * Return the dumper flag for this dispatch target.
190 * The default implementation returns false.
192 * If dumper flag is set:
193 * - on_sound_rate() default handler prints a warning.
194 * - All dumping related do_* functions triggers calls to to on_new_dumper() on all handlers the next time they
196 * - Destroying the handler triggers calls to on_destroy_dumper() on all handlers (if on_new_dumper() has been
199 virtual bool get_dumper_flag() throw();
201 * Notify that a new dumper is joining.
203 * Parameter dumper: The name of the dumper object.
205 virtual void on_new_dumper(const std::string
& dumper
);
207 * Notify that a dumper is leaving.
209 * Parameter dumper: The name of the dumper object.
211 virtual void on_destroy_dumper(const std::string
& dumper
);
213 * Get number of active dumpers.
215 * Calls on_new_dumper() on dumpers that had that not yet called.
217 * Returns: The dumper count.
219 static unsigned get_dumper_count() throw();
221 * Get set of active dumpers.
223 * Calls on_new_dumper() on dumpers that had that not yet called.
225 * Returns: The set of dumper names.
226 * Throws std::bad_alloc: Not enough memory.
228 static std::set
<std::string
> get_dumpers() throw(std::bad_alloc
);
230 * Get name of target.
232 const std::string
& get_name() throw();
234 * Notify that some dumper has attached, deattached, popped into existence or disappeared.
236 * Default implementation does nothing.
238 virtual void on_dumper_update();
240 * Call on_dumper_update on on all objects.
242 static void do_dumper_update() throw();
245 * Call to indicate this target is interested in sound sample data.
247 void enable_send_sound() throw(std::bad_alloc
);
249 static void update_dumpers(bool nocalls
= false) throw();
250 bool known_if_dumper
;
251 bool marked_as_dumper
;
252 std::string target_name
;
253 bool notified_as_dumper
;
256 void dispatch_set_error_streams(std::ostream
* stream
);
258 extern struct dispatcher
<> notify_autohold_reconfigure
;
259 extern struct dispatcher
<unsigned, unsigned, unsigned, bool> notify_autohold_update
;
260 extern struct dispatcher
<unsigned, unsigned, unsigned, unsigned, unsigned> notify_autofire_update
;
261 extern struct dispatcher
<> notify_close
;
262 extern struct dispatcher
<framebuffer
<false>&> notify_set_screen
;
263 extern struct dispatcher
<std::pair
<std::string
, std::string
>> notify_sound_change
;
264 extern struct dispatcher
<> notify_screen_update
;
265 extern struct dispatcher
<> notify_status_update
;
266 extern struct dispatcher
<bool> notify_sound_unmute
;
267 extern struct dispatcher
<bool> notify_mode_change
;
268 extern struct dispatcher
<> notify_core_change
;
269 extern struct dispatcher
<bool> notify_core_changed
;
270 extern struct dispatcher
<> notify_new_core
;
271 extern struct dispatcher
<> notify_voice_stream_change
;
272 extern struct dispatcher
<> notify_vu_change
;
273 extern struct dispatcher
<> notify_subtitle_change
;