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.224 by root, Tue Jun 26 05:07:21 2007 UTC vs.
Revision 1.237 by root, Mon Jul 23 23:46:03 2007 UTC

3 * 3 *
4 * Copyright (©) 2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team 4 * Copyright (©) 2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team
5 * Copyright (©) 2001-2005,2007 by Chachkoff Yann 5 * Copyright (©) 2001-2005,2007 by Chachkoff Yann
6 * Copyright (©) 2006,2007 by Marc Lehmann <cf@schmorp.de> 6 * Copyright (©) 2006,2007 by Marc Lehmann <cf@schmorp.de>
7 * 7 *
8 * Crossfire TRT is free software; you can redistribute it and/or modify it 8 * Crossfire TRT is free software: you can redistribute it and/or modify
9 * under the terms of the GNU General Public License as published by the Free 9 * it under the terms of the GNU General Public License as published by
10 * Software Foundation; either version 2 of the License, or (at your option) 10 * the Free Software Foundation, either version 3 of the License, or
11 * any later version. 11 * (at your option) any later version.
12 * 12 *
13 * This program is distributed in the hope that it will be useful, but 13 * This program is distributed in the hope that it will be useful,
14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * for more details. 16 * GNU General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU General Public License along 18 * You should have received a copy of the GNU General Public License
19 * with Crossfire TRT; if not, write to the Free Software Foundation, Inc. 51 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 * 20 *
22 * The authors can be reached via e-mail to <crossfire@schmorp.de> 21 * The authors can be reached via e-mail to <crossfire@schmorp.de>
23 */ 22 */
24 23
25#include "autoconf.h" 24#include "autoconf.h"
247 delete obj; 246 delete obj;
248 } 247 }
249 } 248 }
250} 249}
251 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
252attachable & 263attachable &
253attachable::operator =(const attachable &src) 264attachable::operator =(const attachable &src)
254{ 265{
255 //if (self || cb) 266 //if (self || cb)
256 //INVOKE_OBJECT (CLONE, this, ARG_OBJECT (dst)); 267 //INVOKE_OBJECT (CLONE, this, ARG_OBJECT (dst));
331{ 342{
332 if (!obj) 343 if (!obj)
333 return &PL_sv_undef; 344 return &PL_sv_undef;
334 345
335 if (!obj->self) 346 if (!obj->self)
347 obj->self = newHV ();
348
349 if (!SvOBJECT (obj->self))
336 { 350 {
337 obj->self = newHV ();
338 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);
339 352
340 // 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
341 return sv_bless (newRV_inc ((SV *)obj->self), stash); 355 return sv_bless (newRV_inc ((SV *)obj->self), stash);
342 } 356 }
343 else 357 else
344 { 358 {
345 SV *sv = newRV_inc ((SV *)obj->self); 359 SV *sv = newRV_inc ((SV *)obj->self);
418inline 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); }
419inline 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); }
420inline 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); }
421inline 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); }
422inline 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); }
423inline 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); }
424inline SV *to_sv (region * v) { return newSVptr (v, stash_cf_region_wrap); }
425inline 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); }
426 440
427inline SV *to_sv (object & v) { return to_sv (&v); } 441inline SV *to_sv (object & v) { return to_sv (&v); }
428inline SV *to_sv (living & v) { return to_sv (&v); } 442inline SV *to_sv (living & v) { return to_sv (&v); }
429 443
455inline 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"); }
456inline 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"); }
457inline 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"); }
458inline 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"); }
459inline 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"); }
460inline 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"); }
461inline 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"); }
462inline void sv_to (SV *sv, region * &v) { v = (region *)SvPTR_ornull (sv, "cf::region"); }
463inline 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"); }
464 478
465//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)]; }
466inline 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)); }
467 481
950} 964}
951 965
952SV * 966SV *
953cfperl_result (int idx) 967cfperl_result (int idx)
954{ 968{
955 AV *av = get_av ("cfperl::invoke_results", 0); 969 AV *av = get_av ("cf::INVOKE_RESULTS", 0);
956 if (!av) 970 if (!av)
957 return &PL_sv_undef; 971 return &PL_sv_undef;
958 972
959 SV **sv = av_fetch (av, idx, 0); 973 SV **sv = av_fetch (av, idx, 0);
960 if (!sv) 974 if (!sv)
1007void 1021void
1008cfperl_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)
1009{ 1023{
1010 CALL_BEGIN (4); 1024 CALL_BEGIN (4);
1011 CALL_ARG (ns); 1025 CALL_ARG (ns);
1012 CALL_ARG (color);
1013 CALL_ARG (type); 1026 CALL_ARG (type);
1014 CALL_ARG_SV (newSVpv_utf8 (msg)); 1027 CALL_ARG_SV (newSVpv_utf8 (msg));
1028 CALL_ARG (color);
1015 CALL_CALL ("cf::client::send_msg", G_VOID); 1029 CALL_CALL ("cf::client::send_msg", G_VOID);
1016 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;
1017} 1046}
1018 1047
1019maptile * 1048maptile *
1020maptile::find_sync (const char *path, maptile *origin) 1049maptile::find_sync (const char *path, maptile *origin)
1021{ 1050{
1535 1564
1536 for_all_objects (op) 1565 for_all_objects (op)
1537 op->reattach (); 1566 op->reattach ();
1538} 1567}
1539 1568
1540void _post_tick ()
1541 CODE:
1542 coroapi::next_cede = SvNV (sv_next_tick) - TICK * (1. - 1. / CEDES_PER_TICK);
1543
1544# support function for map-world.ext 1569# support function for map-world.ext
1545void _quantise (SV *data_sv, SV *plt_sv) 1570void _quantise (SV *data_sv, SV *plt_sv)
1546 CODE: 1571 CODE:
1547{ 1572{
1548 if (!SvROK (plt_sv) || SvTYPE (SvRV (plt_sv)) != SVt_PVAV) 1573 if (!SvROK (plt_sv) || SvTYPE (SvRV (plt_sv)) != SVt_PVAV)
1580 len -= 3; 1605 len -= 3;
1581 } 1606 }
1582 1607
1583 SvCUR_set (data_sv, dst - SvPVX (data_sv)); 1608 SvCUR_set (data_sv, dst - SvPVX (data_sv));
1584} 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
1585 1626
1586NV floor (NV x) 1627NV floor (NV x)
1587 1628
1588NV ceil (NV x) 1629NV ceil (NV x)
1589 1630
1995 2036
1996void add_button_link (object *button, maptile *map, int connected); 2037void add_button_link (object *button, maptile *map, int connected);
1997 2038
1998void remove_button_link (object *op); 2039void remove_button_link (object *op);
1999 2040
2041void handle_apply_yield (object *op);
2042
2000 2043
2001MODULE = cf PACKAGE = cf::object PREFIX = cf_ 2044MODULE = cf PACKAGE = cf::object PREFIX = cf_
2002 2045
2003object *cf_insert_ob_in_ob (object *ob, object *where) 2046object *cf_insert_ob_in_ob (object *ob, object *where)
2004 2047
2010 CODE: 2053 CODE:
2011 RETVAL = archetype ? get_archetype (archetype) : object::create (); 2054 RETVAL = archetype ? get_archetype (archetype) : object::create ();
2012 OUTPUT: 2055 OUTPUT:
2013 RETVAL 2056 RETVAL
2014 2057
2058object *find_object (U32 tag)
2059
2015# TODO: nuke 2060# TODO: nuke
2016object *insert_ob_in_map_at (object *ob, maptile *where, object_ornull *orig, int flag, int x, int y) 2061object *insert_ob_in_map_at (object *ob, maptile *where, object_ornull *orig, int flag, int x, int y)
2017 PROTOTYPE: $$$$$$ 2062 PROTOTYPE: $$$$$$
2018 CODE: 2063 CODE:
2019{ 2064{
2020 int unused_type; 2065 int unused_type;
2021 RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y); 2066 RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y);
2022} 2067}
2023
2024player *contr (object *op)
2025 CODE:
2026 RETVAL = op->contr;
2027 OUTPUT: RETVAL
2028 2068
2029const_utf8_string get_ob_key_value (object *op, utf8_string key) 2069const_utf8_string get_ob_key_value (object *op, utf8_string key)
2030 2070
2031bool set_ob_key_value (object *op, utf8_string key, utf8_string value = 0, int add_key = 1) 2071bool set_ob_key_value (object *op, utf8_string key, utf8_string value = 0, int add_key = 1)
2032 2072
2258 palette = SvRV (palette); 2298 palette = SvRV (palette);
2259 2299
2260 STRLEN idxlen; 2300 STRLEN idxlen;
2261 const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen); 2301 const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen);
2262 2302
2263 region **regionmap = (region **)malloc ( 2303 region_ptr *regionmap = new region_ptr [av_len ((AV *)palette) + 1];
2264 (av_len ((AV *)palette) + 1) * sizeof (region *));
2265 uint8_t *regions = salloc<uint8_t> (THIS->size ()); 2304 uint8_t *regions = salloc<uint8_t> (THIS->size ());
2266 2305
2267 for (int i = av_len ((AV *)palette) + 1; i--; ) 2306 for (int i = av_len ((AV *)palette) + 1; i--; )
2268 regionmap [i] = region::find ( 2307 regionmap [i] = region::find (SvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1)));
2269 SvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1)));
2270 2308
2271 for (int y = 0; y < THIS->height; ++y) 2309 for (int y = 0; y < THIS->height; ++y)
2272 memcpy (regions + y * THIS->width, idx + offset + y * stride, THIS->width); 2310 memcpy (regions + y * THIS->width, idx + offset + y * stride, THIS->width);
2273 2311
2274 sfree (THIS->regions, THIS->size ()); 2312 sfree (THIS->regions, THIS->size ());
2275 free (THIS->regionmap); 2313 delete [] THIS->regionmap;
2276 2314
2277 THIS->regions = regions; 2315 THIS->regions = regions;
2278 THIS->regionmap = regionmap; 2316 THIS->regionmap = regionmap;
2279} 2317}
2280 2318
2583 char *buf = SvPVbyte (packet, len); 2621 char *buf = SvPVbyte (packet, len);
2584 2622
2585 THIS->send_packet (buf, len); 2623 THIS->send_packet (buf, len);
2586} 2624}
2587 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
2588MODULE = cf PACKAGE = cf::face PREFIX = face_ 2635MODULE = cf PACKAGE = cf::face PREFIX = face_
2589 2636
2590#INCLUDE: $PERL $srcdir/genacc faceset ../include/face.h | 2637#INCLUDE: $PERL $srcdir/genacc faceset ../include/face.h |
2591 2638
2592faceidx face_find (utf8_string name, faceidx defidx = 0) 2639faceidx face_find (utf8_string name, faceidx defidx = 0)
2607 if (!strcmp (name, BLANK_FACE_NAME)) blank_face = RETVAL; 2654 if (!strcmp (name, BLANK_FACE_NAME)) blank_face = RETVAL;
2608 if (!strcmp (name, EMPTY_FACE_NAME)) empty_face = RETVAL; 2655 if (!strcmp (name, EMPTY_FACE_NAME)) empty_face = RETVAL;
2609} 2656}
2610 OUTPUT: RETVAL 2657 OUTPUT: RETVAL
2611 2658
2612void set (faceidx idx, int visibility, int magicmap) 2659void set_type (faceidx idx, int value)
2613 CODE: 2660 ALIAS:
2614 faceinfo *f = face_info (idx); 2661 set_type = 0
2615 assert (f); 2662 set_visibility = 1
2616 f->visibility = visibility; 2663 set_magicmap = 2
2617 f->magicmap = magicmap; 2664 set_smooth = 3
2618 2665 set_smoothlevel = 4
2619void set_smooth (faceidx idx, faceidx smooth, int smoothlevel)
2620 CODE: 2666 CODE:
2621 faceinfo *f = face_info (idx); assert (f); 2667 faceinfo *f = face_info (idx); assert (f);
2622 f->smooth = smooth; 2668 switch (ix)
2623 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 }
2624 2676
2625void set_data (faceidx idx, int faceset, SV *data, SV *chksum) 2677void set_data (faceidx idx, int faceset, SV *data, SV *chksum)
2626 CODE: 2678 CODE:
2627{ 2679{
2628 facedata *d = face_data (idx, faceset); 2680 faceinfo *f = face_info (idx); assert (f);
2629 assert (d); 2681 facedata *d = &(faceset ? f->data64 : f->data32);
2630 sv_to (data, d->data); 2682 sv_to (data, d->data);
2631 STRLEN clen; 2683 STRLEN clen;
2632 char *cdata = SvPVbyte (chksum, clen); 2684 char *cdata = SvPVbyte (chksum, clen);
2633 clen = min (CHKSUM_SIZE, clen); 2685 clen = min (CHKSUM_SIZE, clen);
2634 2686
2644 ns->force_newmap = true; 2696 ns->force_newmap = true;
2645 } 2697 }
2646 } 2698 }
2647} 2699}
2648 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
2649void invalidate (faceidx idx) 2715void invalidate (faceidx idx)
2650 CODE: 2716 CODE:
2651 for_all_clients (ns) 2717 for_all_clients (ns)
2652 { 2718 {
2653 ns->faces_sent [idx] = false; 2719 ns->faces_sent [idx] = false;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines