… | |
… | |
76 | # include <netinet/in.h> |
76 | # include <netinet/in.h> |
77 | # include <netinet/tcp.h> |
77 | # include <netinet/tcp.h> |
78 | # include <inttypes.h> |
78 | # include <inttypes.h> |
79 | #endif |
79 | #endif |
80 | |
80 | |
81 | #if __GNUC__ >= 4 |
81 | #include "ecb.h" |
82 | # define expect(expr,value) __builtin_expect ((expr),(value)) |
82 | #include "salloc.h" |
83 | #else |
|
|
84 | # define expect(expr,value) (expr) |
|
|
85 | #endif |
|
|
86 | |
|
|
87 | #define expect_false(expr) expect ((expr) != 0, 0) |
|
|
88 | #define expect_true(expr) expect ((expr) != 0, 1) |
|
|
89 | |
83 | |
90 | #define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, object replacement character */ |
84 | #define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, object replacement character */ |
91 | |
85 | |
92 | /* this is used as fow flag as well, so has to have a different value */ |
86 | /* this is used as fow flag as well, so has to have a different value */ |
93 | /* then anything that is computed by incoming darkness */ |
87 | /* then anything that is computed by incoming darkness */ |
… | |
… | |
111 | fast_sv_grow (SV *sv, STRLEN need) |
105 | fast_sv_grow (SV *sv, STRLEN need) |
112 | { |
106 | { |
113 | STRLEN len = SvLEN (sv); |
107 | STRLEN len = SvLEN (sv); |
114 | STRLEN want = SvCUR (sv) + need; |
108 | STRLEN want = SvCUR (sv) + need; |
115 | |
109 | |
116 | if (expect_false (len < want)) |
110 | if (ecb_expect_false (len < want)) |
117 | { |
111 | { |
118 | do |
112 | do |
119 | len *= 2; |
113 | len *= 2; |
120 | while (len < want); |
114 | while (len < want); |
121 | |
115 | |
… | |
… | |
255 | if (!rect.height) rect.height = 1; |
249 | if (!rect.height) rect.height = 1; |
256 | |
250 | |
257 | *w = rect.width; |
251 | *w = rect.width; |
258 | *h = rect.height; |
252 | *h = rect.height; |
259 | } |
253 | } |
|
|
254 | |
|
|
255 | ///////////////////////////////////////////////////////////////////////////// |
260 | |
256 | |
261 | typedef uint16_t tileid; |
257 | typedef uint16_t tileid; |
262 | typedef uint16_t faceid; |
258 | typedef uint16_t faceid; |
263 | |
259 | |
264 | struct maptex |
260 | struct maptex |
… | |
… | |
302 | static void |
298 | static void |
303 | prepend (T *&ptr, int sze, int inc) |
299 | prepend (T *&ptr, int sze, int inc) |
304 | { |
300 | { |
305 | T *p; |
301 | T *p; |
306 | |
302 | |
307 | Newxz (p, sze + inc, T); |
303 | Newx (p, inc + sze, T); |
|
|
304 | Zero (p, inc, T); |
308 | Move (ptr, p + inc, sze, T); |
305 | Move (ptr, p + inc, sze, T); |
309 | Safefree (ptr); |
306 | Safefree (ptr); |
310 | |
307 | |
311 | ptr = p; |
308 | ptr = p; |
312 | } |
309 | } |
… | |
… | |
458 | { |
455 | { |
459 | return tile == o.tile && x == o.x && y == o.y && level == o.level; |
456 | return tile == o.tile && x == o.x && y == o.y && level == o.level; |
460 | } |
457 | } |
461 | }; |
458 | }; |
462 | |
459 | |
463 | typedef ska::flat_hash_map<smooth_key, IV> smooth_hash; |
460 | typedef ska::flat_hash_map<smooth_key, IV, std::hash<smooth_key>, std::equal_to<smooth_key>, slice_allocator<smooth_key>> smooth_hash; |
464 | |
461 | |
465 | namespace std { |
462 | namespace std { |
466 | template <> |
463 | template <> |
467 | struct hash<smooth_key> |
464 | struct hash<smooth_key> |
468 | { |
465 | { |
… | |
… | |
530 | n |= n >> 4; |
527 | n |= n >> 4; |
531 | n |= n >> 8; |
528 | n |= n >> 8; |
532 | n |= n >> 16; |
529 | n |= n >> 16; |
533 | |
530 | |
534 | return n + 1; |
531 | return n + 1; |
535 | } |
|
|
536 | |
|
|
537 | static unsigned int |
|
|
538 | popcount (unsigned int n) |
|
|
539 | { |
|
|
540 | n -= (n >> 1) & 0x55555555U; |
|
|
541 | n = ((n >> 2) & 0x33333333U) + (n & 0x33333333U); |
|
|
542 | n = ((n >> 4) + n) & 0x0f0f0f0fU; |
|
|
543 | n *= 0x01010101U; |
|
|
544 | |
|
|
545 | return n >> 24; |
|
|
546 | } |
532 | } |
547 | |
533 | |
548 | /* SDL should provide this, really. */ |
534 | /* SDL should provide this, really. */ |
549 | #define SDLK_MODIFIER_MIN 300 |
535 | #define SDLK_MODIFIER_MIN 300 |
550 | #define SDLK_MODIFIER_MAX 314 |
536 | #define SDLK_MODIFIER_MAX 314 |
… | |
… | |
881 | |
867 | |
882 | NV ceil (NV x) |
868 | NV ceil (NV x) |
883 | |
869 | |
884 | IV minpot (UV n) |
870 | IV minpot (UV n) |
885 | |
871 | |
|
|
872 | UV ld32 (UV n) |
|
|
873 | CODE: |
|
|
874 | RETVAL = ecb_ld32 (n); |
|
|
875 | OUTPUT: |
|
|
876 | RETVAL |
|
|
877 | |
886 | IV popcount (UV n) |
878 | IV popcount (UV n) |
|
|
879 | CODE: |
|
|
880 | RETVAL = ecb_popcount32 (n); |
|
|
881 | OUTPUT: |
|
|
882 | RETVAL |
887 | |
883 | |
888 | NV distance (NV dx, NV dy) |
884 | NV distance (NV dx, NV dy) |
889 | CODE: |
885 | CODE: |
890 | RETVAL = pow (dx * dx + dy * dy, 0.5); |
886 | RETVAL = pow (dx * dx + dy * dy, 0.5); |
891 | OUTPUT: |
887 | OUTPUT: |
… | |
… | |
2306 | } |
2302 | } |
2307 | |
2303 | |
2308 | px = (x + 1) * Th - tex.w; |
2304 | px = (x + 1) * Th - tex.w; |
2309 | py = (y + 1) * Tw - tex.h; |
2305 | py = (y + 1) * Tw - tex.h; |
2310 | |
2306 | |
2311 | if (expect_false (cell->player == player) && expect_false (z == 2)) |
2307 | if (ecb_expect_false (cell->player == player) && ecb_expect_false (z == 2)) |
2312 | { |
2308 | { |
2313 | pl_x = px; |
2309 | pl_x = px; |
2314 | pl_y = py; |
2310 | pl_y = py; |
2315 | pl_tex = tex; |
2311 | pl_tex = tex; |
2316 | continue; |
2312 | continue; |
… | |
… | |
2359 | skey.x = x ; skey.y = y ; smooth_or_bits (smooth, skey, 0x0400); |
2355 | skey.x = x ; skey.y = y ; smooth_or_bits (smooth, skey, 0x0400); |
2360 | skey.x = x + 2; skey.y = y ; smooth_or_bits (smooth, skey, 0x0800); |
2356 | skey.x = x + 2; skey.y = y ; smooth_or_bits (smooth, skey, 0x0800); |
2361 | } |
2357 | } |
2362 | } |
2358 | } |
2363 | |
2359 | |
2364 | if (expect_false (z == 2) && expect_false (cell->flags)) |
2360 | if (ecb_expect_false (z == 2) && ecb_expect_false (cell->flags)) |
2365 | { |
2361 | { |
2366 | // overlays such as the speech bubble, probably more to come |
2362 | // overlays such as the speech bubble, probably more to come |
2367 | if (cell->flags & 1) |
2363 | if (cell->flags & 1) |
2368 | { |
2364 | { |
2369 | rc_key_t key_ov = key; |
2365 | rc_key_t key_ov = key; |
… | |
… | |
2488 | mapcell *cell = row->col + (x + mx - row->c0); |
2484 | mapcell *cell = row->col + (x + mx - row->c0); |
2489 | |
2485 | |
2490 | int px = x * Tw; |
2486 | int px = x * Tw; |
2491 | int py = y * Th; |
2487 | int py = y * Th; |
2492 | |
2488 | |
2493 | if (expect_false (cell->player == player)) |
2489 | if (ecb_expect_false (cell->player == player)) |
2494 | { |
2490 | { |
2495 | px += sdx; |
2491 | px += sdx; |
2496 | py += sdy; |
2492 | py += sdy; |
2497 | } |
2493 | } |
2498 | |
2494 | |