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.384 by root, Fri Apr 30 21:00:40 2010 UTC vs.
Revision 1.431 by root, Sat Dec 1 20:22:13 2018 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2018 Marc Alexander Lehmann / the Deliantra team
4 * Copyright (©) 2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 5 * Copyright (©) 2006,2007,2008,2009,2010,2012,2015 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * 6 *
6 * Deliantra is free software: you can redistribute it and/or modify it under 7 * Deliantra is free software: you can redistribute it and/or modify it under
7 * the terms of the Affero GNU General Public License as published by the 8 * the terms of the Affero GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your 9 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version. 10 * option) any later version.
10 * 11 *
11 * This program is distributed in the hope that it will be useful, 12 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. 15 * GNU General Public License for more details.
15 * 16 *
16 * You should have received a copy of the Affero GNU General Public License 17 * 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 18 * and the GNU General Public License along with this program. If not, see
18 * <http://www.gnu.org/licenses/>. 19 * <http://www.gnu.org/licenses/>.
19 * 20 *
20 * The authors can be reached via e-mail to <support@deliantra.net> 21 * The authors can be reached via e-mail to <support@deliantra.net>
21 */ 22 */
22 23
23#include "autoconf.h" 24#include "autoconf.h"
25
26#define CFPERL 1
24 27
25#if HAVE_EXECINFO_H 28#if HAVE_EXECINFO_H
26# include <execinfo.h> 29# include <execinfo.h>
27#endif 30#endif
28 31
29#include <cstdarg> 32#include <cstdarg>
30#include <typeinfo> 33#include <typeinfo>
31 34
32#include "global.h" 35#include "global.h"
33#include "../random_maps/random_map.h" 36#include "rmg.h"
37#include "noise.h"
34#include "evthread.h" 38#include "evthread.h"
35#include "sproto.h" 39#include "sproto.h"
36 40
37#include <unistd.h> 41#include <unistd.h>
38#if _POSIX_MEMLOCK 42#if _POSIX_MEMLOCK
66static int tick_inhibit; 70static int tick_inhibit;
67static int tick_pending; 71static int tick_pending;
68 72
69global gbl_ev; 73global gbl_ev;
70static AV *cb_global, *cb_attachable, *cb_object, *cb_player, *cb_client, *cb_type, *cb_map; 74static 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; 75static SV *sv_runtime, *sv_tick_start, *sv_next_tick, *sv_now, *sv_server_tick;
72static AV *av_reflect; 76static AV *av_reflect;
73 77
74bitset<NUM_EVENT_TYPES> ev_want_event; 78bitset<NUM_EVENT_TYPES> ev_want_event;
75bitset<NUM_TYPES> ev_want_type; 79bitset<NUM_TYPES> ev_want_type;
76 80
84 *stash_cf_client_wrap, 88 *stash_cf_client_wrap,
85 *stash_cf_arch_wrap, 89 *stash_cf_arch_wrap,
86 *stash_cf_party_wrap, 90 *stash_cf_party_wrap,
87 *stash_cf_region_wrap, 91 *stash_cf_region_wrap,
88 *stash_cf_living_wrap, 92 *stash_cf_living_wrap,
93 *stash_cf_layout_wrap,
89 *stash_ext_map_world; 94 *stash_ext_map_world;
90 95
91static SV 96static SV
92 *cv_cf_do_invoke, 97 *cv_cf_do_invoke,
93 *cv_cf__can_merge, 98 *cv_cf__can_merge,
94 *cv_cf_client_send_msg, 99 *cv_cf_client_send_msg,
100 *cv_cf_ix,
95 *cv_cf_tick, 101 *cv_cf_tick,
96 *cv_cf_match_match; 102 *cv_cf_match_match;
97 103
98#ifndef newSVpv_utf8 104#ifndef newSVpv_utf8
99static SV * 105static SV *
122 128
123 return sv; 129 return sv;
124} 130}
125#endif 131#endif
126 132
127static noinline utf8_string 133ecb_noinline utf8_string
128cfSvPVutf8_nolen (SV *sv) 134cfSvPVutf8_nolen (SV *sv)
129{ 135{
130 SvGETMAGIC (sv); 136 SvGETMAGIC (sv);
131 137
132 if (SvPOK (sv)) 138 if (SvPOK (sv))
251 { 257 {
252 static int last_mortalcount; 258 static int last_mortalcount;
253 if (mortals.size () != last_mortalcount) 259 if (mortals.size () != last_mortalcount)
254 { 260 {
255 last_mortalcount = mortals.size (); 261 last_mortalcount = mortals.size ();
256 LOG (llevInfo, "%d mortals.\n", (int)mortals.size ()); 262 object *specimen = is_a<object> (mortals [rndm (mortals.size ())]);
263
264 LOG (llevInfo, "%d mortals (random specimen: %s).\n",
265 (int)mortals.size (), specimen ? specimen->debug_desc () : "(not an object)");
257 266
258 if (0) 267 if (0)
259 { 268 {
260 for (int j = 0; j < mortals.size (); ++j)//D 269 for (int j = 0; j < mortals.size (); ++j)//D
261 fprintf (stderr, "%d:%s %p ", j, &((object *)mortals[j])->name, mortals[j]);//D 270 fprintf (stderr, "%d:%s %p ", j, &((object *)mortals[j])->name, mortals[j]);//D
354////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 363//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
355 364
356static SV * 365static SV *
357newSVptr (void *ptr, HV *stash, HV *hv) 366newSVptr (void *ptr, HV *stash, HV *hv)
358{ 367{
359 SV *sv;
360
361 if (!ptr) 368 if (!ptr)
362 return newSV (0); 369 return newSV (0);
363 370
364 sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, 0, (char *)ptr, 0); 371 sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, 0, (char *)ptr, 0);
365 return sv_bless (newRV_noinc ((SV *)hv), stash); 372 return sv_bless (newRV_noinc ((SV *)hv), stash);
366} 373}
367 374
368static SV * 375ecb_noinline static SV *
369newSVptr (void *ptr, HV *stash) 376newSVptr (void *ptr, HV *stash)
370{ 377{
371 return newSVptr (ptr, stash, newHV ()); 378 return newSVptr (ptr, stash, newHV ());
372} 379}
373 380
388 return 0; 395 return 0;
389} 396}
390 397
391MGVTBL attachable::vtbl = {0, 0, 0, 0, attachable_free}; 398MGVTBL attachable::vtbl = {0, 0, 0, 0, attachable_free};
392 399
393static SV * 400ecb_noinline static SV *
394newSVattachable (attachable *obj, HV *stash) 401newSVattachable (attachable *obj, HV *stash)
395{ 402{
396 if (!obj) 403 if (!obj)
397 return newSV (0); 404 return newSV (0);
398 405
452 croak ("object of type %s expected", klass); 459 croak ("object of type %s expected", klass);
453 460
454 return SvPTR_nc (sv); 461 return SvPTR_nc (sv);
455} 462}
456 463
457static long noinline 464ecb_noinline static long
458SvPTR_ornull (SV *sv, const char *klass) 465SvPTR_ornull (SV *sv, const char *klass)
459{ 466{
460 if (expect_false (!SvOK (sv))) return 0; 467 if (expect_false (!SvOK (sv))) return 0;
461 468
462 return SvPTR (sv, klass); 469 return SvPTR (sv, klass);
463} 470}
464 471
465static long noinline 472ecb_noinline static long
466SvPTR_ornull_client (SV *sv) 473SvPTR_ornull_client (SV *sv)
467{ 474{
468 if (expect_false (!SvOK (sv))) return 0; 475 if (expect_false (!SvOK (sv))) return 0;
469 476
470 if (!SvROK (sv) 477 if (!SvROK (sv)
473 croak ("object of type cf::client expected"); 480 croak ("object of type cf::client expected");
474 481
475 return SvPTR_nc (sv); 482 return SvPTR_nc (sv);
476} 483}
477 484
478static long noinline 485ecb_noinline static long
479SvPTR_ornull_object (SV *sv) 486SvPTR_ornull_object (SV *sv)
480{ 487{
481 if (expect_false (!SvOK (sv))) return 0; 488 if (expect_false (!SvOK (sv))) return 0;
482 489
483 if (!SvROK (sv) 490 if (!SvROK (sv)
488 croak ("object of type cf::object expected"); 495 croak ("object of type cf::object expected");
489 496
490 return SvPTR_nc (sv); 497 return SvPTR_nc (sv);
491} 498}
492 499
493static long noinline 500ecb_noinline static long
494SvPTR_ornull_maptile (SV *sv) 501SvPTR_ornull_maptile (SV *sv)
495{ 502{
496 if (expect_false (!SvOK (sv))) return 0; 503 if (expect_false (!SvOK (sv))) return 0;
497 504
498 if (!SvROK (sv) 505 if (!SvROK (sv)
502 croak ("object of type cf::map expected"); 509 croak ("object of type cf::map expected");
503 510
504 return SvPTR_nc (sv); 511 return SvPTR_nc (sv);
505} 512}
506 513
507static long noinline 514ecb_noinline static long
508SvPTR_ornull_player (SV *sv) 515SvPTR_ornull_player (SV *sv)
509{ 516{
510 if (expect_false (!SvOK (sv))) return 0; 517 if (expect_false (!SvOK (sv))) return 0;
511 518
512 if (!SvROK (sv) 519 if (!SvROK (sv)
532static inline SV *to_sv (unsigned long long v) { return newSVval64 (v); } 539static inline SV *to_sv (unsigned long long v) { return newSVval64 (v); }
533static inline SV *to_sv (float v) { return newSVnv (v); } 540static inline SV *to_sv (float v) { return newSVnv (v); }
534static inline SV *to_sv (double v) { return newSVnv (v); } 541static inline SV *to_sv (double v) { return newSVnv (v); }
535static inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); } 542static inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); }
536static inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); } 543static inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); }
544// gcc dislikes noinline on to_sv
537static inline SV *to_sv (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); } 545ecb_noinline static SV *to_sv_ni (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); }
546static inline SV *to_sv (object * v) { return to_sv_ni (v); }
538static inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); } 547static inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); }
539static inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); } 548static inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); }
540static inline SV *to_sv (region * v) { return newSVattachable (v, stash_cf_region_wrap); } 549static inline SV *to_sv (region * v) { return newSVattachable (v, stash_cf_region_wrap); }
541static inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); } 550static inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); }
542static inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } 551static inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); }
543static inline SV *to_sv (mapspace * v) { return newSVptr (v, stash_cf_mapspace_wrap); } 552static inline SV *to_sv (mapspace * v) { return newSVptr (v, stash_cf_mapspace_wrap); }
553static inline SV *to_sv (layout * v) { return newSVptr (v, stash_cf_layout_wrap); }
544 554
545static inline SV *to_sv (object & v) { return to_sv (&v); } 555static inline SV *to_sv (object & v) { return to_sv (&v); }
546static inline SV *to_sv (living & v) { return to_sv (&v); } 556static inline SV *to_sv (living & v) { return to_sv (&v); }
547 557
548static inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); } 558static inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); }
594static inline void sv_to (SV *sv, region * &v) { v = (region *) (attachable *)SvPTR_ornull (sv, "cf::region"); } 604static inline void sv_to (SV *sv, region * &v) { v = (region *) (attachable *)SvPTR_ornull (sv, "cf::region"); }
595static inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } 605static inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); }
596static inline void sv_to (SV *sv, partylist * &v) { v = (partylist *) SvPTR_ornull (sv, "cf::party"); } 606static inline void sv_to (SV *sv, partylist * &v) { v = (partylist *) SvPTR_ornull (sv, "cf::party"); }
597static inline void sv_to (SV *sv, living * &v) { v = (living *) SvPTR_ornull (sv, "cf::living"); } 607static inline void sv_to (SV *sv, living * &v) { v = (living *) SvPTR_ornull (sv, "cf::living"); }
598static inline void sv_to (SV *sv, mapspace * &v) { v = (mapspace *) SvPTR_ornull (sv, "cf::mapspace"); } 608static inline void sv_to (SV *sv, mapspace * &v) { v = (mapspace *) SvPTR_ornull (sv, "cf::mapspace"); }
609static inline void sv_to (SV *sv, layout * &v) { v = (layout *) SvPTR_ornull (sv, "cf::layout"); }
599static inline void sv_to (SV *sv, object_freezer * &v) { v = (object_freezer *) SvPTR_ornull (sv, "cf::object::freezer"); } 610static inline void sv_to (SV *sv, object_freezer * &v) { v = (object_freezer *) SvPTR_ornull (sv, "cf::object::freezer"); }
600static inline void sv_to (SV *sv, object_thawer * &v) { v = (object_thawer *) SvPTR_ornull (sv, "cf::object::thawer" ); } 611static inline void sv_to (SV *sv, object_thawer * &v) { v = (object_thawer *) SvPTR_ornull (sv, "cf::object::thawer" ); }
601 612
602//static inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; } 613//static inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; }
603static inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); } 614static inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); }
616static inline void sv_to (SV *sv, std::string &v) 627static inline void sv_to (SV *sv, std::string &v)
617{ 628{
618 STRLEN len; 629 STRLEN len;
619 char *data = SvPVbyte (sv, len); 630 char *data = SvPVbyte (sv, len);
620 v.assign (data, len); 631 v.assign (data, len);
632}
633
634static inline void sv_to (SV *sv, refcnt_buf &v)
635{
636 STRLEN len;
637 char *data = SvPVbyte (sv, len);
638 refcnt_buf buf (data, len);
639 v = buf;
621} 640}
622 641
623static inline void sv_to (SV *sv, UUID &v) 642static inline void sv_to (SV *sv, UUID &v)
624{ 643{
625 if (!v.parse (SvPV_nolen (sv))) 644 if (!v.parse (SvPV_nolen (sv)))
710 return sv; 729 return sv;
711} 730}
712 731
713// typemap support, mostly to avoid excessive inlining 732// typemap support, mostly to avoid excessive inlining
714template<class type> 733template<class type>
715static void noinline 734ecb_noinline static void
716cf_obj_to (SV *arg, type &var) 735cf_obj_to (SV *arg, type &var)
717{ 736{
718 sv_to (arg, var); 737 sv_to (arg, var);
719 if (expect_false (!var)) 738 if (expect_false (!var))
720 croak ("must not pass invalid/null cf_obj here"); 739 croak ("must not pass invalid/null cf_obj here");
721} 740}
722 741
723template<class object> 742template<class object>
724static void noinline 743ecb_noinline static void
725cf_obj_ornull_to (SV *arg, object *&var) 744cf_obj_ornull_to (SV *arg, object *&var)
726{ 745{
727 if (SvOK (arg)) 746 if (SvOK (arg))
728 { 747 {
729 sv_to (arg, var); 748 sv_to (arg, var);
821# undef def 840# undef def
822}; 841};
823 842
824#define KLASS_OF(event) (((unsigned int)event) < NUM_EVENT_TYPES ? klass_of [event] : KLASS_NONE) 843#define KLASS_OF(event) (((unsigned int)event) < NUM_EVENT_TYPES ? klass_of [event] : KLASS_NONE)
825 844
826static void noinline 845ecb_noinline static void
827gather_callbacks (AV *&callbacks, AV *registry, event_type event) 846gather_callbacks (AV *&callbacks, AV *registry, event_type event)
828{ 847{
829 // event must be in array 848 // event must be in array
830 if (event >= 0 && event <= AvFILLp (registry)) 849 if (event >= 0 && event <= AvFILLp (registry))
831 { 850 {
917{ 936{
918 attachable::gather_callbacks (callbacks, event); 937 attachable::gather_callbacks (callbacks, event);
919 ::gather_callbacks (callbacks, cb_map, event); 938 ::gather_callbacks (callbacks, cb_map, event);
920} 939}
921 940
922static void noinline 941ecb_noinline static void
923_recalc_want (bitset<NUM_EVENT_TYPES> &set, AV *registry) 942_recalc_want (bitset<NUM_EVENT_TYPES> &set, AV *registry)
924{ 943{
925 for (int event = 0; event <= AvFILLp (registry); ++event) 944 for (int event = 0; event <= AvFILLp (registry); ++event)
926 { 945 {
927 SV *cbs_ = AvARRAY (registry)[event]; 946 SV *cbs_ = AvARRAY (registry)[event];
1142 CALL_ARG (originator); 1161 CALL_ARG (originator);
1143 CALL_CALL ("cf::mapscript::activate", G_VOID); 1162 CALL_CALL ("cf::mapscript::activate", G_VOID);
1144 CALL_END; 1163 CALL_END;
1145} 1164}
1146 1165
1166void cfperl_ix (client *ns, int set, faceidx idx, int pri)
1167{
1168 CALL_BEGIN (3);
1169 CALL_ARG (ns);
1170 CALL_ARG (set);
1171 CALL_ARG (idx);
1172 CALL_ARG (pri);
1173 CALL_CALL (cv_cf_ix, G_VOID);
1174 CALL_END;
1175}
1176
1147player * 1177player *
1148player::find (const_utf8_string name) 1178player::find (const_utf8_string name)
1149{ 1179{
1150 CALL_BEGIN (1); 1180 CALL_BEGIN (1);
1151 CALL_ARG (name); 1181 CALL_ARG (name);
1245 CALL_ARG (y); 1275 CALL_ARG (y);
1246 CALL_CALL ("cf::object::player::goto", G_VOID); 1276 CALL_CALL ("cf::object::player::goto", G_VOID);
1247 CALL_END; 1277 CALL_END;
1248} 1278}
1249 1279
1250const_utf8_string 1280const_utf8_string
1251object::ref () const 1281object::ref () const
1252{ 1282{
1253 if (type == PLAYER) 1283 if (type == PLAYER)
1254 return format ("player/<1.%llx>/%s", (unsigned long long)uuid.seq, &name); 1284 return format ("player/<1.%llx>/%s", (unsigned long long)uuid.seq, &name);
1255 else 1285 else
1397 stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1); 1427 stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1);
1398 stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1); 1428 stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1);
1399 stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1); 1429 stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1);
1400 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); 1430 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1);
1401 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1); 1431 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1);
1432 stash_cf_layout_wrap = gv_stashpv ("cf::layout::wrap", 1);
1402 stash_ext_map_world = gv_stashpv ("ext::map_world" , 1); 1433 stash_ext_map_world = gv_stashpv ("ext::map_world" , 1);
1403 1434
1404 sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV); 1435 sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV);
1405 sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV); 1436 sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV);
1437 sv_server_tick = get_sv ("cf::SERVER_TICK", 1); SvUPGRADE (sv_server_tick, SVt_IV);
1406 sv_tick_start = get_sv ("cf::TICK_START", 1); SvUPGRADE (sv_tick_start, SVt_NV); 1438 sv_tick_start = get_sv ("cf::TICK_START" , 1); SvUPGRADE (sv_tick_start , SVt_NV);
1407 sv_next_tick = get_sv ("cf::NEXT_TICK" , 1); SvUPGRADE (sv_next_tick , SVt_NV); 1439 sv_next_tick = get_sv ("cf::NEXT_TICK" , 1); SvUPGRADE (sv_next_tick , SVt_NV);
1408 1440
1409 cb_global = get_av ("cf::CB_GLOBAL", 1); 1441 cb_global = get_av ("cf::CB_GLOBAL", 1);
1410 cb_attachable = get_av ("cf::CB_ATTACHABLE", 1); 1442 cb_attachable = get_av ("cf::CB_ATTACHABLE", 1);
1411 cb_object = get_av ("cf::CB_OBJECT", 1); 1443 cb_object = get_av ("cf::CB_OBJECT", 1);
1412 cb_player = get_av ("cf::CB_PLAYER", 1); 1444 cb_player = get_av ("cf::CB_PLAYER", 1);
1419_connect_to_perl_2 () 1451_connect_to_perl_2 ()
1420{ 1452{
1421 cv_cf_do_invoke = (SV *)get_cv ("cf::do_invoke" , 0); assert (cv_cf_do_invoke); 1453 cv_cf_do_invoke = (SV *)get_cv ("cf::do_invoke" , 0); assert (cv_cf_do_invoke);
1422 cv_cf__can_merge = (SV *)get_cv ("cf::_can_merge" , 0); assert (cv_cf__can_merge); 1454 cv_cf__can_merge = (SV *)get_cv ("cf::_can_merge" , 0); assert (cv_cf__can_merge);
1423 cv_cf_client_send_msg = (SV *)get_cv ("cf::client::send_msg", 0); assert (cv_cf_client_send_msg); 1455 cv_cf_client_send_msg = (SV *)get_cv ("cf::client::send_msg", 0); assert (cv_cf_client_send_msg);
1456 cv_cf_ix = (SV *)get_cv ("cf::face::ix" , 0); assert (cv_cf_ix);
1424 cv_cf_tick = (SV *)get_cv ("cf::tick" , 0); assert (cv_cf_tick); 1457 cv_cf_tick = (SV *)get_cv ("cf::tick" , 0); assert (cv_cf_tick);
1425 cv_cf_match_match = (SV *)get_cv ("cf::match::match" , 0); assert (cv_cf_match_match); 1458 cv_cf_match_match = (SV *)get_cv ("cf::match::match" , 0); assert (cv_cf_match_match);
1426} 1459}
1427 1460
1428MODULE = cf PACKAGE = cf PREFIX = cf_ 1461MODULE = cf PACKAGE = cf PREFIX = cf_
1433 I_CORO_API (PACKAGE); coroapi::GCoroAPI = GCoroAPI; 1466 I_CORO_API (PACKAGE); coroapi::GCoroAPI = GCoroAPI;
1434 1467
1435 _connect_to_perl_1 (); 1468 _connect_to_perl_1 ();
1436 1469
1437 newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1)); 1470 newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1));
1438
1439 //{
1440 // require_pv ("Time::HiRes");
1441 //
1442 // SV **svp = hv_fetch (PL_modglobal, "Time::NVtime", 12, 0);
1443 // if (!svp) croak ("Time::HiRes is required");
1444 // if (!SvIOK(*svp)) croak ("Time::NVtime isn’t a function pointer");
1445 // coroapi::time = INT2PTR (double(*)(), SvIV(*svp));
1446 //}
1447 1471
1448 static const struct { 1472 static const struct {
1449 const char *name; 1473 const char *name;
1450 IV iv; 1474 IV iv;
1451 } *civ, const_iv[] = { 1475 } *civ, const_iv[] = {
1455# include "attackinc.h" 1479# include "attackinc.h"
1456# undef def 1480# undef def
1457# define def(uc, flags) const_iv (SK_ ## uc) 1481# define def(uc, flags) const_iv (SK_ ## uc)
1458# include "skillinc.h" 1482# include "skillinc.h"
1459# undef def 1483# undef def
1460 1484# define def(name, use, nonuse) const_iv (body_ ## name)
1461 const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd) 1485# include "slotinc.h"
1486# undef def
1462 1487
1463 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) 1488 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y)
1464 1489
1465 const_iv (MAX_TIME) 1490 const_iv (MAX_TIME)
1466 const_iv (MAXSOCKBUF) 1491 const_iv (MAXSOCKBUF)
1480 const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE) 1505 const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE)
1481 1506
1482 const_iv (SK_EXP_ADD_SKILL) const_iv (SK_EXP_TOTAL) const_iv (SK_EXP_NONE) 1507 const_iv (SK_EXP_ADD_SKILL) const_iv (SK_EXP_TOTAL) const_iv (SK_EXP_NONE)
1483 const_iv (SK_SUBTRACT_SKILL_EXP) const_iv (SK_EXP_SKILL_ONLY) 1508 const_iv (SK_SUBTRACT_SKILL_EXP) const_iv (SK_EXP_SKILL_ONLY)
1484 1509
1485 const_iv (MAP_ACTIVE) const_iv (MAP_SWAPPED) const_iv (MAP_LOADING) const_iv (MAP_SAVING)
1486 const_iv (MAP_INACTIVE)
1487
1488 const_iv (KLASS_ATTACHABLE) const_iv (KLASS_GLOBAL) const_iv (KLASS_OBJECT) 1510 const_iv (KLASS_ATTACHABLE) const_iv (KLASS_GLOBAL) const_iv (KLASS_OBJECT)
1489 const_iv (KLASS_CLIENT) const_iv (KLASS_PLAYER) const_iv (KLASS_MAP) 1511 const_iv (KLASS_CLIENT) const_iv (KLASS_PLAYER) const_iv (KLASS_MAP)
1490 1512
1491 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT) 1513 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT)
1492 1514
1493 const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES) 1515 const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES)
1494 }; 1516 };
1495 1517
1496 for (civ = const_iv + array_length (const_iv); civ-- > const_iv; ) 1518 for (civ = const_iv + ecb_array_length (const_iv); civ-- > const_iv; )
1497 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv)); 1519 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv));
1498 1520
1499 static const struct { 1521 static const struct {
1500 const char *name; 1522 const char *name;
1501 int skip; 1523 int skip;
1507# undef def 1529# undef def
1508 }; 1530 };
1509 1531
1510 AV *av = get_av ("cf::EVENT", 1); 1532 AV *av = get_av ("cf::EVENT", 1);
1511 1533
1512 for (eiv = event_iv + array_length (event_iv); eiv-- > event_iv; ) 1534 for (eiv = event_iv + ecb_array_length (event_iv); eiv-- > event_iv; )
1513 { 1535 {
1514 AV *event = newAV (); 1536 AV *event = newAV ();
1515 av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0)); 1537 av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0));
1516 av_push (event, newSViv (eiv->klass)); 1538 av_push (event, newSViv (eiv->klass));
1517 av_store (av, eiv->iv, newRV_noinc ((SV *)event)); 1539 av_store (av, eiv->iv, newRV_noinc ((SV *)event));
1524 1546
1525void _gv_clear (SV *gv) 1547void _gv_clear (SV *gv)
1526 CODE: 1548 CODE:
1527 assert (SvTYPE (gv) == SVt_PVGV); 1549 assert (SvTYPE (gv) == SVt_PVGV);
1528# define f(sv) { SV *sv_ = (SV *)(sv); sv = 0; SvREFCNT_dec (sv_); } 1550# define f(sv) { SV *sv_ = (SV *)(sv); sv = 0; SvREFCNT_dec (sv_); }
1551 SvREFCNT_inc (gv);
1529 f (GvGP (gv)->gp_form); 1552 f (GvGP (gv)->gp_form);
1530 f (GvGP (gv)->gp_io); 1553 f (GvGP (gv)->gp_io);
1531 f (GvGP (gv)->gp_sv); 1554 f (GvGP (gv)->gp_sv);
1532 f (GvGP (gv)->gp_av); 1555 f (GvGP (gv)->gp_av);
1533 f (GvGP (gv)->gp_hv); 1556 f (GvGP (gv)->gp_hv);
1534 f (GvGP (gv)->gp_cv); 1557 f (GvGP (gv)->gp_cv);
1535 GvCVGEN (gv) = 0; 1558 GvCVGEN (gv) = 0;
1536 GvMULTI_off (gv); 1559 GvMULTI_off (gv);
1560 SvREFCNT_dec (gv);
1537# undef f 1561# undef f
1538 1562
1539void _connect_to_perl_1 () 1563void _connect_to_perl_1 ()
1540 1564
1541void _connect_to_perl_2 () 1565void _connect_to_perl_2 ()
1552 1576
1553 for_all_objects (op) 1577 for_all_objects (op)
1554 op->reattach (); 1578 op->reattach ();
1555} 1579}
1556 1580
1557# support function for map-world.ext
1558void _quantise (SV *data_sv, SV *plt_sv)
1559 CODE:
1560{
1561 if (!SvROK (plt_sv) || SvTYPE (SvRV (plt_sv)) != SVt_PVAV)
1562 croak ("_quantise called with invalid agruments");
1563
1564 plt_sv = SvRV (plt_sv);
1565 SV **plt = AvARRAY (plt_sv);
1566 int plt_count = AvFILL (plt_sv) + 1;
1567
1568 STRLEN len;
1569 char *data = SvPVbyte (data_sv, len);
1570 char *dst = data;
1571
1572 while (len >= 3)
1573 {
1574 for (SV **val_sv = plt + plt_count; val_sv-- > plt; )
1575 {
1576 char *val = SvPVX (*val_sv);
1577
1578 if (val [0] == data [0]
1579 && val [1] == data [1]
1580 && val [2] == data [2])
1581 {
1582 *dst++ = val [3];
1583 goto next;
1584 }
1585 }
1586
1587 croak ("_quantise: color not found in palette: #%02x%02x%02x, at offset %d %d",
1588 (uint8_t)data [0], (uint8_t)data [1], (uint8_t)data [2],
1589 dst - SvPVX (data_sv), len);
1590
1591 next:
1592 data += 3;
1593 len -= 3;
1594 }
1595
1596 SvCUR_set (data_sv, dst - SvPVX (data_sv));
1597}
1598
1599void init_anim () 1581void init_anim ()
1600 1582
1601void init_globals () 1583void init_globals ()
1602 1584
1603void init_experience ()
1604
1605void init_attackmess () 1585void init_attackmess ()
1606 1586
1607void init_dynamic () 1587void init_dynamic ()
1608 1588
1609void load_settings () 1589void load_settings ()
1610 1590
1591void _reload_exp_table ()
1592
1611void load_materials () 1593void _reload_materials ()
1612 1594
1613void init_uuid () 1595void init_uuid ()
1614 CODE: 1596 CODE:
1615 UUID::init (); 1597 UUID::init ();
1616 1598
1627 coroapi::cede_to_tick (); 1609 coroapi::cede_to_tick ();
1628 1610
1629NV till_tick () 1611NV till_tick ()
1630 CODE: 1612 CODE:
1631 RETVAL = SvNVX (sv_next_tick) - now (); 1613 RETVAL = SvNVX (sv_next_tick) - now ();
1632 OUTPUT: 1614 OUTPUT: RETVAL
1633 RETVAL
1634 1615
1635int tick_inhibit () 1616int tick_inhibit ()
1636 CODE: 1617 CODE:
1637 RETVAL = tick_inhibit; 1618 RETVAL = tick_inhibit;
1638 OUTPUT: 1619 OUTPUT: RETVAL
1639 RETVAL
1640 1620
1641void tick_inhibit_inc () 1621void tick_inhibit_inc ()
1642 CODE: 1622 CODE:
1643 ++tick_inhibit; 1623 ++tick_inhibit;
1644 1624
1649 { 1629 {
1650 ev_async_send (EV_DEFAULT, &tick_watcher); 1630 ev_async_send (EV_DEFAULT, &tick_watcher);
1651 coroapi::cede (); 1631 coroapi::cede ();
1652 } 1632 }
1653 1633
1654void server_tick () 1634void one_tick ()
1655 CODE: 1635 CODE:
1656{ 1636{
1657 ev_now_update (EV_DEFAULT); 1637 ev_now_update (EV_DEFAULT);
1658 NOW = ev_now (EV_DEFAULT); 1638 NOW = ev_now (EV_DEFAULT);
1659 SvNV_set (sv_now, NOW); SvNOK_only (sv_now); 1639 SvNV_set (sv_now, NOW); SvNOK_only (sv_now);
1660 SvNV_set (sv_tick_start, NOW); SvNOK_only (sv_tick_start); 1640 SvNV_set (sv_tick_start, NOW); SvNOK_only (sv_tick_start);
1661 runtime = SvNVX (sv_runtime); 1641 runtime = SvNVX (sv_runtime);
1662 1642
1643 one_tick ();
1644
1663 server_tick (); 1645 ++server_tick;
1646 SvUV_set (sv_server_tick, server_tick); SvIOK_only_UV (sv_server_tick);
1664 1647
1665 ev_now_update (EV_DEFAULT); 1648 ev_now_update (EV_DEFAULT);
1666 NOW = ev_now (EV_DEFAULT); 1649 NOW = ev_now (EV_DEFAULT);
1667 SvNV_set (sv_now, NOW); SvNOK_only (sv_now); 1650 SvNV_set (sv_now, NOW); SvNOK_only (sv_now);
1651
1668 runtime += TICK; 1652 runtime += TICK;
1669 SvNV_set (sv_runtime, runtime); SvNOK_only (sv_runtime); 1653 SvNV_set (sv_runtime, runtime); SvNOK_only (sv_runtime);
1670} 1654}
1671 1655
1672NV floor (NV x) 1656NV floor (NV x)
1676NV rndm (...) 1660NV rndm (...)
1677 ALIAS: 1661 ALIAS:
1678 rmg_rndm = 1 1662 rmg_rndm = 1
1679 CODE: 1663 CODE:
1680{ 1664{
1681 rand_gen &gen = ix ? rmg_rndm : rndm; 1665 rand_gen &gen = ix ? rmg_rndm : rndm;
1682 switch (items) 1666 switch (items)
1683 { 1667 {
1684 case 0: RETVAL = gen (); break; 1668 case 0: RETVAL = gen (); break;
1685 case 1: RETVAL = gen (SvUV (ST (0))); break; 1669 case 1: RETVAL = gen (SvUV (ST (0))); break;
1686 case 2: RETVAL = gen (SvIV (ST (0)), SvIV (ST (1))); break; 1670 case 2: RETVAL = gen (SvIV (ST (0)), SvIV (ST (1))); break;
1687 default: croak ("cf::rndm requires zero, one or two parameters."); break; 1671 default: croak ("cf::rndm requires zero, one or two parameters."); break;
1688 } 1672 }
1689} 1673}
1690 OUTPUT: 1674 OUTPUT: RETVAL
1691 RETVAL
1692 1675
1693NV clamp (NV value, NV min_value, NV max_value) 1676NV clamp (NV value, NV min_value, NV max_value)
1694 CODE: 1677 CODE:
1695 RETVAL = clamp (value, min_value, max_value); 1678 RETVAL = clamp (value, min_value, max_value);
1696 OUTPUT: 1679 OUTPUT: RETVAL
1697 RETVAL
1698 1680
1699NV lerp (NV value, NV min_in, NV max_in, NV min_out, NV max_out) 1681NV lerp (NV value, NV min_in, NV max_in, NV min_out, NV max_out)
1700 CODE: 1682 CODE:
1701 RETVAL = lerp (value, min_in, max_in, min_out, max_out); 1683 RETVAL = lerp (value, min_in, max_in, min_out, max_out);
1702 OUTPUT: 1684 OUTPUT: RETVAL
1703 RETVAL
1704 1685
1705const char *ordinal (int i) 1686const char *ordinal (int i)
1706 1687
1707void weaken (...) 1688void weaken (...)
1708 PROTOTYPE: @ 1689 PROTOTYPE: @
1771 1752
1772int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) 1753int mlockall (int flags = MCL_CURRENT | MCL_FUTURE)
1773 INIT: 1754 INIT:
1774#if __GLIBC__ 1755#if __GLIBC__
1775 mallopt (M_TOP_PAD, 1024 * 1024); 1756 mallopt (M_TOP_PAD, 1024 * 1024);
1776 mallopt (M_MMAP_THRESHOLD, 1024 * 1024 * 128); 1757 mallopt (M_MMAP_THRESHOLD, 1024 * 1024);
1777 mallopt (M_MMAP_MAX, 0); // likely bug-workaround, also frees memory 1758 mallopt (M_MMAP_MAX, 0); // likely bug-workaround, also frees memory
1759 if (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 10))
1778 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc 1760 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc
1779#endif 1761#endif
1780 1762
1781int munlockall () 1763int munlockall ()
1782 1764
1783#endif 1765#endif
1806 EXTEND (SP, 5*2); 1788 EXTEND (SP, 5*2);
1807 PUSHs (sv_2mortal (newSVpv ("slice_alloc", 0))); PUSHs (sv_2mortal (newSVuv (slice_alloc))); 1789 PUSHs (sv_2mortal (newSVpv ("slice_alloc", 0))); PUSHs (sv_2mortal (newSVuv (slice_alloc)));
1808 PUSHs (sv_2mortal (newSVpv ("shstr_alloc", 0))); PUSHs (sv_2mortal (newSVuv (shstr_alloc))); 1790 PUSHs (sv_2mortal (newSVpv ("shstr_alloc", 0))); PUSHs (sv_2mortal (newSVuv (shstr_alloc)));
1809 PUSHs (sv_2mortal (newSVpv ("objects" , 0))); PUSHs (sv_2mortal (newSVuv (objects.size () * sizeof (object)))); 1791 PUSHs (sv_2mortal (newSVpv ("objects" , 0))); PUSHs (sv_2mortal (newSVuv (objects.size () * sizeof (object))));
1810 PUSHs (sv_2mortal (newSVpv ("sv_count" , 0))); PUSHs (sv_2mortal (newSVuv (PL_sv_count))); 1792 PUSHs (sv_2mortal (newSVpv ("sv_count" , 0))); PUSHs (sv_2mortal (newSVuv (PL_sv_count)));
1811 PUSHs (sv_2mortal (newSVpv ("sv_objcount", 0))); PUSHs (sv_2mortal (newSVuv (PL_sv_objcount)));
1812} 1793}
1813
1814int find_animation (utf8_string text)
1815 PROTOTYPE: $
1816 1794
1817int random_roll (int min, int max, object *op, int goodbad); 1795int random_roll (int min, int max, object *op, int goodbad);
1818 1796
1819const_utf8_string cost_string_from_value(uint64 cost, int approx = 0) 1797const_utf8_string cost_string_from_value(uint64 cost, int approx = 0)
1820 1798
1821int exp_to_level (val64 exp) 1799int exp_to_level (val64 exp)
1822 1800
1823val64 level_to_min_exp (int level) 1801val64 level_to_min_exp (int level)
1824 1802
1803const_utf8_string
1804spellpathnames (int idx)
1805 CODE:
1806 RETVAL = spellpathnames [idx];
1807 OUTPUT: RETVAL
1808
1825SV * 1809SV *
1826resistance_to_string (int atnr) 1810attacktype_name (int atnr)
1827 CODE: 1811 CODE:
1828 if (atnr >= 0 && atnr < NROFATTACKS) 1812 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1829 RETVAL = newSVpv (resist_plus[atnr], 0); 1813 ? newSVpv (attacktype_name [atnr], 0)
1830 else 1814 : &PL_sv_undef;
1831 XSRETURN_UNDEF;
1832 OUTPUT: RETVAL 1815 OUTPUT: RETVAL
1816
1817SV *
1818attacktype_desc (int atnr)
1819 CODE:
1820 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1821 ? newSVpv (attacktype_desc [atnr], 0)
1822 : &PL_sv_undef;
1823 OUTPUT: RETVAL
1824
1825SV *
1826resist_plus (int atnr)
1827 CODE:
1828 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1829 ? newSVpv (resist_plus [atnr], 0)
1830 : &PL_sv_undef;
1831 OUTPUT: RETVAL
1832
1833SV *
1834change_resist_msg (int atnr)
1835 CODE:
1836 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1837 ? newSVpv (change_resist_msg [atnr], 0)
1838 : &PL_sv_undef;
1839 OUTPUT: RETVAL
1840
1841int
1842skill_flags (int idx)
1843 CODE:
1844 if (idx < 0 || idx >= ecb_array_length (skill_flags))
1845 croak ("skill_flags: index out of bounds");
1846 RETVAL = skill_flags [idx];
1847 OUTPUT: RETVAL
1833 1848
1834UUID 1849UUID
1835uuid_cur () 1850uuid_cur ()
1836 CODE: 1851 CODE:
1837 RETVAL = UUID::cur; 1852 RETVAL = UUID::cur;
1838 OUTPUT: 1853 OUTPUT: RETVAL
1839 RETVAL
1840 1854
1841UUID 1855UUID
1842uuid_gen () 1856uuid_gen ()
1843 CODE: 1857 CODE:
1844 RETVAL = UUID::gen (); 1858 RETVAL = UUID::gen ();
1845 OUTPUT: 1859 OUTPUT: RETVAL
1846 RETVAL
1847 1860
1848val64 1861val64
1849uuid_seq (UUID uuid) 1862uuid_seq (UUID uuid)
1850 CODE: 1863 CODE:
1851 RETVAL = uuid.seq; 1864 RETVAL = uuid.seq;
1852 OUTPUT: 1865 OUTPUT: RETVAL
1853 RETVAL
1854 1866
1855UUID 1867UUID
1856uuid_str (val64 seq) 1868uuid_str (val64 seq)
1857 CODE: 1869 CODE:
1858 RETVAL.seq = seq; 1870 RETVAL.seq = seq;
1859 OUTPUT: 1871 OUTPUT: RETVAL
1860 RETVAL
1861 1872
1862void 1873void
1863coin_names () 1874coin_names ()
1864 PPCODE: 1875 PPCODE:
1865 EXTEND (SP, NUM_COINS); 1876 EXTEND (SP, NUM_COINS);
1877load_resource_file_ (octet_string filename) 1888load_resource_file_ (octet_string filename)
1878 1889
1879void 1890void
1880fix_weight () 1891fix_weight ()
1881 1892
1893utf8_string
1894expand_cfpod (int hintmode, int gender, const_utf8_string cfpod)
1895 PPCODE:
1896 XPUSHs (to_sv (player::expand_cfpod (hintmode, gender, cfpod)));
1897
1882MODULE = cf PACKAGE = cf::attachable 1898MODULE = cf PACKAGE = cf::attachable
1883 1899
1884int 1900int
1885valid (SV *obj) 1901valid (SV *obj)
1886 CODE: 1902 CODE:
1887 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); 1903 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext);
1888 OUTPUT: 1904 OUTPUT: RETVAL
1889 RETVAL
1890 1905
1891bool should_invoke (attachable *obj, int event) 1906bool should_invoke (attachable *obj, int event)
1892 CODE: 1907 CODE:
1893 RETVAL = obj->should_invoke ((event_type)event); 1908 RETVAL = obj->should_invoke ((event_type)event);
1894 OUTPUT: RETVAL 1909 OUTPUT: RETVAL
1959int mortals_size () 1974int mortals_size ()
1960 CODE: 1975 CODE:
1961 RETVAL = attachable::mortals.size (); 1976 RETVAL = attachable::mortals.size ();
1962 OUTPUT: RETVAL 1977 OUTPUT: RETVAL
1963 1978
1964const_utf8_string slot_use_name (U32 slot) 1979const_utf8_string slot_name (U32 slot)
1965 ALIAS: 1980 ALIAS:
1981 slot_name = 0
1982 slot_use_name = 1
1966 slot_nonuse_name = 1 1983 slot_nonuse_name = 2
1967 CODE: 1984 CODE:
1968{ 1985{
1969 if (slot >= NUM_BODY_LOCATIONS) 1986 if (slot >= NUM_BODY_LOCATIONS)
1970 croak ("body slot index out of range"); 1987 croak ("body slot index out of range");
1971 1988
1972 switch (ix) 1989 switch (ix)
1973 { 1990 {
1991 case 0: RETVAL = body_locations[slot].name ; break;
1974 case 0: RETVAL = body_locations[slot].use_name; break; 1992 case 1: RETVAL = body_locations[slot].use_name ; break;
1975 case 1: RETVAL = body_locations[slot].nonuse_name; break; 1993 case 2: RETVAL = body_locations[slot].nonuse_name; break;
1976 } 1994 }
1977} 1995}
1978 OUTPUT: 1996 OUTPUT: RETVAL
1979 RETVAL
1980 1997
1981# missing properties 1998# missing properties
1982 1999
1983object *head (object *op) 2000object *head (object *op)
1984 PROTOTYPE: $ 2001 PROTOTYPE: $
1992 PPCODE: 2009 PPCODE:
1993{ 2010{
1994 for (object *o = obj->inv; o; o = o->below) 2011 for (object *o = obj->inv; o; o = o->below)
1995 XPUSHs (sv_2mortal (to_sv (o))); 2012 XPUSHs (sv_2mortal (to_sv (o)));
1996} 2013}
1997
1998void
1999set_animation (object *op, int idx)
2000 CODE:
2001 SET_ANIMATION (op, idx);
2002
2003int
2004num_animations (object *op)
2005 CODE:
2006 RETVAL = NUM_ANIMATIONS (op);
2007 OUTPUT: RETVAL
2008 2014
2009int slot_info (object *op, UV slot, int value = 0) 2015int slot_info (object *op, UV slot, int value = 0)
2010 ALIAS: 2016 ALIAS:
2011 slot_used = 1 2017 slot_used = 1
2012 CODE: 2018 CODE:
2020 if (ix) 2026 if (ix)
2021 op->slot[slot].used = value; 2027 op->slot[slot].used = value;
2022 else 2028 else
2023 op->slot[slot].info = value; 2029 op->slot[slot].info = value;
2024} 2030}
2025 OUTPUT: 2031 OUTPUT: RETVAL
2026 RETVAL
2027 2032
2028object *find_best_object_match (object *op, utf8_string match) 2033object *find_best_object_match (object *op, utf8_string match)
2029 2034
2030int apply_shop_mat (object *shop_mat, object *op); 2035int apply_shop_mat (object *shop_mat, object *op);
2031 2036
2032int move (object *op, int dir, object *originator = op) 2037int move (object *op, int dir, object *originator = op)
2033 CODE: 2038 CODE:
2034 RETVAL = op->move (dir, originator); 2039 RETVAL = op->move (dir, originator);
2035 OUTPUT: 2040 OUTPUT: RETVAL
2036 RETVAL
2037 2041
2038void apply_below (object *op) 2042void apply_below (object *op)
2039 CODE: 2043 CODE:
2040 player_apply_below (op); 2044 player_apply_below (op);
2041 2045
2105int convert_item (object *item, object *converter) 2109int convert_item (object *item, object *converter)
2106 2110
2107void fix_generated_item (object *op, object *creator, int difficulty, int max_magic, int flags); 2111void fix_generated_item (object *op, object *creator, int difficulty, int max_magic, int flags);
2108 2112
2109MODULE = cf PACKAGE = cf::object PREFIX = cf_ 2113MODULE = cf PACKAGE = cf::object PREFIX = cf_
2110
2111# no clean way to get an object from an archetype - stupid idiotic
2112# dumb kludgy misdesigned plug-in api slowly gets on my nerves.
2113 2114
2114object *new (utf8_string archetype = 0) 2115object *new (utf8_string archetype = 0)
2115 PROTOTYPE: ;$ 2116 PROTOTYPE: ;$
2116 CODE: 2117 CODE:
2117 RETVAL = archetype ? get_archetype (archetype) : object::create (); 2118 RETVAL = archetype
2119 ? archetype::get (archetype)
2120 : object::create ();
2118 OUTPUT: 2121 OUTPUT: RETVAL
2119 RETVAL
2120 2122
2121object *generate (utf8_string arch, object *creator) 2123object *generate (utf8_string arch, object *creator)
2122 CODE: 2124 CODE:
2123 object *obj = get_archetype (arch); 2125 object *obj = archetype::get (arch);
2124 fix_generated_item (obj, creator, 0, 0, GT_MINIMAL); 2126 fix_generated_item (obj, creator, 0, 0, GT_MINIMAL);
2125 RETVAL = obj; 2127 RETVAL = obj;
2126 OUTPUT: 2128 OUTPUT: RETVAL
2127 RETVAL
2128 2129
2129object *find_object (U32 tag) 2130object *find_object (U32 tag)
2130 2131
2131object *find_object_uuid (UUID i) 2132object *find_object_uuid (UUID i)
2132 2133
2138 RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y); 2139 RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y);
2139 2140
2140 if (RETVAL->destroyed ()) 2141 if (RETVAL->destroyed ())
2141 RETVAL = 0; 2142 RETVAL = 0;
2142} 2143}
2144 OUTPUT: RETVAL
2143 2145
2144shstr 2146shstr
2145object::kv_get (shstr key) 2147object::kv_get (shstr key)
2148 CODE:
2149 RETVAL = THIS->kv.get (key);
2150 OUTPUT: RETVAL
2146 2151
2147void 2152void
2148object::kv_del (shstr key) 2153object::kv_del (shstr key)
2154 CODE:
2155 THIS->kv.del (key);
2149 2156
2150void 2157void
2151object::kv_set (shstr key, shstr value) 2158object::kv_set (shstr key, shstr value)
2159 CODE:
2160 THIS->kv.set (key, value);
2152 2161
2153object *get_nearest_player (object *ob) 2162object *get_nearest_player (object *ob)
2154 ALIAS: nearest_player = 0 2163 ALIAS: nearest_player = 0
2155 PREINIT: 2164 PREINIT:
2156 extern object *get_nearest_player (object *); 2165 extern object *get_nearest_player (object *);
2245#d# TODO: replace by blocked_los accessor, fix code using this 2254#d# TODO: replace by blocked_los accessor, fix code using this
2246bool 2255bool
2247cell_visible (player *pl, int dx, int dy) 2256cell_visible (player *pl, int dx, int dy)
2248 CODE: 2257 CODE:
2249 RETVAL = pl->blocked_los (dx, dy) != LOS_BLOCKED; 2258 RETVAL = pl->blocked_los (dx, dy) != LOS_BLOCKED;
2250 OUTPUT: 2259 OUTPUT: RETVAL
2251 RETVAL
2252 2260
2253void 2261void
2254send (player *pl, SV *packet) 2262send (player *pl, SV *packet)
2255 CODE: 2263 CODE:
2256{ 2264{
2332outdoor_darkness (int darkness = 0) 2340outdoor_darkness (int darkness = 0)
2333 CODE: 2341 CODE:
2334 RETVAL = maptile::outdoor_darkness; 2342 RETVAL = maptile::outdoor_darkness;
2335 if (items) 2343 if (items)
2336 maptile::outdoor_darkness = darkness; 2344 maptile::outdoor_darkness = darkness;
2337 OUTPUT: 2345 OUTPUT: RETVAL
2338 RETVAL
2339 2346
2340void 2347void
2341maptile::instantiate () 2348maptile::instantiate ()
2342 2349
2343maptile *new () 2350maptile *new ()
2344 PROTOTYPE: 2351 PROTOTYPE:
2345 CODE: 2352 CODE:
2346 RETVAL = new maptile; 2353 RETVAL = new maptile;
2347 OUTPUT: 2354 OUTPUT: RETVAL
2348 RETVAL
2349 2355
2350void 2356void
2351maptile::players () 2357maptile::players ()
2352 PPCODE: 2358 PPCODE:
2353 if (GIMME_V == G_SCALAR) 2359 if (GIMME_V == G_SCALAR)
2359 if (pl->ob && pl->ob->map == THIS) 2365 if (pl->ob && pl->ob->map == THIS)
2360 PUSHs (sv_2mortal (to_sv (pl->ob))); 2366 PUSHs (sv_2mortal (to_sv (pl->ob)));
2361 } 2367 }
2362 2368
2363void 2369void
2370maptile::gen_quadmap (int x, int y, int z)
2371 CODE:
2372 gen_quadmap (THIS, x * 50, y * 50, z);
2373
2374void
2364maptile::add_underlay (SV *data, int offset, int stride, SV *palette) 2375maptile::add_underlay (SV *data, int offset, int stride, SV *palette)
2365 CODE: 2376 CODE:
2366{ 2377{
2367 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV) 2378 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV)
2368 croak ("maptile::add_underlay: palette must be arrayref"); 2379 croak ("maptile::add_underlay: palette must be arrayref");
2369 2380
2370 palette = SvRV (palette); 2381 palette = SvRV (palette);
2371 2382
2372 STRLEN idxlen; 2383 STRLEN idxlen;
2373 const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen); 2384 const uint8 *idx = (const uint8 *)SvPVbyte (data, idxlen);
2374 2385
2375 for (int x = 0; x < THIS->width; ++x) 2386 for (int x = 0; x < THIS->width; ++x)
2376 for (int y = 0; y < THIS->height; ++y) 2387 for (int y = 0; y < THIS->height; ++y)
2377 { 2388 {
2378 for (object *op = THIS->at (x, y).bot; op; op = op->above) 2389 for (object *op = THIS->at (x, y).bot; op; op = op->above)
2384 2395
2385 if (IN_RANGE_EXC (offs, 0, idxlen)) 2396 if (IN_RANGE_EXC (offs, 0, idxlen))
2386 { 2397 {
2387 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) 2398 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0))
2388 { 2399 {
2389 object *ob = get_archetype (cfSvPVutf8_nolen (*elem)); 2400 object *ob = archetype::get (cfSvPVutf8_nolen (*elem));
2390 ob->flag [FLAG_NO_MAP_SAVE] = true; 2401 ob->flag [FLAG_NO_MAP_SAVE] = true;
2391 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); 2402 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY);
2392 2403
2393 if (ob->randomitems && !ob->above) 2404 if (ob->randomitems && !ob->above)
2394 { 2405 {
2398 op->flag [FLAG_NO_MAP_SAVE] = true; 2409 op->flag [FLAG_NO_MAP_SAVE] = true;
2399 // TODO: if this is a pickable object, then the item 2410 // TODO: if this is a pickable object, then the item
2400 // will at a bit weird - saving inside the player 2411 // will at a bit weird - saving inside the player
2401 // will clear the flag, but when the player drops 2412 // will clear the flag, but when the player drops
2402 // it without logging out, it keeps the flag. 2413 // it without logging out, it keeps the flag.
2403 // nobody ahs reported this, but this can be rather 2414 // nobody has reported this, but this can be rather
2404 // annoying on persistent maps. 2415 // annoying on persistent maps.
2405 } 2416 }
2406 } 2417 }
2407 } 2418 }
2408 } 2419 }
2409
2410 skip: ; 2420 skip: ;
2411 } 2421 }
2412} 2422}
2413 2423
2414void 2424void
2419 croak ("maptile::set_regiondata: palette must be arrayref"); 2429 croak ("maptile::set_regiondata: palette must be arrayref");
2420 2430
2421 palette = SvRV (palette); 2431 palette = SvRV (palette);
2422 2432
2423 STRLEN idxlen; 2433 STRLEN idxlen;
2424 const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen); 2434 const uint8 *idx = (const uint8 *)SvPVbyte (data, idxlen);
2425 2435
2426 region_ptr *regionmap = new region_ptr [av_len ((AV *)palette) + 1]; 2436 region_ptr *regionmap = new region_ptr [av_len ((AV *)palette) + 1];
2427 uint8_t *regions = salloc<uint8_t> (THIS->size ()); 2437 uint8 *regions = salloc<uint8_t> (THIS->size ());
2428 2438
2429 for (int i = av_len ((AV *)palette) + 1; i--; ) 2439 for (int i = av_len ((AV *)palette) + 1; i--; )
2430 regionmap [i] = region::find (cfSvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1))); 2440 regionmap [i] = region::find (cfSvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1)));
2431 2441
2432 for (int y = 0; y < THIS->height; ++y) 2442 for (int y = 0; y < THIS->height; ++y)
2445 for (int x = 0; x < THIS->width; ++x) 2455 for (int x = 0; x < THIS->width; ++x)
2446 for (int y = 0; y < THIS->height; ++y) 2456 for (int y = 0; y < THIS->height; ++y)
2447 { 2457 {
2448 region *rgn = THIS->region (x, y); 2458 region *rgn = THIS->region (x, y);
2449 2459
2450 //fprintf (stderr, "%d,%d %f %p\n", x, y, rgn->treasure_density,rgn->treasure);//D
2451 if (object *op = THIS->at (x, y).top) 2460 if (object *op = THIS->at (x, y).top)
2452 if (rgn->treasure && rndm () < rgn->treasure_density) 2461 if (rgn->treasure && rndm () < rgn->treasure_density)
2453 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty); 2462 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty);
2454 } 2463 }
2455 2464
2485 if (!pos.move (dir).normalise ()) 2494 if (!pos.move (dir).normalise ())
2486 XSRETURN_UNDEF; 2495 XSRETURN_UNDEF;
2487 2496
2488 RETVAL = &*pos; 2497 RETVAL = &*pos;
2489} 2498}
2490 OUTPUT: 2499 OUTPUT: RETVAL
2491 RETVAL
2492 2500
2493void 2501void
2494at (maptile *map, unsigned int x, unsigned int y, int dir = 0) 2502at (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2495 PROTOTYPE: $$$;$ 2503 PROTOTYPE: $$$;$
2496 PPCODE: 2504 PPCODE:
2534} 2542}
2535 OUTPUT: RETVAL 2543 OUTPUT: RETVAL
2536 2544
2537# worst xs function of my life 2545# worst xs function of my life
2538bool 2546bool
2539_create_random_map (\ 2547_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: 2548 CODE:
2580{ 2549{
2581 random_map_params rmp; 2550 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); 2551 RETVAL = self->generate_random_map (&rmp);
2623} 2552}
2624 OUTPUT: 2553 OUTPUT: RETVAL
2625 RETVAL
2626 2554
2627MODULE = cf PACKAGE = cf::mapspace 2555MODULE = cf PACKAGE = cf::mapspace
2628 2556
2629INCLUDE: $PERL $srcdir/genacc mapspace $srcdir/../include/map.h | 2557INCLUDE: $PERL $srcdir/genacc mapspace $srcdir/../include/map.h |
2630 2558
2637 2565
2638archetype *archetypes (U32 index) 2566archetype *archetypes (U32 index)
2639 CODE: 2567 CODE:
2640 RETVAL = index < archetypes.size () ? archetypes [index] : 0; 2568 RETVAL = index < archetypes.size () ? archetypes [index] : 0;
2641 OUTPUT: RETVAL 2569 OUTPUT: RETVAL
2570
2571int skillvec_size ()
2572 CODE:
2573 RETVAL = skillvec.size ();
2574 OUTPUT: RETVAL
2575
2576archetype *skillvec (U32 index)
2577 CODE:
2578 RETVAL = index < skillvec.size () ? (archetype *)(object *)skillvec [index] : 0;
2579 OUTPUT: RETVAL
2580
2581void
2582find_by_type (int type)
2583 PPCODE:
2584 for_all_archetypes (arch)
2585 if (arch->type == type)
2586 XPUSHs (sv_2mortal (to_sv (arch)));
2642 2587
2643INCLUDE: $PERL $srcdir/genacc archetype $srcdir/../include/object.h | 2588INCLUDE: $PERL $srcdir/genacc archetype $srcdir/../include/object.h |
2644 2589
2645MODULE = cf PACKAGE = cf::party 2590MODULE = cf PACKAGE = cf::party
2646 2591
2695list () 2640list ()
2696 PPCODE: 2641 PPCODE:
2697 EXTEND (SP, clients.size ()); 2642 EXTEND (SP, clients.size ());
2698 for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i) 2643 for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i)
2699 PUSHs (sv_2mortal (to_sv (*i))); 2644 PUSHs (sv_2mortal (to_sv (*i)));
2645
2646STRLEN
2647client::inbuf_append (SV *data)
2648 CODE:
2649{
2650 STRLEN len;
2651 char *ptr = SvPVbyte (data, len);
2652
2653 min_it (len, sizeof (THIS->inbuf) - THIS->inbuf_len);
2654 memcpy (THIS->inbuf + THIS->inbuf_len, ptr, len);
2655 THIS->inbuf_len += len;
2656
2657 THIS->inbuf_handle ();
2658
2659 RETVAL = len;
2660}
2661 OUTPUT: RETVAL
2700 2662
2701void 2663void
2702client::send_packet (SV *packet) 2664client::send_packet (SV *packet)
2703 CODE: 2665 CODE:
2704{ 2666{
2722 if (RETVAL) 2684 if (RETVAL)
2723 { 2685 {
2724 THIS->send_face (RETVAL, pri); 2686 THIS->send_face (RETVAL, pri);
2725 THIS->flush_fx (); 2687 THIS->flush_fx ();
2726 } 2688 }
2727 OUTPUT: 2689 OUTPUT: RETVAL
2728 RETVAL
2729 2690
2730int 2691int
2731client::fx_want (int idx, int value = -1) 2692client::fx_want (int idx, int value = -1)
2732 CODE: 2693 CODE:
2733 if (0 < idx && idx < FT_NUM) 2694 if (0 < idx && idx < FT_NUM)
2736 if (items > 2) 2697 if (items > 2)
2737 THIS->fx_want [idx] = value; 2698 THIS->fx_want [idx] = value;
2738 } 2699 }
2739 else 2700 else
2740 RETVAL = 0; 2701 RETVAL = 0;
2741 OUTPUT: 2702 OUTPUT: RETVAL
2742 RETVAL
2743 2703
2744MODULE = cf PACKAGE = cf::sound PREFIX = sound_ 2704MODULE = cf PACKAGE = cf::sound PREFIX = sound_
2745 2705
2746faceidx sound_find (utf8_string name) 2706faceidx sound_find (utf8_string name)
2747 2707
2760faceidx face_find (utf8_string name, faceidx defidx = 0) 2720faceidx face_find (utf8_string name, faceidx defidx = 0)
2761 2721
2762faceidx alloc (utf8_string name) 2722faceidx alloc (utf8_string name)
2763 CODE: 2723 CODE:
2764{ 2724{
2765 do 2725 RETVAL = face_alloc ();
2766 {
2767 RETVAL = faces.size ();
2768 faces.resize (RETVAL + 1);
2769 }
2770 while (!RETVAL); // crude way to leave index 0
2771 2726
2772 faces [RETVAL].name = name; 2727 faces [RETVAL].name = name;
2773 facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL)); 2728 facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL));
2774 2729
2775 if (!strcmp (name, BLANK_FACE_NAME )) blank_face = RETVAL; 2730 if (!strcmp (name, BLANK_FACE_NAME )) blank_face = RETVAL;
2776 if (!strcmp (name, EMPTY_FACE_NAME )) empty_face = RETVAL; 2731 if (!strcmp (name, EMPTY_FACE_NAME )) empty_face = RETVAL;
2777 if (!strcmp (name, MAGICMOUTH_FACE_NAME)) magicmouth_face = RETVAL; 2732 if (!strcmp (name, MAGICMOUTH_FACE_NAME)) magicmouth_face = RETVAL;
2778} 2733}
2734 OUTPUT: RETVAL
2735
2736faceidx faces_size ()
2737 CODE:
2738 RETVAL = faces.size ();
2779 OUTPUT: RETVAL 2739 OUTPUT: RETVAL
2780 2740
2781void set_type (faceidx idx, int value) 2741void set_type (faceidx idx, int value)
2782 ALIAS: 2742 ALIAS:
2783 set_type = 0 2743 set_type = 0
2794 case 2: f->magicmap = value; break; 2754 case 2: f->magicmap = value; break;
2795 case 3: f->smooth = value; break; 2755 case 3: f->smooth = value; break;
2796 case 4: f->smoothlevel = value; break; 2756 case 4: f->smoothlevel = value; break;
2797 } 2757 }
2798 2758
2799void set_data (faceidx idx, int faceset, SV *data, SV *chksum) 2759void set_csum (faceidx idx, int faceset, SV *chksum)
2800 CODE: 2760 CODE:
2801{ 2761{
2802 faceinfo *f = face_info (idx); assert (f); 2762 faceinfo *f = face_info (idx); assert (f);
2803 facedata *d = &(faceset ? f->data64 : f->data32); 2763 facedata *d = f->face + faceset;
2804 sv_to (data, d->data);
2805 STRLEN clen; 2764 STRLEN clen;
2806 char *cdata = SvPVbyte (chksum, clen); 2765 char *cdata = SvPVbyte (chksum, clen);
2807 clen = min (CHKSUM_MAXLEN, clen);
2808 2766
2767 assert (("cf::face::set_data called with too long checksum", clen <= CHKSUM_MAXLEN));
2809 assert (("cf::face::set_data must be called with a non-empty checksum", clen)); 2768 assert (("cf::face::set_data must be called with a non-empty checksum", clen));
2810 2769
2811 if (clen != d->chksum_len || memcmp (d->chksum, cdata, clen)) 2770 if (clen != d->chksum_len || memcmp (d->chksum, cdata, clen))
2812 { 2771 {
2813 d->chksum_len = clen; 2772 d->chksum_len = clen;
2814 memcpy (d->chksum, cdata, clen); 2773 memcpy (d->chksum, cdata, clen);
2815 2774
2816 // invalidate existing client face info 2775 // invalidate existing client face info
2817 for_all_clients (ns) 2776 for_all_clients (ns)
2818 if (ns->faceset == faceset) 2777 ns->invalidate_face (idx);
2819 {
2820 ns->faces_sent [idx] = false;
2821 ns->force_newmap = true;
2822 }
2823 } 2778 }
2824} 2779}
2825 2780
2826int get_data_size (faceidx idx, int faceset = 0) 2781SV *mangle_csum (SV *chksum)
2827 CODE: 2782 CODE:
2828 facedata *d = face_data (idx, faceset); 2783 STRLEN len;
2829 if (!d) XSRETURN_UNDEF; 2784 char *data = SvPVbyte (chksum, len);
2830 RETVAL = d->data.size (); 2785 RETVAL = newSVpvn (data, min (len, CHKSUM_MAXLEN));
2831 OUTPUT: 2786 OUTPUT: RETVAL
2832 RETVAL
2833 2787
2834SV *get_chksum (faceidx idx, int faceset = 0) 2788SV *get_csum (faceidx idx, int faceset = 0)
2835 CODE: 2789 CODE:
2836 facedata *d = face_data (idx, faceset); 2790 facedata *d = face_data (idx, faceset);
2837 if (!d) XSRETURN_UNDEF; 2791 if (!d) XSRETURN_UNDEF;
2838 RETVAL = newSVpvn ((char *)d->chksum, d->chksum_len); 2792 RETVAL = newSVpvn ((char *)d->chksum, d->chksum_len);
2839 OUTPUT: 2793 OUTPUT: RETVAL
2840 RETVAL
2841 2794
2842SV *get_data (faceidx idx, int faceset = 0) 2795int get_type (faceidx idx)
2843 CODE: 2796 CODE:
2844 facedata *d = face_data (idx, faceset); 2797 faceinfo *f = face_info (idx);
2845 if (!d) XSRETURN_UNDEF; 2798 if (!f) XSRETURN_UNDEF;
2846 RETVAL = newSVpvn (d->data.data (), d->data.length ()); 2799 RETVAL = f->type;
2847 OUTPUT: 2800 OUTPUT: RETVAL
2848 RETVAL 2801
2802SV *get_name (faceidx idx)
2803 CODE:
2804 faceinfo *f = face_info (idx);
2805 if (!f) XSRETURN_UNDEF;
2806 RETVAL = to_sv (f->name);
2807 OUTPUT: RETVAL
2849 2808
2850void invalidate (faceidx idx) 2809void invalidate (faceidx idx)
2851 CODE: 2810 CODE:
2852 for_all_clients (ns) 2811 for_all_clients (ns)
2853 { 2812 ns->invalidate_face (idx);
2854 ns->faces_sent [idx] = false;
2855 ns->force_newmap = true;
2856 }
2857 2813
2858void invalidate_all () 2814void invalidate_all ()
2859 CODE: 2815 CODE:
2860 for_all_clients (ns) 2816 for_all_clients (ns)
2861 { 2817 ns->invalidate_all_faces ();
2862 ns->faces_sent.reset ();
2863 ns->force_newmap = true;
2864 }
2865 2818
2866MODULE = cf PACKAGE = cf::anim PREFIX = anim_ 2819MODULE = cf PACKAGE = cf::anim PREFIX = anim_
2867 2820
2868#INCLUDE: $PERL $srcdir/genacc faceset $srcdir/../include/anim.h | 2821#INCLUDE: $PERL $srcdir/genacc faceset $srcdir/../include/anim.h |
2869 2822
2873 OUTPUT: RETVAL 2826 OUTPUT: RETVAL
2874 2827
2875animidx set (utf8_string name, SV *frames, int facings = 1) 2828animidx set (utf8_string name, SV *frames, int facings = 1)
2876 CODE: 2829 CODE:
2877{ 2830{
2878 if (!SvROK (frames) && SvTYPE (SvRV (frames)) != SVt_PVAV) 2831 if (!SvROK (frames) && SvTYPE (SvRV (frames)) != SVt_PVAV)
2879 croak ("frames must be an arrayref"); 2832 croak ("frames must be an arrayref");
2880 2833
2881 AV *av = (AV *)SvRV (frames); 2834 AV *av = (AV *)SvRV (frames);
2882 2835
2883 animation *anim = &animation::find (name); 2836 animation *anim = &animation::find (name);
2884 if (anim->number) 2837 if (anim->number)
2885 { 2838 {
2886 anim->resize (av_len (av) + 1); 2839 anim->resize (av_len (av) + 1);
2887 anim->facings = facings; 2840 anim->facings = facings;
2888 } 2841 }
2923bool 2876bool
2924errors_are_fatal (bool fatal) 2877errors_are_fatal (bool fatal)
2925 CODE: 2878 CODE:
2926 RETVAL = object_thawer::errors_are_fatal; 2879 RETVAL = object_thawer::errors_are_fatal;
2927 object_thawer::errors_are_fatal = fatal; 2880 object_thawer::errors_are_fatal = fatal;
2928 OUTPUT: 2881 OUTPUT: RETVAL
2929 RETVAL
2930 2882
2931SV * 2883SV *
2932new_from_file (char *klass, octet_string path) 2884new_from_file (char *klass, octet_string path)
2933 CODE: 2885 CODE:
2934 object_thawer *f = new object_thawer (path); 2886 object_thawer *f = new object_thawer (path);
2960 XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ()))); 2912 XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ())));
2961 2913
2962 self->skip (); 2914 self->skip ();
2963 } 2915 }
2964 2916
2917MODULE = cf PACKAGE = cf::treasurelist
2918
2919# quick hack, because I didn't want to implement accessors for treasurelist.
2920# this asks for even more autogen, actually.
2921
2922void
2923expand (treasurelist *list)
2924 PPCODE:
2925 EXTEND (SP, 3);
2926 PUSHs (sv_2mortal (to_sv (list->name)));
2927 PUSHs (sv_2mortal (to_sv (list->total_chance)));
2928 AV *av = newAV ();
2929 PUSHs (sv_2mortal (newRV_noinc ((SV *)av)));
2930 for (treasure *item = list->items; item; item = item->next)
2931 {
2932 AV *iav = newAV ();
2933 av_push (av, newRV_noinc ((SV *)iav));
2934
2935 av_extend (iav, 7);
2936 av_push (iav, to_sv (item->item));
2937 av_push (iav, to_sv (item->name));
2938 av_push (iav, to_sv (item->change_arch.name));
2939 av_push (iav, to_sv (item->change_arch.title));
2940 av_push (iav, to_sv (item->change_arch.slaying));
2941 av_push (iav, to_sv (item->chance));
2942 av_push (iav, to_sv (item->nrof));
2943 av_push (iav, to_sv (item->magic));
2944 }
2945
2946MODULE = cf PACKAGE = cf::layout
2947
2948INCLUDE: $PERL $srcdir/genacc layout $srcdir/../include/rmg.h |
2949

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines