… | |
… | |
80 | // all objects no longer referenced and empty are |
80 | // all objects no longer referenced and empty are |
81 | // eligible for destruction. |
81 | // eligible for destruction. |
82 | void |
82 | void |
83 | clean_obj_cache () |
83 | clean_obj_cache () |
84 | { |
84 | { |
|
|
85 | static int count; |
|
|
86 | |
|
|
87 | if (++count & 7) |
|
|
88 | return; |
|
|
89 | |
85 | int todo = 10; |
90 | int todo = 1000; |
86 | do |
91 | do |
87 | { |
92 | { |
88 | I32 klen; |
93 | I32 klen; |
89 | char *key; |
94 | char *key; |
90 | HE *he = hv_iternext (obj_cache); |
95 | HE *he = hv_iternext (obj_cache); |
91 | |
96 | |
92 | if (he) |
97 | if (he) |
93 | { |
98 | { |
94 | SV *sv = SvRV (hv_iterval (obj_cache, he)); |
99 | SV *sv = hv_iterval (obj_cache, he); |
95 | |
100 | |
96 | // emopty and unreferened? nuke it |
101 | // empty and unreferenced? nuke it |
97 | if (SvREFCNT (sv) == 1 && !HvFILL ((HV *)sv)) |
102 | if (SvREFCNT (sv) == 1 && SvREFCNT (SvRV (sv)) == 1 && !HvFILL ((HV *)(SvRV (sv)))) |
98 | { |
103 | { |
99 | hv_delete (obj_cache, HeKEY (he), HeKLEN (he), G_DISCARD); |
104 | hv_delete (obj_cache, HeKEY (he), HeKLEN (he), G_DISCARD); |
100 | todo++; |
105 | todo++; |
101 | } |
106 | } |
102 | } |
107 | } |
… | |
… | |
517 | |
522 | |
518 | va_end (args); |
523 | va_end (args); |
519 | |
524 | |
520 | if (context.event_code == EVENT_FREE_OB) |
525 | if (context.event_code == EVENT_FREE_OB) |
521 | { |
526 | { |
522 | SV *sv = hv_delete (obj_cache, (char *)&context.activator, sizeof (object *), 0); |
527 | SV **svp = hv_fetch (obj_cache, (char *)&context.activator, sizeof (void *), 0); |
523 | |
528 | |
524 | if (sv) |
529 | if (svp) |
525 | { |
|
|
526 | clearSVptr (sv); |
530 | clearSVptr (*svp); |
527 | SvREFCNT_dec (sv); |
|
|
528 | } |
|
|
529 | } |
531 | } |
530 | else |
532 | else |
531 | inject_event ("cf::inject_global_event", &context); |
533 | inject_event ("cf::inject_global_event", &context); |
532 | |
534 | |
533 | rv = context.returnvalue; |
535 | rv = context.returnvalue; |
… | |
… | |
1174 | int cf_object_get_flag (object *op, int flag) |
1176 | int cf_object_get_flag (object *op, int flag) |
1175 | ALIAS: flag = 0 |
1177 | ALIAS: flag = 0 |
1176 | |
1178 | |
1177 | void cf_object_set_flag (object *op, int flag, int value) |
1179 | void cf_object_set_flag (object *op, int flag, int value) |
1178 | |
1180 | |
1179 | void cf_object_move (object *op, object *originator, int dir) |
1181 | void cf_object_move (object *op, int dir, object *originator = op) |
1180 | |
1182 | |
1181 | void cf_object_apply (object *op, object *author, int flags = 0) |
1183 | void cf_object_apply (object *op, object *author, int flags = 0) |
1182 | |
1184 | |
1183 | void cf_object_apply_below (object *op) |
1185 | void cf_object_apply_below (object *op) |
1184 | |
1186 | |
… | |
… | |
1267 | void cf_fix_object (object *pl) |
1269 | void cf_fix_object (object *pl) |
1268 | ALIAS: fix = 0 |
1270 | ALIAS: fix = 0 |
1269 | |
1271 | |
1270 | object *cf_insert_ob_in_ob (object *ob, object *where) |
1272 | object *cf_insert_ob_in_ob (object *ob, object *where) |
1271 | |
1273 | |
|
|
1274 | object *get_nearest_player (object *ob) |
|
|
1275 | ALIAS: nearest_player = 0 |
|
|
1276 | PREINIT: |
|
|
1277 | extern object *get_nearest_player (object *); |
|
|
1278 | |
1272 | void rangevector (object *ob, object *other, int flags = 0) |
1279 | void rangevector (object *ob, object *other, int flags = 0) |
1273 | PROTOTYPE: $$;$ |
1280 | PROTOTYPE: $$;$ |
1274 | ALIAS: |
1281 | PPCODE: |
1275 | direction = 1 |
|
|
1276 | distance = 2 |
|
|
1277 | CODE: |
|
|
1278 | { |
1282 | { |
1279 | rv_vector rv; |
1283 | rv_vector rv; |
1280 | // get_rangevector uses these if the objects are not on the same map |
|
|
1281 | // which is not the same as "on_same_map". |
|
|
1282 | rv.distance_x = 32767; |
|
|
1283 | rv.distance_y = 32767; |
|
|
1284 | get_rangevector (ob, other, &rv, flags); |
1284 | get_rangevector (ob, other, &rv, flags); |
1285 | EXTEND (SP, 5); |
1285 | EXTEND (SP, 5); |
1286 | if (!ix || ix == 2) PUSHs (newSVuv (rv.distance)); |
1286 | PUSHs (newSVuv (rv.distance)); |
1287 | if (!ix) PUSHs (newSViv (rv.distance_x)); |
1287 | PUSHs (newSViv (rv.distance_x)); |
1288 | if (!ix) PUSHs (newSViv (rv.distance_y)); |
1288 | PUSHs (newSViv (rv.distance_y)); |
1289 | if (!ix || ix == 1) PUSHs (newSViv (rv.direction)); |
1289 | PUSHs (newSViv (rv.direction)); |
1290 | if (!ix) PUSHs (newSVcfapi (CFAPI_POBJECT, rv.part)); |
1290 | PUSHs (newSVcfapi (CFAPI_POBJECT, rv.part)); |
1291 | } |
1291 | } |
1292 | |
1292 | |
1293 | bool on_same_map_as (object *ob, object *other) |
1293 | bool on_same_map_as (object *ob, object *other) |
1294 | CODE: |
1294 | CODE: |
1295 | RETVAL = on_same_map (ob, other); |
1295 | RETVAL = on_same_map (ob, other); |