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.226 by root, Sun Jul 1 05:00:19 2007 UTC vs.
Revision 1.237 by root, Mon Jul 23 23:46:03 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{
1534 1564
1535 for_all_objects (op) 1565 for_all_objects (op)
1536 op->reattach (); 1566 op->reattach ();
1537} 1567}
1538 1568
1539void _post_tick ()
1540 CODE:
1541 coroapi::next_cede = SvNV (sv_next_tick) - TICK * (1. - 1. / CEDES_PER_TICK);
1542
1543# support function for map-world.ext 1569# support function for map-world.ext
1544void _quantise (SV *data_sv, SV *plt_sv) 1570void _quantise (SV *data_sv, SV *plt_sv)
1545 CODE: 1571 CODE:
1546{ 1572{
1547 if (!SvROK (plt_sv) || SvTYPE (SvRV (plt_sv)) != SVt_PVAV) 1573 if (!SvROK (plt_sv) || SvTYPE (SvRV (plt_sv)) != SVt_PVAV)
1579 len -= 3; 1605 len -= 3;
1580 } 1606 }
1581 1607
1582 SvCUR_set (data_sv, dst - SvPVX (data_sv)); 1608 SvCUR_set (data_sv, dst - SvPVX (data_sv));
1583} 1609}
1610
1611void _post_tick ()
1612 CODE:
1613 coroapi::next_cede = SvNV (sv_next_tick) - TICK * (1. - 1. / CEDES_PER_TICK);
1614
1615NV till_cede ()
1616 CODE:
1617 RETVAL = coroapi::next_cede - now ();
1618 OUTPUT:
1619 RETVAL
1620
1621NV till_tick ()
1622 CODE:
1623 RETVAL = SvNV (sv_next_tick) - now ();
1624 OUTPUT:
1625 RETVAL
1584 1626
1585NV floor (NV x) 1627NV floor (NV x)
1586 1628
1587NV ceil (NV x) 1629NV ceil (NV x)
1588 1630
1994 2036
1995void add_button_link (object *button, maptile *map, int connected); 2037void add_button_link (object *button, maptile *map, int connected);
1996 2038
1997void remove_button_link (object *op); 2039void remove_button_link (object *op);
1998 2040
2041void handle_apply_yield (object *op);
2042
1999 2043
2000MODULE = cf PACKAGE = cf::object PREFIX = cf_ 2044MODULE = cf PACKAGE = cf::object PREFIX = cf_
2001 2045
2002object *cf_insert_ob_in_ob (object *ob, object *where) 2046object *cf_insert_ob_in_ob (object *ob, object *where)
2003 2047
2254 palette = SvRV (palette); 2298 palette = SvRV (palette);
2255 2299
2256 STRLEN idxlen; 2300 STRLEN idxlen;
2257 const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen); 2301 const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen);
2258 2302
2259 region **regionmap = (region **)malloc ( 2303 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 ()); 2304 uint8_t *regions = salloc<uint8_t> (THIS->size ());
2262 2305
2263 for (int i = av_len ((AV *)palette) + 1; i--; ) 2306 for (int i = av_len ((AV *)palette) + 1; i--; )
2264 regionmap [i] = region::find ( 2307 regionmap [i] = region::find (SvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1)));
2265 SvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1)));
2266 2308
2267 for (int y = 0; y < THIS->height; ++y) 2309 for (int y = 0; y < THIS->height; ++y)
2268 memcpy (regions + y * THIS->width, idx + offset + y * stride, THIS->width); 2310 memcpy (regions + y * THIS->width, idx + offset + y * stride, THIS->width);
2269 2311
2270 sfree (THIS->regions, THIS->size ()); 2312 sfree (THIS->regions, THIS->size ());
2271 free (THIS->regionmap); 2313 delete [] THIS->regionmap;
2272 2314
2273 THIS->regions = regions; 2315 THIS->regions = regions;
2274 THIS->regionmap = regionmap; 2316 THIS->regionmap = regionmap;
2275} 2317}
2276 2318
2579 char *buf = SvPVbyte (packet, len); 2621 char *buf = SvPVbyte (packet, len);
2580 2622
2581 THIS->send_packet (buf, len); 2623 THIS->send_packet (buf, len);
2582} 2624}
2583 2625
2626faceidx
2627client::find_face (utf8_string name, faceidx defidx = 0)
2628 CODE:
2629 RETVAL = face_find (name, defidx);
2630 THIS->send_face (RETVAL);
2631 THIS->flush_fx ();
2632 OUTPUT:
2633 RETVAL
2634
2584MODULE = cf PACKAGE = cf::face PREFIX = face_ 2635MODULE = cf PACKAGE = cf::face PREFIX = face_
2585 2636
2586#INCLUDE: $PERL $srcdir/genacc faceset ../include/face.h | 2637#INCLUDE: $PERL $srcdir/genacc faceset ../include/face.h |
2587 2638
2588faceidx face_find (utf8_string name, faceidx defidx = 0) 2639faceidx face_find (utf8_string name, faceidx defidx = 0)
2603 if (!strcmp (name, BLANK_FACE_NAME)) blank_face = RETVAL; 2654 if (!strcmp (name, BLANK_FACE_NAME)) blank_face = RETVAL;
2604 if (!strcmp (name, EMPTY_FACE_NAME)) empty_face = RETVAL; 2655 if (!strcmp (name, EMPTY_FACE_NAME)) empty_face = RETVAL;
2605} 2656}
2606 OUTPUT: RETVAL 2657 OUTPUT: RETVAL
2607 2658
2608void set (faceidx idx, int visibility, int magicmap) 2659void set_type (faceidx idx, int value)
2609 CODE: 2660 ALIAS:
2610 faceinfo *f = face_info (idx); 2661 set_type = 0
2611 assert (f); 2662 set_visibility = 1
2612 f->visibility = visibility; 2663 set_magicmap = 2
2613 f->magicmap = magicmap; 2664 set_smooth = 3
2614 2665 set_smoothlevel = 4
2615void set_smooth (faceidx idx, faceidx smooth, int smoothlevel)
2616 CODE: 2666 CODE:
2617 faceinfo *f = face_info (idx); assert (f); 2667 faceinfo *f = face_info (idx); assert (f);
2618 f->smooth = smooth; 2668 switch (ix)
2619 f->smoothlevel = smoothlevel; 2669 {
2670 case 0: f->type = value; break;
2671 case 1: f->visibility = value; break;
2672 case 2: f->magicmap = value; break;
2673 case 3: f->smooth = value; break;
2674 case 4: f->smoothlevel = value; break;
2675 }
2620 2676
2621void set_data (faceidx idx, int faceset, SV *data, SV *chksum) 2677void set_data (faceidx idx, int faceset, SV *data, SV *chksum)
2622 CODE: 2678 CODE:
2623{ 2679{
2624 facedata *d = face_data (idx, faceset); 2680 faceinfo *f = face_info (idx); assert (f);
2625 assert (d); 2681 facedata *d = &(faceset ? f->data64 : f->data32);
2626 sv_to (data, d->data); 2682 sv_to (data, d->data);
2627 STRLEN clen; 2683 STRLEN clen;
2628 char *cdata = SvPVbyte (chksum, clen); 2684 char *cdata = SvPVbyte (chksum, clen);
2629 clen = min (CHKSUM_SIZE, clen); 2685 clen = min (CHKSUM_SIZE, clen);
2630 2686
2640 ns->force_newmap = true; 2696 ns->force_newmap = true;
2641 } 2697 }
2642 } 2698 }
2643} 2699}
2644 2700
2701int get_data_size (faceidx idx, int faceset = 0)
2702 CODE:
2703 facedata *d = face_data (idx, faceset); assert (d);
2704 RETVAL = d->data.size ();
2705 OUTPUT:
2706 RETVAL
2707
2708SV *get_chksum (faceidx idx, int faceset = 0)
2709 CODE:
2710 facedata *d = face_data (idx, faceset); assert (d);
2711 RETVAL = newSVpvn ((char *)d->chksum, CHKSUM_SIZE);
2712 OUTPUT:
2713 RETVAL
2714
2645void invalidate (faceidx idx) 2715void invalidate (faceidx idx)
2646 CODE: 2716 CODE:
2647 for_all_clients (ns) 2717 for_all_clients (ns)
2648 { 2718 {
2649 ns->faces_sent [idx] = false; 2719 ns->faces_sent [idx] = false;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines