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.391 by root, Sat Jul 3 01:49:18 2010 UTC vs.
Revision 1.402 by root, Sun May 1 13:18:24 2011 UTC

28 28
29#include <cstdarg> 29#include <cstdarg>
30#include <typeinfo> 30#include <typeinfo>
31 31
32#include "global.h" 32#include "global.h"
33#include "../random_maps/random_map.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
1459# include "attackinc.h" 1460# include "attackinc.h"
1460# undef def 1461# undef def
1461# define def(uc, flags) const_iv (SK_ ## uc) 1462# define def(uc, flags) const_iv (SK_ ## uc)
1462# include "skillinc.h" 1463# include "skillinc.h"
1463# undef def 1464# undef def
1464 1465# define def(name, use, nonuse) const_iv (body_ ## name)
1465 const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd) 1466# include "slotinc.h"
1467# undef def
1466 1468
1467 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) 1469 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y)
1468 1470
1469 const_iv (MAX_TIME) 1471 const_iv (MAX_TIME)
1470 const_iv (MAXSOCKBUF) 1472 const_iv (MAXSOCKBUF)
1554 for_all_clients (ns) 1556 for_all_clients (ns)
1555 ns->reattach (); 1557 ns->reattach ();
1556 1558
1557 for_all_objects (op) 1559 for_all_objects (op)
1558 op->reattach (); 1560 op->reattach ();
1559}
1560
1561# support function for map-world.ext
1562void _quantise (SV *data_sv, SV *plt_sv)
1563 CODE:
1564{
1565 if (!SvROK (plt_sv) || SvTYPE (SvRV (plt_sv)) != SVt_PVAV)
1566 croak ("_quantise called with invalid agruments");
1567
1568 plt_sv = SvRV (plt_sv);
1569 SV **plt = AvARRAY (plt_sv);
1570 int plt_count = AvFILL (plt_sv) + 1;
1571
1572 STRLEN len;
1573 char *data = SvPVbyte (data_sv, len);
1574 char *dst = data;
1575
1576 while (len >= 3)
1577 {
1578 for (SV **val_sv = plt + plt_count; val_sv-- > plt; )
1579 {
1580 char *val = SvPVX (*val_sv);
1581
1582 if (val [0] == data [0]
1583 && val [1] == data [1]
1584 && val [2] == data [2])
1585 {
1586 *dst++ = val [3];
1587 goto next;
1588 }
1589 }
1590
1591 croak ("_quantise: color not found in palette: #%02x%02x%02x, at offset %d %d",
1592 (uint8_t)data [0], (uint8_t)data [1], (uint8_t)data [2],
1593 dst - SvPVX (data_sv), len);
1594
1595 next:
1596 data += 3;
1597 len -= 3;
1598 }
1599
1600 SvCUR_set (data_sv, dst - SvPVX (data_sv));
1601} 1561}
1602 1562
1603void init_anim () 1563void init_anim ()
1604 1564
1605void init_globals () 1565void init_globals ()
1775 1735
1776int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) 1736int mlockall (int flags = MCL_CURRENT | MCL_FUTURE)
1777 INIT: 1737 INIT:
1778#if __GLIBC__ 1738#if __GLIBC__
1779 mallopt (M_TOP_PAD, 1024 * 1024); 1739 mallopt (M_TOP_PAD, 1024 * 1024);
1780 mallopt (M_MMAP_THRESHOLD, 1024 * 1024 * 128); 1740 mallopt (M_MMAP_THRESHOLD, 1024 * 1024);
1781 mallopt (M_MMAP_MAX, 0); // likely bug-workaround, also frees memory 1741 mallopt (M_MMAP_MAX, 0); // likely bug-workaround, also frees memory
1742 if (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 10))
1782 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc 1743 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc
1783#endif 1744#endif
1784 1745
1785int munlockall () 1746int munlockall ()
1786 1747
1787#endif 1748#endif
1825int exp_to_level (val64 exp) 1786int exp_to_level (val64 exp)
1826 1787
1827val64 level_to_min_exp (int level) 1788val64 level_to_min_exp (int level)
1828 1789
1829SV * 1790SV *
1830resistance_to_string (int atnr) 1791attacktype_name (int atnr)
1831 CODE: 1792 CODE:
1832 if (atnr >= 0 && atnr < NROFATTACKS) 1793 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1794 ? newSVpv (attacktype_name [atnr], 0)
1795 : &PL_sv_undef;
1796 OUTPUT: RETVAL
1797
1798SV *
1799attacktype_desc (int atnr)
1800 CODE:
1801 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1802 ? newSVpv (attacktype_desc [atnr], 0)
1803 : &PL_sv_undef;
1804 OUTPUT: RETVAL
1805
1806SV *
1807resist_plus (int atnr)
1808 CODE:
1809 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1833 RETVAL = newSVpv (resist_plus[atnr], 0); 1810 ? newSVpv (resist_plus [atnr], 0)
1834 else 1811 : &PL_sv_undef;
1835 XSRETURN_UNDEF; 1812 OUTPUT: RETVAL
1813
1814SV *
1815change_resist_msg (int atnr)
1816 CODE:
1817 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1818 ? newSVpv (change_resist_msg [atnr], 0)
1819 : &PL_sv_undef;
1836 OUTPUT: RETVAL 1820 OUTPUT: RETVAL
1837 1821
1838UUID 1822UUID
1839uuid_cur () 1823uuid_cur ()
1840 CODE: 1824 CODE:
1963int mortals_size () 1947int mortals_size ()
1964 CODE: 1948 CODE:
1965 RETVAL = attachable::mortals.size (); 1949 RETVAL = attachable::mortals.size ();
1966 OUTPUT: RETVAL 1950 OUTPUT: RETVAL
1967 1951
1968const_utf8_string slot_use_name (U32 slot) 1952const_utf8_string slot_name (U32 slot)
1969 ALIAS: 1953 ALIAS:
1954 slot_name = 0
1955 slot_use_name = 1
1970 slot_nonuse_name = 1 1956 slot_nonuse_name = 2
1971 CODE: 1957 CODE:
1972{ 1958{
1973 if (slot >= NUM_BODY_LOCATIONS) 1959 if (slot >= NUM_BODY_LOCATIONS)
1974 croak ("body slot index out of range"); 1960 croak ("body slot index out of range");
1975 1961
1976 switch (ix) 1962 switch (ix)
1977 { 1963 {
1964 case 0: RETVAL = body_locations[slot].name ; break;
1978 case 0: RETVAL = body_locations[slot].use_name; break; 1965 case 1: RETVAL = body_locations[slot].use_name ; break;
1979 case 1: RETVAL = body_locations[slot].nonuse_name; break; 1966 case 2: RETVAL = body_locations[slot].nonuse_name; break;
1980 } 1967 }
1981} 1968}
1982 OUTPUT: 1969 OUTPUT:
1983 RETVAL 1970 RETVAL
1984 1971
2145 RETVAL = 0; 2132 RETVAL = 0;
2146} 2133}
2147 2134
2148shstr 2135shstr
2149object::kv_get (shstr key) 2136object::kv_get (shstr key)
2137 CODE:
2138 RETVAL = THIS->kv.get (key);
2139 OUTPUT:
2140 RETVAL
2150 2141
2151void 2142void
2152object::kv_del (shstr key) 2143object::kv_del (shstr key)
2144 CODE:
2145 THIS->kv.del (key);
2153 2146
2154void 2147void
2155object::kv_set (shstr key, shstr value) 2148object::kv_set (shstr key, shstr value)
2149 CODE:
2150 THIS->kv.set (key, value);
2156 2151
2157object *get_nearest_player (object *ob) 2152object *get_nearest_player (object *ob)
2158 ALIAS: nearest_player = 0 2153 ALIAS: nearest_player = 0
2159 PREINIT: 2154 PREINIT:
2160 extern object *get_nearest_player (object *); 2155 extern object *get_nearest_player (object *);
2362 for_all_players (pl) 2357 for_all_players (pl)
2363 if (pl->ob && pl->ob->map == THIS) 2358 if (pl->ob && pl->ob->map == THIS)
2364 PUSHs (sv_2mortal (to_sv (pl->ob))); 2359 PUSHs (sv_2mortal (to_sv (pl->ob)));
2365 } 2360 }
2366 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
2367void 2420void
2368maptile::add_underlay (SV *data, int offset, int stride, SV *palette) 2421maptile::add_underlay (SV *data, int offset, int stride, SV *palette)
2369 CODE: 2422 CODE:
2370{ 2423{
2371 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV) 2424 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV)
2402 op->flag [FLAG_NO_MAP_SAVE] = true; 2455 op->flag [FLAG_NO_MAP_SAVE] = true;
2403 // TODO: if this is a pickable object, then the item 2456 // TODO: if this is a pickable object, then the item
2404 // will at a bit weird - saving inside the player 2457 // will at a bit weird - saving inside the player
2405 // will clear the flag, but when the player drops 2458 // will clear the flag, but when the player drops
2406 // it without logging out, it keeps the flag. 2459 // it without logging out, it keeps the flag.
2407 // nobody ahs reported this, but this can be rather 2460 // nobody has reported this, but this can be rather
2408 // annoying on persistent maps. 2461 // annoying on persistent maps.
2409 } 2462 }
2410 } 2463 }
2411 } 2464 }
2412 } 2465 }
2413
2414 skip: ; 2466 skip: ;
2415 } 2467 }
2416} 2468}
2417 2469
2418void 2470void
2449 for (int x = 0; x < THIS->width; ++x) 2501 for (int x = 0; x < THIS->width; ++x)
2450 for (int y = 0; y < THIS->height; ++y) 2502 for (int y = 0; y < THIS->height; ++y)
2451 { 2503 {
2452 region *rgn = THIS->region (x, y); 2504 region *rgn = THIS->region (x, y);
2453 2505
2454 //fprintf (stderr, "%d,%d %f %p\n", x, y, rgn->treasure_density,rgn->treasure);//D
2455 if (object *op = THIS->at (x, y).top) 2506 if (object *op = THIS->at (x, y).top)
2456 if (rgn->treasure && rndm () < rgn->treasure_density) 2507 if (rgn->treasure && rndm () < rgn->treasure_density)
2457 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty); 2508 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty);
2458 } 2509 }
2459 2510
2723 2774
2724void set_data (faceidx idx, int faceset, SV *data, SV *chksum) 2775void set_data (faceidx idx, int faceset, SV *data, SV *chksum)
2725 CODE: 2776 CODE:
2726{ 2777{
2727 faceinfo *f = face_info (idx); assert (f); 2778 faceinfo *f = face_info (idx); assert (f);
2728 facedata *d = &(faceset ? f->data64 : f->data32); 2779 facedata *d = f->face + faceset;
2729 sv_to (data, d->data); 2780 sv_to (data, d->data);
2730 STRLEN clen; 2781 STRLEN clen;
2731 char *cdata = SvPVbyte (chksum, clen); 2782 char *cdata = SvPVbyte (chksum, clen);
2732 clen = min (CHKSUM_MAXLEN, clen); 2783 clen = min (CHKSUM_MAXLEN, clen);
2733 2784
2887 self->skip (); 2938 self->skip ();
2888 } 2939 }
2889 2940
2890MODULE = cf PACKAGE = cf::layout 2941MODULE = cf PACKAGE = cf::layout
2891 2942
2892INCLUDE: $PERL $srcdir/genacc layout $srcdir/../random_maps/random_map.h | 2943INCLUDE: $PERL $srcdir/genacc layout $srcdir/../include/rmg.h |
2893 2944

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines