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.321 by root, Sun Nov 18 01:15:04 2018 UTC vs.
Revision 1.322 by root, Sun Nov 18 01:43:12 2018 UTC

15 15
16#include "EXTERN.h" 16#include "EXTERN.h"
17#include "perl.h" 17#include "perl.h"
18#include "XSUB.h" 18#include "XSUB.h"
19 19
20#include "flat_hash_map.hpp"
21
20#ifdef _WIN32 22#ifdef _WIN32
21# undef pipe 23# undef pipe
22// microsoft vs. C 24// microsoft vs. C
23# define sqrtf(x) sqrt(x) 25# define sqrtf(x) sqrt(x)
24# define atan2f(x,y) atan2(x,y) 26# define atan2f(x,y) atan2(x,y)
25# define M_PI 3.14159265f 27# define M_PI 3.14159265f
26#endif 28#endif
27 29
28#include <assert.h> 30#include <cassert>
29#include <math.h> 31#include <cmath>
30#include <string.h> 32#include <cstring>
31#include <stdio.h> 33#include <cstdio>
32#include <stdlib.h> 34#include <cstdlib>
35
36#include <utility>
33 37
34#define USE_RWOPS 1 // for SDL_mixer:LoadMUS_RW 38#define USE_RWOPS 1 // for SDL_mixer:LoadMUS_RW
35 39
36#include <SDL.h> 40#include <SDL.h>
37#include <SDL_thread.h> 41#include <SDL_thread.h>
439 CELL_CLEAR (cell); 443 CELL_CLEAR (cell);
440 } 444 }
441 } 445 }
442} 446}
443 447
444typedef struct { 448struct smooth_key
449{
445 tileid tile; 450 tileid tile;
446 uint8_t x, y, level; 451 uint8_t x, y, level;
447} smooth_key; 452
453 bool operator == (const smooth_key &o) const
454 {
455 return tile == o.tile && x == o.x && y == o.y && level == o.level;
456 }
457};
458
459typedef ska::flat_hash_map<smooth_key, IV> smooth_hash;
460
461namespace std {
462 template <>
463 struct hash<smooth_key>
464 {
465 size_t operator () (const smooth_key &v) const
466 {
467 return v.tile + (v.x << 8) + (v.y << 16) + (v.level << 24);
468 }
469 };
470}
448 471
449static void 472static void
450smooth_or_bits (HV *hv, smooth_key *key, IV bits) 473smooth_or_bits (smooth_hash &h, smooth_key &key, IV bits)
451{ 474{
452 SV **sv = hv_fetch (hv, (char *)key, sizeof (*key), 1); 475 auto &&it = h.find (key);
453 476
454 if (SvIOK (*sv)) 477 if (it == h.end ())
455 SvIV_set (*sv, SvIVX (*sv) | bits); 478 h.insert (std::make_pair (key, bits));
456 else 479 else
457 sv_setiv (*sv, bits); 480 it->second |= bits;
458} 481}
459 482
460static void 483static void
461music_finished (void) 484music_finished (void)
462{ 485{
2193draw (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)
2194 CODE: 2217 CODE:
2195{ 2218{
2196 int x, y, z; 2219 int x, y, z;
2197 2220
2198 HV *smooth = (HV *)sv_2mortal ((SV *)newHV ());
2199 uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level 2221 uint32_t smooth_level[256 / 32]; // one bit for every possible smooth level
2200 static uint8_t smooth_max[256][256]; // egad, fast and wasteful on memory (64k) 2222 static uint8_t smooth_max[256][256]; // egad, fast and wasteful on memory (64k)
2201 smooth_key skey; 2223 smooth_key skey;
2202 int pl_x, pl_y; 2224 int pl_x, pl_y;
2203 maptex pl_tex; 2225 maptex pl_tex;
2252 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 2274 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2253 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); 2275 glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
2254 2276
2255 for (z = 0; z <= 2; z++) 2277 for (z = 0; z <= 2; z++)
2256 { 2278 {
2279 smooth_hash smooth;
2257 memset (smooth_level, 0, sizeof (smooth_level)); 2280 memset (smooth_level, 0, sizeof (smooth_level));
2258 key.texname = -1; 2281 key.texname = -1;
2259 2282
2260 for (y = 0; y < sh; y++) 2283 for (y = 0; y < sh; y++)
2261 if (0 <= y + my && y + my < self->rows) 2284 if (0 <= y + my && y + my < self->rows)
2322 2345
2323 // corners: 1 ┛· 2 ·┗ 4 ·· 8 ·· 2346 // corners: 1 ┛· 2 ·┗ 4 ·· 8 ··
2324 // ·· ·· ·┏ ┓· 2347 // ·· ·· ·┏ ┓·
2325 2348
2326 // full tile 2349 // full tile
2327 skey.x = x + 1; skey.y = y + 1; smooth_or_bits (smooth, &skey, 0x1000); 2350 skey.x = x + 1; skey.y = y + 1; smooth_or_bits (smooth, skey, 0x1000);
2328 2351
2329 // borders 2352 // borders
2330 skey.x = x + 2; skey.y = y + 1; smooth_or_bits (smooth, &skey, 0x0091); 2353 skey.x = x + 2; skey.y = y + 1; smooth_or_bits (smooth, skey, 0x0091);
2331 skey.x = x + 1; skey.y = y + 2; smooth_or_bits (smooth, &skey, 0x0032); 2354 skey.x = x + 1; skey.y = y + 2; smooth_or_bits (smooth, skey, 0x0032);
2332 skey.x = x ; skey.y = y + 1; smooth_or_bits (smooth, &skey, 0x0064); 2355 skey.x = x ; skey.y = y + 1; smooth_or_bits (smooth, skey, 0x0064);
2333 skey.x = x + 1; skey.y = y ; smooth_or_bits (smooth, &skey, 0x00c8); 2356 skey.x = x + 1; skey.y = y ; smooth_or_bits (smooth, skey, 0x00c8);
2334 2357
2335 // corners 2358 // corners
2336 skey.x = x + 2; skey.y = y + 2; smooth_or_bits (smooth, &skey, 0x0100); 2359 skey.x = x + 2; skey.y = y + 2; smooth_or_bits (smooth, skey, 0x0100);
2337 skey.x = x ; skey.y = y + 2; smooth_or_bits (smooth, &skey, 0x0200); 2360 skey.x = x ; skey.y = y + 2; smooth_or_bits (smooth, skey, 0x0200);
2338 skey.x = x ; skey.y = y ; smooth_or_bits (smooth, &skey, 0x0400); 2361 skey.x = x ; skey.y = y ; smooth_or_bits (smooth, skey, 0x0400);
2339 skey.x = x + 2; skey.y = y ; smooth_or_bits (smooth, &skey, 0x0800); 2362 skey.x = x + 2; skey.y = y ; smooth_or_bits (smooth, skey, 0x0800);
2340 } 2363 }
2341 } 2364 }
2342 2365
2343 if (expect_false (z == 2) && expect_false (cell->flags)) 2366 if (expect_false (z == 2) && expect_false (cell->flags))
2344 { 2367 {
2381 if (smask & (((uint32_t)1) << b)) 2404 if (smask & (((uint32_t)1) << b))
2382 { 2405 {
2383 int level = (w << 5) | b; 2406 int level = (w << 5) | b;
2384 HE *he; 2407 HE *he;
2385 2408
2386 hv_iterinit (smooth); 2409 for (auto &&it = smooth.begin (); it != smooth.end (); ++it)
2387 while ((he = hv_iternext (smooth)))
2388 { 2410 {
2389 smooth_key *skey = (smooth_key *)HeKEY (he); 2411 smooth_key &skey = it->first;
2390 IV bits = SvIVX (HeVAL (he)); 2412 IV bits = it->second;
2391 2413
2392 if (!(bits & 0x1000) 2414 if (!(bits & 0x1000)
2393 && skey->level == level 2415 && skey.level == level
2394 && level > smooth_max [skey->x][skey->y]) 2416 && level > smooth_max [skey.x][skey.y])
2395 { 2417 {
2396 maptex tex = self->tex [skey->tile]; 2418 maptex tex = self->tex [skey.tile];
2397 int px = (((int)skey->x) - 1) * Tw; 2419 int px = (((int)skey.x) - 1) * Tw;
2398 int py = (((int)skey->y) - 1) * Th; 2420 int py = (((int)skey.y) - 1) * Th;
2399 int border = bits & 15; 2421 int border = bits & 15;
2400 int corner = (bits >> 8) & ~(bits >> 4) & 15; 2422 int corner = (bits >> 8) & ~(bits >> 4) & 15;
2401 float dx = tex.s * .0625f; // 16 images/row 2423 float dx = tex.s * .0625f; // 16 images/row
2402 float dy = tex.t * .5f ; // 2 images/column 2424 float dy = tex.t * .5f ; // 2 images/column
2403 2425
2405 { 2427 {
2406 // this time avoiding texture state changes 2428 // this time avoiding texture state changes
2407 // save gobs of state changes. 2429 // save gobs of state changes.
2408 if (key.texname != tex.name) 2430 if (key.texname != tex.name)
2409 { 2431 {
2410 self->tex [skey->tile].unused = 0; 2432 self->tex [skey.tile].unused = 0;
2411 2433
2412 glEnd (); 2434 glEnd ();
2413 glBindTexture (GL_TEXTURE_2D, key.texname = tex.name); 2435 glBindTexture (GL_TEXTURE_2D, key.texname = tex.name);
2414 glBegin (GL_QUADS); 2436 glBegin (GL_QUADS);
2415 } 2437 }
2441 2463
2442 glEnd (); 2464 glEnd ();
2443 glDisable (GL_TEXTURE_2D); 2465 glDisable (GL_TEXTURE_2D);
2444 key.texname = -1; 2466 key.texname = -1;
2445 } 2467 }
2446
2447 hv_clear (smooth);
2448 } 2468 }
2449 2469
2450 if (pl_tex.name) 2470 if (pl_tex.name)
2451 { 2471 {
2452 maptex tex = pl_tex; 2472 maptex tex = pl_tex;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines