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.172 by pippijn, Fri Mar 2 15:25:37 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
1819 1854
1820int need_identify (object *obj); 1855int need_identify (object *obj);
1821 1856
1822int apply_shop_mat (object *shop_mat, object *op); 1857int apply_shop_mat (object *shop_mat, object *op);
1823 1858
1859int move_player (object *op, int dir)
1860 CODE:
1861 RETVAL = move_player (op, dir);
1862 OUTPUT:
1863 RETVAL
1864
1824int move (object *op, int dir, object *originator = op) 1865int move (object *op, int dir, object *originator = op)
1825 CODE: 1866 CODE:
1826 RETVAL = move_ob (op, dir, originator); 1867 RETVAL = move_ob (op, dir, originator);
1827 OUTPUT: 1868 OUTPUT:
1828 RETVAL 1869 RETVAL
1832 manual_apply (applied, applier, flags); 1873 manual_apply (applied, applier, flags);
1833 1874
1834void apply_below (object *op) 1875void apply_below (object *op)
1835 CODE: 1876 CODE:
1836 player_apply_below (op); 1877 player_apply_below (op);
1878
1879int cast_heal (object *op, object *caster, object *spell, int dir = 0)
1837 1880
1838object *cf_object_present_archname_inside (object *op, char *whatstr) 1881object *cf_object_present_archname_inside (object *op, char *whatstr)
1839 1882
1840int cf_object_transfer (object *op, int x, int y, int r = 0, object_ornull *orig = 0) 1883int cf_object_transfer (object *op, int x, int y, int r = 0, object_ornull *orig = 0)
1841 1884
2026 2069
2027int command_summon (object *op, char *params) 2070int command_summon (object *op, char *params)
2028 2071
2029int command_arrest (object *op, char *params) 2072int command_arrest (object *op, char *params)
2030 2073
2031int command_kick (object *op, char *params)
2032
2033int command_banish (object *op, char *params) 2074int command_banish (object *op, char *params)
2034 2075
2035 2076
2036MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ 2077MODULE = cf PACKAGE = cf::player PREFIX = cf_player_
2037 2078
2056 pl->orig_stats = pl->ob->stats; 2097 pl->orig_stats = pl->ob->stats;
2057 2098
2058void cf_player_move (player *pl, int dir) 2099void cf_player_move (player *pl, int dir)
2059 2100
2060void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0); 2101void 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 2102
2067bool 2103bool
2068cell_visible (player *pl, int dx, int dy) 2104cell_visible (player *pl, int dx, int dy)
2069 CODE: 2105 CODE:
2070 RETVAL = FABS (dx) <= pl->ns->mapx / 2 && FABS (dy) <= pl->ns->mapy / 2 2106 RETVAL = FABS (dx) <= pl->ns->mapx / 2 && FABS (dy) <= pl->ns->mapy / 2
2149 if (pl->ob && pl->ob->map == THIS) 2185 if (pl->ob && pl->ob->map == THIS)
2150 PUSHs (sv_2mortal (to_sv (pl->ob))); 2186 PUSHs (sv_2mortal (to_sv (pl->ob)));
2151 } 2187 }
2152 2188
2153void 2189void
2154maptile::set_regiondata (SV *data, SV *plt) 2190maptile::add_underlay (SV *data, int offset, int stride, SV *palette)
2155 CODE: 2191 CODE:
2156{ 2192{
2157 if (!SvROK (plt) || SvTYPE (SvRV (plt)) != SVt_PVAV) 2193 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV)
2194 croak ("maptile::add_underlay: palette must be arrayref");
2195
2196 palette = SvRV (palette);
2197
2198 STRLEN idxlen;
2199 const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen);
2200
2201 for (int x = 0; x < THIS->width; ++x)
2202 for (int y = 0; y < THIS->height; ++y)
2203 {
2204 for (object *op = THIS->at (x, y).bot; op; op = op->above)
2205 if (op->flag [FLAG_IS_FLOOR])
2206 goto skip_space;
2207
2208 {
2209 int offs = offset + y * stride + x;
2210 if (IN_RANGE_EXC (offs, 0, idxlen))
2211 {
2212 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0))
2213 {
2214 object *ob = get_archetype (SvPVutf8_nolen (*elem));
2215 ob->flag [FLAG_NO_MAP_SAVE] = true;
2216 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY);
2217 }
2218 }
2219 }
2220
2221 skip_space: ;
2222 }
2223}
2224
2225void
2226maptile::set_regiondata (SV *data, int offset, int stride, SV *palette)
2227 CODE:
2228{
2229 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV)
2158 croak ("maptile::set_regiondata needs arrayref as plt arg"); 2230 croak ("maptile::set_regiondata: palette must be arrayref");
2159 2231
2160 AV *av = (AV *)SvRV (plt); 2232 palette = SvRV (palette);
2161 2233
2162 region **regionmap = (region **)malloc ((av_len (av) + 1) * sizeof (region *)); 2234 STRLEN idxlen;
2235 const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen);
2163 2236
2237 region **regionmap = (region **)malloc (
2238 (av_len ((AV *)palette) + 1) * sizeof (region *));
2239 uint8_t *regions = salloc<uint8_t> (THIS->size ());
2240
2164 for (int i = av_len (av) + 1; i--; ) 2241 for (int i = av_len ((AV *)palette) + 1; i--; )
2165 regionmap [i] = region::find (SvPVutf8_nolen (*av_fetch (av, i, 1))); 2242 regionmap [i] = region::find (
2243 SvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1)));
2166 2244
2167 THIS->regions = salloc<uint8_t> (THIS->size (), (uint8_t *)SvPVbyte_nolen (data)); 2245 for (int y = 0; y < THIS->height; ++y)
2246 memcpy (regions + y * THIS->width, idx + offset + y * stride, THIS->width);
2247
2248 sfree (THIS->regions, THIS->size ());
2249 free (THIS->regionmap);
2250
2251 THIS->regions = regions;
2168 THIS->regionmap = regionmap; 2252 THIS->regionmap = regionmap;
2169} 2253}
2170 2254
2171void play_sound_map (maptile *map, int x, int y, int sound_num) 2255void play_sound_map (maptile *map, int x, int y, int sound_num)
2172 2256
2372 2456
2373INCLUDE: $PERL genacc partylist ../include/player.h | 2457INCLUDE: $PERL genacc partylist ../include/player.h |
2374 2458
2375MODULE = cf PACKAGE = cf::region 2459MODULE = cf PACKAGE = cf::region
2376 2460
2377region *first () 2461void
2378 PROTOTYPE: 2462list ()
2379 CODE: 2463 PPCODE:
2380 RETVAL = first_region; 2464 for_all_regions (rgn)
2381 OUTPUT: RETVAL 2465 XPUSHs (sv_2mortal (to_sv (rgn)));
2382 2466
2383region *find (char *name) 2467region *find (char *name)
2384 PROTOTYPE: $ 2468 PROTOTYPE: $
2385 CODE: 2469 CODE:
2386 RETVAL = region::find (name); 2470 RETVAL = region::find (name);
2387 OUTPUT: RETVAL 2471 OUTPUT: RETVAL
2388 2472
2473region *find_fuzzy (char *name)
2474 PROTOTYPE: $
2475 CODE:
2476 RETVAL = region::find_fuzzy (name);
2477 OUTPUT: RETVAL
2478
2389INCLUDE: $PERL genacc region ../include/map.h | 2479INCLUDE: $PERL genacc region ../include/map.h |
2390 2480
2391MODULE = cf PACKAGE = cf::living 2481MODULE = cf PACKAGE = cf::living
2392 2482
2393INCLUDE: $PERL genacc living ../include/living.h | 2483INCLUDE: $PERL genacc living ../include/living.h |

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines