From d158280425efac5f4ec72e00fb2b7389cdfb5a75 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Tue, 24 Feb 2004 22:39:42 +0000 Subject: the OSystem changes we discussed on the ML (note: renaming of the existing OSystem API is not yet finished); porters will have to fix their ports to get them to compile again svn-id: r13036 --- common/debugger.cpp | 8 +- common/system.cpp | 42 +++++++-- common/system.h | 250 ++++++++++++++++++++++++++++++++++------------------ 3 files changed, 201 insertions(+), 99 deletions(-) (limited to 'common') diff --git a/common/debugger.cpp b/common/debugger.cpp index 03fd28688d..39460c863a 100644 --- a/common/debugger.cpp +++ b/common/debugger.cpp @@ -67,9 +67,7 @@ int Debugger::DebugPrintf(const char *format, ...) { template void Debugger::attach(const char *entry) { - OSystem::Property prop; - prop.show_keyboard = true; - g_system->property(OSystem::PROP_TOGGLE_VIRTUAL_KEYBOARD, &prop); + g_system->setFeatureState(OSystem::kFeatureVirtualKeyboard, true); if (entry) { _errStr = strdup(entry); @@ -82,9 +80,7 @@ void Debugger::attach(const char *entry) { template void Debugger::detach() { - OSystem::Property prop; - prop.show_keyboard = false; - g_system->property(OSystem::PROP_TOGGLE_VIRTUAL_KEYBOARD, &prop); + g_system->setFeatureState(OSystem::kFeatureVirtualKeyboard, false); _detach_now = false; _isAttached = false; diff --git a/common/system.cpp b/common/system.cpp index 59dcee87b3..348273a4c8 100644 --- a/common/system.cpp +++ b/common/system.cpp @@ -29,11 +29,13 @@ #include "common/config-manager.h" #include "common/system.h" -OSystem *g_system = 0; +static OSystem *s_system = 0; static OSystem *createSystem() { - int gfx_mode = GameDetector::parseGraphicsMode(ConfMan.get("gfx_mode")); // FIXME: Get rid of this again! - + // Attention: Do not call parseGraphicsMode() here, nor any other function + // which needs to access the OSystem instance, else you get stuck in an + // endless loop. + #if defined(USE_NULL_DRIVER) return OSystem_NULL_create(); #elif defined(__DC__) @@ -52,12 +54,38 @@ static OSystem *createSystem() { return OSystem_PALMOS_create(gfx_mode); #else /* SDL is the default driver for now */ - return OSystem_SDL_create(gfx_mode); + return OSystem_SDL_create(); #endif } OSystem *OSystem::instance() { - if (!g_system) - g_system = createSystem(); - return g_system; + if (!s_system) + s_system = createSystem(); + return s_system; +} + + +bool OSystem::setGraphicsMode(const char *name) { + if (!name) + return false; + + const GraphicsMode *gm = getSupportedGraphicsModes(); + + // Sepcial case for the 'default' filter + if (!scumm_stricmp(name, "normal") || !scumm_stricmp(name, "default")) { +#ifdef _WIN32_WCE + name = "1x"; +#else + name = "2x"; +#endif + } + + while (gm->name) { + if (!scumm_stricmp(gm->name, name)) { + return setGraphicsMode(gm->id); + } + gm++; + } + + return false; } diff --git a/common/system.h b/common/system.h index d8ead1f7d1..288a92eb18 100644 --- a/common/system.h +++ b/common/system.h @@ -26,6 +26,7 @@ #include "common/scummsys.h" #include "common/savefile.h" + /** * Interface for ScummVM backends. If you want to port ScummVM to a system * which is not currently covered by any of our backends, this is the place @@ -38,105 +39,115 @@ */ class OSystem { public: + /** + * Return a pointer to the (singleton) OSystem instance, i.e. the backend. + * This is not a proper singleton, since OSystem is an interface, not + * a real class. + */ static OSystem *instance(); public: - typedef struct Mutex *MutexRef; - typedef void (*SoundProc)(void *param, byte *buf, int len); - typedef int (*TimerProc)(int interval); + /** Virtual destructor */ + virtual ~OSystem() {} + + + /** @name Graphics */ + //@{ + /** - * The types of events backends can generate. - * @see Event + * A feature in this context means an ability of the backend which can be + * either on or off. Examples include: + * - fullscreen mode + * - aspect ration correction + * - a virtual keyboard for text entry (on PDAs) */ - enum EventCode { - EVENT_KEYDOWN = 1, - EVENT_KEYUP = 2, - EVENT_MOUSEMOVE = 3, - EVENT_LBUTTONDOWN = 4, - EVENT_LBUTTONUP = 5, - EVENT_RBUTTONDOWN = 6, - EVENT_RBUTTONUP = 7, - EVENT_WHEELUP = 8, - EVENT_WHEELDOWN = 9, - - EVENT_QUIT = 10, - EVENT_SCREEN_CHANGED = 11 + enum Feature { + kFeatureFullscreenMode, + kFeatureAspectRatioCorrection, + kFeatureVirtualKeyboard, + kFeatureAutoComputeDirtyRects }; - - enum { - KBD_CTRL = 1, - KBD_ALT = 2, - KBD_SHIFT = 4 - }; - + /** - * Data structure for an event. A pointer to an instance of Event - * can be passed to poll_event. + * Determine whether the backend supports the specified feature. */ - struct Event { - EventCode event_code; - struct { - int keycode; - uint16 ascii; - byte flags; - } kbd; - struct { - int x; - int y; - } mouse; - }; + virtual bool hasFeature(Feature f) { return false; } - enum { - PROP_TOGGLE_FULLSCREEN = 1, - PROP_SET_WINDOW_CAPTION, - PROP_OPEN_CD, - PROP_SET_GFX_MODE, - PROP_GET_GFX_MODE, - PROP_GET_SAMPLE_RATE, - PROP_GET_FULLSCREEN, - PROP_GET_FMOPL_ENV_BITS, - PROP_GET_FMOPL_EG_ENT, - PROP_TOGGLE_ASPECT_RATIO, - PROP_TOGGLE_MOUSE_GRAB, - PROP_WANT_RECT_OPTIM, - PROP_HAS_SCALER, - PROP_TOGGLE_VIRTUAL_KEYBOARD - }; - union Property { - const char *caption; - int cd_num; - int gfx_mode; - bool show_cursor; - bool show_keyboard; - }; + /** + * En-/disable the specified feature. For example, this may be used to + * enable fullscreen mode, or to deactivate aspect correction, etc. + */ + virtual void setFeatureState(Feature f, bool enable) {} - enum SoundFormat { - SOUND_8BIT = 0, - SOUND_16BIT = 1 - }; - + /** + * Query the state of the specified feature. For example, test whether + * fullscreen mode is active or not. + */ + virtual bool getFeatureState(Feature f) { return false; } - /** Virtual destructor */ - virtual ~OSystem() {} + //@} /** @name Graphics */ //@{ - /** Set the size of the video bitmap. Typically 320x200 pixels. */ - virtual void init_size(uint w, uint h) = 0; + struct GraphicsMode { + const char *name; + const char *description; + int id; + }; + + /** + * Retrieve a list of all graphics modes supported by this backend. + * This can be both video modes as well as graphic filters/scalers; + * it is completely up to the backend maintainer to decide what is + * appropriate here and what not. + * The list is terminated by an all-zero entry. + * @return a list of supported graphics modes + */ + virtual const GraphicsMode *getSupportedGraphicsModes() const = 0; + + /** + * Switch to the specified graphics mode. If switching to the new mode + * failed, this method returns false. + * @param mode the ID of the new graphics mode + * @return true if the switch was successful, false otherwise + */ + virtual bool setGraphicsMode(int mode) = 0; + + /** + * Switch to the graphics mode with the given name. If 'name' is unknown, + * or if switching to the new mode failed, this method returns false. + * @param mode the name of the new graphics mode + * @return true if the switch was successful, false otherwise + */ + virtual bool setGraphicsMode(const char *name); + + /** + * Determine which graphics mode is currently active. + * @return the active graphics mode + */ + virtual int getGraphicsMode() const = 0; + + /** + * Set the size of the video bitmap. Typical sizes include: + * - 320x200 (e.g. for most SCUMM games, and Simon) + * - 320x240 (e.g. for FM-TOWN SCUMM games) + * - 640x480 (e.g. for Curse of Monkey Island) + */ + virtual void initSize(uint w, uint h) = 0; /** * Returns the currently set screen height. - * @see init_size + * @see initSize * @return the currently set screen height */ virtual int16 get_height() = 0; /** * Returns the currently set screen width. - * @see init_size + * @see initSize * @return the currently set screen width */ virtual int16 get_width() = 0; @@ -220,6 +231,50 @@ public: /** @name Events and Time */ //@{ + typedef int (*TimerProc)(int interval); + + /** + * The types of events backends can generate. + * @see Event + */ + enum EventCode { + EVENT_KEYDOWN = 1, + EVENT_KEYUP = 2, + EVENT_MOUSEMOVE = 3, + EVENT_LBUTTONDOWN = 4, + EVENT_LBUTTONUP = 5, + EVENT_RBUTTONDOWN = 6, + EVENT_RBUTTONUP = 7, + EVENT_WHEELUP = 8, + EVENT_WHEELDOWN = 9, + + EVENT_QUIT = 10, + EVENT_SCREEN_CHANGED = 11 + }; + + enum { + KBD_CTRL = 1, + KBD_ALT = 2, + KBD_SHIFT = 4 + }; + + /** + * Data structure for an event. A pointer to an instance of Event + * can be passed to poll_event. + */ + struct Event { + EventCode event_code; + struct { + int keycode; + uint16 ascii; + byte flags; + } kbd; + struct { + int x; + int y; + } mouse; + }; + /** Get the number of milliseconds since the program was started. */ virtual uint32 get_msecs() = 0; @@ -242,22 +297,30 @@ public: /** @name Sound */ //@{ + typedef void (*SoundProc)(void *param, byte *buf, int len); + /** * Set the audio callback which is invoked whenever samples need to be generated. * Currently, only the 16-bit signed mode is ever used for Simon & Scumm * @param proc pointer to the callback. * @param param an arbitrary parameter which is stored and passed to proc. - * @param format the sample type format. */ - virtual bool set_sound_proc(SoundProc proc, void *param, SoundFormat format) = 0; + virtual bool setSoundCallback(SoundProc proc, void *param) = 0; /** - * Remove any audio callback previously set via set_sound_proc, thus effectively + * Remove any audio callback previously set via setSoundCallback, thus effectively * stopping all audio output immediately. - * @see set_sound_proc + * @see setSoundCallback */ - virtual void clear_sound_proc() = 0; - //@} + virtual void clearSoundCallback() = 0; + + /** + * Determine the output sample rate. Audio data provided by the sound + * callback will be played using this rate. + * @return the output sample rate + */ + virtual int getOutputSampleRate() const = 0; + //@} @@ -268,7 +331,13 @@ public: //@{ /** - * Poll CD status + * Initialise the specified CD drive for audio playback. + * @return true if the CD drive was inited succesfully + */ + virtual bool openCD(int drive) = 0; + + /** + * Poll CD status. * @return true if CD audio is playing */ virtual bool poll_cdrom() = 0; @@ -283,20 +352,24 @@ public: virtual void play_cdrom(int track, int num_loops, int start_frame, int duration) = 0; /** - // Stop audio CD playback + * Stop audio CD playback. */ virtual void stop_cdrom() = 0; /** - // Update cdrom audio status + * Update cdrom audio status. */ virtual void update_cdrom() = 0; + //@} /** @name Mutex handling */ //@{ + + typedef struct Mutex *MutexRef; + /** * Create a new mutex. * @return the newly created mutex, or 0 if an error occured. @@ -341,12 +414,16 @@ public: /** @name Miscellaneous */ //@{ - /** Get or set a backend property. */ - virtual uint32 property(int param, Property *value) = 0; - /** Quit (exit) the application. */ virtual void quit() = 0; + /** + * Set a window caption or any other comparable status display to the + * given value. + * @param caption the window caption to use from now on + */ + virtual void setWindowCaption(const char *caption) {} + /** Savefile management. */ virtual SaveFileManager *get_savefile_manager() { return new SaveFileManager(); @@ -355,6 +432,7 @@ public: }; /** The global OSystem instance. Inited in main(). */ -extern OSystem *g_system; +#define g_system (OSystem::instance()) + #endif -- cgit v1.2.3