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.170 by root, Fri Feb 16 19:43:41 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
2056 pl->orig_stats = pl->ob->stats; 2093 pl->orig_stats = pl->ob->stats;
2057 2094
2058void cf_player_move (player *pl, int dir) 2095void cf_player_move (player *pl, int dir)
2059 2096
2060void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0); 2097void 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 2098
2067bool 2099bool
2068cell_visible (player *pl, int dx, int dy) 2100cell_visible (player *pl, int dx, int dy)
2069 CODE: 2101 CODE:
2070 RETVAL = FABS (dx) <= pl->ns->mapx / 2 && FABS (dy) <= pl->ns->mapy / 2 2102 RETVAL = FABS (dx) <= pl->ns->mapx / 2 && FABS (dy) <= pl->ns->mapy / 2
2149 if (pl->ob && pl->ob->map == THIS) 2181 if (pl->ob && pl->ob->map == THIS)
2150 PUSHs (sv_2mortal (to_sv (pl->ob))); 2182 PUSHs (sv_2mortal (to_sv (pl->ob)));
2151 } 2183 }
2152 2184
2153void 2185void
2154maptile::set_regiondata (SV *data, SV *plt) 2186maptile::add_underlay (SV *data, int offset, int stride, SV *palette)
2155 CODE: 2187 CODE:
2156{ 2188{
2157 if (!SvROK (plt) || SvTYPE (SvRV (plt)) != SVt_PVAV) 2189 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV)
2190 croak ("maptile::add_underlay: palette must be arrayref");
2191
2192 palette = SvRV (palette);
2193
2194 STRLEN idxlen;
2195 const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen);
2196
2197 for (int x = 0; x < THIS->width; ++x)
2198 for (int y = 0; y < THIS->height; ++y)
2199 {
2200 for (object *op = THIS->at (x, y).bot; op; op = op->above)
2201 if (op->flag [FLAG_IS_FLOOR])
2202 goto skip_space;
2203
2204 {
2205 int offs = offset + y * stride + x;
2206 if (IN_RANGE_EXC (offs, 0, idxlen))
2207 {
2208 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0))
2209 {
2210 object *ob = get_archetype (SvPVutf8_nolen (*elem));
2211 ob->flag [FLAG_NO_MAP_SAVE] = true;
2212 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY);
2213 }
2214 }
2215 }
2216
2217 skip_space: ;
2218 }
2219}
2220
2221void
2222maptile::set_regiondata (SV *data, int offset, int stride, SV *palette)
2223 CODE:
2224{
2225 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV)
2158 croak ("maptile::set_regiondata needs arrayref as plt arg"); 2226 croak ("maptile::set_regiondata: palette must be arrayref");
2159 2227
2160 AV *av = (AV *)SvRV (plt); 2228 palette = SvRV (palette);
2161 2229
2162 region **regionmap = (region **)malloc ((av_len (av) + 1) * sizeof (region *)); 2230 STRLEN idxlen;
2231 const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen);
2163 2232
2233 region **regionmap = (region **)malloc (
2234 (av_len ((AV *)palette) + 1) * sizeof (region *));
2235 uint8_t *regions = salloc<uint8_t> (THIS->size ());
2236
2164 for (int i = av_len (av) + 1; i--; ) 2237 for (int i = av_len ((AV *)palette) + 1; i--; )
2165 regionmap [i] = region::find (SvPVutf8_nolen (*av_fetch (av, i, 1))); 2238 regionmap [i] = region::find (
2239 SvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1)));
2166 2240
2167 THIS->regions = salloc<uint8_t> (THIS->size (), (uint8_t *)SvPVbyte_nolen (data)); 2241 for (int y = 0; y < THIS->height; ++y)
2242 memcpy (regions + y * THIS->width, idx + offset + y * stride, THIS->width);
2243
2244 sfree (THIS->regions, THIS->size ());
2245 free (THIS->regionmap);
2246
2247 THIS->regions = regions;
2168 THIS->regionmap = regionmap; 2248 THIS->regionmap = regionmap;
2169} 2249}
2170 2250
2171void play_sound_map (maptile *map, int x, int y, int sound_num) 2251void play_sound_map (maptile *map, int x, int y, int sound_num)
2172 2252
2372 2452
2373INCLUDE: $PERL genacc partylist ../include/player.h | 2453INCLUDE: $PERL genacc partylist ../include/player.h |
2374 2454
2375MODULE = cf PACKAGE = cf::region 2455MODULE = cf PACKAGE = cf::region
2376 2456
2377region *first () 2457void
2378 PROTOTYPE: 2458list ()
2379 CODE: 2459 PPCODE:
2380 RETVAL = first_region; 2460 for_all_regions (rgn)
2381 OUTPUT: RETVAL 2461 XPUSHs (sv_2mortal (to_sv (rgn)));
2382 2462
2383region *find (char *name) 2463region *find (char *name)
2384 PROTOTYPE: $ 2464 PROTOTYPE: $
2385 CODE: 2465 CODE:
2386 RETVAL = region::find (name); 2466 RETVAL = region::find (name);
2387 OUTPUT: RETVAL 2467 OUTPUT: RETVAL
2388 2468
2469region *find_fuzzy (char *name)
2470 PROTOTYPE: $
2471 CODE:
2472 RETVAL = region::find_fuzzy (name);
2473 OUTPUT: RETVAL
2474
2389INCLUDE: $PERL genacc region ../include/map.h | 2475INCLUDE: $PERL genacc region ../include/map.h |
2390 2476
2391MODULE = cf PACKAGE = cf::living 2477MODULE = cf PACKAGE = cf::living
2392 2478
2393INCLUDE: $PERL genacc living ../include/living.h | 2479INCLUDE: $PERL genacc living ../include/living.h |

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines