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.328 by root, Sun Nov 18 12:47:55 2018 UTC vs.
Revision 1.332 by root, Mon Nov 19 00:56:08 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))
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 82
90#define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, object replacement character */ 83#define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, object replacement character */
91 84
92/* this is used as fow flag as well, so has to have a different value */ 85/* this is used as fow flag as well, so has to have a different value */
93/* then anything that is computed by incoming darkness */ 86/* then anything that is computed by incoming darkness */
111fast_sv_grow (SV *sv, STRLEN need) 104fast_sv_grow (SV *sv, STRLEN need)
112{ 105{
113 STRLEN len = SvLEN (sv); 106 STRLEN len = SvLEN (sv);
114 STRLEN want = SvCUR (sv) + need; 107 STRLEN want = SvCUR (sv) + need;
115 108
116 if (expect_false (len < want)) 109 if (ecb_expect_false (len < want))
117 { 110 {
118 do 111 do
119 len *= 2; 112 len *= 2;
120 while (len < want); 113 while (len < want);
121 114
255 if (!rect.height) rect.height = 1; 248 if (!rect.height) rect.height = 1;
256 249
257 *w = rect.width; 250 *w = rect.width;
258 *h = rect.height; 251 *h = rect.height;
259} 252}
253
254/////////////////////////////////////////////////////////////////////////////
260 255
261typedef uint16_t tileid; 256typedef uint16_t tileid;
262typedef uint16_t faceid; 257typedef uint16_t faceid;
263 258
264struct maptex 259struct maptex
296 maprow *row; 291 maprow *row;
297}; 292};
298 293
299typedef mapgrid *DC__Map; 294typedef mapgrid *DC__Map;
300 295
301static char * 296template<typename T>
297static void
302prepend (char *ptr, int sze, int inc) 298prepend (T *&ptr, int sze, int inc)
303{ 299{
304 char *p; 300 T *p;
305 301
306 New (0, p, sze + inc, char); 302 Newx (p, inc + sze, T);
307 Zero (p, inc, char); 303 Zero (p, inc, T);
308 Move (ptr, p + inc, sze, char); 304 Move (ptr, p + inc, sze, T);
309 Safefree (ptr); 305 Safefree (ptr);
310 306
311 return p; 307 ptr = p;
312} 308}
313 309
314static char * 310template<typename T>
311static void
315append (char *ptr, int sze, int inc) 312append (T *&ptr, int sze, int inc)
316{ 313{
317 Renew (ptr, sze + inc, char); 314 Renew (ptr, sze + inc, T);
318 Zero (ptr + sze, inc, char); 315 Zero (ptr + sze, inc, T);
319
320 return ptr;
321} 316}
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 317
326static void 318static void
327need_facenum (struct mapgrid *self, faceid face) 319need_facenum (struct mapgrid *self, faceid face)
328{ 320{
329 while (self->faces <= face) 321 while (self->faces <= face)
330 { 322 {
331 Append (tileid, self->face2tile, self->faces, self->faces); 323 append (self->face2tile, self->faces, self->faces);
332 self->faces *= 2; 324 self->faces *= 2;
333 } 325 }
334} 326}
335 327
336static void 328static void
337need_texid (struct mapgrid *self, int texid) 329need_texid (struct mapgrid *self, int texid)
338{ 330{
339 while (self->texs <= texid) 331 while (self->texs <= texid)
340 { 332 {
341 Append (maptex, self->tex, self->texs, self->texs); 333 append (self->tex, self->texs, self->texs);
342 self->texs *= 2; 334 self->texs *= 2;
343 } 335 }
344} 336}
345 337
346static maprow * 338static maprow *
347map_get_row (mapgrid *self, int y) 339map_get_row (mapgrid *self, int y)
348{ 340{
349 if (0 > y) 341 if (0 > y)
350 { 342 {
351 int extend = - y + MAP_EXTEND_Y; 343 int extend = - y + MAP_EXTEND_Y;
352 Prepend (maprow, self->row, self->rows, extend); 344 prepend (self->row, self->rows, extend);
353 345
354 self->rows += extend; 346 self->rows += extend;
355 self->y += extend; 347 self->y += extend;
356 y += extend; 348 y += extend;
357 } 349 }
358 else if (y >= self->rows) 350 else if (y >= self->rows)
359 { 351 {
360 int extend = y - self->rows + MAP_EXTEND_Y; 352 int extend = y - self->rows + MAP_EXTEND_Y;
361 Append (maprow, self->row, self->rows, extend); 353 append (self->row, self->rows, extend);
362 self->rows += extend; 354 self->rows += extend;
363 } 355 }
364 356
365 return self->row + y; 357 return self->row + y;
366} 358}
376 } 368 }
377 369
378 if (row->c0 > x) 370 if (row->c0 > x)
379 { 371 {
380 int extend = row->c0 - x + MAP_EXTEND_X; 372 int extend = row->c0 - x + MAP_EXTEND_X;
381 Prepend (mapcell, row->col, row->c1 - row->c0, extend); 373 prepend (row->col, row->c1 - row->c0, extend);
382 row->c0 -= extend; 374 row->c0 -= extend;
383 } 375 }
384 else if (x >= row->c1) 376 else if (x >= row->c1)
385 { 377 {
386 int extend = x - row->c1 + MAP_EXTEND_X; 378 int extend = x - row->c1 + MAP_EXTEND_X;
387 Append (mapcell, row->col, row->c1 - row->c0, extend); 379 append (row->col, row->c1 - row->c0, extend);
388 row->c1 += extend; 380 row->c1 += extend;
389 } 381 }
390 382
391 return row->col + (x - row->c0); 383 return row->col + (x - row->c0);
392} 384}
534 n |= n >> 4; 526 n |= n >> 4;
535 n |= n >> 8; 527 n |= n >> 8;
536 n |= n >> 16; 528 n |= n >> 16;
537 529
538 return n + 1; 530 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} 531}
551 532
552/* SDL should provide this, really. */ 533/* SDL should provide this, really. */
553#define SDLK_MODIFIER_MIN 300 534#define SDLK_MODIFIER_MIN 300
554#define SDLK_MODIFIER_MAX 314 535#define SDLK_MODIFIER_MAX 314
885 866
886NV ceil (NV x) 867NV ceil (NV x)
887 868
888IV minpot (UV n) 869IV minpot (UV n)
889 870
871UV ld32 (UV n)
872 CODE:
873 RETVAL = ecb_ld32 (n);
874 OUTPUT:
875 RETVAL
876
890IV popcount (UV n) 877IV popcount (UV n)
878 CODE:
879 RETVAL = ecb_popcount32 (n);
880 OUTPUT:
881 RETVAL
891 882
892NV distance (NV dx, NV dy) 883NV distance (NV dx, NV dy)
893 CODE: 884 CODE:
894 RETVAL = pow (dx * dx + dy * dy, 0.5); 885 RETVAL = pow (dx * dx + dy * dy, 0.5);
895 OUTPUT: 886 OUTPUT:
2056 self->ox += dx; self->x += dx; 2047 self->ox += dx; self->x += dx;
2057 self->oy += dy; self->y += dy; 2048 self->oy += dy; self->y += dy;
2058 2049
2059 while (self->y < 0) 2050 while (self->y < 0)
2060 { 2051 {
2061 Prepend (maprow, self->row, self->rows, MAP_EXTEND_Y); 2052 prepend (self->row, self->rows, MAP_EXTEND_Y);
2062 2053
2063 self->rows += MAP_EXTEND_Y; 2054 self->rows += MAP_EXTEND_Y;
2064 self->y += MAP_EXTEND_Y; 2055 self->y += MAP_EXTEND_Y;
2065 } 2056 }
2066} 2057}
2310 } 2301 }
2311 2302
2312 px = (x + 1) * Th - tex.w; 2303 px = (x + 1) * Th - tex.w;
2313 py = (y + 1) * Tw - tex.h; 2304 py = (y + 1) * Tw - tex.h;
2314 2305
2315 if (expect_false (cell->player == player) && expect_false (z == 2)) 2306 if (ecb_expect_false (cell->player == player) && ecb_expect_false (z == 2))
2316 { 2307 {
2317 pl_x = px; 2308 pl_x = px;
2318 pl_y = py; 2309 pl_y = py;
2319 pl_tex = tex; 2310 pl_tex = tex;
2320 continue; 2311 continue;
2363 skey.x = x ; skey.y = y ; smooth_or_bits (smooth, skey, 0x0400); 2354 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); 2355 skey.x = x + 2; skey.y = y ; smooth_or_bits (smooth, skey, 0x0800);
2365 } 2356 }
2366 } 2357 }
2367 2358
2368 if (expect_false (z == 2) && expect_false (cell->flags)) 2359 if (ecb_expect_false (z == 2) && ecb_expect_false (cell->flags))
2369 { 2360 {
2370 // overlays such as the speech bubble, probably more to come 2361 // overlays such as the speech bubble, probably more to come
2371 if (cell->flags & 1) 2362 if (cell->flags & 1)
2372 { 2363 {
2373 rc_key_t key_ov = key; 2364 rc_key_t key_ov = key;
2492 mapcell *cell = row->col + (x + mx - row->c0); 2483 mapcell *cell = row->col + (x + mx - row->c0);
2493 2484
2494 int px = x * Tw; 2485 int px = x * Tw;
2495 int py = y * Th; 2486 int py = y * Th;
2496 2487
2497 if (expect_false (cell->player == player)) 2488 if (ecb_expect_false (cell->player == player))
2498 { 2489 {
2499 px += sdx; 2490 px += sdx;
2500 py += sdy; 2491 py += sdy;
2501 } 2492 }
2502 2493

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines