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.52 by root, Tue May 9 17:48:28 2006 UTC vs.
Revision 1.56 by root, Tue Jul 11 14:24:16 2006 UTC

45#include <plugin_common.h> 45#include <plugin_common.h>
46#include <sounds.h> 46#include <sounds.h>
47 47
48#include <stdarg.h> 48#include <stdarg.h>
49 49
50//#include "EventAPI.h"
50#include "perlxsi.c" 51#include "perlxsi.c"
51 52
52typedef object object_ornull; 53typedef object object_ornull;
53typedef mapstruct mapstruct_ornull; 54typedef mapstruct mapstruct_ornull;
54 55
427 registerGlobalEvent (NULL, EVENT_MUZZLE, PLUGIN_NAME, globalEventListener); 428 registerGlobalEvent (NULL, EVENT_MUZZLE, PLUGIN_NAME, globalEventListener);
428 registerGlobalEvent (NULL, EVENT_KICK, PLUGIN_NAME, globalEventListener); 429 registerGlobalEvent (NULL, EVENT_KICK, PLUGIN_NAME, globalEventListener);
429 registerGlobalEvent (NULL, EVENT_FREE_OB, PLUGIN_NAME, globalEventListener); 430 registerGlobalEvent (NULL, EVENT_FREE_OB, PLUGIN_NAME, globalEventListener);
430 registerGlobalEvent (NULL, EVENT_PLAYER_LOAD, PLUGIN_NAME, globalEventListener); 431 registerGlobalEvent (NULL, EVENT_PLAYER_LOAD, PLUGIN_NAME, globalEventListener);
431 registerGlobalEvent (NULL, EVENT_PLAYER_SAVE, PLUGIN_NAME, globalEventListener); 432 registerGlobalEvent (NULL, EVENT_PLAYER_SAVE, PLUGIN_NAME, globalEventListener);
433 registerGlobalEvent (NULL, EVENT_EXTCMD, PLUGIN_NAME, globalEventListener);
432 434
433 char *argv[] = { 435 char *argv[] = {
434 "", 436 "",
435 "-e" 437 "-e"
436 "BEGIN {" 438 "BEGIN {"
442 }; 444 };
443 445
444 perl = perl_alloc (); 446 perl = perl_alloc ();
445 perl_construct (perl); 447 perl_construct (perl);
446 448
449 PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
450
447 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl)) 451 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl))
448 { 452 {
449 printf ("unable to initialize perl-interpreter, continuing without.\n"); 453 printf ("unable to initialize perl-interpreter, continuing without.\n");
450 454
451 perl_destruct (perl); 455 perl_destruct (perl);
485 if (sv) 489 if (sv)
486 clearSVptr (sv); 490 clearSVptr (sv);
487 491
488 rv = 0; 492 rv = 0;
489 } 493 }
494 else if (event_code == EVENT_CLOCK)
495 {
496 dSP;
497
498 clean_obj_cache ();
499
500 ENTER;
501 SAVETMPS;
502 PUSHMARK (SP);
503 XPUSHs (sv_2mortal (newSViv (0)));
504 PUTBACK;
505 call_pv ("Event::one_event", G_DISCARD | G_EVAL);
506 SPAGAIN;
507 FREETMPS;
508 LEAVE;
509 }
490 else 510 else
491 { 511 {
492 dSP; 512 dSP;
493 513
494 ENTER; 514 ENTER;
542 case EVENT_KICK: 562 case EVENT_KICK:
543 PUSH_OB; 563 PUSH_OB;
544 PUSH_PV; 564 PUSH_PV;
545 break; 565 break;
546 566
547 case EVENT_CLOCK: 567 case EVENT_EXTCMD:
548 clean_obj_cache (); 568 PUSH_PL;
569 {
570 char *buf = va_arg (args, char *);
571 int len = va_arg (args, int);
572 PUSHs (sv_2mortal (newSVpvn (buf, len)));
573 }
549 break; 574 break;
550 575
551 case EVENT_TELL: 576 case EVENT_TELL:
552 break; 577 break;
553 } 578 }
1117 const_iv (SOUND_CLOCK) 1142 const_iv (SOUND_CLOCK)
1118 const_iv (SOUND_TURN_HANDLE) 1143 const_iv (SOUND_TURN_HANDLE)
1119 const_iv (SOUND_FALL_HOLE) 1144 const_iv (SOUND_FALL_HOLE)
1120 const_iv (SOUND_DRINK_POISON) 1145 const_iv (SOUND_DRINK_POISON)
1121 const_iv (SOUND_CAST_SPELL_0) 1146 const_iv (SOUND_CAST_SPELL_0)
1147
1148 const_iv (MAP_FLUSH)
1149 const_iv (MAP_PLAYER_UNIQUE)
1150 const_iv (MAP_BLOCK)
1151 const_iv (MAP_STYLE)
1152 const_iv (MAP_OVERLAY)
1153
1154 const_iv (MAP_IN_MEMORY)
1155 const_iv (MAP_SWAPPED)
1156 const_iv (MAP_LOADING)
1157 const_iv (MAP_SAVING)
1122 }; 1158 };
1123 1159
1124 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 1160 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
1125 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 1161 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
1126 1162
1143 const_event (CLOSE) 1179 const_event (CLOSE)
1144 const_event (TIMER) 1180 const_event (TIMER)
1145 const_event (MOVE) 1181 const_event (MOVE)
1146 1182
1147 const_event (BORN) 1183 const_event (BORN)
1148 const_event (CLOCK) 1184 //const_event (CLOCK)
1149 const_event (CRASH) 1185 const_event (CRASH)
1150 const_event (PLAYER_DEATH) 1186 const_event (PLAYER_DEATH)
1151 const_event (PLAYER_LOAD) 1187 const_event (PLAYER_LOAD)
1152 const_event (PLAYER_SAVE) 1188 const_event (PLAYER_SAVE)
1153 const_event (GKILL) 1189 const_event (GKILL)
1163 const_event (REMOVE) 1199 const_event (REMOVE)
1164 const_event (SHOUT) 1200 const_event (SHOUT)
1165 const_event (TELL) 1201 const_event (TELL)
1166 const_event (MUZZLE) 1202 const_event (MUZZLE)
1167 const_event (KICK) 1203 const_event (KICK)
1204 const_event (EXTCMD)
1168 //const_event (FREE_OB) 1205 //const_event (FREE_OB)
1169 }; 1206 };
1170 1207
1171 AV *av = get_av ("cf::EVENT", 1); 1208 AV *av = get_av ("cf::EVENT", 1);
1172 1209
1306 for (cprop = prop_table + sizeof (prop_table) / sizeof (prop_table [0]); cprop-- > prop_table; ) 1343 for (cprop = prop_table + sizeof (prop_table) / sizeof (prop_table [0]); cprop-- > prop_table; )
1307 { 1344 {
1308 hv_store (prop_type, cprop->name, strlen (cprop->name), newSViv (cprop->dtype), 0); 1345 hv_store (prop_type, cprop->name, strlen (cprop->name), newSViv (cprop->dtype), 0);
1309 hv_store (prop_idx, cprop->name, strlen (cprop->name), newSViv (cprop->idx ), 0); 1346 hv_store (prop_idx, cprop->name, strlen (cprop->name), newSViv (cprop->idx ), 0);
1310 } 1347 }
1348
1349 //I_EVENT_API (PACKAGE);
1311} 1350}
1312 1351
1313void 1352void
1314LOG (int level, char *msg) 1353LOG (int level, char *msg)
1315 PROTOTYPE: $$ 1354 PROTOTYPE: $$
1316 C_ARGS: level, "%s", msg 1355 C_ARGS: level, "%s", msg
1356
1357char *path_combine (char *base, char *path)
1358 PROTOTYPE: $$
1359
1360char *path_combine_and_normalize (char *base, char *path)
1361 PROTOTYPE: $$
1317 1362
1318char * 1363char *
1319cf_get_maps_directory (char *path) 1364cf_get_maps_directory (char *path)
1320 PROTOTYPE: $ 1365 PROTOTYPE: $
1321 ALIAS: maps_directory = 0 1366 ALIAS: maps_directory = 0
1633player *next (player *pl) 1678player *next (player *pl)
1634 CODE: 1679 CODE:
1635 RETVAL = pl->next; 1680 RETVAL = pl->next;
1636 OUTPUT: RETVAL 1681 OUTPUT: RETVAL
1637 1682
1683bool
1684cell_visible (player *pl, int dx, int dy)
1685 CODE:
1686 RETVAL = FABS (dx) <= pl->socket.mapx / 2 && FABS (dy) <= pl->socket.mapy / 2
1687 && !pl->blocked_los [dx + pl->socket.mapx / 2][dy + pl->socket.mapy / 2];
1688 OUTPUT:
1689 RETVAL
1690
1691void
1692send (player *pl, SV *packet)
1693 CODE:
1694{
1695 STRLEN len;
1696 char *buf = SvPVbyte (packet, len);
1697
1698 Write_String_To_Socket (&pl->socket, buf, len);
1699}
1700
1638int 1701int
1639listening (player *pl, int new_value = -1) 1702listening (player *pl, int new_value = -1)
1640 CODE: 1703 CODE:
1641 RETVAL = pl->listening; 1704 RETVAL = pl->listening;
1642 if (new_value >= 0) 1705 if (new_value >= 0)
1725 1788
1726void clean_tmp_map (mapstruct *map) 1789void clean_tmp_map (mapstruct *map)
1727 1790
1728void play_sound_map (mapstruct *map, int x, int y, int sound_num) 1791void play_sound_map (mapstruct *map, int x, int y, int sound_num)
1729 1792
1793mapstruct *tile_map (mapstruct *map, unsigned int dir)
1794 CODE:
1795 RETVAL = dir < 4 ? map->tile_map [dir] : 0;
1796 OUTPUT:
1797 RETVAL
1798
1799char *tile_path (mapstruct *map, unsigned int dir)
1800 CODE:
1801 if (dir >= 4)
1802 XSRETURN_UNDEF;
1803 RETVAL = map->tile_path [dir];
1804 OUTPUT:
1805 RETVAL
1806
1730mapstruct *cf_map_get_map (char *name) 1807mapstruct *cf_map_get_map (char *name)
1731 PROTOTYPE: $ 1808 PROTOTYPE: $
1732 ALIAS: map = 0 1809 ALIAS: map = 0
1733 1810
1811mapstruct *has_been_loaded (char *name)
1812 PROTOTYPE: $
1813
1734mapstruct *cf_map_get_first () 1814mapstruct *cf_map_get_first ()
1735 PROTOTYPE: 1815 PROTOTYPE:
1736 ALIAS: first = 0 1816 ALIAS: first = 0
1737 1817
1738# whoever "designed" the plug-in api should have wasted 1818# whoever "designed" the plug-in api should have wasted
1739# his/her time with staying away form the project - would have 1819# his/her time with staying away from the project - would have
1740# saved others a lot of time, without doubt. 1820# saved others a lot of time, without doubt.
1741void set_path (mapstruct *where, char *path) 1821void set_path (mapstruct *where, char *path)
1742 CODE: 1822 CODE:
1743 strcpy (where->path, path); 1823 strcpy (where->path, path);
1824
1825int in_memory (mapstruct *map)
1826 CODE:
1827 RETVAL = map->in_memory;
1828 OUTPUT:
1829 RETVAL
1744 1830
1745bool unique (mapstruct *map) 1831bool unique (mapstruct *map)
1746 CODE: 1832 CODE:
1747 RETVAL = map->unique; 1833 RETVAL = map->unique;
1748 OUTPUT: 1834 OUTPUT:
1757object *cf_map_insert_object (mapstruct *where, object* op, int x, int y) 1843object *cf_map_insert_object (mapstruct *where, object* op, int x, int y)
1758 1844
1759object* cf_map_present_arch_by_name (mapstruct *map, const char* str, int nx, int ny) 1845object* cf_map_present_arch_by_name (mapstruct *map, const char* str, int nx, int ny)
1760 C_ARGS: str, map, nx, ny 1846 C_ARGS: str, map, nx, ny
1761 1847
1762#int cf_map_get_flags (mapstruct* map, mapstruct** nmap, I16 x, I16 y, I16 *nx, I16 *ny)
1763
1764void 1848void
1849cf_map_normalise (mapstruct *map, int x, int y)
1850 PPCODE:
1851{
1852 mapstruct *nmap = 0;
1853 I16 nx = 0, ny = 0;
1854 int flags = cf_map_get_flags (map, &nmap, x, y, &nx, &ny);
1855
1856 EXTEND (SP, 4);
1857 PUSHs (sv_2mortal (newSViv (flags)));
1858
1859 if (GIMME_V == G_ARRAY)
1860 {
1861 PUSHs (sv_2mortal (newSVcfapi (CFAPI_PMAP, nmap)));
1862 PUSHs (sv_2mortal (newSViv (nx)));
1863 PUSHs (sv_2mortal (newSViv (ny)));
1864 }
1865}
1866
1867void
1765at (mapstruct *obj, unsigned int x, unsigned int y) 1868at (mapstruct *map, unsigned int x, unsigned int y)
1766 PROTOTYPE: $$$ 1869 PROTOTYPE: $$$
1767 INIT:
1768 if (x >= MAP_WIDTH (obj) || y >= MAP_HEIGHT (obj)) XSRETURN_EMPTY;
1769 PPCODE: 1870 PPCODE:
1770{ 1871{
1771 object *o; 1872 object *o;
1772 1873 mapstruct *nmap = 0;
1874 I16 nx, ny;
1875
1876 cf_map_get_flags (map, &nmap, x, y, &nx, &ny);
1877
1878 if (nmap)
1773 for (o = GET_MAP_OB (obj, x, y); o; o = o->above) 1879 for (o = GET_MAP_OB (nmap, nx, ny); o; o = o->above)
1774 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); 1880 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o)));
1775} 1881}
1776 1882
1777SV * 1883SV *
1778bot_at (mapstruct *obj, unsigned int x, unsigned int y) 1884bot_at (mapstruct *obj, unsigned int x, unsigned int y)
1779 PROTOTYPE: $$$ 1885 PROTOTYPE: $$$

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines