… | |
… | |
28 | #include <perl.h> |
28 | #include <perl.h> |
29 | #include <XSUB.h> |
29 | #include <XSUB.h> |
30 | |
30 | |
31 | #undef save_long // clashes with libproto.h |
31 | #undef save_long // clashes with libproto.h |
32 | |
32 | |
33 | #define PLUGIN_NAME "cfperl" |
33 | #define PLUGIN_NAME "perl" |
34 | #define PLUGIN_VERSION "cfperl 0.0" |
34 | #define PLUGIN_VERSION "cfperl 0.0" |
35 | |
35 | |
36 | #ifndef __CEXTRACT__ |
36 | #ifndef __CEXTRACT__ |
37 | #include <plugin.h> |
37 | #include <plugin.h> |
38 | #endif |
38 | #endif |
… | |
… | |
62 | object* activator; |
62 | object* activator; |
63 | object* third; |
63 | object* third; |
64 | char message[1024]; |
64 | char message[1024]; |
65 | int fix; |
65 | int fix; |
66 | int event_code; |
66 | int event_code; |
67 | char options[1024]; |
67 | char extension[1024]; // name field, should invoke specific perl extension |
|
|
68 | char options[1024]; // slaying field of event_connectors |
68 | int returnvalue; |
69 | int returnvalue; |
69 | } CFPContext; |
70 | } CFPContext; |
70 | |
71 | |
71 | //static int current_command = -999; |
72 | //static int current_command = -999; |
72 | |
73 | |
… | |
… | |
79 | // all objects no longer referenced and empty are |
80 | // all objects no longer referenced and empty are |
80 | // eligible for destruction. |
81 | // eligible for destruction. |
81 | void |
82 | void |
82 | clean_obj_cache () |
83 | clean_obj_cache () |
83 | { |
84 | { |
|
|
85 | return; // killing neko-san gives me an unreferenced scalar |
84 | int todo = 10; |
86 | int todo = 10; |
85 | do |
87 | do |
86 | { |
88 | { |
87 | I32 klen; |
89 | I32 klen; |
88 | char *key; |
90 | char *key; |
89 | HE *he = hv_iternext (obj_cache); |
91 | HE *he = hv_iternext (obj_cache); |
90 | |
92 | |
91 | if (he) |
93 | if (he) |
92 | { |
94 | { |
93 | SV *sv = SvRV (hv_iterval (obj_cache, he)); |
95 | SV *sv = hv_iterval (obj_cache, he); |
94 | |
96 | |
95 | // emopty and unreferened? nuke it |
97 | // emopty and unreferened? nuke it |
96 | if (SvREFCNT (sv) == 1 && !HvFILL ((HV *)sv)) |
98 | if (SvREFCNT (sv) == 1 && SvREFCNT (SvRV (sv)) == 1 && !HvFILL ((HV *)(SvRV (sv)))) |
97 | { |
99 | { |
98 | hv_delete (obj_cache, HeKEY (he), HeKLEN (he), G_DISCARD); |
100 | hv_delete (obj_cache, HeKEY (he), HeKLEN (he), G_DISCARD); |
99 | todo++; |
101 | todo++; |
100 | } |
102 | } |
101 | } |
103 | } |
… | |
… | |
244 | } |
246 | } |
245 | |
247 | |
246 | ///////////////////////////////////////////////////////////////////////////// |
248 | ///////////////////////////////////////////////////////////////////////////// |
247 | |
249 | |
248 | void |
250 | void |
249 | inject_event (CFPContext *context) |
251 | inject_event (const char *func, CFPContext *context) |
250 | { |
252 | { |
251 | dSP; |
253 | dSP; |
252 | |
254 | |
253 | ENTER; |
255 | ENTER; |
254 | SAVETMPS; |
256 | SAVETMPS; |
255 | |
257 | |
256 | PUSHMARK (SP); |
258 | PUSHMARK (SP); |
257 | |
|
|
258 | EXTEND (SP, 2); |
|
|
259 | //PUSHs (sv_2mortal (newSViv (type))); |
|
|
260 | |
259 | |
261 | HV *hv = newHV (); |
260 | HV *hv = newHV (); |
262 | #define hv_context(type,addr,expr) hv_store (hv, #expr, sizeof (#expr) - 1, newSVcfapi (type, addr context->expr), 0) |
261 | #define hv_context(type,addr,expr) hv_store (hv, #expr, sizeof (#expr) - 1, newSVcfapi (type, addr context->expr), 0) |
263 | hv_context (CFAPI_POBJECT, ,who); |
262 | hv_context (CFAPI_POBJECT, ,who); |
264 | hv_context (CFAPI_POBJECT, ,activator); |
263 | hv_context (CFAPI_POBJECT, ,activator); |
265 | hv_context (CFAPI_POBJECT, ,third); |
264 | hv_context (CFAPI_POBJECT, ,third); |
266 | hv_context (CFAPI_STRING , ,message); |
265 | hv_context (CFAPI_STRING , ,message); |
267 | hv_context (CFAPI_INT ,&,fix); |
266 | hv_context (CFAPI_INT ,&,fix); |
268 | hv_context (CFAPI_INT ,&,event_code); |
267 | hv_context (CFAPI_INT ,&,event_code); |
269 | hv_context (CFAPI_STRING , ,options); |
268 | hv_context (CFAPI_STRING , ,options); |
|
|
269 | hv_context (CFAPI_STRING , ,extension); |
270 | |
270 | |
271 | PUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); |
271 | XPUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); |
272 | |
272 | |
273 | PUTBACK; |
273 | PUTBACK; |
274 | int count = call_pv ("cf::inject_event", G_SCALAR | G_EVAL); |
274 | int count = call_pv (func, G_SCALAR | G_EVAL); |
275 | SPAGAIN; |
275 | SPAGAIN; |
276 | |
276 | |
277 | if (SvTRUE (ERRSV)) |
277 | if (SvTRUE (ERRSV)) |
278 | LOG (llevError, "event '%d' callback evaluation error: %s", context->event_code, SvPV_nolen (ERRSV)); |
278 | LOG (llevError, "event '%d' callback evaluation error: %s", context->event_code, SvPV_nolen (ERRSV)); |
279 | |
279 | |
… | |
… | |
488 | case EVENT_LOGOUT: |
488 | case EVENT_LOGOUT: |
489 | pl = va_arg (args, player *); |
489 | pl = va_arg (args, player *); |
490 | context.activator = pl->ob; |
490 | context.activator = pl->ob; |
491 | buf = va_arg (args, char *); |
491 | buf = va_arg (args, char *); |
492 | if (buf != 0) |
492 | if (buf != 0) |
493 | strcpy (context.message, buf); |
493 | strncpy (context.message, buf, sizeof (context.message)); |
494 | break; |
494 | break; |
495 | |
495 | |
496 | case EVENT_SHOUT: |
496 | case EVENT_SHOUT: |
497 | case EVENT_MUZZLE: |
497 | case EVENT_MUZZLE: |
498 | case EVENT_KICK: |
498 | case EVENT_KICK: |
499 | context.activator = va_arg (args, object *); |
499 | context.activator = va_arg (args, object *); |
500 | buf = va_arg (args, char *); |
500 | buf = va_arg (args, char *); |
501 | if (buf != 0) |
501 | if (buf != 0) |
502 | strcpy (context.message, buf); |
502 | strncpy (context.message, buf, sizeof (context.message)); |
503 | break; |
503 | break; |
504 | |
504 | |
505 | case EVENT_CLOCK: |
505 | case EVENT_CLOCK: |
506 | clean_obj_cache (); |
506 | clean_obj_cache (); |
507 | break; |
507 | break; |
… | |
… | |
510 | break; |
510 | break; |
511 | |
511 | |
512 | case EVENT_MAPRESET: |
512 | case EVENT_MAPRESET: |
513 | buf = va_arg (args, char *); |
513 | buf = va_arg (args, char *); |
514 | if (buf != 0) |
514 | if (buf != 0) |
515 | strcpy (context.message, buf); |
515 | strncpy (context.message, buf, sizeof (context.message)); |
516 | break; |
516 | break; |
517 | } |
517 | } |
518 | |
518 | |
519 | va_end (args); |
519 | va_end (args); |
520 | |
520 | |
… | |
… | |
527 | clearSVptr (sv); |
527 | clearSVptr (sv); |
528 | SvREFCNT_dec (sv); |
528 | SvREFCNT_dec (sv); |
529 | } |
529 | } |
530 | } |
530 | } |
531 | else |
531 | else |
532 | inject_event (&context); |
532 | inject_event ("cf::inject_global_event", &context); |
533 | |
533 | |
534 | rv = context.returnvalue; |
534 | rv = context.returnvalue; |
535 | |
535 | |
536 | return &rv; |
536 | return &rv; |
537 | } |
537 | } |
… | |
… | |
553 | |
553 | |
554 | context.who = va_arg (args, object *); |
554 | context.who = va_arg (args, object *); |
555 | context.event_code = va_arg (args, int); |
555 | context.event_code = va_arg (args, int); |
556 | context.activator = va_arg (args, object *); |
556 | context.activator = va_arg (args, object *); |
557 | context.third = va_arg (args, object *); |
557 | context.third = va_arg (args, object *); |
|
|
558 | |
558 | buf = va_arg (args, char *); |
559 | buf = va_arg (args, char *); |
559 | |
|
|
560 | if (buf != 0) |
560 | if (buf != 0) |
561 | strcpy (context.message, buf); |
561 | strncpy (context.message, buf, sizeof (context.message)); |
562 | |
562 | |
563 | context.fix = va_arg (args, int); |
563 | context.fix = va_arg (args, int); |
|
|
564 | strncpy (context.extension, va_arg (args, char *), sizeof (context.extension)); |
564 | strcpy (context.options, va_arg (args, char *)); |
565 | strncpy (context.options, va_arg (args, char *), sizeof (context.options)); |
565 | context.returnvalue = 0; |
566 | context.returnvalue = 0; |
566 | va_end (args); |
567 | va_end (args); |
567 | |
568 | |
568 | inject_event (&context); |
569 | inject_event ("cf::inject_event", &context); |
569 | |
570 | |
570 | rv = context.returnvalue; |
571 | rv = context.returnvalue; |
571 | return &rv; |
572 | return &rv; |
572 | } |
573 | } |
573 | |
574 | |
… | |
… | |
1174 | int cf_object_get_flag (object *op, int flag) |
1175 | int cf_object_get_flag (object *op, int flag) |
1175 | ALIAS: flag = 0 |
1176 | ALIAS: flag = 0 |
1176 | |
1177 | |
1177 | void cf_object_set_flag (object *op, int flag, int value) |
1178 | void cf_object_set_flag (object *op, int flag, int value) |
1178 | |
1179 | |
1179 | void cf_object_move (object *op, object *originator, int dir) |
1180 | void cf_object_move (object *op, int dir, object *originator) |
1180 | |
1181 | |
1181 | void cf_object_apply (object *op, object *author, int flags = 0) |
1182 | void cf_object_apply (object *op, object *author, int flags = 0) |
1182 | |
1183 | |
1183 | void cf_object_apply_below (object *op) |
1184 | void cf_object_apply_below (object *op) |
1184 | |
1185 | |
… | |
… | |
1267 | void cf_fix_object (object *pl) |
1268 | void cf_fix_object (object *pl) |
1268 | ALIAS: fix = 0 |
1269 | ALIAS: fix = 0 |
1269 | |
1270 | |
1270 | object *cf_insert_ob_in_ob (object *ob, object *where) |
1271 | object *cf_insert_ob_in_ob (object *ob, object *where) |
1271 | |
1272 | |
|
|
1273 | object *get_nearest_player (object *ob) |
|
|
1274 | ALIAS: nearest_player = 0 |
|
|
1275 | |
|
|
1276 | void rangevector (object *ob, object *other, int flags = 0) |
|
|
1277 | PROTOTYPE: $$;$ |
|
|
1278 | PPCODE: |
|
|
1279 | { |
|
|
1280 | rv_vector rv; |
|
|
1281 | get_rangevector (ob, other, &rv, flags); |
|
|
1282 | EXTEND (SP, 5); |
|
|
1283 | PUSHs (newSVuv (rv.distance)); |
|
|
1284 | PUSHs (newSViv (rv.distance_x)); |
|
|
1285 | PUSHs (newSViv (rv.distance_y)); |
|
|
1286 | PUSHs (newSViv (rv.direction)); |
|
|
1287 | PUSHs (newSVcfapi (CFAPI_POBJECT, rv.part)); |
|
|
1288 | } |
|
|
1289 | |
|
|
1290 | bool on_same_map_as (object *ob, object *other) |
|
|
1291 | CODE: |
|
|
1292 | RETVAL = on_same_map (ob, other); |
|
|
1293 | OUTPUT: RETVAL |
|
|
1294 | |
1272 | |
1295 | |
1273 | MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_ |
1296 | MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_ |
1274 | |
1297 | |
1275 | player *player (object *op) |
1298 | player *player (object *op) |
1276 | CODE: |
1299 | CODE: |
… | |
… | |
1307 | # nonstandard |
1330 | # nonstandard |
1308 | object *ob (player *pl) |
1331 | object *ob (player *pl) |
1309 | CODE: |
1332 | CODE: |
1310 | RETVAL = pl->ob; |
1333 | RETVAL = pl->ob; |
1311 | OUTPUT: RETVAL |
1334 | OUTPUT: RETVAL |
|
|
1335 | |
|
|
1336 | player *first () |
|
|
1337 | CODE: |
|
|
1338 | RETVAL = first_player; |
|
|
1339 | OUTPUT: RETVAL |
|
|
1340 | |
|
|
1341 | player *next (player *pl) |
|
|
1342 | CODE: |
|
|
1343 | RETVAL = pl->next; |
|
|
1344 | OUTPUT: RETVAL |
|
|
1345 | |
|
|
1346 | void |
|
|
1347 | list () |
|
|
1348 | PPCODE: |
|
|
1349 | { |
|
|
1350 | player *pl; |
|
|
1351 | for (pl = first_player; pl; pl = pl->next) |
|
|
1352 | XPUSHs (newSVcfapi (CFAPI_PPLAYER, pl)); |
|
|
1353 | } |
1312 | |
1354 | |
1313 | |
1355 | |
1314 | MODULE = cf PACKAGE = cf::map PREFIX = cf_map_ |
1356 | MODULE = cf PACKAGE = cf::map PREFIX = cf_map_ |
1315 | |
1357 | |
1316 | SV * |
1358 | SV * |