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.334 by root, Mon Nov 19 01:37:28 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 */
110fast_sv_grow (SV *sv, STRLEN need) 105fast_sv_grow (SV *sv, STRLEN need)
111{ 106{
112 STRLEN len = SvLEN (sv); 107 STRLEN len = SvLEN (sv);
113 STRLEN want = SvCUR (sv) + need; 108 STRLEN want = SvCUR (sv) + need;
114 109
115 if (expect_false (len < want)) 110 if (ecb_expect_false (len < want))
116 { 111 {
117 do 112 do
118 len *= 2; 113 len *= 2;
119 while (len < want); 114 while (len < want);
120 115
204struct cf_layout { 199struct cf_layout {
205 PangoLayout *pl; 200 PangoLayout *pl;
206 float r, g, b, a; // default color for rgba mode 201 float r, g, b, a; // default color for rgba mode
207 int base_height; 202 int base_height;
208 DC__Font font; 203 DC__Font font;
209 rc_t *rc; 204 rc_t rc;
210}; 205};
211 206
212typedef cf_layout *DC__Layout; 207typedef cf_layout *DC__Layout;
213 208
214static DC__Font default_font; 209static DC__Font default_font;
254 if (!rect.height) rect.height = 1; 249 if (!rect.height) rect.height = 1;
255 250
256 *w = rect.width; 251 *w = rect.width;
257 *h = rect.height; 252 *h = rect.height;
258} 253}
254
255/////////////////////////////////////////////////////////////////////////////
259 256
260typedef uint16_t tileid; 257typedef uint16_t tileid;
261typedef uint16_t faceid; 258typedef uint16_t faceid;
262 259
263struct maptex 260struct maptex
295 maprow *row; 292 maprow *row;
296}; 293};
297 294
298typedef mapgrid *DC__Map; 295typedef mapgrid *DC__Map;
299 296
300static char * 297template<typename T>
298static void
301prepend (char *ptr, int sze, int inc) 299prepend (T *&ptr, int sze, int inc)
302{ 300{
303 char *p; 301 T *p;
304 302
305 New (0, p, sze + inc, char); 303 Newx (p, inc + sze, T);
306 Zero (p, inc, char); 304 Zero (p, inc, T);
307 Move (ptr, p + inc, sze, char); 305 Move (ptr, p + inc, sze, T);
308 Safefree (ptr); 306 Safefree (ptr);
309 307
310 return p; 308 ptr = p;
311} 309}
312 310
313static char * 311template<typename T>
312static void
314append (char *ptr, int sze, int inc) 313append (T *&ptr, int sze, int inc)
315{ 314{
316 Renew (ptr, sze + inc, char); 315 Renew (ptr, sze + inc, T);
317 Zero (ptr + sze, inc, char); 316 Zero (ptr + sze, inc, T);
318
319 return ptr;
320} 317}
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 318
325static void 319static void
326need_facenum (struct mapgrid *self, faceid face) 320need_facenum (struct mapgrid *self, faceid face)
327{ 321{
328 while (self->faces <= face) 322 while (self->faces <= face)
329 { 323 {
330 Append (tileid, self->face2tile, self->faces, self->faces); 324 append (self->face2tile, self->faces, self->faces);
331 self->faces *= 2; 325 self->faces *= 2;
332 } 326 }
333} 327}
334 328
335static void 329static void
336need_texid (struct mapgrid *self, int texid) 330need_texid (struct mapgrid *self, int texid)
337{ 331{
338 while (self->texs <= texid) 332 while (self->texs <= texid)
339 { 333 {
340 Append (maptex, self->tex, self->texs, self->texs); 334 append (self->tex, self->texs, self->texs);
341 self->texs *= 2; 335 self->texs *= 2;
342 } 336 }
343} 337}
344 338
345static maprow * 339static maprow *
346map_get_row (mapgrid *self, int y) 340map_get_row (mapgrid *self, int y)
347{ 341{
348 if (0 > y) 342 if (0 > y)
349 { 343 {
350 int extend = - y + MAP_EXTEND_Y; 344 int extend = - y + MAP_EXTEND_Y;
351 Prepend (maprow, self->row, self->rows, extend); 345 prepend (self->row, self->rows, extend);
352 346
353 self->rows += extend; 347 self->rows += extend;
354 self->y += extend; 348 self->y += extend;
355 y += extend; 349 y += extend;
356 } 350 }
357 else if (y >= self->rows) 351 else if (y >= self->rows)
358 { 352 {
359 int extend = y - self->rows + MAP_EXTEND_Y; 353 int extend = y - self->rows + MAP_EXTEND_Y;
360 Append (maprow, self->row, self->rows, extend); 354 append (self->row, self->rows, extend);
361 self->rows += extend; 355 self->rows += extend;
362 } 356 }
363 357
364 return self->row + y; 358 return self->row + y;
365} 359}
375 } 369 }
376 370
377 if (row->c0 > x) 371 if (row->c0 > x)
378 { 372 {
379 int extend = row->c0 - x + MAP_EXTEND_X; 373 int extend = row->c0 - x + MAP_EXTEND_X;
380 Prepend (mapcell, row->col, row->c1 - row->c0, extend); 374 prepend (row->col, row->c1 - row->c0, extend);
381 row->c0 -= extend; 375 row->c0 -= extend;
382 } 376 }
383 else if (x >= row->c1) 377 else if (x >= row->c1)
384 { 378 {
385 int extend = x - row->c1 + MAP_EXTEND_X; 379 int extend = x - row->c1 + MAP_EXTEND_X;
386 Append (mapcell, row->col, row->c1 - row->c0, extend); 380 append (row->col, row->c1 - row->c0, extend);
387 row->c1 += extend; 381 row->c1 += extend;
388 } 382 }
389 383
390 return row->col + (x - row->c0); 384 return row->col + (x - row->c0);
391} 385}
461 { 455 {
462 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;
463 } 457 }
464}; 458};
465 459
466typedef 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;
467 461
468namespace std { 462namespace std {
469 template <> 463 template <>
470 struct hash<smooth_key> 464 struct hash<smooth_key>
471 { 465 {
533 n |= n >> 4; 527 n |= n >> 4;
534 n |= n >> 8; 528 n |= n >> 8;
535 n |= n >> 16; 529 n |= n >> 16;
536 530
537 return n + 1; 531 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} 532}
550 533
551/* SDL should provide this, really. */ 534/* SDL should provide this, really. */
552#define SDLK_MODIFIER_MIN 300 535#define SDLK_MODIFIER_MIN 300
553#define SDLK_MODIFIER_MAX 314 536#define SDLK_MODIFIER_MAX 314
884 867
885NV ceil (NV x) 868NV ceil (NV x)
886 869
887IV minpot (UV n) 870IV minpot (UV n)
888 871
872UV ld32 (UV n)
873 CODE:
874 RETVAL = ecb_ld32 (n);
875 OUTPUT:
876 RETVAL
877
889IV popcount (UV n) 878IV popcount (UV n)
879 CODE:
880 RETVAL = ecb_popcount32 (n);
881 OUTPUT:
882 RETVAL
890 883
891NV distance (NV dx, NV dy) 884NV distance (NV dx, NV dy)
892 CODE: 885 CODE:
893 RETVAL = pow (dx * dx + dy * dy, 0.5); 886 RETVAL = pow (dx * dx + dy * dy, 0.5);
894 OUTPUT: 887 OUTPUT:
1368 tc_restore (); 1361 tc_restore ();
1369 1362
1370DC::Layout 1363DC::Layout
1371new (SV *klass) 1364new (SV *klass)
1372 CODE: 1365 CODE:
1373 New (0, RETVAL, 1, struct cf_layout); 1366 RETVAL = new cf_layout;
1374 1367
1375 RETVAL->pl = pango_layout_new (opengl_context); 1368 RETVAL->pl = pango_layout_new (opengl_context);
1376 RETVAL->r = 1.; 1369 RETVAL->r = 1.;
1377 RETVAL->g = 1.; 1370 RETVAL->g = 1.;
1378 RETVAL->b = 1.; 1371 RETVAL->b = 1.;
1379 RETVAL->a = 1.; 1372 RETVAL->a = 1.;
1380 RETVAL->base_height = MIN_FONT_HEIGHT; 1373 RETVAL->base_height = MIN_FONT_HEIGHT;
1381 RETVAL->font = 0; 1374 RETVAL->font = 0;
1382 RETVAL->rc = rc_alloc ();
1383 1375
1384 pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR); 1376 pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR);
1385 layout_update_font (RETVAL); 1377 layout_update_font (RETVAL);
1386 OUTPUT: 1378 OUTPUT:
1387 RETVAL 1379 RETVAL
1388 1380
1389void 1381void
1390DESTROY (DC::Layout self) 1382DESTROY (DC::Layout self)
1391 CODE: 1383 CODE:
1392 g_object_unref (self->pl); 1384 g_object_unref (self->pl);
1393 rc_free (self->rc);
1394 Safefree (self); 1385 delete self;
1395 1386
1396void 1387void
1397set_text (DC::Layout self, SV *text_) 1388set_text (DC::Layout self, SV *text_)
1398 CODE: 1389 CODE:
1399{ 1390{
1653} 1644}
1654 1645
1655void 1646void
1656render (DC::Layout self, float x, float y, int flags = 0) 1647render (DC::Layout self, float x, float y, int flags = 0)
1657 CODE: 1648 CODE:
1658 rc_clear (self->rc); 1649 self->rc.clear ();
1659 pango_opengl_render_layout_subpixel ( 1650 pango_opengl_render_layout_subpixel (
1660 self->pl, 1651 self->pl,
1661 self->rc, 1652 &self->rc,
1662 x * PANGO_SCALE, y * PANGO_SCALE, 1653 x * PANGO_SCALE, y * PANGO_SCALE,
1663 self->r, self->g, self->b, self->a, 1654 self->r, self->g, self->b, self->a,
1664 flags 1655 flags
1665 ); 1656 );
1666 // we assume that context_change actually clears/frees stuff 1657 // we assume that context_change actually clears/frees stuff
1677 gl_BlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, 1668 gl_BlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,
1678 GL_ONE , GL_ONE_MINUS_SRC_ALPHA); 1669 GL_ONE , GL_ONE_MINUS_SRC_ALPHA);
1679 glEnable (GL_ALPHA_TEST); 1670 glEnable (GL_ALPHA_TEST);
1680 glAlphaFunc (GL_GREATER, 7.f / 255.f); 1671 glAlphaFunc (GL_GREATER, 7.f / 255.f);
1681 1672
1682 rc_draw (self->rc); 1673 self->rc.draw ();
1683 1674
1684 glDisable (GL_ALPHA_TEST); 1675 glDisable (GL_ALPHA_TEST);
1685 glDisable (GL_BLEND); 1676 glDisable (GL_BLEND);
1686 glDisable (GL_TEXTURE_2D); 1677 glDisable (GL_TEXTURE_2D);
1687} 1678}
2057 self->ox += dx; self->x += dx; 2048 self->ox += dx; self->x += dx;
2058 self->oy += dy; self->y += dy; 2049 self->oy += dy; self->y += dy;
2059 2050
2060 while (self->y < 0) 2051 while (self->y < 0)
2061 { 2052 {
2062 Prepend (maprow, self->row, self->rows, MAP_EXTEND_Y); 2053 prepend (self->row, self->rows, MAP_EXTEND_Y);
2063 2054
2064 self->rows += MAP_EXTEND_Y; 2055 self->rows += MAP_EXTEND_Y;
2065 self->y += MAP_EXTEND_Y; 2056 self->y += MAP_EXTEND_Y;
2066 } 2057 }
2067} 2058}
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) 2214draw (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: 2215 CODE:
2225{ 2216{
2226 int x, y, z; 2217 int x, y, z;
2227 2218
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) 2219 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; 2220 int pl_x, pl_y;
2232 maptex pl_tex; 2221 maptex pl_tex;
2233 rc_t *rc = rc_alloc (); 2222 rc_t rc;
2234 rc_t *rc_ov = rc_alloc (); 2223 rc_t rc_ov;
2235 rc_key_t key; 2224 rc_key_t key;
2236 rc_array_t *arr; 2225 rc_t::array_t *arr;
2237 2226
2238 pl_tex.name = 0; 2227 pl_tex.name = 0;
2239 2228
2240 // that's current max. sorry. 2229 // that's current max. sorry.
2241 if (sw > 255) sw = 255; 2230 if (sw > 255) sw = 255;
2242 if (sh > 255) sh = 255; 2231 if (sh > 255) sh = 255;
2243
2244 // clear key, in case of extra padding
2245 memset (&skey, 0, sizeof (skey));
2246 2232
2247 memset (&key, 0, sizeof (key)); 2233 memset (&key, 0, sizeof (key));
2248 key.r = 255; 2234 key.r = 255;
2249 key.g = 255; 2235 key.g = 255;
2250 key.b = 255; 2236 key.b = 255;
2256 my += self->y; 2242 my += self->y;
2257 2243
2258 // first pass: determine smooth_max 2244 // first pass: determine smooth_max
2259 // rather ugly, if you ask me 2245 // rather ugly, if you ask me
2260 // could also be stored inside mapcell and updated on change 2246 // could also be stored inside mapcell and updated on change
2261 memset (smooth_max, 0, sizeof (smooth_max)); 2247 memset (smooth_max, 0, sizeof (smooth_max[0]) * (sh + 1));
2262 2248
2263 for (y = 0; y < sh; y++) 2249 for (y = 0; y < sh; y++)
2264 if (0 <= y + my && y + my < self->rows) 2250 if (0 <= y + my && y + my < self->rows)
2265 { 2251 {
2266 maprow *row = self->row + (y + my); 2252 maprow *row = self->row + (y + my);
2281 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 2267 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2282 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); 2268 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
2283 2269
2284 for (z = 0; z <= 2; z++) 2270 for (z = 0; z <= 2; z++)
2285 { 2271 {
2272 std::bitset<256> smooth_level; // one bit for every possible smooth level
2273 smooth_key skey;
2286 smooth_hash smooth; 2274 smooth_hash smooth;
2287 memset (smooth_level, 0, sizeof (smooth_level));
2288 key.texname = -1; 2275 key.texname = -1;
2289 2276
2290 for (y = 0; y < sh; y++) 2277 for (y = 0; y < sh; y++)
2291 if (0 <= y + my && y + my < self->rows) 2278 if (0 <= y + my && y + my < self->rows)
2292 { 2279 {
2309 2296
2310 if (!tex.name) 2297 if (!tex.name)
2311 tex = self->tex [TEXID_NOFACE]; /* missing, replace by noface */ 2298 tex = self->tex [TEXID_NOFACE]; /* missing, replace by noface */
2312 2299
2313 key.texname = tex.name; 2300 key.texname = tex.name;
2314 arr = rc_array (rc, &key); 2301 arr = &rc.array (key);
2315 } 2302 }
2316 2303
2317 px = (x + 1) * Th - tex.w; 2304 px = (x + 1) * Th - tex.w;
2318 py = (y + 1) * Tw - tex.h; 2305 py = (y + 1) * Tw - tex.h;
2319 2306
2320 if (expect_false (cell->player == player) && expect_false (z == 2)) 2307 if (ecb_expect_false (cell->player == player) && ecb_expect_false (z == 2))
2321 { 2308 {
2322 pl_x = px; 2309 pl_x = px;
2323 pl_y = py; 2310 pl_y = py;
2324 pl_tex = tex; 2311 pl_tex = tex;
2325 continue; 2312 continue;
2326 } 2313 }
2327 2314
2328 rc_t2f_v3f (arr, 0 , 0 , px , py , 0); 2315 arr->t2f_v3f (0 , 0 , px , py , 0);
2329 rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0); 2316 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); 2317 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); 2318 arr->t2f_v3f (tex.s, 0 , px + tex.w, py , 0);
2332 2319
2333 // update smooth hash 2320 // update smooth hash
2334 if (tex.smoothtile) 2321 if (tex.smoothtile)
2335 { 2322 {
2336 skey.tile = tex.smoothtile; 2323 skey.tile = tex.smoothtile;
2337 skey.level = tex.smoothlevel; 2324 skey.level = tex.smoothlevel;
2338 2325
2339 smooth_level [tex.smoothlevel >> 5] |= ((uint32_t)1) << (tex.smoothlevel & 31); 2326 smooth_level[tex.smoothlevel] = 1;
2340 2327
2341 // add bits to current tile and all neighbours. skey.x|y is 2328 // add bits to current tile and all neighbours. skey.x|y is
2342 // shifted +1|+1 so we always stay positive. 2329 // shifted +1|+1 so we always stay positive.
2343 2330
2344 // bits is ___n cccc CCCC bbbb 2331 // bits is ___n cccc CCCC bbbb
2368 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);
2369 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);
2370 } 2357 }
2371 } 2358 }
2372 2359
2373 if (expect_false (z == 2) && expect_false (cell->flags)) 2360 if (ecb_expect_false (z == 2) && ecb_expect_false (cell->flags))
2374 { 2361 {
2375 // overlays such as the speech bubble, probably more to come 2362 // overlays such as the speech bubble, probably more to come
2376 if (cell->flags & 1) 2363 if (cell->flags & 1)
2377 { 2364 {
2378 rc_key_t key_ov = key; 2365 rc_key_t key_ov = key;
2379 maptex tex = self->tex [TEXID_SPEECH]; 2366 maptex tex = self->tex[TEXID_SPEECH];
2380 rc_array_t *arr;
2381 int px = x * Tw + Tw * 2 / 32; 2367 int px = x * Tw + Tw * 2 / 32;
2382 int py = y * Th - Th * 6 / 32; 2368 int py = y * Th - Th * 6 / 32;
2383 2369
2384 key_ov.texname = tex.name; 2370 key_ov.texname = tex.name;
2385 arr = rc_array (rc_ov, &key_ov); 2371 rc_t::array_t &arr = rc_ov.array (key_ov);
2386 2372
2387 rc_t2f_v3f (arr, 0 , 0 , px , py , 0); 2373 arr.t2f_v3f (0 , 0 , px , py , 0);
2388 rc_t2f_v3f (arr, 0 , tex.t, px , py + Th, 0); 2374 arr.t2f_v3f (0 , tex.t, px , py + Th, 0);
2389 rc_t2f_v3f (arr, tex.s, tex.t, px + Tw, py + Th, 0); 2375 arr.t2f_v3f (tex.s, tex.t, px + Tw, py + Th, 0);
2390 rc_t2f_v3f (arr, tex.s, 0 , px + Tw, py , 0); 2376 arr.t2f_v3f (tex.s, 0 , px + Tw, py , 0);
2391 } 2377 }
2392 } 2378 }
2393 } 2379 }
2394 } 2380 }
2395 2381
2396 rc_draw (rc); 2382 rc.draw ();
2397 rc_clear (rc); 2383 rc.clear ();
2398 2384
2399 // go through all smoothlevels, lowest to highest, then draw. 2385 // go through all smoothlevels, lowest to highest, then draw.
2400 // this is basically counting sort 2386 // this is basically counting sort
2401 { 2387 {
2402 int w, b; 2388 int w, b;
2403 2389
2404 glEnable (GL_TEXTURE_2D); 2390 glEnable (GL_TEXTURE_2D);
2405 glBegin (GL_QUADS); 2391 glBegin (GL_QUADS);
2406 for (w = 0; w < 256 / 32; ++w) 2392 for (int level = 0; level < smooth_level.size (); ++level)
2393 if (smooth_level[level])
2394 for (auto &&it = smooth.begin (); it != smooth.end (); ++it)
2407 { 2395 {
2408 uint32_t smask = smooth_level [w]; 2396 smooth_key &skey = it->first;
2409 if (smask) 2397 IV bits = it->second;
2410 for (b = 0; b < 32; ++b) 2398
2411 if (smask & (((uint32_t)1) << b)) 2399 if (!(bits & 0x1000)
2400 && skey.level == level
2401 && level > smooth_max [skey.x][skey.y])
2412 { 2402 {
2413 int level = (w << 5) | b; 2403 maptex tex = self->tex [skey.tile];
2404 int px = (((int)skey.x) - 1) * Tw;
2405 int py = (((int)skey.y) - 1) * Th;
2406 int border = bits & 15;
2407 int corner = (bits >> 8) & ~(bits >> 4) & 15;
2408 float dx = tex.s * .0625f; // 16 images/row
2409 float dy = tex.t * .5f ; // 2 images/column
2410
2414 HE *he; 2411 if (tex.name)
2415
2416 for (auto &&it = smooth.begin (); it != smooth.end (); ++it)
2417 { 2412 {
2418 smooth_key &skey = it->first; 2413 // this time avoiding texture state changes
2419 IV bits = it->second; 2414 // save gobs of state changes.
2420 2415 if (key.texname != tex.name)
2421 if (!(bits & 0x1000)
2422 && skey.level == level
2423 && level > smooth_max [skey.x][skey.y])
2424 { 2416 {
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; 2417 self->tex [skey.tile].unused = 0;
2440 2418
2441 glEnd (); 2419 glEnd ();
2442 glBindTexture (GL_TEXTURE_2D, key.texname = tex.name); 2420 glBindTexture (GL_TEXTURE_2D, key.texname = tex.name);
2443 glBegin (GL_QUADS); 2421 glBegin (GL_QUADS);
2444 } 2422 }
2445 2423
2446 if (border) 2424 if (border)
2447 { 2425 {
2448 float ox = border * dx; 2426 float ox = border * dx;
2449 2427
2450 glTexCoord2f (ox , 0.f ); glVertex2i (px , py ); 2428 glTexCoord2f (ox , 0.f ); glVertex2i (px , py );
2451 glTexCoord2f (ox , dy ); glVertex2i (px , py + Th); 2429 glTexCoord2f (ox , dy ); glVertex2i (px , py + Th);
2452 glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py + Th); 2430 glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py + Th);
2453 glTexCoord2f (ox + dx, 0.f ); glVertex2i (px + Tw, py ); 2431 glTexCoord2f (ox + dx, 0.f ); glVertex2i (px + Tw, py );
2454 } 2432 }
2455 2433
2456 if (corner) 2434 if (corner)
2457 { 2435 {
2458 float ox = corner * dx; 2436 float ox = corner * dx;
2459 2437
2460 glTexCoord2f (ox , dy ); glVertex2i (px , py ); 2438 glTexCoord2f (ox , dy ); glVertex2i (px , py );
2461 glTexCoord2f (ox , dy * 2.f); glVertex2i (px , py + Th); 2439 glTexCoord2f (ox , dy * 2.f); glVertex2i (px , py + Th);
2462 glTexCoord2f (ox + dx, dy * 2.f); glVertex2i (px + Tw, py + Th); 2440 glTexCoord2f (ox + dx, dy * 2.f); glVertex2i (px + Tw, py + Th);
2463 glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py ); 2441 glTexCoord2f (ox + dx, dy ); glVertex2i (px + Tw, py );
2464 }
2465 }
2466 } 2442 }
2467 } 2443 }
2468 } 2444 }
2469 } 2445 }
2470 2446
2471 glEnd (); 2447 glEnd ();
2472 glDisable (GL_TEXTURE_2D); 2448 glDisable (GL_TEXTURE_2D);
2473 key.texname = -1; 2449 key.texname = -1;
2474 } 2450 }
2479 maptex tex = pl_tex; 2455 maptex tex = pl_tex;
2480 int px = pl_x + sdx; 2456 int px = pl_x + sdx;
2481 int py = pl_y + sdy; 2457 int py = pl_y + sdy;
2482 2458
2483 key.texname = tex.name; 2459 key.texname = tex.name;
2484 arr = rc_array (rc, &key); 2460 rc_t::array_t &arr = rc.array (key);
2485 2461
2486 rc_t2f_v3f (arr, 0 , 0 , px , py , 0); 2462 arr.t2f_v3f (0 , 0 , px , py , 0);
2487 rc_t2f_v3f (arr, 0 , tex.t, px , py + tex.h, 0); 2463 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); 2464 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); 2465 arr.t2f_v3f (tex.s, 0 , px + tex.w, py , 0);
2490 2466
2491 rc_draw (rc); 2467 rc.draw ();
2492 } 2468 }
2493 2469
2494 rc_draw (rc_ov); 2470 rc_ov.draw ();
2495 rc_clear (rc_ov); 2471 rc_ov.clear ();
2496 2472
2497 glDisable (GL_BLEND); 2473 glDisable (GL_BLEND);
2498 rc_free (rc);
2499 rc_free (rc_ov);
2500 2474
2501 // top layer: overlays such as the health bar 2475 // top layer: overlays such as the health bar
2502 for (y = 0; y < sh; y++) 2476 for (y = 0; y < sh; y++)
2503 if (0 <= y + my && y + my < self->rows) 2477 if (0 <= y + my && y + my < self->rows)
2504 { 2478 {
2510 mapcell *cell = row->col + (x + mx - row->c0); 2484 mapcell *cell = row->col + (x + mx - row->c0);
2511 2485
2512 int px = x * Tw; 2486 int px = x * Tw;
2513 int py = y * Th; 2487 int py = y * Th;
2514 2488
2515 if (expect_false (cell->player == player)) 2489 if (ecb_expect_false (cell->player == player))
2516 { 2490 {
2517 px += sdx; 2491 px += sdx;
2518 py += sdy; 2492 py += sdy;
2519 } 2493 }
2520 2494

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines