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.361 by root, Tue Apr 6 22:59:28 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
1224object::ref () const 1254object::ref () const
1225{ 1255{
1226 if (type == PLAYER) 1256 if (type == PLAYER)
1227 return format ("player/<1.%llx>/%s", (unsigned long long)uuid.seq, &name); 1257 return format ("player/<1.%llx>/%s", (unsigned long long)uuid.seq, &name);
1228 else 1258 else
1259 // TODO: should be able to save references within the same map, at least
1229 return 0; 1260 return 0;
1230} 1261}
1231 1262
1232object * 1263object *
1233object::deref (const_utf8_string ref) 1264object::deref (const_utf8_string ref)
1369 stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1); 1400 stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1);
1370 stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1); 1401 stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1);
1371 stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1); 1402 stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1);
1372 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); 1403 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1);
1373 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);
1374 1407
1375 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);
1376 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);
1377 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);
1378 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);
1426# include "attackinc.h" 1459# include "attackinc.h"
1427# undef def 1460# undef def
1428# define def(uc, flags) const_iv (SK_ ## uc) 1461# define def(uc, flags) const_iv (SK_ ## uc)
1429# include "skillinc.h" 1462# include "skillinc.h"
1430# undef def 1463# undef def
1431 1464# define def(name, use, nonuse) const_iv (body_ ## name)
1432 const_iv (llevError) const_iv (llevInfo) const_iv (llevDebug) const_iv (llevMonster) 1465# include "slotinc.h"
1433 const_iv (logBacktrace) 1466# undef def
1434
1435 const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd)
1436 1467
1437 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) 1468 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y)
1438 1469
1439 const_iv (MAX_TIME) 1470 const_iv (MAX_TIME)
1440 const_iv (MAXSOCKBUF) 1471 const_iv (MAXSOCKBUF)
1460 const_iv (MAP_INACTIVE) 1491 const_iv (MAP_INACTIVE)
1461 1492
1462 const_iv (KLASS_ATTACHABLE) const_iv (KLASS_GLOBAL) const_iv (KLASS_OBJECT) 1493 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) 1494 const_iv (KLASS_CLIENT) const_iv (KLASS_PLAYER) const_iv (KLASS_MAP)
1464 1495
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) 1496 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT)
1468 1497
1469 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)
1470 }; 1499 };
1471 1500
1472 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; )
1473 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv)); 1502 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv));
1474 1503
1475 static const struct { 1504 static const struct {
1476 const char *name; 1505 const char *name;
1477 int skip; 1506 int skip;
1483# undef def 1512# undef def
1484 }; 1513 };
1485 1514
1486 AV *av = get_av ("cf::EVENT", 1); 1515 AV *av = get_av ("cf::EVENT", 1);
1487 1516
1488 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; )
1489 { 1518 {
1490 AV *event = newAV (); 1519 AV *event = newAV ();
1491 av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0)); 1520 av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0));
1492 av_push (event, newSViv (eiv->klass)); 1521 av_push (event, newSViv (eiv->klass));
1493 av_store (av, eiv->iv, newRV_noinc ((SV *)event)); 1522 av_store (av, eiv->iv, newRV_noinc ((SV *)event));
1574 1603
1575void init_anim () 1604void init_anim ()
1576 1605
1577void init_globals () 1606void init_globals ()
1578 1607
1579void init_experience ()
1580
1581void init_attackmess () 1608void init_attackmess ()
1582 1609
1583void init_dynamic () 1610void init_dynamic ()
1584 1611
1585void load_settings () 1612void load_settings ()
1586 1613
1614void reload_exp_table ()
1615
1587void load_materials () 1616void reload_materials ()
1588 1617
1589void init_uuid () 1618void init_uuid ()
1590 CODE: 1619 CODE:
1591 UUID::init (); 1620 UUID::init ();
1592 1621
1658 switch (items) 1687 switch (items)
1659 { 1688 {
1660 case 0: RETVAL = gen (); break; 1689 case 0: RETVAL = gen (); break;
1661 case 1: RETVAL = gen (SvUV (ST (0))); break; 1690 case 1: RETVAL = gen (SvUV (ST (0))); break;
1662 case 2: RETVAL = gen (SvIV (ST (0)), SvIV (ST (1))); break; 1691 case 2: RETVAL = gen (SvIV (ST (0)), SvIV (ST (1))); break;
1663 default: croak ("cf::rndm requires none, one or two parameters."); break; 1692 default: croak ("cf::rndm requires zero, one or two parameters."); break;
1664 } 1693 }
1665} 1694}
1666 OUTPUT: 1695 OUTPUT:
1667 RETVAL 1696 RETVAL
1668 1697
1684 PROTOTYPE: @ 1713 PROTOTYPE: @
1685 CODE: 1714 CODE:
1686 while (items > 0) 1715 while (items > 0)
1687 sv_rvweaken (ST (--items)); 1716 sv_rvweaken (ST (--items));
1688 1717
1689void 1718void log_suspend ()
1719
1720void log_resume ()
1721
1690log_backtrace (utf8_string msg) 1722void log_backtrace (utf8_string msg)
1691 1723
1692void
1693LOG (int flags, utf8_string msg) 1724void LOG (int flags, utf8_string msg)
1694 PROTOTYPE: $$ 1725 PROTOTYPE: $$
1695 C_ARGS: flags, "%s", msg 1726 C_ARGS: flags, "%s", msg
1696 1727
1697octet_string path_combine (octet_string base, octet_string path) 1728octet_string path_combine (octet_string base, octet_string path)
1698 PROTOTYPE: $$ 1729 PROTOTYPE: $$
1745 1776
1746int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) 1777int mlockall (int flags = MCL_CURRENT | MCL_FUTURE)
1747 INIT: 1778 INIT:
1748#if __GLIBC__ 1779#if __GLIBC__
1749 mallopt (M_TOP_PAD, 1024 * 1024); 1780 mallopt (M_TOP_PAD, 1024 * 1024);
1750 mallopt (M_MMAP_THRESHOLD, 1024 * 1024 * 128); 1781 mallopt (M_MMAP_THRESHOLD, 1024 * 1024);
1751 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))
1752 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc 1784 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc
1753#endif 1785#endif
1754 1786
1755int munlockall () 1787int munlockall ()
1756 1788
1757#endif 1789#endif
1790 1822
1791int random_roll (int min, int max, object *op, int goodbad); 1823int random_roll (int min, int max, object *op, int goodbad);
1792 1824
1793const_utf8_string cost_string_from_value(uint64 cost, int approx = 0) 1825const_utf8_string cost_string_from_value(uint64 cost, int approx = 0)
1794 1826
1795int
1796exp_to_level (val64 exp) 1827int exp_to_level (val64 exp)
1828
1829val64 level_to_min_exp (int level)
1830
1831SV *
1832attacktype_name (int atnr)
1797 CODE: 1833 CODE:
1798{ 1834 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1799 int i = 0; 1835 ? newSVpv (attacktype_name [atnr], 0)
1800 1836 : &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 1837 OUTPUT: RETVAL
1813 1838
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 * 1839SV *
1826resistance_to_string (int atnr) 1840attacktype_desc (int atnr)
1827 CODE: 1841 CODE:
1828 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)
1829 RETVAL = newSVpv (resist_plus[atnr], 0); 1851 ? newSVpv (resist_plus [atnr], 0)
1830 else 1852 : &PL_sv_undef;
1831 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;
1832 OUTPUT: RETVAL 1861 OUTPUT: RETVAL
1833 1862
1834UUID 1863UUID
1835uuid_cur () 1864uuid_cur ()
1836 CODE: 1865 CODE:
1886 CODE: 1915 CODE:
1887 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); 1916 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext);
1888 OUTPUT: 1917 OUTPUT:
1889 RETVAL 1918 RETVAL
1890 1919
1920bool should_invoke (attachable *obj, int event)
1921 CODE:
1922 RETVAL = obj->should_invoke ((event_type)event);
1923 OUTPUT: RETVAL
1924
1891void 1925void
1892debug_trace (attachable *obj, bool on = true) 1926debug_trace (attachable *obj, bool on = true)
1893 CODE: 1927 CODE:
1894 obj->attachable_flags &= ~attachable::F_DEBUG_TRACE; 1928 obj->attachable_flags &= ~attachable::F_DEBUG_TRACE;
1895 if (on) 1929 if (on)
1954int mortals_size () 1988int mortals_size ()
1955 CODE: 1989 CODE:
1956 RETVAL = attachable::mortals.size (); 1990 RETVAL = attachable::mortals.size ();
1957 OUTPUT: RETVAL 1991 OUTPUT: RETVAL
1958 1992
1959const_utf8_string slot_use_name (U32 slot) 1993const_utf8_string slot_name (U32 slot)
1960 ALIAS: 1994 ALIAS:
1995 slot_name = 0
1996 slot_use_name = 1
1961 slot_nonuse_name = 1 1997 slot_nonuse_name = 2
1962 CODE: 1998 CODE:
1963{ 1999{
1964 if (slot >= NUM_BODY_LOCATIONS) 2000 if (slot >= NUM_BODY_LOCATIONS)
1965 croak ("body slot index out of range"); 2001 croak ("body slot index out of range");
1966 2002
1967 switch (ix) 2003 switch (ix)
1968 { 2004 {
2005 case 0: RETVAL = body_locations[slot].name ; break;
1969 case 0: RETVAL = body_locations[slot].use_name; break; 2006 case 1: RETVAL = body_locations[slot].use_name ; break;
1970 case 1: RETVAL = body_locations[slot].nonuse_name; break; 2007 case 2: RETVAL = body_locations[slot].nonuse_name; break;
1971 } 2008 }
1972} 2009}
1973 OUTPUT: 2010 OUTPUT:
1974 RETVAL 2011 RETVAL
1975 2012
2020 OUTPUT: 2057 OUTPUT:
2021 RETVAL 2058 RETVAL
2022 2059
2023object *find_best_object_match (object *op, utf8_string match) 2060object *find_best_object_match (object *op, utf8_string match)
2024 2061
2025object *find_marked_object (object *op)
2026
2027int need_identify (object *obj);
2028
2029int apply_shop_mat (object *shop_mat, object *op); 2062int apply_shop_mat (object *shop_mat, object *op);
2030 2063
2031int move (object *op, int dir, object *originator = op) 2064int move (object *op, int dir, object *originator = op)
2032 CODE: 2065 CODE:
2033 RETVAL = op->move (dir, originator); 2066 RETVAL = op->move (dir, originator);
2085 2118
2086void pick_up (object *who, object *op) 2119void pick_up (object *who, object *op)
2087 2120
2088void update_object (object *op, int action) 2121void update_object (object *op, int action)
2089 2122
2090void 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)
2091 2124
2092void player_lvl_adj (object *who, object *skill = 0) 2125void player_lvl_adj (object *who, object *skill = 0)
2093 2126
2094int 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)
2095 2128
2158 PROTOTYPE: $$;$ 2191 PROTOTYPE: $$;$
2159 PPCODE: 2192 PPCODE:
2160{ 2193{
2161 rv_vector rv; 2194 rv_vector rv;
2162 2195
2163 PUTBACK;
2164 get_rangevector (ob, other, &rv, flags); 2196 get_rangevector (ob, other, &rv, flags);
2165 SPAGAIN;
2166 2197
2167 EXTEND (SP, 5); 2198 EXTEND (SP, 5);
2168 PUSHs (newSVuv (rv.distance)); 2199 PUSHs (sv_2mortal (newSVuv (rv.distance)));
2169 PUSHs (newSViv (rv.distance_x)); 2200 PUSHs (sv_2mortal (newSViv (rv.distance_x)));
2170 PUSHs (newSViv (rv.distance_y)); 2201 PUSHs (sv_2mortal (newSViv (rv.distance_y)));
2171 PUSHs (newSViv (rv.direction)); 2202 PUSHs (sv_2mortal (newSViv (rv.direction)));
2172 PUSHs (to_sv (rv.part)); 2203 PUSHs (sv_2mortal (to_sv (rv.part)));
2173} 2204}
2174 2205
2175bool on_same_map_as (object *ob, object *other) 2206bool on_same_map_as (object *ob, object *other)
2176 CODE: 2207 CODE:
2177 RETVAL = on_same_map (ob, other); 2208 RETVAL = on_same_map (ob, other);
2462 if (oblinkpt *obp = map->find_link (connection)) 2493 if (oblinkpt *obp = map->find_link (connection))
2463 for (objectlink *ol = obp->link; ol; ol = ol->next) 2494 for (objectlink *ol = obp->link; ol; ol = ol->next)
2464 XPUSHs (sv_2mortal (to_sv ((object *)ol->ob))); 2495 XPUSHs (sv_2mortal (to_sv ((object *)ol->ob)));
2465 2496
2466void 2497void
2467get_map_flags (maptile *map, int x, int y) 2498xy_normalise (maptile *map, int x, int y, int dir = 0)
2468 PPCODE: 2499 PPCODE:
2469{ 2500{
2470 maptile *nmap = 0; 2501 mapxy pos (map, x, y);
2471 I16 nx = 0, ny = 0; 2502 if (!pos.move (dir).normalise ())
2503 XSRETURN_EMPTY;
2472 2504
2473 PUTBACK;
2474 int flags = get_map_flags (map, &nmap, x, y, &nx, &ny);
2475 SPAGAIN;
2476
2477 EXTEND (SP, 4); 2505 EXTEND (SP, 3);
2478 PUSHs (sv_2mortal (newSViv (flags)));
2479
2480 if (GIMME_V == G_ARRAY)
2481 {
2482 PUSHs (sv_2mortal (to_sv (nmap))); 2506 PUSHs (sv_2mortal (to_sv (pos.m)));
2483 PUSHs (sv_2mortal (newSViv (nx))); 2507 PUSHs (sv_2mortal (to_sv (pos.x)));
2484 PUSHs (sv_2mortal (newSViv (ny))); 2508 PUSHs (sv_2mortal (to_sv (pos.y)));
2485 }
2486} 2509}
2487 2510
2488mapspace * 2511mapspace *
2489ms (maptile *map, unsigned int x, unsigned int y) 2512ms (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2490 PROTOTYPE: $$$ 2513 PROTOTYPE: $$$;$
2491 CODE: 2514 CODE:
2492{ 2515{
2493 maptile *nmap = 0; 2516 mapxy pos (map, x, y);
2494 I16 nx, ny; 2517 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; 2518 XSRETURN_UNDEF;
2502 2519
2503 RETVAL = &nmap->at (nx, ny); 2520 RETVAL = &*pos;
2504} 2521}
2505 OUTPUT: 2522 OUTPUT:
2506 RETVAL 2523 RETVAL
2507 2524
2508void 2525void
2509at (maptile *map, unsigned int x, unsigned int y) 2526at (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2510 PROTOTYPE: $$$ 2527 PROTOTYPE: $$$;$
2511 PPCODE: 2528 PPCODE:
2512{ 2529 mapxy pos (map, x, y);
2513 maptile *nmap = 0; 2530 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) 2531 for (object *o = pos->bot; o; o = o->above)
2522 XPUSHs (sv_2mortal (to_sv (o))); 2532 XPUSHs (sv_2mortal (to_sv (o)));
2523}
2524 2533
2525SV * 2534SV *
2526bot_at (maptile *map, unsigned int x, unsigned int y) 2535bot_at (maptile *map, unsigned int x, unsigned int y, int dir = 0)
2527 PROTOTYPE: $$$ 2536 PROTOTYPE: $$$;$
2528 ALIAS: 2537 ALIAS:
2529 top_at = 1 2538 top_at = 1
2530 flags_at = 2 2539 flags_at = 2
2531 light_at = 3 2540 light_at = 3
2532 move_block_at = 4 2541 move_block_at = 4
2533 move_slow_at = 5 2542 move_slow_at = 5
2534 move_on_at = 6 2543 move_on_at = 6
2535 move_off_at = 7 2544 move_off_at = 7
2536 CODE: 2545 CODE:
2537{ 2546{
2538 sint16 nx = x; 2547 mapxy pos (map, x, y);
2539 sint16 ny = y; 2548 if (!pos.move (dir).normalise ())
2540
2541 if (!xy_normalise (map, nx, ny))
2542 XSRETURN_UNDEF; 2549 XSRETURN_UNDEF;
2543 2550
2544 mapspace &ms = map->at (nx, ny); 2551 mapspace &ms = *pos;
2545 2552
2546 ms.update (); 2553 ms.update ();
2547 2554
2548 switch (ix) 2555 switch (ix)
2549 { 2556 {
2559} 2566}
2560 OUTPUT: RETVAL 2567 OUTPUT: RETVAL
2561 2568
2562# worst xs function of my life 2569# worst xs function of my life
2563bool 2570bool
2564_create_random_map (\ 2571_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: 2572 CODE:
2605{ 2573{
2606 random_map_params rmp; 2574 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); 2575 RETVAL = self->generate_random_map (&rmp);
2648} 2576}
2649 OUTPUT: 2577 OUTPUT:
2650 RETVAL 2578 RETVAL
2651 2579
2682void 2610void
2683list () 2611list ()
2684 PPCODE: 2612 PPCODE:
2685 for_all_regions (rgn) 2613 for_all_regions (rgn)
2686 XPUSHs (sv_2mortal (to_sv (rgn))); 2614 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 2615
2694int specificity (region *rgn) 2616int specificity (region *rgn)
2695 CODE: 2617 CODE:
2696 RETVAL = 0; 2618 RETVAL = 0;
2697 while (rgn = rgn->parent) 2619 while (rgn = rgn->parent)
2801 while (!RETVAL); // crude way to leave index 0 2723 while (!RETVAL); // crude way to leave index 0
2802 2724
2803 faces [RETVAL].name = name; 2725 faces [RETVAL].name = name;
2804 facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL)); 2726 facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL));
2805 2727
2806 if (!strcmp (name, BLANK_FACE_NAME)) blank_face = RETVAL; 2728 if (!strcmp (name, BLANK_FACE_NAME )) blank_face = RETVAL;
2807 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;
2808} 2731}
2809 OUTPUT: RETVAL 2732 OUTPUT: RETVAL
2810 2733
2811void set_type (faceidx idx, int value) 2734void set_type (faceidx idx, int value)
2812 ALIAS: 2735 ALIAS:
2828 2751
2829void set_data (faceidx idx, int faceset, SV *data, SV *chksum) 2752void set_data (faceidx idx, int faceset, SV *data, SV *chksum)
2830 CODE: 2753 CODE:
2831{ 2754{
2832 faceinfo *f = face_info (idx); assert (f); 2755 faceinfo *f = face_info (idx); assert (f);
2833 facedata *d = &(faceset ? f->data64 : f->data32); 2756 facedata *d = f->face + faceset;
2834 sv_to (data, d->data); 2757 sv_to (data, d->data);
2835 STRLEN clen; 2758 STRLEN clen;
2836 char *cdata = SvPVbyte (chksum, clen); 2759 char *cdata = SvPVbyte (chksum, clen);
2837 clen = min (CHKSUM_MAXLEN, clen); 2760 clen = min (CHKSUM_MAXLEN, clen);
2838 2761
2946 sv_to (sv, self); 2869 sv_to (sv, self);
2947 delete self; 2870 delete self;
2948 2871
2949MODULE = cf PACKAGE = cf::object::thawer 2872MODULE = cf PACKAGE = cf::object::thawer
2950 2873
2951INCLUDE: $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
2952 2883
2953SV * 2884SV *
2954new_from_file (char *klass, octet_string path) 2885new_from_file (char *klass, octet_string path)
2955 CODE: 2886 CODE:
2956 object_thawer *f = new object_thawer (path); 2887 object_thawer *f = new object_thawer (path);
2982 XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ()))); 2913 XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ())));
2983 2914
2984 self->skip (); 2915 self->skip ();
2985 } 2916 }
2986 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