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.165 by root, Fri Dec 8 14:59:54 2006 UTC vs.
Revision 1.174 by root, Fri Apr 6 07:45:34 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);
1094 XSRETURN_EMPTY; 1136 XSRETURN_EMPTY;
1095 1137
1096 if (!(lp = pango_layout_get_line (self->pl, line))) 1138 if (!(lp = pango_layout_get_line (self->pl, line)))
1097 XSRETURN_EMPTY; /* do better */ 1139 XSRETURN_EMPTY; /* do better */
1098 1140
1099 if (!pango_layout_line_x_to_index (lp, x * PANGO_SCALE, &index, &trailing)) 1141 pango_layout_line_x_to_index (lp, x * PANGO_SCALE, &index, &trailing);
1100 XSRETURN_EMPTY; /* do better */
1101 1142
1102 EXTEND (SP, 2); 1143 EXTEND (SP, 2);
1103 if (GIMME_V == G_SCALAR) 1144 if (GIMME_V == G_SCALAR)
1104 PUSHs (sv_2mortal (newSViv (index + trailing))); 1145 PUSHs (sv_2mortal (newSViv (index + trailing)));
1105 else 1146 else
1217 RETVAL->y = 0; 1258 RETVAL->y = 0;
1218 RETVAL->w = 0; 1259 RETVAL->w = 0;
1219 RETVAL->h = 0; 1260 RETVAL->h = 0;
1220 RETVAL->ox = 0; 1261 RETVAL->ox = 0;
1221 RETVAL->oy = 0; 1262 RETVAL->oy = 0;
1222 RETVAL->faces = 8192; 1263 RETVAL->faces = 8192; Newz (0, RETVAL->face2tile, RETVAL->faces, tileid);
1223 Newz (0, RETVAL->face, RETVAL->faces, mapface); 1264 RETVAL->texs = 8192; Newz (0, RETVAL->tex , RETVAL->texs , maptex);
1224 RETVAL->texs = 8192;
1225 Newz (0, RETVAL->tex, RETVAL->texs, maptex);
1226 RETVAL->rows = 0; 1265 RETVAL->rows = 0;
1227 RETVAL->row = 0; 1266 RETVAL->row = 0;
1228 OUTPUT: 1267 OUTPUT:
1229 RETVAL 1268 RETVAL
1230 1269
1231void 1270void
1232DESTROY (CFPlus::Map self) 1271DESTROY (CFPlus::Map self)
1233 CODE: 1272 CODE:
1234{ 1273{
1235 map_clear (self); 1274 map_clear (self);
1236 Safefree (self->face); 1275 Safefree (self->face2tile);
1237 Safefree (self->tex); 1276 Safefree (self->tex);
1238 Safefree (self); 1277 Safefree (self);
1239} 1278}
1240 1279
1241void 1280void
1248clear (CFPlus::Map self) 1287clear (CFPlus::Map self)
1249 CODE: 1288 CODE:
1250 map_clear (self); 1289 map_clear (self);
1251 1290
1252void 1291void
1253set_face (CFPlus::Map self, int face, int texid) 1292set_tileid (CFPlus::Map self, int face, int tile)
1254 CODE: 1293 CODE:
1255{ 1294{
1256 while (self->faces <= face) 1295 need_facenum (self, face); self->face2tile [face] = tile;
1257 { 1296 need_texid (self, tile);
1258 Append (mapface, self->face, self->faces, self->faces);
1259 self->faces *= 2;
1260 }
1261
1262 self->face [face] = texid;
1263} 1297}
1264 1298
1265void 1299void
1266set_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)
1267 CODE: 1301 CODE:
1268{ 1302{
1269 while (self->texs <= texid) 1303 need_texid (self, texid);
1270 {
1271 Append (maptex, self->tex, self->texs, self->texs);
1272 self->texs *= 2;
1273 }
1274 1304
1275 { 1305 {
1276 maptex *tex = self->tex + texid; 1306 maptex *tex = self->tex + texid;
1277 1307
1278 tex->name = name; 1308 tex->name = name;
1389 cell->stat_width = 1; 1419 cell->stat_width = 1;
1390 cell->stat_hp = *data++; 1420 cell->stat_hp = *data++;
1391 } 1421 }
1392 else if (cmd == 6) // monster width 1422 else if (cmd == 6) // monster width
1393 cell->stat_width = *data++ + 1; 1423 cell->stat_width = *data++ + 1;
1394 else if (cmd == 0x47) // monster width 1424 else if (cmd == 0x47)
1395 { 1425 {
1396 if (*data == 4) 1426 if (*data == 8)
1397 ; // decode player tag 1427 ; // decode player uuid
1398 1428
1399 data += *data + 1; 1429 data += *data + 1;
1400 } 1430 }
1401 else if (cmd == 8) // cell flags 1431 else if (cmd == 8) // cell flags
1402 cell->flags = *data++; 1432 cell->flags = *data++;
1411 cell->darkness = *data++ + 1; 1441 cell->darkness = *data++ + 1;
1412 } 1442 }
1413 1443
1414 if (flags & 4) 1444 if (flags & 4)
1415 { 1445 {
1416 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];
1417 } 1449 }
1418 1450
1419 if (flags & 2) 1451 if (flags & 2)
1420 { 1452 {
1421 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];
1422 } 1456 }
1423 1457
1424 if (flags & 1) 1458 if (flags & 1)
1425 { 1459 {
1426 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];
1427 } 1463 }
1428 } 1464 }
1429 else 1465 else
1430 cell->darkness = 0; 1466 cell->darkness = 0;
1431 } 1467 }
1461 { 1497 {
1462 mapcell *cell = row->col + (x - row->c0); 1498 mapcell *cell = row->col + (x - row->c0);
1463 1499
1464 for (z = 0; z <= 0; z++) 1500 for (z = 0; z <= 0; z++)
1465 { 1501 {
1466 mapface face = cell->face [z];
1467
1468 if (face)
1469 {
1470 maptex tex = self->tex [face]; 1502 maptex tex = self->tex [cell->tile [z]];
1471 int a0 = 255 - tex.a; 1503 int a0 = 255 - tex.a;
1472 int a1 = tex.a; 1504 int a1 = tex.a;
1473 1505
1474 r = (r * a0 + tex.r * a1) / 255; 1506 r = (r * a0 + tex.r * a1) / 255;
1475 g = (g * a0 + tex.g * a1) / 255; 1507 g = (g * a0 + tex.g * a1) / 255;
1476 b = (b * a0 + tex.b * a1) / 255; 1508 b = (b * a0 + tex.b * a1) / 255;
1477 a = (a * a0 + tex.a * a1) / 255; 1509 a = (a * a0 + tex.a * a1) / 255;
1478 }
1479 } 1510 }
1480 } 1511 }
1481 1512
1482 *map++ = (r ) 1513 *map++ = (r )
1483 | (g << 8) 1514 | (g << 8)
1490} 1521}
1491 OUTPUT: 1522 OUTPUT:
1492 RETVAL 1523 RETVAL
1493 1524
1494void 1525void
1495draw (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)
1496 CODE: 1527 CODE:
1497{ 1528{
1498 int x, y, z; 1529 int x, y, z;
1499 int last_name; 1530 int last_name;
1500 mapface face;
1501 1531
1502 glColor4ub (255, 255, 255, 255); 1532 glColor4ub (255, 255, 255, 255);
1503 1533
1504 glEnable (GL_BLEND); 1534 glEnable (GL_BLEND);
1505 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 1535 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1521 1551
1522 for (x = 0; x < sw; x++) 1552 for (x = 0; x < sw; x++)
1523 if (row->c0 <= x + mx && x + mx < row->c1) 1553 if (row->c0 <= x + mx && x + mx < row->c1)
1524 { 1554 {
1525 mapcell *cell = row->col + (x + mx - row->c0); 1555 mapcell *cell = row->col + (x + mx - row->c0);
1526
1527 face = cell->face [z]; 1556 tileid tile = cell->tile [z];
1528 1557
1529 if (face && face < self->texs) 1558 if (tile)
1530 { 1559 {
1531 maptex tex = self->tex [face]; 1560 maptex tex = self->tex [tile];
1532 int px = (x + 1) * 32 - tex.w; 1561 int px = (x + 1) * T - tex.w;
1533 int py = (y + 1) * 32 - tex.h; 1562 int py = (y + 1) * T - tex.h;
1534 1563
1535 if (last_name != tex.name) 1564 if (last_name != tex.name)
1536 { 1565 {
1566 if (!tex.name)
1567 tex = self->tex [2]; /* missing, replace by noface */
1568
1537 glEnd (); 1569 glEnd ();
1538 glBindTexture (GL_TEXTURE_2D, last_name = tex.name); 1570 glBindTexture (GL_TEXTURE_2D, last_name = tex.name);
1539 glBegin (GL_QUADS); 1571 glBegin (GL_QUADS);
1540 } 1572 }
1541 1573
1542 glTexCoord2f (0 , 0 ); glVertex2f (px , py ); 1574 glTexCoord2f (0 , 0 ); glVertex2f (px , py );
1543 glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); 1575 glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h);
1544 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);
1545 glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); 1577 glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py );
1546 }
1547 1578
1548 if (cell->flags && z == 2) 1579 if (cell->flags && z == 2)
1549 {
1550 if (cell->flags & 1)
1551 { 1580 {
1581 if (cell->flags & 1)
1582 {
1552 maptex tex = self->tex [1]; 1583 maptex tex = self->tex [1];
1553 int px = (x + 1) * 32 - tex.w + 2; 1584 int px = x * T + T * 2 / 32;
1554 int py = (y + 1) * 32 - tex.h - 6; 1585 int py = y * T - T * 6 / 32;
1555 1586
1556 glEnd (); 1587 glEnd ();
1557 glBindTexture (GL_TEXTURE_2D, last_name = tex.name); 1588 glBindTexture (GL_TEXTURE_2D, last_name = tex.name);
1558 glBegin (GL_QUADS); 1589 glBegin (GL_QUADS);
1559 1590
1560 glTexCoord2f (0 , 0 ); glVertex2f (px , py ); 1591 glTexCoord2f (0 , 0 ); glVertex2f (px , py );
1561 glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); 1592 glTexCoord2f (0 , tex.t); glVertex2f (px , py + T);
1562 glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h); 1593 glTexCoord2f (tex.s, tex.t); glVertex2f (px + T, py + T);
1563 glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); 1594 glTexCoord2f (tex.s, 0 ); glVertex2f (px + T, py );
1595 }
1564 } 1596 }
1565 } 1597 }
1566 } 1598 }
1567 } 1599 }
1568 1600
1580 for (x = 0; x < sw; x++) 1612 for (x = 0; x < sw; x++)
1581 if (row->c0 <= x + mx && x + mx < row->c1) 1613 if (row->c0 <= x + mx && x + mx < row->c1)
1582 { 1614 {
1583 mapcell *cell = row->col + (x + mx - row->c0); 1615 mapcell *cell = row->col + (x + mx - row->c0);
1584 1616
1585 int px = x * 32; 1617 int px = x * T;
1586 int py = y * 32; 1618 int py = y * T;
1587 1619
1588 if (cell->stat_hp) 1620 if (cell->stat_hp)
1589 { 1621 {
1590 int width = cell->stat_width * 32; 1622 int width = cell->stat_width * T;
1591 int thick = sh / 28 + 1 + cell->stat_width; 1623 int thick = (sh * T / 32 + 27) / 28 + 1 + cell->stat_width;
1592 1624
1593 glColor3ub (0, 0, 0); 1625 glColor3ub (0, 0, 0);
1594 glRectf (px + 1, py - thick - 2, 1626 glRectf (px + 1, py - thick - 2,
1595 px + width - 1, py); 1627 px + width - 1, py);
1596 1628
1735 if (row && row->c0 <= x && x < row->c1) 1767 if (row && row->c0 <= x && x < row->c1)
1736 { 1768 {
1737 mapcell *cell = row->col + (x - row->c0); 1769 mapcell *cell = row->col + (x - row->c0);
1738 uint8_t flags = 0; 1770 uint8_t flags = 0;
1739 1771
1740 if (cell->face [0]) flags |= 1; 1772 if (cell->tile [0]) flags |= 1;
1741 if (cell->face [1]) flags |= 2; 1773 if (cell->tile [1]) flags |= 2;
1742 if (cell->face [2]) flags |= 4; 1774 if (cell->tile [2]) flags |= 4;
1743 1775
1744 *data++ = flags; 1776 *data++ = flags;
1745 1777
1746 if (flags & 1) 1778 if (flags & 1)
1747 { 1779 {
1780 tileid tile = cell->tile [0];
1748 *data++ = cell->face [0] >> 8; 1781 *data++ = tile >> 8;
1749 *data++ = cell->face [0]; 1782 *data++ = tile;
1750 } 1783 }
1751 1784
1752 if (flags & 2) 1785 if (flags & 2)
1753 { 1786 {
1787 tileid tile = cell->tile [1];
1754 *data++ = cell->face [1] >> 8; 1788 *data++ = tile >> 8;
1755 *data++ = cell->face [1]; 1789 *data++ = tile;
1756 } 1790 }
1757 1791
1758 if (flags & 4) 1792 if (flags & 4)
1759 { 1793 {
1794 tileid tile = cell->tile [2];
1760 *data++ = cell->face [2] >> 8; 1795 *data++ = tile >> 8;
1761 *data++ = cell->face [2]; 1796 *data++ = tile;
1762 } 1797 }
1763 } 1798 }
1764 else 1799 else
1765 *data++ = 0; 1800 *data++ = 0;
1766 } 1801 }
1806 { 1841 {
1807 uint8_t flags = *data++; 1842 uint8_t flags = *data++;
1808 1843
1809 if (flags) 1844 if (flags)
1810 { 1845 {
1811 mapface face[3] = { 0, 0, 0 };
1812
1813 mapcell *cell = row_get_cell (row, x); 1846 mapcell *cell = row_get_cell (row, x);
1847 tileid tile[3] = { 0, 0, 0 };
1814 1848
1815 if (flags & 1) { face[0] = *data++ << 8; face[0] |= *data++; } 1849 if (flags & 1) { tile[0] = *data++ << 8; tile[0] |= *data++; }
1816 if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; } 1850 if (flags & 2) { tile[1] = *data++ << 8; tile[1] |= *data++; }
1817 if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; } 1851 if (flags & 4) { tile[2] = *data++ << 8; tile[2] |= *data++; }
1818 1852
1819 if (cell->darkness == 0) 1853 if (cell->darkness == 0)
1820 { 1854 {
1821 cell->darkness = 0; 1855 cell->darkness = 0;
1822 1856
1823 for (z = 0; z <= 2; z++) 1857 for (z = 0; z <= 2; z++)
1824 { 1858 {
1825 cell->face[z] = face[z]; 1859 tileid t = tile [z];
1826 1860
1827 if (face[z] && (face[z] >= self->texs || !self->tex[face [z]].name)) 1861 if (t >= self->texs || !self->tex [t].name)
1862 {
1828 XPUSHs (sv_2mortal (newSViv (face[z]))); 1863 XPUSHs (sv_2mortal (newSViv (t)));
1864 need_texid (self, t);
1865 }
1866
1867 cell->tile [z] = t;
1829 } 1868 }
1830 } 1869 }
1831 } 1870 }
1832 } 1871 }
1833 } 1872 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines