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.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
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, 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
1151player * 1175player *
1152player::find (const_utf8_string name) 1176player::find (const_utf8_string name)
1153{ 1177{
1154 CALL_BEGIN (1); 1178 CALL_BEGIN (1);
1155 CALL_ARG (name); 1179 CALL_ARG (name);
1404 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); 1428 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1);
1405 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1); 1429 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1);
1406 stash_cf_layout_wrap = gv_stashpv ("cf::layout::wrap", 1); 1430 stash_cf_layout_wrap = gv_stashpv ("cf::layout::wrap", 1);
1407 stash_ext_map_world = gv_stashpv ("ext::map_world" , 1); 1431 stash_ext_map_world = gv_stashpv ("ext::map_world" , 1);
1408 1432
1409 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);
1410 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);
1411 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);
1412 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);
1413 1438
1414 cb_global = get_av ("cf::CB_GLOBAL", 1); 1439 cb_global = get_av ("cf::CB_GLOBAL", 1);
1415 cb_attachable = get_av ("cf::CB_ATTACHABLE", 1); 1440 cb_attachable = get_av ("cf::CB_ATTACHABLE", 1);
1416 cb_object = get_av ("cf::CB_OBJECT", 1); 1441 cb_object = get_av ("cf::CB_OBJECT", 1);
1417 cb_player = get_av ("cf::CB_PLAYER", 1); 1442 cb_player = get_av ("cf::CB_PLAYER", 1);
1424_connect_to_perl_2 () 1449_connect_to_perl_2 ()
1425{ 1450{
1426 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);
1427 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);
1428 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);
1429 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);
1430 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);
1431} 1457}
1432 1458
1433MODULE = cf PACKAGE = cf PREFIX = cf_ 1459MODULE = cf PACKAGE = cf PREFIX = cf_
1438 I_CORO_API (PACKAGE); coroapi::GCoroAPI = GCoroAPI; 1464 I_CORO_API (PACKAGE); coroapi::GCoroAPI = GCoroAPI;
1439 1465
1440 _connect_to_perl_1 (); 1466 _connect_to_perl_1 ();
1441 1467
1442 newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1)); 1468 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 1469
1453 static const struct { 1470 static const struct {
1454 const char *name; 1471 const char *name;
1455 IV iv; 1472 IV iv;
1456 } *civ, const_iv[] = { 1473 } *civ, const_iv[] = {
1486 const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE) 1503 const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE)
1487 1504
1488 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)
1489 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)
1490 1507
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) 1508 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) 1509 const_iv (KLASS_CLIENT) const_iv (KLASS_PLAYER) const_iv (KLASS_MAP)
1496 1510
1497 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)
1498 1512
1530 1544
1531void _gv_clear (SV *gv) 1545void _gv_clear (SV *gv)
1532 CODE: 1546 CODE:
1533 assert (SvTYPE (gv) == SVt_PVGV); 1547 assert (SvTYPE (gv) == SVt_PVGV);
1534# 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);
1535 f (GvGP (gv)->gp_form); 1550 f (GvGP (gv)->gp_form);
1536 f (GvGP (gv)->gp_io); 1551 f (GvGP (gv)->gp_io);
1537 f (GvGP (gv)->gp_sv); 1552 f (GvGP (gv)->gp_sv);
1538 f (GvGP (gv)->gp_av); 1553 f (GvGP (gv)->gp_av);
1539 f (GvGP (gv)->gp_hv); 1554 f (GvGP (gv)->gp_hv);
1540 f (GvGP (gv)->gp_cv); 1555 f (GvGP (gv)->gp_cv);
1541 GvCVGEN (gv) = 0; 1556 GvCVGEN (gv) = 0;
1542 GvMULTI_off (gv); 1557 GvMULTI_off (gv);
1558 SvREFCNT_dec (gv);
1543# undef f 1559# undef f
1544 1560
1545void _connect_to_perl_1 () 1561void _connect_to_perl_1 ()
1546 1562
1547void _connect_to_perl_2 () 1563void _connect_to_perl_2 ()
1568 1584
1569void init_dynamic () 1585void init_dynamic ()
1570 1586
1571void load_settings () 1587void load_settings ()
1572 1588
1573void reload_exp_table () 1589void _reload_exp_table ()
1574 1590
1575void reload_materials () 1591void _reload_materials ()
1576 1592
1577void init_uuid () 1593void init_uuid ()
1578 CODE: 1594 CODE:
1579 UUID::init (); 1595 UUID::init ();
1580 1596
1613 { 1629 {
1614 ev_async_send (EV_DEFAULT, &tick_watcher); 1630 ev_async_send (EV_DEFAULT, &tick_watcher);
1615 coroapi::cede (); 1631 coroapi::cede ();
1616 } 1632 }
1617 1633
1618void server_tick () 1634void one_tick ()
1619 CODE: 1635 CODE:
1620{ 1636{
1621 ev_now_update (EV_DEFAULT); 1637 ev_now_update (EV_DEFAULT);
1622 NOW = ev_now (EV_DEFAULT); 1638 NOW = ev_now (EV_DEFAULT);
1623 SvNV_set (sv_now, NOW); SvNOK_only (sv_now); 1639 SvNV_set (sv_now, NOW); SvNOK_only (sv_now);
1624 SvNV_set (sv_tick_start, NOW); SvNOK_only (sv_tick_start); 1640 SvNV_set (sv_tick_start, NOW); SvNOK_only (sv_tick_start);
1625 runtime = SvNVX (sv_runtime); 1641 runtime = SvNVX (sv_runtime);
1626 1642
1643 one_tick ();
1644
1627 server_tick (); 1645 ++server_tick;
1646 SvUV_set (sv_server_tick, server_tick); SvIOK_only_UV (sv_server_tick);
1628 1647
1629 ev_now_update (EV_DEFAULT); 1648 ev_now_update (EV_DEFAULT);
1630 NOW = ev_now (EV_DEFAULT); 1649 NOW = ev_now (EV_DEFAULT);
1631 SvNV_set (sv_now, NOW); SvNOK_only (sv_now); 1650 SvNV_set (sv_now, NOW); SvNOK_only (sv_now);
1651
1632 runtime += TICK; 1652 runtime += TICK;
1633 SvNV_set (sv_runtime, runtime); SvNOK_only (sv_runtime); 1653 SvNV_set (sv_runtime, runtime); SvNOK_only (sv_runtime);
1634} 1654}
1635 1655
1636NV floor (NV x) 1656NV floor (NV x)
1785 1805
1786int exp_to_level (val64 exp) 1806int exp_to_level (val64 exp)
1787 1807
1788val64 level_to_min_exp (int level) 1808val64 level_to_min_exp (int level)
1789 1809
1810const_utf8_string
1811spellpathnames (int idx)
1812 CODE:
1813 RETVAL = spellpathnames [idx];
1814 OUTPUT: RETVAL
1815
1790SV * 1816SV *
1791attacktype_name (int atnr) 1817attacktype_name (int atnr)
1792 CODE: 1818 CODE:
1793 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS) 1819 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1794 ? newSVpv (attacktype_name [atnr], 0) 1820 ? newSVpv (attacktype_name [atnr], 0)
2103# dumb kludgy misdesigned plug-in api slowly gets on my nerves. 2129# dumb kludgy misdesigned plug-in api slowly gets on my nerves.
2104 2130
2105object *new (utf8_string archetype = 0) 2131object *new (utf8_string archetype = 0)
2106 PROTOTYPE: ;$ 2132 PROTOTYPE: ;$
2107 CODE: 2133 CODE:
2108 RETVAL = archetype ? get_archetype (archetype) : object::create (); 2134 RETVAL = archetype
2135 ? archetype::get (archetype)
2136 : object::create ();
2109 OUTPUT: 2137 OUTPUT:
2110 RETVAL 2138 RETVAL
2111 2139
2112object *generate (utf8_string arch, object *creator) 2140object *generate (utf8_string arch, object *creator)
2113 CODE: 2141 CODE:
2114 object *obj = get_archetype (arch); 2142 object *obj = archetype::get (arch);
2115 fix_generated_item (obj, creator, 0, 0, GT_MINIMAL); 2143 fix_generated_item (obj, creator, 0, 0, GT_MINIMAL);
2116 RETVAL = obj; 2144 RETVAL = obj;
2117 OUTPUT: 2145 OUTPUT:
2118 RETVAL 2146 RETVAL
2119 2147
2129 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);
2130 2158
2131 if (RETVAL->destroyed ()) 2159 if (RETVAL->destroyed ())
2132 RETVAL = 0; 2160 RETVAL = 0;
2133} 2161}
2162 OUTPUT:
2163 RETVAL
2134 2164
2135shstr 2165shstr
2136object::kv_get (shstr key) 2166object::kv_get (shstr key)
2137 CODE: 2167 CODE:
2138 RETVAL = THIS->kv.get (key); 2168 RETVAL = THIS->kv.get (key);
2357 for_all_players (pl) 2387 for_all_players (pl)
2358 if (pl->ob && pl->ob->map == THIS) 2388 if (pl->ob && pl->ob->map == THIS)
2359 PUSHs (sv_2mortal (to_sv (pl->ob))); 2389 PUSHs (sv_2mortal (to_sv (pl->ob)));
2360 } 2390 }
2361 2391
2362#if 0
2363
2364void 2392void
2365maptile::add_quadland (int mx, int my, int mz, SV *biome_map, SV *biome_plt) 2393maptile::gen_quadmap (int x, int y, int z)
2366 CODE: 2394 CODE:
2367{ 2395 gen_quadmap (THIS, x * 50, y * 50, z);
2368 static frac_gen<vec2d> frac;
2369 2396
2397void
2398maptile::add_underlay (SV *data, int offset, int stride, SV *palette)
2399 CODE:
2400{
2370 if (!SvROK (biome_plt) || SvTYPE (SvRV (biome_plt)) != SVt_PVAV) 2401 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV)
2371 croak ("maptile::add_quadland: biome_plt must be arrayref"); 2402 croak ("maptile::add_underlay: palette must be arrayref");
2372 2403
2373 biome_plt = SvRV (biome_plt); 2404 palette = SvRV (palette);
2374 2405
2375 const uint8_t *bmap = (const uint8_t *)SvPVbyte_nolen (biome_map); 2406 STRLEN idxlen;
2407 const uint8 *idx = (const uint8 *)SvPVbyte (data, idxlen);
2376 2408
2377 for (int x = 0; x < THIS->width; ++x) 2409 for (int x = 0; x < THIS->width; ++x)
2378 for (int y = 0; y < THIS->height; ++y) 2410 for (int y = 0; y < THIS->height; ++y)
2379 { 2411 {
2380 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)
2381 if (op->flag [FLAG_IS_FLOOR]) 2413 if (op->flag [FLAG_IS_FLOOR])
2382 goto skip; 2414 goto skip;
2383 2415
2384 { 2416 {
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; 2417 int offs = offset + y * stride + x;
2441 2418
2442 if (IN_RANGE_EXC (offs, 0, idxlen)) 2419 if (IN_RANGE_EXC (offs, 0, idxlen))
2443 { 2420 {
2444 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) 2421 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0))
2445 { 2422 {
2446 object *ob = get_archetype (cfSvPVutf8_nolen (*elem)); 2423 object *ob = archetype::get (cfSvPVutf8_nolen (*elem));
2447 ob->flag [FLAG_NO_MAP_SAVE] = true; 2424 ob->flag [FLAG_NO_MAP_SAVE] = true;
2448 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); 2425 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY);
2449 2426
2450 if (ob->randomitems && !ob->above) 2427 if (ob->randomitems && !ob->above)
2451 { 2428 {
2475 croak ("maptile::set_regiondata: palette must be arrayref"); 2452 croak ("maptile::set_regiondata: palette must be arrayref");
2476 2453
2477 palette = SvRV (palette); 2454 palette = SvRV (palette);
2478 2455
2479 STRLEN idxlen; 2456 STRLEN idxlen;
2480 const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen); 2457 const uint8 *idx = (const uint8 *)SvPVbyte (data, idxlen);
2481 2458
2482 region_ptr *regionmap = new region_ptr [av_len ((AV *)palette) + 1]; 2459 region_ptr *regionmap = new region_ptr [av_len ((AV *)palette) + 1];
2483 uint8_t *regions = salloc<uint8_t> (THIS->size ()); 2460 uint8 *regions = salloc<uint8_t> (THIS->size ());
2484 2461
2485 for (int i = av_len ((AV *)palette) + 1; i--; ) 2462 for (int i = av_len ((AV *)palette) + 1; i--; )
2486 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)));
2487 2464
2488 for (int y = 0; y < THIS->height; ++y) 2465 for (int y = 0; y < THIS->height; ++y)
2614archetype *archetypes (U32 index) 2591archetype *archetypes (U32 index)
2615 CODE: 2592 CODE:
2616 RETVAL = index < archetypes.size () ? archetypes [index] : 0; 2593 RETVAL = index < archetypes.size () ? archetypes [index] : 0;
2617 OUTPUT: RETVAL 2594 OUTPUT: RETVAL
2618 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
2619INCLUDE: $PERL $srcdir/genacc archetype $srcdir/../include/object.h | 2606INCLUDE: $PERL $srcdir/genacc archetype $srcdir/../include/object.h |
2620 2607
2621MODULE = cf PACKAGE = cf::party 2608MODULE = cf PACKAGE = cf::party
2622 2609
2623partylist *first () 2610partylist *first ()
2671list () 2658list ()
2672 PPCODE: 2659 PPCODE:
2673 EXTEND (SP, clients.size ()); 2660 EXTEND (SP, clients.size ());
2674 for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i) 2661 for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i)
2675 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
2676 2680
2677void 2681void
2678client::send_packet (SV *packet) 2682client::send_packet (SV *packet)
2679 CODE: 2683 CODE:
2680{ 2684{
2736faceidx face_find (utf8_string name, faceidx defidx = 0) 2740faceidx face_find (utf8_string name, faceidx defidx = 0)
2737 2741
2738faceidx alloc (utf8_string name) 2742faceidx alloc (utf8_string name)
2739 CODE: 2743 CODE:
2740{ 2744{
2741 do 2745 RETVAL = face_alloc ();
2742 {
2743 RETVAL = faces.size ();
2744 faces.resize (RETVAL + 1);
2745 }
2746 while (!RETVAL); // crude way to leave index 0
2747 2746
2748 faces [RETVAL].name = name; 2747 faces [RETVAL].name = name;
2749 facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL)); 2748 facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL));
2750 2749
2751 if (!strcmp (name, BLANK_FACE_NAME )) blank_face = RETVAL; 2750 if (!strcmp (name, BLANK_FACE_NAME )) blank_face = RETVAL;
2752 if (!strcmp (name, EMPTY_FACE_NAME )) empty_face = RETVAL; 2751 if (!strcmp (name, EMPTY_FACE_NAME )) empty_face = RETVAL;
2753 if (!strcmp (name, MAGICMOUTH_FACE_NAME)) magicmouth_face = RETVAL; 2752 if (!strcmp (name, MAGICMOUTH_FACE_NAME)) magicmouth_face = RETVAL;
2754} 2753}
2754 OUTPUT: RETVAL
2755
2756faceidx faces_size ()
2757 CODE:
2758 RETVAL = faces.size ();
2755 OUTPUT: RETVAL 2759 OUTPUT: RETVAL
2756 2760
2757void set_type (faceidx idx, int value) 2761void set_type (faceidx idx, int value)
2758 ALIAS: 2762 ALIAS:
2759 set_type = 0 2763 set_type = 0
2770 case 2: f->magicmap = value; break; 2774 case 2: f->magicmap = value; break;
2771 case 3: f->smooth = value; break; 2775 case 3: f->smooth = value; break;
2772 case 4: f->smoothlevel = value; break; 2776 case 4: f->smoothlevel = value; break;
2773 } 2777 }
2774 2778
2775void set_data (faceidx idx, int faceset, SV *data, SV *chksum) 2779void set_data (faceidx idx, int faceset, uint32 size, uint32 fofs, SV *chksum)
2776 CODE: 2780 CODE:
2777{ 2781{
2778 faceinfo *f = face_info (idx); assert (f); 2782 faceinfo *f = face_info (idx); assert (f);
2779 facedata *d = f->face + faceset; 2783 facedata *d = f->face + faceset;
2780 sv_to (data, d->data);
2781 STRLEN clen; 2784 STRLEN clen;
2782 char *cdata = SvPVbyte (chksum, clen); 2785 char *cdata = SvPVbyte (chksum, clen);
2783 clen = min (CHKSUM_MAXLEN, clen);
2784 2786
2787 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)); 2788 assert (("cf::face::set_data must be called with a non-empty checksum", clen));
2789
2790 d->size = size;
2791 d->fofs = fofs;
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) 2804void set_meta (faceidx idx, SV *sv)
2803 CODE: 2805 CODE:
2804 facedata *d = face_data (idx, faceset); 2806{
2805 if (!d) XSRETURN_UNDEF; 2807 faceinfo *f = face_info (idx); assert (f);
2806 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));
2807 OUTPUT: 2817 OUTPUT:
2808 RETVAL 2818 RETVAL
2809 2819
2810SV *get_chksum (faceidx idx, int faceset = 0) 2820SV *get_chksum (faceidx idx, int faceset = 0)
2811 CODE: 2821 CODE:
2812 facedata *d = face_data (idx, faceset); 2822 facedata *d = face_data (idx, faceset);
2813 if (!d) XSRETURN_UNDEF; 2823 if (!d) XSRETURN_UNDEF;
2814 RETVAL = newSVpvn ((char *)d->chksum, d->chksum_len); 2824 RETVAL = newSVpvn ((char *)d->chksum, d->chksum_len);
2815 OUTPUT: 2825 OUTPUT:
2816 RETVAL 2826 RETVAL
2817 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
2818SV *get_data (faceidx idx, int faceset = 0) 2844uint32 get_size (faceidx idx, int faceset = 0)
2819 CODE: 2845 CODE:
2820 facedata *d = face_data (idx, faceset); 2846 facedata *d = face_data (idx, faceset);
2821 if (!d) XSRETURN_UNDEF; 2847 if (!d) XSRETURN_UNDEF;
2822 RETVAL = newSVpvn (d->data.data (), d->data.length ()); 2848 RETVAL = d->size;
2823 OUTPUT: 2849 OUTPUT:
2824 RETVAL 2850 RETVAL
2825 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
2826void invalidate (faceidx idx) 2868void invalidate (faceidx idx)
2827 CODE: 2869 CODE:
2828 for_all_clients (ns) 2870 for_all_clients (ns)
2829 { 2871 ns->invalidate_face (idx);
2830 ns->faces_sent [idx] = false;
2831 ns->force_newmap = true;
2832 }
2833 2872
2834void invalidate_all () 2873void invalidate_all ()
2835 CODE: 2874 CODE:
2836 for_all_clients (ns) 2875 for_all_clients (ns)
2837 { 2876 ns->invalidate_all_faces ();
2838 ns->faces_sent.reset ();
2839 ns->force_newmap = true;
2840 }
2841 2877
2842MODULE = cf PACKAGE = cf::anim PREFIX = anim_ 2878MODULE = cf PACKAGE = cf::anim PREFIX = anim_
2843 2879
2844#INCLUDE: $PERL $srcdir/genacc faceset $srcdir/../include/anim.h | 2880#INCLUDE: $PERL $srcdir/genacc faceset $srcdir/../include/anim.h |
2845 2881
2849 OUTPUT: RETVAL 2885 OUTPUT: RETVAL
2850 2886
2851animidx set (utf8_string name, SV *frames, int facings = 1) 2887animidx set (utf8_string name, SV *frames, int facings = 1)
2852 CODE: 2888 CODE:
2853{ 2889{
2854 if (!SvROK (frames) && SvTYPE (SvRV (frames)) != SVt_PVAV) 2890 if (!SvROK (frames) && SvTYPE (SvRV (frames)) != SVt_PVAV)
2855 croak ("frames must be an arrayref"); 2891 croak ("frames must be an arrayref");
2856 2892
2857 AV *av = (AV *)SvRV (frames); 2893 AV *av = (AV *)SvRV (frames);
2858 2894
2859 animation *anim = &animation::find (name); 2895 animation *anim = &animation::find (name);
2860 if (anim->number) 2896 if (anim->number)
2861 { 2897 {
2862 anim->resize (av_len (av) + 1); 2898 anim->resize (av_len (av) + 1);
2863 anim->facings = facings; 2899 anim->facings = facings;
2864 } 2900 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines