ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/cf.schmorp.de/dclient/src/frontend/tclient/trenderer.cpp
Revision: 1.3
Committed: Mon Oct 25 01:05:44 2010 UTC (16 years ago) by sf-pippijn
Branch: MAIN
Changes since 1.2: +6 -10 lines
Log Message:
fixed player location

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