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

Comparing deliantra/server/server/cfperl.xs (file contents):
Revision 1.14 by root, Sun Aug 27 13:02:04 2006 UTC vs.
Revision 1.17 by root, Sun Aug 27 17:59:26 2006 UTC

108 108
109 sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0); 109 sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0);
110 return sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1)); 110 return sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1));
111} 111}
112 112
113template<class extendable> 113template<class attachable>
114SV * 114SV *
115newSVextendable (extendable *obj, const char *klass) 115newSVattachable (attachable *obj, const char *klass)
116{ 116{
117 if (!obj) 117 if (!obj)
118 return &PL_sv_undef; 118 return &PL_sv_undef;
119 119
120 if (!obj->self) 120 if (!obj->self)
227 break; 227 break;
228 228
229 case DT_OBJECT: 229 case DT_OBJECT:
230 { 230 {
231 object *obj = va_arg (ap, object *); 231 object *obj = va_arg (ap, object *);
232 sv = newSVextendable (obj, obj && obj->type == PLAYER ? "cf::object::player::wrap" : "cf::object::wrap"); 232 sv = newSVattachable (obj, obj && obj->type == PLAYER ? "cf::object::player::wrap" : "cf::object::wrap");
233 } 233 }
234 break; 234 break;
235 235
236 case DT_MAP: 236 case DT_MAP:
237 // va_arg (object *) when void * is passed is an XSI extension 237 // va_arg (object *) when void * is passed is an XSI extension
238 sv = newSVextendable (va_arg (ap, mapstruct *), "cf::map::wrap"); 238 sv = newSVattachable (va_arg (ap, mapstruct *), "cf::map::wrap");
239 break; 239 break;
240 240
241 case DT_PLAYER: 241 case DT_PLAYER:
242 sv = newSVextendable (va_arg (ap, player *), "cf::player::wrap"); 242 sv = newSVattachable (va_arg (ap, player *), "cf::player::wrap");
243 break; 243 break;
244 244
245 case DT_ARCH: 245 case DT_ARCH:
246 sv = newSVptr (va_arg (ap, archetype *), "cf::arch::wrap"); 246 sv = newSVptr (va_arg (ap, archetype *), "cf::arch::wrap");
247 break; 247 break;
304} 304}
305 305
306////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 306//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
307 307
308SV * 308SV *
309registry_of (extendable_base *ext) 309registry_of (attachable_base *ext)
310{ 310{
311 if (!ext->cb) 311 if (!ext->cb)
312 ext->cb = newAV (); 312 ext->cb = newAV ();
313 313
314 return newRV_inc ((SV *)ext->cb); 314 return newRV_inc ((SV *)ext->cb);
315} 315}
316 316
317void extendable_base::clear () 317void attachable_base::clear ()
318{ 318{
319 //if (self) fprintf (stderr, "free_ob_self %p %s (%p,%p)\n", this, ((object *)this)->name, self, cb);//D 319 //if (self) fprintf (stderr, "free_ob_self %p %s (%p,%p)\n", this, ((object *)this)->name, self, cb);//D
320 320
321 if (self) SvREFCNT_dec (self); 321 if (self) SvREFCNT_dec (self);
322 if (cb) SvREFCNT_dec (cb); 322 if (cb) SvREFCNT_dec (cb);
326 self = 0; 326 self = 0;
327 cb = 0; 327 cb = 0;
328 attach = 0; 328 attach = 0;
329} 329}
330 330
331void extendable_base::optimise () 331void attachable_base::optimise ()
332{ 332{
333 if (!self) 333 if (!self)
334 return; 334 return;
335 335
336 HV *hv = (HV *)SvRV ((SV *)self); 336 HV *hv = (HV *)SvRV ((SV *)self);
356 PUSHs (sv_2mortal (newSVpv (attach, 0))); 356 PUSHs (sv_2mortal (newSVpv (attach, 0)));
357 PUTBACK; 357 PUTBACK;
358 call_pv ("cf::instantiate", G_DISCARD | G_VOID | G_EVAL); 358 call_pv ("cf::instantiate", G_DISCARD | G_VOID | G_EVAL);
359 FREETMPS; 359 FREETMPS;
360 LEAVE; 360 LEAVE;
361
362 INVOKE_OBJECT (INSTANTIATE, this);
361} 363}
362 364
363///////////////////////////////////////////////////////////////////////////// 365/////////////////////////////////////////////////////////////////////////////
364 366
365object_freezer::object_freezer (const char *filename) 367object_freezer::object_freezer (const char *filename)
382 call_pv ("cf::object_freezer_save", G_VOID | G_DISCARD | G_EVAL); 384 call_pv ("cf::object_freezer_save", G_VOID | G_DISCARD | G_EVAL);
383 FREETMPS; 385 FREETMPS;
384 LEAVE; 386 LEAVE;
385} 387}
386 388
387void object_freezer::put (extendable_base *ext) 389void object_freezer::put (attachable_base *ext)
388{ 390{
389 ext->optimise (); 391 ext->optimise ();
390 392
391 if (ext->self) 393 if (ext->self)
392 av_store ((AV *)av, idx, SvREFCNT_inc ((SV *)ext->self)); 394 av_store ((AV *)av, idx, SvREFCNT_inc ((SV *)ext->self));
440 case DT_MAP: INVOKE_MAP (REATTACH, obj); break; 442 case DT_MAP: INVOKE_MAP (REATTACH, obj); break;
441 } 443 }
442} 444}
443 445
444template<class subclass> 446template<class subclass>
445void reattach (extendable<subclass> *obj) 447void reattach (attachable<subclass> *obj)
446{ 448{
449 obj->optimise ();
450
447 if (obj->self) 451 if (obj->self)
448 reattach (subclass::get_dt (), (subclass *)obj); 452 reattach (subclass::get_dt (), (subclass *)obj);
449} 453}
450 454
451void object_thawer::get (data_type type, void *obj, extendable_base *ext) 455void object_thawer::get (data_type type, void *obj, attachable_base *ext)
452{ 456{
453 if (!av) 457 if (!av)
454 return; 458 return;
455 459
456 // we have to "re-instantiate"/reattach to an object, so nuke ext->attach 460 // we have to "re-instantiate"/reattach to an object, so nuke ext->attach
481///////////////////////////////////////////////////////////////////////////// 485/////////////////////////////////////////////////////////////////////////////
482 486
483extern "C" int cfperl_initPlugin (const char *iversion, f_plug_api gethooksptr) 487extern "C" int cfperl_initPlugin (const char *iversion, f_plug_api gethooksptr)
484{ 488{
485 gethook = gethooksptr; 489 gethook = gethooksptr;
486 printf (PLUGIN_VERSION " init\n");
487 490
488 return 0; 491 return 0;
489} 492}
490 493
491static CommArray_s rtn_cmd; 494static CommArray_s rtn_cmd;
571 574
572extern "C" int cfperl_postInitPlugin () 575extern "C" int cfperl_postInitPlugin ()
573{ 576{
574 int hooktype = 1; 577 int hooktype = 1;
575 int rtype = 0; 578 int rtype = 0;
576
577 printf (PLUGIN_VERSION " post init\n");
578 579
579 systemDirectory = (void* (*)(int*, ...)) gethook (&rtype, hooktype, "cfapi_system_directory"); 580 systemDirectory = (void* (*)(int*, ...)) gethook (&rtype, hooktype, "cfapi_system_directory");
580 object_set_property = (void* (*)(int*, ...)) gethook (&rtype, hooktype, "cfapi_object_set_property"); 581 object_set_property = (void* (*)(int*, ...)) gethook (&rtype, hooktype, "cfapi_object_set_property");
581 map_get_map = (void* (*)(int*, ...)) gethook (&rtype, hooktype, "cfapi_map_get_map"); 582 map_get_map = (void* (*)(int*, ...)) gethook (&rtype, hooktype, "cfapi_map_get_map");
582 object_insert = (void* (*)(int*, ...)) gethook (&rtype, hooktype, "cfapi_object_insert"); 583 object_insert = (void* (*)(int*, ...)) gethook (&rtype, hooktype, "cfapi_object_insert");

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines