ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/plugins/cfperl/cfperl.xs
(Generate patch)

Comparing deliantra/server/plugins/cfperl/cfperl.xs (file contents):
Revision 1.15 by root, Wed Feb 8 03:46:15 2006 UTC vs.
Revision 1.20 by root, Thu Feb 9 01:15:25 2006 UTC

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.
82void 82void
83clean_obj_cache () 83clean_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 }
107} 112}
108 113
109static SV * 114static SV *
110newSVptr (void *ptr, const char *klass) 115newSVptr (void *ptr, const char *klass)
111{ 116{
117 SV *sv;
118
112 if (!ptr) 119 if (!ptr)
113 return &PL_sv_undef; 120 return &PL_sv_undef;
114 121
115 HV *hv = newHV (); 122 sv = newSV (0);
116 sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0); 123 sv_magic (sv, 0, PERL_MAGIC_ext, (char *)ptr, 0);
117 return sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1)); 124 return sv_bless (newRV_noinc (sv), gv_stashpv (klass, 1));
118} 125}
119 126
120static SV * 127static SV *
121newSVptr_cached (void *ptr, const char *klass) 128newSVptr_cached (void *ptr, const char *klass)
122{ 129{
129 136
130 if (he) 137 if (he)
131 sv = *he; 138 sv = *he;
132 else 139 else
133 { 140 {
134 sv = newSVptr (ptr, klass); 141 HV *hv = newHV ();
142 sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0);
143 sv = sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1));
135 hv_store (obj_cache, (char *)&ptr, sizeof (ptr), sv, 0); 144 hv_store (obj_cache, (char *)&ptr, sizeof (ptr), sv, 0);
136 } 145 }
137 146
138 return newSVsv (sv); 147 return newSVsv (sv);
139} 148}
517 526
518 va_end (args); 527 va_end (args);
519 528
520 if (context.event_code == EVENT_FREE_OB) 529 if (context.event_code == EVENT_FREE_OB)
521 { 530 {
522 SV *sv = hv_delete (obj_cache, (char *)&context.activator, sizeof (object *), 0); 531 SV *sv = hv_delete (obj_cache, (char *)&context.activator, sizeof (void *), 0);
523 532
524 if (sv) 533 if (sv)
525 {
526 clearSVptr (sv); 534 clearSVptr (sv);
527 SvREFCNT_dec (sv);
528 }
529 } 535 }
530 else 536 else
531 inject_event ("cf::inject_global_event", &context); 537 inject_event ("cf::inject_global_event", &context);
532 538
533 rv = context.returnvalue; 539 rv = context.returnvalue;
1174int cf_object_get_flag (object *op, int flag) 1180int cf_object_get_flag (object *op, int flag)
1175 ALIAS: flag = 0 1181 ALIAS: flag = 0
1176 1182
1177void cf_object_set_flag (object *op, int flag, int value) 1183void cf_object_set_flag (object *op, int flag, int value)
1178 1184
1179void cf_object_move (object *op, object *originator, int dir) 1185void cf_object_move (object *op, int dir, object *originator = op)
1180 1186
1181void cf_object_apply (object *op, object *author, int flags = 0) 1187void cf_object_apply (object *op, object *author, int flags = 0)
1182 1188
1183void cf_object_apply_below (object *op) 1189void cf_object_apply_below (object *op)
1184 1190
1267void cf_fix_object (object *pl) 1273void cf_fix_object (object *pl)
1268 ALIAS: fix = 0 1274 ALIAS: fix = 0
1269 1275
1270object *cf_insert_ob_in_ob (object *ob, object *where) 1276object *cf_insert_ob_in_ob (object *ob, object *where)
1271 1277
1278object *get_nearest_player (object *ob)
1279 ALIAS: nearest_player = 0
1280 PREINIT:
1281 extern object *get_nearest_player (object *);
1282
1272void rangevector (object *ob, object *other, int flags = 0) 1283void rangevector (object *ob, object *other, int flags = 0)
1273 PROTOTYPE: $$;$ 1284 PROTOTYPE: $$;$
1274 ALIAS: 1285 PPCODE:
1275 direction = 1
1276 distance = 2
1277 CODE:
1278{ 1286{
1279 rv_vector rv; 1287 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); 1288 get_rangevector (ob, other, &rv, flags);
1285 EXTEND (SP, 5); 1289 EXTEND (SP, 5);
1286 if (!ix || ix == 2) PUSHs (newSVuv (rv.distance)); 1290 PUSHs (newSVuv (rv.distance));
1287 if (!ix) PUSHs (newSViv (rv.distance_x)); 1291 PUSHs (newSViv (rv.distance_x));
1288 if (!ix) PUSHs (newSViv (rv.distance_y)); 1292 PUSHs (newSViv (rv.distance_y));
1289 if (!ix || ix == 1) PUSHs (newSViv (rv.direction)); 1293 PUSHs (newSViv (rv.direction));
1290 if (!ix) PUSHs (newSVcfapi (CFAPI_POBJECT, rv.part)); 1294 PUSHs (newSVcfapi (CFAPI_POBJECT, rv.part));
1291} 1295}
1292 1296
1293bool on_same_map_as (object *ob, object *other) 1297bool on_same_map_as (object *ob, object *other)
1294 CODE: 1298 CODE:
1295 RETVAL = on_same_map (ob, other); 1299 RETVAL = on_same_map (ob, other);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines