1 #ifndef _dispatch__hpp__included__
2 #define _dispatch__hpp__included__
5 #include "keymapper.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 * Click or release on window was receivied.
117 * The default handler does nothing.
119 * Parameter x: The x-coordinate of the click. May be negative or otherwise out of screen.
120 * Parameter y: The y-coordinate of the click. May be negative or otherwise out of screen.
121 * Parameter buttonmask: Bitfield giving current buttons held:
122 * Bit 0 => Left button is down/held.
123 * Bit 1 => Middle button is down/held.
124 * Bit 2 => Middle button is down/held.
126 virtual void on_click(int32_t x
, int32_t y
, uint32_t buttonmask
);
128 * Call all on_click() handlers.
130 static void do_click(int32_t x
, int32_t y
, uint32_t buttonmask
) throw();
132 * Sound mute/unmute status might have been changed.
134 * The default handler does nothing.
136 * Parameter unmuted: If true, the sound is now enabled. If false, the sound is now disabled.
138 virtual void on_sound_unmute(bool unmuted
);
140 * Call all on_sound_unmute() handlers.
142 static void do_sound_unmute(bool unmuted
) throw();
144 * Sound device might have been changed.
146 * The default handler does nothing.
148 * Parameter dev: The device name sound is now playing (if enabled) from.
150 virtual void on_sound_change(const std::string
& dev
);
152 * Call all on_sound_change() handlers.
154 static void do_sound_change(const std::string
& dev
) throw();
156 * Emulator mode might have been changed.
158 * The default handler does nothing.
160 * Parameter readonly: True if readonly mode is now active, false if now in readwrite mode.
162 virtual void on_mode_change(bool readonly
);
164 * Call all on_mode_change() handlers.
166 static void do_mode_change(bool readonly
) throw();
168 * Autohold on button might have been changed.
170 * The default handler does nothing.
172 * Parameter pid: The physical ID of controller (0-7).
173 * Parameter ctrlnum: Physical control number (0-15).
174 * Parameter newstate: True if autohold is now active, false if autohold is now inactive.
176 virtual void on_autohold_update(unsigned pid
, unsigned ctrlnum
, bool newstate
);
178 * Call all on_autohold_update() handlers.
180 static void do_autohold_update(unsigned pid
, unsigned ctrlnum
, bool newstate
) throw();
182 * Controller configuration may have been changed.
184 * The default handler does nothing.
186 virtual void on_autohold_reconfigure();
188 * Call all on_autohold_reconfigure() handlers.
190 static void do_autohold_reconfigure() throw();
192 * A setting may have changed.
194 * The default handler does nothing.
196 * Parameter setting: The setting that has possibly changed.
197 * Parameter value: The new value for the setting.
199 virtual void on_setting_change(const std::string
& setting
, const std::string
& value
);
201 * Call all on_setting_change() handlers.
203 static void do_setting_change(const std::string
& setting
, const std::string
& value
) throw();
205 * A setting has been cleared (but it might have been cleared already).
207 * The default handler does nothing.
209 * Parameter setting: The setting that is now clear.
211 virtual void on_setting_clear(const std::string
& setting
);
213 * Call all on_setting_clear() handlers
215 static void do_setting_clear(const std::string
& setting
) throw();
217 * A raw frame has been received.
219 * The default handler does nothing.
221 * Parameter raw: The raw frame data. 512*512 element array.
222 * Parameter hires: True if in hires mode (512 wide), false if not (256-wide).
223 * Parameter interlaced: True if in interlaced mode (448/478 high), false if not (224/239 high).
224 * Parameter overscan: True if overscan is active, false if not.
225 * Parameter region: One of VIDEO_REGION_* contstants, giving the region this frame is from.
227 virtual void on_raw_frame(const uint32_t* raw
, bool hires
, bool interlaced
, bool overscan
, unsigned region
);
229 * Call all on_raw_frame() handlers.
231 * Calls on_new_dumper() on dumpers that had that not yet called.
233 static void do_raw_frame(const uint32_t* raw
, bool hires
, bool interlaced
, bool overscan
, unsigned region
)
236 * A frame has been received.
238 * The default handler does nothing.
240 * Parameter _frame: The frame object.
241 * Parameter fps_n: Numerator of current video fps.
242 * Parameter fps_d: Denominator of current video fps.
244 virtual void on_frame(struct lcscreen
& _frame
, uint32_t fps_n
, uint32_t fps_d
);
246 * Call all on_frame() handlers.
248 * Calls on_new_dumper() on dumpers that had that not yet called.
250 static void do_frame(struct lcscreen
& _frame
, uint32_t fps_n
, uint32_t fps_d
) throw();
252 * A sample has been received.
254 * The default handler does nothing.
256 * Parameter l: The left channel sample (16 bit signed).
257 * Parameter r: The right channel sample (16 bit signed).
259 virtual void on_sample(short l
, short r
);
261 * Call all on_sample() handlers.
263 * Calls on_new_dumper() on dumpers that had that not yet called.
265 static void do_sample(short l
, short r
) throw();
269 * Calls on_new_dumper() on dumpers that had that not yet called.
271 * The default handler does nothing.
273 virtual void on_dump_end();
275 * Call all on_dump_end() handlers.
277 static void do_dump_end() throw();
279 * Sound sampling rate is changing
281 * The default handler prints warning if dumper flag is set.
283 * Parameter rate_n: Numerator of the new sampling rate in Hz.
284 * Parameter rate_d: Denominator of the new sampling rate in Hz.
286 virtual void on_sound_rate(uint32_t rate_n
, uint32_t rate_d
);
288 * Call all on_sound_rate() methods and save the parameters.
290 * Calls on_new_dumper() on dumpers that had that not yet called.
292 static void do_sound_rate(uint32_t rate_n
, uint32_t rate_d
) throw();
294 * Get the sound rate most recently set by on_sound_rate().
296 * Returns: The first component is the numerator, the second is the denominator.
298 static std::pair
<uint32_t, uint32_t> get_sound_rate() throw();
300 * Game information is changing.
302 * The default handler does nothing.
304 * Parameter gi: The new game info.
306 virtual void on_gameinfo(const struct gameinfo_struct
& gi
);
308 * Call all on_gameinfo() handlers and save the gameinfo.
310 static void do_gameinfo(const struct gameinfo_struct
& gi
) throw();
312 * Get the gameinfo most recently set by do_gameinfo().
314 * Returns: The gameinfo.
316 static const struct gameinfo_struct
& get_gameinfo() throw();
318 * Return the dumper flag for this dispatch target.
320 * The default implementation returns false.
322 * If dumper flag is set:
323 * - on_sound_rate() default handler prints a warning.
324 * - All dumping related do_* functions triggers calls to to on_new_dumper() on all handlers the next time they
326 * - Destroying the handler triggers calls to on_destroy_dumper() on all handlers (if on_new_dumper() has been
329 virtual bool get_dumper_flag() throw();
331 * Notify that a new dumper is joining.
333 * Parameter dumper: The name of the dumper object.
335 virtual void on_new_dumper(const std::string
& dumper
);
337 * Notify that a dumper is leaving.
339 * Parameter dumper: The name of the dumper object.
341 virtual void on_destroy_dumper(const std::string
& dumper
);
343 * Get number of active dumpers.
345 * Calls on_new_dumper() on dumpers that had that not yet called.
347 * Returns: The dumper count.
349 static unsigned get_dumper_count() throw();
351 * Get set of active dumpers.
353 * Calls on_new_dumper() on dumpers that had that not yet called.
355 * Returns: The set of dumper names.
356 * Throws std::bad_alloc: Not enough memory.
358 static std::set
<std::string
> get_dumpers() throw(std::bad_alloc
);
360 * (Pseudo-)key has been pressed or released.
362 * Parameter modifiers: The modifier set currently active.
363 * Parameter keygroup: The key group the (pseudo-)key is from.
364 * Parameter subkey: Subkey index within the key group.
365 * Parameter polarity: True if key is being pressed, false if being released.
366 * Parameter name: Name of the key being pressed/released.
368 virtual void on_key_event(const modifier_set
& modifiers
, keygroup
& keygroup
, unsigned subkey
,
369 bool polarity
, const std::string
& name
);
371 * Call on_key_event() for all event handlers (or just one if keys are being grabbed).
373 static void do_key_event(const modifier_set
& modifiers
, keygroup
& keygroup
, unsigned subkey
,
374 bool polarity
, const std::string
& name
) throw();
376 * Grab all key events.
378 * While key events are grabbed, do_key_event() only calls on_key_event() for the grabbing object.
380 void grab_keys() throw();
382 * Ungrab all key events.
384 * While key events are grabbed, do_key_event() only calls on_key_event() for the grabbing object.
386 void ungrab_keys() throw();
388 * Get name of target.
390 const std::string
& get_name() throw();
392 * Set window main screen compensation parameters. This is used for mouse click reporting.
394 * parameter xoffset: X coordinate of origin.
395 * parameter yoffset: Y coordinate of origin.
396 * parameter hscl: Horizontal scaling factor.
397 * parameter vscl: Vertical scaling factor.
399 static void do_click_compensation(uint32_t xoffset
, uint32_t yoffset
, uint32_t hscl
, uint32_t vscl
);
401 static void update_dumpers(bool nocalls
= false) throw();
402 bool known_if_dumper
;
403 bool marked_as_dumper
;
404 std::string target_name
;
405 bool notified_as_dumper
;