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.153 by root, Fri Jan 26 20:59:57 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_unmagic ((SV *)self, PERL_MAGIC_ext);
124 assert (!self);
125 }
126} 142}
127 143
128// check wether the object really is dead 144// check wether the object really is dead
129void 145void
130attachable::do_check () 146attachable::do_check ()
145 SvREFCNT_dec (cb); 161 SvREFCNT_dec (cb);
146 cb = 0; 162 cb = 0;
147 } 163 }
148 164
149 if (self) 165 if (self)
150 { 166 sever_self ();
151 hv_clear (self);
152 sv_unmagic ((SV *)self, PERL_MAGIC_ext);
153 // self is now 0
154 assert (!self);//D//TODO remove soon
155 }
156 167
157 mortals.push_back (this); 168 mortals.push_back (this);
158} 169}
159 170
160void 171void
337inline SV *to_sv (treasurelist * v) { return to_sv (v->name); } 348inline SV *to_sv (treasurelist * v) { return to_sv (v->name); }
338 349
339inline SV *to_sv (UUID v) 350inline SV *to_sv (UUID v)
340{ 351{
341 char buf[128]; 352 char buf[128];
342 snprintf (buf, 128, "<1,%" PRIx64 ">", v.seq); 353 snprintf (buf, 128, "<1.%" PRIx64 ">", v.seq);
343 return newSVpv (buf, 0); 354 return newSVpv (buf, 0);
344} 355}
345 356
346inline 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; }
347inline 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; }
594 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))
595 { 606 {
596 printf ("unable to initialize perl-interpreter, aborting.\n"); 607 printf ("unable to initialize perl-interpreter, aborting.\n");
597 exit (EXIT_FAILURE); 608 exit (EXIT_FAILURE);
598 } 609 }
610
611 {
612 dSP;
613
614 PUSHMARK (SP);
615 PUTBACK;
616 call_pv ("cf::init", G_DISCARD | G_VOID);
617 }
599} 618}
600 619
601void cfperl_main () 620void cfperl_main ()
602{ 621{
603 dSP; 622 dSP;
1639 1658
1640void cleanup (const char *cause, bool make_core = false) 1659void cleanup (const char *cause, bool make_core = false)
1641 1660
1642void emergency_save () 1661void emergency_save ()
1643 1662
1663void _exit (int status = EXIT_SUCCESS)
1664
1644UV sv_2watcher (SV *w) 1665UV sv_2watcher (SV *w)
1645 CODE: 1666 CODE:
1646 RETVAL = (UV)GEventAPI->sv_2watcher (w); 1667 RETVAL = (UV)GEventAPI->sv_2watcher (w);
1647 OUTPUT: 1668 OUTPUT:
1648 RETVAL 1669 RETVAL
1649
1650void _exit (int status = 0)
1651 1670
1652#if _POSIX_MEMLOCK 1671#if _POSIX_MEMLOCK
1653 1672
1654int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) 1673int mlockall (int flags = MCL_CURRENT | MCL_FUTURE)
1655 1674
1701 RETVAL = newSVpv (resist_plus[atnr], 0); 1720 RETVAL = newSVpv (resist_plus[atnr], 0);
1702 else 1721 else
1703 XSRETURN_UNDEF; 1722 XSRETURN_UNDEF;
1704 OUTPUT: RETVAL 1723 OUTPUT: RETVAL
1705 1724
1725bool
1726load_regions (const char *filename)
1727 CODE:
1728 RETVAL = loader_region ().load (filename);
1729 OUTPUT: RETVAL
1730
1706MODULE = cf PACKAGE = cf::attachable 1731MODULE = cf PACKAGE = cf::attachable
1707 1732
1708int 1733int
1709valid (SV *obj) 1734valid (SV *obj)
1710 CODE: 1735 CODE:
1794 1819
1795void 1820void
1796set_animation (object *op, int idx) 1821set_animation (object *op, int idx)
1797 CODE: 1822 CODE:
1798 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
1799 1830
1800object *find_best_object_match (object *op, const char *match) 1831object *find_best_object_match (object *op, const char *match)
1801 1832
1802object *find_marked_object (object *op) 1833object *find_marked_object (object *op)
1803 1834
2040 pl->orig_stats = pl->ob->stats; 2071 pl->orig_stats = pl->ob->stats;
2041 2072
2042void cf_player_move (player *pl, int dir) 2073void cf_player_move (player *pl, int dir)
2043 2074
2044void 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);
2045
2046player *first ()
2047 CODE:
2048 RETVAL = first_player;
2049 OUTPUT: RETVAL
2050 2076
2051bool 2077bool
2052cell_visible (player *pl, int dx, int dy) 2078cell_visible (player *pl, int dx, int dy)
2053 CODE: 2079 CODE:
2054 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
2131 EXTEND (SP, THIS->players); 2157 EXTEND (SP, THIS->players);
2132 for_all_players (pl) 2158 for_all_players (pl)
2133 if (pl->ob && pl->ob->map == THIS) 2159 if (pl->ob && pl->ob->map == THIS)
2134 PUSHs (sv_2mortal (to_sv (pl->ob))); 2160 PUSHs (sv_2mortal (to_sv (pl->ob)));
2135 } 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}
2136 2180
2137void 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)
2138 2182
2139int out_of_map (maptile *map, int x, int y) 2183int out_of_map (maptile *map, int x, int y)
2140 2184
2221 OUTPUT: RETVAL 2265 OUTPUT: RETVAL
2222 2266
2223void fix_walls (maptile *map, int x, int y) 2267void fix_walls (maptile *map, int x, int y)
2224 2268
2225void fix_walls_around (maptile *map, int x, int y) 2269void fix_walls_around (maptile *map, int x, int y)
2226
2227const char *
2228region_name (maptile *m)
2229 CODE:
2230 RETVAL = get_name_of_region_for_map (m);
2231 OUTPUT: RETVAL
2232 2270
2233# worst xs function of my life 2271# worst xs function of my life
2234bool 2272bool
2235_create_random_map (\ 2273_create_random_map (\
2236 maptile *self,\ 2274 maptile *self,\
2344 2382
2345INCLUDE: $PERL genacc partylist ../include/player.h | 2383INCLUDE: $PERL genacc partylist ../include/player.h |
2346 2384
2347MODULE = cf PACKAGE = cf::region 2385MODULE = cf PACKAGE = cf::region
2348 2386
2349region *first () 2387void
2350 PROTOTYPE: 2388list ()
2351 CODE: 2389 PPCODE:
2352 RETVAL = first_region; 2390 for_all_regions (rgn)
2353 OUTPUT: RETVAL 2391 XPUSHs (sv_2mortal (to_sv (rgn)));
2354 2392
2355region *find (char *name) 2393region *find (char *name)
2356 PROTOTYPE: $ 2394 PROTOTYPE: $
2357 CODE: 2395 CODE:
2358 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);
2359 OUTPUT: RETVAL 2403 OUTPUT: RETVAL
2360 2404
2361INCLUDE: $PERL genacc region ../include/map.h | 2405INCLUDE: $PERL genacc region ../include/map.h |
2362 2406
2363MODULE = cf PACKAGE = cf::living 2407MODULE = cf PACKAGE = cf::living

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines