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.365 by root, Sun Apr 11 04:09:56 2010 UTC vs.
Revision 1.397 by root, Tue Jan 25 22:39:54 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 "evthread.h" 34#include "evthread.h"
35#include "sproto.h" 35#include "sproto.h"
36 36
37#include <unistd.h> 37#include <unistd.h>
38#if _POSIX_MEMLOCK 38#if _POSIX_MEMLOCK
51#include <perl.h> 51#include <perl.h>
52#include <XSUB.h> 52#include <XSUB.h>
53 53
54#include "CoroAPI.h" 54#include "CoroAPI.h"
55#include "perlxsi.c" 55#include "perlxsi.c"
56
57extern sint64 *levels; // the experience table
58 56
59typedef object_thawer &object_thawer_ref; 57typedef object_thawer &object_thawer_ref;
60typedef object_freezer &object_freezer_ref; 58typedef object_freezer &object_freezer_ref;
61 59
62typedef std::string std__string; 60typedef std::string std__string;
85 *stash_cf_mapspace_wrap, 83 *stash_cf_mapspace_wrap,
86 *stash_cf_client_wrap, 84 *stash_cf_client_wrap,
87 *stash_cf_arch_wrap, 85 *stash_cf_arch_wrap,
88 *stash_cf_party_wrap, 86 *stash_cf_party_wrap,
89 *stash_cf_region_wrap, 87 *stash_cf_region_wrap,
90 *stash_cf_living_wrap; 88 *stash_cf_living_wrap,
89 *stash_cf_layout_wrap,
90 *stash_ext_map_world;
91 91
92static SV 92static SV
93 *cv_cf_do_invoke, 93 *cv_cf_do_invoke,
94 *cv_cf__can_merge, 94 *cv_cf__can_merge,
95 *cv_cf_client_send_msg, 95 *cv_cf_client_send_msg,
123 123
124 return sv; 124 return sv;
125} 125}
126#endif 126#endif
127 127
128static noinline utf8_string 128noinline utf8_string
129cfSvPVutf8_nolen (SV *sv) 129cfSvPVutf8_nolen (SV *sv)
130{ 130{
131 SvGETMAGIC (sv); 131 SvGETMAGIC (sv);
132 132
133 if (SvPOK (sv)) 133 if (SvPOK (sv))
230 do_destroy (); 230 do_destroy ();
231 sever_self (); 231 sever_self ();
232} 232}
233 233
234void 234void
235attachable::do_delete ()
236{
237 delete this;
238}
239
240void
235attachable::check_mortals () 241attachable::check_mortals ()
236{ 242{
237 static int i = 0; 243 static int i = 0;
238 244
239 for (;;) 245 for (;;)
252 258
253 if (0) 259 if (0)
254 { 260 {
255 for (int j = 0; j < mortals.size (); ++j)//D 261 for (int j = 0; j < mortals.size (); ++j)//D
256 fprintf (stderr, "%d:%s %p ", j, &((object *)mortals[j])->name, mortals[j]);//D 262 fprintf (stderr, "%d:%s %p ", j, &((object *)mortals[j])->name, mortals[j]);//D
263
257 fprintf (stderr, "\n");//D 264 fprintf (stderr, "\n");//D
258 } 265 }
259 } 266 }
260 } 267 }
261 268
281 } 288 }
282 else 289 else
283 { 290 {
284 mortals.erase (i); 291 mortals.erase (i);
285 obj->sever_self (); 292 obj->sever_self ();
286 delete obj; 293 obj->do_delete ();
287 } 294 }
288 } 295 }
289} 296}
290 297
291void 298void
346#endif 353#endif
347 354
348////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 355//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
349 356
350static SV * 357static SV *
351newSVptr (void *ptr, HV *stash, HV *hv = newHV ()) 358newSVptr (void *ptr, HV *stash, HV *hv)
352{ 359{
353 SV *sv;
354
355 if (!ptr) 360 if (!ptr)
356 return newSV (0); 361 return newSV (0);
357 362
358 sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, 0, (char *)ptr, 0); 363 sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, 0, (char *)ptr, 0);
359 return sv_bless (newRV_noinc ((SV *)hv), stash); 364 return sv_bless (newRV_noinc ((SV *)hv), stash);
365}
366
367static SV * noinline
368newSVptr (void *ptr, HV *stash)
369{
370 return newSVptr (ptr, stash, newHV ());
360} 371}
361 372
362static int 373static int
363attachable_free (pTHX_ SV *sv, MAGIC *mg) 374attachable_free (pTHX_ SV *sv, MAGIC *mg)
364{ 375{
376 return 0; 387 return 0;
377} 388}
378 389
379MGVTBL attachable::vtbl = {0, 0, 0, 0, attachable_free}; 390MGVTBL attachable::vtbl = {0, 0, 0, 0, attachable_free};
380 391
381static SV * 392static SV * noinline
382newSVattachable (attachable *obj, HV *stash) 393newSVattachable (attachable *obj, HV *stash)
383{ 394{
384 if (!obj) 395 if (!obj)
385 return newSV (0); 396 return newSV (0);
386 397
472 || (SvSTASH (SvRV (sv)) != stash_cf_object_wrap 483 || (SvSTASH (SvRV (sv)) != stash_cf_object_wrap
473 && SvSTASH (SvRV (sv)) != stash_cf_object_player_wrap 484 && SvSTASH (SvRV (sv)) != stash_cf_object_player_wrap
474 && SvSTASH (SvRV (sv)) != stash_cf_arch_wrap 485 && SvSTASH (SvRV (sv)) != stash_cf_arch_wrap
475 && !sv_derived_from (sv, "cf::object"))) 486 && !sv_derived_from (sv, "cf::object")))
476 croak ("object of type cf::object expected"); 487 croak ("object of type cf::object expected");
488
489 return SvPTR_nc (sv);
490}
491
492static long noinline
493SvPTR_ornull_maptile (SV *sv)
494{
495 if (expect_false (!SvOK (sv))) return 0;
496
497 if (!SvROK (sv)
498 || (SvSTASH (SvRV (sv)) != stash_cf_map_wrap
499 && SvSTASH (SvRV (sv)) != stash_ext_map_world
500 && !sv_derived_from (sv, "cf::map")))
501 croak ("object of type cf::map expected");
477 502
478 return SvPTR_nc (sv); 503 return SvPTR_nc (sv);
479} 504}
480 505
481static long noinline 506static long noinline
506static inline SV *to_sv (unsigned long long v) { return newSVval64 (v); } 531static inline SV *to_sv (unsigned long long v) { return newSVval64 (v); }
507static inline SV *to_sv (float v) { return newSVnv (v); } 532static inline SV *to_sv (float v) { return newSVnv (v); }
508static inline SV *to_sv (double v) { return newSVnv (v); } 533static inline SV *to_sv (double v) { return newSVnv (v); }
509static inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); } 534static 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); } 535static inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); }
536// 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); } 537static noinline SV *to_sv_ni (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); }
538static 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); } 539static 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); } 540static 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); } 541static 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); } 542static 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); } 543static 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); } 544static inline SV *to_sv (mapspace * v) { return newSVptr (v, stash_cf_mapspace_wrap); }
545static inline SV *to_sv (layout * v) { return newSVptr (v, stash_cf_layout_wrap); }
518 546
519static inline SV *to_sv (object & v) { return to_sv (&v); } 547static inline SV *to_sv (object & v) { return to_sv (&v); }
520static inline SV *to_sv (living & v) { return to_sv (&v); } 548static inline SV *to_sv (living & v) { return to_sv (&v); }
521 549
522static inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); } 550static 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); } 586static 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); } 587static 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); } 588static 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); } 589static inline void sv_to (SV *sv, float &v) { v = SvNV (sv); }
562static inline void sv_to (SV *sv, double &v) { v = SvNV (sv); } 590static 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); } 591static 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); } 592static 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); } 593static inline void sv_to (SV *sv, object * &v) { v = (object *) (attachable *)SvPTR_ornull_object (sv); }
594static 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"); } 595static 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"); } 596static 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"); } 597static 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"); } 598static 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"); } 599static 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"); } 600static inline void sv_to (SV *sv, mapspace * &v) { v = (mapspace *) SvPTR_ornull (sv, "cf::mapspace"); }
601static 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"); } 602static 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" ); } 603static inline void sv_to (SV *sv, object_thawer * &v) { v = (object_thawer *) SvPTR_ornull (sv, "cf::object::thawer" ); }
575 604
576//static inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; } 605//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)); } 606static inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); }
688template<class type> 717template<class type>
689static void noinline 718static void noinline
690cf_obj_to (SV *arg, type &var) 719cf_obj_to (SV *arg, type &var)
691{ 720{
692 sv_to (arg, var); 721 sv_to (arg, var);
693 if (!var) 722 if (expect_false (!var))
694 croak ("must not pass invalid/null cf_obj here"); 723 croak ("must not pass invalid/null cf_obj here");
695} 724}
696 725
697template<class object> 726template<class object>
698static void noinline 727static void noinline
699cf_obj_ornull_to (SV *arg, object *&var) 728cf_obj_ornull_to (SV *arg, object *&var)
700{ 729{
701 if (SvOK (arg)) 730 if (SvOK (arg))
702 { 731 {
703 sv_to (arg, var); 732 sv_to (arg, var);
704 if (!var) 733 if (expect_false (!var))
705 croak ("unable to convert perl object to C++ object"); 734 croak ("unable to convert perl object to C++ object");
706 } 735 }
707 else 736 else
708 var = 0; 737 var = 0;
709} 738}
744 exit (EXIT_FAILURE); 773 exit (EXIT_FAILURE);
745 } 774 }
746 775
747 eval_pv ( 776 eval_pv (
748 "#line 1 'cfperl init'\n" 777 "#line 1 'cfperl init'\n"
749 "use EV ();\n" 778 "use EV ();\n" // required by bootstrap
750 "use Coro ();\n" 779 "use Coro ();\n" // required by bootstrap
751 "cf->bootstrap;\n" 780 "cf->bootstrap;\n" // required for cf::datadir
752 "unshift @INC, cf::datadir ();\n" 781 "unshift @INC, cf::datadir ();\n" // required for 'require' :)
753 "require cf;\n", 782 "require cf;\n",
754 0 783 0
755 ); 784 );
756 785
757 if (SvTRUE (ERRSV)) 786 if (SvTRUE (ERRSV))
1132 1161
1133 return retval; 1162 return retval;
1134} 1163}
1135 1164
1136maptile * 1165maptile *
1137find_style (const_utf8_string dirname, const_utf8_string stylename, int difficulty) 1166find_style (const_utf8_string dirname, const_utf8_string stylename, int difficulty, bool recurse)
1138{ 1167{
1139 CALL_BEGIN (3); 1168 CALL_BEGIN (4);
1140 CALL_ARG (dirname); 1169 CALL_ARG (dirname);
1141 CALL_ARG (stylename); 1170 CALL_ARG (stylename);
1142 CALL_ARG (difficulty); 1171 CALL_ARG (difficulty);
1172 CALL_ARG (recurse);
1143 CALL_CALL ("ext::map_random::find_style", G_SCALAR); 1173 CALL_CALL ("ext::map_random::find_style", G_SCALAR);
1144 1174
1145 maptile *retval = 0; 1175 maptile *retval = 0;
1146 if (count) sv_to (POPs, retval); 1176 if (count) sv_to (POPs, retval);
1147 1177
1370 stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1); 1400 stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1);
1371 stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1); 1401 stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1);
1372 stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1); 1402 stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1);
1373 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); 1403 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1);
1374 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1); 1404 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1);
1405 stash_cf_layout_wrap = gv_stashpv ("cf::layout::wrap", 1);
1406 stash_ext_map_world = gv_stashpv ("ext::map_world" , 1);
1375 1407
1376 sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV); 1408 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); 1409 sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV);
1378 sv_tick_start = get_sv ("cf::TICK_START", 1); SvUPGRADE (sv_tick_start, SVt_NV); 1410 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); 1411 sv_next_tick = get_sv ("cf::NEXT_TICK" , 1); SvUPGRADE (sv_next_tick , SVt_NV);
1427# include "attackinc.h" 1459# include "attackinc.h"
1428# undef def 1460# undef def
1429# define def(uc, flags) const_iv (SK_ ## uc) 1461# define def(uc, flags) const_iv (SK_ ## uc)
1430# include "skillinc.h" 1462# include "skillinc.h"
1431# undef def 1463# undef def
1432 1464# define def(name, use, nonuse) const_iv (body_ ## name)
1433 const_iv (llevError) const_iv (llevInfo) const_iv (llevDebug) const_iv (llevMonster) 1465# include "slotinc.h"
1434 const_iv (logBacktrace) 1466# undef def
1435
1436 const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd)
1437 1467
1438 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) 1468 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y)
1439 1469
1440 const_iv (MAX_TIME) 1470 const_iv (MAX_TIME)
1441 const_iv (MAXSOCKBUF) 1471 const_iv (MAXSOCKBUF)
1466 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT) 1496 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT)
1467 1497
1468 const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES) 1498 const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES)
1469 }; 1499 };
1470 1500
1471 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 1501 for (civ = const_iv + array_length (const_iv); civ-- > const_iv; )
1472 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv)); 1502 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv));
1473 1503
1474 static const struct { 1504 static const struct {
1475 const char *name; 1505 const char *name;
1476 int skip; 1506 int skip;
1482# undef def 1512# undef def
1483 }; 1513 };
1484 1514
1485 AV *av = get_av ("cf::EVENT", 1); 1515 AV *av = get_av ("cf::EVENT", 1);
1486 1516
1487 for (eiv = event_iv + sizeof (event_iv) / sizeof (event_iv [0]); eiv-- > event_iv; ) 1517 for (eiv = event_iv + array_length (event_iv); eiv-- > event_iv; )
1488 { 1518 {
1489 AV *event = newAV (); 1519 AV *event = newAV ();
1490 av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0)); 1520 av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0));
1491 av_push (event, newSViv (eiv->klass)); 1521 av_push (event, newSViv (eiv->klass));
1492 av_store (av, eiv->iv, newRV_noinc ((SV *)event)); 1522 av_store (av, eiv->iv, newRV_noinc ((SV *)event));
1573 1603
1574void init_anim () 1604void init_anim ()
1575 1605
1576void init_globals () 1606void init_globals ()
1577 1607
1578void init_experience ()
1579
1580void init_attackmess () 1608void init_attackmess ()
1581 1609
1582void init_dynamic () 1610void init_dynamic ()
1583 1611
1584void load_settings () 1612void load_settings ()
1585 1613
1614void reload_exp_table ()
1615
1586void load_materials () 1616void reload_materials ()
1587 1617
1588void init_uuid () 1618void init_uuid ()
1589 CODE: 1619 CODE:
1590 UUID::init (); 1620 UUID::init ();
1591 1621
1657 switch (items) 1687 switch (items)
1658 { 1688 {
1659 case 0: RETVAL = gen (); break; 1689 case 0: RETVAL = gen (); break;
1660 case 1: RETVAL = gen (SvUV (ST (0))); break; 1690 case 1: RETVAL = gen (SvUV (ST (0))); break;
1661 case 2: RETVAL = gen (SvIV (ST (0)), SvIV (ST (1))); break; 1691 case 2: RETVAL = gen (SvIV (ST (0)), SvIV (ST (1))); break;
1662 default: croak ("cf::rndm requires none, one or two parameters."); break; 1692 default: croak ("cf::rndm requires zero, one or two parameters."); break;
1663 } 1693 }
1664} 1694}
1665 OUTPUT: 1695 OUTPUT:
1666 RETVAL 1696 RETVAL
1667 1697
1683 PROTOTYPE: @ 1713 PROTOTYPE: @
1684 CODE: 1714 CODE:
1685 while (items > 0) 1715 while (items > 0)
1686 sv_rvweaken (ST (--items)); 1716 sv_rvweaken (ST (--items));
1687 1717
1688void 1718void log_suspend ()
1719
1720void log_resume ()
1721
1689log_backtrace (utf8_string msg) 1722void log_backtrace (utf8_string msg)
1690 1723
1691void
1692LOG (int flags, utf8_string msg) 1724void LOG (int flags, utf8_string msg)
1693 PROTOTYPE: $$ 1725 PROTOTYPE: $$
1694 C_ARGS: flags, "%s", msg 1726 C_ARGS: flags, "%s", msg
1695 1727
1696octet_string path_combine (octet_string base, octet_string path) 1728octet_string path_combine (octet_string base, octet_string path)
1697 PROTOTYPE: $$ 1729 PROTOTYPE: $$
1744 1776
1745int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) 1777int mlockall (int flags = MCL_CURRENT | MCL_FUTURE)
1746 INIT: 1778 INIT:
1747#if __GLIBC__ 1779#if __GLIBC__
1748 mallopt (M_TOP_PAD, 1024 * 1024); 1780 mallopt (M_TOP_PAD, 1024 * 1024);
1749 mallopt (M_MMAP_THRESHOLD, 1024 * 1024 * 128); 1781 mallopt (M_MMAP_THRESHOLD, 1024 * 1024);
1750 mallopt (M_MMAP_MAX, 0); // likely bug-workaround, also frees memory 1782 mallopt (M_MMAP_MAX, 0); // likely bug-workaround, also frees memory
1783 if (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 10))
1751 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc 1784 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc
1752#endif 1785#endif
1753 1786
1754int munlockall () 1787int munlockall ()
1755 1788
1756#endif 1789#endif
1789 1822
1790int random_roll (int min, int max, object *op, int goodbad); 1823int random_roll (int min, int max, object *op, int goodbad);
1791 1824
1792const_utf8_string cost_string_from_value(uint64 cost, int approx = 0) 1825const_utf8_string cost_string_from_value(uint64 cost, int approx = 0)
1793 1826
1794int
1795exp_to_level (val64 exp) 1827int exp_to_level (val64 exp)
1828
1829val64 level_to_min_exp (int level)
1830
1831SV *
1832attacktype_name (int atnr)
1796 CODE: 1833 CODE:
1797{ 1834 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1798 int i = 0; 1835 ? newSVpv (attacktype_name [atnr], 0)
1799 1836 : &PL_sv_undef;
1800 RETVAL = settings.max_level;
1801
1802 for (i = 1; i <= settings.max_level; i++)
1803 {
1804 if (levels[i] > exp)
1805 {
1806 RETVAL = i - 1;
1807 break;
1808 }
1809 }
1810}
1811 OUTPUT: RETVAL 1837 OUTPUT: RETVAL
1812 1838
1813val64
1814level_to_min_exp (int level)
1815 CODE:
1816 if (level > settings.max_level)
1817 RETVAL = levels[settings.max_level];
1818 else if (level < 1)
1819 RETVAL = 0;
1820 else
1821 RETVAL = levels[level];
1822 OUTPUT: RETVAL
1823
1824SV * 1839SV *
1825resistance_to_string (int atnr) 1840attacktype_desc (int atnr)
1826 CODE: 1841 CODE:
1827 if (atnr >= 0 && atnr < NROFATTACKS) 1842 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1843 ? newSVpv (attacktype_desc [atnr], 0)
1844 : &PL_sv_undef;
1845 OUTPUT: RETVAL
1846
1847SV *
1848resist_plus (int atnr)
1849 CODE:
1850 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1828 RETVAL = newSVpv (resist_plus[atnr], 0); 1851 ? newSVpv (resist_plus [atnr], 0)
1829 else 1852 : &PL_sv_undef;
1830 XSRETURN_UNDEF; 1853 OUTPUT: RETVAL
1854
1855SV *
1856change_resist_msg (int atnr)
1857 CODE:
1858 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1859 ? newSVpv (change_resist_msg [atnr], 0)
1860 : &PL_sv_undef;
1831 OUTPUT: RETVAL 1861 OUTPUT: RETVAL
1832 1862
1833UUID 1863UUID
1834uuid_cur () 1864uuid_cur ()
1835 CODE: 1865 CODE:
1885 CODE: 1915 CODE:
1886 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); 1916 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext);
1887 OUTPUT: 1917 OUTPUT:
1888 RETVAL 1918 RETVAL
1889 1919
1920bool should_invoke (attachable *obj, int event)
1921 CODE:
1922 RETVAL = obj->should_invoke ((event_type)event);
1923 OUTPUT: RETVAL
1924
1890void 1925void
1891debug_trace (attachable *obj, bool on = true) 1926debug_trace (attachable *obj, bool on = true)
1892 CODE: 1927 CODE:
1893 obj->attachable_flags &= ~attachable::F_DEBUG_TRACE; 1928 obj->attachable_flags &= ~attachable::F_DEBUG_TRACE;
1894 if (on) 1929 if (on)
1953int mortals_size () 1988int mortals_size ()
1954 CODE: 1989 CODE:
1955 RETVAL = attachable::mortals.size (); 1990 RETVAL = attachable::mortals.size ();
1956 OUTPUT: RETVAL 1991 OUTPUT: RETVAL
1957 1992
1958const_utf8_string slot_use_name (U32 slot) 1993const_utf8_string slot_name (U32 slot)
1959 ALIAS: 1994 ALIAS:
1995 slot_name = 0
1996 slot_use_name = 1
1960 slot_nonuse_name = 1 1997 slot_nonuse_name = 2
1961 CODE: 1998 CODE:
1962{ 1999{
1963 if (slot >= NUM_BODY_LOCATIONS) 2000 if (slot >= NUM_BODY_LOCATIONS)
1964 croak ("body slot index out of range"); 2001 croak ("body slot index out of range");
1965 2002
1966 switch (ix) 2003 switch (ix)
1967 { 2004 {
2005 case 0: RETVAL = body_locations[slot].name ; break;
1968 case 0: RETVAL = body_locations[slot].use_name; break; 2006 case 1: RETVAL = body_locations[slot].use_name ; break;
1969 case 1: RETVAL = body_locations[slot].nonuse_name; break; 2007 case 2: RETVAL = body_locations[slot].nonuse_name; break;
1970 } 2008 }
1971} 2009}
1972 OUTPUT: 2010 OUTPUT:
1973 RETVAL 2011 RETVAL
1974 2012
2019 OUTPUT: 2057 OUTPUT:
2020 RETVAL 2058 RETVAL
2021 2059
2022object *find_best_object_match (object *op, utf8_string match) 2060object *find_best_object_match (object *op, utf8_string match)
2023 2061
2024object *find_marked_object (object *op)
2025
2026int need_identify (object *obj);
2027
2028int apply_shop_mat (object *shop_mat, object *op); 2062int apply_shop_mat (object *shop_mat, object *op);
2029 2063
2030int move (object *op, int dir, object *originator = op) 2064int move (object *op, int dir, object *originator = op)
2031 CODE: 2065 CODE:
2032 RETVAL = op->move (dir, originator); 2066 RETVAL = op->move (dir, originator);
2084 2118
2085void pick_up (object *who, object *op) 2119void pick_up (object *who, object *op)
2086 2120
2087void update_object (object *op, int action) 2121void update_object (object *op, int action)
2088 2122
2089void change_exp (object *op, uint64 exp, utf8_string skill_name = 0, int flag = 0) 2123void change_exp (object *op, uint64 exp, shstr_tmp skill_name = shstr_tmp (), int flag = 0)
2090 2124
2091void player_lvl_adj (object *who, object *skill = 0) 2125void player_lvl_adj (object *who, object *skill = 0)
2092 2126
2093int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL) 2127int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL)
2094 2128
2459 if (oblinkpt *obp = map->find_link (connection)) 2493 if (oblinkpt *obp = map->find_link (connection))
2460 for (objectlink *ol = obp->link; ol; ol = ol->next) 2494 for (objectlink *ol = obp->link; ol; ol = ol->next)
2461 XPUSHs (sv_2mortal (to_sv ((object *)ol->ob))); 2495 XPUSHs (sv_2mortal (to_sv ((object *)ol->ob)));
2462 2496
2463void 2497void
2464get_map_flags (maptile *map, int x, int y) 2498xy_normalise (maptile *map, int x, int y, int dir = 0)
2465 PPCODE: 2499 PPCODE:
2466{ 2500{
2467 maptile *nmap = 0; 2501 mapxy pos (map, x, y);
2468 I16 nx = 0, ny = 0; 2502 if (!pos.move (dir).normalise ())
2503 XSRETURN_EMPTY;
2469 2504
2470 PUTBACK;
2471 int flags = get_map_flags (map, &nmap, x, y, &nx, &ny);
2472 SPAGAIN;
2473
2474 EXTEND (SP, 4); 2505 EXTEND (SP, 3);
2475 PUSHs (sv_2mortal (newSViv (flags)));
2476
2477 if (GIMME_V == G_ARRAY)
2478 {
2479 PUSHs (sv_2mortal (to_sv (nmap))); 2506 PUSHs (sv_2mortal (to_sv (pos.m)));
2480 PUSHs (sv_2mortal (newSViv (nx))); 2507 PUSHs (sv_2mortal (to_sv (pos.x)));
2481 PUSHs (sv_2mortal (newSViv (ny))); 2508 PUSHs (sv_2mortal (to_sv (pos.y)));
2482 }
2483} 2509}
2484 2510
2485mapspace * 2511mapspace *
2486ms (maptile *map, unsigned int x, unsigned int y) 2512ms (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2487 PROTOTYPE: $$$ 2513 PROTOTYPE: $$$;$
2488 CODE: 2514 CODE:
2489{ 2515{
2490 maptile *nmap = 0; 2516 mapxy pos (map, x, y);
2491 I16 nx, ny; 2517 if (!pos.move (dir).normalise ())
2492
2493 PUTBACK;
2494 get_map_flags (map, &nmap, x, y, &nx, &ny);
2495 SPAGAIN;
2496
2497 if (!nmap)
2498 XSRETURN_UNDEF; 2518 XSRETURN_UNDEF;
2499 2519
2500 RETVAL = &nmap->at (nx, ny); 2520 RETVAL = &*pos;
2501} 2521}
2502 OUTPUT: 2522 OUTPUT:
2503 RETVAL 2523 RETVAL
2504 2524
2505void 2525void
2506at (maptile *map, unsigned int x, unsigned int y) 2526at (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2507 PROTOTYPE: $$$ 2527 PROTOTYPE: $$$;$
2508 PPCODE: 2528 PPCODE:
2509{ 2529 mapxy pos (map, x, y);
2510 maptile *nmap = 0; 2530 if (pos.move (dir).normalise ())
2511 I16 nx, ny;
2512
2513 PUTBACK;
2514 get_map_flags (map, &nmap, x, y, &nx, &ny);
2515 SPAGAIN;
2516
2517 if (nmap)
2518 for (object *o = nmap->at (nx, ny).bot; o; o = o->above) 2531 for (object *o = pos->bot; o; o = o->above)
2519 XPUSHs (sv_2mortal (to_sv (o))); 2532 XPUSHs (sv_2mortal (to_sv (o)));
2520}
2521 2533
2522SV * 2534SV *
2523bot_at (maptile *map, unsigned int x, unsigned int y) 2535bot_at (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2524 PROTOTYPE: $$$ 2536 PROTOTYPE: $$$;$
2525 ALIAS: 2537 ALIAS:
2526 top_at = 1 2538 top_at = 1
2527 flags_at = 2 2539 flags_at = 2
2528 light_at = 3 2540 light_at = 3
2529 move_block_at = 4 2541 move_block_at = 4
2530 move_slow_at = 5 2542 move_slow_at = 5
2531 move_on_at = 6 2543 move_on_at = 6
2532 move_off_at = 7 2544 move_off_at = 7
2533 CODE: 2545 CODE:
2534{ 2546{
2535 sint16 nx = x; 2547 mapxy pos (map, x, y);
2536 sint16 ny = y; 2548 if (!pos.move (dir).normalise ())
2537
2538 if (!xy_normalise (map, nx, ny))
2539 XSRETURN_UNDEF; 2549 XSRETURN_UNDEF;
2540 2550
2541 mapspace &ms = map->at (nx, ny); 2551 mapspace &ms = *pos;
2542 2552
2543 ms.update (); 2553 ms.update ();
2544 2554
2545 switch (ix) 2555 switch (ix)
2546 { 2556 {
2556} 2566}
2557 OUTPUT: RETVAL 2567 OUTPUT: RETVAL
2558 2568
2559# worst xs function of my life 2569# worst xs function of my life
2560bool 2570bool
2561_create_random_map (\ 2571_create_random_map (maptile *self, SV *options)
2562 maptile *self,\
2563 utf8_string wallstyle,\
2564 utf8_string wall_name,\
2565 utf8_string floorstyle,\
2566 utf8_string monsterstyle,\
2567 utf8_string treasurestyle,\
2568 utf8_string layoutstyle,\
2569 utf8_string doorstyle,\
2570 utf8_string decorstyle,\
2571 utf8_string miningstyle,\
2572 utf8_string origin_map,\
2573 utf8_string final_map,\
2574 utf8_string exitstyle,\
2575 utf8_string this_map,\
2576 utf8_string exit_on_final_map,\
2577 int xsize,\
2578 int ysize,\
2579 int expand2x,\
2580 int layoutoptions1,\
2581 int layoutoptions2,\
2582 int layoutoptions3,\
2583 int symmetry,\
2584 int difficulty,\
2585 int difficulty_given,\
2586 float difficulty_increase,\
2587 int dungeon_level,\
2588 int dungeon_depth,\
2589 int decoroptions,\
2590 int orientation,\
2591 int origin_y,\
2592 int origin_x,\
2593 U32 random_seed,\
2594 val64 total_map_hp,\
2595 int map_layout_style,\
2596 int treasureoptions,\
2597 int symmetry_used,\
2598 region *region,\
2599 utf8_string custom\
2600)
2601 CODE: 2572 CODE:
2602{ 2573{
2603 random_map_params rmp; 2574 random_map_params rmp ((HV *)SvRV (options));
2604
2605 assign (rmp.wallstyle , wallstyle);
2606 assign (rmp.wall_name , wall_name);
2607 assign (rmp.floorstyle , floorstyle);
2608 assign (rmp.monsterstyle , monsterstyle);
2609 assign (rmp.treasurestyle , treasurestyle);
2610 assign (rmp.layoutstyle , layoutstyle);
2611 assign (rmp.doorstyle , doorstyle);
2612 assign (rmp.decorstyle , decorstyle);
2613 assign (rmp.miningstyle , miningstyle);
2614 assign (rmp.exitstyle , exitstyle);
2615 assign (rmp.exit_on_final_map, exit_on_final_map);
2616
2617 rmp.origin_map = origin_map;
2618 rmp.final_map = final_map;
2619 rmp.this_map = this_map;
2620 rmp.xsize = xsize;
2621 rmp.ysize = ysize;
2622 rmp.expand2x = expand2x;
2623 rmp.layoutoptions1 = layoutoptions1;
2624 rmp.layoutoptions2 = layoutoptions2;
2625 rmp.layoutoptions3 = layoutoptions3;
2626 rmp.symmetry = symmetry;
2627 rmp.difficulty = difficulty;
2628 rmp.difficulty_given = difficulty_given;
2629 rmp.difficulty_increase = difficulty_increase;
2630 rmp.dungeon_level = dungeon_level;
2631 rmp.dungeon_depth = dungeon_depth;
2632 rmp.decoroptions = decoroptions;
2633 rmp.orientation = orientation;
2634 rmp.origin_y = origin_y;
2635 rmp.origin_x = origin_x;
2636 rmp.random_seed = random_seed;
2637 rmp.total_map_hp = (uint64_t) total_map_hp;
2638 rmp.map_layout_style = map_layout_style;
2639 rmp.treasureoptions = treasureoptions;
2640 rmp.symmetry_used = symmetry_used;
2641 rmp.region = region;
2642 rmp.custom = custom;
2643
2644 RETVAL = self->generate_random_map (&rmp); 2575 RETVAL = self->generate_random_map (&rmp);
2645} 2576}
2646 OUTPUT: 2577 OUTPUT:
2647 RETVAL 2578 RETVAL
2648 2579
2679void 2610void
2680list () 2611list ()
2681 PPCODE: 2612 PPCODE:
2682 for_all_regions (rgn) 2613 for_all_regions (rgn)
2683 XPUSHs (sv_2mortal (to_sv (rgn))); 2614 XPUSHs (sv_2mortal (to_sv (rgn)));
2684
2685region *find (utf8_string name)
2686 PROTOTYPE: $
2687 CODE:
2688 RETVAL = region::find (name);
2689 OUTPUT: RETVAL
2690 2615
2691int specificity (region *rgn) 2616int specificity (region *rgn)
2692 CODE: 2617 CODE:
2693 RETVAL = 0; 2618 RETVAL = 0;
2694 while (rgn = rgn->parent) 2619 while (rgn = rgn->parent)
2798 while (!RETVAL); // crude way to leave index 0 2723 while (!RETVAL); // crude way to leave index 0
2799 2724
2800 faces [RETVAL].name = name; 2725 faces [RETVAL].name = name;
2801 facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL)); 2726 facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL));
2802 2727
2803 if (!strcmp (name, BLANK_FACE_NAME)) blank_face = RETVAL; 2728 if (!strcmp (name, BLANK_FACE_NAME )) blank_face = RETVAL;
2804 if (!strcmp (name, EMPTY_FACE_NAME)) empty_face = RETVAL; 2729 if (!strcmp (name, EMPTY_FACE_NAME )) empty_face = RETVAL;
2730 if (!strcmp (name, MAGICMOUTH_FACE_NAME)) magicmouth_face = RETVAL;
2805} 2731}
2806 OUTPUT: RETVAL 2732 OUTPUT: RETVAL
2807 2733
2808void set_type (faceidx idx, int value) 2734void set_type (faceidx idx, int value)
2809 ALIAS: 2735 ALIAS:
2825 2751
2826void set_data (faceidx idx, int faceset, SV *data, SV *chksum) 2752void set_data (faceidx idx, int faceset, SV *data, SV *chksum)
2827 CODE: 2753 CODE:
2828{ 2754{
2829 faceinfo *f = face_info (idx); assert (f); 2755 faceinfo *f = face_info (idx); assert (f);
2830 facedata *d = &(faceset ? f->data64 : f->data32); 2756 facedata *d = f->face + faceset;
2831 sv_to (data, d->data); 2757 sv_to (data, d->data);
2832 STRLEN clen; 2758 STRLEN clen;
2833 char *cdata = SvPVbyte (chksum, clen); 2759 char *cdata = SvPVbyte (chksum, clen);
2834 clen = min (CHKSUM_MAXLEN, clen); 2760 clen = min (CHKSUM_MAXLEN, clen);
2835 2761
2943 sv_to (sv, self); 2869 sv_to (sv, self);
2944 delete self; 2870 delete self;
2945 2871
2946MODULE = cf PACKAGE = cf::object::thawer 2872MODULE = cf PACKAGE = cf::object::thawer
2947 2873
2948INCLUDE: $PERL $srcdir/genacc object_thawer $srcdir/../include/cfperl.h | 2874INCLUDE: $PERL $srcdir/genacc object_thawer $srcdir/../include/freezethaw.h |
2875
2876bool
2877errors_are_fatal (bool fatal)
2878 CODE:
2879 RETVAL = object_thawer::errors_are_fatal;
2880 object_thawer::errors_are_fatal = fatal;
2881 OUTPUT:
2882 RETVAL
2949 2883
2950SV * 2884SV *
2951new_from_file (char *klass, octet_string path) 2885new_from_file (char *klass, octet_string path)
2952 CODE: 2886 CODE:
2953 object_thawer *f = new object_thawer (path); 2887 object_thawer *f = new object_thawer (path);
2979 XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ()))); 2913 XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ())));
2980 2914
2981 self->skip (); 2915 self->skip ();
2982 } 2916 }
2983 2917
2918MODULE = cf PACKAGE = cf::layout
2919
2920INCLUDE: $PERL $srcdir/genacc layout $srcdir/../include/rmg.h |
2921

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines