ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/cf.schmorp.de/dclient/src/frontend/tclient/trenderer.cpp
Revision: 1.2
Committed: Mon Oct 25 00:51:06 2010 UTC (16 years ago) by sf-pippijn
Branch: MAIN
Changes since 1.1: +86 -0 lines
Log Message:
fixed map widget

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