From a2104deb4cefdcf0cd6bb3a66ef09bb46cba3f66 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Tue, 13 Nov 2018 20:05:59 -0800 Subject: GLK: Changing class and namespaces from Gargoyle to Glk --- engines/glk/glk.h | 363 ++++++++++++++++++++---------------------------------- 1 file changed, 132 insertions(+), 231 deletions(-) (limited to 'engines/glk/glk.h') diff --git a/engines/glk/glk.h b/engines/glk/glk.h index f71ad764ac..92ea2aba91 100644 --- a/engines/glk/glk.h +++ b/engines/glk/glk.h @@ -23,270 +23,171 @@ #ifndef GLK_GLK_H #define GLK_GLK_H -#include "glk/gargoyle.h" +#include "common/scummsys.h" +#include "common/random.h" +#include "common/system.h" +#include "common/serializer.h" +#include "engines/advancedDetector.h" +#include "engines/engine.h" #include "glk/glk_types.h" -#include "glk/blorb.h" -#include "glk/time.h" -#include "glk/windows.h" -namespace Gargoyle { +namespace Glk { + +class Clipboard; +class Conf; +class Events; +class PicList; +class Screen; +class Selection; +class Streams; +class Windows; + +enum InterpreterType { + INTERPRETER_ADVSYS = 0, + INTERPRETER_AGILITY = 1, + INTERPRETER_ALAN2 = 2, + INTERPRETER_ALAN3 = 3, + INTERPRETER_BOCFEL = 4, + INTERPRETER_FROTZ = 5, + INTERPRETER_GEAS = 6, + INTERPRETER_HUGO = 7, + INTERPRETER_JACL = 8, + INTERPRETER_LEVEL9 = 9, + INTERPRETER_MAGNETIC = 10, + INTERPRETER_NITFOL = 11, + INTERPRETER_SCARE = 12, + INTERPRETER_SCOTT = 13, + INTERPRETER_TADS = 14 +}; -/** - * Implements the GLK interface - */ -class Glk : public GargoyleEngine, public Blorb { -private: - bool _gliFirstEvent; - unsigned char _charTolowerTable[256]; - unsigned char _charToupperTable[256]; -public: - /** - * Constructor - */ - Glk(OSystem *syst, const GargoyleGameDescription *gameDesc); +enum GlkDebugChannels { + kDebugCore = 1 << 0, + kDebugScripts = 1 << 1, + kDebugGraphics = 1 << 2, + kDebugSound = 1 << 3 +}; - void glk_exit(void); - void glk_set_interrupt_handler(void(*func)(void)); - void glk_tick(void); - glui32 glk_gestalt(glui32 id, glui32 val); - glui32 glk_gestalt_ext(glui32 id, glui32 val, glui32 *arr, glui32 arrlen); +#define GLK_SAVEGAME_VERSION 1 - unsigned char glk_char_to_lower(unsigned char ch); - unsigned char glk_char_to_upper(unsigned char ch); +struct GlkGameDescription; +/** + * Base class for the different interpreters + */ +class GlkEngine : public Engine { +private: /** - * Get the root window of the window hierarchy + * Handles basic initialization */ - winid_t glk_window_get_root(void) const; + void initialize(); /** - * Open a new window + * Setup the video mode */ - winid_t glk_window_open(winid_t split, glui32 method, glui32 size, - glui32 wintype, glui32 rock = 0) const; - - void glk_window_close(winid_t win, stream_result_t *result = nullptr); - void glk_window_get_size(winid_t win, glui32 *width, glui32 *height); - void glk_window_set_arrangement(winid_t win, glui32 method, - glui32 size, winid_t keyWin); - void glk_window_get_arrangement(winid_t win, glui32 *method, - glui32 *size, winid_t *keyWin); - winid_t glk_window_iterate(winid_t win, glui32 *rock = 0); - glui32 glk_window_get_rock(winid_t win); - glui32 glk_window_get_type(winid_t win); - winid_t glk_window_get_parent(winid_t win); - winid_t glk_window_get_sibling(winid_t win); - void glk_window_clear(winid_t win); - void glk_window_move_cursor(winid_t win, glui32 xpos, glui32 ypos); - - strid_t glk_window_get_stream(winid_t win); - void glk_window_set_echo_stream(winid_t win, strid_t str); - strid_t glk_window_get_echo_stream(winid_t win); - void glk_set_window(winid_t win); - - strid_t glk_stream_open_file(frefid_t fileref, FileMode fmode, glui32 rock = 0); - strid_t glk_stream_open_memory(char *buf, glui32 buflen, FileMode fmode, glui32 rock = 0); - void glk_stream_close(strid_t str, stream_result_t *result = nullptr); - strid_t glk_stream_iterate(strid_t str, glui32 *rockptr) const; - glui32 glk_stream_get_rock(strid_t str) const; - void glk_stream_set_position(strid_t str, glsi32 pos, glui32 seekMode); - glui32 glk_stream_get_position(strid_t str) const; - void glk_stream_set_current(strid_t str); - strid_t glk_stream_get_current(void); - - void glk_put_char(unsigned char ch); - void glk_put_char_stream(strid_t str, unsigned char ch); - void glk_put_string(const char *s); - void glk_put_string_stream(strid_t str, const char *s); - void glk_put_buffer(char *buf, glui32 len); - void glk_put_buffer_stream(strid_t str, const char *buf, glui32 len); - void glk_set_style(glui32 styl); - void glk_set_style_stream(strid_t str, glui32 styl); - - glsi32 glk_get_char_stream(strid_t str); - glui32 glk_get_line_stream(strid_t str, char *buf, glui32 len); - glui32 glk_get_buffer_stream(strid_t str, char *buf, glui32 len); - - void glk_stylehint_set(glui32 wintype, glui32 styl, glui32 hint, - glsi32 val); - void glk_stylehint_clear(glui32 wintype, glui32 style, glui32 hint); - glui32 glk_style_distinguish(winid_t win, glui32 style1, glui32 style2); - bool glk_style_measure(winid_t win, glui32 style, glui32 hint, glui32 *result); + void initGraphicsMode(); +protected: + const GlkGameDescription *_gameDescription; + Common::RandomSource _random; + int _loadSaveSlot; - frefid_t glk_fileref_create_temp(glui32 usage, glui32 rock = 0); - frefid_t glk_fileref_create_by_name(glui32 usage, const char *name, glui32 rock = 0); - frefid_t glk_fileref_create_by_prompt(glui32 usage, FileMode fmode, glui32 rock = 0); - frefid_t glk_fileref_create_from_fileref(glui32 usage, frefid_t fref, glui32 rock = 0); - void glk_fileref_destroy(frefid_t fref); - frefid_t glk_fileref_iterate(frefid_t fref, glui32 *rockptr); - glui32 glk_fileref_get_rock(frefid_t fref); - void glk_fileref_delete_file(frefid_t fref); - glui32 glk_fileref_does_file_exist(frefid_t fref); + // Engine APIs + virtual Common::Error run(); - void glk_select(event_t *event); - void glk_select_poll(event_t *event); - - void glk_request_timer_events(glui32 millisecs); - - void glk_request_line_event(winid_t win, char *buf, glui32 maxlen, - glui32 initlen); - void glk_request_char_event(winid_t win); - void glk_request_mouse_event(winid_t win); - - void glk_cancel_line_event(winid_t win, event_t *event); - void glk_cancel_char_event(winid_t win); - void glk_cancel_mouse_event(winid_t win); - -#ifdef GLK_MODULE_LINE_ECHO - void glk_set_echo_line_event(winid_t win, glui32 val); -#endif /* GLK_MODULE_LINE_ECHO */ - -#ifdef GLK_MODULE_LINE_TERMINATORS - void glk_set_terminators_line_event(winid_t win, glui32 *keycodes, - glui32 count); -#endif /* GLK_MODULE_LINE_TERMINATORS */ + /** + * Returns true whether a given feature is supported by the engine + */ + virtual bool hasFeature(EngineFeature f) const; - /** \addtogroup Unicode - * @{ + /** + * Main game loop for the individual interpreters */ + virtual void runGame(Common::SeekableReadStream *gameFile) = 0; +public: + Clipboard *_clipboard; + Conf *_conf; + Events *_events; + PicList *_picList; + Screen *_screen; + Selection *_selection; + Streams *_streams; + Windows *_windows; + bool _copySelect; + bool _terminated; + void (*gli_unregister_obj)(void *obj, glui32 objclass, gidispatch_rock_t objrock); + gidispatch_rock_t (*gli_register_arr)(void *array, glui32 len, const char *typecode); + void (*gli_unregister_arr)(void *array, glui32 len, const char *typecode, gidispatch_rock_t objrock); - glui32 glk_buffer_to_lower_case_uni(glui32 *buf, glui32 len, - glui32 numchars); - glui32 glk_buffer_to_upper_case_uni(glui32 *buf, glui32 len, - glui32 numchars); - glui32 glk_buffer_to_title_case_uni(glui32 *buf, glui32 len, - glui32 numchars, glui32 lowerrest); - - void glk_put_char_uni(glui32 ch); - void glk_put_string_uni(glui32 *s); - void glk_put_buffer_uni(glui32 *buf, glui32 len); - void glk_put_char_stream_uni(strid_t str, glui32 ch); - void glk_put_string_stream_uni(strid_t str, const glui32 *s); - void glk_put_buffer_stream_uni(strid_t str, const glui32 *buf, glui32 len); - - glsi32 glk_get_char_stream_uni(strid_t str); - glui32 glk_get_buffer_stream_uni(strid_t str, glui32 *buf, glui32 len); - glui32 glk_get_line_stream_uni(strid_t str, glui32 *buf, glui32 len); - - strid_t glk_stream_open_file_uni(frefid_t fileref, FileMode fmode, glui32 rock = 0); - strid_t glk_stream_open_memory_uni(glui32 *buf, glui32 buflen, FileMode fmode, glui32 rock = 0); - - void glk_request_char_event_uni(winid_t win); - void glk_request_line_event_uni(winid_t win, glui32 *buf, - glui32 maxlen, glui32 initlen); - - /** @}*/ - -#ifdef GLK_MODULE_UNICODE_NORM - - glui32 glk_buffer_canon_decompose_uni(glui32 *buf, glui32 len, - glui32 numchars); - glui32 glk_buffer_canon_normalize_uni(glui32 *buf, glui32 len, - glui32 numchars); - -#endif /* GLK_MODULE_UNICODE_NORM */ - -#ifdef GLK_MODULE_IMAGE - - glui32 glk_image_draw(winid_t win, glui32 image, glsi32 val1, glsi32 val2); - glui32 glk_image_draw_scaled(winid_t win, glui32 image, - glsi32 val1, glsi32 val2, glui32 width, glui32 height); - glui32 glk_image_get_info(glui32 image, glui32 *width, glui32 *height); - - void glk_window_flow_break(winid_t win); - - void glk_window_erase_rect(winid_t win, - glsi32 left, glsi32 top, glui32 width, glui32 height); - void glk_window_fill_rect(winid_t win, glui32 color, - glsi32 left, glsi32 top, glui32 width, glui32 height); - void glk_window_set_background_color(winid_t win, glui32 color); - -#endif /* GLK_MODULE_IMAGE */ - -#ifdef GLK_MODULE_SOUND - - schanid_t glk_schannel_create(glui32 rock = 0); - void glk_schannel_destroy(schanid_t chan); - schanid_t glk_schannel_iterate(schanid_t chan, glui32 *rockptr); - glui32 glk_schannel_get_rock(schanid_t chan); - - glui32 glk_schannel_play(schanid_t chan, glui32 snd); - glui32 glk_schannel_play_ext(schanid_t chan, glui32 snd, glui32 repeats, - glui32 notify); - void glk_schannel_stop(schanid_t chan); - void glk_schannel_set_volume(schanid_t chan, glui32 vol); - - void glk_sound_load_hint(glui32 snd, glui32 flag); - -#ifdef GLK_MODULE_SOUND2 - /* Note that this section is nested inside the #ifdef GLK_MODULE_SOUND. - GLK_MODULE_SOUND must be defined if GLK_MODULE_SOUND2 is. */ - - schanid_t glk_schannel_create_ext(glui32 rock, glui32 volume); - glui32 glk_schannel_play_multi(schanid_t *chanarray, glui32 chancount, - glui32 *sndarray, glui32 soundcount, glui32 notify); - void glk_schannel_pause(schanid_t chan); - void glk_schannel_unpause(schanid_t chan); - void glk_schannel_set_volume_ext(schanid_t chan, glui32 vol, - glui32 duration, glui32 notify); - -#endif /* GLK_MODULE_SOUND2 */ -#endif /* GLK_MODULE_SOUND */ - -#ifdef GLK_MODULE_HYPERLINKS +public: + GlkEngine(OSystem *syst, const GlkGameDescription *gameDesc); + virtual ~GlkEngine(); - void glk_set_hyperlink(glui32 linkval); - void glk_set_hyperlink_stream(strid_t str, glui32 linkval); - void glk_request_hyperlink_event(winid_t win); - void glk_cancel_hyperlink_event(winid_t win); + /** + * Returns true if a savegame can be loaded + */ + virtual bool canLoadGameStateCurrently() override { + return true; + } -#endif /* GLK_MODULE_HYPERLINKS */ + /** + * Returns true if the game can be saved + */ + virtual bool canSaveGameStateCurrently() override { + return true; + } -#ifdef GLK_MODULE_DATETIME + /** + * Returns the bitset of game features + */ + uint32 getFeatures() const; - void glk_current_time(glktimeval_t *time); - glsi32 glk_current_simple_time(glui32 factor); - void glk_time_to_date_utc(const glktimeval_t *time, glkdate_t *date); - void glk_time_to_date_local(const glktimeval_t *time, glkdate_t *date); - void glk_simple_time_to_date_utc(glsi32 time, glui32 factor, glkdate_t *date); - void glk_simple_time_to_date_local(glsi32 time, glui32 factor, glkdate_t *date); - void glk_date_to_time_utc(const glkdate_t *date, glktimeval_t *time); - void glk_date_to_time_local(const glkdate_t *date, glktimeval_t *time); - glsi32 glk_date_to_simple_time_utc(const glkdate_t *date, glui32 factor); - glsi32 glk_date_to_simple_time_local(const glkdate_t *date, glui32 factor); + /** + * Returns whether the game is a demo + */ + bool isDemo() const; -#endif /* GLK_MODULE_DATETIME */ + /** + * Returns the language + */ + Common::Language getLanguage() const; - /* XXX non-official Glk functions that may or may not exist */ -#define GARGLK 1 + /** + * Returns the running interpreter type + */ + InterpreterType getInterpreterType() const; - const char *garglk_fileref_get_name(frefid_t fref) const; + /** + * Returns the game's md5 + */ + const Common::String &getGameMD5() const; - void garglk_set_program_name(const char *name); - void garglk_set_program_info(const char *info); - void garglk_set_story_name(const char *name); - void garglk_set_story_title(const char *title); - void garglk_set_config(const char *name); + /** + * Returns the primary filename for the game + */ + const Common::String &getFilename() const; /** - * Removes the specified string from the end of the output buffer, if - * indeed it is there. + * Return the game engine's target name */ - void garglk_unput_string(const char *str); + const Common::String &getTargetName() const { + return _targetName; + } /** - * Removes the specified string from the end of the output buffer, if - * indeed it is there. + * Return the filename for a given save slot */ - void garglk_unput_string_uni(const glui32 *str); + Common::String getSaveName(uint slot) const { + return Common::String::format("%s.%.3u", getTargetName().c_str(), slot); + } - void garglk_set_zcolors(glui32 fg, glui32 bg); - void garglk_set_zcolors_stream(strid_t str, glui32 fg, glui32 bg); - void garglk_set_reversevideo(glui32 reverse); - void garglk_set_reversevideo_stream(strid_t str, glui32 reverse); + /** + * Display a message in a GUI dialog + */ + void GUIError(const char *msg, ...); }; -} // End of namespace Gargoyle +extern GlkEngine *g_vm; + +} // End of namespace Glk #endif -- cgit v1.2.3