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.423 by root, Wed Nov 14 05:25:50 2012 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2006,2007,2008,2009,2010,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * 5 *
6 * Deliantra is free software: you can redistribute it and/or modify it under 6 * Deliantra is free software: you can redistribute it and/or modify it under
7 * the terms of the Affero GNU General Public License as published by the 7 * the terms of the Affero GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your 8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version. 9 * option) any later version.
10 * 10 *
11 * This program is distributed in the hope that it will be useful, 11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 * 15 *
16 * You should have received a copy of the Affero GNU General Public License 16 * You should have received a copy of the Affero GNU General Public License
17 * and the GNU General Public License along with this program. If not, see 17 * and the GNU General Public License along with this program. If not, see
18 * <http://www.gnu.org/licenses/>. 18 * <http://www.gnu.org/licenses/>.
19 * 19 *
20 * The authors can be reached via e-mail to <support@deliantra.net> 20 * The authors can be reached via e-mail to <support@deliantra.net>
21 */ 21 */
22 22
23#include "autoconf.h" 23#include "autoconf.h"
24 24
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)
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)
2097 2122
2098void fix_generated_item (object *op, object *creator, int difficulty, int max_magic, int flags); 2123void fix_generated_item (object *op, object *creator, int difficulty, int max_magic, int flags);
2099 2124
2100MODULE = cf PACKAGE = cf::object PREFIX = cf_ 2125MODULE = cf PACKAGE = cf::object PREFIX = cf_
2101 2126
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) 2127object *new (utf8_string archetype = 0)
2106 PROTOTYPE: ;$ 2128 PROTOTYPE: ;$
2107 CODE: 2129 CODE:
2108 RETVAL = archetype ? get_archetype (archetype) : object::create (); 2130 RETVAL = archetype
2131 ? archetype::get (archetype)
2132 : object::create ();
2109 OUTPUT: 2133 OUTPUT:
2110 RETVAL 2134 RETVAL
2111 2135
2112object *generate (utf8_string arch, object *creator) 2136object *generate (utf8_string arch, object *creator)
2113 CODE: 2137 CODE:
2114 object *obj = get_archetype (arch); 2138 object *obj = archetype::get (arch);
2115 fix_generated_item (obj, creator, 0, 0, GT_MINIMAL); 2139 fix_generated_item (obj, creator, 0, 0, GT_MINIMAL);
2116 RETVAL = obj; 2140 RETVAL = obj;
2117 OUTPUT: 2141 OUTPUT:
2118 RETVAL 2142 RETVAL
2119 2143
2129 RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y); 2153 RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y);
2130 2154
2131 if (RETVAL->destroyed ()) 2155 if (RETVAL->destroyed ())
2132 RETVAL = 0; 2156 RETVAL = 0;
2133} 2157}
2158 OUTPUT:
2159 RETVAL
2134 2160
2135shstr 2161shstr
2136object::kv_get (shstr key) 2162object::kv_get (shstr key)
2137 CODE: 2163 CODE:
2138 RETVAL = THIS->kv.get (key); 2164 RETVAL = THIS->kv.get (key);
2357 for_all_players (pl) 2383 for_all_players (pl)
2358 if (pl->ob && pl->ob->map == THIS) 2384 if (pl->ob && pl->ob->map == THIS)
2359 PUSHs (sv_2mortal (to_sv (pl->ob))); 2385 PUSHs (sv_2mortal (to_sv (pl->ob)));
2360 } 2386 }
2361 2387
2362#if 0
2363
2364void 2388void
2365maptile::add_quadland (int mx, int my, int mz, SV *biome_map, SV *biome_plt) 2389maptile::gen_quadmap (int x, int y, int z)
2366 CODE: 2390 CODE:
2367{ 2391 gen_quadmap (THIS, x * 50, y * 50, z);
2368 static frac_gen<vec2d> frac;
2369 2392
2393void
2394maptile::add_underlay (SV *data, int offset, int stride, SV *palette)
2395 CODE:
2396{
2370 if (!SvROK (biome_plt) || SvTYPE (SvRV (biome_plt)) != SVt_PVAV) 2397 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV)
2371 croak ("maptile::add_quadland: biome_plt must be arrayref"); 2398 croak ("maptile::add_underlay: palette must be arrayref");
2372 2399
2373 biome_plt = SvRV (biome_plt); 2400 palette = SvRV (palette);
2374 2401
2375 const uint8_t *bmap = (const uint8_t *)SvPVbyte_nolen (biome_map); 2402 STRLEN idxlen;
2403 const uint8 *idx = (const uint8 *)SvPVbyte (data, idxlen);
2376 2404
2377 for (int x = 0; x < THIS->width; ++x) 2405 for (int x = 0; x < THIS->width; ++x)
2378 for (int y = 0; y < THIS->height; ++y) 2406 for (int y = 0; y < THIS->height; ++y)
2379 { 2407 {
2380 for (object *op = THIS->at (x, y).bot; op; op = op->above) 2408 for (object *op = THIS->at (x, y).bot; op; op = op->above)
2381 if (op->flag [FLAG_IS_FLOOR]) 2409 if (op->flag [FLAG_IS_FLOOR])
2382 goto skip; 2410 goto skip;
2383 2411
2384 { 2412 {
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; 2413 int offs = offset + y * stride + x;
2441 2414
2442 if (IN_RANGE_EXC (offs, 0, idxlen)) 2415 if (IN_RANGE_EXC (offs, 0, idxlen))
2443 { 2416 {
2444 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) 2417 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0))
2445 { 2418 {
2446 object *ob = get_archetype (cfSvPVutf8_nolen (*elem)); 2419 object *ob = archetype::get (cfSvPVutf8_nolen (*elem));
2447 ob->flag [FLAG_NO_MAP_SAVE] = true; 2420 ob->flag [FLAG_NO_MAP_SAVE] = true;
2448 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); 2421 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY);
2449 2422
2450 if (ob->randomitems && !ob->above) 2423 if (ob->randomitems && !ob->above)
2451 { 2424 {
2475 croak ("maptile::set_regiondata: palette must be arrayref"); 2448 croak ("maptile::set_regiondata: palette must be arrayref");
2476 2449
2477 palette = SvRV (palette); 2450 palette = SvRV (palette);
2478 2451
2479 STRLEN idxlen; 2452 STRLEN idxlen;
2480 const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen); 2453 const uint8 *idx = (const uint8 *)SvPVbyte (data, idxlen);
2481 2454
2482 region_ptr *regionmap = new region_ptr [av_len ((AV *)palette) + 1]; 2455 region_ptr *regionmap = new region_ptr [av_len ((AV *)palette) + 1];
2483 uint8_t *regions = salloc<uint8_t> (THIS->size ()); 2456 uint8 *regions = salloc<uint8_t> (THIS->size ());
2484 2457
2485 for (int i = av_len ((AV *)palette) + 1; i--; ) 2458 for (int i = av_len ((AV *)palette) + 1; i--; )
2486 regionmap [i] = region::find (cfSvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1))); 2459 regionmap [i] = region::find (cfSvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1)));
2487 2460
2488 for (int y = 0; y < THIS->height; ++y) 2461 for (int y = 0; y < THIS->height; ++y)
2614archetype *archetypes (U32 index) 2587archetype *archetypes (U32 index)
2615 CODE: 2588 CODE:
2616 RETVAL = index < archetypes.size () ? archetypes [index] : 0; 2589 RETVAL = index < archetypes.size () ? archetypes [index] : 0;
2617 OUTPUT: RETVAL 2590 OUTPUT: RETVAL
2618 2591
2592int skillvec_size ()
2593 CODE:
2594 RETVAL = skillvec.size ();
2595 OUTPUT: RETVAL
2596
2597archetype *skillvec (U32 index)
2598 CODE:
2599 RETVAL = index < skillvec.size () ? (archetype *)(object *)skillvec [index] : 0;
2600 OUTPUT: RETVAL
2601
2602void
2603find_by_type (int type)
2604 PPCODE:
2605 for_all_archetypes (arch)
2606 if (arch->type == type)
2607 XPUSHs (sv_2mortal (to_sv (arch)));
2608
2619INCLUDE: $PERL $srcdir/genacc archetype $srcdir/../include/object.h | 2609INCLUDE: $PERL $srcdir/genacc archetype $srcdir/../include/object.h |
2620 2610
2621MODULE = cf PACKAGE = cf::party 2611MODULE = cf PACKAGE = cf::party
2622 2612
2623partylist *first () 2613partylist *first ()
2671list () 2661list ()
2672 PPCODE: 2662 PPCODE:
2673 EXTEND (SP, clients.size ()); 2663 EXTEND (SP, clients.size ());
2674 for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i) 2664 for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i)
2675 PUSHs (sv_2mortal (to_sv (*i))); 2665 PUSHs (sv_2mortal (to_sv (*i)));
2666
2667STRLEN
2668client::inbuf_append (SV *data)
2669 CODE:
2670{
2671 STRLEN len;
2672 char *ptr = SvPVbyte (data, len);
2673
2674 min_it (len, sizeof (THIS->inbuf) - THIS->inbuf_len);
2675 memcpy (THIS->inbuf + THIS->inbuf_len, ptr, len);
2676 THIS->inbuf_len += len;
2677
2678 THIS->inbuf_handle ();
2679
2680 RETVAL = len;
2681}
2682 OUTPUT: RETVAL
2676 2683
2677void 2684void
2678client::send_packet (SV *packet) 2685client::send_packet (SV *packet)
2679 CODE: 2686 CODE:
2680{ 2687{
2736faceidx face_find (utf8_string name, faceidx defidx = 0) 2743faceidx face_find (utf8_string name, faceidx defidx = 0)
2737 2744
2738faceidx alloc (utf8_string name) 2745faceidx alloc (utf8_string name)
2739 CODE: 2746 CODE:
2740{ 2747{
2741 do 2748 RETVAL = face_alloc ();
2742 {
2743 RETVAL = faces.size ();
2744 faces.resize (RETVAL + 1);
2745 }
2746 while (!RETVAL); // crude way to leave index 0
2747 2749
2748 faces [RETVAL].name = name; 2750 faces [RETVAL].name = name;
2749 facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL)); 2751 facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL));
2750 2752
2751 if (!strcmp (name, BLANK_FACE_NAME )) blank_face = RETVAL; 2753 if (!strcmp (name, BLANK_FACE_NAME )) blank_face = RETVAL;
2752 if (!strcmp (name, EMPTY_FACE_NAME )) empty_face = RETVAL; 2754 if (!strcmp (name, EMPTY_FACE_NAME )) empty_face = RETVAL;
2753 if (!strcmp (name, MAGICMOUTH_FACE_NAME)) magicmouth_face = RETVAL; 2755 if (!strcmp (name, MAGICMOUTH_FACE_NAME)) magicmouth_face = RETVAL;
2754} 2756}
2757 OUTPUT: RETVAL
2758
2759faceidx faces_size ()
2760 CODE:
2761 RETVAL = faces.size ();
2755 OUTPUT: RETVAL 2762 OUTPUT: RETVAL
2756 2763
2757void set_type (faceidx idx, int value) 2764void set_type (faceidx idx, int value)
2758 ALIAS: 2765 ALIAS:
2759 set_type = 0 2766 set_type = 0
2770 case 2: f->magicmap = value; break; 2777 case 2: f->magicmap = value; break;
2771 case 3: f->smooth = value; break; 2778 case 3: f->smooth = value; break;
2772 case 4: f->smoothlevel = value; break; 2779 case 4: f->smoothlevel = value; break;
2773 } 2780 }
2774 2781
2775void set_data (faceidx idx, int faceset, SV *data, SV *chksum) 2782void set_csum (faceidx idx, int faceset, SV *chksum)
2776 CODE: 2783 CODE:
2777{ 2784{
2778 faceinfo *f = face_info (idx); assert (f); 2785 faceinfo *f = face_info (idx); assert (f);
2779 facedata *d = f->face + faceset; 2786 facedata *d = f->face + faceset;
2780 sv_to (data, d->data);
2781 STRLEN clen; 2787 STRLEN clen;
2782 char *cdata = SvPVbyte (chksum, clen); 2788 char *cdata = SvPVbyte (chksum, clen);
2783 clen = min (CHKSUM_MAXLEN, clen);
2784 2789
2790 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)); 2791 assert (("cf::face::set_data must be called with a non-empty checksum", clen));
2786 2792
2787 if (clen != d->chksum_len || memcmp (d->chksum, cdata, clen)) 2793 if (clen != d->chksum_len || memcmp (d->chksum, cdata, clen))
2788 { 2794 {
2789 d->chksum_len = clen; 2795 d->chksum_len = clen;
2790 memcpy (d->chksum, cdata, clen); 2796 memcpy (d->chksum, cdata, clen);
2791 2797
2792 // invalidate existing client face info 2798 // invalidate existing client face info
2793 for_all_clients (ns) 2799 for_all_clients (ns)
2794 if (ns->faceset == faceset) 2800 ns->invalidate_face (idx);
2795 {
2796 ns->faces_sent [idx] = false;
2797 ns->force_newmap = true;
2798 }
2799 } 2801 }
2800} 2802}
2801 2803
2802int get_data_size (faceidx idx, int faceset = 0) 2804SV *mangle_csum (SV *chksum)
2803 CODE: 2805 CODE:
2804 facedata *d = face_data (idx, faceset); 2806 STRLEN len;
2805 if (!d) XSRETURN_UNDEF; 2807 char *data = SvPVbyte (chksum, len);
2806 RETVAL = d->data.size (); 2808 RETVAL = newSVpvn (data, min (len, CHKSUM_MAXLEN));
2807 OUTPUT: 2809 OUTPUT:
2808 RETVAL 2810 RETVAL
2809 2811
2810SV *get_chksum (faceidx idx, int faceset = 0) 2812SV *get_csum (faceidx idx, int faceset = 0)
2811 CODE: 2813 CODE:
2812 facedata *d = face_data (idx, faceset); 2814 facedata *d = face_data (idx, faceset);
2813 if (!d) XSRETURN_UNDEF; 2815 if (!d) XSRETURN_UNDEF;
2814 RETVAL = newSVpvn ((char *)d->chksum, d->chksum_len); 2816 RETVAL = newSVpvn ((char *)d->chksum, d->chksum_len);
2815 OUTPUT: 2817 OUTPUT:
2816 RETVAL 2818 RETVAL
2817 2819
2818SV *get_data (faceidx idx, int faceset = 0) 2820int get_type (faceidx idx)
2819 CODE: 2821 CODE:
2820 facedata *d = face_data (idx, faceset); 2822 faceinfo *f = face_info (idx);
2821 if (!d) XSRETURN_UNDEF; 2823 if (!f) XSRETURN_UNDEF;
2822 RETVAL = newSVpvn (d->data.data (), d->data.length ()); 2824 RETVAL = f->type;
2823 OUTPUT: 2825 OUTPUT:
2824 RETVAL 2826 RETVAL
2825 2827
2828SV *get_name (faceidx idx)
2829 CODE:
2830 faceinfo *f = face_info (idx);
2831 if (!f) XSRETURN_UNDEF;
2832 RETVAL = to_sv (f->name);
2833 OUTPUT:
2834 RETVAL
2835
2826void invalidate (faceidx idx) 2836void invalidate (faceidx idx)
2827 CODE: 2837 CODE:
2828 for_all_clients (ns) 2838 for_all_clients (ns)
2829 { 2839 ns->invalidate_face (idx);
2830 ns->faces_sent [idx] = false;
2831 ns->force_newmap = true;
2832 }
2833 2840
2834void invalidate_all () 2841void invalidate_all ()
2835 CODE: 2842 CODE:
2836 for_all_clients (ns) 2843 for_all_clients (ns)
2837 { 2844 ns->invalidate_all_faces ();
2838 ns->faces_sent.reset ();
2839 ns->force_newmap = true;
2840 }
2841 2845
2842MODULE = cf PACKAGE = cf::anim PREFIX = anim_ 2846MODULE = cf PACKAGE = cf::anim PREFIX = anim_
2843 2847
2844#INCLUDE: $PERL $srcdir/genacc faceset $srcdir/../include/anim.h | 2848#INCLUDE: $PERL $srcdir/genacc faceset $srcdir/../include/anim.h |
2845 2849
2849 OUTPUT: RETVAL 2853 OUTPUT: RETVAL
2850 2854
2851animidx set (utf8_string name, SV *frames, int facings = 1) 2855animidx set (utf8_string name, SV *frames, int facings = 1)
2852 CODE: 2856 CODE:
2853{ 2857{
2854 if (!SvROK (frames) && SvTYPE (SvRV (frames)) != SVt_PVAV) 2858 if (!SvROK (frames) && SvTYPE (SvRV (frames)) != SVt_PVAV)
2855 croak ("frames must be an arrayref"); 2859 croak ("frames must be an arrayref");
2856 2860
2857 AV *av = (AV *)SvRV (frames); 2861 AV *av = (AV *)SvRV (frames);
2858 2862
2859 animation *anim = &animation::find (name); 2863 animation *anim = &animation::find (name);
2860 if (anim->number) 2864 if (anim->number)
2861 { 2865 {
2862 anim->resize (av_len (av) + 1); 2866 anim->resize (av_len (av) + 1);
2863 anim->facings = facings; 2867 anim->facings = facings;
2864 } 2868 }
2936 XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ()))); 2940 XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ())));
2937 2941
2938 self->skip (); 2942 self->skip ();
2939 } 2943 }
2940 2944
2945MODULE = cf PACKAGE = cf::treasurelist
2946
2947# quick hack, because I didn't want to implement accessors for treasurelist.
2948# this asks for even more autogen, actually.
2949
2950void
2951expand (treasurelist *list)
2952 PPCODE:
2953 EXTEND (SP, 3);
2954 PUSHs (sv_2mortal (to_sv (list->name)));
2955 PUSHs (sv_2mortal (to_sv (list->total_chance)));
2956 AV *av = newAV ();
2957 PUSHs (sv_2mortal (newRV_noinc ((SV *)av)));
2958 for (treasure *item = list->items; item; item = item->next)
2959 {
2960 AV *iav = newAV ();
2961 av_push (av, newRV_noinc ((SV *)iav));
2962
2963 av_extend (iav, 7);
2964 av_push (iav, to_sv (item->item));
2965 av_push (iav, to_sv (item->name));
2966 av_push (iav, to_sv (item->change_arch.name));
2967 av_push (iav, to_sv (item->change_arch.title));
2968 av_push (iav, to_sv (item->change_arch.slaying));
2969 av_push (iav, to_sv (item->chance));
2970 av_push (iav, to_sv (item->nrof));
2971 av_push (iav, to_sv (item->magic));
2972 }
2973
2941MODULE = cf PACKAGE = cf::layout 2974MODULE = cf PACKAGE = cf::layout
2942 2975
2943INCLUDE: $PERL $srcdir/genacc layout $srcdir/../include/rmg.h | 2976INCLUDE: $PERL $srcdir/genacc layout $srcdir/../include/rmg.h |
2944 2977

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines