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.374 by root, Thu Apr 15 06:05:52 2010 UTC vs.
Revision 1.425 by root, Wed Nov 14 06:21:39 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
28 28
29#include <cstdarg> 29#include <cstdarg>
30#include <typeinfo> 30#include <typeinfo>
31 31
32#include "global.h" 32#include "global.h"
33#include "../random_maps/random_map.h" 33#include "rmg.h"
34#include "noise.h"
34#include "evthread.h" 35#include "evthread.h"
35#include "sproto.h" 36#include "sproto.h"
36 37
37#include <unistd.h> 38#include <unistd.h>
38#if _POSIX_MEMLOCK 39#if _POSIX_MEMLOCK
66static int tick_inhibit; 67static int tick_inhibit;
67static int tick_pending; 68static int tick_pending;
68 69
69global gbl_ev; 70global gbl_ev;
70static 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;
71static 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;
72static AV *av_reflect; 73static AV *av_reflect;
73 74
74bitset<NUM_EVENT_TYPES> ev_want_event; 75bitset<NUM_EVENT_TYPES> ev_want_event;
75bitset<NUM_TYPES> ev_want_type; 76bitset<NUM_TYPES> ev_want_type;
76 77
83 *stash_cf_mapspace_wrap, 84 *stash_cf_mapspace_wrap,
84 *stash_cf_client_wrap, 85 *stash_cf_client_wrap,
85 *stash_cf_arch_wrap, 86 *stash_cf_arch_wrap,
86 *stash_cf_party_wrap, 87 *stash_cf_party_wrap,
87 *stash_cf_region_wrap, 88 *stash_cf_region_wrap,
88 *stash_cf_living_wrap; 89 *stash_cf_living_wrap,
90 *stash_cf_layout_wrap,
91 *stash_ext_map_world;
89 92
90static SV 93static SV
91 *cv_cf_do_invoke, 94 *cv_cf_do_invoke,
92 *cv_cf__can_merge, 95 *cv_cf__can_merge,
93 *cv_cf_client_send_msg, 96 *cv_cf_client_send_msg,
97 *cv_cf_ix,
94 *cv_cf_tick, 98 *cv_cf_tick,
95 *cv_cf_match_match; 99 *cv_cf_match_match;
96 100
97#ifndef newSVpv_utf8 101#ifndef newSVpv_utf8
98static SV * 102static SV *
121 125
122 return sv; 126 return sv;
123} 127}
124#endif 128#endif
125 129
126static noinline utf8_string 130noinline utf8_string
127cfSvPVutf8_nolen (SV *sv) 131cfSvPVutf8_nolen (SV *sv)
128{ 132{
129 SvGETMAGIC (sv); 133 SvGETMAGIC (sv);
130 134
131 if (SvPOK (sv)) 135 if (SvPOK (sv))
250 { 254 {
251 static int last_mortalcount; 255 static int last_mortalcount;
252 if (mortals.size () != last_mortalcount) 256 if (mortals.size () != last_mortalcount)
253 { 257 {
254 last_mortalcount = mortals.size (); 258 last_mortalcount = mortals.size ();
255 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)");
256 263
257 if (0) 264 if (0)
258 { 265 {
259 for (int j = 0; j < mortals.size (); ++j)//D 266 for (int j = 0; j < mortals.size (); ++j)//D
260 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
351#endif 358#endif
352 359
353////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 360//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
354 361
355static SV * 362static SV *
356newSVptr (void *ptr, HV *stash, HV *hv = newHV ()) 363newSVptr (void *ptr, HV *stash, HV *hv)
357{ 364{
358 SV *sv;
359
360 if (!ptr) 365 if (!ptr)
361 return newSV (0); 366 return newSV (0);
362 367
363 sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, 0, (char *)ptr, 0); 368 sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, 0, (char *)ptr, 0);
364 return sv_bless (newRV_noinc ((SV *)hv), stash); 369 return sv_bless (newRV_noinc ((SV *)hv), stash);
370}
371
372static SV * noinline
373newSVptr (void *ptr, HV *stash)
374{
375 return newSVptr (ptr, stash, newHV ());
365} 376}
366 377
367static int 378static int
368attachable_free (pTHX_ SV *sv, MAGIC *mg) 379attachable_free (pTHX_ SV *sv, MAGIC *mg)
369{ 380{
381 return 0; 392 return 0;
382} 393}
383 394
384MGVTBL attachable::vtbl = {0, 0, 0, 0, attachable_free}; 395MGVTBL attachable::vtbl = {0, 0, 0, 0, attachable_free};
385 396
386static SV * 397static SV * noinline
387newSVattachable (attachable *obj, HV *stash) 398newSVattachable (attachable *obj, HV *stash)
388{ 399{
389 if (!obj) 400 if (!obj)
390 return newSV (0); 401 return newSV (0);
391 402
477 || (SvSTASH (SvRV (sv)) != stash_cf_object_wrap 488 || (SvSTASH (SvRV (sv)) != stash_cf_object_wrap
478 && SvSTASH (SvRV (sv)) != stash_cf_object_player_wrap 489 && SvSTASH (SvRV (sv)) != stash_cf_object_player_wrap
479 && SvSTASH (SvRV (sv)) != stash_cf_arch_wrap 490 && SvSTASH (SvRV (sv)) != stash_cf_arch_wrap
480 && !sv_derived_from (sv, "cf::object"))) 491 && !sv_derived_from (sv, "cf::object")))
481 croak ("object of type cf::object expected"); 492 croak ("object of type cf::object expected");
493
494 return SvPTR_nc (sv);
495}
496
497static long noinline
498SvPTR_ornull_maptile (SV *sv)
499{
500 if (expect_false (!SvOK (sv))) return 0;
501
502 if (!SvROK (sv)
503 || (SvSTASH (SvRV (sv)) != stash_cf_map_wrap
504 && SvSTASH (SvRV (sv)) != stash_ext_map_world
505 && !sv_derived_from (sv, "cf::map")))
506 croak ("object of type cf::map expected");
482 507
483 return SvPTR_nc (sv); 508 return SvPTR_nc (sv);
484} 509}
485 510
486static long noinline 511static long noinline
511static inline SV *to_sv (unsigned long long v) { return newSVval64 (v); } 536static inline SV *to_sv (unsigned long long v) { return newSVval64 (v); }
512static inline SV *to_sv (float v) { return newSVnv (v); } 537static inline SV *to_sv (float v) { return newSVnv (v); }
513static inline SV *to_sv (double v) { return newSVnv (v); } 538static inline SV *to_sv (double v) { return newSVnv (v); }
514static inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); } 539static inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); }
515static inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); } 540static inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); }
541// gcc dislikes noilnine on to_sv
516static inline SV *to_sv (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); } 542static noinline SV *to_sv_ni (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); }
543static inline SV *to_sv (object * v) { return to_sv_ni (v); }
517static inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); } 544static inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); }
518static inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); } 545static inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); }
519static inline SV *to_sv (region * v) { return newSVattachable (v, stash_cf_region_wrap); } 546static inline SV *to_sv (region * v) { return newSVattachable (v, stash_cf_region_wrap); }
520static inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); } 547static inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); }
521static inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } 548static inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); }
522static inline SV *to_sv (mapspace * v) { return newSVptr (v, stash_cf_mapspace_wrap); } 549static inline SV *to_sv (mapspace * v) { return newSVptr (v, stash_cf_mapspace_wrap); }
550static inline SV *to_sv (layout * v) { return newSVptr (v, stash_cf_layout_wrap); }
523 551
524static inline SV *to_sv (object & v) { return to_sv (&v); } 552static inline SV *to_sv (object & v) { return to_sv (&v); }
525static inline SV *to_sv (living & v) { return to_sv (&v); } 553static inline SV *to_sv (living & v) { return to_sv (&v); }
526 554
527static inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); } 555static inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); }
563static inline void sv_to (SV *sv, unsigned long &v) { v = SvUV (sv); } 591static inline void sv_to (SV *sv, unsigned long &v) { v = SvUV (sv); }
564static inline void sv_to (SV *sv, signed long long &v) { v = ( signed long long)SvVAL64 (sv); } 592static inline void sv_to (SV *sv, signed long long &v) { v = ( signed long long)SvVAL64 (sv); }
565static inline void sv_to (SV *sv, unsigned long long &v) { v = (unsigned long long)SvVAL64 (sv); } 593static inline void sv_to (SV *sv, unsigned long long &v) { v = (unsigned long long)SvVAL64 (sv); }
566static inline void sv_to (SV *sv, float &v) { v = SvNV (sv); } 594static inline void sv_to (SV *sv, float &v) { v = SvNV (sv); }
567static inline void sv_to (SV *sv, double &v) { v = SvNV (sv); } 595static inline void sv_to (SV *sv, double &v) { v = SvNV (sv); }
568static inline void sv_to (SV *sv, client * &v) { v = (client *) (attachable *)SvPTR_ornull_client (sv); } 596static inline void sv_to (SV *sv, client * &v) { v = (client *) (attachable *)SvPTR_ornull_client (sv); }
569static inline void sv_to (SV *sv, player * &v) { v = (player *) (attachable *)SvPTR_ornull_player (sv); } 597static inline void sv_to (SV *sv, player * &v) { v = (player *) (attachable *)SvPTR_ornull_player (sv); }
570static inline void sv_to (SV *sv, object * &v) { v = (object *) (attachable *)SvPTR_ornull_object (sv); } 598static inline void sv_to (SV *sv, object * &v) { v = (object *) (attachable *)SvPTR_ornull_object (sv); }
599static inline void sv_to (SV *sv, maptile * &v) { v = (maptile *) (attachable *)SvPTR_ornull_maptile (sv); }
571static inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)(attachable *)SvPTR_ornull (sv, "cf::arch"); } 600static inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)(attachable *)SvPTR_ornull (sv, "cf::arch"); }
572static inline void sv_to (SV *sv, maptile * &v) { v = (maptile *) (attachable *)SvPTR_ornull (sv, "cf::map"); }
573static inline void sv_to (SV *sv, region * &v) { v = (region *) (attachable *)SvPTR_ornull (sv, "cf::region"); } 601static inline void sv_to (SV *sv, region * &v) { v = (region *) (attachable *)SvPTR_ornull (sv, "cf::region"); }
574static inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } 602static inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); }
575static inline void sv_to (SV *sv, partylist * &v) { v = (partylist *) SvPTR_ornull (sv, "cf::party"); } 603static inline void sv_to (SV *sv, partylist * &v) { v = (partylist *) SvPTR_ornull (sv, "cf::party"); }
576static inline void sv_to (SV *sv, living * &v) { v = (living *) SvPTR_ornull (sv, "cf::living"); } 604static inline void sv_to (SV *sv, living * &v) { v = (living *) SvPTR_ornull (sv, "cf::living"); }
577static inline void sv_to (SV *sv, mapspace * &v) { v = (mapspace *) SvPTR_ornull (sv, "cf::mapspace"); } 605static inline void sv_to (SV *sv, mapspace * &v) { v = (mapspace *) SvPTR_ornull (sv, "cf::mapspace"); }
606static inline void sv_to (SV *sv, layout * &v) { v = (layout *) SvPTR_ornull (sv, "cf::layout"); }
578static inline void sv_to (SV *sv, object_freezer * &v) { v = (object_freezer *) SvPTR_ornull (sv, "cf::object::freezer"); } 607static inline void sv_to (SV *sv, object_freezer * &v) { v = (object_freezer *) SvPTR_ornull (sv, "cf::object::freezer"); }
579static inline void sv_to (SV *sv, object_thawer * &v) { v = (object_thawer *) SvPTR_ornull (sv, "cf::object::thawer" ); } 608static inline void sv_to (SV *sv, object_thawer * &v) { v = (object_thawer *) SvPTR_ornull (sv, "cf::object::thawer" ); }
580 609
581//static inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; } 610//static inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; }
582static inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); } 611static inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); }
595static inline void sv_to (SV *sv, std::string &v) 624static inline void sv_to (SV *sv, std::string &v)
596{ 625{
597 STRLEN len; 626 STRLEN len;
598 char *data = SvPVbyte (sv, len); 627 char *data = SvPVbyte (sv, len);
599 v.assign (data, len); 628 v.assign (data, len);
629}
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;
600} 637}
601 638
602static inline void sv_to (SV *sv, UUID &v) 639static inline void sv_to (SV *sv, UUID &v)
603{ 640{
604 if (!v.parse (SvPV_nolen (sv))) 641 if (!v.parse (SvPV_nolen (sv)))
693template<class type> 730template<class type>
694static void noinline 731static void noinline
695cf_obj_to (SV *arg, type &var) 732cf_obj_to (SV *arg, type &var)
696{ 733{
697 sv_to (arg, var); 734 sv_to (arg, var);
698 if (!var) 735 if (expect_false (!var))
699 croak ("must not pass invalid/null cf_obj here"); 736 croak ("must not pass invalid/null cf_obj here");
700} 737}
701 738
702template<class object> 739template<class object>
703static void noinline 740static void noinline
704cf_obj_ornull_to (SV *arg, object *&var) 741cf_obj_ornull_to (SV *arg, object *&var)
705{ 742{
706 if (SvOK (arg)) 743 if (SvOK (arg))
707 { 744 {
708 sv_to (arg, var); 745 sv_to (arg, var);
709 if (!var) 746 if (expect_false (!var))
710 croak ("unable to convert perl object to C++ object"); 747 croak ("unable to convert perl object to C++ object");
711 } 748 }
712 else 749 else
713 var = 0; 750 var = 0;
714} 751}
749 exit (EXIT_FAILURE); 786 exit (EXIT_FAILURE);
750 } 787 }
751 788
752 eval_pv ( 789 eval_pv (
753 "#line 1 'cfperl init'\n" 790 "#line 1 'cfperl init'\n"
754 "use EV ();\n" 791 "use EV ();\n" // required by bootstrap
755 "use Coro ();\n" 792 "use Coro ();\n" // required by bootstrap
756 "cf->bootstrap;\n" 793 "cf->bootstrap;\n" // required for cf::datadir
757 "unshift @INC, cf::datadir ();\n" 794 "unshift @INC, cf::datadir ();\n" // required for 'require' :)
758 "require cf;\n", 795 "require cf;\n",
759 0 796 0
760 ); 797 );
761 798
762 if (SvTRUE (ERRSV)) 799 if (SvTRUE (ERRSV))
1121 CALL_ARG (originator); 1158 CALL_ARG (originator);
1122 CALL_CALL ("cf::mapscript::activate", G_VOID); 1159 CALL_CALL ("cf::mapscript::activate", G_VOID);
1123 CALL_END; 1160 CALL_END;
1124} 1161}
1125 1162
1163void cfperl_ix (client *ns, int set, faceidx idx, int pri)
1164{
1165 CALL_BEGIN (3);
1166 CALL_ARG (ns);
1167 CALL_ARG (set);
1168 CALL_ARG (idx);
1169 CALL_ARG (pri);
1170 CALL_CALL (cv_cf_ix, G_VOID);
1171 CALL_END;
1172}
1173
1126player * 1174player *
1127player::find (const_utf8_string name) 1175player::find (const_utf8_string name)
1128{ 1176{
1129 CALL_BEGIN (1); 1177 CALL_BEGIN (1);
1130 CALL_ARG (name); 1178 CALL_ARG (name);
1376 stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1); 1424 stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1);
1377 stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1); 1425 stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1);
1378 stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1); 1426 stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1);
1379 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); 1427 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1);
1380 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1); 1428 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1);
1429 stash_cf_layout_wrap = gv_stashpv ("cf::layout::wrap", 1);
1430 stash_ext_map_world = gv_stashpv ("ext::map_world" , 1);
1381 1431
1382 sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV); 1432 sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV);
1383 sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV); 1433 sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV);
1434 sv_server_tick = get_sv ("cf::SERVER_TICK", 1); SvUPGRADE (sv_server_tick, SVt_IV);
1384 sv_tick_start = get_sv ("cf::TICK_START", 1); SvUPGRADE (sv_tick_start, SVt_NV); 1435 sv_tick_start = get_sv ("cf::TICK_START" , 1); SvUPGRADE (sv_tick_start , SVt_NV);
1385 sv_next_tick = get_sv ("cf::NEXT_TICK" , 1); SvUPGRADE (sv_next_tick , SVt_NV); 1436 sv_next_tick = get_sv ("cf::NEXT_TICK" , 1); SvUPGRADE (sv_next_tick , SVt_NV);
1386 1437
1387 cb_global = get_av ("cf::CB_GLOBAL", 1); 1438 cb_global = get_av ("cf::CB_GLOBAL", 1);
1388 cb_attachable = get_av ("cf::CB_ATTACHABLE", 1); 1439 cb_attachable = get_av ("cf::CB_ATTACHABLE", 1);
1389 cb_object = get_av ("cf::CB_OBJECT", 1); 1440 cb_object = get_av ("cf::CB_OBJECT", 1);
1390 cb_player = get_av ("cf::CB_PLAYER", 1); 1441 cb_player = get_av ("cf::CB_PLAYER", 1);
1397_connect_to_perl_2 () 1448_connect_to_perl_2 ()
1398{ 1449{
1399 cv_cf_do_invoke = (SV *)get_cv ("cf::do_invoke" , 0); assert (cv_cf_do_invoke); 1450 cv_cf_do_invoke = (SV *)get_cv ("cf::do_invoke" , 0); assert (cv_cf_do_invoke);
1400 cv_cf__can_merge = (SV *)get_cv ("cf::_can_merge" , 0); assert (cv_cf__can_merge); 1451 cv_cf__can_merge = (SV *)get_cv ("cf::_can_merge" , 0); assert (cv_cf__can_merge);
1401 cv_cf_client_send_msg = (SV *)get_cv ("cf::client::send_msg", 0); assert (cv_cf_client_send_msg); 1452 cv_cf_client_send_msg = (SV *)get_cv ("cf::client::send_msg", 0); assert (cv_cf_client_send_msg);
1453 cv_cf_ix = (SV *)get_cv ("cf::face::ix" , 0); assert (cv_cf_ix);
1402 cv_cf_tick = (SV *)get_cv ("cf::tick" , 0); assert (cv_cf_tick); 1454 cv_cf_tick = (SV *)get_cv ("cf::tick" , 0); assert (cv_cf_tick);
1403 cv_cf_match_match = (SV *)get_cv ("cf::match::match" , 0); assert (cv_cf_match_match); 1455 cv_cf_match_match = (SV *)get_cv ("cf::match::match" , 0); assert (cv_cf_match_match);
1404} 1456}
1405 1457
1406MODULE = cf PACKAGE = cf PREFIX = cf_ 1458MODULE = cf PACKAGE = cf PREFIX = cf_
1411 I_CORO_API (PACKAGE); coroapi::GCoroAPI = GCoroAPI; 1463 I_CORO_API (PACKAGE); coroapi::GCoroAPI = GCoroAPI;
1412 1464
1413 _connect_to_perl_1 (); 1465 _connect_to_perl_1 ();
1414 1466
1415 newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1)); 1467 newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1));
1416
1417 //{
1418 // require_pv ("Time::HiRes");
1419 //
1420 // SV **svp = hv_fetch (PL_modglobal, "Time::NVtime", 12, 0);
1421 // if (!svp) croak ("Time::HiRes is required");
1422 // if (!SvIOK(*svp)) croak ("Time::NVtime isn’t a function pointer");
1423 // coroapi::time = INT2PTR (double(*)(), SvIV(*svp));
1424 //}
1425 1468
1426 static const struct { 1469 static const struct {
1427 const char *name; 1470 const char *name;
1428 IV iv; 1471 IV iv;
1429 } *civ, const_iv[] = { 1472 } *civ, const_iv[] = {
1433# include "attackinc.h" 1476# include "attackinc.h"
1434# undef def 1477# undef def
1435# define def(uc, flags) const_iv (SK_ ## uc) 1478# define def(uc, flags) const_iv (SK_ ## uc)
1436# include "skillinc.h" 1479# include "skillinc.h"
1437# undef def 1480# undef def
1438 1481# define def(name, use, nonuse) const_iv (body_ ## name)
1439 const_iv (llevError) const_iv (llevInfo) const_iv (llevDebug) const_iv (llevMonster) 1482# include "slotinc.h"
1440 const_iv (logBacktrace) 1483# undef def
1441
1442 const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd)
1443 1484
1444 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) 1485 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y)
1445 1486
1446 const_iv (MAX_TIME) 1487 const_iv (MAX_TIME)
1447 const_iv (MAXSOCKBUF) 1488 const_iv (MAXSOCKBUF)
1461 const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE) 1502 const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE)
1462 1503
1463 const_iv (SK_EXP_ADD_SKILL) const_iv (SK_EXP_TOTAL) const_iv (SK_EXP_NONE) 1504 const_iv (SK_EXP_ADD_SKILL) const_iv (SK_EXP_TOTAL) const_iv (SK_EXP_NONE)
1464 const_iv (SK_SUBTRACT_SKILL_EXP) const_iv (SK_EXP_SKILL_ONLY) 1505 const_iv (SK_SUBTRACT_SKILL_EXP) const_iv (SK_EXP_SKILL_ONLY)
1465 1506
1466 const_iv (MAP_ACTIVE) const_iv (MAP_SWAPPED) const_iv (MAP_LOADING) const_iv (MAP_SAVING)
1467 const_iv (MAP_INACTIVE)
1468
1469 const_iv (KLASS_ATTACHABLE) const_iv (KLASS_GLOBAL) const_iv (KLASS_OBJECT) 1507 const_iv (KLASS_ATTACHABLE) const_iv (KLASS_GLOBAL) const_iv (KLASS_OBJECT)
1470 const_iv (KLASS_CLIENT) const_iv (KLASS_PLAYER) const_iv (KLASS_MAP) 1508 const_iv (KLASS_CLIENT) const_iv (KLASS_PLAYER) const_iv (KLASS_MAP)
1471 1509
1472 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT) 1510 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT)
1473 1511
1474 const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES) 1512 const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES)
1475 }; 1513 };
1476 1514
1477 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 1515 for (civ = const_iv + array_length (const_iv); civ-- > const_iv; )
1478 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv)); 1516 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv));
1479 1517
1480 static const struct { 1518 static const struct {
1481 const char *name; 1519 const char *name;
1482 int skip; 1520 int skip;
1488# undef def 1526# undef def
1489 }; 1527 };
1490 1528
1491 AV *av = get_av ("cf::EVENT", 1); 1529 AV *av = get_av ("cf::EVENT", 1);
1492 1530
1493 for (eiv = event_iv + sizeof (event_iv) / sizeof (event_iv [0]); eiv-- > event_iv; ) 1531 for (eiv = event_iv + array_length (event_iv); eiv-- > event_iv; )
1494 { 1532 {
1495 AV *event = newAV (); 1533 AV *event = newAV ();
1496 av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0)); 1534 av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0));
1497 av_push (event, newSViv (eiv->klass)); 1535 av_push (event, newSViv (eiv->klass));
1498 av_store (av, eiv->iv, newRV_noinc ((SV *)event)); 1536 av_store (av, eiv->iv, newRV_noinc ((SV *)event));
1505 1543
1506void _gv_clear (SV *gv) 1544void _gv_clear (SV *gv)
1507 CODE: 1545 CODE:
1508 assert (SvTYPE (gv) == SVt_PVGV); 1546 assert (SvTYPE (gv) == SVt_PVGV);
1509# define f(sv) { SV *sv_ = (SV *)(sv); sv = 0; SvREFCNT_dec (sv_); } 1547# define f(sv) { SV *sv_ = (SV *)(sv); sv = 0; SvREFCNT_dec (sv_); }
1548 SvREFCNT_inc (gv);
1510 f (GvGP (gv)->gp_form); 1549 f (GvGP (gv)->gp_form);
1511 f (GvGP (gv)->gp_io); 1550 f (GvGP (gv)->gp_io);
1512 f (GvGP (gv)->gp_sv); 1551 f (GvGP (gv)->gp_sv);
1513 f (GvGP (gv)->gp_av); 1552 f (GvGP (gv)->gp_av);
1514 f (GvGP (gv)->gp_hv); 1553 f (GvGP (gv)->gp_hv);
1515 f (GvGP (gv)->gp_cv); 1554 f (GvGP (gv)->gp_cv);
1516 GvCVGEN (gv) = 0; 1555 GvCVGEN (gv) = 0;
1517 GvMULTI_off (gv); 1556 GvMULTI_off (gv);
1557 SvREFCNT_dec (gv);
1518# undef f 1558# undef f
1519 1559
1520void _connect_to_perl_1 () 1560void _connect_to_perl_1 ()
1521 1561
1522void _connect_to_perl_2 () 1562void _connect_to_perl_2 ()
1533 1573
1534 for_all_objects (op) 1574 for_all_objects (op)
1535 op->reattach (); 1575 op->reattach ();
1536} 1576}
1537 1577
1538# support function for map-world.ext
1539void _quantise (SV *data_sv, SV *plt_sv)
1540 CODE:
1541{
1542 if (!SvROK (plt_sv) || SvTYPE (SvRV (plt_sv)) != SVt_PVAV)
1543 croak ("_quantise called with invalid agruments");
1544
1545 plt_sv = SvRV (plt_sv);
1546 SV **plt = AvARRAY (plt_sv);
1547 int plt_count = AvFILL (plt_sv) + 1;
1548
1549 STRLEN len;
1550 char *data = SvPVbyte (data_sv, len);
1551 char *dst = data;
1552
1553 while (len >= 3)
1554 {
1555 for (SV **val_sv = plt + plt_count; val_sv-- > plt; )
1556 {
1557 char *val = SvPVX (*val_sv);
1558
1559 if (val [0] == data [0]
1560 && val [1] == data [1]
1561 && val [2] == data [2])
1562 {
1563 *dst++ = val [3];
1564 goto next;
1565 }
1566 }
1567
1568 croak ("_quantise: color not found in palette: #%02x%02x%02x, at offset %d %d",
1569 (uint8_t)data [0], (uint8_t)data [1], (uint8_t)data [2],
1570 dst - SvPVX (data_sv), len);
1571
1572 next:
1573 data += 3;
1574 len -= 3;
1575 }
1576
1577 SvCUR_set (data_sv, dst - SvPVX (data_sv));
1578}
1579
1580void init_anim () 1578void init_anim ()
1581 1579
1582void init_globals () 1580void init_globals ()
1583 1581
1584void init_experience ()
1585
1586void init_attackmess () 1582void init_attackmess ()
1587 1583
1588void init_dynamic () 1584void init_dynamic ()
1589 1585
1590void load_settings () 1586void load_settings ()
1591 1587
1588void _reload_exp_table ()
1589
1592void load_materials () 1590void _reload_materials ()
1593 1591
1594void init_uuid () 1592void init_uuid ()
1595 CODE: 1593 CODE:
1596 UUID::init (); 1594 UUID::init ();
1597 1595
1630 { 1628 {
1631 ev_async_send (EV_DEFAULT, &tick_watcher); 1629 ev_async_send (EV_DEFAULT, &tick_watcher);
1632 coroapi::cede (); 1630 coroapi::cede ();
1633 } 1631 }
1634 1632
1635void server_tick () 1633void one_tick ()
1636 CODE: 1634 CODE:
1637{ 1635{
1638 ev_now_update (EV_DEFAULT); 1636 ev_now_update (EV_DEFAULT);
1639 NOW = ev_now (EV_DEFAULT); 1637 NOW = ev_now (EV_DEFAULT);
1640 SvNV_set (sv_now, NOW); SvNOK_only (sv_now); 1638 SvNV_set (sv_now, NOW); SvNOK_only (sv_now);
1641 SvNV_set (sv_tick_start, NOW); SvNOK_only (sv_tick_start); 1639 SvNV_set (sv_tick_start, NOW); SvNOK_only (sv_tick_start);
1642 runtime = SvNVX (sv_runtime); 1640 runtime = SvNVX (sv_runtime);
1643 1641
1642 one_tick ();
1643
1644 server_tick (); 1644 ++server_tick;
1645 SvUV_set (sv_server_tick, server_tick); SvIOK_only_UV (sv_server_tick);
1645 1646
1646 ev_now_update (EV_DEFAULT); 1647 ev_now_update (EV_DEFAULT);
1647 NOW = ev_now (EV_DEFAULT); 1648 NOW = ev_now (EV_DEFAULT);
1648 SvNV_set (sv_now, NOW); SvNOK_only (sv_now); 1649 SvNV_set (sv_now, NOW); SvNOK_only (sv_now);
1650
1649 runtime += TICK; 1651 runtime += TICK;
1650 SvNV_set (sv_runtime, runtime); SvNOK_only (sv_runtime); 1652 SvNV_set (sv_runtime, runtime); SvNOK_only (sv_runtime);
1651} 1653}
1652 1654
1653NV floor (NV x) 1655NV floor (NV x)
1657NV rndm (...) 1659NV rndm (...)
1658 ALIAS: 1660 ALIAS:
1659 rmg_rndm = 1 1661 rmg_rndm = 1
1660 CODE: 1662 CODE:
1661{ 1663{
1662 rand_gen &gen = ix ? rmg_rndm : rndm; 1664 rand_gen &gen = ix ? rmg_rndm : rndm;
1663 switch (items) 1665 switch (items)
1664 { 1666 {
1665 case 0: RETVAL = gen (); break; 1667 case 0: RETVAL = gen (); break;
1666 case 1: RETVAL = gen (SvUV (ST (0))); break; 1668 case 1: RETVAL = gen (SvUV (ST (0))); break;
1667 case 2: RETVAL = gen (SvIV (ST (0)), SvIV (ST (1))); break; 1669 case 2: RETVAL = gen (SvIV (ST (0)), SvIV (ST (1))); break;
1752 1754
1753int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) 1755int mlockall (int flags = MCL_CURRENT | MCL_FUTURE)
1754 INIT: 1756 INIT:
1755#if __GLIBC__ 1757#if __GLIBC__
1756 mallopt (M_TOP_PAD, 1024 * 1024); 1758 mallopt (M_TOP_PAD, 1024 * 1024);
1757 mallopt (M_MMAP_THRESHOLD, 1024 * 1024 * 128); 1759 mallopt (M_MMAP_THRESHOLD, 1024 * 1024);
1758 mallopt (M_MMAP_MAX, 0); // likely bug-workaround, also frees memory 1760 mallopt (M_MMAP_MAX, 0); // likely bug-workaround, also frees memory
1761 if (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 10))
1759 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc 1762 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc
1760#endif 1763#endif
1761 1764
1762int munlockall () 1765int munlockall ()
1763 1766
1764#endif 1767#endif
1790 PUSHs (sv_2mortal (newSVpv ("objects" , 0))); PUSHs (sv_2mortal (newSVuv (objects.size () * sizeof (object)))); 1793 PUSHs (sv_2mortal (newSVpv ("objects" , 0))); PUSHs (sv_2mortal (newSVuv (objects.size () * sizeof (object))));
1791 PUSHs (sv_2mortal (newSVpv ("sv_count" , 0))); PUSHs (sv_2mortal (newSVuv (PL_sv_count))); 1794 PUSHs (sv_2mortal (newSVpv ("sv_count" , 0))); PUSHs (sv_2mortal (newSVuv (PL_sv_count)));
1792 PUSHs (sv_2mortal (newSVpv ("sv_objcount", 0))); PUSHs (sv_2mortal (newSVuv (PL_sv_objcount))); 1795 PUSHs (sv_2mortal (newSVpv ("sv_objcount", 0))); PUSHs (sv_2mortal (newSVuv (PL_sv_objcount)));
1793} 1796}
1794 1797
1795int find_animation (utf8_string text)
1796 PROTOTYPE: $
1797
1798int random_roll (int min, int max, object *op, int goodbad); 1798int random_roll (int min, int max, object *op, int goodbad);
1799 1799
1800const_utf8_string cost_string_from_value(uint64 cost, int approx = 0) 1800const_utf8_string cost_string_from_value(uint64 cost, int approx = 0)
1801 1801
1802int exp_to_level (val64 exp) 1802int exp_to_level (val64 exp)
1803 1803
1804val64 level_to_min_exp (int level) 1804val64 level_to_min_exp (int level)
1805 1805
1806const_utf8_string
1807spellpathnames (int idx)
1808 CODE:
1809 RETVAL = spellpathnames [idx];
1810 OUTPUT: RETVAL
1811
1806SV * 1812SV *
1807resistance_to_string (int atnr) 1813attacktype_name (int atnr)
1808 CODE: 1814 CODE:
1809 if (atnr >= 0 && atnr < NROFATTACKS) 1815 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1816 ? newSVpv (attacktype_name [atnr], 0)
1817 : &PL_sv_undef;
1818 OUTPUT: RETVAL
1819
1820SV *
1821attacktype_desc (int atnr)
1822 CODE:
1823 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1824 ? newSVpv (attacktype_desc [atnr], 0)
1825 : &PL_sv_undef;
1826 OUTPUT: RETVAL
1827
1828SV *
1829resist_plus (int atnr)
1830 CODE:
1831 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1810 RETVAL = newSVpv (resist_plus[atnr], 0); 1832 ? newSVpv (resist_plus [atnr], 0)
1811 else 1833 : &PL_sv_undef;
1812 XSRETURN_UNDEF; 1834 OUTPUT: RETVAL
1835
1836SV *
1837change_resist_msg (int atnr)
1838 CODE:
1839 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1840 ? newSVpv (change_resist_msg [atnr], 0)
1841 : &PL_sv_undef;
1813 OUTPUT: RETVAL 1842 OUTPUT: RETVAL
1814 1843
1815UUID 1844UUID
1816uuid_cur () 1845uuid_cur ()
1817 CODE: 1846 CODE:
1858load_resource_file_ (octet_string filename) 1887load_resource_file_ (octet_string filename)
1859 1888
1860void 1889void
1861fix_weight () 1890fix_weight ()
1862 1891
1892utf8_string
1893expand_cfpod (int hintmode, int gender, const_utf8_string cfpod)
1894 PPCODE:
1895 XPUSHs (to_sv (player::expand_cfpod (hintmode, gender, cfpod)));
1896
1863MODULE = cf PACKAGE = cf::attachable 1897MODULE = cf PACKAGE = cf::attachable
1864 1898
1865int 1899int
1866valid (SV *obj) 1900valid (SV *obj)
1867 CODE: 1901 CODE:
1868 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); 1902 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext);
1869 OUTPUT: 1903 OUTPUT:
1870 RETVAL 1904 RETVAL
1905
1906bool should_invoke (attachable *obj, int event)
1907 CODE:
1908 RETVAL = obj->should_invoke ((event_type)event);
1909 OUTPUT: RETVAL
1871 1910
1872void 1911void
1873debug_trace (attachable *obj, bool on = true) 1912debug_trace (attachable *obj, bool on = true)
1874 CODE: 1913 CODE:
1875 obj->attachable_flags &= ~attachable::F_DEBUG_TRACE; 1914 obj->attachable_flags &= ~attachable::F_DEBUG_TRACE;
1935int mortals_size () 1974int mortals_size ()
1936 CODE: 1975 CODE:
1937 RETVAL = attachable::mortals.size (); 1976 RETVAL = attachable::mortals.size ();
1938 OUTPUT: RETVAL 1977 OUTPUT: RETVAL
1939 1978
1940const_utf8_string slot_use_name (U32 slot) 1979const_utf8_string slot_name (U32 slot)
1941 ALIAS: 1980 ALIAS:
1981 slot_name = 0
1982 slot_use_name = 1
1942 slot_nonuse_name = 1 1983 slot_nonuse_name = 2
1943 CODE: 1984 CODE:
1944{ 1985{
1945 if (slot >= NUM_BODY_LOCATIONS) 1986 if (slot >= NUM_BODY_LOCATIONS)
1946 croak ("body slot index out of range"); 1987 croak ("body slot index out of range");
1947 1988
1948 switch (ix) 1989 switch (ix)
1949 { 1990 {
1991 case 0: RETVAL = body_locations[slot].name ; break;
1950 case 0: RETVAL = body_locations[slot].use_name; break; 1992 case 1: RETVAL = body_locations[slot].use_name ; break;
1951 case 1: RETVAL = body_locations[slot].nonuse_name; break; 1993 case 2: RETVAL = body_locations[slot].nonuse_name; break;
1952 } 1994 }
1953} 1995}
1954 OUTPUT: 1996 OUTPUT:
1955 RETVAL 1997 RETVAL
1956 1998
2062 2104
2063void pick_up (object *who, object *op) 2105void pick_up (object *who, object *op)
2064 2106
2065void update_object (object *op, int action) 2107void update_object (object *op, int action)
2066 2108
2067void change_exp (object *op, uint64 exp, utf8_string skill_name = 0, int flag = 0) 2109void change_exp (object *op, uint64 exp, shstr_tmp skill_name = shstr_tmp (), int flag = 0)
2068 2110
2069void player_lvl_adj (object *who, object *skill = 0) 2111void player_lvl_adj (object *who, object *skill = 0)
2070 2112
2071int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL) 2113int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL)
2072 2114
2081int convert_item (object *item, object *converter) 2123int convert_item (object *item, object *converter)
2082 2124
2083void fix_generated_item (object *op, object *creator, int difficulty, int max_magic, int flags); 2125void fix_generated_item (object *op, object *creator, int difficulty, int max_magic, int flags);
2084 2126
2085MODULE = cf PACKAGE = cf::object PREFIX = cf_ 2127MODULE = cf PACKAGE = cf::object PREFIX = cf_
2086
2087# no clean way to get an object from an archetype - stupid idiotic
2088# dumb kludgy misdesigned plug-in api slowly gets on my nerves.
2089 2128
2090object *new (utf8_string archetype = 0) 2129object *new (utf8_string archetype = 0)
2091 PROTOTYPE: ;$ 2130 PROTOTYPE: ;$
2092 CODE: 2131 CODE:
2093 RETVAL = archetype ? get_archetype (archetype) : object::create (); 2132 RETVAL = archetype
2133 ? archetype::get (archetype)
2134 : object::create ();
2094 OUTPUT: 2135 OUTPUT:
2095 RETVAL 2136 RETVAL
2096 2137
2097object *generate (utf8_string arch, object *creator) 2138object *generate (utf8_string arch, object *creator)
2098 CODE: 2139 CODE:
2099 object *obj = get_archetype (arch); 2140 object *obj = archetype::get (arch);
2100 fix_generated_item (obj, creator, 0, 0, GT_MINIMAL); 2141 fix_generated_item (obj, creator, 0, 0, GT_MINIMAL);
2101 RETVAL = obj; 2142 RETVAL = obj;
2102 OUTPUT: 2143 OUTPUT:
2103 RETVAL 2144 RETVAL
2104 2145
2114 RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y); 2155 RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y);
2115 2156
2116 if (RETVAL->destroyed ()) 2157 if (RETVAL->destroyed ())
2117 RETVAL = 0; 2158 RETVAL = 0;
2118} 2159}
2160 OUTPUT:
2161 RETVAL
2119 2162
2120shstr 2163shstr
2121object::kv_get (shstr key) 2164object::kv_get (shstr key)
2165 CODE:
2166 RETVAL = THIS->kv.get (key);
2167 OUTPUT:
2168 RETVAL
2122 2169
2123void 2170void
2124object::kv_del (shstr key) 2171object::kv_del (shstr key)
2172 CODE:
2173 THIS->kv.del (key);
2125 2174
2126void 2175void
2127object::kv_set (shstr key, shstr value) 2176object::kv_set (shstr key, shstr value)
2177 CODE:
2178 THIS->kv.set (key, value);
2128 2179
2129object *get_nearest_player (object *ob) 2180object *get_nearest_player (object *ob)
2130 ALIAS: nearest_player = 0 2181 ALIAS: nearest_player = 0
2131 PREINIT: 2182 PREINIT:
2132 extern object *get_nearest_player (object *); 2183 extern object *get_nearest_player (object *);
2335 if (pl->ob && pl->ob->map == THIS) 2386 if (pl->ob && pl->ob->map == THIS)
2336 PUSHs (sv_2mortal (to_sv (pl->ob))); 2387 PUSHs (sv_2mortal (to_sv (pl->ob)));
2337 } 2388 }
2338 2389
2339void 2390void
2391maptile::gen_quadmap (int x, int y, int z)
2392 CODE:
2393 gen_quadmap (THIS, x * 50, y * 50, z);
2394
2395void
2340maptile::add_underlay (SV *data, int offset, int stride, SV *palette) 2396maptile::add_underlay (SV *data, int offset, int stride, SV *palette)
2341 CODE: 2397 CODE:
2342{ 2398{
2343 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV) 2399 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV)
2344 croak ("maptile::add_underlay: palette must be arrayref"); 2400 croak ("maptile::add_underlay: palette must be arrayref");
2345 2401
2346 palette = SvRV (palette); 2402 palette = SvRV (palette);
2347 2403
2348 STRLEN idxlen; 2404 STRLEN idxlen;
2349 const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen); 2405 const uint8 *idx = (const uint8 *)SvPVbyte (data, idxlen);
2350 2406
2351 for (int x = 0; x < THIS->width; ++x) 2407 for (int x = 0; x < THIS->width; ++x)
2352 for (int y = 0; y < THIS->height; ++y) 2408 for (int y = 0; y < THIS->height; ++y)
2353 { 2409 {
2354 for (object *op = THIS->at (x, y).bot; op; op = op->above) 2410 for (object *op = THIS->at (x, y).bot; op; op = op->above)
2360 2416
2361 if (IN_RANGE_EXC (offs, 0, idxlen)) 2417 if (IN_RANGE_EXC (offs, 0, idxlen))
2362 { 2418 {
2363 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) 2419 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0))
2364 { 2420 {
2365 object *ob = get_archetype (cfSvPVutf8_nolen (*elem)); 2421 object *ob = archetype::get (cfSvPVutf8_nolen (*elem));
2366 ob->flag [FLAG_NO_MAP_SAVE] = true; 2422 ob->flag [FLAG_NO_MAP_SAVE] = true;
2367 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); 2423 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY);
2368 2424
2369 if (ob->randomitems && !ob->above) 2425 if (ob->randomitems && !ob->above)
2370 { 2426 {
2374 op->flag [FLAG_NO_MAP_SAVE] = true; 2430 op->flag [FLAG_NO_MAP_SAVE] = true;
2375 // TODO: if this is a pickable object, then the item 2431 // TODO: if this is a pickable object, then the item
2376 // will at a bit weird - saving inside the player 2432 // will at a bit weird - saving inside the player
2377 // will clear the flag, but when the player drops 2433 // will clear the flag, but when the player drops
2378 // it without logging out, it keeps the flag. 2434 // it without logging out, it keeps the flag.
2379 // nobody ahs reported this, but this can be rather 2435 // nobody has reported this, but this can be rather
2380 // annoying on persistent maps. 2436 // annoying on persistent maps.
2381 } 2437 }
2382 } 2438 }
2383 } 2439 }
2384 } 2440 }
2385
2386 skip: ; 2441 skip: ;
2387 } 2442 }
2388} 2443}
2389 2444
2390void 2445void
2395 croak ("maptile::set_regiondata: palette must be arrayref"); 2450 croak ("maptile::set_regiondata: palette must be arrayref");
2396 2451
2397 palette = SvRV (palette); 2452 palette = SvRV (palette);
2398 2453
2399 STRLEN idxlen; 2454 STRLEN idxlen;
2400 const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen); 2455 const uint8 *idx = (const uint8 *)SvPVbyte (data, idxlen);
2401 2456
2402 region_ptr *regionmap = new region_ptr [av_len ((AV *)palette) + 1]; 2457 region_ptr *regionmap = new region_ptr [av_len ((AV *)palette) + 1];
2403 uint8_t *regions = salloc<uint8_t> (THIS->size ()); 2458 uint8 *regions = salloc<uint8_t> (THIS->size ());
2404 2459
2405 for (int i = av_len ((AV *)palette) + 1; i--; ) 2460 for (int i = av_len ((AV *)palette) + 1; i--; )
2406 regionmap [i] = region::find (cfSvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1))); 2461 regionmap [i] = region::find (cfSvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1)));
2407 2462
2408 for (int y = 0; y < THIS->height; ++y) 2463 for (int y = 0; y < THIS->height; ++y)
2421 for (int x = 0; x < THIS->width; ++x) 2476 for (int x = 0; x < THIS->width; ++x)
2422 for (int y = 0; y < THIS->height; ++y) 2477 for (int y = 0; y < THIS->height; ++y)
2423 { 2478 {
2424 region *rgn = THIS->region (x, y); 2479 region *rgn = THIS->region (x, y);
2425 2480
2426 //fprintf (stderr, "%d,%d %f %p\n", x, y, rgn->treasure_density,rgn->treasure);//D
2427 if (object *op = THIS->at (x, y).top) 2481 if (object *op = THIS->at (x, y).top)
2428 if (rgn->treasure && rndm () < rgn->treasure_density) 2482 if (rgn->treasure && rndm () < rgn->treasure_density)
2429 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty); 2483 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty);
2430 } 2484 }
2431 2485
2437 if (oblinkpt *obp = map->find_link (connection)) 2491 if (oblinkpt *obp = map->find_link (connection))
2438 for (objectlink *ol = obp->link; ol; ol = ol->next) 2492 for (objectlink *ol = obp->link; ol; ol = ol->next)
2439 XPUSHs (sv_2mortal (to_sv ((object *)ol->ob))); 2493 XPUSHs (sv_2mortal (to_sv ((object *)ol->ob)));
2440 2494
2441void 2495void
2442get_map_flags (maptile *map, int x, int y) 2496xy_normalise (maptile *map, int x, int y, int dir = 0)
2443 PPCODE: 2497 PPCODE:
2444{ 2498{
2445 maptile *nmap = 0; 2499 mapxy pos (map, x, y);
2446 I16 nx = 0, ny = 0; 2500 if (!pos.move (dir).normalise ())
2501 XSRETURN_EMPTY;
2447 2502
2448 PUTBACK;
2449 int flags = get_map_flags (map, &nmap, x, y, &nx, &ny);
2450 SPAGAIN;
2451
2452 EXTEND (SP, 4); 2503 EXTEND (SP, 3);
2453 PUSHs (sv_2mortal (newSViv (flags)));
2454
2455 if (GIMME_V == G_ARRAY)
2456 {
2457 PUSHs (sv_2mortal (to_sv (nmap))); 2504 PUSHs (sv_2mortal (to_sv (pos.m)));
2458 PUSHs (sv_2mortal (newSViv (nx))); 2505 PUSHs (sv_2mortal (to_sv (pos.x)));
2459 PUSHs (sv_2mortal (newSViv (ny))); 2506 PUSHs (sv_2mortal (to_sv (pos.y)));
2460 }
2461} 2507}
2462 2508
2463mapspace * 2509mapspace *
2464ms (maptile *map, unsigned int x, unsigned int y) 2510ms (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2465 PROTOTYPE: $$$ 2511 PROTOTYPE: $$$;$
2466 CODE: 2512 CODE:
2467{ 2513{
2468 maptile *nmap = 0; 2514 mapxy pos (map, x, y);
2469 I16 nx, ny; 2515 if (!pos.move (dir).normalise ())
2470
2471 PUTBACK;
2472 get_map_flags (map, &nmap, x, y, &nx, &ny);
2473 SPAGAIN;
2474
2475 if (!nmap)
2476 XSRETURN_UNDEF; 2516 XSRETURN_UNDEF;
2477 2517
2478 RETVAL = &nmap->at (nx, ny); 2518 RETVAL = &*pos;
2479} 2519}
2480 OUTPUT: 2520 OUTPUT:
2481 RETVAL 2521 RETVAL
2482 2522
2483void 2523void
2484at (maptile *map, unsigned int x, unsigned int y) 2524at (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2485 PROTOTYPE: $$$ 2525 PROTOTYPE: $$$;$
2486 PPCODE: 2526 PPCODE:
2487{ 2527 mapxy pos (map, x, y);
2488 maptile *nmap = 0; 2528 if (pos.move (dir).normalise ())
2489 I16 nx, ny;
2490
2491 PUTBACK;
2492 get_map_flags (map, &nmap, x, y, &nx, &ny);
2493 SPAGAIN;
2494
2495 if (nmap)
2496 for (object *o = nmap->at (nx, ny).bot; o; o = o->above) 2529 for (object *o = pos->bot; o; o = o->above)
2497 XPUSHs (sv_2mortal (to_sv (o))); 2530 XPUSHs (sv_2mortal (to_sv (o)));
2498}
2499 2531
2500SV * 2532SV *
2501bot_at (maptile *map, unsigned int x, unsigned int y) 2533bot_at (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2502 PROTOTYPE: $$$ 2534 PROTOTYPE: $$$;$
2503 ALIAS: 2535 ALIAS:
2504 top_at = 1 2536 top_at = 1
2505 flags_at = 2 2537 flags_at = 2
2506 light_at = 3 2538 light_at = 3
2507 move_block_at = 4 2539 move_block_at = 4
2508 move_slow_at = 5 2540 move_slow_at = 5
2509 move_on_at = 6 2541 move_on_at = 6
2510 move_off_at = 7 2542 move_off_at = 7
2511 CODE: 2543 CODE:
2512{ 2544{
2513 sint16 nx = x; 2545 mapxy pos (map, x, y);
2514 sint16 ny = y; 2546 if (!pos.move (dir).normalise ())
2515
2516 if (!xy_normalise (map, nx, ny))
2517 XSRETURN_UNDEF; 2547 XSRETURN_UNDEF;
2518 2548
2519 mapspace &ms = map->at (nx, ny); 2549 mapspace &ms = *pos;
2520 2550
2521 ms.update (); 2551 ms.update ();
2522 2552
2523 switch (ix) 2553 switch (ix)
2524 { 2554 {
2534} 2564}
2535 OUTPUT: RETVAL 2565 OUTPUT: RETVAL
2536 2566
2537# worst xs function of my life 2567# worst xs function of my life
2538bool 2568bool
2539_create_random_map (\ 2569_create_random_map (maptile *self, SV *options)
2540 maptile *self,\
2541 utf8_string wallstyle,\
2542 utf8_string wall_name,\
2543 utf8_string floorstyle,\
2544 utf8_string monsterstyle,\
2545 utf8_string treasurestyle,\
2546 utf8_string layoutstyle,\
2547 utf8_string doorstyle,\
2548 utf8_string decorstyle,\
2549 utf8_string miningstyle,\
2550 utf8_string origin_map,\
2551 utf8_string final_map,\
2552 utf8_string exitstyle,\
2553 utf8_string this_map,\
2554 utf8_string exit_on_final_map,\
2555 int xsize,\
2556 int ysize,\
2557 int expand2x,\
2558 int layoutoptions1,\
2559 int layoutoptions2,\
2560 int layoutoptions3,\
2561 int symmetry,\
2562 int difficulty,\
2563 int difficulty_given,\
2564 float difficulty_increase,\
2565 int dungeon_level,\
2566 int dungeon_depth,\
2567 int decoroptions,\
2568 int orientation,\
2569 int origin_y,\
2570 int origin_x,\
2571 U32 random_seed,\
2572 val64 total_map_hp,\
2573 int map_layout_style,\
2574 int treasureoptions,\
2575 int symmetry_used,\
2576 region *region,\
2577 utf8_string custom\
2578)
2579 CODE: 2570 CODE:
2580{ 2571{
2581 random_map_params rmp; 2572 random_map_params rmp ((HV *)SvRV (options));
2582
2583 assign (rmp.wallstyle , wallstyle);
2584 assign (rmp.wall_name , wall_name);
2585 assign (rmp.floorstyle , floorstyle);
2586 assign (rmp.monsterstyle , monsterstyle);
2587 assign (rmp.treasurestyle , treasurestyle);
2588 assign (rmp.layoutstyle , layoutstyle);
2589 assign (rmp.doorstyle , doorstyle);
2590 assign (rmp.decorstyle , decorstyle);
2591 assign (rmp.miningstyle , miningstyle);
2592 assign (rmp.exitstyle , exitstyle);
2593 assign (rmp.exit_on_final_map, exit_on_final_map);
2594
2595 rmp.origin_map = origin_map;
2596 rmp.final_map = final_map;
2597 rmp.this_map = this_map;
2598 rmp.xsize = xsize;
2599 rmp.ysize = ysize;
2600 rmp.expand2x = expand2x;
2601 rmp.layoutoptions1 = layoutoptions1;
2602 rmp.layoutoptions2 = layoutoptions2;
2603 rmp.layoutoptions3 = layoutoptions3;
2604 rmp.symmetry = symmetry;
2605 rmp.difficulty = difficulty;
2606 rmp.difficulty_given = difficulty_given;
2607 rmp.difficulty_increase = difficulty_increase;
2608 rmp.dungeon_level = dungeon_level;
2609 rmp.dungeon_depth = dungeon_depth;
2610 rmp.decoroptions = decoroptions;
2611 rmp.orientation = orientation;
2612 rmp.origin_y = origin_y;
2613 rmp.origin_x = origin_x;
2614 rmp.random_seed = random_seed;
2615 rmp.total_map_hp = (uint64_t) total_map_hp;
2616 rmp.map_layout_style = map_layout_style;
2617 rmp.treasureoptions = treasureoptions;
2618 rmp.symmetry_used = symmetry_used;
2619 rmp.region = region;
2620 rmp.custom = custom;
2621
2622 RETVAL = self->generate_random_map (&rmp); 2573 RETVAL = self->generate_random_map (&rmp);
2623} 2574}
2624 OUTPUT: 2575 OUTPUT:
2625 RETVAL 2576 RETVAL
2626 2577
2637 2588
2638archetype *archetypes (U32 index) 2589archetype *archetypes (U32 index)
2639 CODE: 2590 CODE:
2640 RETVAL = index < archetypes.size () ? archetypes [index] : 0; 2591 RETVAL = index < archetypes.size () ? archetypes [index] : 0;
2641 OUTPUT: RETVAL 2592 OUTPUT: RETVAL
2593
2594int skillvec_size ()
2595 CODE:
2596 RETVAL = skillvec.size ();
2597 OUTPUT: RETVAL
2598
2599archetype *skillvec (U32 index)
2600 CODE:
2601 RETVAL = index < skillvec.size () ? (archetype *)(object *)skillvec [index] : 0;
2602 OUTPUT: RETVAL
2603
2604void
2605find_by_type (int type)
2606 PPCODE:
2607 for_all_archetypes (arch)
2608 if (arch->type == type)
2609 XPUSHs (sv_2mortal (to_sv (arch)));
2642 2610
2643INCLUDE: $PERL $srcdir/genacc archetype $srcdir/../include/object.h | 2611INCLUDE: $PERL $srcdir/genacc archetype $srcdir/../include/object.h |
2644 2612
2645MODULE = cf PACKAGE = cf::party 2613MODULE = cf PACKAGE = cf::party
2646 2614
2658list () 2626list ()
2659 PPCODE: 2627 PPCODE:
2660 for_all_regions (rgn) 2628 for_all_regions (rgn)
2661 XPUSHs (sv_2mortal (to_sv (rgn))); 2629 XPUSHs (sv_2mortal (to_sv (rgn)));
2662 2630
2663region *find (utf8_string name)
2664 PROTOTYPE: $
2665 CODE:
2666 RETVAL = region::find (name);
2667 OUTPUT: RETVAL
2668
2669int specificity (region *rgn) 2631int specificity (region *rgn)
2670 CODE: 2632 CODE:
2671 RETVAL = 0; 2633 RETVAL = 0;
2672 while (rgn = rgn->parent) 2634 while (rgn = rgn->parent)
2673 RETVAL++; 2635 RETVAL++;
2701list () 2663list ()
2702 PPCODE: 2664 PPCODE:
2703 EXTEND (SP, clients.size ()); 2665 EXTEND (SP, clients.size ());
2704 for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i) 2666 for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i)
2705 PUSHs (sv_2mortal (to_sv (*i))); 2667 PUSHs (sv_2mortal (to_sv (*i)));
2668
2669STRLEN
2670client::inbuf_append (SV *data)
2671 CODE:
2672{
2673 STRLEN len;
2674 char *ptr = SvPVbyte (data, len);
2675
2676 min_it (len, sizeof (THIS->inbuf) - THIS->inbuf_len);
2677 memcpy (THIS->inbuf + THIS->inbuf_len, ptr, len);
2678 THIS->inbuf_len += len;
2679
2680 THIS->inbuf_handle ();
2681
2682 RETVAL = len;
2683}
2684 OUTPUT: RETVAL
2706 2685
2707void 2686void
2708client::send_packet (SV *packet) 2687client::send_packet (SV *packet)
2709 CODE: 2688 CODE:
2710{ 2689{
2766faceidx face_find (utf8_string name, faceidx defidx = 0) 2745faceidx face_find (utf8_string name, faceidx defidx = 0)
2767 2746
2768faceidx alloc (utf8_string name) 2747faceidx alloc (utf8_string name)
2769 CODE: 2748 CODE:
2770{ 2749{
2771 do 2750 RETVAL = face_alloc ();
2772 {
2773 RETVAL = faces.size ();
2774 faces.resize (RETVAL + 1);
2775 }
2776 while (!RETVAL); // crude way to leave index 0
2777 2751
2778 faces [RETVAL].name = name; 2752 faces [RETVAL].name = name;
2779 facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL)); 2753 facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL));
2780 2754
2781 if (!strcmp (name, BLANK_FACE_NAME )) blank_face = RETVAL; 2755 if (!strcmp (name, BLANK_FACE_NAME )) blank_face = RETVAL;
2782 if (!strcmp (name, EMPTY_FACE_NAME )) empty_face = RETVAL; 2756 if (!strcmp (name, EMPTY_FACE_NAME )) empty_face = RETVAL;
2783 if (!strcmp (name, MAGICMOUTH_FACE_NAME)) magicmouth_face = RETVAL; 2757 if (!strcmp (name, MAGICMOUTH_FACE_NAME)) magicmouth_face = RETVAL;
2784} 2758}
2759 OUTPUT: RETVAL
2760
2761faceidx faces_size ()
2762 CODE:
2763 RETVAL = faces.size ();
2785 OUTPUT: RETVAL 2764 OUTPUT: RETVAL
2786 2765
2787void set_type (faceidx idx, int value) 2766void set_type (faceidx idx, int value)
2788 ALIAS: 2767 ALIAS:
2789 set_type = 0 2768 set_type = 0
2800 case 2: f->magicmap = value; break; 2779 case 2: f->magicmap = value; break;
2801 case 3: f->smooth = value; break; 2780 case 3: f->smooth = value; break;
2802 case 4: f->smoothlevel = value; break; 2781 case 4: f->smoothlevel = value; break;
2803 } 2782 }
2804 2783
2805void set_data (faceidx idx, int faceset, SV *data, SV *chksum) 2784void set_csum (faceidx idx, int faceset, SV *chksum)
2806 CODE: 2785 CODE:
2807{ 2786{
2808 faceinfo *f = face_info (idx); assert (f); 2787 faceinfo *f = face_info (idx); assert (f);
2809 facedata *d = &(faceset ? f->data64 : f->data32); 2788 facedata *d = f->face + faceset;
2810 sv_to (data, d->data);
2811 STRLEN clen; 2789 STRLEN clen;
2812 char *cdata = SvPVbyte (chksum, clen); 2790 char *cdata = SvPVbyte (chksum, clen);
2813 clen = min (CHKSUM_MAXLEN, clen);
2814 2791
2792 assert (("cf::face::set_data called with too long checksum", clen <= CHKSUM_MAXLEN));
2815 assert (("cf::face::set_data must be called with a non-empty checksum", clen)); 2793 assert (("cf::face::set_data must be called with a non-empty checksum", clen));
2816 2794
2817 if (clen != d->chksum_len || memcmp (d->chksum, cdata, clen)) 2795 if (clen != d->chksum_len || memcmp (d->chksum, cdata, clen))
2818 { 2796 {
2819 d->chksum_len = clen; 2797 d->chksum_len = clen;
2820 memcpy (d->chksum, cdata, clen); 2798 memcpy (d->chksum, cdata, clen);
2821 2799
2822 // invalidate existing client face info 2800 // invalidate existing client face info
2823 for_all_clients (ns) 2801 for_all_clients (ns)
2824 if (ns->faceset == faceset) 2802 ns->invalidate_face (idx);
2825 {
2826 ns->faces_sent [idx] = false;
2827 ns->force_newmap = true;
2828 }
2829 } 2803 }
2830} 2804}
2831 2805
2832int get_data_size (faceidx idx, int faceset = 0) 2806SV *mangle_csum (SV *chksum)
2833 CODE: 2807 CODE:
2834 facedata *d = face_data (idx, faceset); 2808 STRLEN len;
2835 if (!d) XSRETURN_UNDEF; 2809 char *data = SvPVbyte (chksum, len);
2836 RETVAL = d->data.size (); 2810 RETVAL = newSVpvn (data, min (len, CHKSUM_MAXLEN));
2837 OUTPUT: 2811 OUTPUT:
2838 RETVAL 2812 RETVAL
2839 2813
2840SV *get_chksum (faceidx idx, int faceset = 0) 2814SV *get_csum (faceidx idx, int faceset = 0)
2841 CODE: 2815 CODE:
2842 facedata *d = face_data (idx, faceset); 2816 facedata *d = face_data (idx, faceset);
2843 if (!d) XSRETURN_UNDEF; 2817 if (!d) XSRETURN_UNDEF;
2844 RETVAL = newSVpvn ((char *)d->chksum, d->chksum_len); 2818 RETVAL = newSVpvn ((char *)d->chksum, d->chksum_len);
2845 OUTPUT: 2819 OUTPUT:
2846 RETVAL 2820 RETVAL
2847 2821
2848SV *get_data (faceidx idx, int faceset = 0) 2822int get_type (faceidx idx)
2849 CODE: 2823 CODE:
2850 facedata *d = face_data (idx, faceset); 2824 faceinfo *f = face_info (idx);
2851 if (!d) XSRETURN_UNDEF; 2825 if (!f) XSRETURN_UNDEF;
2852 RETVAL = newSVpvn (d->data.data (), d->data.length ()); 2826 RETVAL = f->type;
2853 OUTPUT: 2827 OUTPUT:
2854 RETVAL 2828 RETVAL
2855 2829
2830SV *get_name (faceidx idx)
2831 CODE:
2832 faceinfo *f = face_info (idx);
2833 if (!f) XSRETURN_UNDEF;
2834 RETVAL = to_sv (f->name);
2835 OUTPUT:
2836 RETVAL
2837
2856void invalidate (faceidx idx) 2838void invalidate (faceidx idx)
2857 CODE: 2839 CODE:
2858 for_all_clients (ns) 2840 for_all_clients (ns)
2859 { 2841 ns->invalidate_face (idx);
2860 ns->faces_sent [idx] = false;
2861 ns->force_newmap = true;
2862 }
2863 2842
2864void invalidate_all () 2843void invalidate_all ()
2865 CODE: 2844 CODE:
2866 for_all_clients (ns) 2845 for_all_clients (ns)
2867 { 2846 ns->invalidate_all_faces ();
2868 ns->faces_sent.reset ();
2869 ns->force_newmap = true;
2870 }
2871 2847
2872MODULE = cf PACKAGE = cf::anim PREFIX = anim_ 2848MODULE = cf PACKAGE = cf::anim PREFIX = anim_
2873 2849
2874#INCLUDE: $PERL $srcdir/genacc faceset $srcdir/../include/anim.h | 2850#INCLUDE: $PERL $srcdir/genacc faceset $srcdir/../include/anim.h |
2875 2851
2879 OUTPUT: RETVAL 2855 OUTPUT: RETVAL
2880 2856
2881animidx set (utf8_string name, SV *frames, int facings = 1) 2857animidx set (utf8_string name, SV *frames, int facings = 1)
2882 CODE: 2858 CODE:
2883{ 2859{
2884 if (!SvROK (frames) && SvTYPE (SvRV (frames)) != SVt_PVAV) 2860 if (!SvROK (frames) && SvTYPE (SvRV (frames)) != SVt_PVAV)
2885 croak ("frames must be an arrayref"); 2861 croak ("frames must be an arrayref");
2886 2862
2887 AV *av = (AV *)SvRV (frames); 2863 AV *av = (AV *)SvRV (frames);
2888 2864
2889 animation *anim = &animation::find (name); 2865 animation *anim = &animation::find (name);
2890 if (anim->number) 2866 if (anim->number)
2891 { 2867 {
2892 anim->resize (av_len (av) + 1); 2868 anim->resize (av_len (av) + 1);
2893 anim->facings = facings; 2869 anim->facings = facings;
2894 } 2870 }
2966 XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ()))); 2942 XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ())));
2967 2943
2968 self->skip (); 2944 self->skip ();
2969 } 2945 }
2970 2946
2947MODULE = cf PACKAGE = cf::treasurelist
2948
2949# quick hack, because I didn't want to implement accessors for treasurelist.
2950# this asks for even more autogen, actually.
2951
2952void
2953expand (treasurelist *list)
2954 PPCODE:
2955 EXTEND (SP, 3);
2956 PUSHs (sv_2mortal (to_sv (list->name)));
2957 PUSHs (sv_2mortal (to_sv (list->total_chance)));
2958 AV *av = newAV ();
2959 PUSHs (sv_2mortal (newRV_noinc ((SV *)av)));
2960 for (treasure *item = list->items; item; item = item->next)
2961 {
2962 AV *iav = newAV ();
2963 av_push (av, newRV_noinc ((SV *)iav));
2964
2965 av_extend (iav, 7);
2966 av_push (iav, to_sv (item->item));
2967 av_push (iav, to_sv (item->name));
2968 av_push (iav, to_sv (item->change_arch.name));
2969 av_push (iav, to_sv (item->change_arch.title));
2970 av_push (iav, to_sv (item->change_arch.slaying));
2971 av_push (iav, to_sv (item->chance));
2972 av_push (iav, to_sv (item->nrof));
2973 av_push (iav, to_sv (item->magic));
2974 }
2975
2976MODULE = cf PACKAGE = cf::layout
2977
2978INCLUDE: $PERL $srcdir/genacc layout $srcdir/../include/rmg.h |
2979

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines