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.419 by root, Sun Nov 11 02:38:10 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
253 { 253 {
254 static int last_mortalcount; 254 static int last_mortalcount;
255 if (mortals.size () != last_mortalcount) 255 if (mortals.size () != last_mortalcount)
256 { 256 {
257 last_mortalcount = mortals.size (); 257 last_mortalcount = mortals.size ();
258 LOG (llevInfo, "%d mortals.\n", (int)mortals.size ()); 258 object *specimen = is_a<object> (mortals [rndm (mortals.size ())]);
259
260 LOG (llevInfo, "%d mortals (random specimen: %s).\n",
261 (int)mortals.size (), specimen ? specimen->debug_desc () : "(not an object)");
259 262
260 if (0) 263 if (0)
261 { 264 {
262 for (int j = 0; j < mortals.size (); ++j)//D 265 for (int j = 0; j < mortals.size (); ++j)//D
263 fprintf (stderr, "%d:%s %p ", j, &((object *)mortals[j])->name, mortals[j]);//D 266 fprintf (stderr, "%d:%s %p ", j, &((object *)mortals[j])->name, mortals[j]);//D
622 STRLEN len; 625 STRLEN len;
623 char *data = SvPVbyte (sv, len); 626 char *data = SvPVbyte (sv, len);
624 v.assign (data, len); 627 v.assign (data, len);
625} 628}
626 629
630static inline void sv_to (SV *sv, refcnt_buf &v)
631{
632 STRLEN len;
633 char *data = SvPVbyte (sv, len);
634 refcnt_buf buf (data, len);
635 v = buf;
636}
637
627static inline void sv_to (SV *sv, UUID &v) 638static inline void sv_to (SV *sv, UUID &v)
628{ 639{
629 if (!v.parse (SvPV_nolen (sv))) 640 if (!v.parse (SvPV_nolen (sv)))
630 croak ("unparsable uuid: %s", SvPV_nolen (sv)); 641 croak ("unparsable uuid: %s", SvPV_nolen (sv));
631} 642}
1404 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); 1415 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1);
1405 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1); 1416 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1);
1406 stash_cf_layout_wrap = gv_stashpv ("cf::layout::wrap", 1); 1417 stash_cf_layout_wrap = gv_stashpv ("cf::layout::wrap", 1);
1407 stash_ext_map_world = gv_stashpv ("ext::map_world" , 1); 1418 stash_ext_map_world = gv_stashpv ("ext::map_world" , 1);
1408 1419
1409 sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV); 1420 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); 1421 sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV);
1422 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); 1423 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); 1424 sv_next_tick = get_sv ("cf::NEXT_TICK" , 1); SvUPGRADE (sv_next_tick , SVt_NV);
1413 1425
1414 cb_global = get_av ("cf::CB_GLOBAL", 1); 1426 cb_global = get_av ("cf::CB_GLOBAL", 1);
1415 cb_attachable = get_av ("cf::CB_ATTACHABLE", 1); 1427 cb_attachable = get_av ("cf::CB_ATTACHABLE", 1);
1416 cb_object = get_av ("cf::CB_OBJECT", 1); 1428 cb_object = get_av ("cf::CB_OBJECT", 1);
1417 cb_player = get_av ("cf::CB_PLAYER", 1); 1429 cb_player = get_av ("cf::CB_PLAYER", 1);
1438 I_CORO_API (PACKAGE); coroapi::GCoroAPI = GCoroAPI; 1450 I_CORO_API (PACKAGE); coroapi::GCoroAPI = GCoroAPI;
1439 1451
1440 _connect_to_perl_1 (); 1452 _connect_to_perl_1 ();
1441 1453
1442 newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1)); 1454 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 1455
1453 static const struct { 1456 static const struct {
1454 const char *name; 1457 const char *name;
1455 IV iv; 1458 IV iv;
1456 } *civ, const_iv[] = { 1459 } *civ, const_iv[] = {
1486 const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE) 1489 const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE)
1487 1490
1488 const_iv (SK_EXP_ADD_SKILL) const_iv (SK_EXP_TOTAL) const_iv (SK_EXP_NONE) 1491 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) 1492 const_iv (SK_SUBTRACT_SKILL_EXP) const_iv (SK_EXP_SKILL_ONLY)
1490 1493
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) 1494 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) 1495 const_iv (KLASS_CLIENT) const_iv (KLASS_PLAYER) const_iv (KLASS_MAP)
1496 1496
1497 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT) 1497 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT)
1498 1498
1530 1530
1531void _gv_clear (SV *gv) 1531void _gv_clear (SV *gv)
1532 CODE: 1532 CODE:
1533 assert (SvTYPE (gv) == SVt_PVGV); 1533 assert (SvTYPE (gv) == SVt_PVGV);
1534# define f(sv) { SV *sv_ = (SV *)(sv); sv = 0; SvREFCNT_dec (sv_); } 1534# define f(sv) { SV *sv_ = (SV *)(sv); sv = 0; SvREFCNT_dec (sv_); }
1535 SvREFCNT_inc (gv);
1535 f (GvGP (gv)->gp_form); 1536 f (GvGP (gv)->gp_form);
1536 f (GvGP (gv)->gp_io); 1537 f (GvGP (gv)->gp_io);
1537 f (GvGP (gv)->gp_sv); 1538 f (GvGP (gv)->gp_sv);
1538 f (GvGP (gv)->gp_av); 1539 f (GvGP (gv)->gp_av);
1539 f (GvGP (gv)->gp_hv); 1540 f (GvGP (gv)->gp_hv);
1540 f (GvGP (gv)->gp_cv); 1541 f (GvGP (gv)->gp_cv);
1541 GvCVGEN (gv) = 0; 1542 GvCVGEN (gv) = 0;
1542 GvMULTI_off (gv); 1543 GvMULTI_off (gv);
1544 SvREFCNT_dec (gv);
1543# undef f 1545# undef f
1544 1546
1545void _connect_to_perl_1 () 1547void _connect_to_perl_1 ()
1546 1548
1547void _connect_to_perl_2 () 1549void _connect_to_perl_2 ()
1568 1570
1569void init_dynamic () 1571void init_dynamic ()
1570 1572
1571void load_settings () 1573void load_settings ()
1572 1574
1573void reload_exp_table () 1575void _reload_exp_table ()
1574 1576
1575void reload_materials () 1577void _reload_materials ()
1576 1578
1577void init_uuid () 1579void init_uuid ()
1578 CODE: 1580 CODE:
1579 UUID::init (); 1581 UUID::init ();
1580 1582
1613 { 1615 {
1614 ev_async_send (EV_DEFAULT, &tick_watcher); 1616 ev_async_send (EV_DEFAULT, &tick_watcher);
1615 coroapi::cede (); 1617 coroapi::cede ();
1616 } 1618 }
1617 1619
1618void server_tick () 1620void one_tick ()
1619 CODE: 1621 CODE:
1620{ 1622{
1621 ev_now_update (EV_DEFAULT); 1623 ev_now_update (EV_DEFAULT);
1622 NOW = ev_now (EV_DEFAULT); 1624 NOW = ev_now (EV_DEFAULT);
1623 SvNV_set (sv_now, NOW); SvNOK_only (sv_now); 1625 SvNV_set (sv_now, NOW); SvNOK_only (sv_now);
1624 SvNV_set (sv_tick_start, NOW); SvNOK_only (sv_tick_start); 1626 SvNV_set (sv_tick_start, NOW); SvNOK_only (sv_tick_start);
1625 runtime = SvNVX (sv_runtime); 1627 runtime = SvNVX (sv_runtime);
1626 1628
1629 one_tick ();
1630
1627 server_tick (); 1631 ++server_tick;
1632 SvUV_set (sv_server_tick, server_tick); SvIOK_only_UV (sv_server_tick);
1628 1633
1629 ev_now_update (EV_DEFAULT); 1634 ev_now_update (EV_DEFAULT);
1630 NOW = ev_now (EV_DEFAULT); 1635 NOW = ev_now (EV_DEFAULT);
1631 SvNV_set (sv_now, NOW); SvNOK_only (sv_now); 1636 SvNV_set (sv_now, NOW); SvNOK_only (sv_now);
1637
1632 runtime += TICK; 1638 runtime += TICK;
1633 SvNV_set (sv_runtime, runtime); SvNOK_only (sv_runtime); 1639 SvNV_set (sv_runtime, runtime); SvNOK_only (sv_runtime);
1634} 1640}
1635 1641
1636NV floor (NV x) 1642NV floor (NV x)
1785 1791
1786int exp_to_level (val64 exp) 1792int exp_to_level (val64 exp)
1787 1793
1788val64 level_to_min_exp (int level) 1794val64 level_to_min_exp (int level)
1789 1795
1796const_utf8_string
1797spellpathnames (int idx)
1798 CODE:
1799 RETVAL = spellpathnames [idx];
1800 OUTPUT: RETVAL
1801
1790SV * 1802SV *
1791attacktype_name (int atnr) 1803attacktype_name (int atnr)
1792 CODE: 1804 CODE:
1793 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS) 1805 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1794 ? newSVpv (attacktype_name [atnr], 0) 1806 ? newSVpv (attacktype_name [atnr], 0)
2103# dumb kludgy misdesigned plug-in api slowly gets on my nerves. 2115# dumb kludgy misdesigned plug-in api slowly gets on my nerves.
2104 2116
2105object *new (utf8_string archetype = 0) 2117object *new (utf8_string archetype = 0)
2106 PROTOTYPE: ;$ 2118 PROTOTYPE: ;$
2107 CODE: 2119 CODE:
2108 RETVAL = archetype ? get_archetype (archetype) : object::create (); 2120 RETVAL = archetype
2121 ? archetype::get (archetype)
2122 : object::create ();
2109 OUTPUT: 2123 OUTPUT:
2110 RETVAL 2124 RETVAL
2111 2125
2112object *generate (utf8_string arch, object *creator) 2126object *generate (utf8_string arch, object *creator)
2113 CODE: 2127 CODE:
2114 object *obj = get_archetype (arch); 2128 object *obj = archetype::get (arch);
2115 fix_generated_item (obj, creator, 0, 0, GT_MINIMAL); 2129 fix_generated_item (obj, creator, 0, 0, GT_MINIMAL);
2116 RETVAL = obj; 2130 RETVAL = obj;
2117 OUTPUT: 2131 OUTPUT:
2118 RETVAL 2132 RETVAL
2119 2133
2129 RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y); 2143 RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y);
2130 2144
2131 if (RETVAL->destroyed ()) 2145 if (RETVAL->destroyed ())
2132 RETVAL = 0; 2146 RETVAL = 0;
2133} 2147}
2148 OUTPUT:
2149 RETVAL
2134 2150
2135shstr 2151shstr
2136object::kv_get (shstr key) 2152object::kv_get (shstr key)
2137 CODE: 2153 CODE:
2138 RETVAL = THIS->kv.get (key); 2154 RETVAL = THIS->kv.get (key);
2357 for_all_players (pl) 2373 for_all_players (pl)
2358 if (pl->ob && pl->ob->map == THIS) 2374 if (pl->ob && pl->ob->map == THIS)
2359 PUSHs (sv_2mortal (to_sv (pl->ob))); 2375 PUSHs (sv_2mortal (to_sv (pl->ob)));
2360 } 2376 }
2361 2377
2362#if 0
2363
2364void 2378void
2365maptile::add_quadland (int mx, int my, int mz, SV *biome_map, SV *biome_plt) 2379maptile::gen_quadmap (int x, int y, int z)
2366 CODE: 2380 CODE:
2367{ 2381 gen_quadmap (THIS, x * 50, y * 50, z);
2368 static frac_gen<vec2d> frac;
2369 2382
2383void
2384maptile::add_underlay (SV *data, int offset, int stride, SV *palette)
2385 CODE:
2386{
2370 if (!SvROK (biome_plt) || SvTYPE (SvRV (biome_plt)) != SVt_PVAV) 2387 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV)
2371 croak ("maptile::add_quadland: biome_plt must be arrayref"); 2388 croak ("maptile::add_underlay: palette must be arrayref");
2372 2389
2373 biome_plt = SvRV (biome_plt); 2390 palette = SvRV (palette);
2374 2391
2392 STRLEN idxlen;
2375 const uint8_t *bmap = (const uint8_t *)SvPVbyte_nolen (biome_map); 2393 const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen);
2376 2394
2377 for (int x = 0; x < THIS->width; ++x) 2395 for (int x = 0; x < THIS->width; ++x)
2378 for (int y = 0; y < THIS->height; ++y) 2396 for (int y = 0; y < THIS->height; ++y)
2379 { 2397 {
2380 for (object *op = THIS->at (x, y).bot; op; op = op->above) 2398 for (object *op = THIS->at (x, y).bot; op; op = op->above)
2381 if (op->flag [FLAG_IS_FLOOR]) 2399 if (op->flag [FLAG_IS_FLOOR])
2382 goto skip; 2400 goto skip;
2383 2401
2384 { 2402 {
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; 2403 int offs = offset + y * stride + x;
2441 2404
2442 if (IN_RANGE_EXC (offs, 0, idxlen)) 2405 if (IN_RANGE_EXC (offs, 0, idxlen))
2443 { 2406 {
2444 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) 2407 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0))
2445 { 2408 {
2446 object *ob = get_archetype (cfSvPVutf8_nolen (*elem)); 2409 object *ob = archetype::get (cfSvPVutf8_nolen (*elem));
2447 ob->flag [FLAG_NO_MAP_SAVE] = true; 2410 ob->flag [FLAG_NO_MAP_SAVE] = true;
2448 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); 2411 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY);
2449 2412
2450 if (ob->randomitems && !ob->above) 2413 if (ob->randomitems && !ob->above)
2451 { 2414 {
2614archetype *archetypes (U32 index) 2577archetype *archetypes (U32 index)
2615 CODE: 2578 CODE:
2616 RETVAL = index < archetypes.size () ? archetypes [index] : 0; 2579 RETVAL = index < archetypes.size () ? archetypes [index] : 0;
2617 OUTPUT: RETVAL 2580 OUTPUT: RETVAL
2618 2581
2582int skillvec_size ()
2583 CODE:
2584 RETVAL = skillvec.size ();
2585 OUTPUT: RETVAL
2586
2587archetype *skillvec (U32 index)
2588 CODE:
2589 RETVAL = index < skillvec.size () ? (archetype *)(object *)skillvec [index] : 0;
2590 OUTPUT: RETVAL
2591
2619INCLUDE: $PERL $srcdir/genacc archetype $srcdir/../include/object.h | 2592INCLUDE: $PERL $srcdir/genacc archetype $srcdir/../include/object.h |
2620 2593
2621MODULE = cf PACKAGE = cf::party 2594MODULE = cf PACKAGE = cf::party
2622 2595
2623partylist *first () 2596partylist *first ()
2671list () 2644list ()
2672 PPCODE: 2645 PPCODE:
2673 EXTEND (SP, clients.size ()); 2646 EXTEND (SP, clients.size ());
2674 for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i) 2647 for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i)
2675 PUSHs (sv_2mortal (to_sv (*i))); 2648 PUSHs (sv_2mortal (to_sv (*i)));
2649
2650STRLEN
2651client::inbuf_append (SV *data)
2652 CODE:
2653{
2654 STRLEN len;
2655 char *ptr = SvPVbyte (data, len);
2656
2657 min_it (len, sizeof (THIS->inbuf) - THIS->inbuf_len);
2658 memcpy (THIS->inbuf + THIS->inbuf_len, ptr, len);
2659 THIS->inbuf_len += len;
2660
2661 THIS->inbuf_handle ();
2662
2663 RETVAL = len;
2664}
2665 OUTPUT: RETVAL
2676 2666
2677void 2667void
2678client::send_packet (SV *packet) 2668client::send_packet (SV *packet)
2679 CODE: 2669 CODE:
2680{ 2670{
2736faceidx face_find (utf8_string name, faceidx defidx = 0) 2726faceidx face_find (utf8_string name, faceidx defidx = 0)
2737 2727
2738faceidx alloc (utf8_string name) 2728faceidx alloc (utf8_string name)
2739 CODE: 2729 CODE:
2740{ 2730{
2741 do 2731 RETVAL = face_alloc ();
2742 {
2743 RETVAL = faces.size ();
2744 faces.resize (RETVAL + 1);
2745 }
2746 while (!RETVAL); // crude way to leave index 0
2747 2732
2748 faces [RETVAL].name = name; 2733 faces [RETVAL].name = name;
2749 facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL)); 2734 facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL));
2750 2735
2751 if (!strcmp (name, BLANK_FACE_NAME )) blank_face = RETVAL; 2736 if (!strcmp (name, BLANK_FACE_NAME )) blank_face = RETVAL;
2752 if (!strcmp (name, EMPTY_FACE_NAME )) empty_face = RETVAL; 2737 if (!strcmp (name, EMPTY_FACE_NAME )) empty_face = RETVAL;
2753 if (!strcmp (name, MAGICMOUTH_FACE_NAME)) magicmouth_face = RETVAL; 2738 if (!strcmp (name, MAGICMOUTH_FACE_NAME)) magicmouth_face = RETVAL;
2754} 2739}
2740 OUTPUT: RETVAL
2741
2742faceidx faces_size ()
2743 CODE:
2744 RETVAL = faces.size ();
2755 OUTPUT: RETVAL 2745 OUTPUT: RETVAL
2756 2746
2757void set_type (faceidx idx, int value) 2747void set_type (faceidx idx, int value)
2758 ALIAS: 2748 ALIAS:
2759 set_type = 0 2749 set_type = 0
2778 faceinfo *f = face_info (idx); assert (f); 2768 faceinfo *f = face_info (idx); assert (f);
2779 facedata *d = f->face + faceset; 2769 facedata *d = f->face + faceset;
2780 sv_to (data, d->data); 2770 sv_to (data, d->data);
2781 STRLEN clen; 2771 STRLEN clen;
2782 char *cdata = SvPVbyte (chksum, clen); 2772 char *cdata = SvPVbyte (chksum, clen);
2783 clen = min (CHKSUM_MAXLEN, clen);
2784 2773
2774 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)); 2775 assert (("cf::face::set_data must be called with a non-empty checksum", clen));
2786 2776
2787 if (clen != d->chksum_len || memcmp (d->chksum, cdata, clen)) 2777 if (clen != d->chksum_len || memcmp (d->chksum, cdata, clen))
2788 { 2778 {
2789 d->chksum_len = clen; 2779 d->chksum_len = clen;
2790 memcpy (d->chksum, cdata, clen); 2780 memcpy (d->chksum, cdata, clen);
2791 2781
2792 // invalidate existing client face info 2782 // invalidate existing client face info
2793 for_all_clients (ns) 2783 for_all_clients (ns)
2794 if (ns->faceset == faceset) 2784 ns->invalidate_face (idx);
2795 {
2796 ns->faces_sent [idx] = false;
2797 ns->force_newmap = true;
2798 }
2799 } 2785 }
2800} 2786}
2801 2787
2802int get_data_size (faceidx idx, int faceset = 0) 2788int get_data_size (faceidx idx, int faceset = 0)
2803 CODE: 2789 CODE:
2805 if (!d) XSRETURN_UNDEF; 2791 if (!d) XSRETURN_UNDEF;
2806 RETVAL = d->data.size (); 2792 RETVAL = d->data.size ();
2807 OUTPUT: 2793 OUTPUT:
2808 RETVAL 2794 RETVAL
2809 2795
2796void set_meta (faceidx idx, SV *sv)
2797 CODE:
2798{
2799 faceinfo *f = face_info (idx); assert (f);
2800 SvREFCNT_dec (f->meta_hv);
2801 f->meta_hv = SvOK (sv) ? (HV *)SvREFCNT_inc (SvRV (sv)) : 0;
2802}
2803
2804SV *mangle_chksum (SV *chksum)
2805 CODE:
2806 STRLEN len;
2807 char *data = SvPVbyte (chksum, len);
2808 RETVAL = newSVpvn (data, min (len, CHKSUM_MAXLEN));
2809 OUTPUT:
2810 RETVAL
2811
2810SV *get_chksum (faceidx idx, int faceset = 0) 2812SV *get_chksum (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
2820int get_type (faceidx idx)
2821 CODE:
2822 faceinfo *f = face_info (idx);
2823 if (!f) XSRETURN_UNDEF;
2824 RETVAL = f->type;
2825 OUTPUT:
2826 RETVAL
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
2818SV *get_data (faceidx idx, int faceset = 0) 2836SV *get_data (faceidx idx, int faceset = 0)
2819 CODE: 2837 CODE:
2820 facedata *d = face_data (idx, faceset); 2838 facedata *d = face_data (idx, faceset);
2821 if (!d) XSRETURN_UNDEF; 2839 if (!d) XSRETURN_UNDEF;
2822 RETVAL = newSVpvn (d->data.data (), d->data.length ()); 2840 RETVAL = newSVpvn (d->data, d->data.size ());
2823 OUTPUT: 2841 OUTPUT:
2824 RETVAL 2842 RETVAL
2825 2843
2844SV *get_meta (faceidx idx)
2845 CODE:
2846 faceinfo *f = face_info (idx); assert (f);
2847 if (!f || !f->meta_hv) XSRETURN_UNDEF;
2848 RETVAL = newRV_inc ((SV *)f->meta_hv);
2849 OUTPUT:
2850 RETVAL
2851
2826void invalidate (faceidx idx) 2852void invalidate (faceidx idx)
2827 CODE: 2853 CODE:
2828 for_all_clients (ns) 2854 for_all_clients (ns)
2829 { 2855 ns->invalidate_face (idx);
2830 ns->faces_sent [idx] = false;
2831 ns->force_newmap = true;
2832 }
2833 2856
2834void invalidate_all () 2857void invalidate_all ()
2835 CODE: 2858 CODE:
2836 for_all_clients (ns) 2859 for_all_clients (ns)
2837 { 2860 ns->invalidate_all_faces ();
2838 ns->faces_sent.reset ();
2839 ns->force_newmap = true;
2840 }
2841 2861
2842MODULE = cf PACKAGE = cf::anim PREFIX = anim_ 2862MODULE = cf PACKAGE = cf::anim PREFIX = anim_
2843 2863
2844#INCLUDE: $PERL $srcdir/genacc faceset $srcdir/../include/anim.h | 2864#INCLUDE: $PERL $srcdir/genacc faceset $srcdir/../include/anim.h |
2845 2865
2849 OUTPUT: RETVAL 2869 OUTPUT: RETVAL
2850 2870
2851animidx set (utf8_string name, SV *frames, int facings = 1) 2871animidx set (utf8_string name, SV *frames, int facings = 1)
2852 CODE: 2872 CODE:
2853{ 2873{
2854 if (!SvROK (frames) && SvTYPE (SvRV (frames)) != SVt_PVAV) 2874 if (!SvROK (frames) && SvTYPE (SvRV (frames)) != SVt_PVAV)
2855 croak ("frames must be an arrayref"); 2875 croak ("frames must be an arrayref");
2856 2876
2857 AV *av = (AV *)SvRV (frames); 2877 AV *av = (AV *)SvRV (frames);
2858 2878
2859 animation *anim = &animation::find (name); 2879 animation *anim = &animation::find (name);
2860 if (anim->number) 2880 if (anim->number)
2861 { 2881 {
2862 anim->resize (av_len (av) + 1); 2882 anim->resize (av_len (av) + 1);
2863 anim->facings = facings; 2883 anim->facings = facings;
2864 } 2884 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines