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.155 by root, Thu Sep 21 00:16:42 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 uint32_t player;
168 mapface face[3]; 175 mapface face[3];
176 uint16_t darkness;
177 uint8_t stat_width, stat_hp, flags;
169} mapcell; 178} mapcell;
170 179
171typedef struct { 180typedef struct {
172 int32_t c0, c1; 181 int32_t c0, c1;
173 mapcell *col; 182 mapcell *col;
286static void 295static void
287map_blank (CFPlus__Map self, int x0, int y0, int w, int h) 296map_blank (CFPlus__Map self, int x0, int y0, int w, int h)
288{ 297{
289 int x, y; 298 int x, y;
290 maprow *row; 299 maprow *row;
300 mapcell *cell;
291 301
292 for (y = y0; y < y0 + h; y++) 302 for (y = y0; y < y0 + h; y++)
293 if (y >= 0) 303 if (y >= 0)
294 { 304 {
295 if (y >= self->rows) 305 if (y >= self->rows)
301 if (x >= row->c0) 311 if (x >= row->c0)
302 { 312 {
303 if (x >= row->c1) 313 if (x >= row->c1)
304 break; 314 break;
305 315
306 row->col[x - row->c0].darkness = -1; 316 cell = row->col + x - row->c0;
317
318 cell->darkness = 0;
319 cell->stat_hp = 0;
320 cell->flags = 0;
321 cell->player = 0;
307 } 322 }
308 } 323 }
309} 324}
310 325
311static void 326static void
1025 PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); 1040 PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE)));
1026 PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); 1041 PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE)));
1027} 1042}
1028 1043
1029void 1044void
1030render (CFPlus::Layout self, float x, float y) 1045render (CFPlus::Layout self, float x, float y, int flags = 0)
1031 PPCODE: 1046 PPCODE:
1032 pango_opengl_render_layout_subpixel ( 1047 pango_opengl_render_layout_subpixel (
1033 self->pl, 1048 self->pl,
1034 x * PANGO_SCALE, y * PANGO_SCALE, 1049 x * PANGO_SCALE, y * PANGO_SCALE,
1035 self->r, self->g, self->b, self->a 1050 self->r, self->g, self->b, self->a,
1051 flags
1036 ); 1052 );
1037 1053
1038MODULE = CFPlus PACKAGE = CFPlus::Texture 1054MODULE = CFPlus PACKAGE = CFPlus::Texture
1039 1055
1040void 1056void
1230void 1246void
1231scroll (CFPlus::Map self, int dx, int dy) 1247scroll (CFPlus::Map self, int dx, int dy)
1232 CODE: 1248 CODE:
1233{ 1249{
1234 if (dx > 0) 1250 if (dx > 0)
1235 map_blank (self, self->x, self->y, dx - 1, self->h); 1251 map_blank (self, self->x, self->y, dx, self->h);
1236 else if (dx < 0) 1252 else if (dx < 0)
1237 map_blank (self, self->x + self->w + dx + 1, self->y, 1 - dx, self->h); 1253 map_blank (self, self->x + self->w + dx + 1, self->y, -dx, self->h);
1238 1254
1239 if (dy > 0) 1255 if (dy > 0)
1240 map_blank (self, self->x, self->y, self->w, dy - 1); 1256 map_blank (self, self->x, self->y, self->w, dy);
1241 else if (dy < 0) 1257 else if (dy < 0)
1242 map_blank (self, self->x, self->y + self->h + dy + 1, self->w, 1 - dy); 1258 map_blank (self, self->x, self->y + self->h + dy + 1, self->w, -dy);
1243 1259
1244 self->ox += dx; self->x += dx; 1260 self->ox += dx; self->x += dx;
1245 self->oy += dy; self->y += dy; 1261 self->oy += dy; self->y += dy;
1246 1262
1247 while (self->y < 0) 1263 while (self->y < 0)
1252 self->y += MAP_EXTEND_Y; 1268 self->y += MAP_EXTEND_Y;
1253 } 1269 }
1254} 1270}
1255 1271
1256void 1272void
1257map1a_update (CFPlus::Map self, SV *data_) 1273map1a_update (CFPlus::Map self, SV *data_, int extmap)
1258 CODE: 1274 CODE:
1259{ 1275{
1260 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); 1276 uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_);
1261 uint8_t *data_end = (uint8_t *)SvEND (data_); 1277 uint8_t *data_end = (uint8_t *)SvEND (data_);
1262 mapcell *cell; 1278 mapcell *cell;
1263 int x, y, flags; 1279 int x, y, flags;
1264 1280
1265 while (data < data_end) 1281 while (data < data_end - 1)
1266 { 1282 {
1267 flags = (data [0] << 8) + data [1]; data += 2; 1283 flags = (data [0] << 8) + data [1]; data += 2;
1268 1284
1269 x = self->x + ((flags >> 10) & 63); 1285 x = self->x + ((flags >> 10) & 63);
1270 y = self->y + ((flags >> 4) & 63); 1286 y = self->y + ((flags >> 4) & 63);
1271 1287
1272 cell = map_get_cell (self, x, y); 1288 cell = map_get_cell (self, x, y);
1273 1289
1274 if (flags & 15) 1290 if (flags & 15)
1275 { 1291 {
1276 if (cell->darkness < 0) 1292 if (!cell->darkness)
1277 { 1293 {
1294 memset (cell, 0, sizeof (*cell));
1278 cell->darkness = 0; 1295 cell->darkness = 256;
1279 cell->face [0] = 0;
1280 cell->face [1] = 0;
1281 cell->face [2] = 0;
1282 } 1296 }
1283 1297
1284 cell->darkness = flags & 8 ? *data++ : 255;
1285
1286 //TODO: don't trust server data to be in-range(!) 1298 //TODO: don't trust server data to be in-range(!)
1299
1300 if (flags & 8)
1301 {
1302 if (extmap)
1303 {
1304 uint8_t ext, cmd;
1305
1306 do
1307 {
1308 ext = *data++;
1309 cmd = ext & 0x3f;
1310
1311 if (cmd < 4)
1312 cell->darkness = 255 - ext * 64 + 1;
1313 else if (cmd == 5) // health
1314 {
1315 cell->stat_width = 1;
1316 cell->stat_hp = *data++;
1317 }
1318 else if (cmd == 6) // monster width
1319 cell->stat_width = *data++ + 1;
1320 else if (cmd == 0x47) // monster width
1321 {
1322 if (*data == 4)
1323 ; // decode player tag
1324
1325 data += *data + 1;
1326 }
1327 else if (cmd == 8) // cell flags
1328 cell->flags = *data++;
1329 else if (ext & 0x40) // unknown, multibyte => skip
1330 data += *data + 1;
1331 else
1332 data++;
1333 }
1334 while (ext & 0x80);
1335 }
1336 else
1337 cell->darkness = *data++ + 1;
1338
1339 }
1287 1340
1288 if (flags & 4) 1341 if (flags & 4)
1289 { 1342 {
1290 cell->face [0] = self->face [(data [0] << 8) + data [1]]; data += 2; 1343 cell->face [0] = self->face [(data [0] << 8) + data [1]]; data += 2;
1291 } 1344 }
1299 { 1352 {
1300 cell->face [2] = self->face [(data [0] << 8) + data [1]]; data += 2; 1353 cell->face [2] = self->face [(data [0] << 8) + data [1]]; data += 2;
1301 } 1354 }
1302 } 1355 }
1303 else 1356 else
1304 cell->darkness = -1; 1357 cell->darkness = 0;
1305 } 1358 }
1306} 1359}
1307 1360
1308SV * 1361SV *
1309mapmap (CFPlus::Map self, int x0, int y0, int w, int h) 1362mapmap (CFPlus::Map self, int x0, int y0, int w, int h)
1409 { 1462 {
1410 mapcell *cell = row->col + (x + vx - row->c0); 1463 mapcell *cell = row->col + (x + vx - row->c0);
1411 1464
1412 face = cell->face [z]; 1465 face = cell->face [z];
1413 1466
1414 if (face) 1467 if (face && face < self->texs)
1415 { 1468 {
1416 maptex tex = self->tex [face]; 1469 maptex tex = self->tex [face];
1417
1418 int px = (x + 1) * 32 - tex.w; 1470 int px = (x + 1) * 32 - tex.w;
1419 int py = (y + 1) * 32 - tex.h; 1471 int py = (y + 1) * 32 - tex.h;
1420 1472
1421 if (last_name != tex.name) 1473 if (last_name != tex.name)
1422 { 1474 {
1423 glEnd (); 1475 glEnd ();
1424 last_name = tex.name;
1425 glBindTexture (GL_TEXTURE_2D, last_name); 1476 glBindTexture (GL_TEXTURE_2D, last_name = tex.name);
1426 glBegin (GL_QUADS); 1477 glBegin (GL_QUADS);
1427 } 1478 }
1428 1479
1429 glTexCoord2f (0 , 0 ); glVertex2f (px , py ); 1480 glTexCoord2f (0 , 0 ); glVertex2f (px , py );
1430 glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); 1481 glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h);
1431 glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h); 1482 glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h);
1432 glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); 1483 glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py );
1433 } 1484 }
1485
1486 if (cell->flags && z == 2)
1487 {
1488 if (cell->flags & 1)
1489 {
1490 maptex tex = self->tex [1];
1491 int px = (x + 1) * 32 - tex.w + 2;
1492 int py = (y + 1) * 32 - tex.h - 6;
1493
1494 glEnd ();
1495 glBindTexture (GL_TEXTURE_2D, last_name = tex.name);
1496 glBegin (GL_QUADS);
1497
1498 glTexCoord2f (0 , 0 ); glVertex2f (px , py );
1499 glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h);
1500 glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h);
1501 glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py );
1502 }
1503 }
1434 } 1504 }
1435 } 1505 }
1436 1506
1437 glEnd (); 1507 glEnd ();
1438 1508
1439 glDisable (GL_TEXTURE_2D); 1509 glDisable (GL_TEXTURE_2D);
1440 glDisable (GL_BLEND); 1510 glDisable (GL_BLEND);
1511
1512 // top layer: overlays such as the health bar
1513 for (y = 0; y < sh; y++)
1514 if (0 <= y + vy && y + vy < self->rows)
1515 {
1516 maprow *row = self->row + (y + vy);
1517
1518 for (x = 0; x < sw; x++)
1519 if (row->c0 <= x + vx && x + vx < row->c1)
1520 {
1521 mapcell *cell = row->col + (x + vx - row->c0);
1522
1523 int px = x * 32;
1524 int py = y * 32;
1525
1526 if (cell->stat_hp)
1527 {
1528 int width = cell->stat_width * 32;
1529 int thick = sh / 28 + 1 + cell->stat_width;
1530
1531 glColor3ub (0, 0, 0);
1532 glRectf (px + 1, py - thick - 2,
1533 px + width - 1, py);
1534
1535 glColor3ub (cell->stat_hp, 255 - cell->stat_hp, 0);
1536 glRectf (px + 2,
1537 py - thick - 1,
1538 px + width - 2 - cell->stat_hp * (width - 4) / 255, py - 1);
1539 }
1540 }
1541 }
1441} 1542}
1442 1543
1443void 1544void
1444draw_magicmap (CFPlus::Map self, int dx, int dy, int w, int h, unsigned char *data) 1545draw_magicmap (CFPlus::Map self, int dx, int dy, int w, int h, unsigned char *data)
1445 CODE: 1546 CODE:
1525 for (x = 0; x < sw; x++) 1626 for (x = 0; x < sw; x++)
1526 if (row->c0 <= x + vx && x + vx < row->c1) 1627 if (row->c0 <= x + vx && x + vx < row->c1)
1527 { 1628 {
1528 mapcell *cell = row->col + (x + vx - row->c0); 1629 mapcell *cell = row->col + (x + vx - row->c0);
1529 1630
1530 darkness[y * sw4 + x] = cell->darkness < 0 1631 darkness[y * sw4 + x] = cell->darkness
1632 ? 255 - (cell->darkness - 1)
1531 ? 255 - FOW_DARKNESS 1633 : 255 - FOW_DARKNESS;
1532 : 255 - cell->darkness;
1533 } 1634 }
1534 } 1635 }
1535 1636
1536 EXTEND (SP, 3); 1637 EXTEND (SP, 3);
1537 PUSHs (sv_2mortal (newSViv (sw4))); 1638 PUSHs (sv_2mortal (newSViv (sw4)));
1652 1753
1653 if (flags & 1) { face[0] = *data++ << 8; face[0] |= *data++; } 1754 if (flags & 1) { face[0] = *data++ << 8; face[0] |= *data++; }
1654 if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; } 1755 if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; }
1655 if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; } 1756 if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; }
1656 1757
1657 if (cell->darkness <= 0) 1758 if (cell->darkness == 0)
1658 { 1759 {
1659 cell->darkness = -1; 1760 cell->darkness = 0;
1660 1761
1661 for (z = 0; z <= 2; z++) 1762 for (z = 0; z <= 2; z++)
1662 { 1763 {
1663 cell->face[z] = face[z]; 1764 cell->face[z] = face[z];
1664 1765
1802 const_iv (GL_SEPARABLE_2D), 1903 const_iv (GL_SEPARABLE_2D),
1803 const_iv (GL_CONVOLUTION_2D), 1904 const_iv (GL_CONVOLUTION_2D),
1804 const_iv (GL_CONVOLUTION_BORDER_MODE), 1905 const_iv (GL_CONVOLUTION_BORDER_MODE),
1805 const_iv (GL_CONSTANT_BORDER), 1906 const_iv (GL_CONSTANT_BORDER),
1806 const_iv (GL_LINES), 1907 const_iv (GL_LINES),
1908 const_iv (GL_LINE_STRIP),
1807 const_iv (GL_LINE_LOOP), 1909 const_iv (GL_LINE_LOOP),
1808 const_iv (GL_QUADS), 1910 const_iv (GL_QUADS),
1809 const_iv (GL_QUAD_STRIP), 1911 const_iv (GL_QUAD_STRIP),
1810 const_iv (GL_TRIANGLES), 1912 const_iv (GL_TRIANGLES),
1811 const_iv (GL_TRIANGLE_STRIP), 1913 const_iv (GL_TRIANGLE_STRIP),
2008 2110
2009void glEndList () 2111void glEndList ()
2010 2112
2011void glCallList (int list) 2113void glCallList (int list)
2012 2114
2013

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines