From 27f4eb8f1b78572c005833cfa068e44b56722e01 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Wed, 27 Feb 2019 21:33:20 -0800 Subject: GLK: FROTZ: Move current window into _wp --- engines/glk/frotz/glk_interface.cpp | 20 ++++------ engines/glk/frotz/glk_interface.h | 4 +- engines/glk/frotz/processor_screen.cpp | 66 ++++++++++++++------------------- engines/glk/frotz/processor_windows.cpp | 6 +-- engines/glk/frotz/windows.cpp | 9 ++++- engines/glk/frotz/windows.h | 14 +++++++ 6 files changed, 61 insertions(+), 58 deletions(-) (limited to 'engines/glk') diff --git a/engines/glk/frotz/glk_interface.cpp b/engines/glk/frotz/glk_interface.cpp index ae26ee02eb..9950db1fc5 100644 --- a/engines/glk/frotz/glk_interface.cpp +++ b/engines/glk/frotz/glk_interface.cpp @@ -34,11 +34,10 @@ namespace Frotz { GlkInterface::GlkInterface(OSystem *syst, const GlkGameDescription &gameDesc) : GlkAPI(syst, gameDesc), _pics(nullptr), oldstyle(0), curstyle(0), curr_font(1), prev_font(1), temp_font(0), - curr_status_ht(0), mach_status_ht(0), gos_status(nullptr), gos_curwin(nullptr), gos_linepending(0), - gos_linebuf(nullptr), gos_linewin(nullptr), gos_channel(nullptr), cwin(0), mwin(0), mouse_x(0), mouse_y(0), - fixforced(0), menu_selected(0), enable_wrapping(false), enable_scripting(false), enable_scrolling(false), - enable_buffering(false), next_sample(0), next_volume(0), _soundLocked(false), _soundPlaying(false), - _reverseVideo(false) { + curr_status_ht(0), mach_status_ht(0), gos_status(nullptr), gos_linepending(0), gos_linebuf(nullptr), + gos_linewin(nullptr), gos_channel(nullptr), mwin(0), mouse_x(0), mouse_y(0), fixforced(0), menu_selected(0), + enable_wrapping(false), enable_scripting(false), enable_scrolling(false), enable_buffering(false), + next_sample(0), next_volume(0), _soundLocked(false), _soundPlaying(false), _reverseVideo(false) { Common::fill(&statusline[0], &statusline[256], '\0'); Common::fill(&zcolors[0], &zcolors[zcolor_NUMCOLORS], 0); } @@ -194,9 +193,6 @@ void GlkInterface::initialize() { _wp[i][TRUE_BG_COLOR] = zcolors[h_default_background]; } - cwin = 0; - gos_curwin = _wp._lower; - /* * Icky magic bit setting */ @@ -390,7 +386,7 @@ void GlkInterface::gos_update_width() { void GlkInterface::gos_update_height() { uint height_upper; uint height_lower; - if (gos_curwin) { + if (_wp.currWin()) { glk_window_get_size(_wp._upper, nullptr, &height_upper); glk_window_get_size(_wp._lower, nullptr, &height_lower); h_screen_rows = height_upper + height_lower + 1; @@ -547,7 +543,7 @@ void GlkInterface::showBeyondZorkTitle() { } void GlkInterface::os_draw_picture(int picture, const Common::Point &pos) { - if (cwin == 0) { + if (_wp._cwin == 0) { // Picture embedded within the lower text area glk_image_draw(_wp._lower, picture, imagealign_MarginLeft, 0); } else { @@ -590,7 +586,7 @@ int GlkInterface::os_peek_color() { zchar GlkInterface::os_read_key(int timeout, bool show_cursor) { event_t ev; - winid_t win = gos_curwin ? gos_curwin : _wp._lower; + winid_t win = _wp.currWin() ? _wp.currWin() : _wp._lower; if (gos_linepending) gos_cancel_pending_line(); @@ -638,7 +634,7 @@ zchar GlkInterface::os_read_key(int timeout, bool show_cursor) { zchar GlkInterface::os_read_line(int max, zchar *buf, int timeout, int width, int continued) { event_t ev; - winid_t win = gos_curwin ? gos_curwin : _wp._lower; + winid_t win = _wp.currWin() ? _wp.currWin() : _wp._lower; if (!continued && gos_linepending) gos_cancel_pending_line(); diff --git a/engines/glk/frotz/glk_interface.h b/engines/glk/frotz/glk_interface.h index 22518b8b37..5d47308070 100644 --- a/engines/glk/frotz/glk_interface.h +++ b/engines/glk/frotz/glk_interface.h @@ -75,14 +75,12 @@ public: Windows _wp; winid_t gos_status; - winid_t gos_curwin; int gos_linepending; zchar *gos_linebuf; winid_t gos_linewin; schanid_t gos_channel; - // Current window and mouse data - int cwin; + // Mouse data int mwin; int mouse_y; int mouse_x; diff --git a/engines/glk/frotz/processor_screen.cpp b/engines/glk/frotz/processor_screen.cpp index 9ae076b689..f32bae6c0b 100644 --- a/engines/glk/frotz/processor_screen.cpp +++ b/engines/glk/frotz/processor_screen.cpp @@ -29,7 +29,7 @@ namespace Glk { namespace Frotz { void Processor::screen_mssg_on() { - if (gos_curwin == _wp._lower) { + if (_wp.currWin() == _wp._lower) { oldstyle = curstyle; glk_set_style(style_Preformatted); glk_put_string("\n "); @@ -37,7 +37,7 @@ void Processor::screen_mssg_on() { } void Processor::screen_mssg_off() { - if (gos_curwin == _wp._lower) { + if (_wp.currWin() == _wp._lower) { glk_put_char('\n'); zargs[0] = 0; z_set_text_style(); @@ -101,9 +101,9 @@ uint32 Processor::zchar_to_unicode_rune(zchar c) { } void Processor::screen_char(zchar c) { - if (gos_linepending && (gos_curwin == gos_linewin)) { + if (gos_linepending && (_wp.currWin() == gos_linewin)) { gos_cancel_pending_line(); - if (gos_curwin == _wp._upper) { + if (_wp.currWin() == _wp._upper) { _wp._upper.setCursor(Point(1, _wp._upper[Y_CURSOR] + 1)); } if (c == '\n') @@ -123,7 +123,7 @@ void Processor::screen_char(zchar c) { fixforced = false; } - if (_wp._upper && gos_curwin == _wp._upper) { + if (_wp._upper && _wp.currWin() == _wp._upper) { if (c == '\n' || c == ZC_RETURN) { glk_put_char('\n'); _wp._upper.setCursor(Point(1, _wp._upper[Y_CURSOR] + 1)); @@ -139,7 +139,7 @@ void Processor::screen_char(zchar c) { glk_put_char_uni(c); } else if (curx == h_screen_cols) { glk_put_char_uni(c); - glk_window_move_cursor(gos_curwin, curx-1, cury-1); + glk_window_move_cursor(_wp.currWin(), curx-1, cury-1); } else { smartstatusline(); } @@ -150,13 +150,13 @@ void Processor::screen_char(zchar c) { glk_put_char_uni(c); } else if (curx == (h_screen_cols)) { glk_put_char_uni(c); - glk_window_move_cursor(gos_curwin, curx-1, cury-1); + glk_window_move_cursor(_wp.currWin(), curx-1, cury-1); } curx++; } } - } else if (gos_curwin == _wp._lower) { + } else if (_wp.currWin() == _wp._lower) { if (c == ZC_RETURN) glk_put_char('\n'); else { @@ -205,20 +205,19 @@ void Processor::erase_screen(zword win) { glk_window_clear(_wp._lower); split_window(0); - glk_set_window(_wp._lower); - gos_curwin = _wp._lower; + _wp.setWindow(0); } } void Processor::erase_window(zword win) { - if (h_version == V6 && win != cwin && h_interpreter_number != INTERP_AMIGA) + if (h_version == V6 && win != _wp._cwin && h_interpreter_number != INTERP_AMIGA) garglk_set_zcolors(_wp[win][TRUE_FG_COLOR], _wp[win][TRUE_BG_COLOR]); if (_wp[win]) glk_window_clear(_wp[win]); - if (h_version == V6 && win != cwin && h_interpreter_number != INTERP_AMIGA) - garglk_set_zcolors(_wp[cwin][TRUE_FG_COLOR], _wp[cwin][TRUE_BG_COLOR]); + if (h_version == V6 && win != _wp._cwin && h_interpreter_number != INTERP_AMIGA) + garglk_set_zcolors(_wp[_wp._cwin][TRUE_FG_COLOR], _wp[_wp._cwin][TRUE_BG_COLOR]); } void Processor::z_buffer_mode() { @@ -234,8 +233,8 @@ void Processor::z_erase_line() { flush_buffer(); - if (_wp._upper && gos_curwin == _wp._upper) { - int curx = _wp[cwin][X_CURSOR], cury = _wp[cwin][Y_CURSOR]; + if (_wp._upper && _wp.currWin() == _wp._upper) { + int curx = _wp[_wp._cwin][X_CURSOR], cury = _wp[_wp._cwin][Y_CURSOR]; for (i = 0; i < h_screen_cols + 1 - curx; i++) glk_put_char(' '); @@ -259,8 +258,8 @@ void Processor::z_get_cursor() { flush_buffer(); - x = _wp[cwin][X_CURSOR]; - y = _wp[cwin][Y_CURSOR]; + x = _wp[_wp._cwin][X_CURSOR]; + y = _wp[_wp._cwin][Y_CURSOR]; if (h_version != V6) { // convert to grid positions @@ -274,7 +273,7 @@ void Processor::z_get_cursor() { void Processor::z_print_table() { zword addr = zargs[0]; - int curx = _wp[cwin][X_CURSOR], cury = _wp[cwin][Y_CURSOR]; + int curx = _wp[_wp._cwin][X_CURSOR], cury = _wp[_wp._cwin][Y_CURSOR]; zword xs = curx; int i, j; zbyte c; @@ -287,7 +286,7 @@ void Processor::z_print_table() { // Write text in width x height rectangle for (i = 0; i < zargs[2]; i++, curx = xs, cury++) { - _wp[cwin].setCursor(Point(xs, cury)); + _wp[_wp._cwin].setCursor(Point(xs, cury)); for (j = 0; j < zargs[1]; j++) { LOW_BYTE(addr, c); @@ -368,7 +367,7 @@ void Processor::z_set_colour() { _wp[win][TRUE_FG_COLOR] = fg; _wp[win][TRUE_BG_COLOR] = bg; - if (win == cwin || h_version != V6) + if (win == _wp._cwin || h_version != V6) garglk_set_zcolors(fg, bg); } @@ -419,15 +418,15 @@ void Processor::z_set_font() { void Processor::z_set_cursor() { int x = (int16)zargs[1], y = (int16)zargs[0]; - int win = (h_version == V6) ? winarg2() : cwin; + int win = (h_version == V6) ? winarg2() : _wp._cwin; if (zargc < 3) - zargs[2] = -3; + zargs[2] = (zword)-3; flush_buffer(); _wp[win].setCursor(Point(x, y)); - if (gos_curwin == _wp._upper && _wp[win][Y_CURSOR] > (uint)mach_status_ht) { + if (_wp.currWin() == _wp._upper && _wp[win][Y_CURSOR] > (uint)mach_status_ht) { mach_status_ht = _wp[win][Y_CURSOR]; reset_status_ht(); } @@ -447,7 +446,7 @@ void Processor::z_set_text_style() { else style = curstyle; - if (gos_linepending && gos_curwin == gos_linewin) + if (gos_linepending && _wp.currWin() == gos_linewin) return; if (style & REVERSE_STYLE) { @@ -482,18 +481,9 @@ void Processor::z_set_text_style() { } void Processor::z_set_window() { - cwin = zargs[0]; + _wp.setWindow(zargs[0]); - if (cwin == 0) { - glk_set_window(_wp._lower); - gos_curwin = _wp._lower; - } else { - if (_wp._upper) - glk_set_window(_wp._upper); - gos_curwin = _wp._upper; - } - - if (cwin == 0) + if (_wp._cwin == 0) enable_scripting = true; else enable_scripting = false; @@ -536,8 +526,7 @@ void Processor::z_show_status() { LOW_WORD(addr, global2); // Move to top of the status window, and print in reverse style. - glk_set_window(_wp._upper); - gos_curwin = _wp._upper; + _wp.setWindow(1); os_set_reverse_video(true); _wp._upper.setCursor(Point(1, 1)); @@ -593,8 +582,7 @@ void Processor::z_show_status() { pad_status_line (0); // Return to the lower window - glk_set_window(_wp._lower); - gos_curwin = _wp._lower; + _wp.setWindow(0); } void Processor::z_split_window() { diff --git a/engines/glk/frotz/processor_windows.cpp b/engines/glk/frotz/processor_windows.cpp index 0a50b73d42..a9591c392b 100644 --- a/engines/glk/frotz/processor_windows.cpp +++ b/engines/glk/frotz/processor_windows.cpp @@ -48,7 +48,7 @@ void Processor::z_draw_picture() { flush_buffer(); - Window &win = _wp[cwin]; + Window &win = _wp[_wp._cwin]; if (!x || !y) { // use cursor column if x-coordinate is 0 @@ -281,7 +281,7 @@ void Processor::z_picture_table() { zword Processor::winarg0() { if (h_version == V6 && (short)zargs[0] == -3) - return cwin; + return _wp._cwin; if (zargs[0] >= ((h_version == V6) ? 8 : 2)) runtimeError(ERR_ILL_WIN); @@ -291,7 +291,7 @@ zword Processor::winarg0() { zword Processor::winarg2() { if (zargc < 3 || (short)zargs[2] == -3) - return cwin; + return _wp._cwin; if (zargs[2] >= 8) runtimeError(ERR_ILL_WIN); diff --git a/engines/glk/frotz/windows.cpp b/engines/glk/frotz/windows.cpp index 2e4fdb5758..0e60365807 100644 --- a/engines/glk/frotz/windows.cpp +++ b/engines/glk/frotz/windows.cpp @@ -29,7 +29,7 @@ namespace Glk { namespace Frotz { -Windows::Windows() : _lower(_windows[0]), _upper(_windows[1]), _background(nullptr) { +Windows::Windows() : _lower(_windows[0]), _upper(_windows[1]), _background(nullptr), _cwin(0) { for (size_t idx = 0; idx < 8; ++idx) _windows[idx]._windows = this; } @@ -70,6 +70,13 @@ void Windows::setup(bool isVersion6) { g_vm->glk_set_window(_lower); } +void Windows::setWindow(int win) { + _cwin = win; + + if (_windows[_cwin]._win) + g_vm->glk_set_window(_windows[_cwin]._win); +} + /*--------------------------------------------------------------------------*/ Window::Window() : _windows(nullptr), _win(nullptr) { diff --git a/engines/glk/frotz/windows.h b/engines/glk/frotz/windows.h index 3acb166108..f24be2d636 100644 --- a/engines/glk/frotz/windows.h +++ b/engines/glk/frotz/windows.h @@ -157,6 +157,7 @@ public: winid_t _background; Window &_lower; Window &_upper; + int _cwin; public: /** * Constructor @@ -177,6 +178,19 @@ public: * Setup the screen */ void setup(bool isVersion6); + + /** + * Set current window + */ + void setWindow(int win); + + /** + * Get the current window pointer + */ + winid_t currWin() const { + assert(_windows[_cwin]._win); + return _windows[_cwin]._win; + } }; } // End of namespace Frotz -- cgit v1.2.3