1 |
/* |
2 |
* This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 |
* |
4 |
* Copyright (©) 2006,2007,2008,2009,2010,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 |
* |
6 |
* Deliantra is free software: you can redistribute it and/or modify it under |
7 |
* the terms of the Affero GNU General Public License as published by the |
8 |
* Free Software Foundation, either version 3 of the License, or (at your |
9 |
* option) any later version. |
10 |
* |
11 |
* This program is distributed in the hope that it will be useful, |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
* GNU General Public License for more details. |
15 |
* |
16 |
* You should have received a copy of the Affero GNU General Public License |
17 |
* and the GNU General Public License along with this program. If not, see |
18 |
* <http://www.gnu.org/licenses/>. |
19 |
* |
20 |
* The authors can be reached via e-mail to <support@deliantra.net> |
21 |
*/ |
22 |
|
23 |
#include "autoconf.h" |
24 |
|
25 |
#if HAVE_EXECINFO_H |
26 |
# include <execinfo.h> |
27 |
#endif |
28 |
|
29 |
#include <cstdarg> |
30 |
#include <typeinfo> |
31 |
|
32 |
#include "global.h" |
33 |
#include "rmg.h" |
34 |
#include "noise.h" |
35 |
#include "evthread.h" |
36 |
#include "sproto.h" |
37 |
|
38 |
#include <unistd.h> |
39 |
#if _POSIX_MEMLOCK |
40 |
# include <sys/mman.h> |
41 |
#endif |
42 |
|
43 |
#if HAVE_MALLOC_H |
44 |
# include <malloc.h> |
45 |
#endif |
46 |
|
47 |
#if !__GLIBC__ |
48 |
# define malloc_trim(pad) -1 |
49 |
#endif |
50 |
|
51 |
#include <EXTERN.h> |
52 |
#include <perl.h> |
53 |
#include <XSUB.h> |
54 |
|
55 |
#include "CoroAPI.h" |
56 |
#include "perlxsi.c" |
57 |
|
58 |
typedef object_thawer &object_thawer_ref; |
59 |
typedef object_freezer &object_freezer_ref; |
60 |
|
61 |
typedef std::string std__string; |
62 |
|
63 |
static PerlInterpreter *perl; |
64 |
|
65 |
tstamp NOW, runtime; |
66 |
|
67 |
static int tick_inhibit; |
68 |
static int tick_pending; |
69 |
|
70 |
global gbl_ev; |
71 |
static AV *cb_global, *cb_attachable, *cb_object, *cb_player, *cb_client, *cb_type, *cb_map; |
72 |
static SV *sv_runtime, *sv_tick_start, *sv_next_tick, *sv_now, *sv_server_tick; |
73 |
static AV *av_reflect; |
74 |
|
75 |
bitset<NUM_EVENT_TYPES> ev_want_event; |
76 |
bitset<NUM_TYPES> ev_want_type; |
77 |
|
78 |
static HV |
79 |
*stash_cf, |
80 |
*stash_cf_object_wrap, |
81 |
*stash_cf_object_player_wrap, |
82 |
*stash_cf_player_wrap, |
83 |
*stash_cf_map_wrap, |
84 |
*stash_cf_mapspace_wrap, |
85 |
*stash_cf_client_wrap, |
86 |
*stash_cf_arch_wrap, |
87 |
*stash_cf_party_wrap, |
88 |
*stash_cf_region_wrap, |
89 |
*stash_cf_living_wrap, |
90 |
*stash_cf_layout_wrap, |
91 |
*stash_ext_map_world; |
92 |
|
93 |
static SV |
94 |
*cv_cf_do_invoke, |
95 |
*cv_cf__can_merge, |
96 |
*cv_cf_client_send_msg, |
97 |
*cv_cf_tick, |
98 |
*cv_cf_match_match; |
99 |
|
100 |
#ifndef newSVpv_utf8 |
101 |
static SV * |
102 |
newSVpv_utf8 (const char *s) |
103 |
{ |
104 |
if (!s) |
105 |
return newSV (0); |
106 |
|
107 |
SV *sv = newSVpv (s, 0); |
108 |
SvUTF8_on (sv); |
109 |
return sv; |
110 |
} |
111 |
#endif |
112 |
|
113 |
#ifndef newSVpvn_utf8 |
114 |
static SV * |
115 |
newSVpvn_utf8 (const char *s, STRLEN l, int utf8) |
116 |
{ |
117 |
if (!s) |
118 |
return newSV (0); |
119 |
|
120 |
SV *sv = newSVpvn (s, l); |
121 |
|
122 |
if (utf8) |
123 |
SvUTF8_on (sv); |
124 |
|
125 |
return sv; |
126 |
} |
127 |
#endif |
128 |
|
129 |
noinline utf8_string |
130 |
cfSvPVutf8_nolen (SV *sv) |
131 |
{ |
132 |
SvGETMAGIC (sv); |
133 |
|
134 |
if (SvPOK (sv)) |
135 |
{ |
136 |
if (!SvUTF8 (sv)) |
137 |
sv_utf8_upgrade_nomg (sv); |
138 |
|
139 |
return SvPVX (sv); |
140 |
} |
141 |
|
142 |
return SvPV_nolen (sv); |
143 |
} |
144 |
|
145 |
// helper cast function, returns super class * or 0 |
146 |
template<class super> |
147 |
static super * |
148 |
is_a (attachable *at) |
149 |
{ |
150 |
//return dynamic_cast<super *>(at); // slower, safer |
151 |
if (typeid (*at) == typeid (super)) |
152 |
return static_cast<super *>(at); |
153 |
else |
154 |
return 0; |
155 |
} |
156 |
|
157 |
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
158 |
|
159 |
unordered_vector<attachable *> attachable::mortals; |
160 |
|
161 |
attachable::~attachable () |
162 |
{ |
163 |
assert (!self); |
164 |
assert (!cb); |
165 |
} |
166 |
|
167 |
int |
168 |
attachable::refcnt_cnt () const |
169 |
{ |
170 |
return refcnt + (self ? SvREFCNT (self) - 1 : 0); |
171 |
} |
172 |
|
173 |
void |
174 |
attachable::sever_self () |
175 |
{ |
176 |
if (HV *self = this->self) |
177 |
{ |
178 |
// keep a refcount because sv_unmagic might call attachable_free, |
179 |
// which might clear self, causing sv_unmagic to crash on a now |
180 |
// invalid object. |
181 |
SvREFCNT_inc (self); |
182 |
hv_clear (self); |
183 |
sv_unmagic ((SV *)self, PERL_MAGIC_ext); |
184 |
SvREFCNT_dec (self); |
185 |
|
186 |
// self *must* be null now because that's sv_unmagic's job. |
187 |
assert (!this->self); |
188 |
} |
189 |
} |
190 |
|
191 |
void |
192 |
attachable::optimise () |
193 |
{ |
194 |
if (self |
195 |
&& SvREFCNT (self) == 1 |
196 |
&& !HvTOTALKEYS (self)) |
197 |
sever_self (); |
198 |
} |
199 |
|
200 |
// check wether the object really is dead |
201 |
void |
202 |
attachable::do_check () |
203 |
{ |
204 |
if (refcnt_cnt () > 0) |
205 |
return; |
206 |
|
207 |
destroy (); |
208 |
} |
209 |
|
210 |
void |
211 |
attachable::do_destroy () |
212 |
{ |
213 |
INVOKE_ATTACHABLE (DESTROY, this); |
214 |
|
215 |
if (cb) |
216 |
{ |
217 |
SvREFCNT_dec (cb); |
218 |
cb = 0; |
219 |
} |
220 |
|
221 |
mortals.push_back (this); |
222 |
} |
223 |
|
224 |
void |
225 |
attachable::destroy () |
226 |
{ |
227 |
if (destroyed ()) |
228 |
return; |
229 |
|
230 |
attachable_flags |= F_DESTROYED; |
231 |
do_destroy (); |
232 |
sever_self (); |
233 |
} |
234 |
|
235 |
void |
236 |
attachable::do_delete () |
237 |
{ |
238 |
delete this; |
239 |
} |
240 |
|
241 |
void |
242 |
attachable::check_mortals () |
243 |
{ |
244 |
static int i = 0; |
245 |
|
246 |
for (;;) |
247 |
{ |
248 |
if (i >= mortals.size ()) |
249 |
{ |
250 |
i = 0; |
251 |
|
252 |
if (mortals.size () >= 512) |
253 |
{ |
254 |
static int last_mortalcount; |
255 |
if (mortals.size () != last_mortalcount) |
256 |
{ |
257 |
last_mortalcount = mortals.size (); |
258 |
object *specimen = is_a<object> (mortals [rndm (mortals.size ())]); |
259 |
|
260 |
LOG (llevInfo, "%d mortals (random specimen: %s).\n", |
261 |
(int)mortals.size (), specimen ? specimen->debug_desc () : "(not an object)"); |
262 |
|
263 |
if (0) |
264 |
{ |
265 |
for (int j = 0; j < mortals.size (); ++j)//D |
266 |
fprintf (stderr, "%d:%s %p ", j, &((object *)mortals[j])->name, mortals[j]);//D |
267 |
|
268 |
fprintf (stderr, "\n");//D |
269 |
} |
270 |
} |
271 |
} |
272 |
|
273 |
break; |
274 |
} |
275 |
|
276 |
attachable *obj = mortals [i]; |
277 |
|
278 |
#if 0 |
279 |
if (obj->self)//D make this an assert later |
280 |
{ |
281 |
LOG (llevError, "check_mortals: object '%s' still has self\n", typeid (obj).name ()); |
282 |
obj->sever_self (); |
283 |
} |
284 |
#endif |
285 |
|
286 |
if (obj->refcnt) |
287 |
{ |
288 |
++i; // further delay freeing |
289 |
|
290 |
if (!(i & 0x3ff)) |
291 |
break; |
292 |
} |
293 |
else |
294 |
{ |
295 |
mortals.erase (i); |
296 |
obj->sever_self (); |
297 |
obj->do_delete (); |
298 |
} |
299 |
} |
300 |
} |
301 |
|
302 |
void |
303 |
attachable::set_key (const char *key, const char *value, bool is_utf8) |
304 |
{ |
305 |
if (!self) |
306 |
self = newHV (); |
307 |
|
308 |
if (value) |
309 |
hv_store (self, key, strlen (key), is_utf8 ? newSVpv_utf8 (value) : newSVpv (value, 0), 0); |
310 |
else |
311 |
hv_delete (self, key, strlen (key), G_DISCARD); |
312 |
} |
313 |
|
314 |
attachable & |
315 |
attachable::operator =(const attachable &src) |
316 |
{ |
317 |
//if (self || cb) |
318 |
//INVOKE_OBJECT (CLONE, this, ARG_OBJECT (dst)); |
319 |
|
320 |
attach = src.attach; |
321 |
return *this; |
322 |
} |
323 |
|
324 |
#if 0 |
325 |
template<typename T> |
326 |
static bool |
327 |
find_backref (void *ptr, T *obj) |
328 |
{ |
329 |
char *s = (char *)obj; |
330 |
while (s < (char *)obj + sizeof (T)) |
331 |
{ |
332 |
if (ptr == *(void **)s) |
333 |
return true; |
334 |
|
335 |
s += sizeof (void *); // assume natural alignment |
336 |
} |
337 |
|
338 |
return false; |
339 |
} |
340 |
|
341 |
// for debugging, find "live" objects containing this ptr |
342 |
static void |
343 |
find_backref (void *ptr) |
344 |
{ |
345 |
for_all_objects (op) |
346 |
if (find_backref (ptr, op)) |
347 |
fprintf (stderr, "O %p %d:'%s'\n", op, op->count, &op->name); |
348 |
|
349 |
for_all_players (pl) |
350 |
if (find_backref (ptr, pl)) |
351 |
fprintf (stderr, "P %p\n", pl); |
352 |
|
353 |
for_all_clients (ns) |
354 |
if (find_backref (ptr, ns)) |
355 |
fprintf (stderr, "C %p\n", ns); |
356 |
} |
357 |
#endif |
358 |
|
359 |
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
360 |
|
361 |
static SV * |
362 |
newSVptr (void *ptr, HV *stash, HV *hv) |
363 |
{ |
364 |
if (!ptr) |
365 |
return newSV (0); |
366 |
|
367 |
sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, 0, (char *)ptr, 0); |
368 |
return sv_bless (newRV_noinc ((SV *)hv), stash); |
369 |
} |
370 |
|
371 |
static SV * noinline |
372 |
newSVptr (void *ptr, HV *stash) |
373 |
{ |
374 |
return newSVptr (ptr, stash, newHV ()); |
375 |
} |
376 |
|
377 |
static int |
378 |
attachable_free (pTHX_ SV *sv, MAGIC *mg) |
379 |
{ |
380 |
attachable *at = (attachable *)mg->mg_ptr; |
381 |
|
382 |
//TODO: check if transaction behaviour is really required here |
383 |
if (SV *self = (SV *)at->self) |
384 |
{ |
385 |
at->self = 0; |
386 |
SvREFCNT_dec (self); |
387 |
} |
388 |
|
389 |
// next line makes sense, but most objects still have refcnt 0 by default |
390 |
//at->refcnt_chk (); |
391 |
return 0; |
392 |
} |
393 |
|
394 |
MGVTBL attachable::vtbl = {0, 0, 0, 0, attachable_free}; |
395 |
|
396 |
static SV * noinline |
397 |
newSVattachable (attachable *obj, HV *stash) |
398 |
{ |
399 |
if (!obj) |
400 |
return newSV (0); |
401 |
|
402 |
if (!obj->self) |
403 |
obj->self = newHV (); |
404 |
|
405 |
if (!SvOBJECT (obj->self)) |
406 |
{ |
407 |
sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &attachable::vtbl, (char *)obj, 0); |
408 |
|
409 |
// now bless the object _once_ |
410 |
//TODO: create a class registry with c++ type<=>perl name<=>stash and use it here and elsewhere |
411 |
return sv_bless (newRV_inc ((SV *)obj->self), stash); |
412 |
} |
413 |
else |
414 |
{ |
415 |
SV *sv = newRV_inc ((SV *)obj->self); |
416 |
|
417 |
if (Gv_AMG (stash)) // handle overload correctly, as the perl core does not |
418 |
SvAMAGIC_on (sv); |
419 |
|
420 |
return sv; |
421 |
} |
422 |
} |
423 |
|
424 |
#if 0 // unused |
425 |
static void |
426 |
clearSVptr (SV *sv) |
427 |
{ |
428 |
if (SvROK (sv)) |
429 |
sv = SvRV (sv); |
430 |
|
431 |
hv_clear ((HV *)sv); |
432 |
sv_unmagic (sv, PERL_MAGIC_ext); |
433 |
} |
434 |
#endif |
435 |
|
436 |
static long |
437 |
SvPTR_nc (SV *sv) |
438 |
{ |
439 |
sv = SvRV (sv); |
440 |
|
441 |
// very important shortcut |
442 |
if (expect_true (SvMAGIC (sv) && SvMAGIC (sv)->mg_type == PERL_MAGIC_ext)) |
443 |
return (long)SvMAGIC (sv)->mg_ptr; |
444 |
|
445 |
if (MAGIC *mg = mg_find (sv, PERL_MAGIC_ext)) |
446 |
return (long)mg->mg_ptr; |
447 |
|
448 |
croak ("perl code used object, but C object is already destroyed, caught"); |
449 |
} |
450 |
|
451 |
static long |
452 |
SvPTR (SV *sv, const char *klass) |
453 |
{ |
454 |
if (!sv_derived_from (sv, klass)) |
455 |
croak ("object of type %s expected", klass); |
456 |
|
457 |
return SvPTR_nc (sv); |
458 |
} |
459 |
|
460 |
static long noinline |
461 |
SvPTR_ornull (SV *sv, const char *klass) |
462 |
{ |
463 |
if (expect_false (!SvOK (sv))) return 0; |
464 |
|
465 |
return SvPTR (sv, klass); |
466 |
} |
467 |
|
468 |
static long noinline |
469 |
SvPTR_ornull_client (SV *sv) |
470 |
{ |
471 |
if (expect_false (!SvOK (sv))) return 0; |
472 |
|
473 |
if (!SvROK (sv) |
474 |
|| (SvSTASH (SvRV (sv)) != stash_cf_client_wrap |
475 |
&& !sv_derived_from (sv, "cf::client"))) |
476 |
croak ("object of type cf::client expected"); |
477 |
|
478 |
return SvPTR_nc (sv); |
479 |
} |
480 |
|
481 |
static long noinline |
482 |
SvPTR_ornull_object (SV *sv) |
483 |
{ |
484 |
if (expect_false (!SvOK (sv))) return 0; |
485 |
|
486 |
if (!SvROK (sv) |
487 |
|| (SvSTASH (SvRV (sv)) != stash_cf_object_wrap |
488 |
&& SvSTASH (SvRV (sv)) != stash_cf_object_player_wrap |
489 |
&& SvSTASH (SvRV (sv)) != stash_cf_arch_wrap |
490 |
&& !sv_derived_from (sv, "cf::object"))) |
491 |
croak ("object of type cf::object expected"); |
492 |
|
493 |
return SvPTR_nc (sv); |
494 |
} |
495 |
|
496 |
static long noinline |
497 |
SvPTR_ornull_maptile (SV *sv) |
498 |
{ |
499 |
if (expect_false (!SvOK (sv))) return 0; |
500 |
|
501 |
if (!SvROK (sv) |
502 |
|| (SvSTASH (SvRV (sv)) != stash_cf_map_wrap |
503 |
&& SvSTASH (SvRV (sv)) != stash_ext_map_world |
504 |
&& !sv_derived_from (sv, "cf::map"))) |
505 |
croak ("object of type cf::map expected"); |
506 |
|
507 |
return SvPTR_nc (sv); |
508 |
} |
509 |
|
510 |
static long noinline |
511 |
SvPTR_ornull_player (SV *sv) |
512 |
{ |
513 |
if (expect_false (!SvOK (sv))) return 0; |
514 |
|
515 |
if (!SvROK (sv) |
516 |
|| (SvSTASH (SvRV (sv)) != stash_cf_player_wrap |
517 |
&& !sv_derived_from (sv, "cf::player"))) |
518 |
croak ("object of type cf::player expected"); |
519 |
|
520 |
return SvPTR_nc (sv); |
521 |
} |
522 |
|
523 |
static inline SV *to_sv (const shstr & v) { return newSVpvn_utf8 ((const char *)v, v.length (), 1); } |
524 |
static inline SV *to_sv (const char * v) { return v ? newSVpv (v, 0) : newSV (0); } |
525 |
static inline SV *to_sv (bool v) { return newSViv (v); } |
526 |
static inline SV *to_sv ( signed char v) { return newSViv (v); } |
527 |
static inline SV *to_sv (unsigned char v) { return newSViv (v); } |
528 |
static inline SV *to_sv ( signed short v) { return newSViv (v); } |
529 |
static inline SV *to_sv (unsigned short v) { return newSVuv (v); } |
530 |
static inline SV *to_sv ( signed int v) { return newSViv (v); } |
531 |
static inline SV *to_sv (unsigned int v) { return newSVuv (v); } |
532 |
static inline SV *to_sv ( signed long v) { return newSViv (v); } |
533 |
static inline SV *to_sv (unsigned long v) { return newSVuv (v); } |
534 |
static inline SV *to_sv ( signed long long v) { return newSVval64 (v); } |
535 |
static inline SV *to_sv (unsigned long long v) { return newSVval64 (v); } |
536 |
static inline SV *to_sv (float v) { return newSVnv (v); } |
537 |
static inline SV *to_sv (double v) { return newSVnv (v); } |
538 |
static inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); } |
539 |
static inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); } |
540 |
// gcc dislikes noilnine on to_sv |
541 |
static noinline SV *to_sv_ni (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); } |
542 |
static inline SV *to_sv (object * v) { return to_sv_ni (v); } |
543 |
static inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); } |
544 |
static inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); } |
545 |
static inline SV *to_sv (region * v) { return newSVattachable (v, stash_cf_region_wrap); } |
546 |
static inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); } |
547 |
static inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } |
548 |
static inline SV *to_sv (mapspace * v) { return newSVptr (v, stash_cf_mapspace_wrap); } |
549 |
static inline SV *to_sv (layout * v) { return newSVptr (v, stash_cf_layout_wrap); } |
550 |
|
551 |
static inline SV *to_sv (object & v) { return to_sv (&v); } |
552 |
static inline SV *to_sv (living & v) { return to_sv (&v); } |
553 |
|
554 |
static inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); } |
555 |
static inline SV *to_sv (const treasurelist *v) { return to_sv (v->name); } |
556 |
|
557 |
static inline SV *to_sv (UUID v) { return newSVpv (v.c_str (), 0); } |
558 |
|
559 |
static inline SV *to_sv (dynbuf * v) |
560 |
{ |
561 |
SV *sv = newSV (0); |
562 |
|
563 |
sv_upgrade (sv, SVt_PV); |
564 |
SvGROW (sv, v->size () + 1); |
565 |
SvPOK_only (sv); |
566 |
v->linearise (SvPVX (sv)); |
567 |
SvCUR_set (sv, v->size ()); |
568 |
*SvEND (sv) = 0; |
569 |
|
570 |
return sv; |
571 |
} |
572 |
|
573 |
static inline SV *to_sv (dynbuf_text * v) |
574 |
{ |
575 |
SV *sv = to_sv (static_cast<dynbuf *> (v)); |
576 |
SvUTF8_on (sv); |
577 |
return sv; |
578 |
} |
579 |
|
580 |
static inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? cfSvPVutf8_nolen (sv) : 0; } |
581 |
static inline void sv_to (SV *sv, char * &v) { free (v); v = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; } |
582 |
static inline void sv_to (SV *sv, bool &v) { v = SvIV (sv); } |
583 |
static inline void sv_to (SV *sv, signed char &v) { v = SvIV (sv); } |
584 |
static inline void sv_to (SV *sv, unsigned char &v) { v = SvIV (sv); } |
585 |
static inline void sv_to (SV *sv, signed short &v) { v = SvIV (sv); } |
586 |
static inline void sv_to (SV *sv, unsigned short &v) { v = SvIV (sv); } |
587 |
static inline void sv_to (SV *sv, signed int &v) { v = SvIV (sv); } |
588 |
static inline void sv_to (SV *sv, unsigned int &v) { v = SvUV (sv); } |
589 |
static inline void sv_to (SV *sv, signed long &v) { v = SvIV (sv); } |
590 |
static inline void sv_to (SV *sv, unsigned long &v) { v = SvUV (sv); } |
591 |
static inline void sv_to (SV *sv, signed long long &v) { v = ( signed long long)SvVAL64 (sv); } |
592 |
static inline void sv_to (SV *sv, unsigned long long &v) { v = (unsigned long long)SvVAL64 (sv); } |
593 |
static inline void sv_to (SV *sv, float &v) { v = SvNV (sv); } |
594 |
static inline void sv_to (SV *sv, double &v) { v = SvNV (sv); } |
595 |
static inline void sv_to (SV *sv, client * &v) { v = (client *) (attachable *)SvPTR_ornull_client (sv); } |
596 |
static inline void sv_to (SV *sv, player * &v) { v = (player *) (attachable *)SvPTR_ornull_player (sv); } |
597 |
static inline void sv_to (SV *sv, object * &v) { v = (object *) (attachable *)SvPTR_ornull_object (sv); } |
598 |
static inline void sv_to (SV *sv, maptile * &v) { v = (maptile *) (attachable *)SvPTR_ornull_maptile (sv); } |
599 |
static inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)(attachable *)SvPTR_ornull (sv, "cf::arch"); } |
600 |
static inline void sv_to (SV *sv, region * &v) { v = (region *) (attachable *)SvPTR_ornull (sv, "cf::region"); } |
601 |
static inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } |
602 |
static inline void sv_to (SV *sv, partylist * &v) { v = (partylist *) SvPTR_ornull (sv, "cf::party"); } |
603 |
static inline void sv_to (SV *sv, living * &v) { v = (living *) SvPTR_ornull (sv, "cf::living"); } |
604 |
static inline void sv_to (SV *sv, mapspace * &v) { v = (mapspace *) SvPTR_ornull (sv, "cf::mapspace"); } |
605 |
static inline void sv_to (SV *sv, layout * &v) { v = (layout *) SvPTR_ornull (sv, "cf::layout"); } |
606 |
static inline void sv_to (SV *sv, object_freezer * &v) { v = (object_freezer *) SvPTR_ornull (sv, "cf::object::freezer"); } |
607 |
static inline void sv_to (SV *sv, object_thawer * &v) { v = (object_thawer *) SvPTR_ornull (sv, "cf::object::thawer" ); } |
608 |
|
609 |
//static inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; } |
610 |
static inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); } |
611 |
|
612 |
template<class T> |
613 |
static inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; } |
614 |
|
615 |
template<int N> |
616 |
static inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); } |
617 |
|
618 |
static inline void sv_to (SV *sv, bowtype_t &v) { v = (bowtype_t) SvIV (sv); } |
619 |
static inline void sv_to (SV *sv, petmode_t &v) { v = (petmode_t) SvIV (sv); } |
620 |
static inline void sv_to (SV *sv, usekeytype &v) { v = (usekeytype) SvIV (sv); } |
621 |
static inline void sv_to (SV *sv, unapplymode &v) { v = (unapplymode) SvIV (sv); } |
622 |
|
623 |
static inline void sv_to (SV *sv, std::string &v) |
624 |
{ |
625 |
STRLEN len; |
626 |
char *data = SvPVbyte (sv, len); |
627 |
v.assign (data, len); |
628 |
} |
629 |
|
630 |
static inline void sv_to (SV *sv, refcnt_buf &v) |
631 |
{ |
632 |
STRLEN len; |
633 |
char *data = SvPVbyte (sv, len); |
634 |
refcnt_buf buf (data, len); |
635 |
v = buf; |
636 |
} |
637 |
|
638 |
static inline void sv_to (SV *sv, UUID &v) |
639 |
{ |
640 |
if (!v.parse (SvPV_nolen (sv))) |
641 |
croak ("unparsable uuid: %s", SvPV_nolen (sv)); |
642 |
} |
643 |
|
644 |
static inline void sv_to (SV *sv, object::flags_t::reference v) { v = SvTRUE (sv); } |
645 |
|
646 |
static SV * |
647 |
newSVdt_va (va_list &ap, data_type type) |
648 |
{ |
649 |
SV *sv; |
650 |
|
651 |
switch (type) |
652 |
{ |
653 |
case DT_INT: |
654 |
sv = newSViv (va_arg (ap, int)); |
655 |
break; |
656 |
|
657 |
case DT_INT64: |
658 |
sv = newSVval64 ((val64)va_arg (ap, sint64)); |
659 |
break; |
660 |
|
661 |
case DT_DOUBLE: |
662 |
sv = newSVnv (va_arg (ap, double)); |
663 |
break; |
664 |
|
665 |
case DT_STRING: |
666 |
{ |
667 |
char *str = (char *)va_arg (ap, const char *); |
668 |
sv = str ? newSVpv (str, 0) : newSV (0); |
669 |
} |
670 |
break; |
671 |
|
672 |
case DT_DATA: |
673 |
{ |
674 |
char *str = (char *)va_arg (ap, const void *); |
675 |
int len = va_arg (ap, int); |
676 |
sv = str ? newSVpv (str, len) : newSV (0); |
677 |
} |
678 |
break; |
679 |
|
680 |
case DT_OBJECT: |
681 |
sv = to_sv (va_arg (ap, object *)); |
682 |
break; |
683 |
|
684 |
case DT_MAP: |
685 |
// va_arg (object *) when void * is passed is an XSI extension |
686 |
sv = to_sv (va_arg (ap, maptile *)); |
687 |
break; |
688 |
|
689 |
case DT_CLIENT: |
690 |
sv = to_sv (va_arg (ap, client *)); |
691 |
break; |
692 |
|
693 |
case DT_PLAYER: |
694 |
sv = to_sv (va_arg (ap, player *)); |
695 |
break; |
696 |
|
697 |
case DT_ARCH: |
698 |
sv = to_sv (va_arg (ap, archetype *)); |
699 |
break; |
700 |
|
701 |
case DT_PARTY: |
702 |
sv = to_sv (va_arg (ap, partylist *)); |
703 |
break; |
704 |
|
705 |
case DT_REGION: |
706 |
sv = to_sv (va_arg (ap, region *)); |
707 |
break; |
708 |
|
709 |
default: |
710 |
assert (("unhandled type in newSVdt_va", 0)); |
711 |
} |
712 |
|
713 |
return sv; |
714 |
} |
715 |
|
716 |
static SV * |
717 |
newSVdt (data_type type, ...) |
718 |
{ |
719 |
va_list ap; |
720 |
|
721 |
va_start (ap, type); |
722 |
SV *sv = newSVdt_va (ap, type); |
723 |
va_end (ap); |
724 |
|
725 |
return sv; |
726 |
} |
727 |
|
728 |
// typemap support, mostly to avoid excessive inlining |
729 |
template<class type> |
730 |
static void noinline |
731 |
cf_obj_to (SV *arg, type &var) |
732 |
{ |
733 |
sv_to (arg, var); |
734 |
if (expect_false (!var)) |
735 |
croak ("must not pass invalid/null cf_obj here"); |
736 |
} |
737 |
|
738 |
template<class object> |
739 |
static void noinline |
740 |
cf_obj_ornull_to (SV *arg, object *&var) |
741 |
{ |
742 |
if (SvOK (arg)) |
743 |
{ |
744 |
sv_to (arg, var); |
745 |
if (expect_false (!var)) |
746 |
croak ("unable to convert perl object to C++ object"); |
747 |
} |
748 |
else |
749 |
var = 0; |
750 |
} |
751 |
|
752 |
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
753 |
|
754 |
static SV * |
755 |
registry (attachable *ext) |
756 |
{ |
757 |
if (!ext->cb) |
758 |
ext->cb = newAV (); |
759 |
|
760 |
return newRV_inc ((SV *)ext->cb); |
761 |
} |
762 |
|
763 |
///////////////////////////////////////////////////////////////////////////// |
764 |
|
765 |
void |
766 |
cfperl_init () |
767 |
{ |
768 |
extern char **environ; |
769 |
|
770 |
PERL_SYS_INIT3 (&settings.argc, &settings.argv, &environ); |
771 |
perl = perl_alloc (); |
772 |
perl_construct (perl); |
773 |
|
774 |
PL_exit_flags |= PERL_EXIT_DESTRUCT_END; |
775 |
|
776 |
const char *argv[] = { |
777 |
settings.argv [0], |
778 |
"-e0" |
779 |
}; |
780 |
|
781 |
if (perl_parse (perl, xs_init, 2, (char **)argv, environ) |
782 |
|| perl_run (perl)) |
783 |
{ |
784 |
printf ("unable to initialize perl-interpreter, aborting.\n"); |
785 |
exit (EXIT_FAILURE); |
786 |
} |
787 |
|
788 |
eval_pv ( |
789 |
"#line 1 'cfperl init'\n" |
790 |
"use EV ();\n" // required by bootstrap |
791 |
"use Coro ();\n" // required by bootstrap |
792 |
"cf->bootstrap;\n" // required for cf::datadir |
793 |
"unshift @INC, cf::datadir ();\n" // required for 'require' :) |
794 |
"require cf;\n", |
795 |
0 |
796 |
); |
797 |
|
798 |
if (SvTRUE (ERRSV)) |
799 |
{ |
800 |
printf ("unable to bootstrap perl, aborting:\n%s", SvPV_nolen (ERRSV)); |
801 |
exit (EXIT_FAILURE); |
802 |
} |
803 |
} |
804 |
|
805 |
void |
806 |
cfperl_main () |
807 |
{ |
808 |
dSP; |
809 |
|
810 |
PUSHMARK (SP); |
811 |
PUTBACK; |
812 |
call_pv ("cf::main", G_DISCARD | G_VOID); |
813 |
} |
814 |
|
815 |
void |
816 |
attachable::instantiate () |
817 |
{ |
818 |
if (attach) |
819 |
{ |
820 |
INVOKE_ATTACHABLE (INSTANTIATE, this, ARG_STRING (attach)); |
821 |
attach = 0; |
822 |
} |
823 |
} |
824 |
|
825 |
void |
826 |
attachable::reattach () |
827 |
{ |
828 |
optimise (); |
829 |
//TODO: check for _attachment's, very important for restarts |
830 |
INVOKE_ATTACHABLE (REATTACH, this); |
831 |
} |
832 |
|
833 |
static event_klass klass_of[NUM_EVENT_TYPES] = { |
834 |
# define def(type,name) KLASS_ ## type, |
835 |
# include "eventinc.h" |
836 |
# undef def |
837 |
}; |
838 |
|
839 |
#define KLASS_OF(event) (((unsigned int)event) < NUM_EVENT_TYPES ? klass_of [event] : KLASS_NONE) |
840 |
|
841 |
static void noinline |
842 |
gather_callbacks (AV *&callbacks, AV *registry, event_type event) |
843 |
{ |
844 |
// event must be in array |
845 |
if (event >= 0 && event <= AvFILLp (registry)) |
846 |
{ |
847 |
SV *cbs_ = AvARRAY (registry)[event]; |
848 |
|
849 |
// element must be list of callback entries |
850 |
if (cbs_ && SvROK (cbs_) && SvTYPE (SvRV (cbs_)) == SVt_PVAV) |
851 |
{ |
852 |
AV *cbs = (AV *)SvRV (cbs_); |
853 |
|
854 |
// no callback entries, no callbacks to call |
855 |
if (AvFILLp (cbs) >= 0) |
856 |
{ |
857 |
if (!callbacks) |
858 |
{ |
859 |
callbacks = newAV (); |
860 |
av_extend (callbacks, 16); |
861 |
} |
862 |
|
863 |
// never use SvREFCNT_inc to copy values, but its ok here :) |
864 |
for (int i = 0; i <= AvFILLp (cbs); ++i) |
865 |
av_push (callbacks, SvREFCNT_inc (AvARRAY (cbs)[i])); |
866 |
} |
867 |
} |
868 |
} |
869 |
} |
870 |
|
871 |
void |
872 |
attachable::gather_callbacks (AV *&callbacks, event_type event) const |
873 |
{ |
874 |
::gather_callbacks (callbacks, cb_attachable, event); |
875 |
|
876 |
if (cb) |
877 |
::gather_callbacks (callbacks, cb, event); |
878 |
} |
879 |
|
880 |
void |
881 |
global::gather_callbacks (AV *&callbacks, event_type event) const |
882 |
{ |
883 |
::gather_callbacks (callbacks, cb_global, event); |
884 |
} |
885 |
|
886 |
void |
887 |
object::gather_callbacks (AV *&callbacks, event_type event) const |
888 |
{ |
889 |
if (subtype && type + subtype * NUM_TYPES <= AvFILLp (cb_type)) |
890 |
{ |
891 |
SV *registry = AvARRAY (cb_type)[type + subtype * NUM_TYPES]; |
892 |
|
893 |
if (registry && SvROK (registry) && SvTYPE (SvRV (registry)) == SVt_PVAV) |
894 |
::gather_callbacks (callbacks, (AV *)SvRV (registry), event); |
895 |
} |
896 |
|
897 |
if (type <= AvFILLp (cb_type)) |
898 |
{ |
899 |
SV *registry = AvARRAY (cb_type)[type]; |
900 |
|
901 |
if (registry && SvROK (registry) && SvTYPE (SvRV (registry)) == SVt_PVAV) |
902 |
::gather_callbacks (callbacks, (AV *)SvRV (registry), event); |
903 |
} |
904 |
|
905 |
attachable::gather_callbacks (callbacks, event); |
906 |
::gather_callbacks (callbacks, cb_object, event); |
907 |
} |
908 |
|
909 |
void |
910 |
archetype::gather_callbacks (AV *&callbacks, event_type event) const |
911 |
{ |
912 |
attachable::gather_callbacks (callbacks, event); |
913 |
//TODO//::gather_callbacks (callbacks, cb_archetype, event); |
914 |
} |
915 |
|
916 |
void |
917 |
client::gather_callbacks (AV *&callbacks, event_type event) const |
918 |
{ |
919 |
attachable::gather_callbacks (callbacks, event); |
920 |
::gather_callbacks (callbacks, cb_client, event); |
921 |
} |
922 |
|
923 |
void |
924 |
player::gather_callbacks (AV *&callbacks, event_type event) const |
925 |
{ |
926 |
attachable::gather_callbacks (callbacks, event); |
927 |
::gather_callbacks (callbacks, cb_player, event); |
928 |
} |
929 |
|
930 |
void |
931 |
maptile::gather_callbacks (AV *&callbacks, event_type event) const |
932 |
{ |
933 |
attachable::gather_callbacks (callbacks, event); |
934 |
::gather_callbacks (callbacks, cb_map, event); |
935 |
} |
936 |
|
937 |
static void noinline |
938 |
_recalc_want (bitset<NUM_EVENT_TYPES> &set, AV *registry) |
939 |
{ |
940 |
for (int event = 0; event <= AvFILLp (registry); ++event) |
941 |
{ |
942 |
SV *cbs_ = AvARRAY (registry)[event]; |
943 |
|
944 |
// element must be list of callback entries |
945 |
if (cbs_ && SvROK (cbs_) && SvTYPE (SvRV (cbs_)) == SVt_PVAV) |
946 |
{ |
947 |
AV *cbs = (AV *)SvRV (cbs_); |
948 |
|
949 |
// no callback entries, no callbacks to call |
950 |
if (AvFILLp (cbs) >= 0) |
951 |
set.set (event); |
952 |
} |
953 |
} |
954 |
} |
955 |
|
956 |
// very slow and inefficient way to recalculate the global want bitsets |
957 |
static void |
958 |
_recalc_want () |
959 |
{ |
960 |
ev_want_event.reset (); |
961 |
|
962 |
_recalc_want (ev_want_event, cb_global); |
963 |
_recalc_want (ev_want_event, cb_attachable); |
964 |
_recalc_want (ev_want_event, cb_object); |
965 |
_recalc_want (ev_want_event, cb_client); |
966 |
_recalc_want (ev_want_event, cb_player); |
967 |
_recalc_want (ev_want_event, cb_map); |
968 |
|
969 |
ev_want_type.reset (); |
970 |
|
971 |
for (int type = 0; type <= AvFILLp (cb_type); ++type) |
972 |
{ |
973 |
SV *cbs_ = AvARRAY (cb_type)[type]; |
974 |
|
975 |
// element must be list of callback entries |
976 |
if (cbs_ && SvROK (cbs_) && SvTYPE (SvRV (cbs_)) == SVt_PVAV) |
977 |
{ |
978 |
AV *cbs = (AV *)SvRV (cbs_); |
979 |
|
980 |
// no callback entries, no callbacks to call |
981 |
if (AvFILLp (cbs) >= 0) |
982 |
ev_want_type.set (type % NUM_TYPES); |
983 |
} |
984 |
} |
985 |
} |
986 |
|
987 |
bool |
988 |
attachable::invoke (event_type event, ...) |
989 |
{ |
990 |
data_type dt; |
991 |
|
992 |
// callback call ordering should be: |
993 |
// 1. per-object callback |
994 |
// 2. per-class object |
995 |
// 3. per-type callback |
996 |
// 4. global callbacks |
997 |
|
998 |
AV *callbacks = 0; |
999 |
gather_callbacks (callbacks, event); |
1000 |
|
1001 |
// short-circuit processing if no callbacks found/defined |
1002 |
if (!callbacks) |
1003 |
return 0; |
1004 |
|
1005 |
va_list ap; |
1006 |
va_start (ap, event); |
1007 |
|
1008 |
CALL_BEGIN (3); |
1009 |
CALL_ARG_SV (newSViv (event)); // only used for debugging nowadays |
1010 |
CALL_ARG_SV (newRV_noinc ((SV *)callbacks)); |
1011 |
|
1012 |
//TODO: unhack |
1013 |
if (object *op = is_a<object>(this)) CALL_ARG_SV (newSVdt (DT_OBJECT, op)); |
1014 |
else if (player *pl = is_a<player>(this)) CALL_ARG_SV (newSVdt (DT_PLAYER, pl)); |
1015 |
else if (client *ns = is_a<client>(this)) CALL_ARG_SV (newSVdt (DT_CLIENT, ns)); |
1016 |
else if (maptile *m = is_a<maptile>(this)) CALL_ARG_SV (newSVdt (DT_MAP, m)); |
1017 |
else if (global *gl = is_a<global>(this)) /*nop*/; |
1018 |
else |
1019 |
abort (); //TODO |
1020 |
|
1021 |
for (;;) |
1022 |
{ |
1023 |
dt = (data_type) va_arg (ap, int); |
1024 |
|
1025 |
if (dt == DT_END) |
1026 |
break; |
1027 |
else if (dt == DT_AV) |
1028 |
{ |
1029 |
AV *av = va_arg (ap, AV *); |
1030 |
|
1031 |
for (int i = 0; i <= av_len (av); ++i) |
1032 |
XPUSHs (*av_fetch (av, i, 1)); |
1033 |
} |
1034 |
else |
1035 |
XPUSHs (sv_2mortal (newSVdt_va (ap, dt))); |
1036 |
} |
1037 |
|
1038 |
va_end (ap); |
1039 |
|
1040 |
CALL_CALL (cv_cf_do_invoke, G_SCALAR); |
1041 |
count = count > 0 ? POPi : 0; |
1042 |
|
1043 |
CALL_END; |
1044 |
|
1045 |
return count; |
1046 |
} |
1047 |
|
1048 |
static SV * |
1049 |
cfperl_result (int idx) |
1050 |
{ |
1051 |
AV *av = get_av ("cf::INVOKE_RESULTS", 0); |
1052 |
if (!av) |
1053 |
return &PL_sv_undef; |
1054 |
|
1055 |
SV **sv = av_fetch (av, idx, 0); |
1056 |
if (!sv) |
1057 |
return &PL_sv_undef; |
1058 |
|
1059 |
return *sv; |
1060 |
} |
1061 |
|
1062 |
int |
1063 |
cfperl_result_INT (int idx) |
1064 |
{ |
1065 |
return SvIV (cfperl_result (idx)); |
1066 |
} |
1067 |
|
1068 |
double |
1069 |
cfperl_result_DOUBLE (int idx) |
1070 |
{ |
1071 |
return SvNV (cfperl_result (idx)); |
1072 |
} |
1073 |
|
1074 |
///////////////////////////////////////////////////////////////////////////// |
1075 |
// various c++ => perl glue functions |
1076 |
|
1077 |
void |
1078 |
cfperl_tick () |
1079 |
{ |
1080 |
tick_pending = 1; |
1081 |
|
1082 |
if (tick_inhibit) |
1083 |
return; |
1084 |
|
1085 |
tick_pending = 0; |
1086 |
|
1087 |
dSP; |
1088 |
|
1089 |
PUSHMARK (SP); |
1090 |
PUTBACK; |
1091 |
call_pvsv (cv_cf_tick, G_DISCARD | G_VOID); |
1092 |
|
1093 |
SvNV_set (sv_next_tick, get_next_tick ()); SvNOK_only (sv_next_tick); |
1094 |
} |
1095 |
|
1096 |
void |
1097 |
cfperl_emergency_save () |
1098 |
{ |
1099 |
CALL_BEGIN (0); |
1100 |
CALL_CALL ("cf::emergency_save", G_VOID); |
1101 |
CALL_END; |
1102 |
} |
1103 |
|
1104 |
void |
1105 |
cfperl_cleanup (int make_core) |
1106 |
{ |
1107 |
CALL_BEGIN (1); |
1108 |
CALL_ARG (make_core); |
1109 |
CALL_CALL ("cf::post_cleanup", G_VOID); |
1110 |
CALL_END; |
1111 |
} |
1112 |
|
1113 |
void |
1114 |
cfperl_make_book (object *book, int level) |
1115 |
{ |
1116 |
CALL_BEGIN (2); |
1117 |
CALL_ARG (book); |
1118 |
CALL_ARG (level); |
1119 |
CALL_CALL ("ext::books::make_book", G_VOID); |
1120 |
CALL_END; |
1121 |
} |
1122 |
|
1123 |
void |
1124 |
cfperl_send_msg (client *ns, int color, const_utf8_string type, const_utf8_string msg) |
1125 |
{ |
1126 |
CALL_BEGIN (4); |
1127 |
CALL_ARG (ns); |
1128 |
CALL_ARG (type); |
1129 |
CALL_ARG_SV (newSVpv_utf8 (msg)); |
1130 |
CALL_ARG (color); |
1131 |
CALL_CALL (cv_cf_client_send_msg, G_VOID); |
1132 |
CALL_END; |
1133 |
} |
1134 |
|
1135 |
int |
1136 |
cfperl_can_merge (object *ob1, object *ob2) |
1137 |
{ |
1138 |
int can; |
1139 |
|
1140 |
CALL_BEGIN (2); |
1141 |
CALL_ARG (ob1); |
1142 |
CALL_ARG (ob2); |
1143 |
CALL_CALL (cv_cf__can_merge, G_SCALAR); |
1144 |
can = count && SvTRUE (TOPs); |
1145 |
CALL_END; |
1146 |
|
1147 |
return can; |
1148 |
} |
1149 |
|
1150 |
void |
1151 |
cfperl_mapscript_activate (object *ob, int state, object *activator, object *originator) |
1152 |
{ |
1153 |
CALL_BEGIN (4); |
1154 |
CALL_ARG (ob); |
1155 |
CALL_ARG (state); |
1156 |
CALL_ARG (activator); |
1157 |
CALL_ARG (originator); |
1158 |
CALL_CALL ("cf::mapscript::activate", G_VOID); |
1159 |
CALL_END; |
1160 |
} |
1161 |
|
1162 |
player * |
1163 |
player::find (const_utf8_string name) |
1164 |
{ |
1165 |
CALL_BEGIN (1); |
1166 |
CALL_ARG (name); |
1167 |
CALL_CALL ("cf::player::find", G_SCALAR); |
1168 |
|
1169 |
player *retval = 0; |
1170 |
if (count) sv_to (POPs, retval); |
1171 |
|
1172 |
CALL_END; |
1173 |
|
1174 |
return retval; |
1175 |
} |
1176 |
|
1177 |
maptile * |
1178 |
find_style (const_utf8_string dirname, const_utf8_string stylename, int difficulty, bool recurse) |
1179 |
{ |
1180 |
CALL_BEGIN (4); |
1181 |
CALL_ARG (dirname); |
1182 |
CALL_ARG (stylename); |
1183 |
CALL_ARG (difficulty); |
1184 |
CALL_ARG (recurse); |
1185 |
CALL_CALL ("ext::map_random::find_style", G_SCALAR); |
1186 |
|
1187 |
maptile *retval = 0; |
1188 |
if (count) sv_to (POPs, retval); |
1189 |
|
1190 |
CALL_END; |
1191 |
|
1192 |
return retval; |
1193 |
} |
1194 |
|
1195 |
maptile * |
1196 |
maptile::find_sync (const_utf8_string path, maptile *origin) |
1197 |
{ |
1198 |
CALL_BEGIN (2); |
1199 |
CALL_ARG (path); |
1200 |
CALL_ARG (origin); |
1201 |
CALL_CALL ("cf::map::find_sync", G_SCALAR); |
1202 |
|
1203 |
maptile *retval = 0; |
1204 |
if (count) sv_to (POPs, retval); |
1205 |
|
1206 |
CALL_END; |
1207 |
|
1208 |
return retval; |
1209 |
} |
1210 |
|
1211 |
maptile * |
1212 |
maptile::find_async (const_utf8_string path, maptile *origin, bool load) |
1213 |
{ |
1214 |
CALL_BEGIN (3); |
1215 |
CALL_ARG (path); |
1216 |
CALL_ARG (origin); |
1217 |
CALL_ARG (load); |
1218 |
CALL_CALL ("cf::map::find_async", G_SCALAR); |
1219 |
|
1220 |
maptile *retval = 0; |
1221 |
if (count) sv_to (POPs, retval); |
1222 |
|
1223 |
CALL_END; |
1224 |
|
1225 |
return retval; |
1226 |
} |
1227 |
|
1228 |
void |
1229 |
maptile::do_load_sync () |
1230 |
{ |
1231 |
CALL_BEGIN (1); |
1232 |
CALL_ARG (this); |
1233 |
CALL_CALL ("cf::map::do_load_sync", G_SCALAR); |
1234 |
CALL_END; |
1235 |
} |
1236 |
|
1237 |
void |
1238 |
object::enter_exit (object *exit) |
1239 |
{ |
1240 |
if (type != PLAYER) |
1241 |
return; |
1242 |
|
1243 |
CALL_BEGIN (2); |
1244 |
CALL_ARG (this); |
1245 |
CALL_ARG (exit); |
1246 |
CALL_CALL ("cf::object::player::enter_exit", G_VOID); |
1247 |
CALL_END; |
1248 |
} |
1249 |
|
1250 |
void |
1251 |
object::player_goto (const_utf8_string path, int x, int y) |
1252 |
{ |
1253 |
if (type != PLAYER) |
1254 |
return; |
1255 |
|
1256 |
CALL_BEGIN (4); |
1257 |
CALL_ARG (this); |
1258 |
CALL_ARG (path); |
1259 |
CALL_ARG (x); |
1260 |
CALL_ARG (y); |
1261 |
CALL_CALL ("cf::object::player::goto", G_VOID); |
1262 |
CALL_END; |
1263 |
} |
1264 |
|
1265 |
const_utf8_string |
1266 |
object::ref () const |
1267 |
{ |
1268 |
if (type == PLAYER) |
1269 |
return format ("player/<1.%llx>/%s", (unsigned long long)uuid.seq, &name); |
1270 |
else |
1271 |
// TODO: should be able to save references within the same map, at least |
1272 |
return 0; |
1273 |
} |
1274 |
|
1275 |
object * |
1276 |
object::deref (const_utf8_string ref) |
1277 |
{ |
1278 |
object *retval = 0; |
1279 |
|
1280 |
if (ref) |
1281 |
{ |
1282 |
CALL_BEGIN (1); |
1283 |
CALL_ARG (ref); |
1284 |
CALL_CALL ("cf::object::deref", G_SCALAR); |
1285 |
|
1286 |
if (count) |
1287 |
sv_to (POPs, retval); |
1288 |
|
1289 |
CALL_END; |
1290 |
} |
1291 |
|
1292 |
return retval; |
1293 |
} |
1294 |
|
1295 |
void |
1296 |
log_backtrace (const_utf8_string msg) |
1297 |
{ |
1298 |
#if HAVE_BACKTRACE |
1299 |
void *addr [20]; |
1300 |
int size = backtrace (addr, 20); |
1301 |
|
1302 |
CALL_BEGIN (size); |
1303 |
CALL_ARG (msg); |
1304 |
for (int i = 0; i < size; ++i) |
1305 |
CALL_ARG ((IV)addr [i]); |
1306 |
CALL_CALL ("cf::_log_backtrace", G_VOID); |
1307 |
CALL_END; |
1308 |
#endif |
1309 |
} |
1310 |
|
1311 |
bool |
1312 |
is_match_expr (const_utf8_string expr) |
1313 |
{ |
1314 |
return !strncmp (expr, "match ", sizeof ("match ") - 1); |
1315 |
} |
1316 |
|
1317 |
bool |
1318 |
match (const_utf8_string expr, object *ob, object *self, object *source, object *originator) |
1319 |
{ |
1320 |
if (!strncmp (expr, "match ", sizeof ("match ") - 1)) |
1321 |
expr += sizeof ("match ") - 1; |
1322 |
|
1323 |
CALL_BEGIN (5); |
1324 |
CALL_ARG (expr); |
1325 |
CALL_ARG (ob); |
1326 |
CALL_ARG (self); |
1327 |
CALL_ARG (source); |
1328 |
CALL_ARG (originator); |
1329 |
CALL_CALL (cv_cf_match_match, G_SCALAR); |
1330 |
|
1331 |
bool matched = count && SvTRUE (TOPs); |
1332 |
|
1333 |
CALL_END; |
1334 |
|
1335 |
return matched; |
1336 |
} |
1337 |
|
1338 |
object * |
1339 |
match_one (const_utf8_string expr, object *ob, object *self, object *source, object *originator) |
1340 |
{ |
1341 |
if (!strncmp (expr, "match ", sizeof ("match ") - 1)) |
1342 |
expr += sizeof ("match ") - 1; |
1343 |
|
1344 |
CALL_BEGIN (5); |
1345 |
CALL_ARG (expr); |
1346 |
CALL_ARG (ob); |
1347 |
CALL_ARG (self); |
1348 |
CALL_ARG (source); |
1349 |
CALL_ARG (originator); |
1350 |
CALL_CALL (cv_cf_match_match, G_ARRAY); |
1351 |
|
1352 |
object *one = 0; |
1353 |
|
1354 |
if (count) |
1355 |
sv_to (TOPs, one); |
1356 |
|
1357 |
CALL_END; |
1358 |
|
1359 |
return one; |
1360 |
} |
1361 |
|
1362 |
///////////////////////////////////////////////////////////////////////////// |
1363 |
|
1364 |
struct EVAPI *evapi::GEVAPI; |
1365 |
struct CoroAPI *coroapi::GCoroAPI; |
1366 |
|
1367 |
void |
1368 |
coroapi::do_cede_to_tick () |
1369 |
{ |
1370 |
cede_pending = 0; |
1371 |
cede (); |
1372 |
} |
1373 |
|
1374 |
void |
1375 |
coroapi::wait_for_tick () |
1376 |
{ |
1377 |
CALL_BEGIN (0); |
1378 |
CALL_CALL ("cf::wait_for_tick", G_DISCARD); |
1379 |
CALL_END; |
1380 |
} |
1381 |
|
1382 |
void |
1383 |
coroapi::wait_for_tick_begin () |
1384 |
{ |
1385 |
CALL_BEGIN (0); |
1386 |
CALL_CALL ("cf::wait_for_tick_begin", G_DISCARD); |
1387 |
CALL_END; |
1388 |
} |
1389 |
|
1390 |
void |
1391 |
iow::poll (int events) |
1392 |
{ |
1393 |
if (events != this->events) |
1394 |
{ |
1395 |
int active = ev_is_active ((ev_io *)this); |
1396 |
if (active) stop (); |
1397 |
ev_io_set ((ev_io *)this, fd, events); |
1398 |
if (active) start (); |
1399 |
} |
1400 |
} |
1401 |
|
1402 |
static void |
1403 |
_connect_to_perl_1 () |
1404 |
{ |
1405 |
stash_cf = gv_stashpv ("cf", 1); |
1406 |
|
1407 |
stash_cf_object_wrap = gv_stashpv ("cf::object::wrap", 1); |
1408 |
stash_cf_object_player_wrap = gv_stashpv ("cf::object::player::wrap", 1); |
1409 |
stash_cf_player_wrap = gv_stashpv ("cf::player::wrap", 1); |
1410 |
stash_cf_map_wrap = gv_stashpv ("cf::map::wrap" , 1); |
1411 |
stash_cf_mapspace_wrap = gv_stashpv ("cf::mapspace::wrap" , 1); |
1412 |
stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1); |
1413 |
stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1); |
1414 |
stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1); |
1415 |
stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); |
1416 |
stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1); |
1417 |
stash_cf_layout_wrap = gv_stashpv ("cf::layout::wrap", 1); |
1418 |
stash_ext_map_world = gv_stashpv ("ext::map_world" , 1); |
1419 |
|
1420 |
sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV); |
1421 |
sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV); |
1422 |
sv_server_tick = get_sv ("cf::SERVER_TICK", 1); SvUPGRADE (sv_server_tick, SVt_IV); |
1423 |
sv_tick_start = get_sv ("cf::TICK_START" , 1); SvUPGRADE (sv_tick_start , SVt_NV); |
1424 |
sv_next_tick = get_sv ("cf::NEXT_TICK" , 1); SvUPGRADE (sv_next_tick , SVt_NV); |
1425 |
|
1426 |
cb_global = get_av ("cf::CB_GLOBAL", 1); |
1427 |
cb_attachable = get_av ("cf::CB_ATTACHABLE", 1); |
1428 |
cb_object = get_av ("cf::CB_OBJECT", 1); |
1429 |
cb_player = get_av ("cf::CB_PLAYER", 1); |
1430 |
cb_client = get_av ("cf::CB_CLIENT", 1); |
1431 |
cb_type = get_av ("cf::CB_TYPE" , 1); |
1432 |
cb_map = get_av ("cf::CB_MAP" , 1); |
1433 |
} |
1434 |
|
1435 |
static void |
1436 |
_connect_to_perl_2 () |
1437 |
{ |
1438 |
cv_cf_do_invoke = (SV *)get_cv ("cf::do_invoke" , 0); assert (cv_cf_do_invoke); |
1439 |
cv_cf__can_merge = (SV *)get_cv ("cf::_can_merge" , 0); assert (cv_cf__can_merge); |
1440 |
cv_cf_client_send_msg = (SV *)get_cv ("cf::client::send_msg", 0); assert (cv_cf_client_send_msg); |
1441 |
cv_cf_tick = (SV *)get_cv ("cf::tick" , 0); assert (cv_cf_tick); |
1442 |
cv_cf_match_match = (SV *)get_cv ("cf::match::match" , 0); assert (cv_cf_match_match); |
1443 |
} |
1444 |
|
1445 |
MODULE = cf PACKAGE = cf PREFIX = cf_ |
1446 |
|
1447 |
BOOT: |
1448 |
{ |
1449 |
I_EV_API (PACKAGE); evapi::GEVAPI = GEVAPI; |
1450 |
I_CORO_API (PACKAGE); coroapi::GCoroAPI = GCoroAPI; |
1451 |
|
1452 |
_connect_to_perl_1 (); |
1453 |
|
1454 |
newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1)); |
1455 |
|
1456 |
//{ |
1457 |
// require_pv ("Time::HiRes"); |
1458 |
// |
1459 |
// SV **svp = hv_fetch (PL_modglobal, "Time::NVtime", 12, 0); |
1460 |
// if (!svp) croak ("Time::HiRes is required"); |
1461 |
// if (!SvIOK(*svp)) croak ("Time::NVtime isn’t a function pointer"); |
1462 |
// coroapi::time = INT2PTR (double(*)(), SvIV(*svp)); |
1463 |
//} |
1464 |
|
1465 |
static const struct { |
1466 |
const char *name; |
1467 |
IV iv; |
1468 |
} *civ, const_iv[] = { |
1469 |
# define const_iv(name) { # name, (IV)name }, |
1470 |
# include "const_iv.h" |
1471 |
# define def(uc, lc, name, plus, change) const_iv (AT_ ## uc) const_iv (ATNR_ ## uc) |
1472 |
# include "attackinc.h" |
1473 |
# undef def |
1474 |
# define def(uc, flags) const_iv (SK_ ## uc) |
1475 |
# include "skillinc.h" |
1476 |
# undef def |
1477 |
# define def(name, use, nonuse) const_iv (body_ ## name) |
1478 |
# include "slotinc.h" |
1479 |
# undef def |
1480 |
|
1481 |
const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) |
1482 |
|
1483 |
const_iv (MAX_TIME) |
1484 |
const_iv (MAXSOCKBUF) |
1485 |
|
1486 |
const_iv (UPD_LOCATION) const_iv (UPD_FLAGS) const_iv (UPD_WEIGHT) const_iv (UPD_FACE) |
1487 |
const_iv (UPD_NAME) const_iv (UPD_ANIM) const_iv (UPD_ANIMSPEED) const_iv (UPD_NROF) |
1488 |
|
1489 |
const_iv (UPD_SP_MANA) const_iv (UPD_SP_GRACE) const_iv (UPD_SP_LEVEL) |
1490 |
|
1491 |
const_iv (F_APPLIED) const_iv (F_LOCATION) const_iv (F_UNPAID) const_iv (F_MAGIC) |
1492 |
const_iv (F_CURSED) const_iv (F_DAMNED) const_iv (F_OPEN) const_iv (F_NOPICK) |
1493 |
const_iv (F_LOCKED) |
1494 |
|
1495 |
const_iv (P_BLOCKSVIEW) const_iv (P_NO_MAGIC) const_iv (P_IS_ALIVE) |
1496 |
const_iv (P_NO_CLERIC) const_iv (P_OUT_OF_MAP) const_iv (P_NEW_MAP) const_iv (P_UPTODATE) |
1497 |
|
1498 |
const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE) |
1499 |
|
1500 |
const_iv (SK_EXP_ADD_SKILL) const_iv (SK_EXP_TOTAL) const_iv (SK_EXP_NONE) |
1501 |
const_iv (SK_SUBTRACT_SKILL_EXP) const_iv (SK_EXP_SKILL_ONLY) |
1502 |
|
1503 |
const_iv (KLASS_ATTACHABLE) const_iv (KLASS_GLOBAL) const_iv (KLASS_OBJECT) |
1504 |
const_iv (KLASS_CLIENT) const_iv (KLASS_PLAYER) const_iv (KLASS_MAP) |
1505 |
|
1506 |
const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT) |
1507 |
|
1508 |
const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES) |
1509 |
}; |
1510 |
|
1511 |
for (civ = const_iv + array_length (const_iv); civ-- > const_iv; ) |
1512 |
newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv)); |
1513 |
|
1514 |
static const struct { |
1515 |
const char *name; |
1516 |
int skip; |
1517 |
IV klass; |
1518 |
IV iv; |
1519 |
} *eiv, event_iv[] = { |
1520 |
# define def(klass,name) { "EVENT_" # klass "_" # name, sizeof ("EVENT_" # klass), (IV)KLASS_ ## klass, (IV)EVENT_ ## klass ## _ ## name }, |
1521 |
# include "eventinc.h" |
1522 |
# undef def |
1523 |
}; |
1524 |
|
1525 |
AV *av = get_av ("cf::EVENT", 1); |
1526 |
|
1527 |
for (eiv = event_iv + array_length (event_iv); eiv-- > event_iv; ) |
1528 |
{ |
1529 |
AV *event = newAV (); |
1530 |
av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0)); |
1531 |
av_push (event, newSViv (eiv->klass)); |
1532 |
av_store (av, eiv->iv, newRV_noinc ((SV *)event)); |
1533 |
newCONSTSUB (stash_cf, (char *)eiv->name, newSViv (eiv->iv)); |
1534 |
} |
1535 |
|
1536 |
// used by autogenerated BOOT sections from genacc |
1537 |
av_reflect = get_av ("cf::REFLECT", 1); |
1538 |
} |
1539 |
|
1540 |
void _gv_clear (SV *gv) |
1541 |
CODE: |
1542 |
assert (SvTYPE (gv) == SVt_PVGV); |
1543 |
# define f(sv) { SV *sv_ = (SV *)(sv); sv = 0; SvREFCNT_dec (sv_); } |
1544 |
f (GvGP (gv)->gp_form); |
1545 |
f (GvGP (gv)->gp_io); |
1546 |
f (GvGP (gv)->gp_sv); |
1547 |
f (GvGP (gv)->gp_av); |
1548 |
f (GvGP (gv)->gp_hv); |
1549 |
f (GvGP (gv)->gp_cv); |
1550 |
GvCVGEN (gv) = 0; |
1551 |
GvMULTI_off (gv); |
1552 |
# undef f |
1553 |
|
1554 |
void _connect_to_perl_1 () |
1555 |
|
1556 |
void _connect_to_perl_2 () |
1557 |
|
1558 |
void _recalc_want () |
1559 |
|
1560 |
# not used by default anymore |
1561 |
void _global_reattach () |
1562 |
CODE: |
1563 |
{ |
1564 |
// reattach to all attachable objects in the game. |
1565 |
for_all_clients (ns) |
1566 |
ns->reattach (); |
1567 |
|
1568 |
for_all_objects (op) |
1569 |
op->reattach (); |
1570 |
} |
1571 |
|
1572 |
void init_anim () |
1573 |
|
1574 |
void init_globals () |
1575 |
|
1576 |
void init_attackmess () |
1577 |
|
1578 |
void init_dynamic () |
1579 |
|
1580 |
void load_settings () |
1581 |
|
1582 |
void reload_exp_table () |
1583 |
|
1584 |
void reload_materials () |
1585 |
|
1586 |
void init_uuid () |
1587 |
CODE: |
1588 |
UUID::init (); |
1589 |
|
1590 |
void init_signals () |
1591 |
|
1592 |
void init_skills () |
1593 |
|
1594 |
void init_beforeplay () |
1595 |
|
1596 |
void evthread_start (int aiofd) |
1597 |
|
1598 |
void cede_to_tick () |
1599 |
CODE: |
1600 |
coroapi::cede_to_tick (); |
1601 |
|
1602 |
NV till_tick () |
1603 |
CODE: |
1604 |
RETVAL = SvNVX (sv_next_tick) - now (); |
1605 |
OUTPUT: |
1606 |
RETVAL |
1607 |
|
1608 |
int tick_inhibit () |
1609 |
CODE: |
1610 |
RETVAL = tick_inhibit; |
1611 |
OUTPUT: |
1612 |
RETVAL |
1613 |
|
1614 |
void tick_inhibit_inc () |
1615 |
CODE: |
1616 |
++tick_inhibit; |
1617 |
|
1618 |
void tick_inhibit_dec () |
1619 |
CODE: |
1620 |
if (!--tick_inhibit) |
1621 |
if (tick_pending) |
1622 |
{ |
1623 |
ev_async_send (EV_DEFAULT, &tick_watcher); |
1624 |
coroapi::cede (); |
1625 |
} |
1626 |
|
1627 |
void one_tick () |
1628 |
CODE: |
1629 |
{ |
1630 |
ev_now_update (EV_DEFAULT); |
1631 |
NOW = ev_now (EV_DEFAULT); |
1632 |
SvNV_set (sv_now, NOW); SvNOK_only (sv_now); |
1633 |
SvNV_set (sv_tick_start, NOW); SvNOK_only (sv_tick_start); |
1634 |
runtime = SvNVX (sv_runtime); |
1635 |
|
1636 |
one_tick (); |
1637 |
|
1638 |
++server_tick; |
1639 |
SvUV_set (sv_server_tick, server_tick); SvIOK_only_UV (sv_server_tick); |
1640 |
|
1641 |
ev_now_update (EV_DEFAULT); |
1642 |
NOW = ev_now (EV_DEFAULT); |
1643 |
SvNV_set (sv_now, NOW); SvNOK_only (sv_now); |
1644 |
|
1645 |
runtime += TICK; |
1646 |
SvNV_set (sv_runtime, runtime); SvNOK_only (sv_runtime); |
1647 |
} |
1648 |
|
1649 |
NV floor (NV x) |
1650 |
|
1651 |
NV ceil (NV x) |
1652 |
|
1653 |
NV rndm (...) |
1654 |
ALIAS: |
1655 |
rmg_rndm = 1 |
1656 |
CODE: |
1657 |
{ |
1658 |
rand_gen &gen = ix ? rmg_rndm : rndm; |
1659 |
switch (items) |
1660 |
{ |
1661 |
case 0: RETVAL = gen (); break; |
1662 |
case 1: RETVAL = gen (SvUV (ST (0))); break; |
1663 |
case 2: RETVAL = gen (SvIV (ST (0)), SvIV (ST (1))); break; |
1664 |
default: croak ("cf::rndm requires zero, one or two parameters."); break; |
1665 |
} |
1666 |
} |
1667 |
OUTPUT: |
1668 |
RETVAL |
1669 |
|
1670 |
NV clamp (NV value, NV min_value, NV max_value) |
1671 |
CODE: |
1672 |
RETVAL = clamp (value, min_value, max_value); |
1673 |
OUTPUT: |
1674 |
RETVAL |
1675 |
|
1676 |
NV lerp (NV value, NV min_in, NV max_in, NV min_out, NV max_out) |
1677 |
CODE: |
1678 |
RETVAL = lerp (value, min_in, max_in, min_out, max_out); |
1679 |
OUTPUT: |
1680 |
RETVAL |
1681 |
|
1682 |
const char *ordinal (int i) |
1683 |
|
1684 |
void weaken (...) |
1685 |
PROTOTYPE: @ |
1686 |
CODE: |
1687 |
while (items > 0) |
1688 |
sv_rvweaken (ST (--items)); |
1689 |
|
1690 |
void log_suspend () |
1691 |
|
1692 |
void log_resume () |
1693 |
|
1694 |
void log_backtrace (utf8_string msg) |
1695 |
|
1696 |
void LOG (int flags, utf8_string msg) |
1697 |
PROTOTYPE: $$ |
1698 |
C_ARGS: flags, "%s", msg |
1699 |
|
1700 |
octet_string path_combine (octet_string base, octet_string path) |
1701 |
PROTOTYPE: $$ |
1702 |
|
1703 |
octet_string path_combine_and_normalize (octet_string base, octet_string path) |
1704 |
PROTOTYPE: $$ |
1705 |
|
1706 |
void |
1707 |
sub_generation_inc () |
1708 |
CODE: |
1709 |
PL_sub_generation++; |
1710 |
|
1711 |
const_octet_string |
1712 |
mapdir () |
1713 |
PROTOTYPE: |
1714 |
ALIAS: |
1715 |
mapdir = 0 |
1716 |
uniquedir = 1 |
1717 |
tmpdir = 2 |
1718 |
confdir = 3 |
1719 |
localdir = 4 |
1720 |
playerdir = 5 |
1721 |
datadir = 6 |
1722 |
CODE: |
1723 |
switch (ix) |
1724 |
{ |
1725 |
case 0: RETVAL = settings.mapdir ; break; |
1726 |
case 1: RETVAL = settings.uniquedir; break; |
1727 |
case 2: RETVAL = settings.tmpdir ; break; |
1728 |
case 3: RETVAL = settings.confdir ; break; |
1729 |
case 4: RETVAL = settings.localdir ; break; |
1730 |
case 5: RETVAL = settings.playerdir; break; |
1731 |
case 6: RETVAL = settings.datadir ; break; |
1732 |
} |
1733 |
OUTPUT: RETVAL |
1734 |
|
1735 |
void abort () |
1736 |
|
1737 |
void reset_signals () |
1738 |
|
1739 |
void fork_abort (const_octet_string cause = "cf::fork_abort") |
1740 |
|
1741 |
void cleanup (const_octet_string cause, bool make_core = false) |
1742 |
|
1743 |
void emergency_save () |
1744 |
|
1745 |
void _exit (int status = EXIT_SUCCESS) |
1746 |
|
1747 |
#if _POSIX_MEMLOCK |
1748 |
|
1749 |
int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) |
1750 |
INIT: |
1751 |
#if __GLIBC__ |
1752 |
mallopt (M_TOP_PAD, 1024 * 1024); |
1753 |
mallopt (M_MMAP_THRESHOLD, 1024 * 1024); |
1754 |
mallopt (M_MMAP_MAX, 0); // likely bug-workaround, also frees memory |
1755 |
if (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 10)) |
1756 |
mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc |
1757 |
#endif |
1758 |
|
1759 |
int munlockall () |
1760 |
|
1761 |
#endif |
1762 |
|
1763 |
int |
1764 |
malloc_trim (IV pad = 0) |
1765 |
|
1766 |
void |
1767 |
mallinfo () |
1768 |
PPCODE: |
1769 |
{ |
1770 |
#if __GLIBC__ |
1771 |
struct mallinfo mai = mallinfo (); |
1772 |
EXTEND (SP, 10*2); |
1773 |
PUSHs (sv_2mortal (newSVpv ("arena" , 0))); PUSHs (sv_2mortal (newSViv (mai.arena))); |
1774 |
PUSHs (sv_2mortal (newSVpv ("ordblks" , 0))); PUSHs (sv_2mortal (newSViv (mai.ordblks))); |
1775 |
PUSHs (sv_2mortal (newSVpv ("smblks" , 0))); PUSHs (sv_2mortal (newSViv (mai.smblks))); |
1776 |
PUSHs (sv_2mortal (newSVpv ("hblks" , 0))); PUSHs (sv_2mortal (newSViv (mai.hblks))); |
1777 |
PUSHs (sv_2mortal (newSVpv ("hblkhd" , 0))); PUSHs (sv_2mortal (newSViv (mai.hblkhd))); |
1778 |
PUSHs (sv_2mortal (newSVpv ("usmblks" , 0))); PUSHs (sv_2mortal (newSViv (mai.usmblks))); |
1779 |
PUSHs (sv_2mortal (newSVpv ("fsmblks" , 0))); PUSHs (sv_2mortal (newSViv (mai.fsmblks))); |
1780 |
PUSHs (sv_2mortal (newSVpv ("uordblks", 0))); PUSHs (sv_2mortal (newSViv (mai.uordblks))); |
1781 |
PUSHs (sv_2mortal (newSVpv ("fordblks", 0))); PUSHs (sv_2mortal (newSViv (mai.fordblks))); |
1782 |
PUSHs (sv_2mortal (newSVpv ("keepcost", 0))); PUSHs (sv_2mortal (newSViv (mai.keepcost))); |
1783 |
#endif |
1784 |
EXTEND (SP, 5*2); |
1785 |
PUSHs (sv_2mortal (newSVpv ("slice_alloc", 0))); PUSHs (sv_2mortal (newSVuv (slice_alloc))); |
1786 |
PUSHs (sv_2mortal (newSVpv ("shstr_alloc", 0))); PUSHs (sv_2mortal (newSVuv (shstr_alloc))); |
1787 |
PUSHs (sv_2mortal (newSVpv ("objects" , 0))); PUSHs (sv_2mortal (newSVuv (objects.size () * sizeof (object)))); |
1788 |
PUSHs (sv_2mortal (newSVpv ("sv_count" , 0))); PUSHs (sv_2mortal (newSVuv (PL_sv_count))); |
1789 |
PUSHs (sv_2mortal (newSVpv ("sv_objcount", 0))); PUSHs (sv_2mortal (newSVuv (PL_sv_objcount))); |
1790 |
} |
1791 |
|
1792 |
int find_animation (utf8_string text) |
1793 |
PROTOTYPE: $ |
1794 |
|
1795 |
int random_roll (int min, int max, object *op, int goodbad); |
1796 |
|
1797 |
const_utf8_string cost_string_from_value(uint64 cost, int approx = 0) |
1798 |
|
1799 |
int exp_to_level (val64 exp) |
1800 |
|
1801 |
val64 level_to_min_exp (int level) |
1802 |
|
1803 |
SV * |
1804 |
attacktype_name (int atnr) |
1805 |
CODE: |
1806 |
RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS) |
1807 |
? newSVpv (attacktype_name [atnr], 0) |
1808 |
: &PL_sv_undef; |
1809 |
OUTPUT: RETVAL |
1810 |
|
1811 |
SV * |
1812 |
attacktype_desc (int atnr) |
1813 |
CODE: |
1814 |
RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS) |
1815 |
? newSVpv (attacktype_desc [atnr], 0) |
1816 |
: &PL_sv_undef; |
1817 |
OUTPUT: RETVAL |
1818 |
|
1819 |
SV * |
1820 |
resist_plus (int atnr) |
1821 |
CODE: |
1822 |
RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS) |
1823 |
? newSVpv (resist_plus [atnr], 0) |
1824 |
: &PL_sv_undef; |
1825 |
OUTPUT: RETVAL |
1826 |
|
1827 |
SV * |
1828 |
change_resist_msg (int atnr) |
1829 |
CODE: |
1830 |
RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS) |
1831 |
? newSVpv (change_resist_msg [atnr], 0) |
1832 |
: &PL_sv_undef; |
1833 |
OUTPUT: RETVAL |
1834 |
|
1835 |
UUID |
1836 |
uuid_cur () |
1837 |
CODE: |
1838 |
RETVAL = UUID::cur; |
1839 |
OUTPUT: |
1840 |
RETVAL |
1841 |
|
1842 |
UUID |
1843 |
uuid_gen () |
1844 |
CODE: |
1845 |
RETVAL = UUID::gen (); |
1846 |
OUTPUT: |
1847 |
RETVAL |
1848 |
|
1849 |
val64 |
1850 |
uuid_seq (UUID uuid) |
1851 |
CODE: |
1852 |
RETVAL = uuid.seq; |
1853 |
OUTPUT: |
1854 |
RETVAL |
1855 |
|
1856 |
UUID |
1857 |
uuid_str (val64 seq) |
1858 |
CODE: |
1859 |
RETVAL.seq = seq; |
1860 |
OUTPUT: |
1861 |
RETVAL |
1862 |
|
1863 |
void |
1864 |
coin_names () |
1865 |
PPCODE: |
1866 |
EXTEND (SP, NUM_COINS); |
1867 |
for (int i = 0; i < NUM_COINS; ++i) |
1868 |
PUSHs (sv_2mortal (newSVpv (coins [i], 0))); |
1869 |
|
1870 |
void |
1871 |
coin_archetypes () |
1872 |
PPCODE: |
1873 |
EXTEND (SP, NUM_COINS); |
1874 |
for (int i = 0; i < NUM_COINS; ++i) |
1875 |
PUSHs (sv_2mortal (to_sv (archetype::find (coins [i])))); |
1876 |
|
1877 |
bool |
1878 |
load_resource_file_ (octet_string filename) |
1879 |
|
1880 |
void |
1881 |
fix_weight () |
1882 |
|
1883 |
MODULE = cf PACKAGE = cf::attachable |
1884 |
|
1885 |
int |
1886 |
valid (SV *obj) |
1887 |
CODE: |
1888 |
RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); |
1889 |
OUTPUT: |
1890 |
RETVAL |
1891 |
|
1892 |
bool should_invoke (attachable *obj, int event) |
1893 |
CODE: |
1894 |
RETVAL = obj->should_invoke ((event_type)event); |
1895 |
OUTPUT: RETVAL |
1896 |
|
1897 |
void |
1898 |
debug_trace (attachable *obj, bool on = true) |
1899 |
CODE: |
1900 |
obj->attachable_flags &= ~attachable::F_DEBUG_TRACE; |
1901 |
if (on) |
1902 |
obj->attachable_flags |= attachable::F_DEBUG_TRACE; |
1903 |
|
1904 |
int mortals_size () |
1905 |
CODE: |
1906 |
RETVAL = attachable::mortals.size (); |
1907 |
OUTPUT: RETVAL |
1908 |
|
1909 |
#object *mortals (U32 index) |
1910 |
# CODE: |
1911 |
# RETVAL = index < attachable::mortals.size () ? attachable::mortals [index] : 0; |
1912 |
# OUTPUT: RETVAL |
1913 |
|
1914 |
INCLUDE: $PERL $srcdir/genacc attachable $srcdir/../include/util.h $srcdir/../include/cfperl.h | |
1915 |
|
1916 |
MODULE = cf PACKAGE = cf::global |
1917 |
|
1918 |
int invoke (SV *klass, int event, ...) |
1919 |
CODE: |
1920 |
if (KLASS_OF (event) != KLASS_GLOBAL) croak ("event class must be GLOBAL"); |
1921 |
AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
1922 |
for (int i = 1; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); |
1923 |
RETVAL = gbl_ev.invoke ((event_type)event, ARG_AV (av), DT_END); |
1924 |
OUTPUT: RETVAL |
1925 |
|
1926 |
MODULE = cf PACKAGE = cf::object PREFIX = cf_object_ |
1927 |
|
1928 |
INCLUDE: $PERL $srcdir/genacc object $srcdir/../include/object.h | |
1929 |
|
1930 |
int invoke (object *op, int event, ...) |
1931 |
CODE: |
1932 |
if (KLASS_OF (event) != KLASS_OBJECT) croak ("event class must be OBJECT"); |
1933 |
AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
1934 |
for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); |
1935 |
RETVAL = op->invoke ((event_type)event, ARG_AV (av), DT_END); |
1936 |
OUTPUT: RETVAL |
1937 |
|
1938 |
SV *registry (object *op) |
1939 |
|
1940 |
int objects_size () |
1941 |
CODE: |
1942 |
RETVAL = objects.size (); |
1943 |
OUTPUT: RETVAL |
1944 |
|
1945 |
object *objects (U32 index) |
1946 |
CODE: |
1947 |
RETVAL = index < objects.size () ? objects [index] : 0; |
1948 |
OUTPUT: RETVAL |
1949 |
|
1950 |
int actives_size () |
1951 |
CODE: |
1952 |
RETVAL = actives.size (); |
1953 |
OUTPUT: RETVAL |
1954 |
|
1955 |
object *actives (U32 index) |
1956 |
CODE: |
1957 |
RETVAL = index < actives.size () ? actives [index] : 0; |
1958 |
OUTPUT: RETVAL |
1959 |
|
1960 |
int mortals_size () |
1961 |
CODE: |
1962 |
RETVAL = attachable::mortals.size (); |
1963 |
OUTPUT: RETVAL |
1964 |
|
1965 |
const_utf8_string slot_name (U32 slot) |
1966 |
ALIAS: |
1967 |
slot_name = 0 |
1968 |
slot_use_name = 1 |
1969 |
slot_nonuse_name = 2 |
1970 |
CODE: |
1971 |
{ |
1972 |
if (slot >= NUM_BODY_LOCATIONS) |
1973 |
croak ("body slot index out of range"); |
1974 |
|
1975 |
switch (ix) |
1976 |
{ |
1977 |
case 0: RETVAL = body_locations[slot].name ; break; |
1978 |
case 1: RETVAL = body_locations[slot].use_name ; break; |
1979 |
case 2: RETVAL = body_locations[slot].nonuse_name; break; |
1980 |
} |
1981 |
} |
1982 |
OUTPUT: |
1983 |
RETVAL |
1984 |
|
1985 |
# missing properties |
1986 |
|
1987 |
object *head (object *op) |
1988 |
PROTOTYPE: $ |
1989 |
CODE: |
1990 |
RETVAL = op->head_ (); |
1991 |
OUTPUT: RETVAL |
1992 |
|
1993 |
void |
1994 |
inv (object *obj) |
1995 |
PROTOTYPE: $ |
1996 |
PPCODE: |
1997 |
{ |
1998 |
for (object *o = obj->inv; o; o = o->below) |
1999 |
XPUSHs (sv_2mortal (to_sv (o))); |
2000 |
} |
2001 |
|
2002 |
void |
2003 |
set_animation (object *op, int idx) |
2004 |
CODE: |
2005 |
SET_ANIMATION (op, idx); |
2006 |
|
2007 |
int |
2008 |
num_animations (object *op) |
2009 |
CODE: |
2010 |
RETVAL = NUM_ANIMATIONS (op); |
2011 |
OUTPUT: RETVAL |
2012 |
|
2013 |
int slot_info (object *op, UV slot, int value = 0) |
2014 |
ALIAS: |
2015 |
slot_used = 1 |
2016 |
CODE: |
2017 |
{ |
2018 |
if (slot >= NUM_BODY_LOCATIONS) |
2019 |
croak ("body slot index out of range"); |
2020 |
|
2021 |
RETVAL = ix ? op->slot[slot].used : op->slot[slot].info; |
2022 |
|
2023 |
if (items > 2) |
2024 |
if (ix) |
2025 |
op->slot[slot].used = value; |
2026 |
else |
2027 |
op->slot[slot].info = value; |
2028 |
} |
2029 |
OUTPUT: |
2030 |
RETVAL |
2031 |
|
2032 |
object *find_best_object_match (object *op, utf8_string match) |
2033 |
|
2034 |
int apply_shop_mat (object *shop_mat, object *op); |
2035 |
|
2036 |
int move (object *op, int dir, object *originator = op) |
2037 |
CODE: |
2038 |
RETVAL = op->move (dir, originator); |
2039 |
OUTPUT: |
2040 |
RETVAL |
2041 |
|
2042 |
void apply_below (object *op) |
2043 |
CODE: |
2044 |
player_apply_below (op); |
2045 |
|
2046 |
int cast_heal (object *op, object *caster, object *spell, int dir = 0) |
2047 |
|
2048 |
int casting_level (object *caster, object *spell) |
2049 |
|
2050 |
int pay_item (object *op, object *buyer) |
2051 |
CODE: |
2052 |
RETVAL = pay_for_item (op, buyer); |
2053 |
OUTPUT: RETVAL |
2054 |
|
2055 |
int pay_amount (object *op, uint64 amount) |
2056 |
CODE: |
2057 |
RETVAL = pay_for_amount (amount, op); |
2058 |
OUTPUT: RETVAL |
2059 |
|
2060 |
void pay_player (object *op, uint64 amount) |
2061 |
|
2062 |
val64 pay_player_arch (object *op, utf8_string arch, uint64 amount) |
2063 |
|
2064 |
int cast_spell (object *op, object *caster, int dir, object *spell_ob, utf8_string stringarg = 0) |
2065 |
|
2066 |
void learn_spell (object *op, object *sp, int special_prayer = 0) |
2067 |
CODE: |
2068 |
do_learn_spell (op, sp, special_prayer); |
2069 |
|
2070 |
void forget_spell (object *op, object *sp) |
2071 |
CODE: |
2072 |
do_forget_spell (op, query_name (sp)); |
2073 |
|
2074 |
object *check_for_spell (object *op, utf8_string spellname) |
2075 |
CODE: |
2076 |
RETVAL = check_spell_known (op, spellname); |
2077 |
OUTPUT: RETVAL |
2078 |
|
2079 |
int query_money (object *op) |
2080 |
ALIAS: money = 0 |
2081 |
|
2082 |
val64 query_cost (object *op, object *who, int flags) |
2083 |
ALIAS: cost = 0 |
2084 |
|
2085 |
void spring_trap (object *op, object *victim) |
2086 |
|
2087 |
int check_trigger (object *op, object *cause) |
2088 |
|
2089 |
void drop (object *who, object *op) |
2090 |
|
2091 |
void pick_up (object *who, object *op) |
2092 |
|
2093 |
void update_object (object *op, int action) |
2094 |
|
2095 |
void change_exp (object *op, uint64 exp, shstr_tmp skill_name = shstr_tmp (), int flag = 0) |
2096 |
|
2097 |
void player_lvl_adj (object *who, object *skill = 0) |
2098 |
|
2099 |
int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL) |
2100 |
|
2101 |
int calc_skill_exp (object *who, object *op, object *skill) |
2102 |
|
2103 |
void push_button (object *op, object *originator) |
2104 |
|
2105 |
void use_trigger (object *op, object *originator) |
2106 |
|
2107 |
void handle_apply_yield (object *op) |
2108 |
|
2109 |
int convert_item (object *item, object *converter) |
2110 |
|
2111 |
void fix_generated_item (object *op, object *creator, int difficulty, int max_magic, int flags); |
2112 |
|
2113 |
MODULE = cf PACKAGE = cf::object PREFIX = cf_ |
2114 |
|
2115 |
# no clean way to get an object from an archetype - stupid idiotic |
2116 |
# dumb kludgy misdesigned plug-in api slowly gets on my nerves. |
2117 |
|
2118 |
object *new (utf8_string archetype = 0) |
2119 |
PROTOTYPE: ;$ |
2120 |
CODE: |
2121 |
RETVAL = archetype |
2122 |
? archetype::get (archetype) |
2123 |
: object::create (); |
2124 |
OUTPUT: |
2125 |
RETVAL |
2126 |
|
2127 |
object *generate (utf8_string arch, object *creator) |
2128 |
CODE: |
2129 |
object *obj = archetype::get (arch); |
2130 |
fix_generated_item (obj, creator, 0, 0, GT_MINIMAL); |
2131 |
RETVAL = obj; |
2132 |
OUTPUT: |
2133 |
RETVAL |
2134 |
|
2135 |
object *find_object (U32 tag) |
2136 |
|
2137 |
object *find_object_uuid (UUID i) |
2138 |
|
2139 |
# TODO: nuke |
2140 |
object *insert_ob_in_map_at (object *ob, maptile *where, object_ornull *orig, int flag, int x, int y) |
2141 |
PROTOTYPE: $$$$$$ |
2142 |
CODE: |
2143 |
{ |
2144 |
RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y); |
2145 |
|
2146 |
if (RETVAL->destroyed ()) |
2147 |
RETVAL = 0; |
2148 |
} |
2149 |
OUTPUT: |
2150 |
RETVAL |
2151 |
|
2152 |
shstr |
2153 |
object::kv_get (shstr key) |
2154 |
CODE: |
2155 |
RETVAL = THIS->kv.get (key); |
2156 |
OUTPUT: |
2157 |
RETVAL |
2158 |
|
2159 |
void |
2160 |
object::kv_del (shstr key) |
2161 |
CODE: |
2162 |
THIS->kv.del (key); |
2163 |
|
2164 |
void |
2165 |
object::kv_set (shstr key, shstr value) |
2166 |
CODE: |
2167 |
THIS->kv.set (key, value); |
2168 |
|
2169 |
object *get_nearest_player (object *ob) |
2170 |
ALIAS: nearest_player = 0 |
2171 |
PREINIT: |
2172 |
extern object *get_nearest_player (object *); |
2173 |
|
2174 |
void rangevector (object *ob, object *other, int flags = 0) |
2175 |
PROTOTYPE: $$;$ |
2176 |
PPCODE: |
2177 |
{ |
2178 |
rv_vector rv; |
2179 |
|
2180 |
get_rangevector (ob, other, &rv, flags); |
2181 |
|
2182 |
EXTEND (SP, 5); |
2183 |
PUSHs (sv_2mortal (newSVuv (rv.distance))); |
2184 |
PUSHs (sv_2mortal (newSViv (rv.distance_x))); |
2185 |
PUSHs (sv_2mortal (newSViv (rv.distance_y))); |
2186 |
PUSHs (sv_2mortal (newSViv (rv.direction))); |
2187 |
PUSHs (sv_2mortal (to_sv (rv.part))); |
2188 |
} |
2189 |
|
2190 |
bool on_same_map_as (object *ob, object *other) |
2191 |
CODE: |
2192 |
RETVAL = on_same_map (ob, other); |
2193 |
OUTPUT: RETVAL |
2194 |
|
2195 |
const_utf8_string |
2196 |
base_name (object *op, int plural = op->nrof > 1) |
2197 |
CODE: |
2198 |
RETVAL = query_base_name (op, plural); |
2199 |
OUTPUT: RETVAL |
2200 |
|
2201 |
# return the tail of an object, excluding itself |
2202 |
void |
2203 |
tail (object *op) |
2204 |
PPCODE: |
2205 |
while ((op = op->more)) |
2206 |
XPUSHs (sv_2mortal (to_sv (op))); |
2207 |
|
2208 |
MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_ |
2209 |
|
2210 |
player *player (object *op) |
2211 |
CODE: |
2212 |
RETVAL = op->contr; |
2213 |
OUTPUT: RETVAL |
2214 |
|
2215 |
bool move_player (object *op, int dir) |
2216 |
|
2217 |
void message (object *op, utf8_string txt, int flags = NDI_ORANGE | NDI_UNIQUE) |
2218 |
CODE: |
2219 |
new_draw_info (flags, 0, op, txt); |
2220 |
|
2221 |
void kill_player (object *op) |
2222 |
|
2223 |
void esrv_send_item (object *pl, object *item) |
2224 |
|
2225 |
void esrv_update_item (object *pl, int what, object *item) |
2226 |
C_ARGS: what, pl, item |
2227 |
|
2228 |
void esrv_del_item (object *pl, int tag) |
2229 |
C_ARGS: pl->contr, tag |
2230 |
|
2231 |
int command_summon (object *op, utf8_string params) |
2232 |
|
2233 |
int command_arrest (object *op, utf8_string params) |
2234 |
|
2235 |
|
2236 |
MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ |
2237 |
|
2238 |
INCLUDE: $PERL $srcdir/genacc player $srcdir/../include/player.h | |
2239 |
|
2240 |
int invoke (player *pl, int event, ...) |
2241 |
CODE: |
2242 |
if (KLASS_OF (event) != KLASS_PLAYER) croak ("event class must be PLAYER"); |
2243 |
AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
2244 |
for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); |
2245 |
RETVAL = pl->invoke ((event_type)event, ARG_AV (av), DT_END); |
2246 |
OUTPUT: RETVAL |
2247 |
|
2248 |
SV *registry (player *pl) |
2249 |
|
2250 |
void |
2251 |
save_stats (player *pl) |
2252 |
CODE: |
2253 |
pl->ob->stats.hp = pl->ob->stats.maxhp; |
2254 |
pl->ob->stats.sp = pl->ob->stats.maxsp; |
2255 |
pl->ob->stats.grace = pl->ob->stats.maxgrace; |
2256 |
pl->orig_stats = pl->ob->stats; |
2257 |
|
2258 |
# should only be temporary |
2259 |
void esrv_new_player (player *pl) |
2260 |
|
2261 |
#d# TODO: replace by blocked_los accessor, fix code using this |
2262 |
bool |
2263 |
cell_visible (player *pl, int dx, int dy) |
2264 |
CODE: |
2265 |
RETVAL = pl->blocked_los (dx, dy) != LOS_BLOCKED; |
2266 |
OUTPUT: |
2267 |
RETVAL |
2268 |
|
2269 |
void |
2270 |
send (player *pl, SV *packet) |
2271 |
CODE: |
2272 |
{ |
2273 |
STRLEN len; |
2274 |
char *buf = SvPVbyte (packet, len); |
2275 |
|
2276 |
if (len > MAXSOCKBUF) |
2277 |
pl->failmsg ("[packet too long for client]"); |
2278 |
else if (pl->ns) |
2279 |
pl->ns->send_packet (buf, len); |
2280 |
} |
2281 |
|
2282 |
void savebed (player *pl, SV *map_path = 0, SV *x = 0, SV *y = 0) |
2283 |
PROTOTYPE: $;$$$ |
2284 |
PPCODE: |
2285 |
if (GIMME_V != G_VOID) |
2286 |
{ |
2287 |
EXTEND (SP, 3); |
2288 |
PUSHs (sv_2mortal (newSVpv (pl->savebed_map, 0))); |
2289 |
PUSHs (sv_2mortal (newSViv (pl->bed_x))); |
2290 |
PUSHs (sv_2mortal (newSViv (pl->bed_y))); |
2291 |
} |
2292 |
if (map_path) sv_to (map_path, pl->savebed_map); |
2293 |
if (x) sv_to (x, pl->bed_x); |
2294 |
if (y) sv_to (y, pl->bed_y); |
2295 |
|
2296 |
void |
2297 |
list () |
2298 |
PPCODE: |
2299 |
for_all_players (pl) |
2300 |
XPUSHs (sv_2mortal (to_sv (pl))); |
2301 |
|
2302 |
|
2303 |
MODULE = cf PACKAGE = cf::map PREFIX = cf_map_ |
2304 |
|
2305 |
int invoke (maptile *map, int event, ...) |
2306 |
CODE: |
2307 |
if (KLASS_OF (event) != KLASS_MAP) croak ("event class must be MAP"); |
2308 |
AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
2309 |
for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); |
2310 |
RETVAL = map->invoke ((event_type)event, ARG_AV (av), DT_END); |
2311 |
OUTPUT: RETVAL |
2312 |
|
2313 |
SV *registry (maptile *map) |
2314 |
|
2315 |
void |
2316 |
find_tagged_objects (maptile *map, utf8_string tag = 0) |
2317 |
PPCODE: |
2318 |
{ |
2319 |
if (!map->spaces) |
2320 |
XSRETURN_EMPTY; |
2321 |
|
2322 |
if (tag) |
2323 |
{ |
2324 |
shstr_cmp tag_ (tag); |
2325 |
|
2326 |
for (mapspace *ms = map->spaces + map->size (); ms-- > map->spaces; ) |
2327 |
for (object *op = ms->bot; op; op = op->above) |
2328 |
if (op->tag == tag_) |
2329 |
XPUSHs (sv_2mortal (to_sv (op))); |
2330 |
} |
2331 |
else |
2332 |
{ |
2333 |
for (mapspace *ms = map->spaces + map->size (); ms-- > map->spaces; ) |
2334 |
for (object *op = ms->bot; op; op = op->above) |
2335 |
if (op->tag) |
2336 |
XPUSHs (sv_2mortal (to_sv (op))); |
2337 |
} |
2338 |
} |
2339 |
|
2340 |
INCLUDE: $PERL $srcdir/genacc maptile $srcdir/../include/map.h | |
2341 |
|
2342 |
void |
2343 |
adjust_daylight () |
2344 |
CODE: |
2345 |
maptile::adjust_daylight (); |
2346 |
|
2347 |
int |
2348 |
outdoor_darkness (int darkness = 0) |
2349 |
CODE: |
2350 |
RETVAL = maptile::outdoor_darkness; |
2351 |
if (items) |
2352 |
maptile::outdoor_darkness = darkness; |
2353 |
OUTPUT: |
2354 |
RETVAL |
2355 |
|
2356 |
void |
2357 |
maptile::instantiate () |
2358 |
|
2359 |
maptile *new () |
2360 |
PROTOTYPE: |
2361 |
CODE: |
2362 |
RETVAL = new maptile; |
2363 |
OUTPUT: |
2364 |
RETVAL |
2365 |
|
2366 |
void |
2367 |
maptile::players () |
2368 |
PPCODE: |
2369 |
if (GIMME_V == G_SCALAR) |
2370 |
XPUSHs (sv_2mortal (to_sv (THIS->players))); |
2371 |
else if (GIMME_V == G_ARRAY) |
2372 |
{ |
2373 |
EXTEND (SP, THIS->players); |
2374 |
for_all_players (pl) |
2375 |
if (pl->ob && pl->ob->map == THIS) |
2376 |
PUSHs (sv_2mortal (to_sv (pl->ob))); |
2377 |
} |
2378 |
|
2379 |
void |
2380 |
maptile::gen_quadmap (int x, int y, int z) |
2381 |
CODE: |
2382 |
gen_quadmap (THIS, x * 50, y * 50, z); |
2383 |
|
2384 |
void |
2385 |
maptile::add_underlay (SV *data, int offset, int stride, SV *palette) |
2386 |
CODE: |
2387 |
{ |
2388 |
if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV) |
2389 |
croak ("maptile::add_underlay: palette must be arrayref"); |
2390 |
|
2391 |
palette = SvRV (palette); |
2392 |
|
2393 |
STRLEN idxlen; |
2394 |
const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen); |
2395 |
|
2396 |
for (int x = 0; x < THIS->width; ++x) |
2397 |
for (int y = 0; y < THIS->height; ++y) |
2398 |
{ |
2399 |
for (object *op = THIS->at (x, y).bot; op; op = op->above) |
2400 |
if (op->flag [FLAG_IS_FLOOR]) |
2401 |
goto skip; |
2402 |
|
2403 |
{ |
2404 |
int offs = offset + y * stride + x; |
2405 |
|
2406 |
if (IN_RANGE_EXC (offs, 0, idxlen)) |
2407 |
{ |
2408 |
if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) |
2409 |
{ |
2410 |
object *ob = archetype::get (cfSvPVutf8_nolen (*elem)); |
2411 |
ob->flag [FLAG_NO_MAP_SAVE] = true; |
2412 |
THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); |
2413 |
|
2414 |
if (ob->randomitems && !ob->above) |
2415 |
{ |
2416 |
ob->create_treasure (ob->randomitems); |
2417 |
|
2418 |
for (object *op = ob->above; op; op = op->above) |
2419 |
op->flag [FLAG_NO_MAP_SAVE] = true; |
2420 |
// TODO: if this is a pickable object, then the item |
2421 |
// will at a bit weird - saving inside the player |
2422 |
// will clear the flag, but when the player drops |
2423 |
// it without logging out, it keeps the flag. |
2424 |
// nobody has reported this, but this can be rather |
2425 |
// annoying on persistent maps. |
2426 |
} |
2427 |
} |
2428 |
} |
2429 |
} |
2430 |
skip: ; |
2431 |
} |
2432 |
} |
2433 |
|
2434 |
void |
2435 |
maptile::set_regiondata (SV *data, int offset, int stride, SV *palette) |
2436 |
CODE: |
2437 |
{ |
2438 |
if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV) |
2439 |
croak ("maptile::set_regiondata: palette must be arrayref"); |
2440 |
|
2441 |
palette = SvRV (palette); |
2442 |
|
2443 |
STRLEN idxlen; |
2444 |
const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen); |
2445 |
|
2446 |
region_ptr *regionmap = new region_ptr [av_len ((AV *)palette) + 1]; |
2447 |
uint8_t *regions = salloc<uint8_t> (THIS->size ()); |
2448 |
|
2449 |
for (int i = av_len ((AV *)palette) + 1; i--; ) |
2450 |
regionmap [i] = region::find (cfSvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1))); |
2451 |
|
2452 |
for (int y = 0; y < THIS->height; ++y) |
2453 |
memcpy (regions + y * THIS->width, idx + offset + y * stride, THIS->width); |
2454 |
|
2455 |
sfree (THIS->regions, THIS->size ()); |
2456 |
delete [] THIS->regionmap; |
2457 |
|
2458 |
THIS->regions = regions; |
2459 |
THIS->regionmap = regionmap; |
2460 |
} |
2461 |
|
2462 |
void |
2463 |
maptile::create_region_treasure () |
2464 |
CODE: |
2465 |
for (int x = 0; x < THIS->width; ++x) |
2466 |
for (int y = 0; y < THIS->height; ++y) |
2467 |
{ |
2468 |
region *rgn = THIS->region (x, y); |
2469 |
|
2470 |
if (object *op = THIS->at (x, y).top) |
2471 |
if (rgn->treasure && rndm () < rgn->treasure_density) |
2472 |
create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty); |
2473 |
} |
2474 |
|
2475 |
int out_of_map (maptile *map, int x, int y) |
2476 |
|
2477 |
void |
2478 |
find_link (maptile *map, shstr_tmp connection) |
2479 |
PPCODE: |
2480 |
if (oblinkpt *obp = map->find_link (connection)) |
2481 |
for (objectlink *ol = obp->link; ol; ol = ol->next) |
2482 |
XPUSHs (sv_2mortal (to_sv ((object *)ol->ob))); |
2483 |
|
2484 |
void |
2485 |
xy_normalise (maptile *map, int x, int y, int dir = 0) |
2486 |
PPCODE: |
2487 |
{ |
2488 |
mapxy pos (map, x, y); |
2489 |
if (!pos.move (dir).normalise ()) |
2490 |
XSRETURN_EMPTY; |
2491 |
|
2492 |
EXTEND (SP, 3); |
2493 |
PUSHs (sv_2mortal (to_sv (pos.m))); |
2494 |
PUSHs (sv_2mortal (to_sv (pos.x))); |
2495 |
PUSHs (sv_2mortal (to_sv (pos.y))); |
2496 |
} |
2497 |
|
2498 |
mapspace * |
2499 |
ms (maptile *map, unsigned int x, unsigned int y, int dir = 0) |
2500 |
PROTOTYPE: $$$;$ |
2501 |
CODE: |
2502 |
{ |
2503 |
mapxy pos (map, x, y); |
2504 |
if (!pos.move (dir).normalise ()) |
2505 |
XSRETURN_UNDEF; |
2506 |
|
2507 |
RETVAL = &*pos; |
2508 |
} |
2509 |
OUTPUT: |
2510 |
RETVAL |
2511 |
|
2512 |
void |
2513 |
at (maptile *map, unsigned int x, unsigned int y, int dir = 0) |
2514 |
PROTOTYPE: $$$;$ |
2515 |
PPCODE: |
2516 |
mapxy pos (map, x, y); |
2517 |
if (pos.move (dir).normalise ()) |
2518 |
for (object *o = pos->bot; o; o = o->above) |
2519 |
XPUSHs (sv_2mortal (to_sv (o))); |
2520 |
|
2521 |
SV * |
2522 |
bot_at (maptile *map, unsigned int x, unsigned int y, int dir = 0) |
2523 |
PROTOTYPE: $$$;$ |
2524 |
ALIAS: |
2525 |
top_at = 1 |
2526 |
flags_at = 2 |
2527 |
light_at = 3 |
2528 |
move_block_at = 4 |
2529 |
move_slow_at = 5 |
2530 |
move_on_at = 6 |
2531 |
move_off_at = 7 |
2532 |
CODE: |
2533 |
{ |
2534 |
mapxy pos (map, x, y); |
2535 |
if (!pos.move (dir).normalise ()) |
2536 |
XSRETURN_UNDEF; |
2537 |
|
2538 |
mapspace &ms = *pos; |
2539 |
|
2540 |
ms.update (); |
2541 |
|
2542 |
switch (ix) |
2543 |
{ |
2544 |
case 0: RETVAL = to_sv (ms.bot ); break; |
2545 |
case 1: RETVAL = to_sv (ms.top ); break; |
2546 |
case 2: RETVAL = newSVuv (ms.flags_ ); break; |
2547 |
case 3: RETVAL = newSViv (ms.light ); break; |
2548 |
case 4: RETVAL = newSVuv (ms.move_block); break; |
2549 |
case 5: RETVAL = newSVuv (ms.move_slow ); break; |
2550 |
case 6: RETVAL = newSVuv (ms.move_on ); break; |
2551 |
case 7: RETVAL = newSVuv (ms.move_off ); break; |
2552 |
} |
2553 |
} |
2554 |
OUTPUT: RETVAL |
2555 |
|
2556 |
# worst xs function of my life |
2557 |
bool |
2558 |
_create_random_map (maptile *self, SV *options) |
2559 |
CODE: |
2560 |
{ |
2561 |
random_map_params rmp ((HV *)SvRV (options)); |
2562 |
RETVAL = self->generate_random_map (&rmp); |
2563 |
} |
2564 |
OUTPUT: |
2565 |
RETVAL |
2566 |
|
2567 |
MODULE = cf PACKAGE = cf::mapspace |
2568 |
|
2569 |
INCLUDE: $PERL $srcdir/genacc mapspace $srcdir/../include/map.h | |
2570 |
|
2571 |
MODULE = cf PACKAGE = cf::arch |
2572 |
|
2573 |
int archetypes_size () |
2574 |
CODE: |
2575 |
RETVAL = archetypes.size (); |
2576 |
OUTPUT: RETVAL |
2577 |
|
2578 |
archetype *archetypes (U32 index) |
2579 |
CODE: |
2580 |
RETVAL = index < archetypes.size () ? archetypes [index] : 0; |
2581 |
OUTPUT: RETVAL |
2582 |
|
2583 |
INCLUDE: $PERL $srcdir/genacc archetype $srcdir/../include/object.h | |
2584 |
|
2585 |
MODULE = cf PACKAGE = cf::party |
2586 |
|
2587 |
partylist *first () |
2588 |
PROTOTYPE: |
2589 |
CODE: |
2590 |
RETVAL = get_firstparty (); |
2591 |
OUTPUT: RETVAL |
2592 |
|
2593 |
INCLUDE: $PERL $srcdir/genacc partylist $srcdir/../include/player.h | |
2594 |
|
2595 |
MODULE = cf PACKAGE = cf::region |
2596 |
|
2597 |
void |
2598 |
list () |
2599 |
PPCODE: |
2600 |
for_all_regions (rgn) |
2601 |
XPUSHs (sv_2mortal (to_sv (rgn))); |
2602 |
|
2603 |
int specificity (region *rgn) |
2604 |
CODE: |
2605 |
RETVAL = 0; |
2606 |
while (rgn = rgn->parent) |
2607 |
RETVAL++; |
2608 |
OUTPUT: RETVAL |
2609 |
|
2610 |
INCLUDE: $PERL $srcdir/genacc region $srcdir/../include/region.h | |
2611 |
|
2612 |
MODULE = cf PACKAGE = cf::living |
2613 |
|
2614 |
INCLUDE: $PERL $srcdir/genacc living $srcdir/../include/living.h | |
2615 |
|
2616 |
MODULE = cf PACKAGE = cf::settings |
2617 |
|
2618 |
INCLUDE: $PERL $srcdir/genacc Settings $srcdir/../include/global.h | |
2619 |
|
2620 |
MODULE = cf PACKAGE = cf::client |
2621 |
|
2622 |
INCLUDE: $PERL $srcdir/genacc client $srcdir/../include/client.h | |
2623 |
|
2624 |
int invoke (client *ns, int event, ...) |
2625 |
CODE: |
2626 |
if (KLASS_OF (event) != KLASS_CLIENT) croak ("event class must be CLIENT"); |
2627 |
AV *av = (AV *)sv_2mortal ((SV *)newAV ()); |
2628 |
for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); |
2629 |
RETVAL = ns->invoke ((event_type)event, ARG_AV (av), DT_END); |
2630 |
OUTPUT: RETVAL |
2631 |
|
2632 |
SV *registry (client *ns) |
2633 |
|
2634 |
void |
2635 |
list () |
2636 |
PPCODE: |
2637 |
EXTEND (SP, clients.size ()); |
2638 |
for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i) |
2639 |
PUSHs (sv_2mortal (to_sv (*i))); |
2640 |
|
2641 |
void |
2642 |
client::send_packet (SV *packet) |
2643 |
CODE: |
2644 |
{ |
2645 |
STRLEN len; |
2646 |
char *buf = SvPVbyte (packet, len); |
2647 |
|
2648 |
if (len > MAXSOCKBUF) |
2649 |
{ |
2650 |
// ugly |
2651 |
if (THIS->pl) |
2652 |
THIS->pl->failmsg ("[packet too long for client]"); |
2653 |
} |
2654 |
else |
2655 |
THIS->send_packet (buf, len); |
2656 |
} |
2657 |
|
2658 |
faceidx |
2659 |
client::need_face (utf8_string name, int pri = 0) |
2660 |
CODE: |
2661 |
RETVAL = face_find (name, 0); |
2662 |
if (RETVAL) |
2663 |
{ |
2664 |
THIS->send_face (RETVAL, pri); |
2665 |
THIS->flush_fx (); |
2666 |
} |
2667 |
OUTPUT: |
2668 |
RETVAL |
2669 |
|
2670 |
int |
2671 |
client::fx_want (int idx, int value = -1) |
2672 |
CODE: |
2673 |
if (0 < idx && idx < FT_NUM) |
2674 |
{ |
2675 |
RETVAL = THIS->fx_want [idx]; |
2676 |
if (items > 2) |
2677 |
THIS->fx_want [idx] = value; |
2678 |
} |
2679 |
else |
2680 |
RETVAL = 0; |
2681 |
OUTPUT: |
2682 |
RETVAL |
2683 |
|
2684 |
MODULE = cf PACKAGE = cf::sound PREFIX = sound_ |
2685 |
|
2686 |
faceidx sound_find (utf8_string name) |
2687 |
|
2688 |
void sound_set (utf8_string str, faceidx face) |
2689 |
|
2690 |
# dire hack |
2691 |
void old_sound_index (int idx, faceidx face) |
2692 |
CODE: |
2693 |
extern faceidx old_sound_index [SOUND_CAST_SPELL_0]; |
2694 |
old_sound_index [idx] = face; |
2695 |
|
2696 |
MODULE = cf PACKAGE = cf::face PREFIX = face_ |
2697 |
|
2698 |
#INCLUDE: $PERL $srcdir/genacc faceset $srcdir/../include/face.h | |
2699 |
|
2700 |
faceidx face_find (utf8_string name, faceidx defidx = 0) |
2701 |
|
2702 |
faceidx alloc (utf8_string name) |
2703 |
CODE: |
2704 |
{ |
2705 |
RETVAL = face_alloc (); |
2706 |
|
2707 |
faces [RETVAL].name = name; |
2708 |
facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL)); |
2709 |
|
2710 |
if (!strcmp (name, BLANK_FACE_NAME )) blank_face = RETVAL; |
2711 |
if (!strcmp (name, EMPTY_FACE_NAME )) empty_face = RETVAL; |
2712 |
if (!strcmp (name, MAGICMOUTH_FACE_NAME)) magicmouth_face = RETVAL; |
2713 |
} |
2714 |
OUTPUT: RETVAL |
2715 |
|
2716 |
void set_type (faceidx idx, int value) |
2717 |
ALIAS: |
2718 |
set_type = 0 |
2719 |
set_visibility = 1 |
2720 |
set_magicmap = 2 |
2721 |
set_smooth = 3 |
2722 |
set_smoothlevel = 4 |
2723 |
CODE: |
2724 |
faceinfo *f = face_info (idx); assert (f); |
2725 |
switch (ix) |
2726 |
{ |
2727 |
case 0: f->type = value; break; |
2728 |
case 1: f->visibility = value; break; |
2729 |
case 2: f->magicmap = value; break; |
2730 |
case 3: f->smooth = value; break; |
2731 |
case 4: f->smoothlevel = value; break; |
2732 |
} |
2733 |
|
2734 |
void set_data (faceidx idx, int faceset, SV *data, SV *chksum) |
2735 |
CODE: |
2736 |
{ |
2737 |
faceinfo *f = face_info (idx); assert (f); |
2738 |
facedata *d = f->face + faceset; |
2739 |
sv_to (data, d->data); |
2740 |
STRLEN clen; |
2741 |
char *cdata = SvPVbyte (chksum, clen); |
2742 |
clen = min (CHKSUM_MAXLEN, clen); |
2743 |
|
2744 |
assert (("cf::face::set_data must be called with a non-empty checksum", clen)); |
2745 |
|
2746 |
if (clen != d->chksum_len || memcmp (d->chksum, cdata, clen)) |
2747 |
{ |
2748 |
d->chksum_len = clen; |
2749 |
memcpy (d->chksum, cdata, clen); |
2750 |
|
2751 |
// invalidate existing client face info |
2752 |
for_all_clients (ns) |
2753 |
if (ns->faceset == faceset) |
2754 |
{ |
2755 |
ns->faces_sent [idx] = false; |
2756 |
ns->force_newmap = true; |
2757 |
} |
2758 |
} |
2759 |
} |
2760 |
|
2761 |
int get_data_size (faceidx idx, int faceset = 0) |
2762 |
CODE: |
2763 |
facedata *d = face_data (idx, faceset); |
2764 |
if (!d) XSRETURN_UNDEF; |
2765 |
RETVAL = d->data.size (); |
2766 |
OUTPUT: |
2767 |
RETVAL |
2768 |
|
2769 |
void set_meta (faceidx idx, SV *sv) |
2770 |
CODE: |
2771 |
{ |
2772 |
faceinfo *f = face_info (idx); assert (f); |
2773 |
SvREFCNT_dec (f->meta_hv); |
2774 |
f->meta_hv = SvOK (sv) ? (HV *)SvREFCNT_inc (SvRV (sv)) : 0; |
2775 |
} |
2776 |
|
2777 |
SV *get_chksum (faceidx idx, int faceset = 0) |
2778 |
CODE: |
2779 |
facedata *d = face_data (idx, faceset); |
2780 |
if (!d) XSRETURN_UNDEF; |
2781 |
RETVAL = newSVpvn ((char *)d->chksum, d->chksum_len); |
2782 |
OUTPUT: |
2783 |
RETVAL |
2784 |
|
2785 |
SV *get_data (faceidx idx, int faceset = 0) |
2786 |
CODE: |
2787 |
facedata *d = face_data (idx, faceset); |
2788 |
if (!d) XSRETURN_UNDEF; |
2789 |
RETVAL = newSVpvn (d->data, d->data.size ()); |
2790 |
OUTPUT: |
2791 |
RETVAL |
2792 |
|
2793 |
SV *get_meta (faceidx idx) |
2794 |
CODE: |
2795 |
faceinfo *f = face_info (idx); assert (f); |
2796 |
if (!f || !f->meta_hv) XSRETURN_UNDEF; |
2797 |
RETVAL = newRV_inc ((SV *)f->meta_hv); |
2798 |
OUTPUT: |
2799 |
RETVAL |
2800 |
|
2801 |
void invalidate (faceidx idx) |
2802 |
CODE: |
2803 |
for_all_clients (ns) |
2804 |
ns->invalidate_face (idx); |
2805 |
|
2806 |
void invalidate_all () |
2807 |
CODE: |
2808 |
for_all_clients (ns) |
2809 |
ns->invalidate_all_faces (); |
2810 |
|
2811 |
MODULE = cf PACKAGE = cf::anim PREFIX = anim_ |
2812 |
|
2813 |
#INCLUDE: $PERL $srcdir/genacc faceset $srcdir/../include/anim.h | |
2814 |
|
2815 |
animidx anim_find (utf8_string name) |
2816 |
CODE: |
2817 |
RETVAL = animation::find (name).number; |
2818 |
OUTPUT: RETVAL |
2819 |
|
2820 |
animidx set (utf8_string name, SV *frames, int facings = 1) |
2821 |
CODE: |
2822 |
{ |
2823 |
if (!SvROK (frames) && SvTYPE (SvRV (frames)) != SVt_PVAV) |
2824 |
croak ("frames must be an arrayref"); |
2825 |
|
2826 |
AV *av = (AV *)SvRV (frames); |
2827 |
|
2828 |
animation *anim = &animation::find (name); |
2829 |
if (anim->number) |
2830 |
{ |
2831 |
anim->resize (av_len (av) + 1); |
2832 |
anim->facings = facings; |
2833 |
} |
2834 |
else |
2835 |
anim = &animation::create (name, av_len (av) + 1, facings); |
2836 |
|
2837 |
for (int i = 0; i < anim->num_animations; ++i) |
2838 |
anim->faces [i] = face_find (cfSvPVutf8_nolen (*av_fetch (av, i, 1))); |
2839 |
} |
2840 |
OUTPUT: RETVAL |
2841 |
|
2842 |
void invalidate_all () |
2843 |
CODE: |
2844 |
for_all_clients (ns) |
2845 |
ns->anims_sent.reset (); |
2846 |
|
2847 |
MODULE = cf PACKAGE = cf::object::freezer |
2848 |
|
2849 |
INCLUDE: $PERL $srcdir/genacc object_freezer $srcdir/../include/cfperl.h | |
2850 |
|
2851 |
SV * |
2852 |
new (char *klass) |
2853 |
CODE: |
2854 |
RETVAL = newSVptr (new object_freezer, gv_stashpv ("cf::object::freezer", 1)); |
2855 |
OUTPUT: RETVAL |
2856 |
|
2857 |
void |
2858 |
DESTROY (SV *sv) |
2859 |
CODE: |
2860 |
object_freezer *self; |
2861 |
sv_to (sv, self); |
2862 |
delete self; |
2863 |
|
2864 |
MODULE = cf PACKAGE = cf::object::thawer |
2865 |
|
2866 |
INCLUDE: $PERL $srcdir/genacc object_thawer $srcdir/../include/freezethaw.h | |
2867 |
|
2868 |
bool |
2869 |
errors_are_fatal (bool fatal) |
2870 |
CODE: |
2871 |
RETVAL = object_thawer::errors_are_fatal; |
2872 |
object_thawer::errors_are_fatal = fatal; |
2873 |
OUTPUT: |
2874 |
RETVAL |
2875 |
|
2876 |
SV * |
2877 |
new_from_file (char *klass, octet_string path) |
2878 |
CODE: |
2879 |
object_thawer *f = new object_thawer (path); |
2880 |
if (!*f) |
2881 |
{ |
2882 |
delete f; |
2883 |
XSRETURN_UNDEF; |
2884 |
} |
2885 |
RETVAL = newSVptr (f, gv_stashpv ("cf::object::thawer", 1)); |
2886 |
OUTPUT: RETVAL |
2887 |
|
2888 |
void |
2889 |
DESTROY (SV *sv) |
2890 |
CODE: |
2891 |
object_thawer *self; |
2892 |
sv_to (sv, self); |
2893 |
delete self; |
2894 |
|
2895 |
void |
2896 |
extract_tags (object_thawer *self) |
2897 |
PPCODE: |
2898 |
while (self->kw != KW_EOF) |
2899 |
{ |
2900 |
PUTBACK; |
2901 |
coroapi::cede_to_tick (); |
2902 |
SPAGAIN; |
2903 |
|
2904 |
if (self->kw == KW_tag) |
2905 |
XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ()))); |
2906 |
|
2907 |
self->skip (); |
2908 |
} |
2909 |
|
2910 |
MODULE = cf PACKAGE = cf::layout |
2911 |
|
2912 |
INCLUDE: $PERL $srcdir/genacc layout $srcdir/../include/rmg.h | |
2913 |
|