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.154 by root, Fri Jan 26 21:44:11 2007 UTC vs.
Revision 1.164 by root, Sun Feb 11 01:38:49 2007 UTC

29#include <plugin_common.h> 29#include <plugin_common.h>
30#include <sounds.h> 30#include <sounds.h>
31#include <cstdarg> 31#include <cstdarg>
32#include <sproto.h> 32#include <sproto.h>
33 33
34#include "loader.h"
34#include "cfperl.h" 35#include "cfperl.h"
35#include "shstr.h" 36#include "shstr.h"
36 37
37#include <unistd.h> 38#include <unistd.h>
38#if _POSIX_MEMLOCK 39#if _POSIX_MEMLOCK
112{ 113{
113 return refcnt + (self ? SvREFCNT (self) - 1 : 0); 114 return refcnt + (self ? SvREFCNT (self) - 1 : 0);
114} 115}
115 116
116void 117void
118attachable::sever_self ()
119{
120 if (HV *self = this->self)
121 {
122 // keep a refcount because sv_unmagic might call attachable_free,
123 // which might clear self, causing sv_unmagic to crash on a now
124 // invalid object.
125 SvREFCNT_inc (self);
126 hv_clear (self);
127 sv_unmagic ((SV *)self, PERL_MAGIC_ext);
128 SvREFCNT_dec (self);
129
130 // self *must* be null now because thats sv_unmagic's job.
131 assert (!this->self);
132 flags |= 0x80; // severed //D
133 }
134}
135
136void
117attachable::optimise () 137attachable::optimise ()
118{ 138{
119 if (self 139 if (self
120 && SvREFCNT (self) == 1 140 && SvREFCNT (self) == 1
121 && !HvTOTALKEYS (self)) 141 && !HvTOTALKEYS (self))
122 { 142 flags |= 0x40,//D
123 SV *self = (SV *)this->self; 143 sever_self ();
124
125 SvREFCNT_inc (self);
126 sv_unmagic (self, PERL_MAGIC_ext);
127 SvREFCNT_dec (self);
128 assert (!this->self);
129 }
130} 144}
131 145
132// check wether the object really is dead 146// check wether the object really is dead
133void 147void
134attachable::do_check () 148attachable::do_check ()
149 SvREFCNT_dec (cb); 163 SvREFCNT_dec (cb);
150 cb = 0; 164 cb = 0;
151 } 165 }
152 166
153 if (self) 167 if (self)
154 { 168 sever_self ();
155 hv_clear (self);
156 169
157 SV *self = (SV *)this->self; 170 flags |= 0x20; //D
158 SvREFCNT_inc (self);
159 sv_unmagic (self, PERL_MAGIC_ext);
160 SvREFCNT_dec (self);
161 // self is now 0
162 assert (!this->self);//D//TODO remove soon
163 }
164
165 mortals.push_back (this); 171 mortals.push_back (this);
166} 172}
167 173
168void 174void
169attachable::destroy () 175attachable::destroy ()
264 270
265 if (!obj->self) 271 if (!obj->self)
266 { 272 {
267 obj->self = newHV (); 273 obj->self = newHV ();
268 sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &attachable::vtbl, (char *)obj, 0); 274 sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &attachable::vtbl, (char *)obj, 0);
275 obj->flags &= ~0xc0;//D
276 obj->flags |= 0x10;//D
269 277
270 // now bless the object _once_ 278 // now bless the object _once_
271 return sv_bless (newRV_inc ((SV *)obj->self), stash); 279 return sv_bless (newRV_inc ((SV *)obj->self), stash);
272 } 280 }
273 else 281 else
345inline SV *to_sv (treasurelist * v) { return to_sv (v->name); } 353inline SV *to_sv (treasurelist * v) { return to_sv (v->name); }
346 354
347inline SV *to_sv (UUID v) 355inline SV *to_sv (UUID v)
348{ 356{
349 char buf[128]; 357 char buf[128];
350 snprintf (buf, 128, "<1,%" PRIx64 ">", v.seq); 358 snprintf (buf, 128, "<1.%" PRIx64 ">", v.seq);
351 return newSVpv (buf, 0); 359 return newSVpv (buf, 0);
352} 360}
353 361
354inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? SvPV_nolen (sv) : 0; } 362inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? SvPV_nolen (sv) : 0; }
355inline void sv_to (SV *sv, char * &v) { free (v); v = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; } 363inline void sv_to (SV *sv, char * &v) { free (v); v = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; }
602 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl)) 610 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl))
603 { 611 {
604 printf ("unable to initialize perl-interpreter, aborting.\n"); 612 printf ("unable to initialize perl-interpreter, aborting.\n");
605 exit (EXIT_FAILURE); 613 exit (EXIT_FAILURE);
606 } 614 }
615
616 {
617 dSP;
618
619 PUSHMARK (SP);
620 PUTBACK;
621 call_pv ("cf::init", G_DISCARD | G_VOID);
622 }
607} 623}
608 624
609void cfperl_main () 625void cfperl_main ()
610{ 626{
611 dSP; 627 dSP;
1647 1663
1648void cleanup (const char *cause, bool make_core = false) 1664void cleanup (const char *cause, bool make_core = false)
1649 1665
1650void emergency_save () 1666void emergency_save ()
1651 1667
1668void _exit (int status = EXIT_SUCCESS)
1669
1652UV sv_2watcher (SV *w) 1670UV sv_2watcher (SV *w)
1653 CODE: 1671 CODE:
1654 RETVAL = (UV)GEventAPI->sv_2watcher (w); 1672 RETVAL = (UV)GEventAPI->sv_2watcher (w);
1655 OUTPUT: 1673 OUTPUT:
1656 RETVAL 1674 RETVAL
1657
1658void _exit (int status = 0)
1659 1675
1660#if _POSIX_MEMLOCK 1676#if _POSIX_MEMLOCK
1661 1677
1662int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) 1678int mlockall (int flags = MCL_CURRENT | MCL_FUTURE)
1663 1679
1709 RETVAL = newSVpv (resist_plus[atnr], 0); 1725 RETVAL = newSVpv (resist_plus[atnr], 0);
1710 else 1726 else
1711 XSRETURN_UNDEF; 1727 XSRETURN_UNDEF;
1712 OUTPUT: RETVAL 1728 OUTPUT: RETVAL
1713 1729
1730bool
1731load_regions (const char *filename)
1732 CODE:
1733 RETVAL = loader_region ().load (filename);
1734 OUTPUT: RETVAL
1735
1714MODULE = cf PACKAGE = cf::attachable 1736MODULE = cf PACKAGE = cf::attachable
1715 1737
1716int 1738int
1717valid (SV *obj) 1739valid (SV *obj)
1718 CODE: 1740 CODE:
1719 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); 1741 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext);
1720 OUTPUT: 1742 OUTPUT:
1721 RETVAL 1743 RETVAL
1744
1745void
1746debug_trace (attachable *obj, bool on = true)
1747 CODE:
1748 obj->flags &= ~attachable::F_DEBUG_TRACE;
1749 if (on)
1750 obj->flags |= attachable::F_DEBUG_TRACE;
1722 1751
1723int mortals_size () 1752int mortals_size ()
1724 CODE: 1753 CODE:
1725 RETVAL = attachable::mortals.size (); 1754 RETVAL = attachable::mortals.size ();
1726 OUTPUT: RETVAL 1755 OUTPUT: RETVAL
1802 1831
1803void 1832void
1804set_animation (object *op, int idx) 1833set_animation (object *op, int idx)
1805 CODE: 1834 CODE:
1806 SET_ANIMATION (op, idx); 1835 SET_ANIMATION (op, idx);
1836
1837int
1838num_animations (object *op)
1839 CODE:
1840 RETVAL = NUM_ANIMATIONS (op);
1841 OUTPUT: RETVAL
1807 1842
1808object *find_best_object_match (object *op, const char *match) 1843object *find_best_object_match (object *op, const char *match)
1809 1844
1810object *find_marked_object (object *op) 1845object *find_marked_object (object *op)
1811 1846
2048 pl->orig_stats = pl->ob->stats; 2083 pl->orig_stats = pl->ob->stats;
2049 2084
2050void cf_player_move (player *pl, int dir) 2085void cf_player_move (player *pl, int dir)
2051 2086
2052void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0); 2087void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0);
2053
2054player *first ()
2055 CODE:
2056 RETVAL = first_player;
2057 OUTPUT: RETVAL
2058 2088
2059bool 2089bool
2060cell_visible (player *pl, int dx, int dy) 2090cell_visible (player *pl, int dx, int dy)
2061 CODE: 2091 CODE:
2062 RETVAL = FABS (dx) <= pl->ns->mapx / 2 && FABS (dy) <= pl->ns->mapy / 2 2092 RETVAL = FABS (dx) <= pl->ns->mapx / 2 && FABS (dy) <= pl->ns->mapy / 2
2139 EXTEND (SP, THIS->players); 2169 EXTEND (SP, THIS->players);
2140 for_all_players (pl) 2170 for_all_players (pl)
2141 if (pl->ob && pl->ob->map == THIS) 2171 if (pl->ob && pl->ob->map == THIS)
2142 PUSHs (sv_2mortal (to_sv (pl->ob))); 2172 PUSHs (sv_2mortal (to_sv (pl->ob)));
2143 } 2173 }
2174
2175void
2176maptile::set_regiondata (SV *data, SV *plt)
2177 CODE:
2178{
2179 if (!SvROK (plt) || SvTYPE (SvRV (plt)) != SVt_PVAV)
2180 croak ("maptile::set_regiondata needs arrayref as plt arg");
2181
2182 AV *av = (AV *)SvRV (plt);
2183
2184 region **regionmap = (region **)malloc ((av_len (av) + 1) * sizeof (region *));
2185
2186 for (int i = av_len (av) + 1; i--; )
2187 regionmap [i] = region::find (SvPVutf8_nolen (*av_fetch (av, i, 1)));
2188
2189 THIS->regions = salloc<uint8_t> (THIS->size (), (uint8_t *)SvPVbyte_nolen (data));
2190 THIS->regionmap = regionmap;
2191}
2144 2192
2145void play_sound_map (maptile *map, int x, int y, int sound_num) 2193void play_sound_map (maptile *map, int x, int y, int sound_num)
2146 2194
2147int out_of_map (maptile *map, int x, int y) 2195int out_of_map (maptile *map, int x, int y)
2148 2196
2229 OUTPUT: RETVAL 2277 OUTPUT: RETVAL
2230 2278
2231void fix_walls (maptile *map, int x, int y) 2279void fix_walls (maptile *map, int x, int y)
2232 2280
2233void fix_walls_around (maptile *map, int x, int y) 2281void fix_walls_around (maptile *map, int x, int y)
2234
2235const char *
2236region_name (maptile *m)
2237 CODE:
2238 RETVAL = get_name_of_region_for_map (m);
2239 OUTPUT: RETVAL
2240 2282
2241# worst xs function of my life 2283# worst xs function of my life
2242bool 2284bool
2243_create_random_map (\ 2285_create_random_map (\
2244 maptile *self,\ 2286 maptile *self,\
2352 2394
2353INCLUDE: $PERL genacc partylist ../include/player.h | 2395INCLUDE: $PERL genacc partylist ../include/player.h |
2354 2396
2355MODULE = cf PACKAGE = cf::region 2397MODULE = cf PACKAGE = cf::region
2356 2398
2357region *first () 2399void
2358 PROTOTYPE: 2400list ()
2359 CODE: 2401 PPCODE:
2360 RETVAL = first_region; 2402 for_all_regions (rgn)
2361 OUTPUT: RETVAL 2403 XPUSHs (sv_2mortal (to_sv (rgn)));
2362 2404
2363region *find (char *name) 2405region *find (char *name)
2364 PROTOTYPE: $ 2406 PROTOTYPE: $
2365 CODE: 2407 CODE:
2366 RETVAL = get_region_by_name (name); 2408 RETVAL = region::find (name);
2409 OUTPUT: RETVAL
2410
2411region *find_fuzzy (char *name)
2412 PROTOTYPE: $
2413 CODE:
2414 RETVAL = region::find_fuzzy (name);
2367 OUTPUT: RETVAL 2415 OUTPUT: RETVAL
2368 2416
2369INCLUDE: $PERL genacc region ../include/map.h | 2417INCLUDE: $PERL genacc region ../include/map.h |
2370 2418
2371MODULE = cf PACKAGE = cf::living 2419MODULE = cf PACKAGE = cf::living

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines