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.369 by root, Wed Apr 14 02:31:24 2010 UTC vs.
Revision 1.419 by root, Sun Nov 11 02:38:10 2012 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2006,2007,2008,2009,2010,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * 5 *
6 * Deliantra is free software: you can redistribute it and/or modify it under 6 * Deliantra is free software: you can redistribute it and/or modify it under
7 * the terms of the Affero GNU General Public License as published by the 7 * the terms of the Affero GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your 8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version. 9 * option) any later version.
10 * 10 *
11 * This program is distributed in the hope that it will be useful, 11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 * 15 *
16 * You should have received a copy of the Affero GNU General Public License 16 * You should have received a copy of the Affero GNU General Public License
17 * and the GNU General Public License along with this program. If not, see 17 * and the GNU General Public License along with this program. If not, see
18 * <http://www.gnu.org/licenses/>. 18 * <http://www.gnu.org/licenses/>.
19 * 19 *
20 * The authors can be reached via e-mail to <support@deliantra.net> 20 * The authors can be reached via e-mail to <support@deliantra.net>
21 */ 21 */
22 22
23#include "autoconf.h" 23#include "autoconf.h"
24 24
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
52#include <XSUB.h> 53#include <XSUB.h>
53 54
54#include "CoroAPI.h" 55#include "CoroAPI.h"
55#include "perlxsi.c" 56#include "perlxsi.c"
56 57
57extern sint64 *levels; // the experience table
58
59typedef object_thawer &object_thawer_ref; 58typedef object_thawer &object_thawer_ref;
60typedef object_freezer &object_freezer_ref; 59typedef object_freezer &object_freezer_ref;
61 60
62typedef std::string std__string; 61typedef std::string std__string;
63 62
68static int tick_inhibit; 67static int tick_inhibit;
69static int tick_pending; 68static int tick_pending;
70 69
71global gbl_ev; 70global gbl_ev;
72static 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;
73static 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;
74static AV *av_reflect; 73static AV *av_reflect;
75 74
76bitset<NUM_EVENT_TYPES> ev_want_event; 75bitset<NUM_EVENT_TYPES> ev_want_event;
77bitset<NUM_TYPES> ev_want_type; 76bitset<NUM_TYPES> ev_want_type;
78 77
85 *stash_cf_mapspace_wrap, 84 *stash_cf_mapspace_wrap,
86 *stash_cf_client_wrap, 85 *stash_cf_client_wrap,
87 *stash_cf_arch_wrap, 86 *stash_cf_arch_wrap,
88 *stash_cf_party_wrap, 87 *stash_cf_party_wrap,
89 *stash_cf_region_wrap, 88 *stash_cf_region_wrap,
90 *stash_cf_living_wrap; 89 *stash_cf_living_wrap,
90 *stash_cf_layout_wrap,
91 *stash_ext_map_world;
91 92
92static SV 93static SV
93 *cv_cf_do_invoke, 94 *cv_cf_do_invoke,
94 *cv_cf__can_merge, 95 *cv_cf__can_merge,
95 *cv_cf_client_send_msg, 96 *cv_cf_client_send_msg,
123 124
124 return sv; 125 return sv;
125} 126}
126#endif 127#endif
127 128
128static noinline utf8_string 129noinline utf8_string
129cfSvPVutf8_nolen (SV *sv) 130cfSvPVutf8_nolen (SV *sv)
130{ 131{
131 SvGETMAGIC (sv); 132 SvGETMAGIC (sv);
132 133
133 if (SvPOK (sv)) 134 if (SvPOK (sv))
252 { 253 {
253 static int last_mortalcount; 254 static int last_mortalcount;
254 if (mortals.size () != last_mortalcount) 255 if (mortals.size () != last_mortalcount)
255 { 256 {
256 last_mortalcount = mortals.size (); 257 last_mortalcount = mortals.size ();
257 LOG (llevInfo, "%d mortals.\n", (int)mortals.size ()); 258 object *specimen = is_a<object> (mortals [rndm (mortals.size ())]);
259
260 LOG (llevInfo, "%d mortals (random specimen: %s).\n",
261 (int)mortals.size (), specimen ? specimen->debug_desc () : "(not an object)");
258 262
259 if (0) 263 if (0)
260 { 264 {
261 for (int j = 0; j < mortals.size (); ++j)//D 265 for (int j = 0; j < mortals.size (); ++j)//D
262 fprintf (stderr, "%d:%s %p ", j, &((object *)mortals[j])->name, mortals[j]);//D 266 fprintf (stderr, "%d:%s %p ", j, &((object *)mortals[j])->name, mortals[j]);//D
353#endif 357#endif
354 358
355////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 359//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
356 360
357static SV * 361static SV *
358newSVptr (void *ptr, HV *stash, HV *hv = newHV ()) 362newSVptr (void *ptr, HV *stash, HV *hv)
359{ 363{
360 SV *sv;
361
362 if (!ptr) 364 if (!ptr)
363 return newSV (0); 365 return newSV (0);
364 366
365 sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, 0, (char *)ptr, 0); 367 sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, 0, (char *)ptr, 0);
366 return sv_bless (newRV_noinc ((SV *)hv), stash); 368 return sv_bless (newRV_noinc ((SV *)hv), stash);
369}
370
371static SV * noinline
372newSVptr (void *ptr, HV *stash)
373{
374 return newSVptr (ptr, stash, newHV ());
367} 375}
368 376
369static int 377static int
370attachable_free (pTHX_ SV *sv, MAGIC *mg) 378attachable_free (pTHX_ SV *sv, MAGIC *mg)
371{ 379{
383 return 0; 391 return 0;
384} 392}
385 393
386MGVTBL attachable::vtbl = {0, 0, 0, 0, attachable_free}; 394MGVTBL attachable::vtbl = {0, 0, 0, 0, attachable_free};
387 395
388static SV * 396static SV * noinline
389newSVattachable (attachable *obj, HV *stash) 397newSVattachable (attachable *obj, HV *stash)
390{ 398{
391 if (!obj) 399 if (!obj)
392 return newSV (0); 400 return newSV (0);
393 401
479 || (SvSTASH (SvRV (sv)) != stash_cf_object_wrap 487 || (SvSTASH (SvRV (sv)) != stash_cf_object_wrap
480 && SvSTASH (SvRV (sv)) != stash_cf_object_player_wrap 488 && SvSTASH (SvRV (sv)) != stash_cf_object_player_wrap
481 && SvSTASH (SvRV (sv)) != stash_cf_arch_wrap 489 && SvSTASH (SvRV (sv)) != stash_cf_arch_wrap
482 && !sv_derived_from (sv, "cf::object"))) 490 && !sv_derived_from (sv, "cf::object")))
483 croak ("object of type cf::object expected"); 491 croak ("object of type cf::object expected");
492
493 return SvPTR_nc (sv);
494}
495
496static long noinline
497SvPTR_ornull_maptile (SV *sv)
498{
499 if (expect_false (!SvOK (sv))) return 0;
500
501 if (!SvROK (sv)
502 || (SvSTASH (SvRV (sv)) != stash_cf_map_wrap
503 && SvSTASH (SvRV (sv)) != stash_ext_map_world
504 && !sv_derived_from (sv, "cf::map")))
505 croak ("object of type cf::map expected");
484 506
485 return SvPTR_nc (sv); 507 return SvPTR_nc (sv);
486} 508}
487 509
488static long noinline 510static long noinline
513static inline SV *to_sv (unsigned long long v) { return newSVval64 (v); } 535static inline SV *to_sv (unsigned long long v) { return newSVval64 (v); }
514static inline SV *to_sv (float v) { return newSVnv (v); } 536static inline SV *to_sv (float v) { return newSVnv (v); }
515static inline SV *to_sv (double v) { return newSVnv (v); } 537static inline SV *to_sv (double v) { return newSVnv (v); }
516static inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); } 538static inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); }
517static inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); } 539static inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); }
540// gcc dislikes noilnine on to_sv
518static inline SV *to_sv (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); } 541static noinline 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); }
519static inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); } 543static inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); }
520static inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); } 544static inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); }
521static inline SV *to_sv (region * v) { return newSVattachable (v, stash_cf_region_wrap); } 545static inline SV *to_sv (region * v) { return newSVattachable (v, stash_cf_region_wrap); }
522static inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); } 546static inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); }
523static inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } 547static inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); }
524static inline SV *to_sv (mapspace * v) { return newSVptr (v, stash_cf_mapspace_wrap); } 548static inline SV *to_sv (mapspace * v) { return newSVptr (v, stash_cf_mapspace_wrap); }
549static inline SV *to_sv (layout * v) { return newSVptr (v, stash_cf_layout_wrap); }
525 550
526static inline SV *to_sv (object & v) { return to_sv (&v); } 551static inline SV *to_sv (object & v) { return to_sv (&v); }
527static inline SV *to_sv (living & v) { return to_sv (&v); } 552static inline SV *to_sv (living & v) { return to_sv (&v); }
528 553
529static inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); } 554static inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); }
565static inline void sv_to (SV *sv, unsigned long &v) { v = SvUV (sv); } 590static inline void sv_to (SV *sv, unsigned long &v) { v = SvUV (sv); }
566static inline void sv_to (SV *sv, signed long long &v) { v = ( signed long long)SvVAL64 (sv); } 591static inline void sv_to (SV *sv, signed long long &v) { v = ( signed long long)SvVAL64 (sv); }
567static inline void sv_to (SV *sv, unsigned long long &v) { v = (unsigned long long)SvVAL64 (sv); } 592static inline void sv_to (SV *sv, unsigned long long &v) { v = (unsigned long long)SvVAL64 (sv); }
568static inline void sv_to (SV *sv, float &v) { v = SvNV (sv); } 593static inline void sv_to (SV *sv, float &v) { v = SvNV (sv); }
569static inline void sv_to (SV *sv, double &v) { v = SvNV (sv); } 594static inline void sv_to (SV *sv, double &v) { v = SvNV (sv); }
570static inline void sv_to (SV *sv, client * &v) { v = (client *) (attachable *)SvPTR_ornull_client (sv); } 595static inline void sv_to (SV *sv, client * &v) { v = (client *) (attachable *)SvPTR_ornull_client (sv); }
571static inline void sv_to (SV *sv, player * &v) { v = (player *) (attachable *)SvPTR_ornull_player (sv); } 596static inline void sv_to (SV *sv, player * &v) { v = (player *) (attachable *)SvPTR_ornull_player (sv); }
572static inline void sv_to (SV *sv, object * &v) { v = (object *) (attachable *)SvPTR_ornull_object (sv); } 597static inline void sv_to (SV *sv, object * &v) { v = (object *) (attachable *)SvPTR_ornull_object (sv); }
598static inline void sv_to (SV *sv, maptile * &v) { v = (maptile *) (attachable *)SvPTR_ornull_maptile (sv); }
573static inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)(attachable *)SvPTR_ornull (sv, "cf::arch"); } 599static inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)(attachable *)SvPTR_ornull (sv, "cf::arch"); }
574static inline void sv_to (SV *sv, maptile * &v) { v = (maptile *) (attachable *)SvPTR_ornull (sv, "cf::map"); }
575static inline void sv_to (SV *sv, region * &v) { v = (region *) (attachable *)SvPTR_ornull (sv, "cf::region"); } 600static inline void sv_to (SV *sv, region * &v) { v = (region *) (attachable *)SvPTR_ornull (sv, "cf::region"); }
576static inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } 601static inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); }
577static inline void sv_to (SV *sv, partylist * &v) { v = (partylist *) SvPTR_ornull (sv, "cf::party"); } 602static inline void sv_to (SV *sv, partylist * &v) { v = (partylist *) SvPTR_ornull (sv, "cf::party"); }
578static inline void sv_to (SV *sv, living * &v) { v = (living *) SvPTR_ornull (sv, "cf::living"); } 603static inline void sv_to (SV *sv, living * &v) { v = (living *) SvPTR_ornull (sv, "cf::living"); }
579static inline void sv_to (SV *sv, mapspace * &v) { v = (mapspace *) SvPTR_ornull (sv, "cf::mapspace"); } 604static inline void sv_to (SV *sv, mapspace * &v) { v = (mapspace *) SvPTR_ornull (sv, "cf::mapspace"); }
605static inline void sv_to (SV *sv, layout * &v) { v = (layout *) SvPTR_ornull (sv, "cf::layout"); }
580static inline void sv_to (SV *sv, object_freezer * &v) { v = (object_freezer *) SvPTR_ornull (sv, "cf::object::freezer"); } 606static inline void sv_to (SV *sv, object_freezer * &v) { v = (object_freezer *) SvPTR_ornull (sv, "cf::object::freezer"); }
581static inline void sv_to (SV *sv, object_thawer * &v) { v = (object_thawer *) SvPTR_ornull (sv, "cf::object::thawer" ); } 607static inline void sv_to (SV *sv, object_thawer * &v) { v = (object_thawer *) SvPTR_ornull (sv, "cf::object::thawer" ); }
582 608
583//static inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; } 609//static inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; }
584static inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); } 610static inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); }
597static inline void sv_to (SV *sv, std::string &v) 623static inline void sv_to (SV *sv, std::string &v)
598{ 624{
599 STRLEN len; 625 STRLEN len;
600 char *data = SvPVbyte (sv, len); 626 char *data = SvPVbyte (sv, len);
601 v.assign (data, len); 627 v.assign (data, len);
628}
629
630static inline void sv_to (SV *sv, refcnt_buf &v)
631{
632 STRLEN len;
633 char *data = SvPVbyte (sv, len);
634 refcnt_buf buf (data, len);
635 v = buf;
602} 636}
603 637
604static inline void sv_to (SV *sv, UUID &v) 638static inline void sv_to (SV *sv, UUID &v)
605{ 639{
606 if (!v.parse (SvPV_nolen (sv))) 640 if (!v.parse (SvPV_nolen (sv)))
695template<class type> 729template<class type>
696static void noinline 730static void noinline
697cf_obj_to (SV *arg, type &var) 731cf_obj_to (SV *arg, type &var)
698{ 732{
699 sv_to (arg, var); 733 sv_to (arg, var);
700 if (!var) 734 if (expect_false (!var))
701 croak ("must not pass invalid/null cf_obj here"); 735 croak ("must not pass invalid/null cf_obj here");
702} 736}
703 737
704template<class object> 738template<class object>
705static void noinline 739static void noinline
706cf_obj_ornull_to (SV *arg, object *&var) 740cf_obj_ornull_to (SV *arg, object *&var)
707{ 741{
708 if (SvOK (arg)) 742 if (SvOK (arg))
709 { 743 {
710 sv_to (arg, var); 744 sv_to (arg, var);
711 if (!var) 745 if (expect_false (!var))
712 croak ("unable to convert perl object to C++ object"); 746 croak ("unable to convert perl object to C++ object");
713 } 747 }
714 else 748 else
715 var = 0; 749 var = 0;
716} 750}
751 exit (EXIT_FAILURE); 785 exit (EXIT_FAILURE);
752 } 786 }
753 787
754 eval_pv ( 788 eval_pv (
755 "#line 1 'cfperl init'\n" 789 "#line 1 'cfperl init'\n"
756 "use EV ();\n" 790 "use EV ();\n" // required by bootstrap
757 "use Coro ();\n" 791 "use Coro ();\n" // required by bootstrap
758 "cf->bootstrap;\n" 792 "cf->bootstrap;\n" // required for cf::datadir
759 "unshift @INC, cf::datadir ();\n" 793 "unshift @INC, cf::datadir ();\n" // required for 'require' :)
760 "require cf;\n", 794 "require cf;\n",
761 0 795 0
762 ); 796 );
763 797
764 if (SvTRUE (ERRSV)) 798 if (SvTRUE (ERRSV))
1378 stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1); 1412 stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1);
1379 stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1); 1413 stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1);
1380 stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1); 1414 stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1);
1381 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); 1415 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1);
1382 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1); 1416 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1);
1417 stash_cf_layout_wrap = gv_stashpv ("cf::layout::wrap", 1);
1418 stash_ext_map_world = gv_stashpv ("ext::map_world" , 1);
1383 1419
1384 sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV); 1420 sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV);
1385 sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV); 1421 sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV);
1422 sv_server_tick = get_sv ("cf::SERVER_TICK", 1); SvUPGRADE (sv_server_tick, SVt_IV);
1386 sv_tick_start = get_sv ("cf::TICK_START", 1); SvUPGRADE (sv_tick_start, SVt_NV); 1423 sv_tick_start = get_sv ("cf::TICK_START" , 1); SvUPGRADE (sv_tick_start , SVt_NV);
1387 sv_next_tick = get_sv ("cf::NEXT_TICK" , 1); SvUPGRADE (sv_next_tick , SVt_NV); 1424 sv_next_tick = get_sv ("cf::NEXT_TICK" , 1); SvUPGRADE (sv_next_tick , SVt_NV);
1388 1425
1389 cb_global = get_av ("cf::CB_GLOBAL", 1); 1426 cb_global = get_av ("cf::CB_GLOBAL", 1);
1390 cb_attachable = get_av ("cf::CB_ATTACHABLE", 1); 1427 cb_attachable = get_av ("cf::CB_ATTACHABLE", 1);
1391 cb_object = get_av ("cf::CB_OBJECT", 1); 1428 cb_object = get_av ("cf::CB_OBJECT", 1);
1392 cb_player = get_av ("cf::CB_PLAYER", 1); 1429 cb_player = get_av ("cf::CB_PLAYER", 1);
1413 I_CORO_API (PACKAGE); coroapi::GCoroAPI = GCoroAPI; 1450 I_CORO_API (PACKAGE); coroapi::GCoroAPI = GCoroAPI;
1414 1451
1415 _connect_to_perl_1 (); 1452 _connect_to_perl_1 ();
1416 1453
1417 newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1)); 1454 newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1));
1418
1419 //{
1420 // require_pv ("Time::HiRes");
1421 //
1422 // SV **svp = hv_fetch (PL_modglobal, "Time::NVtime", 12, 0);
1423 // if (!svp) croak ("Time::HiRes is required");
1424 // if (!SvIOK(*svp)) croak ("Time::NVtime isn’t a function pointer");
1425 // coroapi::time = INT2PTR (double(*)(), SvIV(*svp));
1426 //}
1427 1455
1428 static const struct { 1456 static const struct {
1429 const char *name; 1457 const char *name;
1430 IV iv; 1458 IV iv;
1431 } *civ, const_iv[] = { 1459 } *civ, const_iv[] = {
1435# include "attackinc.h" 1463# include "attackinc.h"
1436# undef def 1464# undef def
1437# define def(uc, flags) const_iv (SK_ ## uc) 1465# define def(uc, flags) const_iv (SK_ ## uc)
1438# include "skillinc.h" 1466# include "skillinc.h"
1439# undef def 1467# undef def
1440 1468# define def(name, use, nonuse) const_iv (body_ ## name)
1441 const_iv (llevError) const_iv (llevInfo) const_iv (llevDebug) const_iv (llevMonster) 1469# include "slotinc.h"
1442 const_iv (logBacktrace) 1470# undef def
1443
1444 const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd)
1445 1471
1446 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) 1472 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y)
1447 1473
1448 const_iv (MAX_TIME) 1474 const_iv (MAX_TIME)
1449 const_iv (MAXSOCKBUF) 1475 const_iv (MAXSOCKBUF)
1463 const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE) 1489 const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE)
1464 1490
1465 const_iv (SK_EXP_ADD_SKILL) const_iv (SK_EXP_TOTAL) const_iv (SK_EXP_NONE) 1491 const_iv (SK_EXP_ADD_SKILL) const_iv (SK_EXP_TOTAL) const_iv (SK_EXP_NONE)
1466 const_iv (SK_SUBTRACT_SKILL_EXP) const_iv (SK_EXP_SKILL_ONLY) 1492 const_iv (SK_SUBTRACT_SKILL_EXP) const_iv (SK_EXP_SKILL_ONLY)
1467 1493
1468 const_iv (MAP_ACTIVE) const_iv (MAP_SWAPPED) const_iv (MAP_LOADING) const_iv (MAP_SAVING)
1469 const_iv (MAP_INACTIVE)
1470
1471 const_iv (KLASS_ATTACHABLE) const_iv (KLASS_GLOBAL) const_iv (KLASS_OBJECT) 1494 const_iv (KLASS_ATTACHABLE) const_iv (KLASS_GLOBAL) const_iv (KLASS_OBJECT)
1472 const_iv (KLASS_CLIENT) const_iv (KLASS_PLAYER) const_iv (KLASS_MAP) 1495 const_iv (KLASS_CLIENT) const_iv (KLASS_PLAYER) const_iv (KLASS_MAP)
1473 1496
1474 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT) 1497 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT)
1475 1498
1476 const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES) 1499 const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES)
1477 }; 1500 };
1478 1501
1479 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 1502 for (civ = const_iv + array_length (const_iv); civ-- > const_iv; )
1480 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv)); 1503 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv));
1481 1504
1482 static const struct { 1505 static const struct {
1483 const char *name; 1506 const char *name;
1484 int skip; 1507 int skip;
1490# undef def 1513# undef def
1491 }; 1514 };
1492 1515
1493 AV *av = get_av ("cf::EVENT", 1); 1516 AV *av = get_av ("cf::EVENT", 1);
1494 1517
1495 for (eiv = event_iv + sizeof (event_iv) / sizeof (event_iv [0]); eiv-- > event_iv; ) 1518 for (eiv = event_iv + array_length (event_iv); eiv-- > event_iv; )
1496 { 1519 {
1497 AV *event = newAV (); 1520 AV *event = newAV ();
1498 av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0)); 1521 av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0));
1499 av_push (event, newSViv (eiv->klass)); 1522 av_push (event, newSViv (eiv->klass));
1500 av_store (av, eiv->iv, newRV_noinc ((SV *)event)); 1523 av_store (av, eiv->iv, newRV_noinc ((SV *)event));
1507 1530
1508void _gv_clear (SV *gv) 1531void _gv_clear (SV *gv)
1509 CODE: 1532 CODE:
1510 assert (SvTYPE (gv) == SVt_PVGV); 1533 assert (SvTYPE (gv) == SVt_PVGV);
1511# define f(sv) { SV *sv_ = (SV *)(sv); sv = 0; SvREFCNT_dec (sv_); } 1534# define f(sv) { SV *sv_ = (SV *)(sv); sv = 0; SvREFCNT_dec (sv_); }
1535 SvREFCNT_inc (gv);
1512 f (GvGP (gv)->gp_form); 1536 f (GvGP (gv)->gp_form);
1513 f (GvGP (gv)->gp_io); 1537 f (GvGP (gv)->gp_io);
1514 f (GvGP (gv)->gp_sv); 1538 f (GvGP (gv)->gp_sv);
1515 f (GvGP (gv)->gp_av); 1539 f (GvGP (gv)->gp_av);
1516 f (GvGP (gv)->gp_hv); 1540 f (GvGP (gv)->gp_hv);
1517 f (GvGP (gv)->gp_cv); 1541 f (GvGP (gv)->gp_cv);
1518 GvCVGEN (gv) = 0; 1542 GvCVGEN (gv) = 0;
1519 GvMULTI_off (gv); 1543 GvMULTI_off (gv);
1544 SvREFCNT_dec (gv);
1520# undef f 1545# undef f
1521 1546
1522void _connect_to_perl_1 () 1547void _connect_to_perl_1 ()
1523 1548
1524void _connect_to_perl_2 () 1549void _connect_to_perl_2 ()
1535 1560
1536 for_all_objects (op) 1561 for_all_objects (op)
1537 op->reattach (); 1562 op->reattach ();
1538} 1563}
1539 1564
1540# support function for map-world.ext
1541void _quantise (SV *data_sv, SV *plt_sv)
1542 CODE:
1543{
1544 if (!SvROK (plt_sv) || SvTYPE (SvRV (plt_sv)) != SVt_PVAV)
1545 croak ("_quantise called with invalid agruments");
1546
1547 plt_sv = SvRV (plt_sv);
1548 SV **plt = AvARRAY (plt_sv);
1549 int plt_count = AvFILL (plt_sv) + 1;
1550
1551 STRLEN len;
1552 char *data = SvPVbyte (data_sv, len);
1553 char *dst = data;
1554
1555 while (len >= 3)
1556 {
1557 for (SV **val_sv = plt + plt_count; val_sv-- > plt; )
1558 {
1559 char *val = SvPVX (*val_sv);
1560
1561 if (val [0] == data [0]
1562 && val [1] == data [1]
1563 && val [2] == data [2])
1564 {
1565 *dst++ = val [3];
1566 goto next;
1567 }
1568 }
1569
1570 croak ("_quantise: color not found in palette: #%02x%02x%02x, at offset %d %d",
1571 (uint8_t)data [0], (uint8_t)data [1], (uint8_t)data [2],
1572 dst - SvPVX (data_sv), len);
1573
1574 next:
1575 data += 3;
1576 len -= 3;
1577 }
1578
1579 SvCUR_set (data_sv, dst - SvPVX (data_sv));
1580}
1581
1582void init_anim () 1565void init_anim ()
1583 1566
1584void init_globals () 1567void init_globals ()
1585 1568
1586void init_experience ()
1587
1588void init_attackmess () 1569void init_attackmess ()
1589 1570
1590void init_dynamic () 1571void init_dynamic ()
1591 1572
1592void load_settings () 1573void load_settings ()
1593 1574
1575void _reload_exp_table ()
1576
1594void load_materials () 1577void _reload_materials ()
1595 1578
1596void init_uuid () 1579void init_uuid ()
1597 CODE: 1580 CODE:
1598 UUID::init (); 1581 UUID::init ();
1599 1582
1632 { 1615 {
1633 ev_async_send (EV_DEFAULT, &tick_watcher); 1616 ev_async_send (EV_DEFAULT, &tick_watcher);
1634 coroapi::cede (); 1617 coroapi::cede ();
1635 } 1618 }
1636 1619
1637void server_tick () 1620void one_tick ()
1638 CODE: 1621 CODE:
1639{ 1622{
1640 ev_now_update (EV_DEFAULT); 1623 ev_now_update (EV_DEFAULT);
1641 NOW = ev_now (EV_DEFAULT); 1624 NOW = ev_now (EV_DEFAULT);
1642 SvNV_set (sv_now, NOW); SvNOK_only (sv_now); 1625 SvNV_set (sv_now, NOW); SvNOK_only (sv_now);
1643 SvNV_set (sv_tick_start, NOW); SvNOK_only (sv_tick_start); 1626 SvNV_set (sv_tick_start, NOW); SvNOK_only (sv_tick_start);
1644 runtime = SvNVX (sv_runtime); 1627 runtime = SvNVX (sv_runtime);
1645 1628
1629 one_tick ();
1630
1646 server_tick (); 1631 ++server_tick;
1632 SvUV_set (sv_server_tick, server_tick); SvIOK_only_UV (sv_server_tick);
1647 1633
1648 ev_now_update (EV_DEFAULT); 1634 ev_now_update (EV_DEFAULT);
1649 NOW = ev_now (EV_DEFAULT); 1635 NOW = ev_now (EV_DEFAULT);
1650 SvNV_set (sv_now, NOW); SvNOK_only (sv_now); 1636 SvNV_set (sv_now, NOW); SvNOK_only (sv_now);
1637
1651 runtime += TICK; 1638 runtime += TICK;
1652 SvNV_set (sv_runtime, runtime); SvNOK_only (sv_runtime); 1639 SvNV_set (sv_runtime, runtime); SvNOK_only (sv_runtime);
1653} 1640}
1654 1641
1655NV floor (NV x) 1642NV floor (NV x)
1754 1741
1755int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) 1742int mlockall (int flags = MCL_CURRENT | MCL_FUTURE)
1756 INIT: 1743 INIT:
1757#if __GLIBC__ 1744#if __GLIBC__
1758 mallopt (M_TOP_PAD, 1024 * 1024); 1745 mallopt (M_TOP_PAD, 1024 * 1024);
1759 mallopt (M_MMAP_THRESHOLD, 1024 * 1024 * 128); 1746 mallopt (M_MMAP_THRESHOLD, 1024 * 1024);
1760 mallopt (M_MMAP_MAX, 0); // likely bug-workaround, also frees memory 1747 mallopt (M_MMAP_MAX, 0); // likely bug-workaround, also frees memory
1748 if (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 10))
1761 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc 1749 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc
1762#endif 1750#endif
1763 1751
1764int munlockall () 1752int munlockall ()
1765 1753
1766#endif 1754#endif
1799 1787
1800int random_roll (int min, int max, object *op, int goodbad); 1788int random_roll (int min, int max, object *op, int goodbad);
1801 1789
1802const_utf8_string cost_string_from_value(uint64 cost, int approx = 0) 1790const_utf8_string cost_string_from_value(uint64 cost, int approx = 0)
1803 1791
1804int
1805exp_to_level (val64 exp) 1792int exp_to_level (val64 exp)
1793
1794val64 level_to_min_exp (int level)
1795
1796const_utf8_string
1797spellpathnames (int idx)
1798 CODE:
1799 RETVAL = spellpathnames [idx];
1800 OUTPUT: RETVAL
1801
1802SV *
1803attacktype_name (int atnr)
1806 CODE: 1804 CODE:
1807{ 1805 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1808 int i = 0; 1806 ? newSVpv (attacktype_name [atnr], 0)
1809 1807 : &PL_sv_undef;
1810 RETVAL = settings.max_level;
1811
1812 for (i = 1; i <= settings.max_level; i++)
1813 {
1814 if (levels[i] > exp)
1815 {
1816 RETVAL = i - 1;
1817 break;
1818 }
1819 }
1820}
1821 OUTPUT: RETVAL 1808 OUTPUT: RETVAL
1822 1809
1823val64
1824level_to_min_exp (int level)
1825 CODE:
1826 if (level > settings.max_level)
1827 RETVAL = levels[settings.max_level];
1828 else if (level < 1)
1829 RETVAL = 0;
1830 else
1831 RETVAL = levels[level];
1832 OUTPUT: RETVAL
1833
1834SV * 1810SV *
1835resistance_to_string (int atnr) 1811attacktype_desc (int atnr)
1836 CODE: 1812 CODE:
1837 if (atnr >= 0 && atnr < NROFATTACKS) 1813 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1814 ? newSVpv (attacktype_desc [atnr], 0)
1815 : &PL_sv_undef;
1816 OUTPUT: RETVAL
1817
1818SV *
1819resist_plus (int atnr)
1820 CODE:
1821 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1838 RETVAL = newSVpv (resist_plus[atnr], 0); 1822 ? newSVpv (resist_plus [atnr], 0)
1839 else 1823 : &PL_sv_undef;
1840 XSRETURN_UNDEF; 1824 OUTPUT: RETVAL
1825
1826SV *
1827change_resist_msg (int atnr)
1828 CODE:
1829 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1830 ? newSVpv (change_resist_msg [atnr], 0)
1831 : &PL_sv_undef;
1841 OUTPUT: RETVAL 1832 OUTPUT: RETVAL
1842 1833
1843UUID 1834UUID
1844uuid_cur () 1835uuid_cur ()
1845 CODE: 1836 CODE:
1895 CODE: 1886 CODE:
1896 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); 1887 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext);
1897 OUTPUT: 1888 OUTPUT:
1898 RETVAL 1889 RETVAL
1899 1890
1891bool should_invoke (attachable *obj, int event)
1892 CODE:
1893 RETVAL = obj->should_invoke ((event_type)event);
1894 OUTPUT: RETVAL
1895
1900void 1896void
1901debug_trace (attachable *obj, bool on = true) 1897debug_trace (attachable *obj, bool on = true)
1902 CODE: 1898 CODE:
1903 obj->attachable_flags &= ~attachable::F_DEBUG_TRACE; 1899 obj->attachable_flags &= ~attachable::F_DEBUG_TRACE;
1904 if (on) 1900 if (on)
1963int mortals_size () 1959int mortals_size ()
1964 CODE: 1960 CODE:
1965 RETVAL = attachable::mortals.size (); 1961 RETVAL = attachable::mortals.size ();
1966 OUTPUT: RETVAL 1962 OUTPUT: RETVAL
1967 1963
1968const_utf8_string slot_use_name (U32 slot) 1964const_utf8_string slot_name (U32 slot)
1969 ALIAS: 1965 ALIAS:
1966 slot_name = 0
1967 slot_use_name = 1
1970 slot_nonuse_name = 1 1968 slot_nonuse_name = 2
1971 CODE: 1969 CODE:
1972{ 1970{
1973 if (slot >= NUM_BODY_LOCATIONS) 1971 if (slot >= NUM_BODY_LOCATIONS)
1974 croak ("body slot index out of range"); 1972 croak ("body slot index out of range");
1975 1973
1976 switch (ix) 1974 switch (ix)
1977 { 1975 {
1976 case 0: RETVAL = body_locations[slot].name ; break;
1978 case 0: RETVAL = body_locations[slot].use_name; break; 1977 case 1: RETVAL = body_locations[slot].use_name ; break;
1979 case 1: RETVAL = body_locations[slot].nonuse_name; break; 1978 case 2: RETVAL = body_locations[slot].nonuse_name; break;
1980 } 1979 }
1981} 1980}
1982 OUTPUT: 1981 OUTPUT:
1983 RETVAL 1982 RETVAL
1984 1983
2029 OUTPUT: 2028 OUTPUT:
2030 RETVAL 2029 RETVAL
2031 2030
2032object *find_best_object_match (object *op, utf8_string match) 2031object *find_best_object_match (object *op, utf8_string match)
2033 2032
2034object *find_marked_object (object *op)
2035
2036int need_identify (object *obj);
2037
2038int apply_shop_mat (object *shop_mat, object *op); 2033int apply_shop_mat (object *shop_mat, object *op);
2039 2034
2040int move (object *op, int dir, object *originator = op) 2035int move (object *op, int dir, object *originator = op)
2041 CODE: 2036 CODE:
2042 RETVAL = op->move (dir, originator); 2037 RETVAL = op->move (dir, originator);
2094 2089
2095void pick_up (object *who, object *op) 2090void pick_up (object *who, object *op)
2096 2091
2097void update_object (object *op, int action) 2092void update_object (object *op, int action)
2098 2093
2099void change_exp (object *op, uint64 exp, utf8_string skill_name = 0, int flag = 0) 2094void change_exp (object *op, uint64 exp, shstr_tmp skill_name = shstr_tmp (), int flag = 0)
2100 2095
2101void player_lvl_adj (object *who, object *skill = 0) 2096void player_lvl_adj (object *who, object *skill = 0)
2102 2097
2103int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL) 2098int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL)
2104 2099
2120# dumb kludgy misdesigned plug-in api slowly gets on my nerves. 2115# dumb kludgy misdesigned plug-in api slowly gets on my nerves.
2121 2116
2122object *new (utf8_string archetype = 0) 2117object *new (utf8_string archetype = 0)
2123 PROTOTYPE: ;$ 2118 PROTOTYPE: ;$
2124 CODE: 2119 CODE:
2125 RETVAL = archetype ? get_archetype (archetype) : object::create (); 2120 RETVAL = archetype
2121 ? archetype::get (archetype)
2122 : object::create ();
2126 OUTPUT: 2123 OUTPUT:
2127 RETVAL 2124 RETVAL
2128 2125
2129object *generate (utf8_string arch, object *creator) 2126object *generate (utf8_string arch, object *creator)
2130 CODE: 2127 CODE:
2131 object *obj = get_archetype (arch); 2128 object *obj = archetype::get (arch);
2132 fix_generated_item (obj, creator, 0, 0, GT_MINIMAL); 2129 fix_generated_item (obj, creator, 0, 0, GT_MINIMAL);
2133 RETVAL = obj; 2130 RETVAL = obj;
2134 OUTPUT: 2131 OUTPUT:
2135 RETVAL 2132 RETVAL
2136 2133
2146 RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y); 2143 RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y);
2147 2144
2148 if (RETVAL->destroyed ()) 2145 if (RETVAL->destroyed ())
2149 RETVAL = 0; 2146 RETVAL = 0;
2150} 2147}
2148 OUTPUT:
2149 RETVAL
2151 2150
2152shstr 2151shstr
2153object::kv_get (shstr key) 2152object::kv_get (shstr key)
2153 CODE:
2154 RETVAL = THIS->kv.get (key);
2155 OUTPUT:
2156 RETVAL
2154 2157
2155void 2158void
2156object::kv_del (shstr key) 2159object::kv_del (shstr key)
2160 CODE:
2161 THIS->kv.del (key);
2157 2162
2158void 2163void
2159object::kv_set (shstr key, shstr value) 2164object::kv_set (shstr key, shstr value)
2165 CODE:
2166 THIS->kv.set (key, value);
2160 2167
2161object *get_nearest_player (object *ob) 2168object *get_nearest_player (object *ob)
2162 ALIAS: nearest_player = 0 2169 ALIAS: nearest_player = 0
2163 PREINIT: 2170 PREINIT:
2164 extern object *get_nearest_player (object *); 2171 extern object *get_nearest_player (object *);
2367 if (pl->ob && pl->ob->map == THIS) 2374 if (pl->ob && pl->ob->map == THIS)
2368 PUSHs (sv_2mortal (to_sv (pl->ob))); 2375 PUSHs (sv_2mortal (to_sv (pl->ob)));
2369 } 2376 }
2370 2377
2371void 2378void
2379maptile::gen_quadmap (int x, int y, int z)
2380 CODE:
2381 gen_quadmap (THIS, x * 50, y * 50, z);
2382
2383void
2372maptile::add_underlay (SV *data, int offset, int stride, SV *palette) 2384maptile::add_underlay (SV *data, int offset, int stride, SV *palette)
2373 CODE: 2385 CODE:
2374{ 2386{
2375 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV) 2387 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV)
2376 croak ("maptile::add_underlay: palette must be arrayref"); 2388 croak ("maptile::add_underlay: palette must be arrayref");
2392 2404
2393 if (IN_RANGE_EXC (offs, 0, idxlen)) 2405 if (IN_RANGE_EXC (offs, 0, idxlen))
2394 { 2406 {
2395 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) 2407 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0))
2396 { 2408 {
2397 object *ob = get_archetype (cfSvPVutf8_nolen (*elem)); 2409 object *ob = archetype::get (cfSvPVutf8_nolen (*elem));
2398 ob->flag [FLAG_NO_MAP_SAVE] = true; 2410 ob->flag [FLAG_NO_MAP_SAVE] = true;
2399 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); 2411 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY);
2400 2412
2401 if (ob->randomitems && !ob->above) 2413 if (ob->randomitems && !ob->above)
2402 { 2414 {
2406 op->flag [FLAG_NO_MAP_SAVE] = true; 2418 op->flag [FLAG_NO_MAP_SAVE] = true;
2407 // TODO: if this is a pickable object, then the item 2419 // TODO: if this is a pickable object, then the item
2408 // will at a bit weird - saving inside the player 2420 // will at a bit weird - saving inside the player
2409 // will clear the flag, but when the player drops 2421 // will clear the flag, but when the player drops
2410 // it without logging out, it keeps the flag. 2422 // it without logging out, it keeps the flag.
2411 // nobody ahs reported this, but this can be rather 2423 // nobody has reported this, but this can be rather
2412 // annoying on persistent maps. 2424 // annoying on persistent maps.
2413 } 2425 }
2414 } 2426 }
2415 } 2427 }
2416 } 2428 }
2417
2418 skip: ; 2429 skip: ;
2419 } 2430 }
2420} 2431}
2421 2432
2422void 2433void
2453 for (int x = 0; x < THIS->width; ++x) 2464 for (int x = 0; x < THIS->width; ++x)
2454 for (int y = 0; y < THIS->height; ++y) 2465 for (int y = 0; y < THIS->height; ++y)
2455 { 2466 {
2456 region *rgn = THIS->region (x, y); 2467 region *rgn = THIS->region (x, y);
2457 2468
2458 //fprintf (stderr, "%d,%d %f %p\n", x, y, rgn->treasure_density,rgn->treasure);//D
2459 if (object *op = THIS->at (x, y).top) 2469 if (object *op = THIS->at (x, y).top)
2460 if (rgn->treasure && rndm () < rgn->treasure_density) 2470 if (rgn->treasure && rndm () < rgn->treasure_density)
2461 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty); 2471 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty);
2462 } 2472 }
2463 2473
2469 if (oblinkpt *obp = map->find_link (connection)) 2479 if (oblinkpt *obp = map->find_link (connection))
2470 for (objectlink *ol = obp->link; ol; ol = ol->next) 2480 for (objectlink *ol = obp->link; ol; ol = ol->next)
2471 XPUSHs (sv_2mortal (to_sv ((object *)ol->ob))); 2481 XPUSHs (sv_2mortal (to_sv ((object *)ol->ob)));
2472 2482
2473void 2483void
2474get_map_flags (maptile *map, int x, int y) 2484xy_normalise (maptile *map, int x, int y, int dir = 0)
2475 PPCODE: 2485 PPCODE:
2476{ 2486{
2477 maptile *nmap = 0; 2487 mapxy pos (map, x, y);
2478 I16 nx = 0, ny = 0; 2488 if (!pos.move (dir).normalise ())
2489 XSRETURN_EMPTY;
2479 2490
2480 PUTBACK;
2481 int flags = get_map_flags (map, &nmap, x, y, &nx, &ny);
2482 SPAGAIN;
2483
2484 EXTEND (SP, 4); 2491 EXTEND (SP, 3);
2485 PUSHs (sv_2mortal (newSViv (flags)));
2486
2487 if (GIMME_V == G_ARRAY)
2488 {
2489 PUSHs (sv_2mortal (to_sv (nmap))); 2492 PUSHs (sv_2mortal (to_sv (pos.m)));
2490 PUSHs (sv_2mortal (newSViv (nx))); 2493 PUSHs (sv_2mortal (to_sv (pos.x)));
2491 PUSHs (sv_2mortal (newSViv (ny))); 2494 PUSHs (sv_2mortal (to_sv (pos.y)));
2492 }
2493} 2495}
2494 2496
2495mapspace * 2497mapspace *
2496ms (maptile *map, unsigned int x, unsigned int y) 2498ms (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2497 PROTOTYPE: $$$ 2499 PROTOTYPE: $$$;$
2498 CODE: 2500 CODE:
2499{ 2501{
2500 maptile *nmap = 0; 2502 mapxy pos (map, x, y);
2501 I16 nx, ny; 2503 if (!pos.move (dir).normalise ())
2502
2503 PUTBACK;
2504 get_map_flags (map, &nmap, x, y, &nx, &ny);
2505 SPAGAIN;
2506
2507 if (!nmap)
2508 XSRETURN_UNDEF; 2504 XSRETURN_UNDEF;
2509 2505
2510 RETVAL = &nmap->at (nx, ny); 2506 RETVAL = &*pos;
2511} 2507}
2512 OUTPUT: 2508 OUTPUT:
2513 RETVAL 2509 RETVAL
2514 2510
2515void 2511void
2516at (maptile *map, unsigned int x, unsigned int y) 2512at (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2517 PROTOTYPE: $$$ 2513 PROTOTYPE: $$$;$
2518 PPCODE: 2514 PPCODE:
2519{ 2515 mapxy pos (map, x, y);
2520 maptile *nmap = 0; 2516 if (pos.move (dir).normalise ())
2521 I16 nx, ny;
2522
2523 PUTBACK;
2524 get_map_flags (map, &nmap, x, y, &nx, &ny);
2525 SPAGAIN;
2526
2527 if (nmap)
2528 for (object *o = nmap->at (nx, ny).bot; o; o = o->above) 2517 for (object *o = pos->bot; o; o = o->above)
2529 XPUSHs (sv_2mortal (to_sv (o))); 2518 XPUSHs (sv_2mortal (to_sv (o)));
2530}
2531 2519
2532SV * 2520SV *
2533bot_at (maptile *map, unsigned int x, unsigned int y) 2521bot_at (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2534 PROTOTYPE: $$$ 2522 PROTOTYPE: $$$;$
2535 ALIAS: 2523 ALIAS:
2536 top_at = 1 2524 top_at = 1
2537 flags_at = 2 2525 flags_at = 2
2538 light_at = 3 2526 light_at = 3
2539 move_block_at = 4 2527 move_block_at = 4
2540 move_slow_at = 5 2528 move_slow_at = 5
2541 move_on_at = 6 2529 move_on_at = 6
2542 move_off_at = 7 2530 move_off_at = 7
2543 CODE: 2531 CODE:
2544{ 2532{
2545 sint16 nx = x; 2533 mapxy pos (map, x, y);
2546 sint16 ny = y; 2534 if (!pos.move (dir).normalise ())
2547
2548 if (!xy_normalise (map, nx, ny))
2549 XSRETURN_UNDEF; 2535 XSRETURN_UNDEF;
2550 2536
2551 mapspace &ms = map->at (nx, ny); 2537 mapspace &ms = *pos;
2552 2538
2553 ms.update (); 2539 ms.update ();
2554 2540
2555 switch (ix) 2541 switch (ix)
2556 { 2542 {
2566} 2552}
2567 OUTPUT: RETVAL 2553 OUTPUT: RETVAL
2568 2554
2569# worst xs function of my life 2555# worst xs function of my life
2570bool 2556bool
2571_create_random_map (\ 2557_create_random_map (maptile *self, SV *options)
2572 maptile *self,\
2573 utf8_string wallstyle,\
2574 utf8_string wall_name,\
2575 utf8_string floorstyle,\
2576 utf8_string monsterstyle,\
2577 utf8_string treasurestyle,\
2578 utf8_string layoutstyle,\
2579 utf8_string doorstyle,\
2580 utf8_string decorstyle,\
2581 utf8_string miningstyle,\
2582 utf8_string origin_map,\
2583 utf8_string final_map,\
2584 utf8_string exitstyle,\
2585 utf8_string this_map,\
2586 utf8_string exit_on_final_map,\
2587 int xsize,\
2588 int ysize,\
2589 int expand2x,\
2590 int layoutoptions1,\
2591 int layoutoptions2,\
2592 int layoutoptions3,\
2593 int symmetry,\
2594 int difficulty,\
2595 int difficulty_given,\
2596 float difficulty_increase,\
2597 int dungeon_level,\
2598 int dungeon_depth,\
2599 int decoroptions,\
2600 int orientation,\
2601 int origin_y,\
2602 int origin_x,\
2603 U32 random_seed,\
2604 val64 total_map_hp,\
2605 int map_layout_style,\
2606 int treasureoptions,\
2607 int symmetry_used,\
2608 region *region,\
2609 utf8_string custom\
2610)
2611 CODE: 2558 CODE:
2612{ 2559{
2613 random_map_params rmp; 2560 random_map_params rmp ((HV *)SvRV (options));
2614
2615 assign (rmp.wallstyle , wallstyle);
2616 assign (rmp.wall_name , wall_name);
2617 assign (rmp.floorstyle , floorstyle);
2618 assign (rmp.monsterstyle , monsterstyle);
2619 assign (rmp.treasurestyle , treasurestyle);
2620 assign (rmp.layoutstyle , layoutstyle);
2621 assign (rmp.doorstyle , doorstyle);
2622 assign (rmp.decorstyle , decorstyle);
2623 assign (rmp.miningstyle , miningstyle);
2624 assign (rmp.exitstyle , exitstyle);
2625 assign (rmp.exit_on_final_map, exit_on_final_map);
2626
2627 rmp.origin_map = origin_map;
2628 rmp.final_map = final_map;
2629 rmp.this_map = this_map;
2630 rmp.xsize = xsize;
2631 rmp.ysize = ysize;
2632 rmp.expand2x = expand2x;
2633 rmp.layoutoptions1 = layoutoptions1;
2634 rmp.layoutoptions2 = layoutoptions2;
2635 rmp.layoutoptions3 = layoutoptions3;
2636 rmp.symmetry = symmetry;
2637 rmp.difficulty = difficulty;
2638 rmp.difficulty_given = difficulty_given;
2639 rmp.difficulty_increase = difficulty_increase;
2640 rmp.dungeon_level = dungeon_level;
2641 rmp.dungeon_depth = dungeon_depth;
2642 rmp.decoroptions = decoroptions;
2643 rmp.orientation = orientation;
2644 rmp.origin_y = origin_y;
2645 rmp.origin_x = origin_x;
2646 rmp.random_seed = random_seed;
2647 rmp.total_map_hp = (uint64_t) total_map_hp;
2648 rmp.map_layout_style = map_layout_style;
2649 rmp.treasureoptions = treasureoptions;
2650 rmp.symmetry_used = symmetry_used;
2651 rmp.region = region;
2652 rmp.custom = custom;
2653
2654 RETVAL = self->generate_random_map (&rmp); 2561 RETVAL = self->generate_random_map (&rmp);
2655} 2562}
2656 OUTPUT: 2563 OUTPUT:
2657 RETVAL 2564 RETVAL
2658 2565
2668 OUTPUT: RETVAL 2575 OUTPUT: RETVAL
2669 2576
2670archetype *archetypes (U32 index) 2577archetype *archetypes (U32 index)
2671 CODE: 2578 CODE:
2672 RETVAL = index < archetypes.size () ? archetypes [index] : 0; 2579 RETVAL = index < archetypes.size () ? archetypes [index] : 0;
2580 OUTPUT: RETVAL
2581
2582int skillvec_size ()
2583 CODE:
2584 RETVAL = skillvec.size ();
2585 OUTPUT: RETVAL
2586
2587archetype *skillvec (U32 index)
2588 CODE:
2589 RETVAL = index < skillvec.size () ? (archetype *)(object *)skillvec [index] : 0;
2673 OUTPUT: RETVAL 2590 OUTPUT: RETVAL
2674 2591
2675INCLUDE: $PERL $srcdir/genacc archetype $srcdir/../include/object.h | 2592INCLUDE: $PERL $srcdir/genacc archetype $srcdir/../include/object.h |
2676 2593
2677MODULE = cf PACKAGE = cf::party 2594MODULE = cf PACKAGE = cf::party
2690list () 2607list ()
2691 PPCODE: 2608 PPCODE:
2692 for_all_regions (rgn) 2609 for_all_regions (rgn)
2693 XPUSHs (sv_2mortal (to_sv (rgn))); 2610 XPUSHs (sv_2mortal (to_sv (rgn)));
2694 2611
2695region *find (utf8_string name)
2696 PROTOTYPE: $
2697 CODE:
2698 RETVAL = region::find (name);
2699 OUTPUT: RETVAL
2700
2701int specificity (region *rgn) 2612int specificity (region *rgn)
2702 CODE: 2613 CODE:
2703 RETVAL = 0; 2614 RETVAL = 0;
2704 while (rgn = rgn->parent) 2615 while (rgn = rgn->parent)
2705 RETVAL++; 2616 RETVAL++;
2733list () 2644list ()
2734 PPCODE: 2645 PPCODE:
2735 EXTEND (SP, clients.size ()); 2646 EXTEND (SP, clients.size ());
2736 for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i) 2647 for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i)
2737 PUSHs (sv_2mortal (to_sv (*i))); 2648 PUSHs (sv_2mortal (to_sv (*i)));
2649
2650STRLEN
2651client::inbuf_append (SV *data)
2652 CODE:
2653{
2654 STRLEN len;
2655 char *ptr = SvPVbyte (data, len);
2656
2657 min_it (len, sizeof (THIS->inbuf) - THIS->inbuf_len);
2658 memcpy (THIS->inbuf + THIS->inbuf_len, ptr, len);
2659 THIS->inbuf_len += len;
2660
2661 THIS->inbuf_handle ();
2662
2663 RETVAL = len;
2664}
2665 OUTPUT: RETVAL
2738 2666
2739void 2667void
2740client::send_packet (SV *packet) 2668client::send_packet (SV *packet)
2741 CODE: 2669 CODE:
2742{ 2670{
2798faceidx face_find (utf8_string name, faceidx defidx = 0) 2726faceidx face_find (utf8_string name, faceidx defidx = 0)
2799 2727
2800faceidx alloc (utf8_string name) 2728faceidx alloc (utf8_string name)
2801 CODE: 2729 CODE:
2802{ 2730{
2803 do 2731 RETVAL = face_alloc ();
2804 {
2805 RETVAL = faces.size ();
2806 faces.resize (RETVAL + 1);
2807 }
2808 while (!RETVAL); // crude way to leave index 0
2809 2732
2810 faces [RETVAL].name = name; 2733 faces [RETVAL].name = name;
2811 facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL)); 2734 facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL));
2812 2735
2813 if (!strcmp (name, BLANK_FACE_NAME )) blank_face = RETVAL; 2736 if (!strcmp (name, BLANK_FACE_NAME )) blank_face = RETVAL;
2814 if (!strcmp (name, EMPTY_FACE_NAME )) empty_face = RETVAL; 2737 if (!strcmp (name, EMPTY_FACE_NAME )) empty_face = RETVAL;
2815 if (!strcmp (name, MAGICMOUTH_FACE_NAME)) magicmouth_face = RETVAL; 2738 if (!strcmp (name, MAGICMOUTH_FACE_NAME)) magicmouth_face = RETVAL;
2816} 2739}
2740 OUTPUT: RETVAL
2741
2742faceidx faces_size ()
2743 CODE:
2744 RETVAL = faces.size ();
2817 OUTPUT: RETVAL 2745 OUTPUT: RETVAL
2818 2746
2819void set_type (faceidx idx, int value) 2747void set_type (faceidx idx, int value)
2820 ALIAS: 2748 ALIAS:
2821 set_type = 0 2749 set_type = 0
2836 2764
2837void set_data (faceidx idx, int faceset, SV *data, SV *chksum) 2765void set_data (faceidx idx, int faceset, SV *data, SV *chksum)
2838 CODE: 2766 CODE:
2839{ 2767{
2840 faceinfo *f = face_info (idx); assert (f); 2768 faceinfo *f = face_info (idx); assert (f);
2841 facedata *d = &(faceset ? f->data64 : f->data32); 2769 facedata *d = f->face + faceset;
2842 sv_to (data, d->data); 2770 sv_to (data, d->data);
2843 STRLEN clen; 2771 STRLEN clen;
2844 char *cdata = SvPVbyte (chksum, clen); 2772 char *cdata = SvPVbyte (chksum, clen);
2845 clen = min (CHKSUM_MAXLEN, clen);
2846 2773
2774 assert (("cf::face::set_data called with too long checksum", clen <= CHKSUM_MAXLEN));
2847 assert (("cf::face::set_data must be called with a non-empty checksum", clen)); 2775 assert (("cf::face::set_data must be called with a non-empty checksum", clen));
2848 2776
2849 if (clen != d->chksum_len || memcmp (d->chksum, cdata, clen)) 2777 if (clen != d->chksum_len || memcmp (d->chksum, cdata, clen))
2850 { 2778 {
2851 d->chksum_len = clen; 2779 d->chksum_len = clen;
2852 memcpy (d->chksum, cdata, clen); 2780 memcpy (d->chksum, cdata, clen);
2853 2781
2854 // invalidate existing client face info 2782 // invalidate existing client face info
2855 for_all_clients (ns) 2783 for_all_clients (ns)
2856 if (ns->faceset == faceset) 2784 ns->invalidate_face (idx);
2857 {
2858 ns->faces_sent [idx] = false;
2859 ns->force_newmap = true;
2860 }
2861 } 2785 }
2862} 2786}
2863 2787
2864int get_data_size (faceidx idx, int faceset = 0) 2788int get_data_size (faceidx idx, int faceset = 0)
2865 CODE: 2789 CODE:
2867 if (!d) XSRETURN_UNDEF; 2791 if (!d) XSRETURN_UNDEF;
2868 RETVAL = d->data.size (); 2792 RETVAL = d->data.size ();
2869 OUTPUT: 2793 OUTPUT:
2870 RETVAL 2794 RETVAL
2871 2795
2796void set_meta (faceidx idx, SV *sv)
2797 CODE:
2798{
2799 faceinfo *f = face_info (idx); assert (f);
2800 SvREFCNT_dec (f->meta_hv);
2801 f->meta_hv = SvOK (sv) ? (HV *)SvREFCNT_inc (SvRV (sv)) : 0;
2802}
2803
2804SV *mangle_chksum (SV *chksum)
2805 CODE:
2806 STRLEN len;
2807 char *data = SvPVbyte (chksum, len);
2808 RETVAL = newSVpvn (data, min (len, CHKSUM_MAXLEN));
2809 OUTPUT:
2810 RETVAL
2811
2872SV *get_chksum (faceidx idx, int faceset = 0) 2812SV *get_chksum (faceidx idx, int faceset = 0)
2873 CODE: 2813 CODE:
2874 facedata *d = face_data (idx, faceset); 2814 facedata *d = face_data (idx, faceset);
2875 if (!d) XSRETURN_UNDEF; 2815 if (!d) XSRETURN_UNDEF;
2876 RETVAL = newSVpvn ((char *)d->chksum, d->chksum_len); 2816 RETVAL = newSVpvn ((char *)d->chksum, d->chksum_len);
2877 OUTPUT: 2817 OUTPUT:
2878 RETVAL 2818 RETVAL
2879 2819
2820int get_type (faceidx idx)
2821 CODE:
2822 faceinfo *f = face_info (idx);
2823 if (!f) XSRETURN_UNDEF;
2824 RETVAL = f->type;
2825 OUTPUT:
2826 RETVAL
2827
2828SV *get_name (faceidx idx)
2829 CODE:
2830 faceinfo *f = face_info (idx);
2831 if (!f) XSRETURN_UNDEF;
2832 RETVAL = to_sv (f->name);
2833 OUTPUT:
2834 RETVAL
2835
2880SV *get_data (faceidx idx, int faceset = 0) 2836SV *get_data (faceidx idx, int faceset = 0)
2881 CODE: 2837 CODE:
2882 facedata *d = face_data (idx, faceset); 2838 facedata *d = face_data (idx, faceset);
2883 if (!d) XSRETURN_UNDEF; 2839 if (!d) XSRETURN_UNDEF;
2884 RETVAL = newSVpvn (d->data.data (), d->data.length ()); 2840 RETVAL = newSVpvn (d->data, d->data.size ());
2885 OUTPUT: 2841 OUTPUT:
2886 RETVAL 2842 RETVAL
2887 2843
2844SV *get_meta (faceidx idx)
2845 CODE:
2846 faceinfo *f = face_info (idx); assert (f);
2847 if (!f || !f->meta_hv) XSRETURN_UNDEF;
2848 RETVAL = newRV_inc ((SV *)f->meta_hv);
2849 OUTPUT:
2850 RETVAL
2851
2888void invalidate (faceidx idx) 2852void invalidate (faceidx idx)
2889 CODE: 2853 CODE:
2890 for_all_clients (ns) 2854 for_all_clients (ns)
2891 { 2855 ns->invalidate_face (idx);
2892 ns->faces_sent [idx] = false;
2893 ns->force_newmap = true;
2894 }
2895 2856
2896void invalidate_all () 2857void invalidate_all ()
2897 CODE: 2858 CODE:
2898 for_all_clients (ns) 2859 for_all_clients (ns)
2899 { 2860 ns->invalidate_all_faces ();
2900 ns->faces_sent.reset ();
2901 ns->force_newmap = true;
2902 }
2903 2861
2904MODULE = cf PACKAGE = cf::anim PREFIX = anim_ 2862MODULE = cf PACKAGE = cf::anim PREFIX = anim_
2905 2863
2906#INCLUDE: $PERL $srcdir/genacc faceset $srcdir/../include/anim.h | 2864#INCLUDE: $PERL $srcdir/genacc faceset $srcdir/../include/anim.h |
2907 2865
2911 OUTPUT: RETVAL 2869 OUTPUT: RETVAL
2912 2870
2913animidx set (utf8_string name, SV *frames, int facings = 1) 2871animidx set (utf8_string name, SV *frames, int facings = 1)
2914 CODE: 2872 CODE:
2915{ 2873{
2916 if (!SvROK (frames) && SvTYPE (SvRV (frames)) != SVt_PVAV) 2874 if (!SvROK (frames) && SvTYPE (SvRV (frames)) != SVt_PVAV)
2917 croak ("frames must be an arrayref"); 2875 croak ("frames must be an arrayref");
2918 2876
2919 AV *av = (AV *)SvRV (frames); 2877 AV *av = (AV *)SvRV (frames);
2920 2878
2921 animation *anim = &animation::find (name); 2879 animation *anim = &animation::find (name);
2922 if (anim->number) 2880 if (anim->number)
2923 { 2881 {
2924 anim->resize (av_len (av) + 1); 2882 anim->resize (av_len (av) + 1);
2925 anim->facings = facings; 2883 anim->facings = facings;
2926 } 2884 }
2954 sv_to (sv, self); 2912 sv_to (sv, self);
2955 delete self; 2913 delete self;
2956 2914
2957MODULE = cf PACKAGE = cf::object::thawer 2915MODULE = cf PACKAGE = cf::object::thawer
2958 2916
2959INCLUDE: $PERL $srcdir/genacc object_thawer $srcdir/../include/cfperl.h | 2917INCLUDE: $PERL $srcdir/genacc object_thawer $srcdir/../include/freezethaw.h |
2918
2919bool
2920errors_are_fatal (bool fatal)
2921 CODE:
2922 RETVAL = object_thawer::errors_are_fatal;
2923 object_thawer::errors_are_fatal = fatal;
2924 OUTPUT:
2925 RETVAL
2960 2926
2961SV * 2927SV *
2962new_from_file (char *klass, octet_string path) 2928new_from_file (char *klass, octet_string path)
2963 CODE: 2929 CODE:
2964 object_thawer *f = new object_thawer (path); 2930 object_thawer *f = new object_thawer (path);
2990 XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ()))); 2956 XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ())));
2991 2957
2992 self->skip (); 2958 self->skip ();
2993 } 2959 }
2994 2960
2961MODULE = cf PACKAGE = cf::layout
2962
2963INCLUDE: $PERL $srcdir/genacc layout $srcdir/../include/rmg.h |
2964

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines