ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/cfperl.xs
(Generate patch)

Comparing deliantra/server/server/cfperl.xs (file contents):
Revision 1.377 by root, Wed Apr 21 03:12:46 2010 UTC vs.
Revision 1.425 by root, Wed Nov 14 06:21:39 2012 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2006,2007,2008,2009,2010,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * 5 *
6 * Deliantra is free software: you can redistribute it and/or modify it under 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 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 8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version. 9 * option) any later version.
10 * 10 *
11 * This program is distributed in the hope that it will be useful, 11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 * 15 *
16 * You should have received a copy of the Affero GNU General Public License 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 17 * and the GNU General Public License along with this program. If not, see
18 * <http://www.gnu.org/licenses/>. 18 * <http://www.gnu.org/licenses/>.
19 * 19 *
20 * The authors can be reached via e-mail to <support@deliantra.net> 20 * The authors can be reached via e-mail to <support@deliantra.net>
21 */ 21 */
22 22
23#include "autoconf.h" 23#include "autoconf.h"
24 24
28 28
29#include <cstdarg> 29#include <cstdarg>
30#include <typeinfo> 30#include <typeinfo>
31 31
32#include "global.h" 32#include "global.h"
33#include "../random_maps/random_map.h" 33#include "rmg.h"
34#include "noise.h"
34#include "evthread.h" 35#include "evthread.h"
35#include "sproto.h" 36#include "sproto.h"
36 37
37#include <unistd.h> 38#include <unistd.h>
38#if _POSIX_MEMLOCK 39#if _POSIX_MEMLOCK
66static int tick_inhibit; 67static int tick_inhibit;
67static int tick_pending; 68static int tick_pending;
68 69
69global gbl_ev; 70global gbl_ev;
70static AV *cb_global, *cb_attachable, *cb_object, *cb_player, *cb_client, *cb_type, *cb_map; 71static AV *cb_global, *cb_attachable, *cb_object, *cb_player, *cb_client, *cb_type, *cb_map;
71static SV *sv_runtime, *sv_tick_start, *sv_next_tick, *sv_now; 72static SV *sv_runtime, *sv_tick_start, *sv_next_tick, *sv_now, *sv_server_tick;
72static AV *av_reflect; 73static AV *av_reflect;
73 74
74bitset<NUM_EVENT_TYPES> ev_want_event; 75bitset<NUM_EVENT_TYPES> ev_want_event;
75bitset<NUM_TYPES> ev_want_type; 76bitset<NUM_TYPES> ev_want_type;
76 77
84 *stash_cf_client_wrap, 85 *stash_cf_client_wrap,
85 *stash_cf_arch_wrap, 86 *stash_cf_arch_wrap,
86 *stash_cf_party_wrap, 87 *stash_cf_party_wrap,
87 *stash_cf_region_wrap, 88 *stash_cf_region_wrap,
88 *stash_cf_living_wrap, 89 *stash_cf_living_wrap,
90 *stash_cf_layout_wrap,
89 *stash_ext_map_world; 91 *stash_ext_map_world;
90 92
91static SV 93static SV
92 *cv_cf_do_invoke, 94 *cv_cf_do_invoke,
93 *cv_cf__can_merge, 95 *cv_cf__can_merge,
94 *cv_cf_client_send_msg, 96 *cv_cf_client_send_msg,
97 *cv_cf_ix,
95 *cv_cf_tick, 98 *cv_cf_tick,
96 *cv_cf_match_match; 99 *cv_cf_match_match;
97 100
98#ifndef newSVpv_utf8 101#ifndef newSVpv_utf8
99static SV * 102static SV *
122 125
123 return sv; 126 return sv;
124} 127}
125#endif 128#endif
126 129
127static noinline utf8_string 130noinline utf8_string
128cfSvPVutf8_nolen (SV *sv) 131cfSvPVutf8_nolen (SV *sv)
129{ 132{
130 SvGETMAGIC (sv); 133 SvGETMAGIC (sv);
131 134
132 if (SvPOK (sv)) 135 if (SvPOK (sv))
251 { 254 {
252 static int last_mortalcount; 255 static int last_mortalcount;
253 if (mortals.size () != last_mortalcount) 256 if (mortals.size () != last_mortalcount)
254 { 257 {
255 last_mortalcount = mortals.size (); 258 last_mortalcount = mortals.size ();
256 LOG (llevInfo, "%d mortals.\n", (int)mortals.size ()); 259 object *specimen = is_a<object> (mortals [rndm (mortals.size ())]);
260
261 LOG (llevInfo, "%d mortals (random specimen: %s).\n",
262 (int)mortals.size (), specimen ? specimen->debug_desc () : "(not an object)");
257 263
258 if (0) 264 if (0)
259 { 265 {
260 for (int j = 0; j < mortals.size (); ++j)//D 266 for (int j = 0; j < mortals.size (); ++j)//D
261 fprintf (stderr, "%d:%s %p ", j, &((object *)mortals[j])->name, mortals[j]);//D 267 fprintf (stderr, "%d:%s %p ", j, &((object *)mortals[j])->name, mortals[j]);//D
352#endif 358#endif
353 359
354////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 360//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
355 361
356static SV * 362static SV *
357newSVptr (void *ptr, HV *stash, HV *hv = newHV ()) 363newSVptr (void *ptr, HV *stash, HV *hv)
358{ 364{
359 SV *sv;
360
361 if (!ptr) 365 if (!ptr)
362 return newSV (0); 366 return newSV (0);
363 367
364 sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, 0, (char *)ptr, 0); 368 sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, 0, (char *)ptr, 0);
365 return sv_bless (newRV_noinc ((SV *)hv), stash); 369 return sv_bless (newRV_noinc ((SV *)hv), stash);
370}
371
372static SV * noinline
373newSVptr (void *ptr, HV *stash)
374{
375 return newSVptr (ptr, stash, newHV ());
366} 376}
367 377
368static int 378static int
369attachable_free (pTHX_ SV *sv, MAGIC *mg) 379attachable_free (pTHX_ SV *sv, MAGIC *mg)
370{ 380{
382 return 0; 392 return 0;
383} 393}
384 394
385MGVTBL attachable::vtbl = {0, 0, 0, 0, attachable_free}; 395MGVTBL attachable::vtbl = {0, 0, 0, 0, attachable_free};
386 396
387static SV * 397static SV * noinline
388newSVattachable (attachable *obj, HV *stash) 398newSVattachable (attachable *obj, HV *stash)
389{ 399{
390 if (!obj) 400 if (!obj)
391 return newSV (0); 401 return newSV (0);
392 402
526static inline SV *to_sv (unsigned long long v) { return newSVval64 (v); } 536static inline SV *to_sv (unsigned long long v) { return newSVval64 (v); }
527static inline SV *to_sv (float v) { return newSVnv (v); } 537static inline SV *to_sv (float v) { return newSVnv (v); }
528static inline SV *to_sv (double v) { return newSVnv (v); } 538static inline SV *to_sv (double v) { return newSVnv (v); }
529static inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); } 539static inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); }
530static inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); } 540static inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); }
541// gcc dislikes noilnine on to_sv
531static inline SV *to_sv (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); } 542static noinline SV *to_sv_ni (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); }
543static inline SV *to_sv (object * v) { return to_sv_ni (v); }
532static inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); } 544static inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); }
533static inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); } 545static inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); }
534static inline SV *to_sv (region * v) { return newSVattachable (v, stash_cf_region_wrap); } 546static inline SV *to_sv (region * v) { return newSVattachable (v, stash_cf_region_wrap); }
535static inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); } 547static inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); }
536static inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } 548static inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); }
537static inline SV *to_sv (mapspace * v) { return newSVptr (v, stash_cf_mapspace_wrap); } 549static inline SV *to_sv (mapspace * v) { return newSVptr (v, stash_cf_mapspace_wrap); }
550static inline SV *to_sv (layout * v) { return newSVptr (v, stash_cf_layout_wrap); }
538 551
539static inline SV *to_sv (object & v) { return to_sv (&v); } 552static inline SV *to_sv (object & v) { return to_sv (&v); }
540static inline SV *to_sv (living & v) { return to_sv (&v); } 553static inline SV *to_sv (living & v) { return to_sv (&v); }
541 554
542static inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); } 555static inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); }
588static inline void sv_to (SV *sv, region * &v) { v = (region *) (attachable *)SvPTR_ornull (sv, "cf::region"); } 601static inline void sv_to (SV *sv, region * &v) { v = (region *) (attachable *)SvPTR_ornull (sv, "cf::region"); }
589static inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } 602static inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); }
590static inline void sv_to (SV *sv, partylist * &v) { v = (partylist *) SvPTR_ornull (sv, "cf::party"); } 603static inline void sv_to (SV *sv, partylist * &v) { v = (partylist *) SvPTR_ornull (sv, "cf::party"); }
591static inline void sv_to (SV *sv, living * &v) { v = (living *) SvPTR_ornull (sv, "cf::living"); } 604static inline void sv_to (SV *sv, living * &v) { v = (living *) SvPTR_ornull (sv, "cf::living"); }
592static inline void sv_to (SV *sv, mapspace * &v) { v = (mapspace *) SvPTR_ornull (sv, "cf::mapspace"); } 605static inline void sv_to (SV *sv, mapspace * &v) { v = (mapspace *) SvPTR_ornull (sv, "cf::mapspace"); }
606static inline void sv_to (SV *sv, layout * &v) { v = (layout *) SvPTR_ornull (sv, "cf::layout"); }
593static inline void sv_to (SV *sv, object_freezer * &v) { v = (object_freezer *) SvPTR_ornull (sv, "cf::object::freezer"); } 607static inline void sv_to (SV *sv, object_freezer * &v) { v = (object_freezer *) SvPTR_ornull (sv, "cf::object::freezer"); }
594static inline void sv_to (SV *sv, object_thawer * &v) { v = (object_thawer *) SvPTR_ornull (sv, "cf::object::thawer" ); } 608static inline void sv_to (SV *sv, object_thawer * &v) { v = (object_thawer *) SvPTR_ornull (sv, "cf::object::thawer" ); }
595 609
596//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, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; }
597static inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); } 611static inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); }
610static inline void sv_to (SV *sv, std::string &v) 624static inline void sv_to (SV *sv, std::string &v)
611{ 625{
612 STRLEN len; 626 STRLEN len;
613 char *data = SvPVbyte (sv, len); 627 char *data = SvPVbyte (sv, len);
614 v.assign (data, len); 628 v.assign (data, len);
629}
630
631static inline void sv_to (SV *sv, refcnt_buf &v)
632{
633 STRLEN len;
634 char *data = SvPVbyte (sv, len);
635 refcnt_buf buf (data, len);
636 v = buf;
615} 637}
616 638
617static inline void sv_to (SV *sv, UUID &v) 639static inline void sv_to (SV *sv, UUID &v)
618{ 640{
619 if (!v.parse (SvPV_nolen (sv))) 641 if (!v.parse (SvPV_nolen (sv)))
764 exit (EXIT_FAILURE); 786 exit (EXIT_FAILURE);
765 } 787 }
766 788
767 eval_pv ( 789 eval_pv (
768 "#line 1 'cfperl init'\n" 790 "#line 1 'cfperl init'\n"
769 "use EV ();\n" 791 "use EV ();\n" // required by bootstrap
770 "use Coro ();\n" 792 "use Coro ();\n" // required by bootstrap
771 "cf->bootstrap;\n" 793 "cf->bootstrap;\n" // required for cf::datadir
772 "unshift @INC, cf::datadir ();\n" 794 "unshift @INC, cf::datadir ();\n" // required for 'require' :)
773 "require cf;\n", 795 "require cf;\n",
774 0 796 0
775 ); 797 );
776 798
777 if (SvTRUE (ERRSV)) 799 if (SvTRUE (ERRSV))
1136 CALL_ARG (originator); 1158 CALL_ARG (originator);
1137 CALL_CALL ("cf::mapscript::activate", G_VOID); 1159 CALL_CALL ("cf::mapscript::activate", G_VOID);
1138 CALL_END; 1160 CALL_END;
1139} 1161}
1140 1162
1163void cfperl_ix (client *ns, int set, faceidx idx, int pri)
1164{
1165 CALL_BEGIN (3);
1166 CALL_ARG (ns);
1167 CALL_ARG (set);
1168 CALL_ARG (idx);
1169 CALL_ARG (pri);
1170 CALL_CALL (cv_cf_ix, G_VOID);
1171 CALL_END;
1172}
1173
1141player * 1174player *
1142player::find (const_utf8_string name) 1175player::find (const_utf8_string name)
1143{ 1176{
1144 CALL_BEGIN (1); 1177 CALL_BEGIN (1);
1145 CALL_ARG (name); 1178 CALL_ARG (name);
1391 stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1); 1424 stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1);
1392 stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1); 1425 stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1);
1393 stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1); 1426 stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1);
1394 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); 1427 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1);
1395 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1); 1428 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1);
1429 stash_cf_layout_wrap = gv_stashpv ("cf::layout::wrap", 1);
1396 stash_ext_map_world = gv_stashpv ("ext::map_world" , 1); 1430 stash_ext_map_world = gv_stashpv ("ext::map_world" , 1);
1397 1431
1398 sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV); 1432 sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV);
1399 sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV); 1433 sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV);
1434 sv_server_tick = get_sv ("cf::SERVER_TICK", 1); SvUPGRADE (sv_server_tick, SVt_IV);
1400 sv_tick_start = get_sv ("cf::TICK_START", 1); SvUPGRADE (sv_tick_start, SVt_NV); 1435 sv_tick_start = get_sv ("cf::TICK_START" , 1); SvUPGRADE (sv_tick_start , SVt_NV);
1401 sv_next_tick = get_sv ("cf::NEXT_TICK" , 1); SvUPGRADE (sv_next_tick , SVt_NV); 1436 sv_next_tick = get_sv ("cf::NEXT_TICK" , 1); SvUPGRADE (sv_next_tick , SVt_NV);
1402 1437
1403 cb_global = get_av ("cf::CB_GLOBAL", 1); 1438 cb_global = get_av ("cf::CB_GLOBAL", 1);
1404 cb_attachable = get_av ("cf::CB_ATTACHABLE", 1); 1439 cb_attachable = get_av ("cf::CB_ATTACHABLE", 1);
1405 cb_object = get_av ("cf::CB_OBJECT", 1); 1440 cb_object = get_av ("cf::CB_OBJECT", 1);
1406 cb_player = get_av ("cf::CB_PLAYER", 1); 1441 cb_player = get_av ("cf::CB_PLAYER", 1);
1413_connect_to_perl_2 () 1448_connect_to_perl_2 ()
1414{ 1449{
1415 cv_cf_do_invoke = (SV *)get_cv ("cf::do_invoke" , 0); assert (cv_cf_do_invoke); 1450 cv_cf_do_invoke = (SV *)get_cv ("cf::do_invoke" , 0); assert (cv_cf_do_invoke);
1416 cv_cf__can_merge = (SV *)get_cv ("cf::_can_merge" , 0); assert (cv_cf__can_merge); 1451 cv_cf__can_merge = (SV *)get_cv ("cf::_can_merge" , 0); assert (cv_cf__can_merge);
1417 cv_cf_client_send_msg = (SV *)get_cv ("cf::client::send_msg", 0); assert (cv_cf_client_send_msg); 1452 cv_cf_client_send_msg = (SV *)get_cv ("cf::client::send_msg", 0); assert (cv_cf_client_send_msg);
1453 cv_cf_ix = (SV *)get_cv ("cf::face::ix" , 0); assert (cv_cf_ix);
1418 cv_cf_tick = (SV *)get_cv ("cf::tick" , 0); assert (cv_cf_tick); 1454 cv_cf_tick = (SV *)get_cv ("cf::tick" , 0); assert (cv_cf_tick);
1419 cv_cf_match_match = (SV *)get_cv ("cf::match::match" , 0); assert (cv_cf_match_match); 1455 cv_cf_match_match = (SV *)get_cv ("cf::match::match" , 0); assert (cv_cf_match_match);
1420} 1456}
1421 1457
1422MODULE = cf PACKAGE = cf PREFIX = cf_ 1458MODULE = cf PACKAGE = cf PREFIX = cf_
1427 I_CORO_API (PACKAGE); coroapi::GCoroAPI = GCoroAPI; 1463 I_CORO_API (PACKAGE); coroapi::GCoroAPI = GCoroAPI;
1428 1464
1429 _connect_to_perl_1 (); 1465 _connect_to_perl_1 ();
1430 1466
1431 newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1)); 1467 newCONSTSUB (stash_cf, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1));
1432
1433 //{
1434 // require_pv ("Time::HiRes");
1435 //
1436 // SV **svp = hv_fetch (PL_modglobal, "Time::NVtime", 12, 0);
1437 // if (!svp) croak ("Time::HiRes is required");
1438 // if (!SvIOK(*svp)) croak ("Time::NVtime isn’t a function pointer");
1439 // coroapi::time = INT2PTR (double(*)(), SvIV(*svp));
1440 //}
1441 1468
1442 static const struct { 1469 static const struct {
1443 const char *name; 1470 const char *name;
1444 IV iv; 1471 IV iv;
1445 } *civ, const_iv[] = { 1472 } *civ, const_iv[] = {
1449# include "attackinc.h" 1476# include "attackinc.h"
1450# undef def 1477# undef def
1451# define def(uc, flags) const_iv (SK_ ## uc) 1478# define def(uc, flags) const_iv (SK_ ## uc)
1452# include "skillinc.h" 1479# include "skillinc.h"
1453# undef def 1480# undef def
1454 1481# define def(name, use, nonuse) const_iv (body_ ## name)
1455 const_iv (llevError) const_iv (llevInfo) const_iv (llevDebug) const_iv (llevMonster) 1482# include "slotinc.h"
1456 const_iv (logBacktrace) 1483# undef def
1457
1458 const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd)
1459 1484
1460 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) 1485 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y)
1461 1486
1462 const_iv (MAX_TIME) 1487 const_iv (MAX_TIME)
1463 const_iv (MAXSOCKBUF) 1488 const_iv (MAXSOCKBUF)
1477 const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE) 1502 const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE)
1478 1503
1479 const_iv (SK_EXP_ADD_SKILL) const_iv (SK_EXP_TOTAL) const_iv (SK_EXP_NONE) 1504 const_iv (SK_EXP_ADD_SKILL) const_iv (SK_EXP_TOTAL) const_iv (SK_EXP_NONE)
1480 const_iv (SK_SUBTRACT_SKILL_EXP) const_iv (SK_EXP_SKILL_ONLY) 1505 const_iv (SK_SUBTRACT_SKILL_EXP) const_iv (SK_EXP_SKILL_ONLY)
1481 1506
1482 const_iv (MAP_ACTIVE) const_iv (MAP_SWAPPED) const_iv (MAP_LOADING) const_iv (MAP_SAVING)
1483 const_iv (MAP_INACTIVE)
1484
1485 const_iv (KLASS_ATTACHABLE) const_iv (KLASS_GLOBAL) const_iv (KLASS_OBJECT) 1507 const_iv (KLASS_ATTACHABLE) const_iv (KLASS_GLOBAL) const_iv (KLASS_OBJECT)
1486 const_iv (KLASS_CLIENT) const_iv (KLASS_PLAYER) const_iv (KLASS_MAP) 1508 const_iv (KLASS_CLIENT) const_iv (KLASS_PLAYER) const_iv (KLASS_MAP)
1487 1509
1488 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT) 1510 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT)
1489 1511
1490 const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES) 1512 const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES)
1491 }; 1513 };
1492 1514
1493 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 1515 for (civ = const_iv + array_length (const_iv); civ-- > const_iv; )
1494 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv)); 1516 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv));
1495 1517
1496 static const struct { 1518 static const struct {
1497 const char *name; 1519 const char *name;
1498 int skip; 1520 int skip;
1504# undef def 1526# undef def
1505 }; 1527 };
1506 1528
1507 AV *av = get_av ("cf::EVENT", 1); 1529 AV *av = get_av ("cf::EVENT", 1);
1508 1530
1509 for (eiv = event_iv + sizeof (event_iv) / sizeof (event_iv [0]); eiv-- > event_iv; ) 1531 for (eiv = event_iv + array_length (event_iv); eiv-- > event_iv; )
1510 { 1532 {
1511 AV *event = newAV (); 1533 AV *event = newAV ();
1512 av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0)); 1534 av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0));
1513 av_push (event, newSViv (eiv->klass)); 1535 av_push (event, newSViv (eiv->klass));
1514 av_store (av, eiv->iv, newRV_noinc ((SV *)event)); 1536 av_store (av, eiv->iv, newRV_noinc ((SV *)event));
1521 1543
1522void _gv_clear (SV *gv) 1544void _gv_clear (SV *gv)
1523 CODE: 1545 CODE:
1524 assert (SvTYPE (gv) == SVt_PVGV); 1546 assert (SvTYPE (gv) == SVt_PVGV);
1525# define f(sv) { SV *sv_ = (SV *)(sv); sv = 0; SvREFCNT_dec (sv_); } 1547# define f(sv) { SV *sv_ = (SV *)(sv); sv = 0; SvREFCNT_dec (sv_); }
1548 SvREFCNT_inc (gv);
1526 f (GvGP (gv)->gp_form); 1549 f (GvGP (gv)->gp_form);
1527 f (GvGP (gv)->gp_io); 1550 f (GvGP (gv)->gp_io);
1528 f (GvGP (gv)->gp_sv); 1551 f (GvGP (gv)->gp_sv);
1529 f (GvGP (gv)->gp_av); 1552 f (GvGP (gv)->gp_av);
1530 f (GvGP (gv)->gp_hv); 1553 f (GvGP (gv)->gp_hv);
1531 f (GvGP (gv)->gp_cv); 1554 f (GvGP (gv)->gp_cv);
1532 GvCVGEN (gv) = 0; 1555 GvCVGEN (gv) = 0;
1533 GvMULTI_off (gv); 1556 GvMULTI_off (gv);
1557 SvREFCNT_dec (gv);
1534# undef f 1558# undef f
1535 1559
1536void _connect_to_perl_1 () 1560void _connect_to_perl_1 ()
1537 1561
1538void _connect_to_perl_2 () 1562void _connect_to_perl_2 ()
1549 1573
1550 for_all_objects (op) 1574 for_all_objects (op)
1551 op->reattach (); 1575 op->reattach ();
1552} 1576}
1553 1577
1554# support function for map-world.ext
1555void _quantise (SV *data_sv, SV *plt_sv)
1556 CODE:
1557{
1558 if (!SvROK (plt_sv) || SvTYPE (SvRV (plt_sv)) != SVt_PVAV)
1559 croak ("_quantise called with invalid agruments");
1560
1561 plt_sv = SvRV (plt_sv);
1562 SV **plt = AvARRAY (plt_sv);
1563 int plt_count = AvFILL (plt_sv) + 1;
1564
1565 STRLEN len;
1566 char *data = SvPVbyte (data_sv, len);
1567 char *dst = data;
1568
1569 while (len >= 3)
1570 {
1571 for (SV **val_sv = plt + plt_count; val_sv-- > plt; )
1572 {
1573 char *val = SvPVX (*val_sv);
1574
1575 if (val [0] == data [0]
1576 && val [1] == data [1]
1577 && val [2] == data [2])
1578 {
1579 *dst++ = val [3];
1580 goto next;
1581 }
1582 }
1583
1584 croak ("_quantise: color not found in palette: #%02x%02x%02x, at offset %d %d",
1585 (uint8_t)data [0], (uint8_t)data [1], (uint8_t)data [2],
1586 dst - SvPVX (data_sv), len);
1587
1588 next:
1589 data += 3;
1590 len -= 3;
1591 }
1592
1593 SvCUR_set (data_sv, dst - SvPVX (data_sv));
1594}
1595
1596void init_anim () 1578void init_anim ()
1597 1579
1598void init_globals () 1580void init_globals ()
1599 1581
1600void init_experience ()
1601
1602void init_attackmess () 1582void init_attackmess ()
1603 1583
1604void init_dynamic () 1584void init_dynamic ()
1605 1585
1606void load_settings () 1586void load_settings ()
1607 1587
1588void _reload_exp_table ()
1589
1608void load_materials () 1590void _reload_materials ()
1609 1591
1610void init_uuid () 1592void init_uuid ()
1611 CODE: 1593 CODE:
1612 UUID::init (); 1594 UUID::init ();
1613 1595
1646 { 1628 {
1647 ev_async_send (EV_DEFAULT, &tick_watcher); 1629 ev_async_send (EV_DEFAULT, &tick_watcher);
1648 coroapi::cede (); 1630 coroapi::cede ();
1649 } 1631 }
1650 1632
1651void server_tick () 1633void one_tick ()
1652 CODE: 1634 CODE:
1653{ 1635{
1654 ev_now_update (EV_DEFAULT); 1636 ev_now_update (EV_DEFAULT);
1655 NOW = ev_now (EV_DEFAULT); 1637 NOW = ev_now (EV_DEFAULT);
1656 SvNV_set (sv_now, NOW); SvNOK_only (sv_now); 1638 SvNV_set (sv_now, NOW); SvNOK_only (sv_now);
1657 SvNV_set (sv_tick_start, NOW); SvNOK_only (sv_tick_start); 1639 SvNV_set (sv_tick_start, NOW); SvNOK_only (sv_tick_start);
1658 runtime = SvNVX (sv_runtime); 1640 runtime = SvNVX (sv_runtime);
1659 1641
1642 one_tick ();
1643
1660 server_tick (); 1644 ++server_tick;
1645 SvUV_set (sv_server_tick, server_tick); SvIOK_only_UV (sv_server_tick);
1661 1646
1662 ev_now_update (EV_DEFAULT); 1647 ev_now_update (EV_DEFAULT);
1663 NOW = ev_now (EV_DEFAULT); 1648 NOW = ev_now (EV_DEFAULT);
1664 SvNV_set (sv_now, NOW); SvNOK_only (sv_now); 1649 SvNV_set (sv_now, NOW); SvNOK_only (sv_now);
1650
1665 runtime += TICK; 1651 runtime += TICK;
1666 SvNV_set (sv_runtime, runtime); SvNOK_only (sv_runtime); 1652 SvNV_set (sv_runtime, runtime); SvNOK_only (sv_runtime);
1667} 1653}
1668 1654
1669NV floor (NV x) 1655NV floor (NV x)
1673NV rndm (...) 1659NV rndm (...)
1674 ALIAS: 1660 ALIAS:
1675 rmg_rndm = 1 1661 rmg_rndm = 1
1676 CODE: 1662 CODE:
1677{ 1663{
1678 rand_gen &gen = ix ? rmg_rndm : rndm; 1664 rand_gen &gen = ix ? rmg_rndm : rndm;
1679 switch (items) 1665 switch (items)
1680 { 1666 {
1681 case 0: RETVAL = gen (); break; 1667 case 0: RETVAL = gen (); break;
1682 case 1: RETVAL = gen (SvUV (ST (0))); break; 1668 case 1: RETVAL = gen (SvUV (ST (0))); break;
1683 case 2: RETVAL = gen (SvIV (ST (0)), SvIV (ST (1))); break; 1669 case 2: RETVAL = gen (SvIV (ST (0)), SvIV (ST (1))); break;
1768 1754
1769int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) 1755int mlockall (int flags = MCL_CURRENT | MCL_FUTURE)
1770 INIT: 1756 INIT:
1771#if __GLIBC__ 1757#if __GLIBC__
1772 mallopt (M_TOP_PAD, 1024 * 1024); 1758 mallopt (M_TOP_PAD, 1024 * 1024);
1773 mallopt (M_MMAP_THRESHOLD, 1024 * 1024 * 128); 1759 mallopt (M_MMAP_THRESHOLD, 1024 * 1024);
1774 mallopt (M_MMAP_MAX, 0); // likely bug-workaround, also frees memory 1760 mallopt (M_MMAP_MAX, 0); // likely bug-workaround, also frees memory
1761 if (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 10))
1775 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc 1762 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc
1776#endif 1763#endif
1777 1764
1778int munlockall () 1765int munlockall ()
1779 1766
1780#endif 1767#endif
1806 PUSHs (sv_2mortal (newSVpv ("objects" , 0))); PUSHs (sv_2mortal (newSVuv (objects.size () * sizeof (object)))); 1793 PUSHs (sv_2mortal (newSVpv ("objects" , 0))); PUSHs (sv_2mortal (newSVuv (objects.size () * sizeof (object))));
1807 PUSHs (sv_2mortal (newSVpv ("sv_count" , 0))); PUSHs (sv_2mortal (newSVuv (PL_sv_count))); 1794 PUSHs (sv_2mortal (newSVpv ("sv_count" , 0))); PUSHs (sv_2mortal (newSVuv (PL_sv_count)));
1808 PUSHs (sv_2mortal (newSVpv ("sv_objcount", 0))); PUSHs (sv_2mortal (newSVuv (PL_sv_objcount))); 1795 PUSHs (sv_2mortal (newSVpv ("sv_objcount", 0))); PUSHs (sv_2mortal (newSVuv (PL_sv_objcount)));
1809} 1796}
1810 1797
1811int find_animation (utf8_string text)
1812 PROTOTYPE: $
1813
1814int random_roll (int min, int max, object *op, int goodbad); 1798int random_roll (int min, int max, object *op, int goodbad);
1815 1799
1816const_utf8_string cost_string_from_value(uint64 cost, int approx = 0) 1800const_utf8_string cost_string_from_value(uint64 cost, int approx = 0)
1817 1801
1818int exp_to_level (val64 exp) 1802int exp_to_level (val64 exp)
1819 1803
1820val64 level_to_min_exp (int level) 1804val64 level_to_min_exp (int level)
1821 1805
1806const_utf8_string
1807spellpathnames (int idx)
1808 CODE:
1809 RETVAL = spellpathnames [idx];
1810 OUTPUT: RETVAL
1811
1822SV * 1812SV *
1823resistance_to_string (int atnr) 1813attacktype_name (int atnr)
1824 CODE: 1814 CODE:
1825 if (atnr >= 0 && atnr < NROFATTACKS) 1815 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1816 ? newSVpv (attacktype_name [atnr], 0)
1817 : &PL_sv_undef;
1818 OUTPUT: RETVAL
1819
1820SV *
1821attacktype_desc (int atnr)
1822 CODE:
1823 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1824 ? newSVpv (attacktype_desc [atnr], 0)
1825 : &PL_sv_undef;
1826 OUTPUT: RETVAL
1827
1828SV *
1829resist_plus (int atnr)
1830 CODE:
1831 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1826 RETVAL = newSVpv (resist_plus[atnr], 0); 1832 ? newSVpv (resist_plus [atnr], 0)
1827 else 1833 : &PL_sv_undef;
1828 XSRETURN_UNDEF; 1834 OUTPUT: RETVAL
1835
1836SV *
1837change_resist_msg (int atnr)
1838 CODE:
1839 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1840 ? newSVpv (change_resist_msg [atnr], 0)
1841 : &PL_sv_undef;
1829 OUTPUT: RETVAL 1842 OUTPUT: RETVAL
1830 1843
1831UUID 1844UUID
1832uuid_cur () 1845uuid_cur ()
1833 CODE: 1846 CODE:
1874load_resource_file_ (octet_string filename) 1887load_resource_file_ (octet_string filename)
1875 1888
1876void 1889void
1877fix_weight () 1890fix_weight ()
1878 1891
1892utf8_string
1893expand_cfpod (int hintmode, int gender, const_utf8_string cfpod)
1894 PPCODE:
1895 XPUSHs (to_sv (player::expand_cfpod (hintmode, gender, cfpod)));
1896
1879MODULE = cf PACKAGE = cf::attachable 1897MODULE = cf PACKAGE = cf::attachable
1880 1898
1881int 1899int
1882valid (SV *obj) 1900valid (SV *obj)
1883 CODE: 1901 CODE:
1956int mortals_size () 1974int mortals_size ()
1957 CODE: 1975 CODE:
1958 RETVAL = attachable::mortals.size (); 1976 RETVAL = attachable::mortals.size ();
1959 OUTPUT: RETVAL 1977 OUTPUT: RETVAL
1960 1978
1961const_utf8_string slot_use_name (U32 slot) 1979const_utf8_string slot_name (U32 slot)
1962 ALIAS: 1980 ALIAS:
1981 slot_name = 0
1982 slot_use_name = 1
1963 slot_nonuse_name = 1 1983 slot_nonuse_name = 2
1964 CODE: 1984 CODE:
1965{ 1985{
1966 if (slot >= NUM_BODY_LOCATIONS) 1986 if (slot >= NUM_BODY_LOCATIONS)
1967 croak ("body slot index out of range"); 1987 croak ("body slot index out of range");
1968 1988
1969 switch (ix) 1989 switch (ix)
1970 { 1990 {
1991 case 0: RETVAL = body_locations[slot].name ; break;
1971 case 0: RETVAL = body_locations[slot].use_name; break; 1992 case 1: RETVAL = body_locations[slot].use_name ; break;
1972 case 1: RETVAL = body_locations[slot].nonuse_name; break; 1993 case 2: RETVAL = body_locations[slot].nonuse_name; break;
1973 } 1994 }
1974} 1995}
1975 OUTPUT: 1996 OUTPUT:
1976 RETVAL 1997 RETVAL
1977 1998
2083 2104
2084void pick_up (object *who, object *op) 2105void pick_up (object *who, object *op)
2085 2106
2086void update_object (object *op, int action) 2107void update_object (object *op, int action)
2087 2108
2088void change_exp (object *op, uint64 exp, utf8_string skill_name = 0, int flag = 0) 2109void change_exp (object *op, uint64 exp, shstr_tmp skill_name = shstr_tmp (), int flag = 0)
2089 2110
2090void player_lvl_adj (object *who, object *skill = 0) 2111void player_lvl_adj (object *who, object *skill = 0)
2091 2112
2092int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL) 2113int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL)
2093 2114
2102int convert_item (object *item, object *converter) 2123int convert_item (object *item, object *converter)
2103 2124
2104void fix_generated_item (object *op, object *creator, int difficulty, int max_magic, int flags); 2125void fix_generated_item (object *op, object *creator, int difficulty, int max_magic, int flags);
2105 2126
2106MODULE = cf PACKAGE = cf::object PREFIX = cf_ 2127MODULE = cf PACKAGE = cf::object PREFIX = cf_
2107
2108# no clean way to get an object from an archetype - stupid idiotic
2109# dumb kludgy misdesigned plug-in api slowly gets on my nerves.
2110 2128
2111object *new (utf8_string archetype = 0) 2129object *new (utf8_string archetype = 0)
2112 PROTOTYPE: ;$ 2130 PROTOTYPE: ;$
2113 CODE: 2131 CODE:
2114 RETVAL = archetype ? get_archetype (archetype) : object::create (); 2132 RETVAL = archetype
2133 ? archetype::get (archetype)
2134 : object::create ();
2115 OUTPUT: 2135 OUTPUT:
2116 RETVAL 2136 RETVAL
2117 2137
2118object *generate (utf8_string arch, object *creator) 2138object *generate (utf8_string arch, object *creator)
2119 CODE: 2139 CODE:
2120 object *obj = get_archetype (arch); 2140 object *obj = archetype::get (arch);
2121 fix_generated_item (obj, creator, 0, 0, GT_MINIMAL); 2141 fix_generated_item (obj, creator, 0, 0, GT_MINIMAL);
2122 RETVAL = obj; 2142 RETVAL = obj;
2123 OUTPUT: 2143 OUTPUT:
2124 RETVAL 2144 RETVAL
2125 2145
2135 RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y); 2155 RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y);
2136 2156
2137 if (RETVAL->destroyed ()) 2157 if (RETVAL->destroyed ())
2138 RETVAL = 0; 2158 RETVAL = 0;
2139} 2159}
2160 OUTPUT:
2161 RETVAL
2140 2162
2141shstr 2163shstr
2142object::kv_get (shstr key) 2164object::kv_get (shstr key)
2165 CODE:
2166 RETVAL = THIS->kv.get (key);
2167 OUTPUT:
2168 RETVAL
2143 2169
2144void 2170void
2145object::kv_del (shstr key) 2171object::kv_del (shstr key)
2172 CODE:
2173 THIS->kv.del (key);
2146 2174
2147void 2175void
2148object::kv_set (shstr key, shstr value) 2176object::kv_set (shstr key, shstr value)
2177 CODE:
2178 THIS->kv.set (key, value);
2149 2179
2150object *get_nearest_player (object *ob) 2180object *get_nearest_player (object *ob)
2151 ALIAS: nearest_player = 0 2181 ALIAS: nearest_player = 0
2152 PREINIT: 2182 PREINIT:
2153 extern object *get_nearest_player (object *); 2183 extern object *get_nearest_player (object *);
2356 if (pl->ob && pl->ob->map == THIS) 2386 if (pl->ob && pl->ob->map == THIS)
2357 PUSHs (sv_2mortal (to_sv (pl->ob))); 2387 PUSHs (sv_2mortal (to_sv (pl->ob)));
2358 } 2388 }
2359 2389
2360void 2390void
2391maptile::gen_quadmap (int x, int y, int z)
2392 CODE:
2393 gen_quadmap (THIS, x * 50, y * 50, z);
2394
2395void
2361maptile::add_underlay (SV *data, int offset, int stride, SV *palette) 2396maptile::add_underlay (SV *data, int offset, int stride, SV *palette)
2362 CODE: 2397 CODE:
2363{ 2398{
2364 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV) 2399 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV)
2365 croak ("maptile::add_underlay: palette must be arrayref"); 2400 croak ("maptile::add_underlay: palette must be arrayref");
2366 2401
2367 palette = SvRV (palette); 2402 palette = SvRV (palette);
2368 2403
2369 STRLEN idxlen; 2404 STRLEN idxlen;
2370 const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen); 2405 const uint8 *idx = (const uint8 *)SvPVbyte (data, idxlen);
2371 2406
2372 for (int x = 0; x < THIS->width; ++x) 2407 for (int x = 0; x < THIS->width; ++x)
2373 for (int y = 0; y < THIS->height; ++y) 2408 for (int y = 0; y < THIS->height; ++y)
2374 { 2409 {
2375 for (object *op = THIS->at (x, y).bot; op; op = op->above) 2410 for (object *op = THIS->at (x, y).bot; op; op = op->above)
2381 2416
2382 if (IN_RANGE_EXC (offs, 0, idxlen)) 2417 if (IN_RANGE_EXC (offs, 0, idxlen))
2383 { 2418 {
2384 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) 2419 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0))
2385 { 2420 {
2386 object *ob = get_archetype (cfSvPVutf8_nolen (*elem)); 2421 object *ob = archetype::get (cfSvPVutf8_nolen (*elem));
2387 ob->flag [FLAG_NO_MAP_SAVE] = true; 2422 ob->flag [FLAG_NO_MAP_SAVE] = true;
2388 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); 2423 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY);
2389 2424
2390 if (ob->randomitems && !ob->above) 2425 if (ob->randomitems && !ob->above)
2391 { 2426 {
2395 op->flag [FLAG_NO_MAP_SAVE] = true; 2430 op->flag [FLAG_NO_MAP_SAVE] = true;
2396 // TODO: if this is a pickable object, then the item 2431 // TODO: if this is a pickable object, then the item
2397 // will at a bit weird - saving inside the player 2432 // will at a bit weird - saving inside the player
2398 // will clear the flag, but when the player drops 2433 // will clear the flag, but when the player drops
2399 // it without logging out, it keeps the flag. 2434 // it without logging out, it keeps the flag.
2400 // nobody ahs reported this, but this can be rather 2435 // nobody has reported this, but this can be rather
2401 // annoying on persistent maps. 2436 // annoying on persistent maps.
2402 } 2437 }
2403 } 2438 }
2404 } 2439 }
2405 } 2440 }
2406
2407 skip: ; 2441 skip: ;
2408 } 2442 }
2409} 2443}
2410 2444
2411void 2445void
2416 croak ("maptile::set_regiondata: palette must be arrayref"); 2450 croak ("maptile::set_regiondata: palette must be arrayref");
2417 2451
2418 palette = SvRV (palette); 2452 palette = SvRV (palette);
2419 2453
2420 STRLEN idxlen; 2454 STRLEN idxlen;
2421 const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen); 2455 const uint8 *idx = (const uint8 *)SvPVbyte (data, idxlen);
2422 2456
2423 region_ptr *regionmap = new region_ptr [av_len ((AV *)palette) + 1]; 2457 region_ptr *regionmap = new region_ptr [av_len ((AV *)palette) + 1];
2424 uint8_t *regions = salloc<uint8_t> (THIS->size ()); 2458 uint8 *regions = salloc<uint8_t> (THIS->size ());
2425 2459
2426 for (int i = av_len ((AV *)palette) + 1; i--; ) 2460 for (int i = av_len ((AV *)palette) + 1; i--; )
2427 regionmap [i] = region::find (cfSvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1))); 2461 regionmap [i] = region::find (cfSvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1)));
2428 2462
2429 for (int y = 0; y < THIS->height; ++y) 2463 for (int y = 0; y < THIS->height; ++y)
2442 for (int x = 0; x < THIS->width; ++x) 2476 for (int x = 0; x < THIS->width; ++x)
2443 for (int y = 0; y < THIS->height; ++y) 2477 for (int y = 0; y < THIS->height; ++y)
2444 { 2478 {
2445 region *rgn = THIS->region (x, y); 2479 region *rgn = THIS->region (x, y);
2446 2480
2447 //fprintf (stderr, "%d,%d %f %p\n", x, y, rgn->treasure_density,rgn->treasure);//D
2448 if (object *op = THIS->at (x, y).top) 2481 if (object *op = THIS->at (x, y).top)
2449 if (rgn->treasure && rndm () < rgn->treasure_density) 2482 if (rgn->treasure && rndm () < rgn->treasure_density)
2450 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty); 2483 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty);
2451 } 2484 }
2452 2485
2458 if (oblinkpt *obp = map->find_link (connection)) 2491 if (oblinkpt *obp = map->find_link (connection))
2459 for (objectlink *ol = obp->link; ol; ol = ol->next) 2492 for (objectlink *ol = obp->link; ol; ol = ol->next)
2460 XPUSHs (sv_2mortal (to_sv ((object *)ol->ob))); 2493 XPUSHs (sv_2mortal (to_sv ((object *)ol->ob)));
2461 2494
2462void 2495void
2463normalise (maptile *map, int x, int y, int dir = 0) 2496xy_normalise (maptile *map, int x, int y, int dir = 0)
2464 PPCODE: 2497 PPCODE:
2465{ 2498{
2466 mapxy pos (map, x, y); 2499 mapxy pos (map, x, y);
2467 if (!pos.move (dir).normalise ()) 2500 if (!pos.move (dir).normalise ())
2468 XSRETURN_EMPTY; 2501 XSRETURN_EMPTY;
2531} 2564}
2532 OUTPUT: RETVAL 2565 OUTPUT: RETVAL
2533 2566
2534# worst xs function of my life 2567# worst xs function of my life
2535bool 2568bool
2536_create_random_map (\ 2569_create_random_map (maptile *self, SV *options)
2537 maptile *self,\
2538 utf8_string wallstyle,\
2539 utf8_string wall_name,\
2540 utf8_string floorstyle,\
2541 utf8_string monsterstyle,\
2542 utf8_string treasurestyle,\
2543 utf8_string layoutstyle,\
2544 utf8_string doorstyle,\
2545 utf8_string decorstyle,\
2546 utf8_string miningstyle,\
2547 utf8_string origin_map,\
2548 utf8_string final_map,\
2549 utf8_string exitstyle,\
2550 utf8_string this_map,\
2551 utf8_string exit_on_final_map,\
2552 int xsize,\
2553 int ysize,\
2554 int expand2x,\
2555 int layoutoptions1,\
2556 int layoutoptions2,\
2557 int layoutoptions3,\
2558 int symmetry,\
2559 int difficulty,\
2560 int difficulty_given,\
2561 float difficulty_increase,\
2562 int dungeon_level,\
2563 int dungeon_depth,\
2564 int decoroptions,\
2565 int orientation,\
2566 int origin_y,\
2567 int origin_x,\
2568 U32 random_seed,\
2569 val64 total_map_hp,\
2570 int map_layout_style,\
2571 int treasureoptions,\
2572 int symmetry_used,\
2573 region *region,\
2574 utf8_string custom\
2575)
2576 CODE: 2570 CODE:
2577{ 2571{
2578 random_map_params rmp; 2572 random_map_params rmp ((HV *)SvRV (options));
2579
2580 assign (rmp.wallstyle , wallstyle);
2581 assign (rmp.wall_name , wall_name);
2582 assign (rmp.floorstyle , floorstyle);
2583 assign (rmp.monsterstyle , monsterstyle);
2584 assign (rmp.treasurestyle , treasurestyle);
2585 assign (rmp.layoutstyle , layoutstyle);
2586 assign (rmp.doorstyle , doorstyle);
2587 assign (rmp.decorstyle , decorstyle);
2588 assign (rmp.miningstyle , miningstyle);
2589 assign (rmp.exitstyle , exitstyle);
2590 assign (rmp.exit_on_final_map, exit_on_final_map);
2591
2592 rmp.origin_map = origin_map;
2593 rmp.final_map = final_map;
2594 rmp.this_map = this_map;
2595 rmp.xsize = xsize;
2596 rmp.ysize = ysize;
2597 rmp.expand2x = expand2x;
2598 rmp.layoutoptions1 = layoutoptions1;
2599 rmp.layoutoptions2 = layoutoptions2;
2600 rmp.layoutoptions3 = layoutoptions3;
2601 rmp.symmetry = symmetry;
2602 rmp.difficulty = difficulty;
2603 rmp.difficulty_given = difficulty_given;
2604 rmp.difficulty_increase = difficulty_increase;
2605 rmp.dungeon_level = dungeon_level;
2606 rmp.dungeon_depth = dungeon_depth;
2607 rmp.decoroptions = decoroptions;
2608 rmp.orientation = orientation;
2609 rmp.origin_y = origin_y;
2610 rmp.origin_x = origin_x;
2611 rmp.random_seed = random_seed;
2612 rmp.total_map_hp = (uint64_t) total_map_hp;
2613 rmp.map_layout_style = map_layout_style;
2614 rmp.treasureoptions = treasureoptions;
2615 rmp.symmetry_used = symmetry_used;
2616 rmp.region = region;
2617 rmp.custom = custom;
2618
2619 RETVAL = self->generate_random_map (&rmp); 2573 RETVAL = self->generate_random_map (&rmp);
2620} 2574}
2621 OUTPUT: 2575 OUTPUT:
2622 RETVAL 2576 RETVAL
2623 2577
2634 2588
2635archetype *archetypes (U32 index) 2589archetype *archetypes (U32 index)
2636 CODE: 2590 CODE:
2637 RETVAL = index < archetypes.size () ? archetypes [index] : 0; 2591 RETVAL = index < archetypes.size () ? archetypes [index] : 0;
2638 OUTPUT: RETVAL 2592 OUTPUT: RETVAL
2593
2594int skillvec_size ()
2595 CODE:
2596 RETVAL = skillvec.size ();
2597 OUTPUT: RETVAL
2598
2599archetype *skillvec (U32 index)
2600 CODE:
2601 RETVAL = index < skillvec.size () ? (archetype *)(object *)skillvec [index] : 0;
2602 OUTPUT: RETVAL
2603
2604void
2605find_by_type (int type)
2606 PPCODE:
2607 for_all_archetypes (arch)
2608 if (arch->type == type)
2609 XPUSHs (sv_2mortal (to_sv (arch)));
2639 2610
2640INCLUDE: $PERL $srcdir/genacc archetype $srcdir/../include/object.h | 2611INCLUDE: $PERL $srcdir/genacc archetype $srcdir/../include/object.h |
2641 2612
2642MODULE = cf PACKAGE = cf::party 2613MODULE = cf PACKAGE = cf::party
2643 2614
2655list () 2626list ()
2656 PPCODE: 2627 PPCODE:
2657 for_all_regions (rgn) 2628 for_all_regions (rgn)
2658 XPUSHs (sv_2mortal (to_sv (rgn))); 2629 XPUSHs (sv_2mortal (to_sv (rgn)));
2659 2630
2660region *find (utf8_string name)
2661 PROTOTYPE: $
2662 CODE:
2663 RETVAL = region::find (name);
2664 OUTPUT: RETVAL
2665
2666int specificity (region *rgn) 2631int specificity (region *rgn)
2667 CODE: 2632 CODE:
2668 RETVAL = 0; 2633 RETVAL = 0;
2669 while (rgn = rgn->parent) 2634 while (rgn = rgn->parent)
2670 RETVAL++; 2635 RETVAL++;
2698list () 2663list ()
2699 PPCODE: 2664 PPCODE:
2700 EXTEND (SP, clients.size ()); 2665 EXTEND (SP, clients.size ());
2701 for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i) 2666 for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i)
2702 PUSHs (sv_2mortal (to_sv (*i))); 2667 PUSHs (sv_2mortal (to_sv (*i)));
2668
2669STRLEN
2670client::inbuf_append (SV *data)
2671 CODE:
2672{
2673 STRLEN len;
2674 char *ptr = SvPVbyte (data, len);
2675
2676 min_it (len, sizeof (THIS->inbuf) - THIS->inbuf_len);
2677 memcpy (THIS->inbuf + THIS->inbuf_len, ptr, len);
2678 THIS->inbuf_len += len;
2679
2680 THIS->inbuf_handle ();
2681
2682 RETVAL = len;
2683}
2684 OUTPUT: RETVAL
2703 2685
2704void 2686void
2705client::send_packet (SV *packet) 2687client::send_packet (SV *packet)
2706 CODE: 2688 CODE:
2707{ 2689{
2763faceidx face_find (utf8_string name, faceidx defidx = 0) 2745faceidx face_find (utf8_string name, faceidx defidx = 0)
2764 2746
2765faceidx alloc (utf8_string name) 2747faceidx alloc (utf8_string name)
2766 CODE: 2748 CODE:
2767{ 2749{
2768 do 2750 RETVAL = face_alloc ();
2769 {
2770 RETVAL = faces.size ();
2771 faces.resize (RETVAL + 1);
2772 }
2773 while (!RETVAL); // crude way to leave index 0
2774 2751
2775 faces [RETVAL].name = name; 2752 faces [RETVAL].name = name;
2776 facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL)); 2753 facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL));
2777 2754
2778 if (!strcmp (name, BLANK_FACE_NAME )) blank_face = RETVAL; 2755 if (!strcmp (name, BLANK_FACE_NAME )) blank_face = RETVAL;
2779 if (!strcmp (name, EMPTY_FACE_NAME )) empty_face = RETVAL; 2756 if (!strcmp (name, EMPTY_FACE_NAME )) empty_face = RETVAL;
2780 if (!strcmp (name, MAGICMOUTH_FACE_NAME)) magicmouth_face = RETVAL; 2757 if (!strcmp (name, MAGICMOUTH_FACE_NAME)) magicmouth_face = RETVAL;
2781} 2758}
2759 OUTPUT: RETVAL
2760
2761faceidx faces_size ()
2762 CODE:
2763 RETVAL = faces.size ();
2782 OUTPUT: RETVAL 2764 OUTPUT: RETVAL
2783 2765
2784void set_type (faceidx idx, int value) 2766void set_type (faceidx idx, int value)
2785 ALIAS: 2767 ALIAS:
2786 set_type = 0 2768 set_type = 0
2797 case 2: f->magicmap = value; break; 2779 case 2: f->magicmap = value; break;
2798 case 3: f->smooth = value; break; 2780 case 3: f->smooth = value; break;
2799 case 4: f->smoothlevel = value; break; 2781 case 4: f->smoothlevel = value; break;
2800 } 2782 }
2801 2783
2802void set_data (faceidx idx, int faceset, SV *data, SV *chksum) 2784void set_csum (faceidx idx, int faceset, SV *chksum)
2803 CODE: 2785 CODE:
2804{ 2786{
2805 faceinfo *f = face_info (idx); assert (f); 2787 faceinfo *f = face_info (idx); assert (f);
2806 facedata *d = &(faceset ? f->data64 : f->data32); 2788 facedata *d = f->face + faceset;
2807 sv_to (data, d->data);
2808 STRLEN clen; 2789 STRLEN clen;
2809 char *cdata = SvPVbyte (chksum, clen); 2790 char *cdata = SvPVbyte (chksum, clen);
2810 clen = min (CHKSUM_MAXLEN, clen);
2811 2791
2792 assert (("cf::face::set_data called with too long checksum", clen <= CHKSUM_MAXLEN));
2812 assert (("cf::face::set_data must be called with a non-empty checksum", clen)); 2793 assert (("cf::face::set_data must be called with a non-empty checksum", clen));
2813 2794
2814 if (clen != d->chksum_len || memcmp (d->chksum, cdata, clen)) 2795 if (clen != d->chksum_len || memcmp (d->chksum, cdata, clen))
2815 { 2796 {
2816 d->chksum_len = clen; 2797 d->chksum_len = clen;
2817 memcpy (d->chksum, cdata, clen); 2798 memcpy (d->chksum, cdata, clen);
2818 2799
2819 // invalidate existing client face info 2800 // invalidate existing client face info
2820 for_all_clients (ns) 2801 for_all_clients (ns)
2821 if (ns->faceset == faceset) 2802 ns->invalidate_face (idx);
2822 {
2823 ns->faces_sent [idx] = false;
2824 ns->force_newmap = true;
2825 }
2826 } 2803 }
2827} 2804}
2828 2805
2829int get_data_size (faceidx idx, int faceset = 0) 2806SV *mangle_csum (SV *chksum)
2830 CODE: 2807 CODE:
2831 facedata *d = face_data (idx, faceset); 2808 STRLEN len;
2832 if (!d) XSRETURN_UNDEF; 2809 char *data = SvPVbyte (chksum, len);
2833 RETVAL = d->data.size (); 2810 RETVAL = newSVpvn (data, min (len, CHKSUM_MAXLEN));
2834 OUTPUT: 2811 OUTPUT:
2835 RETVAL 2812 RETVAL
2836 2813
2837SV *get_chksum (faceidx idx, int faceset = 0) 2814SV *get_csum (faceidx idx, int faceset = 0)
2838 CODE: 2815 CODE:
2839 facedata *d = face_data (idx, faceset); 2816 facedata *d = face_data (idx, faceset);
2840 if (!d) XSRETURN_UNDEF; 2817 if (!d) XSRETURN_UNDEF;
2841 RETVAL = newSVpvn ((char *)d->chksum, d->chksum_len); 2818 RETVAL = newSVpvn ((char *)d->chksum, d->chksum_len);
2842 OUTPUT: 2819 OUTPUT:
2843 RETVAL 2820 RETVAL
2844 2821
2845SV *get_data (faceidx idx, int faceset = 0) 2822int get_type (faceidx idx)
2846 CODE: 2823 CODE:
2847 facedata *d = face_data (idx, faceset); 2824 faceinfo *f = face_info (idx);
2848 if (!d) XSRETURN_UNDEF; 2825 if (!f) XSRETURN_UNDEF;
2849 RETVAL = newSVpvn (d->data.data (), d->data.length ()); 2826 RETVAL = f->type;
2850 OUTPUT: 2827 OUTPUT:
2851 RETVAL 2828 RETVAL
2852 2829
2830SV *get_name (faceidx idx)
2831 CODE:
2832 faceinfo *f = face_info (idx);
2833 if (!f) XSRETURN_UNDEF;
2834 RETVAL = to_sv (f->name);
2835 OUTPUT:
2836 RETVAL
2837
2853void invalidate (faceidx idx) 2838void invalidate (faceidx idx)
2854 CODE: 2839 CODE:
2855 for_all_clients (ns) 2840 for_all_clients (ns)
2856 { 2841 ns->invalidate_face (idx);
2857 ns->faces_sent [idx] = false;
2858 ns->force_newmap = true;
2859 }
2860 2842
2861void invalidate_all () 2843void invalidate_all ()
2862 CODE: 2844 CODE:
2863 for_all_clients (ns) 2845 for_all_clients (ns)
2864 { 2846 ns->invalidate_all_faces ();
2865 ns->faces_sent.reset ();
2866 ns->force_newmap = true;
2867 }
2868 2847
2869MODULE = cf PACKAGE = cf::anim PREFIX = anim_ 2848MODULE = cf PACKAGE = cf::anim PREFIX = anim_
2870 2849
2871#INCLUDE: $PERL $srcdir/genacc faceset $srcdir/../include/anim.h | 2850#INCLUDE: $PERL $srcdir/genacc faceset $srcdir/../include/anim.h |
2872 2851
2876 OUTPUT: RETVAL 2855 OUTPUT: RETVAL
2877 2856
2878animidx set (utf8_string name, SV *frames, int facings = 1) 2857animidx set (utf8_string name, SV *frames, int facings = 1)
2879 CODE: 2858 CODE:
2880{ 2859{
2881 if (!SvROK (frames) && SvTYPE (SvRV (frames)) != SVt_PVAV) 2860 if (!SvROK (frames) && SvTYPE (SvRV (frames)) != SVt_PVAV)
2882 croak ("frames must be an arrayref"); 2861 croak ("frames must be an arrayref");
2883 2862
2884 AV *av = (AV *)SvRV (frames); 2863 AV *av = (AV *)SvRV (frames);
2885 2864
2886 animation *anim = &animation::find (name); 2865 animation *anim = &animation::find (name);
2887 if (anim->number) 2866 if (anim->number)
2888 { 2867 {
2889 anim->resize (av_len (av) + 1); 2868 anim->resize (av_len (av) + 1);
2890 anim->facings = facings; 2869 anim->facings = facings;
2891 } 2870 }
2963 XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ()))); 2942 XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ())));
2964 2943
2965 self->skip (); 2944 self->skip ();
2966 } 2945 }
2967 2946
2947MODULE = cf PACKAGE = cf::treasurelist
2948
2949# quick hack, because I didn't want to implement accessors for treasurelist.
2950# this asks for even more autogen, actually.
2951
2952void
2953expand (treasurelist *list)
2954 PPCODE:
2955 EXTEND (SP, 3);
2956 PUSHs (sv_2mortal (to_sv (list->name)));
2957 PUSHs (sv_2mortal (to_sv (list->total_chance)));
2958 AV *av = newAV ();
2959 PUSHs (sv_2mortal (newRV_noinc ((SV *)av)));
2960 for (treasure *item = list->items; item; item = item->next)
2961 {
2962 AV *iav = newAV ();
2963 av_push (av, newRV_noinc ((SV *)iav));
2964
2965 av_extend (iav, 7);
2966 av_push (iav, to_sv (item->item));
2967 av_push (iav, to_sv (item->name));
2968 av_push (iav, to_sv (item->change_arch.name));
2969 av_push (iav, to_sv (item->change_arch.title));
2970 av_push (iav, to_sv (item->change_arch.slaying));
2971 av_push (iav, to_sv (item->chance));
2972 av_push (iav, to_sv (item->nrof));
2973 av_push (iav, to_sv (item->magic));
2974 }
2975
2976MODULE = cf PACKAGE = cf::layout
2977
2978INCLUDE: $PERL $srcdir/genacc layout $srcdir/../include/rmg.h |
2979

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines