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.390 by root, Sat Jul 3 01:12:45 2010 UTC vs.
Revision 1.414 by root, Tue Oct 30 17:07:50 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 ()
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
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
1829SV * 1805SV *
1830resistance_to_string (int atnr) 1806attacktype_name (int atnr)
1831 CODE: 1807 CODE:
1832 if (atnr >= 0 && atnr < NROFATTACKS) 1808 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1809 ? newSVpv (attacktype_name [atnr], 0)
1810 : &PL_sv_undef;
1811 OUTPUT: RETVAL
1812
1813SV *
1814attacktype_desc (int atnr)
1815 CODE:
1816 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1817 ? newSVpv (attacktype_desc [atnr], 0)
1818 : &PL_sv_undef;
1819 OUTPUT: RETVAL
1820
1821SV *
1822resist_plus (int atnr)
1823 CODE:
1824 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1833 RETVAL = newSVpv (resist_plus[atnr], 0); 1825 ? newSVpv (resist_plus [atnr], 0)
1834 else 1826 : &PL_sv_undef;
1835 XSRETURN_UNDEF; 1827 OUTPUT: RETVAL
1828
1829SV *
1830change_resist_msg (int atnr)
1831 CODE:
1832 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1833 ? newSVpv (change_resist_msg [atnr], 0)
1834 : &PL_sv_undef;
1836 OUTPUT: RETVAL 1835 OUTPUT: RETVAL
1837 1836
1838UUID 1837UUID
1839uuid_cur () 1838uuid_cur ()
1840 CODE: 1839 CODE:
1963int mortals_size () 1962int mortals_size ()
1964 CODE: 1963 CODE:
1965 RETVAL = attachable::mortals.size (); 1964 RETVAL = attachable::mortals.size ();
1966 OUTPUT: RETVAL 1965 OUTPUT: RETVAL
1967 1966
1968const_utf8_string slot_use_name (U32 slot) 1967const_utf8_string slot_name (U32 slot)
1969 ALIAS: 1968 ALIAS:
1969 slot_name = 0
1970 slot_use_name = 1
1970 slot_nonuse_name = 1 1971 slot_nonuse_name = 2
1971 CODE: 1972 CODE:
1972{ 1973{
1973 if (slot >= NUM_BODY_LOCATIONS) 1974 if (slot >= NUM_BODY_LOCATIONS)
1974 croak ("body slot index out of range"); 1975 croak ("body slot index out of range");
1975 1976
1976 switch (ix) 1977 switch (ix)
1977 { 1978 {
1979 case 0: RETVAL = body_locations[slot].name ; break;
1978 case 0: RETVAL = body_locations[slot].use_name; break; 1980 case 1: RETVAL = body_locations[slot].use_name ; break;
1979 case 1: RETVAL = body_locations[slot].nonuse_name; break; 1981 case 2: RETVAL = body_locations[slot].nonuse_name; break;
1980 } 1982 }
1981} 1983}
1982 OUTPUT: 1984 OUTPUT:
1983 RETVAL 1985 RETVAL
1984 1986
2116# dumb kludgy misdesigned plug-in api slowly gets on my nerves. 2118# dumb kludgy misdesigned plug-in api slowly gets on my nerves.
2117 2119
2118object *new (utf8_string archetype = 0) 2120object *new (utf8_string archetype = 0)
2119 PROTOTYPE: ;$ 2121 PROTOTYPE: ;$
2120 CODE: 2122 CODE:
2121 RETVAL = archetype ? get_archetype (archetype) : object::create (); 2123 RETVAL = archetype
2124 ? archetype::get (archetype)
2125 : object::create ();
2122 OUTPUT: 2126 OUTPUT:
2123 RETVAL 2127 RETVAL
2124 2128
2125object *generate (utf8_string arch, object *creator) 2129object *generate (utf8_string arch, object *creator)
2126 CODE: 2130 CODE:
2127 object *obj = get_archetype (arch); 2131 object *obj = archetype::get (arch);
2128 fix_generated_item (obj, creator, 0, 0, GT_MINIMAL); 2132 fix_generated_item (obj, creator, 0, 0, GT_MINIMAL);
2129 RETVAL = obj; 2133 RETVAL = obj;
2130 OUTPUT: 2134 OUTPUT:
2131 RETVAL 2135 RETVAL
2132 2136
2142 RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y); 2146 RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y);
2143 2147
2144 if (RETVAL->destroyed ()) 2148 if (RETVAL->destroyed ())
2145 RETVAL = 0; 2149 RETVAL = 0;
2146} 2150}
2151 OUTPUT:
2152 RETVAL
2147 2153
2148shstr 2154shstr
2149object::kv_get (shstr key) 2155object::kv_get (shstr key)
2156 CODE:
2157 RETVAL = THIS->kv.get (key);
2158 OUTPUT:
2159 RETVAL
2150 2160
2151void 2161void
2152object::kv_del (shstr key) 2162object::kv_del (shstr key)
2163 CODE:
2164 THIS->kv.del (key);
2153 2165
2154void 2166void
2155object::kv_set (shstr key, shstr value) 2167object::kv_set (shstr key, shstr value)
2168 CODE:
2169 THIS->kv.set (key, value);
2156 2170
2157object *get_nearest_player (object *ob) 2171object *get_nearest_player (object *ob)
2158 ALIAS: nearest_player = 0 2172 ALIAS: nearest_player = 0
2159 PREINIT: 2173 PREINIT:
2160 extern object *get_nearest_player (object *); 2174 extern object *get_nearest_player (object *);
2363 if (pl->ob && pl->ob->map == THIS) 2377 if (pl->ob && pl->ob->map == THIS)
2364 PUSHs (sv_2mortal (to_sv (pl->ob))); 2378 PUSHs (sv_2mortal (to_sv (pl->ob)));
2365 } 2379 }
2366 2380
2367void 2381void
2382maptile::gen_quadmap (int x, int y, int z)
2383 CODE:
2384 gen_quadmap (THIS, x * 50, y * 50, z);
2385
2386void
2368maptile::add_underlay (SV *data, int offset, int stride, SV *palette) 2387maptile::add_underlay (SV *data, int offset, int stride, SV *palette)
2369 CODE: 2388 CODE:
2370{ 2389{
2371 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV) 2390 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV)
2372 croak ("maptile::add_underlay: palette must be arrayref"); 2391 croak ("maptile::add_underlay: palette must be arrayref");
2388 2407
2389 if (IN_RANGE_EXC (offs, 0, idxlen)) 2408 if (IN_RANGE_EXC (offs, 0, idxlen))
2390 { 2409 {
2391 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) 2410 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0))
2392 { 2411 {
2393 object *ob = get_archetype (cfSvPVutf8_nolen (*elem)); 2412 object *ob = archetype::get (cfSvPVutf8_nolen (*elem));
2394 ob->flag [FLAG_NO_MAP_SAVE] = true; 2413 ob->flag [FLAG_NO_MAP_SAVE] = true;
2395 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); 2414 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY);
2396 2415
2397 if (ob->randomitems && !ob->above) 2416 if (ob->randomitems && !ob->above)
2398 { 2417 {
2402 op->flag [FLAG_NO_MAP_SAVE] = true; 2421 op->flag [FLAG_NO_MAP_SAVE] = true;
2403 // TODO: if this is a pickable object, then the item 2422 // TODO: if this is a pickable object, then the item
2404 // will at a bit weird - saving inside the player 2423 // will at a bit weird - saving inside the player
2405 // will clear the flag, but when the player drops 2424 // will clear the flag, but when the player drops
2406 // it without logging out, it keeps the flag. 2425 // it without logging out, it keeps the flag.
2407 // nobody ahs reported this, but this can be rather 2426 // nobody has reported this, but this can be rather
2408 // annoying on persistent maps. 2427 // annoying on persistent maps.
2409 } 2428 }
2410 } 2429 }
2411 } 2430 }
2412 } 2431 }
2413
2414 skip: ; 2432 skip: ;
2415 } 2433 }
2416} 2434}
2417 2435
2418void 2436void
2449 for (int x = 0; x < THIS->width; ++x) 2467 for (int x = 0; x < THIS->width; ++x)
2450 for (int y = 0; y < THIS->height; ++y) 2468 for (int y = 0; y < THIS->height; ++y)
2451 { 2469 {
2452 region *rgn = THIS->region (x, y); 2470 region *rgn = THIS->region (x, y);
2453 2471
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) 2472 if (object *op = THIS->at (x, y).top)
2456 if (rgn->treasure && rndm () < rgn->treasure_density) 2473 if (rgn->treasure && rndm () < rgn->treasure_density)
2457 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty); 2474 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty);
2458 } 2475 }
2459 2476
2538} 2555}
2539 OUTPUT: RETVAL 2556 OUTPUT: RETVAL
2540 2557
2541# worst xs function of my life 2558# worst xs function of my life
2542bool 2559bool
2543_create_random_map (\ 2560_create_random_map (maptile *self, SV *options)
2544 maptile *self,\
2545 SV *options,\
2546 val64 total_map_hp,\
2547 region *region\
2548)
2549 CODE: 2561 CODE:
2550{ 2562{
2551 random_map_params rmp; 2563 random_map_params rmp ((HV *)SvRV (options));
2552
2553 rmp.hv = (HV *)SvREFCNT_inc_NN (SvRV (options));
2554
2555 assign (rmp.wall_name, rmp.get_str ("wall_name"));
2556
2557 rmp.xsize = rmp.get_iv ("xsize");
2558 rmp.ysize = rmp.get_iv ("ysize");
2559 rmp.expand2x = rmp.get_iv ("expand2x");
2560 rmp.layoutoptions1 = rmp.get_iv ("layoutoptions1");
2561 rmp.layoutoptions2 = rmp.get_iv ("layoutoptions2");
2562 rmp.layoutoptions3 = rmp.get_iv ("layoutoptions3");
2563 rmp.symmetry = rmp.get_iv ("symmetry");
2564 rmp.difficulty = rmp.get_iv ("difficulty");
2565 rmp.difficulty_given = rmp.get_iv ("difficulty_given");
2566 rmp.difficulty_increase = rmp.get_nv ("difficulty_increase");
2567 rmp.dungeon_level = rmp.get_iv ("dungeon_level");
2568 rmp.dungeon_depth = rmp.get_iv ("dungeon_depth");
2569 rmp.orientation = rmp.get_iv ("orientation");
2570 rmp.random_seed = rmp.get_uv ("random_seed");
2571 rmp.total_map_hp = (uint64_t)total_map_hp;
2572 rmp.map_layout_style = rmp.get_iv ("map_layout_style");
2573 rmp.symmetry_used = rmp.get_iv ("symmetry_used");
2574 rmp.region = region;
2575
2576 RETVAL = self->generate_random_map (&rmp); 2564 RETVAL = self->generate_random_map (&rmp);
2577} 2565}
2578 OUTPUT: 2566 OUTPUT:
2579 RETVAL 2567 RETVAL
2580 2568
2649list () 2637list ()
2650 PPCODE: 2638 PPCODE:
2651 EXTEND (SP, clients.size ()); 2639 EXTEND (SP, clients.size ());
2652 for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i) 2640 for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i)
2653 PUSHs (sv_2mortal (to_sv (*i))); 2641 PUSHs (sv_2mortal (to_sv (*i)));
2642
2643STRLEN
2644client::inbuf_append (SV *data)
2645 CODE:
2646{
2647 STRLEN len;
2648 char *ptr = SvPVbyte (data, len);
2649
2650 min_it (len, sizeof (THIS->inbuf) - THIS->inbuf_len);
2651 memcpy (THIS->inbuf + THIS->inbuf_len, ptr, len);
2652 THIS->inbuf_len += len;
2653
2654 THIS->inbuf_handle ();
2655
2656 RETVAL = len;
2657}
2658 OUTPUT: RETVAL
2654 2659
2655void 2660void
2656client::send_packet (SV *packet) 2661client::send_packet (SV *packet)
2657 CODE: 2662 CODE:
2658{ 2663{
2714faceidx face_find (utf8_string name, faceidx defidx = 0) 2719faceidx face_find (utf8_string name, faceidx defidx = 0)
2715 2720
2716faceidx alloc (utf8_string name) 2721faceidx alloc (utf8_string name)
2717 CODE: 2722 CODE:
2718{ 2723{
2719 do 2724 RETVAL = face_alloc ();
2720 {
2721 RETVAL = faces.size ();
2722 faces.resize (RETVAL + 1);
2723 }
2724 while (!RETVAL); // crude way to leave index 0
2725 2725
2726 faces [RETVAL].name = name; 2726 faces [RETVAL].name = name;
2727 facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL)); 2727 facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL));
2728 2728
2729 if (!strcmp (name, BLANK_FACE_NAME )) blank_face = RETVAL; 2729 if (!strcmp (name, BLANK_FACE_NAME )) blank_face = RETVAL;
2730 if (!strcmp (name, EMPTY_FACE_NAME )) empty_face = RETVAL; 2730 if (!strcmp (name, EMPTY_FACE_NAME )) empty_face = RETVAL;
2731 if (!strcmp (name, MAGICMOUTH_FACE_NAME)) magicmouth_face = RETVAL; 2731 if (!strcmp (name, MAGICMOUTH_FACE_NAME)) magicmouth_face = RETVAL;
2732} 2732}
2733 OUTPUT: RETVAL
2734
2735faceidx faces_size ()
2736 CODE:
2737 RETVAL = faces.size ();
2733 OUTPUT: RETVAL 2738 OUTPUT: RETVAL
2734 2739
2735void set_type (faceidx idx, int value) 2740void set_type (faceidx idx, int value)
2736 ALIAS: 2741 ALIAS:
2737 set_type = 0 2742 set_type = 0
2752 2757
2753void set_data (faceidx idx, int faceset, SV *data, SV *chksum) 2758void set_data (faceidx idx, int faceset, SV *data, SV *chksum)
2754 CODE: 2759 CODE:
2755{ 2760{
2756 faceinfo *f = face_info (idx); assert (f); 2761 faceinfo *f = face_info (idx); assert (f);
2757 facedata *d = &(faceset ? f->data64 : f->data32); 2762 facedata *d = f->face + faceset;
2758 sv_to (data, d->data); 2763 sv_to (data, d->data);
2759 STRLEN clen; 2764 STRLEN clen;
2760 char *cdata = SvPVbyte (chksum, clen); 2765 char *cdata = SvPVbyte (chksum, clen);
2761 clen = min (CHKSUM_MAXLEN, clen); 2766 clen = min (CHKSUM_MAXLEN, clen);
2762 2767
2783 if (!d) XSRETURN_UNDEF; 2788 if (!d) XSRETURN_UNDEF;
2784 RETVAL = d->data.size (); 2789 RETVAL = d->data.size ();
2785 OUTPUT: 2790 OUTPUT:
2786 RETVAL 2791 RETVAL
2787 2792
2793void set_meta (faceidx idx, SV *sv)
2794 CODE:
2795{
2796 faceinfo *f = face_info (idx); assert (f);
2797 SvREFCNT_dec (f->meta_hv);
2798 f->meta_hv = SvOK (sv) ? (HV *)SvREFCNT_inc (SvRV (sv)) : 0;
2799}
2800
2788SV *get_chksum (faceidx idx, int faceset = 0) 2801SV *get_chksum (faceidx idx, int faceset = 0)
2789 CODE: 2802 CODE:
2790 facedata *d = face_data (idx, faceset); 2803 facedata *d = face_data (idx, faceset);
2791 if (!d) XSRETURN_UNDEF; 2804 if (!d) XSRETURN_UNDEF;
2792 RETVAL = newSVpvn ((char *)d->chksum, d->chksum_len); 2805 RETVAL = newSVpvn ((char *)d->chksum, d->chksum_len);
2793 OUTPUT: 2806 OUTPUT:
2794 RETVAL 2807 RETVAL
2795 2808
2809int get_type (faceidx idx)
2810 CODE:
2811 faceinfo *f = face_info (idx);
2812 if (!f) XSRETURN_UNDEF;
2813 RETVAL = f->type;
2814 OUTPUT:
2815 RETVAL
2816
2796SV *get_data (faceidx idx, int faceset = 0) 2817SV *get_data (faceidx idx, int faceset = 0)
2797 CODE: 2818 CODE:
2798 facedata *d = face_data (idx, faceset); 2819 facedata *d = face_data (idx, faceset);
2799 if (!d) XSRETURN_UNDEF; 2820 if (!d) XSRETURN_UNDEF;
2800 RETVAL = newSVpvn (d->data.data (), d->data.length ()); 2821 RETVAL = newSVpvn (d->data, d->data.size ());
2801 OUTPUT: 2822 OUTPUT:
2802 RETVAL 2823 RETVAL
2803 2824
2825SV *get_meta (faceidx idx)
2826 CODE:
2827 faceinfo *f = face_info (idx); assert (f);
2828 if (!f || !f->meta_hv) XSRETURN_UNDEF;
2829 RETVAL = newRV_inc ((SV *)f->meta_hv);
2830 OUTPUT:
2831 RETVAL
2832
2804void invalidate (faceidx idx) 2833void invalidate (faceidx idx)
2805 CODE: 2834 CODE:
2806 for_all_clients (ns) 2835 for_all_clients (ns)
2807 { 2836 ns->invalidate_face (idx);
2808 ns->faces_sent [idx] = false;
2809 ns->force_newmap = true;
2810 }
2811 2837
2812void invalidate_all () 2838void invalidate_all ()
2813 CODE: 2839 CODE:
2814 for_all_clients (ns) 2840 for_all_clients (ns)
2815 { 2841 ns->invalidate_all_faces ();
2816 ns->faces_sent.reset ();
2817 ns->force_newmap = true;
2818 }
2819 2842
2820MODULE = cf PACKAGE = cf::anim PREFIX = anim_ 2843MODULE = cf PACKAGE = cf::anim PREFIX = anim_
2821 2844
2822#INCLUDE: $PERL $srcdir/genacc faceset $srcdir/../include/anim.h | 2845#INCLUDE: $PERL $srcdir/genacc faceset $srcdir/../include/anim.h |
2823 2846
2827 OUTPUT: RETVAL 2850 OUTPUT: RETVAL
2828 2851
2829animidx set (utf8_string name, SV *frames, int facings = 1) 2852animidx set (utf8_string name, SV *frames, int facings = 1)
2830 CODE: 2853 CODE:
2831{ 2854{
2832 if (!SvROK (frames) && SvTYPE (SvRV (frames)) != SVt_PVAV) 2855 if (!SvROK (frames) && SvTYPE (SvRV (frames)) != SVt_PVAV)
2833 croak ("frames must be an arrayref"); 2856 croak ("frames must be an arrayref");
2834 2857
2835 AV *av = (AV *)SvRV (frames); 2858 AV *av = (AV *)SvRV (frames);
2836 2859
2837 animation *anim = &animation::find (name); 2860 animation *anim = &animation::find (name);
2838 if (anim->number) 2861 if (anim->number)
2839 { 2862 {
2840 anim->resize (av_len (av) + 1); 2863 anim->resize (av_len (av) + 1);
2841 anim->facings = facings; 2864 anim->facings = facings;
2842 } 2865 }
2916 self->skip (); 2939 self->skip ();
2917 } 2940 }
2918 2941
2919MODULE = cf PACKAGE = cf::layout 2942MODULE = cf PACKAGE = cf::layout
2920 2943
2921INCLUDE: $PERL $srcdir/genacc layout $srcdir/../random_maps/random_map.h | 2944INCLUDE: $PERL $srcdir/genacc layout $srcdir/../include/rmg.h |
2922 2945

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines