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.160 by elmex, Wed Jan 31 14:11:02 2007 UTC vs.
Revision 1.171 by pippijn, Fri Mar 2 13:32:52 2007 UTC

4 4
5/* 5/*
6 * This code is placed under the GNU General Public Licence (GPL) 6 * This code is placed under the GNU General Public Licence (GPL)
7 * 7 *
8 * Copyright (C) 2001-2005 by Chachkoff Yann 8 * Copyright (C) 2001-2005 by Chachkoff Yann
9 * Copyright (C) 2006 by Marc Lehmann <cf@schmorp.de> 9 * Copyright (C) 2006,2007 by Marc Lehmann <cf@schmorp.de>
10 * 10 *
11 * This program is free software; you can redistribute it and/or modify 11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by 12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or 13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version. 14 * (at your option) any later version.
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
101 102
102unordered_vector<attachable *> attachable::mortals; 103unordered_vector<attachable *> attachable::mortals;
103 104
104attachable::~attachable () 105attachable::~attachable ()
105{ 106{
107 flags |=0x3300;//D
106 assert (!self); 108 assert (!self);
107 assert (!cb); 109 assert (!cb);
108} 110}
109 111
110int 112int
126 sv_unmagic ((SV *)self, PERL_MAGIC_ext); 128 sv_unmagic ((SV *)self, PERL_MAGIC_ext);
127 SvREFCNT_dec (self); 129 SvREFCNT_dec (self);
128 130
129 // self *must* be null now because thats sv_unmagic's job. 131 // self *must* be null now because thats sv_unmagic's job.
130 assert (!this->self); 132 assert (!this->self);
133 flags |= 0x80; // severed //D
131 } 134 }
132} 135}
133 136
134void 137void
135attachable::optimise () 138attachable::optimise ()
136{ 139{
137 if (self 140 if (self
138 && SvREFCNT (self) == 1 141 && SvREFCNT (self) == 1
139 && !HvTOTALKEYS (self)) 142 && !HvTOTALKEYS (self))
143 flags |= 0x40,//D
140 sever_self (); 144 sever_self ();
141} 145}
142 146
143// check wether the object really is dead 147// check wether the object really is dead
144void 148void
162 } 166 }
163 167
164 if (self) 168 if (self)
165 sever_self (); 169 sever_self ();
166 170
171 flags |= 0x20; //D
167 mortals.push_back (this); 172 mortals.push_back (this);
168} 173}
169 174
170void 175void
171attachable::destroy () 176attachable::destroy ()
266 271
267 if (!obj->self) 272 if (!obj->self)
268 { 273 {
269 obj->self = newHV (); 274 obj->self = newHV ();
270 sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &attachable::vtbl, (char *)obj, 0); 275 sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &attachable::vtbl, (char *)obj, 0);
276 obj->flags |= (obj->flags & 0xc0) << 8;
277 obj->flags &= ~0xc0;//D
278 obj->flags |= 0x10;//D
271 279
272 // now bless the object _once_ 280 // now bless the object _once_
273 return sv_bless (newRV_inc ((SV *)obj->self), stash); 281 return sv_bless (newRV_inc ((SV *)obj->self), stash);
274 } 282 }
275 else 283 else
604 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl)) 612 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl))
605 { 613 {
606 printf ("unable to initialize perl-interpreter, aborting.\n"); 614 printf ("unable to initialize perl-interpreter, aborting.\n");
607 exit (EXIT_FAILURE); 615 exit (EXIT_FAILURE);
608 } 616 }
617
618 {
619 dSP;
620
621 PUSHMARK (SP);
622 PUTBACK;
623 call_pv ("cf::init", G_DISCARD | G_VOID);
624 }
609} 625}
610 626
611void cfperl_main () 627void cfperl_main ()
612{ 628{
613 dSP; 629 dSP;
831void 847void
832cfperl_emergency_save () 848cfperl_emergency_save ()
833{ 849{
834 CALL_BEGIN (0); 850 CALL_BEGIN (0);
835 CALL_CALL ("cf::emergency_save", G_VOID); 851 CALL_CALL ("cf::emergency_save", G_VOID);
852 CALL_END;
853}
854
855void
856cfperl_cleanup (int make_core)
857{
858 CALL_BEGIN (1);
859 CALL_ARG (make_core);
860 CALL_CALL ("cf::post_cleanup", G_VOID);
836 CALL_END; 861 CALL_END;
837} 862}
838 863
839maptile * 864maptile *
840maptile::find_sync (const char *path, maptile *origin) 865maptile::find_sync (const char *path, maptile *origin)
1711 RETVAL = newSVpv (resist_plus[atnr], 0); 1736 RETVAL = newSVpv (resist_plus[atnr], 0);
1712 else 1737 else
1713 XSRETURN_UNDEF; 1738 XSRETURN_UNDEF;
1714 OUTPUT: RETVAL 1739 OUTPUT: RETVAL
1715 1740
1741bool
1742load_resource_file (const char *filename)
1743
1716MODULE = cf PACKAGE = cf::attachable 1744MODULE = cf PACKAGE = cf::attachable
1717 1745
1718int 1746int
1719valid (SV *obj) 1747valid (SV *obj)
1720 CODE: 1748 CODE:
1721 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); 1749 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext);
1722 OUTPUT: 1750 OUTPUT:
1723 RETVAL 1751 RETVAL
1752
1753void
1754debug_trace (attachable *obj, bool on = true)
1755 CODE:
1756 obj->flags &= ~attachable::F_DEBUG_TRACE;
1757 if (on)
1758 obj->flags |= attachable::F_DEBUG_TRACE;
1724 1759
1725int mortals_size () 1760int mortals_size ()
1726 CODE: 1761 CODE:
1727 RETVAL = attachable::mortals.size (); 1762 RETVAL = attachable::mortals.size ();
1728 OUTPUT: RETVAL 1763 OUTPUT: RETVAL
1832 manual_apply (applied, applier, flags); 1867 manual_apply (applied, applier, flags);
1833 1868
1834void apply_below (object *op) 1869void apply_below (object *op)
1835 CODE: 1870 CODE:
1836 player_apply_below (op); 1871 player_apply_below (op);
1872
1873int cast_heal (object *op, object *caster, object *spell, int dir = 0)
1837 1874
1838object *cf_object_present_archname_inside (object *op, char *whatstr) 1875object *cf_object_present_archname_inside (object *op, char *whatstr)
1839 1876
1840int cf_object_transfer (object *op, int x, int y, int r = 0, object_ornull *orig = 0) 1877int cf_object_transfer (object *op, int x, int y, int r = 0, object_ornull *orig = 0)
1841 1878
2026 2063
2027int command_summon (object *op, char *params) 2064int command_summon (object *op, char *params)
2028 2065
2029int command_arrest (object *op, char *params) 2066int command_arrest (object *op, char *params)
2030 2067
2031int command_kick (object *op, char *params)
2032
2033int command_banish (object *op, char *params) 2068int command_banish (object *op, char *params)
2034 2069
2035 2070
2036MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ 2071MODULE = cf PACKAGE = cf::player PREFIX = cf_player_
2037 2072
2056 pl->orig_stats = pl->ob->stats; 2091 pl->orig_stats = pl->ob->stats;
2057 2092
2058void cf_player_move (player *pl, int dir) 2093void cf_player_move (player *pl, int dir)
2059 2094
2060void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0); 2095void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0);
2061
2062player *first ()
2063 CODE:
2064 RETVAL = first_player;
2065 OUTPUT: RETVAL
2066 2096
2067bool 2097bool
2068cell_visible (player *pl, int dx, int dy) 2098cell_visible (player *pl, int dx, int dy)
2069 CODE: 2099 CODE:
2070 RETVAL = FABS (dx) <= pl->ns->mapx / 2 && FABS (dy) <= pl->ns->mapy / 2 2100 RETVAL = FABS (dx) <= pl->ns->mapx / 2 && FABS (dy) <= pl->ns->mapy / 2
2149 if (pl->ob && pl->ob->map == THIS) 2179 if (pl->ob && pl->ob->map == THIS)
2150 PUSHs (sv_2mortal (to_sv (pl->ob))); 2180 PUSHs (sv_2mortal (to_sv (pl->ob)));
2151 } 2181 }
2152 2182
2153void 2183void
2154maptile::set_regiondata (SV *data, SV *plt) 2184maptile::add_underlay (SV *data, int offset, int stride, SV *palette)
2155 CODE: 2185 CODE:
2156{ 2186{
2157 if (!SvROK (plt) || SvTYPE (SvRV (plt)) != SVt_PVAV) 2187 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV)
2188 croak ("maptile::add_underlay: palette must be arrayref");
2189
2190 palette = SvRV (palette);
2191
2192 STRLEN idxlen;
2193 const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen);
2194
2195 for (int x = 0; x < THIS->width; ++x)
2196 for (int y = 0; y < THIS->height; ++y)
2197 {
2198 for (object *op = THIS->at (x, y).bot; op; op = op->above)
2199 if (op->flag [FLAG_IS_FLOOR])
2200 goto skip_space;
2201
2202 {
2203 int offs = offset + y * stride + x;
2204 if (IN_RANGE_EXC (offs, 0, idxlen))
2205 {
2206 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0))
2207 {
2208 object *ob = get_archetype (SvPVutf8_nolen (*elem));
2209 ob->flag [FLAG_NO_MAP_SAVE] = true;
2210 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY);
2211 }
2212 }
2213 }
2214
2215 skip_space: ;
2216 }
2217}
2218
2219void
2220maptile::set_regiondata (SV *data, int offset, int stride, SV *palette)
2221 CODE:
2222{
2223 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV)
2158 croak ("maptile::set_regiondata needs arrayref as plt arg"); 2224 croak ("maptile::set_regiondata: palette must be arrayref");
2159 2225
2160 AV *av = (AV *)SvRV (plt); 2226 palette = SvRV (palette);
2161 2227
2162 region **regionmap = (region **)malloc ((av_len (av) + 1) * sizeof (region *)); 2228 STRLEN idxlen;
2229 const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen);
2163 2230
2231 region **regionmap = (region **)malloc (
2232 (av_len ((AV *)palette) + 1) * sizeof (region *));
2233 uint8_t *regions = salloc<uint8_t> (THIS->size ());
2234
2164 for (int i = av_len (av) + 1; i--; ) 2235 for (int i = av_len ((AV *)palette) + 1; i--; )
2165 regionmap [i] = region::find (SvPVutf8_nolen (*av_fetch (av, i, 1))); 2236 regionmap [i] = region::find (
2237 SvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1)));
2166 2238
2167 THIS->regions = salloc<uint8_t> (THIS->size (), (uint8_t *)SvPVbyte_nolen (data)); 2239 for (int y = 0; y < THIS->height; ++y)
2240 memcpy (regions + y * THIS->width, idx + offset + y * stride, THIS->width);
2241
2242 sfree (THIS->regions, THIS->size ());
2243 free (THIS->regionmap);
2244
2245 THIS->regions = regions;
2168 THIS->regionmap = regionmap; 2246 THIS->regionmap = regionmap;
2169} 2247}
2170 2248
2171void play_sound_map (maptile *map, int x, int y, int sound_num) 2249void play_sound_map (maptile *map, int x, int y, int sound_num)
2172 2250
2372 2450
2373INCLUDE: $PERL genacc partylist ../include/player.h | 2451INCLUDE: $PERL genacc partylist ../include/player.h |
2374 2452
2375MODULE = cf PACKAGE = cf::region 2453MODULE = cf PACKAGE = cf::region
2376 2454
2377region *first () 2455void
2378 PROTOTYPE: 2456list ()
2379 CODE: 2457 PPCODE:
2380 RETVAL = first_region; 2458 for_all_regions (rgn)
2381 OUTPUT: RETVAL 2459 XPUSHs (sv_2mortal (to_sv (rgn)));
2382 2460
2383region *find (char *name) 2461region *find (char *name)
2384 PROTOTYPE: $ 2462 PROTOTYPE: $
2385 CODE: 2463 CODE:
2386 RETVAL = region::find (name); 2464 RETVAL = region::find (name);
2387 OUTPUT: RETVAL 2465 OUTPUT: RETVAL
2388 2466
2467region *find_fuzzy (char *name)
2468 PROTOTYPE: $
2469 CODE:
2470 RETVAL = region::find_fuzzy (name);
2471 OUTPUT: RETVAL
2472
2389INCLUDE: $PERL genacc region ../include/map.h | 2473INCLUDE: $PERL genacc region ../include/map.h |
2390 2474
2391MODULE = cf PACKAGE = cf::living 2475MODULE = cf PACKAGE = cf::living
2392 2476
2393INCLUDE: $PERL genacc living ../include/living.h | 2477INCLUDE: $PERL genacc living ../include/living.h |

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines