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.402 by root, Sun May 1 13:18:24 2011 UTC vs.
Revision 1.424 by root, Wed Nov 14 06:18:13 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
67static int tick_inhibit; 67static int tick_inhibit;
68static int tick_pending; 68static int tick_pending;
69 69
70global gbl_ev; 70global gbl_ev;
71static 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;
72static 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;
73static AV *av_reflect; 73static AV *av_reflect;
74 74
75bitset<NUM_EVENT_TYPES> ev_want_event; 75bitset<NUM_EVENT_TYPES> ev_want_event;
76bitset<NUM_TYPES> ev_want_type; 76bitset<NUM_TYPES> ev_want_type;
77 77
92 92
93static SV 93static SV
94 *cv_cf_do_invoke, 94 *cv_cf_do_invoke,
95 *cv_cf__can_merge, 95 *cv_cf__can_merge,
96 *cv_cf_client_send_msg, 96 *cv_cf_client_send_msg,
97 *cv_cf_ix,
97 *cv_cf_tick, 98 *cv_cf_tick,
98 *cv_cf_match_match; 99 *cv_cf_match_match;
99 100
100#ifndef newSVpv_utf8 101#ifndef newSVpv_utf8
101static SV * 102static SV *
253 { 254 {
254 static int last_mortalcount; 255 static int last_mortalcount;
255 if (mortals.size () != last_mortalcount) 256 if (mortals.size () != last_mortalcount)
256 { 257 {
257 last_mortalcount = mortals.size (); 258 last_mortalcount = mortals.size ();
258 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)");
259 263
260 if (0) 264 if (0)
261 { 265 {
262 for (int j = 0; j < mortals.size (); ++j)//D 266 for (int j = 0; j < mortals.size (); ++j)//D
263 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
622 STRLEN len; 626 STRLEN len;
623 char *data = SvPVbyte (sv, len); 627 char *data = SvPVbyte (sv, len);
624 v.assign (data, len); 628 v.assign (data, len);
625} 629}
626 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
627static inline void sv_to (SV *sv, UUID &v) 639static inline void sv_to (SV *sv, UUID &v)
628{ 640{
629 if (!v.parse (SvPV_nolen (sv))) 641 if (!v.parse (SvPV_nolen (sv)))
630 croak ("unparsable uuid: %s", SvPV_nolen (sv)); 642 croak ("unparsable uuid: %s", SvPV_nolen (sv));
631} 643}
1146 CALL_ARG (originator); 1158 CALL_ARG (originator);
1147 CALL_CALL ("cf::mapscript::activate", G_VOID); 1159 CALL_CALL ("cf::mapscript::activate", G_VOID);
1148 CALL_END; 1160 CALL_END;
1149} 1161}
1150 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
1151player * 1174player *
1152player::find (const_utf8_string name) 1175player::find (const_utf8_string name)
1153{ 1176{
1154 CALL_BEGIN (1); 1177 CALL_BEGIN (1);
1155 CALL_ARG (name); 1178 CALL_ARG (name);
1404 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); 1427 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1);
1405 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1); 1428 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1);
1406 stash_cf_layout_wrap = gv_stashpv ("cf::layout::wrap", 1); 1429 stash_cf_layout_wrap = gv_stashpv ("cf::layout::wrap", 1);
1407 stash_ext_map_world = gv_stashpv ("ext::map_world" , 1); 1430 stash_ext_map_world = gv_stashpv ("ext::map_world" , 1);
1408 1431
1409 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);
1410 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);
1411 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);
1412 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);
1413 1437
1414 cb_global = get_av ("cf::CB_GLOBAL", 1); 1438 cb_global = get_av ("cf::CB_GLOBAL", 1);
1415 cb_attachable = get_av ("cf::CB_ATTACHABLE", 1); 1439 cb_attachable = get_av ("cf::CB_ATTACHABLE", 1);
1416 cb_object = get_av ("cf::CB_OBJECT", 1); 1440 cb_object = get_av ("cf::CB_OBJECT", 1);
1417 cb_player = get_av ("cf::CB_PLAYER", 1); 1441 cb_player = get_av ("cf::CB_PLAYER", 1);
1424_connect_to_perl_2 () 1448_connect_to_perl_2 ()
1425{ 1449{
1426 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);
1427 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);
1428 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);
1429 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);
1430 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);
1431} 1456}
1432 1457
1433MODULE = cf PACKAGE = cf PREFIX = cf_ 1458MODULE = cf PACKAGE = cf PREFIX = cf_
1438 I_CORO_API (PACKAGE); coroapi::GCoroAPI = GCoroAPI; 1463 I_CORO_API (PACKAGE); coroapi::GCoroAPI = GCoroAPI;
1439 1464
1440 _connect_to_perl_1 (); 1465 _connect_to_perl_1 ();
1441 1466
1442 newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1)); 1467 newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1));
1443
1444 //{
1445 // require_pv ("Time::HiRes");
1446 //
1447 // SV **svp = hv_fetch (PL_modglobal, "Time::NVtime", 12, 0);
1448 // if (!svp) croak ("Time::HiRes is required");
1449 // if (!SvIOK(*svp)) croak ("Time::NVtime isn’t a function pointer");
1450 // coroapi::time = INT2PTR (double(*)(), SvIV(*svp));
1451 //}
1452 1468
1453 static const struct { 1469 static const struct {
1454 const char *name; 1470 const char *name;
1455 IV iv; 1471 IV iv;
1456 } *civ, const_iv[] = { 1472 } *civ, const_iv[] = {
1486 const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE) 1502 const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE)
1487 1503
1488 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)
1489 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)
1490 1506
1491 const_iv (MAP_ACTIVE) const_iv (MAP_SWAPPED) const_iv (MAP_LOADING) const_iv (MAP_SAVING)
1492 const_iv (MAP_INACTIVE)
1493
1494 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)
1495 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)
1496 1509
1497 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)
1498 1511
1530 1543
1531void _gv_clear (SV *gv) 1544void _gv_clear (SV *gv)
1532 CODE: 1545 CODE:
1533 assert (SvTYPE (gv) == SVt_PVGV); 1546 assert (SvTYPE (gv) == SVt_PVGV);
1534# 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);
1535 f (GvGP (gv)->gp_form); 1549 f (GvGP (gv)->gp_form);
1536 f (GvGP (gv)->gp_io); 1550 f (GvGP (gv)->gp_io);
1537 f (GvGP (gv)->gp_sv); 1551 f (GvGP (gv)->gp_sv);
1538 f (GvGP (gv)->gp_av); 1552 f (GvGP (gv)->gp_av);
1539 f (GvGP (gv)->gp_hv); 1553 f (GvGP (gv)->gp_hv);
1540 f (GvGP (gv)->gp_cv); 1554 f (GvGP (gv)->gp_cv);
1541 GvCVGEN (gv) = 0; 1555 GvCVGEN (gv) = 0;
1542 GvMULTI_off (gv); 1556 GvMULTI_off (gv);
1557 SvREFCNT_dec (gv);
1543# undef f 1558# undef f
1544 1559
1545void _connect_to_perl_1 () 1560void _connect_to_perl_1 ()
1546 1561
1547void _connect_to_perl_2 () 1562void _connect_to_perl_2 ()
1568 1583
1569void init_dynamic () 1584void init_dynamic ()
1570 1585
1571void load_settings () 1586void load_settings ()
1572 1587
1573void reload_exp_table () 1588void _reload_exp_table ()
1574 1589
1575void reload_materials () 1590void _reload_materials ()
1576 1591
1577void init_uuid () 1592void init_uuid ()
1578 CODE: 1593 CODE:
1579 UUID::init (); 1594 UUID::init ();
1580 1595
1613 { 1628 {
1614 ev_async_send (EV_DEFAULT, &tick_watcher); 1629 ev_async_send (EV_DEFAULT, &tick_watcher);
1615 coroapi::cede (); 1630 coroapi::cede ();
1616 } 1631 }
1617 1632
1618void server_tick () 1633void one_tick ()
1619 CODE: 1634 CODE:
1620{ 1635{
1621 ev_now_update (EV_DEFAULT); 1636 ev_now_update (EV_DEFAULT);
1622 NOW = ev_now (EV_DEFAULT); 1637 NOW = ev_now (EV_DEFAULT);
1623 SvNV_set (sv_now, NOW); SvNOK_only (sv_now); 1638 SvNV_set (sv_now, NOW); SvNOK_only (sv_now);
1624 SvNV_set (sv_tick_start, NOW); SvNOK_only (sv_tick_start); 1639 SvNV_set (sv_tick_start, NOW); SvNOK_only (sv_tick_start);
1625 runtime = SvNVX (sv_runtime); 1640 runtime = SvNVX (sv_runtime);
1626 1641
1642 one_tick ();
1643
1627 server_tick (); 1644 ++server_tick;
1645 SvUV_set (sv_server_tick, server_tick); SvIOK_only_UV (sv_server_tick);
1628 1646
1629 ev_now_update (EV_DEFAULT); 1647 ev_now_update (EV_DEFAULT);
1630 NOW = ev_now (EV_DEFAULT); 1648 NOW = ev_now (EV_DEFAULT);
1631 SvNV_set (sv_now, NOW); SvNOK_only (sv_now); 1649 SvNV_set (sv_now, NOW); SvNOK_only (sv_now);
1650
1632 runtime += TICK; 1651 runtime += TICK;
1633 SvNV_set (sv_runtime, runtime); SvNOK_only (sv_runtime); 1652 SvNV_set (sv_runtime, runtime); SvNOK_only (sv_runtime);
1634} 1653}
1635 1654
1636NV floor (NV x) 1655NV floor (NV x)
1640NV rndm (...) 1659NV rndm (...)
1641 ALIAS: 1660 ALIAS:
1642 rmg_rndm = 1 1661 rmg_rndm = 1
1643 CODE: 1662 CODE:
1644{ 1663{
1645 rand_gen &gen = ix ? rmg_rndm : rndm; 1664 rand_gen &gen = ix ? rmg_rndm : rndm;
1646 switch (items) 1665 switch (items)
1647 { 1666 {
1648 case 0: RETVAL = gen (); break; 1667 case 0: RETVAL = gen (); break;
1649 case 1: RETVAL = gen (SvUV (ST (0))); break; 1668 case 1: RETVAL = gen (SvUV (ST (0))); break;
1650 case 2: RETVAL = gen (SvIV (ST (0)), SvIV (ST (1))); break; 1669 case 2: RETVAL = gen (SvIV (ST (0)), SvIV (ST (1))); break;
1785 1804
1786int exp_to_level (val64 exp) 1805int exp_to_level (val64 exp)
1787 1806
1788val64 level_to_min_exp (int level) 1807val64 level_to_min_exp (int level)
1789 1808
1809const_utf8_string
1810spellpathnames (int idx)
1811 CODE:
1812 RETVAL = spellpathnames [idx];
1813 OUTPUT: RETVAL
1814
1790SV * 1815SV *
1791attacktype_name (int atnr) 1816attacktype_name (int atnr)
1792 CODE: 1817 CODE:
1793 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS) 1818 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1794 ? newSVpv (attacktype_name [atnr], 0) 1819 ? newSVpv (attacktype_name [atnr], 0)
1865load_resource_file_ (octet_string filename) 1890load_resource_file_ (octet_string filename)
1866 1891
1867void 1892void
1868fix_weight () 1893fix_weight ()
1869 1894
1895utf8_string
1896expand_cfpod (int hintmode, int gender, const_utf8_string cfpod)
1897 PPCODE:
1898 XPUSHs (to_sv (player::expand_cfpod (hintmode, gender, cfpod)));
1899
1870MODULE = cf PACKAGE = cf::attachable 1900MODULE = cf PACKAGE = cf::attachable
1871 1901
1872int 1902int
1873valid (SV *obj) 1903valid (SV *obj)
1874 CODE: 1904 CODE:
2097 2127
2098void fix_generated_item (object *op, object *creator, int difficulty, int max_magic, int flags); 2128void fix_generated_item (object *op, object *creator, int difficulty, int max_magic, int flags);
2099 2129
2100MODULE = cf PACKAGE = cf::object PREFIX = cf_ 2130MODULE = cf PACKAGE = cf::object PREFIX = cf_
2101 2131
2102# no clean way to get an object from an archetype - stupid idiotic
2103# dumb kludgy misdesigned plug-in api slowly gets on my nerves.
2104
2105object *new (utf8_string archetype = 0) 2132object *new (utf8_string archetype = 0)
2106 PROTOTYPE: ;$ 2133 PROTOTYPE: ;$
2107 CODE: 2134 CODE:
2108 RETVAL = archetype ? get_archetype (archetype) : object::create (); 2135 RETVAL = archetype
2136 ? archetype::get (archetype)
2137 : object::create ();
2109 OUTPUT: 2138 OUTPUT:
2110 RETVAL 2139 RETVAL
2111 2140
2112object *generate (utf8_string arch, object *creator) 2141object *generate (utf8_string arch, object *creator)
2113 CODE: 2142 CODE:
2114 object *obj = get_archetype (arch); 2143 object *obj = archetype::get (arch);
2115 fix_generated_item (obj, creator, 0, 0, GT_MINIMAL); 2144 fix_generated_item (obj, creator, 0, 0, GT_MINIMAL);
2116 RETVAL = obj; 2145 RETVAL = obj;
2117 OUTPUT: 2146 OUTPUT:
2118 RETVAL 2147 RETVAL
2119 2148
2129 RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y); 2158 RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y);
2130 2159
2131 if (RETVAL->destroyed ()) 2160 if (RETVAL->destroyed ())
2132 RETVAL = 0; 2161 RETVAL = 0;
2133} 2162}
2163 OUTPUT:
2164 RETVAL
2134 2165
2135shstr 2166shstr
2136object::kv_get (shstr key) 2167object::kv_get (shstr key)
2137 CODE: 2168 CODE:
2138 RETVAL = THIS->kv.get (key); 2169 RETVAL = THIS->kv.get (key);
2357 for_all_players (pl) 2388 for_all_players (pl)
2358 if (pl->ob && pl->ob->map == THIS) 2389 if (pl->ob && pl->ob->map == THIS)
2359 PUSHs (sv_2mortal (to_sv (pl->ob))); 2390 PUSHs (sv_2mortal (to_sv (pl->ob)));
2360 } 2391 }
2361 2392
2362#if 0
2363
2364void 2393void
2365maptile::add_quadland (int mx, int my, int mz, SV *biome_map, SV *biome_plt) 2394maptile::gen_quadmap (int x, int y, int z)
2366 CODE: 2395 CODE:
2367{ 2396 gen_quadmap (THIS, x * 50, y * 50, z);
2368 static frac_gen<vec2d> frac;
2369 2397
2398void
2399maptile::add_underlay (SV *data, int offset, int stride, SV *palette)
2400 CODE:
2401{
2370 if (!SvROK (biome_plt) || SvTYPE (SvRV (biome_plt)) != SVt_PVAV) 2402 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV)
2371 croak ("maptile::add_quadland: biome_plt must be arrayref"); 2403 croak ("maptile::add_underlay: palette must be arrayref");
2372 2404
2373 biome_plt = SvRV (biome_plt); 2405 palette = SvRV (palette);
2374 2406
2375 const uint8_t *bmap = (const uint8_t *)SvPVbyte_nolen (biome_map); 2407 STRLEN idxlen;
2408 const uint8 *idx = (const uint8 *)SvPVbyte (data, idxlen);
2376 2409
2377 for (int x = 0; x < THIS->width; ++x) 2410 for (int x = 0; x < THIS->width; ++x)
2378 for (int y = 0; y < THIS->height; ++y) 2411 for (int y = 0; y < THIS->height; ++y)
2379 { 2412 {
2380 for (object *op = THIS->at (x, y).bot; op; op = op->above) 2413 for (object *op = THIS->at (x, y).bot; op; op = op->above)
2381 if (op->flag [FLAG_IS_FLOOR]) 2414 if (op->flag [FLAG_IS_FLOOR])
2382 goto skip; 2415 goto skip;
2383 2416
2384 { 2417 {
2385 float fx = mx * THIS->width + x;
2386 float fy = my * THIS->height + y;
2387
2388 int temp = clamp (int (32 * frac.fBm (vec2d (fx * 0.001, fy * 0.001), 2) ) - 8, 0, 15);
2389 int rain = clamp (int (16 * frac.ridgedmultifractal (vec2d (fx * 0.01, fy * 0.01), 3, 1.03, 2)) - 8, 0, 15);
2390
2391 rain = lerp (rain, 0, 15, 0, temp);
2392 printf ("rain %d\n", temp);//D
2393
2394 int biome = bmap [rain * 16 + temp];
2395
2396 //printf ("%2d %2d => %s\n", temp, rain, SvPV_nolen (AvARRAY ((AV *)biome_plt)[biome]));//D
2397#if 1
2398 if (SV **elem = av_fetch ((AV *)biome_plt, bmap [rain * 16 + temp], 0))
2399 {
2400 object *ob = get_archetype (cfSvPVutf8_nolen (*elem));
2401 ob->flag [FLAG_NO_MAP_SAVE] = true;
2402 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY);
2403
2404 if (ob->randomitems && !ob->above)
2405 {
2406 ob->create_treasure (ob->randomitems);
2407
2408 for (object *op = ob->above; op; op = op->above)
2409 op->flag [FLAG_NO_MAP_SAVE] = true;
2410 }
2411 }
2412#endif
2413 }
2414 skip: ;
2415 }
2416}
2417
2418#endif
2419
2420void
2421maptile::add_underlay (SV *data, int offset, int stride, SV *palette)
2422 CODE:
2423{
2424 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV)
2425 croak ("maptile::add_underlay: palette must be arrayref");
2426
2427 palette = SvRV (palette);
2428
2429 STRLEN idxlen;
2430 const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen);
2431
2432 for (int x = 0; x < THIS->width; ++x)
2433 for (int y = 0; y < THIS->height; ++y)
2434 {
2435 for (object *op = THIS->at (x, y).bot; op; op = op->above)
2436 if (op->flag [FLAG_IS_FLOOR])
2437 goto skip;
2438
2439 {
2440 int offs = offset + y * stride + x; 2418 int offs = offset + y * stride + x;
2441 2419
2442 if (IN_RANGE_EXC (offs, 0, idxlen)) 2420 if (IN_RANGE_EXC (offs, 0, idxlen))
2443 { 2421 {
2444 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) 2422 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0))
2445 { 2423 {
2446 object *ob = get_archetype (cfSvPVutf8_nolen (*elem)); 2424 object *ob = archetype::get (cfSvPVutf8_nolen (*elem));
2447 ob->flag [FLAG_NO_MAP_SAVE] = true; 2425 ob->flag [FLAG_NO_MAP_SAVE] = true;
2448 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); 2426 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY);
2449 2427
2450 if (ob->randomitems && !ob->above) 2428 if (ob->randomitems && !ob->above)
2451 { 2429 {
2475 croak ("maptile::set_regiondata: palette must be arrayref"); 2453 croak ("maptile::set_regiondata: palette must be arrayref");
2476 2454
2477 palette = SvRV (palette); 2455 palette = SvRV (palette);
2478 2456
2479 STRLEN idxlen; 2457 STRLEN idxlen;
2480 const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen); 2458 const uint8 *idx = (const uint8 *)SvPVbyte (data, idxlen);
2481 2459
2482 region_ptr *regionmap = new region_ptr [av_len ((AV *)palette) + 1]; 2460 region_ptr *regionmap = new region_ptr [av_len ((AV *)palette) + 1];
2483 uint8_t *regions = salloc<uint8_t> (THIS->size ()); 2461 uint8 *regions = salloc<uint8_t> (THIS->size ());
2484 2462
2485 for (int i = av_len ((AV *)palette) + 1; i--; ) 2463 for (int i = av_len ((AV *)palette) + 1; i--; )
2486 regionmap [i] = region::find (cfSvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1))); 2464 regionmap [i] = region::find (cfSvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1)));
2487 2465
2488 for (int y = 0; y < THIS->height; ++y) 2466 for (int y = 0; y < THIS->height; ++y)
2614archetype *archetypes (U32 index) 2592archetype *archetypes (U32 index)
2615 CODE: 2593 CODE:
2616 RETVAL = index < archetypes.size () ? archetypes [index] : 0; 2594 RETVAL = index < archetypes.size () ? archetypes [index] : 0;
2617 OUTPUT: RETVAL 2595 OUTPUT: RETVAL
2618 2596
2597int skillvec_size ()
2598 CODE:
2599 RETVAL = skillvec.size ();
2600 OUTPUT: RETVAL
2601
2602archetype *skillvec (U32 index)
2603 CODE:
2604 RETVAL = index < skillvec.size () ? (archetype *)(object *)skillvec [index] : 0;
2605 OUTPUT: RETVAL
2606
2607void
2608find_by_type (int type)
2609 PPCODE:
2610 for_all_archetypes (arch)
2611 if (arch->type == type)
2612 XPUSHs (sv_2mortal (to_sv (arch)));
2613
2619INCLUDE: $PERL $srcdir/genacc archetype $srcdir/../include/object.h | 2614INCLUDE: $PERL $srcdir/genacc archetype $srcdir/../include/object.h |
2620 2615
2621MODULE = cf PACKAGE = cf::party 2616MODULE = cf PACKAGE = cf::party
2622 2617
2623partylist *first () 2618partylist *first ()
2671list () 2666list ()
2672 PPCODE: 2667 PPCODE:
2673 EXTEND (SP, clients.size ()); 2668 EXTEND (SP, clients.size ());
2674 for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i) 2669 for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i)
2675 PUSHs (sv_2mortal (to_sv (*i))); 2670 PUSHs (sv_2mortal (to_sv (*i)));
2671
2672STRLEN
2673client::inbuf_append (SV *data)
2674 CODE:
2675{
2676 STRLEN len;
2677 char *ptr = SvPVbyte (data, len);
2678
2679 min_it (len, sizeof (THIS->inbuf) - THIS->inbuf_len);
2680 memcpy (THIS->inbuf + THIS->inbuf_len, ptr, len);
2681 THIS->inbuf_len += len;
2682
2683 THIS->inbuf_handle ();
2684
2685 RETVAL = len;
2686}
2687 OUTPUT: RETVAL
2676 2688
2677void 2689void
2678client::send_packet (SV *packet) 2690client::send_packet (SV *packet)
2679 CODE: 2691 CODE:
2680{ 2692{
2736faceidx face_find (utf8_string name, faceidx defidx = 0) 2748faceidx face_find (utf8_string name, faceidx defidx = 0)
2737 2749
2738faceidx alloc (utf8_string name) 2750faceidx alloc (utf8_string name)
2739 CODE: 2751 CODE:
2740{ 2752{
2741 do 2753 RETVAL = face_alloc ();
2742 {
2743 RETVAL = faces.size ();
2744 faces.resize (RETVAL + 1);
2745 }
2746 while (!RETVAL); // crude way to leave index 0
2747 2754
2748 faces [RETVAL].name = name; 2755 faces [RETVAL].name = name;
2749 facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL)); 2756 facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL));
2750 2757
2751 if (!strcmp (name, BLANK_FACE_NAME )) blank_face = RETVAL; 2758 if (!strcmp (name, BLANK_FACE_NAME )) blank_face = RETVAL;
2752 if (!strcmp (name, EMPTY_FACE_NAME )) empty_face = RETVAL; 2759 if (!strcmp (name, EMPTY_FACE_NAME )) empty_face = RETVAL;
2753 if (!strcmp (name, MAGICMOUTH_FACE_NAME)) magicmouth_face = RETVAL; 2760 if (!strcmp (name, MAGICMOUTH_FACE_NAME)) magicmouth_face = RETVAL;
2754} 2761}
2762 OUTPUT: RETVAL
2763
2764faceidx faces_size ()
2765 CODE:
2766 RETVAL = faces.size ();
2755 OUTPUT: RETVAL 2767 OUTPUT: RETVAL
2756 2768
2757void set_type (faceidx idx, int value) 2769void set_type (faceidx idx, int value)
2758 ALIAS: 2770 ALIAS:
2759 set_type = 0 2771 set_type = 0
2770 case 2: f->magicmap = value; break; 2782 case 2: f->magicmap = value; break;
2771 case 3: f->smooth = value; break; 2783 case 3: f->smooth = value; break;
2772 case 4: f->smoothlevel = value; break; 2784 case 4: f->smoothlevel = value; break;
2773 } 2785 }
2774 2786
2775void set_data (faceidx idx, int faceset, SV *data, SV *chksum) 2787void set_csum (faceidx idx, int faceset, SV *chksum)
2776 CODE: 2788 CODE:
2777{ 2789{
2778 faceinfo *f = face_info (idx); assert (f); 2790 faceinfo *f = face_info (idx); assert (f);
2779 facedata *d = f->face + faceset; 2791 facedata *d = f->face + faceset;
2780 sv_to (data, d->data);
2781 STRLEN clen; 2792 STRLEN clen;
2782 char *cdata = SvPVbyte (chksum, clen); 2793 char *cdata = SvPVbyte (chksum, clen);
2783 clen = min (CHKSUM_MAXLEN, clen);
2784 2794
2795 assert (("cf::face::set_data called with too long checksum", clen <= CHKSUM_MAXLEN));
2785 assert (("cf::face::set_data must be called with a non-empty checksum", clen)); 2796 assert (("cf::face::set_data must be called with a non-empty checksum", clen));
2786 2797
2787 if (clen != d->chksum_len || memcmp (d->chksum, cdata, clen)) 2798 if (clen != d->chksum_len || memcmp (d->chksum, cdata, clen))
2788 { 2799 {
2789 d->chksum_len = clen; 2800 d->chksum_len = clen;
2790 memcpy (d->chksum, cdata, clen); 2801 memcpy (d->chksum, cdata, clen);
2791 2802
2792 // invalidate existing client face info 2803 // invalidate existing client face info
2793 for_all_clients (ns) 2804 for_all_clients (ns)
2794 if (ns->faceset == faceset) 2805 ns->invalidate_face (idx);
2795 {
2796 ns->faces_sent [idx] = false;
2797 ns->force_newmap = true;
2798 }
2799 } 2806 }
2800} 2807}
2801 2808
2802int get_data_size (faceidx idx, int faceset = 0) 2809SV *mangle_csum (SV *chksum)
2803 CODE: 2810 CODE:
2804 facedata *d = face_data (idx, faceset); 2811 STRLEN len;
2805 if (!d) XSRETURN_UNDEF; 2812 char *data = SvPVbyte (chksum, len);
2806 RETVAL = d->data.size (); 2813 RETVAL = newSVpvn (data, min (len, CHKSUM_MAXLEN));
2807 OUTPUT: 2814 OUTPUT:
2808 RETVAL 2815 RETVAL
2809 2816
2810SV *get_chksum (faceidx idx, int faceset = 0) 2817SV *get_csum (faceidx idx, int faceset = 0)
2811 CODE: 2818 CODE:
2812 facedata *d = face_data (idx, faceset); 2819 facedata *d = face_data (idx, faceset);
2813 if (!d) XSRETURN_UNDEF; 2820 if (!d) XSRETURN_UNDEF;
2814 RETVAL = newSVpvn ((char *)d->chksum, d->chksum_len); 2821 RETVAL = newSVpvn ((char *)d->chksum, d->chksum_len);
2815 OUTPUT: 2822 OUTPUT:
2816 RETVAL 2823 RETVAL
2817 2824
2818SV *get_data (faceidx idx, int faceset = 0) 2825int get_type (faceidx idx)
2819 CODE: 2826 CODE:
2820 facedata *d = face_data (idx, faceset); 2827 faceinfo *f = face_info (idx);
2821 if (!d) XSRETURN_UNDEF; 2828 if (!f) XSRETURN_UNDEF;
2822 RETVAL = newSVpvn (d->data.data (), d->data.length ()); 2829 RETVAL = f->type;
2823 OUTPUT: 2830 OUTPUT:
2824 RETVAL 2831 RETVAL
2825 2832
2833SV *get_name (faceidx idx)
2834 CODE:
2835 faceinfo *f = face_info (idx);
2836 if (!f) XSRETURN_UNDEF;
2837 RETVAL = to_sv (f->name);
2838 OUTPUT:
2839 RETVAL
2840
2826void invalidate (faceidx idx) 2841void invalidate (faceidx idx)
2827 CODE: 2842 CODE:
2828 for_all_clients (ns) 2843 for_all_clients (ns)
2829 { 2844 ns->invalidate_face (idx);
2830 ns->faces_sent [idx] = false;
2831 ns->force_newmap = true;
2832 }
2833 2845
2834void invalidate_all () 2846void invalidate_all ()
2835 CODE: 2847 CODE:
2836 for_all_clients (ns) 2848 for_all_clients (ns)
2837 { 2849 ns->invalidate_all_faces ();
2838 ns->faces_sent.reset ();
2839 ns->force_newmap = true;
2840 }
2841 2850
2842MODULE = cf PACKAGE = cf::anim PREFIX = anim_ 2851MODULE = cf PACKAGE = cf::anim PREFIX = anim_
2843 2852
2844#INCLUDE: $PERL $srcdir/genacc faceset $srcdir/../include/anim.h | 2853#INCLUDE: $PERL $srcdir/genacc faceset $srcdir/../include/anim.h |
2845 2854
2849 OUTPUT: RETVAL 2858 OUTPUT: RETVAL
2850 2859
2851animidx set (utf8_string name, SV *frames, int facings = 1) 2860animidx set (utf8_string name, SV *frames, int facings = 1)
2852 CODE: 2861 CODE:
2853{ 2862{
2854 if (!SvROK (frames) && SvTYPE (SvRV (frames)) != SVt_PVAV) 2863 if (!SvROK (frames) && SvTYPE (SvRV (frames)) != SVt_PVAV)
2855 croak ("frames must be an arrayref"); 2864 croak ("frames must be an arrayref");
2856 2865
2857 AV *av = (AV *)SvRV (frames); 2866 AV *av = (AV *)SvRV (frames);
2858 2867
2859 animation *anim = &animation::find (name); 2868 animation *anim = &animation::find (name);
2860 if (anim->number) 2869 if (anim->number)
2861 { 2870 {
2862 anim->resize (av_len (av) + 1); 2871 anim->resize (av_len (av) + 1);
2863 anim->facings = facings; 2872 anim->facings = facings;
2864 } 2873 }
2936 XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ()))); 2945 XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ())));
2937 2946
2938 self->skip (); 2947 self->skip ();
2939 } 2948 }
2940 2949
2950MODULE = cf PACKAGE = cf::treasurelist
2951
2952# quick hack, because I didn't want to implement accessors for treasurelist.
2953# this asks for even more autogen, actually.
2954
2955void
2956expand (treasurelist *list)
2957 PPCODE:
2958 EXTEND (SP, 3);
2959 PUSHs (sv_2mortal (to_sv (list->name)));
2960 PUSHs (sv_2mortal (to_sv (list->total_chance)));
2961 AV *av = newAV ();
2962 PUSHs (sv_2mortal (newRV_noinc ((SV *)av)));
2963 for (treasure *item = list->items; item; item = item->next)
2964 {
2965 AV *iav = newAV ();
2966 av_push (av, newRV_noinc ((SV *)iav));
2967
2968 av_extend (iav, 7);
2969 av_push (iav, to_sv (item->item));
2970 av_push (iav, to_sv (item->name));
2971 av_push (iav, to_sv (item->change_arch.name));
2972 av_push (iav, to_sv (item->change_arch.title));
2973 av_push (iav, to_sv (item->change_arch.slaying));
2974 av_push (iav, to_sv (item->chance));
2975 av_push (iav, to_sv (item->nrof));
2976 av_push (iav, to_sv (item->magic));
2977 }
2978
2941MODULE = cf PACKAGE = cf::layout 2979MODULE = cf PACKAGE = cf::layout
2942 2980
2943INCLUDE: $PERL $srcdir/genacc layout $srcdir/../include/rmg.h | 2981INCLUDE: $PERL $srcdir/genacc layout $srcdir/../include/rmg.h |
2944 2982

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines