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.221 by root, Sat Jun 16 00:12:20 2007 UTC vs.
Revision 1.243 by root, Fri Aug 24 00:26:10 2007 UTC

3 * 3 *
4 * Copyright (©) 2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team 4 * Copyright (©) 2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team
5 * Copyright (©) 2001-2005,2007 by Chachkoff Yann 5 * Copyright (©) 2001-2005,2007 by Chachkoff Yann
6 * Copyright (©) 2006,2007 by Marc Lehmann <cf@schmorp.de> 6 * Copyright (©) 2006,2007 by Marc Lehmann <cf@schmorp.de>
7 * 7 *
8 * Crossfire TRT is free software; you can redistribute it and/or modify it 8 * Crossfire TRT is free software: you can redistribute it and/or modify
9 * under the terms of the GNU General Public License as published by the Free 9 * it under the terms of the GNU General Public License as published by
10 * Software Foundation; either version 2 of the License, or (at your option) 10 * the Free Software Foundation, either version 3 of the License, or
11 * any later version. 11 * (at your option) any later version.
12 * 12 *
13 * This program is distributed in the hope that it will be useful, but 13 * This program is distributed in the hope that it will be useful,
14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * for more details. 16 * GNU General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU General Public License along 18 * You should have received a copy of the GNU General Public License
19 * with Crossfire TRT; if not, write to the Free Software Foundation, Inc. 51 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 * 20 *
22 * The authors can be reached via e-mail to <crossfire@schmorp.de> 21 * The authors can be reached via e-mail to <crossfire@schmorp.de>
23 */ 22 */
24 23
25#include "autoconf.h" 24#include "autoconf.h"
247 delete obj; 246 delete obj;
248 } 247 }
249 } 248 }
250} 249}
251 250
251void
252attachable::set_key (const char *key, const char *value)
253{
254 if (!self)
255 self = newHV ();
256
257 if (value)
258 hv_store (self, key, strlen (key), newSVpv (value, 0), 0);
259 else
260 hv_delete (self, key, strlen (key), G_DISCARD);
261}
262
252attachable & 263attachable &
253attachable::operator =(const attachable &src) 264attachable::operator =(const attachable &src)
254{ 265{
255 //if (self || cb) 266 //if (self || cb)
256 //INVOKE_OBJECT (CLONE, this, ARG_OBJECT (dst)); 267 //INVOKE_OBJECT (CLONE, this, ARG_OBJECT (dst));
331{ 342{
332 if (!obj) 343 if (!obj)
333 return &PL_sv_undef; 344 return &PL_sv_undef;
334 345
335 if (!obj->self) 346 if (!obj->self)
347 obj->self = newHV ();
348
349 if (!SvOBJECT (obj->self))
336 { 350 {
337 obj->self = newHV ();
338 sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &attachable::vtbl, (char *)obj, 0); 351 sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &attachable::vtbl, (char *)obj, 0);
339 352
340 // now bless the object _once_ 353 // now bless the object _once_
354 //TODO: create a class registry with c++ type<=>perl name<=>stash and use it here and elsewhere
341 return sv_bless (newRV_inc ((SV *)obj->self), stash); 355 return sv_bless (newRV_inc ((SV *)obj->self), stash);
342 } 356 }
343 else 357 else
344 { 358 {
345 SV *sv = newRV_inc ((SV *)obj->self); 359 SV *sv = newRV_inc ((SV *)obj->self);
382 return SvPTR (sv, klass); 396 return SvPTR (sv, klass);
383 else 397 else
384 return 0; 398 return 0;
385} 399}
386 400
401static inline SV *
402newSVpv_utf8 (const char *s)
403{
404 SV *sv = newSVpv (s, 0);
405 SvUTF8_on (sv);
406 return sv;
407}
408
409static inline SV *
410newSVpvn_utf8 (const char *s, STRLEN l)
411{
412 SV *sv = newSVpvn (s, l);
413 SvUTF8_on (sv);
414 return sv;
415}
416
387inline SV *to_sv (const shstr & v) { return v ? newSVpvn ((const char *)v, v.length ()) : &PL_sv_undef; } 417inline SV *to_sv (const shstr & v) { return v ? newSVpvn_utf8 ((const char *)v, v.length ()) : &PL_sv_undef; }
388inline SV *to_sv (const char * v) { return newSVpv (v, 0); } 418inline SV *to_sv (const char * v) { return newSVpv (v, 0); }
389inline SV *to_sv (bool v) { return newSViv (v); } 419inline SV *to_sv (bool v) { return newSViv (v); }
390inline SV *to_sv ( signed char v) { return newSViv (v); } 420inline SV *to_sv ( signed char v) { return newSViv (v); }
391inline SV *to_sv (unsigned char v) { return newSViv (v); } 421inline SV *to_sv (unsigned char v) { return newSViv (v); }
392inline SV *to_sv ( signed short v) { return newSViv (v); } 422inline SV *to_sv ( signed short v) { return newSViv (v); }
402inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); } 432inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); }
403inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); } 433inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); }
404inline SV *to_sv (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); } 434inline SV *to_sv (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); }
405inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); } 435inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); }
406inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); } 436inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); }
437inline SV *to_sv (region * v) { return newSVattachable (v, stash_cf_region_wrap); }
407inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); } 438inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); }
408inline SV *to_sv (region * v) { return newSVptr (v, stash_cf_region_wrap); }
409inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } 439inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); }
410 440
411inline SV *to_sv (object & v) { return to_sv (&v); } 441inline SV *to_sv (object & v) { return to_sv (&v); }
412inline SV *to_sv (living & v) { return to_sv (&v); } 442inline SV *to_sv (living & v) { return to_sv (&v); }
413 443
419 char buf[128]; 449 char buf[128];
420 snprintf (buf, 128, "<1.%" PRIx64 ">", v.seq); 450 snprintf (buf, 128, "<1.%" PRIx64 ">", v.seq);
421 return newSVpv (buf, 0); 451 return newSVpv (buf, 0);
422} 452}
423 453
424inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? SvPV_nolen (sv) : 0; } 454inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? SvPVutf8_nolen (sv) : 0; }
425inline void sv_to (SV *sv, char * &v) { free (v); v = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; } 455inline void sv_to (SV *sv, char * &v) { free (v); v = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; }
426inline void sv_to (SV *sv, bool &v) { v = SvIV (sv); } 456inline void sv_to (SV *sv, bool &v) { v = SvIV (sv); }
427inline void sv_to (SV *sv, signed char &v) { v = SvIV (sv); } 457inline void sv_to (SV *sv, signed char &v) { v = SvIV (sv); }
428inline void sv_to (SV *sv, unsigned char &v) { v = SvIV (sv); } 458inline void sv_to (SV *sv, unsigned char &v) { v = SvIV (sv); }
429inline void sv_to (SV *sv, signed short &v) { v = SvIV (sv); } 459inline void sv_to (SV *sv, signed short &v) { v = SvIV (sv); }
439inline void sv_to (SV *sv, client * &v) { v = (client *)(attachable *)SvPTR_ornull (sv, "cf::client"); } 469inline void sv_to (SV *sv, client * &v) { v = (client *)(attachable *)SvPTR_ornull (sv, "cf::client"); }
440inline void sv_to (SV *sv, player * &v) { v = (player *)(attachable *)SvPTR_ornull (sv, "cf::player"); } 470inline void sv_to (SV *sv, player * &v) { v = (player *)(attachable *)SvPTR_ornull (sv, "cf::player"); }
441inline void sv_to (SV *sv, object * &v) { v = (object *)(attachable *)SvPTR_ornull (sv, "cf::object"); } 471inline void sv_to (SV *sv, object * &v) { v = (object *)(attachable *)SvPTR_ornull (sv, "cf::object"); }
442inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)(attachable *)SvPTR_ornull (sv, "cf::arch"); } 472inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)(attachable *)SvPTR_ornull (sv, "cf::arch"); }
443inline void sv_to (SV *sv, maptile * &v) { v = (maptile *)(attachable *)SvPTR_ornull (sv, "cf::map"); } 473inline void sv_to (SV *sv, maptile * &v) { v = (maptile *)(attachable *)SvPTR_ornull (sv, "cf::map"); }
474inline void sv_to (SV *sv, region * &v) { v = (region *)(attachable *)SvPTR_ornull (sv, "cf::region"); }
444inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } 475inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); }
445inline void sv_to (SV *sv, partylist * &v) { v = (partylist *)SvPTR_ornull (sv, "cf::party"); } 476inline void sv_to (SV *sv, partylist * &v) { v = (partylist *)SvPTR_ornull (sv, "cf::party"); }
446inline void sv_to (SV *sv, region * &v) { v = (region *)SvPTR_ornull (sv, "cf::region"); }
447inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); } 477inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); }
448 478
449//inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; } 479//inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; }
450inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); } 480inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); }
451 481
934} 964}
935 965
936SV * 966SV *
937cfperl_result (int idx) 967cfperl_result (int idx)
938{ 968{
939 AV *av = get_av ("cfperl::invoke_results", 0); 969 AV *av = get_av ("cf::INVOKE_RESULTS", 0);
940 if (!av) 970 if (!av)
941 return &PL_sv_undef; 971 return &PL_sv_undef;
942 972
943 SV **sv = av_fetch (av, idx, 0); 973 SV **sv = av_fetch (av, idx, 0);
944 if (!sv) 974 if (!sv)
986 CALL_ARG (level); 1016 CALL_ARG (level);
987 CALL_CALL ("ext::books::make_book", G_VOID); 1017 CALL_CALL ("ext::books::make_book", G_VOID);
988 CALL_END; 1018 CALL_END;
989} 1019}
990 1020
1021void
1022cfperl_send_msg (client *ns, int color, const char *type, const char *msg)
1023{
1024 CALL_BEGIN (4);
1025 CALL_ARG (ns);
1026 CALL_ARG (type);
1027 CALL_ARG_SV (newSVpv_utf8 (msg));
1028 CALL_ARG (color);
1029 CALL_CALL ("cf::client::send_msg", G_VOID);
1030 CALL_END;
1031}
1032
1033int
1034cfperl_can_merge (object *ob1, object *ob2)
1035{
1036 int can;
1037
1038 CALL_BEGIN (2);
1039 CALL_ARG (ob1);
1040 CALL_ARG (ob2);
1041 CALL_CALL ("cf::_can_merge", G_SCALAR);
1042 can = count && SvTRUE (TOPs);
1043 CALL_END;
1044
1045 return can;
1046}
1047
991maptile * 1048maptile *
992maptile::find_sync (const char *path, maptile *origin) 1049maptile::find_sync (const char *path, maptile *origin)
993{ 1050{
994 CALL_BEGIN (2); 1051 CALL_BEGIN (2);
995 CALL_ARG (path); 1052 CALL_ARG (path);
1007 1064
1008 return retval; 1065 return retval;
1009} 1066}
1010 1067
1011maptile * 1068maptile *
1012maptile::find_async (const char *path, maptile *origin) 1069maptile::find_async (const char *path, maptile *origin, bool load)
1013{ 1070{
1014 CALL_BEGIN (2); 1071 CALL_BEGIN (3);
1015 CALL_ARG (path); 1072 CALL_ARG (path);
1016 CALL_ARG (origin); 1073 CALL_ARG (origin);
1074 CALL_ARG (load);
1017 CALL_CALL ("cf::map::find_async", G_SCALAR); 1075 CALL_CALL ("cf::map::find_async", G_SCALAR);
1018 1076
1019 maptile *retval; 1077 maptile *retval;
1020 1078
1021 if (count) 1079 if (count)
1327 1385
1328 const_iv (NDI_BLACK) const_iv (NDI_WHITE) const_iv (NDI_NAVY) const_iv (NDI_RED) 1386 const_iv (NDI_BLACK) const_iv (NDI_WHITE) const_iv (NDI_NAVY) const_iv (NDI_RED)
1329 const_iv (NDI_ORANGE) const_iv (NDI_BLUE) const_iv (NDI_DK_ORANGE) const_iv (NDI_GREEN) 1387 const_iv (NDI_ORANGE) const_iv (NDI_BLUE) const_iv (NDI_DK_ORANGE) const_iv (NDI_GREEN)
1330 const_iv (NDI_LT_GREEN) const_iv (NDI_GREY) const_iv (NDI_BROWN) const_iv (NDI_GOLD) 1388 const_iv (NDI_LT_GREEN) const_iv (NDI_GREY) const_iv (NDI_BROWN) const_iv (NDI_GOLD)
1331 const_iv (NDI_TAN) const_iv (NDI_MAX_COLOR) const_iv (NDI_COLOR_MASK) const_iv (NDI_UNIQUE) 1389 const_iv (NDI_TAN) const_iv (NDI_MAX_COLOR) const_iv (NDI_COLOR_MASK) const_iv (NDI_UNIQUE)
1390 const_iv (NDI_ALL) const_iv (NDI_DEF) const_iv (NDI_REPLY) const_iv (NDI_CLIENT_MASK)
1332 const_iv (NDI_ALL) 1391 const_iv (NDI_NOCREATE)
1333 1392
1334 const_iv (UPD_LOCATION) const_iv (UPD_FLAGS) const_iv (UPD_WEIGHT) const_iv (UPD_FACE) 1393 const_iv (UPD_LOCATION) const_iv (UPD_FLAGS) const_iv (UPD_WEIGHT) const_iv (UPD_FACE)
1335 const_iv (UPD_NAME) const_iv (UPD_ANIM) const_iv (UPD_ANIMSPEED) const_iv (UPD_NROF) 1394 const_iv (UPD_NAME) const_iv (UPD_ANIM) const_iv (UPD_ANIMSPEED) const_iv (UPD_NROF)
1336 1395
1337 const_iv (UPD_SP_MANA) const_iv (UPD_SP_GRACE) const_iv (UPD_SP_DAMAGE) 1396 const_iv (UPD_SP_MANA) const_iv (UPD_SP_GRACE) const_iv (UPD_SP_DAMAGE)
1464 const_iv (SYMMETRY_Y) const_iv (SYMMETRY_XY) 1523 const_iv (SYMMETRY_Y) const_iv (SYMMETRY_XY)
1465 1524
1466 const_iv (GT_ENVIRONMENT) const_iv (GT_INVISIBLE) const_iv (GT_STARTEQUIP) 1525 const_iv (GT_ENVIRONMENT) const_iv (GT_INVISIBLE) const_iv (GT_STARTEQUIP)
1467 const_iv (GT_APPLY) const_iv (GT_ONLY_GOOD) const_iv (GT_UPDATE_INV) 1526 const_iv (GT_APPLY) const_iv (GT_ONLY_GOOD) const_iv (GT_UPDATE_INV)
1468 const_iv (GT_MINIMAL) 1527 const_iv (GT_MINIMAL)
1528
1529 const_iv (FT_FACE) const_iv (FT_MUSIC) const_iv (FT_SOUND)
1530 const_iv (FT_RSRC) const_iv (FT_NUM)
1469 }; 1531 };
1470 1532
1471 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 1533 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
1472 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv)); 1534 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv));
1473 1535
1507 1569
1508 for_all_objects (op) 1570 for_all_objects (op)
1509 op->reattach (); 1571 op->reattach ();
1510} 1572}
1511 1573
1512void _post_tick ()
1513 CODE:
1514 coroapi::next_cede = SvNV (sv_next_tick) - TICK * (1. - 1. / CEDES_PER_TICK);
1515
1516# support function for map-world.ext 1574# support function for map-world.ext
1517void _quantise (SV *data_sv, SV *plt_sv) 1575void _quantise (SV *data_sv, SV *plt_sv)
1518 CODE: 1576 CODE:
1519{ 1577{
1520 if (!SvROK (plt_sv) || SvTYPE (SvRV (plt_sv)) != SVt_PVAV) 1578 if (!SvROK (plt_sv) || SvTYPE (SvRV (plt_sv)) != SVt_PVAV)
1552 len -= 3; 1610 len -= 3;
1553 } 1611 }
1554 1612
1555 SvCUR_set (data_sv, dst - SvPVX (data_sv)); 1613 SvCUR_set (data_sv, dst - SvPVX (data_sv));
1556} 1614}
1615
1616void _post_tick ()
1617 CODE:
1618 coroapi::next_cede = SvNV (sv_next_tick) - TICK * (1. - 1. / CEDES_PER_TICK);
1619
1620NV till_cede ()
1621 CODE:
1622 RETVAL = coroapi::next_cede - now ();
1623 OUTPUT:
1624 RETVAL
1625
1626NV till_tick ()
1627 CODE:
1628 RETVAL = SvNV (sv_next_tick) - now ();
1629 OUTPUT:
1630 RETVAL
1557 1631
1558NV floor (NV x) 1632NV floor (NV x)
1559 1633
1560NV ceil (NV x) 1634NV ceil (NV x)
1561 1635
1604octet_string path_combine (octet_string base, octet_string path) 1678octet_string path_combine (octet_string base, octet_string path)
1605 PROTOTYPE: $$ 1679 PROTOTYPE: $$
1606 1680
1607octet_string path_combine_and_normalize (octet_string base, octet_string path) 1681octet_string path_combine_and_normalize (octet_string base, octet_string path)
1608 PROTOTYPE: $$ 1682 PROTOTYPE: $$
1609
1610const_octet_string
1611get_maps_directory (octet_string path)
1612 PROTOTYPE: $
1613 ALIAS: maps_directory = 0
1614 CODE:
1615 RETVAL = create_pathname (path);
1616 OUTPUT: RETVAL
1617 1683
1618void 1684void
1619sub_generation_inc () 1685sub_generation_inc ()
1620 CODE: 1686 CODE:
1621 PL_sub_generation++; 1687 PL_sub_generation++;
1743#object *mortals (U32 index) 1809#object *mortals (U32 index)
1744# CODE: 1810# CODE:
1745# RETVAL = index < attachable::mortals.size () ? attachable::mortals [index] : 0; 1811# RETVAL = index < attachable::mortals.size () ? attachable::mortals [index] : 0;
1746# OUTPUT: RETVAL 1812# OUTPUT: RETVAL
1747 1813
1748INCLUDE: $PERL $srcdir/genacc attachable ../include/cfperl.h | 1814INCLUDE: $PERL $srcdir/genacc attachable ../include/util.h ../include/cfperl.h |
1749 1815
1750MODULE = cf PACKAGE = cf::global 1816MODULE = cf PACKAGE = cf::global
1751 1817
1752int invoke (SV *klass, int event, ...) 1818int invoke (SV *klass, int event, ...)
1753 CODE: 1819 CODE:
1967 2033
1968void add_button_link (object *button, maptile *map, int connected); 2034void add_button_link (object *button, maptile *map, int connected);
1969 2035
1970void remove_button_link (object *op); 2036void remove_button_link (object *op);
1971 2037
2038void handle_apply_yield (object *op);
2039
1972 2040
1973MODULE = cf PACKAGE = cf::object PREFIX = cf_ 2041MODULE = cf PACKAGE = cf::object PREFIX = cf_
1974 2042
1975object *cf_insert_ob_in_ob (object *ob, object *where) 2043object *cf_insert_ob_in_ob (object *ob, object *where)
1976 2044
1982 CODE: 2050 CODE:
1983 RETVAL = archetype ? get_archetype (archetype) : object::create (); 2051 RETVAL = archetype ? get_archetype (archetype) : object::create ();
1984 OUTPUT: 2052 OUTPUT:
1985 RETVAL 2053 RETVAL
1986 2054
2055object *find_object (U32 tag)
2056
1987# TODO: nuke 2057# TODO: nuke
1988object *insert_ob_in_map_at (object *ob, maptile *where, object_ornull *orig, int flag, int x, int y) 2058object *insert_ob_in_map_at (object *ob, maptile *where, object_ornull *orig, int flag, int x, int y)
1989 PROTOTYPE: $$$$$$ 2059 PROTOTYPE: $$$$$$
1990 CODE: 2060 CODE:
1991{ 2061{
1992 int unused_type; 2062 int unused_type;
1993 RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y); 2063 RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y);
1994} 2064}
1995
1996player *contr (object *op)
1997 CODE:
1998 RETVAL = op->contr;
1999 OUTPUT: RETVAL
2000 2065
2001const_utf8_string get_ob_key_value (object *op, utf8_string key) 2066const_utf8_string get_ob_key_value (object *op, utf8_string key)
2002 2067
2003bool set_ob_key_value (object *op, utf8_string key, utf8_string value = 0, int add_key = 1) 2068bool set_ob_key_value (object *op, utf8_string key, utf8_string value = 0, int add_key = 1)
2004 2069
2080 pl->orig_stats = pl->ob->stats; 2145 pl->orig_stats = pl->ob->stats;
2081 2146
2082void clear_los (player *pl) 2147void clear_los (player *pl)
2083 2148
2084void cf_player_move (player *pl, int dir) 2149void cf_player_move (player *pl, int dir)
2085
2086void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0);
2087 2150
2088bool 2151bool
2089cell_visible (player *pl, int dx, int dy) 2152cell_visible (player *pl, int dx, int dy)
2090 CODE: 2153 CODE:
2091 RETVAL = FABS (dx) <= pl->ns->mapx / 2 && FABS (dy) <= pl->ns->mapy / 2 2154 RETVAL = FABS (dx) <= pl->ns->mapx / 2 && FABS (dy) <= pl->ns->mapy / 2
2230 palette = SvRV (palette); 2293 palette = SvRV (palette);
2231 2294
2232 STRLEN idxlen; 2295 STRLEN idxlen;
2233 const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen); 2296 const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen);
2234 2297
2235 region **regionmap = (region **)malloc ( 2298 region_ptr *regionmap = new region_ptr [av_len ((AV *)palette) + 1];
2236 (av_len ((AV *)palette) + 1) * sizeof (region *));
2237 uint8_t *regions = salloc<uint8_t> (THIS->size ()); 2299 uint8_t *regions = salloc<uint8_t> (THIS->size ());
2238 2300
2239 for (int i = av_len ((AV *)palette) + 1; i--; ) 2301 for (int i = av_len ((AV *)palette) + 1; i--; )
2240 regionmap [i] = region::find ( 2302 regionmap [i] = region::find (SvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1)));
2241 SvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1)));
2242 2303
2243 for (int y = 0; y < THIS->height; ++y) 2304 for (int y = 0; y < THIS->height; ++y)
2244 memcpy (regions + y * THIS->width, idx + offset + y * stride, THIS->width); 2305 memcpy (regions + y * THIS->width, idx + offset + y * stride, THIS->width);
2245 2306
2246 sfree (THIS->regions, THIS->size ()); 2307 sfree (THIS->regions, THIS->size ());
2247 free (THIS->regionmap); 2308 delete [] THIS->regionmap;
2248 2309
2249 THIS->regions = regions; 2310 THIS->regions = regions;
2250 THIS->regionmap = regionmap; 2311 THIS->regionmap = regionmap;
2251} 2312}
2252 2313
2272 } 2333 }
2273 } 2334 }
2274 2335
2275 op->destroy (); 2336 op->destroy ();
2276} 2337}
2277
2278void play_sound_map (maptile *map, int x, int y, int sound_num)
2279 2338
2280int out_of_map (maptile *map, int x, int y) 2339int out_of_map (maptile *map, int x, int y)
2281 2340
2282void 2341void
2283trigger (maptile *map, long connection, bool state = true) 2342trigger (maptile *map, long connection, bool state = true)
2555 char *buf = SvPVbyte (packet, len); 2614 char *buf = SvPVbyte (packet, len);
2556 2615
2557 THIS->send_packet (buf, len); 2616 THIS->send_packet (buf, len);
2558} 2617}
2559 2618
2619faceidx
2620client::need_face (utf8_string name, int pri = 0)
2621 CODE:
2622 RETVAL = face_find (name, 0);
2623 if (RETVAL)
2624 {
2625 THIS->send_face (RETVAL, pri);
2626 THIS->flush_fx ();
2627 }
2628 OUTPUT:
2629 RETVAL
2630
2631int
2632client::fx_want (int idx, int value = -1)
2633 CODE:
2634 if (0 < idx && idx < FT_NUM)
2635 {
2636 RETVAL = THIS->fx_want [idx];
2637 if (items > 2)
2638 THIS->fx_want [idx] = value;
2639 }
2640 else
2641 RETVAL = 0;
2642 OUTPUT:
2643 RETVAL
2644
2645MODULE = cf PACKAGE = cf::sound PREFIX = sound_
2646
2647faceidx sound_find (utf8_string name)
2648
2649void sound_set (utf8_string str, faceidx face)
2650
2651# dire hack
2652void old_sound_index (int idx, faceidx face)
2653 CODE:
2654 extern faceidx old_sound_index [SOUND_CAST_SPELL_0];
2655 old_sound_index [idx] = face;
2656
2560MODULE = cf PACKAGE = cf::face PREFIX = face_ 2657MODULE = cf PACKAGE = cf::face PREFIX = face_
2561 2658
2562#INCLUDE: $PERL $srcdir/genacc faceset ../include/face.h | 2659#INCLUDE: $PERL $srcdir/genacc faceset ../include/face.h |
2563 2660
2564faceidx face_find (utf8_string name, faceidx defidx = 0) 2661faceidx face_find (utf8_string name, faceidx defidx = 0)
2579 if (!strcmp (name, BLANK_FACE_NAME)) blank_face = RETVAL; 2676 if (!strcmp (name, BLANK_FACE_NAME)) blank_face = RETVAL;
2580 if (!strcmp (name, EMPTY_FACE_NAME)) empty_face = RETVAL; 2677 if (!strcmp (name, EMPTY_FACE_NAME)) empty_face = RETVAL;
2581} 2678}
2582 OUTPUT: RETVAL 2679 OUTPUT: RETVAL
2583 2680
2584void set (faceidx idx, int visibility, int magicmap) 2681void set_type (faceidx idx, int value)
2585 CODE: 2682 ALIAS:
2586 faceinfo *f = face_info (idx); 2683 set_type = 0
2587 assert (f); 2684 set_visibility = 1
2588 f->visibility = visibility; 2685 set_magicmap = 2
2589 f->magicmap = magicmap; 2686 set_smooth = 3
2590 2687 set_smoothlevel = 4
2591void set_smooth (faceidx idx, faceidx smooth, int smoothlevel)
2592 CODE: 2688 CODE:
2593 faceinfo *f = face_info (idx); assert (f); 2689 faceinfo *f = face_info (idx); assert (f);
2594 f->smooth = smooth; 2690 switch (ix)
2595 f->smoothlevel = smoothlevel; 2691 {
2692 case 0: f->type = value; break;
2693 case 1: f->visibility = value; break;
2694 case 2: f->magicmap = value; break;
2695 case 3: f->smooth = value; break;
2696 case 4: f->smoothlevel = value; break;
2697 }
2596 2698
2597void set_data (faceidx idx, int faceset, SV *data, SV *chksum) 2699void set_data (faceidx idx, int faceset, SV *data, SV *chksum)
2598 CODE: 2700 CODE:
2599{ 2701{
2600 facedata *d = face_data (idx, faceset); 2702 faceinfo *f = face_info (idx); assert (f);
2601 assert (d); 2703 facedata *d = &(faceset ? f->data64 : f->data32);
2602 sv_to (data, d->data); 2704 sv_to (data, d->data);
2603 STRLEN clen; 2705 STRLEN clen;
2604 char *cdata = SvPVbyte (chksum, clen); 2706 char *cdata = SvPVbyte (chksum, clen);
2605 clen = min (CHKSUM_SIZE, clen); 2707 clen = min (CHKSUM_SIZE, clen);
2606 2708
2616 ns->force_newmap = true; 2718 ns->force_newmap = true;
2617 } 2719 }
2618 } 2720 }
2619} 2721}
2620 2722
2723int get_data_size (faceidx idx, int faceset = 0)
2724 CODE:
2725 facedata *d = face_data (idx, faceset); assert (d);
2726 RETVAL = d->data.size ();
2727 OUTPUT:
2728 RETVAL
2729
2730SV *get_chksum (faceidx idx, int faceset = 0)
2731 CODE:
2732 facedata *d = face_data (idx, faceset); assert (d);
2733 RETVAL = newSVpvn ((char *)d->chksum, CHKSUM_SIZE);
2734 OUTPUT:
2735 RETVAL
2736
2621void invalidate (faceidx idx) 2737void invalidate (faceidx idx)
2622 CODE: 2738 CODE:
2623 for_all_clients (ns) 2739 for_all_clients (ns)
2624 { 2740 {
2625 ns->faces_sent [idx] = false; 2741 ns->faces_sent [idx] = false;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines