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.162 by root, Thu Feb 1 19:40:42 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 }
133}
134
135void
117attachable::optimise () 136attachable::optimise ()
118{ 137{
119 if (self 138 if (self
120 && SvREFCNT (self) == 1 139 && SvREFCNT (self) == 1
121 && !HvTOTALKEYS (self)) 140 && !HvTOTALKEYS (self))
122 { 141 sever_self ();
123 SV *self = (SV *)this->self;
124
125 SvREFCNT_inc (self);
126 sv_unmagic (self, PERL_MAGIC_ext);
127 SvREFCNT_dec (self);
128 assert (!this->self);
129 }
130} 142}
131 143
132// check wether the object really is dead 144// check wether the object really is dead
133void 145void
134attachable::do_check () 146attachable::do_check ()
149 SvREFCNT_dec (cb); 161 SvREFCNT_dec (cb);
150 cb = 0; 162 cb = 0;
151 } 163 }
152 164
153 if (self) 165 if (self)
154 { 166 sever_self ();
155 hv_clear (self);
156
157 SV *self = (SV *)this->self;
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 167
165 mortals.push_back (this); 168 mortals.push_back (this);
166} 169}
167 170
168void 171void
345inline SV *to_sv (treasurelist * v) { return to_sv (v->name); } 348inline SV *to_sv (treasurelist * v) { return to_sv (v->name); }
346 349
347inline SV *to_sv (UUID v) 350inline SV *to_sv (UUID v)
348{ 351{
349 char buf[128]; 352 char buf[128];
350 snprintf (buf, 128, "<1,%" PRIx64 ">", v.seq); 353 snprintf (buf, 128, "<1.%" PRIx64 ">", v.seq);
351 return newSVpv (buf, 0); 354 return newSVpv (buf, 0);
352} 355}
353 356
354inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? SvPV_nolen (sv) : 0; } 357inline 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; } 358inline 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)) 605 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl))
603 { 606 {
604 printf ("unable to initialize perl-interpreter, aborting.\n"); 607 printf ("unable to initialize perl-interpreter, aborting.\n");
605 exit (EXIT_FAILURE); 608 exit (EXIT_FAILURE);
606 } 609 }
610
611 {
612 dSP;
613
614 PUSHMARK (SP);
615 PUTBACK;
616 call_pv ("cf::init", G_DISCARD | G_VOID);
617 }
607} 618}
608 619
609void cfperl_main () 620void cfperl_main ()
610{ 621{
611 dSP; 622 dSP;
1647 1658
1648void cleanup (const char *cause, bool make_core = false) 1659void cleanup (const char *cause, bool make_core = false)
1649 1660
1650void emergency_save () 1661void emergency_save ()
1651 1662
1663void _exit (int status = EXIT_SUCCESS)
1664
1652UV sv_2watcher (SV *w) 1665UV sv_2watcher (SV *w)
1653 CODE: 1666 CODE:
1654 RETVAL = (UV)GEventAPI->sv_2watcher (w); 1667 RETVAL = (UV)GEventAPI->sv_2watcher (w);
1655 OUTPUT: 1668 OUTPUT:
1656 RETVAL 1669 RETVAL
1657
1658void _exit (int status = 0)
1659 1670
1660#if _POSIX_MEMLOCK 1671#if _POSIX_MEMLOCK
1661 1672
1662int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) 1673int mlockall (int flags = MCL_CURRENT | MCL_FUTURE)
1663 1674
1709 RETVAL = newSVpv (resist_plus[atnr], 0); 1720 RETVAL = newSVpv (resist_plus[atnr], 0);
1710 else 1721 else
1711 XSRETURN_UNDEF; 1722 XSRETURN_UNDEF;
1712 OUTPUT: RETVAL 1723 OUTPUT: RETVAL
1713 1724
1725bool
1726load_regions (const char *filename)
1727 CODE:
1728 RETVAL = loader_region ().load (filename);
1729 OUTPUT: RETVAL
1730
1714MODULE = cf PACKAGE = cf::attachable 1731MODULE = cf PACKAGE = cf::attachable
1715 1732
1716int 1733int
1717valid (SV *obj) 1734valid (SV *obj)
1718 CODE: 1735 CODE:
1802 1819
1803void 1820void
1804set_animation (object *op, int idx) 1821set_animation (object *op, int idx)
1805 CODE: 1822 CODE:
1806 SET_ANIMATION (op, idx); 1823 SET_ANIMATION (op, idx);
1824
1825int
1826num_animations (object *op)
1827 CODE:
1828 RETVAL = NUM_ANIMATIONS (op);
1829 OUTPUT: RETVAL
1807 1830
1808object *find_best_object_match (object *op, const char *match) 1831object *find_best_object_match (object *op, const char *match)
1809 1832
1810object *find_marked_object (object *op) 1833object *find_marked_object (object *op)
1811 1834
2048 pl->orig_stats = pl->ob->stats; 2071 pl->orig_stats = pl->ob->stats;
2049 2072
2050void cf_player_move (player *pl, int dir) 2073void cf_player_move (player *pl, int dir)
2051 2074
2052void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0); 2075void 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 2076
2059bool 2077bool
2060cell_visible (player *pl, int dx, int dy) 2078cell_visible (player *pl, int dx, int dy)
2061 CODE: 2079 CODE:
2062 RETVAL = FABS (dx) <= pl->ns->mapx / 2 && FABS (dy) <= pl->ns->mapy / 2 2080 RETVAL = FABS (dx) <= pl->ns->mapx / 2 && FABS (dy) <= pl->ns->mapy / 2
2139 EXTEND (SP, THIS->players); 2157 EXTEND (SP, THIS->players);
2140 for_all_players (pl) 2158 for_all_players (pl)
2141 if (pl->ob && pl->ob->map == THIS) 2159 if (pl->ob && pl->ob->map == THIS)
2142 PUSHs (sv_2mortal (to_sv (pl->ob))); 2160 PUSHs (sv_2mortal (to_sv (pl->ob)));
2143 } 2161 }
2162
2163void
2164maptile::set_regiondata (SV *data, SV *plt)
2165 CODE:
2166{
2167 if (!SvROK (plt) || SvTYPE (SvRV (plt)) != SVt_PVAV)
2168 croak ("maptile::set_regiondata needs arrayref as plt arg");
2169
2170 AV *av = (AV *)SvRV (plt);
2171
2172 region **regionmap = (region **)malloc ((av_len (av) + 1) * sizeof (region *));
2173
2174 for (int i = av_len (av) + 1; i--; )
2175 regionmap [i] = region::find (SvPVutf8_nolen (*av_fetch (av, i, 1)));
2176
2177 THIS->regions = salloc<uint8_t> (THIS->size (), (uint8_t *)SvPVbyte_nolen (data));
2178 THIS->regionmap = regionmap;
2179}
2144 2180
2145void play_sound_map (maptile *map, int x, int y, int sound_num) 2181void play_sound_map (maptile *map, int x, int y, int sound_num)
2146 2182
2147int out_of_map (maptile *map, int x, int y) 2183int out_of_map (maptile *map, int x, int y)
2148 2184
2229 OUTPUT: RETVAL 2265 OUTPUT: RETVAL
2230 2266
2231void fix_walls (maptile *map, int x, int y) 2267void fix_walls (maptile *map, int x, int y)
2232 2268
2233void fix_walls_around (maptile *map, int x, int y) 2269void 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 2270
2241# worst xs function of my life 2271# worst xs function of my life
2242bool 2272bool
2243_create_random_map (\ 2273_create_random_map (\
2244 maptile *self,\ 2274 maptile *self,\
2352 2382
2353INCLUDE: $PERL genacc partylist ../include/player.h | 2383INCLUDE: $PERL genacc partylist ../include/player.h |
2354 2384
2355MODULE = cf PACKAGE = cf::region 2385MODULE = cf PACKAGE = cf::region
2356 2386
2357region *first () 2387void
2358 PROTOTYPE: 2388list ()
2359 CODE: 2389 PPCODE:
2360 RETVAL = first_region; 2390 for_all_regions (rgn)
2361 OUTPUT: RETVAL 2391 XPUSHs (sv_2mortal (to_sv (rgn)));
2362 2392
2363region *find (char *name) 2393region *find (char *name)
2364 PROTOTYPE: $ 2394 PROTOTYPE: $
2365 CODE: 2395 CODE:
2366 RETVAL = get_region_by_name (name); 2396 RETVAL = region::find (name);
2397 OUTPUT: RETVAL
2398
2399region *find_fuzzy (char *name)
2400 PROTOTYPE: $
2401 CODE:
2402 RETVAL = region::find_fuzzy (name);
2367 OUTPUT: RETVAL 2403 OUTPUT: RETVAL
2368 2404
2369INCLUDE: $PERL genacc region ../include/map.h | 2405INCLUDE: $PERL genacc region ../include/map.h |
2370 2406
2371MODULE = cf PACKAGE = cf::living 2407MODULE = cf PACKAGE = cf::living

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines