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.89 by elmex, Wed Dec 20 10:31:00 2006 UTC vs.
Revision 1.97 by root, Thu Dec 21 22:41:35 2006 UTC

59static f_plug_api object_set_property = cfapi_object_set_property; 59static f_plug_api object_set_property = cfapi_object_set_property;
60static f_plug_api object_insert = cfapi_object_insert; 60static f_plug_api object_insert = cfapi_object_insert;
61 61
62static PerlInterpreter *perl; 62static PerlInterpreter *perl;
63 63
64static AV *cb_global, *cb_object, *cb_player, *cb_type, *cb_map; 64static AV *cb_global, *cb_object, *cb_player, *cb_client, *cb_type, *cb_map;
65 65
66////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 66//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
67 67
68static SV * 68static SV *
69newSVptr (void *ptr, const char *klass, HV *hv = newHV ()) 69newSVptr (void *ptr, const char *klass, HV *hv = newHV ())
412 412
413 switch (type) 413 switch (type)
414 { 414 {
415 case DT_OBJECT: INVOKE_OBJECT (REATTACH, obj); break; 415 case DT_OBJECT: INVOKE_OBJECT (REATTACH, obj); break;
416 case DT_PLAYER: INVOKE_PLAYER (REATTACH, obj); break; 416 case DT_PLAYER: INVOKE_PLAYER (REATTACH, obj); break;
417 case DT_CLIENT: INVOKE_CLIENT (REATTACH, obj); break;
417 case DT_MAP: INVOKE_MAP (REATTACH, obj); break; 418 case DT_MAP: INVOKE_MAP (REATTACH, obj); break;
418 } 419 }
419} 420}
420 421
421template<class subclass> 422template<class subclass>
906 AV *callbacks = 0; 907 AV *callbacks = 0;
907 908
908 object *op; 909 object *op;
909 player *pl; 910 player *pl;
910 maptile *map; 911 maptile *map;
912 client *ns;
911 913
912 // callback call ordering is: 914 // callback call ordering is:
913 // 1. per-object callback 915 // 1. per-object callback
914 // 2. per-class object 916 // 2. per-class object
915 // 3. per-type callback 917 // 3. per-type callback
973 gather_callbacks (callbacks, map->cb, event); 975 gather_callbacks (callbacks, map->cb, event);
974 976
975 gather_callbacks (callbacks, cb_map, event); 977 gather_callbacks (callbacks, cb_map, event);
976 break; 978 break;
977 979
980 case KLASS_CLIENT:
981 dt = (data_type) va_arg (ap, int);
982 assert (("first argument must be of type client", dt == DT_CLIENT));
983 ns = va_arg (ap, client *);
984
985 if (ns->cb)
986 gather_callbacks (callbacks, ns->cb, event);
987
988 gather_callbacks (callbacks, cb_client, event);
989 break;
990
978 default: 991 default:
979 assert (("unsupported event klass in cfperl_invoke", 0)); 992 assert (("unsupported event klass in cfperl_invoke", 0));
980 } 993 }
981 994
982 // short-circuit processing if no callbacks found/defined 995 // short-circuit processing if no callbacks found/defined
995 1008
996 switch (KLASS_OF (event)) 1009 switch (KLASS_OF (event))
997 { 1010 {
998 case KLASS_OBJECT: PUSHs (sv_2mortal (newSVdt (DT_OBJECT, op))); break; 1011 case KLASS_OBJECT: PUSHs (sv_2mortal (newSVdt (DT_OBJECT, op))); break;
999 case KLASS_PLAYER: PUSHs (sv_2mortal (newSVdt (DT_PLAYER, pl))); break; 1012 case KLASS_PLAYER: PUSHs (sv_2mortal (newSVdt (DT_PLAYER, pl))); break;
1013 case KLASS_CLIENT: PUSHs (sv_2mortal (newSVdt (DT_CLIENT, pl))); break;
1000 case KLASS_MAP: PUSHs (sv_2mortal (newSVdt (DT_MAP, map))); break; 1014 case KLASS_MAP: PUSHs (sv_2mortal (newSVdt (DT_MAP, map))); break;
1001 } 1015 }
1002 1016
1003 for (;;) 1017 for (;;)
1004 { 1018 {
1147 const_iv (POTION) 1161 const_iv (POTION)
1148 const_iv (FOOD) 1162 const_iv (FOOD)
1149 const_iv (POISON) 1163 const_iv (POISON)
1150 const_iv (BOOK) 1164 const_iv (BOOK)
1151 const_iv (CLOCK) 1165 const_iv (CLOCK)
1152 const_iv (LIGHTNING)
1153 const_iv (ARROW) 1166 const_iv (ARROW)
1154 const_iv (BOW) 1167 const_iv (BOW)
1155 const_iv (WEAPON) 1168 const_iv (WEAPON)
1156 const_iv (ARMOUR) 1169 const_iv (ARMOUR)
1157 const_iv (PEDESTAL) 1170 const_iv (PEDESTAL)
1206 const_iv (FLOOR) 1219 const_iv (FLOOR)
1207 const_iv (FLESH) 1220 const_iv (FLESH)
1208 const_iv (INORGANIC) 1221 const_iv (INORGANIC)
1209 const_iv (SKILL_TOOL) 1222 const_iv (SKILL_TOOL)
1210 const_iv (LIGHTER) 1223 const_iv (LIGHTER)
1211 const_iv (TRAP_PART)
1212 const_iv (WALL) 1224 const_iv (BUILDABLE_WALL)
1213 const_iv (LIGHT_SOURCE)
1214 const_iv (MISC_OBJECT) 1225 const_iv (MISC_OBJECT)
1215 const_iv (MONSTER)
1216 const_iv (SPAWN_GENERATOR)
1217 const_iv (LAMP) 1226 const_iv (LAMP)
1218 const_iv (DUPLICATOR) 1227 const_iv (DUPLICATOR)
1219 const_iv (TOOL)
1220 const_iv (SPELLBOOK) 1228 const_iv (SPELLBOOK)
1221 const_iv (BUILDFAC)
1222 const_iv (CLOAK) 1229 const_iv (CLOAK)
1223 const_iv (SPINNER) 1230 const_iv (SPINNER)
1224 const_iv (GATE) 1231 const_iv (GATE)
1225 const_iv (BUTTON) 1232 const_iv (BUTTON)
1226 const_iv (CF_HANDLE) 1233 const_iv (CF_HANDLE)
1233 const_iv (SPELL_EFFECT) 1240 const_iv (SPELL_EFFECT)
1234 const_iv (CONVERTER) 1241 const_iv (CONVERTER)
1235 const_iv (BRACERS) 1242 const_iv (BRACERS)
1236 const_iv (POISONING) 1243 const_iv (POISONING)
1237 const_iv (SAVEBED) 1244 const_iv (SAVEBED)
1238 const_iv (POISONCLOUD)
1239 const_iv (FIREHOLES)
1240 const_iv (WAND) 1245 const_iv (WAND)
1241 const_iv (SCROLL) 1246 const_iv (SCROLL)
1242 const_iv (DIRECTOR) 1247 const_iv (DIRECTOR)
1243 const_iv (GIRDLE) 1248 const_iv (GIRDLE)
1244 const_iv (FORCE) 1249 const_iv (FORCE)
1259 const_iv (DISEASE) 1264 const_iv (DISEASE)
1260 const_iv (SYMPTOM) 1265 const_iv (SYMPTOM)
1261 const_iv (BUILDER) 1266 const_iv (BUILDER)
1262 const_iv (MATERIAL) 1267 const_iv (MATERIAL)
1263 const_iv (ITEM_TRANSFORMER) 1268 const_iv (ITEM_TRANSFORMER)
1264 const_iv (QUEST)
1265 1269
1266 const_iv (NUM_SUBTYPES) 1270 const_iv (NUM_SUBTYPES)
1267 1271
1268 const_iv (ST_BD_BUILD) 1272 const_iv (ST_BD_BUILD)
1269 const_iv (ST_BD_REMOVE) 1273 const_iv (ST_BD_REMOVE)
1454 const_iv (F_BUY) 1458 const_iv (F_BUY)
1455 const_iv (F_SHOP) 1459 const_iv (F_SHOP)
1456 const_iv (F_SELL) 1460 const_iv (F_SELL)
1457 1461
1458 const_iv (P_BLOCKSVIEW) 1462 const_iv (P_BLOCKSVIEW)
1463 const_iv (P_PLAYER)
1459 const_iv (P_NO_MAGIC) 1464 const_iv (P_NO_MAGIC)
1460 const_iv (P_IS_ALIVE) 1465 const_iv (P_IS_ALIVE)
1461 const_iv (P_NO_CLERIC) 1466 const_iv (P_NO_CLERIC)
1462 const_iv (P_NEED_UPDATE) 1467 const_iv (P_NEED_UPDATE)
1463 const_iv (P_NO_ERROR)
1464 const_iv (P_OUT_OF_MAP) 1468 const_iv (P_OUT_OF_MAP)
1465 const_iv (P_NEW_MAP) 1469 const_iv (P_NEW_MAP)
1466 1470
1467 const_iv (UP_OBJ_INSERT) 1471 const_iv (UP_OBJ_INSERT)
1468 const_iv (UP_OBJ_REMOVE) 1472 const_iv (UP_OBJ_REMOVE)
1614 const_iv (MAP_LOADING) 1618 const_iv (MAP_LOADING)
1615 const_iv (MAP_SAVING) 1619 const_iv (MAP_SAVING)
1616 1620
1617 const_iv (KLASS_GLOBAL) 1621 const_iv (KLASS_GLOBAL)
1618 const_iv (KLASS_OBJECT) 1622 const_iv (KLASS_OBJECT)
1623 const_iv (KLASS_CLIENT)
1619 const_iv (KLASS_PLAYER) 1624 const_iv (KLASS_PLAYER)
1620 const_iv (KLASS_MAP) 1625 const_iv (KLASS_MAP)
1621 }; 1626 };
1622 1627
1623 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 1628 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
1649void _init_vars () 1654void _init_vars ()
1650 CODE: 1655 CODE:
1651 cb_global = get_av ("cf::CB_GLOBAL", 1); 1656 cb_global = get_av ("cf::CB_GLOBAL", 1);
1652 cb_object = get_av ("cf::CB_OBJECT", 1); 1657 cb_object = get_av ("cf::CB_OBJECT", 1);
1653 cb_player = get_av ("cf::CB_PLAYER", 1); 1658 cb_player = get_av ("cf::CB_PLAYER", 1);
1659 cb_client = get_av ("cf::CB_CLIENT", 1);
1654 cb_type = get_av ("cf::CB_TYPE" , 1); 1660 cb_type = get_av ("cf::CB_TYPE" , 1);
1655 cb_map = get_av ("cf::CB_MAP" , 1); 1661 cb_map = get_av ("cf::CB_MAP" , 1);
1656 1662
1657void _global_reattach () 1663void _global_reattach ()
1658 CODE: 1664 CODE:
1659{ 1665{
1660 // reattach to all attachable objects in the game. 1666 // reattach to all attachable objects in the game.
1667 for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i)
1668 reattach (*i);
1669
1661 for (player *pl = first_player; pl; pl = pl->next) 1670 for (player *pl = first_player; pl; pl = pl->next)
1662 reattach (pl); 1671 reattach (pl);
1663 1672
1664 for (maptile *map = first_map; map; map = map->next) 1673 for (maptile *map = first_map; map; map = map->next)
1665 reattach (map); 1674 reattach (map);
1666 1675
1667 for (object *op = object::first; op; op = op->next) 1676 for (object *op = object::first; op; op = op->next)
1668 reattach (op); 1677 reattach (op);
1669} 1678}
1670
1671bool
1672add_client (int fd, const char *peername)
1673 1679
1674NV floor (NV x) 1680NV floor (NV x)
1675 1681
1676NV ceil (NV x) 1682NV ceil (NV x)
1677 1683
1779 RETVAL = newSVpv (resist_plus[atnr], 0); 1785 RETVAL = newSVpv (resist_plus[atnr], 0);
1780 else 1786 else
1781 XSRETURN_UNDEF; 1787 XSRETURN_UNDEF;
1782 OUTPUT: RETVAL 1788 OUTPUT: RETVAL
1783 1789
1790MODULE = cf PACKAGE = cf::attachable
1791
1784int 1792int
1785_valid (SV *obj) 1793valid (SV *obj)
1786 CODE: 1794 CODE:
1787 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); 1795 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext);
1788 OUTPUT: 1796 OUTPUT:
1789 RETVAL 1797 RETVAL
1790 1798
2446 RETVAL = INVOKE_((event_type)event, ARG_CLIENT (ns), ARG_AV (av)); 2454 RETVAL = INVOKE_((event_type)event, ARG_CLIENT (ns), ARG_AV (av));
2447 OUTPUT: RETVAL 2455 OUTPUT: RETVAL
2448 2456
2449SV *registry (client *ns) 2457SV *registry (client *ns)
2450 2458
2459client *
2460create (int fd, const char *peername)
2461 CODE:
2462 RETVAL = client::create (fd, peername);
2463 OUTPUT:
2464 RETVAL
2465
2451void 2466void
2452client::destroy () 2467client::destroy ()
2453 2468

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines