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.323 by root, Sun Nov 18 01:48:39 2018 UTC vs.
Revision 1.335 by root, Mon Nov 19 01:56:11 2018 UTC

32#include <cstring> 32#include <cstring>
33#include <cstdio> 33#include <cstdio>
34#include <cstdlib> 34#include <cstdlib>
35 35
36#include <utility> 36#include <utility>
37#include <bitset>
37 38
38#define USE_RWOPS 1 // for SDL_mixer:LoadMUS_RW 39#define USE_RWOPS 1 // for SDL_mixer:LoadMUS_RW
39 40
40#include <SDL.h> 41#include <SDL.h>
41#include <SDL_thread.h> 42#include <SDL_thread.h>
75# include <netinet/in.h> 76# include <netinet/in.h>
76# include <netinet/tcp.h> 77# include <netinet/tcp.h>
77# include <inttypes.h> 78# include <inttypes.h>
78#endif 79#endif
79 80
80#if __GNUC__ >= 4 81#include "ecb.h"
81# define expect(expr,value) __builtin_expect ((expr),(value)) 82#include "salloc.h"
82#else
83# define expect(expr,value) (expr)
84#endif
85
86#define expect_false(expr) expect ((expr) != 0, 0)
87#define expect_true(expr) expect ((expr) != 0, 1)
88 83
89#define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, object replacement character */ 84#define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, object replacement character */
90 85
91/* 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 */
92/* then anything that is computed by incoming darkness */ 87/* then anything that is computed by incoming darkness */
104#define KMOD_LRAM 0x10000 // our extension 99#define KMOD_LRAM 0x10000 // our extension
105 100
106#define TEXID_SPEECH 1 101#define TEXID_SPEECH 1
107#define TEXID_NOFACE 2 102#define TEXID_NOFACE 2
108 103
104// approximately divide by 255
105static unsigned int
106div255 (unsigned int n)
107{
108 return (n + (n >> 8)) >> 8;
109}
110
111static unsigned int
112minpot (unsigned int n)
113{
114 if (!n)
115 return 0;
116
117 --n;
118
119 n |= n >> 1;
120 n |= n >> 2;
121 n |= n >> 4;
122 n |= n >> 8;
123 n |= n >> 16;
124
125 return n + 1;
126}
127
109static char * 128static char *
110fast_sv_grow (SV *sv, STRLEN need) 129fast_sv_grow (SV *sv, STRLEN need)
111{ 130{
112 STRLEN len = SvLEN (sv); 131 STRLEN len = SvLEN (sv);
113 STRLEN want = SvCUR (sv) + need; 132 STRLEN want = SvCUR (sv) + need;
114 133
115 if (expect_false (len < want)) 134 if (ecb_expect_false (len < want))
116 { 135 {
117 do 136 do
118 len *= 2; 137 len *= 2;
119 while (len < want); 138 while (len < want);
120 139
204struct cf_layout { 223struct cf_layout {
205 PangoLayout *pl; 224 PangoLayout *pl;
206 float r, g, b, a; // default color for rgba mode 225 float r, g, b, a; // default color for rgba mode
207 int base_height; 226 int base_height;
208 DC__Font font; 227 DC__Font font;
209 rc_t *rc; 228 rc_t rc;
210}; 229};
211 230
212typedef cf_layout *DC__Layout; 231typedef cf_layout *DC__Layout;
213 232
214static DC__Font default_font; 233static DC__Font default_font;
254 if (!rect.height) rect.height = 1; 273 if (!rect.height) rect.height = 1;
255 274
256 *w = rect.width; 275 *w = rect.width;
257 *h = rect.height; 276 *h = rect.height;
258} 277}
278
279/////////////////////////////////////////////////////////////////////////////
259 280
260typedef uint16_t tileid; 281typedef uint16_t tileid;
261typedef uint16_t faceid; 282typedef uint16_t faceid;
262 283
263struct maptex 284struct maptex
295 maprow *row; 316 maprow *row;
296}; 317};
297 318
298typedef mapgrid *DC__Map; 319typedef mapgrid *DC__Map;
299 320
300static char * 321template<typename T>
322ecb_cold static void
301prepend (char *ptr, int sze, int inc) 323prepend (T *&ptr, int sze, int inc)
302{ 324{
303 char *p; 325 T *p;
304 326
305 New (0, p, sze + inc, char); 327 Newx (p, inc + sze, T);
306 Zero (p, inc, char); 328 Zero (p, inc, T);
307 Move (ptr, p + inc, sze, char); 329 Move (ptr, p + inc, sze, T);
308 Safefree (ptr); 330 Safefree (ptr);
309 331
310 return p; 332 ptr = p;
311} 333}
312 334
313static char * 335template<typename T>
336ecb_cold static void
314append (char *ptr, int sze, int inc) 337append (T *&ptr, int sze, int inc)
315{ 338{
316 Renew (ptr, sze + inc, char); 339 Renew (ptr, sze + inc, T);
317 Zero (ptr + sze, inc, char); 340 Zero (ptr + sze, inc, T);
318
319 return ptr;
320} 341}
321
322#define Append(type,ptr,sze,inc) (ptr) = (type *)append ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type))
323#define Prepend(type,ptr,sze,inc) (ptr) = (type *)prepend ((char *)ptr, (sze) * sizeof (type), (inc) * sizeof (type))
324 342
325static void 343static void
326need_facenum (struct mapgrid *self, faceid face) 344need_facenum (struct mapgrid *self, faceid face)
327{ 345{
328 while (self->faces <= face) 346 if (ecb_expect_true (self->faces > face))
329 { 347 return;
348
349 size_t newsize = minpot (face + 1);
330 Append (tileid, self->face2tile, self->faces, self->faces); 350 append (self->face2tile, self->faces, newsize - self->faces);
331 self->faces *= 2; 351 self->faces = newsize;
332 }
333} 352}
334 353
335static void 354static void
336need_texid (struct mapgrid *self, int texid) 355need_texid (struct mapgrid *self, int texid)
337{ 356{
338 while (self->texs <= texid) 357 if (ecb_expect_true (self->texs > texid))
339 { 358 return;
359
360 size_t newsize = minpot (texid + 1);
340 Append (maptex, self->tex, self->texs, self->texs); 361 append (self->tex, self->texs, newsize - self->texs);
341 self->texs *= 2; 362 self->texs = newsize;
342 }
343} 363}
344 364
345static maprow * 365static maprow *
346map_get_row (mapgrid *self, int y) 366map_get_row (mapgrid *self, int y)
347{ 367{
348 if (0 > y) 368 if (0 > y)
349 { 369 {
350 int extend = - y + MAP_EXTEND_Y; 370 int extend = - y + MAP_EXTEND_Y;
351 Prepend (maprow, self->row, self->rows, extend); 371 prepend (self->row, self->rows, extend);
352 372
353 self->rows += extend; 373 self->rows += extend;
354 self->y += extend; 374 self->y += extend;
355 y += extend; 375 y += extend;
356 } 376 }
357 else if (y >= self->rows) 377 else if (y >= self->rows)
358 { 378 {
359 int extend = y - self->rows + MAP_EXTEND_Y; 379 int extend = y - self->rows + MAP_EXTEND_Y;
360 Append (maprow, self->row, self->rows, extend); 380 append (self->row, self->rows, extend);
361 self->rows += extend; 381 self->rows += extend;
362 } 382 }
363 383
364 return self->row + y; 384 return self->row + y;
365} 385}
375 } 395 }
376 396
377 if (row->c0 > x) 397 if (row->c0 > x)
378 { 398 {
379 int extend = row->c0 - x + MAP_EXTEND_X; 399 int extend = row->c0 - x + MAP_EXTEND_X;
380 Prepend (mapcell, row->col, row->c1 - row->c0, extend); 400 prepend (row->col, row->c1 - row->c0, extend);
381 row->c0 -= extend; 401 row->c0 -= extend;
382 } 402 }
383 else if (x >= row->c1) 403 else if (x >= row->c1)
384 { 404 {
385 int extend = x - row->c1 + MAP_EXTEND_X; 405 int extend = x - row->c1 + MAP_EXTEND_X;
386 Append (mapcell, row->col, row->c1 - row->c0, extend); 406 append (row->col, row->c1 - row->c0, extend);
387 row->c1 += extend; 407 row->c1 += extend;
388 } 408 }
389 409
390 return row->col + (x - row->c0); 410 return row->col + (x - row->c0);
391} 411}
461 { 481 {
462 return tile == o.tile && x == o.x && y == o.y && level == o.level; 482 return tile == o.tile && x == o.x && y == o.y && level == o.level;
463 } 483 }
464}; 484};
465 485
466typedef ska::flat_hash_map<smooth_key, IV> smooth_hash; 486typedef ska::flat_hash_map<smooth_key, IV, std::hash<smooth_key>, std::equal_to<smooth_key>, slice_allocator<smooth_key>> smooth_hash;
467 487
468namespace std { 488namespace std {
469 template <> 489 template <>
470 struct hash<smooth_key> 490 struct hash<smooth_key>
471 { 491 {
509 ev.code = 1; 529 ev.code = 1;
510 ev.data1 = (void *)(long)channel; 530 ev.data1 = (void *)(long)channel;
511 ev.data2 = 0; 531 ev.data2 = 0;
512 532
513 SDL_PushEvent ((SDL_Event *)&ev); 533 SDL_PushEvent ((SDL_Event *)&ev);
514}
515
516// approximately divide by 255
517static unsigned int
518div255 (unsigned int n)
519{
520 return (n + (n >> 8)) >> 8;
521}
522
523static unsigned int
524minpot (unsigned int n)
525{
526 if (!n)
527 return 0;
528
529 --n;
530
531 n |= n >> 1;
532 n |= n >> 2;
533 n |= n >> 4;
534 n |= n >> 8;
535 n |= n >> 16;
536
537 return n + 1;
538}
539
540static unsigned int
541popcount (unsigned int n)
542{
543 n -= (n >> 1) & 0x55555555U;
544 n = ((n >> 2) & 0x33333333U) + (n & 0x33333333U);
545 n = ((n >> 4) + n) & 0x0f0f0f0fU;
546 n *= 0x01010101U;
547
548 return n >> 24;
549} 534}
550 535
551/* SDL should provide this, really. */ 536/* SDL should provide this, really. */
552#define SDLK_MODIFIER_MIN 300 537#define SDLK_MODIFIER_MIN 300
553#define SDLK_MODIFIER_MAX 314 538#define SDLK_MODIFIER_MAX 314
884 869
885NV ceil (NV x) 870NV ceil (NV x)
886 871
887IV minpot (UV n) 872IV minpot (UV n)
888 873
874UV ld32 (UV n)
875 CODE:
876 RETVAL = ecb_ld32 (n);
877 OUTPUT:
878 RETVAL
879
889IV popcount (UV n) 880IV popcount (UV n)
881 CODE:
882 RETVAL = ecb_popcount32 (n);
883 OUTPUT:
884 RETVAL
890 885
891NV distance (NV dx, NV dy) 886NV distance (NV dx, NV dy)
892 CODE: 887 CODE:
893 RETVAL = pow (dx * dx + dy * dy, 0.5); 888 RETVAL = pow (dx * dx + dy * dy, 0.5);
894 OUTPUT: 889 OUTPUT:
1368 tc_restore (); 1363 tc_restore ();
1369 1364
1370DC::Layout 1365DC::Layout
1371new (SV *klass) 1366new (SV *klass)
1372 CODE: 1367 CODE:
1373 New (0, RETVAL, 1, struct cf_layout); 1368 RETVAL = new cf_layout;
1374 1369
1375 RETVAL->pl = pango_layout_new (opengl_context); 1370 RETVAL->pl = pango_layout_new (opengl_context);
1376 RETVAL->r = 1.; 1371 RETVAL->r = 1.;
1377 RETVAL->g = 1.; 1372 RETVAL->g = 1.;
1378 RETVAL->b = 1.; 1373 RETVAL->b = 1.;
1379 RETVAL->a = 1.; 1374 RETVAL->a = 1.;
1380 RETVAL->base_height = MIN_FONT_HEIGHT; 1375 RETVAL->base_height = MIN_FONT_HEIGHT;
1381 RETVAL->font = 0; 1376 RETVAL->font = 0;
1382 RETVAL->rc = rc_alloc ();
1383 1377
1384 pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR); 1378 pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR);
1385 layout_update_font (RETVAL); 1379 layout_update_font (RETVAL);
1386 OUTPUT: 1380 OUTPUT:
1387 RETVAL 1381 RETVAL
1388 1382
1389void 1383void
1390DESTROY (DC::Layout self) 1384DESTROY (DC::Layout self)
1391 CODE: 1385 CODE:
1392 g_object_unref (self->pl); 1386 g_object_unref (self->pl);
1393 rc_free (self->rc);
1394 Safefree (self); 1387 delete self;
1395 1388
1396void 1389void
1397set_text (DC::Layout self, SV *text_) 1390set_text (DC::Layout self, SV *text_)
1398 CODE: 1391 CODE:
1399{ 1392{
1653} 1646}
1654 1647
1655void 1648void
1656render (DC::Layout self, float x, float y, int flags = 0) 1649render (DC::Layout self, float x, float y, int flags = 0)
1657 CODE: 1650 CODE:
1658 rc_clear (self->rc); 1651 self->rc.clear ();
1659 pango_opengl_render_layout_subpixel ( 1652 pango_opengl_render_layout_subpixel (
1660 self->pl, 1653 self->pl,
1661 self->rc, 1654 &self->rc,
1662 x * PANGO_SCALE, y * PANGO_SCALE, 1655 x * PANGO_SCALE, y * PANGO_SCALE,
1663 self->r, self->g, self->b, self->a, 1656 self->r, self->g, self->b, self->a,
1664 flags 1657 flags
1665 ); 1658 );
1666 // we assume that context_change actually clears/frees stuff 1659 // we assume that context_change actually clears/frees stuff
1677 gl_BlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, 1670 gl_BlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,
1678 GL_ONE , GL_ONE_MINUS_SRC_ALPHA); 1671 GL_ONE , GL_ONE_MINUS_SRC_ALPHA);
1679 glEnable (GL_ALPHA_TEST); 1672 glEnable (GL_ALPHA_TEST);
1680 glAlphaFunc (GL_GREATER, 7.f / 255.f); 1673 glAlphaFunc (GL_GREATER, 7.f / 255.f);
1681 1674
1682 rc_draw (self->rc); 1675 self->rc.draw ();
1683 1676
1684 glDisable (GL_ALPHA_TEST); 1677 glDisable (GL_ALPHA_TEST);
1685 glDisable (GL_BLEND); 1678 glDisable (GL_BLEND);
1686 glDisable (GL_TEXTURE_2D); 1679 glDisable (GL_TEXTURE_2D);
1687} 1680}
2057 self->ox += dx; self->x += dx; 2050 self->ox += dx; self->x += dx;
2058 self->oy += dy; self->y += dy; 2051 self->oy += dy; self->y += dy;
2059 2052
2060 while (self->y < 0) 2053 while (self->y < 0)
2061 { 2054 {
2062 Prepend (maprow, self->row, self->rows, MAP_EXTEND_Y); 2055 prepend (self->row, self->rows, MAP_EXTEND_Y);
2063 2056
2064 self->rows += MAP_EXTEND_Y; 2057 self->rows += MAP_EXTEND_Y;
2065 self->y += MAP_EXTEND_Y; 2058 self->y += MAP_EXTEND_Y;
2066 } 2059 }
2067} 2060}
2223draw (DC::Map self, int mx, int my, int sw, int sh, int Tw, int Th, U32 player = 0xffffffff, int sdx = 0, int sdy = 0) 2216draw (DC::Map self, int mx, int my, int sw, int sh, int Tw, int Th, U32 player = 0xffffffff, int sdx = 0, int sdy = 0)
2224 CODE: 2217 CODE:
2225{ 2218{
2226 int x, y, z; 2219 int x, y, z;
2227 2220
2228 uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level
2229 static uint8_t smooth_max[256][256]; // egad, fast and wasteful on memory (64k) 2221 static uint8_t smooth_max[256][256]; // egad, fast and wasteful on memory (64k), also, static!
2230 smooth_key skey;
2231 int pl_x, pl_y; 2222 int pl_x, pl_y;
2232 maptex pl_tex; 2223 maptex pl_tex;
2233 rc_t *rc = rc_alloc (); 2224 rc_t rc;
2234 rc_t *rc_ov = rc_alloc (); 2225 rc_t rc_ov;
2235 rc_key_t key; 2226 rc_key_t key;
2236 rc_array_t *arr; 2227 rc_t::array_t *arr;
2237 2228
2238 pl_tex.name = 0; 2229 pl_tex.name = 0;
2239 2230
2240 // that's current max. sorry. 2231 // that's current max. sorry.
2241 if (sw > 255) sw = 255; 2232 if (sw > 255) sw = 255;
2242 if (sh > 255) sh = 255; 2233 if (sh > 255) sh = 255;
2243
2244 // clear key, in case of extra padding
2245 memset (&skey, 0, sizeof (skey));
2246 2234
2247 memset (&key, 0, sizeof (key)); 2235 memset (&key, 0, sizeof (key));
2248 key.r = 255; 2236 key.r = 255;
2249 key.g = 255; 2237 key.g = 255;
2250 key.b = 255; 2238 key.b = 255;
2256 my += self->y; 2244 my += self->y;
2257 2245
2258 // first pass: determine smooth_max 2246 // first pass: determine smooth_max
2259 // rather ugly, if you ask me 2247 // rather ugly, if you ask me
2260 // could also be stored inside mapcell and updated on change 2248 // could also be stored inside mapcell and updated on change
2261 memset (smooth_max, 0, sizeof (smooth_max)); 2249 memset (smooth_max, 0, sizeof (smooth_max[0]) * (sh + 1));
2262 2250
2263 for (y = 0; y < sh; y++) 2251 for (y = 0; y < sh; y++)
2264 if (0 <= y + my && y + my < self->rows) 2252 if (0 <= y + my && y + my < self->rows)
2265 { 2253 {
2266 maprow *row = self->row + (y + my); 2254 maprow *row = self->row + (y + my);
2281 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 2269 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2282 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); 2270 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
2283 2271
2284 for (z = 0; z <= 2; z++) 2272 for (z = 0; z <= 2; z++)
2285 { 2273 {
2274 std::bitset<256> smooth_level; // one bit for every possible smooth level
2275 smooth_key skey;
2286 smooth_hash smooth; 2276 smooth_hash smooth;
2287 memset (smooth_level, 0, sizeof (smooth_level));
2288 key.texname = -1; 2277 key.texname = -1;
2289 2278
2290 for (y = 0; y < sh; y++) 2279 for (y = 0; y < sh; y++)
2291 if (0 <= y + my && y + my < self->rows) 2280 if (0 <= y + my && y + my < self->rows)
2292 { 2281 {
2309 2298
2310 if (!tex.name) 2299 if (!tex.name)
2311 tex = self->tex [TEXID_NOFACE]; /* missing, replace by noface */ 2300 tex = self->tex [TEXID_NOFACE]; /* missing, replace by noface */
2312 2301
2313 key.texname = tex.name; 2302 key.texname = tex.name;
2314 arr = rc_array (rc, &key); 2303 arr = &rc.array (key);
2315 } 2304 }
2316 2305
2317 px = (x + 1) * Th - tex.w; 2306 px = (x + 1) * Th - tex.w;
2318 py = (y + 1) * Tw - tex.h; 2307 py = (y + 1) * Tw - tex.h;
2319 2308
2320 if (expect_false (cell->player == player) && expect_false (z == 2)) 2309 if (ecb_expect_false (cell->player == player) && ecb_expect_false (z == 2))
2321 { 2310 {
2322 pl_x = px; 2311 pl_x = px;
2323 pl_y = py; 2312 pl_y = py;
2324 pl_tex = tex; 2313 pl_tex = tex;
2325 continue; 2314 continue;
2326 } 2315 }
2327 2316
2328 rc_t2f_v3f (arr, 0 , 0 , px , py , 0); 2317 arr->t2f_v3f (0 , 0 , px , py , 0);
2329 rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0); 2318 arr->t2f_v3f (0 , tex.t, px , py + tex.h, 0);
2330 rc_t2f_v3f (arr, tex.s, tex.t, px + tex.w, py + tex.h, 0); 2319 arr->t2f_v3f (tex.s, tex.t, px + tex.w, py + tex.h, 0);
2331 rc_t2f_v3f (arr, tex.s, 0 , px + tex.w, py , 0); 2320 arr->t2f_v3f (tex.s, 0 , px + tex.w, py , 0);
2332 2321
2333 // update smooth hash 2322 // update smooth hash
2334 if (tex.smoothtile) 2323 if (tex.smoothtile)
2335 { 2324 {
2336 skey.tile = tex.smoothtile; 2325 skey.tile = tex.smoothtile;
2337 skey.level = tex.smoothlevel; 2326 skey.level = tex.smoothlevel;
2338 2327
2339 smooth_level [tex.smoothlevel >> 5] |= ((uint32_t)1) << (tex.smoothlevel & 31); 2328 smooth_level[tex.smoothlevel] = 1;
2340 2329
2341 // add bits to current tile and all neighbours. skey.x|y is 2330 // add bits to current tile and all neighbours. skey.x|y is
2342 // shifted +1|+1 so we always stay positive. 2331 // shifted +1|+1 so we always stay positive.
2343 2332
2344 // bits is ___n cccc CCCC bbbb 2333 // bits is ___n cccc CCCC bbbb
2368 skey.x = x ; skey.y = y ; smooth_or_bits (smooth, skey, 0x0400); 2357 skey.x = x ; skey.y = y ; smooth_or_bits (smooth, skey, 0x0400);
2369 skey.x = x + 2; skey.y = y ; smooth_or_bits (smooth, skey, 0x0800); 2358 skey.x = x + 2; skey.y = y ; smooth_or_bits (smooth, skey, 0x0800);
2370 } 2359 }
2371 } 2360 }
2372 2361
2373 if (expect_false (z == 2) && expect_false (cell->flags)) 2362 if (ecb_expect_false (z == 2) && ecb_expect_false (cell->flags))
2374 { 2363 {
2375 // overlays such as the speech bubble, probably more to come 2364 // overlays such as the speech bubble, probably more to come
2376 if (cell->flags & 1) 2365 if (cell->flags & 1)
2377 { 2366 {
2378 rc_key_t key_ov = key; 2367 rc_key_t key_ov = key;
2379 maptex tex = self->tex [TEXID_SPEECH]; 2368 maptex tex = self->tex[TEXID_SPEECH];
2380 rc_array_t *arr;
2381 int px = x * Tw + Tw * 2 / 32; 2369 int px = x * Tw + Tw * 2 / 32;
2382 int py = y * Th - Th * 6 / 32; 2370 int py = y * Th - Th * 6 / 32;
2383 2371
2384 key_ov.texname = tex.name; 2372 key_ov.texname = tex.name;
2385 arr = rc_array (rc_ov, &key_ov); 2373 rc_t::array_t &arr = rc_ov.array (key_ov);
2386 2374
2387 rc_t2f_v3f (arr, 0 , 0 , px , py , 0); 2375 arr.t2f_v3f (0 , 0 , px , py , 0);
2388 rc_t2f_v3f (arr, 0 , tex.t, px , py + Th, 0); 2376 arr.t2f_v3f (0 , tex.t, px , py + Th, 0);
2389 rc_t2f_v3f (arr, tex.s, tex.t, px + Tw, py + Th, 0); 2377 arr.t2f_v3f (tex.s, tex.t, px + Tw, py + Th, 0);
2390 rc_t2f_v3f (arr, tex.s, 0 , px + Tw, py , 0); 2378 arr.t2f_v3f (tex.s, 0 , px + Tw, py , 0);
2391 } 2379 }
2392 } 2380 }
2393 } 2381 }
2394 } 2382 }
2395 2383
2396 rc_draw (rc); 2384 rc.draw ();
2397 rc_clear (rc); 2385 rc.clear ();
2398 2386
2399 // go through all smoothlevels, lowest to highest, then draw. 2387 // go through all smoothlevels, lowest to highest, then draw.
2400 // this is basically counting sort 2388 // this is basically counting sort
2401 { 2389 {
2402 int w, b; 2390 int w, b;
2403 2391
2404 glEnable (GL_TEXTURE_2D); 2392 glEnable (GL_TEXTURE_2D);
2405 glBegin (GL_QUADS); 2393 glBegin (GL_QUADS);
2406 for (w = 0; w < 256 / 32; ++w) 2394 for (int level = 0; level < smooth_level.size (); ++level)
2395 if (smooth_level[level])
2396 for (auto &&it = smooth.begin (); it != smooth.end (); ++it)
2407 { 2397 {
2408 uint32_t smask = smooth_level [w]; 2398 smooth_key &skey = it->first;
2409 if (smask) 2399 IV bits = it->second;
2410 for (b = 0; b < 32; ++b) 2400
2411 if (smask & (((uint32_t)1) << b)) 2401 if (!(bits & 0x1000)
2402 && skey.level == level
2403 && level > smooth_max [skey.x][skey.y])
2412 { 2404 {
2413 int level = (w << 5) | b; 2405 maptex tex = self->tex [skey.tile];
2406 int px = (((int)skey.x) - 1) * Tw;
2407 int py = (((int)skey.y) - 1) * Th;
2408 int border = bits & 15;
2409 int corner = (bits >> 8) & ~(bits >> 4) & 15;
2410 float dx = tex.s * .0625f; // 16 images/row
2411 float dy = tex.t * .5f ; // 2 images/column
2412
2414 HE *he; 2413 if (tex.name)
2415
2416 for (auto &&it = smooth.begin (); it != smooth.end (); ++it)
2417 { 2414 {
2418 smooth_key &skey = it->first; 2415 // this time avoiding texture state changes
2419 IV bits = it->second; 2416 // save gobs of state changes.
2420 2417 if (key.texname != tex.name)
2421 if (!(bits & 0x1000)
2422 && skey.level == level
2423 && level > smooth_max [skey.x][skey.y])
2424 { 2418 {
2425 maptex tex = self->tex [skey.tile];
2426 int px = (((int)skey.x) - 1) * Tw;
2427 int py = (((int)skey.y) - 1) * Th;
2428 int border = bits & 15;
2429 int corner = (bits >> 8) & ~(bits >> 4) & 15;
2430 float dx = tex.s * .0625f; // 16 images/row
2431 float dy = tex.t * .5f ; // 2 images/column
2432
2433 if (tex.name)
2434 {
2435 // this time avoiding texture state changes
2436 // save gobs of state changes.
2437 if (key.texname != tex.name)
2438 {
2439 self->tex [skey.tile].unused = 0; 2419 self->tex [skey.tile].unused = 0;
2440 2420
2441 glEnd (); 2421 glEnd ();
2442 glBindTexture (GL_TEXTURE_2D, key.texname = tex.name); 2422 glBindTexture (GL_TEXTURE_2D, key.texname = tex.name);
2443 glBegin (GL_QUADS); 2423 glBegin (GL_QUADS);
2444 } 2424 }
2445 2425
2446 if (border) 2426 if (border)
2447 { 2427 {
2448 float ox = border * dx; 2428 float ox = border * dx;
2449 2429
2450 glTexCoord2f (ox , 0.f ); glVertex2i (px , py ); 2430 glTexCoord2f (ox , 0.f ); glVertex2i (px , py );
2451 glTexCoord2f (ox , dy ); glVertex2i (px , py + Th); 2431 glTexCoord2f (ox , dy ); glVertex2i (px , py + Th);
2452 glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py + Th); 2432 glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py + Th);
2453 glTexCoord2f (ox + dx, 0.f ); glVertex2i (px + Tw, py ); 2433 glTexCoord2f (ox + dx, 0.f ); glVertex2i (px + Tw, py );
2454 } 2434 }
2455 2435
2456 if (corner) 2436 if (corner)
2457 { 2437 {
2458 float ox = corner * dx; 2438 float ox = corner * dx;
2459 2439
2460 glTexCoord2f (ox , dy ); glVertex2i (px , py ); 2440 glTexCoord2f (ox , dy ); glVertex2i (px , py );
2461 glTexCoord2f (ox , dy * 2.f); glVertex2i (px , py + Th); 2441 glTexCoord2f (ox , dy * 2.f); glVertex2i (px , py + Th);
2462 glTexCoord2f (ox + dx, dy * 2.f); glVertex2i (px + Tw, py + Th); 2442 glTexCoord2f (ox + dx, dy * 2.f); glVertex2i (px + Tw, py + Th);
2463 glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py ); 2443 glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py );
2464 }
2465 }
2466 } 2444 }
2467 } 2445 }
2468 } 2446 }
2469 } 2447 }
2470 2448
2471 glEnd (); 2449 glEnd ();
2472 glDisable (GL_TEXTURE_2D); 2450 glDisable (GL_TEXTURE_2D);
2473 key.texname = -1; 2451 key.texname = -1;
2474 } 2452 }
2479 maptex tex = pl_tex; 2457 maptex tex = pl_tex;
2480 int px = pl_x + sdx; 2458 int px = pl_x + sdx;
2481 int py = pl_y + sdy; 2459 int py = pl_y + sdy;
2482 2460
2483 key.texname = tex.name; 2461 key.texname = tex.name;
2484 arr = rc_array (rc, &key); 2462 rc_t::array_t &arr = rc.array (key);
2485 2463
2486 rc_t2f_v3f (arr, 0 , 0 , px , py , 0); 2464 arr.t2f_v3f (0 , 0 , px , py , 0);
2487 rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0); 2465 arr.t2f_v3f (0 , tex.t, px , py + tex.h, 0);
2488 rc_t2f_v3f (arr, tex.s, tex.t, px + tex.w, py + tex.h, 0); 2466 arr.t2f_v3f (tex.s, tex.t, px + tex.w, py + tex.h, 0);
2489 rc_t2f_v3f (arr, tex.s, 0 , px + tex.w, py , 0); 2467 arr.t2f_v3f (tex.s, 0 , px + tex.w, py , 0);
2490 2468
2491 rc_draw (rc); 2469 rc.draw ();
2492 } 2470 }
2493 2471
2494 rc_draw (rc_ov); 2472 rc_ov.draw ();
2495 rc_clear (rc_ov); 2473 rc_ov.clear ();
2496 2474
2497 glDisable (GL_BLEND); 2475 glDisable (GL_BLEND);
2498 rc_free (rc);
2499 rc_free (rc_ov);
2500 2476
2501 // top layer: overlays such as the health bar 2477 // top layer: overlays such as the health bar
2502 for (y = 0; y < sh; y++) 2478 for (y = 0; y < sh; y++)
2503 if (0 <= y + my && y + my < self->rows) 2479 if (0 <= y + my && y + my < self->rows)
2504 { 2480 {
2510 mapcell *cell = row->col + (x + mx - row->c0); 2486 mapcell *cell = row->col + (x + mx - row->c0);
2511 2487
2512 int px = x * Tw; 2488 int px = x * Tw;
2513 int py = y * Th; 2489 int py = y * Th;
2514 2490
2515 if (expect_false (cell->player == player)) 2491 if (ecb_expect_false (cell->player == player))
2516 { 2492 {
2517 px += sdx; 2493 px += sdx;
2518 py += sdy; 2494 py += sdy;
2519 } 2495 }
2520 2496

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines