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.397 by root, Tue Jan 25 22:39:54 2011 UTC vs.
Revision 1.420 by root, Sun Nov 11 04:29:11 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, faceidx idx, int pri, uint32 size, uint32 fofs)
1164{
1165 CALL_BEGIN (5);
1166 CALL_ARG (ns);
1167 CALL_ARG (idx);
1168 CALL_ARG (pri);
1169 CALL_ARG (size);
1170 CALL_ARG (fofs);
1171 CALL_CALL (cv_cf_ix, G_VOID);
1172 CALL_END;
1173}
1174
1150player * 1175player *
1151player::find (const_utf8_string name) 1176player::find (const_utf8_string name)
1152{ 1177{
1153 CALL_BEGIN (1); 1178 CALL_BEGIN (1);
1154 CALL_ARG (name); 1179 CALL_ARG (name);
1403 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); 1428 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1);
1404 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1); 1429 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1);
1405 stash_cf_layout_wrap = gv_stashpv ("cf::layout::wrap", 1); 1430 stash_cf_layout_wrap = gv_stashpv ("cf::layout::wrap", 1);
1406 stash_ext_map_world = gv_stashpv ("ext::map_world" , 1); 1431 stash_ext_map_world = gv_stashpv ("ext::map_world" , 1);
1407 1432
1408 sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV); 1433 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); 1434 sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV);
1435 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); 1436 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); 1437 sv_next_tick = get_sv ("cf::NEXT_TICK" , 1); SvUPGRADE (sv_next_tick , SVt_NV);
1412 1438
1413 cb_global = get_av ("cf::CB_GLOBAL", 1); 1439 cb_global = get_av ("cf::CB_GLOBAL", 1);
1414 cb_attachable = get_av ("cf::CB_ATTACHABLE", 1); 1440 cb_attachable = get_av ("cf::CB_ATTACHABLE", 1);
1415 cb_object = get_av ("cf::CB_OBJECT", 1); 1441 cb_object = get_av ("cf::CB_OBJECT", 1);
1416 cb_player = get_av ("cf::CB_PLAYER", 1); 1442 cb_player = get_av ("cf::CB_PLAYER", 1);
1423_connect_to_perl_2 () 1449_connect_to_perl_2 ()
1424{ 1450{
1425 cv_cf_do_invoke = (SV *)get_cv ("cf::do_invoke" , 0); assert (cv_cf_do_invoke); 1451 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); 1452 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); 1453 cv_cf_client_send_msg = (SV *)get_cv ("cf::client::send_msg", 0); assert (cv_cf_client_send_msg);
1454 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); 1455 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); 1456 cv_cf_match_match = (SV *)get_cv ("cf::match::match" , 0); assert (cv_cf_match_match);
1430} 1457}
1431 1458
1432MODULE = cf PACKAGE = cf PREFIX = cf_ 1459MODULE = cf PACKAGE = cf PREFIX = cf_
1437 I_CORO_API (PACKAGE); coroapi::GCoroAPI = GCoroAPI; 1464 I_CORO_API (PACKAGE); coroapi::GCoroAPI = GCoroAPI;
1438 1465
1439 _connect_to_perl_1 (); 1466 _connect_to_perl_1 ();
1440 1467
1441 newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1)); 1468 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 1469
1452 static const struct { 1470 static const struct {
1453 const char *name; 1471 const char *name;
1454 IV iv; 1472 IV iv;
1455 } *civ, const_iv[] = { 1473 } *civ, const_iv[] = {
1485 const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE) 1503 const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE)
1486 1504
1487 const_iv (SK_EXP_ADD_SKILL) const_iv (SK_EXP_TOTAL) const_iv (SK_EXP_NONE) 1505 const_iv (SK_EXP_ADD_SKILL) const_iv (SK_EXP_TOTAL) const_iv (SK_EXP_NONE)
1488 const_iv (SK_SUBTRACT_SKILL_EXP) const_iv (SK_EXP_SKILL_ONLY) 1506 const_iv (SK_SUBTRACT_SKILL_EXP) const_iv (SK_EXP_SKILL_ONLY)
1489 1507
1490 const_iv (MAP_ACTIVE) const_iv (MAP_SWAPPED) const_iv (MAP_LOADING) const_iv (MAP_SAVING)
1491 const_iv (MAP_INACTIVE)
1492
1493 const_iv (KLASS_ATTACHABLE) const_iv (KLASS_GLOBAL) const_iv (KLASS_OBJECT) 1508 const_iv (KLASS_ATTACHABLE) const_iv (KLASS_GLOBAL) const_iv (KLASS_OBJECT)
1494 const_iv (KLASS_CLIENT) const_iv (KLASS_PLAYER) const_iv (KLASS_MAP) 1509 const_iv (KLASS_CLIENT) const_iv (KLASS_PLAYER) const_iv (KLASS_MAP)
1495 1510
1496 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT) 1511 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT)
1497 1512
1529 1544
1530void _gv_clear (SV *gv) 1545void _gv_clear (SV *gv)
1531 CODE: 1546 CODE:
1532 assert (SvTYPE (gv) == SVt_PVGV); 1547 assert (SvTYPE (gv) == SVt_PVGV);
1533# define f(sv) { SV *sv_ = (SV *)(sv); sv = 0; SvREFCNT_dec (sv_); } 1548# define f(sv) { SV *sv_ = (SV *)(sv); sv = 0; SvREFCNT_dec (sv_); }
1549 SvREFCNT_inc (gv);
1534 f (GvGP (gv)->gp_form); 1550 f (GvGP (gv)->gp_form);
1535 f (GvGP (gv)->gp_io); 1551 f (GvGP (gv)->gp_io);
1536 f (GvGP (gv)->gp_sv); 1552 f (GvGP (gv)->gp_sv);
1537 f (GvGP (gv)->gp_av); 1553 f (GvGP (gv)->gp_av);
1538 f (GvGP (gv)->gp_hv); 1554 f (GvGP (gv)->gp_hv);
1539 f (GvGP (gv)->gp_cv); 1555 f (GvGP (gv)->gp_cv);
1540 GvCVGEN (gv) = 0; 1556 GvCVGEN (gv) = 0;
1541 GvMULTI_off (gv); 1557 GvMULTI_off (gv);
1558 SvREFCNT_dec (gv);
1542# undef f 1559# undef f
1543 1560
1544void _connect_to_perl_1 () 1561void _connect_to_perl_1 ()
1545 1562
1546void _connect_to_perl_2 () 1563void _connect_to_perl_2 ()
1557 1574
1558 for_all_objects (op) 1575 for_all_objects (op)
1559 op->reattach (); 1576 op->reattach ();
1560} 1577}
1561 1578
1562# support function for map-world.ext
1563void _quantise (SV *data_sv, SV *plt_sv)
1564 CODE:
1565{
1566 if (!SvROK (plt_sv) || SvTYPE (SvRV (plt_sv)) != SVt_PVAV)
1567 croak ("_quantise called with invalid agruments");
1568
1569 plt_sv = SvRV (plt_sv);
1570 SV **plt = AvARRAY (plt_sv);
1571 int plt_count = AvFILL (plt_sv) + 1;
1572
1573 STRLEN len;
1574 char *data = SvPVbyte (data_sv, len);
1575 char *dst = data;
1576
1577 while (len >= 3)
1578 {
1579 for (SV **val_sv = plt + plt_count; val_sv-- > plt; )
1580 {
1581 char *val = SvPVX (*val_sv);
1582
1583 if (val [0] == data [0]
1584 && val [1] == data [1]
1585 && val [2] == data [2])
1586 {
1587 *dst++ = val [3];
1588 goto next;
1589 }
1590 }
1591
1592 croak ("_quantise: color not found in palette: #%02x%02x%02x, at offset %d %d",
1593 (uint8_t)data [0], (uint8_t)data [1], (uint8_t)data [2],
1594 dst - SvPVX (data_sv), len);
1595
1596 next:
1597 data += 3;
1598 len -= 3;
1599 }
1600
1601 SvCUR_set (data_sv, dst - SvPVX (data_sv));
1602}
1603
1604void init_anim () 1579void init_anim ()
1605 1580
1606void init_globals () 1581void init_globals ()
1607 1582
1608void init_attackmess () 1583void init_attackmess ()
1609 1584
1610void init_dynamic () 1585void init_dynamic ()
1611 1586
1612void load_settings () 1587void load_settings ()
1613 1588
1614void reload_exp_table () 1589void _reload_exp_table ()
1615 1590
1616void reload_materials () 1591void _reload_materials ()
1617 1592
1618void init_uuid () 1593void init_uuid ()
1619 CODE: 1594 CODE:
1620 UUID::init (); 1595 UUID::init ();
1621 1596
1654 { 1629 {
1655 ev_async_send (EV_DEFAULT, &tick_watcher); 1630 ev_async_send (EV_DEFAULT, &tick_watcher);
1656 coroapi::cede (); 1631 coroapi::cede ();
1657 } 1632 }
1658 1633
1659void server_tick () 1634void one_tick ()
1660 CODE: 1635 CODE:
1661{ 1636{
1662 ev_now_update (EV_DEFAULT); 1637 ev_now_update (EV_DEFAULT);
1663 NOW = ev_now (EV_DEFAULT); 1638 NOW = ev_now (EV_DEFAULT);
1664 SvNV_set (sv_now, NOW); SvNOK_only (sv_now); 1639 SvNV_set (sv_now, NOW); SvNOK_only (sv_now);
1665 SvNV_set (sv_tick_start, NOW); SvNOK_only (sv_tick_start); 1640 SvNV_set (sv_tick_start, NOW); SvNOK_only (sv_tick_start);
1666 runtime = SvNVX (sv_runtime); 1641 runtime = SvNVX (sv_runtime);
1667 1642
1643 one_tick ();
1644
1668 server_tick (); 1645 ++server_tick;
1646 SvUV_set (sv_server_tick, server_tick); SvIOK_only_UV (sv_server_tick);
1669 1647
1670 ev_now_update (EV_DEFAULT); 1648 ev_now_update (EV_DEFAULT);
1671 NOW = ev_now (EV_DEFAULT); 1649 NOW = ev_now (EV_DEFAULT);
1672 SvNV_set (sv_now, NOW); SvNOK_only (sv_now); 1650 SvNV_set (sv_now, NOW); SvNOK_only (sv_now);
1651
1673 runtime += TICK; 1652 runtime += TICK;
1674 SvNV_set (sv_runtime, runtime); SvNOK_only (sv_runtime); 1653 SvNV_set (sv_runtime, runtime); SvNOK_only (sv_runtime);
1675} 1654}
1676 1655
1677NV floor (NV x) 1656NV floor (NV x)
1826 1805
1827int exp_to_level (val64 exp) 1806int exp_to_level (val64 exp)
1828 1807
1829val64 level_to_min_exp (int level) 1808val64 level_to_min_exp (int level)
1830 1809
1810const_utf8_string
1811spellpathnames (int idx)
1812 CODE:
1813 RETVAL = spellpathnames [idx];
1814 OUTPUT: RETVAL
1815
1831SV * 1816SV *
1832attacktype_name (int atnr) 1817attacktype_name (int atnr)
1833 CODE: 1818 CODE:
1834 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS) 1819 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1835 ? newSVpv (attacktype_name [atnr], 0) 1820 ? newSVpv (attacktype_name [atnr], 0)
2144# dumb kludgy misdesigned plug-in api slowly gets on my nerves. 2129# dumb kludgy misdesigned plug-in api slowly gets on my nerves.
2145 2130
2146object *new (utf8_string archetype = 0) 2131object *new (utf8_string archetype = 0)
2147 PROTOTYPE: ;$ 2132 PROTOTYPE: ;$
2148 CODE: 2133 CODE:
2149 RETVAL = archetype ? get_archetype (archetype) : object::create (); 2134 RETVAL = archetype
2135 ? archetype::get (archetype)
2136 : object::create ();
2150 OUTPUT: 2137 OUTPUT:
2151 RETVAL 2138 RETVAL
2152 2139
2153object *generate (utf8_string arch, object *creator) 2140object *generate (utf8_string arch, object *creator)
2154 CODE: 2141 CODE:
2155 object *obj = get_archetype (arch); 2142 object *obj = archetype::get (arch);
2156 fix_generated_item (obj, creator, 0, 0, GT_MINIMAL); 2143 fix_generated_item (obj, creator, 0, 0, GT_MINIMAL);
2157 RETVAL = obj; 2144 RETVAL = obj;
2158 OUTPUT: 2145 OUTPUT:
2159 RETVAL 2146 RETVAL
2160 2147
2170 RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y); 2157 RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y);
2171 2158
2172 if (RETVAL->destroyed ()) 2159 if (RETVAL->destroyed ())
2173 RETVAL = 0; 2160 RETVAL = 0;
2174} 2161}
2162 OUTPUT:
2163 RETVAL
2175 2164
2176shstr 2165shstr
2177object::kv_get (shstr key) 2166object::kv_get (shstr key)
2167 CODE:
2168 RETVAL = THIS->kv.get (key);
2169 OUTPUT:
2170 RETVAL
2178 2171
2179void 2172void
2180object::kv_del (shstr key) 2173object::kv_del (shstr key)
2174 CODE:
2175 THIS->kv.del (key);
2181 2176
2182void 2177void
2183object::kv_set (shstr key, shstr value) 2178object::kv_set (shstr key, shstr value)
2179 CODE:
2180 THIS->kv.set (key, value);
2184 2181
2185object *get_nearest_player (object *ob) 2182object *get_nearest_player (object *ob)
2186 ALIAS: nearest_player = 0 2183 ALIAS: nearest_player = 0
2187 PREINIT: 2184 PREINIT:
2188 extern object *get_nearest_player (object *); 2185 extern object *get_nearest_player (object *);
2391 if (pl->ob && pl->ob->map == THIS) 2388 if (pl->ob && pl->ob->map == THIS)
2392 PUSHs (sv_2mortal (to_sv (pl->ob))); 2389 PUSHs (sv_2mortal (to_sv (pl->ob)));
2393 } 2390 }
2394 2391
2395void 2392void
2393maptile::gen_quadmap (int x, int y, int z)
2394 CODE:
2395 gen_quadmap (THIS, x * 50, y * 50, z);
2396
2397void
2396maptile::add_underlay (SV *data, int offset, int stride, SV *palette) 2398maptile::add_underlay (SV *data, int offset, int stride, SV *palette)
2397 CODE: 2399 CODE:
2398{ 2400{
2399 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV) 2401 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV)
2400 croak ("maptile::add_underlay: palette must be arrayref"); 2402 croak ("maptile::add_underlay: palette must be arrayref");
2401 2403
2402 palette = SvRV (palette); 2404 palette = SvRV (palette);
2403 2405
2404 STRLEN idxlen; 2406 STRLEN idxlen;
2405 const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen); 2407 const uint8 *idx = (const uint8 *)SvPVbyte (data, idxlen);
2406 2408
2407 for (int x = 0; x < THIS->width; ++x) 2409 for (int x = 0; x < THIS->width; ++x)
2408 for (int y = 0; y < THIS->height; ++y) 2410 for (int y = 0; y < THIS->height; ++y)
2409 { 2411 {
2410 for (object *op = THIS->at (x, y).bot; op; op = op->above) 2412 for (object *op = THIS->at (x, y).bot; op; op = op->above)
2416 2418
2417 if (IN_RANGE_EXC (offs, 0, idxlen)) 2419 if (IN_RANGE_EXC (offs, 0, idxlen))
2418 { 2420 {
2419 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) 2421 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0))
2420 { 2422 {
2421 object *ob = get_archetype (cfSvPVutf8_nolen (*elem)); 2423 object *ob = archetype::get (cfSvPVutf8_nolen (*elem));
2422 ob->flag [FLAG_NO_MAP_SAVE] = true; 2424 ob->flag [FLAG_NO_MAP_SAVE] = true;
2423 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); 2425 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY);
2424 2426
2425 if (ob->randomitems && !ob->above) 2427 if (ob->randomitems && !ob->above)
2426 { 2428 {
2430 op->flag [FLAG_NO_MAP_SAVE] = true; 2432 op->flag [FLAG_NO_MAP_SAVE] = true;
2431 // TODO: if this is a pickable object, then the item 2433 // TODO: if this is a pickable object, then the item
2432 // will at a bit weird - saving inside the player 2434 // will at a bit weird - saving inside the player
2433 // will clear the flag, but when the player drops 2435 // will clear the flag, but when the player drops
2434 // it without logging out, it keeps the flag. 2436 // it without logging out, it keeps the flag.
2435 // nobody ahs reported this, but this can be rather 2437 // nobody has reported this, but this can be rather
2436 // annoying on persistent maps. 2438 // annoying on persistent maps.
2437 } 2439 }
2438 } 2440 }
2439 } 2441 }
2440 } 2442 }
2441
2442 skip: ; 2443 skip: ;
2443 } 2444 }
2444} 2445}
2445 2446
2446void 2447void
2451 croak ("maptile::set_regiondata: palette must be arrayref"); 2452 croak ("maptile::set_regiondata: palette must be arrayref");
2452 2453
2453 palette = SvRV (palette); 2454 palette = SvRV (palette);
2454 2455
2455 STRLEN idxlen; 2456 STRLEN idxlen;
2456 const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen); 2457 const uint8 *idx = (const uint8 *)SvPVbyte (data, idxlen);
2457 2458
2458 region_ptr *regionmap = new region_ptr [av_len ((AV *)palette) + 1]; 2459 region_ptr *regionmap = new region_ptr [av_len ((AV *)palette) + 1];
2459 uint8_t *regions = salloc<uint8_t> (THIS->size ()); 2460 uint8 *regions = salloc<uint8_t> (THIS->size ());
2460 2461
2461 for (int i = av_len ((AV *)palette) + 1; i--; ) 2462 for (int i = av_len ((AV *)palette) + 1; i--; )
2462 regionmap [i] = region::find (cfSvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1))); 2463 regionmap [i] = region::find (cfSvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1)));
2463 2464
2464 for (int y = 0; y < THIS->height; ++y) 2465 for (int y = 0; y < THIS->height; ++y)
2477 for (int x = 0; x < THIS->width; ++x) 2478 for (int x = 0; x < THIS->width; ++x)
2478 for (int y = 0; y < THIS->height; ++y) 2479 for (int y = 0; y < THIS->height; ++y)
2479 { 2480 {
2480 region *rgn = THIS->region (x, y); 2481 region *rgn = THIS->region (x, y);
2481 2482
2482 //fprintf (stderr, "%d,%d %f %p\n", x, y, rgn->treasure_density,rgn->treasure);//D
2483 if (object *op = THIS->at (x, y).top) 2483 if (object *op = THIS->at (x, y).top)
2484 if (rgn->treasure && rndm () < rgn->treasure_density) 2484 if (rgn->treasure && rndm () < rgn->treasure_density)
2485 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty); 2485 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty);
2486 } 2486 }
2487 2487
2591archetype *archetypes (U32 index) 2591archetype *archetypes (U32 index)
2592 CODE: 2592 CODE:
2593 RETVAL = index < archetypes.size () ? archetypes [index] : 0; 2593 RETVAL = index < archetypes.size () ? archetypes [index] : 0;
2594 OUTPUT: RETVAL 2594 OUTPUT: RETVAL
2595 2595
2596int skillvec_size ()
2597 CODE:
2598 RETVAL = skillvec.size ();
2599 OUTPUT: RETVAL
2600
2601archetype *skillvec (U32 index)
2602 CODE:
2603 RETVAL = index < skillvec.size () ? (archetype *)(object *)skillvec [index] : 0;
2604 OUTPUT: RETVAL
2605
2596INCLUDE: $PERL $srcdir/genacc archetype $srcdir/../include/object.h | 2606INCLUDE: $PERL $srcdir/genacc archetype $srcdir/../include/object.h |
2597 2607
2598MODULE = cf PACKAGE = cf::party 2608MODULE = cf PACKAGE = cf::party
2599 2609
2600partylist *first () 2610partylist *first ()
2648list () 2658list ()
2649 PPCODE: 2659 PPCODE:
2650 EXTEND (SP, clients.size ()); 2660 EXTEND (SP, clients.size ());
2651 for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i) 2661 for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i)
2652 PUSHs (sv_2mortal (to_sv (*i))); 2662 PUSHs (sv_2mortal (to_sv (*i)));
2663
2664STRLEN
2665client::inbuf_append (SV *data)
2666 CODE:
2667{
2668 STRLEN len;
2669 char *ptr = SvPVbyte (data, len);
2670
2671 min_it (len, sizeof (THIS->inbuf) - THIS->inbuf_len);
2672 memcpy (THIS->inbuf + THIS->inbuf_len, ptr, len);
2673 THIS->inbuf_len += len;
2674
2675 THIS->inbuf_handle ();
2676
2677 RETVAL = len;
2678}
2679 OUTPUT: RETVAL
2653 2680
2654void 2681void
2655client::send_packet (SV *packet) 2682client::send_packet (SV *packet)
2656 CODE: 2683 CODE:
2657{ 2684{
2713faceidx face_find (utf8_string name, faceidx defidx = 0) 2740faceidx face_find (utf8_string name, faceidx defidx = 0)
2714 2741
2715faceidx alloc (utf8_string name) 2742faceidx alloc (utf8_string name)
2716 CODE: 2743 CODE:
2717{ 2744{
2718 do 2745 RETVAL = face_alloc ();
2719 {
2720 RETVAL = faces.size ();
2721 faces.resize (RETVAL + 1);
2722 }
2723 while (!RETVAL); // crude way to leave index 0
2724 2746
2725 faces [RETVAL].name = name; 2747 faces [RETVAL].name = name;
2726 facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL)); 2748 facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL));
2727 2749
2728 if (!strcmp (name, BLANK_FACE_NAME )) blank_face = RETVAL; 2750 if (!strcmp (name, BLANK_FACE_NAME )) blank_face = RETVAL;
2729 if (!strcmp (name, EMPTY_FACE_NAME )) empty_face = RETVAL; 2751 if (!strcmp (name, EMPTY_FACE_NAME )) empty_face = RETVAL;
2730 if (!strcmp (name, MAGICMOUTH_FACE_NAME)) magicmouth_face = RETVAL; 2752 if (!strcmp (name, MAGICMOUTH_FACE_NAME)) magicmouth_face = RETVAL;
2731} 2753}
2754 OUTPUT: RETVAL
2755
2756faceidx faces_size ()
2757 CODE:
2758 RETVAL = faces.size ();
2732 OUTPUT: RETVAL 2759 OUTPUT: RETVAL
2733 2760
2734void set_type (faceidx idx, int value) 2761void set_type (faceidx idx, int value)
2735 ALIAS: 2762 ALIAS:
2736 set_type = 0 2763 set_type = 0
2747 case 2: f->magicmap = value; break; 2774 case 2: f->magicmap = value; break;
2748 case 3: f->smooth = value; break; 2775 case 3: f->smooth = value; break;
2749 case 4: f->smoothlevel = value; break; 2776 case 4: f->smoothlevel = value; break;
2750 } 2777 }
2751 2778
2752void set_data (faceidx idx, int faceset, SV *data, SV *chksum) 2779void set_data (faceidx idx, int faceset, uint32 size, uint32 fofs, SV *chksum)
2753 CODE: 2780 CODE:
2754{ 2781{
2755 faceinfo *f = face_info (idx); assert (f); 2782 faceinfo *f = face_info (idx); assert (f);
2756 facedata *d = f->face + faceset; 2783 facedata *d = f->face + faceset;
2757 sv_to (data, d->data);
2758 STRLEN clen; 2784 STRLEN clen;
2759 char *cdata = SvPVbyte (chksum, clen); 2785 char *cdata = SvPVbyte (chksum, clen);
2760 clen = min (CHKSUM_MAXLEN, clen);
2761 2786
2787 assert (("cf::face::set_data called with too long checksum", clen <= CHKSUM_MAXLEN));
2762 assert (("cf::face::set_data must be called with a non-empty checksum", clen)); 2788 assert (("cf::face::set_data must be called with a non-empty checksum", clen));
2789
2790 d->size = size;
2791 d->fofs = fofs;
2763 2792
2764 if (clen != d->chksum_len || memcmp (d->chksum, cdata, clen)) 2793 if (clen != d->chksum_len || memcmp (d->chksum, cdata, clen))
2765 { 2794 {
2766 d->chksum_len = clen; 2795 d->chksum_len = clen;
2767 memcpy (d->chksum, cdata, clen); 2796 memcpy (d->chksum, cdata, clen);
2768 2797
2769 // invalidate existing client face info 2798 // invalidate existing client face info
2770 for_all_clients (ns) 2799 for_all_clients (ns)
2771 if (ns->faceset == faceset) 2800 ns->invalidate_face (idx);
2772 {
2773 ns->faces_sent [idx] = false;
2774 ns->force_newmap = true;
2775 }
2776 } 2801 }
2777} 2802}
2778 2803
2779int get_data_size (faceidx idx, int faceset = 0) 2804void set_meta (faceidx idx, SV *sv)
2780 CODE: 2805 CODE:
2781 facedata *d = face_data (idx, faceset); 2806{
2782 if (!d) XSRETURN_UNDEF; 2807 faceinfo *f = face_info (idx); assert (f);
2783 RETVAL = d->data.size (); 2808 SvREFCNT_dec (f->meta_hv);
2809 f->meta_hv = SvOK (sv) ? (HV *)SvREFCNT_inc (SvRV (sv)) : 0;
2810}
2811
2812SV *mangle_chksum (SV *chksum)
2813 CODE:
2814 STRLEN len;
2815 char *data = SvPVbyte (chksum, len);
2816 RETVAL = newSVpvn (data, min (len, CHKSUM_MAXLEN));
2784 OUTPUT: 2817 OUTPUT:
2785 RETVAL 2818 RETVAL
2786 2819
2787SV *get_chksum (faceidx idx, int faceset = 0) 2820SV *get_chksum (faceidx idx, int faceset = 0)
2788 CODE: 2821 CODE:
2789 facedata *d = face_data (idx, faceset); 2822 facedata *d = face_data (idx, faceset);
2790 if (!d) XSRETURN_UNDEF; 2823 if (!d) XSRETURN_UNDEF;
2791 RETVAL = newSVpvn ((char *)d->chksum, d->chksum_len); 2824 RETVAL = newSVpvn ((char *)d->chksum, d->chksum_len);
2792 OUTPUT: 2825 OUTPUT:
2793 RETVAL 2826 RETVAL
2794 2827
2828int get_type (faceidx idx)
2829 CODE:
2830 faceinfo *f = face_info (idx);
2831 if (!f) XSRETURN_UNDEF;
2832 RETVAL = f->type;
2833 OUTPUT:
2834 RETVAL
2835
2836SV *get_name (faceidx idx)
2837 CODE:
2838 faceinfo *f = face_info (idx);
2839 if (!f) XSRETURN_UNDEF;
2840 RETVAL = to_sv (f->name);
2841 OUTPUT:
2842 RETVAL
2843
2795SV *get_data (faceidx idx, int faceset = 0) 2844uint32 get_size (faceidx idx, int faceset = 0)
2796 CODE: 2845 CODE:
2797 facedata *d = face_data (idx, faceset); 2846 facedata *d = face_data (idx, faceset);
2798 if (!d) XSRETURN_UNDEF; 2847 if (!d) XSRETURN_UNDEF;
2799 RETVAL = newSVpvn (d->data.data (), d->data.length ()); 2848 RETVAL = d->size;
2800 OUTPUT: 2849 OUTPUT:
2801 RETVAL 2850 RETVAL
2802 2851
2852uint32 get_fofs (faceidx idx, int faceset = 0)
2853 CODE:
2854 facedata *d = face_data (idx, faceset);
2855 if (!d) XSRETURN_UNDEF;
2856 RETVAL = d->fofs;
2857 OUTPUT:
2858 RETVAL
2859
2860SV *get_meta (faceidx idx)
2861 CODE:
2862 faceinfo *f = face_info (idx); assert (f);
2863 if (!f || !f->meta_hv) XSRETURN_UNDEF;
2864 RETVAL = newRV_inc ((SV *)f->meta_hv);
2865 OUTPUT:
2866 RETVAL
2867
2803void invalidate (faceidx idx) 2868void invalidate (faceidx idx)
2804 CODE: 2869 CODE:
2805 for_all_clients (ns) 2870 for_all_clients (ns)
2806 { 2871 ns->invalidate_face (idx);
2807 ns->faces_sent [idx] = false;
2808 ns->force_newmap = true;
2809 }
2810 2872
2811void invalidate_all () 2873void invalidate_all ()
2812 CODE: 2874 CODE:
2813 for_all_clients (ns) 2875 for_all_clients (ns)
2814 { 2876 ns->invalidate_all_faces ();
2815 ns->faces_sent.reset ();
2816 ns->force_newmap = true;
2817 }
2818 2877
2819MODULE = cf PACKAGE = cf::anim PREFIX = anim_ 2878MODULE = cf PACKAGE = cf::anim PREFIX = anim_
2820 2879
2821#INCLUDE: $PERL $srcdir/genacc faceset $srcdir/../include/anim.h | 2880#INCLUDE: $PERL $srcdir/genacc faceset $srcdir/../include/anim.h |
2822 2881
2826 OUTPUT: RETVAL 2885 OUTPUT: RETVAL
2827 2886
2828animidx set (utf8_string name, SV *frames, int facings = 1) 2887animidx set (utf8_string name, SV *frames, int facings = 1)
2829 CODE: 2888 CODE:
2830{ 2889{
2831 if (!SvROK (frames) && SvTYPE (SvRV (frames)) != SVt_PVAV) 2890 if (!SvROK (frames) && SvTYPE (SvRV (frames)) != SVt_PVAV)
2832 croak ("frames must be an arrayref"); 2891 croak ("frames must be an arrayref");
2833 2892
2834 AV *av = (AV *)SvRV (frames); 2893 AV *av = (AV *)SvRV (frames);
2835 2894
2836 animation *anim = &animation::find (name); 2895 animation *anim = &animation::find (name);
2837 if (anim->number) 2896 if (anim->number)
2838 { 2897 {
2839 anim->resize (av_len (av) + 1); 2898 anim->resize (av_len (av) + 1);
2840 anim->facings = facings; 2899 anim->facings = facings;
2841 } 2900 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines