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.388 by root, Wed Jun 30 01:57:54 2010 UTC vs.
Revision 1.400 by root, Sat Apr 23 04:46:27 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
84 *stash_cf_client_wrap, 85 *stash_cf_client_wrap,
85 *stash_cf_arch_wrap, 86 *stash_cf_arch_wrap,
86 *stash_cf_party_wrap, 87 *stash_cf_party_wrap,
87 *stash_cf_region_wrap, 88 *stash_cf_region_wrap,
88 *stash_cf_living_wrap, 89 *stash_cf_living_wrap,
90 *stash_cf_layout_wrap,
89 *stash_ext_map_world; 91 *stash_ext_map_world;
90 92
91static SV 93static SV
92 *cv_cf_do_invoke, 94 *cv_cf_do_invoke,
93 *cv_cf__can_merge, 95 *cv_cf__can_merge,
539static inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); } 541static inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); }
540static inline SV *to_sv (region * v) { return newSVattachable (v, stash_cf_region_wrap); } 542static inline SV *to_sv (region * v) { return newSVattachable (v, stash_cf_region_wrap); }
541static inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); } 543static inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); }
542static inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } 544static inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); }
543static inline SV *to_sv (mapspace * v) { return newSVptr (v, stash_cf_mapspace_wrap); } 545static inline SV *to_sv (mapspace * v) { return newSVptr (v, stash_cf_mapspace_wrap); }
546static inline SV *to_sv (layout * v) { return newSVptr (v, stash_cf_layout_wrap); }
544 547
545static inline SV *to_sv (object & v) { return to_sv (&v); } 548static inline SV *to_sv (object & v) { return to_sv (&v); }
546static inline SV *to_sv (living & v) { return to_sv (&v); } 549static inline SV *to_sv (living & v) { return to_sv (&v); }
547 550
548static inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); } 551static inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); }
594static inline void sv_to (SV *sv, region * &v) { v = (region *) (attachable *)SvPTR_ornull (sv, "cf::region"); } 597static inline void sv_to (SV *sv, region * &v) { v = (region *) (attachable *)SvPTR_ornull (sv, "cf::region"); }
595static inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } 598static inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); }
596static inline void sv_to (SV *sv, partylist * &v) { v = (partylist *) SvPTR_ornull (sv, "cf::party"); } 599static inline void sv_to (SV *sv, partylist * &v) { v = (partylist *) SvPTR_ornull (sv, "cf::party"); }
597static inline void sv_to (SV *sv, living * &v) { v = (living *) SvPTR_ornull (sv, "cf::living"); } 600static inline void sv_to (SV *sv, living * &v) { v = (living *) SvPTR_ornull (sv, "cf::living"); }
598static inline void sv_to (SV *sv, mapspace * &v) { v = (mapspace *) SvPTR_ornull (sv, "cf::mapspace"); } 601static inline void sv_to (SV *sv, mapspace * &v) { v = (mapspace *) SvPTR_ornull (sv, "cf::mapspace"); }
602static inline void sv_to (SV *sv, layout * &v) { v = (layout *) SvPTR_ornull (sv, "cf::layout"); }
599static inline void sv_to (SV *sv, object_freezer * &v) { v = (object_freezer *) SvPTR_ornull (sv, "cf::object::freezer"); } 603static inline void sv_to (SV *sv, object_freezer * &v) { v = (object_freezer *) SvPTR_ornull (sv, "cf::object::freezer"); }
600static inline void sv_to (SV *sv, object_thawer * &v) { v = (object_thawer *) SvPTR_ornull (sv, "cf::object::thawer" ); } 604static inline void sv_to (SV *sv, object_thawer * &v) { v = (object_thawer *) SvPTR_ornull (sv, "cf::object::thawer" ); }
601 605
602//static inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; } 606//static inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; }
603static inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); } 607static inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); }
1397 stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1); 1401 stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1);
1398 stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1); 1402 stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1);
1399 stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1); 1403 stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1);
1400 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); 1404 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1);
1401 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1); 1405 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1);
1406 stash_cf_layout_wrap = gv_stashpv ("cf::layout::wrap", 1);
1402 stash_ext_map_world = gv_stashpv ("ext::map_world" , 1); 1407 stash_ext_map_world = gv_stashpv ("ext::map_world" , 1);
1403 1408
1404 sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV); 1409 sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV);
1405 sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV); 1410 sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV);
1406 sv_tick_start = get_sv ("cf::TICK_START", 1); SvUPGRADE (sv_tick_start, SVt_NV); 1411 sv_tick_start = get_sv ("cf::TICK_START", 1); SvUPGRADE (sv_tick_start, SVt_NV);
1455# include "attackinc.h" 1460# include "attackinc.h"
1456# undef def 1461# undef def
1457# define def(uc, flags) const_iv (SK_ ## uc) 1462# define def(uc, flags) const_iv (SK_ ## uc)
1458# include "skillinc.h" 1463# include "skillinc.h"
1459# undef def 1464# undef def
1460 1465# define def(name, use, nonuse) const_iv (body_ ## name)
1461 const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd) 1466# include "slotinc.h"
1467# undef def
1462 1468
1463 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) 1469 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y)
1464 1470
1465 const_iv (MAX_TIME) 1471 const_iv (MAX_TIME)
1466 const_iv (MAXSOCKBUF) 1472 const_iv (MAXSOCKBUF)
1550 for_all_clients (ns) 1556 for_all_clients (ns)
1551 ns->reattach (); 1557 ns->reattach ();
1552 1558
1553 for_all_objects (op) 1559 for_all_objects (op)
1554 op->reattach (); 1560 op->reattach ();
1555}
1556
1557# support function for map-world.ext
1558void _quantise (SV *data_sv, SV *plt_sv)
1559 CODE:
1560{
1561 if (!SvROK (plt_sv) || SvTYPE (SvRV (plt_sv)) != SVt_PVAV)
1562 croak ("_quantise called with invalid agruments");
1563
1564 plt_sv = SvRV (plt_sv);
1565 SV **plt = AvARRAY (plt_sv);
1566 int plt_count = AvFILL (plt_sv) + 1;
1567
1568 STRLEN len;
1569 char *data = SvPVbyte (data_sv, len);
1570 char *dst = data;
1571
1572 while (len >= 3)
1573 {
1574 for (SV **val_sv = plt + plt_count; val_sv-- > plt; )
1575 {
1576 char *val = SvPVX (*val_sv);
1577
1578 if (val [0] == data [0]
1579 && val [1] == data [1]
1580 && val [2] == data [2])
1581 {
1582 *dst++ = val [3];
1583 goto next;
1584 }
1585 }
1586
1587 croak ("_quantise: color not found in palette: #%02x%02x%02x, at offset %d %d",
1588 (uint8_t)data [0], (uint8_t)data [1], (uint8_t)data [2],
1589 dst - SvPVX (data_sv), len);
1590
1591 next:
1592 data += 3;
1593 len -= 3;
1594 }
1595
1596 SvCUR_set (data_sv, dst - SvPVX (data_sv));
1597} 1561}
1598 1562
1599void init_anim () 1563void init_anim ()
1600 1564
1601void init_globals () 1565void init_globals ()
1771 1735
1772int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) 1736int mlockall (int flags = MCL_CURRENT | MCL_FUTURE)
1773 INIT: 1737 INIT:
1774#if __GLIBC__ 1738#if __GLIBC__
1775 mallopt (M_TOP_PAD, 1024 * 1024); 1739 mallopt (M_TOP_PAD, 1024 * 1024);
1776 mallopt (M_MMAP_THRESHOLD, 1024 * 1024 * 128); 1740 mallopt (M_MMAP_THRESHOLD, 1024 * 1024);
1777 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))
1778 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc 1743 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc
1779#endif 1744#endif
1780 1745
1781int munlockall () 1746int munlockall ()
1782 1747
1783#endif 1748#endif
1821int exp_to_level (val64 exp) 1786int exp_to_level (val64 exp)
1822 1787
1823val64 level_to_min_exp (int level) 1788val64 level_to_min_exp (int level)
1824 1789
1825SV * 1790SV *
1826resistance_to_string (int atnr) 1791attacktype_name (int atnr)
1827 CODE: 1792 CODE:
1828 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)
1829 RETVAL = newSVpv (resist_plus[atnr], 0); 1810 ? newSVpv (resist_plus [atnr], 0)
1830 else 1811 : &PL_sv_undef;
1831 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;
1832 OUTPUT: RETVAL 1820 OUTPUT: RETVAL
1833 1821
1834UUID 1822UUID
1835uuid_cur () 1823uuid_cur ()
1836 CODE: 1824 CODE:
1959int mortals_size () 1947int mortals_size ()
1960 CODE: 1948 CODE:
1961 RETVAL = attachable::mortals.size (); 1949 RETVAL = attachable::mortals.size ();
1962 OUTPUT: RETVAL 1950 OUTPUT: RETVAL
1963 1951
1964const_utf8_string slot_use_name (U32 slot) 1952const_utf8_string slot_name (U32 slot)
1965 ALIAS: 1953 ALIAS:
1954 slot_name = 0
1955 slot_use_name = 1
1966 slot_nonuse_name = 1 1956 slot_nonuse_name = 2
1967 CODE: 1957 CODE:
1968{ 1958{
1969 if (slot >= NUM_BODY_LOCATIONS) 1959 if (slot >= NUM_BODY_LOCATIONS)
1970 croak ("body slot index out of range"); 1960 croak ("body slot index out of range");
1971 1961
1972 switch (ix) 1962 switch (ix)
1973 { 1963 {
1964 case 0: RETVAL = body_locations[slot].name ; break;
1974 case 0: RETVAL = body_locations[slot].use_name; break; 1965 case 1: RETVAL = body_locations[slot].use_name ; break;
1975 case 1: RETVAL = body_locations[slot].nonuse_name; break; 1966 case 2: RETVAL = body_locations[slot].nonuse_name; break;
1976 } 1967 }
1977} 1968}
1978 OUTPUT: 1969 OUTPUT:
1979 RETVAL 1970 RETVAL
1980 1971
2359 if (pl->ob && pl->ob->map == THIS) 2350 if (pl->ob && pl->ob->map == THIS)
2360 PUSHs (sv_2mortal (to_sv (pl->ob))); 2351 PUSHs (sv_2mortal (to_sv (pl->ob)));
2361 } 2352 }
2362 2353
2363void 2354void
2355maptile::add_quadland (int mx, int my, int mz, SV *biome_map, SV *biome_plt)
2356 CODE:
2357{
2358 static frac_gen<vec2d> frac;
2359
2360 if (!SvROK (biome_plt) || SvTYPE (SvRV (biome_plt)) != SVt_PVAV)
2361 croak ("maptile::add_quadland: biome_plt must be arrayref");
2362
2363 biome_plt = SvRV (biome_plt);
2364
2365 const uint8_t *bmap = (const uint8_t *)SvPVbyte_nolen (biome_map);
2366
2367 for (int x = 0; x < THIS->width; ++x)
2368 for (int y = 0; y < THIS->height; ++y)
2369 {
2370 for (object *op = THIS->at (x, y).bot; op; op = op->above)
2371 if (op->flag [FLAG_IS_FLOOR])
2372 goto skip;
2373
2374 {
2375 float fx = mx * THIS->width + x;
2376 float fy = my * THIS->height + y;
2377
2378 int temp = clamp (int (32 * frac.fBm (vec2d (fx * 0.001, fy * 0.001), 2) ) - 8, 0, 15);
2379 int rain = clamp (int (16 * frac.ridgedmultifractal (vec2d (fx * 0.01, fy * 0.01), 3, 1.03, 2)) - 8, 0, 15);
2380
2381 rain = lerp (rain, 0, 15, 0, temp);
2382 printf ("rain %d\n", temp);//D
2383
2384 int biome = bmap [rain * 16 + temp];
2385
2386 //printf ("%2d %2d => %s\n", temp, rain, SvPV_nolen (AvARRAY ((AV *)biome_plt)[biome]));//D
2387#if 1
2388 if (SV **elem = av_fetch ((AV *)biome_plt, bmap [rain * 16 + temp], 0))
2389 {
2390 object *ob = get_archetype (cfSvPVutf8_nolen (*elem));
2391 ob->flag [FLAG_NO_MAP_SAVE] = true;
2392 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY);
2393
2394 if (ob->randomitems && !ob->above)
2395 {
2396 ob->create_treasure (ob->randomitems);
2397
2398 for (object *op = ob->above; op; op = op->above)
2399 op->flag [FLAG_NO_MAP_SAVE] = true;
2400 }
2401 }
2402#endif
2403 }
2404 skip: ;
2405 }
2406}
2407
2408void
2364maptile::add_underlay (SV *data, int offset, int stride, SV *palette) 2409maptile::add_underlay (SV *data, int offset, int stride, SV *palette)
2365 CODE: 2410 CODE:
2366{ 2411{
2367 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV) 2412 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV)
2368 croak ("maptile::add_underlay: palette must be arrayref"); 2413 croak ("maptile::add_underlay: palette must be arrayref");
2398 op->flag [FLAG_NO_MAP_SAVE] = true; 2443 op->flag [FLAG_NO_MAP_SAVE] = true;
2399 // TODO: if this is a pickable object, then the item 2444 // TODO: if this is a pickable object, then the item
2400 // will at a bit weird - saving inside the player 2445 // will at a bit weird - saving inside the player
2401 // will clear the flag, but when the player drops 2446 // will clear the flag, but when the player drops
2402 // it without logging out, it keeps the flag. 2447 // it without logging out, it keeps the flag.
2403 // nobody ahs reported this, but this can be rather 2448 // nobody has reported this, but this can be rather
2404 // annoying on persistent maps. 2449 // annoying on persistent maps.
2405 } 2450 }
2406 } 2451 }
2407 } 2452 }
2408 } 2453 }
2409
2410 skip: ; 2454 skip: ;
2411 } 2455 }
2412} 2456}
2413 2457
2414void 2458void
2445 for (int x = 0; x < THIS->width; ++x) 2489 for (int x = 0; x < THIS->width; ++x)
2446 for (int y = 0; y < THIS->height; ++y) 2490 for (int y = 0; y < THIS->height; ++y)
2447 { 2491 {
2448 region *rgn = THIS->region (x, y); 2492 region *rgn = THIS->region (x, y);
2449 2493
2450 //fprintf (stderr, "%d,%d %f %p\n", x, y, rgn->treasure_density,rgn->treasure);//D
2451 if (object *op = THIS->at (x, y).top) 2494 if (object *op = THIS->at (x, y).top)
2452 if (rgn->treasure && rndm () < rgn->treasure_density) 2495 if (rgn->treasure && rndm () < rgn->treasure_density)
2453 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty); 2496 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty);
2454 } 2497 }
2455 2498
2534} 2577}
2535 OUTPUT: RETVAL 2578 OUTPUT: RETVAL
2536 2579
2537# worst xs function of my life 2580# worst xs function of my life
2538bool 2581bool
2539_create_random_map (\ 2582_create_random_map (maptile *self, SV *options)
2540 maptile *self,\
2541 SV *options,\
2542 val64 total_map_hp,\
2543 region *region\
2544)
2545 CODE: 2583 CODE:
2546{ 2584{
2547 random_map_params rmp; 2585 random_map_params rmp ((HV *)SvRV (options));
2548
2549 rmp.hv = (HV *)SvREFCNT_inc_NN (SvRV (options));
2550
2551 assign (rmp.wall_name , rmp.get_str ("wall_name"));
2552 assign (rmp.monsterstyle , rmp.get_str ("monsterstyle"));
2553 assign (rmp.layoutstyle , rmp.get_str ("layoutstyle"));
2554 assign (rmp.doorstyle , rmp.get_str ("doorstyle"));
2555 assign (rmp.exit_on_final_map, rmp.get_str ("exit_on_final_map"));
2556
2557 rmp.origin_map = rmp.get_str ("origin_map");
2558 rmp.origin_x = rmp.get_iv ("origin_x");
2559 rmp.origin_y = rmp.get_iv ("origin_y");
2560 rmp.final_map = rmp.get_str ("final_map");
2561 rmp.this_map = rmp.get_str ("this_map");
2562 rmp.xsize = rmp.get_iv ("xsize");
2563 rmp.ysize = rmp.get_iv ("ysize");
2564 rmp.expand2x = rmp.get_iv ("expand2x");
2565 rmp.layoutoptions1 = rmp.get_iv ("layoutoptions1");
2566 rmp.layoutoptions2 = rmp.get_iv ("layoutoptions2");
2567 rmp.layoutoptions3 = rmp.get_iv ("layoutoptions3");
2568 rmp.symmetry = rmp.get_iv ("symmetry");
2569 rmp.difficulty = rmp.get_iv ("difficulty");
2570 rmp.difficulty_given = rmp.get_iv ("difficulty_given");
2571 rmp.difficulty_increase = rmp.get_nv ("difficulty_increase");
2572 rmp.dungeon_level = rmp.get_iv ("dungeon_level");
2573 rmp.dungeon_depth = rmp.get_iv ("dungeon_depth");
2574 rmp.orientation = rmp.get_iv ("orientation");
2575 rmp.random_seed = rmp.get_uv ("random_seed");
2576 rmp.total_map_hp = (uint64_t)total_map_hp;
2577 rmp.map_layout_style = rmp.get_iv ("map_layout_style");
2578 rmp.symmetry_used = rmp.get_iv ("symmetry_used");
2579 rmp.region = region;
2580
2581 RETVAL = self->generate_random_map (&rmp); 2586 RETVAL = self->generate_random_map (&rmp);
2582} 2587}
2583 OUTPUT: 2588 OUTPUT:
2584 RETVAL 2589 RETVAL
2585 2590
2757 2762
2758void set_data (faceidx idx, int faceset, SV *data, SV *chksum) 2763void set_data (faceidx idx, int faceset, SV *data, SV *chksum)
2759 CODE: 2764 CODE:
2760{ 2765{
2761 faceinfo *f = face_info (idx); assert (f); 2766 faceinfo *f = face_info (idx); assert (f);
2762 facedata *d = &(faceset ? f->data64 : f->data32); 2767 facedata *d = f->face + faceset;
2763 sv_to (data, d->data); 2768 sv_to (data, d->data);
2764 STRLEN clen; 2769 STRLEN clen;
2765 char *cdata = SvPVbyte (chksum, clen); 2770 char *cdata = SvPVbyte (chksum, clen);
2766 clen = min (CHKSUM_MAXLEN, clen); 2771 clen = min (CHKSUM_MAXLEN, clen);
2767 2772
2919 XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ()))); 2924 XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ())));
2920 2925
2921 self->skip (); 2926 self->skip ();
2922 } 2927 }
2923 2928
2929MODULE = cf PACKAGE = cf::layout
2930
2931INCLUDE: $PERL $srcdir/genacc layout $srcdir/../include/rmg.h |
2932

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines