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.378 by root, Wed Apr 21 03:29:27 2010 UTC vs.
Revision 1.414 by root, Tue Oct 30 17:07:50 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,
122 124
123 return sv; 125 return sv;
124} 126}
125#endif 127#endif
126 128
127static noinline utf8_string 129noinline utf8_string
128cfSvPVutf8_nolen (SV *sv) 130cfSvPVutf8_nolen (SV *sv)
129{ 131{
130 SvGETMAGIC (sv); 132 SvGETMAGIC (sv);
131 133
132 if (SvPOK (sv)) 134 if (SvPOK (sv))
251 { 253 {
252 static int last_mortalcount; 254 static int last_mortalcount;
253 if (mortals.size () != last_mortalcount) 255 if (mortals.size () != last_mortalcount)
254 { 256 {
255 last_mortalcount = mortals.size (); 257 last_mortalcount = mortals.size ();
256 LOG (llevInfo, "%d mortals.\n", (int)mortals.size ()); 258 object *specimen = is_a<object> (mortals [rndm (mortals.size ())]);
259
260 LOG (llevInfo, "%d mortals (random specimen: %s).\n",
261 (int)mortals.size (), specimen ? specimen->debug_desc () : "(not an object)");
257 262
258 if (0) 263 if (0)
259 { 264 {
260 for (int j = 0; j < mortals.size (); ++j)//D 265 for (int j = 0; j < mortals.size (); ++j)//D
261 fprintf (stderr, "%d:%s %p ", j, &((object *)mortals[j])->name, mortals[j]);//D 266 fprintf (stderr, "%d:%s %p ", j, &((object *)mortals[j])->name, mortals[j]);//D
352#endif 357#endif
353 358
354////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 359//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
355 360
356static SV * 361static SV *
357newSVptr (void *ptr, HV *stash, HV *hv = newHV ()) 362newSVptr (void *ptr, HV *stash, HV *hv)
358{ 363{
359 SV *sv;
360
361 if (!ptr) 364 if (!ptr)
362 return newSV (0); 365 return newSV (0);
363 366
364 sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, 0, (char *)ptr, 0); 367 sv_magicext ((SV *)hv, 0, PERL_MAGIC_ext, 0, (char *)ptr, 0);
365 return sv_bless (newRV_noinc ((SV *)hv), stash); 368 return sv_bless (newRV_noinc ((SV *)hv), stash);
369}
370
371static SV * noinline
372newSVptr (void *ptr, HV *stash)
373{
374 return newSVptr (ptr, stash, newHV ());
366} 375}
367 376
368static int 377static int
369attachable_free (pTHX_ SV *sv, MAGIC *mg) 378attachable_free (pTHX_ SV *sv, MAGIC *mg)
370{ 379{
382 return 0; 391 return 0;
383} 392}
384 393
385MGVTBL attachable::vtbl = {0, 0, 0, 0, attachable_free}; 394MGVTBL attachable::vtbl = {0, 0, 0, 0, attachable_free};
386 395
387static SV * 396static SV * noinline
388newSVattachable (attachable *obj, HV *stash) 397newSVattachable (attachable *obj, HV *stash)
389{ 398{
390 if (!obj) 399 if (!obj)
391 return newSV (0); 400 return newSV (0);
392 401
526static inline SV *to_sv (unsigned long long v) { return newSVval64 (v); } 535static inline SV *to_sv (unsigned long long v) { return newSVval64 (v); }
527static inline SV *to_sv (float v) { return newSVnv (v); } 536static inline SV *to_sv (float v) { return newSVnv (v); }
528static inline SV *to_sv (double v) { return newSVnv (v); } 537static inline SV *to_sv (double v) { return newSVnv (v); }
529static inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); } 538static 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); } 539static inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); }
540// 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); } 541static noinline SV *to_sv_ni (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); }
542static 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); } 543static 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); } 544static 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); } 545static 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); } 546static 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); } 547static 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); } 548static inline SV *to_sv (mapspace * v) { return newSVptr (v, stash_cf_mapspace_wrap); }
549static inline SV *to_sv (layout * v) { return newSVptr (v, stash_cf_layout_wrap); }
538 550
539static inline SV *to_sv (object & v) { return to_sv (&v); } 551static inline SV *to_sv (object & v) { return to_sv (&v); }
540static inline SV *to_sv (living & v) { return to_sv (&v); } 552static inline SV *to_sv (living & v) { return to_sv (&v); }
541 553
542static inline SV *to_sv (const std::string & v) { return newSVpvn (v.data (), v.size ()); } 554static 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"); } 600static 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"); } 601static 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"); } 602static 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"); } 603static 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"); } 604static inline void sv_to (SV *sv, mapspace * &v) { v = (mapspace *) SvPTR_ornull (sv, "cf::mapspace"); }
605static 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"); } 606static 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" ); } 607static inline void sv_to (SV *sv, object_thawer * &v) { v = (object_thawer *) SvPTR_ornull (sv, "cf::object::thawer" ); }
595 608
596//static inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; } 609//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)); } 610static inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); }
610static inline void sv_to (SV *sv, std::string &v) 623static inline void sv_to (SV *sv, std::string &v)
611{ 624{
612 STRLEN len; 625 STRLEN len;
613 char *data = SvPVbyte (sv, len); 626 char *data = SvPVbyte (sv, len);
614 v.assign (data, len); 627 v.assign (data, len);
628}
629
630static inline void sv_to (SV *sv, refcnt_buf &v)
631{
632 STRLEN len;
633 char *data = SvPVbyte (sv, len);
634 refcnt_buf buf (data, len);
635 v = buf;
615} 636}
616 637
617static inline void sv_to (SV *sv, UUID &v) 638static inline void sv_to (SV *sv, UUID &v)
618{ 639{
619 if (!v.parse (SvPV_nolen (sv))) 640 if (!v.parse (SvPV_nolen (sv)))
764 exit (EXIT_FAILURE); 785 exit (EXIT_FAILURE);
765 } 786 }
766 787
767 eval_pv ( 788 eval_pv (
768 "#line 1 'cfperl init'\n" 789 "#line 1 'cfperl init'\n"
769 "use EV ();\n" 790 "use EV ();\n" // required by bootstrap
770 "use Coro ();\n" 791 "use Coro ();\n" // required by bootstrap
771 "cf->bootstrap;\n" 792 "cf->bootstrap;\n" // required for cf::datadir
772 "unshift @INC, cf::datadir ();\n" 793 "unshift @INC, cf::datadir ();\n" // required for 'require' :)
773 "require cf;\n", 794 "require cf;\n",
774 0 795 0
775 ); 796 );
776 797
777 if (SvTRUE (ERRSV)) 798 if (SvTRUE (ERRSV))
1391 stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1); 1412 stash_cf_client_wrap = gv_stashpv ("cf::client::wrap", 1);
1392 stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1); 1413 stash_cf_arch_wrap = gv_stashpv ("cf::arch::wrap" , 1);
1393 stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1); 1414 stash_cf_party_wrap = gv_stashpv ("cf::party::wrap" , 1);
1394 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); 1415 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1);
1395 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1); 1416 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1);
1417 stash_cf_layout_wrap = gv_stashpv ("cf::layout::wrap", 1);
1396 stash_ext_map_world = gv_stashpv ("ext::map_world" , 1); 1418 stash_ext_map_world = gv_stashpv ("ext::map_world" , 1);
1397 1419
1398 sv_now = get_sv ("cf::NOW" , 1); SvUPGRADE (sv_now , SVt_NV); 1420 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); 1421 sv_runtime = get_sv ("cf::RUNTIME" , 1); SvUPGRADE (sv_runtime , SVt_NV);
1422 sv_server_tick = get_sv ("cf::SERVER_TICK", 1); SvUPGRADE (sv_server_tick, SVt_IV);
1400 sv_tick_start = get_sv ("cf::TICK_START", 1); SvUPGRADE (sv_tick_start, SVt_NV); 1423 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); 1424 sv_next_tick = get_sv ("cf::NEXT_TICK" , 1); SvUPGRADE (sv_next_tick , SVt_NV);
1402 1425
1403 cb_global = get_av ("cf::CB_GLOBAL", 1); 1426 cb_global = get_av ("cf::CB_GLOBAL", 1);
1404 cb_attachable = get_av ("cf::CB_ATTACHABLE", 1); 1427 cb_attachable = get_av ("cf::CB_ATTACHABLE", 1);
1405 cb_object = get_av ("cf::CB_OBJECT", 1); 1428 cb_object = get_av ("cf::CB_OBJECT", 1);
1406 cb_player = get_av ("cf::CB_PLAYER", 1); 1429 cb_player = get_av ("cf::CB_PLAYER", 1);
1449# include "attackinc.h" 1472# include "attackinc.h"
1450# undef def 1473# undef def
1451# define def(uc, flags) const_iv (SK_ ## uc) 1474# define def(uc, flags) const_iv (SK_ ## uc)
1452# include "skillinc.h" 1475# include "skillinc.h"
1453# undef def 1476# undef def
1454 1477# define def(name, use, nonuse) const_iv (body_ ## name)
1455 const_iv (llevError) const_iv (llevInfo) const_iv (llevDebug) const_iv (llevMonster) 1478# include "slotinc.h"
1456 const_iv (logBacktrace) 1479# undef def
1457
1458 const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd)
1459 1480
1460 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) 1481 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y)
1461 1482
1462 const_iv (MAX_TIME) 1483 const_iv (MAX_TIME)
1463 const_iv (MAXSOCKBUF) 1484 const_iv (MAXSOCKBUF)
1477 const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE) 1498 const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE)
1478 1499
1479 const_iv (SK_EXP_ADD_SKILL) const_iv (SK_EXP_TOTAL) const_iv (SK_EXP_NONE) 1500 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) 1501 const_iv (SK_SUBTRACT_SKILL_EXP) const_iv (SK_EXP_SKILL_ONLY)
1481 1502
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) 1503 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) 1504 const_iv (KLASS_CLIENT) const_iv (KLASS_PLAYER) const_iv (KLASS_MAP)
1487 1505
1488 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT) 1506 const_iv (CS_QUERY_YESNO) const_iv (CS_QUERY_SINGLECHAR) const_iv (CS_QUERY_HIDEINPUT)
1489 1507
1490 const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES) 1508 const_iv (IO_HEADER) const_iv (IO_OBJECTS) const_iv (IO_UNIQUES)
1491 }; 1509 };
1492 1510
1493 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 1511 for (civ = const_iv + array_length (const_iv); civ-- > const_iv; )
1494 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv)); 1512 newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv));
1495 1513
1496 static const struct { 1514 static const struct {
1497 const char *name; 1515 const char *name;
1498 int skip; 1516 int skip;
1504# undef def 1522# undef def
1505 }; 1523 };
1506 1524
1507 AV *av = get_av ("cf::EVENT", 1); 1525 AV *av = get_av ("cf::EVENT", 1);
1508 1526
1509 for (eiv = event_iv + sizeof (event_iv) / sizeof (event_iv [0]); eiv-- > event_iv; ) 1527 for (eiv = event_iv + array_length (event_iv); eiv-- > event_iv; )
1510 { 1528 {
1511 AV *event = newAV (); 1529 AV *event = newAV ();
1512 av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0)); 1530 av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0));
1513 av_push (event, newSViv (eiv->klass)); 1531 av_push (event, newSViv (eiv->klass));
1514 av_store (av, eiv->iv, newRV_noinc ((SV *)event)); 1532 av_store (av, eiv->iv, newRV_noinc ((SV *)event));
1521 1539
1522void _gv_clear (SV *gv) 1540void _gv_clear (SV *gv)
1523 CODE: 1541 CODE:
1524 assert (SvTYPE (gv) == SVt_PVGV); 1542 assert (SvTYPE (gv) == SVt_PVGV);
1525# define f(sv) { SV *sv_ = (SV *)(sv); sv = 0; SvREFCNT_dec (sv_); } 1543# define f(sv) { SV *sv_ = (SV *)(sv); sv = 0; SvREFCNT_dec (sv_); }
1544 SvREFCNT_inc (gv);
1526 f (GvGP (gv)->gp_form); 1545 f (GvGP (gv)->gp_form);
1527 f (GvGP (gv)->gp_io); 1546 f (GvGP (gv)->gp_io);
1528 f (GvGP (gv)->gp_sv); 1547 f (GvGP (gv)->gp_sv);
1529 f (GvGP (gv)->gp_av); 1548 f (GvGP (gv)->gp_av);
1530 f (GvGP (gv)->gp_hv); 1549 f (GvGP (gv)->gp_hv);
1531 f (GvGP (gv)->gp_cv); 1550 f (GvGP (gv)->gp_cv);
1532 GvCVGEN (gv) = 0; 1551 GvCVGEN (gv) = 0;
1533 GvMULTI_off (gv); 1552 GvMULTI_off (gv);
1553 SvREFCNT_dec (gv);
1534# undef f 1554# undef f
1535 1555
1536void _connect_to_perl_1 () 1556void _connect_to_perl_1 ()
1537 1557
1538void _connect_to_perl_2 () 1558void _connect_to_perl_2 ()
1549 1569
1550 for_all_objects (op) 1570 for_all_objects (op)
1551 op->reattach (); 1571 op->reattach ();
1552} 1572}
1553 1573
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 () 1574void init_anim ()
1597 1575
1598void init_globals () 1576void init_globals ()
1599 1577
1600void init_experience ()
1601
1602void init_attackmess () 1578void init_attackmess ()
1603 1579
1604void init_dynamic () 1580void init_dynamic ()
1605 1581
1606void load_settings () 1582void load_settings ()
1607 1583
1584void reload_exp_table ()
1585
1608void load_materials () 1586void reload_materials ()
1609 1587
1610void init_uuid () 1588void init_uuid ()
1611 CODE: 1589 CODE:
1612 UUID::init (); 1590 UUID::init ();
1613 1591
1646 { 1624 {
1647 ev_async_send (EV_DEFAULT, &tick_watcher); 1625 ev_async_send (EV_DEFAULT, &tick_watcher);
1648 coroapi::cede (); 1626 coroapi::cede ();
1649 } 1627 }
1650 1628
1651void server_tick () 1629void one_tick ()
1652 CODE: 1630 CODE:
1653{ 1631{
1654 ev_now_update (EV_DEFAULT); 1632 ev_now_update (EV_DEFAULT);
1655 NOW = ev_now (EV_DEFAULT); 1633 NOW = ev_now (EV_DEFAULT);
1656 SvNV_set (sv_now, NOW); SvNOK_only (sv_now); 1634 SvNV_set (sv_now, NOW); SvNOK_only (sv_now);
1657 SvNV_set (sv_tick_start, NOW); SvNOK_only (sv_tick_start); 1635 SvNV_set (sv_tick_start, NOW); SvNOK_only (sv_tick_start);
1658 runtime = SvNVX (sv_runtime); 1636 runtime = SvNVX (sv_runtime);
1659 1637
1638 one_tick ();
1639
1660 server_tick (); 1640 ++server_tick;
1641 SvUV_set (sv_server_tick, server_tick); SvIOK_only_UV (sv_server_tick);
1661 1642
1662 ev_now_update (EV_DEFAULT); 1643 ev_now_update (EV_DEFAULT);
1663 NOW = ev_now (EV_DEFAULT); 1644 NOW = ev_now (EV_DEFAULT);
1664 SvNV_set (sv_now, NOW); SvNOK_only (sv_now); 1645 SvNV_set (sv_now, NOW); SvNOK_only (sv_now);
1646
1665 runtime += TICK; 1647 runtime += TICK;
1666 SvNV_set (sv_runtime, runtime); SvNOK_only (sv_runtime); 1648 SvNV_set (sv_runtime, runtime); SvNOK_only (sv_runtime);
1667} 1649}
1668 1650
1669NV floor (NV x) 1651NV floor (NV x)
1768 1750
1769int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) 1751int mlockall (int flags = MCL_CURRENT | MCL_FUTURE)
1770 INIT: 1752 INIT:
1771#if __GLIBC__ 1753#if __GLIBC__
1772 mallopt (M_TOP_PAD, 1024 * 1024); 1754 mallopt (M_TOP_PAD, 1024 * 1024);
1773 mallopt (M_MMAP_THRESHOLD, 1024 * 1024 * 128); 1755 mallopt (M_MMAP_THRESHOLD, 1024 * 1024);
1774 mallopt (M_MMAP_MAX, 0); // likely bug-workaround, also frees memory 1756 mallopt (M_MMAP_MAX, 0); // likely bug-workaround, also frees memory
1757 if (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 10))
1775 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc 1758 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc
1776#endif 1759#endif
1777 1760
1778int munlockall () 1761int munlockall ()
1779 1762
1780#endif 1763#endif
1818int exp_to_level (val64 exp) 1801int exp_to_level (val64 exp)
1819 1802
1820val64 level_to_min_exp (int level) 1803val64 level_to_min_exp (int level)
1821 1804
1822SV * 1805SV *
1823resistance_to_string (int atnr) 1806attacktype_name (int atnr)
1824 CODE: 1807 CODE:
1825 if (atnr >= 0 && atnr < NROFATTACKS) 1808 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1809 ? newSVpv (attacktype_name [atnr], 0)
1810 : &PL_sv_undef;
1811 OUTPUT: RETVAL
1812
1813SV *
1814attacktype_desc (int atnr)
1815 CODE:
1816 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1817 ? newSVpv (attacktype_desc [atnr], 0)
1818 : &PL_sv_undef;
1819 OUTPUT: RETVAL
1820
1821SV *
1822resist_plus (int atnr)
1823 CODE:
1824 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1826 RETVAL = newSVpv (resist_plus[atnr], 0); 1825 ? newSVpv (resist_plus [atnr], 0)
1827 else 1826 : &PL_sv_undef;
1828 XSRETURN_UNDEF; 1827 OUTPUT: RETVAL
1828
1829SV *
1830change_resist_msg (int atnr)
1831 CODE:
1832 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1833 ? newSVpv (change_resist_msg [atnr], 0)
1834 : &PL_sv_undef;
1829 OUTPUT: RETVAL 1835 OUTPUT: RETVAL
1830 1836
1831UUID 1837UUID
1832uuid_cur () 1838uuid_cur ()
1833 CODE: 1839 CODE:
1956int mortals_size () 1962int mortals_size ()
1957 CODE: 1963 CODE:
1958 RETVAL = attachable::mortals.size (); 1964 RETVAL = attachable::mortals.size ();
1959 OUTPUT: RETVAL 1965 OUTPUT: RETVAL
1960 1966
1961const_utf8_string slot_use_name (U32 slot) 1967const_utf8_string slot_name (U32 slot)
1962 ALIAS: 1968 ALIAS:
1969 slot_name = 0
1970 slot_use_name = 1
1963 slot_nonuse_name = 1 1971 slot_nonuse_name = 2
1964 CODE: 1972 CODE:
1965{ 1973{
1966 if (slot >= NUM_BODY_LOCATIONS) 1974 if (slot >= NUM_BODY_LOCATIONS)
1967 croak ("body slot index out of range"); 1975 croak ("body slot index out of range");
1968 1976
1969 switch (ix) 1977 switch (ix)
1970 { 1978 {
1979 case 0: RETVAL = body_locations[slot].name ; break;
1971 case 0: RETVAL = body_locations[slot].use_name; break; 1980 case 1: RETVAL = body_locations[slot].use_name ; break;
1972 case 1: RETVAL = body_locations[slot].nonuse_name; break; 1981 case 2: RETVAL = body_locations[slot].nonuse_name; break;
1973 } 1982 }
1974} 1983}
1975 OUTPUT: 1984 OUTPUT:
1976 RETVAL 1985 RETVAL
1977 1986
2083 2092
2084void pick_up (object *who, object *op) 2093void pick_up (object *who, object *op)
2085 2094
2086void update_object (object *op, int action) 2095void update_object (object *op, int action)
2087 2096
2088void change_exp (object *op, uint64 exp, utf8_string skill_name = 0, int flag = 0) 2097void change_exp (object *op, uint64 exp, shstr_tmp skill_name = shstr_tmp (), int flag = 0)
2089 2098
2090void player_lvl_adj (object *who, object *skill = 0) 2099void player_lvl_adj (object *who, object *skill = 0)
2091 2100
2092int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL) 2101int kill_object (object *op, int dam = 0, object *hitter = 0, int type = AT_PHYSICAL)
2093 2102
2109# dumb kludgy misdesigned plug-in api slowly gets on my nerves. 2118# dumb kludgy misdesigned plug-in api slowly gets on my nerves.
2110 2119
2111object *new (utf8_string archetype = 0) 2120object *new (utf8_string archetype = 0)
2112 PROTOTYPE: ;$ 2121 PROTOTYPE: ;$
2113 CODE: 2122 CODE:
2114 RETVAL = archetype ? get_archetype (archetype) : object::create (); 2123 RETVAL = archetype
2124 ? archetype::get (archetype)
2125 : object::create ();
2115 OUTPUT: 2126 OUTPUT:
2116 RETVAL 2127 RETVAL
2117 2128
2118object *generate (utf8_string arch, object *creator) 2129object *generate (utf8_string arch, object *creator)
2119 CODE: 2130 CODE:
2120 object *obj = get_archetype (arch); 2131 object *obj = archetype::get (arch);
2121 fix_generated_item (obj, creator, 0, 0, GT_MINIMAL); 2132 fix_generated_item (obj, creator, 0, 0, GT_MINIMAL);
2122 RETVAL = obj; 2133 RETVAL = obj;
2123 OUTPUT: 2134 OUTPUT:
2124 RETVAL 2135 RETVAL
2125 2136
2135 RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y); 2146 RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y);
2136 2147
2137 if (RETVAL->destroyed ()) 2148 if (RETVAL->destroyed ())
2138 RETVAL = 0; 2149 RETVAL = 0;
2139} 2150}
2151 OUTPUT:
2152 RETVAL
2140 2153
2141shstr 2154shstr
2142object::kv_get (shstr key) 2155object::kv_get (shstr key)
2156 CODE:
2157 RETVAL = THIS->kv.get (key);
2158 OUTPUT:
2159 RETVAL
2143 2160
2144void 2161void
2145object::kv_del (shstr key) 2162object::kv_del (shstr key)
2163 CODE:
2164 THIS->kv.del (key);
2146 2165
2147void 2166void
2148object::kv_set (shstr key, shstr value) 2167object::kv_set (shstr key, shstr value)
2168 CODE:
2169 THIS->kv.set (key, value);
2149 2170
2150object *get_nearest_player (object *ob) 2171object *get_nearest_player (object *ob)
2151 ALIAS: nearest_player = 0 2172 ALIAS: nearest_player = 0
2152 PREINIT: 2173 PREINIT:
2153 extern object *get_nearest_player (object *); 2174 extern object *get_nearest_player (object *);
2356 if (pl->ob && pl->ob->map == THIS) 2377 if (pl->ob && pl->ob->map == THIS)
2357 PUSHs (sv_2mortal (to_sv (pl->ob))); 2378 PUSHs (sv_2mortal (to_sv (pl->ob)));
2358 } 2379 }
2359 2380
2360void 2381void
2382maptile::gen_quadmap (int x, int y, int z)
2383 CODE:
2384 gen_quadmap (THIS, x * 50, y * 50, z);
2385
2386void
2361maptile::add_underlay (SV *data, int offset, int stride, SV *palette) 2387maptile::add_underlay (SV *data, int offset, int stride, SV *palette)
2362 CODE: 2388 CODE:
2363{ 2389{
2364 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV) 2390 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV)
2365 croak ("maptile::add_underlay: palette must be arrayref"); 2391 croak ("maptile::add_underlay: palette must be arrayref");
2381 2407
2382 if (IN_RANGE_EXC (offs, 0, idxlen)) 2408 if (IN_RANGE_EXC (offs, 0, idxlen))
2383 { 2409 {
2384 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) 2410 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0))
2385 { 2411 {
2386 object *ob = get_archetype (cfSvPVutf8_nolen (*elem)); 2412 object *ob = archetype::get (cfSvPVutf8_nolen (*elem));
2387 ob->flag [FLAG_NO_MAP_SAVE] = true; 2413 ob->flag [FLAG_NO_MAP_SAVE] = true;
2388 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); 2414 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY);
2389 2415
2390 if (ob->randomitems && !ob->above) 2416 if (ob->randomitems && !ob->above)
2391 { 2417 {
2395 op->flag [FLAG_NO_MAP_SAVE] = true; 2421 op->flag [FLAG_NO_MAP_SAVE] = true;
2396 // TODO: if this is a pickable object, then the item 2422 // TODO: if this is a pickable object, then the item
2397 // will at a bit weird - saving inside the player 2423 // will at a bit weird - saving inside the player
2398 // will clear the flag, but when the player drops 2424 // will clear the flag, but when the player drops
2399 // it without logging out, it keeps the flag. 2425 // it without logging out, it keeps the flag.
2400 // nobody ahs reported this, but this can be rather 2426 // nobody has reported this, but this can be rather
2401 // annoying on persistent maps. 2427 // annoying on persistent maps.
2402 } 2428 }
2403 } 2429 }
2404 } 2430 }
2405 } 2431 }
2406
2407 skip: ; 2432 skip: ;
2408 } 2433 }
2409} 2434}
2410 2435
2411void 2436void
2442 for (int x = 0; x < THIS->width; ++x) 2467 for (int x = 0; x < THIS->width; ++x)
2443 for (int y = 0; y < THIS->height; ++y) 2468 for (int y = 0; y < THIS->height; ++y)
2444 { 2469 {
2445 region *rgn = THIS->region (x, y); 2470 region *rgn = THIS->region (x, y);
2446 2471
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) 2472 if (object *op = THIS->at (x, y).top)
2449 if (rgn->treasure && rndm () < rgn->treasure_density) 2473 if (rgn->treasure && rndm () < rgn->treasure_density)
2450 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty); 2474 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty);
2451 } 2475 }
2452 2476
2531} 2555}
2532 OUTPUT: RETVAL 2556 OUTPUT: RETVAL
2533 2557
2534# worst xs function of my life 2558# worst xs function of my life
2535bool 2559bool
2536_create_random_map (\ 2560_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: 2561 CODE:
2577{ 2562{
2578 random_map_params rmp; 2563 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); 2564 RETVAL = self->generate_random_map (&rmp);
2620} 2565}
2621 OUTPUT: 2566 OUTPUT:
2622 RETVAL 2567 RETVAL
2623 2568
2655list () 2600list ()
2656 PPCODE: 2601 PPCODE:
2657 for_all_regions (rgn) 2602 for_all_regions (rgn)
2658 XPUSHs (sv_2mortal (to_sv (rgn))); 2603 XPUSHs (sv_2mortal (to_sv (rgn)));
2659 2604
2660region *find (utf8_string name)
2661 PROTOTYPE: $
2662 CODE:
2663 RETVAL = region::find (name);
2664 OUTPUT: RETVAL
2665
2666int specificity (region *rgn) 2605int specificity (region *rgn)
2667 CODE: 2606 CODE:
2668 RETVAL = 0; 2607 RETVAL = 0;
2669 while (rgn = rgn->parent) 2608 while (rgn = rgn->parent)
2670 RETVAL++; 2609 RETVAL++;
2698list () 2637list ()
2699 PPCODE: 2638 PPCODE:
2700 EXTEND (SP, clients.size ()); 2639 EXTEND (SP, clients.size ());
2701 for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i) 2640 for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i)
2702 PUSHs (sv_2mortal (to_sv (*i))); 2641 PUSHs (sv_2mortal (to_sv (*i)));
2642
2643STRLEN
2644client::inbuf_append (SV *data)
2645 CODE:
2646{
2647 STRLEN len;
2648 char *ptr = SvPVbyte (data, len);
2649
2650 min_it (len, sizeof (THIS->inbuf) - THIS->inbuf_len);
2651 memcpy (THIS->inbuf + THIS->inbuf_len, ptr, len);
2652 THIS->inbuf_len += len;
2653
2654 THIS->inbuf_handle ();
2655
2656 RETVAL = len;
2657}
2658 OUTPUT: RETVAL
2703 2659
2704void 2660void
2705client::send_packet (SV *packet) 2661client::send_packet (SV *packet)
2706 CODE: 2662 CODE:
2707{ 2663{
2763faceidx face_find (utf8_string name, faceidx defidx = 0) 2719faceidx face_find (utf8_string name, faceidx defidx = 0)
2764 2720
2765faceidx alloc (utf8_string name) 2721faceidx alloc (utf8_string name)
2766 CODE: 2722 CODE:
2767{ 2723{
2768 do 2724 RETVAL = face_alloc ();
2769 {
2770 RETVAL = faces.size ();
2771 faces.resize (RETVAL + 1);
2772 }
2773 while (!RETVAL); // crude way to leave index 0
2774 2725
2775 faces [RETVAL].name = name; 2726 faces [RETVAL].name = name;
2776 facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL)); 2727 facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL));
2777 2728
2778 if (!strcmp (name, BLANK_FACE_NAME )) blank_face = RETVAL; 2729 if (!strcmp (name, BLANK_FACE_NAME )) blank_face = RETVAL;
2779 if (!strcmp (name, EMPTY_FACE_NAME )) empty_face = RETVAL; 2730 if (!strcmp (name, EMPTY_FACE_NAME )) empty_face = RETVAL;
2780 if (!strcmp (name, MAGICMOUTH_FACE_NAME)) magicmouth_face = RETVAL; 2731 if (!strcmp (name, MAGICMOUTH_FACE_NAME)) magicmouth_face = RETVAL;
2781} 2732}
2733 OUTPUT: RETVAL
2734
2735faceidx faces_size ()
2736 CODE:
2737 RETVAL = faces.size ();
2782 OUTPUT: RETVAL 2738 OUTPUT: RETVAL
2783 2739
2784void set_type (faceidx idx, int value) 2740void set_type (faceidx idx, int value)
2785 ALIAS: 2741 ALIAS:
2786 set_type = 0 2742 set_type = 0
2801 2757
2802void set_data (faceidx idx, int faceset, SV *data, SV *chksum) 2758void set_data (faceidx idx, int faceset, SV *data, SV *chksum)
2803 CODE: 2759 CODE:
2804{ 2760{
2805 faceinfo *f = face_info (idx); assert (f); 2761 faceinfo *f = face_info (idx); assert (f);
2806 facedata *d = &(faceset ? f->data64 : f->data32); 2762 facedata *d = f->face + faceset;
2807 sv_to (data, d->data); 2763 sv_to (data, d->data);
2808 STRLEN clen; 2764 STRLEN clen;
2809 char *cdata = SvPVbyte (chksum, clen); 2765 char *cdata = SvPVbyte (chksum, clen);
2810 clen = min (CHKSUM_MAXLEN, clen); 2766 clen = min (CHKSUM_MAXLEN, clen);
2811 2767
2832 if (!d) XSRETURN_UNDEF; 2788 if (!d) XSRETURN_UNDEF;
2833 RETVAL = d->data.size (); 2789 RETVAL = d->data.size ();
2834 OUTPUT: 2790 OUTPUT:
2835 RETVAL 2791 RETVAL
2836 2792
2793void set_meta (faceidx idx, SV *sv)
2794 CODE:
2795{
2796 faceinfo *f = face_info (idx); assert (f);
2797 SvREFCNT_dec (f->meta_hv);
2798 f->meta_hv = SvOK (sv) ? (HV *)SvREFCNT_inc (SvRV (sv)) : 0;
2799}
2800
2837SV *get_chksum (faceidx idx, int faceset = 0) 2801SV *get_chksum (faceidx idx, int faceset = 0)
2838 CODE: 2802 CODE:
2839 facedata *d = face_data (idx, faceset); 2803 facedata *d = face_data (idx, faceset);
2840 if (!d) XSRETURN_UNDEF; 2804 if (!d) XSRETURN_UNDEF;
2841 RETVAL = newSVpvn ((char *)d->chksum, d->chksum_len); 2805 RETVAL = newSVpvn ((char *)d->chksum, d->chksum_len);
2842 OUTPUT: 2806 OUTPUT:
2843 RETVAL 2807 RETVAL
2844 2808
2809int get_type (faceidx idx)
2810 CODE:
2811 faceinfo *f = face_info (idx);
2812 if (!f) XSRETURN_UNDEF;
2813 RETVAL = f->type;
2814 OUTPUT:
2815 RETVAL
2816
2845SV *get_data (faceidx idx, int faceset = 0) 2817SV *get_data (faceidx idx, int faceset = 0)
2846 CODE: 2818 CODE:
2847 facedata *d = face_data (idx, faceset); 2819 facedata *d = face_data (idx, faceset);
2848 if (!d) XSRETURN_UNDEF; 2820 if (!d) XSRETURN_UNDEF;
2849 RETVAL = newSVpvn (d->data.data (), d->data.length ()); 2821 RETVAL = newSVpvn (d->data, d->data.size ());
2850 OUTPUT: 2822 OUTPUT:
2851 RETVAL 2823 RETVAL
2852 2824
2825SV *get_meta (faceidx idx)
2826 CODE:
2827 faceinfo *f = face_info (idx); assert (f);
2828 if (!f || !f->meta_hv) XSRETURN_UNDEF;
2829 RETVAL = newRV_inc ((SV *)f->meta_hv);
2830 OUTPUT:
2831 RETVAL
2832
2853void invalidate (faceidx idx) 2833void invalidate (faceidx idx)
2854 CODE: 2834 CODE:
2855 for_all_clients (ns) 2835 for_all_clients (ns)
2856 { 2836 ns->invalidate_face (idx);
2857 ns->faces_sent [idx] = false;
2858 ns->force_newmap = true;
2859 }
2860 2837
2861void invalidate_all () 2838void invalidate_all ()
2862 CODE: 2839 CODE:
2863 for_all_clients (ns) 2840 for_all_clients (ns)
2864 { 2841 ns->invalidate_all_faces ();
2865 ns->faces_sent.reset ();
2866 ns->force_newmap = true;
2867 }
2868 2842
2869MODULE = cf PACKAGE = cf::anim PREFIX = anim_ 2843MODULE = cf PACKAGE = cf::anim PREFIX = anim_
2870 2844
2871#INCLUDE: $PERL $srcdir/genacc faceset $srcdir/../include/anim.h | 2845#INCLUDE: $PERL $srcdir/genacc faceset $srcdir/../include/anim.h |
2872 2846
2876 OUTPUT: RETVAL 2850 OUTPUT: RETVAL
2877 2851
2878animidx set (utf8_string name, SV *frames, int facings = 1) 2852animidx set (utf8_string name, SV *frames, int facings = 1)
2879 CODE: 2853 CODE:
2880{ 2854{
2881 if (!SvROK (frames) && SvTYPE (SvRV (frames)) != SVt_PVAV) 2855 if (!SvROK (frames) && SvTYPE (SvRV (frames)) != SVt_PVAV)
2882 croak ("frames must be an arrayref"); 2856 croak ("frames must be an arrayref");
2883 2857
2884 AV *av = (AV *)SvRV (frames); 2858 AV *av = (AV *)SvRV (frames);
2885 2859
2886 animation *anim = &animation::find (name); 2860 animation *anim = &animation::find (name);
2887 if (anim->number) 2861 if (anim->number)
2888 { 2862 {
2889 anim->resize (av_len (av) + 1); 2863 anim->resize (av_len (av) + 1);
2890 anim->facings = facings; 2864 anim->facings = facings;
2891 } 2865 }
2963 XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ()))); 2937 XPUSHs (sv_2mortal (newSVpv_utf8 (self->get_str ())));
2964 2938
2965 self->skip (); 2939 self->skip ();
2966 } 2940 }
2967 2941
2942MODULE = cf PACKAGE = cf::layout
2943
2944INCLUDE: $PERL $srcdir/genacc layout $srcdir/../include/rmg.h |
2945

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines