… | |
… | |
246 | delete obj; |
246 | delete obj; |
247 | } |
247 | } |
248 | } |
248 | } |
249 | } |
249 | } |
250 | |
250 | |
|
|
251 | void |
|
|
252 | attachable::set_key (const char *key, const char *value) |
|
|
253 | { |
|
|
254 | if (!self) |
|
|
255 | self = newHV (); |
|
|
256 | |
|
|
257 | if (value) |
|
|
258 | hv_store (self, key, strlen (key), newSVpv (value, 0), 0); |
|
|
259 | else |
|
|
260 | hv_delete (self, key, strlen (key), G_DISCARD); |
|
|
261 | } |
|
|
262 | |
251 | attachable & |
263 | attachable & |
252 | attachable::operator =(const attachable &src) |
264 | attachable::operator =(const attachable &src) |
253 | { |
265 | { |
254 | //if (self || cb) |
266 | //if (self || cb) |
255 | //INVOKE_OBJECT (CLONE, this, ARG_OBJECT (dst)); |
267 | //INVOKE_OBJECT (CLONE, this, ARG_OBJECT (dst)); |
… | |
… | |
330 | { |
342 | { |
331 | if (!obj) |
343 | if (!obj) |
332 | return &PL_sv_undef; |
344 | return &PL_sv_undef; |
333 | |
345 | |
334 | if (!obj->self) |
346 | if (!obj->self) |
|
|
347 | obj->self = newHV (); |
|
|
348 | |
|
|
349 | if (!SvOBJECT (obj->self)) |
335 | { |
350 | { |
336 | obj->self = newHV (); |
|
|
337 | sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &attachable::vtbl, (char *)obj, 0); |
351 | sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &attachable::vtbl, (char *)obj, 0); |
338 | |
352 | |
339 | // now bless the object _once_ |
353 | // now bless the object _once_ |
|
|
354 | //TODO: create a class registry with c++ type<=>perl name<=>stash and use it here and elsewhere |
340 | return sv_bless (newRV_inc ((SV *)obj->self), stash); |
355 | return sv_bless (newRV_inc ((SV *)obj->self), stash); |
341 | } |
356 | } |
342 | else |
357 | else |
343 | { |
358 | { |
344 | SV *sv = newRV_inc ((SV *)obj->self); |
359 | SV *sv = newRV_inc ((SV *)obj->self); |
… | |
… | |
417 | inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); } |
432 | inline SV *to_sv (client * v) { return newSVattachable (v, stash_cf_client_wrap); } |
418 | inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); } |
433 | inline SV *to_sv (player * v) { return newSVattachable (v, stash_cf_player_wrap); } |
419 | inline SV *to_sv (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); } |
434 | inline SV *to_sv (object * v) { return newSVattachable (v, v && v->type == PLAYER ? stash_cf_object_player_wrap : stash_cf_object_wrap); } |
420 | inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); } |
435 | inline SV *to_sv (maptile * v) { return newSVattachable (v, stash_cf_map_wrap); } |
421 | inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); } |
436 | inline SV *to_sv (archetype * v) { return newSVattachable (v, stash_cf_arch_wrap); } |
|
|
437 | inline SV *to_sv (region * v) { return newSVattachable (v, stash_cf_region_wrap); } |
422 | inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); } |
438 | inline SV *to_sv (partylist * v) { return newSVptr (v, stash_cf_party_wrap); } |
423 | inline SV *to_sv (region * v) { return newSVptr (v, stash_cf_region_wrap); } |
|
|
424 | inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } |
439 | inline SV *to_sv (living * v) { return newSVptr (v, stash_cf_living_wrap); } |
425 | |
440 | |
426 | inline SV *to_sv (object & v) { return to_sv (&v); } |
441 | inline SV *to_sv (object & v) { return to_sv (&v); } |
427 | inline SV *to_sv (living & v) { return to_sv (&v); } |
442 | inline SV *to_sv (living & v) { return to_sv (&v); } |
428 | |
443 | |
… | |
… | |
454 | inline void sv_to (SV *sv, client * &v) { v = (client *)(attachable *)SvPTR_ornull (sv, "cf::client"); } |
469 | inline void sv_to (SV *sv, client * &v) { v = (client *)(attachable *)SvPTR_ornull (sv, "cf::client"); } |
455 | inline void sv_to (SV *sv, player * &v) { v = (player *)(attachable *)SvPTR_ornull (sv, "cf::player"); } |
470 | inline void sv_to (SV *sv, player * &v) { v = (player *)(attachable *)SvPTR_ornull (sv, "cf::player"); } |
456 | inline void sv_to (SV *sv, object * &v) { v = (object *)(attachable *)SvPTR_ornull (sv, "cf::object"); } |
471 | inline void sv_to (SV *sv, object * &v) { v = (object *)(attachable *)SvPTR_ornull (sv, "cf::object"); } |
457 | inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)(attachable *)SvPTR_ornull (sv, "cf::arch"); } |
472 | inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)(attachable *)SvPTR_ornull (sv, "cf::arch"); } |
458 | inline void sv_to (SV *sv, maptile * &v) { v = (maptile *)(attachable *)SvPTR_ornull (sv, "cf::map"); } |
473 | inline void sv_to (SV *sv, maptile * &v) { v = (maptile *)(attachable *)SvPTR_ornull (sv, "cf::map"); } |
|
|
474 | inline void sv_to (SV *sv, region * &v) { v = (region *)(attachable *)SvPTR_ornull (sv, "cf::region"); } |
459 | inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } |
475 | inline void sv_to (SV *sv, attachable * &v) { v = (attachable *)SvPTR_ornull (sv, "cf::attachable"); } |
460 | inline void sv_to (SV *sv, partylist * &v) { v = (partylist *)SvPTR_ornull (sv, "cf::party"); } |
476 | inline void sv_to (SV *sv, partylist * &v) { v = (partylist *)SvPTR_ornull (sv, "cf::party"); } |
461 | inline void sv_to (SV *sv, region * &v) { v = (region *)SvPTR_ornull (sv, "cf::region"); } |
|
|
462 | inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); } |
477 | inline void sv_to (SV *sv, living * &v) { v = (living *)SvPTR_ornull (sv, "cf::living"); } |
463 | |
478 | |
464 | //inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; } |
479 | //inline void sv_to (SV *sv, faceinfo * &v) { v = &faces [face_find (SvPV_nolen (sv), 0)]; } |
465 | inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); } |
480 | inline void sv_to (SV *sv, treasurelist * &v) { v = treasurelist::find (SvPV_nolen (sv)); } |
466 | |
481 | |
… | |
… | |
949 | } |
964 | } |
950 | |
965 | |
951 | SV * |
966 | SV * |
952 | cfperl_result (int idx) |
967 | cfperl_result (int idx) |
953 | { |
968 | { |
954 | AV *av = get_av ("cfperl::invoke_results", 0); |
969 | AV *av = get_av ("cf::INVOKE_RESULTS", 0); |
955 | if (!av) |
970 | if (!av) |
956 | return &PL_sv_undef; |
971 | return &PL_sv_undef; |
957 | |
972 | |
958 | SV **sv = av_fetch (av, idx, 0); |
973 | SV **sv = av_fetch (av, idx, 0); |
959 | if (!sv) |
974 | if (!sv) |
… | |
… | |
1006 | void |
1021 | void |
1007 | cfperl_send_msg (client *ns, int color, const char *type, const char *msg) |
1022 | cfperl_send_msg (client *ns, int color, const char *type, const char *msg) |
1008 | { |
1023 | { |
1009 | CALL_BEGIN (4); |
1024 | CALL_BEGIN (4); |
1010 | CALL_ARG (ns); |
1025 | CALL_ARG (ns); |
1011 | CALL_ARG (color); |
|
|
1012 | CALL_ARG (type); |
1026 | CALL_ARG (type); |
1013 | CALL_ARG_SV (newSVpv_utf8 (msg)); |
1027 | CALL_ARG_SV (newSVpv_utf8 (msg)); |
|
|
1028 | CALL_ARG (color); |
1014 | CALL_CALL ("cf::client::send_msg", G_VOID); |
1029 | CALL_CALL ("cf::client::send_msg", G_VOID); |
1015 | CALL_END; |
1030 | CALL_END; |
|
|
1031 | } |
|
|
1032 | |
|
|
1033 | int |
|
|
1034 | cfperl_can_merge (object *ob1, object *ob2) |
|
|
1035 | { |
|
|
1036 | int can; |
|
|
1037 | |
|
|
1038 | CALL_BEGIN (2); |
|
|
1039 | CALL_ARG (ob1); |
|
|
1040 | CALL_ARG (ob2); |
|
|
1041 | CALL_CALL ("cf::_can_merge", G_SCALAR); |
|
|
1042 | can = count && SvTRUE (TOPs); |
|
|
1043 | CALL_END; |
|
|
1044 | |
|
|
1045 | return can; |
1016 | } |
1046 | } |
1017 | |
1047 | |
1018 | maptile * |
1048 | maptile * |
1019 | maptile::find_sync (const char *path, maptile *origin) |
1049 | maptile::find_sync (const char *path, maptile *origin) |
1020 | { |
1050 | { |
… | |
… | |
1491 | const_iv (SYMMETRY_Y) const_iv (SYMMETRY_XY) |
1521 | const_iv (SYMMETRY_Y) const_iv (SYMMETRY_XY) |
1492 | |
1522 | |
1493 | const_iv (GT_ENVIRONMENT) const_iv (GT_INVISIBLE) const_iv (GT_STARTEQUIP) |
1523 | const_iv (GT_ENVIRONMENT) const_iv (GT_INVISIBLE) const_iv (GT_STARTEQUIP) |
1494 | const_iv (GT_APPLY) const_iv (GT_ONLY_GOOD) const_iv (GT_UPDATE_INV) |
1524 | const_iv (GT_APPLY) const_iv (GT_ONLY_GOOD) const_iv (GT_UPDATE_INV) |
1495 | const_iv (GT_MINIMAL) |
1525 | const_iv (GT_MINIMAL) |
|
|
1526 | |
|
|
1527 | const_iv (FT_FACE) const_iv (FT_MUSIC) const_iv (FT_SOUND) |
|
|
1528 | const_iv (FT_RSRC) const_iv (FT_NUM) |
1496 | }; |
1529 | }; |
1497 | |
1530 | |
1498 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
1531 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
1499 | newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv)); |
1532 | newCONSTSUB (stash_cf, (char *)civ->name, newSViv (civ->iv)); |
1500 | |
1533 | |
… | |
… | |
1534 | |
1567 | |
1535 | for_all_objects (op) |
1568 | for_all_objects (op) |
1536 | op->reattach (); |
1569 | op->reattach (); |
1537 | } |
1570 | } |
1538 | |
1571 | |
1539 | void _post_tick () |
|
|
1540 | CODE: |
|
|
1541 | coroapi::next_cede = SvNV (sv_next_tick) - TICK * (1. - 1. / CEDES_PER_TICK); |
|
|
1542 | |
|
|
1543 | # support function for map-world.ext |
1572 | # support function for map-world.ext |
1544 | void _quantise (SV *data_sv, SV *plt_sv) |
1573 | void _quantise (SV *data_sv, SV *plt_sv) |
1545 | CODE: |
1574 | CODE: |
1546 | { |
1575 | { |
1547 | if (!SvROK (plt_sv) || SvTYPE (SvRV (plt_sv)) != SVt_PVAV) |
1576 | if (!SvROK (plt_sv) || SvTYPE (SvRV (plt_sv)) != SVt_PVAV) |
… | |
… | |
1579 | len -= 3; |
1608 | len -= 3; |
1580 | } |
1609 | } |
1581 | |
1610 | |
1582 | SvCUR_set (data_sv, dst - SvPVX (data_sv)); |
1611 | SvCUR_set (data_sv, dst - SvPVX (data_sv)); |
1583 | } |
1612 | } |
|
|
1613 | |
|
|
1614 | void _post_tick () |
|
|
1615 | CODE: |
|
|
1616 | coroapi::next_cede = SvNV (sv_next_tick) - TICK * (1. - 1. / CEDES_PER_TICK); |
|
|
1617 | |
|
|
1618 | NV till_cede () |
|
|
1619 | CODE: |
|
|
1620 | RETVAL = coroapi::next_cede - now (); |
|
|
1621 | OUTPUT: |
|
|
1622 | RETVAL |
|
|
1623 | |
|
|
1624 | NV till_tick () |
|
|
1625 | CODE: |
|
|
1626 | RETVAL = SvNV (sv_next_tick) - now (); |
|
|
1627 | OUTPUT: |
|
|
1628 | RETVAL |
1584 | |
1629 | |
1585 | NV floor (NV x) |
1630 | NV floor (NV x) |
1586 | |
1631 | |
1587 | NV ceil (NV x) |
1632 | NV ceil (NV x) |
1588 | |
1633 | |
… | |
… | |
1994 | |
2039 | |
1995 | void add_button_link (object *button, maptile *map, int connected); |
2040 | void add_button_link (object *button, maptile *map, int connected); |
1996 | |
2041 | |
1997 | void remove_button_link (object *op); |
2042 | void remove_button_link (object *op); |
1998 | |
2043 | |
|
|
2044 | void handle_apply_yield (object *op); |
|
|
2045 | |
1999 | |
2046 | |
2000 | MODULE = cf PACKAGE = cf::object PREFIX = cf_ |
2047 | MODULE = cf PACKAGE = cf::object PREFIX = cf_ |
2001 | |
2048 | |
2002 | object *cf_insert_ob_in_ob (object *ob, object *where) |
2049 | object *cf_insert_ob_in_ob (object *ob, object *where) |
2003 | |
2050 | |
… | |
… | |
2254 | palette = SvRV (palette); |
2301 | palette = SvRV (palette); |
2255 | |
2302 | |
2256 | STRLEN idxlen; |
2303 | STRLEN idxlen; |
2257 | const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen); |
2304 | const uint8_t *idx = (const uint8_t *)SvPVbyte (data, idxlen); |
2258 | |
2305 | |
2259 | region **regionmap = (region **)malloc ( |
2306 | region_ptr *regionmap = new region_ptr [av_len ((AV *)palette) + 1]; |
2260 | (av_len ((AV *)palette) + 1) * sizeof (region *)); |
|
|
2261 | uint8_t *regions = salloc<uint8_t> (THIS->size ()); |
2307 | uint8_t *regions = salloc<uint8_t> (THIS->size ()); |
2262 | |
2308 | |
2263 | for (int i = av_len ((AV *)palette) + 1; i--; ) |
2309 | for (int i = av_len ((AV *)palette) + 1; i--; ) |
2264 | regionmap [i] = region::find ( |
2310 | regionmap [i] = region::find (SvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1))); |
2265 | SvPVutf8_nolen (*av_fetch ((AV *)palette, i, 1))); |
|
|
2266 | |
2311 | |
2267 | for (int y = 0; y < THIS->height; ++y) |
2312 | for (int y = 0; y < THIS->height; ++y) |
2268 | memcpy (regions + y * THIS->width, idx + offset + y * stride, THIS->width); |
2313 | memcpy (regions + y * THIS->width, idx + offset + y * stride, THIS->width); |
2269 | |
2314 | |
2270 | sfree (THIS->regions, THIS->size ()); |
2315 | sfree (THIS->regions, THIS->size ()); |
2271 | free (THIS->regionmap); |
2316 | delete [] THIS->regionmap; |
2272 | |
2317 | |
2273 | THIS->regions = regions; |
2318 | THIS->regions = regions; |
2274 | THIS->regionmap = regionmap; |
2319 | THIS->regionmap = regionmap; |
2275 | } |
2320 | } |
2276 | |
2321 | |
… | |
… | |
2579 | char *buf = SvPVbyte (packet, len); |
2624 | char *buf = SvPVbyte (packet, len); |
2580 | |
2625 | |
2581 | THIS->send_packet (buf, len); |
2626 | THIS->send_packet (buf, len); |
2582 | } |
2627 | } |
2583 | |
2628 | |
|
|
2629 | faceidx |
|
|
2630 | client::need_face (utf8_string name, int pri = 0) |
|
|
2631 | CODE: |
|
|
2632 | RETVAL = face_find (name, 0); |
|
|
2633 | if (RETVAL) |
|
|
2634 | { |
|
|
2635 | THIS->send_face (RETVAL, pri); |
|
|
2636 | THIS->flush_fx (); |
|
|
2637 | } |
|
|
2638 | OUTPUT: |
|
|
2639 | RETVAL |
|
|
2640 | |
|
|
2641 | int |
|
|
2642 | client::fx_want (int idx, int value = -1) |
|
|
2643 | CODE: |
|
|
2644 | if (0 < idx && idx < FT_NUM) |
|
|
2645 | { |
|
|
2646 | RETVAL = THIS->fx_want [idx]; |
|
|
2647 | if (items > 2) |
|
|
2648 | THIS->fx_want [idx] = value; |
|
|
2649 | } |
|
|
2650 | else |
|
|
2651 | RETVAL = 0; |
|
|
2652 | OUTPUT: |
|
|
2653 | RETVAL |
|
|
2654 | |
2584 | MODULE = cf PACKAGE = cf::face PREFIX = face_ |
2655 | MODULE = cf PACKAGE = cf::face PREFIX = face_ |
2585 | |
2656 | |
2586 | #INCLUDE: $PERL $srcdir/genacc faceset ../include/face.h | |
2657 | #INCLUDE: $PERL $srcdir/genacc faceset ../include/face.h | |
2587 | |
2658 | |
2588 | faceidx face_find (utf8_string name, faceidx defidx = 0) |
2659 | faceidx face_find (utf8_string name, faceidx defidx = 0) |
… | |
… | |
2611 | set_visibility = 1 |
2682 | set_visibility = 1 |
2612 | set_magicmap = 2 |
2683 | set_magicmap = 2 |
2613 | set_smooth = 3 |
2684 | set_smooth = 3 |
2614 | set_smoothlevel = 4 |
2685 | set_smoothlevel = 4 |
2615 | CODE: |
2686 | CODE: |
2616 | faceinfo *f = face_info (idx); |
2687 | faceinfo *f = face_info (idx); assert (f); |
2617 | assert (f); |
|
|
2618 | switch (ix) |
2688 | switch (ix) |
2619 | { |
2689 | { |
2620 | case 0: f->type = value; break; |
2690 | case 0: f->type = value; break; |
2621 | case 1: f->visibility = value; break; |
2691 | case 1: f->visibility = value; break; |
2622 | case 2: f->magicmap = value; break; |
2692 | case 2: f->magicmap = value; break; |
… | |
… | |
2625 | } |
2695 | } |
2626 | |
2696 | |
2627 | void set_data (faceidx idx, int faceset, SV *data, SV *chksum) |
2697 | void set_data (faceidx idx, int faceset, SV *data, SV *chksum) |
2628 | CODE: |
2698 | CODE: |
2629 | { |
2699 | { |
2630 | facedata *d = face_data (idx, faceset); |
2700 | faceinfo *f = face_info (idx); assert (f); |
2631 | assert (d); |
2701 | facedata *d = &(faceset ? f->data64 : f->data32); |
2632 | sv_to (data, d->data); |
2702 | sv_to (data, d->data); |
2633 | STRLEN clen; |
2703 | STRLEN clen; |
2634 | char *cdata = SvPVbyte (chksum, clen); |
2704 | char *cdata = SvPVbyte (chksum, clen); |
2635 | clen = min (CHKSUM_SIZE, clen); |
2705 | clen = min (CHKSUM_SIZE, clen); |
2636 | |
2706 | |
… | |
… | |
2646 | ns->force_newmap = true; |
2716 | ns->force_newmap = true; |
2647 | } |
2717 | } |
2648 | } |
2718 | } |
2649 | } |
2719 | } |
2650 | |
2720 | |
|
|
2721 | int get_data_size (faceidx idx, int faceset = 0) |
|
|
2722 | CODE: |
|
|
2723 | facedata *d = face_data (idx, faceset); assert (d); |
|
|
2724 | RETVAL = d->data.size (); |
|
|
2725 | OUTPUT: |
|
|
2726 | RETVAL |
|
|
2727 | |
|
|
2728 | SV *get_chksum (faceidx idx, int faceset = 0) |
|
|
2729 | CODE: |
|
|
2730 | facedata *d = face_data (idx, faceset); assert (d); |
|
|
2731 | RETVAL = newSVpvn ((char *)d->chksum, CHKSUM_SIZE); |
|
|
2732 | OUTPUT: |
|
|
2733 | RETVAL |
|
|
2734 | |
2651 | void invalidate (faceidx idx) |
2735 | void invalidate (faceidx idx) |
2652 | CODE: |
2736 | CODE: |
2653 | for_all_clients (ns) |
2737 | for_all_clients (ns) |
2654 | { |
2738 | { |
2655 | ns->faces_sent [idx] = false; |
2739 | ns->faces_sent [idx] = false; |