… | |
… | |
419 | |
419 | |
420 | FREETMPS; |
420 | FREETMPS; |
421 | LEAVE; |
421 | LEAVE; |
422 | } |
422 | } |
423 | |
423 | |
|
|
424 | void reattach (data_type type, void *obj) |
|
|
425 | { |
|
|
426 | dSP; |
|
|
427 | ENTER; |
|
|
428 | SAVETMPS; |
|
|
429 | PUSHMARK (SP); |
|
|
430 | XPUSHs (sv_2mortal (newSVdt (type, obj))); |
|
|
431 | PUTBACK; |
|
|
432 | call_pv ("cf::reattach", G_DISCARD | G_VOID | G_EVAL); |
|
|
433 | FREETMPS; |
|
|
434 | LEAVE; |
|
|
435 | |
|
|
436 | switch (type) |
|
|
437 | { |
|
|
438 | case DT_OBJECT: INVOKE_OBJECT (REATTACH, obj); break; |
|
|
439 | case DT_PLAYER: INVOKE_PLAYER (REATTACH, obj); break; |
|
|
440 | case DT_MAP: INVOKE_MAP (REATTACH, obj); break; |
|
|
441 | } |
|
|
442 | } |
|
|
443 | |
|
|
444 | template<class subclass> |
|
|
445 | void reattach (extendable<subclass> *obj) |
|
|
446 | { |
|
|
447 | if (obj->self) |
|
|
448 | reattach (subclass::get_dt (), (subclass *)obj); |
|
|
449 | } |
|
|
450 | |
424 | void object_thawer::get (data_type type, void *obj, extendable_base *ext) |
451 | void object_thawer::get (data_type type, void *obj, extendable_base *ext) |
425 | { |
452 | { |
426 | if (!av) |
453 | if (!av) |
427 | return; |
454 | return; |
428 | |
455 | |
… | |
… | |
439 | if (SvROK (*svp)) |
466 | if (SvROK (*svp)) |
440 | { |
467 | { |
441 | ext->self = SvREFCNT_inc (*svp); |
468 | ext->self = SvREFCNT_inc (*svp); |
442 | sv_magic (SvRV ((SV *)ext->self), 0, PERL_MAGIC_ext, (char *)obj, 0); |
469 | sv_magic (SvRV ((SV *)ext->self), 0, PERL_MAGIC_ext, (char *)obj, 0); |
443 | |
470 | |
444 | dSP; |
471 | reattach (type, obj); |
445 | ENTER; |
|
|
446 | SAVETMPS; |
|
|
447 | PUSHMARK (SP); |
|
|
448 | EXTEND (SP, 1); |
|
|
449 | PUSHs (sv_2mortal (newSVdt (type, obj))); |
|
|
450 | PUTBACK; |
|
|
451 | call_pv ("cf::reattach", G_DISCARD | G_VOID | G_EVAL); |
|
|
452 | FREETMPS; |
|
|
453 | LEAVE; |
|
|
454 | |
|
|
455 | if (ext->cb && type == DT_OBJECT) |
|
|
456 | INVOKE_OBJECT (REATTACH, (object *)obj); |
|
|
457 | } |
472 | } |
458 | } |
473 | } |
459 | |
474 | |
460 | object_thawer::~object_thawer () |
475 | object_thawer::~object_thawer () |
461 | { |
476 | { |
… | |
… | |
686 | op = va_arg (ap, object *); |
701 | op = va_arg (ap, object *); |
687 | |
702 | |
688 | if (op->cb) |
703 | if (op->cb) |
689 | gather_callbacks (callbacks, (AV *)op->cb, event); |
704 | gather_callbacks (callbacks, (AV *)op->cb, event); |
690 | |
705 | |
|
|
706 | if (op->type) |
|
|
707 | { |
|
|
708 | if (op->subtype && op->type + op->subtype * NUM_SUBTYPES <= AvFILLp (cb_type)) |
|
|
709 | { |
|
|
710 | SV *registry = AvARRAY (cb_type)[op->type + op->subtype * NUM_SUBTYPES]; |
|
|
711 | |
|
|
712 | if (registry && SvROK (registry) && SvTYPE (SvRV (registry)) == SVt_PVAV) |
|
|
713 | gather_callbacks (callbacks, (AV *)SvRV (registry), event); |
|
|
714 | } |
|
|
715 | |
|
|
716 | if (op->type <= AvFILLp (cb_type)) |
|
|
717 | { |
|
|
718 | SV *registry = AvARRAY (cb_type)[op->type]; |
|
|
719 | |
|
|
720 | if (registry && SvROK (registry) && SvTYPE (SvRV (registry)) == SVt_PVAV) |
|
|
721 | gather_callbacks (callbacks, (AV *)SvRV (registry), event); |
|
|
722 | } |
|
|
723 | } |
|
|
724 | |
691 | gather_callbacks (callbacks, cb_object, event); |
725 | gather_callbacks (callbacks, cb_object, event); |
692 | |
|
|
693 | if (op->type > 0 && op->type <= AvFILLp (cb_type)) |
|
|
694 | { |
|
|
695 | SV *registry = AvARRAY (cb_type)[op->type]; |
|
|
696 | |
|
|
697 | if (registry && SvROK (registry) && SvTYPE (SvRV (registry)) == SVt_PVAV) |
|
|
698 | gather_callbacks (callbacks, (AV *)SvRV (registry), event); |
|
|
699 | } |
|
|
700 | |
726 | |
701 | break; |
727 | break; |
702 | |
728 | |
703 | case KLASS_PLAYER: |
729 | case KLASS_PLAYER: |
704 | dt = (data_type) va_arg (ap, int); |
730 | dt = (data_type) va_arg (ap, int); |
… | |
… | |
938 | const_iv (BUILDER) |
964 | const_iv (BUILDER) |
939 | const_iv (MATERIAL) |
965 | const_iv (MATERIAL) |
940 | const_iv (ITEM_TRANSFORMER) |
966 | const_iv (ITEM_TRANSFORMER) |
941 | const_iv (QUEST) |
967 | const_iv (QUEST) |
942 | |
968 | |
|
|
969 | const_iv (NUM_SUBTYPES) |
|
|
970 | |
943 | const_iv (ST_BD_BUILD) |
971 | const_iv (ST_BD_BUILD) |
944 | const_iv (ST_BD_REMOVE) |
972 | const_iv (ST_BD_REMOVE) |
945 | |
973 | |
946 | const_iv (ST_MAT_FLOOR) |
974 | const_iv (ST_MAT_FLOOR) |
947 | const_iv (ST_MAT_WALL) |
975 | const_iv (ST_MAT_WALL) |
… | |
… | |
1288 | |
1316 | |
1289 | const_iv (KLASS_GLOBAL) |
1317 | const_iv (KLASS_GLOBAL) |
1290 | const_iv (KLASS_OBJECT) |
1318 | const_iv (KLASS_OBJECT) |
1291 | const_iv (KLASS_PLAYER) |
1319 | const_iv (KLASS_PLAYER) |
1292 | const_iv (KLASS_MAP) |
1320 | const_iv (KLASS_MAP) |
1293 | |
|
|
1294 | const_iv (EVENT_OBJECT_INSTANTIATE) |
|
|
1295 | }; |
1321 | }; |
1296 | |
1322 | |
1297 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
1323 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
1298 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
1324 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
1299 | |
1325 | |
1300 | static const struct { |
1326 | static const struct { |
1301 | const char *name; |
1327 | const char *name; |
|
|
1328 | int skip; |
1302 | IV klass; |
1329 | IV klass; |
1303 | IV iv; |
1330 | IV iv; |
1304 | } *eiv, event_iv[] = { |
1331 | } *eiv, event_iv[] = { |
1305 | # define def(klass,name) { # name, (IV)KLASS_ ## klass, (IV)EVENT_ ## klass ## _ ## name }, |
1332 | # define def(klass,name) { "EVENT_" # klass "_" # name, sizeof ("EVENT_" # klass), (IV)KLASS_ ## klass, (IV)EVENT_ ## klass ## _ ## name }, |
1306 | # include "eventinc.h" |
1333 | # include "eventinc.h" |
1307 | # undef def |
1334 | # undef def |
1308 | }; |
1335 | }; |
1309 | |
1336 | |
1310 | AV *av = get_av ("cf::EVENT", 1); |
1337 | AV *av = get_av ("cf::EVENT", 1); |
1311 | |
1338 | |
1312 | for (eiv = event_iv + sizeof (event_iv) / sizeof (event_iv [0]); eiv-- > event_iv; ) |
1339 | for (eiv = event_iv + sizeof (event_iv) / sizeof (event_iv [0]); eiv-- > event_iv; ) |
1313 | { |
1340 | { |
1314 | AV *event = newAV (); |
1341 | AV *event = newAV (); |
1315 | av_push (event, newSVpv ((char *)eiv->name, 0)); |
1342 | av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0)); |
1316 | av_push (event, newSViv (eiv->klass)); |
1343 | av_push (event, newSViv (eiv->klass)); |
1317 | av_store (av, eiv->iv, newRV_noinc ((SV *)event)); |
1344 | av_store (av, eiv->iv, newRV_noinc ((SV *)event)); |
|
|
1345 | newCONSTSUB (stash, (char *)eiv->name, newSViv (eiv->iv)); |
1318 | } |
1346 | } |
1319 | |
1347 | |
1320 | static const struct { |
1348 | static const struct { |
1321 | int dtype; |
1349 | int dtype; |
1322 | const char *name; |
1350 | const char *name; |
… | |
… | |
1451 | { |
1479 | { |
1452 | hv_store (prop_type, cprop->name, strlen (cprop->name), newSViv (cprop->dtype), 0); |
1480 | hv_store (prop_type, cprop->name, strlen (cprop->name), newSViv (cprop->dtype), 0); |
1453 | hv_store (prop_idx, cprop->name, strlen (cprop->name), newSViv (cprop->idx ), 0); |
1481 | hv_store (prop_idx, cprop->name, strlen (cprop->name), newSViv (cprop->idx ), 0); |
1454 | } |
1482 | } |
1455 | |
1483 | |
1456 | cb_global = get_av ("cf::CB_GLOBAL", 1); |
|
|
1457 | cb_object = get_av ("cf::CB_OBJECT", 1); |
|
|
1458 | cb_player = get_av ("cf::CB_PLAYER", 1); |
|
|
1459 | cb_type = get_av ("cf::CB_TYPE" , 1); |
|
|
1460 | cb_map = get_av ("cf::CB_MAP" , 1); |
|
|
1461 | |
|
|
1462 | //I_EVENT_API (PACKAGE); |
1484 | //I_EVENT_API (PACKAGE); |
|
|
1485 | } |
|
|
1486 | |
|
|
1487 | void _reload_1 () |
|
|
1488 | CODE: |
|
|
1489 | cb_global = get_av ("cf::CB_GLOBAL", 1); |
|
|
1490 | cb_object = get_av ("cf::CB_OBJECT", 1); |
|
|
1491 | cb_player = get_av ("cf::CB_PLAYER", 1); |
|
|
1492 | cb_type = get_av ("cf::CB_TYPE" , 1); |
|
|
1493 | cb_map = get_av ("cf::CB_MAP" , 1); |
|
|
1494 | |
|
|
1495 | void _reload_2 () |
|
|
1496 | CODE: |
|
|
1497 | { |
|
|
1498 | // reattach to all attachable objects in the game. |
|
|
1499 | for (player *pl = first_player; pl; pl = pl->next) |
|
|
1500 | reattach (pl); |
|
|
1501 | |
|
|
1502 | for (mapstruct *map = first_map; map; map = map->next) |
|
|
1503 | reattach (map); |
|
|
1504 | |
|
|
1505 | for (object *op = objects; op; op = op->next) |
|
|
1506 | reattach (op); |
1463 | } |
1507 | } |
1464 | |
1508 | |
1465 | NV floor (NV x) |
1509 | NV floor (NV x) |
1466 | |
1510 | |
1467 | NV ceil (NV x) |
1511 | NV ceil (NV x) |