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.418 by root, Sun Nov 11 01:27:44 2012 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2006,2007,2008,2009,2010,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * 5 *
6 * Deliantra is free software: you can redistribute it and/or modify it under 6 * Deliantra is free software: you can redistribute it and/or modify it under
7 * the terms of the Affero GNU General Public License as published by the 7 * the terms of the Affero GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your 8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version. 9 * option) any later version.
10 * 10 *
11 * This program is distributed in the hope that it will be useful, 11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 * 15 *
16 * You should have received a copy of the Affero GNU General Public License 16 * You should have received a copy of the Affero GNU General Public License
17 * and the GNU General Public License along with this program. If not, see 17 * and the GNU General Public License along with this program. If not, see
18 * <http://www.gnu.org/licenses/>. 18 * <http://www.gnu.org/licenses/>.
19 * 19 *
20 * The authors can be reached via e-mail to <support@deliantra.net> 20 * The authors can be reached via e-mail to <support@deliantra.net>
21 */ 21 */
22 22
23#include "autoconf.h" 23#include "autoconf.h"
24 24
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
66static int tick_inhibit; 67static int tick_inhibit;
67static int tick_pending; 68static int tick_pending;
68 69
69global gbl_ev; 70global gbl_ev;
70static AV *cb_global, *cb_attachable, *cb_object, *cb_player, *cb_client, *cb_type, *cb_map; 71static AV *cb_global, *cb_attachable, *cb_object, *cb_player, *cb_client, *cb_type, *cb_map;
71static SV *sv_runtime, *sv_tick_start, *sv_next_tick, *sv_now; 72static SV *sv_runtime, *sv_tick_start, *sv_next_tick, *sv_now, *sv_server_tick;
72static AV *av_reflect; 73static AV *av_reflect;
73 74
74bitset<NUM_EVENT_TYPES> ev_want_event; 75bitset<NUM_EVENT_TYPES> ev_want_event;
75bitset<NUM_TYPES> ev_want_type; 76bitset<NUM_TYPES> ev_want_type;
76 77
252 { 253 {
253 static int last_mortalcount; 254 static int last_mortalcount;
254 if (mortals.size () != last_mortalcount) 255 if (mortals.size () != last_mortalcount)
255 { 256 {
256 last_mortalcount = mortals.size (); 257 last_mortalcount = mortals.size ();
257 LOG (llevInfo, "%d mortals.\n", (int)mortals.size ()); 258 object *specimen = is_a<object> (mortals [rndm (mortals.size ())]);
259
260 LOG (llevInfo, "%d mortals (random specimen: %s).\n",
261 (int)mortals.size (), specimen ? specimen->debug_desc () : "(not an object)");
258 262
259 if (0) 263 if (0)
260 { 264 {
261 for (int j = 0; j < mortals.size (); ++j)//D 265 for (int j = 0; j < mortals.size (); ++j)//D
262 fprintf (stderr, "%d:%s %p ", j, &((object *)mortals[j])->name, mortals[j]);//D 266 fprintf (stderr, "%d:%s %p ", j, &((object *)mortals[j])->name, mortals[j]);//D
621 STRLEN len; 625 STRLEN len;
622 char *data = SvPVbyte (sv, len); 626 char *data = SvPVbyte (sv, len);
623 v.assign (data, len); 627 v.assign (data, len);
624} 628}
625 629
630static inline void sv_to (SV *sv, refcnt_buf &v)
631{
632 STRLEN len;
633 char *data = SvPVbyte (sv, len);
634 refcnt_buf buf (data, len);
635 v = buf;
636}
637
626static inline void sv_to (SV *sv, UUID &v) 638static inline void sv_to (SV *sv, UUID &v)
627{ 639{
628 if (!v.parse (SvPV_nolen (sv))) 640 if (!v.parse (SvPV_nolen (sv)))
629 croak ("unparsable uuid: %s", SvPV_nolen (sv)); 641 croak ("unparsable uuid: %s", SvPV_nolen (sv));
630} 642}
1403 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); 1415 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1);
1404 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1); 1416 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1);
1405 stash_cf_layout_wrap = gv_stashpv ("cf::layout::wrap", 1); 1417 stash_cf_layout_wrap = gv_stashpv ("cf::layout::wrap", 1);
1406 stash_ext_map_world = gv_stashpv ("ext::map_world" , 1); 1418 stash_ext_map_world = gv_stashpv ("ext::map_world" , 1);
1407 1419
1408 sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV); 1420 sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV);
1409 sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV); 1421 sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV);
1422 sv_server_tick = get_sv ("cf::SERVER_TICK", 1); SvUPGRADE (sv_server_tick, SVt_IV);
1410 sv_tick_start = get_sv ("cf::TICK_START", 1); SvUPGRADE (sv_tick_start, SVt_NV); 1423 sv_tick_start = get_sv ("cf::TICK_START" , 1); SvUPGRADE (sv_tick_start , SVt_NV);
1411 sv_next_tick = get_sv ("cf::NEXT_TICK" , 1); SvUPGRADE (sv_next_tick , SVt_NV); 1424 sv_next_tick = get_sv ("cf::NEXT_TICK" , 1); SvUPGRADE (sv_next_tick , SVt_NV);
1412 1425
1413 cb_global = get_av ("cf::CB_GLOBAL", 1); 1426 cb_global = get_av ("cf::CB_GLOBAL", 1);
1414 cb_attachable = get_av ("cf::CB_ATTACHABLE", 1); 1427 cb_attachable = get_av ("cf::CB_ATTACHABLE", 1);
1415 cb_object = get_av ("cf::CB_OBJECT", 1); 1428 cb_object = get_av ("cf::CB_OBJECT", 1);
1416 cb_player = get_av ("cf::CB_PLAYER", 1); 1429 cb_player = get_av ("cf::CB_PLAYER", 1);
1459# include "attackinc.h" 1472# include "attackinc.h"
1460# undef def 1473# undef def
1461# define def(uc, flags) const_iv (SK_ ## uc) 1474# define def(uc, flags) const_iv (SK_ ## uc)
1462# include "skillinc.h" 1475# include "skillinc.h"
1463# undef def 1476# undef def
1464 1477# define def(name, use, nonuse) const_iv (body_ ## name)
1465 const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd) 1478# include "slotinc.h"
1479# undef def
1466 1480
1467 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) 1481 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y)
1468 1482
1469 const_iv (MAX_TIME) 1483 const_iv (MAX_TIME)
1470 const_iv (MAXSOCKBUF) 1484 const_iv (MAXSOCKBUF)
1483 1497
1484 const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE) 1498 const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE)
1485 1499
1486 const_iv (SK_EXP_ADD_SKILL) const_iv (SK_EXP_TOTAL) const_iv (SK_EXP_NONE) 1500 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) 1501 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 1502
1492 const_iv (KLASS_ATTACHABLE) const_iv (KLASS_GLOBAL) const_iv (KLASS_OBJECT) 1503 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) 1504 const_iv (KLASS_CLIENT) const_iv (KLASS_PLAYER) const_iv (KLASS_MAP)
1494 1505
1495 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT) 1506 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT)
1528 1539
1529void _gv_clear (SV *gv) 1540void _gv_clear (SV *gv)
1530 CODE: 1541 CODE:
1531 assert (SvTYPE (gv) == SVt_PVGV); 1542 assert (SvTYPE (gv) == SVt_PVGV);
1532# define f(sv) { SV *sv_ = (SV *)(sv); sv = 0; SvREFCNT_dec (sv_); } 1543# define f(sv) { SV *sv_ = (SV *)(sv); sv = 0; SvREFCNT_dec (sv_); }
1544 SvREFCNT_inc (gv);
1533 f (GvGP (gv)->gp_form); 1545 f (GvGP (gv)->gp_form);
1534 f (GvGP (gv)->gp_io); 1546 f (GvGP (gv)->gp_io);
1535 f (GvGP (gv)->gp_sv); 1547 f (GvGP (gv)->gp_sv);
1536 f (GvGP (gv)->gp_av); 1548 f (GvGP (gv)->gp_av);
1537 f (GvGP (gv)->gp_hv); 1549 f (GvGP (gv)->gp_hv);
1538 f (GvGP (gv)->gp_cv); 1550 f (GvGP (gv)->gp_cv);
1539 GvCVGEN (gv) = 0; 1551 GvCVGEN (gv) = 0;
1540 GvMULTI_off (gv); 1552 GvMULTI_off (gv);
1553 SvREFCNT_dec (gv);
1541# undef f 1554# undef f
1542 1555
1543void _connect_to_perl_1 () 1556void _connect_to_perl_1 ()
1544 1557
1545void _connect_to_perl_2 () 1558void _connect_to_perl_2 ()
1556 1569
1557 for_all_objects (op) 1570 for_all_objects (op)
1558 op->reattach (); 1571 op->reattach ();
1559} 1572}
1560 1573
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}
1602
1603void init_anim () 1574void init_anim ()
1604 1575
1605void init_globals () 1576void init_globals ()
1606 1577
1607void init_attackmess () 1578void init_attackmess ()
1608 1579
1609void init_dynamic () 1580void init_dynamic ()
1610 1581
1611void load_settings () 1582void load_settings ()
1612 1583
1613void reload_exp_table () 1584void _reload_exp_table ()
1614 1585
1615void reload_materials () 1586void _reload_materials ()
1616 1587
1617void init_uuid () 1588void init_uuid ()
1618 CODE: 1589 CODE:
1619 UUID::init (); 1590 UUID::init ();
1620 1591
1653 { 1624 {
1654 ev_async_send (EV_DEFAULT, &tick_watcher); 1625 ev_async_send (EV_DEFAULT, &tick_watcher);
1655 coroapi::cede (); 1626 coroapi::cede ();
1656 } 1627 }
1657 1628
1658void server_tick () 1629void one_tick ()
1659 CODE: 1630 CODE:
1660{ 1631{
1661 ev_now_update (EV_DEFAULT); 1632 ev_now_update (EV_DEFAULT);
1662 NOW = ev_now (EV_DEFAULT); 1633 NOW = ev_now (EV_DEFAULT);
1663 SvNV_set (sv_now, NOW); SvNOK_only (sv_now); 1634 SvNV_set (sv_now, NOW); SvNOK_only (sv_now);
1664 SvNV_set (sv_tick_start, NOW); SvNOK_only (sv_tick_start); 1635 SvNV_set (sv_tick_start, NOW); SvNOK_only (sv_tick_start);
1665 runtime = SvNVX (sv_runtime); 1636 runtime = SvNVX (sv_runtime);
1666 1637
1638 one_tick ();
1639
1667 server_tick (); 1640 ++server_tick;
1641 SvUV_set (sv_server_tick, server_tick); SvIOK_only_UV (sv_server_tick);
1668 1642
1669 ev_now_update (EV_DEFAULT); 1643 ev_now_update (EV_DEFAULT);
1670 NOW = ev_now (EV_DEFAULT); 1644 NOW = ev_now (EV_DEFAULT);
1671 SvNV_set (sv_now, NOW); SvNOK_only (sv_now); 1645 SvNV_set (sv_now, NOW); SvNOK_only (sv_now);
1646
1672 runtime += TICK; 1647 runtime += TICK;
1673 SvNV_set (sv_runtime, runtime); SvNOK_only (sv_runtime); 1648 SvNV_set (sv_runtime, runtime); SvNOK_only (sv_runtime);
1674} 1649}
1675 1650
1676NV floor (NV x) 1651NV floor (NV x)
1775 1750
1776int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) 1751int mlockall (int flags = MCL_CURRENT | MCL_FUTURE)
1777 INIT: 1752 INIT:
1778#if __GLIBC__ 1753#if __GLIBC__
1779 mallopt (M_TOP_PAD, 1024 * 1024); 1754 mallopt (M_TOP_PAD, 1024 * 1024);
1780 mallopt (M_MMAP_THRESHOLD, 1024 * 1024 * 128); 1755 mallopt (M_MMAP_THRESHOLD, 1024 * 1024);
1781 mallopt (M_MMAP_MAX, 0); // likely bug-workaround, also frees memory 1756 mallopt (M_MMAP_MAX, 0); // likely bug-workaround, also frees memory
1757 if (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 10))
1782 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc 1758 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc
1783#endif 1759#endif
1784 1760
1785int munlockall () 1761int munlockall ()
1786 1762
1787#endif 1763#endif
1824 1800
1825int exp_to_level (val64 exp) 1801int exp_to_level (val64 exp)
1826 1802
1827val64 level_to_min_exp (int level) 1803val64 level_to_min_exp (int level)
1828 1804
1805const_utf8_string
1806spellpathnames (int idx)
1807 CODE:
1808 RETVAL = spellpathnames [idx];
1809 OUTPUT: RETVAL
1810
1829SV * 1811SV *
1830resistance_to_string (int atnr) 1812attacktype_name (int atnr)
1831 CODE: 1813 CODE:
1832 if (atnr >= 0 && atnr < NROFATTACKS) 1814 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1815 ? newSVpv (attacktype_name [atnr], 0)
1816 : &PL_sv_undef;
1817 OUTPUT: RETVAL
1818
1819SV *
1820attacktype_desc (int atnr)
1821 CODE:
1822 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1823 ? newSVpv (attacktype_desc [atnr], 0)
1824 : &PL_sv_undef;
1825 OUTPUT: RETVAL
1826
1827SV *
1828resist_plus (int atnr)
1829 CODE:
1830 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1833 RETVAL = newSVpv (resist_plus[atnr], 0); 1831 ? newSVpv (resist_plus [atnr], 0)
1834 else 1832 : &PL_sv_undef;
1835 XSRETURN_UNDEF; 1833 OUTPUT: RETVAL
1834
1835SV *
1836change_resist_msg (int atnr)
1837 CODE:
1838 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1839 ? newSVpv (change_resist_msg [atnr], 0)
1840 : &PL_sv_undef;
1836 OUTPUT: RETVAL 1841 OUTPUT: RETVAL
1837 1842
1838UUID 1843UUID
1839uuid_cur () 1844uuid_cur ()
1840 CODE: 1845 CODE:
1963int mortals_size () 1968int mortals_size ()
1964 CODE: 1969 CODE:
1965 RETVAL = attachable::mortals.size (); 1970 RETVAL = attachable::mortals.size ();
1966 OUTPUT: RETVAL 1971 OUTPUT: RETVAL
1967 1972
1968const_utf8_string slot_use_name (U32 slot) 1973const_utf8_string slot_name (U32 slot)
1969 ALIAS: 1974 ALIAS:
1975 slot_name = 0
1976 slot_use_name = 1
1970 slot_nonuse_name = 1 1977 slot_nonuse_name = 2
1971 CODE: 1978 CODE:
1972{ 1979{
1973 if (slot >= NUM_BODY_LOCATIONS) 1980 if (slot >= NUM_BODY_LOCATIONS)
1974 croak ("body slot index out of range"); 1981 croak ("body slot index out of range");
1975 1982
1976 switch (ix) 1983 switch (ix)
1977 { 1984 {
1985 case 0: RETVAL = body_locations[slot].name ; break;
1978 case 0: RETVAL = body_locations[slot].use_name; break; 1986 case 1: RETVAL = body_locations[slot].use_name ; break;
1979 case 1: RETVAL = body_locations[slot].nonuse_name; break; 1987 case 2: RETVAL = body_locations[slot].nonuse_name; break;
1980 } 1988 }
1981} 1989}
1982 OUTPUT: 1990 OUTPUT:
1983 RETVAL 1991 RETVAL
1984 1992
2116# dumb kludgy misdesigned plug-in api slowly gets on my nerves. 2124# dumb kludgy misdesigned plug-in api slowly gets on my nerves.
2117 2125
2118object *new (utf8_string archetype = 0) 2126object *new (utf8_string archetype = 0)
2119 PROTOTYPE: ;$ 2127 PROTOTYPE: ;$
2120 CODE: 2128 CODE:
2121 RETVAL = archetype ? get_archetype (archetype) : object::create (); 2129 RETVAL = archetype
2130 ? archetype::get (archetype)
2131 : object::create ();
2122 OUTPUT: 2132 OUTPUT:
2123 RETVAL 2133 RETVAL
2124 2134
2125object *generate (utf8_string arch, object *creator) 2135object *generate (utf8_string arch, object *creator)
2126 CODE: 2136 CODE:
2127 object *obj = get_archetype (arch); 2137 object *obj = archetype::get (arch);
2128 fix_generated_item (obj, creator, 0, 0, GT_MINIMAL); 2138 fix_generated_item (obj, creator, 0, 0, GT_MINIMAL);
2129 RETVAL = obj; 2139 RETVAL = obj;
2130 OUTPUT: 2140 OUTPUT:
2131 RETVAL 2141 RETVAL
2132 2142
2142 RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y); 2152 RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y);
2143 2153
2144 if (RETVAL->destroyed ()) 2154 if (RETVAL->destroyed ())
2145 RETVAL = 0; 2155 RETVAL = 0;
2146} 2156}
2157 OUTPUT:
2158 RETVAL
2147 2159
2148shstr 2160shstr
2149object::kv_get (shstr key) 2161object::kv_get (shstr key)
2162 CODE:
2163 RETVAL = THIS->kv.get (key);
2164 OUTPUT:
2165 RETVAL
2150 2166
2151void 2167void
2152object::kv_del (shstr key) 2168object::kv_del (shstr key)
2169 CODE:
2170 THIS->kv.del (key);
2153 2171
2154void 2172void
2155object::kv_set (shstr key, shstr value) 2173object::kv_set (shstr key, shstr value)
2174 CODE:
2175 THIS->kv.set (key, value);
2156 2176
2157object *get_nearest_player (object *ob) 2177object *get_nearest_player (object *ob)
2158 ALIAS: nearest_player = 0 2178 ALIAS: nearest_player = 0
2159 PREINIT: 2179 PREINIT:
2160 extern object *get_nearest_player (object *); 2180 extern object *get_nearest_player (object *);
2363 if (pl->ob && pl->ob->map == THIS) 2383 if (pl->ob && pl->ob->map == THIS)
2364 PUSHs (sv_2mortal (to_sv (pl->ob))); 2384 PUSHs (sv_2mortal (to_sv (pl->ob)));
2365 } 2385 }
2366 2386
2367void 2387void
2388maptile::gen_quadmap (int x, int y, int z)
2389 CODE:
2390 gen_quadmap (THIS, x * 50, y * 50, z);
2391
2392void
2368maptile::add_underlay (SV *data, int offset, int stride, SV *palette) 2393maptile::add_underlay (SV *data, int offset, int stride, SV *palette)
2369 CODE: 2394 CODE:
2370{ 2395{
2371 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV) 2396 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV)
2372 croak ("maptile::add_underlay: palette must be arrayref"); 2397 croak ("maptile::add_underlay: palette must be arrayref");
2388 2413
2389 if (IN_RANGE_EXC (offs, 0, idxlen)) 2414 if (IN_RANGE_EXC (offs, 0, idxlen))
2390 { 2415 {
2391 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) 2416 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0))
2392 { 2417 {
2393 object *ob = get_archetype (cfSvPVutf8_nolen (*elem)); 2418 object *ob = archetype::get (cfSvPVutf8_nolen (*elem));
2394 ob->flag [FLAG_NO_MAP_SAVE] = true; 2419 ob->flag [FLAG_NO_MAP_SAVE] = true;
2395 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); 2420 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY);
2396 2421
2397 if (ob->randomitems && !ob->above) 2422 if (ob->randomitems && !ob->above)
2398 { 2423 {
2402 op->flag [FLAG_NO_MAP_SAVE] = true; 2427 op->flag [FLAG_NO_MAP_SAVE] = true;
2403 // TODO: if this is a pickable object, then the item 2428 // TODO: if this is a pickable object, then the item
2404 // will at a bit weird - saving inside the player 2429 // will at a bit weird - saving inside the player
2405 // will clear the flag, but when the player drops 2430 // will clear the flag, but when the player drops
2406 // it without logging out, it keeps the flag. 2431 // it without logging out, it keeps the flag.
2407 // nobody ahs reported this, but this can be rather 2432 // nobody has reported this, but this can be rather
2408 // annoying on persistent maps. 2433 // annoying on persistent maps.
2409 } 2434 }
2410 } 2435 }
2411 } 2436 }
2412 } 2437 }
2413
2414 skip: ; 2438 skip: ;
2415 } 2439 }
2416} 2440}
2417 2441
2418void 2442void
2449 for (int x = 0; x < THIS->width; ++x) 2473 for (int x = 0; x < THIS->width; ++x)
2450 for (int y = 0; y < THIS->height; ++y) 2474 for (int y = 0; y < THIS->height; ++y)
2451 { 2475 {
2452 region *rgn = THIS->region (x, y); 2476 region *rgn = THIS->region (x, y);
2453 2477
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) 2478 if (object *op = THIS->at (x, y).top)
2456 if (rgn->treasure && rndm () < rgn->treasure_density) 2479 if (rgn->treasure && rndm () < rgn->treasure_density)
2457 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty); 2480 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty);
2458 } 2481 }
2459 2482
2563archetype *archetypes (U32 index) 2586archetype *archetypes (U32 index)
2564 CODE: 2587 CODE:
2565 RETVAL = index < archetypes.size () ? archetypes [index] : 0; 2588 RETVAL = index < archetypes.size () ? archetypes [index] : 0;
2566 OUTPUT: RETVAL 2589 OUTPUT: RETVAL
2567 2590
2591int skillvec_size ()
2592 CODE:
2593 RETVAL = skillvec.size ();
2594 OUTPUT: RETVAL
2595
2596archetype *skillvec (U32 index)
2597 CODE:
2598 RETVAL = index < skillvec.size () ? (archetype *)(object *)skillvec [index] : 0;
2599 OUTPUT: RETVAL
2600
2568INCLUDE: $PERL $srcdir/genacc archetype $srcdir/../include/object.h | 2601INCLUDE: $PERL $srcdir/genacc archetype $srcdir/../include/object.h |
2569 2602
2570MODULE = cf PACKAGE = cf::party 2603MODULE = cf PACKAGE = cf::party
2571 2604
2572partylist *first () 2605partylist *first ()
2620list () 2653list ()
2621 PPCODE: 2654 PPCODE:
2622 EXTEND (SP, clients.size ()); 2655 EXTEND (SP, clients.size ());
2623 for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i) 2656 for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i)
2624 PUSHs (sv_2mortal (to_sv (*i))); 2657 PUSHs (sv_2mortal (to_sv (*i)));
2658
2659STRLEN
2660client::inbuf_append (SV *data)
2661 CODE:
2662{
2663 STRLEN len;
2664 char *ptr = SvPVbyte (data, len);
2665
2666 min_it (len, sizeof (THIS->inbuf) - THIS->inbuf_len);
2667 memcpy (THIS->inbuf + THIS->inbuf_len, ptr, len);
2668 THIS->inbuf_len += len;
2669
2670 THIS->inbuf_handle ();
2671
2672 RETVAL = len;
2673}
2674 OUTPUT: RETVAL
2625 2675
2626void 2676void
2627client::send_packet (SV *packet) 2677client::send_packet (SV *packet)
2628 CODE: 2678 CODE:
2629{ 2679{
2685faceidx face_find (utf8_string name, faceidx defidx = 0) 2735faceidx face_find (utf8_string name, faceidx defidx = 0)
2686 2736
2687faceidx alloc (utf8_string name) 2737faceidx alloc (utf8_string name)
2688 CODE: 2738 CODE:
2689{ 2739{
2690 do 2740 RETVAL = face_alloc ();
2691 {
2692 RETVAL = faces.size ();
2693 faces.resize (RETVAL + 1);
2694 }
2695 while (!RETVAL); // crude way to leave index 0
2696 2741
2697 faces [RETVAL].name = name; 2742 faces [RETVAL].name = name;
2698 facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL)); 2743 facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL));
2699 2744
2700 if (!strcmp (name, BLANK_FACE_NAME )) blank_face = RETVAL; 2745 if (!strcmp (name, BLANK_FACE_NAME )) blank_face = RETVAL;
2701 if (!strcmp (name, EMPTY_FACE_NAME )) empty_face = RETVAL; 2746 if (!strcmp (name, EMPTY_FACE_NAME )) empty_face = RETVAL;
2702 if (!strcmp (name, MAGICMOUTH_FACE_NAME)) magicmouth_face = RETVAL; 2747 if (!strcmp (name, MAGICMOUTH_FACE_NAME)) magicmouth_face = RETVAL;
2703} 2748}
2749 OUTPUT: RETVAL
2750
2751faceidx faces_size ()
2752 CODE:
2753 RETVAL = faces.size ();
2704 OUTPUT: RETVAL 2754 OUTPUT: RETVAL
2705 2755
2706void set_type (faceidx idx, int value) 2756void set_type (faceidx idx, int value)
2707 ALIAS: 2757 ALIAS:
2708 set_type = 0 2758 set_type = 0
2723 2773
2724void set_data (faceidx idx, int faceset, SV *data, SV *chksum) 2774void set_data (faceidx idx, int faceset, SV *data, SV *chksum)
2725 CODE: 2775 CODE:
2726{ 2776{
2727 faceinfo *f = face_info (idx); assert (f); 2777 faceinfo *f = face_info (idx); assert (f);
2728 facedata *d = &(faceset ? f->data64 : f->data32); 2778 facedata *d = f->face + faceset;
2729 sv_to (data, d->data); 2779 sv_to (data, d->data);
2730 STRLEN clen; 2780 STRLEN clen;
2731 char *cdata = SvPVbyte (chksum, clen); 2781 char *cdata = SvPVbyte (chksum, clen);
2732 clen = min (CHKSUM_MAXLEN, clen);
2733 2782
2783 assert (("cf::face::set_data called with too long checksum", clen <= CHKSUM_MAXLEN));
2734 assert (("cf::face::set_data must be called with a non-empty checksum", clen)); 2784 assert (("cf::face::set_data must be called with a non-empty checksum", clen));
2735 2785
2736 if (clen != d->chksum_len || memcmp (d->chksum, cdata, clen)) 2786 if (clen != d->chksum_len || memcmp (d->chksum, cdata, clen))
2737 { 2787 {
2738 d->chksum_len = clen; 2788 d->chksum_len = clen;
2739 memcpy (d->chksum, cdata, clen); 2789 memcpy (d->chksum, cdata, clen);
2740 2790
2741 // invalidate existing client face info 2791 // invalidate existing client face info
2742 for_all_clients (ns) 2792 for_all_clients (ns)
2743 if (ns->faceset == faceset) 2793 ns->invalidate_face (idx);
2744 {
2745 ns->faces_sent [idx] = false;
2746 ns->force_newmap = true;
2747 }
2748 } 2794 }
2749} 2795}
2750 2796
2751int get_data_size (faceidx idx, int faceset = 0) 2797int get_data_size (faceidx idx, int faceset = 0)
2752 CODE: 2798 CODE:
2754 if (!d) XSRETURN_UNDEF; 2800 if (!d) XSRETURN_UNDEF;
2755 RETVAL = d->data.size (); 2801 RETVAL = d->data.size ();
2756 OUTPUT: 2802 OUTPUT:
2757 RETVAL 2803 RETVAL
2758 2804
2805void set_meta (faceidx idx, SV *sv)
2806 CODE:
2807{
2808 faceinfo *f = face_info (idx); assert (f);
2809 SvREFCNT_dec (f->meta_hv);
2810 f->meta_hv = SvOK (sv) ? (HV *)SvREFCNT_inc (SvRV (sv)) : 0;
2811}
2812
2813SV *mangle_chksum (SV *chksum)
2814 CODE:
2815 STRLEN len;
2816 char *data = SvPVbyte (chksum, len);
2817 RETVAL = newSVpvn (data, min (len, CHKSUM_MAXLEN));
2818 OUTPUT:
2819 RETVAL
2820
2759SV *get_chksum (faceidx idx, int faceset = 0) 2821SV *get_chksum (faceidx idx, int faceset = 0)
2760 CODE: 2822 CODE:
2761 facedata *d = face_data (idx, faceset); 2823 facedata *d = face_data (idx, faceset);
2762 if (!d) XSRETURN_UNDEF; 2824 if (!d) XSRETURN_UNDEF;
2763 RETVAL = newSVpvn ((char *)d->chksum, d->chksum_len); 2825 RETVAL = newSVpvn ((char *)d->chksum, d->chksum_len);
2764 OUTPUT: 2826 OUTPUT:
2765 RETVAL 2827 RETVAL
2766 2828
2829int get_type (faceidx idx)
2830 CODE:
2831 faceinfo *f = face_info (idx);
2832 if (!f) XSRETURN_UNDEF;
2833 RETVAL = f->type;
2834 OUTPUT:
2835 RETVAL
2836
2837SV *get_name (faceidx idx)
2838 CODE:
2839 faceinfo *f = face_info (idx);
2840 if (!f) XSRETURN_UNDEF;
2841 RETVAL = to_sv (f->name);
2842 OUTPUT:
2843 RETVAL
2844
2767SV *get_data (faceidx idx, int faceset = 0) 2845SV *get_data (faceidx idx, int faceset = 0)
2768 CODE: 2846 CODE:
2769 facedata *d = face_data (idx, faceset); 2847 facedata *d = face_data (idx, faceset);
2770 if (!d) XSRETURN_UNDEF; 2848 if (!d) XSRETURN_UNDEF;
2771 RETVAL = newSVpvn (d->data.data (), d->data.length ()); 2849 RETVAL = newSVpvn (d->data, d->data.size ());
2772 OUTPUT: 2850 OUTPUT:
2773 RETVAL 2851 RETVAL
2774 2852
2853SV *get_meta (faceidx idx)
2854 CODE:
2855 faceinfo *f = face_info (idx); assert (f);
2856 if (!f || !f->meta_hv) XSRETURN_UNDEF;
2857 RETVAL = newRV_inc ((SV *)f->meta_hv);
2858 OUTPUT:
2859 RETVAL
2860
2775void invalidate (faceidx idx) 2861void invalidate (faceidx idx)
2776 CODE: 2862 CODE:
2777 for_all_clients (ns) 2863 for_all_clients (ns)
2778 { 2864 ns->invalidate_face (idx);
2779 ns->faces_sent [idx] = false;
2780 ns->force_newmap = true;
2781 }
2782 2865
2783void invalidate_all () 2866void invalidate_all ()
2784 CODE: 2867 CODE:
2785 for_all_clients (ns) 2868 for_all_clients (ns)
2786 { 2869 ns->invalidate_all_faces ();
2787 ns->faces_sent.reset ();
2788 ns->force_newmap = true;
2789 }
2790 2870
2791MODULE = cf PACKAGE = cf::anim PREFIX = anim_ 2871MODULE = cf PACKAGE = cf::anim PREFIX = anim_
2792 2872
2793#INCLUDE: $PERL $srcdir/genacc faceset $srcdir/../include/anim.h | 2873#INCLUDE: $PERL $srcdir/genacc faceset $srcdir/../include/anim.h |
2794 2874
2798 OUTPUT: RETVAL 2878 OUTPUT: RETVAL
2799 2879
2800animidx set (utf8_string name, SV *frames, int facings = 1) 2880animidx set (utf8_string name, SV *frames, int facings = 1)
2801 CODE: 2881 CODE:
2802{ 2882{
2803 if (!SvROK (frames) && SvTYPE (SvRV (frames)) != SVt_PVAV) 2883 if (!SvROK (frames) && SvTYPE (SvRV (frames)) != SVt_PVAV)
2804 croak ("frames must be an arrayref"); 2884 croak ("frames must be an arrayref");
2805 2885
2806 AV *av = (AV *)SvRV (frames); 2886 AV *av = (AV *)SvRV (frames);
2807 2887
2808 animation *anim = &animation::find (name); 2888 animation *anim = &animation::find (name);
2809 if (anim->number) 2889 if (anim->number)
2810 { 2890 {
2811 anim->resize (av_len (av) + 1); 2891 anim->resize (av_len (av) + 1);
2812 anim->facings = facings; 2892 anim->facings = facings;
2813 } 2893 }
2887 self->skip (); 2967 self->skip ();
2888 } 2968 }
2889 2969
2890MODULE = cf PACKAGE = cf::layout 2970MODULE = cf PACKAGE = cf::layout
2891 2971
2892INCLUDE: $PERL $srcdir/genacc layout $srcdir/../random_maps/random_map.h | 2972INCLUDE: $PERL $srcdir/genacc layout $srcdir/../include/rmg.h |
2893 2973

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines