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.276 by root, Tue Apr 15 14:21:04 2008 UTC vs.
Revision 1.291 by root, Sun Jun 15 20:32:51 2008 UTC

21 * The authors can be reached via e-mail to <support@deliantra.net> 21 * The authors can be reached via e-mail to <support@deliantra.net>
22 */ 22 */
23 23
24#include "autoconf.h" 24#include "autoconf.h"
25 25
26#define PLUGIN_NAME "perl"
27#define PLUGIN_VERSION "cfperl 0.5"
28
29#if HAVE_EXECINFO_H 26#if HAVE_EXECINFO_H
30# include <execinfo.h> 27# include <execinfo.h>
31#endif 28#endif
32 29
33#include <cstdarg> 30#include <cstdarg>
43# include <sys/mman.h> 40# include <sys/mman.h>
44#endif 41#endif
45 42
46#if HAVE_MALLOC_H 43#if HAVE_MALLOC_H
47# include <malloc.h> 44# include <malloc.h>
45#endif
46
47#if !__GLIBC__
48# define malloc_trim(pad) -1
48#endif 49#endif
49 50
50#include <EXTERN.h> 51#include <EXTERN.h>
51#include <perl.h> 52#include <perl.h>
52#include <XSUB.h> 53#include <XSUB.h>
940 CALL_CALL ("ext::books::make_book", G_VOID); 941 CALL_CALL ("ext::books::make_book", G_VOID);
941 CALL_END; 942 CALL_END;
942} 943}
943 944
944void 945void
946cfperl_expand_cfpod (player *pl, std::string &msg)
947{
948 CALL_BEGIN (2);
949 CALL_ARG (pl);
950 CALL_ARG_SV (newSVpvn_utf8 (msg.data (), msg.size ()));
951 CALL_CALL ("cf::player::expand_cfpod", G_SCALAR);
952
953 if (count)
954 {
955 STRLEN len;
956 char *data = SvPVutf8 (TOPs, len);
957 msg.assign (data, len);
958 }
959
960 CALL_END;
961}
962
963void
945cfperl_send_msg (client *ns, int color, const char *type, const char *msg) 964cfperl_send_msg (client *ns, int color, const char *type, const char *msg)
946{ 965{
947 CALL_BEGIN (4); 966 CALL_BEGIN (4);
948 CALL_ARG (ns); 967 CALL_ARG (ns);
949 CALL_ARG (type); 968 CALL_ARG (type);
973{ 992{
974 CALL_BEGIN (1); 993 CALL_BEGIN (1);
975 CALL_ARG (name); 994 CALL_ARG (name);
976 CALL_CALL ("cf::player::find", G_SCALAR); 995 CALL_CALL ("cf::player::find", G_SCALAR);
977 996
978 player *retval; 997 player *retval = 0;
979
980 if (count)
981 sv_to (POPs, retval); 998 if (count) sv_to (POPs, retval);
982 else 999
983 retval = 0; 1000 CALL_END;
1001
1002 return retval;
1003}
1004
1005maptile *
1006find_style (const char *dirname, const char *stylename, int difficulty)
1007{
1008 CALL_BEGIN (3);
1009 CALL_ARG (dirname);
1010 CALL_ARG (stylename);
1011 CALL_ARG (difficulty);
1012 CALL_CALL ("ext::map_random::find_style", G_SCALAR);
1013
1014 maptile *retval = 0;
1015 if (count) sv_to (POPs, retval);
984 1016
985 CALL_END; 1017 CALL_END;
986 1018
987 return retval; 1019 return retval;
988} 1020}
993 CALL_BEGIN (2); 1025 CALL_BEGIN (2);
994 CALL_ARG (path); 1026 CALL_ARG (path);
995 CALL_ARG (origin); 1027 CALL_ARG (origin);
996 CALL_CALL ("cf::map::find_sync", G_SCALAR); 1028 CALL_CALL ("cf::map::find_sync", G_SCALAR);
997 1029
998 maptile *retval; 1030 maptile *retval = 0;
999
1000 if (count)
1001 sv_to (POPs, retval); 1031 if (count) sv_to (POPs, retval);
1002 else
1003 retval = 0;
1004 1032
1005 CALL_END; 1033 CALL_END;
1006 1034
1007 return retval; 1035 return retval;
1008} 1036}
1014 CALL_ARG (path); 1042 CALL_ARG (path);
1015 CALL_ARG (origin); 1043 CALL_ARG (origin);
1016 CALL_ARG (load); 1044 CALL_ARG (load);
1017 CALL_CALL ("cf::map::find_async", G_SCALAR); 1045 CALL_CALL ("cf::map::find_async", G_SCALAR);
1018 1046
1019 maptile *retval; 1047 maptile *retval = 0;
1020
1021 if (count)
1022 sv_to (POPs, retval); 1048 if (count) sv_to (POPs, retval);
1023 else
1024 retval = 0;
1025 1049
1026 CALL_END; 1050 CALL_END;
1027 1051
1028 return retval; 1052 return retval;
1029} 1053}
1054 1078
1055 CALL_BEGIN (2); 1079 CALL_BEGIN (2);
1056 CALL_ARG (this); 1080 CALL_ARG (this);
1057 CALL_ARG (exit); 1081 CALL_ARG (exit);
1058 CALL_CALL ("cf::object::player::enter_exit", G_VOID); 1082 CALL_CALL ("cf::object::player::enter_exit", G_VOID);
1083 CALL_END;
1084}
1085
1086void
1087object::player_goto (const char *path, int x, int y)
1088{
1089 if (type != PLAYER)
1090 return;
1091
1092 CALL_BEGIN (4);
1093 CALL_ARG (this);
1094 CALL_ARG (path);
1095 CALL_ARG (x);
1096 CALL_ARG (y);
1097 CALL_CALL ("cf::object::player::goto", G_VOID);
1059 CALL_END; 1098 CALL_END;
1060} 1099}
1061 1100
1062const char * 1101const char *
1063object::ref () const 1102object::ref () const
1428 1467
1429 const_iv (SYMMETRY_RANDOM) const_iv (SYMMETRY_NONE) const_iv (SYMMETRY_X) 1468 const_iv (SYMMETRY_RANDOM) const_iv (SYMMETRY_NONE) const_iv (SYMMETRY_X)
1430 const_iv (SYMMETRY_Y) const_iv (SYMMETRY_XY) 1469 const_iv (SYMMETRY_Y) const_iv (SYMMETRY_XY)
1431 1470
1432 const_iv (GT_ENVIRONMENT) const_iv (GT_INVISIBLE) const_iv (GT_STARTEQUIP) 1471 const_iv (GT_ENVIRONMENT) const_iv (GT_INVISIBLE) const_iv (GT_STARTEQUIP)
1433 const_iv (GT_APPLY) const_iv (GT_ONLY_GOOD) const_iv (GT_UPDATE_INV) 1472 const_iv (GT_APPLY) const_iv (GT_ONLY_GOOD) const_iv (GT_MINIMAL)
1434 const_iv (GT_MINIMAL)
1435 1473
1436 const_iv (FT_FACE) const_iv (FT_MUSIC) const_iv (FT_SOUND) 1474 const_iv (FT_FACE) const_iv (FT_MUSIC) const_iv (FT_SOUND)
1437 const_iv (FT_RSRC) const_iv (FT_NUM) 1475 const_iv (FT_RSRC) const_iv (FT_NUM)
1438 }; 1476 };
1439 1477
1570NV floor (NV x) 1608NV floor (NV x)
1571 1609
1572NV ceil (NV x) 1610NV ceil (NV x)
1573 1611
1574NV rndm (...) 1612NV rndm (...)
1613 ALIAS:
1614 rmg_rndm = 1
1575 CODE: 1615 CODE:
1616{
1617 rand_gen &gen = ix ? rmg_rndm : rndm;
1576 switch (items) 1618 switch (items)
1577 { 1619 {
1578 case 0: RETVAL = rndm (); break; 1620 case 0: RETVAL = gen (); break;
1579 case 1: RETVAL = rndm (SvUV (ST (0))); break; 1621 case 1: RETVAL = gen (SvUV (ST (0))); break;
1580 case 2: RETVAL = rndm (SvIV (ST (0)), SvIV (ST (1))); break; 1622 case 2: RETVAL = gen (SvIV (ST (0)), SvIV (ST (1))); break;
1581 default: croak ("cf::rndm requires none, one or two parameters."); break; 1623 default: croak ("cf::rndm requires none, one or two parameters."); break;
1582 } 1624 }
1625}
1583 OUTPUT: 1626 OUTPUT:
1584 RETVAL 1627 RETVAL
1585 1628
1586NV clamp (NV value, NV min_value, NV max_value) 1629NV clamp (NV value, NV min_value, NV max_value)
1587 CODE: 1630 CODE:
1612octet_string path_combine (octet_string base, octet_string path) 1655octet_string path_combine (octet_string base, octet_string path)
1613 PROTOTYPE: $$ 1656 PROTOTYPE: $$
1614 1657
1615octet_string path_combine_and_normalize (octet_string base, octet_string path) 1658octet_string path_combine_and_normalize (octet_string base, octet_string path)
1616 PROTOTYPE: $$ 1659 PROTOTYPE: $$
1617
1618void
1619mallinfo ()
1620 PPCODE:
1621{
1622#if __GLIBC__
1623 struct mallinfo mai = mallinfo ();
1624 EXTEND (SP, 10*2);
1625 PUSHs (sv_2mortal (newSVpv ("arena" , 0))); PUSHs (sv_2mortal (newSViv (mai.arena)));
1626 PUSHs (sv_2mortal (newSVpv ("ordblks" , 0))); PUSHs (sv_2mortal (newSViv (mai.ordblks)));
1627 PUSHs (sv_2mortal (newSVpv ("smblks" , 0))); PUSHs (sv_2mortal (newSViv (mai.smblks)));
1628 PUSHs (sv_2mortal (newSVpv ("hblks" , 0))); PUSHs (sv_2mortal (newSViv (mai.hblks)));
1629 PUSHs (sv_2mortal (newSVpv ("hblkhd" , 0))); PUSHs (sv_2mortal (newSViv (mai.hblkhd)));
1630 PUSHs (sv_2mortal (newSVpv ("usmblks" , 0))); PUSHs (sv_2mortal (newSViv (mai.usmblks)));
1631 PUSHs (sv_2mortal (newSVpv ("fsmblks" , 0))); PUSHs (sv_2mortal (newSViv (mai.fsmblks)));
1632 PUSHs (sv_2mortal (newSVpv ("uordblks", 0))); PUSHs (sv_2mortal (newSViv (mai.uordblks)));
1633 PUSHs (sv_2mortal (newSVpv ("fordblks", 0))); PUSHs (sv_2mortal (newSViv (mai.fordblks)));
1634 PUSHs (sv_2mortal (newSVpv ("keepcost", 0))); PUSHs (sv_2mortal (newSViv (mai.keepcost)));
1635#endif
1636 EXTEND (SP, 2*2);
1637 PUSHs (sv_2mortal (newSVpv ("slice_alloc", 0))); PUSHs (sv_2mortal (newSVuv (slice_alloc)));
1638 PUSHs (sv_2mortal (newSVpv ("shstr_alloc", 0))); PUSHs (sv_2mortal (newSVuv (shstr_alloc)));
1639}
1640 1660
1641void 1661void
1642sub_generation_inc () 1662sub_generation_inc ()
1643 CODE: 1663 CODE:
1644 PL_sub_generation++; 1664 PL_sub_generation++;
1681 1701
1682#if _POSIX_MEMLOCK 1702#if _POSIX_MEMLOCK
1683 1703
1684int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) 1704int mlockall (int flags = MCL_CURRENT | MCL_FUTURE)
1685 INIT: 1705 INIT:
1706#if __GLIBC__
1686 mallopt (M_PERTURB, 0xaa); // bug-workaround for linux glibc+mlockall+calloc 1707 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc
1708#endif
1687 1709
1688int munlockall () 1710int munlockall ()
1689 1711
1690#endif 1712#endif
1713
1714int
1715malloc_trim (IV pad = 0)
1716
1717void
1718mallinfo ()
1719 PPCODE:
1720{
1721#if __GLIBC__
1722 struct mallinfo mai = mallinfo ();
1723 EXTEND (SP, 10*2);
1724 PUSHs (sv_2mortal (newSVpv ("arena" , 0))); PUSHs (sv_2mortal (newSViv (mai.arena)));
1725 PUSHs (sv_2mortal (newSVpv ("ordblks" , 0))); PUSHs (sv_2mortal (newSViv (mai.ordblks)));
1726 PUSHs (sv_2mortal (newSVpv ("smblks" , 0))); PUSHs (sv_2mortal (newSViv (mai.smblks)));
1727 PUSHs (sv_2mortal (newSVpv ("hblks" , 0))); PUSHs (sv_2mortal (newSViv (mai.hblks)));
1728 PUSHs (sv_2mortal (newSVpv ("hblkhd" , 0))); PUSHs (sv_2mortal (newSViv (mai.hblkhd)));
1729 PUSHs (sv_2mortal (newSVpv ("usmblks" , 0))); PUSHs (sv_2mortal (newSViv (mai.usmblks)));
1730 PUSHs (sv_2mortal (newSVpv ("fsmblks" , 0))); PUSHs (sv_2mortal (newSViv (mai.fsmblks)));
1731 PUSHs (sv_2mortal (newSVpv ("uordblks", 0))); PUSHs (sv_2mortal (newSViv (mai.uordblks)));
1732 PUSHs (sv_2mortal (newSVpv ("fordblks", 0))); PUSHs (sv_2mortal (newSViv (mai.fordblks)));
1733 PUSHs (sv_2mortal (newSVpv ("keepcost", 0))); PUSHs (sv_2mortal (newSViv (mai.keepcost)));
1734#endif
1735 EXTEND (SP, 2*2);
1736 PUSHs (sv_2mortal (newSVpv ("slice_alloc", 0))); PUSHs (sv_2mortal (newSVuv (slice_alloc)));
1737 PUSHs (sv_2mortal (newSVpv ("shstr_alloc", 0))); PUSHs (sv_2mortal (newSVuv (shstr_alloc)));
1738 PUSHs (sv_2mortal (newSVpv ("objects" , 0))); PUSHs (sv_2mortal (newSVuv (objects.size () * sizeof (object))));
1739}
1691 1740
1692int find_animation (utf8_string text) 1741int find_animation (utf8_string text)
1693 PROTOTYPE: $ 1742 PROTOTYPE: $
1694 1743
1695int random_roll (int min, int max, object *op, int goodbad); 1744int random_roll (int min, int max, object *op, int goodbad);
1776 EXTEND (SP, NUM_COINS); 1825 EXTEND (SP, NUM_COINS);
1777 for (int i = 0; i < NUM_COINS; ++i) 1826 for (int i = 0; i < NUM_COINS; ++i)
1778 PUSHs (sv_2mortal (to_sv (archetype::find (coins [i])))); 1827 PUSHs (sv_2mortal (to_sv (archetype::find (coins [i]))));
1779 1828
1780bool 1829bool
1781load_resource_file (octet_string filename) 1830load_resource_file_ (octet_string filename)
1831
1832void
1833fix_weight ()
1782 1834
1783MODULE = cf PACKAGE = cf::attachable 1835MODULE = cf PACKAGE = cf::attachable
1784 1836
1785int 1837int
1786valid (SV *obj) 1838valid (SV *obj)
1850object *actives (U32 index) 1902object *actives (U32 index)
1851 CODE: 1903 CODE:
1852 RETVAL = index < actives.size () ? actives [index] : 0; 1904 RETVAL = index < actives.size () ? actives [index] : 0;
1853 OUTPUT: RETVAL 1905 OUTPUT: RETVAL
1854 1906
1907int mortals_size ()
1908 CODE:
1909 RETVAL = attachable::mortals.size ();
1910 OUTPUT: RETVAL
1911
1855const char *slot_use_name (U32 slot) 1912const char *slot_use_name (U32 slot)
1856 ALIAS: 1913 ALIAS:
1857 slot_nonuse_name = 1 1914 slot_nonuse_name = 1
1858 CODE: 1915 CODE:
1859{ 1916{
1937void apply_below (object *op) 1994void apply_below (object *op)
1938 CODE: 1995 CODE:
1939 player_apply_below (op); 1996 player_apply_below (op);
1940 1997
1941int cast_heal (object *op, object *caster, object *spell, int dir = 0) 1998int cast_heal (object *op, object *caster, object *spell, int dir = 0)
1942
1943#//TODO
1944object *clone_ (object *op, int recursive = 0)
1945 CODE:
1946 if (recursive)
1947 RETVAL = object_create_clone (op);
1948 else
1949 {
1950 RETVAL = object::create ();
1951 op->copy_to (RETVAL);
1952 }
1953 OUTPUT: RETVAL
1954 1999
1955int pay_item (object *op, object *buyer) 2000int pay_item (object *op, object *buyer)
1956 CODE: 2001 CODE:
1957 RETVAL = pay_for_item (op, buyer); 2002 RETVAL = pay_for_item (op, buyer);
1958 OUTPUT: RETVAL 2003 OUTPUT: RETVAL
2036 CODE: 2081 CODE:
2037{ 2082{
2038 RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y); 2083 RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y);
2039} 2084}
2040 2085
2041const_utf8_string get_ob_key_value (object *op, utf8_string key) 2086shstr
2087object::kv_get (shstr key)
2042 2088
2043bool set_ob_key_value (object *op, utf8_string key, utf8_string value = 0, int add_key = 1) 2089void
2090object::kv_del (shstr key)
2091
2092void
2093object::kv_set (shstr key, shstr value)
2044 2094
2045object *get_nearest_player (object *ob) 2095object *get_nearest_player (object *ob)
2046 ALIAS: nearest_player = 0 2096 ALIAS: nearest_player = 0
2047 PREINIT: 2097 PREINIT:
2048 extern object *get_nearest_player (object *); 2098 extern object *get_nearest_player (object *);
2050void rangevector (object *ob, object *other, int flags = 0) 2100void rangevector (object *ob, object *other, int flags = 0)
2051 PROTOTYPE: $$;$ 2101 PROTOTYPE: $$;$
2052 PPCODE: 2102 PPCODE:
2053{ 2103{
2054 rv_vector rv; 2104 rv_vector rv;
2105
2106 PUTBACK;
2055 get_rangevector (ob, other, &rv, flags); 2107 get_rangevector (ob, other, &rv, flags);
2108 SPAGAIN;
2109
2056 EXTEND (SP, 5); 2110 EXTEND (SP, 5);
2057 PUSHs (newSVuv (rv.distance)); 2111 PUSHs (newSVuv (rv.distance));
2058 PUSHs (newSViv (rv.distance_x)); 2112 PUSHs (newSViv (rv.distance_x));
2059 PUSHs (newSViv (rv.distance_y)); 2113 PUSHs (newSViv (rv.distance_y));
2060 PUSHs (newSViv (rv.direction)); 2114 PUSHs (newSViv (rv.direction));
2069const_utf8_string 2123const_utf8_string
2070base_name (object *op, int plural = op->nrof > 1) 2124base_name (object *op, int plural = op->nrof > 1)
2071 CODE: 2125 CODE:
2072 RETVAL = query_base_name (op, plural); 2126 RETVAL = query_base_name (op, plural);
2073 OUTPUT: RETVAL 2127 OUTPUT: RETVAL
2074
2075object *decrease_ob_nr (object *op, unsigned long i)
2076 2128
2077# return the tail of an object, excluding itself 2129# return the tail of an object, excluding itself
2078void 2130void
2079tail (object *op) 2131tail (object *op)
2080 PPCODE: 2132 PPCODE:
2369get_map_flags (maptile *map, int x, int y) 2421get_map_flags (maptile *map, int x, int y)
2370 PPCODE: 2422 PPCODE:
2371{ 2423{
2372 maptile *nmap = 0; 2424 maptile *nmap = 0;
2373 I16 nx = 0, ny = 0; 2425 I16 nx = 0, ny = 0;
2426
2427 PUTBACK;
2374 int flags = get_map_flags (map, &nmap, x, y, &nx, &ny); 2428 int flags = get_map_flags (map, &nmap, x, y, &nx, &ny);
2429 SPAGAIN;
2375 2430
2376 EXTEND (SP, 4); 2431 EXTEND (SP, 4);
2377 PUSHs (sv_2mortal (newSViv (flags))); 2432 PUSHs (sv_2mortal (newSViv (flags)));
2378 2433
2379 if (GIMME_V == G_ARRAY) 2434 if (GIMME_V == G_ARRAY)
2387void 2442void
2388at (maptile *map, unsigned int x, unsigned int y) 2443at (maptile *map, unsigned int x, unsigned int y)
2389 PROTOTYPE: $$$ 2444 PROTOTYPE: $$$
2390 PPCODE: 2445 PPCODE:
2391{ 2446{
2392 object *o;
2393 maptile *nmap = 0; 2447 maptile *nmap = 0;
2394 I16 nx, ny; 2448 I16 nx, ny;
2395 2449
2450 PUTBACK;
2396 get_map_flags (map, &nmap, x, y, &nx, &ny); 2451 get_map_flags (map, &nmap, x, y, &nx, &ny);
2452 SPAGAIN;
2397 2453
2398 if (nmap) 2454 if (nmap)
2399 for (o = GET_MAP_OB (nmap, nx, ny); o; o = o->above) 2455 for (object *o = nmap->at (nx, ny).bot; o; o = o->above)
2400 XPUSHs (sv_2mortal (to_sv (o))); 2456 XPUSHs (sv_2mortal (to_sv (o)));
2401} 2457}
2402 2458
2403SV * 2459SV *
2404bot_at (maptile *obj, unsigned int x, unsigned int y) 2460bot_at (maptile *obj, unsigned int x, unsigned int y)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines