ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/cfperl.xs
(Generate patch)

Comparing deliantra/server/server/cfperl.xs (file contents):
Revision 1.396 by root, Sun Jan 23 23:35:30 2011 UTC vs.
Revision 1.402 by root, Sun May 1 13:18:24 2011 UTC

29#include <cstdarg> 29#include <cstdarg>
30#include <typeinfo> 30#include <typeinfo>
31 31
32#include "global.h" 32#include "global.h"
33#include "rmg.h" 33#include "rmg.h"
34#include "noise.h"
34#include "evthread.h" 35#include "evthread.h"
35#include "sproto.h" 36#include "sproto.h"
36 37
37#include <unistd.h> 38#include <unistd.h>
38#if _POSIX_MEMLOCK 39#if _POSIX_MEMLOCK
1557 1558
1558 for_all_objects (op) 1559 for_all_objects (op)
1559 op->reattach (); 1560 op->reattach ();
1560} 1561}
1561 1562
1562# support function for map-world.ext
1563void _quantise (SV *data_sv, SV *plt_sv)
1564 CODE:
1565{
1566 if (!SvROK (plt_sv) || SvTYPE (SvRV (plt_sv)) != SVt_PVAV)
1567 croak ("_quantise called with invalid agruments");
1568
1569 plt_sv = SvRV (plt_sv);
1570 SV **plt = AvARRAY (plt_sv);
1571 int plt_count = AvFILL (plt_sv) + 1;
1572
1573 STRLEN len;
1574 char *data = SvPVbyte (data_sv, len);
1575 char *dst = data;
1576
1577 while (len >= 3)
1578 {
1579 for (SV **val_sv = plt + plt_count; val_sv-- > plt; )
1580 {
1581 char *val = SvPVX (*val_sv);
1582
1583 if (val [0] == data [0]
1584 && val [1] == data [1]
1585 && val [2] == data [2])
1586 {
1587 *dst++ = val [3];
1588 goto next;
1589 }
1590 }
1591
1592 croak ("_quantise: color not found in palette: #%02x%02x%02x, at offset %d %d",
1593 (uint8_t)data [0], (uint8_t)data [1], (uint8_t)data [2],
1594 dst - SvPVX (data_sv), len);
1595
1596 next:
1597 data += 3;
1598 len -= 3;
1599 }
1600
1601 SvCUR_set (data_sv, dst - SvPVX (data_sv));
1602}
1603
1604void init_anim () 1563void init_anim ()
1605 1564
1606void init_globals () 1565void init_globals ()
1607 1566
1608void init_attackmess () 1567void init_attackmess ()
1778 INIT: 1737 INIT:
1779#if __GLIBC__ 1738#if __GLIBC__
1780 mallopt (M_TOP_PAD, 1024 * 1024); 1739 mallopt (M_TOP_PAD, 1024 * 1024);
1781 mallopt (M_MMAP_THRESHOLD, 1024 * 1024); 1740 mallopt (M_MMAP_THRESHOLD, 1024 * 1024);
1782 mallopt (M_MMAP_MAX, 0); // likely bug-workaround, also frees memory 1741 mallopt (M_MMAP_MAX, 0); // likely bug-workaround, also frees memory
1783 if (__GLIBC_MAJOR < 2 || (__GLIBC_MAJOR == 2 && __GLIBC_MINOR < 10)) 1742 if (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 10))
1784 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc 1743 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc
1785#endif 1744#endif
1786 1745
1787int munlockall () 1746int munlockall ()
1788 1747
2173 RETVAL = 0; 2132 RETVAL = 0;
2174} 2133}
2175 2134
2176shstr 2135shstr
2177object::kv_get (shstr key) 2136object::kv_get (shstr key)
2137 CODE:
2138 RETVAL = THIS->kv.get (key);
2139 OUTPUT:
2140 RETVAL
2178 2141
2179void 2142void
2180object::kv_del (shstr key) 2143object::kv_del (shstr key)
2144 CODE:
2145 THIS->kv.del (key);
2181 2146
2182void 2147void
2183object::kv_set (shstr key, shstr value) 2148object::kv_set (shstr key, shstr value)
2149 CODE:
2150 THIS->kv.set (key, value);
2184 2151
2185object *get_nearest_player (object *ob) 2152object *get_nearest_player (object *ob)
2186 ALIAS: nearest_player = 0 2153 ALIAS: nearest_player = 0
2187 PREINIT: 2154 PREINIT:
2188 extern object *get_nearest_player (object *); 2155 extern object *get_nearest_player (object *);
2390 for_all_players (pl) 2357 for_all_players (pl)
2391 if (pl->ob && pl->ob->map == THIS) 2358 if (pl->ob && pl->ob->map == THIS)
2392 PUSHs (sv_2mortal (to_sv (pl->ob))); 2359 PUSHs (sv_2mortal (to_sv (pl->ob)));
2393 } 2360 }
2394 2361
2362#if 0
2363
2364void
2365maptile::add_quadland (int mx, int my, int mz, SV *biome_map, SV *biome_plt)
2366 CODE:
2367{
2368 static frac_gen<vec2d> frac;
2369
2370 if (!SvROK (biome_plt) || SvTYPE (SvRV (biome_plt)) != SVt_PVAV)
2371 croak ("maptile::add_quadland: biome_plt must be arrayref");
2372
2373 biome_plt = SvRV (biome_plt);
2374
2375 const uint8_t *bmap = (const uint8_t *)SvPVbyte_nolen (biome_map);
2376
2377 for (int x = 0; x < THIS->width; ++x)
2378 for (int y = 0; y < THIS->height; ++y)
2379 {
2380 for (object *op = THIS->at (x, y).bot; op; op = op->above)
2381 if (op->flag [FLAG_IS_FLOOR])
2382 goto skip;
2383
2384 {
2385 float fx = mx * THIS->width + x;
2386 float fy = my * THIS->height + y;
2387
2388 int temp = clamp (int (32 * frac.fBm (vec2d (fx * 0.001, fy * 0.001), 2) ) - 8, 0, 15);
2389 int rain = clamp (int (16 * frac.ridgedmultifractal (vec2d (fx * 0.01, fy * 0.01), 3, 1.03, 2)) - 8, 0, 15);
2390
2391 rain = lerp (rain, 0, 15, 0, temp);
2392 printf ("rain %d\n", temp);//D
2393
2394 int biome = bmap [rain * 16 + temp];
2395
2396 //printf ("%2d %2d => %s\n", temp, rain, SvPV_nolen (AvARRAY ((AV *)biome_plt)[biome]));//D
2397#if 1
2398 if (SV **elem = av_fetch ((AV *)biome_plt, bmap [rain * 16 + temp], 0))
2399 {
2400 object *ob = get_archetype (cfSvPVutf8_nolen (*elem));
2401 ob->flag [FLAG_NO_MAP_SAVE] = true;
2402 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY);
2403
2404 if (ob->randomitems && !ob->above)
2405 {
2406 ob->create_treasure (ob->randomitems);
2407
2408 for (object *op = ob->above; op; op = op->above)
2409 op->flag [FLAG_NO_MAP_SAVE] = true;
2410 }
2411 }
2412#endif
2413 }
2414 skip: ;
2415 }
2416}
2417
2418#endif
2419
2395void 2420void
2396maptile::add_underlay (SV *data, int offset, int stride, SV *palette) 2421maptile::add_underlay (SV *data, int offset, int stride, SV *palette)
2397 CODE: 2422 CODE:
2398{ 2423{
2399 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV) 2424 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV)
2430 op->flag [FLAG_NO_MAP_SAVE] = true; 2455 op->flag [FLAG_NO_MAP_SAVE] = true;
2431 // TODO: if this is a pickable object, then the item 2456 // TODO: if this is a pickable object, then the item
2432 // will at a bit weird - saving inside the player 2457 // will at a bit weird - saving inside the player
2433 // will clear the flag, but when the player drops 2458 // will clear the flag, but when the player drops
2434 // it without logging out, it keeps the flag. 2459 // it without logging out, it keeps the flag.
2435 // nobody ahs reported this, but this can be rather 2460 // nobody has reported this, but this can be rather
2436 // annoying on persistent maps. 2461 // annoying on persistent maps.
2437 } 2462 }
2438 } 2463 }
2439 } 2464 }
2440 } 2465 }
2441
2442 skip: ; 2466 skip: ;
2443 } 2467 }
2444} 2468}
2445 2469
2446void 2470void
2477 for (int x = 0; x < THIS->width; ++x) 2501 for (int x = 0; x < THIS->width; ++x)
2478 for (int y = 0; y < THIS->height; ++y) 2502 for (int y = 0; y < THIS->height; ++y)
2479 { 2503 {
2480 region *rgn = THIS->region (x, y); 2504 region *rgn = THIS->region (x, y);
2481 2505
2482 //fprintf (stderr, "%d,%d %f %p\n", x, y, rgn->treasure_density,rgn->treasure);//D
2483 if (object *op = THIS->at (x, y).top) 2506 if (object *op = THIS->at (x, y).top)
2484 if (rgn->treasure && rndm () < rgn->treasure_density) 2507 if (rgn->treasure && rndm () < rgn->treasure_density)
2485 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty); 2508 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty);
2486 } 2509 }
2487 2510

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines