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.326 by root, Sun Nov 18 03:06:13 2018 UTC vs.
Revision 1.334 by root, Mon Nov 19 01:37:28 2018 UTC

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 */
111fast_sv_grow (SV *sv, STRLEN need) 105fast_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
261typedef uint16_t tileid; 257typedef uint16_t tileid;
262typedef uint16_t faceid; 258typedef uint16_t faceid;
263 259
264struct maptex 260struct maptex
296 maprow *row; 292 maprow *row;
297}; 293};
298 294
299typedef mapgrid *DC__Map; 295typedef mapgrid *DC__Map;
300 296
301static char * 297template<typename T>
298static void
302prepend (char *ptr, int sze, int inc) 299prepend (T *&ptr, int sze, int inc)
303{ 300{
304 char *p; 301 T *p;
305 302
306 New (0, p, sze + inc, char); 303 Newx (p, inc + sze, T);
307 Zero (p, inc, char); 304 Zero (p, inc, T);
308 Move (ptr, p + inc, sze, char); 305 Move (ptr, p + inc, sze, T);
309 Safefree (ptr); 306 Safefree (ptr);
310 307
311 return p; 308 ptr = p;
312} 309}
313 310
314static char * 311template<typename T>
312static void
315append (char *ptr, int sze, int inc) 313append (T *&ptr, int sze, int inc)
316{ 314{
317 Renew (ptr, sze + inc, char); 315 Renew (ptr, sze + inc, T);
318 Zero (ptr + sze, inc, char); 316 Zero (ptr + sze, inc, T);
319
320 return ptr;
321} 317}
322
323#define Append(type,ptr,sze,inc) (ptr) = (type *)append ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type))
324#define Prepend(type,ptr,sze,inc) (ptr) = (type *)prepend ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type))
325 318
326static void 319static void
327need_facenum (struct mapgrid *self, faceid face) 320need_facenum (struct mapgrid *self, faceid face)
328{ 321{
329 while (self->faces <= face) 322 while (self->faces <= face)
330 { 323 {
331 Append (tileid, self->face2tile, self->faces, self->faces); 324 append (self->face2tile, self->faces, self->faces);
332 self->faces *= 2; 325 self->faces *= 2;
333 } 326 }
334} 327}
335 328
336static void 329static void
337need_texid (struct mapgrid *self, int texid) 330need_texid (struct mapgrid *self, int texid)
338{ 331{
339 while (self->texs <= texid) 332 while (self->texs <= texid)
340 { 333 {
341 Append (maptex, self->tex, self->texs, self->texs); 334 append (self->tex, self->texs, self->texs);
342 self->texs *= 2; 335 self->texs *= 2;
343 } 336 }
344} 337}
345 338
346static maprow * 339static maprow *
347map_get_row (mapgrid *self, int y) 340map_get_row (mapgrid *self, int y)
348{ 341{
349 if (0 > y) 342 if (0 > y)
350 { 343 {
351 int extend = - y + MAP_EXTEND_Y; 344 int extend = - y + MAP_EXTEND_Y;
352 Prepend (maprow, self->row, self->rows, extend); 345 prepend (self->row, self->rows, extend);
353 346
354 self->rows += extend; 347 self->rows += extend;
355 self->y += extend; 348 self->y += extend;
356 y += extend; 349 y += extend;
357 } 350 }
358 else if (y >= self->rows) 351 else if (y >= self->rows)
359 { 352 {
360 int extend = y - self->rows + MAP_EXTEND_Y; 353 int extend = y - self->rows + MAP_EXTEND_Y;
361 Append (maprow, self->row, self->rows, extend); 354 append (self->row, self->rows, extend);
362 self->rows += extend; 355 self->rows += extend;
363 } 356 }
364 357
365 return self->row + y; 358 return self->row + y;
366} 359}
376 } 369 }
377 370
378 if (row->c0 > x) 371 if (row->c0 > x)
379 { 372 {
380 int extend = row->c0 - x + MAP_EXTEND_X; 373 int extend = row->c0 - x + MAP_EXTEND_X;
381 Prepend (mapcell, row->col, row->c1 - row->c0, extend); 374 prepend (row->col, row->c1 - row->c0, extend);
382 row->c0 -= extend; 375 row->c0 -= extend;
383 } 376 }
384 else if (x >= row->c1) 377 else if (x >= row->c1)
385 { 378 {
386 int extend = x - row->c1 + MAP_EXTEND_X; 379 int extend = x - row->c1 + MAP_EXTEND_X;
387 Append (mapcell, row->col, row->c1 - row->c0, extend); 380 append (row->col, row->c1 - row->c0, extend);
388 row->c1 += extend; 381 row->c1 += extend;
389 } 382 }
390 383
391 return row->col + (x - row->c0); 384 return row->col + (x - row->c0);
392} 385}
462 { 455 {
463 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;
464 } 457 }
465}; 458};
466 459
467typedef ska::flat_hash_map<smooth_key, IV> smooth_hash; 460typedef ska::flat_hash_map<smooth_key, IV, std::hash<smooth_key>, std::equal_to<smooth_key>, slice_allocator<smooth_key>> smooth_hash;
468 461
469namespace std { 462namespace std {
470 template <> 463 template <>
471 struct hash<smooth_key> 464 struct hash<smooth_key>
472 { 465 {
534 n |= n >> 4; 527 n |= n >> 4;
535 n |= n >> 8; 528 n |= n >> 8;
536 n |= n >> 16; 529 n |= n >> 16;
537 530
538 return n + 1; 531 return n + 1;
539}
540
541static unsigned int
542popcount (unsigned int n)
543{
544 n -= (n >> 1) & 0x55555555U;
545 n = ((n >> 2) & 0x33333333U) + (n & 0x33333333U);
546 n = ((n >> 4) + n) & 0x0f0f0f0fU;
547 n *= 0x01010101U;
548
549 return n >> 24;
550} 532}
551 533
552/* SDL should provide this, really. */ 534/* SDL should provide this, really. */
553#define SDLK_MODIFIER_MIN 300 535#define SDLK_MODIFIER_MIN 300
554#define SDLK_MODIFIER_MAX 314 536#define SDLK_MODIFIER_MAX 314
885 867
886NV ceil (NV x) 868NV ceil (NV x)
887 869
888IV minpot (UV n) 870IV minpot (UV n)
889 871
872UV ld32 (UV n)
873 CODE:
874 RETVAL = ecb_ld32 (n);
875 OUTPUT:
876 RETVAL
877
890IV popcount (UV n) 878IV popcount (UV n)
879 CODE:
880 RETVAL = ecb_popcount32 (n);
881 OUTPUT:
882 RETVAL
891 883
892NV distance (NV dx, NV dy) 884NV distance (NV dx, NV dy)
893 CODE: 885 CODE:
894 RETVAL = pow (dx * dx + dy * dy, 0.5); 886 RETVAL = pow (dx * dx + dy * dy, 0.5);
895 OUTPUT: 887 OUTPUT:
2056 self->ox += dx; self->x += dx; 2048 self->ox += dx; self->x += dx;
2057 self->oy += dy; self->y += dy; 2049 self->oy += dy; self->y += dy;
2058 2050
2059 while (self->y < 0) 2051 while (self->y < 0)
2060 { 2052 {
2061 Prepend (maprow, self->row, self->rows, MAP_EXTEND_Y); 2053 prepend (self->row, self->rows, MAP_EXTEND_Y);
2062 2054
2063 self->rows += MAP_EXTEND_Y; 2055 self->rows += MAP_EXTEND_Y;
2064 self->y += MAP_EXTEND_Y; 2056 self->y += MAP_EXTEND_Y;
2065 } 2057 }
2066} 2058}
2310 } 2302 }
2311 2303
2312 px = (x + 1) * Th - tex.w; 2304 px = (x + 1) * Th - tex.w;
2313 py = (y + 1) * Tw - tex.h; 2305 py = (y + 1) * Tw - tex.h;
2314 2306
2315 if (expect_false (cell->player == player) && expect_false (z == 2)) 2307 if (ecb_expect_false (cell->player == player) && ecb_expect_false (z == 2))
2316 { 2308 {
2317 pl_x = px; 2309 pl_x = px;
2318 pl_y = py; 2310 pl_y = py;
2319 pl_tex = tex; 2311 pl_tex = tex;
2320 continue; 2312 continue;
2363 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);
2364 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);
2365 } 2357 }
2366 } 2358 }
2367 2359
2368 if (expect_false (z == 2) && expect_false (cell->flags)) 2360 if (ecb_expect_false (z == 2) && ecb_expect_false (cell->flags))
2369 { 2361 {
2370 // overlays such as the speech bubble, probably more to come 2362 // overlays such as the speech bubble, probably more to come
2371 if (cell->flags & 1) 2363 if (cell->flags & 1)
2372 { 2364 {
2373 rc_key_t key_ov = key; 2365 rc_key_t key_ov = key;
2492 mapcell *cell = row->col + (x + mx - row->c0); 2484 mapcell *cell = row->col + (x + mx - row->c0);
2493 2485
2494 int px = x * Tw; 2486 int px = x * Tw;
2495 int py = y * Th; 2487 int py = y * Th;
2496 2488
2497 if (expect_false (cell->player == player)) 2489 if (ecb_expect_false (cell->player == player))
2498 { 2490 {
2499 px += sdx; 2491 px += sdx;
2500 py += sdy; 2492 py += sdy;
2501 } 2493 }
2502 2494

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines