From d84295a22efbece1d87710fd6ff3dcfea8371e39 Mon Sep 17 00:00:00 2001 From: dshaligram Date: Sat, 27 Oct 2007 16:44:37 +0000 Subject: Trunk->0.3 merge (2628-2629): View code fixes for DOS. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/branches/stone_soup-0.3@2630 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/acr.cc | 4 -- crawl-ref/source/beam.cc | 4 -- crawl-ref/source/direct.h | 15 +++++++ crawl-ref/source/libdos.h | 2 + crawl-ref/source/libunix.cc | 38 +++++++++++++++++ crawl-ref/source/libunix.h | 8 ++++ crawl-ref/source/libw32c.cc | 15 +++++++ crawl-ref/source/libw32c.h | 5 ++- crawl-ref/source/output.cc | 2 - crawl-ref/source/view.cc | 100 ++++++++++++++------------------------------ 10 files changed, 112 insertions(+), 81 deletions(-) diff --git a/crawl-ref/source/acr.cc b/crawl-ref/source/acr.cc index 6660f1b755..c41f6af728 100644 --- a/crawl-ref/source/acr.cc +++ b/crawl-ref/source/acr.cc @@ -1829,11 +1829,7 @@ static void prep_input() { you.time_taken = player_speed(); you.shield_blocks = 0; // no blocks this round -#ifdef UNIX update_screen(); -#else - window( 1, 1, 80, get_number_of_lines() ); -#endif textcolor(LIGHTGREY); diff --git a/crawl-ref/source/beam.cc b/crawl-ref/source/beam.cc index dec5d4758a..1f47dad544 100644 --- a/crawl-ref/source/beam.cc +++ b/crawl-ref/source/beam.cc @@ -1458,10 +1458,8 @@ void fire_beam( bolt &pbolt, item_def *item ) gotoxy(drawx, drawy); putch(pbolt.type); -#ifdef UNIX // get curses to update the screen so we can see the beam update_screen(); -#endif delay(15); @@ -4447,12 +4445,10 @@ void explosion( bolt &beam, bool hole_in_the_middle, } // new-- delay after every 'ring' {gdl} -#ifdef UNIX // If we don't refresh curses we won't // guarantee that the explosion is visible if (drawing) update_screen(); -#endif // only delay on real explosion if (!beam.is_tracer && drawing) delay(50); diff --git a/crawl-ref/source/direct.h b/crawl-ref/source/direct.h index 9d9198b1a1..ad4f6f3b44 100644 --- a/crawl-ref/source/direct.h +++ b/crawl-ref/source/direct.h @@ -18,6 +18,19 @@ #include "enum.h" #include "ray.h" +class crawl_view_buffer +{ +public: + crawl_view_buffer(); + ~crawl_view_buffer(); + void size(const coord_def &size); + operator screen_buffer_t * () { return (buffer); } + + void draw(); +private: + screen_buffer_t *buffer; +}; + // last updated 12may2000 {dlb} /* *********************************************************************** * called from: acr - debug - effects - it_use3 - item_use - spells1 - @@ -34,6 +47,8 @@ public: coord_def msgp; // Left-top pos of the message pane. coord_def msgsz; // Size of the message pane. + crawl_view_buffer vbuf; // Buffer for drawing the main game map. + coord_def vgrdc; // What grid pos is at the centre of the view // usually you.pos(). diff --git a/crawl-ref/source/libdos.h b/crawl-ref/source/libdos.h index 38bbd48699..bbf8720009 100644 --- a/crawl-ref/source/libdos.h +++ b/crawl-ref/source/libdos.h @@ -1,6 +1,8 @@ #ifndef __LIBDOS_H__ #define __LIBDOS_H__ +typedef unsigned char screen_buffer_t; + void init_libdos(); int get_number_of_lines(); diff --git a/crawl-ref/source/libunix.cc b/crawl-ref/source/libunix.cc index 1f8f1d67f9..c4a64a779e 100644 --- a/crawl-ref/source/libunix.cc +++ b/crawl-ref/source/libunix.cc @@ -593,6 +593,44 @@ int window(int x1, int y1, int x2, int y2) return (refresh()); } +// NOTE: This affects libunix.cc draw state; use this just before setting +// textcolour and drawing a character and call set_altcharset(false) +// after you're done drawing. +// +int cset_adjust(int raw) +{ + if (Options.char_set != CSET_ASCII && Options.char_set != CSET_UNICODE) + { + // switch to alternate char set for 8-bit characters: + set_altcharset( raw > 127 ); + + // shift the DEC line drawing set: + if (Options.char_set == CSET_DEC + && raw >= 0xE0) + { + raw &= 0x7F; + } + } + return (raw); +} + +void puttext(int x1, int y1, int x2, int y2, const screen_buffer_t *buf) +{ + for (int y = y1; y <= y2; ++y) + { + gotoxy(x1, y); + for (int x = x1; x <= x2; ++x) + { + const screen_buffer_t ch = cset_adjust( *buf ); + textattr( buf[1] ); + putwch( ch ); + buf += 2; + } + } + set_altcharset(false); + update_screen(); +} + // These next four are front functions so that we can reduce // the amount of curses special code that occurs outside this // this file. This is good, since there are some issues with diff --git a/crawl-ref/source/libunix.h b/crawl-ref/source/libunix.h index cee2e6577e..ee424433df 100644 --- a/crawl-ref/source/libunix.h +++ b/crawl-ref/source/libunix.h @@ -7,6 +7,12 @@ #define O_BINARY O_RDWR #endif +#ifdef UNICODE_GLYPHS +typedef unsigned int screen_buffer_t; +#else +typedef unsigned short screen_buffer_t; +#endif + char getche(void); void message_out(int mline, int colour, const char *str, int firstcol = 0, @@ -30,6 +36,7 @@ int translate_keypad(int keyin); int wherex(void); int wherey(void); int window(int x1, int y1, int x2, int y2); +void puttext(int x1, int y1, int x2, int y2, const screen_buffer_t *); void update_screen(void); void clear_to_end_of_line(void); void clear_to_end_of_screen(void); @@ -41,6 +48,7 @@ void unixcurses_startup(void); void textbackground(int bg); void textcolor(int col); void textattr(int col); +int cset_adjust(int raw); void set_altcharset(bool alt_on); bool get_altcharset(); diff --git a/crawl-ref/source/libw32c.cc b/crawl-ref/source/libw32c.cc index c50d095067..81279dd7b3 100644 --- a/crawl-ref/source/libw32c.cc +++ b/crawl-ref/source/libw32c.cc @@ -987,6 +987,21 @@ int get_console_string(char *buf, int maxlen) return (int)nread; } +void puttext(int x1, int y1, int x2, int y2, const screen_buffer_t *buf) +{ + for (int y = y1; y <= y2; ++y) + { + gotoxy(x1, y); + for (int x = x1; x <= x2; x++) + { + textattr( buf[1] ); + putwch( *buf ); + buf += 2; + } + } + update_screen(); +} + void update_screen() { bFlush(); diff --git a/crawl-ref/source/libw32c.h b/crawl-ref/source/libw32c.h index 6e424a43ca..09ccbb906b 100644 --- a/crawl-ref/source/libw32c.h +++ b/crawl-ref/source/libw32c.h @@ -8,6 +8,8 @@ #include #include +typedef unsigned short screen_buffer_t; + void init_libw32c(void); void deinit_libw32c(void); @@ -45,6 +47,7 @@ int getche(void); int kbhit(void); void delay(int ms); void textbackground(int c); +void puttext(int x1, int y1, int x2, int y2, const screen_buffer_t *); void update_screen(); void enable_smart_cursor(bool cursor); @@ -52,5 +55,3 @@ bool is_smart_cursor_enabled(); void set_mouse_enabled(bool enabled); #endif - - diff --git a/crawl-ref/source/output.cc b/crawl-ref/source/output.cc index e48a9a8884..ee215b8ee2 100644 --- a/crawl-ref/source/output.cc +++ b/crawl-ref/source/output.cc @@ -621,10 +621,8 @@ void print_stats(void) cprintf( "Position (%2d,%2d)", you.x_pos, you.y_pos ); #endif -#ifdef UNIX // get curses to redraw screen update_screen(); -#endif } // end print_stats() const char* itosym1(int stat) diff --git a/crawl-ref/source/view.cc b/crawl-ref/source/view.cc index 9c51826ca3..0371313bf1 100644 --- a/crawl-ref/source/view.cc +++ b/crawl-ref/source/view.cc @@ -80,12 +80,6 @@ static FixedVector Feature; -#ifdef UNICODE_GLYPHS -typedef unsigned int screen_buffer_t; -#else -typedef unsigned short screen_buffer_t; -#endif - crawl_view_geometry crawl_view; FixedArray < unsigned int, ENV_SHOW_DIAMETER, ENV_SHOW_DIAMETER > Show_Backup; @@ -2530,29 +2524,6 @@ static int find_feature( const std::vector& features, return 0; } -#ifdef USE_CURSES -// NOTE: This affects libunix.cc draw state; use this just before setting -// textcolour and drawing a character and call set_altcharset(false) -// after you're done drawing. -// -static int cset_adjust(int raw) -{ - if (Options.char_set != CSET_ASCII && Options.char_set != CSET_UNICODE) - { - // switch to alternate char set for 8-bit characters: - set_altcharset( raw > 127 ); - - // shift the DEC line drawing set: - if (Options.char_set == CSET_DEC - && raw >= 0xE0) - { - raw &= 0x7F; - } - } - return (raw); -} -#endif - static int get_number_of_lines_levelmap() { return get_number_of_lines() - (Options.level_map_title ? 1 : 0); @@ -2639,25 +2610,9 @@ static void draw_level_map(int start_x, int start_y, bool travel_mode) } bufcount2 += 2; - - // newline - if (screen_x == 0 && screen_y > 0) - gotoxy( 1, screen_y + top ); - - unsigned ch = buffer2[bufcount2 - 2]; -#ifdef USE_CURSES - ch = cset_adjust( ch ); -#endif - textcolor( buffer2[bufcount2 - 1] ); - putwch(ch); } } - -#ifdef USE_CURSES - set_altcharset(false); -#endif - - update_screen(); + puttext(1, top, num_cols - 1, top + num_lines - 1, buffer2); } static void reset_travel_colours(std::vector &features) @@ -4081,7 +4036,7 @@ void view_update_at(const coord_def &pos) flash_colour = viewmap_flash_colour(); gotoxy(vp.x, vp.y); - textcolor(flash_colour? real_colour(flash_colour) : colour); + textattr(flash_colour? real_colour(flash_colour) : colour); putwch(ch); } @@ -4109,8 +4064,7 @@ bool view_update() //--------------------------------------------------------------- void viewwindow(bool draw_it, bool do_updates) { - std::vector buffy( - crawl_view.viewsz.y * crawl_view.viewsz.x * 2); + screen_buffer_t *buffy(crawl_view.vbuf); int count_x, count_y; @@ -4302,29 +4256,33 @@ void viewwindow(bool draw_it, bool do_updates) if (draw) { you.last_view_update = you.num_turns; - bufcount = 0; - for (count_y = 0; count_y < crawl_view.viewsz.y; count_y++) - { - gotoxy( crawl_view.viewp.x, crawl_view.viewp.y + count_y ); - for (count_x = 0; count_x < crawl_view.viewsz.x; count_x++) - { -#ifdef USE_CURSES - buffy[bufcount] = cset_adjust( buffy[bufcount] ); -#endif - textcolor( buffy[bufcount + 1] ); - putwch( buffy[bufcount] ); - bufcount += 2; - } - } + puttext(crawl_view.viewp.x, crawl_view.viewp.y, + crawl_view.viewp.x + crawl_view.viewsz.x - 1, + crawl_view.viewp.y + crawl_view.viewsz.y - 1, + buffy); } - -#ifdef USE_CURSES - set_altcharset( false ); -#endif - update_screen(); } } // end viewwindow() +////////////////////////////////////////////////////////////////////////////// +// crawl_view_buffer + +crawl_view_buffer::crawl_view_buffer() + : buffer(NULL) +{ +} + +crawl_view_buffer::~crawl_view_buffer() +{ + delete [] buffer; +} + +void crawl_view_buffer::size(const coord_def &sz) +{ + delete [] buffer; + buffer = new screen_buffer_t [ sz.x * sz.y * 2 ]; +} + ////////////////////////////////////////////////////////////////////////////// // crawl_view_geometry @@ -4336,7 +4294,9 @@ const int crawl_view_geometry::hud_max_gutter; crawl_view_geometry::crawl_view_geometry() : termsz(80, 24), viewp(1, 1), viewsz(33, 17), hudp(40, 1), hudsz(41, 17), - msgp(1, viewp.y + viewsz.y), msgsz(80, 7) + msgp(1, viewp.y + viewsz.y), msgsz(80, 7), + vbuf(), vgrdc(), viewhalfsz(), glos1(), glos2(), + vlos1(), vlos2(), mousep(), last_player_pos() { } @@ -4440,6 +4400,8 @@ void crawl_view_geometry::init_geometry() if (viewsz.x < VIEW_MIN_WIDTH) viewsz.x = VIEW_MIN_WIDTH; + vbuf.size(viewsz); + // The hud appears after the viewport + gutter. hudp = coord_def(viewsz.x + 1 + hud_min_gutter, 1); -- cgit v1.2.3-54-g00ecf