--- deliantra/server/plugins/cfperl/cfperl.xs 2006/03/15 14:05:32 1.1.1.1 +++ deliantra/server/plugins/cfperl/cfperl.xs 2006/02/08 03:46:15 1.15 @@ -31,7 +31,7 @@ #undef save_long // clashes with libproto.h #define PLUGIN_NAME "perl" -#define PLUGIN_VERSION "cfperl 0.2" +#define PLUGIN_VERSION "cfperl 0.0" #ifndef __CEXTRACT__ #include @@ -49,16 +49,12 @@ #include "perlxsi.c" -typedef object object_ornull; -typedef mapstruct mapstruct_ornull; - static f_plug_api gethook; static f_plug_api registerGlobalEvent; static f_plug_api unregisterGlobalEvent; static f_plug_api systemDirectory; static f_plug_api object_set_property; static f_plug_api map_get_map; -static f_plug_api object_insert; typedef struct { @@ -86,12 +82,7 @@ void clean_obj_cache () { - static int count; - - if (++count & 7) - return; - - int todo = 1000; + int todo = 10; do { I32 klen; @@ -100,10 +91,10 @@ if (he) { - SV *sv = hv_iterval (obj_cache, he); + SV *sv = SvRV (hv_iterval (obj_cache, he)); - // empty and unreferenced? nuke it - if (SvREFCNT (sv) == 1 && SvREFCNT (SvRV (sv)) == 1 && !HvFILL ((HV *)(SvRV (sv)))) + // emopty and unreferened? nuke it + if (SvREFCNT (sv) == 1 && !HvFILL ((HV *)sv)) { hv_delete (obj_cache, HeKEY (he), HeKLEN (he), G_DISCARD); todo++; @@ -118,14 +109,12 @@ static SV * newSVptr (void *ptr, const char *klass) { - SV *sv; - if (!ptr) return &PL_sv_undef; - sv = newSV (0); - sv_magic (sv, 0, PERL_MAGIC_ext, (char *)ptr, 0); - return sv_bless (newRV_noinc (sv), gv_stashpv (klass, 1)); + HV *hv = newHV (); + sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0); + return sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1)); } static SV * @@ -142,9 +131,7 @@ sv = *he; else { - HV *hv = newHV (); - sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0); - sv = sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1)); + sv = newSVptr (ptr, klass); hv_store (obj_cache, (char *)&ptr, sizeof (ptr), sv, 0); } @@ -175,15 +162,6 @@ return (long)mg->mg_ptr; } -static long -SvPTR_ornull (SV *sv, const char *klass) -{ - if (SvOK (sv)) - return SvPTR (sv, klass); - else - return 0; -} - SV * newSVcfapi (int type, ...) { @@ -413,7 +391,6 @@ systemDirectory = gethook (&rtype, hooktype, "cfapi_system_directory"); object_set_property = gethook (&rtype, hooktype, "cfapi_object_set_property"); map_get_map = gethook (&rtype, hooktype, "cfapi_map_get_map"); - object_insert = gethook (&rtype, hooktype, "cfapi_object_insert"); cf_init_plugin (gethook); @@ -542,10 +519,13 @@ if (context.event_code == EVENT_FREE_OB) { - SV *sv = hv_delete (obj_cache, (char *)&context.activator, sizeof (void *), 0); + SV *sv = hv_delete (obj_cache, (char *)&context.activator, sizeof (object *), 0); if (sv) - clearSVptr (sv); + { + clearSVptr (sv); + SvREFCNT_dec (sv); + } } else inject_event ("cf::inject_global_event", &context); @@ -752,33 +732,6 @@ const_iv (ST_MAT_WALL) const_iv (ST_MAT_ITEM) - const_iv (AT_PHYSICAL) - const_iv (AT_MAGIC) - const_iv (AT_FIRE) - const_iv (AT_ELECTRICITY) - const_iv (AT_COLD) - const_iv (AT_CONFUSION) - const_iv (AT_ACID) - const_iv (AT_DRAIN) - const_iv (AT_WEAPONMAGIC) - const_iv (AT_GHOSTHIT) - const_iv (AT_POISON) - const_iv (AT_SLOW) - const_iv (AT_PARALYZE) - const_iv (AT_TURN_UNDEAD) - const_iv (AT_FEAR) - const_iv (AT_CANCELLATION) - const_iv (AT_DEPLETE) - const_iv (AT_DEATH) - const_iv (AT_CHAOS) - const_iv (AT_COUNTERSPELL) - const_iv (AT_GODPOWER) - const_iv (AT_HOLYWORD) - const_iv (AT_BLIND) - const_iv (AT_INTERNAL) - const_iv (AT_LIFE_STEALING) - const_iv (AT_DISEASE) - const_iv (QUEST_IN_PROGRESS) const_iv (QUEST_DONE_QUEST) const_iv (QUEST_DONE_TASK) @@ -1199,46 +1152,12 @@ } break; case CFAPI_STRING: - cf_object_set_string_property (obj, idx, SvOK (newval) ? SvPV_nolen (newval) : 0); - break; - case CFAPI_POBJECT: - { - int unused_type; - object_set_property (&unused_type, obj, idx, (object *)SvPTR_ornull (newval, "cf::object")); - } + cf_object_set_string_property (obj, idx, SvPV_nolen (newval)); break; default: croak ("unhandled type '%d' in set_property '%d'", type, idx); } -# missing properties - -void -set_attacktype (object *obj, U32 attacktype) - CODE: - obj->attacktype = attacktype; - -U32 -get_attacktype (object *obj) - ALIAS: - attacktype = 0 - CODE: - RETVAL = obj->attacktype; - OUTPUT: RETVAL - -void -set_food (object *obj, int food) - CODE: - obj->stats.food = food; - -int -get_food (object *obj) - ALIAS: - food = 0 - CODE: - RETVAL = obj->stats.food; - OUTPUT: RETVAL - void inv (object *obj) PROTOTYPE: $ @@ -1257,7 +1176,7 @@ void cf_object_set_flag (object *op, int flag, int value) -void cf_object_move (object *op, int dir, object *originator = op) +void cf_object_move (object *op, object *originator, int dir) void cf_object_apply (object *op, object *author, int flags = 0) @@ -1273,15 +1192,15 @@ int cf_object_change_map (object *op, int x, int y, mapstruct *map) -object *cf_object_clone (object *op, int clonetype = 0) +object *cf_object_clone (object *op, int clonetype) int cf_object_pay_item (object *op, object *buyer) int cf_object_pay_amount (object *op, double amount) -int cf_object_cast_spell (object *caster, object *ctoo, int dir, object *spell_ob, char *stringarg = 0) +int cf_object_cast_spell (object *caster, object *ctoo, int dir, object *sp_, char *flags) -int cf_object_cast_ability (object *caster, object *ctoo, int dir, object *sp_, char *stringarg = 0) +int cf_object_cast_ability (object *caster, object *ctoo, int dir, object *sp_, char *flags) void cf_object_learn_spell (object *op, object *sp) @@ -1327,50 +1246,48 @@ void cf_object_set_key (object *op, char *keyname, char *value) -object *cf_create_object_by_name (const char *name) - -MODULE = cf PACKAGE = cf::object PREFIX = cf_ - -void cf_fix_object (object *pl) - ALIAS: fix = 0 - -object *cf_insert_ob_in_ob (object *ob, object *where) +char * +base_name (object *ob, int plural) + CODE: + RETVAL = cf_query_base_name (ob, plural); + OUTPUT: RETVAL -# no clean way to get an object from an archetype - stupid idiotic -# dumb kludgy misdesigned plug-in api slowly gets on my nerves. +MODULE = cf PACKAGE = cf::object PREFIX = cf_object_ -object *new (const char *archetype = 0) +object *cf_create_object_by_name (const char *name = 0) PROTOTYPE: ;$ + ALIAS: + create_object = 0 + new = 0 CODE: - RETVAL = archetype ? get_archetype (archetype) : cf_create_object (); + RETVAL = name ? cf_create_object_by_name (name) : cf_create_object (); OUTPUT: RETVAL -object *insert_ob_in_map_at (object *ob, mapstruct *where, object_ornull *orig, int flag, int x, int y) - PROTOTYPE: $$$$$$ - CODE: -{ - int unused_type; - RETVAL = (object *)object_insert (&unused_type, ob, 0, where, orig, flag, x, y); -} +void cf_fix_object (object *pl) + ALIAS: fix = 0 -object *get_nearest_player (object *ob) - ALIAS: nearest_player = 0 - PREINIT: - extern object *get_nearest_player (object *); +object *cf_insert_ob_in_ob (object *ob, object *where) void rangevector (object *ob, object *other, int flags = 0) PROTOTYPE: $$;$ - PPCODE: + ALIAS: + direction = 1 + distance = 2 + CODE: { rv_vector rv; + // get_rangevector uses these if the objects are not on the same map + // which is not the same as "on_same_map". + rv.distance_x = 32767; + rv.distance_y = 32767; get_rangevector (ob, other, &rv, flags); EXTEND (SP, 5); - PUSHs (newSVuv (rv.distance)); - PUSHs (newSViv (rv.distance_x)); - PUSHs (newSViv (rv.distance_y)); - PUSHs (newSViv (rv.direction)); - PUSHs (newSVcfapi (CFAPI_POBJECT, rv.part)); + if (!ix || ix == 2) PUSHs (newSVuv (rv.distance)); + if (!ix) PUSHs (newSViv (rv.distance_x)); + if (!ix) PUSHs (newSViv (rv.distance_y)); + if (!ix || ix == 1) PUSHs (newSViv (rv.direction)); + if (!ix) PUSHs (newSVcfapi (CFAPI_POBJECT, rv.part)); } bool on_same_map_as (object *ob, object *other) @@ -1378,12 +1295,6 @@ RETVAL = on_same_map (ob, other); OUTPUT: RETVAL -char * -base_name (object *ob, int plural) - CODE: - RETVAL = cf_query_base_name (ob, plural); - OUTPUT: RETVAL - MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_ @@ -1396,11 +1307,6 @@ object *cf_player_send_inventory (object *op) -player *contr (object *op) - CODE: - RETVAL = op->contr; - OUTPUT: RETVAL - char *cf_player_get_ip (object *op) ALIAS: ip = 0 @@ -1424,8 +1330,6 @@ void cf_player_move (player *pl, int dir) -void MapNewmapCmd (player *pl) - # nonstandard object *ob (player *pl) CODE: