… | |
… | |
210 | attachable::destroy () |
210 | attachable::destroy () |
211 | { |
211 | { |
212 | if (destroyed ()) |
212 | if (destroyed ()) |
213 | return; |
213 | return; |
214 | |
214 | |
215 | flags |= F_DESTROYED; |
215 | attachable_flags |= F_DESTROYED; |
216 | do_destroy (); |
216 | do_destroy (); |
217 | sever_self (); |
217 | sever_self (); |
218 | } |
218 | } |
219 | |
219 | |
220 | void |
220 | void |
… | |
… | |
402 | hv_clear ((HV *)sv); |
402 | hv_clear ((HV *)sv); |
403 | sv_unmagic (sv, PERL_MAGIC_ext); |
403 | sv_unmagic (sv, PERL_MAGIC_ext); |
404 | } |
404 | } |
405 | #endif |
405 | #endif |
406 | |
406 | |
|
|
407 | static long SvPTR_nc (SV *sv) |
|
|
408 | { |
|
|
409 | sv = SvRV (sv); |
|
|
410 | |
|
|
411 | // very important shortcut |
|
|
412 | if (expect_true (SvMAGIC (sv)->mg_type == PERL_MAGIC_ext)) |
|
|
413 | return (long)SvMAGIC (sv)->mg_ptr; |
|
|
414 | |
|
|
415 | if (MAGIC *mg = mg_find (sv, PERL_MAGIC_ext)) |
|
|
416 | return (long)mg->mg_ptr; |
|
|
417 | |
|
|
418 | croak ("perl code used object, but C object is already destroyed, caught"); |
|
|
419 | } |
|
|
420 | |
407 | static long |
421 | static long |
408 | SvPTR (SV *sv, const char *klass) |
422 | SvPTR (SV *sv, const char *klass) |
409 | { |
423 | { |
410 | if (!sv_derived_from (sv, klass)) |
424 | if (!sv_derived_from (sv, klass)) |
411 | croak ("object of type %s expected", klass); |
425 | croak ("object of type %s expected", klass); |
412 | |
426 | |
413 | MAGIC *mg = mg_find (SvRV (sv), PERL_MAGIC_ext); |
427 | return SvPTR_nc (sv); |
414 | |
|
|
415 | if (!mg) |
|
|
416 | croak ("perl code used %s object, but C object is already destroyed, caught", klass); |
|
|
417 | |
|
|
418 | return (long)mg->mg_ptr; |
|
|
419 | } |
428 | } |
420 | |
429 | |
421 | static long noinline |
430 | static long noinline |
422 | SvPTR_ornull (SV *sv, const char *klass) |
431 | SvPTR_ornull (SV *sv, const char *klass) |
423 | { |
432 | { |
424 | if (SvOK (sv)) |
433 | if (expect_false (!SvOK (sv))) return 0; |
|
|
434 | |
425 | return SvPTR (sv, klass); |
435 | return SvPTR (sv, klass); |
426 | else |
436 | } |
427 | return 0; |
437 | |
|
|
438 | static long noinline |
|
|
439 | SvPTR_ornull_client (SV *sv) |
|
|
440 | { |
|
|
441 | if (expect_false (!SvOK (sv))) return 0; |
|
|
442 | |
|
|
443 | if (!SvROK (sv) |
|
|
444 | || (SvSTASH (SvRV (sv)) != stash_cf_client_wrap |
|
|
445 | && !sv_derived_from (sv, "cf::client"))) |
|
|
446 | croak ("object of type cf::client expected"); |
|
|
447 | |
|
|
448 | return SvPTR_nc (sv); |
|
|
449 | } |
|
|
450 | |
|
|
451 | static long noinline |
|
|
452 | SvPTR_ornull_object (SV *sv) |
|
|
453 | { |
|
|
454 | if (expect_false (!SvOK (sv))) return 0; |
|
|
455 | |
|
|
456 | if (!SvROK (sv) |
|
|
457 | || (SvSTASH (SvRV (sv)) != stash_cf_object_wrap |
|
|
458 | && SvSTASH (SvRV (sv)) != stash_cf_object_player_wrap |
|
|
459 | && SvSTASH (SvRV (sv)) != stash_cf_arch_wrap |
|
|
460 | && !sv_derived_from (sv, "cf::object"))) |
|
|
461 | croak ("object of type cf::object expected"); |
|
|
462 | |
|
|
463 | return SvPTR_nc (sv); |
|
|
464 | } |
|
|
465 | |
|
|
466 | static long noinline |
|
|
467 | SvPTR_ornull_player (SV *sv) |
|
|
468 | { |
|
|
469 | if (expect_false (!SvOK (sv))) return 0; |
|
|
470 | |
|
|
471 | if (!SvROK (sv) |
|
|
472 | || (SvSTASH (SvRV (sv)) != stash_cf_player_wrap |
|
|
473 | && !sv_derived_from (sv, "cf::player"))) |
|
|
474 | croak ("object of type cf::player expected"); |
|
|
475 | |
|
|
476 | if (SvSTASH (SvRV (sv)) != stash_cf_player_wrap) |
|
|
477 | printf ("unexpected stash %s:%s\n", HvNAME(SvSTASH(SvRV(sv))));//D |
|
|
478 | |
|
|
479 | |
|
|
480 | return SvPTR_nc (sv); |
428 | } |
481 | } |
429 | |
482 | |
430 | static inline SV *to_sv (const shstr & v) { return newSVpvn_utf8 ((const char *)v, v.length (), 1); } |
483 | static inline SV *to_sv (const shstr & v) { return newSVpvn_utf8 ((const char *)v, v.length (), 1); } |
431 | static inline SV *to_sv (const char * v) { return v ? newSVpv (v, 0) : newSV (0); } |
484 | static inline SV *to_sv (const char * v) { return v ? newSVpv (v, 0) : newSV (0); } |
432 | static inline SV *to_sv (bool v) { return newSViv (v); } |
485 | static inline SV *to_sv (bool v) { return newSViv (v); } |
… | |
… | |
494 | static inline void sv_to (SV *sv, unsigned long &v) { v = SvUV (sv); } |
547 | static inline void sv_to (SV *sv, unsigned long &v) { v = SvUV (sv); } |
495 | static inline void sv_to (SV *sv, signed long long &v) { v = ( signed long long)SvVAL64 (sv); } |
548 | static inline void sv_to (SV *sv, signed long long &v) { v = ( signed long long)SvVAL64 (sv); } |
496 | static inline void sv_to (SV *sv, unsigned long long &v) { v = (unsigned long long)SvVAL64 (sv); } |
549 | static inline void sv_to (SV *sv, unsigned long long &v) { v = (unsigned long long)SvVAL64 (sv); } |
497 | static inline void sv_to (SV *sv, float &v) { v = SvNV (sv); } |
550 | static inline void sv_to (SV *sv, float &v) { v = SvNV (sv); } |
498 | static inline void sv_to (SV *sv, double &v) { v = SvNV (sv); } |
551 | static inline void sv_to (SV *sv, double &v) { v = SvNV (sv); } |
499 | static inline void sv_to (SV *sv, client * &v) { v = (client *)(attachable *)SvPTR_ornull (sv, "cf::client"); } |
552 | static inline void sv_to (SV *sv, client * &v) { v = (client *) (attachable *)SvPTR_ornull_client (sv); } |
500 | static inline void sv_to (SV *sv, player * &v) { v = (player *)(attachable *)SvPTR_ornull (sv, "cf::player"); } |
553 | static inline void sv_to (SV *sv, player * &v) { v = (player *) (attachable *)SvPTR_ornull_player (sv); } |
501 | static inline void sv_to (SV *sv, object * &v) { v = (object *)(attachable *)SvPTR_ornull (sv, "cf::object"); } |
554 | static inline void sv_to (SV *sv, object * &v) { v = (object *) (attachable *)SvPTR_ornull_object (sv); } |
502 | static inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)(attachable *)SvPTR_ornull (sv, "cf::arch"); } |
555 | static inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)(attachable *)SvPTR_ornull (sv, "cf::arch"); } |
503 | static inline void sv_to (SV *sv, maptile * &v) { v = (maptile *)(attachable *)SvPTR_ornull (sv, "cf::map"); } |
556 | static inline void sv_to (SV *sv, maptile * &v) { v = (maptile *) (attachable *)SvPTR_ornull (sv, "cf::map"); } |
504 | static inline void sv_to (SV *sv, region * &v) { v = (region *)(attachable *)SvPTR_ornull (sv, "cf::region"); } |
557 | static inline void sv_to (SV *sv, region * &v) { v = (region *) (attachable *)SvPTR_ornull (sv, "cf::region"); } |
505 | static inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } |
558 | static inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } |
506 | static inline void sv_to (SV *sv, partylist * &v) { v = (partylist *)SvPTR_ornull (sv, "cf::party"); } |
559 | static inline void sv_to (SV *sv, partylist * &v) { v = (partylist *) SvPTR_ornull (sv, "cf::party"); } |
507 | static inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); } |
560 | static inline void sv_to (SV *sv, living * &v) { v = (living *) SvPTR_ornull (sv, "cf::living"); } |
508 | static inline void sv_to (SV *sv, mapspace * &v) { v = (mapspace *)SvPTR_ornull (sv, "cf::mapspace"); } |
561 | static inline void sv_to (SV *sv, mapspace * &v) { v = (mapspace *) SvPTR_ornull (sv, "cf::mapspace"); } |
509 | static inline void sv_to (SV *sv, object_freezer * &v) { v = (object_freezer *)SvPTR_ornull (sv, "cf::object::freezer"); } |
562 | static inline void sv_to (SV *sv, object_freezer * &v) { v = (object_freezer *) SvPTR_ornull (sv, "cf::object::freezer"); } |
510 | static inline void sv_to (SV *sv, object_thawer * &v) { v = (object_thawer *)SvPTR_ornull (sv, "cf::object::thawer" ); } |
563 | static inline void sv_to (SV *sv, object_thawer * &v) { v = (object_thawer *) SvPTR_ornull (sv, "cf::object::thawer" ); } |
511 | |
564 | |
512 | //static inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; } |
565 | //static inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; } |
513 | static inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); } |
566 | static inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); } |
514 | |
567 | |
515 | template<class T> |
568 | template<class T> |
… | |
… | |
2015 | RETVAL |
2068 | RETVAL |
2016 | |
2069 | |
2017 | void |
2070 | void |
2018 | debug_trace (attachable *obj, bool on = true) |
2071 | debug_trace (attachable *obj, bool on = true) |
2019 | CODE: |
2072 | CODE: |
2020 | obj->flags &= ~attachable::F_DEBUG_TRACE; |
2073 | obj->attachable_flags &= ~attachable::F_DEBUG_TRACE; |
2021 | if (on) |
2074 | if (on) |
2022 | obj->flags |= attachable::F_DEBUG_TRACE; |
2075 | obj->attachable_flags |= attachable::F_DEBUG_TRACE; |
2023 | |
2076 | |
2024 | int mortals_size () |
2077 | int mortals_size () |
2025 | CODE: |
2078 | CODE: |
2026 | RETVAL = attachable::mortals.size (); |
2079 | RETVAL = attachable::mortals.size (); |
2027 | OUTPUT: RETVAL |
2080 | OUTPUT: RETVAL |