1 #pragma once 2 3 #include "tilecell.h" 4 #include "coord-def.h" 5 6 struct screen_cell_t 7 { 8 // Console output part. 9 #ifndef USE_TILE_LOCAL 10 char32_t glyph; 11 unsigned short colour; // TODO: check if this is real colour (8 bit) 12 #endif 13 // Tiles output part. 14 #ifdef USE_TILE 15 unsigned short flash_colour; 16 packed_cell tile; 17 #endif 18 }; 19 20 class crawl_view_buffer 21 { 22 public: 23 crawl_view_buffer(); 24 crawl_view_buffer(const coord_def &sz); 25 crawl_view_buffer(const crawl_view_buffer &rhs); 26 ~crawl_view_buffer(); 27 size()28 coord_def size() const { return m_size; } 29 bool empty() const; 30 31 operator screen_cell_t * () { return m_buffer; } 32 operator const screen_cell_t * () const { return m_buffer; } 33 const crawl_view_buffer & operator =(crawl_view_buffer rhs); 34 35 template<class Indexer> operator()36 screen_cell_t& operator () (const Indexer &i) 37 { 38 ASSERT(i.x >= 0 && i.y >= 0 && i.x < m_size.x && i.y < m_size.y); 39 return m_buffer[i.y*m_size.x + i.x]; 40 } 41 42 void fill(const screen_cell_t& value); 43 void clear(); 44 void draw(); 45 private: 46 void resize(const coord_def &sz); 47 coord_def m_size; 48 screen_cell_t *m_buffer; 49 }; 50 51 struct crawl_view_geometry 52 { 53 public: 54 coord_def termp; // Left-top pos of terminal. 55 coord_def termsz; // Size of the terminal. 56 coord_def viewp; // Left-top pos of viewport. 57 coord_def viewsz; // Size of the viewport (play area). 58 coord_def hudp; // Left-top pos of status area. 59 coord_def hudsz; // Size of the status area. 60 coord_def msgp; // Left-top pos of the message pane. 61 coord_def msgsz; // Size of the message pane. 62 coord_def mlistp; // Left-top pos of the monster list. 63 coord_def mlistsz; // Size of the monster list. 64 65 coord_def vgrdc; // What grid pos is at the centre of the view 66 // usually you.pos(). 67 68 coord_def viewhalfsz; 69 70 coord_def glos1, glos2; // LOS limit grid coords (inclusive) 71 coord_def vlos1, vlos2; // LOS limit viewport coords (inclusive) 72 73 coord_def mousep; // Where the mouse is. 74 75 private: 76 coord_def last_player_pos; 77 78 public: 79 crawl_view_geometry(); 80 void init_geometry(); 81 82 void init_view(); 83 void set_player_at(const coord_def &c, bool force_centre = false); 84 // Set new location, but preserve scrolling as if the player didn't move. 85 void shift_player_to(const coord_def &c); 86 // Recalculate vlos1 and vlos2. 87 void calc_vlos(); 88 view2gridcrawl_view_geometry89 inline coord_def view2grid(const coord_def &pos) const 90 { 91 return pos - viewhalfsz + vgrdc - coord_def(1, 1); 92 } 93 grid2viewcrawl_view_geometry94 inline coord_def grid2view(const coord_def &pos) const 95 { 96 return pos - vgrdc + viewhalfsz + coord_def(1, 1); 97 } 98 view2showcrawl_view_geometry99 inline coord_def view2show(const coord_def &pos) const 100 { 101 return pos - vlos1; 102 } 103 show2viewcrawl_view_geometry104 inline coord_def show2view(const coord_def &pos) const 105 { 106 return pos + vlos1; 107 } 108 grid2showcrawl_view_geometry109 inline coord_def grid2show(const coord_def &pos) const 110 { 111 return view2show(grid2view(pos)); 112 } 113 show2gridcrawl_view_geometry114 inline coord_def show2grid(const coord_def &pos) const 115 { 116 return view2grid(show2view(pos)); 117 } 118 screen2viewcrawl_view_geometry119 inline coord_def screen2view(const coord_def& pos) const 120 { 121 return pos - viewp + termp; 122 } 123 view2screencrawl_view_geometry124 inline coord_def view2screen(const coord_def& pos) const 125 { 126 return pos + viewp - termp; 127 } 128 screen2gridcrawl_view_geometry129 inline coord_def screen2grid(const coord_def& pos) const 130 { 131 return view2grid(screen2view(pos)); 132 } 133 grid2screencrawl_view_geometry134 inline coord_def grid2screen(const coord_def& pos) const 135 { 136 return view2screen(grid2view(pos)); 137 } 138 glosccrawl_view_geometry139 coord_def glosc() const 140 { 141 return (glos1 + glos2) / 2; 142 } 143 in_los_bounds_gcrawl_view_geometry144 bool in_los_bounds_g(const coord_def &c) const 145 { 146 return c.x >= glos1.x && c.x <= glos2.x 147 && c.y >= glos1.y && c.y <= glos2.y; 148 } 149 in_los_bounds_vcrawl_view_geometry150 bool in_los_bounds_v(const coord_def &c) const 151 { 152 return in_los_bounds_g(view2grid(c)); 153 } 154 in_viewport_vcrawl_view_geometry155 bool in_viewport_v(const coord_def &c) const 156 { 157 return c.x > 0 && c.y > 0 158 && c.x <= viewsz.x && c.y <= viewsz.y; 159 } 160 in_viewport_scrawl_view_geometry161 bool in_viewport_s(const coord_def &c) const 162 { 163 return in_viewport_v(screen2view(c)); 164 } 165 in_viewport_gcrawl_view_geometry166 bool in_viewport_g(const coord_def &c) const 167 { 168 return in_viewport_v(grid2view(c)); 169 } 170 }; 171 172 extern crawl_view_geometry crawl_view; 173 view2grid(const coord_def & pos)174static inline coord_def view2grid(const coord_def &pos) 175 { 176 return crawl_view.view2grid(pos); 177 } 178 grid2view(const coord_def & pos)179static inline coord_def grid2view(const coord_def &pos) 180 { 181 return crawl_view.grid2view(pos); 182 } 183 view2show(const coord_def & pos)184static inline coord_def view2show(const coord_def &pos) 185 { 186 return crawl_view.view2show(pos); 187 } 188 show2view(const coord_def & pos)189static inline coord_def show2view(const coord_def &pos) 190 { 191 return crawl_view.show2view(pos); 192 } 193 grid2show(const coord_def & pos)194static inline coord_def grid2show(const coord_def &pos) 195 { 196 return crawl_view.grid2show(pos); 197 } 198 show2grid(const coord_def & pos)199static inline coord_def show2grid(const coord_def &pos) 200 { 201 return crawl_view.show2grid(pos); 202 } 203 in_los_bounds_v(const coord_def & pos)204static inline bool in_los_bounds_v(const coord_def& pos) 205 { 206 return crawl_view.in_los_bounds_v(pos); 207 } 208 in_los_bounds_g(const coord_def & pos)209static inline bool in_los_bounds_g(const coord_def& pos) 210 { 211 return crawl_view.in_los_bounds_g(pos); 212 } 213