ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/deliantra/dclient/src/frontend/tclient/trenderer.cpp
Revision: 1.5
Committed: Mon Oct 25 12:06:58 2010 UTC (16 years ago) by sf-pippijn
Branch: MAIN
Changes since 1.4: +14 -0 lines
Log Message:
be more strict about the protocol

File Contents

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