1 #ifndef _dispatch__hpp__included__
2 #define _dispatch__hpp__included__
4 #include "core/keymapper.hpp"
5 #include "library/framebuffer.hpp"
14 * Video data region is NTSC.
16 #define VIDEO_REGION_NTSC 0
18 * Video data region is PAL.
20 #define VIDEO_REGION_PAL 1
23 * Information about run.
25 struct gameinfo_struct
29 * Construct game info.
31 gameinfo_struct() throw(std::bad_alloc
);
37 * Run length in seconds.
41 * Rerecord count (base 10 ASCII)
43 std::string rerecords
;
45 * Authors. The first components are real names, the second components are nicknames. Either (but not both) may be
48 std::vector
<std::pair
<std::string
, std::string
>> authors
;
50 * Format human-redable representation of the length.
52 * Parameter digits: Number of sub-second digits to use.
53 * Returns: The time formated.
54 * Throws std::bad_alloc: Not enough memory.
56 std::string
get_readable_time(unsigned digits
) const throw(std::bad_alloc
);
58 * Get number of authors.
60 * Returns: Number of authors.
62 size_t get_author_count() const throw();
64 * Get short name of author (nickname if present, otherwise full name).
66 * Parameter idx: Index of author (0-based).
67 * Returns: The short name.
68 * Throws std::bad_alloc: Not enough memory.
70 std::string
get_author_short(size_t idx
) const throw(std::bad_alloc
);
72 * Get rerecord count as a number. If rerecord count is too high, returns the maximum representatible count.
74 * Returns: The rerecord count.
76 uint64_t get_rerecords() const throw();
81 * Information dispatch.
83 * This class handles dispatching information between the components of the emulator.
85 * Each kind of information has virtual method on_foo() which can be overridden to handle events of that type, and
86 * static method do_foo(), which calls on_foo on all known objects.
88 * The information is delivered to each instance of this class.
90 class information_dispatch
94 * Create new object to receive information dispatch events.
96 * Parameter name: The name for the object.
97 * Throws std::bad_alloc: Not enough memory.
99 information_dispatch(const std::string
& name
) throw(std::bad_alloc
);
103 ~information_dispatch() throw();
105 * Window close event received (this is not emulator close!)
107 * The default handler does nothing.
109 virtual void on_close();
111 * Call all on_close() handlers.
113 static void do_close() throw();
115 * Sound mute/unmute status might have been changed.
117 * The default handler does nothing.
119 * Parameter unmuted: If true, the sound is now enabled. If false, the sound is now disabled.
121 virtual void on_sound_unmute(bool unmuted
);
123 * Call all on_sound_unmute() handlers.
125 static void do_sound_unmute(bool unmuted
) throw();
127 * Sound device might have been changed.
129 * The default handler does nothing.
131 * Parameter dev: The device name sound is now playing (if enabled) from.
133 virtual void on_sound_change(const std::string
& dev
);
135 * Call all on_sound_change() handlers.
137 static void do_sound_change(const std::string
& dev
) throw();
139 * Emulator mode might have been changed.
141 * The default handler does nothing.
143 * Parameter readonly: True if readonly mode is now active, false if now in readwrite mode.
145 virtual void on_mode_change(bool readonly
);
147 * Call all on_mode_change() handlers.
149 static void do_mode_change(bool readonly
) throw();
151 * Autohold on button might have been changed.
153 * The default handler does nothing.
155 * Parameter pid: The physical ID of controller (0-7).
156 * Parameter ctrlnum: Physical control number (0-15).
157 * Parameter newstate: True if autohold is now active, false if autohold is now inactive.
159 virtual void on_autohold_update(unsigned pid
, unsigned ctrlnum
, bool newstate
);
161 * Call all on_autohold_update() handlers.
163 static void do_autohold_update(unsigned pid
, unsigned ctrlnum
, bool newstate
) throw();
165 * Controller configuration may have been changed.
167 * The default handler does nothing.
169 virtual void on_autohold_reconfigure();
171 * Call all on_autohold_reconfigure() handlers.
173 static void do_autohold_reconfigure() throw();
175 * A setting may have changed.
177 * The default handler does nothing.
179 * Parameter setting: The setting that has possibly changed.
180 * Parameter value: The new value for the setting.
182 virtual void on_setting_change(const std::string
& setting
, const std::string
& value
);
184 * Call all on_setting_change() handlers.
186 static void do_setting_change(const std::string
& setting
, const std::string
& value
) throw();
188 * A setting has been cleared (but it might have been cleared already).
190 * The default handler does nothing.
192 * Parameter setting: The setting that is now clear.
194 virtual void on_setting_clear(const std::string
& setting
);
196 * Call all on_setting_clear() handlers
198 static void do_setting_clear(const std::string
& setting
) throw();
200 * A raw frame has been received.
202 * The default handler does nothing.
204 * Parameter raw: The raw frame data. 512*512 element array.
205 * Parameter hires: True if in hires mode (512 wide), false if not (256-wide).
206 * Parameter interlaced: True if in interlaced mode (448/478 high), false if not (224/239 high).
207 * Parameter overscan: True if overscan is active, false if not.
208 * Parameter region: One of VIDEO_REGION_* contstants, giving the region this frame is from.
210 virtual void on_raw_frame(const uint32_t* raw
, bool hires
, bool interlaced
, bool overscan
, unsigned region
);
212 * Call all on_raw_frame() handlers.
214 * Calls on_new_dumper() on dumpers that had that not yet called.
216 static void do_raw_frame(const uint32_t* raw
, bool hires
, bool interlaced
, bool overscan
, unsigned region
)
219 * A frame has been received.
221 * The default handler does nothing.
223 * Parameter _frame: The frame object.
224 * Parameter fps_n: Numerator of current video fps.
225 * Parameter fps_d: Denominator of current video fps.
227 virtual void on_frame(struct framebuffer_raw
& _frame
, uint32_t fps_n
, uint32_t fps_d
);
229 * Call all on_frame() handlers.
231 * Calls on_new_dumper() on dumpers that had that not yet called.
233 static void do_frame(struct framebuffer_raw
& _frame
, uint32_t fps_n
, uint32_t fps_d
) throw();
235 * A sample has been received.
237 * The default handler does nothing.
239 * Parameter l: The left channel sample (16 bit signed).
240 * Parameter r: The right channel sample (16 bit signed).
242 virtual void on_sample(short l
, short r
);
244 * Call all on_sample() handlers.
246 * Calls on_new_dumper() on dumpers that had that not yet called.
248 static void do_sample(short l
, short r
) throw();
252 * Calls on_new_dumper() on dumpers that had that not yet called.
254 * The default handler does nothing.
256 virtual void on_dump_end();
258 * Call all on_dump_end() handlers.
260 static void do_dump_end() throw();
262 * Sound sampling rate is changing
264 * The default handler prints warning if dumper flag is set.
266 * Parameter rate_n: Numerator of the new sampling rate in Hz.
267 * Parameter rate_d: Denominator of the new sampling rate in Hz.
269 virtual void on_sound_rate(uint32_t rate_n
, uint32_t rate_d
);
271 * Call all on_sound_rate() methods and save the parameters.
273 * Calls on_new_dumper() on dumpers that had that not yet called.
275 static void do_sound_rate(uint32_t rate_n
, uint32_t rate_d
) throw();
277 * Get the sound rate most recently set by on_sound_rate().
279 * Returns: The first component is the numerator, the second is the denominator.
281 static std::pair
<uint32_t, uint32_t> get_sound_rate() throw();
283 * Game information is changing.
285 * The default handler does nothing.
287 * Parameter gi: The new game info.
289 virtual void on_gameinfo(const struct gameinfo_struct
& gi
);
291 * Call all on_gameinfo() handlers and save the gameinfo.
293 static void do_gameinfo(const struct gameinfo_struct
& gi
) throw();
295 * Get the gameinfo most recently set by do_gameinfo().
297 * Returns: The gameinfo.
299 static const struct gameinfo_struct
& get_gameinfo() throw();
301 * Return the dumper flag for this dispatch target.
303 * The default implementation returns false.
305 * If dumper flag is set:
306 * - on_sound_rate() default handler prints a warning.
307 * - All dumping related do_* functions triggers calls to to on_new_dumper() on all handlers the next time they
309 * - Destroying the handler triggers calls to on_destroy_dumper() on all handlers (if on_new_dumper() has been
312 virtual bool get_dumper_flag() throw();
314 * Notify that a new dumper is joining.
316 * Parameter dumper: The name of the dumper object.
318 virtual void on_new_dumper(const std::string
& dumper
);
320 * Notify that a dumper is leaving.
322 * Parameter dumper: The name of the dumper object.
324 virtual void on_destroy_dumper(const std::string
& dumper
);
326 * Get number of active dumpers.
328 * Calls on_new_dumper() on dumpers that had that not yet called.
330 * Returns: The dumper count.
332 static unsigned get_dumper_count() throw();
334 * Get set of active dumpers.
336 * Calls on_new_dumper() on dumpers that had that not yet called.
338 * Returns: The set of dumper names.
339 * Throws std::bad_alloc: Not enough memory.
341 static std::set
<std::string
> get_dumpers() throw(std::bad_alloc
);
343 * (Pseudo-)key has been pressed or released.
345 * Parameter modifiers: The modifier set currently active.
346 * Parameter keygroup: The key group the (pseudo-)key is from.
347 * Parameter subkey: Subkey index within the key group.
348 * Parameter polarity: True if key is being pressed, false if being released.
349 * Parameter name: Name of the key being pressed/released.
351 virtual void on_key_event(const modifier_set
& modifiers
, keygroup
& keygroup
, unsigned subkey
,
352 bool polarity
, const std::string
& name
);
354 * Call on_key_event() for all event handlers (or just one if keys are being grabbed).
356 static void do_key_event(const modifier_set
& modifiers
, keygroup
& keygroup
, unsigned subkey
,
357 bool polarity
, const std::string
& name
) throw();
359 * Grab all key events.
361 * While key events are grabbed, do_key_event() only calls on_key_event() for the grabbing object.
363 void grab_keys() throw();
365 * Ungrab all key events.
367 * While key events are grabbed, do_key_event() only calls on_key_event() for the grabbing object.
369 void ungrab_keys() throw();
371 * Get name of target.
373 const std::string
& get_name() throw();
375 * Render buffer needs to be (possibly) resized, so that graphics plugin can update the mappings.
377 * Default implementation does nothing.
379 * parameter scr: The render buffer object.
381 virtual void on_set_screen(framebuffer
<false>& scr
);
383 * Call on_set_screen on all objects.
385 static void do_set_screen(framebuffer
<false>& scr
) throw();
387 * Notify that new frame is available.
389 * Default implementation does nothing.
391 virtual void on_screen_update();
393 * Call on_screen_update() in all objects.
395 static void do_screen_update() throw();
397 * Notify that status buffer has been updated.
399 * Default implementation does nothing.
401 virtual void on_status_update();
403 * Call on_status_update() in all objects.
405 static void do_status_update() throw();
407 * Notify that some dumper has attached, deattached, popped into existence or disappeared.
409 * Default implementation does nothing.
411 virtual void on_dumper_update();
413 * Call on_dumper_update on on all objects.
415 static void do_dumper_update() throw();
417 * Notify about changes to voice streams.
419 * Default implementation does nothing.
421 virtual void on_voice_stream_change();
423 * Call on_voice_stream_change on all objects.
425 static void do_voice_stream_change() throw();
427 * Notify about changes to subtitles.
429 * Default implementation does nothing.
431 virtual void on_subtitle_change();
433 * Call on_subtitle_change on all objects.
435 static void do_subtitle_change() throw();
437 * Notify about changes to VU levels.
439 * Default implementation does nothing.
441 virtual void on_vu_change();
443 * Call on_vu_change on all objects.
445 static void do_vu_change() throw();
449 * Call to indicate this target is interested in sound sample data.
451 void enable_send_sound() throw(std::bad_alloc
);
453 static void update_dumpers(bool nocalls
= false) throw();
454 bool known_if_dumper
;
455 bool marked_as_dumper
;
456 std::string target_name
;
457 bool notified_as_dumper
;