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 _WIN32_WINNT 0x0500 // 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 | # pragma warning(disable:4244) |
7 | # pragma warning(disable:4244) |
|
|
8 | # pragma warning(disable:4761) |
7 | #endif |
9 | #endif |
8 | |
10 | |
9 | #include "EXTERN.h" |
11 | #include "EXTERN.h" |
10 | #include "perl.h" |
12 | #include "perl.h" |
11 | #include "XSUB.h" |
13 | #include "XSUB.h" |
… | |
… | |
36 | # include <sys/types.h> |
38 | # include <sys/types.h> |
37 | # include <sys/socket.h> |
39 | # include <sys/socket.h> |
38 | # include <netinet/in.h> |
40 | # include <netinet/in.h> |
39 | # include <netinet/tcp.h> |
41 | # include <netinet/tcp.h> |
40 | # include <inttypes.h> |
42 | # include <inttypes.h> |
41 | #else |
|
|
42 | typedef unsigned char uint8_t; |
|
|
43 | typedef unsigned short uint16_t; |
|
|
44 | typedef unsigned int uint32_t; |
|
|
45 | typedef signed char int8_t; |
|
|
46 | typedef signed short int16_t; |
|
|
47 | typedef signed int int32_t; |
|
|
48 | #endif |
43 | #endif |
49 | |
44 | |
50 | #define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, objetc replacement character */ |
45 | #define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, object replacement character */ |
51 | |
46 | |
52 | #define FOW_DARKNESS 32 |
47 | #define FOW_DARKNESS 32 |
53 | |
48 | |
54 | #define MAP_EXTEND_X 32 |
49 | #define MAP_EXTEND_X 32 |
55 | #define MAP_EXTEND_Y 512 |
50 | #define MAP_EXTEND_Y 512 |
… | |
… | |
144 | } |
139 | } |
145 | |
140 | |
146 | static void |
141 | static void |
147 | layout_get_pixel_size (CFPlus__Layout self, int *w, int *h) |
142 | layout_get_pixel_size (CFPlus__Layout self, int *w, int *h) |
148 | { |
143 | { |
|
|
144 | PangoRectangle rect; |
|
|
145 | |
|
|
146 | // get_pixel_* wrongly rounds down |
149 | pango_layout_get_pixel_size (self->pl, w, h); |
147 | pango_layout_get_extents (self->pl, 0, &rect); |
150 | |
148 | |
151 | if (!*w) *w = 1; |
149 | rect.width = (rect.width + PANGO_SCALE - 1) / PANGO_SCALE; |
152 | if (!*h) *h = 1; |
150 | rect.height = (rect.height + PANGO_SCALE - 1) / PANGO_SCALE; |
153 | |
151 | |
154 | *w = (*w + 3) & ~3; |
152 | if (!rect.width) rect.width = 1; |
|
|
153 | if (!rect.height) rect.height = 1; |
|
|
154 | |
|
|
155 | *w = rect.width; |
|
|
156 | *h = rect.height; |
155 | } |
157 | } |
156 | |
158 | |
157 | typedef uint16_t mapface; |
159 | typedef uint16_t mapface; |
158 | |
160 | |
159 | typedef struct { |
161 | typedef struct { |
… | |
… | |
162 | float s, t; |
164 | float s, t; |
163 | uint8_t r, g, b, a; |
165 | uint8_t r, g, b, a; |
164 | } maptex; |
166 | } maptex; |
165 | |
167 | |
166 | typedef struct { |
168 | typedef struct { |
167 | int16_t darkness; |
169 | uint32_t player; |
168 | mapface face[3]; |
170 | mapface face[3]; |
|
|
171 | uint16_t darkness; |
|
|
172 | uint8_t stat_width, stat_hp, flags; |
169 | } mapcell; |
173 | } mapcell; |
170 | |
174 | |
171 | typedef struct { |
175 | typedef struct { |
172 | int32_t c0, c1; |
176 | int32_t c0, c1; |
173 | mapcell *col; |
177 | mapcell *col; |
… | |
… | |
286 | static void |
290 | static void |
287 | map_blank (CFPlus__Map self, int x0, int y0, int w, int h) |
291 | map_blank (CFPlus__Map self, int x0, int y0, int w, int h) |
288 | { |
292 | { |
289 | int x, y; |
293 | int x, y; |
290 | maprow *row; |
294 | maprow *row; |
|
|
295 | mapcell *cell; |
291 | |
296 | |
292 | for (y = y0; y < y0 + h; y++) |
297 | for (y = y0; y < y0 + h; y++) |
293 | if (y >= 0) |
298 | if (y >= 0) |
294 | { |
299 | { |
295 | if (y >= self->rows) |
300 | if (y >= self->rows) |
… | |
… | |
301 | if (x >= row->c0) |
306 | if (x >= row->c0) |
302 | { |
307 | { |
303 | if (x >= row->c1) |
308 | if (x >= row->c1) |
304 | break; |
309 | break; |
305 | |
310 | |
306 | row->col[x - row->c0].darkness = -1; |
311 | cell = row->col + x - row->c0; |
|
|
312 | |
|
|
313 | cell->darkness = 0; |
|
|
314 | cell->stat_hp = 0; |
|
|
315 | cell->flags = 0; |
|
|
316 | cell->player = 0; |
307 | } |
317 | } |
308 | } |
318 | } |
309 | } |
319 | } |
310 | |
320 | |
311 | static void |
321 | static void |
… | |
… | |
512 | SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0); |
522 | SDL_GL_SetAttribute (SDL_GL_ACCUM_GREEN_SIZE, 0); |
513 | SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE, 0); |
523 | SDL_GL_SetAttribute (SDL_GL_ACCUM_BLUE_SIZE, 0); |
514 | SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0); |
524 | SDL_GL_SetAttribute (SDL_GL_ACCUM_ALPHA_SIZE, 0); |
515 | |
525 | |
516 | SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); |
526 | SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1); |
|
|
527 | #if SDL_VERSION_ATLEAST(1,2,10) |
517 | SDL_GL_SetAttribute (SDL_GL_ACCELERATED_VISUAL, 1); |
528 | SDL_GL_SetAttribute (SDL_GL_ACCELERATED_VISUAL, 1); |
518 | SDL_GL_SetAttribute (SDL_GL_SWAP_CONTROL, 1); |
529 | SDL_GL_SetAttribute (SDL_GL_SWAP_CONTROL, 1); |
|
|
530 | #endif |
519 | |
531 | |
520 | SDL_EnableUNICODE (1); |
532 | SDL_EnableUNICODE (1); |
521 | SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); |
533 | SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); |
522 | |
534 | |
523 | m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL); |
535 | m = SDL_ListModes (0, SDL_FULLSCREEN | SDL_OPENGL); |
… | |
… | |
632 | lowdelay (int fd, int val = 1) |
644 | lowdelay (int fd, int val = 1) |
633 | CODE: |
645 | CODE: |
634 | #ifndef _WIN32 |
646 | #ifndef _WIN32 |
635 | setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val)); |
647 | setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val)); |
636 | #endif |
648 | #endif |
|
|
649 | |
|
|
650 | void |
|
|
651 | win32_proxy_info () |
|
|
652 | PPCODE: |
|
|
653 | { |
|
|
654 | #ifdef _WIN32 |
|
|
655 | char buffer[2048]; |
|
|
656 | DWORD buflen; |
|
|
657 | |
|
|
658 | EXTEND (SP, 3); |
|
|
659 | |
|
|
660 | buflen = sizeof (buffer); |
|
|
661 | if (InternetQueryOption (0, INTERNET_OPTION_PROXY, (void *)buffer, &buflen)) |
|
|
662 | if (((INTERNET_PROXY_INFO *)buffer)->dwAccessType == INTERNET_OPEN_TYPE_PROXY) |
|
|
663 | { |
|
|
664 | PUSHs (newSVpv (((INTERNET_PROXY_INFO *)buffer)->lpszProxy, 0)); |
|
|
665 | |
|
|
666 | buflen = sizeof (buffer); |
|
|
667 | if (InternetQueryOption (0, INTERNET_OPTION_PROXY_USERNAME, (void *)buffer, &buflen)) |
|
|
668 | { |
|
|
669 | PUSHs (newSVpv (buffer, 0)); |
|
|
670 | |
|
|
671 | buflen = sizeof (buffer); |
|
|
672 | if (InternetQueryOption (0, INTERNET_OPTION_PROXY_PASSWORD, (void *)buffer, &buflen)) |
|
|
673 | PUSHs (newSVpv (buffer, 0)); |
|
|
674 | } |
|
|
675 | } |
|
|
676 | #endif |
|
|
677 | } |
637 | |
678 | |
638 | void |
679 | void |
639 | add_font (char *file) |
680 | add_font (char *file) |
640 | CODE: |
681 | CODE: |
641 | FcConfigAppFontAddFile (0, (const FcChar8 *)file); |
682 | FcConfigAppFontAddFile (0, (const FcChar8 *)file); |
… | |
… | |
745 | MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR); |
786 | MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR); |
746 | #endif |
787 | #endif |
747 | _exit (1); |
788 | _exit (1); |
748 | |
789 | |
749 | void |
790 | void |
750 | _exit (int retval) |
791 | _exit (int retval = 0) |
751 | CODE: |
792 | CODE: |
|
|
793 | #ifdef WIN32 |
|
|
794 | ExitThread (retval); // unclean, please beam me up |
|
|
795 | #else |
752 | _exit (retval); |
796 | _exit (retval); |
|
|
797 | #endif |
753 | |
798 | |
754 | MODULE = CFPlus PACKAGE = CFPlus::Font |
799 | MODULE = CFPlus PACKAGE = CFPlus::Font |
755 | |
800 | |
756 | CFPlus::Font |
801 | CFPlus::Font |
757 | new_from_file (SV *class, char *path, int id = 0) |
802 | new_from_file (SV *class, char *path, int id = 0) |
… | |
… | |
1023 | PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); |
1068 | PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); |
1024 | PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); |
1069 | PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); |
1025 | } |
1070 | } |
1026 | |
1071 | |
1027 | void |
1072 | void |
1028 | render (CFPlus::Layout self, float x, float y) |
1073 | render (CFPlus::Layout self, float x, float y, int flags = 0) |
1029 | PPCODE: |
1074 | PPCODE: |
1030 | pango_opengl_render_layout_subpixel ( |
1075 | pango_opengl_render_layout_subpixel ( |
1031 | self->pl, |
1076 | self->pl, |
1032 | x * PANGO_SCALE, y * PANGO_SCALE, |
1077 | x * PANGO_SCALE, y * PANGO_SCALE, |
1033 | self->r, self->g, self->b, self->a |
1078 | self->r, self->g, self->b, self->a, |
|
|
1079 | flags |
1034 | ); |
1080 | ); |
1035 | |
1081 | |
1036 | MODULE = CFPlus PACKAGE = CFPlus::Texture |
1082 | MODULE = CFPlus PACKAGE = CFPlus::Texture |
1037 | |
1083 | |
1038 | void |
1084 | void |
… | |
… | |
1122 | } |
1168 | } |
1123 | |
1169 | |
1124 | MODULE = CFPlus PACKAGE = CFPlus::Map |
1170 | MODULE = CFPlus PACKAGE = CFPlus::Map |
1125 | |
1171 | |
1126 | CFPlus::Map |
1172 | CFPlus::Map |
1127 | new (SV *class, int map_width, int map_height) |
1173 | new (SV *class) |
1128 | CODE: |
1174 | CODE: |
1129 | New (0, RETVAL, 1, struct map); |
1175 | New (0, RETVAL, 1, struct map); |
1130 | RETVAL->x = 0; |
1176 | RETVAL->x = 0; |
1131 | RETVAL->y = 0; |
1177 | RETVAL->y = 0; |
1132 | RETVAL->w = map_width; |
1178 | RETVAL->w = 0; |
1133 | RETVAL->h = map_height; |
1179 | RETVAL->h = 0; |
1134 | RETVAL->ox = 0; |
1180 | RETVAL->ox = 0; |
1135 | RETVAL->oy = 0; |
1181 | RETVAL->oy = 0; |
1136 | RETVAL->faces = 8192; |
1182 | RETVAL->faces = 8192; |
1137 | Newz (0, RETVAL->face, RETVAL->faces, mapface); |
1183 | Newz (0, RETVAL->face, RETVAL->faces, mapface); |
1138 | RETVAL->texs = 8192; |
1184 | RETVAL->texs = 8192; |
… | |
… | |
1149 | map_clear (self); |
1195 | map_clear (self); |
1150 | Safefree (self->face); |
1196 | Safefree (self->face); |
1151 | Safefree (self->tex); |
1197 | Safefree (self->tex); |
1152 | Safefree (self); |
1198 | Safefree (self); |
1153 | } |
1199 | } |
|
|
1200 | |
|
|
1201 | void |
|
|
1202 | resize (CFPlus::Map self, int map_width, int map_height) |
|
|
1203 | CODE: |
|
|
1204 | self->w = map_width; |
|
|
1205 | self->h = map_height; |
1154 | |
1206 | |
1155 | void |
1207 | void |
1156 | clear (CFPlus::Map self) |
1208 | clear (CFPlus::Map self) |
1157 | CODE: |
1209 | CODE: |
1158 | map_clear (self); |
1210 | map_clear (self); |
… | |
… | |
1228 | void |
1280 | void |
1229 | scroll (CFPlus::Map self, int dx, int dy) |
1281 | scroll (CFPlus::Map self, int dx, int dy) |
1230 | CODE: |
1282 | CODE: |
1231 | { |
1283 | { |
1232 | if (dx > 0) |
1284 | if (dx > 0) |
1233 | map_blank (self, self->x, self->y, dx - 1, self->h); |
1285 | map_blank (self, self->x, self->y, dx, self->h); |
1234 | else if (dx < 0) |
1286 | else if (dx < 0) |
1235 | map_blank (self, self->x + self->w + dx + 1, self->y, 1 - dx, self->h); |
1287 | map_blank (self, self->x + self->w + dx + 1, self->y, -dx, self->h); |
1236 | |
1288 | |
1237 | if (dy > 0) |
1289 | if (dy > 0) |
1238 | map_blank (self, self->x, self->y, self->w, dy - 1); |
1290 | map_blank (self, self->x, self->y, self->w, dy); |
1239 | else if (dy < 0) |
1291 | else if (dy < 0) |
1240 | map_blank (self, self->x, self->y + self->h + dy + 1, self->w, 1 - dy); |
1292 | map_blank (self, self->x, self->y + self->h + dy + 1, self->w, -dy); |
1241 | |
1293 | |
1242 | self->ox += dx; self->x += dx; |
1294 | self->ox += dx; self->x += dx; |
1243 | self->oy += dy; self->y += dy; |
1295 | self->oy += dy; self->y += dy; |
1244 | |
1296 | |
1245 | while (self->y < 0) |
1297 | while (self->y < 0) |
… | |
… | |
1250 | self->y += MAP_EXTEND_Y; |
1302 | self->y += MAP_EXTEND_Y; |
1251 | } |
1303 | } |
1252 | } |
1304 | } |
1253 | |
1305 | |
1254 | void |
1306 | void |
1255 | map1a_update (CFPlus::Map self, SV *data_) |
1307 | map1a_update (CFPlus::Map self, SV *data_, int extmap) |
1256 | CODE: |
1308 | CODE: |
1257 | { |
1309 | { |
1258 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
1310 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
1259 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
1311 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
1260 | mapcell *cell; |
1312 | mapcell *cell; |
1261 | int x, y, flags; |
1313 | int x, y, flags; |
1262 | |
1314 | |
1263 | while (data < data_end) |
1315 | while (data < data_end - 1) |
1264 | { |
1316 | { |
1265 | flags = (data [0] << 8) + data [1]; data += 2; |
1317 | flags = (data [0] << 8) + data [1]; data += 2; |
1266 | |
1318 | |
1267 | x = self->x + ((flags >> 10) & 63); |
1319 | x = self->x + ((flags >> 10) & 63); |
1268 | y = self->y + ((flags >> 4) & 63); |
1320 | y = self->y + ((flags >> 4) & 63); |
1269 | |
1321 | |
1270 | cell = map_get_cell (self, x, y); |
1322 | cell = map_get_cell (self, x, y); |
1271 | |
1323 | |
1272 | if (flags & 15) |
1324 | if (flags & 15) |
1273 | { |
1325 | { |
1274 | if (cell->darkness < 0) |
1326 | if (!cell->darkness) |
1275 | { |
1327 | { |
|
|
1328 | memset (cell, 0, sizeof (*cell)); |
1276 | cell->darkness = 0; |
1329 | cell->darkness = 256; |
1277 | cell->face [0] = 0; |
|
|
1278 | cell->face [1] = 0; |
|
|
1279 | cell->face [2] = 0; |
|
|
1280 | } |
1330 | } |
1281 | |
1331 | |
1282 | cell->darkness = flags & 8 ? *data++ : 255; |
|
|
1283 | |
|
|
1284 | //TODO: don't trust server data to be in-range(!) |
1332 | //TODO: don't trust server data to be in-range(!) |
|
|
1333 | |
|
|
1334 | if (flags & 8) |
|
|
1335 | { |
|
|
1336 | if (extmap) |
|
|
1337 | { |
|
|
1338 | uint8_t ext, cmd; |
|
|
1339 | |
|
|
1340 | do |
|
|
1341 | { |
|
|
1342 | ext = *data++; |
|
|
1343 | cmd = ext & 0x3f; |
|
|
1344 | |
|
|
1345 | if (cmd < 4) |
|
|
1346 | cell->darkness = 255 - ext * 64 + 1; |
|
|
1347 | else if (cmd == 5) // health |
|
|
1348 | { |
|
|
1349 | cell->stat_width = 1; |
|
|
1350 | cell->stat_hp = *data++; |
|
|
1351 | } |
|
|
1352 | else if (cmd == 6) // monster width |
|
|
1353 | cell->stat_width = *data++ + 1; |
|
|
1354 | else if (cmd == 0x47) // monster width |
|
|
1355 | { |
|
|
1356 | if (*data == 4) |
|
|
1357 | ; // decode player tag |
|
|
1358 | |
|
|
1359 | data += *data + 1; |
|
|
1360 | } |
|
|
1361 | else if (cmd == 8) // cell flags |
|
|
1362 | cell->flags = *data++; |
|
|
1363 | else if (ext & 0x40) // unknown, multibyte => skip |
|
|
1364 | data += *data + 1; |
|
|
1365 | else |
|
|
1366 | data++; |
|
|
1367 | } |
|
|
1368 | while (ext & 0x80); |
|
|
1369 | } |
|
|
1370 | else |
|
|
1371 | cell->darkness = *data++ + 1; |
|
|
1372 | } |
1285 | |
1373 | |
1286 | if (flags & 4) |
1374 | if (flags & 4) |
1287 | { |
1375 | { |
1288 | cell->face [0] = self->face [(data [0] << 8) + data [1]]; data += 2; |
1376 | cell->face [0] = self->face [(data [0] << 8) + data [1]]; data += 2; |
1289 | } |
1377 | } |
… | |
… | |
1297 | { |
1385 | { |
1298 | cell->face [2] = self->face [(data [0] << 8) + data [1]]; data += 2; |
1386 | cell->face [2] = self->face [(data [0] << 8) + data [1]]; data += 2; |
1299 | } |
1387 | } |
1300 | } |
1388 | } |
1301 | else |
1389 | else |
1302 | cell->darkness = -1; |
1390 | cell->darkness = 0; |
1303 | } |
1391 | } |
1304 | } |
1392 | } |
1305 | |
1393 | |
1306 | SV * |
1394 | SV * |
1307 | mapmap (CFPlus::Map self, int x0, int y0, int w, int h) |
1395 | mapmap (CFPlus::Map self, int x0, int y0, int w, int h) |
… | |
… | |
1362 | } |
1450 | } |
1363 | OUTPUT: |
1451 | OUTPUT: |
1364 | RETVAL |
1452 | RETVAL |
1365 | |
1453 | |
1366 | void |
1454 | void |
1367 | draw (CFPlus::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) |
1455 | draw (CFPlus::Map self, int mx, int my, int sw, int sh) |
1368 | CODE: |
1456 | CODE: |
1369 | { |
1457 | { |
1370 | int vx, vy; |
|
|
1371 | int x, y, z; |
1458 | int x, y, z; |
1372 | int last_name; |
1459 | int last_name; |
1373 | mapface face; |
1460 | mapface face; |
1374 | |
|
|
1375 | vx = self->x + self->w / 2 - sw / 2 - shift_x; |
|
|
1376 | vy = self->y + self->h / 2 - sh / 2 - shift_y; |
|
|
1377 | |
|
|
1378 | /* |
|
|
1379 | int vx = self->vx = self->w >= sw |
|
|
1380 | ? self->x + (self->w - sw) / 2 |
|
|
1381 | : MIN (self->x, MAX (self->x + self->w - sw + 1, self->vx)); |
|
|
1382 | |
|
|
1383 | int vy = self->vy = self->h >= sh |
|
|
1384 | ? self->y + (self->h - sh) / 2 |
|
|
1385 | : MIN (self->y, MAX (self->y + self->h - sh + 1, self->vy)); |
|
|
1386 | */ |
|
|
1387 | |
1461 | |
1388 | glColor4ub (255, 255, 255, 255); |
1462 | glColor4ub (255, 255, 255, 255); |
1389 | |
1463 | |
1390 | glEnable (GL_BLEND); |
1464 | glEnable (GL_BLEND); |
1391 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
1465 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
… | |
… | |
1394 | |
1468 | |
1395 | glBegin (GL_QUADS); |
1469 | glBegin (GL_QUADS); |
1396 | |
1470 | |
1397 | last_name = 0; |
1471 | last_name = 0; |
1398 | |
1472 | |
|
|
1473 | mx += self->x; |
|
|
1474 | my += self->y; |
|
|
1475 | |
1399 | for (z = 0; z < 3; z++) |
1476 | for (z = 0; z < 3; z++) |
1400 | for (y = 0; y < sh; y++) |
1477 | for (y = 0; y < sh; y++) |
1401 | if (0 <= y + vy && y + vy < self->rows) |
1478 | if (0 <= y + my && y + my < self->rows) |
1402 | { |
1479 | { |
1403 | maprow *row = self->row + (y + vy); |
1480 | maprow *row = self->row + (y + my); |
1404 | |
1481 | |
1405 | for (x = 0; x < sw; x++) |
1482 | for (x = 0; x < sw; x++) |
1406 | if (row->c0 <= x + vx && x + vx < row->c1) |
1483 | if (row->c0 <= x + mx && x + mx < row->c1) |
1407 | { |
1484 | { |
1408 | mapcell *cell = row->col + (x + vx - row->c0); |
1485 | mapcell *cell = row->col + (x + mx - row->c0); |
1409 | |
1486 | |
1410 | face = cell->face [z]; |
1487 | face = cell->face [z]; |
1411 | |
1488 | |
1412 | if (face) |
1489 | if (face && face < self->texs) |
1413 | { |
1490 | { |
1414 | maptex tex = self->tex [face]; |
1491 | maptex tex = self->tex [face]; |
1415 | |
|
|
1416 | int px = (x + 1) * 32 - tex.w; |
1492 | int px = (x + 1) * 32 - tex.w; |
1417 | int py = (y + 1) * 32 - tex.h; |
1493 | int py = (y + 1) * 32 - tex.h; |
1418 | |
1494 | |
1419 | if (last_name != tex.name) |
1495 | if (last_name != tex.name) |
1420 | { |
1496 | { |
1421 | glEnd (); |
1497 | glEnd (); |
1422 | last_name = tex.name; |
|
|
1423 | glBindTexture (GL_TEXTURE_2D, last_name); |
1498 | glBindTexture (GL_TEXTURE_2D, last_name = tex.name); |
1424 | glBegin (GL_QUADS); |
1499 | glBegin (GL_QUADS); |
1425 | } |
1500 | } |
1426 | |
1501 | |
1427 | glTexCoord2f (0 , 0 ); glVertex2f (px , py ); |
1502 | glTexCoord2f (0 , 0 ); glVertex2f (px , py ); |
1428 | glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); |
1503 | glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); |
1429 | glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h); |
1504 | glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h); |
1430 | glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); |
1505 | glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); |
1431 | } |
1506 | } |
|
|
1507 | |
|
|
1508 | if (cell->flags && z == 2) |
|
|
1509 | { |
|
|
1510 | if (cell->flags & 1) |
|
|
1511 | { |
|
|
1512 | maptex tex = self->tex [1]; |
|
|
1513 | int px = (x + 1) * 32 - tex.w + 2; |
|
|
1514 | int py = (y + 1) * 32 - tex.h - 6; |
|
|
1515 | |
|
|
1516 | glEnd (); |
|
|
1517 | glBindTexture (GL_TEXTURE_2D, last_name = tex.name); |
|
|
1518 | glBegin (GL_QUADS); |
|
|
1519 | |
|
|
1520 | glTexCoord2f (0 , 0 ); glVertex2f (px , py ); |
|
|
1521 | glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); |
|
|
1522 | glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h); |
|
|
1523 | glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); |
|
|
1524 | } |
|
|
1525 | } |
1432 | } |
1526 | } |
1433 | } |
1527 | } |
1434 | |
1528 | |
1435 | glEnd (); |
1529 | glEnd (); |
1436 | |
1530 | |
1437 | glDisable (GL_TEXTURE_2D); |
1531 | glDisable (GL_TEXTURE_2D); |
1438 | glDisable (GL_BLEND); |
1532 | glDisable (GL_BLEND); |
|
|
1533 | |
|
|
1534 | // top layer: overlays such as the health bar |
|
|
1535 | for (y = 0; y < sh; y++) |
|
|
1536 | if (0 <= y + my && y + my < self->rows) |
|
|
1537 | { |
|
|
1538 | maprow *row = self->row + (y + my); |
|
|
1539 | |
|
|
1540 | for (x = 0; x < sw; x++) |
|
|
1541 | if (row->c0 <= x + mx && x + mx < row->c1) |
|
|
1542 | { |
|
|
1543 | mapcell *cell = row->col + (x + mx - row->c0); |
|
|
1544 | |
|
|
1545 | int px = x * 32; |
|
|
1546 | int py = y * 32; |
|
|
1547 | |
|
|
1548 | if (cell->stat_hp) |
|
|
1549 | { |
|
|
1550 | int width = cell->stat_width * 32; |
|
|
1551 | int thick = sh / 28 + 1 + cell->stat_width; |
|
|
1552 | |
|
|
1553 | glColor3ub (0, 0, 0); |
|
|
1554 | glRectf (px + 1, py - thick - 2, |
|
|
1555 | px + width - 1, py); |
|
|
1556 | |
|
|
1557 | glColor3ub (cell->stat_hp, 255 - cell->stat_hp, 0); |
|
|
1558 | glRectf (px + 2, |
|
|
1559 | py - thick - 1, |
|
|
1560 | px + width - 2 - cell->stat_hp * (width - 4) / 255, py - 1); |
|
|
1561 | } |
|
|
1562 | } |
|
|
1563 | } |
1439 | } |
1564 | } |
1440 | |
1565 | |
1441 | void |
1566 | void |
1442 | draw_magicmap (CFPlus::Map self, int dx, int dy, int w, int h, unsigned char *data) |
1567 | draw_magicmap (CFPlus::Map self, int dx, int dy, int w, int h, unsigned char *data) |
1443 | CODE: |
1568 | CODE: |
… | |
… | |
1497 | glDisable (GL_BLEND); |
1622 | glDisable (GL_BLEND); |
1498 | glDisable (GL_TEXTURE_2D); |
1623 | glDisable (GL_TEXTURE_2D); |
1499 | } |
1624 | } |
1500 | |
1625 | |
1501 | void |
1626 | void |
1502 | fow_texture (CFPlus::Map self, int shift_x, int shift_y, int x0, int y0, int sw, int sh) |
1627 | fow_texture (CFPlus::Map self, int mx, int my, int sw, int sh) |
1503 | PPCODE: |
1628 | PPCODE: |
1504 | { |
1629 | { |
1505 | int vx, vy; |
|
|
1506 | int x, y; |
1630 | int x, y; |
1507 | int sw4 = (sw + 3) & ~3; |
1631 | int sw4 = (sw + 3) & ~3; |
1508 | SV *darkness_sv = sv_2mortal (newSV (sw4 * sh)); |
1632 | SV *darkness_sv = sv_2mortal (newSV (sw4 * sh)); |
1509 | uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv); |
1633 | uint8_t *darkness = (uint8_t *)SvPVX (darkness_sv); |
1510 | |
1634 | |
1511 | memset (darkness, 255, sw4 * sh); |
1635 | memset (darkness, 255, sw4 * sh); |
1512 | SvPOK_only (darkness_sv); |
1636 | SvPOK_only (darkness_sv); |
1513 | SvCUR_set (darkness_sv, sw4 * sh); |
1637 | SvCUR_set (darkness_sv, sw4 * sh); |
1514 | |
1638 | |
1515 | vx = self->x + (self->w - sw + 1) / 2 - shift_x; |
1639 | mx += self->x; |
1516 | vy = self->y + (self->h - sh + 1) / 2 - shift_y; |
1640 | my += self->y; |
1517 | |
1641 | |
1518 | for (y = 0; y < sh; y++) |
1642 | for (y = 0; y < sh; y++) |
1519 | if (0 <= y + vy && y + vy < self->rows) |
1643 | if (0 <= y + my && y + my < self->rows) |
1520 | { |
1644 | { |
1521 | maprow *row = self->row + (y + vy); |
1645 | maprow *row = self->row + (y + my); |
1522 | |
1646 | |
1523 | for (x = 0; x < sw; x++) |
1647 | for (x = 0; x < sw; x++) |
1524 | if (row->c0 <= x + vx && x + vx < row->c1) |
1648 | if (row->c0 <= x + mx && x + mx < row->c1) |
1525 | { |
1649 | { |
1526 | mapcell *cell = row->col + (x + vx - row->c0); |
1650 | mapcell *cell = row->col + (x + mx - row->c0); |
1527 | |
1651 | |
1528 | darkness[y * sw4 + x] = cell->darkness < 0 |
1652 | darkness[y * sw4 + x] = cell->darkness |
|
|
1653 | ? 255 - (cell->darkness - 1) |
1529 | ? 255 - FOW_DARKNESS |
1654 | : 255 - FOW_DARKNESS; |
1530 | : 255 - cell->darkness; |
|
|
1531 | } |
1655 | } |
1532 | } |
1656 | } |
1533 | |
1657 | |
1534 | EXTEND (SP, 3); |
1658 | EXTEND (SP, 3); |
1535 | PUSHs (sv_2mortal (newSViv (sw4))); |
1659 | PUSHs (sv_2mortal (newSViv (sw4))); |
… | |
… | |
1650 | |
1774 | |
1651 | if (flags & 1) { face[0] = *data++ << 8; face[0] |= *data++; } |
1775 | if (flags & 1) { face[0] = *data++ << 8; face[0] |= *data++; } |
1652 | if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; } |
1776 | if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; } |
1653 | if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; } |
1777 | if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; } |
1654 | |
1778 | |
1655 | if (cell->darkness <= 0) |
1779 | if (cell->darkness == 0) |
1656 | { |
1780 | { |
1657 | cell->darkness = -1; |
1781 | cell->darkness = 0; |
1658 | |
1782 | |
1659 | for (z = 0; z <= 2; z++) |
1783 | for (z = 0; z <= 2; z++) |
1660 | { |
1784 | { |
1661 | cell->face[z] = face[z]; |
1785 | cell->face[z] = face[z]; |
1662 | |
1786 | |
… | |
… | |
1800 | const_iv (GL_SEPARABLE_2D), |
1924 | const_iv (GL_SEPARABLE_2D), |
1801 | const_iv (GL_CONVOLUTION_2D), |
1925 | const_iv (GL_CONVOLUTION_2D), |
1802 | const_iv (GL_CONVOLUTION_BORDER_MODE), |
1926 | const_iv (GL_CONVOLUTION_BORDER_MODE), |
1803 | const_iv (GL_CONSTANT_BORDER), |
1927 | const_iv (GL_CONSTANT_BORDER), |
1804 | const_iv (GL_LINES), |
1928 | const_iv (GL_LINES), |
|
|
1929 | const_iv (GL_LINE_STRIP), |
1805 | const_iv (GL_LINE_LOOP), |
1930 | const_iv (GL_LINE_LOOP), |
1806 | const_iv (GL_QUADS), |
1931 | const_iv (GL_QUADS), |
1807 | const_iv (GL_QUAD_STRIP), |
1932 | const_iv (GL_QUAD_STRIP), |
1808 | const_iv (GL_TRIANGLES), |
1933 | const_iv (GL_TRIANGLES), |
1809 | const_iv (GL_TRIANGLE_STRIP), |
1934 | const_iv (GL_TRIANGLE_STRIP), |
… | |
… | |
2006 | |
2131 | |
2007 | void glEndList () |
2132 | void glEndList () |
2008 | |
2133 | |
2009 | void glCallList (int list) |
2134 | void glCallList (int list) |
2010 | |
2135 | |
2011 | |
|
|