… | |
… | |
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 | |
102 | unordered_vector<attachable *> attachable::mortals; |
103 | unordered_vector<attachable *> attachable::mortals; |
103 | |
104 | |
104 | attachable::~attachable () |
105 | attachable::~attachable () |
105 | { |
106 | { |
106 | assert (!(flags & F_BORROWED)); |
107 | assert (!self); |
|
|
108 | assert (!cb); |
107 | } |
109 | } |
108 | |
110 | |
109 | int |
111 | int |
110 | attachable::refcnt_cnt () const |
112 | attachable::refcnt_cnt () const |
111 | { |
113 | { |
112 | return refcnt + (self ? SvREFCNT (self) : 0); |
114 | return refcnt + (self ? SvREFCNT (self) - 1 : 0); |
|
|
115 | } |
|
|
116 | |
|
|
117 | void |
|
|
118 | attachable::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 | } |
113 | } |
133 | } |
114 | |
134 | |
115 | void |
135 | void |
116 | attachable::optimise () |
136 | attachable::optimise () |
117 | { |
137 | { |
118 | if (self |
138 | if (self |
119 | && SvREFCNT (self) == 1 |
139 | && SvREFCNT (self) == 1 |
120 | && !HvTOTALKEYS (self)) |
140 | && !HvTOTALKEYS (self)) |
|
|
141 | sever_self (); |
|
|
142 | } |
|
|
143 | |
|
|
144 | // check wether the object really is dead |
|
|
145 | void |
|
|
146 | attachable::do_check () |
|
|
147 | { |
|
|
148 | if (refcnt_cnt () > 0) |
|
|
149 | return; |
|
|
150 | |
|
|
151 | destroy (); |
|
|
152 | } |
|
|
153 | |
|
|
154 | void |
|
|
155 | attachable::do_destroy () |
|
|
156 | { |
|
|
157 | invoke (EVENT_ATTACHABLE_DESTROY, DT_END); |
|
|
158 | |
|
|
159 | if (cb) |
121 | { |
160 | { |
122 | flags &= ~F_BORROWED; |
|
|
123 | refcnt_inc (); |
|
|
124 | SvREFCNT_dec ((SV *)self); |
161 | SvREFCNT_dec (cb); |
|
|
162 | cb = 0; |
125 | } |
163 | } |
126 | } |
|
|
127 | |
|
|
128 | // check wether the object really is dead |
|
|
129 | void |
|
|
130 | attachable::do_check () |
|
|
131 | { |
|
|
132 | if (refcnt > 0) |
|
|
133 | return; |
|
|
134 | |
|
|
135 | optimise (); |
|
|
136 | |
164 | |
137 | if (self) |
165 | if (self) |
138 | { |
166 | sever_self (); |
139 | if (refcnt + SvREFCNT (self) > 0) |
|
|
140 | return; |
|
|
141 | |
|
|
142 | assert (flags & F_BORROWED); |
|
|
143 | |
|
|
144 | flags &= ~F_BORROWED; |
|
|
145 | refcnt_inc (); |
|
|
146 | SvREFCNT_dec (self); |
|
|
147 | self = 0; |
|
|
148 | } |
|
|
149 | |
|
|
150 | if (refcnt > 0) |
|
|
151 | return; |
|
|
152 | |
|
|
153 | destroy (); |
|
|
154 | } |
|
|
155 | |
|
|
156 | void |
|
|
157 | attachable::do_destroy () |
|
|
158 | { |
|
|
159 | invoke (EVENT_ATTACHABLE_DESTROY, DT_END); |
|
|
160 | |
|
|
161 | if (self) |
|
|
162 | hv_clear (self); |
|
|
163 | |
167 | |
164 | mortals.push_back (this); |
168 | mortals.push_back (this); |
165 | } |
169 | } |
166 | |
170 | |
167 | void |
171 | void |
… | |
… | |
175 | } |
179 | } |
176 | |
180 | |
177 | void |
181 | void |
178 | attachable::check_mortals () |
182 | attachable::check_mortals () |
179 | { |
183 | { |
180 | for (int i = 0; i < mortals.size (); ) |
184 | static int i = 0; |
|
|
185 | |
|
|
186 | for (;;) |
181 | { |
187 | { |
|
|
188 | if (i >= mortals.size ()) |
|
|
189 | { |
|
|
190 | i = 0; |
|
|
191 | |
|
|
192 | if (mortals.size () > 1000) |
|
|
193 | fprintf (stderr, "mortal queue size (%d) exceeds 1000.\n", (int)mortals.size ()); |
|
|
194 | |
|
|
195 | break; |
|
|
196 | } |
|
|
197 | |
182 | attachable *obj = mortals [i]; |
198 | attachable *obj = mortals [i]; |
183 | |
199 | |
184 | obj->refcnt_chk (); // unborrow from perl, if necessary |
200 | obj->refcnt_chk (); // unborrow from perl, if necessary |
185 | |
201 | |
|
|
202 | //if (obj->refcnt > 0 || obj->self) |
186 | if (obj->refcnt || obj->self) |
203 | if (obj->refcnt || obj->self) |
187 | { |
204 | { |
188 | #if 0 |
205 | //printf ("%p rc %d\n", obj, obj->refcnt_cnt ());//D |
189 | if (mortals.size() > 5)fprintf (stderr, "%d delaying %d:%p:%s %d (self %p:%d)\n", time(0),i, obj, typeid (*obj).name (), |
|
|
190 | obj->refcnt, obj->self, obj->self ? SvREFCNT(obj->self): - 1);//D |
|
|
191 | #endif |
|
|
192 | |
|
|
193 | ++i; // further delay freeing |
206 | ++i; // further delay freeing |
|
|
207 | |
|
|
208 | if (!(i & 0x3ff)) |
|
|
209 | break; |
194 | }//D |
210 | } |
195 | else |
211 | else |
196 | { |
212 | { |
197 | //Dfprintf (stderr, "deleteing %d:%p:%s\n", i, obj,typeid (*obj).name ());//D |
|
|
198 | mortals.erase (i); |
213 | mortals.erase (i); |
199 | delete obj; |
214 | delete obj; |
200 | } |
215 | } |
201 | } |
216 | } |
202 | } |
217 | } |
… | |
… | |
227 | |
242 | |
228 | static int |
243 | static int |
229 | attachable_free (pTHX_ SV *sv, MAGIC *mg) |
244 | attachable_free (pTHX_ SV *sv, MAGIC *mg) |
230 | { |
245 | { |
231 | attachable *at = (attachable *)mg->mg_ptr; |
246 | attachable *at = (attachable *)mg->mg_ptr; |
232 | assert (!(at->flags & attachable::F_BORROWED)); |
247 | |
|
|
248 | //TODO: check if transaction behaviour is really required here |
|
|
249 | if (SV *self = (SV *)at->self) |
|
|
250 | { |
233 | at->self = 0; |
251 | at->self = 0; |
|
|
252 | SvREFCNT_dec (self); |
|
|
253 | } |
|
|
254 | |
234 | // next line makes sense, but most objects still have refcnt 0 by default |
255 | // next line makes sense, but most objects still have refcnt 0 by default |
235 | //at->refcnt_chk (); |
256 | //at->refcnt_chk (); |
236 | return 0; |
257 | return 0; |
237 | } |
258 | } |
238 | |
259 | |
… | |
… | |
247 | if (!obj->self) |
268 | if (!obj->self) |
248 | { |
269 | { |
249 | obj->self = newHV (); |
270 | obj->self = newHV (); |
250 | sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &attachable::vtbl, (char *)obj, 0); |
271 | sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &attachable::vtbl, (char *)obj, 0); |
251 | |
272 | |
252 | // borrow the refcnt from the object |
|
|
253 | obj->flags |= attachable::F_BORROWED; |
|
|
254 | obj->refcnt_dec (); |
|
|
255 | |
|
|
256 | // now bless the object _once_ |
273 | // now bless the object _once_ |
257 | return sv_bless (newRV_inc ((SV *)obj->self), stash); |
274 | return sv_bless (newRV_inc ((SV *)obj->self), stash); |
258 | } |
275 | } |
259 | else |
276 | else |
|
|
277 | { |
260 | return newRV_inc ((SV *)obj->self); |
278 | SV *sv = newRV_inc ((SV *)obj->self); |
|
|
279 | |
|
|
280 | if (Gv_AMG (stash)) // handle overload correctly, as the perl core does not |
|
|
281 | SvAMAGIC_on (sv); |
|
|
282 | |
|
|
283 | return sv; |
|
|
284 | } |
261 | } |
285 | } |
262 | |
286 | |
263 | static void |
287 | static void |
264 | clearSVptr (SV *sv) |
288 | clearSVptr (SV *sv) |
265 | { |
289 | { |
… | |
… | |
318 | inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } |
342 | inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } |
319 | |
343 | |
320 | inline SV *to_sv (object & v) { return to_sv (&v); } |
344 | inline SV *to_sv (object & v) { return to_sv (&v); } |
321 | inline SV *to_sv (living & v) { return to_sv (&v); } |
345 | inline SV *to_sv (living & v) { return to_sv (&v); } |
322 | |
346 | |
323 | //TODO: |
|
|
324 | inline SV *to_sv (New_Face * v) { return to_sv (v->name); } |
347 | inline SV *to_sv (facetile * v) { return to_sv (v->name); } |
325 | inline SV *to_sv (treasurelist * v) { return to_sv (v->name); } |
348 | inline SV *to_sv (treasurelist * v) { return to_sv (v->name); } |
326 | |
349 | |
327 | inline SV *to_sv (UUID v) |
350 | inline SV *to_sv (UUID v) |
328 | { |
351 | { |
329 | char buf[128]; |
352 | char buf[128]; |
330 | snprintf (buf, 128, "<1,%" PRIx64 ">", v.seq); |
353 | snprintf (buf, 128, "<1.%" PRIx64 ">", v.seq); |
331 | return newSVpv (buf, 0); |
354 | return newSVpv (buf, 0); |
332 | } |
355 | } |
333 | |
356 | |
334 | inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? SvPV_nolen (sv) : 0; } |
357 | inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? SvPV_nolen (sv) : 0; } |
335 | inline void sv_to (SV *sv, char * &v) { free (v); v = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; } |
358 | inline void sv_to (SV *sv, char * &v) { free (v); v = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; } |
… | |
… | |
354 | inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } |
377 | inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } |
355 | inline void sv_to (SV *sv, partylist * &v) { v = (partylist *)SvPTR_ornull (sv, "cf::party"); } |
378 | inline void sv_to (SV *sv, partylist * &v) { v = (partylist *)SvPTR_ornull (sv, "cf::party"); } |
356 | inline void sv_to (SV *sv, region * &v) { v = (region *)SvPTR_ornull (sv, "cf::region"); } |
379 | inline void sv_to (SV *sv, region * &v) { v = (region *)SvPTR_ornull (sv, "cf::region"); } |
357 | inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); } |
380 | inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); } |
358 | |
381 | |
359 | inline void sv_to (SV *sv, New_Face * &v) { v = &new_faces[FindFace (SvPV_nolen (sv), 0)]; } //TODO |
382 | inline void sv_to (SV *sv, facetile * &v) { v = &new_faces[FindFace (SvPV_nolen (sv), 0)]; } |
360 | inline void sv_to (SV *sv, treasurelist * &v) { v = find_treasurelist (SvPV_nolen (sv)); } // TODO |
383 | inline void sv_to (SV *sv, treasurelist * &v) { v = find_treasurelist (SvPV_nolen (sv)); } |
361 | |
384 | |
362 | template<class T> |
385 | template<class T> |
363 | inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; } |
386 | inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; } |
364 | |
387 | |
365 | template<int N> |
388 | template<int N> |
… | |
… | |
501 | if (!ext->cb) |
524 | if (!ext->cb) |
502 | ext->cb = newAV (); |
525 | ext->cb = newAV (); |
503 | |
526 | |
504 | return newRV_inc ((SV *)ext->cb); |
527 | return newRV_inc ((SV *)ext->cb); |
505 | } |
528 | } |
506 | |
|
|
507 | #if 0 |
|
|
508 | void attachable::clear () |
|
|
509 | { |
|
|
510 | if (self) |
|
|
511 | { |
|
|
512 | // disconnect Perl from C, to avoid crashes |
|
|
513 | sv_unmagic (SvRV ((SV *)self), PERL_MAGIC_ext); |
|
|
514 | |
|
|
515 | // clear the perl hash, might or might not be a good idea |
|
|
516 | hv_clear ((HV *)SvRV ((SV *)self)); |
|
|
517 | |
|
|
518 | SvREFCNT_dec (self); |
|
|
519 | self = 0; |
|
|
520 | } |
|
|
521 | |
|
|
522 | if (cb) |
|
|
523 | { |
|
|
524 | SvREFCNT_dec (cb); |
|
|
525 | cb = 0; |
|
|
526 | } |
|
|
527 | |
|
|
528 | attach = 0; |
|
|
529 | } |
|
|
530 | #endif |
|
|
531 | |
529 | |
532 | ///////////////////////////////////////////////////////////////////////////// |
530 | ///////////////////////////////////////////////////////////////////////////// |
533 | |
531 | |
534 | extern "C" int cfperl_initPlugin (const char *iversion, f_plug_api gethooksptr) |
532 | extern "C" int cfperl_initPlugin (const char *iversion, f_plug_api gethooksptr) |
535 | { |
533 | { |
… | |
… | |
607 | 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)) |
608 | { |
606 | { |
609 | printf ("unable to initialize perl-interpreter, aborting.\n"); |
607 | printf ("unable to initialize perl-interpreter, aborting.\n"); |
610 | exit (EXIT_FAILURE); |
608 | exit (EXIT_FAILURE); |
611 | } |
609 | } |
|
|
610 | |
|
|
611 | { |
|
|
612 | dSP; |
|
|
613 | |
|
|
614 | PUSHMARK (SP); |
|
|
615 | PUTBACK; |
|
|
616 | call_pv ("cf::init", G_DISCARD | G_VOID); |
|
|
617 | } |
612 | } |
618 | } |
613 | |
619 | |
614 | void cfperl_main () |
620 | void cfperl_main () |
615 | { |
621 | { |
616 | dSP; |
622 | dSP; |
… | |
… | |
830 | } |
836 | } |
831 | |
837 | |
832 | ///////////////////////////////////////////////////////////////////////////// |
838 | ///////////////////////////////////////////////////////////////////////////// |
833 | |
839 | |
834 | void |
840 | void |
835 | maptile::emergency_save () |
841 | cfperl_emergency_save () |
836 | { |
842 | { |
837 | CALL_BEGIN (0); |
843 | CALL_BEGIN (0); |
838 | CALL_CALL ("cf::map::emergency_save", G_VOID); |
844 | CALL_CALL ("cf::emergency_save", G_VOID); |
839 | CALL_END; |
845 | CALL_END; |
840 | } |
846 | } |
841 | |
847 | |
842 | maptile * |
848 | maptile * |
843 | maptile::find_sync (const char *path, maptile *origin) |
849 | maptile::find_sync (const char *path, maptile *origin) |
844 | { |
850 | { |
845 | CALL_BEGIN (2); |
851 | CALL_BEGIN (2); |
846 | CALL_ARG (path); |
852 | CALL_ARG (path); |
847 | CALL_ARG (origin); |
853 | CALL_ARG (origin); |
848 | CALL_CALL ("cf::map::find_sync", G_SCALAR); |
854 | CALL_CALL ("cf::map::find_sync", G_SCALAR); |
|
|
855 | |
|
|
856 | maptile *retval; |
|
|
857 | |
|
|
858 | if (count) |
|
|
859 | sv_to (POPs, retval); |
|
|
860 | else |
|
|
861 | retval = 0; |
|
|
862 | |
|
|
863 | CALL_END; |
|
|
864 | |
|
|
865 | return retval; |
|
|
866 | } |
|
|
867 | |
|
|
868 | maptile * |
|
|
869 | maptile::find_async (const char *path, maptile *origin) |
|
|
870 | { |
|
|
871 | CALL_BEGIN (2); |
|
|
872 | CALL_ARG (path); |
|
|
873 | CALL_ARG (origin); |
|
|
874 | CALL_CALL ("cf::map::find_async", G_SCALAR); |
849 | |
875 | |
850 | maptile *retval; |
876 | maptile *retval; |
851 | |
877 | |
852 | if (count) |
878 | if (count) |
853 | sv_to (POPs, retval); |
879 | sv_to (POPs, retval); |
… | |
… | |
906 | void |
932 | void |
907 | iw::alloc () |
933 | iw::alloc () |
908 | { |
934 | { |
909 | pe = GEventAPI->new_idle (0, 0); |
935 | pe = GEventAPI->new_idle (0, 0); |
910 | |
936 | |
|
|
937 | WaREENTRANT_off (pe); |
911 | pe->base.callback = (void *)iw_dispatch; |
938 | pe->base.callback = (void *)iw_dispatch; |
912 | pe->base.ext_data = (void *)this; |
939 | pe->base.ext_data = (void *)this; |
913 | } |
940 | } |
914 | |
941 | |
915 | static void iow_dispatch (pe_event *ev) |
942 | static void iow_dispatch (pe_event *ev) |
… | |
… | |
921 | void |
948 | void |
922 | iow::alloc () |
949 | iow::alloc () |
923 | { |
950 | { |
924 | pe = GEventAPI->new_io (0, 0); |
951 | pe = GEventAPI->new_io (0, 0); |
925 | |
952 | |
|
|
953 | WaREENTRANT_off (pe); |
926 | pe->base.callback = (void *)iow_dispatch; |
954 | pe->base.callback = (void *)iow_dispatch; |
927 | pe->base.ext_data = (void *)this; |
955 | pe->base.ext_data = (void *)this; |
928 | |
956 | |
929 | pe->fd = -1; |
957 | pe->fd = -1; |
930 | pe->poll = 0; |
958 | pe->poll = 0; |
… | |
… | |
1258 | const_iv (FLAG_ACTIVATE_ON_RELEASE) |
1286 | const_iv (FLAG_ACTIVATE_ON_RELEASE) |
1259 | const_iv (FLAG_IS_WATER) |
1287 | const_iv (FLAG_IS_WATER) |
1260 | const_iv (FLAG_CONTENT_ON_GEN) |
1288 | const_iv (FLAG_CONTENT_ON_GEN) |
1261 | const_iv (FLAG_IS_A_TEMPLATE) |
1289 | const_iv (FLAG_IS_A_TEMPLATE) |
1262 | const_iv (FLAG_IS_BUILDABLE) |
1290 | const_iv (FLAG_IS_BUILDABLE) |
|
|
1291 | const_iv (FLAG_DESTROY_ON_DEATH) |
|
|
1292 | const_iv (FLAG_NO_MAP_SAVE) |
1263 | |
1293 | |
1264 | const_iv (NDI_BLACK) |
1294 | const_iv (NDI_BLACK) |
1265 | const_iv (NDI_WHITE) |
1295 | const_iv (NDI_WHITE) |
1266 | const_iv (NDI_NAVY) |
1296 | const_iv (NDI_NAVY) |
1267 | const_iv (NDI_RED) |
1297 | const_iv (NDI_RED) |
… | |
… | |
1452 | const_iv (ATNR_BLIND) |
1482 | const_iv (ATNR_BLIND) |
1453 | const_iv (ATNR_INTERNAL) |
1483 | const_iv (ATNR_INTERNAL) |
1454 | const_iv (ATNR_LIFE_STEALING) |
1484 | const_iv (ATNR_LIFE_STEALING) |
1455 | const_iv (ATNR_DISEASE) |
1485 | const_iv (ATNR_DISEASE) |
1456 | |
1486 | |
1457 | const_iv (MAP_FLUSH) |
|
|
1458 | const_iv (MAP_PLAYER_UNIQUE) |
|
|
1459 | const_iv (MAP_BLOCK) |
|
|
1460 | const_iv (MAP_STYLE) |
|
|
1461 | const_iv (MAP_OVERLAY) |
|
|
1462 | |
|
|
1463 | const_iv (MAP_IN_MEMORY) |
1487 | const_iv (MAP_IN_MEMORY) |
1464 | const_iv (MAP_SWAPPED) |
1488 | const_iv (MAP_SWAPPED) |
1465 | const_iv (MAP_LOADING) |
1489 | const_iv (MAP_LOADING) |
1466 | const_iv (MAP_SAVING) |
1490 | const_iv (MAP_SAVING) |
1467 | |
1491 | |
… | |
… | |
1560 | } |
1584 | } |
1561 | |
1585 | |
1562 | NV floor (NV x) |
1586 | NV floor (NV x) |
1563 | |
1587 | |
1564 | NV ceil (NV x) |
1588 | NV ceil (NV x) |
|
|
1589 | |
|
|
1590 | NV rndm (...) |
|
|
1591 | CODE: |
|
|
1592 | switch (items) |
|
|
1593 | { |
|
|
1594 | case 0: RETVAL = rndm (); break; |
|
|
1595 | case 1: RETVAL = rndm (SvUV (ST (0))); break; |
|
|
1596 | case 2: RETVAL = rndm (SvIV (ST (0)), SvIV (ST (1))); break; |
|
|
1597 | default: croak ("cf::rndm requires none, one or two parameters."); break; |
|
|
1598 | } |
|
|
1599 | OUTPUT: |
|
|
1600 | RETVAL |
1565 | |
1601 | |
1566 | void server_tick () |
1602 | void server_tick () |
1567 | CODE: |
1603 | CODE: |
1568 | runtime = SvNVx (sv_runtime); |
1604 | runtime = SvNVx (sv_runtime); |
1569 | server_tick (); |
1605 | server_tick (); |
… | |
… | |
1616 | } |
1652 | } |
1617 | OUTPUT: RETVAL |
1653 | OUTPUT: RETVAL |
1618 | |
1654 | |
1619 | void abort () |
1655 | void abort () |
1620 | |
1656 | |
|
|
1657 | void fork_abort (char *cause = "cf::fork_abort") |
|
|
1658 | |
|
|
1659 | void cleanup (const char *cause, bool make_core = false) |
|
|
1660 | |
1621 | void emergency_save () |
1661 | void emergency_save () |
1622 | |
1662 | |
1623 | void _exit (int status = 0) |
1663 | void _exit (int status = EXIT_SUCCESS) |
|
|
1664 | |
|
|
1665 | UV sv_2watcher (SV *w) |
|
|
1666 | CODE: |
|
|
1667 | RETVAL = (UV)GEventAPI->sv_2watcher (w); |
|
|
1668 | OUTPUT: |
|
|
1669 | RETVAL |
1624 | |
1670 | |
1625 | #if _POSIX_MEMLOCK |
1671 | #if _POSIX_MEMLOCK |
1626 | |
1672 | |
1627 | int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) |
1673 | int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) |
1628 | |
1674 | |
… | |
… | |
1674 | RETVAL = newSVpv (resist_plus[atnr], 0); |
1720 | RETVAL = newSVpv (resist_plus[atnr], 0); |
1675 | else |
1721 | else |
1676 | XSRETURN_UNDEF; |
1722 | XSRETURN_UNDEF; |
1677 | OUTPUT: RETVAL |
1723 | OUTPUT: RETVAL |
1678 | |
1724 | |
|
|
1725 | bool |
|
|
1726 | load_regions (const char *filename) |
|
|
1727 | CODE: |
|
|
1728 | RETVAL = loader_region ().load (filename); |
|
|
1729 | OUTPUT: RETVAL |
|
|
1730 | |
1679 | MODULE = cf PACKAGE = cf::attachable |
1731 | MODULE = cf PACKAGE = cf::attachable |
1680 | |
1732 | |
1681 | int |
1733 | int |
1682 | valid (SV *obj) |
1734 | valid (SV *obj) |
1683 | CODE: |
1735 | CODE: |
1684 | RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); |
1736 | RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); |
1685 | OUTPUT: |
1737 | OUTPUT: |
1686 | RETVAL |
1738 | RETVAL |
|
|
1739 | |
|
|
1740 | int mortals_size () |
|
|
1741 | CODE: |
|
|
1742 | RETVAL = attachable::mortals.size (); |
|
|
1743 | OUTPUT: RETVAL |
|
|
1744 | |
|
|
1745 | #object *mortals (U32 index) |
|
|
1746 | # CODE: |
|
|
1747 | # RETVAL = index < attachable::mortals.size () ? attachable::mortals [index] : 0; |
|
|
1748 | # OUTPUT: RETVAL |
1687 | |
1749 | |
1688 | INCLUDE: $PERL genacc attachable ../include/cfperl.h | |
1750 | INCLUDE: $PERL genacc attachable ../include/cfperl.h | |
1689 | |
1751 | |
1690 | MODULE = cf PACKAGE = cf::global |
1752 | MODULE = cf PACKAGE = cf::global |
1691 | |
1753 | |
… | |
… | |
1709 | RETVAL = op->invoke ((event_type)event, ARG_AV (av), DT_END); |
1771 | RETVAL = op->invoke ((event_type)event, ARG_AV (av), DT_END); |
1710 | OUTPUT: RETVAL |
1772 | OUTPUT: RETVAL |
1711 | |
1773 | |
1712 | SV *registry (object *op) |
1774 | SV *registry (object *op) |
1713 | |
1775 | |
1714 | void mortals () |
1776 | int objects_size () |
1715 | PPCODE: |
1777 | CODE: |
1716 | EXTEND (SP, object::mortals.size ()); |
|
|
1717 | for (AUTODECL (i, object::mortals.begin ()); i != object::mortals.end (); ++i) |
|
|
1718 | PUSHs (to_sv (*i)); |
|
|
1719 | |
|
|
1720 | object *first () |
|
|
1721 | CODE: |
|
|
1722 | RETVAL = object::first; |
1778 | RETVAL = objects.size (); |
|
|
1779 | OUTPUT: RETVAL |
|
|
1780 | |
|
|
1781 | object *objects (U32 index) |
|
|
1782 | CODE: |
|
|
1783 | RETVAL = index < objects.size () ? objects [index] : 0; |
|
|
1784 | OUTPUT: RETVAL |
|
|
1785 | |
|
|
1786 | int actives_size () |
|
|
1787 | CODE: |
|
|
1788 | RETVAL = actives.size (); |
|
|
1789 | OUTPUT: RETVAL |
|
|
1790 | |
|
|
1791 | object *actives (U32 index) |
|
|
1792 | CODE: |
|
|
1793 | RETVAL = index < actives.size () ? actives [index] : 0; |
1723 | OUTPUT: RETVAL |
1794 | OUTPUT: RETVAL |
1724 | |
1795 | |
1725 | # missing properties |
1796 | # missing properties |
1726 | |
1797 | |
1727 | object *head (object *op) |
1798 | object *head (object *op) |
1728 | PROTOTYPE: $ |
1799 | PROTOTYPE: $ |
1729 | CODE: |
1800 | CODE: |
1730 | RETVAL = op->head ? op->head : op; |
1801 | RETVAL = op->head_ (); |
1731 | OUTPUT: RETVAL |
1802 | OUTPUT: RETVAL |
1732 | |
1803 | |
1733 | int is_head (object *op) |
1804 | int is_head (object *op) |
1734 | PROTOTYPE: $ |
1805 | PROTOTYPE: $ |
1735 | CODE: |
1806 | CODE: |
1736 | RETVAL = !op->head; |
1807 | RETVAL = op->head_ () == op; |
1737 | OUTPUT: RETVAL |
1808 | OUTPUT: RETVAL |
1738 | |
1809 | |
1739 | void |
1810 | void |
1740 | inv (object *obj) |
1811 | inv (object *obj) |
1741 | PROTOTYPE: $ |
1812 | PROTOTYPE: $ |
… | |
… | |
1748 | |
1819 | |
1749 | void |
1820 | void |
1750 | set_animation (object *op, int idx) |
1821 | set_animation (object *op, int idx) |
1751 | CODE: |
1822 | CODE: |
1752 | SET_ANIMATION (op, idx); |
1823 | SET_ANIMATION (op, idx); |
|
|
1824 | |
|
|
1825 | int |
|
|
1826 | num_animations (object *op) |
|
|
1827 | CODE: |
|
|
1828 | RETVAL = NUM_ANIMATIONS (op); |
|
|
1829 | OUTPUT: RETVAL |
1753 | |
1830 | |
1754 | object *find_best_object_match (object *op, const char *match) |
1831 | object *find_best_object_match (object *op, const char *match) |
1755 | |
1832 | |
1756 | object *find_marked_object (object *op) |
1833 | object *find_marked_object (object *op) |
1757 | |
1834 | |
… | |
… | |
1832 | |
1909 | |
1833 | void drop (object *who, object *op) |
1910 | void drop (object *who, object *op) |
1834 | |
1911 | |
1835 | void pick_up (object *who, object *op) |
1912 | void pick_up (object *who, object *op) |
1836 | |
1913 | |
1837 | object *cf_object_insert_object (object *op, object *container) |
|
|
1838 | |
|
|
1839 | object *cf_object_insert_in_ob (object *ob, object *where) |
|
|
1840 | |
|
|
1841 | int cf_object_teleport (object *op, maptile *map, int x, int y) |
1914 | int cf_object_teleport (object *op, maptile *map, int x, int y) |
1842 | |
1915 | |
1843 | void update_object (object *op, int action) |
1916 | void update_object (object *op, int action) |
1844 | |
1917 | |
1845 | object *cf_create_object_by_name (const char *name) |
1918 | object *cf_create_object_by_name (const char *name) |
… | |
… | |
1964 | void esrv_update_item (object *op, int what, object *item) |
2037 | void esrv_update_item (object *op, int what, object *item) |
1965 | C_ARGS: what, op, item |
2038 | C_ARGS: what, op, item |
1966 | |
2039 | |
1967 | void clear_los (object *op) |
2040 | void clear_los (object *op) |
1968 | |
2041 | |
1969 | int command_teleport (object *op, char *params) |
|
|
1970 | |
|
|
1971 | int command_summon (object *op, char *params) |
2042 | int command_summon (object *op, char *params) |
1972 | |
2043 | |
1973 | int command_arrest (object *op, char *params) |
2044 | int command_arrest (object *op, char *params) |
1974 | |
2045 | |
1975 | int command_kick (object *op, char *params) |
2046 | int command_kick (object *op, char *params) |
… | |
… | |
2000 | pl->orig_stats = pl->ob->stats; |
2071 | pl->orig_stats = pl->ob->stats; |
2001 | |
2072 | |
2002 | void cf_player_move (player *pl, int dir) |
2073 | void cf_player_move (player *pl, int dir) |
2003 | |
2074 | |
2004 | void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0); |
2075 | void play_sound_player_only (player *pl, int soundnum, int x = 0, int y = 0); |
2005 | |
|
|
2006 | player *first () |
|
|
2007 | CODE: |
|
|
2008 | RETVAL = first_player; |
|
|
2009 | OUTPUT: RETVAL |
|
|
2010 | |
2076 | |
2011 | bool |
2077 | bool |
2012 | cell_visible (player *pl, int dx, int dy) |
2078 | cell_visible (player *pl, int dx, int dy) |
2013 | CODE: |
2079 | CODE: |
2014 | 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 |
… | |
… | |
2092 | for_all_players (pl) |
2158 | for_all_players (pl) |
2093 | if (pl->ob && pl->ob->map == THIS) |
2159 | if (pl->ob && pl->ob->map == THIS) |
2094 | PUSHs (sv_2mortal (to_sv (pl->ob))); |
2160 | PUSHs (sv_2mortal (to_sv (pl->ob))); |
2095 | } |
2161 | } |
2096 | |
2162 | |
|
|
2163 | void |
|
|
2164 | maptile::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 | } |
|
|
2180 | |
2097 | void play_sound_map (maptile *map, int x, int y, int sound_num) |
2181 | void play_sound_map (maptile *map, int x, int y, int sound_num) |
2098 | |
2182 | |
2099 | int out_of_map (maptile *map, int x, int y) |
2183 | int out_of_map (maptile *map, int x, int y) |
2100 | |
2184 | |
2101 | void |
2185 | void |
… | |
… | |
2117 | |
2201 | |
2118 | object* cf_map_present_arch_by_name (maptile *map, const char* str, int nx, int ny) |
2202 | object* cf_map_present_arch_by_name (maptile *map, const char* str, int nx, int ny) |
2119 | C_ARGS: str, map, nx, ny |
2203 | C_ARGS: str, map, nx, ny |
2120 | |
2204 | |
2121 | void |
2205 | void |
2122 | cf_map_normalise (maptile *map, int x, int y) |
2206 | get_map_flags (maptile *map, int x, int y) |
2123 | PPCODE: |
2207 | PPCODE: |
2124 | { |
2208 | { |
2125 | maptile *nmap = 0; |
2209 | maptile *nmap = 0; |
2126 | I16 nx = 0, ny = 0; |
2210 | I16 nx = 0, ny = 0; |
2127 | int flags = get_map_flags (map, &nmap, x, y, &nx, &ny); |
2211 | int flags = get_map_flags (map, &nmap, x, y, &nx, &ny); |
… | |
… | |
2182 | |
2266 | |
2183 | void fix_walls (maptile *map, int x, int y) |
2267 | void fix_walls (maptile *map, int x, int y) |
2184 | |
2268 | |
2185 | void fix_walls_around (maptile *map, int x, int y) |
2269 | void fix_walls_around (maptile *map, int x, int y) |
2186 | |
2270 | |
2187 | const char * |
|
|
2188 | region_name (maptile *m) |
|
|
2189 | CODE: |
|
|
2190 | RETVAL = get_name_of_region_for_map (m); |
|
|
2191 | OUTPUT: RETVAL |
|
|
2192 | |
|
|
2193 | # worst xs function of my life |
2271 | # worst xs function of my life |
2194 | maptile * |
2272 | bool |
2195 | _create_random_map (\ |
2273 | _create_random_map (\ |
2196 | char *path,\ |
2274 | maptile *self,\ |
2197 | char *wallstyle,\ |
2275 | char *wallstyle,\ |
2198 | char *wall_name,\ |
2276 | char *wall_name,\ |
2199 | char *floorstyle,\ |
2277 | char *floorstyle,\ |
2200 | char *monsterstyle,\ |
2278 | char *monsterstyle,\ |
2201 | char *treasurestyle,\ |
2279 | char *treasurestyle,\ |
… | |
… | |
2205 | char *origin_map,\ |
2283 | char *origin_map,\ |
2206 | char *final_map,\ |
2284 | char *final_map,\ |
2207 | char *exitstyle,\ |
2285 | char *exitstyle,\ |
2208 | char *this_map,\ |
2286 | char *this_map,\ |
2209 | char *exit_on_final_map,\ |
2287 | char *exit_on_final_map,\ |
2210 | int Xsize,\ |
2288 | int xsize,\ |
2211 | int Ysize,\ |
2289 | int ysize,\ |
2212 | int expand2x,\ |
2290 | int expand2x,\ |
2213 | int layoutoptions1,\ |
2291 | int layoutoptions1,\ |
2214 | int layoutoptions2,\ |
2292 | int layoutoptions2,\ |
2215 | int layoutoptions3,\ |
2293 | int layoutoptions3,\ |
2216 | int symmetry,\ |
2294 | int symmetry,\ |
… | |
… | |
2221 | int dungeon_depth,\ |
2299 | int dungeon_depth,\ |
2222 | int decoroptions,\ |
2300 | int decoroptions,\ |
2223 | int orientation,\ |
2301 | int orientation,\ |
2224 | int origin_y,\ |
2302 | int origin_y,\ |
2225 | int origin_x,\ |
2303 | int origin_x,\ |
2226 | int random_seed,\ |
2304 | U32 random_seed,\ |
2227 | val64 total_map_hp,\ |
2305 | val64 total_map_hp,\ |
2228 | int map_layout_style,\ |
2306 | int map_layout_style,\ |
2229 | int treasureoptions,\ |
2307 | int treasureoptions,\ |
2230 | int symmetry_used,\ |
2308 | int symmetry_used,\ |
2231 | region *region\ |
2309 | region *region,\ |
|
|
2310 | char *custom\ |
2232 | ) |
2311 | ) |
2233 | CODE: |
2312 | CODE: |
2234 | { |
2313 | { |
2235 | random_map_params rmp; |
2314 | random_map_params rmp; |
2236 | |
2315 | |
… | |
… | |
2246 | assign (rmp.exit_on_final_map, exit_on_final_map); |
2325 | assign (rmp.exit_on_final_map, exit_on_final_map); |
2247 | |
2326 | |
2248 | rmp.origin_map = origin_map; |
2327 | rmp.origin_map = origin_map; |
2249 | rmp.final_map = final_map; |
2328 | rmp.final_map = final_map; |
2250 | rmp.this_map = this_map; |
2329 | rmp.this_map = this_map; |
2251 | rmp.Xsize = Xsize; |
2330 | rmp.xsize = xsize; |
2252 | rmp.Ysize = Ysize; |
2331 | rmp.ysize = ysize; |
2253 | rmp.expand2x = expand2x; |
2332 | rmp.expand2x = expand2x; |
2254 | rmp.layoutoptions1 = layoutoptions1; |
2333 | rmp.layoutoptions1 = layoutoptions1; |
2255 | rmp.layoutoptions2 = layoutoptions2; |
2334 | rmp.layoutoptions2 = layoutoptions2; |
2256 | rmp.layoutoptions3 = layoutoptions3; |
2335 | rmp.layoutoptions3 = layoutoptions3; |
2257 | rmp.symmetry = symmetry; |
2336 | rmp.symmetry = symmetry; |
… | |
… | |
2268 | rmp.total_map_hp = total_map_hp; |
2347 | rmp.total_map_hp = total_map_hp; |
2269 | rmp.map_layout_style = map_layout_style; |
2348 | rmp.map_layout_style = map_layout_style; |
2270 | rmp.treasureoptions = treasureoptions; |
2349 | rmp.treasureoptions = treasureoptions; |
2271 | rmp.symmetry_used = symmetry_used; |
2350 | rmp.symmetry_used = symmetry_used; |
2272 | rmp.region = region; |
2351 | rmp.region = region; |
|
|
2352 | rmp.custom = custom; |
2273 | |
2353 | |
2274 | RETVAL = generate_random_map (path, &rmp); |
2354 | RETVAL = self->generate_random_map (&rmp); |
2275 | } |
2355 | } |
2276 | OUTPUT: |
2356 | OUTPUT: |
2277 | RETVAL |
2357 | RETVAL |
2278 | |
2358 | |
2279 | MODULE = cf PACKAGE = cf::arch |
2359 | MODULE = cf PACKAGE = cf::arch |
… | |
… | |
2302 | |
2382 | |
2303 | INCLUDE: $PERL genacc partylist ../include/player.h | |
2383 | INCLUDE: $PERL genacc partylist ../include/player.h | |
2304 | |
2384 | |
2305 | MODULE = cf PACKAGE = cf::region |
2385 | MODULE = cf PACKAGE = cf::region |
2306 | |
2386 | |
2307 | region *first () |
2387 | void |
2308 | PROTOTYPE: |
2388 | list () |
2309 | CODE: |
2389 | PPCODE: |
2310 | RETVAL = first_region; |
2390 | for_all_regions (rgn) |
2311 | OUTPUT: RETVAL |
2391 | XPUSHs (sv_2mortal (to_sv (rgn))); |
2312 | |
2392 | |
2313 | region *find (char *name) |
2393 | region *find (char *name) |
2314 | PROTOTYPE: $ |
2394 | PROTOTYPE: $ |
2315 | CODE: |
2395 | CODE: |
2316 | RETVAL = get_region_by_name (name); |
2396 | RETVAL = region::find (name); |
|
|
2397 | OUTPUT: RETVAL |
|
|
2398 | |
|
|
2399 | region *find_fuzzy (char *name) |
|
|
2400 | PROTOTYPE: $ |
|
|
2401 | CODE: |
|
|
2402 | RETVAL = region::find_fuzzy (name); |
2317 | OUTPUT: RETVAL |
2403 | OUTPUT: RETVAL |
2318 | |
2404 | |
2319 | INCLUDE: $PERL genacc region ../include/map.h | |
2405 | INCLUDE: $PERL genacc region ../include/map.h | |
2320 | |
2406 | |
2321 | MODULE = cf PACKAGE = cf::living |
2407 | MODULE = cf PACKAGE = cf::living |