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.164 by root, Tue Nov 7 22:41:27 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);
1049xy_to_index (CFPlus::Layout self, int x, int y) 1091xy_to_index (CFPlus::Layout self, int x, int y)
1050 CODE: 1092 CODE:
1051{ 1093{
1052 int index, trailing; 1094 int index, trailing;
1053 pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing); 1095 pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing);
1054 RETVAL = index; 1096 RETVAL = index + trailing;
1055} 1097}
1056 OUTPUT: 1098 OUTPUT:
1057 RETVAL 1099 RETVAL
1058 1100
1059void 1101void
1065 1107
1066 EXTEND (SP, 3); 1108 EXTEND (SP, 3);
1067 PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE))); 1109 PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE)));
1068 PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); 1110 PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE)));
1069 PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); 1111 PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE)));
1112}
1113
1114void
1115index_to_line_x (CFPlus::Layout self, int index, int trailing = 0)
1116 PPCODE:
1117{
1118 int line, x;
1119
1120 pango_layout_index_to_line_x (self->pl, index, trailing, &line, &x);
1121 /* pango bug: line is between 1..numlines, not 0..numlines-1 */
1122
1123 EXTEND (SP, 2);
1124 PUSHs (sv_2mortal (newSViv (line - 1)));
1125 PUSHs (sv_2mortal (newSViv (x / PANGO_SCALE)));
1126}
1127
1128void
1129line_x_to_index (CFPlus::Layout self, int line, int x)
1130 PPCODE:
1131{
1132 PangoLayoutLine *lp;
1133 int index, trailing;
1134
1135 if (line < 0)
1136 XSRETURN_EMPTY;
1137
1138 if (!(lp = pango_layout_get_line (self->pl, line)))
1139 XSRETURN_EMPTY; /* do better */
1140
1141 pango_layout_line_x_to_index (lp, x * PANGO_SCALE, &index, &trailing);
1142
1143 EXTEND (SP, 2);
1144 if (GIMME_V == G_SCALAR)
1145 PUSHs (sv_2mortal (newSViv (index + trailing)));
1146 else
1147 {
1148 PUSHs (sv_2mortal (newSViv (index)));
1149 PUSHs (sv_2mortal (newSViv (trailing)));
1150 }
1070} 1151}
1071 1152
1072void 1153void
1073render (CFPlus::Layout self, float x, float y, int flags = 0) 1154render (CFPlus::Layout self, float x, float y, int flags = 0)
1074 PPCODE: 1155 PPCODE:
1177 RETVAL->y = 0; 1258 RETVAL->y = 0;
1178 RETVAL->w = 0; 1259 RETVAL->w = 0;
1179 RETVAL->h = 0; 1260 RETVAL->h = 0;
1180 RETVAL->ox = 0; 1261 RETVAL->ox = 0;
1181 RETVAL->oy = 0; 1262 RETVAL->oy = 0;
1182 RETVAL->faces = 8192; 1263 RETVAL->faces = 8192; Newz (0, RETVAL->face2tile, RETVAL->faces, tileid);
1183 Newz (0, RETVAL->face, RETVAL->faces, mapface); 1264 RETVAL->texs = 8192; Newz (0, RETVAL->tex , RETVAL->texs , maptex);
1184 RETVAL->texs = 8192;
1185 Newz (0, RETVAL->tex, RETVAL->texs, maptex);
1186 RETVAL->rows = 0; 1265 RETVAL->rows = 0;
1187 RETVAL->row = 0; 1266 RETVAL->row = 0;
1188 OUTPUT: 1267 OUTPUT:
1189 RETVAL 1268 RETVAL
1190 1269
1191void 1270void
1192DESTROY (CFPlus::Map self) 1271DESTROY (CFPlus::Map self)
1193 CODE: 1272 CODE:
1194{ 1273{
1195 map_clear (self); 1274 map_clear (self);
1196 Safefree (self->face); 1275 Safefree (self->face2tile);
1197 Safefree (self->tex); 1276 Safefree (self->tex);
1198 Safefree (self); 1277 Safefree (self);
1199} 1278}
1200 1279
1201void 1280void
1208clear (CFPlus::Map self) 1287clear (CFPlus::Map self)
1209 CODE: 1288 CODE:
1210 map_clear (self); 1289 map_clear (self);
1211 1290
1212void 1291void
1213set_face (CFPlus::Map self, int face, int texid) 1292set_tileid (CFPlus::Map self, int face, int tile)
1214 CODE: 1293 CODE:
1215{ 1294{
1216 while (self->faces <= face) 1295 need_facenum (self, face); self->face2tile [face] = tile;
1217 { 1296 need_texid (self, tile);
1218 Append (mapface, self->face, self->faces, self->faces);
1219 self->faces *= 2;
1220 }
1221
1222 self->face [face] = texid;
1223} 1297}
1224 1298
1225void 1299void
1226set_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)
1227 CODE: 1301 CODE:
1228{ 1302{
1229 while (self->texs <= texid) 1303 need_texid (self, texid);
1230 {
1231 Append (maptex, self->tex, self->texs, self->texs);
1232 self->texs *= 2;
1233 }
1234 1304
1235 { 1305 {
1236 maptex *tex = self->tex + texid; 1306 maptex *tex = self->tex + texid;
1237 1307
1238 tex->name = name; 1308 tex->name = name;
1349 cell->stat_width = 1; 1419 cell->stat_width = 1;
1350 cell->stat_hp = *data++; 1420 cell->stat_hp = *data++;
1351 } 1421 }
1352 else if (cmd == 6) // monster width 1422 else if (cmd == 6) // monster width
1353 cell->stat_width = *data++ + 1; 1423 cell->stat_width = *data++ + 1;
1354 else if (cmd == 0x47) // monster width 1424 else if (cmd == 0x47)
1355 { 1425 {
1356 if (*data == 4) 1426 if (*data == 8)
1357 ; // decode player tag 1427 ; // decode player uuid
1358 1428
1359 data += *data + 1; 1429 data += *data + 1;
1360 } 1430 }
1361 else if (cmd == 8) // cell flags 1431 else if (cmd == 8) // cell flags
1362 cell->flags = *data++; 1432 cell->flags = *data++;
1371 cell->darkness = *data++ + 1; 1441 cell->darkness = *data++ + 1;
1372 } 1442 }
1373 1443
1374 if (flags & 4) 1444 if (flags & 4)
1375 { 1445 {
1376 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];
1377 } 1449 }
1378 1450
1379 if (flags & 2) 1451 if (flags & 2)
1380 { 1452 {
1381 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];
1382 } 1456 }
1383 1457
1384 if (flags & 1) 1458 if (flags & 1)
1385 { 1459 {
1386 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];
1387 } 1463 }
1388 } 1464 }
1389 else 1465 else
1390 cell->darkness = 0; 1466 cell->darkness = 0;
1391 } 1467 }
1421 { 1497 {
1422 mapcell *cell = row->col + (x - row->c0); 1498 mapcell *cell = row->col + (x - row->c0);
1423 1499
1424 for (z = 0; z <= 0; z++) 1500 for (z = 0; z <= 0; z++)
1425 { 1501 {
1426 mapface face = cell->face [z];
1427
1428 if (face)
1429 {
1430 maptex tex = self->tex [face]; 1502 maptex tex = self->tex [cell->tile [z]];
1431 int a0 = 255 - tex.a; 1503 int a0 = 255 - tex.a;
1432 int a1 = tex.a; 1504 int a1 = tex.a;
1433 1505
1434 r = (r * a0 + tex.r * a1) / 255; 1506 r = (r * a0 + tex.r * a1) / 255;
1435 g = (g * a0 + tex.g * a1) / 255; 1507 g = (g * a0 + tex.g * a1) / 255;
1436 b = (b * a0 + tex.b * a1) / 255; 1508 b = (b * a0 + tex.b * a1) / 255;
1437 a = (a * a0 + tex.a * a1) / 255; 1509 a = (a * a0 + tex.a * a1) / 255;
1438 }
1439 } 1510 }
1440 } 1511 }
1441 1512
1442 *map++ = (r ) 1513 *map++ = (r )
1443 | (g << 8) 1514 | (g << 8)
1450} 1521}
1451 OUTPUT: 1522 OUTPUT:
1452 RETVAL 1523 RETVAL
1453 1524
1454void 1525void
1455draw (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)
1456 CODE: 1527 CODE:
1457{ 1528{
1458 int x, y, z; 1529 int x, y, z;
1459 int last_name; 1530 int last_name;
1460 mapface face;
1461 1531
1462 glColor4ub (255, 255, 255, 255); 1532 glColor4ub (255, 255, 255, 255);
1463 1533
1464 glEnable (GL_BLEND); 1534 glEnable (GL_BLEND);
1465 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 1535 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1481 1551
1482 for (x = 0; x < sw; x++) 1552 for (x = 0; x < sw; x++)
1483 if (row->c0 <= x + mx && x + mx < row->c1) 1553 if (row->c0 <= x + mx && x + mx < row->c1)
1484 { 1554 {
1485 mapcell *cell = row->col + (x + mx - row->c0); 1555 mapcell *cell = row->col + (x + mx - row->c0);
1486
1487 face = cell->face [z]; 1556 tileid tile = cell->tile [z];
1488 1557
1489 if (face && face < self->texs) 1558 if (tile)
1490 { 1559 {
1491 maptex tex = self->tex [face]; 1560 maptex tex = self->tex [tile];
1492 int px = (x + 1) * 32 - tex.w; 1561 int px = (x + 1) * T - tex.w;
1493 int py = (y + 1) * 32 - tex.h; 1562 int py = (y + 1) * T - tex.h;
1494 1563
1495 if (last_name != tex.name) 1564 if (last_name != tex.name)
1496 { 1565 {
1566 if (!tex.name)
1567 tex = self->tex [2]; /* missing, replace by noface */
1568
1497 glEnd (); 1569 glEnd ();
1498 glBindTexture (GL_TEXTURE_2D, last_name = tex.name); 1570 glBindTexture (GL_TEXTURE_2D, last_name = tex.name);
1499 glBegin (GL_QUADS); 1571 glBegin (GL_QUADS);
1500 } 1572 }
1501 1573
1502 glTexCoord2f (0 , 0 ); glVertex2f (px , py ); 1574 glTexCoord2f (0 , 0 ); glVertex2f (px , py );
1503 glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); 1575 glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h);
1504 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);
1505 glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); 1577 glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py );
1506 }
1507 1578
1508 if (cell->flags && z == 2) 1579 if (cell->flags && z == 2)
1509 {
1510 if (cell->flags & 1)
1511 { 1580 {
1581 if (cell->flags & 1)
1582 {
1512 maptex tex = self->tex [1]; 1583 maptex tex = self->tex [1];
1513 int px = (x + 1) * 32 - tex.w + 2; 1584 int px = x * T + T * 2 / 32;
1514 int py = (y + 1) * 32 - tex.h - 6; 1585 int py = y * T - T * 6 / 32;
1515 1586
1516 glEnd (); 1587 glEnd ();
1517 glBindTexture (GL_TEXTURE_2D, last_name = tex.name); 1588 glBindTexture (GL_TEXTURE_2D, last_name = tex.name);
1518 glBegin (GL_QUADS); 1589 glBegin (GL_QUADS);
1519 1590
1520 glTexCoord2f (0 , 0 ); glVertex2f (px , py ); 1591 glTexCoord2f (0 , 0 ); glVertex2f (px , py );
1521 glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); 1592 glTexCoord2f (0 , tex.t); glVertex2f (px , py + T);
1522 glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h); 1593 glTexCoord2f (tex.s, tex.t); glVertex2f (px + T, py + T);
1523 glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); 1594 glTexCoord2f (tex.s, 0 ); glVertex2f (px + T, py );
1595 }
1524 } 1596 }
1525 } 1597 }
1526 } 1598 }
1527 } 1599 }
1528 1600
1540 for (x = 0; x < sw; x++) 1612 for (x = 0; x < sw; x++)
1541 if (row->c0 <= x + mx && x + mx < row->c1) 1613 if (row->c0 <= x + mx && x + mx < row->c1)
1542 { 1614 {
1543 mapcell *cell = row->col + (x + mx - row->c0); 1615 mapcell *cell = row->col + (x + mx - row->c0);
1544 1616
1545 int px = x * 32; 1617 int px = x * T;
1546 int py = y * 32; 1618 int py = y * T;
1547 1619
1548 if (cell->stat_hp) 1620 if (cell->stat_hp)
1549 { 1621 {
1550 int width = cell->stat_width * 32; 1622 int width = cell->stat_width * T;
1551 int thick = sh / 28 + 1 + cell->stat_width; 1623 int thick = (sh * T / 32 + 27) / 28 + 1 + cell->stat_width;
1552 1624
1553 glColor3ub (0, 0, 0); 1625 glColor3ub (0, 0, 0);
1554 glRectf (px + 1, py - thick - 2, 1626 glRectf (px + 1, py - thick - 2,
1555 px + width - 1, py); 1627 px + width - 1, py);
1556 1628
1695 if (row && row->c0 <= x && x < row->c1) 1767 if (row && row->c0 <= x && x < row->c1)
1696 { 1768 {
1697 mapcell *cell = row->col + (x - row->c0); 1769 mapcell *cell = row->col + (x - row->c0);
1698 uint8_t flags = 0; 1770 uint8_t flags = 0;
1699 1771
1700 if (cell->face [0]) flags |= 1; 1772 if (cell->tile [0]) flags |= 1;
1701 if (cell->face [1]) flags |= 2; 1773 if (cell->tile [1]) flags |= 2;
1702 if (cell->face [2]) flags |= 4; 1774 if (cell->tile [2]) flags |= 4;
1703 1775
1704 *data++ = flags; 1776 *data++ = flags;
1705 1777
1706 if (flags & 1) 1778 if (flags & 1)
1707 { 1779 {
1780 tileid tile = cell->tile [0];
1708 *data++ = cell->face [0] >> 8; 1781 *data++ = tile >> 8;
1709 *data++ = cell->face [0]; 1782 *data++ = tile;
1710 } 1783 }
1711 1784
1712 if (flags & 2) 1785 if (flags & 2)
1713 { 1786 {
1787 tileid tile = cell->tile [1];
1714 *data++ = cell->face [1] >> 8; 1788 *data++ = tile >> 8;
1715 *data++ = cell->face [1]; 1789 *data++ = tile;
1716 } 1790 }
1717 1791
1718 if (flags & 4) 1792 if (flags & 4)
1719 { 1793 {
1794 tileid tile = cell->tile [2];
1720 *data++ = cell->face [2] >> 8; 1795 *data++ = tile >> 8;
1721 *data++ = cell->face [2]; 1796 *data++ = tile;
1722 } 1797 }
1723 } 1798 }
1724 else 1799 else
1725 *data++ = 0; 1800 *data++ = 0;
1726 } 1801 }
1766 { 1841 {
1767 uint8_t flags = *data++; 1842 uint8_t flags = *data++;
1768 1843
1769 if (flags) 1844 if (flags)
1770 { 1845 {
1771 mapface face[3] = { 0, 0, 0 };
1772
1773 mapcell *cell = row_get_cell (row, x); 1846 mapcell *cell = row_get_cell (row, x);
1847 tileid tile[3] = { 0, 0, 0 };
1774 1848
1775 if (flags & 1) { face[0] = *data++ << 8; face[0] |= *data++; } 1849 if (flags & 1) { tile[0] = *data++ << 8; tile[0] |= *data++; }
1776 if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; } 1850 if (flags & 2) { tile[1] = *data++ << 8; tile[1] |= *data++; }
1777 if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; } 1851 if (flags & 4) { tile[2] = *data++ << 8; tile[2] |= *data++; }
1778 1852
1779 if (cell->darkness == 0) 1853 if (cell->darkness == 0)
1780 { 1854 {
1781 cell->darkness = 0; 1855 cell->darkness = 0;
1782 1856
1783 for (z = 0; z <= 2; z++) 1857 for (z = 0; z <= 2; z++)
1784 { 1858 {
1785 cell->face[z] = face[z]; 1859 tileid t = tile [z];
1786 1860
1787 if (face[z] && (face[z] >= self->texs || !self->tex[face [z]].name)) 1861 if (t >= self->texs || (t && !self->tex [t].name))
1862 {
1788 XPUSHs (sv_2mortal (newSViv (face[z]))); 1863 XPUSHs (sv_2mortal (newSViv (t)));
1864 need_texid (self, t);
1865 }
1866
1867 cell->tile [z] = t;
1789 } 1868 }
1790 } 1869 }
1791 } 1870 }
1792 } 1871 }
1793 } 1872 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines