From 9433afa7a9fc967c3243215eb3f5576c6d51a544 Mon Sep 17 00:00:00 2001 From: Ilari Liusvaara Date: Mon, 31 Oct 2011 21:05:54 +0200 Subject: [PATCH] Reorganize the window code a bit --- generic/window.cpp | 7 +++ generic/window.hpp | 108 ++++++++++++++++++++++++++++---------- platform/SDL/joystick-sdl.cpp | 2 +- platform/SDL/window-sdl.cpp | 11 ++-- platform/dummy/joystick-dummy.cpp | 2 +- platform/dummy/window-dummy.cpp | 10 ---- platform/evdev/joystick-evdev.cpp | 2 +- 7 files changed, 94 insertions(+), 48 deletions(-) diff --git a/generic/window.cpp b/generic/window.cpp index 6c403070..5c52e0b2 100644 --- a/generic/window.cpp +++ b/generic/window.cpp @@ -76,6 +76,8 @@ namespace } }); + std::map emustatus; + class window_output { public: @@ -118,6 +120,11 @@ namespace window_callback* wcb = NULL; } +std::map& window::get_emustatus() throw() +{ + return emustatus; +} + void window::init() { graphics_init(); diff --git a/generic/window.hpp b/generic/window.hpp index a8163fab..3bea5dac 100644 --- a/generic/window.hpp +++ b/generic/window.hpp @@ -45,6 +45,8 @@ public: /** * Sound/Graphics init/quit functions. Sound init is called after graphics init, and vice versa for quit. + * + * These need to be implemented by the corresponding plugins. */ void graphics_init(); void sound_init(); @@ -59,40 +61,62 @@ void joystick_quit(); class window { public: +/** + * Window constructor. + */ window() throw() {} /** * Initialize the graphics system. + * + * Implemented by generic window code. */ static void init(); /** * Shut down the graphics system. + * + * Implemented by generic window code. */ static void quit(); /** - * Adds a messages to mesage queue to be shown. + * Get output stream printing into message queue. * - * parameter msg: The messages to add (split by '\n'). + * Note that lines printed there should be terminated by '\n'. + * + * Implemented by the generic window code. + * + * returns: The output stream. * throws std::bad_alloc: Not enough memory. */ - static void message(const std::string& msg) throw(std::bad_alloc); + static std::ostream& out() throw(std::bad_alloc); /** - * Get output stream printing into message queue. + * Get emulator status area * - * Note that lines printed there should be terminated by '\n'. + * Implemented by the generic window code. + * + * returns: Emulator status area. + */ + static std::map& get_emustatus() throw(); + +/** + * Adds a messages to mesage queue to be shown. * - * returns: The output stream. + * Needs to be implemented by the graphics plugin. + * + * parameter msg: The messages to add (split by '\n'). * throws std::bad_alloc: Not enough memory. */ - static std::ostream& out() throw(std::bad_alloc); + static void message(const std::string& msg) throw(std::bad_alloc); /** * Displays a modal message, not returning until the message is acknowledged. Keybindings are not available, but * should quit be generated somehow, modal message will be closed and command callback triggered. * + * Needs to be implemented by the graphics plugin. + * * parameter msg: The message to show. * parameter confirm: If true, ask for Ok/cancel type input. * returns: If confirm is true, true if ok was chosen, false if cancel was chosen. Otherwise always false. @@ -102,6 +126,8 @@ public: /** * Displays fatal error message, quitting after the user acks it. + * + * Needs to be implemented by the graphics plugin. */ static void fatal_error() throw(); @@ -109,20 +135,17 @@ public: * Processes inputs. If in non-modal mode (normal mode without pause), this returns quickly. Otherwise it waits * for modal mode to exit. Also needs to call poll_joysticks(). * + * Needs to be implemented by the graphics plugin. + * * throws std::bad_alloc: Not enough memory. */ static void poll_inputs() throw(std::bad_alloc); /** - * Get emulator status area - * - * returns: Emulator status area. - */ - static std::map& get_emustatus() throw(); - -/** * Notify that the screen has been updated. * + * Needs to be implemented by the graphics plugin. + * * parameter full: Do full refresh if true. */ static void notify_screen_update(bool full = false) throw(); @@ -130,6 +153,8 @@ public: /** * Set the screen to use as main surface. * + * Needs to be implemented by the graphics plugin. + * * parameter scr: The screen to use. */ static void set_main_surface(screen& scr) throw(); @@ -137,6 +162,8 @@ public: /** * Enable/Disable pause mode. * + * Needs to be implemented by the graphics plugin. + * * parameter enable: Enable pause if true, disable otherwise. */ static void paused(bool enable) throw(); @@ -144,6 +171,8 @@ public: /** * Wait specified number of microseconds (polling for input). * + * Needs to be implemented by the graphics plugin. + * * parameter usec: Number of us to wait. * throws std::bad_alloc: Not enough memory. */ @@ -151,18 +180,36 @@ public: /** * Cancel pending wait_usec, making it return now. + * + * Needs to be implemented by the graphics plugin. */ static void cancel_wait() throw(); /** + * Set window main screen compensation parameters. This is used for mouse click reporting. + * + * Needs to be implemented by the graphics plugin. + * + * parameter xoffset: X coordinate of origin. + * parameter yoffset: Y coordinate of origin. + * parameter hscl: Horizontal scaling factor. + * parameter vscl: Vertical scaling factor. + */ + static void set_window_compensation(uint32_t xoffset, uint32_t yoffset, uint32_t hscl, uint32_t vscl); + +/** * Enable or disable sound. * + * Needs to be implemented by the sound plugin. + * * parameter enable: Enable sounds if true, otherwise disable sounds. */ static void sound_enable(bool enable) throw(); /** - * Input audio sample (at 32040.5Hz). + * Input audio sample (at specified rate). + * + * Needs to be implemented by the sound plugin. * * parameter left: Left sample. * parameter right: Right sample. @@ -170,18 +217,10 @@ public: static void play_audio_sample(uint16_t left, uint16_t right) throw(); /** - * Set window main screen compensation parameters. This is used for mouse click reporting. - * - * parameter xoffset: X coordinate of origin. - * parameter yoffset: Y coordinate of origin. - * parameter hscl: Horizontal scaling factor. - * parameter vscl: Vertical scaling factor. - */ - static void set_window_compensation(uint32_t xoffset, uint32_t yoffset, uint32_t hscl, uint32_t vscl); - -/** * Set sound sampling rate. * + * Needs to be implemented by the sound plugin. + * * parameter rate_n: Numerator of sampling rate. * parameter rate_d: Denomerator of sampling rate. */ @@ -189,30 +228,45 @@ public: /** * Has the sound system been successfully initialized? + * + * Needs to be implemented by the sound plugin. */ static bool sound_initialized(); /** * Set sound device. + * + * Needs to be implemented by the sound plugin. */ static void set_sound_device(const std::string& dev); /** * Get current sound device. + * + * Needs to be implemented by the sound plugin. */ static std::string get_current_sound_device(); /** * Get available sound devices. + * + * Needs to be implemented by the sound plugin. */ static std::map get_sound_devices(); +/** + * Poll joysticks. + * + * Needs to be implemented by the joystick plugin. + */ + static void poll_joysticks(); private: window(const window&); window& operator==(const window&); }; -void poll_joysticks(); - +/** + * Names of plugins. + */ extern const char* sound_plugin_name; extern const char* graphics_plugin_name; extern const char* joystick_plugin_name; diff --git a/platform/SDL/joystick-sdl.cpp b/platform/SDL/joystick-sdl.cpp index be7e859e..e36070bf 100644 --- a/platform/SDL/joystick-sdl.cpp +++ b/platform/SDL/joystick-sdl.cpp @@ -1,6 +1,6 @@ //Empty -void poll_joysticks() +void window::poll_joysticks() { //We poll it in event loop for SDL. } diff --git a/platform/SDL/window-sdl.cpp b/platform/SDL/window-sdl.cpp index c6257493..203de631 100644 --- a/platform/SDL/window-sdl.cpp +++ b/platform/SDL/window-sdl.cpp @@ -475,7 +475,6 @@ namespace unsigned old_screen_w; unsigned old_screen_h; unsigned state; - std::map emustatus; std::map messagebuffer; uint64_t messagebuffer_next_seq; uint64_t messagebuffer_first_seq; @@ -1135,6 +1134,7 @@ namespace void show_fps() { + auto& emustatus = window::get_emustatus(); try { std::ostringstream y; y << get_framerate(); @@ -1201,6 +1201,7 @@ namespace { uint32_t status_x = screensize.first + 16; uint32_t status_y = 6; + auto& emustatus = window::get_emustatus(); for(auto i : emustatus) { std::string msg = i.first + " " + i.second; draw_string(reinterpret_cast(swsurf->pixels), swsurf->pitch, msg, status_x, status_y, @@ -1311,8 +1312,7 @@ void poll_inputs_internal() throw(std::bad_alloc) if(state == WINSTATE_IDENTIFY) keygroup::set_exclusive_key_listener(&h); while(state != WINSTATE_NORMAL) { - - poll_joysticks(); + window::poll_joysticks(); if(SDL_PollEvent(&e)) do_event(e); ::wait_usec(10000); @@ -1344,11 +1344,6 @@ void window::poll_inputs() throw(std::bad_alloc) } } -std::map& window::get_emustatus() throw() -{ - return emustatus; -} - void window::paused(bool enable) throw() { pause_active = enable; diff --git a/platform/dummy/joystick-dummy.cpp b/platform/dummy/joystick-dummy.cpp index 240b33cf..8f6de611 100644 --- a/platform/dummy/joystick-dummy.cpp +++ b/platform/dummy/joystick-dummy.cpp @@ -1,6 +1,6 @@ #include "window.hpp" -void poll_joysticks() +void window::poll_joysticks() { } diff --git a/platform/dummy/window-dummy.cpp b/platform/dummy/window-dummy.cpp index 5bac2a86..f1681dd4 100644 --- a/platform/dummy/window-dummy.cpp +++ b/platform/dummy/window-dummy.cpp @@ -2,11 +2,6 @@ #include #include -namespace -{ - std::map status; -} - void graphics_init() {} void graphics_quit() {} void window::poll_inputs() throw(std::bad_alloc) {} @@ -37,11 +32,6 @@ void window::message(const std::string& msg) throw(std::bad_alloc) std::cout << msg << std::endl; } -std::map& window::get_emustatus() throw() -{ - return status; -} - uint64_t get_ticks_msec() throw() { static uint64_t c = 0; diff --git a/platform/evdev/joystick-evdev.cpp b/platform/evdev/joystick-evdev.cpp index b7606365..0a582b79 100644 --- a/platform/evdev/joystick-evdev.cpp +++ b/platform/evdev/joystick-evdev.cpp @@ -387,7 +387,7 @@ namespace }); } -void poll_joysticks() +void window::poll_joysticks() { for(int fd : joysticks) { while(read_one_input_event(fd)); -- 2.11.4.GIT