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.366 by root, Sun Apr 11 17:27:52 2010 UTC vs.
Revision 1.425 by root, Wed Nov 14 06:21:39 2012 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2006,2007,2008,2009,2010,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * 5 *
6 * Deliantra is free software: you can redistribute it and/or modify it under 6 * Deliantra is free software: you can redistribute it and/or modify it under
7 * the terms of the Affero GNU General Public License as published by the 7 * the terms of the Affero GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your 8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version. 9 * option) any later version.
10 * 10 *
11 * This program is distributed in the hope that it will be useful, 11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 * 15 *
16 * You should have received a copy of the Affero GNU General Public License 16 * You should have received a copy of the Affero GNU General Public License
17 * and the GNU General Public License along with this program. If not, see 17 * and the GNU General Public License along with this program. If not, see
18 * <http://www.gnu.org/licenses/>. 18 * <http://www.gnu.org/licenses/>.
19 * 19 *
20 * The authors can be reached via e-mail to <support@deliantra.net> 20 * The authors can be reached via e-mail to <support@deliantra.net>
21 */ 21 */
22 22
23#include "autoconf.h" 23#include "autoconf.h"
24 24
28 28
29#include <cstdarg> 29#include <cstdarg>
30#include <typeinfo> 30#include <typeinfo>
31 31
32#include "global.h" 32#include "global.h"
33#include "../random_maps/random_map.h" 33#include "rmg.h"
34#include "noise.h"
34#include "evthread.h" 35#include "evthread.h"
35#include "sproto.h" 36#include "sproto.h"
36 37
37#include <unistd.h> 38#include <unistd.h>
38#if _POSIX_MEMLOCK 39#if _POSIX_MEMLOCK
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,
97 *cv_cf_ix,
96 *cv_cf_tick, 98 *cv_cf_tick,
97 *cv_cf_match_match; 99 *cv_cf_match_match;
98 100
99#ifndef newSVpv_utf8 101#ifndef newSVpv_utf8
100static SV * 102static SV *
123 125
124 return sv; 126 return sv;
125} 127}
126#endif 128#endif
127 129
128static noinline utf8_string 130noinline utf8_string
129cfSvPVutf8_nolen (SV *sv) 131cfSvPVutf8_nolen (SV *sv)
130{ 132{
131 SvGETMAGIC (sv); 133 SvGETMAGIC (sv);
132 134
133 if (SvPOK (sv)) 135 if (SvPOK (sv))
230 do_destroy (); 232 do_destroy ();
231 sever_self (); 233 sever_self ();
232} 234}
233 235
234void 236void
237attachable::do_delete ()
238{
239 delete this;
240}
241
242void
235attachable::check_mortals () 243attachable::check_mortals ()
236{ 244{
237 static int i = 0; 245 static int i = 0;
238 246
239 for (;;) 247 for (;;)
246 { 254 {
247 static int last_mortalcount; 255 static int last_mortalcount;
248 if (mortals.size () != last_mortalcount) 256 if (mortals.size () != last_mortalcount)
249 { 257 {
250 last_mortalcount = mortals.size (); 258 last_mortalcount = mortals.size ();
251 LOG (llevInfo, "%d mortals.\n", (int)mortals.size ()); 259 object *specimen = is_a<object> (mortals [rndm (mortals.size ())]);
260
261 LOG (llevInfo, "%d mortals (random specimen: %s).\n",
262 (int)mortals.size (), specimen ? specimen->debug_desc () : "(not an object)");
252 263
253 if (0) 264 if (0)
254 { 265 {
255 for (int j = 0; j < mortals.size (); ++j)//D 266 for (int j = 0; j < mortals.size (); ++j)//D
256 fprintf (stderr, "%d:%s %p ", j, &((object *)mortals[j])->name, mortals[j]);//D 267 fprintf (stderr, "%d:%s %p ", j, &((object *)mortals[j])->name, mortals[j]);//D
268
257 fprintf (stderr, "\n");//D 269 fprintf (stderr, "\n");//D
258 } 270 }
259 } 271 }
260 } 272 }
261 273
281 } 293 }
282 else 294 else
283 { 295 {
284 mortals.erase (i); 296 mortals.erase (i);
285 obj->sever_self (); 297 obj->sever_self ();
286 delete obj; 298 obj->do_delete ();
287 } 299 }
288 } 300 }
289} 301}
290 302
291void 303void
346#endif 358#endif
347 359
348////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 360//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
349 361
350static SV * 362static SV *
351newSVptr (void *ptr, HV *stash, HV *hv = newHV ()) 363newSVptr (void *ptr, HV *stash, HV *hv)
352{ 364{
353 SV *sv;
354
355 if (!ptr) 365 if (!ptr)
356 return newSV (0); 366 return newSV (0);
357 367
358 sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, 0, (char *)ptr, 0); 368 sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, 0, (char *)ptr, 0);
359 return sv_bless (newRV_noinc ((SV *)hv), stash); 369 return sv_bless (newRV_noinc ((SV *)hv), stash);
370}
371
372static SV * noinline
373newSVptr (void *ptr, HV *stash)
374{
375 return newSVptr (ptr, stash, newHV ());
360} 376}
361 377
362static int 378static int
363attachable_free (pTHX_ SV *sv, MAGIC *mg) 379attachable_free (pTHX_ SV *sv, MAGIC *mg)
364{ 380{
376 return 0; 392 return 0;
377} 393}
378 394
379MGVTBL attachable::vtbl = {0, 0, 0, 0, attachable_free}; 395MGVTBL attachable::vtbl = {0, 0, 0, 0, attachable_free};
380 396
381static SV * 397static SV * noinline
382newSVattachable (attachable *obj, HV *stash) 398newSVattachable (attachable *obj, HV *stash)
383{ 399{
384 if (!obj) 400 if (!obj)
385 return newSV (0); 401 return newSV (0);
386 402
472 || (SvSTASH (SvRV (sv)) != stash_cf_object_wrap 488 || (SvSTASH (SvRV (sv)) != stash_cf_object_wrap
473 && SvSTASH (SvRV (sv)) != stash_cf_object_player_wrap 489 && SvSTASH (SvRV (sv)) != stash_cf_object_player_wrap
474 && SvSTASH (SvRV (sv)) != stash_cf_arch_wrap 490 && SvSTASH (SvRV (sv)) != stash_cf_arch_wrap
475 && !sv_derived_from (sv, "cf::object"))) 491 && !sv_derived_from (sv, "cf::object")))
476 croak ("object of type cf::object expected"); 492 croak ("object of type cf::object expected");
493
494 return SvPTR_nc (sv);
495}
496
497static long noinline
498SvPTR_ornull_maptile (SV *sv)
499{
500 if (expect_false (!SvOK (sv))) return 0;
501
502 if (!SvROK (sv)
503 || (SvSTASH (SvRV (sv)) != stash_cf_map_wrap
504 && SvSTASH (SvRV (sv)) != stash_ext_map_world
505 && !sv_derived_from (sv, "cf::map")))
506 croak ("object of type cf::map expected");
477 507
478 return SvPTR_nc (sv); 508 return SvPTR_nc (sv);
479} 509}
480 510
481static long noinline 511static long noinline
506static inline SV *to_sv (unsigned long long v) { return newSVval64 (v); } 536static inline SV *to_sv (unsigned long long v) { return newSVval64 (v); }
507static inline SV *to_sv (float v) { return newSVnv (v); } 537static inline SV *to_sv (float v) { return newSVnv (v); }
508static inline SV *to_sv (double v) { return newSVnv (v); } 538static inline SV *to_sv (double v) { return newSVnv (v); }
509static inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); } 539static inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); }
510static inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); } 540static inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); }
541// gcc dislikes noilnine on to_sv
511static inline SV *to_sv (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); } 542static noinline SV *to_sv_ni (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); }
543static inline SV *to_sv (object * v) { return to_sv_ni (v); }
512static inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); } 544static inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); }
513static inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); } 545static inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); }
514static inline SV *to_sv (region * v) { return newSVattachable (v, stash_cf_region_wrap); } 546static inline SV *to_sv (region * v) { return newSVattachable (v, stash_cf_region_wrap); }
515static inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); } 547static inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); }
516static inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } 548static inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); }
517static inline SV *to_sv (mapspace * v) { return newSVptr (v, stash_cf_mapspace_wrap); } 549static inline SV *to_sv (mapspace * v) { return newSVptr (v, stash_cf_mapspace_wrap); }
550static inline SV *to_sv (layout * v) { return newSVptr (v, stash_cf_layout_wrap); }
518 551
519static inline SV *to_sv (object & v) { return to_sv (&v); } 552static inline SV *to_sv (object & v) { return to_sv (&v); }
520static inline SV *to_sv (living & v) { return to_sv (&v); } 553static inline SV *to_sv (living & v) { return to_sv (&v); }
521 554
522static inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); } 555static inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); }
558static inline void sv_to (SV *sv, unsigned long &v) { v = SvUV (sv); } 591static inline void sv_to (SV *sv, unsigned long &v) { v = SvUV (sv); }
559static inline void sv_to (SV *sv, signed long long &v) { v = ( signed long long)SvVAL64 (sv); } 592static inline void sv_to (SV *sv, signed long long &v) { v = ( signed long long)SvVAL64 (sv); }
560static inline void sv_to (SV *sv, unsigned long long &v) { v = (unsigned long long)SvVAL64 (sv); } 593static inline void sv_to (SV *sv, unsigned long long &v) { v = (unsigned long long)SvVAL64 (sv); }
561static inline void sv_to (SV *sv, float &v) { v = SvNV (sv); } 594static inline void sv_to (SV *sv, float &v) { v = SvNV (sv); }
562static inline void sv_to (SV *sv, double &v) { v = SvNV (sv); } 595static inline void sv_to (SV *sv, double &v) { v = SvNV (sv); }
563static inline void sv_to (SV *sv, client * &v) { v = (client *) (attachable *)SvPTR_ornull_client (sv); } 596static inline void sv_to (SV *sv, client * &v) { v = (client *) (attachable *)SvPTR_ornull_client (sv); }
564static inline void sv_to (SV *sv, player * &v) { v = (player *) (attachable *)SvPTR_ornull_player (sv); } 597static inline void sv_to (SV *sv, player * &v) { v = (player *) (attachable *)SvPTR_ornull_player (sv); }
565static inline void sv_to (SV *sv, object * &v) { v = (object *) (attachable *)SvPTR_ornull_object (sv); } 598static inline void sv_to (SV *sv, object * &v) { v = (object *) (attachable *)SvPTR_ornull_object (sv); }
599static inline void sv_to (SV *sv, maptile * &v) { v = (maptile *) (attachable *)SvPTR_ornull_maptile (sv); }
566static inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)(attachable *)SvPTR_ornull (sv, "cf::arch"); } 600static inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)(attachable *)SvPTR_ornull (sv, "cf::arch"); }
567static inline void sv_to (SV *sv, maptile * &v) { v = (maptile *) (attachable *)SvPTR_ornull (sv, "cf::map"); }
568static inline void sv_to (SV *sv, region * &v) { v = (region *) (attachable *)SvPTR_ornull (sv, "cf::region"); } 601static inline void sv_to (SV *sv, region * &v) { v = (region *) (attachable *)SvPTR_ornull (sv, "cf::region"); }
569static inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } 602static inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); }
570static inline void sv_to (SV *sv, partylist * &v) { v = (partylist *) SvPTR_ornull (sv, "cf::party"); } 603static inline void sv_to (SV *sv, partylist * &v) { v = (partylist *) SvPTR_ornull (sv, "cf::party"); }
571static inline void sv_to (SV *sv, living * &v) { v = (living *) SvPTR_ornull (sv, "cf::living"); } 604static inline void sv_to (SV *sv, living * &v) { v = (living *) SvPTR_ornull (sv, "cf::living"); }
572static inline void sv_to (SV *sv, mapspace * &v) { v = (mapspace *) SvPTR_ornull (sv, "cf::mapspace"); } 605static inline void sv_to (SV *sv, mapspace * &v) { v = (mapspace *) SvPTR_ornull (sv, "cf::mapspace"); }
606static inline void sv_to (SV *sv, layout * &v) { v = (layout *) SvPTR_ornull (sv, "cf::layout"); }
573static inline void sv_to (SV *sv, object_freezer * &v) { v = (object_freezer *) SvPTR_ornull (sv, "cf::object::freezer"); } 607static inline void sv_to (SV *sv, object_freezer * &v) { v = (object_freezer *) SvPTR_ornull (sv, "cf::object::freezer"); }
574static inline void sv_to (SV *sv, object_thawer * &v) { v = (object_thawer *) SvPTR_ornull (sv, "cf::object::thawer" ); } 608static inline void sv_to (SV *sv, object_thawer * &v) { v = (object_thawer *) SvPTR_ornull (sv, "cf::object::thawer" ); }
575 609
576//static inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; } 610//static inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; }
577static inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); } 611static inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); }
590static inline void sv_to (SV *sv, std::string &v) 624static inline void sv_to (SV *sv, std::string &v)
591{ 625{
592 STRLEN len; 626 STRLEN len;
593 char *data = SvPVbyte (sv, len); 627 char *data = SvPVbyte (sv, len);
594 v.assign (data, len); 628 v.assign (data, len);
629}
630
631static inline void sv_to (SV *sv, refcnt_buf &v)
632{
633 STRLEN len;
634 char *data = SvPVbyte (sv, len);
635 refcnt_buf buf (data, len);
636 v = buf;
595} 637}
596 638
597static inline void sv_to (SV *sv, UUID &v) 639static inline void sv_to (SV *sv, UUID &v)
598{ 640{
599 if (!v.parse (SvPV_nolen (sv))) 641 if (!v.parse (SvPV_nolen (sv)))
688template<class type> 730template<class type>
689static void noinline 731static void noinline
690cf_obj_to (SV *arg, type &var) 732cf_obj_to (SV *arg, type &var)
691{ 733{
692 sv_to (arg, var); 734 sv_to (arg, var);
693 if (!var) 735 if (expect_false (!var))
694 croak ("must not pass invalid/null cf_obj here"); 736 croak ("must not pass invalid/null cf_obj here");
695} 737}
696 738
697template<class object> 739template<class object>
698static void noinline 740static void noinline
699cf_obj_ornull_to (SV *arg, object *&var) 741cf_obj_ornull_to (SV *arg, object *&var)
700{ 742{
701 if (SvOK (arg)) 743 if (SvOK (arg))
702 { 744 {
703 sv_to (arg, var); 745 sv_to (arg, var);
704 if (!var) 746 if (expect_false (!var))
705 croak ("unable to convert perl object to C++ object"); 747 croak ("unable to convert perl object to C++ object");
706 } 748 }
707 else 749 else
708 var = 0; 750 var = 0;
709} 751}
744 exit (EXIT_FAILURE); 786 exit (EXIT_FAILURE);
745 } 787 }
746 788
747 eval_pv ( 789 eval_pv (
748 "#line 1 'cfperl init'\n" 790 "#line 1 'cfperl init'\n"
749 "use EV ();\n" 791 "use EV ();\n" // required by bootstrap
750 "use Coro ();\n" 792 "use Coro ();\n" // required by bootstrap
751 "cf->bootstrap;\n" 793 "cf->bootstrap;\n" // required for cf::datadir
752 "unshift @INC, cf::datadir ();\n" 794 "unshift @INC, cf::datadir ();\n" // required for 'require' :)
753 "require cf;\n", 795 "require cf;\n",
754 0 796 0
755 ); 797 );
756 798
757 if (SvTRUE (ERRSV)) 799 if (SvTRUE (ERRSV))
1116 CALL_ARG (originator); 1158 CALL_ARG (originator);
1117 CALL_CALL ("cf::mapscript::activate", G_VOID); 1159 CALL_CALL ("cf::mapscript::activate", G_VOID);
1118 CALL_END; 1160 CALL_END;
1119} 1161}
1120 1162
1163void cfperl_ix (client *ns, int set, faceidx idx, int pri)
1164{
1165 CALL_BEGIN (3);
1166 CALL_ARG (ns);
1167 CALL_ARG (set);
1168 CALL_ARG (idx);
1169 CALL_ARG (pri);
1170 CALL_CALL (cv_cf_ix, G_VOID);
1171 CALL_END;
1172}
1173
1121player * 1174player *
1122player::find (const_utf8_string name) 1175player::find (const_utf8_string name)
1123{ 1176{
1124 CALL_BEGIN (1); 1177 CALL_BEGIN (1);
1125 CALL_ARG (name); 1178 CALL_ARG (name);
1132 1185
1133 return retval; 1186 return retval;
1134} 1187}
1135 1188
1136maptile * 1189maptile *
1137find_style (const_utf8_string dirname, const_utf8_string stylename, int difficulty) 1190find_style (const_utf8_string dirname, const_utf8_string stylename, int difficulty, bool recurse)
1138{ 1191{
1139 CALL_BEGIN (3); 1192 CALL_BEGIN (4);
1140 CALL_ARG (dirname); 1193 CALL_ARG (dirname);
1141 CALL_ARG (stylename); 1194 CALL_ARG (stylename);
1142 CALL_ARG (difficulty); 1195 CALL_ARG (difficulty);
1196 CALL_ARG (recurse);
1143 CALL_CALL ("ext::map_random::find_style", G_SCALAR); 1197 CALL_CALL ("ext::map_random::find_style", G_SCALAR);
1144 1198
1145 maptile *retval = 0; 1199 maptile *retval = 0;
1146 if (count) sv_to (POPs, retval); 1200 if (count) sv_to (POPs, retval);
1147 1201
1370 stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1); 1424 stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1);
1371 stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1); 1425 stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1);
1372 stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1); 1426 stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1);
1373 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); 1427 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1);
1374 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1); 1428 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1);
1429 stash_cf_layout_wrap = gv_stashpv ("cf::layout::wrap", 1);
1430 stash_ext_map_world = gv_stashpv ("ext::map_world" , 1);
1375 1431
1376 sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV); 1432 sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV);
1377 sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV); 1433 sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV);
1434 sv_server_tick = get_sv ("cf::SERVER_TICK", 1); SvUPGRADE (sv_server_tick, SVt_IV);
1378 sv_tick_start = get_sv ("cf::TICK_START", 1); SvUPGRADE (sv_tick_start, SVt_NV); 1435 sv_tick_start = get_sv ("cf::TICK_START" , 1); SvUPGRADE (sv_tick_start , SVt_NV);
1379 sv_next_tick = get_sv ("cf::NEXT_TICK" , 1); SvUPGRADE (sv_next_tick , SVt_NV); 1436 sv_next_tick = get_sv ("cf::NEXT_TICK" , 1); SvUPGRADE (sv_next_tick , SVt_NV);
1380 1437
1381 cb_global = get_av ("cf::CB_GLOBAL", 1); 1438 cb_global = get_av ("cf::CB_GLOBAL", 1);
1382 cb_attachable = get_av ("cf::CB_ATTACHABLE", 1); 1439 cb_attachable = get_av ("cf::CB_ATTACHABLE", 1);
1383 cb_object = get_av ("cf::CB_OBJECT", 1); 1440 cb_object = get_av ("cf::CB_OBJECT", 1);
1384 cb_player = get_av ("cf::CB_PLAYER", 1); 1441 cb_player = get_av ("cf::CB_PLAYER", 1);
1391_connect_to_perl_2 () 1448_connect_to_perl_2 ()
1392{ 1449{
1393 cv_cf_do_invoke = (SV *)get_cv ("cf::do_invoke" , 0); assert (cv_cf_do_invoke); 1450 cv_cf_do_invoke = (SV *)get_cv ("cf::do_invoke" , 0); assert (cv_cf_do_invoke);
1394 cv_cf__can_merge = (SV *)get_cv ("cf::_can_merge" , 0); assert (cv_cf__can_merge); 1451 cv_cf__can_merge = (SV *)get_cv ("cf::_can_merge" , 0); assert (cv_cf__can_merge);
1395 cv_cf_client_send_msg = (SV *)get_cv ("cf::client::send_msg", 0); assert (cv_cf_client_send_msg); 1452 cv_cf_client_send_msg = (SV *)get_cv ("cf::client::send_msg", 0); assert (cv_cf_client_send_msg);
1453 cv_cf_ix = (SV *)get_cv ("cf::face::ix" , 0); assert (cv_cf_ix);
1396 cv_cf_tick = (SV *)get_cv ("cf::tick" , 0); assert (cv_cf_tick); 1454 cv_cf_tick = (SV *)get_cv ("cf::tick" , 0); assert (cv_cf_tick);
1397 cv_cf_match_match = (SV *)get_cv ("cf::match::match" , 0); assert (cv_cf_match_match); 1455 cv_cf_match_match = (SV *)get_cv ("cf::match::match" , 0); assert (cv_cf_match_match);
1398} 1456}
1399 1457
1400MODULE = cf PACKAGE = cf PREFIX = cf_ 1458MODULE = cf PACKAGE = cf PREFIX = cf_
1405 I_CORO_API (PACKAGE); coroapi::GCoroAPI = GCoroAPI; 1463 I_CORO_API (PACKAGE); coroapi::GCoroAPI = GCoroAPI;
1406 1464
1407 _connect_to_perl_1 (); 1465 _connect_to_perl_1 ();
1408 1466
1409 newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1)); 1467 newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1));
1410
1411 //{
1412 // require_pv ("Time::HiRes");
1413 //
1414 // SV **svp = hv_fetch (PL_modglobal, "Time::NVtime", 12, 0);
1415 // if (!svp) croak ("Time::HiRes is required");
1416 // if (!SvIOK(*svp)) croak ("Time::NVtime isn’t a function pointer");
1417 // coroapi::time = INT2PTR (double(*)(), SvIV(*svp));
1418 //}
1419 1468
1420 static const struct { 1469 static const struct {
1421 const char *name; 1470 const char *name;
1422 IV iv; 1471 IV iv;
1423 } *civ, const_iv[] = { 1472 } *civ, const_iv[] = {
1427# include "attackinc.h" 1476# include "attackinc.h"
1428# undef def 1477# undef def
1429# define def(uc, flags) const_iv (SK_ ## uc) 1478# define def(uc, flags) const_iv (SK_ ## uc)
1430# include "skillinc.h" 1479# include "skillinc.h"
1431# undef def 1480# undef def
1432 1481# define def(name, use, nonuse) const_iv (body_ ## name)
1433 const_iv (llevError) const_iv (llevInfo) const_iv (llevDebug) const_iv (llevMonster) 1482# include "slotinc.h"
1434 const_iv (logBacktrace) 1483# undef def
1435
1436 const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd)
1437 1484
1438 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) 1485 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y)
1439 1486
1440 const_iv (MAX_TIME) 1487 const_iv (MAX_TIME)
1441 const_iv (MAXSOCKBUF) 1488 const_iv (MAXSOCKBUF)
1455 const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE) 1502 const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE)
1456 1503
1457 const_iv (SK_EXP_ADD_SKILL) const_iv (SK_EXP_TOTAL) const_iv (SK_EXP_NONE) 1504 const_iv (SK_EXP_ADD_SKILL) const_iv (SK_EXP_TOTAL) const_iv (SK_EXP_NONE)
1458 const_iv (SK_SUBTRACT_SKILL_EXP) const_iv (SK_EXP_SKILL_ONLY) 1505 const_iv (SK_SUBTRACT_SKILL_EXP) const_iv (SK_EXP_SKILL_ONLY)
1459 1506
1460 const_iv (MAP_ACTIVE) const_iv (MAP_SWAPPED) const_iv (MAP_LOADING) const_iv (MAP_SAVING)
1461 const_iv (MAP_INACTIVE)
1462
1463 const_iv (KLASS_ATTACHABLE) const_iv (KLASS_GLOBAL) const_iv (KLASS_OBJECT) 1507 const_iv (KLASS_ATTACHABLE) const_iv (KLASS_GLOBAL) const_iv (KLASS_OBJECT)
1464 const_iv (KLASS_CLIENT) const_iv (KLASS_PLAYER) const_iv (KLASS_MAP) 1508 const_iv (KLASS_CLIENT) const_iv (KLASS_PLAYER) const_iv (KLASS_MAP)
1465 1509
1466 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT) 1510 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT)
1467 1511
1468 const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES) 1512 const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES)
1469 }; 1513 };
1470 1514
1471 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 1515 for (civ = const_iv + array_length (const_iv); civ-- > const_iv; )
1472 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv)); 1516 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv));
1473 1517
1474 static const struct { 1518 static const struct {
1475 const char *name; 1519 const char *name;
1476 int skip; 1520 int skip;
1482# undef def 1526# undef def
1483 }; 1527 };
1484 1528
1485 AV *av = get_av ("cf::EVENT", 1); 1529 AV *av = get_av ("cf::EVENT", 1);
1486 1530
1487 for (eiv = event_iv + sizeof (event_iv) / sizeof (event_iv [0]); eiv-- > event_iv; ) 1531 for (eiv = event_iv + array_length (event_iv); eiv-- > event_iv; )
1488 { 1532 {
1489 AV *event = newAV (); 1533 AV *event = newAV ();
1490 av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0)); 1534 av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0));
1491 av_push (event, newSViv (eiv->klass)); 1535 av_push (event, newSViv (eiv->klass));
1492 av_store (av, eiv->iv, newRV_noinc ((SV *)event)); 1536 av_store (av, eiv->iv, newRV_noinc ((SV *)event));
1499 1543
1500void _gv_clear (SV *gv) 1544void _gv_clear (SV *gv)
1501 CODE: 1545 CODE:
1502 assert (SvTYPE (gv) == SVt_PVGV); 1546 assert (SvTYPE (gv) == SVt_PVGV);
1503# define f(sv) { SV *sv_ = (SV *)(sv); sv = 0; SvREFCNT_dec (sv_); } 1547# define f(sv) { SV *sv_ = (SV *)(sv); sv = 0; SvREFCNT_dec (sv_); }
1548 SvREFCNT_inc (gv);
1504 f (GvGP (gv)->gp_form); 1549 f (GvGP (gv)->gp_form);
1505 f (GvGP (gv)->gp_io); 1550 f (GvGP (gv)->gp_io);
1506 f (GvGP (gv)->gp_sv); 1551 f (GvGP (gv)->gp_sv);
1507 f (GvGP (gv)->gp_av); 1552 f (GvGP (gv)->gp_av);
1508 f (GvGP (gv)->gp_hv); 1553 f (GvGP (gv)->gp_hv);
1509 f (GvGP (gv)->gp_cv); 1554 f (GvGP (gv)->gp_cv);
1510 GvCVGEN (gv) = 0; 1555 GvCVGEN (gv) = 0;
1511 GvMULTI_off (gv); 1556 GvMULTI_off (gv);
1557 SvREFCNT_dec (gv);
1512# undef f 1558# undef f
1513 1559
1514void _connect_to_perl_1 () 1560void _connect_to_perl_1 ()
1515 1561
1516void _connect_to_perl_2 () 1562void _connect_to_perl_2 ()
1527 1573
1528 for_all_objects (op) 1574 for_all_objects (op)
1529 op->reattach (); 1575 op->reattach ();
1530} 1576}
1531 1577
1532# support function for map-world.ext
1533void _quantise (SV *data_sv, SV *plt_sv)
1534 CODE:
1535{
1536 if (!SvROK (plt_sv) || SvTYPE (SvRV (plt_sv)) != SVt_PVAV)
1537 croak ("_quantise called with invalid agruments");
1538
1539 plt_sv = SvRV (plt_sv);
1540 SV **plt = AvARRAY (plt_sv);
1541 int plt_count = AvFILL (plt_sv) + 1;
1542
1543 STRLEN len;
1544 char *data = SvPVbyte (data_sv, len);
1545 char *dst = data;
1546
1547 while (len >= 3)
1548 {
1549 for (SV **val_sv = plt + plt_count; val_sv-- > plt; )
1550 {
1551 char *val = SvPVX (*val_sv);
1552
1553 if (val [0] == data [0]
1554 && val [1] == data [1]
1555 && val [2] == data [2])
1556 {
1557 *dst++ = val [3];
1558 goto next;
1559 }
1560 }
1561
1562 croak ("_quantise: color not found in palette: #%02x%02x%02x, at offset %d %d",
1563 (uint8_t)data [0], (uint8_t)data [1], (uint8_t)data [2],
1564 dst - SvPVX (data_sv), len);
1565
1566 next:
1567 data += 3;
1568 len -= 3;
1569 }
1570
1571 SvCUR_set (data_sv, dst - SvPVX (data_sv));
1572}
1573
1574void init_anim () 1578void init_anim ()
1575 1579
1576void init_globals () 1580void init_globals ()
1577 1581
1578void init_experience ()
1579
1580void init_attackmess () 1582void init_attackmess ()
1581 1583
1582void init_dynamic () 1584void init_dynamic ()
1583 1585
1584void load_settings () 1586void load_settings ()
1585 1587
1588void _reload_exp_table ()
1589
1586void load_materials () 1590void _reload_materials ()
1587 1591
1588void init_uuid () 1592void init_uuid ()
1589 CODE: 1593 CODE:
1590 UUID::init (); 1594 UUID::init ();
1591 1595
1624 { 1628 {
1625 ev_async_send (EV_DEFAULT, &tick_watcher); 1629 ev_async_send (EV_DEFAULT, &tick_watcher);
1626 coroapi::cede (); 1630 coroapi::cede ();
1627 } 1631 }
1628 1632
1629void server_tick () 1633void one_tick ()
1630 CODE: 1634 CODE:
1631{ 1635{
1632 ev_now_update (EV_DEFAULT); 1636 ev_now_update (EV_DEFAULT);
1633 NOW = ev_now (EV_DEFAULT); 1637 NOW = ev_now (EV_DEFAULT);
1634 SvNV_set (sv_now, NOW); SvNOK_only (sv_now); 1638 SvNV_set (sv_now, NOW); SvNOK_only (sv_now);
1635 SvNV_set (sv_tick_start, NOW); SvNOK_only (sv_tick_start); 1639 SvNV_set (sv_tick_start, NOW); SvNOK_only (sv_tick_start);
1636 runtime = SvNVX (sv_runtime); 1640 runtime = SvNVX (sv_runtime);
1637 1641
1642 one_tick ();
1643
1638 server_tick (); 1644 ++server_tick;
1645 SvUV_set (sv_server_tick, server_tick); SvIOK_only_UV (sv_server_tick);
1639 1646
1640 ev_now_update (EV_DEFAULT); 1647 ev_now_update (EV_DEFAULT);
1641 NOW = ev_now (EV_DEFAULT); 1648 NOW = ev_now (EV_DEFAULT);
1642 SvNV_set (sv_now, NOW); SvNOK_only (sv_now); 1649 SvNV_set (sv_now, NOW); SvNOK_only (sv_now);
1650
1643 runtime += TICK; 1651 runtime += TICK;
1644 SvNV_set (sv_runtime, runtime); SvNOK_only (sv_runtime); 1652 SvNV_set (sv_runtime, runtime); SvNOK_only (sv_runtime);
1645} 1653}
1646 1654
1647NV floor (NV x) 1655NV floor (NV x)
1651NV rndm (...) 1659NV rndm (...)
1652 ALIAS: 1660 ALIAS:
1653 rmg_rndm = 1 1661 rmg_rndm = 1
1654 CODE: 1662 CODE:
1655{ 1663{
1656 rand_gen &gen = ix ? rmg_rndm : rndm; 1664 rand_gen &gen = ix ? rmg_rndm : rndm;
1657 switch (items) 1665 switch (items)
1658 { 1666 {
1659 case 0: RETVAL = gen (); break; 1667 case 0: RETVAL = gen (); break;
1660 case 1: RETVAL = gen (SvUV (ST (0))); break; 1668 case 1: RETVAL = gen (SvUV (ST (0))); break;
1661 case 2: RETVAL = gen (SvIV (ST (0)), SvIV (ST (1))); break; 1669 case 2: RETVAL = gen (SvIV (ST (0)), SvIV (ST (1))); break;
1662 default: croak ("cf::rndm requires none, one or two parameters."); break; 1670 default: croak ("cf::rndm requires zero, one or two parameters."); break;
1663 } 1671 }
1664} 1672}
1665 OUTPUT: 1673 OUTPUT:
1666 RETVAL 1674 RETVAL
1667 1675
1746 1754
1747int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) 1755int mlockall (int flags = MCL_CURRENT | MCL_FUTURE)
1748 INIT: 1756 INIT:
1749#if __GLIBC__ 1757#if __GLIBC__
1750 mallopt (M_TOP_PAD, 1024 * 1024); 1758 mallopt (M_TOP_PAD, 1024 * 1024);
1751 mallopt (M_MMAP_THRESHOLD, 1024 * 1024 * 128); 1759 mallopt (M_MMAP_THRESHOLD, 1024 * 1024);
1752 mallopt (M_MMAP_MAX, 0); // likely bug-workaround, also frees memory 1760 mallopt (M_MMAP_MAX, 0); // likely bug-workaround, also frees memory
1761 if (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 10))
1753 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc 1762 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc
1754#endif 1763#endif
1755 1764
1756int munlockall () 1765int munlockall ()
1757 1766
1758#endif 1767#endif
1784 PUSHs (sv_2mortal (newSVpv ("objects" , 0))); PUSHs (sv_2mortal (newSVuv (objects.size () * sizeof (object)))); 1793 PUSHs (sv_2mortal (newSVpv ("objects" , 0))); PUSHs (sv_2mortal (newSVuv (objects.size () * sizeof (object))));
1785 PUSHs (sv_2mortal (newSVpv ("sv_count" , 0))); PUSHs (sv_2mortal (newSVuv (PL_sv_count))); 1794 PUSHs (sv_2mortal (newSVpv ("sv_count" , 0))); PUSHs (sv_2mortal (newSVuv (PL_sv_count)));
1786 PUSHs (sv_2mortal (newSVpv ("sv_objcount", 0))); PUSHs (sv_2mortal (newSVuv (PL_sv_objcount))); 1795 PUSHs (sv_2mortal (newSVpv ("sv_objcount", 0))); PUSHs (sv_2mortal (newSVuv (PL_sv_objcount)));
1787} 1796}
1788 1797
1789int find_animation (utf8_string text)
1790 PROTOTYPE: $
1791
1792int random_roll (int min, int max, object *op, int goodbad); 1798int random_roll (int min, int max, object *op, int goodbad);
1793 1799
1794const_utf8_string cost_string_from_value(uint64 cost, int approx = 0) 1800const_utf8_string cost_string_from_value(uint64 cost, int approx = 0)
1795 1801
1796int
1797exp_to_level (val64 exp) 1802int exp_to_level (val64 exp)
1803
1804val64 level_to_min_exp (int level)
1805
1806const_utf8_string
1807spellpathnames (int idx)
1808 CODE:
1809 RETVAL = spellpathnames [idx];
1810 OUTPUT: RETVAL
1811
1812SV *
1813attacktype_name (int atnr)
1798 CODE: 1814 CODE:
1799{ 1815 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1800 int i = 0; 1816 ? newSVpv (attacktype_name [atnr], 0)
1801 1817 : &PL_sv_undef;
1802 RETVAL = settings.max_level;
1803
1804 for (i = 1; i <= settings.max_level; i++)
1805 {
1806 if (levels[i] > exp)
1807 {
1808 RETVAL = i - 1;
1809 break;
1810 }
1811 }
1812}
1813 OUTPUT: RETVAL 1818 OUTPUT: RETVAL
1814 1819
1815val64
1816level_to_min_exp (int level)
1817 CODE:
1818 if (level > settings.max_level)
1819 RETVAL = levels[settings.max_level];
1820 else if (level < 1)
1821 RETVAL = 0;
1822 else
1823 RETVAL = levels[level];
1824 OUTPUT: RETVAL
1825
1826SV * 1820SV *
1827resistance_to_string (int atnr) 1821attacktype_desc (int atnr)
1828 CODE: 1822 CODE:
1829 if (atnr >= 0 && atnr < NROFATTACKS) 1823 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1824 ? newSVpv (attacktype_desc [atnr], 0)
1825 : &PL_sv_undef;
1826 OUTPUT: RETVAL
1827
1828SV *
1829resist_plus (int atnr)
1830 CODE:
1831 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1830 RETVAL = newSVpv (resist_plus[atnr], 0); 1832 ? newSVpv (resist_plus [atnr], 0)
1831 else 1833 : &PL_sv_undef;
1832 XSRETURN_UNDEF; 1834 OUTPUT: RETVAL
1835
1836SV *
1837change_resist_msg (int atnr)
1838 CODE:
1839 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1840 ? newSVpv (change_resist_msg [atnr], 0)
1841 : &PL_sv_undef;
1833 OUTPUT: RETVAL 1842 OUTPUT: RETVAL
1834 1843
1835UUID 1844UUID
1836uuid_cur () 1845uuid_cur ()
1837 CODE: 1846 CODE:
1878load_resource_file_ (octet_string filename) 1887load_resource_file_ (octet_string filename)
1879 1888
1880void 1889void
1881fix_weight () 1890fix_weight ()
1882 1891
1892utf8_string
1893expand_cfpod (int hintmode, int gender, const_utf8_string cfpod)
1894 PPCODE:
1895 XPUSHs (to_sv (player::expand_cfpod (hintmode, gender, cfpod)));
1896
1883MODULE = cf PACKAGE = cf::attachable 1897MODULE = cf PACKAGE = cf::attachable
1884 1898
1885int 1899int
1886valid (SV *obj) 1900valid (SV *obj)
1887 CODE: 1901 CODE:
1888 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); 1902 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext);
1889 OUTPUT: 1903 OUTPUT:
1890 RETVAL 1904 RETVAL
1905
1906bool should_invoke (attachable *obj, int event)
1907 CODE:
1908 RETVAL = obj->should_invoke ((event_type)event);
1909 OUTPUT: RETVAL
1891 1910
1892void 1911void
1893debug_trace (attachable *obj, bool on = true) 1912debug_trace (attachable *obj, bool on = true)
1894 CODE: 1913 CODE:
1895 obj->attachable_flags &= ~attachable::F_DEBUG_TRACE; 1914 obj->attachable_flags &= ~attachable::F_DEBUG_TRACE;
1955int mortals_size () 1974int mortals_size ()
1956 CODE: 1975 CODE:
1957 RETVAL = attachable::mortals.size (); 1976 RETVAL = attachable::mortals.size ();
1958 OUTPUT: RETVAL 1977 OUTPUT: RETVAL
1959 1978
1960const_utf8_string slot_use_name (U32 slot) 1979const_utf8_string slot_name (U32 slot)
1961 ALIAS: 1980 ALIAS:
1981 slot_name = 0
1982 slot_use_name = 1
1962 slot_nonuse_name = 1 1983 slot_nonuse_name = 2
1963 CODE: 1984 CODE:
1964{ 1985{
1965 if (slot >= NUM_BODY_LOCATIONS) 1986 if (slot >= NUM_BODY_LOCATIONS)
1966 croak ("body slot index out of range"); 1987 croak ("body slot index out of range");
1967 1988
1968 switch (ix) 1989 switch (ix)
1969 { 1990 {
1991 case 0: RETVAL = body_locations[slot].name ; break;
1970 case 0: RETVAL = body_locations[slot].use_name; break; 1992 case 1: RETVAL = body_locations[slot].use_name ; break;
1971 case 1: RETVAL = body_locations[slot].nonuse_name; break; 1993 case 2: RETVAL = body_locations[slot].nonuse_name; break;
1972 } 1994 }
1973} 1995}
1974 OUTPUT: 1996 OUTPUT:
1975 RETVAL 1997 RETVAL
1976 1998
2021 OUTPUT: 2043 OUTPUT:
2022 RETVAL 2044 RETVAL
2023 2045
2024object *find_best_object_match (object *op, utf8_string match) 2046object *find_best_object_match (object *op, utf8_string match)
2025 2047
2026object *find_marked_object (object *op)
2027
2028int need_identify (object *obj);
2029
2030int apply_shop_mat (object *shop_mat, object *op); 2048int apply_shop_mat (object *shop_mat, object *op);
2031 2049
2032int move (object *op, int dir, object *originator = op) 2050int move (object *op, int dir, object *originator = op)
2033 CODE: 2051 CODE:
2034 RETVAL = op->move (dir, originator); 2052 RETVAL = op->move (dir, originator);
2086 2104
2087void pick_up (object *who, object *op) 2105void pick_up (object *who, object *op)
2088 2106
2089void update_object (object *op, int action) 2107void update_object (object *op, int action)
2090 2108
2091void change_exp (object *op, uint64 exp, utf8_string skill_name = 0, int flag = 0) 2109void change_exp (object *op, uint64 exp, shstr_tmp skill_name = shstr_tmp (), int flag = 0)
2092 2110
2093void player_lvl_adj (object *who, object *skill = 0) 2111void player_lvl_adj (object *who, object *skill = 0)
2094 2112
2095int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL) 2113int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL)
2096 2114
2105int convert_item (object *item, object *converter) 2123int convert_item (object *item, object *converter)
2106 2124
2107void fix_generated_item (object *op, object *creator, int difficulty, int max_magic, int flags); 2125void fix_generated_item (object *op, object *creator, int difficulty, int max_magic, int flags);
2108 2126
2109MODULE = cf PACKAGE = cf::object PREFIX = cf_ 2127MODULE = 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 2128
2114object *new (utf8_string archetype = 0) 2129object *new (utf8_string archetype = 0)
2115 PROTOTYPE: ;$ 2130 PROTOTYPE: ;$
2116 CODE: 2131 CODE:
2117 RETVAL = archetype ? get_archetype (archetype) : object::create (); 2132 RETVAL = archetype
2133 ? archetype::get (archetype)
2134 : object::create ();
2118 OUTPUT: 2135 OUTPUT:
2119 RETVAL 2136 RETVAL
2120 2137
2121object *generate (utf8_string arch, object *creator) 2138object *generate (utf8_string arch, object *creator)
2122 CODE: 2139 CODE:
2123 object *obj = get_archetype (arch); 2140 object *obj = archetype::get (arch);
2124 fix_generated_item (obj, creator, 0, 0, GT_MINIMAL); 2141 fix_generated_item (obj, creator, 0, 0, GT_MINIMAL);
2125 RETVAL = obj; 2142 RETVAL = obj;
2126 OUTPUT: 2143 OUTPUT:
2127 RETVAL 2144 RETVAL
2128 2145
2138 RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y); 2155 RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y);
2139 2156
2140 if (RETVAL->destroyed ()) 2157 if (RETVAL->destroyed ())
2141 RETVAL = 0; 2158 RETVAL = 0;
2142} 2159}
2160 OUTPUT:
2161 RETVAL
2143 2162
2144shstr 2163shstr
2145object::kv_get (shstr key) 2164object::kv_get (shstr key)
2165 CODE:
2166 RETVAL = THIS->kv.get (key);
2167 OUTPUT:
2168 RETVAL
2146 2169
2147void 2170void
2148object::kv_del (shstr key) 2171object::kv_del (shstr key)
2172 CODE:
2173 THIS->kv.del (key);
2149 2174
2150void 2175void
2151object::kv_set (shstr key, shstr value) 2176object::kv_set (shstr key, shstr value)
2177 CODE:
2178 THIS->kv.set (key, value);
2152 2179
2153object *get_nearest_player (object *ob) 2180object *get_nearest_player (object *ob)
2154 ALIAS: nearest_player = 0 2181 ALIAS: nearest_player = 0
2155 PREINIT: 2182 PREINIT:
2156 extern object *get_nearest_player (object *); 2183 extern object *get_nearest_player (object *);
2359 if (pl->ob && pl->ob->map == THIS) 2386 if (pl->ob && pl->ob->map == THIS)
2360 PUSHs (sv_2mortal (to_sv (pl->ob))); 2387 PUSHs (sv_2mortal (to_sv (pl->ob)));
2361 } 2388 }
2362 2389
2363void 2390void
2391maptile::gen_quadmap (int x, int y, int z)
2392 CODE:
2393 gen_quadmap (THIS, x * 50, y * 50, z);
2394
2395void
2364maptile::add_underlay (SV *data, int offset, int stride, SV *palette) 2396maptile::add_underlay (SV *data, int offset, int stride, SV *palette)
2365 CODE: 2397 CODE:
2366{ 2398{
2367 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV) 2399 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV)
2368 croak ("maptile::add_underlay: palette must be arrayref"); 2400 croak ("maptile::add_underlay: palette must be arrayref");
2369 2401
2370 palette = SvRV (palette); 2402 palette = SvRV (palette);
2371 2403
2372 STRLEN idxlen; 2404 STRLEN idxlen;
2373 const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen); 2405 const uint8 *idx = (const uint8 *)SvPVbyte (data, idxlen);
2374 2406
2375 for (int x = 0; x < THIS->width; ++x) 2407 for (int x = 0; x < THIS->width; ++x)
2376 for (int y = 0; y < THIS->height; ++y) 2408 for (int y = 0; y < THIS->height; ++y)
2377 { 2409 {
2378 for (object *op = THIS->at (x, y).bot; op; op = op->above) 2410 for (object *op = THIS->at (x, y).bot; op; op = op->above)
2384 2416
2385 if (IN_RANGE_EXC (offs, 0, idxlen)) 2417 if (IN_RANGE_EXC (offs, 0, idxlen))
2386 { 2418 {
2387 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) 2419 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0))
2388 { 2420 {
2389 object *ob = get_archetype (cfSvPVutf8_nolen (*elem)); 2421 object *ob = archetype::get (cfSvPVutf8_nolen (*elem));
2390 ob->flag [FLAG_NO_MAP_SAVE] = true; 2422 ob->flag [FLAG_NO_MAP_SAVE] = true;
2391 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); 2423 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY);
2392 2424
2393 if (ob->randomitems && !ob->above) 2425 if (ob->randomitems && !ob->above)
2394 { 2426 {
2398 op->flag [FLAG_NO_MAP_SAVE] = true; 2430 op->flag [FLAG_NO_MAP_SAVE] = true;
2399 // TODO: if this is a pickable object, then the item 2431 // TODO: if this is a pickable object, then the item
2400 // will at a bit weird - saving inside the player 2432 // will at a bit weird - saving inside the player
2401 // will clear the flag, but when the player drops 2433 // will clear the flag, but when the player drops
2402 // it without logging out, it keeps the flag. 2434 // it without logging out, it keeps the flag.
2403 // nobody ahs reported this, but this can be rather 2435 // nobody has reported this, but this can be rather
2404 // annoying on persistent maps. 2436 // annoying on persistent maps.
2405 } 2437 }
2406 } 2438 }
2407 } 2439 }
2408 } 2440 }
2409
2410 skip: ; 2441 skip: ;
2411 } 2442 }
2412} 2443}
2413 2444
2414void 2445void
2419 croak ("maptile::set_regiondata: palette must be arrayref"); 2450 croak ("maptile::set_regiondata: palette must be arrayref");
2420 2451
2421 palette = SvRV (palette); 2452 palette = SvRV (palette);
2422 2453
2423 STRLEN idxlen; 2454 STRLEN idxlen;
2424 const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen); 2455 const uint8 *idx = (const uint8 *)SvPVbyte (data, idxlen);
2425 2456
2426 region_ptr *regionmap = new region_ptr [av_len ((AV *)palette) + 1]; 2457 region_ptr *regionmap = new region_ptr [av_len ((AV *)palette) + 1];
2427 uint8_t *regions = salloc<uint8_t> (THIS->size ()); 2458 uint8 *regions = salloc<uint8_t> (THIS->size ());
2428 2459
2429 for (int i = av_len ((AV *)palette) + 1; i--; ) 2460 for (int i = av_len ((AV *)palette) + 1; i--; )
2430 regionmap [i] = region::find (cfSvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1))); 2461 regionmap [i] = region::find (cfSvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1)));
2431 2462
2432 for (int y = 0; y < THIS->height; ++y) 2463 for (int y = 0; y < THIS->height; ++y)
2445 for (int x = 0; x < THIS->width; ++x) 2476 for (int x = 0; x < THIS->width; ++x)
2446 for (int y = 0; y < THIS->height; ++y) 2477 for (int y = 0; y < THIS->height; ++y)
2447 { 2478 {
2448 region *rgn = THIS->region (x, y); 2479 region *rgn = THIS->region (x, y);
2449 2480
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) 2481 if (object *op = THIS->at (x, y).top)
2452 if (rgn->treasure && rndm () < rgn->treasure_density) 2482 if (rgn->treasure && rndm () < rgn->treasure_density)
2453 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty); 2483 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty);
2454 } 2484 }
2455 2485
2461 if (oblinkpt *obp = map->find_link (connection)) 2491 if (oblinkpt *obp = map->find_link (connection))
2462 for (objectlink *ol = obp->link; ol; ol = ol->next) 2492 for (objectlink *ol = obp->link; ol; ol = ol->next)
2463 XPUSHs (sv_2mortal (to_sv ((object *)ol->ob))); 2493 XPUSHs (sv_2mortal (to_sv ((object *)ol->ob)));
2464 2494
2465void 2495void
2466get_map_flags (maptile *map, int x, int y) 2496xy_normalise (maptile *map, int x, int y, int dir = 0)
2467 PPCODE: 2497 PPCODE:
2468{ 2498{
2469 maptile *nmap = 0; 2499 mapxy pos (map, x, y);
2470 I16 nx = 0, ny = 0; 2500 if (!pos.move (dir).normalise ())
2501 XSRETURN_EMPTY;
2471 2502
2472 PUTBACK;
2473 int flags = get_map_flags (map, &nmap, x, y, &nx, &ny);
2474 SPAGAIN;
2475
2476 EXTEND (SP, 4); 2503 EXTEND (SP, 3);
2477 PUSHs (sv_2mortal (newSViv (flags)));
2478
2479 if (GIMME_V == G_ARRAY)
2480 {
2481 PUSHs (sv_2mortal (to_sv (nmap))); 2504 PUSHs (sv_2mortal (to_sv (pos.m)));
2482 PUSHs (sv_2mortal (newSViv (nx))); 2505 PUSHs (sv_2mortal (to_sv (pos.x)));
2483 PUSHs (sv_2mortal (newSViv (ny))); 2506 PUSHs (sv_2mortal (to_sv (pos.y)));
2484 }
2485} 2507}
2486 2508
2487mapspace * 2509mapspace *
2488ms (maptile *map, unsigned int x, unsigned int y) 2510ms (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2489 PROTOTYPE: $$$ 2511 PROTOTYPE: $$$;$
2490 CODE: 2512 CODE:
2491{ 2513{
2492 maptile *nmap = 0; 2514 mapxy pos (map, x, y);
2493 I16 nx, ny; 2515 if (!pos.move (dir).normalise ())
2494
2495 PUTBACK;
2496 get_map_flags (map, &nmap, x, y, &nx, &ny);
2497 SPAGAIN;
2498
2499 if (!nmap)
2500 XSRETURN_UNDEF; 2516 XSRETURN_UNDEF;
2501 2517
2502 RETVAL = &nmap->at (nx, ny); 2518 RETVAL = &*pos;
2503} 2519}
2504 OUTPUT: 2520 OUTPUT:
2505 RETVAL 2521 RETVAL
2506 2522
2507void 2523void
2508at (maptile *map, unsigned int x, unsigned int y) 2524at (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2509 PROTOTYPE: $$$ 2525 PROTOTYPE: $$$;$
2510 PPCODE: 2526 PPCODE:
2511{ 2527 mapxy pos (map, x, y);
2512 maptile *nmap = 0; 2528 if (pos.move (dir).normalise ())
2513 I16 nx, ny;
2514
2515 PUTBACK;
2516 get_map_flags (map, &nmap, x, y, &nx, &ny);
2517 SPAGAIN;
2518
2519 if (nmap)
2520 for (object *o = nmap->at (nx, ny).bot; o; o = o->above) 2529 for (object *o = pos->bot; o; o = o->above)
2521 XPUSHs (sv_2mortal (to_sv (o))); 2530 XPUSHs (sv_2mortal (to_sv (o)));
2522}
2523 2531
2524SV * 2532SV *
2525bot_at (maptile *map, unsigned int x, unsigned int y) 2533bot_at (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2526 PROTOTYPE: $$$ 2534 PROTOTYPE: $$$;$
2527 ALIAS: 2535 ALIAS:
2528 top_at = 1 2536 top_at = 1
2529 flags_at = 2 2537 flags_at = 2
2530 light_at = 3 2538 light_at = 3
2531 move_block_at = 4 2539 move_block_at = 4
2532 move_slow_at = 5 2540 move_slow_at = 5
2533 move_on_at = 6 2541 move_on_at = 6
2534 move_off_at = 7 2542 move_off_at = 7
2535 CODE: 2543 CODE:
2536{ 2544{
2537 sint16 nx = x; 2545 mapxy pos (map, x, y);
2538 sint16 ny = y; 2546 if (!pos.move (dir).normalise ())
2539
2540 if (!xy_normalise (map, nx, ny))
2541 XSRETURN_UNDEF; 2547 XSRETURN_UNDEF;
2542 2548
2543 mapspace &ms = map->at (nx, ny); 2549 mapspace &ms = *pos;
2544 2550
2545 ms.update (); 2551 ms.update ();
2546 2552
2547 switch (ix) 2553 switch (ix)
2548 { 2554 {
2558} 2564}
2559 OUTPUT: RETVAL 2565 OUTPUT: RETVAL
2560 2566
2561# worst xs function of my life 2567# worst xs function of my life
2562bool 2568bool
2563_create_random_map (\ 2569_create_random_map (maptile *self, SV *options)
2564 maptile *self,\
2565 utf8_string wallstyle,\
2566 utf8_string wall_name,\
2567 utf8_string floorstyle,\
2568 utf8_string monsterstyle,\
2569 utf8_string treasurestyle,\
2570 utf8_string layoutstyle,\
2571 utf8_string doorstyle,\
2572 utf8_string decorstyle,\
2573 utf8_string miningstyle,\
2574 utf8_string origin_map,\
2575 utf8_string final_map,\
2576 utf8_string exitstyle,\
2577 utf8_string this_map,\
2578 utf8_string exit_on_final_map,\
2579 int xsize,\
2580 int ysize,\
2581 int expand2x,\
2582 int layoutoptions1,\
2583 int layoutoptions2,\
2584 int layoutoptions3,\
2585 int symmetry,\
2586 int difficulty,\
2587 int difficulty_given,\
2588 float difficulty_increase,\
2589 int dungeon_level,\
2590 int dungeon_depth,\
2591 int decoroptions,\
2592 int orientation,\
2593 int origin_y,\
2594 int origin_x,\
2595 U32 random_seed,\
2596 val64 total_map_hp,\
2597 int map_layout_style,\
2598 int treasureoptions,\
2599 int symmetry_used,\
2600 region *region,\
2601 utf8_string custom\
2602)
2603 CODE: 2570 CODE:
2604{ 2571{
2605 random_map_params rmp; 2572 random_map_params rmp ((HV *)SvRV (options));
2606
2607 assign (rmp.wallstyle , wallstyle);
2608 assign (rmp.wall_name , wall_name);
2609 assign (rmp.floorstyle , floorstyle);
2610 assign (rmp.monsterstyle , monsterstyle);
2611 assign (rmp.treasurestyle , treasurestyle);
2612 assign (rmp.layoutstyle , layoutstyle);
2613 assign (rmp.doorstyle , doorstyle);
2614 assign (rmp.decorstyle , decorstyle);
2615 assign (rmp.miningstyle , miningstyle);
2616 assign (rmp.exitstyle , exitstyle);
2617 assign (rmp.exit_on_final_map, exit_on_final_map);
2618
2619 rmp.origin_map = origin_map;
2620 rmp.final_map = final_map;
2621 rmp.this_map = this_map;
2622 rmp.xsize = xsize;
2623 rmp.ysize = ysize;
2624 rmp.expand2x = expand2x;
2625 rmp.layoutoptions1 = layoutoptions1;
2626 rmp.layoutoptions2 = layoutoptions2;
2627 rmp.layoutoptions3 = layoutoptions3;
2628 rmp.symmetry = symmetry;
2629 rmp.difficulty = difficulty;
2630 rmp.difficulty_given = difficulty_given;
2631 rmp.difficulty_increase = difficulty_increase;
2632 rmp.dungeon_level = dungeon_level;
2633 rmp.dungeon_depth = dungeon_depth;
2634 rmp.decoroptions = decoroptions;
2635 rmp.orientation = orientation;
2636 rmp.origin_y = origin_y;
2637 rmp.origin_x = origin_x;
2638 rmp.random_seed = random_seed;
2639 rmp.total_map_hp = (uint64_t) total_map_hp;
2640 rmp.map_layout_style = map_layout_style;
2641 rmp.treasureoptions = treasureoptions;
2642 rmp.symmetry_used = symmetry_used;
2643 rmp.region = region;
2644 rmp.custom = custom;
2645
2646 RETVAL = self->generate_random_map (&rmp); 2573 RETVAL = self->generate_random_map (&rmp);
2647} 2574}
2648 OUTPUT: 2575 OUTPUT:
2649 RETVAL 2576 RETVAL
2650 2577
2661 2588
2662archetype *archetypes (U32 index) 2589archetype *archetypes (U32 index)
2663 CODE: 2590 CODE:
2664 RETVAL = index < archetypes.size () ? archetypes [index] : 0; 2591 RETVAL = index < archetypes.size () ? archetypes [index] : 0;
2665 OUTPUT: RETVAL 2592 OUTPUT: RETVAL
2593
2594int skillvec_size ()
2595 CODE:
2596 RETVAL = skillvec.size ();
2597 OUTPUT: RETVAL
2598
2599archetype *skillvec (U32 index)
2600 CODE:
2601 RETVAL = index < skillvec.size () ? (archetype *)(object *)skillvec [index] : 0;
2602 OUTPUT: RETVAL
2603
2604void
2605find_by_type (int type)
2606 PPCODE:
2607 for_all_archetypes (arch)
2608 if (arch->type == type)
2609 XPUSHs (sv_2mortal (to_sv (arch)));
2666 2610
2667INCLUDE: $PERL $srcdir/genacc archetype $srcdir/../include/object.h | 2611INCLUDE: $PERL $srcdir/genacc archetype $srcdir/../include/object.h |
2668 2612
2669MODULE = cf PACKAGE = cf::party 2613MODULE = cf PACKAGE = cf::party
2670 2614
2682list () 2626list ()
2683 PPCODE: 2627 PPCODE:
2684 for_all_regions (rgn) 2628 for_all_regions (rgn)
2685 XPUSHs (sv_2mortal (to_sv (rgn))); 2629 XPUSHs (sv_2mortal (to_sv (rgn)));
2686 2630
2687region *find (utf8_string name)
2688 PROTOTYPE: $
2689 CODE:
2690 RETVAL = region::find (name);
2691 OUTPUT: RETVAL
2692
2693int specificity (region *rgn) 2631int specificity (region *rgn)
2694 CODE: 2632 CODE:
2695 RETVAL = 0; 2633 RETVAL = 0;
2696 while (rgn = rgn->parent) 2634 while (rgn = rgn->parent)
2697 RETVAL++; 2635 RETVAL++;
2725list () 2663list ()
2726 PPCODE: 2664 PPCODE:
2727 EXTEND (SP, clients.size ()); 2665 EXTEND (SP, clients.size ());
2728 for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i) 2666 for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i)
2729 PUSHs (sv_2mortal (to_sv (*i))); 2667 PUSHs (sv_2mortal (to_sv (*i)));
2668
2669STRLEN
2670client::inbuf_append (SV *data)
2671 CODE:
2672{
2673 STRLEN len;
2674 char *ptr = SvPVbyte (data, len);
2675
2676 min_it (len, sizeof (THIS->inbuf) - THIS->inbuf_len);
2677 memcpy (THIS->inbuf + THIS->inbuf_len, ptr, len);
2678 THIS->inbuf_len += len;
2679
2680 THIS->inbuf_handle ();
2681
2682 RETVAL = len;
2683}
2684 OUTPUT: RETVAL
2730 2685
2731void 2686void
2732client::send_packet (SV *packet) 2687client::send_packet (SV *packet)
2733 CODE: 2688 CODE:
2734{ 2689{
2790faceidx face_find (utf8_string name, faceidx defidx = 0) 2745faceidx face_find (utf8_string name, faceidx defidx = 0)
2791 2746
2792faceidx alloc (utf8_string name) 2747faceidx alloc (utf8_string name)
2793 CODE: 2748 CODE:
2794{ 2749{
2795 do 2750 RETVAL = face_alloc ();
2796 {
2797 RETVAL = faces.size ();
2798 faces.resize (RETVAL + 1);
2799 }
2800 while (!RETVAL); // crude way to leave index 0
2801 2751
2802 faces [RETVAL].name = name; 2752 faces [RETVAL].name = name;
2803 facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL)); 2753 facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL));
2804 2754
2805 if (!strcmp (name, BLANK_FACE_NAME)) blank_face = RETVAL; 2755 if (!strcmp (name, BLANK_FACE_NAME )) blank_face = RETVAL;
2806 if (!strcmp (name, EMPTY_FACE_NAME)) empty_face = RETVAL; 2756 if (!strcmp (name, EMPTY_FACE_NAME )) empty_face = RETVAL;
2757 if (!strcmp (name, MAGICMOUTH_FACE_NAME)) magicmouth_face = RETVAL;
2807} 2758}
2759 OUTPUT: RETVAL
2760
2761faceidx faces_size ()
2762 CODE:
2763 RETVAL = faces.size ();
2808 OUTPUT: RETVAL 2764 OUTPUT: RETVAL
2809 2765
2810void set_type (faceidx idx, int value) 2766void set_type (faceidx idx, int value)
2811 ALIAS: 2767 ALIAS:
2812 set_type = 0 2768 set_type = 0
2823 case 2: f->magicmap = value; break; 2779 case 2: f->magicmap = value; break;
2824 case 3: f->smooth = value; break; 2780 case 3: f->smooth = value; break;
2825 case 4: f->smoothlevel = value; break; 2781 case 4: f->smoothlevel = value; break;
2826 } 2782 }
2827 2783
2828void set_data (faceidx idx, int faceset, SV *data, SV *chksum) 2784void set_csum (faceidx idx, int faceset, SV *chksum)
2829 CODE: 2785 CODE:
2830{ 2786{
2831 faceinfo *f = face_info (idx); assert (f); 2787 faceinfo *f = face_info (idx); assert (f);
2832 facedata *d = &(faceset ? f->data64 : f->data32); 2788 facedata *d = f->face + faceset;
2833 sv_to (data, d->data);
2834 STRLEN clen; 2789 STRLEN clen;
2835 char *cdata = SvPVbyte (chksum, clen); 2790 char *cdata = SvPVbyte (chksum, clen);
2836 clen = min (CHKSUM_MAXLEN, clen);
2837 2791
2792 assert (("cf::face::set_data called with too long checksum", clen <= CHKSUM_MAXLEN));
2838 assert (("cf::face::set_data must be called with a non-empty checksum", clen)); 2793 assert (("cf::face::set_data must be called with a non-empty checksum", clen));
2839 2794
2840 if (clen != d->chksum_len || memcmp (d->chksum, cdata, clen)) 2795 if (clen != d->chksum_len || memcmp (d->chksum, cdata, clen))
2841 { 2796 {
2842 d->chksum_len = clen; 2797 d->chksum_len = clen;
2843 memcpy (d->chksum, cdata, clen); 2798 memcpy (d->chksum, cdata, clen);
2844 2799
2845 // invalidate existing client face info 2800 // invalidate existing client face info
2846 for_all_clients (ns) 2801 for_all_clients (ns)
2847 if (ns->faceset == faceset) 2802 ns->invalidate_face (idx);
2848 {
2849 ns->faces_sent [idx] = false;
2850 ns->force_newmap = true;
2851 }
2852 } 2803 }
2853} 2804}
2854 2805
2855int get_data_size (faceidx idx, int faceset = 0) 2806SV *mangle_csum (SV *chksum)
2856 CODE: 2807 CODE:
2857 facedata *d = face_data (idx, faceset); 2808 STRLEN len;
2858 if (!d) XSRETURN_UNDEF; 2809 char *data = SvPVbyte (chksum, len);
2859 RETVAL = d->data.size (); 2810 RETVAL = newSVpvn (data, min (len, CHKSUM_MAXLEN));
2860 OUTPUT: 2811 OUTPUT:
2861 RETVAL 2812 RETVAL
2862 2813
2863SV *get_chksum (faceidx idx, int faceset = 0) 2814SV *get_csum (faceidx idx, int faceset = 0)
2864 CODE: 2815 CODE:
2865 facedata *d = face_data (idx, faceset); 2816 facedata *d = face_data (idx, faceset);
2866 if (!d) XSRETURN_UNDEF; 2817 if (!d) XSRETURN_UNDEF;
2867 RETVAL = newSVpvn ((char *)d->chksum, d->chksum_len); 2818 RETVAL = newSVpvn ((char *)d->chksum, d->chksum_len);
2868 OUTPUT: 2819 OUTPUT:
2869 RETVAL 2820 RETVAL
2870 2821
2871SV *get_data (faceidx idx, int faceset = 0) 2822int get_type (faceidx idx)
2872 CODE: 2823 CODE:
2873 facedata *d = face_data (idx, faceset); 2824 faceinfo *f = face_info (idx);
2874 if (!d) XSRETURN_UNDEF; 2825 if (!f) XSRETURN_UNDEF;
2875 RETVAL = newSVpvn (d->data.data (), d->data.length ()); 2826 RETVAL = f->type;
2876 OUTPUT: 2827 OUTPUT:
2877 RETVAL 2828 RETVAL
2878 2829
2830SV *get_name (faceidx idx)
2831 CODE:
2832 faceinfo *f = face_info (idx);
2833 if (!f) XSRETURN_UNDEF;
2834 RETVAL = to_sv (f->name);
2835 OUTPUT:
2836 RETVAL
2837
2879void invalidate (faceidx idx) 2838void invalidate (faceidx idx)
2880 CODE: 2839 CODE:
2881 for_all_clients (ns) 2840 for_all_clients (ns)
2882 { 2841 ns->invalidate_face (idx);
2883 ns->faces_sent [idx] = false;
2884 ns->force_newmap = true;
2885 }
2886 2842
2887void invalidate_all () 2843void invalidate_all ()
2888 CODE: 2844 CODE:
2889 for_all_clients (ns) 2845 for_all_clients (ns)
2890 { 2846 ns->invalidate_all_faces ();
2891 ns->faces_sent.reset ();
2892 ns->force_newmap = true;
2893 }
2894 2847
2895MODULE = cf PACKAGE = cf::anim PREFIX = anim_ 2848MODULE = cf PACKAGE = cf::anim PREFIX = anim_
2896 2849
2897#INCLUDE: $PERL $srcdir/genacc faceset $srcdir/../include/anim.h | 2850#INCLUDE: $PERL $srcdir/genacc faceset $srcdir/../include/anim.h |
2898 2851
2902 OUTPUT: RETVAL 2855 OUTPUT: RETVAL
2903 2856
2904animidx set (utf8_string name, SV *frames, int facings = 1) 2857animidx set (utf8_string name, SV *frames, int facings = 1)
2905 CODE: 2858 CODE:
2906{ 2859{
2907 if (!SvROK (frames) && SvTYPE (SvRV (frames)) != SVt_PVAV) 2860 if (!SvROK (frames) && SvTYPE (SvRV (frames)) != SVt_PVAV)
2908 croak ("frames must be an arrayref"); 2861 croak ("frames must be an arrayref");
2909 2862
2910 AV *av = (AV *)SvRV (frames); 2863 AV *av = (AV *)SvRV (frames);
2911 2864
2912 animation *anim = &animation::find (name); 2865 animation *anim = &animation::find (name);
2913 if (anim->number) 2866 if (anim->number)
2914 { 2867 {
2915 anim->resize (av_len (av) + 1); 2868 anim->resize (av_len (av) + 1);
2916 anim->facings = facings; 2869 anim->facings = facings;
2917 } 2870 }
2945 sv_to (sv, self); 2898 sv_to (sv, self);
2946 delete self; 2899 delete self;
2947 2900
2948MODULE = cf PACKAGE = cf::object::thawer 2901MODULE = cf PACKAGE = cf::object::thawer
2949 2902
2950INCLUDE: $PERL $srcdir/genacc object_thawer $srcdir/../include/cfperl.h | 2903INCLUDE: $PERL $srcdir/genacc object_thawer $srcdir/../include/freezethaw.h |
2904
2905bool
2906errors_are_fatal (bool fatal)
2907 CODE:
2908 RETVAL = object_thawer::errors_are_fatal;
2909 object_thawer::errors_are_fatal = fatal;
2910 OUTPUT:
2911 RETVAL
2951 2912
2952SV * 2913SV *
2953new_from_file (char *klass, octet_string path) 2914new_from_file (char *klass, octet_string path)
2954 CODE: 2915 CODE:
2955 object_thawer *f = new object_thawer (path); 2916 object_thawer *f = new object_thawer (path);
2981 XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ()))); 2942 XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ())));
2982 2943
2983 self->skip (); 2944 self->skip ();
2984 } 2945 }
2985 2946
2947MODULE = cf PACKAGE = cf::treasurelist
2948
2949# quick hack, because I didn't want to implement accessors for treasurelist.
2950# this asks for even more autogen, actually.
2951
2952void
2953expand (treasurelist *list)
2954 PPCODE:
2955 EXTEND (SP, 3);
2956 PUSHs (sv_2mortal (to_sv (list->name)));
2957 PUSHs (sv_2mortal (to_sv (list->total_chance)));
2958 AV *av = newAV ();
2959 PUSHs (sv_2mortal (newRV_noinc ((SV *)av)));
2960 for (treasure *item = list->items; item; item = item->next)
2961 {
2962 AV *iav = newAV ();
2963 av_push (av, newRV_noinc ((SV *)iav));
2964
2965 av_extend (iav, 7);
2966 av_push (iav, to_sv (item->item));
2967 av_push (iav, to_sv (item->name));
2968 av_push (iav, to_sv (item->change_arch.name));
2969 av_push (iav, to_sv (item->change_arch.title));
2970 av_push (iav, to_sv (item->change_arch.slaying));
2971 av_push (iav, to_sv (item->chance));
2972 av_push (iav, to_sv (item->nrof));
2973 av_push (iav, to_sv (item->magic));
2974 }
2975
2976MODULE = cf PACKAGE = cf::layout
2977
2978INCLUDE: $PERL $srcdir/genacc layout $srcdir/../include/rmg.h |
2979

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines