1 | /* |
1 | /* |
2 | * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team |
4 | * Copyright (©) 2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2001-2005,2007 by Chachkoff Yann |
5 | * Copyright (©) 2001-2005,2007 by Chachkoff Yann |
6 | * Copyright (©) 2006,2007 by Marc Lehmann <cf@schmorp.de> |
6 | * Copyright (©) 2006,2007 by Marc Lehmann <cf@schmorp.de> |
7 | * |
7 | * |
8 | * Crossfire TRT is free software: you can redistribute it and/or modify |
8 | * Deliantra is free software: you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by |
9 | * it under the terms of the GNU General Public License as published by |
10 | * the Free Software Foundation, either version 3 of the License, or |
10 | * the Free Software Foundation, either version 3 of the License, or |
11 | * (at your option) any later version. |
11 | * (at your option) any later version. |
12 | * |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
… | |
… | |
16 | * GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
17 | * |
17 | * |
18 | * You should have received a copy of the GNU General Public License |
18 | * You should have received a copy of the GNU General Public License |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 | * |
20 | * |
21 | * The authors can be reached via e-mail to <crossfire@schmorp.de> |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | */ |
22 | */ |
23 | |
23 | |
24 | #include "autoconf.h" |
24 | #include "autoconf.h" |
25 | |
25 | |
26 | #define PLUGIN_NAME "perl" |
26 | #define PLUGIN_NAME "perl" |
27 | #define PLUGIN_VERSION "cfperl 0.5" |
27 | #define PLUGIN_VERSION "cfperl 0.5" |
28 | |
|
|
29 | #define CEDES_PER_TICK 5 |
|
|
30 | |
28 | |
31 | #if HAVE_EXECINFO_H |
29 | #if HAVE_EXECINFO_H |
32 | # include <execinfo.h> |
30 | # include <execinfo.h> |
33 | #endif |
31 | #endif |
34 | |
32 | |
35 | #include <plugin_common.h> |
|
|
36 | #include <sounds.h> |
|
|
37 | #include <cstdarg> |
33 | #include <cstdarg> |
38 | #include <sproto.h> |
|
|
39 | |
34 | |
|
|
35 | #include "global.h" |
40 | #include "loader.h" |
36 | #include "loader.h" |
|
|
37 | #include "../random_maps/random_map.h" |
41 | #include "cfperl.h" |
38 | #include "evthread.h" |
42 | #include "shstr.h" |
39 | #include "sproto.h" |
43 | |
40 | |
44 | #include <unistd.h> |
41 | #include <unistd.h> |
45 | #if _POSIX_MEMLOCK |
42 | #if _POSIX_MEMLOCK |
46 | # include <sys/mman.h> |
43 | # include <sys/mman.h> |
|
|
44 | #endif |
|
|
45 | |
|
|
46 | #if HAVE_MALLOC_H |
|
|
47 | # include <malloc.h> |
47 | #endif |
48 | #endif |
48 | |
49 | |
49 | #include <EXTERN.h> |
50 | #include <EXTERN.h> |
50 | #include <perl.h> |
51 | #include <perl.h> |
51 | #include <XSUB.h> |
52 | #include <XSUB.h> |
… | |
… | |
68 | typedef double val64; |
69 | typedef double val64; |
69 | # define newSVval64 newSVnv |
70 | # define newSVval64 newSVnv |
70 | # define SvVAL64 SvNV |
71 | # define SvVAL64 SvNV |
71 | #endif |
72 | #endif |
72 | |
73 | |
73 | static f_plug_api gethook = cfapi_get_hooks; |
|
|
74 | static f_plug_api object_insert = cfapi_object_insert; |
|
|
75 | |
|
|
76 | static PerlInterpreter *perl; |
74 | static PerlInterpreter *perl; |
77 | |
75 | |
78 | tstamp NOW, runtime; |
76 | tstamp NOW, runtime; |
|
|
77 | |
|
|
78 | static int tick_inhibit; |
|
|
79 | static int tick_pending; |
79 | |
80 | |
80 | global gbl_ev; |
81 | global gbl_ev; |
81 | static AV *cb_global, *cb_attachable, *cb_object, *cb_player, *cb_client, *cb_type, *cb_map; |
82 | static AV *cb_global, *cb_attachable, *cb_object, *cb_player, *cb_client, *cb_type, *cb_map; |
82 | static SV *sv_runtime, *sv_next_tick; |
83 | static SV *sv_runtime, *sv_tick_start, *sv_next_tick, *sv_now; |
83 | |
84 | |
84 | bitset<NUM_EVENT_TYPES> ev_want_event; |
85 | bitset<NUM_EVENT_TYPES> ev_want_event; |
85 | bitset<NUM_TYPES> ev_want_type; |
86 | bitset<NUM_TYPES> ev_want_type; |
86 | |
87 | |
87 | static HV |
88 | static HV |
… | |
… | |
97 | *stash_cf_living_wrap; |
98 | *stash_cf_living_wrap; |
98 | |
99 | |
99 | static inline SV * |
100 | static inline SV * |
100 | newSVpv_utf8 (const char *s) |
101 | newSVpv_utf8 (const char *s) |
101 | { |
102 | { |
|
|
103 | if (!s) |
|
|
104 | return newSV (0); |
|
|
105 | |
102 | SV *sv = newSVpv (s, 0); |
106 | SV *sv = newSVpv (s, 0); |
103 | SvUTF8_on (sv); |
107 | SvUTF8_on (sv); |
104 | return sv; |
108 | return sv; |
105 | } |
109 | } |
106 | |
110 | |
107 | static inline SV * |
111 | static inline SV * |
108 | newSVpvn_utf8 (const char *s, STRLEN l) |
112 | newSVpvn_utf8 (const char *s, STRLEN l) |
109 | { |
113 | { |
|
|
114 | if (!s) |
|
|
115 | return newSV (0); |
|
|
116 | |
110 | SV *sv = newSVpvn (s, l); |
117 | SV *sv = newSVpvn (s, l); |
111 | SvUTF8_on (sv); |
118 | SvUTF8_on (sv); |
112 | return sv; |
119 | return sv; |
113 | } |
120 | } |
114 | |
121 | |
… | |
… | |
321 | newSVptr (void *ptr, HV *stash, HV *hv = newHV ()) |
328 | newSVptr (void *ptr, HV *stash, HV *hv = newHV ()) |
322 | { |
329 | { |
323 | SV *sv; |
330 | SV *sv; |
324 | |
331 | |
325 | if (!ptr) |
332 | if (!ptr) |
326 | return &PL_sv_undef; |
333 | return newSV (0); |
327 | |
334 | |
328 | sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, 0, (char *)ptr, 0); |
335 | sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, 0, (char *)ptr, 0); |
329 | return sv_bless (newRV_noinc ((SV *)hv), stash); |
336 | return sv_bless (newRV_noinc ((SV *)hv), stash); |
330 | } |
337 | } |
331 | |
338 | |
… | |
… | |
350 | |
357 | |
351 | static SV * |
358 | static SV * |
352 | newSVattachable (attachable *obj, HV *stash) |
359 | newSVattachable (attachable *obj, HV *stash) |
353 | { |
360 | { |
354 | if (!obj) |
361 | if (!obj) |
355 | return &PL_sv_undef; |
362 | return newSV (0); |
356 | |
363 | |
357 | if (!obj->self) |
364 | if (!obj->self) |
358 | obj->self = newHV (); |
365 | obj->self = newHV (); |
359 | |
366 | |
360 | if (!SvOBJECT (obj->self)) |
367 | if (!SvOBJECT (obj->self)) |
… | |
… | |
407 | return SvPTR (sv, klass); |
414 | return SvPTR (sv, klass); |
408 | else |
415 | else |
409 | return 0; |
416 | return 0; |
410 | } |
417 | } |
411 | |
418 | |
412 | inline SV *to_sv (const shstr & v) { return v ? newSVpvn_utf8 ((const char *)v, v.length ()) : &PL_sv_undef; } |
419 | inline SV *to_sv (const shstr & v) { return newSVpvn_utf8 ((const char *)v, v.length ()); } |
413 | inline SV *to_sv (const char * v) { return v ? newSVpv (v, 0) : &PL_sv_undef; } |
420 | inline SV *to_sv (const char * v) { return v ? newSVpv (v, 0) : newSV (0); } |
414 | inline SV *to_sv (bool v) { return newSViv (v); } |
421 | inline SV *to_sv (bool v) { return newSViv (v); } |
415 | inline SV *to_sv ( signed char v) { return newSViv (v); } |
422 | inline SV *to_sv ( signed char v) { return newSViv (v); } |
416 | inline SV *to_sv (unsigned char v) { return newSViv (v); } |
423 | inline SV *to_sv (unsigned char v) { return newSViv (v); } |
417 | inline SV *to_sv ( signed short v) { return newSViv (v); } |
424 | inline SV *to_sv ( signed short v) { return newSViv (v); } |
418 | inline SV *to_sv (unsigned short v) { return newSVuv (v); } |
425 | inline SV *to_sv (unsigned short v) { return newSVuv (v); } |
… | |
… | |
524 | break; |
531 | break; |
525 | |
532 | |
526 | case DT_STRING: |
533 | case DT_STRING: |
527 | { |
534 | { |
528 | char *str = (char *)va_arg (ap, const char *); |
535 | char *str = (char *)va_arg (ap, const char *); |
529 | sv = str ? newSVpv (str, 0) : &PL_sv_undef; |
536 | sv = str ? newSVpv (str, 0) : newSV (0); |
530 | } |
537 | } |
531 | break; |
538 | break; |
532 | |
539 | |
533 | case DT_DATA: |
540 | case DT_DATA: |
534 | { |
541 | { |
535 | char *str = (char *)va_arg (ap, const void *); |
542 | char *str = (char *)va_arg (ap, const void *); |
536 | int len = va_arg (ap, int); |
543 | int len = va_arg (ap, int); |
537 | sv = str ? newSVpv (str, len) : &PL_sv_undef; |
544 | sv = str ? newSVpv (str, len) : newSV (0); |
538 | } |
545 | } |
539 | break; |
546 | break; |
540 | |
547 | |
541 | case DT_OBJECT: |
548 | case DT_OBJECT: |
542 | sv = to_sv (va_arg (ap, object *)); |
549 | sv = to_sv (va_arg (ap, object *)); |
… | |
… | |
584 | va_end (ap); |
591 | va_end (ap); |
585 | |
592 | |
586 | return sv; |
593 | return sv; |
587 | } |
594 | } |
588 | |
595 | |
589 | static SV * |
|
|
590 | newSVcfapi (int type, ...) |
|
|
591 | { |
|
|
592 | SV *sv; |
|
|
593 | |
|
|
594 | va_list ap; |
|
|
595 | va_start (ap, type); |
|
|
596 | |
|
|
597 | switch (type) |
|
|
598 | { |
|
|
599 | case CFAPI_INT: sv = newSViv (*va_arg (ap, int * )); break; |
|
|
600 | case CFAPI_LONG: sv = newSVval64 (*va_arg (ap, sint64 *)); break; |
|
|
601 | case CFAPI_DOUBLE: sv = newSVnv (*va_arg (ap, double *)); break; |
|
|
602 | case CFAPI_STRING: sv = newSVdt_va (ap, DT_STRING); break; |
|
|
603 | case CFAPI_POBJECT: sv = newSVdt_va (ap, DT_OBJECT); break; |
|
|
604 | case CFAPI_PMAP: sv = newSVdt_va (ap, DT_MAP ); break; |
|
|
605 | case CFAPI_PPLAYER: sv = newSVdt_va (ap, DT_PLAYER); break; |
|
|
606 | case CFAPI_PARCH: sv = newSVdt_va (ap, DT_ARCH ); break; |
|
|
607 | case CFAPI_PPARTY: sv = newSVdt_va (ap, DT_PARTY ); break; |
|
|
608 | case CFAPI_PREGION: sv = newSVdt_va (ap, DT_REGION); break; |
|
|
609 | |
|
|
610 | default: |
|
|
611 | assert (("unhandled type in newSVcfapi", 0)); |
|
|
612 | } |
|
|
613 | |
|
|
614 | va_end (ap); |
|
|
615 | |
|
|
616 | return sv; |
|
|
617 | } |
|
|
618 | |
|
|
619 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
596 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
620 | |
597 | |
621 | SV * |
598 | SV * |
622 | registry (attachable *ext) |
599 | registry (attachable *ext) |
623 | { |
600 | { |
… | |
… | |
627 | return newRV_inc ((SV *)ext->cb); |
604 | return newRV_inc ((SV *)ext->cb); |
628 | } |
605 | } |
629 | |
606 | |
630 | ///////////////////////////////////////////////////////////////////////////// |
607 | ///////////////////////////////////////////////////////////////////////////// |
631 | |
608 | |
632 | extern "C" int cfperl_initPlugin (const char *iversion, f_plug_api gethooksptr) |
|
|
633 | { |
|
|
634 | return 0; |
|
|
635 | } |
|
|
636 | |
|
|
637 | static CommArray_s rtn_cmd; |
|
|
638 | |
|
|
639 | static int |
|
|
640 | runPluginCommand (object *obj, char *params) |
|
|
641 | { |
|
|
642 | return -1; |
|
|
643 | } |
|
|
644 | |
|
|
645 | extern "C" void *cfperl_getPluginProperty (int *type, ...) |
|
|
646 | { |
|
|
647 | va_list args; |
|
|
648 | char *propname; |
|
|
649 | int i; |
|
|
650 | va_start (args, type); |
|
|
651 | propname = va_arg (args, char *); |
|
|
652 | //printf ("Property name: %s\n", propname); |
|
|
653 | |
|
|
654 | if (!strcmp (propname, "command?")) |
|
|
655 | return NULL; |
|
|
656 | else if (!strcmp (propname, "Identification")) |
|
|
657 | { |
|
|
658 | va_end (args); |
|
|
659 | return (void *)PLUGIN_NAME; |
|
|
660 | } |
|
|
661 | else if (!strcmp (propname, "FullName")) |
|
|
662 | { |
|
|
663 | va_end (args); |
|
|
664 | return (void *)PLUGIN_VERSION; |
|
|
665 | } |
|
|
666 | else |
|
|
667 | va_end (args); |
|
|
668 | |
|
|
669 | return NULL; |
|
|
670 | } |
|
|
671 | |
|
|
672 | extern "C" int cfperl_postInitPlugin () |
|
|
673 | { |
|
|
674 | int hooktype = 1; |
|
|
675 | int rtype = 0; |
|
|
676 | |
|
|
677 | cf_init_plugin (gethook); |
|
|
678 | |
|
|
679 | return 0; |
|
|
680 | } |
|
|
681 | |
|
|
682 | extern "C" int cfperl_closePlugin () |
|
|
683 | { |
|
|
684 | return 0; |
|
|
685 | } |
|
|
686 | |
|
|
687 | void |
609 | void |
688 | cfperl_init () |
610 | cfperl_init () |
689 | { |
611 | { |
|
|
612 | extern char **environ; |
|
|
613 | |
690 | PERL_SYS_INIT3 (&settings.argc, &settings.argv, 0); |
614 | PERL_SYS_INIT3 (&settings.argc, &settings.argv, &environ); |
691 | perl = perl_alloc (); |
615 | perl = perl_alloc (); |
692 | perl_construct (perl); |
616 | perl_construct (perl); |
693 | |
617 | |
694 | PL_exit_flags |= PERL_EXIT_DESTRUCT_END; |
618 | PL_exit_flags |= PERL_EXIT_DESTRUCT_END; |
695 | |
619 | |
696 | const char *argv[] = { |
620 | const char *argv[] = { |
697 | settings.argv [0], |
621 | settings.argv [0], |
698 | "-e" |
622 | "-e" |
699 | "use Event; use Coro;" // required for bootstrap |
623 | "use EV; use Coro;" // required for bootstrap |
700 | "cf->bootstrap;" // required for datadir :*> |
624 | "cf->bootstrap;" // required for datadir :*> |
701 | "unshift @INC, cf::datadir ();" |
625 | "unshift @INC, cf::datadir ();" |
702 | "require cf;" |
626 | "require cf;" |
703 | }; |
627 | }; |
704 | |
628 | |
705 | if (perl_parse (perl, xs_init, 2, (char **)argv, (char **)NULL) |
629 | if (perl_parse (perl, xs_init, 2, (char **)argv, environ) |
706 | || perl_run (perl)) |
630 | || perl_run (perl)) |
707 | { |
631 | { |
708 | printf ("unable to initialize perl-interpreter, aborting.\n"); |
632 | printf ("unable to initialize perl-interpreter, aborting.\n"); |
709 | exit (EXIT_FAILURE); |
633 | exit (EXIT_FAILURE); |
710 | } |
634 | } |
… | |
… | |
987 | } |
911 | } |
988 | |
912 | |
989 | ///////////////////////////////////////////////////////////////////////////// |
913 | ///////////////////////////////////////////////////////////////////////////// |
990 | // various c++ => perl glue functions |
914 | // various c++ => perl glue functions |
991 | |
915 | |
|
|
916 | void cfperl_tick () |
|
|
917 | { |
|
|
918 | tick_pending = 1; |
|
|
919 | |
|
|
920 | if (tick_inhibit) |
|
|
921 | return; |
|
|
922 | |
|
|
923 | tick_pending = 0; |
|
|
924 | |
|
|
925 | dSP; |
|
|
926 | |
|
|
927 | PUSHMARK (SP); |
|
|
928 | PUTBACK; |
|
|
929 | call_pv ("cf::tick", G_DISCARD | G_VOID); |
|
|
930 | |
|
|
931 | SvNV_set (sv_next_tick, get_next_tick ()); SvNOK_only (sv_next_tick); |
|
|
932 | } |
|
|
933 | |
992 | void |
934 | void |
993 | cfperl_emergency_save () |
935 | cfperl_emergency_save () |
994 | { |
936 | { |
995 | CALL_BEGIN (0); |
937 | CALL_BEGIN (0); |
996 | CALL_CALL ("cf::emergency_save", G_VOID); |
938 | CALL_CALL ("cf::emergency_save", G_VOID); |
… | |
… | |
1179 | #endif |
1121 | #endif |
1180 | } |
1122 | } |
1181 | |
1123 | |
1182 | ///////////////////////////////////////////////////////////////////////////// |
1124 | ///////////////////////////////////////////////////////////////////////////// |
1183 | |
1125 | |
1184 | struct EventAPI *watcher_base::GEventAPI; |
1126 | struct EVAPI *evapi::GEVAPI; |
1185 | struct CoroAPI *coroapi::GCoroAPI; |
1127 | struct CoroAPI *coroapi::GCoroAPI; |
1186 | |
|
|
1187 | int coroapi::cede_counter; |
|
|
1188 | tstamp coroapi::next_cede; |
|
|
1189 | |
1128 | |
1190 | void coroapi::do_cede_to_tick () |
1129 | void coroapi::do_cede_to_tick () |
1191 | { |
1130 | { |
1192 | cede_counter = 0; |
1131 | cede_pending = 0; |
1193 | |
|
|
1194 | cede (); |
1132 | cede (); |
1195 | |
|
|
1196 | next_cede += (TICK / CEDES_PER_TICK) * 0.99; |
|
|
1197 | if (next_cede > SvNV (sv_next_tick) - 0.02) |
|
|
1198 | next_cede = SvNV (sv_next_tick); |
|
|
1199 | } |
|
|
1200 | |
|
|
1201 | void coroapi::do_cede_every () |
|
|
1202 | { |
|
|
1203 | cede_counter = 0; |
|
|
1204 | |
|
|
1205 | if (coroapi::nready ()) |
|
|
1206 | coroapi::cede (); |
|
|
1207 | } |
|
|
1208 | |
|
|
1209 | void coroapi::do_cede_to_tick_every () |
|
|
1210 | { |
|
|
1211 | cede_counter = 0; |
|
|
1212 | |
|
|
1213 | cede_to_tick (); |
|
|
1214 | } |
1133 | } |
1215 | |
1134 | |
1216 | void |
1135 | void |
1217 | coroapi::wait_for_tick () |
1136 | coroapi::wait_for_tick () |
1218 | { |
1137 | { |
… | |
… | |
1227 | CALL_BEGIN (0); |
1146 | CALL_BEGIN (0); |
1228 | CALL_CALL ("cf::wait_for_tick_begin", G_DISCARD); |
1147 | CALL_CALL ("cf::wait_for_tick_begin", G_DISCARD); |
1229 | CALL_END; |
1148 | CALL_END; |
1230 | } |
1149 | } |
1231 | |
1150 | |
1232 | static void |
|
|
1233 | iw_dispatch (pe_event *ev) |
|
|
1234 | { |
|
|
1235 | iw *w = (iw *)ev->ext_data; |
|
|
1236 | w->call (*w); |
|
|
1237 | } |
|
|
1238 | |
|
|
1239 | void |
|
|
1240 | iw::alloc () |
|
|
1241 | { |
|
|
1242 | pe = GEventAPI->new_idle (0, 0); |
|
|
1243 | |
|
|
1244 | WaREENTRANT_off (pe); |
|
|
1245 | pe->base.callback = (void *)iw_dispatch; |
|
|
1246 | pe->base.ext_data = (void *)this; |
|
|
1247 | } |
|
|
1248 | |
|
|
1249 | static void iow_dispatch (pe_event *ev) |
|
|
1250 | { |
|
|
1251 | iow *w = (iow *)ev->ext_data; |
|
|
1252 | w->call (*w, ((pe_ioevent *)ev)->got); |
|
|
1253 | } |
|
|
1254 | |
|
|
1255 | void |
|
|
1256 | iow::alloc () |
|
|
1257 | { |
|
|
1258 | pe = GEventAPI->new_io (0, 0); |
|
|
1259 | |
|
|
1260 | WaREENTRANT_off (pe); |
|
|
1261 | pe->base.callback = (void *)iow_dispatch; |
|
|
1262 | pe->base.ext_data = (void *)this; |
|
|
1263 | |
|
|
1264 | pe->fd = -1; |
|
|
1265 | pe->poll = 0; |
|
|
1266 | } |
|
|
1267 | |
|
|
1268 | void |
|
|
1269 | iow::fd (int fd) |
|
|
1270 | { |
|
|
1271 | pe->fd = fd; |
|
|
1272 | } |
|
|
1273 | |
|
|
1274 | int |
|
|
1275 | iow::poll () |
|
|
1276 | { |
|
|
1277 | return pe->poll; |
|
|
1278 | } |
|
|
1279 | |
|
|
1280 | void |
1151 | void |
1281 | iow::poll (int events) |
1152 | iow::poll (int events) |
1282 | { |
1153 | { |
1283 | if (pe->poll != events) |
1154 | if (events != this->events) |
1284 | { |
1155 | { |
|
|
1156 | int active = ev_is_active ((ev_io *)this); |
1285 | if (pe->poll) stop (); |
1157 | if (active) stop (); |
1286 | pe->poll = events; |
1158 | ev_io_set ((ev_io *)this, fd, events); |
1287 | if (pe->poll) start (); |
1159 | if (active) start (); |
1288 | } |
1160 | } |
1289 | } |
1161 | } |
1290 | |
1162 | |
1291 | void |
1163 | void |
1292 | _connect_to_perl () |
1164 | _connect_to_perl () |
1293 | { |
1165 | { |
1294 | stash_cf = gv_stashpv ("cf" , 1); |
1166 | stash_cf = gv_stashpv ("cf", 1); |
1295 | |
1167 | |
1296 | stash_cf_object_wrap = gv_stashpv ("cf::object::wrap", 1); |
1168 | stash_cf_object_wrap = gv_stashpv ("cf::object::wrap", 1); |
1297 | stash_cf_object_player_wrap = gv_stashpv ("cf::object::player::wrap", 1); |
1169 | stash_cf_object_player_wrap = gv_stashpv ("cf::object::player::wrap", 1); |
1298 | stash_cf_player_wrap = gv_stashpv ("cf::player::wrap", 1); |
1170 | stash_cf_player_wrap = gv_stashpv ("cf::player::wrap", 1); |
1299 | stash_cf_map_wrap = gv_stashpv ("cf::map::wrap" , 1); |
1171 | stash_cf_map_wrap = gv_stashpv ("cf::map::wrap" , 1); |
… | |
… | |
1301 | stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1); |
1173 | stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1); |
1302 | stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1); |
1174 | stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1); |
1303 | stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); |
1175 | stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); |
1304 | stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1); |
1176 | stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1); |
1305 | |
1177 | |
|
|
1178 | sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV); |
1306 | sv_runtime = get_sv ("cf::RUNTIME" , 1); sv_upgrade (sv_runtime , SVt_NV); |
1179 | sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV); |
|
|
1180 | sv_tick_start = get_sv ("cf::TICK_START", 1); SvUPGRADE (sv_tick_start, SVt_NV); |
1307 | sv_next_tick = get_sv ("cf::NEXT_TICK", 1); sv_upgrade (sv_next_tick, SVt_NV); |
1181 | sv_next_tick = get_sv ("cf::NEXT_TICK" , 1); SvUPGRADE (sv_next_tick , SVt_NV); |
1308 | |
1182 | |
1309 | cb_global = get_av ("cf::CB_GLOBAL", 1); |
1183 | cb_global = get_av ("cf::CB_GLOBAL", 1); |
1310 | cb_attachable = get_av ("cf::CB_ATTACHABLE", 1); |
1184 | cb_attachable = get_av ("cf::CB_ATTACHABLE", 1); |
1311 | cb_object = get_av ("cf::CB_OBJECT", 1); |
1185 | cb_object = get_av ("cf::CB_OBJECT", 1); |
1312 | cb_player = get_av ("cf::CB_PLAYER", 1); |
1186 | cb_player = get_av ("cf::CB_PLAYER", 1); |
… | |
… | |
1317 | |
1191 | |
1318 | MODULE = cf PACKAGE = cf PREFIX = cf_ |
1192 | MODULE = cf PACKAGE = cf PREFIX = cf_ |
1319 | |
1193 | |
1320 | BOOT: |
1194 | BOOT: |
1321 | { |
1195 | { |
1322 | I_EVENT_API (PACKAGE); watcher_base::GEventAPI = GEventAPI; |
1196 | I_EV_API (PACKAGE); evapi::GEVAPI = GEVAPI; |
1323 | I_CORO_API (PACKAGE); coroapi::GCoroAPI = GCoroAPI; |
1197 | I_CORO_API (PACKAGE); coroapi::GCoroAPI = GCoroAPI; |
1324 | |
1198 | |
1325 | _connect_to_perl (); |
1199 | _connect_to_perl (); |
1326 | |
1200 | |
1327 | newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1)); |
1201 | newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1)); |
1328 | |
1202 | |
… | |
… | |
1346 | const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd) |
1220 | const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd) |
1347 | |
1221 | |
1348 | const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) |
1222 | const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) |
1349 | |
1223 | |
1350 | const_iv (MAX_TIME) |
1224 | const_iv (MAX_TIME) |
|
|
1225 | const_iv (MAXSOCKBUF) |
1351 | |
1226 | |
1352 | const_iv (NUM_BODY_LOCATIONS) |
1227 | const_iv (NUM_BODY_LOCATIONS) |
1353 | const_iv (body_range) const_iv (body_shield) const_iv (body_combat) |
1228 | const_iv (body_range) const_iv (body_shield) const_iv (body_combat) |
1354 | const_iv (body_arm) const_iv (body_torso) const_iv (body_head) |
1229 | const_iv (body_arm) const_iv (body_torso) const_iv (body_head) |
1355 | const_iv (body_neck) const_iv (body_skill) const_iv (body_finger) |
1230 | const_iv (body_neck) const_iv (body_skill) const_iv (body_finger) |
… | |
… | |
1500 | const_iv (P_NO_CLERIC) const_iv (P_OUT_OF_MAP) const_iv (P_NEW_MAP) const_iv (P_UPTODATE) |
1375 | const_iv (P_NO_CLERIC) const_iv (P_OUT_OF_MAP) const_iv (P_NEW_MAP) const_iv (P_UPTODATE) |
1501 | |
1376 | |
1502 | const_iv (UP_OBJ_INSERT) const_iv (UP_OBJ_REMOVE) const_iv (UP_OBJ_CHANGE) const_iv (UP_OBJ_FACE) |
1377 | const_iv (UP_OBJ_INSERT) const_iv (UP_OBJ_REMOVE) const_iv (UP_OBJ_CHANGE) const_iv (UP_OBJ_FACE) |
1503 | |
1378 | |
1504 | const_iv (INS_NO_MERGE) const_iv (INS_ABOVE_FLOOR_ONLY) const_iv (INS_NO_WALK_ON) |
1379 | const_iv (INS_NO_MERGE) const_iv (INS_ABOVE_FLOOR_ONLY) const_iv (INS_NO_WALK_ON) |
1505 | const_iv (INS_ON_TOP) const_iv (INS_BELOW_ORIGINATOR) const_iv (INS_MAP_LOAD) |
1380 | const_iv (INS_ON_TOP) const_iv (INS_BELOW_ORIGINATOR) |
1506 | |
1381 | |
1507 | const_iv (WILL_APPLY_HANDLE) const_iv (WILL_APPLY_TREASURE) const_iv (WILL_APPLY_EARTHWALL) |
1382 | const_iv (WILL_APPLY_HANDLE) const_iv (WILL_APPLY_TREASURE) const_iv (WILL_APPLY_EARTHWALL) |
1508 | const_iv (WILL_APPLY_DOOR) const_iv (WILL_APPLY_FOOD) |
1383 | const_iv (WILL_APPLY_DOOR) const_iv (WILL_APPLY_FOOD) |
1509 | |
1384 | |
1510 | const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE) |
1385 | const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE) |
… | |
… | |
1549 | const_iv (MAP_IN_MEMORY) const_iv (MAP_SWAPPED) const_iv (MAP_LOADING) const_iv (MAP_SAVING) |
1424 | const_iv (MAP_IN_MEMORY) const_iv (MAP_SWAPPED) const_iv (MAP_LOADING) const_iv (MAP_SAVING) |
1550 | |
1425 | |
1551 | const_iv (KLASS_ATTACHABLE) const_iv (KLASS_GLOBAL) const_iv (KLASS_OBJECT) |
1426 | const_iv (KLASS_ATTACHABLE) const_iv (KLASS_GLOBAL) const_iv (KLASS_OBJECT) |
1552 | const_iv (KLASS_CLIENT) const_iv (KLASS_PLAYER) const_iv (KLASS_MAP) |
1427 | const_iv (KLASS_CLIENT) const_iv (KLASS_PLAYER) const_iv (KLASS_MAP) |
1553 | |
1428 | |
|
|
1429 | const_iv (VERSION_CS) const_iv (VERSION_SC) |
|
|
1430 | |
1554 | const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT) |
1431 | const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT) |
1555 | |
1432 | |
1556 | const_iv (ST_DEAD) const_iv (ST_SETUP) const_iv (ST_PLAYING) const_iv (ST_CUSTOM) |
1433 | const_iv (ST_DEAD) const_iv (ST_SETUP) const_iv (ST_PLAYING) const_iv (ST_CUSTOM) |
1557 | |
1434 | |
1558 | const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES) |
1435 | const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES) |
… | |
… | |
1657 | } |
1534 | } |
1658 | |
1535 | |
1659 | SvCUR_set (data_sv, dst - SvPVX (data_sv)); |
1536 | SvCUR_set (data_sv, dst - SvPVX (data_sv)); |
1660 | } |
1537 | } |
1661 | |
1538 | |
|
|
1539 | void evthread_start () |
|
|
1540 | |
1662 | void _post_tick () |
1541 | void cede_to_tick () |
1663 | CODE: |
1542 | CODE: |
1664 | coroapi::next_cede = SvNV (sv_next_tick) - TICK * (1. - 1. / CEDES_PER_TICK); |
1543 | coroapi::cede_to_tick (); |
1665 | |
1544 | |
1666 | NV till_cede () |
1545 | NV till_tick () |
1667 | CODE: |
1546 | CODE: |
1668 | RETVAL = coroapi::next_cede - now (); |
1547 | RETVAL = SvNVX (sv_next_tick) - now (); |
1669 | OUTPUT: |
1548 | OUTPUT: |
1670 | RETVAL |
1549 | RETVAL |
1671 | |
1550 | |
1672 | NV till_tick () |
1551 | int tick_inhibit () |
1673 | CODE: |
1552 | CODE: |
1674 | RETVAL = SvNV (sv_next_tick) - now (); |
1553 | RETVAL = tick_inhibit; |
1675 | OUTPUT: |
1554 | OUTPUT: |
1676 | RETVAL |
1555 | RETVAL |
|
|
1556 | |
|
|
1557 | void tick_inhibit_inc () |
|
|
1558 | CODE: |
|
|
1559 | ++tick_inhibit; |
|
|
1560 | |
|
|
1561 | void tick_inhibit_dec () |
|
|
1562 | CODE: |
|
|
1563 | if (!--tick_inhibit) |
|
|
1564 | if (tick_pending) |
|
|
1565 | { |
|
|
1566 | ev_async_send (EV_DEFAULT, &tick_watcher); |
|
|
1567 | coroapi::cede (); |
|
|
1568 | } |
|
|
1569 | |
|
|
1570 | void server_tick () |
|
|
1571 | CODE: |
|
|
1572 | { |
|
|
1573 | NOW = ev_now (EV_DEFAULT); |
|
|
1574 | SvNV_set (sv_now, NOW); SvNOK_only (sv_now); |
|
|
1575 | SvNV_set (sv_tick_start, NOW); SvNOK_only (sv_tick_start); |
|
|
1576 | runtime = SvNVX (sv_runtime); |
|
|
1577 | |
|
|
1578 | server_tick (); |
|
|
1579 | |
|
|
1580 | NOW = ev_time (); |
|
|
1581 | SvNV_set (sv_now, NOW); SvNOK_only (sv_now); |
|
|
1582 | runtime += TICK; |
|
|
1583 | SvNV_set (sv_runtime, runtime); SvNOK_only (sv_runtime); |
|
|
1584 | } |
1677 | |
1585 | |
1678 | NV floor (NV x) |
1586 | NV floor (NV x) |
1679 | |
1587 | |
1680 | NV ceil (NV x) |
1588 | NV ceil (NV x) |
1681 | |
1589 | |
… | |
… | |
1701 | CODE: |
1609 | CODE: |
1702 | RETVAL = lerp (value, min_in, max_in, min_out, max_out); |
1610 | RETVAL = lerp (value, min_in, max_in, min_out, max_out); |
1703 | OUTPUT: |
1611 | OUTPUT: |
1704 | RETVAL |
1612 | RETVAL |
1705 | |
1613 | |
1706 | void cede_to_tick () |
1614 | void weaken (...) |
1707 | CODE: |
1615 | PROTOTYPE: @ |
1708 | coroapi::cede_to_tick (); |
1616 | CODE: |
1709 | |
1617 | while (items > 0) |
1710 | void server_tick () |
1618 | sv_rvweaken (ST (--items)); |
1711 | CODE: |
|
|
1712 | NOW = now (); |
|
|
1713 | runtime = SvNVx (sv_runtime); |
|
|
1714 | server_tick (); |
|
|
1715 | |
1619 | |
1716 | void |
1620 | void |
1717 | log_backtrace (utf8_string msg) |
1621 | log_backtrace (utf8_string msg) |
1718 | |
1622 | |
1719 | void |
1623 | void |
… | |
… | |
1724 | octet_string path_combine (octet_string base, octet_string path) |
1628 | octet_string path_combine (octet_string base, octet_string path) |
1725 | PROTOTYPE: $$ |
1629 | PROTOTYPE: $$ |
1726 | |
1630 | |
1727 | octet_string path_combine_and_normalize (octet_string base, octet_string path) |
1631 | octet_string path_combine_and_normalize (octet_string base, octet_string path) |
1728 | PROTOTYPE: $$ |
1632 | PROTOTYPE: $$ |
|
|
1633 | |
|
|
1634 | void |
|
|
1635 | mallinfo () |
|
|
1636 | PPCODE: |
|
|
1637 | { |
|
|
1638 | #if __GLIBC__ |
|
|
1639 | struct mallinfo mai = mallinfo (); |
|
|
1640 | EXTEND (SP, 10*2); |
|
|
1641 | PUSHs (sv_2mortal (newSVpv ("arena" , 0))); PUSHs (sv_2mortal (newSViv (mai.arena))); |
|
|
1642 | PUSHs (sv_2mortal (newSVpv ("ordblks" , 0))); PUSHs (sv_2mortal (newSViv (mai.ordblks))); |
|
|
1643 | PUSHs (sv_2mortal (newSVpv ("smblks" , 0))); PUSHs (sv_2mortal (newSViv (mai.smblks))); |
|
|
1644 | PUSHs (sv_2mortal (newSVpv ("hblks" , 0))); PUSHs (sv_2mortal (newSViv (mai.hblks))); |
|
|
1645 | PUSHs (sv_2mortal (newSVpv ("hblkhd" , 0))); PUSHs (sv_2mortal (newSViv (mai.hblkhd))); |
|
|
1646 | PUSHs (sv_2mortal (newSVpv ("usmblks" , 0))); PUSHs (sv_2mortal (newSViv (mai.usmblks))); |
|
|
1647 | PUSHs (sv_2mortal (newSVpv ("fsmblks" , 0))); PUSHs (sv_2mortal (newSViv (mai.fsmblks))); |
|
|
1648 | PUSHs (sv_2mortal (newSVpv ("uordblks", 0))); PUSHs (sv_2mortal (newSViv (mai.uordblks))); |
|
|
1649 | PUSHs (sv_2mortal (newSVpv ("fordblks", 0))); PUSHs (sv_2mortal (newSViv (mai.fordblks))); |
|
|
1650 | PUSHs (sv_2mortal (newSVpv ("keepcost", 0))); PUSHs (sv_2mortal (newSViv (mai.keepcost))); |
|
|
1651 | #endif |
|
|
1652 | EXTEND (SP, 2*2); |
|
|
1653 | PUSHs (sv_2mortal (newSVpv ("slice_alloc", 0))); PUSHs (sv_2mortal (newSVuv (slice_alloc))); |
|
|
1654 | PUSHs (sv_2mortal (newSVpv ("shstr_alloc", 0))); PUSHs (sv_2mortal (newSVuv (shstr_alloc))); |
|
|
1655 | } |
1729 | |
1656 | |
1730 | void |
1657 | void |
1731 | sub_generation_inc () |
1658 | sub_generation_inc () |
1732 | CODE: |
1659 | CODE: |
1733 | PL_sub_generation++; |
1660 | PL_sub_generation++; |
… | |
… | |
1758 | |
1685 | |
1759 | void abort () |
1686 | void abort () |
1760 | |
1687 | |
1761 | void reset_signals () |
1688 | void reset_signals () |
1762 | |
1689 | |
1763 | void fork_abort (octet_string cause = "cf::fork_abort") |
1690 | void fork_abort (const_octet_string cause = "cf::fork_abort") |
1764 | |
1691 | |
1765 | void cleanup (octet_string cause, bool make_core = false) |
1692 | void cleanup (const_octet_string cause, bool make_core = false) |
1766 | |
1693 | |
1767 | void emergency_save () |
1694 | void emergency_save () |
1768 | |
1695 | |
1769 | void _exit (int status = EXIT_SUCCESS) |
1696 | void _exit (int status = EXIT_SUCCESS) |
1770 | |
1697 | |
1771 | UV sv_2watcher (SV *w) |
|
|
1772 | CODE: |
|
|
1773 | RETVAL = (UV)GEventAPI->sv_2watcher (w); |
|
|
1774 | OUTPUT: |
|
|
1775 | RETVAL |
|
|
1776 | |
|
|
1777 | #if _POSIX_MEMLOCK |
1698 | #if _POSIX_MEMLOCK |
1778 | |
1699 | |
1779 | int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) |
1700 | int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) |
|
|
1701 | INIT: |
|
|
1702 | mallopt (M_PERTURB, 0xaa); // bug-workaround for linux glibc+mlockall+calloc |
1780 | |
1703 | |
1781 | int munlockall () |
1704 | int munlockall () |
1782 | |
1705 | |
1783 | #endif |
1706 | #endif |
1784 | |
1707 | |
… | |
… | |
1931 | void |
1854 | void |
1932 | inv (object *obj) |
1855 | inv (object *obj) |
1933 | PROTOTYPE: $ |
1856 | PROTOTYPE: $ |
1934 | PPCODE: |
1857 | PPCODE: |
1935 | { |
1858 | { |
1936 | object *o; |
|
|
1937 | for (o = obj->inv; o; o = o->below) |
1859 | for (object *o = obj->inv; o; o = o->below) |
1938 | XPUSHs (sv_2mortal (to_sv (o))); |
1860 | XPUSHs (sv_2mortal (to_sv (o))); |
1939 | } |
1861 | } |
1940 | |
1862 | |
1941 | void |
1863 | void |
1942 | set_animation (object *op, int idx) |
1864 | set_animation (object *op, int idx) |
… | |
… | |
1974 | |
1896 | |
1975 | int need_identify (object *obj); |
1897 | int need_identify (object *obj); |
1976 | |
1898 | |
1977 | int apply_shop_mat (object *shop_mat, object *op); |
1899 | int apply_shop_mat (object *shop_mat, object *op); |
1978 | |
1900 | |
1979 | int move_player (object *op, int dir) |
|
|
1980 | CODE: |
|
|
1981 | RETVAL = move_player (op, dir); |
|
|
1982 | OUTPUT: |
|
|
1983 | RETVAL |
|
|
1984 | |
|
|
1985 | int move (object *op, int dir, object *originator = op) |
1901 | int move (object *op, int dir, object *originator = op) |
1986 | CODE: |
1902 | CODE: |
1987 | RETVAL = move_ob (op, dir, originator); |
1903 | RETVAL = move_ob (op, dir, originator); |
1988 | OUTPUT: |
1904 | OUTPUT: |
1989 | RETVAL |
1905 | RETVAL |
… | |
… | |
1995 | void apply_below (object *op) |
1911 | void apply_below (object *op) |
1996 | CODE: |
1912 | CODE: |
1997 | player_apply_below (op); |
1913 | player_apply_below (op); |
1998 | |
1914 | |
1999 | int cast_heal (object *op, object *caster, object *spell, int dir = 0) |
1915 | int cast_heal (object *op, object *caster, object *spell, int dir = 0) |
2000 | |
|
|
2001 | object *cf_object_present_archname_inside (object *op, utf8_string whatstr) |
|
|
2002 | |
|
|
2003 | int cf_object_transfer (object *op, int x, int y, int r = 0, object_ornull *orig = 0) |
|
|
2004 | |
|
|
2005 | int cf_object_change_map (object *op, int x, int y, maptile *map) |
|
|
2006 | |
1916 | |
2007 | #//TODO |
1917 | #//TODO |
2008 | object *clone_ (object *op, int recursive = 0) |
1918 | object *clone_ (object *op, int recursive = 0) |
2009 | CODE: |
1919 | CODE: |
2010 | if (recursive) |
1920 | if (recursive) |
… | |
… | |
2057 | |
1967 | |
2058 | void drop (object *who, object *op) |
1968 | void drop (object *who, object *op) |
2059 | |
1969 | |
2060 | void pick_up (object *who, object *op) |
1970 | void pick_up (object *who, object *op) |
2061 | |
1971 | |
2062 | int cf_object_teleport (object *op, maptile *map, int x, int y) |
|
|
2063 | |
|
|
2064 | void update_object (object *op, int action) |
1972 | void update_object (object *op, int action) |
2065 | |
1973 | |
2066 | object *cf_create_object_by_name (utf8_string name) |
|
|
2067 | |
|
|
2068 | void change_exp (object *op, uint64 exp, utf8_string skill_name = 0, int flag = 0) |
1974 | void change_exp (object *op, uint64 exp, utf8_string skill_name = 0, int flag = 0) |
2069 | |
1975 | |
2070 | void player_lvl_adj (object *who, object *skill = 0) |
1976 | void player_lvl_adj (object *who, object *skill = 0) |
2071 | |
1977 | |
2072 | int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL) |
1978 | int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL) |
… | |
… | |
2083 | |
1989 | |
2084 | void handle_apply_yield (object *op); |
1990 | void handle_apply_yield (object *op); |
2085 | |
1991 | |
2086 | |
1992 | |
2087 | MODULE = cf PACKAGE = cf::object PREFIX = cf_ |
1993 | MODULE = cf PACKAGE = cf::object PREFIX = cf_ |
2088 | |
|
|
2089 | object *cf_insert_ob_in_ob (object *ob, object *where) |
|
|
2090 | |
1994 | |
2091 | # no clean way to get an object from an archetype - stupid idiotic |
1995 | # no clean way to get an object from an archetype - stupid idiotic |
2092 | # dumb kludgy misdesigned plug-in api slowly gets on my nerves. |
1996 | # dumb kludgy misdesigned plug-in api slowly gets on my nerves. |
2093 | |
1997 | |
2094 | object *new (utf8_string archetype = 0) |
1998 | object *new (utf8_string archetype = 0) |
… | |
… | |
2103 | # TODO: nuke |
2007 | # TODO: nuke |
2104 | object *insert_ob_in_map_at (object *ob, maptile *where, object_ornull *orig, int flag, int x, int y) |
2008 | object *insert_ob_in_map_at (object *ob, maptile *where, object_ornull *orig, int flag, int x, int y) |
2105 | PROTOTYPE: $$$$$$ |
2009 | PROTOTYPE: $$$$$$ |
2106 | CODE: |
2010 | CODE: |
2107 | { |
2011 | { |
2108 | int unused_type; |
2012 | RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y); |
2109 | RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y); |
|
|
2110 | } |
2013 | } |
2111 | |
2014 | |
2112 | const_utf8_string get_ob_key_value (object *op, utf8_string key) |
2015 | const_utf8_string get_ob_key_value (object *op, utf8_string key) |
2113 | |
2016 | |
2114 | bool set_ob_key_value (object *op, utf8_string key, utf8_string value = 0, int add_key = 1) |
2017 | bool set_ob_key_value (object *op, utf8_string key, utf8_string value = 0, int add_key = 1) |
… | |
… | |
2127 | EXTEND (SP, 5); |
2030 | EXTEND (SP, 5); |
2128 | PUSHs (newSVuv (rv.distance)); |
2031 | PUSHs (newSVuv (rv.distance)); |
2129 | PUSHs (newSViv (rv.distance_x)); |
2032 | PUSHs (newSViv (rv.distance_x)); |
2130 | PUSHs (newSViv (rv.distance_y)); |
2033 | PUSHs (newSViv (rv.distance_y)); |
2131 | PUSHs (newSViv (rv.direction)); |
2034 | PUSHs (newSViv (rv.direction)); |
2132 | PUSHs (newSVcfapi (CFAPI_POBJECT, rv.part)); |
2035 | PUSHs (to_sv (rv.part)); |
2133 | } |
2036 | } |
2134 | |
2037 | |
2135 | bool on_same_map_as (object *ob, object *other) |
2038 | bool on_same_map_as (object *ob, object *other) |
2136 | CODE: |
2039 | CODE: |
2137 | RETVAL = on_same_map (ob, other); |
2040 | RETVAL = on_same_map (ob, other); |
… | |
… | |
2143 | RETVAL = query_base_name (op, plural); |
2046 | RETVAL = query_base_name (op, plural); |
2144 | OUTPUT: RETVAL |
2047 | OUTPUT: RETVAL |
2145 | |
2048 | |
2146 | object *decrease_ob_nr (object *op, unsigned long i) |
2049 | object *decrease_ob_nr (object *op, unsigned long i) |
2147 | |
2050 | |
|
|
2051 | # return the tail of an object, excluding itself |
|
|
2052 | void |
|
|
2053 | tail (object *op) |
|
|
2054 | PPCODE: |
|
|
2055 | while ((op = op->more)) |
|
|
2056 | XPUSHs (sv_2mortal (to_sv (op))); |
|
|
2057 | |
2148 | MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_ |
2058 | MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_ |
2149 | |
2059 | |
2150 | player *player (object *op) |
2060 | player *player (object *op) |
2151 | CODE: |
2061 | CODE: |
2152 | RETVAL = op->contr; |
2062 | RETVAL = op->contr; |
2153 | OUTPUT: RETVAL |
2063 | OUTPUT: RETVAL |
2154 | |
2064 | |
|
|
2065 | bool move_player (object *op, int dir) |
|
|
2066 | |
2155 | void check_score (object *op) |
2067 | void check_score (object *op) |
2156 | |
2068 | |
2157 | void message (object *op, utf8_string txt, int flags = NDI_ORANGE | NDI_UNIQUE) |
2069 | void message (object *op, utf8_string txt, int flags = NDI_ORANGE | NDI_UNIQUE) |
2158 | CODE: |
2070 | CODE: |
2159 | new_draw_info (flags, 0, op, txt); |
2071 | new_draw_info (flags, 0, op, txt); |
2160 | |
2072 | |
2161 | void kill_player (object *op) |
2073 | void kill_player (object *op) |
2162 | |
2074 | |
|
|
2075 | void esrv_send_item (object *pl, object *item) |
|
|
2076 | |
2163 | void esrv_update_item (object *op, int what, object *item) |
2077 | void esrv_update_item (object *pl, int what, object *item) |
2164 | C_ARGS: what, op, item |
2078 | C_ARGS: what, pl, item |
|
|
2079 | |
|
|
2080 | void esrv_del_item (object *pl, int tag) |
|
|
2081 | C_ARGS: pl->contr, tag |
2165 | |
2082 | |
2166 | int command_summon (object *op, utf8_string params) |
2083 | int command_summon (object *op, utf8_string params) |
2167 | |
2084 | |
2168 | int command_arrest (object *op, utf8_string params) |
2085 | int command_arrest (object *op, utf8_string params) |
2169 | |
2086 | |
… | |
… | |
2190 | pl->ob->stats.grace = pl->ob->stats.maxgrace; |
2107 | pl->ob->stats.grace = pl->ob->stats.maxgrace; |
2191 | pl->orig_stats = pl->ob->stats; |
2108 | pl->orig_stats = pl->ob->stats; |
2192 | |
2109 | |
2193 | void clear_los (player *pl) |
2110 | void clear_los (player *pl) |
2194 | |
2111 | |
2195 | void cf_player_move (player *pl, int dir) |
|
|
2196 | |
|
|
2197 | bool |
2112 | bool |
2198 | cell_visible (player *pl, int dx, int dy) |
2113 | cell_visible (player *pl, int dx, int dy) |
2199 | CODE: |
2114 | CODE: |
2200 | RETVAL = FABS (dx) <= pl->ns->mapx / 2 && FABS (dy) <= pl->ns->mapy / 2 |
2115 | RETVAL = FABS (dx) <= pl->ns->mapx / 2 && FABS (dy) <= pl->ns->mapy / 2 |
2201 | && !pl->blocked_los [dx + pl->ns->mapx / 2][dy + pl->ns->mapy / 2]; |
2116 | && !pl->blocked_los [dx + pl->ns->mapx / 2][dy + pl->ns->mapy / 2]; |
… | |
… | |
2207 | CODE: |
2122 | CODE: |
2208 | { |
2123 | { |
2209 | STRLEN len; |
2124 | STRLEN len; |
2210 | char *buf = SvPVbyte (packet, len); |
2125 | char *buf = SvPVbyte (packet, len); |
2211 | |
2126 | |
|
|
2127 | if (len > MAXSOCKBUF) |
|
|
2128 | pl->failmsg ("[packet too long for client]"); |
2212 | if (pl->ns) |
2129 | else if (pl->ns) |
2213 | pl->ns->send_packet (buf, len); |
2130 | pl->ns->send_packet (buf, len); |
2214 | } |
2131 | } |
2215 | |
2132 | |
2216 | int |
2133 | int |
2217 | listening (player *pl, int new_value = -1) |
2134 | listening (player *pl, int new_value = -1) |
… | |
… | |
2253 | RETVAL = map->invoke ((event_type)event, ARG_AV (av), DT_END); |
2170 | RETVAL = map->invoke ((event_type)event, ARG_AV (av), DT_END); |
2254 | OUTPUT: RETVAL |
2171 | OUTPUT: RETVAL |
2255 | |
2172 | |
2256 | SV *registry (maptile *map) |
2173 | SV *registry (maptile *map) |
2257 | |
2174 | |
|
|
2175 | void |
|
|
2176 | find_tagged_objects (maptile *map, utf8_string tag = 0) |
|
|
2177 | PPCODE: |
|
|
2178 | { |
|
|
2179 | if (!map->spaces) |
|
|
2180 | XSRETURN_EMPTY; |
|
|
2181 | |
|
|
2182 | if (tag) |
|
|
2183 | { |
|
|
2184 | shstr_cmp tag_ (tag); |
|
|
2185 | |
|
|
2186 | for (mapspace *ms = map->spaces + map->size (); ms-- > map->spaces; ) |
|
|
2187 | for (object *op = ms->bot; op; op = op->above) |
|
|
2188 | if (op->tag == tag_) |
|
|
2189 | XPUSHs (sv_2mortal (to_sv (op))); |
|
|
2190 | } |
|
|
2191 | else |
|
|
2192 | { |
|
|
2193 | for (mapspace *ms = map->spaces + map->size (); ms-- > map->spaces; ) |
|
|
2194 | for (object *op = ms->bot; op; op = op->above) |
|
|
2195 | if (op->tag) |
|
|
2196 | XPUSHs (sv_2mortal (to_sv (op))); |
|
|
2197 | } |
|
|
2198 | } |
|
|
2199 | |
2258 | INCLUDE: $PERL $srcdir/genacc maptile ../include/map.h | |
2200 | INCLUDE: $PERL $srcdir/genacc maptile ../include/map.h | |
2259 | |
2201 | |
2260 | void |
2202 | void |
2261 | maptile::instantiate () |
2203 | maptile::instantiate () |
2262 | |
2204 | |
… | |
… | |
2393 | get_connection (maptile *map, long connection) |
2335 | get_connection (maptile *map, long connection) |
2394 | PPCODE: |
2336 | PPCODE: |
2395 | oblinkpt *obp = get_connection_links (map, connection); |
2337 | oblinkpt *obp = get_connection_links (map, connection); |
2396 | if (obp) |
2338 | if (obp) |
2397 | for (objectlink *ol = obp->link; ol; ol = ol->next) |
2339 | for (objectlink *ol = obp->link; ol; ol = ol->next) |
2398 | XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, (object *)ol->ob))); |
2340 | XPUSHs (sv_2mortal (to_sv ((object *)ol->ob))); |
2399 | |
|
|
2400 | object *cf_map_insert_object_there (maptile *where, object *op, object *originator, int flags) |
|
|
2401 | |
|
|
2402 | object *cf_map_insert_object (maptile *where, object* op, int x, int y) |
|
|
2403 | |
|
|
2404 | object* cf_map_present_arch_by_name (maptile *map, const char* str, int nx, int ny) |
|
|
2405 | C_ARGS: str, map, nx, ny |
|
|
2406 | |
2341 | |
2407 | void |
2342 | void |
2408 | get_map_flags (maptile *map, int x, int y) |
2343 | get_map_flags (maptile *map, int x, int y) |
2409 | PPCODE: |
2344 | PPCODE: |
2410 | { |
2345 | { |
… | |
… | |
2415 | EXTEND (SP, 4); |
2350 | EXTEND (SP, 4); |
2416 | PUSHs (sv_2mortal (newSViv (flags))); |
2351 | PUSHs (sv_2mortal (newSViv (flags))); |
2417 | |
2352 | |
2418 | if (GIMME_V == G_ARRAY) |
2353 | if (GIMME_V == G_ARRAY) |
2419 | { |
2354 | { |
2420 | PUSHs (sv_2mortal (newSVcfapi (CFAPI_PMAP, nmap))); |
2355 | PUSHs (sv_2mortal (to_sv (nmap))); |
2421 | PUSHs (sv_2mortal (newSViv (nx))); |
2356 | PUSHs (sv_2mortal (newSViv (nx))); |
2422 | PUSHs (sv_2mortal (newSViv (ny))); |
2357 | PUSHs (sv_2mortal (newSViv (ny))); |
2423 | } |
2358 | } |
2424 | } |
2359 | } |
2425 | |
2360 | |
… | |
… | |
2434 | |
2369 | |
2435 | get_map_flags (map, &nmap, x, y, &nx, &ny); |
2370 | get_map_flags (map, &nmap, x, y, &nx, &ny); |
2436 | |
2371 | |
2437 | if (nmap) |
2372 | if (nmap) |
2438 | for (o = GET_MAP_OB (nmap, nx, ny); o; o = o->above) |
2373 | for (o = GET_MAP_OB (nmap, nx, ny); o; o = o->above) |
2439 | XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); |
2374 | XPUSHs (sv_2mortal (to_sv (o))); |
2440 | } |
2375 | } |
2441 | |
2376 | |
2442 | SV * |
2377 | SV * |
2443 | bot_at (maptile *obj, unsigned int x, unsigned int y) |
2378 | bot_at (maptile *obj, unsigned int x, unsigned int y) |
2444 | PROTOTYPE: $$$ |
2379 | PROTOTYPE: $$$ |
… | |
… | |
2453 | INIT: |
2388 | INIT: |
2454 | if (x >= obj->width || y >= obj->height) XSRETURN_UNDEF; |
2389 | if (x >= obj->width || y >= obj->height) XSRETURN_UNDEF; |
2455 | CODE: |
2390 | CODE: |
2456 | switch (ix) |
2391 | switch (ix) |
2457 | { |
2392 | { |
2458 | case 0: RETVAL = newSVcfapi (CFAPI_POBJECT, GET_MAP_OB (obj, x, y)); break; |
2393 | case 0: RETVAL = to_sv (GET_MAP_OB (obj, x, y)); break; |
2459 | case 1: RETVAL = newSVcfapi (CFAPI_POBJECT, GET_MAP_TOP (obj, x, y)); break; |
2394 | case 1: RETVAL = to_sv (GET_MAP_TOP (obj, x, y)); break; |
2460 | case 2: RETVAL = newSVuv ( GET_MAP_FLAGS (obj, x, y)); break; |
2395 | case 2: RETVAL = newSVuv (GET_MAP_FLAGS (obj, x, y)); break; |
2461 | case 3: RETVAL = newSViv ( GET_MAP_LIGHT (obj, x, y)); break; |
2396 | case 3: RETVAL = newSViv (GET_MAP_LIGHT (obj, x, y)); break; |
2462 | case 4: RETVAL = newSVuv ( GET_MAP_MOVE_BLOCK (obj, x, y)); break; |
2397 | case 4: RETVAL = newSVuv (GET_MAP_MOVE_BLOCK (obj, x, y)); break; |
2463 | case 5: RETVAL = newSVuv ( GET_MAP_MOVE_SLOW (obj, x, y)); break; |
2398 | case 5: RETVAL = newSVuv (GET_MAP_MOVE_SLOW (obj, x, y)); break; |
2464 | case 6: RETVAL = newSVuv ( GET_MAP_MOVE_ON (obj, x, y)); break; |
2399 | case 6: RETVAL = newSVuv (GET_MAP_MOVE_ON (obj, x, y)); break; |
2465 | case 7: RETVAL = newSVuv ( GET_MAP_MOVE_OFF (obj, x, y)); break; |
2400 | case 7: RETVAL = newSVuv (GET_MAP_MOVE_OFF (obj, x, y)); break; |
2466 | } |
2401 | } |
2467 | OUTPUT: RETVAL |
2402 | OUTPUT: RETVAL |
2468 | |
2403 | |
2469 | void fix_walls (maptile *map, int x, int y) |
2404 | void fix_walls (maptile *map, int x, int y) |
2470 | |
2405 | |
… | |
… | |
2651 | CODE: |
2586 | CODE: |
2652 | { |
2587 | { |
2653 | STRLEN len; |
2588 | STRLEN len; |
2654 | char *buf = SvPVbyte (packet, len); |
2589 | char *buf = SvPVbyte (packet, len); |
2655 | |
2590 | |
|
|
2591 | if (len > MAXSOCKBUF) |
|
|
2592 | { |
|
|
2593 | // ugly |
|
|
2594 | if (THIS->pl) |
|
|
2595 | THIS->pl->failmsg ("[packet too long for client]"); |
|
|
2596 | } |
|
|
2597 | else |
2656 | THIS->send_packet (buf, len); |
2598 | THIS->send_packet (buf, len); |
2657 | } |
2599 | } |
2658 | |
2600 | |
2659 | faceidx |
2601 | faceidx |
2660 | client::need_face (utf8_string name, int pri = 0) |
2602 | client::need_face (utf8_string name, int pri = 0) |
2661 | CODE: |
2603 | CODE: |
… | |
… | |
2760 | } |
2702 | } |
2761 | } |
2703 | } |
2762 | |
2704 | |
2763 | int get_data_size (faceidx idx, int faceset = 0) |
2705 | int get_data_size (faceidx idx, int faceset = 0) |
2764 | CODE: |
2706 | CODE: |
2765 | facedata *d = face_data (idx, faceset); assert (d); |
2707 | facedata *d = face_data (idx, faceset); |
|
|
2708 | if (!d) XSRETURN_UNDEF; |
2766 | RETVAL = d->data.size (); |
2709 | RETVAL = d->data.size (); |
2767 | OUTPUT: |
2710 | OUTPUT: |
2768 | RETVAL |
2711 | RETVAL |
2769 | |
2712 | |
2770 | SV *get_chksum (faceidx idx, int faceset = 0) |
2713 | SV *get_chksum (faceidx idx, int faceset = 0) |
2771 | CODE: |
2714 | CODE: |
2772 | facedata *d = face_data (idx, faceset); assert (d); |
2715 | facedata *d = face_data (idx, faceset); |
|
|
2716 | if (!d) XSRETURN_UNDEF; |
2773 | RETVAL = newSVpvn ((char *)d->chksum, CHKSUM_SIZE); |
2717 | RETVAL = newSVpvn ((char *)d->chksum, CHKSUM_SIZE); |
|
|
2718 | OUTPUT: |
|
|
2719 | RETVAL |
|
|
2720 | |
|
|
2721 | SV *get_data (faceidx idx, int faceset = 0) |
|
|
2722 | CODE: |
|
|
2723 | facedata *d = face_data (idx, faceset); |
|
|
2724 | if (!d) XSRETURN_UNDEF; |
|
|
2725 | RETVAL = newSVpvn (d->data.data (), d->data.length ()); |
2774 | OUTPUT: |
2726 | OUTPUT: |
2775 | RETVAL |
2727 | RETVAL |
2776 | |
2728 | |
2777 | void invalidate (faceidx idx) |
2729 | void invalidate (faceidx idx) |
2778 | CODE: |
2730 | CODE: |
… | |
… | |
2864 | CODE: |
2816 | CODE: |
2865 | object_thawer *self; |
2817 | object_thawer *self; |
2866 | sv_to (sv, self); |
2818 | sv_to (sv, self); |
2867 | delete self; |
2819 | delete self; |
2868 | |
2820 | |
|
|
2821 | void |
|
|
2822 | extract_tags (object_thawer *self) |
|
|
2823 | PPCODE: |
|
|
2824 | while (self->kw != KW_EOF) |
|
|
2825 | { |
|
|
2826 | PUTBACK; |
|
|
2827 | coroapi::cede_to_tick (); |
|
|
2828 | SPAGAIN; |
|
|
2829 | |
|
|
2830 | if (self->kw == KW_tag) |
|
|
2831 | XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ()))); |
|
|
2832 | |
|
|
2833 | self->skip (); |
|
|
2834 | } |
|
|
2835 | |