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.394 by root, Mon Oct 11 18:40:44 2010 UTC vs.
Revision 1.425 by root, Wed Nov 14 06:21:39 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
29#include <cstdarg> 29#include <cstdarg>
30#include <typeinfo> 30#include <typeinfo>
31 31
32#include "global.h" 32#include "global.h"
33#include "rmg.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
91 92
92static SV 93static SV
93 *cv_cf_do_invoke, 94 *cv_cf_do_invoke,
94 *cv_cf__can_merge, 95 *cv_cf__can_merge,
95 *cv_cf_client_send_msg, 96 *cv_cf_client_send_msg,
97 *cv_cf_ix,
96 *cv_cf_tick, 98 *cv_cf_tick,
97 *cv_cf_match_match; 99 *cv_cf_match_match;
98 100
99#ifndef newSVpv_utf8 101#ifndef newSVpv_utf8
100static SV * 102static SV *
252 { 254 {
253 static int last_mortalcount; 255 static int last_mortalcount;
254 if (mortals.size () != last_mortalcount) 256 if (mortals.size () != last_mortalcount)
255 { 257 {
256 last_mortalcount = mortals.size (); 258 last_mortalcount = mortals.size ();
257 LOG (llevInfo, "%d mortals.\n", (int)mortals.size ()); 259 object *specimen = is_a<object> (mortals [rndm (mortals.size ())]);
260
261 LOG (llevInfo, "%d mortals (random specimen: %s).\n",
262 (int)mortals.size (), specimen ? specimen->debug_desc () : "(not an object)");
258 263
259 if (0) 264 if (0)
260 { 265 {
261 for (int j = 0; j < mortals.size (); ++j)//D 266 for (int j = 0; j < mortals.size (); ++j)//D
262 fprintf (stderr, "%d:%s %p ", j, &((object *)mortals[j])->name, mortals[j]);//D 267 fprintf (stderr, "%d:%s %p ", j, &((object *)mortals[j])->name, mortals[j]);//D
621 STRLEN len; 626 STRLEN len;
622 char *data = SvPVbyte (sv, len); 627 char *data = SvPVbyte (sv, len);
623 v.assign (data, len); 628 v.assign (data, len);
624} 629}
625 630
631static inline void sv_to (SV *sv, refcnt_buf &v)
632{
633 STRLEN len;
634 char *data = SvPVbyte (sv, len);
635 refcnt_buf buf (data, len);
636 v = buf;
637}
638
626static inline void sv_to (SV *sv, UUID &v) 639static inline void sv_to (SV *sv, UUID &v)
627{ 640{
628 if (!v.parse (SvPV_nolen (sv))) 641 if (!v.parse (SvPV_nolen (sv)))
629 croak ("unparsable uuid: %s", SvPV_nolen (sv)); 642 croak ("unparsable uuid: %s", SvPV_nolen (sv));
630} 643}
1145 CALL_ARG (originator); 1158 CALL_ARG (originator);
1146 CALL_CALL ("cf::mapscript::activate", G_VOID); 1159 CALL_CALL ("cf::mapscript::activate", G_VOID);
1147 CALL_END; 1160 CALL_END;
1148} 1161}
1149 1162
1163void cfperl_ix (client *ns, int set, faceidx idx, int pri)
1164{
1165 CALL_BEGIN (3);
1166 CALL_ARG (ns);
1167 CALL_ARG (set);
1168 CALL_ARG (idx);
1169 CALL_ARG (pri);
1170 CALL_CALL (cv_cf_ix, G_VOID);
1171 CALL_END;
1172}
1173
1150player * 1174player *
1151player::find (const_utf8_string name) 1175player::find (const_utf8_string name)
1152{ 1176{
1153 CALL_BEGIN (1); 1177 CALL_BEGIN (1);
1154 CALL_ARG (name); 1178 CALL_ARG (name);
1403 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); 1427 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1);
1404 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1); 1428 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1);
1405 stash_cf_layout_wrap = gv_stashpv ("cf::layout::wrap", 1); 1429 stash_cf_layout_wrap = gv_stashpv ("cf::layout::wrap", 1);
1406 stash_ext_map_world = gv_stashpv ("ext::map_world" , 1); 1430 stash_ext_map_world = gv_stashpv ("ext::map_world" , 1);
1407 1431
1408 sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV); 1432 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); 1433 sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV);
1434 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); 1435 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); 1436 sv_next_tick = get_sv ("cf::NEXT_TICK" , 1); SvUPGRADE (sv_next_tick , SVt_NV);
1412 1437
1413 cb_global = get_av ("cf::CB_GLOBAL", 1); 1438 cb_global = get_av ("cf::CB_GLOBAL", 1);
1414 cb_attachable = get_av ("cf::CB_ATTACHABLE", 1); 1439 cb_attachable = get_av ("cf::CB_ATTACHABLE", 1);
1415 cb_object = get_av ("cf::CB_OBJECT", 1); 1440 cb_object = get_av ("cf::CB_OBJECT", 1);
1416 cb_player = get_av ("cf::CB_PLAYER", 1); 1441 cb_player = get_av ("cf::CB_PLAYER", 1);
1423_connect_to_perl_2 () 1448_connect_to_perl_2 ()
1424{ 1449{
1425 cv_cf_do_invoke = (SV *)get_cv ("cf::do_invoke" , 0); assert (cv_cf_do_invoke); 1450 cv_cf_do_invoke = (SV *)get_cv ("cf::do_invoke" , 0); assert (cv_cf_do_invoke);
1426 cv_cf__can_merge = (SV *)get_cv ("cf::_can_merge" , 0); assert (cv_cf__can_merge); 1451 cv_cf__can_merge = (SV *)get_cv ("cf::_can_merge" , 0); assert (cv_cf__can_merge);
1427 cv_cf_client_send_msg = (SV *)get_cv ("cf::client::send_msg", 0); assert (cv_cf_client_send_msg); 1452 cv_cf_client_send_msg = (SV *)get_cv ("cf::client::send_msg", 0); assert (cv_cf_client_send_msg);
1453 cv_cf_ix = (SV *)get_cv ("cf::face::ix" , 0); assert (cv_cf_ix);
1428 cv_cf_tick = (SV *)get_cv ("cf::tick" , 0); assert (cv_cf_tick); 1454 cv_cf_tick = (SV *)get_cv ("cf::tick" , 0); assert (cv_cf_tick);
1429 cv_cf_match_match = (SV *)get_cv ("cf::match::match" , 0); assert (cv_cf_match_match); 1455 cv_cf_match_match = (SV *)get_cv ("cf::match::match" , 0); assert (cv_cf_match_match);
1430} 1456}
1431 1457
1432MODULE = cf PACKAGE = cf PREFIX = cf_ 1458MODULE = cf PACKAGE = cf PREFIX = cf_
1437 I_CORO_API (PACKAGE); coroapi::GCoroAPI = GCoroAPI; 1463 I_CORO_API (PACKAGE); coroapi::GCoroAPI = GCoroAPI;
1438 1464
1439 _connect_to_perl_1 (); 1465 _connect_to_perl_1 ();
1440 1466
1441 newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1)); 1467 newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1));
1442
1443 //{
1444 // require_pv ("Time::HiRes");
1445 //
1446 // SV **svp = hv_fetch (PL_modglobal, "Time::NVtime", 12, 0);
1447 // if (!svp) croak ("Time::HiRes is required");
1448 // if (!SvIOK(*svp)) croak ("Time::NVtime isn’t a function pointer");
1449 // coroapi::time = INT2PTR (double(*)(), SvIV(*svp));
1450 //}
1451 1468
1452 static const struct { 1469 static const struct {
1453 const char *name; 1470 const char *name;
1454 IV iv; 1471 IV iv;
1455 } *civ, const_iv[] = { 1472 } *civ, const_iv[] = {
1463# undef def 1480# undef def
1464# define def(name, use, nonuse) const_iv (body_ ## name) 1481# define def(name, use, nonuse) const_iv (body_ ## name)
1465# include "slotinc.h" 1482# include "slotinc.h"
1466# undef def 1483# undef def
1467 1484
1468 const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd)
1469
1470 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) 1485 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y)
1471 1486
1472 const_iv (MAX_TIME) 1487 const_iv (MAX_TIME)
1473 const_iv (MAXSOCKBUF) 1488 const_iv (MAXSOCKBUF)
1474 1489
1486 1501
1487 const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE) 1502 const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE)
1488 1503
1489 const_iv (SK_EXP_ADD_SKILL) const_iv (SK_EXP_TOTAL) const_iv (SK_EXP_NONE) 1504 const_iv (SK_EXP_ADD_SKILL) const_iv (SK_EXP_TOTAL) const_iv (SK_EXP_NONE)
1490 const_iv (SK_SUBTRACT_SKILL_EXP) const_iv (SK_EXP_SKILL_ONLY) 1505 const_iv (SK_SUBTRACT_SKILL_EXP) const_iv (SK_EXP_SKILL_ONLY)
1491
1492 const_iv (MAP_ACTIVE) const_iv (MAP_SWAPPED) const_iv (MAP_LOADING) const_iv (MAP_SAVING)
1493 const_iv (MAP_INACTIVE)
1494 1506
1495 const_iv (KLASS_ATTACHABLE) const_iv (KLASS_GLOBAL) const_iv (KLASS_OBJECT) 1507 const_iv (KLASS_ATTACHABLE) const_iv (KLASS_GLOBAL) const_iv (KLASS_OBJECT)
1496 const_iv (KLASS_CLIENT) const_iv (KLASS_PLAYER) const_iv (KLASS_MAP) 1508 const_iv (KLASS_CLIENT) const_iv (KLASS_PLAYER) const_iv (KLASS_MAP)
1497 1509
1498 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT) 1510 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT)
1531 1543
1532void _gv_clear (SV *gv) 1544void _gv_clear (SV *gv)
1533 CODE: 1545 CODE:
1534 assert (SvTYPE (gv) == SVt_PVGV); 1546 assert (SvTYPE (gv) == SVt_PVGV);
1535# define f(sv) { SV *sv_ = (SV *)(sv); sv = 0; SvREFCNT_dec (sv_); } 1547# define f(sv) { SV *sv_ = (SV *)(sv); sv = 0; SvREFCNT_dec (sv_); }
1548 SvREFCNT_inc (gv);
1536 f (GvGP (gv)->gp_form); 1549 f (GvGP (gv)->gp_form);
1537 f (GvGP (gv)->gp_io); 1550 f (GvGP (gv)->gp_io);
1538 f (GvGP (gv)->gp_sv); 1551 f (GvGP (gv)->gp_sv);
1539 f (GvGP (gv)->gp_av); 1552 f (GvGP (gv)->gp_av);
1540 f (GvGP (gv)->gp_hv); 1553 f (GvGP (gv)->gp_hv);
1541 f (GvGP (gv)->gp_cv); 1554 f (GvGP (gv)->gp_cv);
1542 GvCVGEN (gv) = 0; 1555 GvCVGEN (gv) = 0;
1543 GvMULTI_off (gv); 1556 GvMULTI_off (gv);
1557 SvREFCNT_dec (gv);
1544# undef f 1558# undef f
1545 1559
1546void _connect_to_perl_1 () 1560void _connect_to_perl_1 ()
1547 1561
1548void _connect_to_perl_2 () 1562void _connect_to_perl_2 ()
1559 1573
1560 for_all_objects (op) 1574 for_all_objects (op)
1561 op->reattach (); 1575 op->reattach ();
1562} 1576}
1563 1577
1564# support function for map-world.ext
1565void _quantise (SV *data_sv, SV *plt_sv)
1566 CODE:
1567{
1568 if (!SvROK (plt_sv) || SvTYPE (SvRV (plt_sv)) != SVt_PVAV)
1569 croak ("_quantise called with invalid agruments");
1570
1571 plt_sv = SvRV (plt_sv);
1572 SV **plt = AvARRAY (plt_sv);
1573 int plt_count = AvFILL (plt_sv) + 1;
1574
1575 STRLEN len;
1576 char *data = SvPVbyte (data_sv, len);
1577 char *dst = data;
1578
1579 while (len >= 3)
1580 {
1581 for (SV **val_sv = plt + plt_count; val_sv-- > plt; )
1582 {
1583 char *val = SvPVX (*val_sv);
1584
1585 if (val [0] == data [0]
1586 && val [1] == data [1]
1587 && val [2] == data [2])
1588 {
1589 *dst++ = val [3];
1590 goto next;
1591 }
1592 }
1593
1594 croak ("_quantise: color not found in palette: #%02x%02x%02x, at offset %d %d",
1595 (uint8_t)data [0], (uint8_t)data [1], (uint8_t)data [2],
1596 dst - SvPVX (data_sv), len);
1597
1598 next:
1599 data += 3;
1600 len -= 3;
1601 }
1602
1603 SvCUR_set (data_sv, dst - SvPVX (data_sv));
1604}
1605
1606void init_anim () 1578void init_anim ()
1607 1579
1608void init_globals () 1580void init_globals ()
1609 1581
1610void init_attackmess () 1582void init_attackmess ()
1611 1583
1612void init_dynamic () 1584void init_dynamic ()
1613 1585
1614void load_settings () 1586void load_settings ()
1615 1587
1616void reload_exp_table () 1588void _reload_exp_table ()
1617 1589
1618void reload_materials () 1590void _reload_materials ()
1619 1591
1620void init_uuid () 1592void init_uuid ()
1621 CODE: 1593 CODE:
1622 UUID::init (); 1594 UUID::init ();
1623 1595
1656 { 1628 {
1657 ev_async_send (EV_DEFAULT, &tick_watcher); 1629 ev_async_send (EV_DEFAULT, &tick_watcher);
1658 coroapi::cede (); 1630 coroapi::cede ();
1659 } 1631 }
1660 1632
1661void server_tick () 1633void one_tick ()
1662 CODE: 1634 CODE:
1663{ 1635{
1664 ev_now_update (EV_DEFAULT); 1636 ev_now_update (EV_DEFAULT);
1665 NOW = ev_now (EV_DEFAULT); 1637 NOW = ev_now (EV_DEFAULT);
1666 SvNV_set (sv_now, NOW); SvNOK_only (sv_now); 1638 SvNV_set (sv_now, NOW); SvNOK_only (sv_now);
1667 SvNV_set (sv_tick_start, NOW); SvNOK_only (sv_tick_start); 1639 SvNV_set (sv_tick_start, NOW); SvNOK_only (sv_tick_start);
1668 runtime = SvNVX (sv_runtime); 1640 runtime = SvNVX (sv_runtime);
1669 1641
1642 one_tick ();
1643
1670 server_tick (); 1644 ++server_tick;
1645 SvUV_set (sv_server_tick, server_tick); SvIOK_only_UV (sv_server_tick);
1671 1646
1672 ev_now_update (EV_DEFAULT); 1647 ev_now_update (EV_DEFAULT);
1673 NOW = ev_now (EV_DEFAULT); 1648 NOW = ev_now (EV_DEFAULT);
1674 SvNV_set (sv_now, NOW); SvNOK_only (sv_now); 1649 SvNV_set (sv_now, NOW); SvNOK_only (sv_now);
1650
1675 runtime += TICK; 1651 runtime += TICK;
1676 SvNV_set (sv_runtime, runtime); SvNOK_only (sv_runtime); 1652 SvNV_set (sv_runtime, runtime); SvNOK_only (sv_runtime);
1677} 1653}
1678 1654
1679NV floor (NV x) 1655NV floor (NV x)
1683NV rndm (...) 1659NV rndm (...)
1684 ALIAS: 1660 ALIAS:
1685 rmg_rndm = 1 1661 rmg_rndm = 1
1686 CODE: 1662 CODE:
1687{ 1663{
1688 rand_gen &gen = ix ? rmg_rndm : rndm; 1664 rand_gen &gen = ix ? rmg_rndm : rndm;
1689 switch (items) 1665 switch (items)
1690 { 1666 {
1691 case 0: RETVAL = gen (); break; 1667 case 0: RETVAL = gen (); break;
1692 case 1: RETVAL = gen (SvUV (ST (0))); break; 1668 case 1: RETVAL = gen (SvUV (ST (0))); break;
1693 case 2: RETVAL = gen (SvIV (ST (0)), SvIV (ST (1))); break; 1669 case 2: RETVAL = gen (SvIV (ST (0)), SvIV (ST (1))); break;
1778 1754
1779int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) 1755int mlockall (int flags = MCL_CURRENT | MCL_FUTURE)
1780 INIT: 1756 INIT:
1781#if __GLIBC__ 1757#if __GLIBC__
1782 mallopt (M_TOP_PAD, 1024 * 1024); 1758 mallopt (M_TOP_PAD, 1024 * 1024);
1783 mallopt (M_MMAP_THRESHOLD, 1024 * 1024 * 128); 1759 mallopt (M_MMAP_THRESHOLD, 1024 * 1024);
1784 mallopt (M_MMAP_MAX, 0); // likely bug-workaround, also frees memory 1760 mallopt (M_MMAP_MAX, 0); // likely bug-workaround, also frees memory
1761 if (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 10))
1785 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc 1762 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc
1786#endif 1763#endif
1787 1764
1788int munlockall () 1765int munlockall ()
1789 1766
1790#endif 1767#endif
1816 PUSHs (sv_2mortal (newSVpv ("objects" , 0))); PUSHs (sv_2mortal (newSVuv (objects.size () * sizeof (object)))); 1793 PUSHs (sv_2mortal (newSVpv ("objects" , 0))); PUSHs (sv_2mortal (newSVuv (objects.size () * sizeof (object))));
1817 PUSHs (sv_2mortal (newSVpv ("sv_count" , 0))); PUSHs (sv_2mortal (newSVuv (PL_sv_count))); 1794 PUSHs (sv_2mortal (newSVpv ("sv_count" , 0))); PUSHs (sv_2mortal (newSVuv (PL_sv_count)));
1818 PUSHs (sv_2mortal (newSVpv ("sv_objcount", 0))); PUSHs (sv_2mortal (newSVuv (PL_sv_objcount))); 1795 PUSHs (sv_2mortal (newSVpv ("sv_objcount", 0))); PUSHs (sv_2mortal (newSVuv (PL_sv_objcount)));
1819} 1796}
1820 1797
1821int find_animation (utf8_string text)
1822 PROTOTYPE: $
1823
1824int random_roll (int min, int max, object *op, int goodbad); 1798int random_roll (int min, int max, object *op, int goodbad);
1825 1799
1826const_utf8_string cost_string_from_value(uint64 cost, int approx = 0) 1800const_utf8_string cost_string_from_value(uint64 cost, int approx = 0)
1827 1801
1828int exp_to_level (val64 exp) 1802int exp_to_level (val64 exp)
1829 1803
1830val64 level_to_min_exp (int level) 1804val64 level_to_min_exp (int level)
1805
1806const_utf8_string
1807spellpathnames (int idx)
1808 CODE:
1809 RETVAL = spellpathnames [idx];
1810 OUTPUT: RETVAL
1831 1811
1832SV * 1812SV *
1833attacktype_name (int atnr) 1813attacktype_name (int atnr)
1834 CODE: 1814 CODE:
1835 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS) 1815 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1907load_resource_file_ (octet_string filename) 1887load_resource_file_ (octet_string filename)
1908 1888
1909void 1889void
1910fix_weight () 1890fix_weight ()
1911 1891
1892utf8_string
1893expand_cfpod (int hintmode, int gender, const_utf8_string cfpod)
1894 PPCODE:
1895 XPUSHs (to_sv (player::expand_cfpod (hintmode, gender, cfpod)));
1896
1912MODULE = cf PACKAGE = cf::attachable 1897MODULE = cf PACKAGE = cf::attachable
1913 1898
1914int 1899int
1915valid (SV *obj) 1900valid (SV *obj)
1916 CODE: 1901 CODE:
2139 2124
2140void fix_generated_item (object *op, object *creator, int difficulty, int max_magic, int flags); 2125void fix_generated_item (object *op, object *creator, int difficulty, int max_magic, int flags);
2141 2126
2142MODULE = cf PACKAGE = cf::object PREFIX = cf_ 2127MODULE = cf PACKAGE = cf::object PREFIX = cf_
2143 2128
2144# no clean way to get an object from an archetype - stupid idiotic
2145# dumb kludgy misdesigned plug-in api slowly gets on my nerves.
2146
2147object *new (utf8_string archetype = 0) 2129object *new (utf8_string archetype = 0)
2148 PROTOTYPE: ;$ 2130 PROTOTYPE: ;$
2149 CODE: 2131 CODE:
2150 RETVAL = archetype ? get_archetype (archetype) : object::create (); 2132 RETVAL = archetype
2133 ? archetype::get (archetype)
2134 : object::create ();
2151 OUTPUT: 2135 OUTPUT:
2152 RETVAL 2136 RETVAL
2153 2137
2154object *generate (utf8_string arch, object *creator) 2138object *generate (utf8_string arch, object *creator)
2155 CODE: 2139 CODE:
2156 object *obj = get_archetype (arch); 2140 object *obj = archetype::get (arch);
2157 fix_generated_item (obj, creator, 0, 0, GT_MINIMAL); 2141 fix_generated_item (obj, creator, 0, 0, GT_MINIMAL);
2158 RETVAL = obj; 2142 RETVAL = obj;
2159 OUTPUT: 2143 OUTPUT:
2160 RETVAL 2144 RETVAL
2161 2145
2171 RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y); 2155 RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y);
2172 2156
2173 if (RETVAL->destroyed ()) 2157 if (RETVAL->destroyed ())
2174 RETVAL = 0; 2158 RETVAL = 0;
2175} 2159}
2160 OUTPUT:
2161 RETVAL
2176 2162
2177shstr 2163shstr
2178object::kv_get (shstr key) 2164object::kv_get (shstr key)
2165 CODE:
2166 RETVAL = THIS->kv.get (key);
2167 OUTPUT:
2168 RETVAL
2179 2169
2180void 2170void
2181object::kv_del (shstr key) 2171object::kv_del (shstr key)
2172 CODE:
2173 THIS->kv.del (key);
2182 2174
2183void 2175void
2184object::kv_set (shstr key, shstr value) 2176object::kv_set (shstr key, shstr value)
2177 CODE:
2178 THIS->kv.set (key, value);
2185 2179
2186object *get_nearest_player (object *ob) 2180object *get_nearest_player (object *ob)
2187 ALIAS: nearest_player = 0 2181 ALIAS: nearest_player = 0
2188 PREINIT: 2182 PREINIT:
2189 extern object *get_nearest_player (object *); 2183 extern object *get_nearest_player (object *);
2392 if (pl->ob && pl->ob->map == THIS) 2386 if (pl->ob && pl->ob->map == THIS)
2393 PUSHs (sv_2mortal (to_sv (pl->ob))); 2387 PUSHs (sv_2mortal (to_sv (pl->ob)));
2394 } 2388 }
2395 2389
2396void 2390void
2391maptile::gen_quadmap (int x, int y, int z)
2392 CODE:
2393 gen_quadmap (THIS, x * 50, y * 50, z);
2394
2395void
2397maptile::add_underlay (SV *data, int offset, int stride, SV *palette) 2396maptile::add_underlay (SV *data, int offset, int stride, SV *palette)
2398 CODE: 2397 CODE:
2399{ 2398{
2400 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV) 2399 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV)
2401 croak ("maptile::add_underlay: palette must be arrayref"); 2400 croak ("maptile::add_underlay: palette must be arrayref");
2402 2401
2403 palette = SvRV (palette); 2402 palette = SvRV (palette);
2404 2403
2405 STRLEN idxlen; 2404 STRLEN idxlen;
2406 const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen); 2405 const uint8 *idx = (const uint8 *)SvPVbyte (data, idxlen);
2407 2406
2408 for (int x = 0; x < THIS->width; ++x) 2407 for (int x = 0; x < THIS->width; ++x)
2409 for (int y = 0; y < THIS->height; ++y) 2408 for (int y = 0; y < THIS->height; ++y)
2410 { 2409 {
2411 for (object *op = THIS->at (x, y).bot; op; op = op->above) 2410 for (object *op = THIS->at (x, y).bot; op; op = op->above)
2417 2416
2418 if (IN_RANGE_EXC (offs, 0, idxlen)) 2417 if (IN_RANGE_EXC (offs, 0, idxlen))
2419 { 2418 {
2420 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) 2419 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0))
2421 { 2420 {
2422 object *ob = get_archetype (cfSvPVutf8_nolen (*elem)); 2421 object *ob = archetype::get (cfSvPVutf8_nolen (*elem));
2423 ob->flag [FLAG_NO_MAP_SAVE] = true; 2422 ob->flag [FLAG_NO_MAP_SAVE] = true;
2424 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); 2423 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY);
2425 2424
2426 if (ob->randomitems && !ob->above) 2425 if (ob->randomitems && !ob->above)
2427 { 2426 {
2431 op->flag [FLAG_NO_MAP_SAVE] = true; 2430 op->flag [FLAG_NO_MAP_SAVE] = true;
2432 // TODO: if this is a pickable object, then the item 2431 // TODO: if this is a pickable object, then the item
2433 // will at a bit weird - saving inside the player 2432 // will at a bit weird - saving inside the player
2434 // will clear the flag, but when the player drops 2433 // will clear the flag, but when the player drops
2435 // it without logging out, it keeps the flag. 2434 // it without logging out, it keeps the flag.
2436 // nobody ahs reported this, but this can be rather 2435 // nobody has reported this, but this can be rather
2437 // annoying on persistent maps. 2436 // annoying on persistent maps.
2438 } 2437 }
2439 } 2438 }
2440 } 2439 }
2441 } 2440 }
2442
2443 skip: ; 2441 skip: ;
2444 } 2442 }
2445} 2443}
2446 2444
2447void 2445void
2452 croak ("maptile::set_regiondata: palette must be arrayref"); 2450 croak ("maptile::set_regiondata: palette must be arrayref");
2453 2451
2454 palette = SvRV (palette); 2452 palette = SvRV (palette);
2455 2453
2456 STRLEN idxlen; 2454 STRLEN idxlen;
2457 const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen); 2455 const uint8 *idx = (const uint8 *)SvPVbyte (data, idxlen);
2458 2456
2459 region_ptr *regionmap = new region_ptr [av_len ((AV *)palette) + 1]; 2457 region_ptr *regionmap = new region_ptr [av_len ((AV *)palette) + 1];
2460 uint8_t *regions = salloc<uint8_t> (THIS->size ()); 2458 uint8 *regions = salloc<uint8_t> (THIS->size ());
2461 2459
2462 for (int i = av_len ((AV *)palette) + 1; i--; ) 2460 for (int i = av_len ((AV *)palette) + 1; i--; )
2463 regionmap [i] = region::find (cfSvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1))); 2461 regionmap [i] = region::find (cfSvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1)));
2464 2462
2465 for (int y = 0; y < THIS->height; ++y) 2463 for (int y = 0; y < THIS->height; ++y)
2478 for (int x = 0; x < THIS->width; ++x) 2476 for (int x = 0; x < THIS->width; ++x)
2479 for (int y = 0; y < THIS->height; ++y) 2477 for (int y = 0; y < THIS->height; ++y)
2480 { 2478 {
2481 region *rgn = THIS->region (x, y); 2479 region *rgn = THIS->region (x, y);
2482 2480
2483 //fprintf (stderr, "%d,%d %f %p\n", x, y, rgn->treasure_density,rgn->treasure);//D
2484 if (object *op = THIS->at (x, y).top) 2481 if (object *op = THIS->at (x, y).top)
2485 if (rgn->treasure && rndm () < rgn->treasure_density) 2482 if (rgn->treasure && rndm () < rgn->treasure_density)
2486 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty); 2483 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty);
2487 } 2484 }
2488 2485
2592archetype *archetypes (U32 index) 2589archetype *archetypes (U32 index)
2593 CODE: 2590 CODE:
2594 RETVAL = index < archetypes.size () ? archetypes [index] : 0; 2591 RETVAL = index < archetypes.size () ? archetypes [index] : 0;
2595 OUTPUT: RETVAL 2592 OUTPUT: RETVAL
2596 2593
2594int skillvec_size ()
2595 CODE:
2596 RETVAL = skillvec.size ();
2597 OUTPUT: RETVAL
2598
2599archetype *skillvec (U32 index)
2600 CODE:
2601 RETVAL = index < skillvec.size () ? (archetype *)(object *)skillvec [index] : 0;
2602 OUTPUT: RETVAL
2603
2604void
2605find_by_type (int type)
2606 PPCODE:
2607 for_all_archetypes (arch)
2608 if (arch->type == type)
2609 XPUSHs (sv_2mortal (to_sv (arch)));
2610
2597INCLUDE: $PERL $srcdir/genacc archetype $srcdir/../include/object.h | 2611INCLUDE: $PERL $srcdir/genacc archetype $srcdir/../include/object.h |
2598 2612
2599MODULE = cf PACKAGE = cf::party 2613MODULE = cf PACKAGE = cf::party
2600 2614
2601partylist *first () 2615partylist *first ()
2649list () 2663list ()
2650 PPCODE: 2664 PPCODE:
2651 EXTEND (SP, clients.size ()); 2665 EXTEND (SP, clients.size ());
2652 for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i) 2666 for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i)
2653 PUSHs (sv_2mortal (to_sv (*i))); 2667 PUSHs (sv_2mortal (to_sv (*i)));
2668
2669STRLEN
2670client::inbuf_append (SV *data)
2671 CODE:
2672{
2673 STRLEN len;
2674 char *ptr = SvPVbyte (data, len);
2675
2676 min_it (len, sizeof (THIS->inbuf) - THIS->inbuf_len);
2677 memcpy (THIS->inbuf + THIS->inbuf_len, ptr, len);
2678 THIS->inbuf_len += len;
2679
2680 THIS->inbuf_handle ();
2681
2682 RETVAL = len;
2683}
2684 OUTPUT: RETVAL
2654 2685
2655void 2686void
2656client::send_packet (SV *packet) 2687client::send_packet (SV *packet)
2657 CODE: 2688 CODE:
2658{ 2689{
2714faceidx face_find (utf8_string name, faceidx defidx = 0) 2745faceidx face_find (utf8_string name, faceidx defidx = 0)
2715 2746
2716faceidx alloc (utf8_string name) 2747faceidx alloc (utf8_string name)
2717 CODE: 2748 CODE:
2718{ 2749{
2719 do 2750 RETVAL = face_alloc ();
2720 {
2721 RETVAL = faces.size ();
2722 faces.resize (RETVAL + 1);
2723 }
2724 while (!RETVAL); // crude way to leave index 0
2725 2751
2726 faces [RETVAL].name = name; 2752 faces [RETVAL].name = name;
2727 facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL)); 2753 facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL));
2728 2754
2729 if (!strcmp (name, BLANK_FACE_NAME )) blank_face = RETVAL; 2755 if (!strcmp (name, BLANK_FACE_NAME )) blank_face = RETVAL;
2730 if (!strcmp (name, EMPTY_FACE_NAME )) empty_face = RETVAL; 2756 if (!strcmp (name, EMPTY_FACE_NAME )) empty_face = RETVAL;
2731 if (!strcmp (name, MAGICMOUTH_FACE_NAME)) magicmouth_face = RETVAL; 2757 if (!strcmp (name, MAGICMOUTH_FACE_NAME)) magicmouth_face = RETVAL;
2732} 2758}
2759 OUTPUT: RETVAL
2760
2761faceidx faces_size ()
2762 CODE:
2763 RETVAL = faces.size ();
2733 OUTPUT: RETVAL 2764 OUTPUT: RETVAL
2734 2765
2735void set_type (faceidx idx, int value) 2766void set_type (faceidx idx, int value)
2736 ALIAS: 2767 ALIAS:
2737 set_type = 0 2768 set_type = 0
2748 case 2: f->magicmap = value; break; 2779 case 2: f->magicmap = value; break;
2749 case 3: f->smooth = value; break; 2780 case 3: f->smooth = value; break;
2750 case 4: f->smoothlevel = value; break; 2781 case 4: f->smoothlevel = value; break;
2751 } 2782 }
2752 2783
2753void set_data (faceidx idx, int faceset, SV *data, SV *chksum) 2784void set_csum (faceidx idx, int faceset, SV *chksum)
2754 CODE: 2785 CODE:
2755{ 2786{
2756 faceinfo *f = face_info (idx); assert (f); 2787 faceinfo *f = face_info (idx); assert (f);
2757 facedata *d = f->face + faceset; 2788 facedata *d = f->face + faceset;
2758 sv_to (data, d->data);
2759 STRLEN clen; 2789 STRLEN clen;
2760 char *cdata = SvPVbyte (chksum, clen); 2790 char *cdata = SvPVbyte (chksum, clen);
2761 clen = min (CHKSUM_MAXLEN, clen);
2762 2791
2792 assert (("cf::face::set_data called with too long checksum", clen <= CHKSUM_MAXLEN));
2763 assert (("cf::face::set_data must be called with a non-empty checksum", clen)); 2793 assert (("cf::face::set_data must be called with a non-empty checksum", clen));
2764 2794
2765 if (clen != d->chksum_len || memcmp (d->chksum, cdata, clen)) 2795 if (clen != d->chksum_len || memcmp (d->chksum, cdata, clen))
2766 { 2796 {
2767 d->chksum_len = clen; 2797 d->chksum_len = clen;
2768 memcpy (d->chksum, cdata, clen); 2798 memcpy (d->chksum, cdata, clen);
2769 2799
2770 // invalidate existing client face info 2800 // invalidate existing client face info
2771 for_all_clients (ns) 2801 for_all_clients (ns)
2772 if (ns->faceset == faceset) 2802 ns->invalidate_face (idx);
2773 {
2774 ns->faces_sent [idx] = false;
2775 ns->force_newmap = true;
2776 }
2777 } 2803 }
2778} 2804}
2779 2805
2780int get_data_size (faceidx idx, int faceset = 0) 2806SV *mangle_csum (SV *chksum)
2781 CODE: 2807 CODE:
2782 facedata *d = face_data (idx, faceset); 2808 STRLEN len;
2783 if (!d) XSRETURN_UNDEF; 2809 char *data = SvPVbyte (chksum, len);
2784 RETVAL = d->data.size (); 2810 RETVAL = newSVpvn (data, min (len, CHKSUM_MAXLEN));
2785 OUTPUT: 2811 OUTPUT:
2786 RETVAL 2812 RETVAL
2787 2813
2788SV *get_chksum (faceidx idx, int faceset = 0) 2814SV *get_csum (faceidx idx, int faceset = 0)
2789 CODE: 2815 CODE:
2790 facedata *d = face_data (idx, faceset); 2816 facedata *d = face_data (idx, faceset);
2791 if (!d) XSRETURN_UNDEF; 2817 if (!d) XSRETURN_UNDEF;
2792 RETVAL = newSVpvn ((char *)d->chksum, d->chksum_len); 2818 RETVAL = newSVpvn ((char *)d->chksum, d->chksum_len);
2793 OUTPUT: 2819 OUTPUT:
2794 RETVAL 2820 RETVAL
2795 2821
2796SV *get_data (faceidx idx, int faceset = 0) 2822int get_type (faceidx idx)
2797 CODE: 2823 CODE:
2798 facedata *d = face_data (idx, faceset); 2824 faceinfo *f = face_info (idx);
2799 if (!d) XSRETURN_UNDEF; 2825 if (!f) XSRETURN_UNDEF;
2800 RETVAL = newSVpvn (d->data.data (), d->data.length ()); 2826 RETVAL = f->type;
2801 OUTPUT: 2827 OUTPUT:
2802 RETVAL 2828 RETVAL
2803 2829
2830SV *get_name (faceidx idx)
2831 CODE:
2832 faceinfo *f = face_info (idx);
2833 if (!f) XSRETURN_UNDEF;
2834 RETVAL = to_sv (f->name);
2835 OUTPUT:
2836 RETVAL
2837
2804void invalidate (faceidx idx) 2838void invalidate (faceidx idx)
2805 CODE: 2839 CODE:
2806 for_all_clients (ns) 2840 for_all_clients (ns)
2807 { 2841 ns->invalidate_face (idx);
2808 ns->faces_sent [idx] = false;
2809 ns->force_newmap = true;
2810 }
2811 2842
2812void invalidate_all () 2843void invalidate_all ()
2813 CODE: 2844 CODE:
2814 for_all_clients (ns) 2845 for_all_clients (ns)
2815 { 2846 ns->invalidate_all_faces ();
2816 ns->faces_sent.reset ();
2817 ns->force_newmap = true;
2818 }
2819 2847
2820MODULE = cf PACKAGE = cf::anim PREFIX = anim_ 2848MODULE = cf PACKAGE = cf::anim PREFIX = anim_
2821 2849
2822#INCLUDE: $PERL $srcdir/genacc faceset $srcdir/../include/anim.h | 2850#INCLUDE: $PERL $srcdir/genacc faceset $srcdir/../include/anim.h |
2823 2851
2827 OUTPUT: RETVAL 2855 OUTPUT: RETVAL
2828 2856
2829animidx set (utf8_string name, SV *frames, int facings = 1) 2857animidx set (utf8_string name, SV *frames, int facings = 1)
2830 CODE: 2858 CODE:
2831{ 2859{
2832 if (!SvROK (frames) && SvTYPE (SvRV (frames)) != SVt_PVAV) 2860 if (!SvROK (frames) && SvTYPE (SvRV (frames)) != SVt_PVAV)
2833 croak ("frames must be an arrayref"); 2861 croak ("frames must be an arrayref");
2834 2862
2835 AV *av = (AV *)SvRV (frames); 2863 AV *av = (AV *)SvRV (frames);
2836 2864
2837 animation *anim = &animation::find (name); 2865 animation *anim = &animation::find (name);
2838 if (anim->number) 2866 if (anim->number)
2839 { 2867 {
2840 anim->resize (av_len (av) + 1); 2868 anim->resize (av_len (av) + 1);
2841 anim->facings = facings; 2869 anim->facings = facings;
2842 } 2870 }
2914 XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ()))); 2942 XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ())));
2915 2943
2916 self->skip (); 2944 self->skip ();
2917 } 2945 }
2918 2946
2947MODULE = cf PACKAGE = cf::treasurelist
2948
2949# quick hack, because I didn't want to implement accessors for treasurelist.
2950# this asks for even more autogen, actually.
2951
2952void
2953expand (treasurelist *list)
2954 PPCODE:
2955 EXTEND (SP, 3);
2956 PUSHs (sv_2mortal (to_sv (list->name)));
2957 PUSHs (sv_2mortal (to_sv (list->total_chance)));
2958 AV *av = newAV ();
2959 PUSHs (sv_2mortal (newRV_noinc ((SV *)av)));
2960 for (treasure *item = list->items; item; item = item->next)
2961 {
2962 AV *iav = newAV ();
2963 av_push (av, newRV_noinc ((SV *)iav));
2964
2965 av_extend (iav, 7);
2966 av_push (iav, to_sv (item->item));
2967 av_push (iav, to_sv (item->name));
2968 av_push (iav, to_sv (item->change_arch.name));
2969 av_push (iav, to_sv (item->change_arch.title));
2970 av_push (iav, to_sv (item->change_arch.slaying));
2971 av_push (iav, to_sv (item->chance));
2972 av_push (iav, to_sv (item->nrof));
2973 av_push (iav, to_sv (item->magic));
2974 }
2975
2919MODULE = cf PACKAGE = cf::layout 2976MODULE = cf PACKAGE = cf::layout
2920 2977
2921INCLUDE: $PERL $srcdir/genacc layout $srcdir/../include/rmg.h | 2978INCLUDE: $PERL $srcdir/genacc layout $srcdir/../include/rmg.h |
2922 2979

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines