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.223 by root, Tue Jun 26 04:50:05 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);
380{ 394{
381 if (SvOK (sv)) 395 if (SvOK (sv))
382 return SvPTR (sv, klass); 396 return SvPTR (sv, klass);
383 else 397 else
384 return 0; 398 return 0;
399}
400
401static inline SV *
402newSVpv_utf8 (const char *s)
403{
404 SV *sv = newSVpv (s, 0);
405 SvUTF8_on (sv);
406 return sv;
385} 407}
386 408
387static inline SV * 409static inline SV *
388newSVpvn_utf8 (const char *s, STRLEN l) 410newSVpvn_utf8 (const char *s, STRLEN l)
389{ 411{
410inline 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); }
411inline 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); }
412inline 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); }
413inline 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); }
414inline 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); }
415inline 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); }
416inline SV *to_sv (region * v) { return newSVptr (v, stash_cf_region_wrap); }
417inline 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); }
418 440
419inline SV *to_sv (object & v) { return to_sv (&v); } 441inline SV *to_sv (object & v) { return to_sv (&v); }
420inline SV *to_sv (living & v) { return to_sv (&v); } 442inline SV *to_sv (living & v) { return to_sv (&v); }
421 443
447inline 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"); }
448inline 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"); }
449inline 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"); }
450inline 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"); }
451inline 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"); }
452inline 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"); }
453inline 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"); }
454inline void sv_to (SV *sv, region * &v) { v = (region *)SvPTR_ornull (sv, "cf::region"); }
455inline 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"); }
456 478
457//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)]; }
458inline 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)); }
459 481
942} 964}
943 965
944SV * 966SV *
945cfperl_result (int idx) 967cfperl_result (int idx)
946{ 968{
947 AV *av = get_av ("cfperl::invoke_results", 0); 969 AV *av = get_av ("cf::INVOKE_RESULTS", 0);
948 if (!av) 970 if (!av)
949 return &PL_sv_undef; 971 return &PL_sv_undef;
950 972
951 SV **sv = av_fetch (av, idx, 0); 973 SV **sv = av_fetch (av, idx, 0);
952 if (!sv) 974 if (!sv)
999void 1021void
1000cfperl_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)
1001{ 1023{
1002 CALL_BEGIN (4); 1024 CALL_BEGIN (4);
1003 CALL_ARG (ns); 1025 CALL_ARG (ns);
1026 CALL_ARG (type);
1027 CALL_ARG_SV (newSVpv_utf8 (msg));
1004 CALL_ARG (color); 1028 CALL_ARG (color);
1005 CALL_ARG (type);
1006 CALL_ARG (msg);
1007 CALL_CALL ("cf::client::send_msg", G_VOID); 1029 CALL_CALL ("cf::client::send_msg", G_VOID);
1008 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;
1009} 1046}
1010 1047
1011maptile * 1048maptile *
1012maptile::find_sync (const char *path, maptile *origin) 1049maptile::find_sync (const char *path, maptile *origin)
1013{ 1050{
1527 1564
1528 for_all_objects (op) 1565 for_all_objects (op)
1529 op->reattach (); 1566 op->reattach ();
1530} 1567}
1531 1568
1532void _post_tick ()
1533 CODE:
1534 coroapi::next_cede = SvNV (sv_next_tick) - TICK * (1. - 1. / CEDES_PER_TICK);
1535
1536# support function for map-world.ext 1569# support function for map-world.ext
1537void _quantise (SV *data_sv, SV *plt_sv) 1570void _quantise (SV *data_sv, SV *plt_sv)
1538 CODE: 1571 CODE:
1539{ 1572{
1540 if (!SvROK (plt_sv) || SvTYPE (SvRV (plt_sv)) != SVt_PVAV) 1573 if (!SvROK (plt_sv) || SvTYPE (SvRV (plt_sv)) != SVt_PVAV)
1572 len -= 3; 1605 len -= 3;
1573 } 1606 }
1574 1607
1575 SvCUR_set (data_sv, dst - SvPVX (data_sv)); 1608 SvCUR_set (data_sv, dst - SvPVX (data_sv));
1576} 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
1577 1626
1578NV floor (NV x) 1627NV floor (NV x)
1579 1628
1580NV ceil (NV x) 1629NV ceil (NV x)
1581 1630
1987 2036
1988void add_button_link (object *button, maptile *map, int connected); 2037void add_button_link (object *button, maptile *map, int connected);
1989 2038
1990void remove_button_link (object *op); 2039void remove_button_link (object *op);
1991 2040
2041void handle_apply_yield (object *op);
2042
1992 2043
1993MODULE = cf PACKAGE = cf::object PREFIX = cf_ 2044MODULE = cf PACKAGE = cf::object PREFIX = cf_
1994 2045
1995object *cf_insert_ob_in_ob (object *ob, object *where) 2046object *cf_insert_ob_in_ob (object *ob, object *where)
1996 2047
2002 CODE: 2053 CODE:
2003 RETVAL = archetype ? get_archetype (archetype) : object::create (); 2054 RETVAL = archetype ? get_archetype (archetype) : object::create ();
2004 OUTPUT: 2055 OUTPUT:
2005 RETVAL 2056 RETVAL
2006 2057
2058object *find_object (U32 tag)
2059
2007# TODO: nuke 2060# TODO: nuke
2008object *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)
2009 PROTOTYPE: $$$$$$ 2062 PROTOTYPE: $$$$$$
2010 CODE: 2063 CODE:
2011{ 2064{
2012 int unused_type; 2065 int unused_type;
2013 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);
2014} 2067}
2015
2016player *contr (object *op)
2017 CODE:
2018 RETVAL = op->contr;
2019 OUTPUT: RETVAL
2020 2068
2021const_utf8_string get_ob_key_value (object *op, utf8_string key) 2069const_utf8_string get_ob_key_value (object *op, utf8_string key)
2022 2070
2023bool 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)
2024 2072
2250 palette = SvRV (palette); 2298 palette = SvRV (palette);
2251 2299
2252 STRLEN idxlen; 2300 STRLEN idxlen;
2253 const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen); 2301 const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen);
2254 2302
2255 region **regionmap = (region **)malloc ( 2303 region_ptr *regionmap = new region_ptr [av_len ((AV *)palette) + 1];
2256 (av_len ((AV *)palette) + 1) * sizeof (region *));
2257 uint8_t *regions = salloc<uint8_t> (THIS->size ()); 2304 uint8_t *regions = salloc<uint8_t> (THIS->size ());
2258 2305
2259 for (int i = av_len ((AV *)palette) + 1; i--; ) 2306 for (int i = av_len ((AV *)palette) + 1; i--; )
2260 regionmap [i] = region::find ( 2307 regionmap [i] = region::find (SvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1)));
2261 SvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1)));
2262 2308
2263 for (int y = 0; y < THIS->height; ++y) 2309 for (int y = 0; y < THIS->height; ++y)
2264 memcpy (regions + y * THIS->width, idx + offset + y * stride, THIS->width); 2310 memcpy (regions + y * THIS->width, idx + offset + y * stride, THIS->width);
2265 2311
2266 sfree (THIS->regions, THIS->size ()); 2312 sfree (THIS->regions, THIS->size ());
2267 free (THIS->regionmap); 2313 delete [] THIS->regionmap;
2268 2314
2269 THIS->regions = regions; 2315 THIS->regions = regions;
2270 THIS->regionmap = regionmap; 2316 THIS->regionmap = regionmap;
2271} 2317}
2272 2318
2575 char *buf = SvPVbyte (packet, len); 2621 char *buf = SvPVbyte (packet, len);
2576 2622
2577 THIS->send_packet (buf, len); 2623 THIS->send_packet (buf, len);
2578} 2624}
2579 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
2580MODULE = cf PACKAGE = cf::face PREFIX = face_ 2635MODULE = cf PACKAGE = cf::face PREFIX = face_
2581 2636
2582#INCLUDE: $PERL $srcdir/genacc faceset ../include/face.h | 2637#INCLUDE: $PERL $srcdir/genacc faceset ../include/face.h |
2583 2638
2584faceidx face_find (utf8_string name, faceidx defidx = 0) 2639faceidx face_find (utf8_string name, faceidx defidx = 0)
2599 if (!strcmp (name, BLANK_FACE_NAME)) blank_face = RETVAL; 2654 if (!strcmp (name, BLANK_FACE_NAME)) blank_face = RETVAL;
2600 if (!strcmp (name, EMPTY_FACE_NAME)) empty_face = RETVAL; 2655 if (!strcmp (name, EMPTY_FACE_NAME)) empty_face = RETVAL;
2601} 2656}
2602 OUTPUT: RETVAL 2657 OUTPUT: RETVAL
2603 2658
2604void set (faceidx idx, int visibility, int magicmap) 2659void set_type (faceidx idx, int value)
2605 CODE: 2660 ALIAS:
2606 faceinfo *f = face_info (idx); 2661 set_type = 0
2607 assert (f); 2662 set_visibility = 1
2608 f->visibility = visibility; 2663 set_magicmap = 2
2609 f->magicmap = magicmap; 2664 set_smooth = 3
2610 2665 set_smoothlevel = 4
2611void set_smooth (faceidx idx, faceidx smooth, int smoothlevel)
2612 CODE: 2666 CODE:
2613 faceinfo *f = face_info (idx); assert (f); 2667 faceinfo *f = face_info (idx); assert (f);
2614 f->smooth = smooth; 2668 switch (ix)
2615 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 }
2616 2676
2617void set_data (faceidx idx, int faceset, SV *data, SV *chksum) 2677void set_data (faceidx idx, int faceset, SV *data, SV *chksum)
2618 CODE: 2678 CODE:
2619{ 2679{
2620 facedata *d = face_data (idx, faceset); 2680 faceinfo *f = face_info (idx); assert (f);
2621 assert (d); 2681 facedata *d = &(faceset ? f->data64 : f->data32);
2622 sv_to (data, d->data); 2682 sv_to (data, d->data);
2623 STRLEN clen; 2683 STRLEN clen;
2624 char *cdata = SvPVbyte (chksum, clen); 2684 char *cdata = SvPVbyte (chksum, clen);
2625 clen = min (CHKSUM_SIZE, clen); 2685 clen = min (CHKSUM_SIZE, clen);
2626 2686
2636 ns->force_newmap = true; 2696 ns->force_newmap = true;
2637 } 2697 }
2638 } 2698 }
2639} 2699}
2640 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
2641void invalidate (faceidx idx) 2715void invalidate (faceidx idx)
2642 CODE: 2716 CODE:
2643 for_all_clients (ns) 2717 for_all_clients (ns)
2644 { 2718 {
2645 ns->faces_sent [idx] = false; 2719 ns->faces_sent [idx] = false;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines