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.227 by root, Tue Jul 10 16:24:00 2007 UTC vs.
Revision 1.231 by root, Mon Jul 16 14:26:30 2007 UTC

246 delete obj; 246 delete obj;
247 } 247 }
248 } 248 }
249} 249}
250 250
251void
252attachable::set_key (const char *key, const char *value)
253{
254 if (!self)
255 self = newHV ();
256
257 if (value)
258 hv_store (self, key, strlen (key), newSVpv (value, 0), 0);
259 else
260 hv_delete (self, key, strlen (key), G_DISCARD);
261}
262
251attachable & 263attachable &
252attachable::operator =(const attachable &src) 264attachable::operator =(const attachable &src)
253{ 265{
254 //if (self || cb) 266 //if (self || cb)
255 //INVOKE_OBJECT (CLONE, this, ARG_OBJECT (dst)); 267 //INVOKE_OBJECT (CLONE, this, ARG_OBJECT (dst));
330{ 342{
331 if (!obj) 343 if (!obj)
332 return &PL_sv_undef; 344 return &PL_sv_undef;
333 345
334 if (!obj->self) 346 if (!obj->self)
347 obj->self = newHV ();
348
349 if (!SvOBJECT (obj->self))
335 { 350 {
336 obj->self = newHV ();
337 sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &attachable::vtbl, (char *)obj, 0); 351 sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &attachable::vtbl, (char *)obj, 0);
338 352
339 // now bless the object _once_ 353 // now bless the object _once_
354 //TODO: create a class registry with c++ type<=>perl name<=>stash and use it here and elsewhere
340 return sv_bless (newRV_inc ((SV *)obj->self), stash); 355 return sv_bless (newRV_inc ((SV *)obj->self), stash);
341 } 356 }
342 else 357 else
343 { 358 {
344 SV *sv = newRV_inc ((SV *)obj->self); 359 SV *sv = newRV_inc ((SV *)obj->self);
417inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); } 432inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); }
418inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); } 433inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); }
419inline SV *to_sv (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); } 434inline SV *to_sv (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); }
420inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); } 435inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); }
421inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); } 436inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); }
437inline SV *to_sv (region * v) { return newSVattachable (v, stash_cf_region_wrap); }
422inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); } 438inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); }
423inline SV *to_sv (region * v) { return newSVptr (v, stash_cf_region_wrap); }
424inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } 439inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); }
425 440
426inline SV *to_sv (object & v) { return to_sv (&v); } 441inline SV *to_sv (object & v) { return to_sv (&v); }
427inline SV *to_sv (living & v) { return to_sv (&v); } 442inline SV *to_sv (living & v) { return to_sv (&v); }
428 443
454inline void sv_to (SV *sv, client * &v) { v = (client *)(attachable *)SvPTR_ornull (sv, "cf::client"); } 469inline void sv_to (SV *sv, client * &v) { v = (client *)(attachable *)SvPTR_ornull (sv, "cf::client"); }
455inline void sv_to (SV *sv, player * &v) { v = (player *)(attachable *)SvPTR_ornull (sv, "cf::player"); } 470inline void sv_to (SV *sv, player * &v) { v = (player *)(attachable *)SvPTR_ornull (sv, "cf::player"); }
456inline void sv_to (SV *sv, object * &v) { v = (object *)(attachable *)SvPTR_ornull (sv, "cf::object"); } 471inline void sv_to (SV *sv, object * &v) { v = (object *)(attachable *)SvPTR_ornull (sv, "cf::object"); }
457inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)(attachable *)SvPTR_ornull (sv, "cf::arch"); } 472inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)(attachable *)SvPTR_ornull (sv, "cf::arch"); }
458inline void sv_to (SV *sv, maptile * &v) { v = (maptile *)(attachable *)SvPTR_ornull (sv, "cf::map"); } 473inline void sv_to (SV *sv, maptile * &v) { v = (maptile *)(attachable *)SvPTR_ornull (sv, "cf::map"); }
474inline void sv_to (SV *sv, region * &v) { v = (region *)(attachable *)SvPTR_ornull (sv, "cf::region"); }
459inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } 475inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); }
460inline void sv_to (SV *sv, partylist * &v) { v = (partylist *)SvPTR_ornull (sv, "cf::party"); } 476inline void sv_to (SV *sv, partylist * &v) { v = (partylist *)SvPTR_ornull (sv, "cf::party"); }
461inline void sv_to (SV *sv, region * &v) { v = (region *)SvPTR_ornull (sv, "cf::region"); }
462inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); } 477inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); }
463 478
464//inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; } 479//inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; }
465inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); } 480inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); }
466 481
2254 palette = SvRV (palette); 2269 palette = SvRV (palette);
2255 2270
2256 STRLEN idxlen; 2271 STRLEN idxlen;
2257 const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen); 2272 const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen);
2258 2273
2259 region **regionmap = (region **)malloc ( 2274 region_ptr *regionmap = new region_ptr [av_len ((AV *)palette) + 1];
2260 (av_len ((AV *)palette) + 1) * sizeof (region *));
2261 uint8_t *regions = salloc<uint8_t> (THIS->size ()); 2275 uint8_t *regions = salloc<uint8_t> (THIS->size ());
2262 2276
2263 for (int i = av_len ((AV *)palette) + 1; i--; ) 2277 for (int i = av_len ((AV *)palette) + 1; i--; )
2264 regionmap [i] = region::find ( 2278 regionmap [i] = region::find (SvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1)));
2265 SvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1)));
2266 2279
2267 for (int y = 0; y < THIS->height; ++y) 2280 for (int y = 0; y < THIS->height; ++y)
2268 memcpy (regions + y * THIS->width, idx + offset + y * stride, THIS->width); 2281 memcpy (regions + y * THIS->width, idx + offset + y * stride, THIS->width);
2269 2282
2270 sfree (THIS->regions, THIS->size ()); 2283 sfree (THIS->regions, THIS->size ());
2271 free (THIS->regionmap); 2284 delete [] THIS->regionmap;
2272 2285
2273 THIS->regions = regions; 2286 THIS->regions = regions;
2274 THIS->regionmap = regionmap; 2287 THIS->regionmap = regionmap;
2275} 2288}
2276 2289
2611 set_visibility = 1 2624 set_visibility = 1
2612 set_magicmap = 2 2625 set_magicmap = 2
2613 set_smooth = 3 2626 set_smooth = 3
2614 set_smoothlevel = 4 2627 set_smoothlevel = 4
2615 CODE: 2628 CODE:
2616 faceinfo *f = face_info (idx); 2629 faceinfo *f = face_info (idx); assert (f);
2617 assert (f);
2618 switch (ix) 2630 switch (ix)
2619 { 2631 {
2620 case 0: f->type = value; break; 2632 case 0: f->type = value; break;
2621 case 1: f->visibility = value; break; 2633 case 1: f->visibility = value; break;
2622 case 2: f->magicmap = value; break; 2634 case 2: f->magicmap = value; break;
2625 } 2637 }
2626 2638
2627void set_data (faceidx idx, int faceset, SV *data, SV *chksum) 2639void set_data (faceidx idx, int faceset, SV *data, SV *chksum)
2628 CODE: 2640 CODE:
2629{ 2641{
2630 facedata *d = face_data (idx, faceset); 2642 faceinfo *f = face_info (idx); assert (f);
2631 assert (d); 2643 facedata *d = &(faceset ? f->data64 : f->data32);
2632 sv_to (data, d->data); 2644 sv_to (data, d->data);
2633 STRLEN clen; 2645 STRLEN clen;
2634 char *cdata = SvPVbyte (chksum, clen); 2646 char *cdata = SvPVbyte (chksum, clen);
2635 clen = min (CHKSUM_SIZE, clen); 2647 clen = min (CHKSUM_SIZE, clen);
2636 2648
2646 ns->force_newmap = true; 2658 ns->force_newmap = true;
2647 } 2659 }
2648 } 2660 }
2649} 2661}
2650 2662
2663int get_data_size (faceidx idx, int faceset = 0)
2664 CODE:
2665 facedata *d = face_data (idx, faceset); assert (d);
2666 RETVAL = d->data.size ();
2667 OUTPUT:
2668 RETVAL
2669
2670SV *get_chksum (faceidx idx, int faceset = 0)
2671 CODE:
2672 facedata *d = face_data (idx, faceset); assert (d);
2673 RETVAL = newSVpvn ((char *)d->chksum, CHKSUM_SIZE);
2674 OUTPUT:
2675 RETVAL
2676
2651void invalidate (faceidx idx) 2677void invalidate (faceidx idx)
2652 CODE: 2678 CODE:
2653 for_all_clients (ns) 2679 for_all_clients (ns)
2654 { 2680 {
2655 ns->faces_sent [idx] = false; 2681 ns->faces_sent [idx] = false;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines