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.335 by root, Wed Nov 11 04:45:23 2009 UTC vs.
Revision 1.339 by root, Thu Nov 26 08:08:40 2009 UTC

210attachable::destroy () 210attachable::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
220void 220void
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
407static long SvPTR_nc (SV *sv)
408{
409 sv = SvRV (sv);
410
411 // very important shortcut
412 if (expect_true (SvMAGIC (sv) && 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
407static long 421static long
408SvPTR (SV *sv, const char *klass) 422SvPTR (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
421static long noinline 430static long noinline
422SvPTR_ornull (SV *sv, const char *klass) 431SvPTR_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
438static long noinline
439SvPTR_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
451static long noinline
452SvPTR_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
466static long noinline
467SvPTR_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 return SvPTR_nc (sv);
428} 477}
429 478
430static inline SV *to_sv (const shstr & v) { return newSVpvn_utf8 ((const char *)v, v.length (), 1); } 479static inline SV *to_sv (const shstr & v) { return newSVpvn_utf8 ((const char *)v, v.length (), 1); }
431static inline SV *to_sv (const char * v) { return v ? newSVpv (v, 0) : newSV (0); } 480static inline SV *to_sv (const char * v) { return v ? newSVpv (v, 0) : newSV (0); }
432static inline SV *to_sv (bool v) { return newSViv (v); } 481static inline SV *to_sv (bool v) { return newSViv (v); }
494static inline void sv_to (SV *sv, unsigned long &v) { v = SvUV (sv); } 543static inline void sv_to (SV *sv, unsigned long &v) { v = SvUV (sv); }
495static inline void sv_to (SV *sv, signed long long &v) { v = ( signed long long)SvVAL64 (sv); } 544static inline void sv_to (SV *sv, signed long long &v) { v = ( signed long long)SvVAL64 (sv); }
496static inline void sv_to (SV *sv, unsigned long long &v) { v = (unsigned long long)SvVAL64 (sv); } 545static inline void sv_to (SV *sv, unsigned long long &v) { v = (unsigned long long)SvVAL64 (sv); }
497static inline void sv_to (SV *sv, float &v) { v = SvNV (sv); } 546static inline void sv_to (SV *sv, float &v) { v = SvNV (sv); }
498static inline void sv_to (SV *sv, double &v) { v = SvNV (sv); } 547static inline void sv_to (SV *sv, double &v) { v = SvNV (sv); }
499static inline void sv_to (SV *sv, client * &v) { v = (client *)(attachable *)SvPTR_ornull (sv, "cf::client"); } 548static inline void sv_to (SV *sv, client * &v) { v = (client *) (attachable *)SvPTR_ornull_client (sv); }
500static inline void sv_to (SV *sv, player * &v) { v = (player *)(attachable *)SvPTR_ornull (sv, "cf::player"); } 549static inline void sv_to (SV *sv, player * &v) { v = (player *) (attachable *)SvPTR_ornull_player (sv); }
501static inline void sv_to (SV *sv, object * &v) { v = (object *)(attachable *)SvPTR_ornull (sv, "cf::object"); } 550static inline void sv_to (SV *sv, object * &v) { v = (object *) (attachable *)SvPTR_ornull_object (sv); }
502static inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)(attachable *)SvPTR_ornull (sv, "cf::arch"); } 551static inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)(attachable *)SvPTR_ornull (sv, "cf::arch"); }
503static inline void sv_to (SV *sv, maptile * &v) { v = (maptile *)(attachable *)SvPTR_ornull (sv, "cf::map"); } 552static inline void sv_to (SV *sv, maptile * &v) { v = (maptile *) (attachable *)SvPTR_ornull (sv, "cf::map"); }
504static inline void sv_to (SV *sv, region * &v) { v = (region *)(attachable *)SvPTR_ornull (sv, "cf::region"); } 553static inline void sv_to (SV *sv, region * &v) { v = (region *) (attachable *)SvPTR_ornull (sv, "cf::region"); }
505static inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } 554static inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); }
506static inline void sv_to (SV *sv, partylist * &v) { v = (partylist *)SvPTR_ornull (sv, "cf::party"); } 555static inline void sv_to (SV *sv, partylist * &v) { v = (partylist *) SvPTR_ornull (sv, "cf::party"); }
507static inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); } 556static inline void sv_to (SV *sv, living * &v) { v = (living *) SvPTR_ornull (sv, "cf::living"); }
508static inline void sv_to (SV *sv, mapspace * &v) { v = (mapspace *)SvPTR_ornull (sv, "cf::mapspace"); } 557static inline void sv_to (SV *sv, mapspace * &v) { v = (mapspace *) SvPTR_ornull (sv, "cf::mapspace"); }
509static inline void sv_to (SV *sv, object_freezer * &v) { v = (object_freezer *)SvPTR_ornull (sv, "cf::object::freezer"); } 558static inline void sv_to (SV *sv, object_freezer * &v) { v = (object_freezer *) SvPTR_ornull (sv, "cf::object::freezer"); }
510static inline void sv_to (SV *sv, object_thawer * &v) { v = (object_thawer *)SvPTR_ornull (sv, "cf::object::thawer" ); } 559static inline void sv_to (SV *sv, object_thawer * &v) { v = (object_thawer *) SvPTR_ornull (sv, "cf::object::thawer" ); }
511 560
512//static inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; } 561//static inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; }
513static inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); } 562static inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); }
514 563
515template<class T> 564template<class T>
2015 RETVAL 2064 RETVAL
2016 2065
2017void 2066void
2018debug_trace (attachable *obj, bool on = true) 2067debug_trace (attachable *obj, bool on = true)
2019 CODE: 2068 CODE:
2020 obj->flags &= ~attachable::F_DEBUG_TRACE; 2069 obj->attachable_flags &= ~attachable::F_DEBUG_TRACE;
2021 if (on) 2070 if (on)
2022 obj->flags |= attachable::F_DEBUG_TRACE; 2071 obj->attachable_flags |= attachable::F_DEBUG_TRACE;
2023 2072
2024int mortals_size () 2073int mortals_size ()
2025 CODE: 2074 CODE:
2026 RETVAL = attachable::mortals.size (); 2075 RETVAL = attachable::mortals.size ();
2027 OUTPUT: RETVAL 2076 OUTPUT: RETVAL
2955 faceinfo *f = face_info (idx); assert (f); 3004 faceinfo *f = face_info (idx); assert (f);
2956 facedata *d = &(faceset ? f->data64 : f->data32); 3005 facedata *d = &(faceset ? f->data64 : f->data32);
2957 sv_to (data, d->data); 3006 sv_to (data, d->data);
2958 STRLEN clen; 3007 STRLEN clen;
2959 char *cdata = SvPVbyte (chksum, clen); 3008 char *cdata = SvPVbyte (chksum, clen);
2960 clen = min (CHKSUM_SIZE, clen); 3009 clen = min (CHKSUM_MAXLEN, clen);
2961 3010
2962 if (memcmp (d->chksum, cdata, clen)) 3011 if (clen != d->chksum_len || memcmp (d->chksum, cdata, clen))
2963 { 3012 {
3013 d->chksum_len = clen;
2964 memcpy (d->chksum, cdata, clen); 3014 memcpy (d->chksum, cdata, clen);
2965 3015
2966 // invalidate existing client face info 3016 // invalidate existing client face info
2967 for_all_clients (ns) 3017 for_all_clients (ns)
2968 if (ns->faceset == faceset) 3018 if (ns->faceset == faceset)
2983 3033
2984SV *get_chksum (faceidx idx, int faceset = 0) 3034SV *get_chksum (faceidx idx, int faceset = 0)
2985 CODE: 3035 CODE:
2986 facedata *d = face_data (idx, faceset); 3036 facedata *d = face_data (idx, faceset);
2987 if (!d) XSRETURN_UNDEF; 3037 if (!d) XSRETURN_UNDEF;
2988 RETVAL = newSVpvn ((char *)d->chksum, CHKSUM_SIZE); 3038 RETVAL = newSVpvn ((char *)d->chksum, d->chksum_len);
2989 OUTPUT: 3039 OUTPUT:
2990 RETVAL 3040 RETVAL
2991 3041
2992SV *get_data (faceidx idx, int faceset = 0) 3042SV *get_data (faceidx idx, int faceset = 0)
2993 CODE: 3043 CODE:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines