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.235 by root, Sun Jul 22 15:05:33 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
949} 964}
950 965
951SV * 966SV *
952cfperl_result (int idx) 967cfperl_result (int idx)
953{ 968{
954 AV *av = get_av ("cfperl::invoke_results", 0); 969 AV *av = get_av ("cf::INVOKE_RESULTS", 0);
955 if (!av) 970 if (!av)
956 return &PL_sv_undef; 971 return &PL_sv_undef;
957 972
958 SV **sv = av_fetch (av, idx, 0); 973 SV **sv = av_fetch (av, idx, 0);
959 if (!sv) 974 if (!sv)
1006void 1021void
1007cfperl_send_msg (client *ns, int color, const char *type, const char *msg) 1022cfperl_send_msg (client *ns, int color, const char *type, const char *msg)
1008{ 1023{
1009 CALL_BEGIN (4); 1024 CALL_BEGIN (4);
1010 CALL_ARG (ns); 1025 CALL_ARG (ns);
1011 CALL_ARG (color);
1012 CALL_ARG (type); 1026 CALL_ARG (type);
1013 CALL_ARG_SV (newSVpv_utf8 (msg)); 1027 CALL_ARG_SV (newSVpv_utf8 (msg));
1028 CALL_ARG (color);
1014 CALL_CALL ("cf::client::send_msg", G_VOID); 1029 CALL_CALL ("cf::client::send_msg", G_VOID);
1015 CALL_END; 1030 CALL_END;
1031}
1032
1033int
1034cfperl_can_merge (object *ob1, object *ob2)
1035{
1036 int can;
1037
1038 CALL_BEGIN (2);
1039 CALL_ARG (ob1);
1040 CALL_ARG (ob2);
1041 CALL_CALL ("cf::_can_merge", G_SCALAR);
1042 can = count && SvTRUE (TOPs);
1043 CALL_END;
1044
1045 return can;
1016} 1046}
1017 1047
1018maptile * 1048maptile *
1019maptile::find_sync (const char *path, maptile *origin) 1049maptile::find_sync (const char *path, maptile *origin)
1020{ 1050{
1994 2024
1995void add_button_link (object *button, maptile *map, int connected); 2025void add_button_link (object *button, maptile *map, int connected);
1996 2026
1997void remove_button_link (object *op); 2027void remove_button_link (object *op);
1998 2028
2029void handle_apply_yield (object *op);
2030
1999 2031
2000MODULE = cf PACKAGE = cf::object PREFIX = cf_ 2032MODULE = cf PACKAGE = cf::object PREFIX = cf_
2001 2033
2002object *cf_insert_ob_in_ob (object *ob, object *where) 2034object *cf_insert_ob_in_ob (object *ob, object *where)
2003 2035
2254 palette = SvRV (palette); 2286 palette = SvRV (palette);
2255 2287
2256 STRLEN idxlen; 2288 STRLEN idxlen;
2257 const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen); 2289 const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen);
2258 2290
2259 region **regionmap = (region **)malloc ( 2291 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 ()); 2292 uint8_t *regions = salloc<uint8_t> (THIS->size ());
2262 2293
2263 for (int i = av_len ((AV *)palette) + 1; i--; ) 2294 for (int i = av_len ((AV *)palette) + 1; i--; )
2264 regionmap [i] = region::find ( 2295 regionmap [i] = region::find (SvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1)));
2265 SvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1)));
2266 2296
2267 for (int y = 0; y < THIS->height; ++y) 2297 for (int y = 0; y < THIS->height; ++y)
2268 memcpy (regions + y * THIS->width, idx + offset + y * stride, THIS->width); 2298 memcpy (regions + y * THIS->width, idx + offset + y * stride, THIS->width);
2269 2299
2270 sfree (THIS->regions, THIS->size ()); 2300 sfree (THIS->regions, THIS->size ());
2271 free (THIS->regionmap); 2301 delete [] THIS->regionmap;
2272 2302
2273 THIS->regions = regions; 2303 THIS->regions = regions;
2274 THIS->regionmap = regionmap; 2304 THIS->regionmap = regionmap;
2275} 2305}
2276 2306
2611 set_visibility = 1 2641 set_visibility = 1
2612 set_magicmap = 2 2642 set_magicmap = 2
2613 set_smooth = 3 2643 set_smooth = 3
2614 set_smoothlevel = 4 2644 set_smoothlevel = 4
2615 CODE: 2645 CODE:
2616 faceinfo *f = face_info (idx); 2646 faceinfo *f = face_info (idx); assert (f);
2617 assert (f);
2618 switch (ix) 2647 switch (ix)
2619 { 2648 {
2620 case 0: f->type = value; break; 2649 case 0: f->type = value; break;
2621 case 1: f->visibility = value; break; 2650 case 1: f->visibility = value; break;
2622 case 2: f->magicmap = value; break; 2651 case 2: f->magicmap = value; break;
2625 } 2654 }
2626 2655
2627void set_data (faceidx idx, int faceset, SV *data, SV *chksum) 2656void set_data (faceidx idx, int faceset, SV *data, SV *chksum)
2628 CODE: 2657 CODE:
2629{ 2658{
2630 facedata *d = face_data (idx, faceset); 2659 faceinfo *f = face_info (idx); assert (f);
2631 assert (d); 2660 facedata *d = &(faceset ? f->data64 : f->data32);
2632 sv_to (data, d->data); 2661 sv_to (data, d->data);
2633 STRLEN clen; 2662 STRLEN clen;
2634 char *cdata = SvPVbyte (chksum, clen); 2663 char *cdata = SvPVbyte (chksum, clen);
2635 clen = min (CHKSUM_SIZE, clen); 2664 clen = min (CHKSUM_SIZE, clen);
2636 2665
2646 ns->force_newmap = true; 2675 ns->force_newmap = true;
2647 } 2676 }
2648 } 2677 }
2649} 2678}
2650 2679
2680int get_data_size (faceidx idx, int faceset = 0)
2681 CODE:
2682 facedata *d = face_data (idx, faceset); assert (d);
2683 RETVAL = d->data.size ();
2684 OUTPUT:
2685 RETVAL
2686
2687SV *get_chksum (faceidx idx, int faceset = 0)
2688 CODE:
2689 facedata *d = face_data (idx, faceset); assert (d);
2690 RETVAL = newSVpvn ((char *)d->chksum, CHKSUM_SIZE);
2691 OUTPUT:
2692 RETVAL
2693
2651void invalidate (faceidx idx) 2694void invalidate (faceidx idx)
2652 CODE: 2695 CODE:
2653 for_all_clients (ns) 2696 for_all_clients (ns)
2654 { 2697 {
2655 ns->faces_sent [idx] = false; 2698 ns->faces_sent [idx] = false;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines