summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source
diff options
context:
space:
mode:
authordshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2007-10-27 15:59:10 +0000
committerdshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2007-10-27 15:59:10 +0000
commiteb7baf83704e5ffa3d0059e8db34b3c3508b2428 (patch)
treebf46bfe4012e9d369c1a4f915e4037c417598ba1 /crawl-ref/source
parent64c0b7fe918fdc3bc41483b17f6796d3273ac05a (diff)
downloadcrawl-ref-eb7baf83704e5ffa3d0059e8db34b3c3508b2428.tar.gz
crawl-ref-eb7baf83704e5ffa3d0059e8db34b3c3508b2428.zip
Minor view code cleanup; this ought to fix the DOS redraw issues as well.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@2629 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source')
-rw-r--r--crawl-ref/source/direct.h15
-rw-r--r--crawl-ref/source/libdos.h2
-rw-r--r--crawl-ref/source/libunix.cc38
-rw-r--r--crawl-ref/source/libunix.h8
-rw-r--r--crawl-ref/source/libw32c.cc15
-rw-r--r--crawl-ref/source/libw32c.h5
-rw-r--r--crawl-ref/source/view.cc98
7 files changed, 111 insertions, 70 deletions
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 <string>
#include <stdarg.h>
+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/view.cc b/crawl-ref/source/view.cc
index 41b0263754..773509411b 100644
--- a/crawl-ref/source/view.cc
+++ b/crawl-ref/source/view.cc
@@ -83,12 +83,6 @@
static FixedVector<feature_def, NUM_FEATURES> 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;
@@ -2638,29 +2632,6 @@ static int find_feature( const std::vector<coord_def>& 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);
@@ -2747,25 +2718,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
- textattr( 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<coord_def> &features)
@@ -4266,8 +4221,7 @@ bool view_update()
//---------------------------------------------------------------
void viewwindow(bool draw_it, bool do_updates)
{
- std::vector<screen_buffer_t> buffy(
- crawl_view.viewsz.y * crawl_view.viewsz.x * 2);
+ screen_buffer_t *buffy(crawl_view.vbuf);
int count_x, count_y;
@@ -4464,30 +4418,34 @@ 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
- textattr( 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
const int crawl_view_geometry::message_min_lines;
@@ -4498,7 +4456,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()
{
}
@@ -4602,6 +4562,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);