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.414 by root, Tue Oct 30 17:07:50 2012 UTC vs.
Revision 1.431 by root, Sat Dec 1 20:22:13 2018 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 (©) 2018 Marc Alexander Lehmann / the Deliantra team
4 * Copyright (©) 2006,2007,2008,2009,2010,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 5 * Copyright (©) 2006,2007,2008,2009,2010,2012,2015 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * 6 *
6 * Deliantra is free software: you can redistribute it and/or modify it under 7 * 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 8 * 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 9 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version. 10 * option) any later version.
20 * The authors can be reached via e-mail to <support@deliantra.net> 21 * The authors can be reached via e-mail to <support@deliantra.net>
21 */ 22 */
22 23
23#include "autoconf.h" 24#include "autoconf.h"
24 25
26#define CFPERL 1
27
25#if HAVE_EXECINFO_H 28#if HAVE_EXECINFO_H
26# include <execinfo.h> 29# include <execinfo.h>
27#endif 30#endif
28 31
29#include <cstdarg> 32#include <cstdarg>
92 95
93static SV 96static SV
94 *cv_cf_do_invoke, 97 *cv_cf_do_invoke,
95 *cv_cf__can_merge, 98 *cv_cf__can_merge,
96 *cv_cf_client_send_msg, 99 *cv_cf_client_send_msg,
100 *cv_cf_ix,
97 *cv_cf_tick, 101 *cv_cf_tick,
98 *cv_cf_match_match; 102 *cv_cf_match_match;
99 103
100#ifndef newSVpv_utf8 104#ifndef newSVpv_utf8
101static SV * 105static SV *
124 128
125 return sv; 129 return sv;
126} 130}
127#endif 131#endif
128 132
129noinline utf8_string 133ecb_noinline utf8_string
130cfSvPVutf8_nolen (SV *sv) 134cfSvPVutf8_nolen (SV *sv)
131{ 135{
132 SvGETMAGIC (sv); 136 SvGETMAGIC (sv);
133 137
134 if (SvPOK (sv)) 138 if (SvPOK (sv))
366 370
367 sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, 0, (char *)ptr, 0); 371 sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, 0, (char *)ptr, 0);
368 return sv_bless (newRV_noinc ((SV *)hv), stash); 372 return sv_bless (newRV_noinc ((SV *)hv), stash);
369} 373}
370 374
371static SV * noinline 375ecb_noinline static SV *
372newSVptr (void *ptr, HV *stash) 376newSVptr (void *ptr, HV *stash)
373{ 377{
374 return newSVptr (ptr, stash, newHV ()); 378 return newSVptr (ptr, stash, newHV ());
375} 379}
376 380
391 return 0; 395 return 0;
392} 396}
393 397
394MGVTBL attachable::vtbl = {0, 0, 0, 0, attachable_free}; 398MGVTBL attachable::vtbl = {0, 0, 0, 0, attachable_free};
395 399
396static SV * noinline 400ecb_noinline static SV *
397newSVattachable (attachable *obj, HV *stash) 401newSVattachable (attachable *obj, HV *stash)
398{ 402{
399 if (!obj) 403 if (!obj)
400 return newSV (0); 404 return newSV (0);
401 405
455 croak ("object of type %s expected", klass); 459 croak ("object of type %s expected", klass);
456 460
457 return SvPTR_nc (sv); 461 return SvPTR_nc (sv);
458} 462}
459 463
460static long noinline 464ecb_noinline static long
461SvPTR_ornull (SV *sv, const char *klass) 465SvPTR_ornull (SV *sv, const char *klass)
462{ 466{
463 if (expect_false (!SvOK (sv))) return 0; 467 if (expect_false (!SvOK (sv))) return 0;
464 468
465 return SvPTR (sv, klass); 469 return SvPTR (sv, klass);
466} 470}
467 471
468static long noinline 472ecb_noinline static long
469SvPTR_ornull_client (SV *sv) 473SvPTR_ornull_client (SV *sv)
470{ 474{
471 if (expect_false (!SvOK (sv))) return 0; 475 if (expect_false (!SvOK (sv))) return 0;
472 476
473 if (!SvROK (sv) 477 if (!SvROK (sv)
476 croak ("object of type cf::client expected"); 480 croak ("object of type cf::client expected");
477 481
478 return SvPTR_nc (sv); 482 return SvPTR_nc (sv);
479} 483}
480 484
481static long noinline 485ecb_noinline static long
482SvPTR_ornull_object (SV *sv) 486SvPTR_ornull_object (SV *sv)
483{ 487{
484 if (expect_false (!SvOK (sv))) return 0; 488 if (expect_false (!SvOK (sv))) return 0;
485 489
486 if (!SvROK (sv) 490 if (!SvROK (sv)
491 croak ("object of type cf::object expected"); 495 croak ("object of type cf::object expected");
492 496
493 return SvPTR_nc (sv); 497 return SvPTR_nc (sv);
494} 498}
495 499
496static long noinline 500ecb_noinline static long
497SvPTR_ornull_maptile (SV *sv) 501SvPTR_ornull_maptile (SV *sv)
498{ 502{
499 if (expect_false (!SvOK (sv))) return 0; 503 if (expect_false (!SvOK (sv))) return 0;
500 504
501 if (!SvROK (sv) 505 if (!SvROK (sv)
505 croak ("object of type cf::map expected"); 509 croak ("object of type cf::map expected");
506 510
507 return SvPTR_nc (sv); 511 return SvPTR_nc (sv);
508} 512}
509 513
510static long noinline 514ecb_noinline static long
511SvPTR_ornull_player (SV *sv) 515SvPTR_ornull_player (SV *sv)
512{ 516{
513 if (expect_false (!SvOK (sv))) return 0; 517 if (expect_false (!SvOK (sv))) return 0;
514 518
515 if (!SvROK (sv) 519 if (!SvROK (sv)
535static inline SV *to_sv (unsigned long long v) { return newSVval64 (v); } 539static inline SV *to_sv (unsigned long long v) { return newSVval64 (v); }
536static inline SV *to_sv (float v) { return newSVnv (v); } 540static inline SV *to_sv (float v) { return newSVnv (v); }
537static inline SV *to_sv (double v) { return newSVnv (v); } 541static inline SV *to_sv (double v) { return newSVnv (v); }
538static inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); } 542static inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); }
539static inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); } 543static inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); }
540// gcc dislikes noilnine on to_sv 544// gcc dislikes noinline on to_sv
541static noinline SV *to_sv_ni (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); } 545ecb_noinline static SV *to_sv_ni (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); }
542static inline SV *to_sv (object * v) { return to_sv_ni (v); } 546static inline SV *to_sv (object * v) { return to_sv_ni (v); }
543static inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); } 547static inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); }
544static inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); } 548static inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); }
545static inline SV *to_sv (region * v) { return newSVattachable (v, stash_cf_region_wrap); } 549static inline SV *to_sv (region * v) { return newSVattachable (v, stash_cf_region_wrap); }
546static inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); } 550static inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); }
725 return sv; 729 return sv;
726} 730}
727 731
728// typemap support, mostly to avoid excessive inlining 732// typemap support, mostly to avoid excessive inlining
729template<class type> 733template<class type>
730static void noinline 734ecb_noinline static void
731cf_obj_to (SV *arg, type &var) 735cf_obj_to (SV *arg, type &var)
732{ 736{
733 sv_to (arg, var); 737 sv_to (arg, var);
734 if (expect_false (!var)) 738 if (expect_false (!var))
735 croak ("must not pass invalid/null cf_obj here"); 739 croak ("must not pass invalid/null cf_obj here");
736} 740}
737 741
738template<class object> 742template<class object>
739static void noinline 743ecb_noinline static void
740cf_obj_ornull_to (SV *arg, object *&var) 744cf_obj_ornull_to (SV *arg, object *&var)
741{ 745{
742 if (SvOK (arg)) 746 if (SvOK (arg))
743 { 747 {
744 sv_to (arg, var); 748 sv_to (arg, var);
836# undef def 840# undef def
837}; 841};
838 842
839#define KLASS_OF(event) (((unsigned int)event) < NUM_EVENT_TYPES ? klass_of [event] : KLASS_NONE) 843#define KLASS_OF(event) (((unsigned int)event) < NUM_EVENT_TYPES ? klass_of [event] : KLASS_NONE)
840 844
841static void noinline 845ecb_noinline static void
842gather_callbacks (AV *&callbacks, AV *registry, event_type event) 846gather_callbacks (AV *&callbacks, AV *registry, event_type event)
843{ 847{
844 // event must be in array 848 // event must be in array
845 if (event >= 0 && event <= AvFILLp (registry)) 849 if (event >= 0 && event <= AvFILLp (registry))
846 { 850 {
932{ 936{
933 attachable::gather_callbacks (callbacks, event); 937 attachable::gather_callbacks (callbacks, event);
934 ::gather_callbacks (callbacks, cb_map, event); 938 ::gather_callbacks (callbacks, cb_map, event);
935} 939}
936 940
937static void noinline 941ecb_noinline static void
938_recalc_want (bitset<NUM_EVENT_TYPES> &set, AV *registry) 942_recalc_want (bitset<NUM_EVENT_TYPES> &set, AV *registry)
939{ 943{
940 for (int event = 0; event <= AvFILLp (registry); ++event) 944 for (int event = 0; event <= AvFILLp (registry); ++event)
941 { 945 {
942 SV *cbs_ = AvARRAY (registry)[event]; 946 SV *cbs_ = AvARRAY (registry)[event];
1157 CALL_ARG (originator); 1161 CALL_ARG (originator);
1158 CALL_CALL ("cf::mapscript::activate", G_VOID); 1162 CALL_CALL ("cf::mapscript::activate", G_VOID);
1159 CALL_END; 1163 CALL_END;
1160} 1164}
1161 1165
1166void cfperl_ix (client *ns, int set, faceidx idx, int pri)
1167{
1168 CALL_BEGIN (3);
1169 CALL_ARG (ns);
1170 CALL_ARG (set);
1171 CALL_ARG (idx);
1172 CALL_ARG (pri);
1173 CALL_CALL (cv_cf_ix, G_VOID);
1174 CALL_END;
1175}
1176
1162player * 1177player *
1163player::find (const_utf8_string name) 1178player::find (const_utf8_string name)
1164{ 1179{
1165 CALL_BEGIN (1); 1180 CALL_BEGIN (1);
1166 CALL_ARG (name); 1181 CALL_ARG (name);
1260 CALL_ARG (y); 1275 CALL_ARG (y);
1261 CALL_CALL ("cf::object::player::goto", G_VOID); 1276 CALL_CALL ("cf::object::player::goto", G_VOID);
1262 CALL_END; 1277 CALL_END;
1263} 1278}
1264 1279
1265const_utf8_string 1280const_utf8_string
1266object::ref () const 1281object::ref () const
1267{ 1282{
1268 if (type == PLAYER) 1283 if (type == PLAYER)
1269 return format ("player/<1.%llx>/%s", (unsigned long long)uuid.seq, &name); 1284 return format ("player/<1.%llx>/%s", (unsigned long long)uuid.seq, &name);
1270 else 1285 else
1436_connect_to_perl_2 () 1451_connect_to_perl_2 ()
1437{ 1452{
1438 cv_cf_do_invoke = (SV *)get_cv ("cf::do_invoke" , 0); assert (cv_cf_do_invoke); 1453 cv_cf_do_invoke = (SV *)get_cv ("cf::do_invoke" , 0); assert (cv_cf_do_invoke);
1439 cv_cf__can_merge = (SV *)get_cv ("cf::_can_merge" , 0); assert (cv_cf__can_merge); 1454 cv_cf__can_merge = (SV *)get_cv ("cf::_can_merge" , 0); assert (cv_cf__can_merge);
1440 cv_cf_client_send_msg = (SV *)get_cv ("cf::client::send_msg", 0); assert (cv_cf_client_send_msg); 1455 cv_cf_client_send_msg = (SV *)get_cv ("cf::client::send_msg", 0); assert (cv_cf_client_send_msg);
1456 cv_cf_ix = (SV *)get_cv ("cf::face::ix" , 0); assert (cv_cf_ix);
1441 cv_cf_tick = (SV *)get_cv ("cf::tick" , 0); assert (cv_cf_tick); 1457 cv_cf_tick = (SV *)get_cv ("cf::tick" , 0); assert (cv_cf_tick);
1442 cv_cf_match_match = (SV *)get_cv ("cf::match::match" , 0); assert (cv_cf_match_match); 1458 cv_cf_match_match = (SV *)get_cv ("cf::match::match" , 0); assert (cv_cf_match_match);
1443} 1459}
1444 1460
1445MODULE = cf PACKAGE = cf PREFIX = cf_ 1461MODULE = cf PACKAGE = cf PREFIX = cf_
1450 I_CORO_API (PACKAGE); coroapi::GCoroAPI = GCoroAPI; 1466 I_CORO_API (PACKAGE); coroapi::GCoroAPI = GCoroAPI;
1451 1467
1452 _connect_to_perl_1 (); 1468 _connect_to_perl_1 ();
1453 1469
1454 newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1)); 1470 newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1));
1455
1456 //{
1457 // require_pv ("Time::HiRes");
1458 //
1459 // SV **svp = hv_fetch (PL_modglobal, "Time::NVtime", 12, 0);
1460 // if (!svp) croak ("Time::HiRes is required");
1461 // if (!SvIOK(*svp)) croak ("Time::NVtime isn’t a function pointer");
1462 // coroapi::time = INT2PTR (double(*)(), SvIV(*svp));
1463 //}
1464 1471
1465 static const struct { 1472 static const struct {
1466 const char *name; 1473 const char *name;
1467 IV iv; 1474 IV iv;
1468 } *civ, const_iv[] = { 1475 } *civ, const_iv[] = {
1506 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT) 1513 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT)
1507 1514
1508 const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES) 1515 const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES)
1509 }; 1516 };
1510 1517
1511 for (civ = const_iv + array_length (const_iv); civ-- > const_iv; ) 1518 for (civ = const_iv + ecb_array_length (const_iv); civ-- > const_iv; )
1512 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv)); 1519 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv));
1513 1520
1514 static const struct { 1521 static const struct {
1515 const char *name; 1522 const char *name;
1516 int skip; 1523 int skip;
1522# undef def 1529# undef def
1523 }; 1530 };
1524 1531
1525 AV *av = get_av ("cf::EVENT", 1); 1532 AV *av = get_av ("cf::EVENT", 1);
1526 1533
1527 for (eiv = event_iv + array_length (event_iv); eiv-- > event_iv; ) 1534 for (eiv = event_iv + ecb_array_length (event_iv); eiv-- > event_iv; )
1528 { 1535 {
1529 AV *event = newAV (); 1536 AV *event = newAV ();
1530 av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0)); 1537 av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0));
1531 av_push (event, newSViv (eiv->klass)); 1538 av_push (event, newSViv (eiv->klass));
1532 av_store (av, eiv->iv, newRV_noinc ((SV *)event)); 1539 av_store (av, eiv->iv, newRV_noinc ((SV *)event));
1579 1586
1580void init_dynamic () 1587void init_dynamic ()
1581 1588
1582void load_settings () 1589void load_settings ()
1583 1590
1584void reload_exp_table () 1591void _reload_exp_table ()
1585 1592
1586void reload_materials () 1593void _reload_materials ()
1587 1594
1588void init_uuid () 1595void init_uuid ()
1589 CODE: 1596 CODE:
1590 UUID::init (); 1597 UUID::init ();
1591 1598
1602 coroapi::cede_to_tick (); 1609 coroapi::cede_to_tick ();
1603 1610
1604NV till_tick () 1611NV till_tick ()
1605 CODE: 1612 CODE:
1606 RETVAL = SvNVX (sv_next_tick) - now (); 1613 RETVAL = SvNVX (sv_next_tick) - now ();
1607 OUTPUT: 1614 OUTPUT: RETVAL
1608 RETVAL
1609 1615
1610int tick_inhibit () 1616int tick_inhibit ()
1611 CODE: 1617 CODE:
1612 RETVAL = tick_inhibit; 1618 RETVAL = tick_inhibit;
1613 OUTPUT: 1619 OUTPUT: RETVAL
1614 RETVAL
1615 1620
1616void tick_inhibit_inc () 1621void tick_inhibit_inc ()
1617 CODE: 1622 CODE:
1618 ++tick_inhibit; 1623 ++tick_inhibit;
1619 1624
1655NV rndm (...) 1660NV rndm (...)
1656 ALIAS: 1661 ALIAS:
1657 rmg_rndm = 1 1662 rmg_rndm = 1
1658 CODE: 1663 CODE:
1659{ 1664{
1660 rand_gen &gen = ix ? rmg_rndm : rndm; 1665 rand_gen &gen = ix ? rmg_rndm : rndm;
1661 switch (items) 1666 switch (items)
1662 { 1667 {
1663 case 0: RETVAL = gen (); break; 1668 case 0: RETVAL = gen (); break;
1664 case 1: RETVAL = gen (SvUV (ST (0))); break; 1669 case 1: RETVAL = gen (SvUV (ST (0))); break;
1665 case 2: RETVAL = gen (SvIV (ST (0)), SvIV (ST (1))); break; 1670 case 2: RETVAL = gen (SvIV (ST (0)), SvIV (ST (1))); break;
1666 default: croak ("cf::rndm requires zero, one or two parameters."); break; 1671 default: croak ("cf::rndm requires zero, one or two parameters."); break;
1667 } 1672 }
1668} 1673}
1669 OUTPUT: 1674 OUTPUT: RETVAL
1670 RETVAL
1671 1675
1672NV clamp (NV value, NV min_value, NV max_value) 1676NV clamp (NV value, NV min_value, NV max_value)
1673 CODE: 1677 CODE:
1674 RETVAL = clamp (value, min_value, max_value); 1678 RETVAL = clamp (value, min_value, max_value);
1675 OUTPUT: 1679 OUTPUT: RETVAL
1676 RETVAL
1677 1680
1678NV lerp (NV value, NV min_in, NV max_in, NV min_out, NV max_out) 1681NV lerp (NV value, NV min_in, NV max_in, NV min_out, NV max_out)
1679 CODE: 1682 CODE:
1680 RETVAL = lerp (value, min_in, max_in, min_out, max_out); 1683 RETVAL = lerp (value, min_in, max_in, min_out, max_out);
1681 OUTPUT: 1684 OUTPUT: RETVAL
1682 RETVAL
1683 1685
1684const char *ordinal (int i) 1686const char *ordinal (int i)
1685 1687
1686void weaken (...) 1688void weaken (...)
1687 PROTOTYPE: @ 1689 PROTOTYPE: @
1786 EXTEND (SP, 5*2); 1788 EXTEND (SP, 5*2);
1787 PUSHs (sv_2mortal (newSVpv ("slice_alloc", 0))); PUSHs (sv_2mortal (newSVuv (slice_alloc))); 1789 PUSHs (sv_2mortal (newSVpv ("slice_alloc", 0))); PUSHs (sv_2mortal (newSVuv (slice_alloc)));
1788 PUSHs (sv_2mortal (newSVpv ("shstr_alloc", 0))); PUSHs (sv_2mortal (newSVuv (shstr_alloc))); 1790 PUSHs (sv_2mortal (newSVpv ("shstr_alloc", 0))); PUSHs (sv_2mortal (newSVuv (shstr_alloc)));
1789 PUSHs (sv_2mortal (newSVpv ("objects" , 0))); PUSHs (sv_2mortal (newSVuv (objects.size () * sizeof (object)))); 1791 PUSHs (sv_2mortal (newSVpv ("objects" , 0))); PUSHs (sv_2mortal (newSVuv (objects.size () * sizeof (object))));
1790 PUSHs (sv_2mortal (newSVpv ("sv_count" , 0))); PUSHs (sv_2mortal (newSVuv (PL_sv_count))); 1792 PUSHs (sv_2mortal (newSVpv ("sv_count" , 0))); PUSHs (sv_2mortal (newSVuv (PL_sv_count)));
1791 PUSHs (sv_2mortal (newSVpv ("sv_objcount", 0))); PUSHs (sv_2mortal (newSVuv (PL_sv_objcount)));
1792} 1793}
1793
1794int find_animation (utf8_string text)
1795 PROTOTYPE: $
1796 1794
1797int random_roll (int min, int max, object *op, int goodbad); 1795int random_roll (int min, int max, object *op, int goodbad);
1798 1796
1799const_utf8_string cost_string_from_value(uint64 cost, int approx = 0) 1797const_utf8_string cost_string_from_value(uint64 cost, int approx = 0)
1800 1798
1801int exp_to_level (val64 exp) 1799int exp_to_level (val64 exp)
1802 1800
1803val64 level_to_min_exp (int level) 1801val64 level_to_min_exp (int level)
1802
1803const_utf8_string
1804spellpathnames (int idx)
1805 CODE:
1806 RETVAL = spellpathnames [idx];
1807 OUTPUT: RETVAL
1804 1808
1805SV * 1809SV *
1806attacktype_name (int atnr) 1810attacktype_name (int atnr)
1807 CODE: 1811 CODE:
1808 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS) 1812 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1832 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS) 1836 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1833 ? newSVpv (change_resist_msg [atnr], 0) 1837 ? newSVpv (change_resist_msg [atnr], 0)
1834 : &PL_sv_undef; 1838 : &PL_sv_undef;
1835 OUTPUT: RETVAL 1839 OUTPUT: RETVAL
1836 1840
1841int
1842skill_flags (int idx)
1843 CODE:
1844 if (idx < 0 || idx >= ecb_array_length (skill_flags))
1845 croak ("skill_flags: index out of bounds");
1846 RETVAL = skill_flags [idx];
1847 OUTPUT: RETVAL
1848
1837UUID 1849UUID
1838uuid_cur () 1850uuid_cur ()
1839 CODE: 1851 CODE:
1840 RETVAL = UUID::cur; 1852 RETVAL = UUID::cur;
1841 OUTPUT: 1853 OUTPUT: RETVAL
1842 RETVAL
1843 1854
1844UUID 1855UUID
1845uuid_gen () 1856uuid_gen ()
1846 CODE: 1857 CODE:
1847 RETVAL = UUID::gen (); 1858 RETVAL = UUID::gen ();
1848 OUTPUT: 1859 OUTPUT: RETVAL
1849 RETVAL
1850 1860
1851val64 1861val64
1852uuid_seq (UUID uuid) 1862uuid_seq (UUID uuid)
1853 CODE: 1863 CODE:
1854 RETVAL = uuid.seq; 1864 RETVAL = uuid.seq;
1855 OUTPUT: 1865 OUTPUT: RETVAL
1856 RETVAL
1857 1866
1858UUID 1867UUID
1859uuid_str (val64 seq) 1868uuid_str (val64 seq)
1860 CODE: 1869 CODE:
1861 RETVAL.seq = seq; 1870 RETVAL.seq = seq;
1862 OUTPUT: 1871 OUTPUT: RETVAL
1863 RETVAL
1864 1872
1865void 1873void
1866coin_names () 1874coin_names ()
1867 PPCODE: 1875 PPCODE:
1868 EXTEND (SP, NUM_COINS); 1876 EXTEND (SP, NUM_COINS);
1880load_resource_file_ (octet_string filename) 1888load_resource_file_ (octet_string filename)
1881 1889
1882void 1890void
1883fix_weight () 1891fix_weight ()
1884 1892
1893utf8_string
1894expand_cfpod (int hintmode, int gender, const_utf8_string cfpod)
1895 PPCODE:
1896 XPUSHs (to_sv (player::expand_cfpod (hintmode, gender, cfpod)));
1897
1885MODULE = cf PACKAGE = cf::attachable 1898MODULE = cf PACKAGE = cf::attachable
1886 1899
1887int 1900int
1888valid (SV *obj) 1901valid (SV *obj)
1889 CODE: 1902 CODE:
1890 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); 1903 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext);
1891 OUTPUT: 1904 OUTPUT: RETVAL
1892 RETVAL
1893 1905
1894bool should_invoke (attachable *obj, int event) 1906bool should_invoke (attachable *obj, int event)
1895 CODE: 1907 CODE:
1896 RETVAL = obj->should_invoke ((event_type)event); 1908 RETVAL = obj->should_invoke ((event_type)event);
1897 OUTPUT: RETVAL 1909 OUTPUT: RETVAL
1979 case 0: RETVAL = body_locations[slot].name ; break; 1991 case 0: RETVAL = body_locations[slot].name ; break;
1980 case 1: RETVAL = body_locations[slot].use_name ; break; 1992 case 1: RETVAL = body_locations[slot].use_name ; break;
1981 case 2: RETVAL = body_locations[slot].nonuse_name; break; 1993 case 2: RETVAL = body_locations[slot].nonuse_name; break;
1982 } 1994 }
1983} 1995}
1984 OUTPUT: 1996 OUTPUT: RETVAL
1985 RETVAL
1986 1997
1987# missing properties 1998# missing properties
1988 1999
1989object *head (object *op) 2000object *head (object *op)
1990 PROTOTYPE: $ 2001 PROTOTYPE: $
1998 PPCODE: 2009 PPCODE:
1999{ 2010{
2000 for (object *o = obj->inv; o; o = o->below) 2011 for (object *o = obj->inv; o; o = o->below)
2001 XPUSHs (sv_2mortal (to_sv (o))); 2012 XPUSHs (sv_2mortal (to_sv (o)));
2002} 2013}
2003
2004void
2005set_animation (object *op, int idx)
2006 CODE:
2007 SET_ANIMATION (op, idx);
2008
2009int
2010num_animations (object *op)
2011 CODE:
2012 RETVAL = NUM_ANIMATIONS (op);
2013 OUTPUT: RETVAL
2014 2014
2015int slot_info (object *op, UV slot, int value = 0) 2015int slot_info (object *op, UV slot, int value = 0)
2016 ALIAS: 2016 ALIAS:
2017 slot_used = 1 2017 slot_used = 1
2018 CODE: 2018 CODE:
2026 if (ix) 2026 if (ix)
2027 op->slot[slot].used = value; 2027 op->slot[slot].used = value;
2028 else 2028 else
2029 op->slot[slot].info = value; 2029 op->slot[slot].info = value;
2030} 2030}
2031 OUTPUT: 2031 OUTPUT: RETVAL
2032 RETVAL
2033 2032
2034object *find_best_object_match (object *op, utf8_string match) 2033object *find_best_object_match (object *op, utf8_string match)
2035 2034
2036int apply_shop_mat (object *shop_mat, object *op); 2035int apply_shop_mat (object *shop_mat, object *op);
2037 2036
2038int move (object *op, int dir, object *originator = op) 2037int move (object *op, int dir, object *originator = op)
2039 CODE: 2038 CODE:
2040 RETVAL = op->move (dir, originator); 2039 RETVAL = op->move (dir, originator);
2041 OUTPUT: 2040 OUTPUT: RETVAL
2042 RETVAL
2043 2041
2044void apply_below (object *op) 2042void apply_below (object *op)
2045 CODE: 2043 CODE:
2046 player_apply_below (op); 2044 player_apply_below (op);
2047 2045
2111int convert_item (object *item, object *converter) 2109int convert_item (object *item, object *converter)
2112 2110
2113void fix_generated_item (object *op, object *creator, int difficulty, int max_magic, int flags); 2111void fix_generated_item (object *op, object *creator, int difficulty, int max_magic, int flags);
2114 2112
2115MODULE = cf PACKAGE = cf::object PREFIX = cf_ 2113MODULE = cf PACKAGE = cf::object PREFIX = cf_
2116
2117# no clean way to get an object from an archetype - stupid idiotic
2118# dumb kludgy misdesigned plug-in api slowly gets on my nerves.
2119 2114
2120object *new (utf8_string archetype = 0) 2115object *new (utf8_string archetype = 0)
2121 PROTOTYPE: ;$ 2116 PROTOTYPE: ;$
2122 CODE: 2117 CODE:
2123 RETVAL = archetype 2118 RETVAL = archetype
2124 ? archetype::get (archetype) 2119 ? archetype::get (archetype)
2125 : object::create (); 2120 : object::create ();
2126 OUTPUT: 2121 OUTPUT: RETVAL
2127 RETVAL
2128 2122
2129object *generate (utf8_string arch, object *creator) 2123object *generate (utf8_string arch, object *creator)
2130 CODE: 2124 CODE:
2131 object *obj = archetype::get (arch); 2125 object *obj = archetype::get (arch);
2132 fix_generated_item (obj, creator, 0, 0, GT_MINIMAL); 2126 fix_generated_item (obj, creator, 0, 0, GT_MINIMAL);
2133 RETVAL = obj; 2127 RETVAL = obj;
2134 OUTPUT: 2128 OUTPUT: RETVAL
2135 RETVAL
2136 2129
2137object *find_object (U32 tag) 2130object *find_object (U32 tag)
2138 2131
2139object *find_object_uuid (UUID i) 2132object *find_object_uuid (UUID i)
2140 2133
2146 RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y); 2139 RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y);
2147 2140
2148 if (RETVAL->destroyed ()) 2141 if (RETVAL->destroyed ())
2149 RETVAL = 0; 2142 RETVAL = 0;
2150} 2143}
2151 OUTPUT: 2144 OUTPUT: RETVAL
2152 RETVAL
2153 2145
2154shstr 2146shstr
2155object::kv_get (shstr key) 2147object::kv_get (shstr key)
2156 CODE: 2148 CODE:
2157 RETVAL = THIS->kv.get (key); 2149 RETVAL = THIS->kv.get (key);
2158 OUTPUT: 2150 OUTPUT: RETVAL
2159 RETVAL
2160 2151
2161void 2152void
2162object::kv_del (shstr key) 2153object::kv_del (shstr key)
2163 CODE: 2154 CODE:
2164 THIS->kv.del (key); 2155 THIS->kv.del (key);
2263#d# TODO: replace by blocked_los accessor, fix code using this 2254#d# TODO: replace by blocked_los accessor, fix code using this
2264bool 2255bool
2265cell_visible (player *pl, int dx, int dy) 2256cell_visible (player *pl, int dx, int dy)
2266 CODE: 2257 CODE:
2267 RETVAL = pl->blocked_los (dx, dy) != LOS_BLOCKED; 2258 RETVAL = pl->blocked_los (dx, dy) != LOS_BLOCKED;
2268 OUTPUT: 2259 OUTPUT: RETVAL
2269 RETVAL
2270 2260
2271void 2261void
2272send (player *pl, SV *packet) 2262send (player *pl, SV *packet)
2273 CODE: 2263 CODE:
2274{ 2264{
2350outdoor_darkness (int darkness = 0) 2340outdoor_darkness (int darkness = 0)
2351 CODE: 2341 CODE:
2352 RETVAL = maptile::outdoor_darkness; 2342 RETVAL = maptile::outdoor_darkness;
2353 if (items) 2343 if (items)
2354 maptile::outdoor_darkness = darkness; 2344 maptile::outdoor_darkness = darkness;
2355 OUTPUT: 2345 OUTPUT: RETVAL
2356 RETVAL
2357 2346
2358void 2347void
2359maptile::instantiate () 2348maptile::instantiate ()
2360 2349
2361maptile *new () 2350maptile *new ()
2362 PROTOTYPE: 2351 PROTOTYPE:
2363 CODE: 2352 CODE:
2364 RETVAL = new maptile; 2353 RETVAL = new maptile;
2365 OUTPUT: 2354 OUTPUT: RETVAL
2366 RETVAL
2367 2355
2368void 2356void
2369maptile::players () 2357maptile::players ()
2370 PPCODE: 2358 PPCODE:
2371 if (GIMME_V == G_SCALAR) 2359 if (GIMME_V == G_SCALAR)
2391 croak ("maptile::add_underlay: palette must be arrayref"); 2379 croak ("maptile::add_underlay: palette must be arrayref");
2392 2380
2393 palette = SvRV (palette); 2381 palette = SvRV (palette);
2394 2382
2395 STRLEN idxlen; 2383 STRLEN idxlen;
2396 const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen); 2384 const uint8 *idx = (const uint8 *)SvPVbyte (data, idxlen);
2397 2385
2398 for (int x = 0; x < THIS->width; ++x) 2386 for (int x = 0; x < THIS->width; ++x)
2399 for (int y = 0; y < THIS->height; ++y) 2387 for (int y = 0; y < THIS->height; ++y)
2400 { 2388 {
2401 for (object *op = THIS->at (x, y).bot; op; op = op->above) 2389 for (object *op = THIS->at (x, y).bot; op; op = op->above)
2441 croak ("maptile::set_regiondata: palette must be arrayref"); 2429 croak ("maptile::set_regiondata: palette must be arrayref");
2442 2430
2443 palette = SvRV (palette); 2431 palette = SvRV (palette);
2444 2432
2445 STRLEN idxlen; 2433 STRLEN idxlen;
2446 const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen); 2434 const uint8 *idx = (const uint8 *)SvPVbyte (data, idxlen);
2447 2435
2448 region_ptr *regionmap = new region_ptr [av_len ((AV *)palette) + 1]; 2436 region_ptr *regionmap = new region_ptr [av_len ((AV *)palette) + 1];
2449 uint8_t *regions = salloc<uint8_t> (THIS->size ()); 2437 uint8 *regions = salloc<uint8_t> (THIS->size ());
2450 2438
2451 for (int i = av_len ((AV *)palette) + 1; i--; ) 2439 for (int i = av_len ((AV *)palette) + 1; i--; )
2452 regionmap [i] = region::find (cfSvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1))); 2440 regionmap [i] = region::find (cfSvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1)));
2453 2441
2454 for (int y = 0; y < THIS->height; ++y) 2442 for (int y = 0; y < THIS->height; ++y)
2506 if (!pos.move (dir).normalise ()) 2494 if (!pos.move (dir).normalise ())
2507 XSRETURN_UNDEF; 2495 XSRETURN_UNDEF;
2508 2496
2509 RETVAL = &*pos; 2497 RETVAL = &*pos;
2510} 2498}
2511 OUTPUT: 2499 OUTPUT: RETVAL
2512 RETVAL
2513 2500
2514void 2501void
2515at (maptile *map, unsigned int x, unsigned int y, int dir = 0) 2502at (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2516 PROTOTYPE: $$$;$ 2503 PROTOTYPE: $$$;$
2517 PPCODE: 2504 PPCODE:
2558# worst xs function of my life 2545# worst xs function of my life
2559bool 2546bool
2560_create_random_map (maptile *self, SV *options) 2547_create_random_map (maptile *self, SV *options)
2561 CODE: 2548 CODE:
2562{ 2549{
2563 random_map_params rmp ((HV *)SvRV (options)); 2550 random_map_params rmp ((HV *)SvRV (options));
2564 RETVAL = self->generate_random_map (&rmp); 2551 RETVAL = self->generate_random_map (&rmp);
2565} 2552}
2566 OUTPUT: 2553 OUTPUT: RETVAL
2567 RETVAL
2568 2554
2569MODULE = cf PACKAGE = cf::mapspace 2555MODULE = cf PACKAGE = cf::mapspace
2570 2556
2571INCLUDE: $PERL $srcdir/genacc mapspace $srcdir/../include/map.h | 2557INCLUDE: $PERL $srcdir/genacc mapspace $srcdir/../include/map.h |
2572 2558
2579 2565
2580archetype *archetypes (U32 index) 2566archetype *archetypes (U32 index)
2581 CODE: 2567 CODE:
2582 RETVAL = index < archetypes.size () ? archetypes [index] : 0; 2568 RETVAL = index < archetypes.size () ? archetypes [index] : 0;
2583 OUTPUT: RETVAL 2569 OUTPUT: RETVAL
2570
2571int skillvec_size ()
2572 CODE:
2573 RETVAL = skillvec.size ();
2574 OUTPUT: RETVAL
2575
2576archetype *skillvec (U32 index)
2577 CODE:
2578 RETVAL = index < skillvec.size () ? (archetype *)(object *)skillvec [index] : 0;
2579 OUTPUT: RETVAL
2580
2581void
2582find_by_type (int type)
2583 PPCODE:
2584 for_all_archetypes (arch)
2585 if (arch->type == type)
2586 XPUSHs (sv_2mortal (to_sv (arch)));
2584 2587
2585INCLUDE: $PERL $srcdir/genacc archetype $srcdir/../include/object.h | 2588INCLUDE: $PERL $srcdir/genacc archetype $srcdir/../include/object.h |
2586 2589
2587MODULE = cf PACKAGE = cf::party 2590MODULE = cf PACKAGE = cf::party
2588 2591
2681 if (RETVAL) 2684 if (RETVAL)
2682 { 2685 {
2683 THIS->send_face (RETVAL, pri); 2686 THIS->send_face (RETVAL, pri);
2684 THIS->flush_fx (); 2687 THIS->flush_fx ();
2685 } 2688 }
2686 OUTPUT: 2689 OUTPUT: RETVAL
2687 RETVAL
2688 2690
2689int 2691int
2690client::fx_want (int idx, int value = -1) 2692client::fx_want (int idx, int value = -1)
2691 CODE: 2693 CODE:
2692 if (0 < idx && idx < FT_NUM) 2694 if (0 < idx && idx < FT_NUM)
2695 if (items > 2) 2697 if (items > 2)
2696 THIS->fx_want [idx] = value; 2698 THIS->fx_want [idx] = value;
2697 } 2699 }
2698 else 2700 else
2699 RETVAL = 0; 2701 RETVAL = 0;
2700 OUTPUT: 2702 OUTPUT: RETVAL
2701 RETVAL
2702 2703
2703MODULE = cf PACKAGE = cf::sound PREFIX = sound_ 2704MODULE = cf PACKAGE = cf::sound PREFIX = sound_
2704 2705
2705faceidx sound_find (utf8_string name) 2706faceidx sound_find (utf8_string name)
2706 2707
2753 case 2: f->magicmap = value; break; 2754 case 2: f->magicmap = value; break;
2754 case 3: f->smooth = value; break; 2755 case 3: f->smooth = value; break;
2755 case 4: f->smoothlevel = value; break; 2756 case 4: f->smoothlevel = value; break;
2756 } 2757 }
2757 2758
2758void set_data (faceidx idx, int faceset, SV *data, SV *chksum) 2759void set_csum (faceidx idx, int faceset, SV *chksum)
2759 CODE: 2760 CODE:
2760{ 2761{
2761 faceinfo *f = face_info (idx); assert (f); 2762 faceinfo *f = face_info (idx); assert (f);
2762 facedata *d = f->face + faceset; 2763 facedata *d = f->face + faceset;
2763 sv_to (data, d->data);
2764 STRLEN clen; 2764 STRLEN clen;
2765 char *cdata = SvPVbyte (chksum, clen); 2765 char *cdata = SvPVbyte (chksum, clen);
2766 clen = min (CHKSUM_MAXLEN, clen);
2767 2766
2767 assert (("cf::face::set_data called with too long checksum", clen <= CHKSUM_MAXLEN));
2768 assert (("cf::face::set_data must be called with a non-empty checksum", clen)); 2768 assert (("cf::face::set_data must be called with a non-empty checksum", clen));
2769 2769
2770 if (clen != d->chksum_len || memcmp (d->chksum, cdata, clen)) 2770 if (clen != d->chksum_len || memcmp (d->chksum, cdata, clen))
2771 { 2771 {
2772 d->chksum_len = clen; 2772 d->chksum_len = clen;
2773 memcpy (d->chksum, cdata, clen); 2773 memcpy (d->chksum, cdata, clen);
2774 2774
2775 // invalidate existing client face info 2775 // invalidate existing client face info
2776 for_all_clients (ns) 2776 for_all_clients (ns)
2777 if (ns->faceset == faceset) 2777 ns->invalidate_face (idx);
2778 {
2779 ns->faces_sent [idx] = false;
2780 ns->force_newmap = true;
2781 }
2782 } 2778 }
2783} 2779}
2784 2780
2785int get_data_size (faceidx idx, int faceset = 0) 2781SV *mangle_csum (SV *chksum)
2786 CODE: 2782 CODE:
2787 facedata *d = face_data (idx, faceset); 2783 STRLEN len;
2788 if (!d) XSRETURN_UNDEF; 2784 char *data = SvPVbyte (chksum, len);
2789 RETVAL = d->data.size (); 2785 RETVAL = newSVpvn (data, min (len, CHKSUM_MAXLEN));
2790 OUTPUT: 2786 OUTPUT: RETVAL
2791 RETVAL
2792 2787
2793void set_meta (faceidx idx, SV *sv)
2794 CODE:
2795{
2796 faceinfo *f = face_info (idx); assert (f);
2797 SvREFCNT_dec (f->meta_hv);
2798 f->meta_hv = SvOK (sv) ? (HV *)SvREFCNT_inc (SvRV (sv)) : 0;
2799}
2800
2801SV *get_chksum (faceidx idx, int faceset = 0) 2788SV *get_csum (faceidx idx, int faceset = 0)
2802 CODE: 2789 CODE:
2803 facedata *d = face_data (idx, faceset); 2790 facedata *d = face_data (idx, faceset);
2804 if (!d) XSRETURN_UNDEF; 2791 if (!d) XSRETURN_UNDEF;
2805 RETVAL = newSVpvn ((char *)d->chksum, d->chksum_len); 2792 RETVAL = newSVpvn ((char *)d->chksum, d->chksum_len);
2806 OUTPUT: 2793 OUTPUT: RETVAL
2807 RETVAL
2808 2794
2809int get_type (faceidx idx) 2795int get_type (faceidx idx)
2810 CODE: 2796 CODE:
2811 faceinfo *f = face_info (idx); 2797 faceinfo *f = face_info (idx);
2812 if (!f) XSRETURN_UNDEF; 2798 if (!f) XSRETURN_UNDEF;
2813 RETVAL = f->type; 2799 RETVAL = f->type;
2814 OUTPUT: 2800 OUTPUT: RETVAL
2815 RETVAL
2816 2801
2817SV *get_data (faceidx idx, int faceset = 0) 2802SV *get_name (faceidx idx)
2818 CODE: 2803 CODE:
2819 facedata *d = face_data (idx, faceset); 2804 faceinfo *f = face_info (idx);
2820 if (!d) XSRETURN_UNDEF; 2805 if (!f) XSRETURN_UNDEF;
2821 RETVAL = newSVpvn (d->data, d->data.size ()); 2806 RETVAL = to_sv (f->name);
2822 OUTPUT: 2807 OUTPUT: RETVAL
2823 RETVAL
2824
2825SV *get_meta (faceidx idx)
2826 CODE:
2827 faceinfo *f = face_info (idx); assert (f);
2828 if (!f || !f->meta_hv) XSRETURN_UNDEF;
2829 RETVAL = newRV_inc ((SV *)f->meta_hv);
2830 OUTPUT:
2831 RETVAL
2832 2808
2833void invalidate (faceidx idx) 2809void invalidate (faceidx idx)
2834 CODE: 2810 CODE:
2835 for_all_clients (ns) 2811 for_all_clients (ns)
2836 ns->invalidate_face (idx); 2812 ns->invalidate_face (idx);
2900bool 2876bool
2901errors_are_fatal (bool fatal) 2877errors_are_fatal (bool fatal)
2902 CODE: 2878 CODE:
2903 RETVAL = object_thawer::errors_are_fatal; 2879 RETVAL = object_thawer::errors_are_fatal;
2904 object_thawer::errors_are_fatal = fatal; 2880 object_thawer::errors_are_fatal = fatal;
2905 OUTPUT: 2881 OUTPUT: RETVAL
2906 RETVAL
2907 2882
2908SV * 2883SV *
2909new_from_file (char *klass, octet_string path) 2884new_from_file (char *klass, octet_string path)
2910 CODE: 2885 CODE:
2911 object_thawer *f = new object_thawer (path); 2886 object_thawer *f = new object_thawer (path);
2937 XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ()))); 2912 XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ())));
2938 2913
2939 self->skip (); 2914 self->skip ();
2940 } 2915 }
2941 2916
2917MODULE = cf PACKAGE = cf::treasurelist
2918
2919# quick hack, because I didn't want to implement accessors for treasurelist.
2920# this asks for even more autogen, actually.
2921
2922void
2923expand (treasurelist *list)
2924 PPCODE:
2925 EXTEND (SP, 3);
2926 PUSHs (sv_2mortal (to_sv (list->name)));
2927 PUSHs (sv_2mortal (to_sv (list->total_chance)));
2928 AV *av = newAV ();
2929 PUSHs (sv_2mortal (newRV_noinc ((SV *)av)));
2930 for (treasure *item = list->items; item; item = item->next)
2931 {
2932 AV *iav = newAV ();
2933 av_push (av, newRV_noinc ((SV *)iav));
2934
2935 av_extend (iav, 7);
2936 av_push (iav, to_sv (item->item));
2937 av_push (iav, to_sv (item->name));
2938 av_push (iav, to_sv (item->change_arch.name));
2939 av_push (iav, to_sv (item->change_arch.title));
2940 av_push (iav, to_sv (item->change_arch.slaying));
2941 av_push (iav, to_sv (item->chance));
2942 av_push (iav, to_sv (item->nrof));
2943 av_push (iav, to_sv (item->magic));
2944 }
2945
2942MODULE = cf PACKAGE = cf::layout 2946MODULE = cf PACKAGE = cf::layout
2943 2947
2944INCLUDE: $PERL $srcdir/genacc layout $srcdir/../include/rmg.h | 2948INCLUDE: $PERL $srcdir/genacc layout $srcdir/../include/rmg.h |
2945 2949

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines