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

# Content
1 #include <cstring>
2
3 #include <iostream>
4
5 #include "adt/array_size.h"
6
7 #include "deliantra/data/glyph.h"
8 #include "deliantra/data/map.h"
9
10 #include "trenderer.h"
11
12 void
13 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 renderer::drawinfo (int level, std::string const &msg)
27 {
28 std::cout << "drawinfo: " << msg << '\n';
29 }
30
31
32 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 void
46 renderer::map (data::map const &map)
47 {
48 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 int const playerx = (W - !(W % 2)) / 2;
58 int const playery = (H - !(H % 2)) / 2;
59
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 }
101
102
103 void
104 renderer::map_scroll (int dx, int dy)
105 {
106 std::cout << "map_scroll " << dx << ' ' << dy << '\n';
107 }
108
109
110 void
111 renderer::msg (int level, std::string const &channel, std::string const &msg)
112 {
113 std::cout << channel << ": " << msg << '\n';
114 }
115
116
117 void
118 renderer::newmap ()
119 {
120 std::cout << "newmap\n";
121 }
122
123
124 void
125 renderer::stats (data::statistics const &stats)
126 {
127 }