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.359 by root, Sun Apr 4 20:00:06 2010 UTC vs.
Revision 1.402 by root, Sun May 1 13:18:24 2011 UTC

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
51#include <perl.h> 52#include <perl.h>
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
57extern sint64 *levels; // the experience table
58 57
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;
85 *stash_cf_mapspace_wrap, 84 *stash_cf_mapspace_wrap,
86 *stash_cf_client_wrap, 85 *stash_cf_client_wrap,
87 *stash_cf_arch_wrap, 86 *stash_cf_arch_wrap,
88 *stash_cf_party_wrap, 87 *stash_cf_party_wrap,
89 *stash_cf_region_wrap, 88 *stash_cf_region_wrap,
90 *stash_cf_living_wrap; 89 *stash_cf_living_wrap,
90 *stash_cf_layout_wrap,
91 *stash_ext_map_world;
91 92
92static SV 93static SV
93 *cv_cf_do_invoke, 94 *cv_cf_do_invoke,
94 *cv_cf__can_merge, 95 *cv_cf__can_merge,
95 *cv_cf_client_send_msg, 96 *cv_cf_client_send_msg,
123 124
124 return sv; 125 return sv;
125} 126}
126#endif 127#endif
127 128
128static noinline utf8_string 129noinline utf8_string
129cfSvPVutf8_nolen (SV *sv) 130cfSvPVutf8_nolen (SV *sv)
130{ 131{
131 SvGETMAGIC (sv); 132 SvGETMAGIC (sv);
132 133
133 if (SvPOK (sv)) 134 if (SvPOK (sv))
230 do_destroy (); 231 do_destroy ();
231 sever_self (); 232 sever_self ();
232} 233}
233 234
234void 235void
236attachable::do_delete ()
237{
238 delete this;
239}
240
241void
235attachable::check_mortals () 242attachable::check_mortals ()
236{ 243{
237 static int i = 0; 244 static int i = 0;
238 245
239 for (;;) 246 for (;;)
252 259
253 if (0) 260 if (0)
254 { 261 {
255 for (int j = 0; j < mortals.size (); ++j)//D 262 for (int j = 0; j < mortals.size (); ++j)//D
256 fprintf (stderr, "%d:%s %p ", j, &((object *)mortals[j])->name, mortals[j]);//D 263 fprintf (stderr, "%d:%s %p ", j, &((object *)mortals[j])->name, mortals[j]);//D
264
257 fprintf (stderr, "\n");//D 265 fprintf (stderr, "\n");//D
258 } 266 }
259 } 267 }
260 } 268 }
261 269
281 } 289 }
282 else 290 else
283 { 291 {
284 mortals.erase (i); 292 mortals.erase (i);
285 obj->sever_self (); 293 obj->sever_self ();
286 delete obj; 294 obj->do_delete ();
287 } 295 }
288 } 296 }
289} 297}
290 298
291void 299void
346#endif 354#endif
347 355
348////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 356//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
349 357
350static SV * 358static SV *
351newSVptr (void *ptr, HV *stash, HV *hv = newHV ()) 359newSVptr (void *ptr, HV *stash, HV *hv)
352{ 360{
353 SV *sv;
354
355 if (!ptr) 361 if (!ptr)
356 return newSV (0); 362 return newSV (0);
357 363
358 sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, 0, (char *)ptr, 0); 364 sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, 0, (char *)ptr, 0);
359 return sv_bless (newRV_noinc ((SV *)hv), stash); 365 return sv_bless (newRV_noinc ((SV *)hv), stash);
366}
367
368static SV * noinline
369newSVptr (void *ptr, HV *stash)
370{
371 return newSVptr (ptr, stash, newHV ());
360} 372}
361 373
362static int 374static int
363attachable_free (pTHX_ SV *sv, MAGIC *mg) 375attachable_free (pTHX_ SV *sv, MAGIC *mg)
364{ 376{
376 return 0; 388 return 0;
377} 389}
378 390
379MGVTBL attachable::vtbl = {0, 0, 0, 0, attachable_free}; 391MGVTBL attachable::vtbl = {0, 0, 0, 0, attachable_free};
380 392
381static SV * 393static SV * noinline
382newSVattachable (attachable *obj, HV *stash) 394newSVattachable (attachable *obj, HV *stash)
383{ 395{
384 if (!obj) 396 if (!obj)
385 return newSV (0); 397 return newSV (0);
386 398
472 || (SvSTASH (SvRV (sv)) != stash_cf_object_wrap 484 || (SvSTASH (SvRV (sv)) != stash_cf_object_wrap
473 && SvSTASH (SvRV (sv)) != stash_cf_object_player_wrap 485 && SvSTASH (SvRV (sv)) != stash_cf_object_player_wrap
474 && SvSTASH (SvRV (sv)) != stash_cf_arch_wrap 486 && SvSTASH (SvRV (sv)) != stash_cf_arch_wrap
475 && !sv_derived_from (sv, "cf::object"))) 487 && !sv_derived_from (sv, "cf::object")))
476 croak ("object of type cf::object expected"); 488 croak ("object of type cf::object expected");
489
490 return SvPTR_nc (sv);
491}
492
493static long noinline
494SvPTR_ornull_maptile (SV *sv)
495{
496 if (expect_false (!SvOK (sv))) return 0;
497
498 if (!SvROK (sv)
499 || (SvSTASH (SvRV (sv)) != stash_cf_map_wrap
500 && SvSTASH (SvRV (sv)) != stash_ext_map_world
501 && !sv_derived_from (sv, "cf::map")))
502 croak ("object of type cf::map expected");
477 503
478 return SvPTR_nc (sv); 504 return SvPTR_nc (sv);
479} 505}
480 506
481static long noinline 507static long noinline
506static inline SV *to_sv (unsigned long long v) { return newSVval64 (v); } 532static inline SV *to_sv (unsigned long long v) { return newSVval64 (v); }
507static inline SV *to_sv (float v) { return newSVnv (v); } 533static inline SV *to_sv (float v) { return newSVnv (v); }
508static inline SV *to_sv (double v) { return newSVnv (v); } 534static inline SV *to_sv (double v) { return newSVnv (v); }
509static inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); } 535static 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); } 536static inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); }
537// 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); } 538static noinline SV *to_sv_ni (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); }
539static 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); } 540static 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); } 541static 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); } 542static 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); } 543static 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); } 544static 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); } 545static inline SV *to_sv (mapspace * v) { return newSVptr (v, stash_cf_mapspace_wrap); }
546static inline SV *to_sv (layout * v) { return newSVptr (v, stash_cf_layout_wrap); }
518 547
519static inline SV *to_sv (object & v) { return to_sv (&v); } 548static inline SV *to_sv (object & v) { return to_sv (&v); }
520static inline SV *to_sv (living & v) { return to_sv (&v); } 549static inline SV *to_sv (living & v) { return to_sv (&v); }
521 550
522static inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); } 551static 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); } 587static 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); } 588static 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); } 589static 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); } 590static inline void sv_to (SV *sv, float &v) { v = SvNV (sv); }
562static inline void sv_to (SV *sv, double &v) { v = SvNV (sv); } 591static 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); } 592static 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); } 593static 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); } 594static inline void sv_to (SV *sv, object * &v) { v = (object *) (attachable *)SvPTR_ornull_object (sv); }
595static 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"); } 596static 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"); } 597static 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"); } 598static 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"); } 599static 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"); } 600static 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"); } 601static inline void sv_to (SV *sv, mapspace * &v) { v = (mapspace *) SvPTR_ornull (sv, "cf::mapspace"); }
602static 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"); } 603static 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" ); } 604static inline void sv_to (SV *sv, object_thawer * &v) { v = (object_thawer *) SvPTR_ornull (sv, "cf::object::thawer" ); }
575 605
576//static inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; } 606//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)); } 607static inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); }
688template<class type> 718template<class type>
689static void noinline 719static void noinline
690cf_obj_to (SV *arg, type &var) 720cf_obj_to (SV *arg, type &var)
691{ 721{
692 sv_to (arg, var); 722 sv_to (arg, var);
693 if (!var) 723 if (expect_false (!var))
694 croak ("must not pass invalid/null cf_obj here"); 724 croak ("must not pass invalid/null cf_obj here");
695} 725}
696 726
697template<class object> 727template<class object>
698static void noinline 728static void noinline
699cf_obj_ornull_to (SV *arg, object *&var) 729cf_obj_ornull_to (SV *arg, object *&var)
700{ 730{
701 if (SvOK (arg)) 731 if (SvOK (arg))
702 { 732 {
703 sv_to (arg, var); 733 sv_to (arg, var);
704 if (!var) 734 if (expect_false (!var))
705 croak ("unable to convert perl object to C++ object"); 735 croak ("unable to convert perl object to C++ object");
706 } 736 }
707 else 737 else
708 var = 0; 738 var = 0;
709} 739}
744 exit (EXIT_FAILURE); 774 exit (EXIT_FAILURE);
745 } 775 }
746 776
747 eval_pv ( 777 eval_pv (
748 "#line 1 'cfperl init'\n" 778 "#line 1 'cfperl init'\n"
749 "use EV ();\n" 779 "use EV ();\n" // required by bootstrap
750 "use Coro ();\n" 780 "use Coro ();\n" // required by bootstrap
751 "cf->bootstrap;\n" 781 "cf->bootstrap;\n" // required for cf::datadir
752 "unshift @INC, cf::datadir ();\n" 782 "unshift @INC, cf::datadir ();\n" // required for 'require' :)
753 "require cf;\n", 783 "require cf;\n",
754 0 784 0
755 ); 785 );
756 786
757 if (SvTRUE (ERRSV)) 787 if (SvTRUE (ERRSV))
1132 1162
1133 return retval; 1163 return retval;
1134} 1164}
1135 1165
1136maptile * 1166maptile *
1137find_style (const_utf8_string dirname, const_utf8_string stylename, int difficulty) 1167find_style (const_utf8_string dirname, const_utf8_string stylename, int difficulty, bool recurse)
1138{ 1168{
1139 CALL_BEGIN (3); 1169 CALL_BEGIN (4);
1140 CALL_ARG (dirname); 1170 CALL_ARG (dirname);
1141 CALL_ARG (stylename); 1171 CALL_ARG (stylename);
1142 CALL_ARG (difficulty); 1172 CALL_ARG (difficulty);
1173 CALL_ARG (recurse);
1143 CALL_CALL ("ext::map_random::find_style", G_SCALAR); 1174 CALL_CALL ("ext::map_random::find_style", G_SCALAR);
1144 1175
1145 maptile *retval = 0; 1176 maptile *retval = 0;
1146 if (count) sv_to (POPs, retval); 1177 if (count) sv_to (POPs, retval);
1147 1178
1224object::ref () const 1255object::ref () const
1225{ 1256{
1226 if (type == PLAYER) 1257 if (type == PLAYER)
1227 return format ("player/<1.%llx>/%s", (unsigned long long)uuid.seq, &name); 1258 return format ("player/<1.%llx>/%s", (unsigned long long)uuid.seq, &name);
1228 else 1259 else
1260 // TODO: should be able to save references within the same map, at least
1229 return 0; 1261 return 0;
1230} 1262}
1231 1263
1232object * 1264object *
1233object::deref (const_utf8_string ref) 1265object::deref (const_utf8_string ref)
1369 stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1); 1401 stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1);
1370 stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1); 1402 stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1);
1371 stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1); 1403 stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1);
1372 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); 1404 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1);
1373 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1); 1405 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1);
1406 stash_cf_layout_wrap = gv_stashpv ("cf::layout::wrap", 1);
1407 stash_ext_map_world = gv_stashpv ("ext::map_world" , 1);
1374 1408
1375 sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV); 1409 sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV);
1376 sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV); 1410 sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV);
1377 sv_tick_start = get_sv ("cf::TICK_START", 1); SvUPGRADE (sv_tick_start, SVt_NV); 1411 sv_tick_start = get_sv ("cf::TICK_START", 1); SvUPGRADE (sv_tick_start, SVt_NV);
1378 sv_next_tick = get_sv ("cf::NEXT_TICK" , 1); SvUPGRADE (sv_next_tick , SVt_NV); 1412 sv_next_tick = get_sv ("cf::NEXT_TICK" , 1); SvUPGRADE (sv_next_tick , SVt_NV);
1426# include "attackinc.h" 1460# include "attackinc.h"
1427# undef def 1461# undef def
1428# define def(uc, flags) const_iv (SK_ ## uc) 1462# define def(uc, flags) const_iv (SK_ ## uc)
1429# include "skillinc.h" 1463# include "skillinc.h"
1430# undef def 1464# undef def
1431 1465# define def(name, use, nonuse) const_iv (body_ ## name)
1432 const_iv (llevError) const_iv (llevInfo) const_iv (llevDebug) const_iv (llevMonster) 1466# include "slotinc.h"
1433 const_iv (logBacktrace) 1467# undef def
1434
1435 const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd)
1436 1468
1437 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) 1469 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y)
1438 1470
1439 const_iv (MAX_TIME) 1471 const_iv (MAX_TIME)
1440 const_iv (MAXSOCKBUF) 1472 const_iv (MAXSOCKBUF)
1460 const_iv (MAP_INACTIVE) 1492 const_iv (MAP_INACTIVE)
1461 1493
1462 const_iv (KLASS_ATTACHABLE) const_iv (KLASS_GLOBAL) const_iv (KLASS_OBJECT) 1494 const_iv (KLASS_ATTACHABLE) const_iv (KLASS_GLOBAL) const_iv (KLASS_OBJECT)
1463 const_iv (KLASS_CLIENT) const_iv (KLASS_PLAYER) const_iv (KLASS_MAP) 1495 const_iv (KLASS_CLIENT) const_iv (KLASS_PLAYER) const_iv (KLASS_MAP)
1464 1496
1465 const_iv (VERSION_CS) const_iv (VERSION_SC)
1466
1467 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT) 1497 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT)
1468 1498
1469 const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES) 1499 const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES)
1470 }; 1500 };
1471 1501
1472 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 1502 for (civ = const_iv + array_length (const_iv); civ-- > const_iv; )
1473 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv)); 1503 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv));
1474 1504
1475 static const struct { 1505 static const struct {
1476 const char *name; 1506 const char *name;
1477 int skip; 1507 int skip;
1483# undef def 1513# undef def
1484 }; 1514 };
1485 1515
1486 AV *av = get_av ("cf::EVENT", 1); 1516 AV *av = get_av ("cf::EVENT", 1);
1487 1517
1488 for (eiv = event_iv + sizeof (event_iv) / sizeof (event_iv [0]); eiv-- > event_iv; ) 1518 for (eiv = event_iv + array_length (event_iv); eiv-- > event_iv; )
1489 { 1519 {
1490 AV *event = newAV (); 1520 AV *event = newAV ();
1491 av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0)); 1521 av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0));
1492 av_push (event, newSViv (eiv->klass)); 1522 av_push (event, newSViv (eiv->klass));
1493 av_store (av, eiv->iv, newRV_noinc ((SV *)event)); 1523 av_store (av, eiv->iv, newRV_noinc ((SV *)event));
1528 1558
1529 for_all_objects (op) 1559 for_all_objects (op)
1530 op->reattach (); 1560 op->reattach ();
1531} 1561}
1532 1562
1533# support function for map-world.ext
1534void _quantise (SV *data_sv, SV *plt_sv)
1535 CODE:
1536{
1537 if (!SvROK (plt_sv) || SvTYPE (SvRV (plt_sv)) != SVt_PVAV)
1538 croak ("_quantise called with invalid agruments");
1539
1540 plt_sv = SvRV (plt_sv);
1541 SV **plt = AvARRAY (plt_sv);
1542 int plt_count = AvFILL (plt_sv) + 1;
1543
1544 STRLEN len;
1545 char *data = SvPVbyte (data_sv, len);
1546 char *dst = data;
1547
1548 while (len >= 3)
1549 {
1550 for (SV **val_sv = plt + plt_count; val_sv-- > plt; )
1551 {
1552 char *val = SvPVX (*val_sv);
1553
1554 if (val [0] == data [0]
1555 && val [1] == data [1]
1556 && val [2] == data [2])
1557 {
1558 *dst++ = val [3];
1559 goto next;
1560 }
1561 }
1562
1563 croak ("_quantise: color not found in palette: #%02x%02x%02x, at offset %d %d",
1564 (uint8_t)data [0], (uint8_t)data [1], (uint8_t)data [2],
1565 dst - SvPVX (data_sv), len);
1566
1567 next:
1568 data += 3;
1569 len -= 3;
1570 }
1571
1572 SvCUR_set (data_sv, dst - SvPVX (data_sv));
1573}
1574
1575void init_anim () 1563void init_anim ()
1576 1564
1577void init_globals () 1565void init_globals ()
1578 1566
1579void init_experience ()
1580
1581void init_attackmess () 1567void init_attackmess ()
1582 1568
1583void init_dynamic () 1569void init_dynamic ()
1584 1570
1585void load_settings () 1571void load_settings ()
1586 1572
1573void reload_exp_table ()
1574
1587void load_materials () 1575void reload_materials ()
1588 1576
1589void init_uuid () 1577void init_uuid ()
1590 CODE: 1578 CODE:
1591 UUID::init (); 1579 UUID::init ();
1592 1580
1593void init_signals () 1581void init_signals ()
1594
1595void init_commands ()
1596 1582
1597void init_skills () 1583void init_skills ()
1598 1584
1599void init_beforeplay () 1585void init_beforeplay ()
1600 1586
1660 switch (items) 1646 switch (items)
1661 { 1647 {
1662 case 0: RETVAL = gen (); break; 1648 case 0: RETVAL = gen (); break;
1663 case 1: RETVAL = gen (SvUV (ST (0))); break; 1649 case 1: RETVAL = gen (SvUV (ST (0))); break;
1664 case 2: RETVAL = gen (SvIV (ST (0)), SvIV (ST (1))); break; 1650 case 2: RETVAL = gen (SvIV (ST (0)), SvIV (ST (1))); break;
1665 default: croak ("cf::rndm requires none, one or two parameters."); break; 1651 default: croak ("cf::rndm requires zero, one or two parameters."); break;
1666 } 1652 }
1667} 1653}
1668 OUTPUT: 1654 OUTPUT:
1669 RETVAL 1655 RETVAL
1670 1656
1677NV lerp (NV value, NV min_in, NV max_in, NV min_out, NV max_out) 1663NV lerp (NV value, NV min_in, NV max_in, NV min_out, NV max_out)
1678 CODE: 1664 CODE:
1679 RETVAL = lerp (value, min_in, max_in, min_out, max_out); 1665 RETVAL = lerp (value, min_in, max_in, min_out, max_out);
1680 OUTPUT: 1666 OUTPUT:
1681 RETVAL 1667 RETVAL
1668
1669const char *ordinal (int i)
1682 1670
1683void weaken (...) 1671void weaken (...)
1684 PROTOTYPE: @ 1672 PROTOTYPE: @
1685 CODE: 1673 CODE:
1686 while (items > 0) 1674 while (items > 0)
1687 sv_rvweaken (ST (--items)); 1675 sv_rvweaken (ST (--items));
1688 1676
1689void 1677void log_suspend ()
1678
1679void log_resume ()
1680
1690log_backtrace (utf8_string msg) 1681void log_backtrace (utf8_string msg)
1691 1682
1692void
1693LOG (int flags, utf8_string msg) 1683void LOG (int flags, utf8_string msg)
1694 PROTOTYPE: $$ 1684 PROTOTYPE: $$
1695 C_ARGS: flags, "%s", msg 1685 C_ARGS: flags, "%s", msg
1696 1686
1697octet_string path_combine (octet_string base, octet_string path) 1687octet_string path_combine (octet_string base, octet_string path)
1698 PROTOTYPE: $$ 1688 PROTOTYPE: $$
1745 1735
1746int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) 1736int mlockall (int flags = MCL_CURRENT | MCL_FUTURE)
1747 INIT: 1737 INIT:
1748#if __GLIBC__ 1738#if __GLIBC__
1749 mallopt (M_TOP_PAD, 1024 * 1024); 1739 mallopt (M_TOP_PAD, 1024 * 1024);
1750 mallopt (M_MMAP_THRESHOLD, 1024 * 1024 * 128); 1740 mallopt (M_MMAP_THRESHOLD, 1024 * 1024);
1751 mallopt (M_MMAP_MAX, 0); // likely bug-workaround, also frees memory 1741 mallopt (M_MMAP_MAX, 0); // likely bug-workaround, also frees memory
1742 if (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 10))
1752 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc 1743 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc
1753#endif 1744#endif
1754 1745
1755int munlockall () 1746int munlockall ()
1756 1747
1757#endif 1748#endif
1790 1781
1791int random_roll (int min, int max, object *op, int goodbad); 1782int random_roll (int min, int max, object *op, int goodbad);
1792 1783
1793const_utf8_string cost_string_from_value(uint64 cost, int approx = 0) 1784const_utf8_string cost_string_from_value(uint64 cost, int approx = 0)
1794 1785
1795int
1796exp_to_level (val64 exp) 1786int exp_to_level (val64 exp)
1787
1788val64 level_to_min_exp (int level)
1789
1790SV *
1791attacktype_name (int atnr)
1797 CODE: 1792 CODE:
1798{ 1793 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1799 int i = 0; 1794 ? newSVpv (attacktype_name [atnr], 0)
1800 1795 : &PL_sv_undef;
1801 RETVAL = settings.max_level;
1802
1803 for (i = 1; i <= settings.max_level; i++)
1804 {
1805 if (levels[i] > exp)
1806 {
1807 RETVAL = i - 1;
1808 break;
1809 }
1810 }
1811}
1812 OUTPUT: RETVAL 1796 OUTPUT: RETVAL
1813 1797
1814val64
1815level_to_min_exp (int level)
1816 CODE:
1817 if (level > settings.max_level)
1818 RETVAL = levels[settings.max_level];
1819 else if (level < 1)
1820 RETVAL = 0;
1821 else
1822 RETVAL = levels[level];
1823 OUTPUT: RETVAL
1824
1825SV * 1798SV *
1826resistance_to_string (int atnr) 1799attacktype_desc (int atnr)
1827 CODE: 1800 CODE:
1828 if (atnr >= 0 && atnr < NROFATTACKS) 1801 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1802 ? newSVpv (attacktype_desc [atnr], 0)
1803 : &PL_sv_undef;
1804 OUTPUT: RETVAL
1805
1806SV *
1807resist_plus (int atnr)
1808 CODE:
1809 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1829 RETVAL = newSVpv (resist_plus[atnr], 0); 1810 ? newSVpv (resist_plus [atnr], 0)
1830 else 1811 : &PL_sv_undef;
1831 XSRETURN_UNDEF; 1812 OUTPUT: RETVAL
1813
1814SV *
1815change_resist_msg (int atnr)
1816 CODE:
1817 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1818 ? newSVpv (change_resist_msg [atnr], 0)
1819 : &PL_sv_undef;
1832 OUTPUT: RETVAL 1820 OUTPUT: RETVAL
1833 1821
1834UUID 1822UUID
1835uuid_cur () 1823uuid_cur ()
1836 CODE: 1824 CODE:
1886 CODE: 1874 CODE:
1887 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); 1875 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext);
1888 OUTPUT: 1876 OUTPUT:
1889 RETVAL 1877 RETVAL
1890 1878
1879bool should_invoke (attachable *obj, int event)
1880 CODE:
1881 RETVAL = obj->should_invoke ((event_type)event);
1882 OUTPUT: RETVAL
1883
1891void 1884void
1892debug_trace (attachable *obj, bool on = true) 1885debug_trace (attachable *obj, bool on = true)
1893 CODE: 1886 CODE:
1894 obj->attachable_flags &= ~attachable::F_DEBUG_TRACE; 1887 obj->attachable_flags &= ~attachable::F_DEBUG_TRACE;
1895 if (on) 1888 if (on)
1954int mortals_size () 1947int mortals_size ()
1955 CODE: 1948 CODE:
1956 RETVAL = attachable::mortals.size (); 1949 RETVAL = attachable::mortals.size ();
1957 OUTPUT: RETVAL 1950 OUTPUT: RETVAL
1958 1951
1959const_utf8_string slot_use_name (U32 slot) 1952const_utf8_string slot_name (U32 slot)
1960 ALIAS: 1953 ALIAS:
1954 slot_name = 0
1955 slot_use_name = 1
1961 slot_nonuse_name = 1 1956 slot_nonuse_name = 2
1962 CODE: 1957 CODE:
1963{ 1958{
1964 if (slot >= NUM_BODY_LOCATIONS) 1959 if (slot >= NUM_BODY_LOCATIONS)
1965 croak ("body slot index out of range"); 1960 croak ("body slot index out of range");
1966 1961
1967 switch (ix) 1962 switch (ix)
1968 { 1963 {
1964 case 0: RETVAL = body_locations[slot].name ; break;
1969 case 0: RETVAL = body_locations[slot].use_name; break; 1965 case 1: RETVAL = body_locations[slot].use_name ; break;
1970 case 1: RETVAL = body_locations[slot].nonuse_name; break; 1966 case 2: RETVAL = body_locations[slot].nonuse_name; break;
1971 } 1967 }
1972} 1968}
1973 OUTPUT: 1969 OUTPUT:
1974 RETVAL 1970 RETVAL
1975 1971
2020 OUTPUT: 2016 OUTPUT:
2021 RETVAL 2017 RETVAL
2022 2018
2023object *find_best_object_match (object *op, utf8_string match) 2019object *find_best_object_match (object *op, utf8_string match)
2024 2020
2025object *find_marked_object (object *op)
2026
2027int need_identify (object *obj);
2028
2029int apply_shop_mat (object *shop_mat, object *op); 2021int apply_shop_mat (object *shop_mat, object *op);
2030 2022
2031int move (object *op, int dir, object *originator = op) 2023int move (object *op, int dir, object *originator = op)
2032 CODE: 2024 CODE:
2033 RETVAL = op->move (dir, originator); 2025 RETVAL = op->move (dir, originator);
2085 2077
2086void pick_up (object *who, object *op) 2078void pick_up (object *who, object *op)
2087 2079
2088void update_object (object *op, int action) 2080void update_object (object *op, int action)
2089 2081
2090void change_exp (object *op, uint64 exp, utf8_string skill_name = 0, int flag = 0) 2082void change_exp (object *op, uint64 exp, shstr_tmp skill_name = shstr_tmp (), int flag = 0)
2091 2083
2092void player_lvl_adj (object *who, object *skill = 0) 2084void player_lvl_adj (object *who, object *skill = 0)
2093 2085
2094int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL) 2086int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL)
2095 2087
2140 RETVAL = 0; 2132 RETVAL = 0;
2141} 2133}
2142 2134
2143shstr 2135shstr
2144object::kv_get (shstr key) 2136object::kv_get (shstr key)
2137 CODE:
2138 RETVAL = THIS->kv.get (key);
2139 OUTPUT:
2140 RETVAL
2145 2141
2146void 2142void
2147object::kv_del (shstr key) 2143object::kv_del (shstr key)
2144 CODE:
2145 THIS->kv.del (key);
2148 2146
2149void 2147void
2150object::kv_set (shstr key, shstr value) 2148object::kv_set (shstr key, shstr value)
2149 CODE:
2150 THIS->kv.set (key, value);
2151 2151
2152object *get_nearest_player (object *ob) 2152object *get_nearest_player (object *ob)
2153 ALIAS: nearest_player = 0 2153 ALIAS: nearest_player = 0
2154 PREINIT: 2154 PREINIT:
2155 extern object *get_nearest_player (object *); 2155 extern object *get_nearest_player (object *);
2158 PROTOTYPE: $$;$ 2158 PROTOTYPE: $$;$
2159 PPCODE: 2159 PPCODE:
2160{ 2160{
2161 rv_vector rv; 2161 rv_vector rv;
2162 2162
2163 PUTBACK;
2164 get_rangevector (ob, other, &rv, flags); 2163 get_rangevector (ob, other, &rv, flags);
2165 SPAGAIN;
2166 2164
2167 EXTEND (SP, 5); 2165 EXTEND (SP, 5);
2168 PUSHs (newSVuv (rv.distance)); 2166 PUSHs (sv_2mortal (newSVuv (rv.distance)));
2169 PUSHs (newSViv (rv.distance_x)); 2167 PUSHs (sv_2mortal (newSViv (rv.distance_x)));
2170 PUSHs (newSViv (rv.distance_y)); 2168 PUSHs (sv_2mortal (newSViv (rv.distance_y)));
2171 PUSHs (newSViv (rv.direction)); 2169 PUSHs (sv_2mortal (newSViv (rv.direction)));
2172 PUSHs (to_sv (rv.part)); 2170 PUSHs (sv_2mortal (to_sv (rv.part)));
2173} 2171}
2174 2172
2175bool on_same_map_as (object *ob, object *other) 2173bool on_same_map_as (object *ob, object *other)
2176 CODE: 2174 CODE:
2177 RETVAL = on_same_map (ob, other); 2175 RETVAL = on_same_map (ob, other);
2359 for_all_players (pl) 2357 for_all_players (pl)
2360 if (pl->ob && pl->ob->map == THIS) 2358 if (pl->ob && pl->ob->map == THIS)
2361 PUSHs (sv_2mortal (to_sv (pl->ob))); 2359 PUSHs (sv_2mortal (to_sv (pl->ob)));
2362 } 2360 }
2363 2361
2362#if 0
2363
2364void
2365maptile::add_quadland (int mx, int my, int mz, SV *biome_map, SV *biome_plt)
2366 CODE:
2367{
2368 static frac_gen<vec2d> frac;
2369
2370 if (!SvROK (biome_plt) || SvTYPE (SvRV (biome_plt)) != SVt_PVAV)
2371 croak ("maptile::add_quadland: biome_plt must be arrayref");
2372
2373 biome_plt = SvRV (biome_plt);
2374
2375 const uint8_t *bmap = (const uint8_t *)SvPVbyte_nolen (biome_map);
2376
2377 for (int x = 0; x < THIS->width; ++x)
2378 for (int y = 0; y < THIS->height; ++y)
2379 {
2380 for (object *op = THIS->at (x, y).bot; op; op = op->above)
2381 if (op->flag [FLAG_IS_FLOOR])
2382 goto skip;
2383
2384 {
2385 float fx = mx * THIS->width + x;
2386 float fy = my * THIS->height + y;
2387
2388 int temp = clamp (int (32 * frac.fBm (vec2d (fx * 0.001, fy * 0.001), 2) ) - 8, 0, 15);
2389 int rain = clamp (int (16 * frac.ridgedmultifractal (vec2d (fx * 0.01, fy * 0.01), 3, 1.03, 2)) - 8, 0, 15);
2390
2391 rain = lerp (rain, 0, 15, 0, temp);
2392 printf ("rain %d\n", temp);//D
2393
2394 int biome = bmap [rain * 16 + temp];
2395
2396 //printf ("%2d %2d => %s\n", temp, rain, SvPV_nolen (AvARRAY ((AV *)biome_plt)[biome]));//D
2397#if 1
2398 if (SV **elem = av_fetch ((AV *)biome_plt, bmap [rain * 16 + temp], 0))
2399 {
2400 object *ob = get_archetype (cfSvPVutf8_nolen (*elem));
2401 ob->flag [FLAG_NO_MAP_SAVE] = true;
2402 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY);
2403
2404 if (ob->randomitems && !ob->above)
2405 {
2406 ob->create_treasure (ob->randomitems);
2407
2408 for (object *op = ob->above; op; op = op->above)
2409 op->flag [FLAG_NO_MAP_SAVE] = true;
2410 }
2411 }
2412#endif
2413 }
2414 skip: ;
2415 }
2416}
2417
2418#endif
2419
2364void 2420void
2365maptile::add_underlay (SV *data, int offset, int stride, SV *palette) 2421maptile::add_underlay (SV *data, int offset, int stride, SV *palette)
2366 CODE: 2422 CODE:
2367{ 2423{
2368 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV) 2424 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV)
2399 op->flag [FLAG_NO_MAP_SAVE] = true; 2455 op->flag [FLAG_NO_MAP_SAVE] = true;
2400 // TODO: if this is a pickable object, then the item 2456 // TODO: if this is a pickable object, then the item
2401 // will at a bit weird - saving inside the player 2457 // will at a bit weird - saving inside the player
2402 // will clear the flag, but when the player drops 2458 // will clear the flag, but when the player drops
2403 // it without logging out, it keeps the flag. 2459 // it without logging out, it keeps the flag.
2404 // nobody ahs reported this, but this can be rather 2460 // nobody has reported this, but this can be rather
2405 // annoying on persistent maps. 2461 // annoying on persistent maps.
2406 } 2462 }
2407 } 2463 }
2408 } 2464 }
2409 } 2465 }
2410
2411 skip: ; 2466 skip: ;
2412 } 2467 }
2413} 2468}
2414 2469
2415void 2470void
2446 for (int x = 0; x < THIS->width; ++x) 2501 for (int x = 0; x < THIS->width; ++x)
2447 for (int y = 0; y < THIS->height; ++y) 2502 for (int y = 0; y < THIS->height; ++y)
2448 { 2503 {
2449 region *rgn = THIS->region (x, y); 2504 region *rgn = THIS->region (x, y);
2450 2505
2451 //fprintf (stderr, "%d,%d %f %p\n", x, y, rgn->treasure_density,rgn->treasure);//D
2452 if (object *op = THIS->at (x, y).top) 2506 if (object *op = THIS->at (x, y).top)
2453 if (rgn->treasure && rndm () < rgn->treasure_density) 2507 if (rgn->treasure && rndm () < rgn->treasure_density)
2454 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty); 2508 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty);
2455 } 2509 }
2456 2510
2462 if (oblinkpt *obp = map->find_link (connection)) 2516 if (oblinkpt *obp = map->find_link (connection))
2463 for (objectlink *ol = obp->link; ol; ol = ol->next) 2517 for (objectlink *ol = obp->link; ol; ol = ol->next)
2464 XPUSHs (sv_2mortal (to_sv ((object *)ol->ob))); 2518 XPUSHs (sv_2mortal (to_sv ((object *)ol->ob)));
2465 2519
2466void 2520void
2467get_map_flags (maptile *map, int x, int y) 2521xy_normalise (maptile *map, int x, int y, int dir = 0)
2468 PPCODE: 2522 PPCODE:
2469{ 2523{
2470 maptile *nmap = 0; 2524 mapxy pos (map, x, y);
2471 I16 nx = 0, ny = 0; 2525 if (!pos.move (dir).normalise ())
2526 XSRETURN_EMPTY;
2472 2527
2473 PUTBACK;
2474 int flags = get_map_flags (map, &nmap, x, y, &nx, &ny);
2475 SPAGAIN;
2476
2477 EXTEND (SP, 4); 2528 EXTEND (SP, 3);
2478 PUSHs (sv_2mortal (newSViv (flags)));
2479
2480 if (GIMME_V == G_ARRAY)
2481 {
2482 PUSHs (sv_2mortal (to_sv (nmap))); 2529 PUSHs (sv_2mortal (to_sv (pos.m)));
2483 PUSHs (sv_2mortal (newSViv (nx))); 2530 PUSHs (sv_2mortal (to_sv (pos.x)));
2484 PUSHs (sv_2mortal (newSViv (ny))); 2531 PUSHs (sv_2mortal (to_sv (pos.y)));
2485 }
2486} 2532}
2487 2533
2488mapspace * 2534mapspace *
2489ms (maptile *map, unsigned int x, unsigned int y) 2535ms (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2490 PROTOTYPE: $$$ 2536 PROTOTYPE: $$$;$
2491 CODE: 2537 CODE:
2492{ 2538{
2493 maptile *nmap = 0; 2539 mapxy pos (map, x, y);
2494 I16 nx, ny; 2540 if (!pos.move (dir).normalise ())
2495
2496 PUTBACK;
2497 get_map_flags (map, &nmap, x, y, &nx, &ny);
2498 SPAGAIN;
2499
2500 if (!nmap)
2501 XSRETURN_UNDEF; 2541 XSRETURN_UNDEF;
2502 2542
2503 RETVAL = &nmap->at (nx, ny); 2543 RETVAL = &*pos;
2504} 2544}
2505 OUTPUT: 2545 OUTPUT:
2506 RETVAL 2546 RETVAL
2507 2547
2508void 2548void
2509at (maptile *map, unsigned int x, unsigned int y) 2549at (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2510 PROTOTYPE: $$$ 2550 PROTOTYPE: $$$;$
2511 PPCODE: 2551 PPCODE:
2512{ 2552 mapxy pos (map, x, y);
2513 maptile *nmap = 0; 2553 if (pos.move (dir).normalise ())
2514 I16 nx, ny;
2515
2516 PUTBACK;
2517 get_map_flags (map, &nmap, x, y, &nx, &ny);
2518 SPAGAIN;
2519
2520 if (nmap)
2521 for (object *o = nmap->at (nx, ny).bot; o; o = o->above) 2554 for (object *o = pos->bot; o; o = o->above)
2522 XPUSHs (sv_2mortal (to_sv (o))); 2555 XPUSHs (sv_2mortal (to_sv (o)));
2523}
2524 2556
2525SV * 2557SV *
2526bot_at (maptile *map, unsigned int x, unsigned int y) 2558bot_at (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2527 PROTOTYPE: $$$ 2559 PROTOTYPE: $$$;$
2528 ALIAS: 2560 ALIAS:
2529 top_at = 1 2561 top_at = 1
2530 flags_at = 2 2562 flags_at = 2
2531 light_at = 3 2563 light_at = 3
2532 move_block_at = 4 2564 move_block_at = 4
2533 move_slow_at = 5 2565 move_slow_at = 5
2534 move_on_at = 6 2566 move_on_at = 6
2535 move_off_at = 7 2567 move_off_at = 7
2536 CODE: 2568 CODE:
2537{ 2569{
2538 sint16 nx = x; 2570 mapxy pos (map, x, y);
2539 sint16 ny = y; 2571 if (!pos.move (dir).normalise ())
2540
2541 if (!xy_normalise (map, nx, ny))
2542 XSRETURN_UNDEF; 2572 XSRETURN_UNDEF;
2543 2573
2544 mapspace &ms = map->at (nx, ny); 2574 mapspace &ms = *pos;
2545 2575
2546 ms.update (); 2576 ms.update ();
2547 2577
2548 switch (ix) 2578 switch (ix)
2549 { 2579 {
2559} 2589}
2560 OUTPUT: RETVAL 2590 OUTPUT: RETVAL
2561 2591
2562# worst xs function of my life 2592# worst xs function of my life
2563bool 2593bool
2564_create_random_map (\ 2594_create_random_map (maptile *self, SV *options)
2565 maptile *self,\
2566 utf8_string wallstyle,\
2567 utf8_string wall_name,\
2568 utf8_string floorstyle,\
2569 utf8_string monsterstyle,\
2570 utf8_string treasurestyle,\
2571 utf8_string layoutstyle,\
2572 utf8_string doorstyle,\
2573 utf8_string decorstyle,\
2574 utf8_string miningstyle,\
2575 utf8_string origin_map,\
2576 utf8_string final_map,\
2577 utf8_string exitstyle,\
2578 utf8_string this_map,\
2579 utf8_string exit_on_final_map,\
2580 int xsize,\
2581 int ysize,\
2582 int expand2x,\
2583 int layoutoptions1,\
2584 int layoutoptions2,\
2585 int layoutoptions3,\
2586 int symmetry,\
2587 int difficulty,\
2588 int difficulty_given,\
2589 float difficulty_increase,\
2590 int dungeon_level,\
2591 int dungeon_depth,\
2592 int decoroptions,\
2593 int orientation,\
2594 int origin_y,\
2595 int origin_x,\
2596 U32 random_seed,\
2597 val64 total_map_hp,\
2598 int map_layout_style,\
2599 int treasureoptions,\
2600 int symmetry_used,\
2601 region *region,\
2602 utf8_string custom\
2603)
2604 CODE: 2595 CODE:
2605{ 2596{
2606 random_map_params rmp; 2597 random_map_params rmp ((HV *)SvRV (options));
2607
2608 assign (rmp.wallstyle , wallstyle);
2609 assign (rmp.wall_name , wall_name);
2610 assign (rmp.floorstyle , floorstyle);
2611 assign (rmp.monsterstyle , monsterstyle);
2612 assign (rmp.treasurestyle , treasurestyle);
2613 assign (rmp.layoutstyle , layoutstyle);
2614 assign (rmp.doorstyle , doorstyle);
2615 assign (rmp.decorstyle , decorstyle);
2616 assign (rmp.miningstyle , miningstyle);
2617 assign (rmp.exitstyle , exitstyle);
2618 assign (rmp.exit_on_final_map, exit_on_final_map);
2619
2620 rmp.origin_map = origin_map;
2621 rmp.final_map = final_map;
2622 rmp.this_map = this_map;
2623 rmp.xsize = xsize;
2624 rmp.ysize = ysize;
2625 rmp.expand2x = expand2x;
2626 rmp.layoutoptions1 = layoutoptions1;
2627 rmp.layoutoptions2 = layoutoptions2;
2628 rmp.layoutoptions3 = layoutoptions3;
2629 rmp.symmetry = symmetry;
2630 rmp.difficulty = difficulty;
2631 rmp.difficulty_given = difficulty_given;
2632 rmp.difficulty_increase = difficulty_increase;
2633 rmp.dungeon_level = dungeon_level;
2634 rmp.dungeon_depth = dungeon_depth;
2635 rmp.decoroptions = decoroptions;
2636 rmp.orientation = orientation;
2637 rmp.origin_y = origin_y;
2638 rmp.origin_x = origin_x;
2639 rmp.random_seed = random_seed;
2640 rmp.total_map_hp = (uint64_t) total_map_hp;
2641 rmp.map_layout_style = map_layout_style;
2642 rmp.treasureoptions = treasureoptions;
2643 rmp.symmetry_used = symmetry_used;
2644 rmp.region = region;
2645 rmp.custom = custom;
2646
2647 RETVAL = self->generate_random_map (&rmp); 2598 RETVAL = self->generate_random_map (&rmp);
2648} 2599}
2649 OUTPUT: 2600 OUTPUT:
2650 RETVAL 2601 RETVAL
2651 2602
2682void 2633void
2683list () 2634list ()
2684 PPCODE: 2635 PPCODE:
2685 for_all_regions (rgn) 2636 for_all_regions (rgn)
2686 XPUSHs (sv_2mortal (to_sv (rgn))); 2637 XPUSHs (sv_2mortal (to_sv (rgn)));
2687
2688region *find (utf8_string name)
2689 PROTOTYPE: $
2690 CODE:
2691 RETVAL = region::find (name);
2692 OUTPUT: RETVAL
2693 2638
2694int specificity (region *rgn) 2639int specificity (region *rgn)
2695 CODE: 2640 CODE:
2696 RETVAL = 0; 2641 RETVAL = 0;
2697 while (rgn = rgn->parent) 2642 while (rgn = rgn->parent)
2801 while (!RETVAL); // crude way to leave index 0 2746 while (!RETVAL); // crude way to leave index 0
2802 2747
2803 faces [RETVAL].name = name; 2748 faces [RETVAL].name = name;
2804 facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL)); 2749 facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL));
2805 2750
2806 if (!strcmp (name, BLANK_FACE_NAME)) blank_face = RETVAL; 2751 if (!strcmp (name, BLANK_FACE_NAME )) blank_face = RETVAL;
2807 if (!strcmp (name, EMPTY_FACE_NAME)) empty_face = RETVAL; 2752 if (!strcmp (name, EMPTY_FACE_NAME )) empty_face = RETVAL;
2753 if (!strcmp (name, MAGICMOUTH_FACE_NAME)) magicmouth_face = RETVAL;
2808} 2754}
2809 OUTPUT: RETVAL 2755 OUTPUT: RETVAL
2810 2756
2811void set_type (faceidx idx, int value) 2757void set_type (faceidx idx, int value)
2812 ALIAS: 2758 ALIAS:
2828 2774
2829void set_data (faceidx idx, int faceset, SV *data, SV *chksum) 2775void set_data (faceidx idx, int faceset, SV *data, SV *chksum)
2830 CODE: 2776 CODE:
2831{ 2777{
2832 faceinfo *f = face_info (idx); assert (f); 2778 faceinfo *f = face_info (idx); assert (f);
2833 facedata *d = &(faceset ? f->data64 : f->data32); 2779 facedata *d = f->face + faceset;
2834 sv_to (data, d->data); 2780 sv_to (data, d->data);
2835 STRLEN clen; 2781 STRLEN clen;
2836 char *cdata = SvPVbyte (chksum, clen); 2782 char *cdata = SvPVbyte (chksum, clen);
2837 clen = min (CHKSUM_MAXLEN, clen); 2783 clen = min (CHKSUM_MAXLEN, clen);
2838 2784
2946 sv_to (sv, self); 2892 sv_to (sv, self);
2947 delete self; 2893 delete self;
2948 2894
2949MODULE = cf PACKAGE = cf::object::thawer 2895MODULE = cf PACKAGE = cf::object::thawer
2950 2896
2951INCLUDE: $PERL $srcdir/genacc object_thawer $srcdir/../include/cfperl.h | 2897INCLUDE: $PERL $srcdir/genacc object_thawer $srcdir/../include/freezethaw.h |
2898
2899bool
2900errors_are_fatal (bool fatal)
2901 CODE:
2902 RETVAL = object_thawer::errors_are_fatal;
2903 object_thawer::errors_are_fatal = fatal;
2904 OUTPUT:
2905 RETVAL
2952 2906
2953SV * 2907SV *
2954new_from_file (char *klass, octet_string path) 2908new_from_file (char *klass, octet_string path)
2955 CODE: 2909 CODE:
2956 object_thawer *f = new object_thawer (path); 2910 object_thawer *f = new object_thawer (path);
2982 XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ()))); 2936 XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ())));
2983 2937
2984 self->skip (); 2938 self->skip ();
2985 } 2939 }
2986 2940
2941MODULE = cf PACKAGE = cf::layout
2942
2943INCLUDE: $PERL $srcdir/genacc layout $srcdir/../include/rmg.h |
2944

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines