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.391 by root, Sat Jul 3 01:49:18 2010 UTC vs.
Revision 1.409 by root, Wed Jan 4 02:48:57 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.
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
252 { 253 {
253 static int last_mortalcount; 254 static int last_mortalcount;
254 if (mortals.size () != last_mortalcount) 255 if (mortals.size () != last_mortalcount)
255 { 256 {
256 last_mortalcount = mortals.size (); 257 last_mortalcount = mortals.size ();
257 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)");
258 262
259 if (0) 263 if (0)
260 { 264 {
261 for (int j = 0; j < mortals.size (); ++j)//D 265 for (int j = 0; j < mortals.size (); ++j)//D
262 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
621 STRLEN len; 625 STRLEN len;
622 char *data = SvPVbyte (sv, len); 626 char *data = SvPVbyte (sv, len);
623 v.assign (data, len); 627 v.assign (data, len);
624} 628}
625 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;
636}
637
626static inline void sv_to (SV *sv, UUID &v) 638static inline void sv_to (SV *sv, UUID &v)
627{ 639{
628 if (!v.parse (SvPV_nolen (sv))) 640 if (!v.parse (SvPV_nolen (sv)))
629 croak ("unparsable uuid: %s", SvPV_nolen (sv)); 641 croak ("unparsable uuid: %s", SvPV_nolen (sv));
630} 642}
1403 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1); 1415 stash_cf_region_wrap = gv_stashpv ("cf::region::wrap", 1);
1404 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1); 1416 stash_cf_living_wrap = gv_stashpv ("cf::living::wrap", 1);
1405 stash_cf_layout_wrap = gv_stashpv ("cf::layout::wrap", 1); 1417 stash_cf_layout_wrap = gv_stashpv ("cf::layout::wrap", 1);
1406 stash_ext_map_world = gv_stashpv ("ext::map_world" , 1); 1418 stash_ext_map_world = gv_stashpv ("ext::map_world" , 1);
1407 1419
1408 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);
1409 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);
1410 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);
1411 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);
1412 1425
1413 cb_global = get_av ("cf::CB_GLOBAL", 1); 1426 cb_global = get_av ("cf::CB_GLOBAL", 1);
1414 cb_attachable = get_av ("cf::CB_ATTACHABLE", 1); 1427 cb_attachable = get_av ("cf::CB_ATTACHABLE", 1);
1415 cb_object = get_av ("cf::CB_OBJECT", 1); 1428 cb_object = get_av ("cf::CB_OBJECT", 1);
1416 cb_player = get_av ("cf::CB_PLAYER", 1); 1429 cb_player = get_av ("cf::CB_PLAYER", 1);
1459# include "attackinc.h" 1472# include "attackinc.h"
1460# undef def 1473# undef def
1461# define def(uc, flags) const_iv (SK_ ## uc) 1474# define def(uc, flags) const_iv (SK_ ## uc)
1462# include "skillinc.h" 1475# include "skillinc.h"
1463# undef def 1476# undef def
1464 1477# define def(name, use, nonuse) const_iv (body_ ## name)
1465 const_iv (Map0Cmd) const_iv (Map1Cmd) const_iv (Map1aCmd) 1478# include "slotinc.h"
1479# undef def
1466 1480
1467 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y) 1481 const_iv (MAP_CLIENT_X) const_iv (MAP_CLIENT_Y)
1468 1482
1469 const_iv (MAX_TIME) 1483 const_iv (MAX_TIME)
1470 const_iv (MAXSOCKBUF) 1484 const_iv (MAXSOCKBUF)
1483 1497
1484 const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE) 1498 const_iv (SAVE_MODE) const_iv (SAVE_DIR_MODE)
1485 1499
1486 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)
1487 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)
1488
1489 const_iv (MAP_ACTIVE) const_iv (MAP_SWAPPED) const_iv (MAP_LOADING) const_iv (MAP_SAVING)
1490 const_iv (MAP_INACTIVE)
1491 1502
1492 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)
1493 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)
1494 1505
1495 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)
1556 1567
1557 for_all_objects (op) 1568 for_all_objects (op)
1558 op->reattach (); 1569 op->reattach ();
1559} 1570}
1560 1571
1561# support function for map-world.ext
1562void _quantise (SV *data_sv, SV *plt_sv)
1563 CODE:
1564{
1565 if (!SvROK (plt_sv) || SvTYPE (SvRV (plt_sv)) != SVt_PVAV)
1566 croak ("_quantise called with invalid agruments");
1567
1568 plt_sv = SvRV (plt_sv);
1569 SV **plt = AvARRAY (plt_sv);
1570 int plt_count = AvFILL (plt_sv) + 1;
1571
1572 STRLEN len;
1573 char *data = SvPVbyte (data_sv, len);
1574 char *dst = data;
1575
1576 while (len >= 3)
1577 {
1578 for (SV **val_sv = plt + plt_count; val_sv-- > plt; )
1579 {
1580 char *val = SvPVX (*val_sv);
1581
1582 if (val [0] == data [0]
1583 && val [1] == data [1]
1584 && val [2] == data [2])
1585 {
1586 *dst++ = val [3];
1587 goto next;
1588 }
1589 }
1590
1591 croak ("_quantise: color not found in palette: #%02x%02x%02x, at offset %d %d",
1592 (uint8_t)data [0], (uint8_t)data [1], (uint8_t)data [2],
1593 dst - SvPVX (data_sv), len);
1594
1595 next:
1596 data += 3;
1597 len -= 3;
1598 }
1599
1600 SvCUR_set (data_sv, dst - SvPVX (data_sv));
1601}
1602
1603void init_anim () 1572void init_anim ()
1604 1573
1605void init_globals () 1574void init_globals ()
1606 1575
1607void init_attackmess () 1576void init_attackmess ()
1653 { 1622 {
1654 ev_async_send (EV_DEFAULT, &tick_watcher); 1623 ev_async_send (EV_DEFAULT, &tick_watcher);
1655 coroapi::cede (); 1624 coroapi::cede ();
1656 } 1625 }
1657 1626
1658void server_tick () 1627void one_tick ()
1659 CODE: 1628 CODE:
1660{ 1629{
1661 ev_now_update (EV_DEFAULT); 1630 ev_now_update (EV_DEFAULT);
1662 NOW = ev_now (EV_DEFAULT); 1631 NOW = ev_now (EV_DEFAULT);
1663 SvNV_set (sv_now, NOW); SvNOK_only (sv_now); 1632 SvNV_set (sv_now, NOW); SvNOK_only (sv_now);
1664 SvNV_set (sv_tick_start, NOW); SvNOK_only (sv_tick_start); 1633 SvNV_set (sv_tick_start, NOW); SvNOK_only (sv_tick_start);
1665 runtime = SvNVX (sv_runtime); 1634 runtime = SvNVX (sv_runtime);
1666 1635
1636 one_tick ();
1637
1667 server_tick (); 1638 ++server_tick;
1639 SvUV_set (sv_server_tick, server_tick); SvIOK_only_UV (sv_server_tick);
1668 1640
1669 ev_now_update (EV_DEFAULT); 1641 ev_now_update (EV_DEFAULT);
1670 NOW = ev_now (EV_DEFAULT); 1642 NOW = ev_now (EV_DEFAULT);
1671 SvNV_set (sv_now, NOW); SvNOK_only (sv_now); 1643 SvNV_set (sv_now, NOW); SvNOK_only (sv_now);
1644
1672 runtime += TICK; 1645 runtime += TICK;
1673 SvNV_set (sv_runtime, runtime); SvNOK_only (sv_runtime); 1646 SvNV_set (sv_runtime, runtime); SvNOK_only (sv_runtime);
1674} 1647}
1675 1648
1676NV floor (NV x) 1649NV floor (NV x)
1775 1748
1776int mlockall (int flags = MCL_CURRENT | MCL_FUTURE) 1749int mlockall (int flags = MCL_CURRENT | MCL_FUTURE)
1777 INIT: 1750 INIT:
1778#if __GLIBC__ 1751#if __GLIBC__
1779 mallopt (M_TOP_PAD, 1024 * 1024); 1752 mallopt (M_TOP_PAD, 1024 * 1024);
1780 mallopt (M_MMAP_THRESHOLD, 1024 * 1024 * 128); 1753 mallopt (M_MMAP_THRESHOLD, 1024 * 1024);
1781 mallopt (M_MMAP_MAX, 0); // likely bug-workaround, also frees memory 1754 mallopt (M_MMAP_MAX, 0); // likely bug-workaround, also frees memory
1755 if (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 10))
1782 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc 1756 mallopt (M_PERTURB, 0xee); // bug-workaround for linux glibc+mlockall+calloc
1783#endif 1757#endif
1784 1758
1785int munlockall () 1759int munlockall ()
1786 1760
1787#endif 1761#endif
1825int exp_to_level (val64 exp) 1799int exp_to_level (val64 exp)
1826 1800
1827val64 level_to_min_exp (int level) 1801val64 level_to_min_exp (int level)
1828 1802
1829SV * 1803SV *
1830resistance_to_string (int atnr) 1804attacktype_name (int atnr)
1831 CODE: 1805 CODE:
1832 if (atnr >= 0 && atnr < NROFATTACKS) 1806 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1807 ? newSVpv (attacktype_name [atnr], 0)
1808 : &PL_sv_undef;
1809 OUTPUT: RETVAL
1810
1811SV *
1812attacktype_desc (int atnr)
1813 CODE:
1814 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1815 ? newSVpv (attacktype_desc [atnr], 0)
1816 : &PL_sv_undef;
1817 OUTPUT: RETVAL
1818
1819SV *
1820resist_plus (int atnr)
1821 CODE:
1822 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1833 RETVAL = newSVpv (resist_plus[atnr], 0); 1823 ? newSVpv (resist_plus [atnr], 0)
1834 else 1824 : &PL_sv_undef;
1835 XSRETURN_UNDEF; 1825 OUTPUT: RETVAL
1826
1827SV *
1828change_resist_msg (int atnr)
1829 CODE:
1830 RETVAL = IN_RANGE_EXC (atnr, 0, NROFATTACKS)
1831 ? newSVpv (change_resist_msg [atnr], 0)
1832 : &PL_sv_undef;
1836 OUTPUT: RETVAL 1833 OUTPUT: RETVAL
1837 1834
1838UUID 1835UUID
1839uuid_cur () 1836uuid_cur ()
1840 CODE: 1837 CODE:
1963int mortals_size () 1960int mortals_size ()
1964 CODE: 1961 CODE:
1965 RETVAL = attachable::mortals.size (); 1962 RETVAL = attachable::mortals.size ();
1966 OUTPUT: RETVAL 1963 OUTPUT: RETVAL
1967 1964
1968const_utf8_string slot_use_name (U32 slot) 1965const_utf8_string slot_name (U32 slot)
1969 ALIAS: 1966 ALIAS:
1967 slot_name = 0
1968 slot_use_name = 1
1970 slot_nonuse_name = 1 1969 slot_nonuse_name = 2
1971 CODE: 1970 CODE:
1972{ 1971{
1973 if (slot >= NUM_BODY_LOCATIONS) 1972 if (slot >= NUM_BODY_LOCATIONS)
1974 croak ("body slot index out of range"); 1973 croak ("body slot index out of range");
1975 1974
1976 switch (ix) 1975 switch (ix)
1977 { 1976 {
1977 case 0: RETVAL = body_locations[slot].name ; break;
1978 case 0: RETVAL = body_locations[slot].use_name; break; 1978 case 1: RETVAL = body_locations[slot].use_name ; break;
1979 case 1: RETVAL = body_locations[slot].nonuse_name; break; 1979 case 2: RETVAL = body_locations[slot].nonuse_name; break;
1980 } 1980 }
1981} 1981}
1982 OUTPUT: 1982 OUTPUT:
1983 RETVAL 1983 RETVAL
1984 1984
2116# dumb kludgy misdesigned plug-in api slowly gets on my nerves. 2116# dumb kludgy misdesigned plug-in api slowly gets on my nerves.
2117 2117
2118object *new (utf8_string archetype = 0) 2118object *new (utf8_string archetype = 0)
2119 PROTOTYPE: ;$ 2119 PROTOTYPE: ;$
2120 CODE: 2120 CODE:
2121 RETVAL = archetype ? get_archetype (archetype) : object::create (); 2121 RETVAL = archetype
2122 ? archetype::get (archetype)
2123 : object::create ();
2122 OUTPUT: 2124 OUTPUT:
2123 RETVAL 2125 RETVAL
2124 2126
2125object *generate (utf8_string arch, object *creator) 2127object *generate (utf8_string arch, object *creator)
2126 CODE: 2128 CODE:
2127 object *obj = get_archetype (arch); 2129 object *obj = archetype::get (arch);
2128 fix_generated_item (obj, creator, 0, 0, GT_MINIMAL); 2130 fix_generated_item (obj, creator, 0, 0, GT_MINIMAL);
2129 RETVAL = obj; 2131 RETVAL = obj;
2130 OUTPUT: 2132 OUTPUT:
2131 RETVAL 2133 RETVAL
2132 2134
2142 RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y); 2144 RETVAL = insert_ob_in_map_at (ob, where, orig, flag, x, y);
2143 2145
2144 if (RETVAL->destroyed ()) 2146 if (RETVAL->destroyed ())
2145 RETVAL = 0; 2147 RETVAL = 0;
2146} 2148}
2149 OUTPUT:
2150 RETVAL
2147 2151
2148shstr 2152shstr
2149object::kv_get (shstr key) 2153object::kv_get (shstr key)
2154 CODE:
2155 RETVAL = THIS->kv.get (key);
2156 OUTPUT:
2157 RETVAL
2150 2158
2151void 2159void
2152object::kv_del (shstr key) 2160object::kv_del (shstr key)
2161 CODE:
2162 THIS->kv.del (key);
2153 2163
2154void 2164void
2155object::kv_set (shstr key, shstr value) 2165object::kv_set (shstr key, shstr value)
2166 CODE:
2167 THIS->kv.set (key, value);
2156 2168
2157object *get_nearest_player (object *ob) 2169object *get_nearest_player (object *ob)
2158 ALIAS: nearest_player = 0 2170 ALIAS: nearest_player = 0
2159 PREINIT: 2171 PREINIT:
2160 extern object *get_nearest_player (object *); 2172 extern object *get_nearest_player (object *);
2363 if (pl->ob && pl->ob->map == THIS) 2375 if (pl->ob && pl->ob->map == THIS)
2364 PUSHs (sv_2mortal (to_sv (pl->ob))); 2376 PUSHs (sv_2mortal (to_sv (pl->ob)));
2365 } 2377 }
2366 2378
2367void 2379void
2380maptile::gen_quadmap (int x, int y, int z)
2381 CODE:
2382 gen_quadmap (THIS, x * 50, y * 50, z);
2383
2384void
2368maptile::add_underlay (SV *data, int offset, int stride, SV *palette) 2385maptile::add_underlay (SV *data, int offset, int stride, SV *palette)
2369 CODE: 2386 CODE:
2370{ 2387{
2371 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV) 2388 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV)
2372 croak ("maptile::add_underlay: palette must be arrayref"); 2389 croak ("maptile::add_underlay: palette must be arrayref");
2388 2405
2389 if (IN_RANGE_EXC (offs, 0, idxlen)) 2406 if (IN_RANGE_EXC (offs, 0, idxlen))
2390 { 2407 {
2391 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0)) 2408 if (SV **elem = av_fetch ((AV *)palette, idx [offs], 0))
2392 { 2409 {
2393 object *ob = get_archetype (cfSvPVutf8_nolen (*elem)); 2410 object *ob = archetype::get (cfSvPVutf8_nolen (*elem));
2394 ob->flag [FLAG_NO_MAP_SAVE] = true; 2411 ob->flag [FLAG_NO_MAP_SAVE] = true;
2395 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY); 2412 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY);
2396 2413
2397 if (ob->randomitems && !ob->above) 2414 if (ob->randomitems && !ob->above)
2398 { 2415 {
2402 op->flag [FLAG_NO_MAP_SAVE] = true; 2419 op->flag [FLAG_NO_MAP_SAVE] = true;
2403 // TODO: if this is a pickable object, then the item 2420 // TODO: if this is a pickable object, then the item
2404 // will at a bit weird - saving inside the player 2421 // will at a bit weird - saving inside the player
2405 // will clear the flag, but when the player drops 2422 // will clear the flag, but when the player drops
2406 // it without logging out, it keeps the flag. 2423 // it without logging out, it keeps the flag.
2407 // nobody ahs reported this, but this can be rather 2424 // nobody has reported this, but this can be rather
2408 // annoying on persistent maps. 2425 // annoying on persistent maps.
2409 } 2426 }
2410 } 2427 }
2411 } 2428 }
2412 } 2429 }
2413
2414 skip: ; 2430 skip: ;
2415 } 2431 }
2416} 2432}
2417 2433
2418void 2434void
2449 for (int x = 0; x < THIS->width; ++x) 2465 for (int x = 0; x < THIS->width; ++x)
2450 for (int y = 0; y < THIS->height; ++y) 2466 for (int y = 0; y < THIS->height; ++y)
2451 { 2467 {
2452 region *rgn = THIS->region (x, y); 2468 region *rgn = THIS->region (x, y);
2453 2469
2454 //fprintf (stderr, "%d,%d %f %p\n", x, y, rgn->treasure_density,rgn->treasure);//D
2455 if (object *op = THIS->at (x, y).top) 2470 if (object *op = THIS->at (x, y).top)
2456 if (rgn->treasure && rndm () < rgn->treasure_density) 2471 if (rgn->treasure && rndm () < rgn->treasure_density)
2457 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty); 2472 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty);
2458 } 2473 }
2459 2474
2685faceidx face_find (utf8_string name, faceidx defidx = 0) 2700faceidx face_find (utf8_string name, faceidx defidx = 0)
2686 2701
2687faceidx alloc (utf8_string name) 2702faceidx alloc (utf8_string name)
2688 CODE: 2703 CODE:
2689{ 2704{
2690 do 2705 RETVAL = face_alloc ();
2691 {
2692 RETVAL = faces.size ();
2693 faces.resize (RETVAL + 1);
2694 }
2695 while (!RETVAL); // crude way to leave index 0
2696 2706
2697 faces [RETVAL].name = name; 2707 faces [RETVAL].name = name;
2698 facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL)); 2708 facehash.insert (std::make_pair (faces [RETVAL].name, RETVAL));
2699 2709
2700 if (!strcmp (name, BLANK_FACE_NAME )) blank_face = RETVAL; 2710 if (!strcmp (name, BLANK_FACE_NAME )) blank_face = RETVAL;
2723 2733
2724void set_data (faceidx idx, int faceset, SV *data, SV *chksum) 2734void set_data (faceidx idx, int faceset, SV *data, SV *chksum)
2725 CODE: 2735 CODE:
2726{ 2736{
2727 faceinfo *f = face_info (idx); assert (f); 2737 faceinfo *f = face_info (idx); assert (f);
2728 facedata *d = &(faceset ? f->data64 : f->data32); 2738 facedata *d = f->face + faceset;
2729 sv_to (data, d->data); 2739 sv_to (data, d->data);
2730 STRLEN clen; 2740 STRLEN clen;
2731 char *cdata = SvPVbyte (chksum, clen); 2741 char *cdata = SvPVbyte (chksum, clen);
2732 clen = min (CHKSUM_MAXLEN, clen); 2742 clen = min (CHKSUM_MAXLEN, clen);
2733 2743
2754 if (!d) XSRETURN_UNDEF; 2764 if (!d) XSRETURN_UNDEF;
2755 RETVAL = d->data.size (); 2765 RETVAL = d->data.size ();
2756 OUTPUT: 2766 OUTPUT:
2757 RETVAL 2767 RETVAL
2758 2768
2769void set_meta (faceidx idx, SV *sv)
2770 CODE:
2771{
2772 faceinfo *f = face_info (idx); assert (f);
2773 SvREFCNT_dec (f->meta_hv);
2774 f->meta_hv = SvOK (sv) ? (HV *)SvREFCNT_inc (SvRV (sv)) : 0;
2775}
2776
2759SV *get_chksum (faceidx idx, int faceset = 0) 2777SV *get_chksum (faceidx idx, int faceset = 0)
2760 CODE: 2778 CODE:
2761 facedata *d = face_data (idx, faceset); 2779 facedata *d = face_data (idx, faceset);
2762 if (!d) XSRETURN_UNDEF; 2780 if (!d) XSRETURN_UNDEF;
2763 RETVAL = newSVpvn ((char *)d->chksum, d->chksum_len); 2781 RETVAL = newSVpvn ((char *)d->chksum, d->chksum_len);
2766 2784
2767SV *get_data (faceidx idx, int faceset = 0) 2785SV *get_data (faceidx idx, int faceset = 0)
2768 CODE: 2786 CODE:
2769 facedata *d = face_data (idx, faceset); 2787 facedata *d = face_data (idx, faceset);
2770 if (!d) XSRETURN_UNDEF; 2788 if (!d) XSRETURN_UNDEF;
2771 RETVAL = newSVpvn (d->data.data (), d->data.length ()); 2789 RETVAL = newSVpvn (d->data, d->data.size ());
2772 OUTPUT: 2790 OUTPUT:
2773 RETVAL 2791 RETVAL
2774 2792
2793SV *get_meta (faceidx idx)
2794 CODE:
2795 faceinfo *f = face_info (idx); assert (f);
2796 if (!f || !f->meta_hv) XSRETURN_UNDEF;
2797 RETVAL = newRV_inc ((SV *)f->meta_hv);
2798 OUTPUT:
2799 RETVAL
2800
2775void invalidate (faceidx idx) 2801void invalidate (faceidx idx)
2776 CODE: 2802 CODE:
2777 for_all_clients (ns) 2803 for_all_clients (ns)
2778 { 2804 ns->invalidate_face (idx);
2779 ns->faces_sent [idx] = false;
2780 ns->force_newmap = true;
2781 }
2782 2805
2783void invalidate_all () 2806void invalidate_all ()
2784 CODE: 2807 CODE:
2785 for_all_clients (ns) 2808 for_all_clients (ns)
2786 { 2809 ns->invalidate_all_faces ();
2787 ns->faces_sent.reset ();
2788 ns->force_newmap = true;
2789 }
2790 2810
2791MODULE = cf PACKAGE = cf::anim PREFIX = anim_ 2811MODULE = cf PACKAGE = cf::anim PREFIX = anim_
2792 2812
2793#INCLUDE: $PERL $srcdir/genacc faceset $srcdir/../include/anim.h | 2813#INCLUDE: $PERL $srcdir/genacc faceset $srcdir/../include/anim.h |
2794 2814
2887 self->skip (); 2907 self->skip ();
2888 } 2908 }
2889 2909
2890MODULE = cf PACKAGE = cf::layout 2910MODULE = cf PACKAGE = cf::layout
2891 2911
2892INCLUDE: $PERL $srcdir/genacc layout $srcdir/../random_maps/random_map.h | 2912INCLUDE: $PERL $srcdir/genacc layout $srcdir/../include/rmg.h |
2893 2913

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines