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.427 by root, Tue Nov 20 14:50:17 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
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);
1248 CALL_ARG (y); 1272 CALL_ARG (y);
1249 CALL_CALL ("cf::object::player::goto", G_VOID); 1273 CALL_CALL ("cf::object::player::goto", G_VOID);
1250 CALL_END; 1274 CALL_END;
1251} 1275}
1252 1276
1253const_utf8_string 1277const_utf8_string
1254object::ref () const 1278object::ref () const
1255{ 1279{
1256 if (type == PLAYER) 1280 if (type == PLAYER)
1257 return format ("player/<1.%llx>/%s", (unsigned long long)uuid.seq, &name); 1281 return format ("player/<1.%llx>/%s", (unsigned long long)uuid.seq, &name);
1258 else 1282 else
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[] = {
1459# include "attackinc.h" 1476# include "attackinc.h"
1460# undef def 1477# undef def
1461# define def(uc, flags) const_iv (SK_ ## uc) 1478# define def(uc, flags) const_iv (SK_ ## uc)
1462# include "skillinc.h" 1479# include "skillinc.h"
1463# undef def 1480# undef def
1464 1481# define def(name, use, nonuse) const_iv (body_ ## name)
1465 const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd) 1482# include "slotinc.h"
1483# undef def
1466 1484
1467 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) 1485 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y)
1468 1486
1469 const_iv (MAX_TIME) 1487 const_iv (MAX_TIME)
1470 const_iv (MAXSOCKBUF) 1488 const_iv (MAXSOCKBUF)
1483 1501
1484 const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE) 1502 const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE)
1485 1503
1486 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)
1487 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)
1488
1489 const_iv (MAP_ACTIVE) const_iv (MAP_SWAPPED) const_iv (MAP_LOADING) const_iv (MAP_SAVING)
1490 const_iv (MAP_INACTIVE)
1491 1506
1492 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)
1493 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)
1494 1509
1495 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)
1528 1543
1529void _gv_clear (SV *gv) 1544void _gv_clear (SV *gv)
1530 CODE: 1545 CODE:
1531 assert (SvTYPE (gv) == SVt_PVGV); 1546 assert (SvTYPE (gv) == SVt_PVGV);
1532# 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);
1533 f (GvGP (gv)->gp_form); 1549 f (GvGP (gv)->gp_form);
1534 f (GvGP (gv)->gp_io); 1550 f (GvGP (gv)->gp_io);
1535 f (GvGP (gv)->gp_sv); 1551 f (GvGP (gv)->gp_sv);
1536 f (GvGP (gv)->gp_av); 1552 f (GvGP (gv)->gp_av);
1537 f (GvGP (gv)->gp_hv); 1553 f (GvGP (gv)->gp_hv);
1538 f (GvGP (gv)->gp_cv); 1554 f (GvGP (gv)->gp_cv);
1539 GvCVGEN (gv) = 0; 1555 GvCVGEN (gv) = 0;
1540 GvMULTI_off (gv); 1556 GvMULTI_off (gv);
1557 SvREFCNT_dec (gv);
1541# undef f 1558# undef f
1542 1559
1543void _connect_to_perl_1 () 1560void _connect_to_perl_1 ()
1544 1561
1545void _connect_to_perl_2 () 1562void _connect_to_perl_2 ()
1556 1573
1557 for_all_objects (op) 1574 for_all_objects (op)
1558 op->reattach (); 1575 op->reattach ();
1559} 1576}
1560 1577
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 () 1578void init_anim ()
1604 1579
1605void init_globals () 1580void init_globals ()
1606 1581
1607void init_attackmess () 1582void init_attackmess ()
1608 1583
1609void init_dynamic () 1584void init_dynamic ()
1610 1585
1611void load_settings () 1586void load_settings ()
1612 1587
1613void reload_exp_table () 1588void _reload_exp_table ()
1614 1589
1615void reload_materials () 1590void _reload_materials ()
1616 1591
1617void init_uuid () 1592void init_uuid ()
1618 CODE: 1593 CODE:
1619 UUID::init (); 1594 UUID::init ();
1620 1595
1631 coroapi::cede_to_tick (); 1606 coroapi::cede_to_tick ();
1632 1607
1633NV till_tick () 1608NV till_tick ()
1634 CODE: 1609 CODE:
1635 RETVAL = SvNVX (sv_next_tick) - now (); 1610 RETVAL = SvNVX (sv_next_tick) - now ();
1636 OUTPUT: 1611 OUTPUT: RETVAL
1637 RETVAL
1638 1612
1639int tick_inhibit () 1613int tick_inhibit ()
1640 CODE: 1614 CODE:
1641 RETVAL = tick_inhibit; 1615 RETVAL = tick_inhibit;
1642 OUTPUT: 1616 OUTPUT: RETVAL
1643 RETVAL
1644 1617
1645void tick_inhibit_inc () 1618void tick_inhibit_inc ()
1646 CODE: 1619 CODE:
1647 ++tick_inhibit; 1620 ++tick_inhibit;
1648 1621
1653 { 1626 {
1654 ev_async_send (EV_DEFAULT, &tick_watcher); 1627 ev_async_send (EV_DEFAULT, &tick_watcher);
1655 coroapi::cede (); 1628 coroapi::cede ();
1656 } 1629 }
1657 1630
1658void server_tick () 1631void one_tick ()
1659 CODE: 1632 CODE:
1660{ 1633{
1661 ev_now_update (EV_DEFAULT); 1634 ev_now_update (EV_DEFAULT);
1662 NOW = ev_now (EV_DEFAULT); 1635 NOW = ev_now (EV_DEFAULT);
1663 SvNV_set (sv_now, NOW); SvNOK_only (sv_now); 1636 SvNV_set (sv_now, NOW); SvNOK_only (sv_now);
1664 SvNV_set (sv_tick_start, NOW); SvNOK_only (sv_tick_start); 1637 SvNV_set (sv_tick_start, NOW); SvNOK_only (sv_tick_start);
1665 runtime = SvNVX (sv_runtime); 1638 runtime = SvNVX (sv_runtime);
1666 1639
1640 one_tick ();
1641
1667 server_tick (); 1642 ++server_tick;
1643 SvUV_set (sv_server_tick, server_tick); SvIOK_only_UV (sv_server_tick);
1668 1644
1669 ev_now_update (EV_DEFAULT); 1645 ev_now_update (EV_DEFAULT);
1670 NOW = ev_now (EV_DEFAULT); 1646 NOW = ev_now (EV_DEFAULT);
1671 SvNV_set (sv_now, NOW); SvNOK_only (sv_now); 1647 SvNV_set (sv_now, NOW); SvNOK_only (sv_now);
1648
1672 runtime += TICK; 1649 runtime += TICK;
1673 SvNV_set (sv_runtime, runtime); SvNOK_only (sv_runtime); 1650 SvNV_set (sv_runtime, runtime); SvNOK_only (sv_runtime);
1674} 1651}
1675 1652
1676NV floor (NV x) 1653NV floor (NV x)
1680NV rndm (...) 1657NV rndm (...)
1681 ALIAS: 1658 ALIAS:
1682 rmg_rndm = 1 1659 rmg_rndm = 1
1683 CODE: 1660 CODE:
1684{ 1661{
1685 rand_gen &gen = ix ? rmg_rndm : rndm; 1662 rand_gen &gen = ix ? rmg_rndm : rndm;
1686 switch (items) 1663 switch (items)
1687 { 1664 {
1688 case 0: RETVAL = gen (); break; 1665 case 0: RETVAL = gen (); break;
1689 case 1: RETVAL = gen (SvUV (ST (0))); break; 1666 case 1: RETVAL = gen (SvUV (ST (0))); break;
1690 case 2: RETVAL = gen (SvIV (ST (0)), SvIV (ST (1))); break; 1667 case 2: RETVAL = gen (SvIV (ST (0)), SvIV (ST (1))); break;
1691 default: croak ("cf::rndm requires zero, one or two parameters."); break; 1668 default: croak ("cf::rndm requires zero, one or two parameters."); break;
1692 } 1669 }
1693} 1670}
1694 OUTPUT: 1671 OUTPUT: RETVAL
1695 RETVAL
1696 1672
1697NV clamp (NV value, NV min_value, NV max_value) 1673NV clamp (NV value, NV min_value, NV max_value)
1698 CODE: 1674 CODE:
1699 RETVAL = clamp (value, min_value, max_value); 1675 RETVAL = clamp (value, min_value, max_value);
1700 OUTPUT: 1676 OUTPUT: RETVAL
1701 RETVAL
1702 1677
1703NV lerp (NV value, NV min_in, NV max_in, NV min_out, NV max_out) 1678NV lerp (NV value, NV min_in, NV max_in, NV min_out, NV max_out)
1704 CODE: 1679 CODE:
1705 RETVAL = lerp (value, min_in, max_in, min_out, max_out); 1680 RETVAL = lerp (value, min_in, max_in, min_out, max_out);
1706 OUTPUT: 1681 OUTPUT: RETVAL
1707 RETVAL
1708 1682
1709const char *ordinal (int i) 1683const char *ordinal (int i)
1710 1684
1711void weaken (...) 1685void weaken (...)
1712 PROTOTYPE: @ 1686 PROTOTYPE: @
1775 1749
1776int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) 1750int mlockall (int flags = MCL_CURRENT | MCL_FUTURE)
1777 INIT: 1751 INIT:
1778#if __GLIBC__ 1752#if __GLIBC__
1779 mallopt (M_TOP_PAD, 1024 * 1024); 1753 mallopt (M_TOP_PAD, 1024 * 1024);
1780 mallopt (M_MMAP_THRESHOLD, 1024 * 1024 * 128); 1754 mallopt (M_MMAP_THRESHOLD, 1024 * 1024);
1781 mallopt (M_MMAP_MAX, 0); // likely bug-workaround, also frees memory 1755 mallopt (M_MMAP_MAX, 0); // likely bug-workaround, also frees memory
1756 if (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 10))
1782 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc 1757 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc
1783#endif 1758#endif
1784 1759
1785int munlockall () 1760int munlockall ()
1786 1761
1787#endif 1762#endif
1813 PUSHs (sv_2mortal (newSVpv ("objects" , 0))); PUSHs (sv_2mortal (newSVuv (objects.size () * sizeof (object)))); 1788 PUSHs (sv_2mortal (newSVpv ("objects" , 0))); PUSHs (sv_2mortal (newSVuv (objects.size () * sizeof (object))));
1814 PUSHs (sv_2mortal (newSVpv ("sv_count" , 0))); PUSHs (sv_2mortal (newSVuv (PL_sv_count))); 1789 PUSHs (sv_2mortal (newSVpv ("sv_count" , 0))); PUSHs (sv_2mortal (newSVuv (PL_sv_count)));
1815 PUSHs (sv_2mortal (newSVpv ("sv_objcount", 0))); PUSHs (sv_2mortal (newSVuv (PL_sv_objcount))); 1790 PUSHs (sv_2mortal (newSVpv ("sv_objcount", 0))); PUSHs (sv_2mortal (newSVuv (PL_sv_objcount)));
1816} 1791}
1817 1792
1818int find_animation (utf8_string text)
1819 PROTOTYPE: $
1820
1821int random_roll (int min, int max, object *op, int goodbad); 1793int random_roll (int min, int max, object *op, int goodbad);
1822 1794
1823const_utf8_string cost_string_from_value(uint64 cost, int approx = 0) 1795const_utf8_string cost_string_from_value(uint64 cost, int approx = 0)
1824 1796
1825int exp_to_level (val64 exp) 1797int exp_to_level (val64 exp)
1826 1798
1827val64 level_to_min_exp (int level) 1799val64 level_to_min_exp (int level)
1828 1800
1801const_utf8_string
1802spellpathnames (int idx)
1803 CODE:
1804 RETVAL = spellpathnames [idx];
1805 OUTPUT: RETVAL
1806
1829SV * 1807SV *
1830resistance_to_string (int atnr) 1808attacktype_name (int atnr)
1831 CODE: 1809 CODE:
1832 if (atnr >= 0 && atnr < NROFATTACKS) 1810 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1833 RETVAL = newSVpv (resist_plus[atnr], 0); 1811 ? newSVpv (attacktype_name [atnr], 0)
1834 else 1812 : &PL_sv_undef;
1835 XSRETURN_UNDEF;
1836 OUTPUT: RETVAL 1813 OUTPUT: RETVAL
1814
1815SV *
1816attacktype_desc (int atnr)
1817 CODE:
1818 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1819 ? newSVpv (attacktype_desc [atnr], 0)
1820 : &PL_sv_undef;
1821 OUTPUT: RETVAL
1822
1823SV *
1824resist_plus (int atnr)
1825 CODE:
1826 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1827 ? newSVpv (resist_plus [atnr], 0)
1828 : &PL_sv_undef;
1829 OUTPUT: RETVAL
1830
1831SV *
1832change_resist_msg (int atnr)
1833 CODE:
1834 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1835 ? newSVpv (change_resist_msg [atnr], 0)
1836 : &PL_sv_undef;
1837 OUTPUT: RETVAL
1838
1839int
1840skill_flags (int idx)
1841 CODE:
1842 if (idx < 0 || idx >= array_length (skill_flags))
1843 croak ("skill_flags: index out of bounds");
1844 RETVAL = skill_flags [idx];
1845 OUTPUT: RETVAL
1837 1846
1838UUID 1847UUID
1839uuid_cur () 1848uuid_cur ()
1840 CODE: 1849 CODE:
1841 RETVAL = UUID::cur; 1850 RETVAL = UUID::cur;
1842 OUTPUT: 1851 OUTPUT: RETVAL
1843 RETVAL
1844 1852
1845UUID 1853UUID
1846uuid_gen () 1854uuid_gen ()
1847 CODE: 1855 CODE:
1848 RETVAL = UUID::gen (); 1856 RETVAL = UUID::gen ();
1849 OUTPUT: 1857 OUTPUT: RETVAL
1850 RETVAL
1851 1858
1852val64 1859val64
1853uuid_seq (UUID uuid) 1860uuid_seq (UUID uuid)
1854 CODE: 1861 CODE:
1855 RETVAL = uuid.seq; 1862 RETVAL = uuid.seq;
1856 OUTPUT: 1863 OUTPUT: RETVAL
1857 RETVAL
1858 1864
1859UUID 1865UUID
1860uuid_str (val64 seq) 1866uuid_str (val64 seq)
1861 CODE: 1867 CODE:
1862 RETVAL.seq = seq; 1868 RETVAL.seq = seq;
1863 OUTPUT: 1869 OUTPUT: RETVAL
1864 RETVAL
1865 1870
1866void 1871void
1867coin_names () 1872coin_names ()
1868 PPCODE: 1873 PPCODE:
1869 EXTEND (SP, NUM_COINS); 1874 EXTEND (SP, NUM_COINS);
1881load_resource_file_ (octet_string filename) 1886load_resource_file_ (octet_string filename)
1882 1887
1883void 1888void
1884fix_weight () 1889fix_weight ()
1885 1890
1891utf8_string
1892expand_cfpod (int hintmode, int gender, const_utf8_string cfpod)
1893 PPCODE:
1894 XPUSHs (to_sv (player::expand_cfpod (hintmode, gender, cfpod)));
1895
1886MODULE = cf PACKAGE = cf::attachable 1896MODULE = cf PACKAGE = cf::attachable
1887 1897
1888int 1898int
1889valid (SV *obj) 1899valid (SV *obj)
1890 CODE: 1900 CODE:
1891 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); 1901 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext);
1892 OUTPUT: 1902 OUTPUT: RETVAL
1893 RETVAL
1894 1903
1895bool should_invoke (attachable *obj, int event) 1904bool should_invoke (attachable *obj, int event)
1896 CODE: 1905 CODE:
1897 RETVAL = obj->should_invoke ((event_type)event); 1906 RETVAL = obj->should_invoke ((event_type)event);
1898 OUTPUT: RETVAL 1907 OUTPUT: RETVAL
1963int mortals_size () 1972int mortals_size ()
1964 CODE: 1973 CODE:
1965 RETVAL = attachable::mortals.size (); 1974 RETVAL = attachable::mortals.size ();
1966 OUTPUT: RETVAL 1975 OUTPUT: RETVAL
1967 1976
1968const_utf8_string slot_use_name (U32 slot) 1977const_utf8_string slot_name (U32 slot)
1969 ALIAS: 1978 ALIAS:
1979 slot_name = 0
1980 slot_use_name = 1
1970 slot_nonuse_name = 1 1981 slot_nonuse_name = 2
1971 CODE: 1982 CODE:
1972{ 1983{
1973 if (slot >= NUM_BODY_LOCATIONS) 1984 if (slot >= NUM_BODY_LOCATIONS)
1974 croak ("body slot index out of range"); 1985 croak ("body slot index out of range");
1975 1986
1976 switch (ix) 1987 switch (ix)
1977 { 1988 {
1989 case 0: RETVAL = body_locations[slot].name ; break;
1978 case 0: RETVAL = body_locations[slot].use_name; break; 1990 case 1: RETVAL = body_locations[slot].use_name ; break;
1979 case 1: RETVAL = body_locations[slot].nonuse_name; break; 1991 case 2: RETVAL = body_locations[slot].nonuse_name; break;
1980 } 1992 }
1981} 1993}
1982 OUTPUT: 1994 OUTPUT: RETVAL
1983 RETVAL
1984 1995
1985# missing properties 1996# missing properties
1986 1997
1987object *head (object *op) 1998object *head (object *op)
1988 PROTOTYPE: $ 1999 PROTOTYPE: $
2024 if (ix) 2035 if (ix)
2025 op->slot[slot].used = value; 2036 op->slot[slot].used = value;
2026 else 2037 else
2027 op->slot[slot].info = value; 2038 op->slot[slot].info = value;
2028} 2039}
2029 OUTPUT: 2040 OUTPUT: RETVAL
2030 RETVAL
2031 2041
2032object *find_best_object_match (object *op, utf8_string match) 2042object *find_best_object_match (object *op, utf8_string match)
2033 2043
2034int apply_shop_mat (object *shop_mat, object *op); 2044int apply_shop_mat (object *shop_mat, object *op);
2035 2045
2036int move (object *op, int dir, object *originator = op) 2046int move (object *op, int dir, object *originator = op)
2037 CODE: 2047 CODE:
2038 RETVAL = op->move (dir, originator); 2048 RETVAL = op->move (dir, originator);
2039 OUTPUT: 2049 OUTPUT: RETVAL
2040 RETVAL
2041 2050
2042void apply_below (object *op) 2051void apply_below (object *op)
2043 CODE: 2052 CODE:
2044 player_apply_below (op); 2053 player_apply_below (op);
2045 2054
2109int convert_item (object *item, object *converter) 2118int convert_item (object *item, object *converter)
2110 2119
2111void fix_generated_item (object *op, object *creator, int difficulty, int max_magic, int flags); 2120void fix_generated_item (object *op, object *creator, int difficulty, int max_magic, int flags);
2112 2121
2113MODULE = cf PACKAGE = cf::object PREFIX = cf_ 2122MODULE = cf PACKAGE = cf::object PREFIX = cf_
2114
2115# no clean way to get an object from an archetype - stupid idiotic
2116# dumb kludgy misdesigned plug-in api slowly gets on my nerves.
2117 2123
2118object *new (utf8_string archetype = 0) 2124object *new (utf8_string archetype = 0)
2119 PROTOTYPE: ;$ 2125 PROTOTYPE: ;$
2120 CODE: 2126 CODE:
2121 RETVAL = archetype ? get_archetype (archetype) : object::create (); 2127 RETVAL = archetype
2128 ? archetype::get (archetype)
2129 : object::create ();
2122 OUTPUT: 2130 OUTPUT: RETVAL
2123 RETVAL
2124 2131
2125object *generate (utf8_string arch, object *creator) 2132object *generate (utf8_string arch, object *creator)
2126 CODE: 2133 CODE:
2127 object *obj = get_archetype (arch); 2134 object *obj = archetype::get (arch);
2128 fix_generated_item (obj, creator, 0, 0, GT_MINIMAL); 2135 fix_generated_item (obj, creator, 0, 0, GT_MINIMAL);
2129 RETVAL = obj; 2136 RETVAL = obj;
2130 OUTPUT: 2137 OUTPUT: RETVAL
2131 RETVAL
2132 2138
2133object *find_object (U32 tag) 2139object *find_object (U32 tag)
2134 2140
2135object *find_object_uuid (UUID i) 2141object *find_object_uuid (UUID i)
2136 2142
2142 RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y); 2148 RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y);
2143 2149
2144 if (RETVAL->destroyed ()) 2150 if (RETVAL->destroyed ())
2145 RETVAL = 0; 2151 RETVAL = 0;
2146} 2152}
2153 OUTPUT: RETVAL
2147 2154
2148shstr 2155shstr
2149object::kv_get (shstr key) 2156object::kv_get (shstr key)
2157 CODE:
2158 RETVAL = THIS->kv.get (key);
2159 OUTPUT: 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 *);
2249#d# TODO: replace by blocked_los accessor, fix code using this 2263#d# TODO: replace by blocked_los accessor, fix code using this
2250bool 2264bool
2251cell_visible (player *pl, int dx, int dy) 2265cell_visible (player *pl, int dx, int dy)
2252 CODE: 2266 CODE:
2253 RETVAL = pl->blocked_los (dx, dy) != LOS_BLOCKED; 2267 RETVAL = pl->blocked_los (dx, dy) != LOS_BLOCKED;
2254 OUTPUT: 2268 OUTPUT: RETVAL
2255 RETVAL
2256 2269
2257void 2270void
2258send (player *pl, SV *packet) 2271send (player *pl, SV *packet)
2259 CODE: 2272 CODE:
2260{ 2273{
2336outdoor_darkness (int darkness = 0) 2349outdoor_darkness (int darkness = 0)
2337 CODE: 2350 CODE:
2338 RETVAL = maptile::outdoor_darkness; 2351 RETVAL = maptile::outdoor_darkness;
2339 if (items) 2352 if (items)
2340 maptile::outdoor_darkness = darkness; 2353 maptile::outdoor_darkness = darkness;
2341 OUTPUT: 2354 OUTPUT: RETVAL
2342 RETVAL
2343 2355
2344void 2356void
2345maptile::instantiate () 2357maptile::instantiate ()
2346 2358
2347maptile *new () 2359maptile *new ()
2348 PROTOTYPE: 2360 PROTOTYPE:
2349 CODE: 2361 CODE:
2350 RETVAL = new maptile; 2362 RETVAL = new maptile;
2351 OUTPUT: 2363 OUTPUT: RETVAL
2352 RETVAL
2353 2364
2354void 2365void
2355maptile::players () 2366maptile::players ()
2356 PPCODE: 2367 PPCODE:
2357 if (GIMME_V == G_SCALAR) 2368 if (GIMME_V == G_SCALAR)
2363 if (pl->ob && pl->ob->map == THIS) 2374 if (pl->ob && pl->ob->map == THIS)
2364 PUSHs (sv_2mortal (to_sv (pl->ob))); 2375 PUSHs (sv_2mortal (to_sv (pl->ob)));
2365 } 2376 }
2366 2377
2367void 2378void
2379maptile::gen_quadmap (int x, int y, int z)
2380 CODE:
2381 gen_quadmap (THIS, x * 50, y * 50, z);
2382
2383void
2368maptile::add_underlay (SV *data, int offset, int stride, SV *palette) 2384maptile::add_underlay (SV *data, int offset, int stride, SV *palette)
2369 CODE: 2385 CODE:
2370{ 2386{
2371 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV) 2387 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV)
2372 croak ("maptile::add_underlay: palette must be arrayref"); 2388 croak ("maptile::add_underlay: palette must be arrayref");
2373 2389
2374 palette = SvRV (palette); 2390 palette = SvRV (palette);
2375 2391
2376 STRLEN idxlen; 2392 STRLEN idxlen;
2377 const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen); 2393 const uint8 *idx = (const uint8 *)SvPVbyte (data, idxlen);
2378 2394
2379 for (int x = 0; x < THIS->width; ++x) 2395 for (int x = 0; x < THIS->width; ++x)
2380 for (int y = 0; y < THIS->height; ++y) 2396 for (int y = 0; y < THIS->height; ++y)
2381 { 2397 {
2382 for (object *op = THIS->at (x, y).bot; op; op = op->above) 2398 for (object *op = THIS->at (x, y).bot; op; op = op->above)
2388 2404
2389 if (IN_RANGE_EXC (offs, 0, idxlen)) 2405 if (IN_RANGE_EXC (offs, 0, idxlen))
2390 { 2406 {
2391 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) 2407 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0))
2392 { 2408 {
2393 object *ob = get_archetype (cfSvPVutf8_nolen (*elem)); 2409 object *ob = archetype::get (cfSvPVutf8_nolen (*elem));
2394 ob->flag [FLAG_NO_MAP_SAVE] = true; 2410 ob->flag [FLAG_NO_MAP_SAVE] = true;
2395 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); 2411 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY);
2396 2412
2397 if (ob->randomitems && !ob->above) 2413 if (ob->randomitems && !ob->above)
2398 { 2414 {
2402 op->flag [FLAG_NO_MAP_SAVE] = true; 2418 op->flag [FLAG_NO_MAP_SAVE] = true;
2403 // TODO: if this is a pickable object, then the item 2419 // TODO: if this is a pickable object, then the item
2404 // will at a bit weird - saving inside the player 2420 // will at a bit weird - saving inside the player
2405 // will clear the flag, but when the player drops 2421 // will clear the flag, but when the player drops
2406 // it without logging out, it keeps the flag. 2422 // it without logging out, it keeps the flag.
2407 // nobody ahs reported this, but this can be rather 2423 // nobody has reported this, but this can be rather
2408 // annoying on persistent maps. 2424 // annoying on persistent maps.
2409 } 2425 }
2410 } 2426 }
2411 } 2427 }
2412 } 2428 }
2413
2414 skip: ; 2429 skip: ;
2415 } 2430 }
2416} 2431}
2417 2432
2418void 2433void
2423 croak ("maptile::set_regiondata: palette must be arrayref"); 2438 croak ("maptile::set_regiondata: palette must be arrayref");
2424 2439
2425 palette = SvRV (palette); 2440 palette = SvRV (palette);
2426 2441
2427 STRLEN idxlen; 2442 STRLEN idxlen;
2428 const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen); 2443 const uint8 *idx = (const uint8 *)SvPVbyte (data, idxlen);
2429 2444
2430 region_ptr *regionmap = new region_ptr [av_len ((AV *)palette) + 1]; 2445 region_ptr *regionmap = new region_ptr [av_len ((AV *)palette) + 1];
2431 uint8_t *regions = salloc<uint8_t> (THIS->size ()); 2446 uint8 *regions = salloc<uint8_t> (THIS->size ());
2432 2447
2433 for (int i = av_len ((AV *)palette) + 1; i--; ) 2448 for (int i = av_len ((AV *)palette) + 1; i--; )
2434 regionmap [i] = region::find (cfSvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1))); 2449 regionmap [i] = region::find (cfSvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1)));
2435 2450
2436 for (int y = 0; y < THIS->height; ++y) 2451 for (int y = 0; y < THIS->height; ++y)
2449 for (int x = 0; x < THIS->width; ++x) 2464 for (int x = 0; x < THIS->width; ++x)
2450 for (int y = 0; y < THIS->height; ++y) 2465 for (int y = 0; y < THIS->height; ++y)
2451 { 2466 {
2452 region *rgn = THIS->region (x, y); 2467 region *rgn = THIS->region (x, y);
2453 2468
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) 2469 if (object *op = THIS->at (x, y).top)
2456 if (rgn->treasure && rndm () < rgn->treasure_density) 2470 if (rgn->treasure && rndm () < rgn->treasure_density)
2457 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty); 2471 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty);
2458 } 2472 }
2459 2473
2489 if (!pos.move (dir).normalise ()) 2503 if (!pos.move (dir).normalise ())
2490 XSRETURN_UNDEF; 2504 XSRETURN_UNDEF;
2491 2505
2492 RETVAL = &*pos; 2506 RETVAL = &*pos;
2493} 2507}
2494 OUTPUT: 2508 OUTPUT: RETVAL
2495 RETVAL
2496 2509
2497void 2510void
2498at (maptile *map, unsigned int x, unsigned int y, int dir = 0) 2511at (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2499 PROTOTYPE: $$$;$ 2512 PROTOTYPE: $$$;$
2500 PPCODE: 2513 PPCODE:
2541# worst xs function of my life 2554# worst xs function of my life
2542bool 2555bool
2543_create_random_map (maptile *self, SV *options) 2556_create_random_map (maptile *self, SV *options)
2544 CODE: 2557 CODE:
2545{ 2558{
2546 random_map_params rmp ((HV *)SvRV (options)); 2559 random_map_params rmp ((HV *)SvRV (options));
2547 RETVAL = self->generate_random_map (&rmp); 2560 RETVAL = self->generate_random_map (&rmp);
2548} 2561}
2549 OUTPUT: 2562 OUTPUT: RETVAL
2550 RETVAL
2551 2563
2552MODULE = cf PACKAGE = cf::mapspace 2564MODULE = cf PACKAGE = cf::mapspace
2553 2565
2554INCLUDE: $PERL $srcdir/genacc mapspace $srcdir/../include/map.h | 2566INCLUDE: $PERL $srcdir/genacc mapspace $srcdir/../include/map.h |
2555 2567
2562 2574
2563archetype *archetypes (U32 index) 2575archetype *archetypes (U32 index)
2564 CODE: 2576 CODE:
2565 RETVAL = index < archetypes.size () ? archetypes [index] : 0; 2577 RETVAL = index < archetypes.size () ? archetypes [index] : 0;
2566 OUTPUT: RETVAL 2578 OUTPUT: RETVAL
2579
2580int skillvec_size ()
2581 CODE:
2582 RETVAL = skillvec.size ();
2583 OUTPUT: RETVAL
2584
2585archetype *skillvec (U32 index)
2586 CODE:
2587 RETVAL = index < skillvec.size () ? (archetype *)(object *)skillvec [index] : 0;
2588 OUTPUT: RETVAL
2589
2590void
2591find_by_type (int type)
2592 PPCODE:
2593 for_all_archetypes (arch)
2594 if (arch->type == type)
2595 XPUSHs (sv_2mortal (to_sv (arch)));
2567 2596
2568INCLUDE: $PERL $srcdir/genacc archetype $srcdir/../include/object.h | 2597INCLUDE: $PERL $srcdir/genacc archetype $srcdir/../include/object.h |
2569 2598
2570MODULE = cf PACKAGE = cf::party 2599MODULE = cf PACKAGE = cf::party
2571 2600
2620list () 2649list ()
2621 PPCODE: 2650 PPCODE:
2622 EXTEND (SP, clients.size ()); 2651 EXTEND (SP, clients.size ());
2623 for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i) 2652 for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i)
2624 PUSHs (sv_2mortal (to_sv (*i))); 2653 PUSHs (sv_2mortal (to_sv (*i)));
2654
2655STRLEN
2656client::inbuf_append (SV *data)
2657 CODE:
2658{
2659 STRLEN len;
2660 char *ptr = SvPVbyte (data, len);
2661
2662 min_it (len, sizeof (THIS->inbuf) - THIS->inbuf_len);
2663 memcpy (THIS->inbuf + THIS->inbuf_len, ptr, len);
2664 THIS->inbuf_len += len;
2665
2666 THIS->inbuf_handle ();
2667
2668 RETVAL = len;
2669}
2670 OUTPUT: RETVAL
2625 2671
2626void 2672void
2627client::send_packet (SV *packet) 2673client::send_packet (SV *packet)
2628 CODE: 2674 CODE:
2629{ 2675{
2647 if (RETVAL) 2693 if (RETVAL)
2648 { 2694 {
2649 THIS->send_face (RETVAL, pri); 2695 THIS->send_face (RETVAL, pri);
2650 THIS->flush_fx (); 2696 THIS->flush_fx ();
2651 } 2697 }
2652 OUTPUT: 2698 OUTPUT: RETVAL
2653 RETVAL
2654 2699
2655int 2700int
2656client::fx_want (int idx, int value = -1) 2701client::fx_want (int idx, int value = -1)
2657 CODE: 2702 CODE:
2658 if (0 < idx && idx < FT_NUM) 2703 if (0 < idx && idx < FT_NUM)
2661 if (items > 2) 2706 if (items > 2)
2662 THIS->fx_want [idx] = value; 2707 THIS->fx_want [idx] = value;
2663 } 2708 }
2664 else 2709 else
2665 RETVAL = 0; 2710 RETVAL = 0;
2666 OUTPUT: 2711 OUTPUT: RETVAL
2667 RETVAL
2668 2712
2669MODULE = cf PACKAGE = cf::sound PREFIX = sound_ 2713MODULE = cf PACKAGE = cf::sound PREFIX = sound_
2670 2714
2671faceidx sound_find (utf8_string name) 2715faceidx sound_find (utf8_string name)
2672 2716
2685faceidx face_find (utf8_string name, faceidx defidx = 0) 2729faceidx face_find (utf8_string name, faceidx defidx = 0)
2686 2730
2687faceidx alloc (utf8_string name) 2731faceidx alloc (utf8_string name)
2688 CODE: 2732 CODE:
2689{ 2733{
2690 do 2734 RETVAL = face_alloc ();
2691 {
2692 RETVAL = faces.size ();
2693 faces.resize (RETVAL + 1);
2694 }
2695 while (!RETVAL); // crude way to leave index 0
2696 2735
2697 faces [RETVAL].name = name; 2736 faces [RETVAL].name = name;
2698 facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL)); 2737 facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL));
2699 2738
2700 if (!strcmp (name, BLANK_FACE_NAME )) blank_face = RETVAL; 2739 if (!strcmp (name, BLANK_FACE_NAME )) blank_face = RETVAL;
2701 if (!strcmp (name, EMPTY_FACE_NAME )) empty_face = RETVAL; 2740 if (!strcmp (name, EMPTY_FACE_NAME )) empty_face = RETVAL;
2702 if (!strcmp (name, MAGICMOUTH_FACE_NAME)) magicmouth_face = RETVAL; 2741 if (!strcmp (name, MAGICMOUTH_FACE_NAME)) magicmouth_face = RETVAL;
2703} 2742}
2743 OUTPUT: RETVAL
2744
2745faceidx faces_size ()
2746 CODE:
2747 RETVAL = faces.size ();
2704 OUTPUT: RETVAL 2748 OUTPUT: RETVAL
2705 2749
2706void set_type (faceidx idx, int value) 2750void set_type (faceidx idx, int value)
2707 ALIAS: 2751 ALIAS:
2708 set_type = 0 2752 set_type = 0
2719 case 2: f->magicmap = value; break; 2763 case 2: f->magicmap = value; break;
2720 case 3: f->smooth = value; break; 2764 case 3: f->smooth = value; break;
2721 case 4: f->smoothlevel = value; break; 2765 case 4: f->smoothlevel = value; break;
2722 } 2766 }
2723 2767
2724void set_data (faceidx idx, int faceset, SV *data, SV *chksum) 2768void set_csum (faceidx idx, int faceset, SV *chksum)
2725 CODE: 2769 CODE:
2726{ 2770{
2727 faceinfo *f = face_info (idx); assert (f); 2771 faceinfo *f = face_info (idx); assert (f);
2728 facedata *d = &(faceset ? f->data64 : f->data32); 2772 facedata *d = f->face + faceset;
2729 sv_to (data, d->data);
2730 STRLEN clen; 2773 STRLEN clen;
2731 char *cdata = SvPVbyte (chksum, clen); 2774 char *cdata = SvPVbyte (chksum, clen);
2732 clen = min (CHKSUM_MAXLEN, clen);
2733 2775
2776 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)); 2777 assert (("cf::face::set_data must be called with a non-empty checksum", clen));
2735 2778
2736 if (clen != d->chksum_len || memcmp (d->chksum, cdata, clen)) 2779 if (clen != d->chksum_len || memcmp (d->chksum, cdata, clen))
2737 { 2780 {
2738 d->chksum_len = clen; 2781 d->chksum_len = clen;
2739 memcpy (d->chksum, cdata, clen); 2782 memcpy (d->chksum, cdata, clen);
2740 2783
2741 // invalidate existing client face info 2784 // invalidate existing client face info
2742 for_all_clients (ns) 2785 for_all_clients (ns)
2743 if (ns->faceset == faceset) 2786 ns->invalidate_face (idx);
2744 {
2745 ns->faces_sent [idx] = false;
2746 ns->force_newmap = true;
2747 }
2748 } 2787 }
2749} 2788}
2750 2789
2751int get_data_size (faceidx idx, int faceset = 0) 2790SV *mangle_csum (SV *chksum)
2752 CODE: 2791 CODE:
2753 facedata *d = face_data (idx, faceset); 2792 STRLEN len;
2754 if (!d) XSRETURN_UNDEF; 2793 char *data = SvPVbyte (chksum, len);
2755 RETVAL = d->data.size (); 2794 RETVAL = newSVpvn (data, min (len, CHKSUM_MAXLEN));
2756 OUTPUT: 2795 OUTPUT: RETVAL
2757 RETVAL
2758 2796
2759SV *get_chksum (faceidx idx, int faceset = 0) 2797SV *get_csum (faceidx idx, int faceset = 0)
2760 CODE: 2798 CODE:
2761 facedata *d = face_data (idx, faceset); 2799 facedata *d = face_data (idx, faceset);
2762 if (!d) XSRETURN_UNDEF; 2800 if (!d) XSRETURN_UNDEF;
2763 RETVAL = newSVpvn ((char *)d->chksum, d->chksum_len); 2801 RETVAL = newSVpvn ((char *)d->chksum, d->chksum_len);
2764 OUTPUT: 2802 OUTPUT: RETVAL
2765 RETVAL
2766 2803
2767SV *get_data (faceidx idx, int faceset = 0) 2804int get_type (faceidx idx)
2768 CODE: 2805 CODE:
2769 facedata *d = face_data (idx, faceset); 2806 faceinfo *f = face_info (idx);
2770 if (!d) XSRETURN_UNDEF; 2807 if (!f) XSRETURN_UNDEF;
2771 RETVAL = newSVpvn (d->data.data (), d->data.length ()); 2808 RETVAL = f->type;
2772 OUTPUT: 2809 OUTPUT: RETVAL
2773 RETVAL 2810
2811SV *get_name (faceidx idx)
2812 CODE:
2813 faceinfo *f = face_info (idx);
2814 if (!f) XSRETURN_UNDEF;
2815 RETVAL = to_sv (f->name);
2816 OUTPUT: RETVAL
2774 2817
2775void invalidate (faceidx idx) 2818void invalidate (faceidx idx)
2776 CODE: 2819 CODE:
2777 for_all_clients (ns) 2820 for_all_clients (ns)
2778 { 2821 ns->invalidate_face (idx);
2779 ns->faces_sent [idx] = false;
2780 ns->force_newmap = true;
2781 }
2782 2822
2783void invalidate_all () 2823void invalidate_all ()
2784 CODE: 2824 CODE:
2785 for_all_clients (ns) 2825 for_all_clients (ns)
2786 { 2826 ns->invalidate_all_faces ();
2787 ns->faces_sent.reset ();
2788 ns->force_newmap = true;
2789 }
2790 2827
2791MODULE = cf PACKAGE = cf::anim PREFIX = anim_ 2828MODULE = cf PACKAGE = cf::anim PREFIX = anim_
2792 2829
2793#INCLUDE: $PERL $srcdir/genacc faceset $srcdir/../include/anim.h | 2830#INCLUDE: $PERL $srcdir/genacc faceset $srcdir/../include/anim.h |
2794 2831
2798 OUTPUT: RETVAL 2835 OUTPUT: RETVAL
2799 2836
2800animidx set (utf8_string name, SV *frames, int facings = 1) 2837animidx set (utf8_string name, SV *frames, int facings = 1)
2801 CODE: 2838 CODE:
2802{ 2839{
2803 if (!SvROK (frames) && SvTYPE (SvRV (frames)) != SVt_PVAV) 2840 if (!SvROK (frames) && SvTYPE (SvRV (frames)) != SVt_PVAV)
2804 croak ("frames must be an arrayref"); 2841 croak ("frames must be an arrayref");
2805 2842
2806 AV *av = (AV *)SvRV (frames); 2843 AV *av = (AV *)SvRV (frames);
2807 2844
2808 animation *anim = &animation::find (name); 2845 animation *anim = &animation::find (name);
2809 if (anim->number) 2846 if (anim->number)
2810 { 2847 {
2811 anim->resize (av_len (av) + 1); 2848 anim->resize (av_len (av) + 1);
2812 anim->facings = facings; 2849 anim->facings = facings;
2813 } 2850 }
2848bool 2885bool
2849errors_are_fatal (bool fatal) 2886errors_are_fatal (bool fatal)
2850 CODE: 2887 CODE:
2851 RETVAL = object_thawer::errors_are_fatal; 2888 RETVAL = object_thawer::errors_are_fatal;
2852 object_thawer::errors_are_fatal = fatal; 2889 object_thawer::errors_are_fatal = fatal;
2853 OUTPUT: 2890 OUTPUT: RETVAL
2854 RETVAL
2855 2891
2856SV * 2892SV *
2857new_from_file (char *klass, octet_string path) 2893new_from_file (char *klass, octet_string path)
2858 CODE: 2894 CODE:
2859 object_thawer *f = new object_thawer (path); 2895 object_thawer *f = new object_thawer (path);
2885 XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ()))); 2921 XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ())));
2886 2922
2887 self->skip (); 2923 self->skip ();
2888 } 2924 }
2889 2925
2926MODULE = cf PACKAGE = cf::treasurelist
2927
2928# quick hack, because I didn't want to implement accessors for treasurelist.
2929# this asks for even more autogen, actually.
2930
2931void
2932expand (treasurelist *list)
2933 PPCODE:
2934 EXTEND (SP, 3);
2935 PUSHs (sv_2mortal (to_sv (list->name)));
2936 PUSHs (sv_2mortal (to_sv (list->total_chance)));
2937 AV *av = newAV ();
2938 PUSHs (sv_2mortal (newRV_noinc ((SV *)av)));
2939 for (treasure *item = list->items; item; item = item->next)
2940 {
2941 AV *iav = newAV ();
2942 av_push (av, newRV_noinc ((SV *)iav));
2943
2944 av_extend (iav, 7);
2945 av_push (iav, to_sv (item->item));
2946 av_push (iav, to_sv (item->name));
2947 av_push (iav, to_sv (item->change_arch.name));
2948 av_push (iav, to_sv (item->change_arch.title));
2949 av_push (iav, to_sv (item->change_arch.slaying));
2950 av_push (iav, to_sv (item->chance));
2951 av_push (iav, to_sv (item->nrof));
2952 av_push (iav, to_sv (item->magic));
2953 }
2954
2890MODULE = cf PACKAGE = cf::layout 2955MODULE = cf PACKAGE = cf::layout
2891 2956
2892INCLUDE: $PERL $srcdir/genacc layout $srcdir/../random_maps/random_map.h | 2957INCLUDE: $PERL $srcdir/genacc layout $srcdir/../include/rmg.h |
2893 2958

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines