ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/deliantra/dclient/src/frontend/tclient/trenderer.cpp
Revision: 1.6
Committed: Mon Feb 7 19:18:45 2011 UTC (15 years, 8 months ago) by sf-pippijn
Branch: MAIN
CVS Tags: HEAD
Changes since 1.5: +6 -4 lines
Log Message:
inventory_widget: don't fault on pgdn with only one item

by Jonathan Neuschäfer <j.neuschaefer@gmx.net>

File Contents

# User Rev Content
1 sf-pippijn 1.6 #include <cstring>
2    
3     #include <iostream>
4    
5     #include "adt/array_size.h"
6 sf-pippijn 1.1
7 sf-pippijn 1.2 #include "deliantra/data/glyph.h"
8     #include "deliantra/data/map.h"
9    
10 sf-pippijn 1.6 #include "trenderer.h"
11 sf-pippijn 1.1
12     void
13 sf-pippijn 1.4 renderer::draw_map () const
14     {
15     for (size_t y = 0; y < array_size (win); y++)
16     {
17     wchar_t buf[array_size (win[y]) + 1];
18     memcpy (buf, win[y], sizeof win[y]);
19     buf[array_size (win[y])] = L'\0';
20     printf ("%ls\n", buf);
21     }
22     }
23    
24    
25     void
26 sf-pippijn 1.1 renderer::drawinfo (int level, std::string const &msg)
27     {
28     std::cout << "drawinfo: " << msg << '\n';
29     }
30    
31 sf-pippijn 1.3
32 sf-pippijn 1.2 static u16
33     select_face (u16 const (&face)[3], int layer)
34     {
35     if (layer == -1)
36     return face[2]
37     ? face[2]
38     : face[1]
39     ? face[1]
40     : face[0]
41     ;
42     return face[layer];
43     }
44    
45 sf-pippijn 1.1 void
46     renderer::map (data::map const &map)
47     {
48 sf-pippijn 1.2 static int const layer = -1;
49    
50     for (size_t y = 0; y < array_size (win); y++)
51     for (size_t x = 0; x < array_size (win[y]); x++)
52     win[y][x] = L'_';
53    
54     static data::glyph const space = { { { 0, 0, L'?' }, { 0, 0, L'?' } } };
55     static data::glyph const player = { { { 0, 0, L'@' }, { 0, 0, L'@' } } };
56    
57 sf-pippijn 1.3 int const playerx = (W - !(W % 2)) / 2;
58     int const playery = (H - !(H % 2)) / 2;
59 sf-pippijn 1.2
60     int const offx = (map.w - W) / 2;
61     int const offy = (map.h - H) / 2;
62    
63     return_unless (!data::glyphs.empty ());
64    
65     for (int y = 0; y < H; y++)
66     {
67     int const mapy = y + map.y + offy;
68     if (!map.rows.has (mapy))
69     continue;
70     auto const &row = map.rows[mapy];
71     for (int x = 0; x < W; x++)
72     {
73     int const mapx = x + map.x + offx;
74     if (!row.has (mapx))
75     continue;
76     data::map::cell const &cell = row[mapx];
77     u32 const face = select_face (cell.face, layer);
78    
79     data::glyph const *glyph;
80    
81     int const winy = y * 1;
82     int const winx = x * 2;
83    
84     if (x == playerx && y == playery)
85     glyph = &player;
86     else if (face && face < data::glyphs.size ()) // TODO: warn about face >= size
87     glyph = &data::glyphs[face];
88     else
89     glyph = &space;
90    
91     return_unless (winy >= 0);
92     return_unless (winx >= 0);
93     return_unless (winy < int (array_size ( win)));
94     return_unless (winx < int (array_size (*win)));
95    
96     win[winy][winx + 0] = (*glyph)[0].text;
97     win[winy][winx + 1] = (*glyph)[1].text;
98     }
99     }
100 sf-pippijn 1.1 }
101    
102 sf-pippijn 1.3
103 sf-pippijn 1.1 void
104 sf-pippijn 1.5 renderer::map_scroll (int dx, int dy)
105     {
106     std::cout << "map_scroll " << dx << ' ' << dy << '\n';
107     }
108    
109    
110     void
111 sf-pippijn 1.1 renderer::msg (int level, std::string const &channel, std::string const &msg)
112     {
113     std::cout << channel << ": " << msg << '\n';
114     }
115    
116 sf-pippijn 1.3
117 sf-pippijn 1.1 void
118 sf-pippijn 1.5 renderer::newmap ()
119     {
120     std::cout << "newmap\n";
121     }
122    
123    
124     void
125 sf-pippijn 1.1 renderer::stats (data::statistics const &stats)
126     {
127     }