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.166 by root, Fri Dec 8 15:07:08 2006 UTC vs.
Revision 1.175 by root, Fri Apr 6 08:09:42 2007 UTC

1#ifdef _WIN32 1#ifdef _WIN32
2# define WIN32_LEAN_AND_MEAN 2# define WIN32_LEAN_AND_MEAN
3# define _WIN32_WINNT 0x0500 // needed to get win2000 api calls 3# define NTDDI_VERSION NTDDI_WIN2K // needed to get win2000 api calls
4# include <malloc.h> 4# include <malloc.h>
5# include <windows.h> 5# include <windows.h>
6# include <wininet.h> 6# include <wininet.h>
7# pragma warning(disable:4244) 7# pragma warning(disable:4244)
8# pragma warning(disable:4761) 8# pragma warning(disable:4761)
14 14
15#ifdef _WIN32 15#ifdef _WIN32
16# undef pipe 16# undef pipe
17#endif 17#endif
18 18
19#include <assert.h>
19#include <math.h> 20#include <math.h>
20#include <string.h> 21#include <string.h>
21#include <stdio.h> 22#include <stdio.h>
22#include <stdlib.h> 23#include <stdlib.h>
23 24
154 155
155 *w = rect.width; 156 *w = rect.width;
156 *h = rect.height; 157 *h = rect.height;
157} 158}
158 159
160typedef uint16_t tileid;
159typedef uint16_t mapface; 161typedef uint16_t faceid;
160 162
161typedef struct { 163typedef struct {
162 GLint name; 164 int name;
163 int w, h; 165 int w, h;
164 float s, t; 166 float s, t;
165 uint8_t r, g, b, a; 167 uint8_t r, g, b, a;
166} maptex; 168} maptex;
167 169
168typedef struct { 170typedef struct {
169 uint32_t player; 171 uint32_t player;
170 mapface face[3]; 172 tileid tile[3];
171 uint16_t darkness; 173 uint16_t darkness;
172 uint8_t stat_width, stat_hp, flags; 174 uint8_t stat_width, stat_hp, flags;
173} mapcell; 175} mapcell;
174 176
175typedef struct { 177typedef struct {
178} maprow; 180} maprow;
179 181
180typedef struct map { 182typedef struct map {
181 int x, y, w, h; 183 int x, y, w, h;
182 int ox, oy; /* offset to virtual global coordinate system */ 184 int ox, oy; /* offset to virtual global coordinate system */
183 int faces; 185 int faces; tileid *face2tile; // [faceid]
184 mapface *face; 186 int texs; maptex *tex; // [tileid]
185
186 int texs;
187 maptex *tex;
188 187
189 int32_t rows; 188 int32_t rows;
190 maprow *row; 189 maprow *row;
191} *CFPlus__Map; 190} *CFPlus__Map;
192 191
212 return ptr; 211 return ptr;
213} 212}
214 213
215#define Append(type,ptr,sze,inc) (ptr) = (type *)append ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type)) 214#define Append(type,ptr,sze,inc) (ptr) = (type *)append ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type))
216#define Prepend(type,ptr,sze,inc) (ptr) = (type *)prepend ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type)) 215#define Prepend(type,ptr,sze,inc) (ptr) = (type *)prepend ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type))
216
217static void
218need_facenum (struct map *self, faceid face)
219{
220 while (self->faces <= face)
221 {
222 Append (tileid, self->face2tile, self->faces, self->faces);
223 self->faces *= 2;
224 }
225}
226
227static void
228need_texid (struct map *self, int texid)
229{
230 while (self->texs <= texid)
231 {
232 Append (maptex, self->tex, self->texs, self->texs);
233 self->texs *= 2;
234 }
235}
217 236
218static maprow * 237static maprow *
219map_get_row (CFPlus__Map self, int y) 238map_get_row (CFPlus__Map self, int y)
220{ 239{
221 if (0 > y) 240 if (0 > y)
359 n |= n >> 16; 378 n |= n >> 16;
360 379
361 return n + 1; 380 return n + 1;
362} 381}
363 382
383/* SDL should provide this, really. */
384#define SDLK_MODIFIER_MIN 300
385#define SDLK_MODIFIER_MAX 314
386
364MODULE = CFPlus PACKAGE = CFPlus 387MODULE = CFPlus PACKAGE = CFPlus
365 388
366PROTOTYPES: ENABLE 389PROTOTYPES: ENABLE
367 390
368BOOT: 391BOOT:
371 static const struct { 394 static const struct {
372 const char *name; 395 const char *name;
373 IV iv; 396 IV iv;
374 } *civ, const_iv[] = { 397 } *civ, const_iv[] = {
375# define const_iv(name) { # name, (IV)name } 398# define const_iv(name) { # name, (IV)name }
399 const_iv (SDLK_MODIFIER_MIN),
400 const_iv (SDLK_MODIFIER_MAX),
401
376 const_iv (SDL_ACTIVEEVENT), 402 const_iv (SDL_ACTIVEEVENT),
377 const_iv (SDL_KEYDOWN), 403 const_iv (SDL_KEYDOWN),
378 const_iv (SDL_KEYUP), 404 const_iv (SDL_KEYUP),
379 const_iv (SDL_MOUSEMOTION), 405 const_iv (SDL_MOUSEMOTION),
380 const_iv (SDL_MOUSEBUTTONDOWN), 406 const_iv (SDL_MOUSEBUTTONDOWN),
389 const_iv (SDL_EVENT_RESERVEDA), 415 const_iv (SDL_EVENT_RESERVEDA),
390 const_iv (SDL_EVENT_RESERVEDB), 416 const_iv (SDL_EVENT_RESERVEDB),
391 const_iv (SDL_VIDEORESIZE), 417 const_iv (SDL_VIDEORESIZE),
392 const_iv (SDL_VIDEOEXPOSE), 418 const_iv (SDL_VIDEOEXPOSE),
393 const_iv (SDL_USEREVENT), 419 const_iv (SDL_USEREVENT),
420
421 const_iv (SDL_APPINPUTFOCUS),
422 const_iv (SDL_APPMOUSEFOCUS),
423 const_iv (SDL_APPACTIVE),
424
394 const_iv (SDLK_KP0), 425 const_iv (SDLK_KP0),
395 const_iv (SDLK_KP1), 426 const_iv (SDLK_KP1),
396 const_iv (SDLK_KP2), 427 const_iv (SDLK_KP2),
397 const_iv (SDLK_KP3), 428 const_iv (SDLK_KP3),
398 const_iv (SDLK_KP4), 429 const_iv (SDLK_KP4),
453 const_iv (SDLK_BREAK), 484 const_iv (SDLK_BREAK),
454 const_iv (SDLK_MENU), 485 const_iv (SDLK_MENU),
455 const_iv (SDLK_POWER), 486 const_iv (SDLK_POWER),
456 const_iv (SDLK_EURO), 487 const_iv (SDLK_EURO),
457 const_iv (SDLK_UNDO), 488 const_iv (SDLK_UNDO),
489
458 const_iv (KMOD_NONE), 490 const_iv (KMOD_NONE),
491 const_iv (KMOD_SHIFT),
459 const_iv (KMOD_LSHIFT), 492 const_iv (KMOD_LSHIFT),
460 const_iv (KMOD_RSHIFT), 493 const_iv (KMOD_RSHIFT),
494 const_iv (KMOD_CTRL),
461 const_iv (KMOD_LCTRL), 495 const_iv (KMOD_LCTRL),
462 const_iv (KMOD_RCTRL), 496 const_iv (KMOD_RCTRL),
497 const_iv (KMOD_ALT),
463 const_iv (KMOD_LALT), 498 const_iv (KMOD_LALT),
464 const_iv (KMOD_RALT), 499 const_iv (KMOD_RALT),
500 const_iv (KMOD_META),
465 const_iv (KMOD_LMETA), 501 const_iv (KMOD_LMETA),
466 const_iv (KMOD_RMETA), 502 const_iv (KMOD_RMETA),
467 const_iv (KMOD_NUM), 503 const_iv (KMOD_NUM),
468 const_iv (KMOD_CAPS), 504 const_iv (KMOD_CAPS),
469 const_iv (KMOD_MODE), 505 const_iv (KMOD_MODE),
470 const_iv (KMOD_CTRL),
471 const_iv (KMOD_SHIFT),
472 const_iv (KMOD_ALT),
473 const_iv (KMOD_META)
474# undef const_iv 506# undef const_iv
475 }; 507 };
476 508
477 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 509 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
478 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 510 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
511
512 assert (SDLK_MODIFIER_MIN == SDLK_NUMLOCK);
513 assert (SDLK_MODIFIER_MAX == SDLK_COMPOSE);
479} 514}
515
516void
517weaken (SV *rv)
518 PROTOTYPE: $
519 CODE:
520 sv_rvweaken (rv);
480 521
481int 522int
482in_destruct () 523in_destruct ()
483 CODE: 524 CODE:
484 RETVAL = PL_main_cv == Nullcv; 525 RETVAL = PL_main_cv == Nullcv;
587 case SDL_KEYDOWN: 628 case SDL_KEYDOWN:
588 case SDL_KEYUP: 629 case SDL_KEYUP:
589 hv_store (hv, "state", 5, newSViv (ev.key.state), 0); 630 hv_store (hv, "state", 5, newSViv (ev.key.state), 0);
590 hv_store (hv, "sym", 3, newSViv (ev.key.keysym.sym), 0); 631 hv_store (hv, "sym", 3, newSViv (ev.key.keysym.sym), 0);
591 hv_store (hv, "mod", 3, newSViv (ev.key.keysym.mod), 0); 632 hv_store (hv, "mod", 3, newSViv (ev.key.keysym.mod), 0);
633 hv_store (hv, "cmod", 4, newSViv (SDL_GetModState ()), 0); /* current mode */
592 hv_store (hv, "unicode", 7, newSViv (ev.key.keysym.unicode), 0); 634 hv_store (hv, "unicode", 7, newSViv (ev.key.keysym.unicode), 0);
593 break; 635 break;
594 636
595 case SDL_ACTIVEEVENT: 637 case SDL_ACTIVEEVENT:
596 hv_store (hv, "gain", 4, newSViv (ev.active.gain), 0); 638 hv_store (hv, "gain", 4, newSViv (ev.active.gain), 0);
1216 RETVAL->y = 0; 1258 RETVAL->y = 0;
1217 RETVAL->w = 0; 1259 RETVAL->w = 0;
1218 RETVAL->h = 0; 1260 RETVAL->h = 0;
1219 RETVAL->ox = 0; 1261 RETVAL->ox = 0;
1220 RETVAL->oy = 0; 1262 RETVAL->oy = 0;
1221 RETVAL->faces = 8192; 1263 RETVAL->faces = 8192; Newz (0, RETVAL->face2tile, RETVAL->faces, tileid);
1222 Newz (0, RETVAL->face, RETVAL->faces, mapface); 1264 RETVAL->texs = 8192; Newz (0, RETVAL->tex , RETVAL->texs , maptex);
1223 RETVAL->texs = 8192;
1224 Newz (0, RETVAL->tex, RETVAL->texs, maptex);
1225 RETVAL->rows = 0; 1265 RETVAL->rows = 0;
1226 RETVAL->row = 0; 1266 RETVAL->row = 0;
1227 OUTPUT: 1267 OUTPUT:
1228 RETVAL 1268 RETVAL
1229 1269
1230void 1270void
1231DESTROY (CFPlus::Map self) 1271DESTROY (CFPlus::Map self)
1232 CODE: 1272 CODE:
1233{ 1273{
1234 map_clear (self); 1274 map_clear (self);
1235 Safefree (self->face); 1275 Safefree (self->face2tile);
1236 Safefree (self->tex); 1276 Safefree (self->tex);
1237 Safefree (self); 1277 Safefree (self);
1238} 1278}
1239 1279
1240void 1280void
1247clear (CFPlus::Map self) 1287clear (CFPlus::Map self)
1248 CODE: 1288 CODE:
1249 map_clear (self); 1289 map_clear (self);
1250 1290
1251void 1291void
1252set_face (CFPlus::Map self, int face, int texid) 1292set_tileid (CFPlus::Map self, int face, int tile)
1253 CODE: 1293 CODE:
1254{ 1294{
1255 while (self->faces <= face) 1295 need_facenum (self, face); self->face2tile [face] = tile;
1256 { 1296 need_texid (self, tile);
1257 Append (mapface, self->face, self->faces, self->faces);
1258 self->faces *= 2;
1259 }
1260
1261 self->face [face] = texid;
1262} 1297}
1263 1298
1264void 1299void
1265set_texture (CFPlus::Map self, int texid, int name, int w, int h, float s, float t, int r, int g, int b, int a) 1300set_texture (CFPlus::Map self, int texid, int name, int w, int h, float s, float t, int r, int g, int b, int a)
1266 CODE: 1301 CODE:
1267{ 1302{
1268 while (self->texs <= texid) 1303 need_texid (self, texid);
1269 {
1270 Append (maptex, self->tex, self->texs, self->texs);
1271 self->texs *= 2;
1272 }
1273 1304
1274 { 1305 {
1275 maptex *tex = self->tex + texid; 1306 maptex *tex = self->tex + texid;
1276 1307
1277 tex->name = name; 1308 tex->name = name;
1388 cell->stat_width = 1; 1419 cell->stat_width = 1;
1389 cell->stat_hp = *data++; 1420 cell->stat_hp = *data++;
1390 } 1421 }
1391 else if (cmd == 6) // monster width 1422 else if (cmd == 6) // monster width
1392 cell->stat_width = *data++ + 1; 1423 cell->stat_width = *data++ + 1;
1393 else if (cmd == 0x47) // monster width 1424 else if (cmd == 0x47)
1394 { 1425 {
1395 if (*data == 4) 1426 if (*data == 8)
1396 ; // decode player tag 1427 ; // decode player uuid
1397 1428
1398 data += *data + 1; 1429 data += *data + 1;
1399 } 1430 }
1400 else if (cmd == 8) // cell flags 1431 else if (cmd == 8) // cell flags
1401 cell->flags = *data++; 1432 cell->flags = *data++;
1410 cell->darkness = *data++ + 1; 1441 cell->darkness = *data++ + 1;
1411 } 1442 }
1412 1443
1413 if (flags & 4) 1444 if (flags & 4)
1414 { 1445 {
1415 cell->face [0] = self->face [(data [0] << 8) + data [1]]; data += 2; 1446 faceid face = (data [0] << 8) + data [1]; data += 2;
1447 need_facenum (self, face);
1448 cell->tile [0] = self->face2tile [face];
1416 } 1449 }
1417 1450
1418 if (flags & 2) 1451 if (flags & 2)
1419 { 1452 {
1420 cell->face [1] = self->face [(data [0] << 8) + data [1]]; data += 2; 1453 faceid face = (data [0] << 8) + data [1]; data += 2;
1454 need_facenum (self, face);
1455 cell->tile [1] = self->face2tile [face];
1421 } 1456 }
1422 1457
1423 if (flags & 1) 1458 if (flags & 1)
1424 { 1459 {
1425 cell->face [2] = self->face [(data [0] << 8) + data [1]]; data += 2; 1460 faceid face = (data [0] << 8) + data [1]; data += 2;
1461 need_facenum (self, face);
1462 cell->tile [2] = self->face2tile [face];
1426 } 1463 }
1427 } 1464 }
1428 else 1465 else
1429 cell->darkness = 0; 1466 cell->darkness = 0;
1430 } 1467 }
1460 { 1497 {
1461 mapcell *cell = row->col + (x - row->c0); 1498 mapcell *cell = row->col + (x - row->c0);
1462 1499
1463 for (z = 0; z <= 0; z++) 1500 for (z = 0; z <= 0; z++)
1464 { 1501 {
1465 mapface face = cell->face [z];
1466
1467 if (face)
1468 {
1469 maptex tex = self->tex [face]; 1502 maptex tex = self->tex [cell->tile [z]];
1470 int a0 = 255 - tex.a; 1503 int a0 = 255 - tex.a;
1471 int a1 = tex.a; 1504 int a1 = tex.a;
1472 1505
1473 r = (r * a0 + tex.r * a1) / 255; 1506 r = (r * a0 + tex.r * a1) / 255;
1474 g = (g * a0 + tex.g * a1) / 255; 1507 g = (g * a0 + tex.g * a1) / 255;
1475 b = (b * a0 + tex.b * a1) / 255; 1508 b = (b * a0 + tex.b * a1) / 255;
1476 a = (a * a0 + tex.a * a1) / 255; 1509 a = (a * a0 + tex.a * a1) / 255;
1477 }
1478 } 1510 }
1479 } 1511 }
1480 1512
1481 *map++ = (r ) 1513 *map++ = (r )
1482 | (g << 8) 1514 | (g << 8)
1489} 1521}
1490 OUTPUT: 1522 OUTPUT:
1491 RETVAL 1523 RETVAL
1492 1524
1493void 1525void
1494draw (CFPlus::Map self, int mx, int my, int sw, int sh) 1526draw (CFPlus::Map self, int mx, int my, int sw, int sh, int T)
1495 CODE: 1527 CODE:
1496{ 1528{
1497 int x, y, z; 1529 int x, y, z;
1498 int last_name; 1530 int last_name;
1499 mapface face;
1500 1531
1501 glColor4ub (255, 255, 255, 255); 1532 glColor4ub (255, 255, 255, 255);
1502 1533
1503 glEnable (GL_BLEND); 1534 glEnable (GL_BLEND);
1504 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 1535 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1520 1551
1521 for (x = 0; x < sw; x++) 1552 for (x = 0; x < sw; x++)
1522 if (row->c0 <= x + mx && x + mx < row->c1) 1553 if (row->c0 <= x + mx && x + mx < row->c1)
1523 { 1554 {
1524 mapcell *cell = row->col + (x + mx - row->c0); 1555 mapcell *cell = row->col + (x + mx - row->c0);
1525
1526 face = cell->face [z]; 1556 tileid tile = cell->tile [z];
1527 1557
1528 if (face && face < self->texs) 1558 if (tile)
1529 { 1559 {
1530 maptex tex = self->tex [face]; 1560 maptex tex = self->tex [tile];
1531 int px = (x + 1) * 32 - tex.w; 1561 int px = (x + 1) * T - tex.w;
1532 int py = (y + 1) * 32 - tex.h; 1562 int py = (y + 1) * T - tex.h;
1533 1563
1534 if (last_name != tex.name) 1564 if (last_name != tex.name)
1535 { 1565 {
1566 if (!tex.name)
1567 tex = self->tex [2]; /* missing, replace by noface */
1568
1536 glEnd (); 1569 glEnd ();
1537 glBindTexture (GL_TEXTURE_2D, last_name = tex.name); 1570 glBindTexture (GL_TEXTURE_2D, last_name = tex.name);
1538 glBegin (GL_QUADS); 1571 glBegin (GL_QUADS);
1539 } 1572 }
1540 1573
1541 glTexCoord2f (0 , 0 ); glVertex2f (px , py ); 1574 glTexCoord2f (0 , 0 ); glVertex2f (px , py );
1542 glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); 1575 glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h);
1543 glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h); 1576 glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h);
1544 glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); 1577 glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py );
1545 }
1546 1578
1547 if (cell->flags && z == 2) 1579 if (cell->flags && z == 2)
1548 {
1549 if (cell->flags & 1)
1550 { 1580 {
1581 if (cell->flags & 1)
1582 {
1551 maptex tex = self->tex [1]; 1583 maptex tex = self->tex [1];
1552 int px = (x + 1) * 32 - tex.w + 2; 1584 int px = x * T + T * 2 / 32;
1553 int py = (y + 1) * 32 - tex.h - 6; 1585 int py = y * T - T * 6 / 32;
1554 1586
1555 glEnd (); 1587 glEnd ();
1556 glBindTexture (GL_TEXTURE_2D, last_name = tex.name); 1588 glBindTexture (GL_TEXTURE_2D, last_name = tex.name);
1557 glBegin (GL_QUADS); 1589 glBegin (GL_QUADS);
1558 1590
1559 glTexCoord2f (0 , 0 ); glVertex2f (px , py ); 1591 glTexCoord2f (0 , 0 ); glVertex2f (px , py );
1560 glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); 1592 glTexCoord2f (0 , tex.t); glVertex2f (px , py + T);
1561 glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h); 1593 glTexCoord2f (tex.s, tex.t); glVertex2f (px + T, py + T);
1562 glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); 1594 glTexCoord2f (tex.s, 0 ); glVertex2f (px + T, py );
1595 }
1563 } 1596 }
1564 } 1597 }
1565 } 1598 }
1566 } 1599 }
1567 1600
1579 for (x = 0; x < sw; x++) 1612 for (x = 0; x < sw; x++)
1580 if (row->c0 <= x + mx && x + mx < row->c1) 1613 if (row->c0 <= x + mx && x + mx < row->c1)
1581 { 1614 {
1582 mapcell *cell = row->col + (x + mx - row->c0); 1615 mapcell *cell = row->col + (x + mx - row->c0);
1583 1616
1584 int px = x * 32; 1617 int px = x * T;
1585 int py = y * 32; 1618 int py = y * T;
1586 1619
1587 if (cell->stat_hp) 1620 if (cell->stat_hp)
1588 { 1621 {
1589 int width = cell->stat_width * 32; 1622 int width = cell->stat_width * T;
1590 int thick = sh / 28 + 1 + cell->stat_width; 1623 int thick = (sh * T / 32 + 27) / 28 + 1 + cell->stat_width;
1591 1624
1592 glColor3ub (0, 0, 0); 1625 glColor3ub (0, 0, 0);
1593 glRectf (px + 1, py - thick - 2, 1626 glRectf (px + 1, py - thick - 2,
1594 px + width - 1, py); 1627 px + width - 1, py);
1595 1628
1734 if (row && row->c0 <= x && x < row->c1) 1767 if (row && row->c0 <= x && x < row->c1)
1735 { 1768 {
1736 mapcell *cell = row->col + (x - row->c0); 1769 mapcell *cell = row->col + (x - row->c0);
1737 uint8_t flags = 0; 1770 uint8_t flags = 0;
1738 1771
1739 if (cell->face [0]) flags |= 1; 1772 if (cell->tile [0]) flags |= 1;
1740 if (cell->face [1]) flags |= 2; 1773 if (cell->tile [1]) flags |= 2;
1741 if (cell->face [2]) flags |= 4; 1774 if (cell->tile [2]) flags |= 4;
1742 1775
1743 *data++ = flags; 1776 *data++ = flags;
1744 1777
1745 if (flags & 1) 1778 if (flags & 1)
1746 { 1779 {
1780 tileid tile = cell->tile [0];
1747 *data++ = cell->face [0] >> 8; 1781 *data++ = tile >> 8;
1748 *data++ = cell->face [0]; 1782 *data++ = tile;
1749 } 1783 }
1750 1784
1751 if (flags & 2) 1785 if (flags & 2)
1752 { 1786 {
1787 tileid tile = cell->tile [1];
1753 *data++ = cell->face [1] >> 8; 1788 *data++ = tile >> 8;
1754 *data++ = cell->face [1]; 1789 *data++ = tile;
1755 } 1790 }
1756 1791
1757 if (flags & 4) 1792 if (flags & 4)
1758 { 1793 {
1794 tileid tile = cell->tile [2];
1759 *data++ = cell->face [2] >> 8; 1795 *data++ = tile >> 8;
1760 *data++ = cell->face [2]; 1796 *data++ = tile;
1761 } 1797 }
1762 } 1798 }
1763 else 1799 else
1764 *data++ = 0; 1800 *data++ = 0;
1765 } 1801 }
1805 { 1841 {
1806 uint8_t flags = *data++; 1842 uint8_t flags = *data++;
1807 1843
1808 if (flags) 1844 if (flags)
1809 { 1845 {
1810 mapface face[3] = { 0, 0, 0 };
1811
1812 mapcell *cell = row_get_cell (row, x); 1846 mapcell *cell = row_get_cell (row, x);
1847 tileid tile[3] = { 0, 0, 0 };
1813 1848
1814 if (flags & 1) { face[0] = *data++ << 8; face[0] |= *data++; } 1849 if (flags & 1) { tile[0] = *data++ << 8; tile[0] |= *data++; }
1815 if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; } 1850 if (flags & 2) { tile[1] = *data++ << 8; tile[1] |= *data++; }
1816 if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; } 1851 if (flags & 4) { tile[2] = *data++ << 8; tile[2] |= *data++; }
1817 1852
1818 if (cell->darkness == 0) 1853 if (cell->darkness == 0)
1819 { 1854 {
1820 cell->darkness = 0; 1855 cell->darkness = 0;
1821 1856
1822 for (z = 0; z <= 2; z++) 1857 for (z = 0; z <= 2; z++)
1823 { 1858 {
1824 cell->face[z] = face[z]; 1859 tileid t = tile [z];
1825 1860
1826 if (face[z] && (face[z] >= self->texs || !self->tex[face [z]].name)) 1861 if (t >= self->texs || (t && !self->tex [t].name))
1862 {
1827 XPUSHs (sv_2mortal (newSViv (face[z]))); 1863 XPUSHs (sv_2mortal (newSViv (t)));
1864 need_texid (self, t);
1865 }
1866
1867 cell->tile [z] = t;
1828 } 1868 }
1829 } 1869 }
1830 } 1870 }
1831 } 1871 }
1832 } 1872 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines