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.404 by root, Wed May 4 07:36:41 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)
1483 1485
1484 const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE) 1486 const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE)
1485 1487
1486 const_iv (SK_EXP_ADD_SKILL) const_iv (SK_EXP_TOTAL) const_iv (SK_EXP_NONE) 1488 const_iv (SK_EXP_ADD_SKILL) const_iv (SK_EXP_TOTAL) const_iv (SK_EXP_NONE)
1487 const_iv (SK_SUBTRACT_SKILL_EXP) const_iv (SK_EXP_SKILL_ONLY) 1489 const_iv (SK_SUBTRACT_SKILL_EXP) const_iv (SK_EXP_SKILL_ONLY)
1488
1489 const_iv (MAP_ACTIVE) const_iv (MAP_SWAPPED) const_iv (MAP_LOADING) const_iv (MAP_SAVING)
1490 const_iv (MAP_INACTIVE)
1491 1490
1492 const_iv (KLASS_ATTACHABLE) const_iv (KLASS_GLOBAL) const_iv (KLASS_OBJECT) 1491 const_iv (KLASS_ATTACHABLE) const_iv (KLASS_GLOBAL) const_iv (KLASS_OBJECT)
1493 const_iv (KLASS_CLIENT) const_iv (KLASS_PLAYER) const_iv (KLASS_MAP) 1492 const_iv (KLASS_CLIENT) const_iv (KLASS_PLAYER) const_iv (KLASS_MAP)
1494 1493
1495 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT) 1494 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT)
1554 for_all_clients (ns) 1553 for_all_clients (ns)
1555 ns->reattach (); 1554 ns->reattach ();
1556 1555
1557 for_all_objects (op) 1556 for_all_objects (op)
1558 op->reattach (); 1557 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} 1558}
1602 1559
1603void init_anim () 1560void init_anim ()
1604 1561
1605void init_globals () 1562void init_globals ()
1775 1732
1776int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) 1733int mlockall (int flags = MCL_CURRENT | MCL_FUTURE)
1777 INIT: 1734 INIT:
1778#if __GLIBC__ 1735#if __GLIBC__
1779 mallopt (M_TOP_PAD, 1024 * 1024); 1736 mallopt (M_TOP_PAD, 1024 * 1024);
1780 mallopt (M_MMAP_THRESHOLD, 1024 * 1024 * 128); 1737 mallopt (M_MMAP_THRESHOLD, 1024 * 1024);
1781 mallopt (M_MMAP_MAX, 0); // likely bug-workaround, also frees memory 1738 mallopt (M_MMAP_MAX, 0); // likely bug-workaround, also frees memory
1739 if (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 10))
1782 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc 1740 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc
1783#endif 1741#endif
1784 1742
1785int munlockall () 1743int munlockall ()
1786 1744
1787#endif 1745#endif
1825int exp_to_level (val64 exp) 1783int exp_to_level (val64 exp)
1826 1784
1827val64 level_to_min_exp (int level) 1785val64 level_to_min_exp (int level)
1828 1786
1829SV * 1787SV *
1830resistance_to_string (int atnr) 1788attacktype_name (int atnr)
1831 CODE: 1789 CODE:
1832 if (atnr >= 0 && atnr < NROFATTACKS) 1790 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1791 ? newSVpv (attacktype_name [atnr], 0)
1792 : &PL_sv_undef;
1793 OUTPUT: RETVAL
1794
1795SV *
1796attacktype_desc (int atnr)
1797 CODE:
1798 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1799 ? newSVpv (attacktype_desc [atnr], 0)
1800 : &PL_sv_undef;
1801 OUTPUT: RETVAL
1802
1803SV *
1804resist_plus (int atnr)
1805 CODE:
1806 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1833 RETVAL = newSVpv (resist_plus[atnr], 0); 1807 ? newSVpv (resist_plus [atnr], 0)
1834 else 1808 : &PL_sv_undef;
1835 XSRETURN_UNDEF; 1809 OUTPUT: RETVAL
1810
1811SV *
1812change_resist_msg (int atnr)
1813 CODE:
1814 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1815 ? newSVpv (change_resist_msg [atnr], 0)
1816 : &PL_sv_undef;
1836 OUTPUT: RETVAL 1817 OUTPUT: RETVAL
1837 1818
1838UUID 1819UUID
1839uuid_cur () 1820uuid_cur ()
1840 CODE: 1821 CODE:
1963int mortals_size () 1944int mortals_size ()
1964 CODE: 1945 CODE:
1965 RETVAL = attachable::mortals.size (); 1946 RETVAL = attachable::mortals.size ();
1966 OUTPUT: RETVAL 1947 OUTPUT: RETVAL
1967 1948
1968const_utf8_string slot_use_name (U32 slot) 1949const_utf8_string slot_name (U32 slot)
1969 ALIAS: 1950 ALIAS:
1951 slot_name = 0
1952 slot_use_name = 1
1970 slot_nonuse_name = 1 1953 slot_nonuse_name = 2
1971 CODE: 1954 CODE:
1972{ 1955{
1973 if (slot >= NUM_BODY_LOCATIONS) 1956 if (slot >= NUM_BODY_LOCATIONS)
1974 croak ("body slot index out of range"); 1957 croak ("body slot index out of range");
1975 1958
1976 switch (ix) 1959 switch (ix)
1977 { 1960 {
1961 case 0: RETVAL = body_locations[slot].name ; break;
1978 case 0: RETVAL = body_locations[slot].use_name; break; 1962 case 1: RETVAL = body_locations[slot].use_name ; break;
1979 case 1: RETVAL = body_locations[slot].nonuse_name; break; 1963 case 2: RETVAL = body_locations[slot].nonuse_name; break;
1980 } 1964 }
1981} 1965}
1982 OUTPUT: 1966 OUTPUT:
1983 RETVAL 1967 RETVAL
1984 1968
2116# dumb kludgy misdesigned plug-in api slowly gets on my nerves. 2100# dumb kludgy misdesigned plug-in api slowly gets on my nerves.
2117 2101
2118object *new (utf8_string archetype = 0) 2102object *new (utf8_string archetype = 0)
2119 PROTOTYPE: ;$ 2103 PROTOTYPE: ;$
2120 CODE: 2104 CODE:
2121 RETVAL = archetype ? get_archetype (archetype) : object::create (); 2105 RETVAL = archetype
2106 ? archetype::get (archetype)
2107 : object::create ();
2122 OUTPUT: 2108 OUTPUT:
2123 RETVAL 2109 RETVAL
2124 2110
2125object *generate (utf8_string arch, object *creator) 2111object *generate (utf8_string arch, object *creator)
2126 CODE: 2112 CODE:
2127 object *obj = get_archetype (arch); 2113 object *obj = archetype::get (arch);
2128 fix_generated_item (obj, creator, 0, 0, GT_MINIMAL); 2114 fix_generated_item (obj, creator, 0, 0, GT_MINIMAL);
2129 RETVAL = obj; 2115 RETVAL = obj;
2130 OUTPUT: 2116 OUTPUT:
2131 RETVAL 2117 RETVAL
2132 2118
2145 RETVAL = 0; 2131 RETVAL = 0;
2146} 2132}
2147 2133
2148shstr 2134shstr
2149object::kv_get (shstr key) 2135object::kv_get (shstr key)
2136 CODE:
2137 RETVAL = THIS->kv.get (key);
2138 OUTPUT:
2139 RETVAL
2150 2140
2151void 2141void
2152object::kv_del (shstr key) 2142object::kv_del (shstr key)
2143 CODE:
2144 THIS->kv.del (key);
2153 2145
2154void 2146void
2155object::kv_set (shstr key, shstr value) 2147object::kv_set (shstr key, shstr value)
2148 CODE:
2149 THIS->kv.set (key, value);
2156 2150
2157object *get_nearest_player (object *ob) 2151object *get_nearest_player (object *ob)
2158 ALIAS: nearest_player = 0 2152 ALIAS: nearest_player = 0
2159 PREINIT: 2153 PREINIT:
2160 extern object *get_nearest_player (object *); 2154 extern object *get_nearest_player (object *);
2363 if (pl->ob && pl->ob->map == THIS) 2357 if (pl->ob && pl->ob->map == THIS)
2364 PUSHs (sv_2mortal (to_sv (pl->ob))); 2358 PUSHs (sv_2mortal (to_sv (pl->ob)));
2365 } 2359 }
2366 2360
2367void 2361void
2362maptile::gen_quadmap (int x, int y, int z)
2363 CODE:
2364 gen_quadmap (THIS, x * 50, y * 50, z);
2365
2366void
2368maptile::add_underlay (SV *data, int offset, int stride, SV *palette) 2367maptile::add_underlay (SV *data, int offset, int stride, SV *palette)
2369 CODE: 2368 CODE:
2370{ 2369{
2371 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV) 2370 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV)
2372 croak ("maptile::add_underlay: palette must be arrayref"); 2371 croak ("maptile::add_underlay: palette must be arrayref");
2388 2387
2389 if (IN_RANGE_EXC (offs, 0, idxlen)) 2388 if (IN_RANGE_EXC (offs, 0, idxlen))
2390 { 2389 {
2391 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) 2390 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0))
2392 { 2391 {
2393 object *ob = get_archetype (cfSvPVutf8_nolen (*elem)); 2392 object *ob = archetype::get (cfSvPVutf8_nolen (*elem));
2394 ob->flag [FLAG_NO_MAP_SAVE] = true; 2393 ob->flag [FLAG_NO_MAP_SAVE] = true;
2395 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); 2394 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY);
2396 2395
2397 if (ob->randomitems && !ob->above) 2396 if (ob->randomitems && !ob->above)
2398 { 2397 {
2402 op->flag [FLAG_NO_MAP_SAVE] = true; 2401 op->flag [FLAG_NO_MAP_SAVE] = true;
2403 // TODO: if this is a pickable object, then the item 2402 // TODO: if this is a pickable object, then the item
2404 // will at a bit weird - saving inside the player 2403 // will at a bit weird - saving inside the player
2405 // will clear the flag, but when the player drops 2404 // will clear the flag, but when the player drops
2406 // it without logging out, it keeps the flag. 2405 // it without logging out, it keeps the flag.
2407 // nobody ahs reported this, but this can be rather 2406 // nobody has reported this, but this can be rather
2408 // annoying on persistent maps. 2407 // annoying on persistent maps.
2409 } 2408 }
2410 } 2409 }
2411 } 2410 }
2412 } 2411 }
2413
2414 skip: ; 2412 skip: ;
2415 } 2413 }
2416} 2414}
2417 2415
2418void 2416void
2449 for (int x = 0; x < THIS->width; ++x) 2447 for (int x = 0; x < THIS->width; ++x)
2450 for (int y = 0; y < THIS->height; ++y) 2448 for (int y = 0; y < THIS->height; ++y)
2451 { 2449 {
2452 region *rgn = THIS->region (x, y); 2450 region *rgn = THIS->region (x, y);
2453 2451
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) 2452 if (object *op = THIS->at (x, y).top)
2456 if (rgn->treasure && rndm () < rgn->treasure_density) 2453 if (rgn->treasure && rndm () < rgn->treasure_density)
2457 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty); 2454 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty);
2458 } 2455 }
2459 2456
2723 2720
2724void set_data (faceidx idx, int faceset, SV *data, SV *chksum) 2721void set_data (faceidx idx, int faceset, SV *data, SV *chksum)
2725 CODE: 2722 CODE:
2726{ 2723{
2727 faceinfo *f = face_info (idx); assert (f); 2724 faceinfo *f = face_info (idx); assert (f);
2728 facedata *d = &(faceset ? f->data64 : f->data32); 2725 facedata *d = f->face + faceset;
2729 sv_to (data, d->data); 2726 sv_to (data, d->data);
2730 STRLEN clen; 2727 STRLEN clen;
2731 char *cdata = SvPVbyte (chksum, clen); 2728 char *cdata = SvPVbyte (chksum, clen);
2732 clen = min (CHKSUM_MAXLEN, clen); 2729 clen = min (CHKSUM_MAXLEN, clen);
2733 2730
2887 self->skip (); 2884 self->skip ();
2888 } 2885 }
2889 2886
2890MODULE = cf PACKAGE = cf::layout 2887MODULE = cf PACKAGE = cf::layout
2891 2888
2892INCLUDE: $PERL $srcdir/genacc layout $srcdir/../random_maps/random_map.h | 2889INCLUDE: $PERL $srcdir/genacc layout $srcdir/../include/rmg.h |
2893 2890

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines