… | |
… | |
21 | * You should have received a copy of the GNU General Public License |
21 | * You should have received a copy of the GNU General Public License |
22 | * along with this program; if not, write to the Free Software |
22 | * along with this program; if not, write to the Free Software |
23 | * Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
23 | * Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
24 | */ |
24 | */ |
25 | |
25 | |
|
|
26 | #include "autoconf.h" |
|
|
27 | |
26 | #define PLUGIN_NAME "perl" |
28 | #define PLUGIN_NAME "perl" |
27 | #define PLUGIN_VERSION "cfperl 0.5" |
29 | #define PLUGIN_VERSION "cfperl 0.5" |
28 | |
30 | |
29 | #define CEDES_PER_TICK 5 |
31 | #define CEDES_PER_TICK 5 |
|
|
32 | |
|
|
33 | #if HAVE_EXECINFO_H |
|
|
34 | # include <execinfo.h> |
|
|
35 | #endif |
30 | |
36 | |
31 | #include <plugin_common.h> |
37 | #include <plugin_common.h> |
32 | #include <sounds.h> |
38 | #include <sounds.h> |
33 | #include <cstdarg> |
39 | #include <cstdarg> |
34 | #include <sproto.h> |
40 | #include <sproto.h> |
… | |
… | |
180 | if (destroyed ()) |
186 | if (destroyed ()) |
181 | return; |
187 | return; |
182 | |
188 | |
183 | flags |= F_DESTROYED; |
189 | flags |= F_DESTROYED; |
184 | do_destroy (); |
190 | do_destroy (); |
|
|
191 | sever_self (); |
185 | } |
192 | } |
186 | |
193 | |
187 | void |
194 | void |
188 | attachable::check_mortals () |
195 | attachable::check_mortals () |
189 | { |
196 | { |
… | |
… | |
209 | LOG (llevError, "check_mortals: object '%s' still has self\n", typeid (obj).name ()); |
216 | LOG (llevError, "check_mortals: object '%s' still has self\n", typeid (obj).name ()); |
210 | obj->sever_self (); |
217 | obj->sever_self (); |
211 | } |
218 | } |
212 | #endif |
219 | #endif |
213 | |
220 | |
214 | if (obj->refcnt_cnt ()) |
221 | if (obj->refcnt) |
215 | { |
222 | { |
216 | ++i; // further delay freeing |
223 | ++i; // further delay freeing |
217 | |
224 | |
218 | if (!(i & 0x3ff)) |
225 | if (!(i & 0x3ff)) |
219 | break; |
226 | break; |
… | |
… | |
397 | inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; } |
404 | inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; } |
398 | |
405 | |
399 | template<int N> |
406 | template<int N> |
400 | inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); } |
407 | inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); } |
401 | |
408 | |
402 | inline void sv_to (SV *sv, rangetype &v) { v = (rangetype) SvIV (sv); } |
|
|
403 | inline void sv_to (SV *sv, bowtype_t &v) { v = (bowtype_t) SvIV (sv); } |
409 | inline void sv_to (SV *sv, bowtype_t &v) { v = (bowtype_t) SvIV (sv); } |
404 | inline void sv_to (SV *sv, petmode_t &v) { v = (petmode_t) SvIV (sv); } |
410 | inline void sv_to (SV *sv, petmode_t &v) { v = (petmode_t) SvIV (sv); } |
405 | inline void sv_to (SV *sv, usekeytype &v) { v = (usekeytype) SvIV (sv); } |
411 | inline void sv_to (SV *sv, usekeytype &v) { v = (usekeytype) SvIV (sv); } |
406 | inline void sv_to (SV *sv, unapplymode &v) { v = (unapplymode) SvIV (sv); } |
412 | inline void sv_to (SV *sv, unapplymode &v) { v = (unapplymode) SvIV (sv); } |
407 | |
413 | |
… | |
… | |
610 | perl_construct (perl); |
616 | perl_construct (perl); |
611 | |
617 | |
612 | PL_exit_flags |= PERL_EXIT_DESTRUCT_END; |
618 | PL_exit_flags |= PERL_EXIT_DESTRUCT_END; |
613 | |
619 | |
614 | const char *argv[] = { |
620 | const char *argv[] = { |
615 | "", |
621 | settings.argv [0], |
616 | "-e" |
622 | "-e" |
617 | "use Event; use Coro;" // required for bootstrap |
623 | "use Event; use Coro;" // required for bootstrap |
618 | "cf->bootstrap;" // required for datadir :*> |
624 | "cf->bootstrap;" // required for datadir :*> |
619 | "unshift @INC, cf::datadir ();" |
625 | "unshift @INC, cf::datadir ();" |
620 | "require cf;" |
626 | "require cf;" |
… | |
… | |
942 | CALL_ARG (exit); |
948 | CALL_ARG (exit); |
943 | CALL_CALL ("cf::object::player::enter_exit", G_VOID); |
949 | CALL_CALL ("cf::object::player::enter_exit", G_VOID); |
944 | CALL_END; |
950 | CALL_END; |
945 | } |
951 | } |
946 | |
952 | |
|
|
953 | void |
|
|
954 | log_backtrace (const char *msg) |
|
|
955 | { |
|
|
956 | #if HAVE_BACKTRACE |
|
|
957 | void *addr [20]; |
|
|
958 | int size = backtrace (addr, 20); |
|
|
959 | |
|
|
960 | CALL_BEGIN (size); |
|
|
961 | CALL_ARG (msg); |
|
|
962 | for (int i = 0; i < size; ++i) |
|
|
963 | CALL_ARG ((IV)addr [i]); |
|
|
964 | CALL_CALL ("cf::_log_backtrace", G_VOID); |
|
|
965 | CALL_END; |
|
|
966 | #endif |
|
|
967 | } |
|
|
968 | |
947 | ///////////////////////////////////////////////////////////////////////////// |
969 | ///////////////////////////////////////////////////////////////////////////// |
948 | |
970 | |
949 | struct EventAPI *watcher_base::GEventAPI; |
971 | struct EventAPI *watcher_base::GEventAPI; |
950 | struct CoroAPI *coroapi::GCoroAPI; |
972 | struct CoroAPI *coroapi::GCoroAPI; |
951 | |
973 | |
… | |
… | |
1105 | const char *name; |
1127 | const char *name; |
1106 | IV iv; |
1128 | IV iv; |
1107 | } *civ, const_iv[] = { |
1129 | } *civ, const_iv[] = { |
1108 | # define const_iv(name) { # name, (IV)name }, |
1130 | # define const_iv(name) { # name, (IV)name }, |
1109 | const_iv (llevError) const_iv (llevInfo) const_iv (llevDebug) const_iv (llevMonster) |
1131 | const_iv (llevError) const_iv (llevInfo) const_iv (llevDebug) const_iv (llevMonster) |
|
|
1132 | const_iv (logBacktrace) |
1110 | |
1133 | |
1111 | const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd) |
1134 | const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd) |
1112 | |
1135 | |
1113 | const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) |
1136 | const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) |
1114 | |
1137 | |
… | |
… | |
1386 | CODE: |
1409 | CODE: |
1387 | runtime = SvNVx (sv_runtime); |
1410 | runtime = SvNVx (sv_runtime); |
1388 | server_tick (); |
1411 | server_tick (); |
1389 | |
1412 | |
1390 | void |
1413 | void |
|
|
1414 | log_backtrace (utf8_string msg) |
|
|
1415 | |
|
|
1416 | void |
1391 | LOG (int level, utf8_string msg) |
1417 | LOG (int flags, utf8_string msg) |
1392 | PROTOTYPE: $$ |
1418 | PROTOTYPE: $$ |
1393 | C_ARGS: (LogLevel)level, "%s", msg |
1419 | C_ARGS: flags, "%s", msg |
1394 | |
1420 | |
1395 | octet_string path_combine (octet_string base, octet_string path) |
1421 | octet_string path_combine (octet_string base, octet_string path) |
1396 | PROTOTYPE: $$ |
1422 | PROTOTYPE: $$ |
1397 | |
1423 | |
1398 | octet_string path_combine_and_normalize (octet_string base, octet_string path) |
1424 | octet_string path_combine_and_normalize (octet_string base, octet_string path) |
… | |
… | |
1435 | } |
1461 | } |
1436 | OUTPUT: RETVAL |
1462 | OUTPUT: RETVAL |
1437 | |
1463 | |
1438 | void abort () |
1464 | void abort () |
1439 | |
1465 | |
|
|
1466 | void reset_signals () |
|
|
1467 | |
1440 | void fork_abort (octet_string cause = "cf::fork_abort") |
1468 | void fork_abort (octet_string cause = "cf::fork_abort") |
1441 | |
1469 | |
1442 | void cleanup (octet_string cause, bool make_core = false) |
1470 | void cleanup (octet_string cause, bool make_core = false) |
1443 | |
1471 | |
1444 | void emergency_save () |
1472 | void emergency_save () |
… | |
… | |
1970 | if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) |
1998 | if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) |
1971 | { |
1999 | { |
1972 | object *ob = get_archetype (SvPVutf8_nolen (*elem)); |
2000 | object *ob = get_archetype (SvPVutf8_nolen (*elem)); |
1973 | ob->flag [FLAG_NO_MAP_SAVE] = true; |
2001 | ob->flag [FLAG_NO_MAP_SAVE] = true; |
1974 | THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); |
2002 | THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); |
|
|
2003 | |
|
|
2004 | if (ob->randomitems) |
|
|
2005 | { |
|
|
2006 | if (!ob->above) |
|
|
2007 | { |
|
|
2008 | ob->create_treasure (ob->randomitems); |
|
|
2009 | |
|
|
2010 | for (object *op = ob->above; op; op = op->above) |
|
|
2011 | op->flag [FLAG_NO_MAP_SAVE] = true; |
|
|
2012 | } |
|
|
2013 | |
|
|
2014 | ob->randomitems = 0; |
|
|
2015 | } |
1975 | } |
2016 | } |
1976 | } |
2017 | } |
1977 | } |
2018 | } |
1978 | |
2019 | |
1979 | skip_space: ; |
2020 | skip_space: ; |