ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/Client.xs
(Generate patch)

Comparing deliantra/Deliantra-Client/Client.xs (file contents):
Revision 1.134 by root, Fri Aug 4 16:49:58 2006 UTC vs.
Revision 1.151 by root, Sat Aug 19 18:17:18 2006 UTC

144} 144}
145 145
146static void 146static void
147layout_get_pixel_size (CFPlus__Layout self, int *w, int *h) 147layout_get_pixel_size (CFPlus__Layout self, int *w, int *h)
148{ 148{
149 PangoRectangle rect;
150
151 // get_pixel_* wrongly rounds down
149 pango_layout_get_pixel_size (self->pl, w, h); 152 pango_layout_get_extents (self->pl, 0, &rect);
150 153
151 if (!*w) *w = 1; 154 rect.width = (rect.width + PANGO_SCALE - 1) / PANGO_SCALE;
152 if (!*h) *h = 1; 155 rect.height = (rect.height + PANGO_SCALE - 1) / PANGO_SCALE;
153 156
154 *w = (*w + 3) & ~3; 157 if (!rect.width) rect.width = 1;
158 if (!rect.height) rect.height = 1;
159
160 *w = rect.width;
161 *h = rect.height;
155} 162}
156 163
157typedef uint16_t mapface; 164typedef uint16_t mapface;
158 165
159typedef struct { 166typedef struct {
162 float s, t; 169 float s, t;
163 uint8_t r, g, b, a; 170 uint8_t r, g, b, a;
164} maptex; 171} maptex;
165 172
166typedef struct { 173typedef struct {
167 int16_t darkness; 174 uint16_t darkness;
168 mapface face[3]; 175 mapface face[3];
176 uint8_t stat_width, stat_hp;
169} mapcell; 177} mapcell;
170 178
171typedef struct { 179typedef struct {
172 int32_t c0, c1; 180 int32_t c0, c1;
173 mapcell *col; 181 mapcell *col;
286static void 294static void
287map_blank (CFPlus__Map self, int x0, int y0, int w, int h) 295map_blank (CFPlus__Map self, int x0, int y0, int w, int h)
288{ 296{
289 int x, y; 297 int x, y;
290 maprow *row; 298 maprow *row;
299 mapcell *cell;
291 300
292 for (y = y0; y < y0 + h; y++) 301 for (y = y0; y < y0 + h; y++)
293 if (y >= 0) 302 if (y >= 0)
294 { 303 {
295 if (y >= self->rows) 304 if (y >= self->rows)
301 if (x >= row->c0) 310 if (x >= row->c0)
302 { 311 {
303 if (x >= row->c1) 312 if (x >= row->c1)
304 break; 313 break;
305 314
306 row->col[x - row->c0].darkness = -1; 315 cell = row->col + x - row->c0;
316
317 cell->darkness = 0;
318 cell->stat_hp = 0;
307 } 319 }
308 } 320 }
309} 321}
310 322
311static void 323static void
1025 PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); 1037 PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE)));
1026 PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); 1038 PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE)));
1027} 1039}
1028 1040
1029void 1041void
1030render (CFPlus::Layout self, float x, float y) 1042render (CFPlus::Layout self, float x, float y, int flags = 0)
1031 PPCODE: 1043 PPCODE:
1032 pango_opengl_render_layout_subpixel ( 1044 pango_opengl_render_layout_subpixel (
1033 self->pl, 1045 self->pl,
1034 x * PANGO_SCALE, y * PANGO_SCALE, 1046 x * PANGO_SCALE, y * PANGO_SCALE,
1035 self->r, self->g, self->b, self->a 1047 self->r, self->g, self->b, self->a,
1048 flags
1036 ); 1049 );
1037 1050
1038MODULE = CFPlus PACKAGE = CFPlus::Texture 1051MODULE = CFPlus PACKAGE = CFPlus::Texture
1039 1052
1040void 1053void
1252 self->y += MAP_EXTEND_Y; 1265 self->y += MAP_EXTEND_Y;
1253 } 1266 }
1254} 1267}
1255 1268
1256void 1269void
1257map1a_update (CFPlus::Map self, SV *data_) 1270map1a_update (CFPlus::Map self, SV *data_, int extmap)
1258 CODE: 1271 CODE:
1259{ 1272{
1260 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); 1273 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_);
1261 uint8_t *data_end = (uint8_t *)SvEND (data_); 1274 uint8_t *data_end = (uint8_t *)SvEND (data_);
1262 mapcell *cell; 1275 mapcell *cell;
1263 int x, y, flags; 1276 int x, y, flags;
1264 1277
1265 while (data < data_end) 1278 while (data < data_end - 1)
1266 { 1279 {
1267 flags = (data [0] << 8) + data [1]; data += 2; 1280 flags = (data [0] << 8) + data [1]; data += 2;
1268 1281
1269 x = self->x + ((flags >> 10) & 63); 1282 x = self->x + ((flags >> 10) & 63);
1270 y = self->y + ((flags >> 4) & 63); 1283 y = self->y + ((flags >> 4) & 63);
1271 1284
1272 cell = map_get_cell (self, x, y); 1285 cell = map_get_cell (self, x, y);
1273 1286
1274 if (flags & 15) 1287 if (flags & 15)
1275 { 1288 {
1276 if (cell->darkness < 0) 1289 if (!cell->darkness)
1277 { 1290 {
1278 cell->darkness = 0; 1291 cell->darkness = 256;
1279 cell->face [0] = 0; 1292 cell->face [0] = 0;
1280 cell->face [1] = 0; 1293 cell->face [1] = 0;
1281 cell->face [2] = 0; 1294 cell->face [2] = 0;
1282 } 1295 }
1283 1296
1284 cell->darkness = flags & 8 ? *data++ : 255;
1285
1286 //TODO: don't trust server data to be in-range(!) 1297 //TODO: don't trust server data to be in-range(!)
1298
1299 if (flags & 8)
1300 {
1301 if (extmap)
1302 {
1303 uint8_t ext, cmd;
1304
1305 do
1306 {
1307 ext = *data++;
1308 cmd = ext & 0x3f;
1309
1310 if (cmd < 4)
1311 cell->darkness = 255 - ext * 64 + 1;
1312 else if (cmd == 5) // health
1313 {
1314 cell->stat_width = 1;
1315 cell->stat_hp = *data++;
1316 }
1317 else if (cmd == 6) // monster width
1318 cell->stat_width = *data++ + 1;
1319 else if (ext & 0x40) // unknown, multibyte => skip
1320 data += *data + 1;
1321 else
1322 data++;
1323 }
1324 while (ext & 0x80);
1325 }
1326 else
1327 cell->darkness = *data++ + 1;
1328 }
1287 1329
1288 if (flags & 4) 1330 if (flags & 4)
1289 { 1331 {
1290 cell->face [0] = self->face [(data [0] << 8) + data [1]]; data += 2; 1332 cell->face [0] = self->face [(data [0] << 8) + data [1]]; data += 2;
1291 } 1333 }
1299 { 1341 {
1300 cell->face [2] = self->face [(data [0] << 8) + data [1]]; data += 2; 1342 cell->face [2] = self->face [(data [0] << 8) + data [1]]; data += 2;
1301 } 1343 }
1302 } 1344 }
1303 else 1345 else
1346 {
1304 cell->darkness = -1; 1347 cell->darkness = 0;
1348 cell->stat_hp = 0;
1349 }
1305 } 1350 }
1306} 1351}
1307 1352
1308SV * 1353SV *
1309mapmap (CFPlus::Map self, int x0, int y0, int w, int h) 1354mapmap (CFPlus::Map self, int x0, int y0, int w, int h)
1409 { 1454 {
1410 mapcell *cell = row->col + (x + vx - row->c0); 1455 mapcell *cell = row->col + (x + vx - row->c0);
1411 1456
1412 face = cell->face [z]; 1457 face = cell->face [z];
1413 1458
1414 if (face) 1459 if (face && face < self->texs)
1415 { 1460 {
1416 maptex tex = self->tex [face]; 1461 maptex tex = self->tex [face];
1417 1462
1418 int px = (x + 1) * 32 - tex.w; 1463 int px = (x + 1) * 32 - tex.w;
1419 int py = (y + 1) * 32 - tex.h; 1464 int py = (y + 1) * 32 - tex.h;
1435 } 1480 }
1436 1481
1437 glEnd (); 1482 glEnd ();
1438 1483
1439 glDisable (GL_TEXTURE_2D); 1484 glDisable (GL_TEXTURE_2D);
1485
1486 // top layer: overlays such as the health bar
1487 for (y = 0; y < sh; y++)
1488 if (0 <= y + vy && y + vy < self->rows)
1489 {
1490 maprow *row = self->row + (y + vy);
1491
1492 for (x = 0; x < sw; x++)
1493 if (row->c0 <= x + vx && x + vx < row->c1)
1494 {
1495 mapcell *cell = row->col + (x + vx - row->c0);
1496
1497 int px = x * 32;
1498 int py = y * 32;
1499
1500 if (cell->stat_hp)
1501 {
1502 int width = cell->stat_width * 32;
1503 int thick = sh / 28 + 1 + cell->stat_width;
1504
1505 glColor4ub (0, 0, 0, 223);
1506 glRectf (px + 1, py - thick - 2,
1507 px + width - 1, py);
1508
1509 glColor4ub (cell->stat_hp, 255 - cell->stat_hp, 0, 223);
1510 glRectf (px + 2,
1511 py - thick - 1,
1512 px + width - 2 - cell->stat_hp * (width - 4) / 255, py - 1);
1513 }
1514 }
1515 }
1516
1440 glDisable (GL_BLEND); 1517 glDisable (GL_BLEND);
1441} 1518}
1442 1519
1443void 1520void
1444draw_magicmap (CFPlus::Map self, int dx, int dy, int w, int h, unsigned char *data) 1521draw_magicmap (CFPlus::Map self, int dx, int dy, int w, int h, unsigned char *data)
1525 for (x = 0; x < sw; x++) 1602 for (x = 0; x < sw; x++)
1526 if (row->c0 <= x + vx && x + vx < row->c1) 1603 if (row->c0 <= x + vx && x + vx < row->c1)
1527 { 1604 {
1528 mapcell *cell = row->col + (x + vx - row->c0); 1605 mapcell *cell = row->col + (x + vx - row->c0);
1529 1606
1530 darkness[y * sw4 + x] = cell->darkness < 0 1607 darkness[y * sw4 + x] = cell->darkness
1608 ? 255 - (cell->darkness - 1)
1531 ? 255 - FOW_DARKNESS 1609 : 255 - FOW_DARKNESS;
1532 : 255 - cell->darkness;
1533 } 1610 }
1534 } 1611 }
1535 1612
1536 EXTEND (SP, 3); 1613 EXTEND (SP, 3);
1537 PUSHs (sv_2mortal (newSViv (sw4))); 1614 PUSHs (sv_2mortal (newSViv (sw4)));
1652 1729
1653 if (flags & 1) { face[0] = *data++ << 8; face[0] |= *data++; } 1730 if (flags & 1) { face[0] = *data++ << 8; face[0] |= *data++; }
1654 if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; } 1731 if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; }
1655 if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; } 1732 if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; }
1656 1733
1657 if (cell->darkness <= 0) 1734 if (cell->darkness == 0)
1658 { 1735 {
1659 cell->darkness = -1; 1736 cell->darkness = 0;
1660 1737
1661 for (z = 0; z <= 2; z++) 1738 for (z = 0; z <= 2; z++)
1662 { 1739 {
1663 cell->face[z] = face[z]; 1740 cell->face[z] = face[z];
1664 1741
1802 const_iv (GL_SEPARABLE_2D), 1879 const_iv (GL_SEPARABLE_2D),
1803 const_iv (GL_CONVOLUTION_2D), 1880 const_iv (GL_CONVOLUTION_2D),
1804 const_iv (GL_CONVOLUTION_BORDER_MODE), 1881 const_iv (GL_CONVOLUTION_BORDER_MODE),
1805 const_iv (GL_CONSTANT_BORDER), 1882 const_iv (GL_CONSTANT_BORDER),
1806 const_iv (GL_LINES), 1883 const_iv (GL_LINES),
1884 const_iv (GL_LINE_STRIP),
1807 const_iv (GL_LINE_LOOP), 1885 const_iv (GL_LINE_LOOP),
1808 const_iv (GL_QUADS), 1886 const_iv (GL_QUADS),
1809 const_iv (GL_QUAD_STRIP), 1887 const_iv (GL_QUAD_STRIP),
1810 const_iv (GL_TRIANGLES), 1888 const_iv (GL_TRIANGLES),
1811 const_iv (GL_TRIANGLE_STRIP), 1889 const_iv (GL_TRIANGLE_STRIP),
2008 2086
2009void glEndList () 2087void glEndList ()
2010 2088
2011void glCallList (int list) 2089void glCallList (int list)
2012 2090
2013

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines