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.65 by root, Tue Nov 7 16:30:55 2006 UTC vs.
Revision 1.70 by elmex, Mon Dec 4 15:15:34 2006 UTC

51 51
52static f_plug_api gethook = cfapi_get_hooks; 52static f_plug_api gethook = cfapi_get_hooks;
53static f_plug_api object_set_property = cfapi_object_set_property; 53static f_plug_api object_set_property = cfapi_object_set_property;
54static f_plug_api object_insert = cfapi_object_insert; 54static f_plug_api object_insert = cfapi_object_insert;
55 55
56static HV *obj_cache;
57static PerlInterpreter *perl; 56static PerlInterpreter *perl;
58 57
59static AV *cb_global, *cb_object, *cb_player, *cb_type, *cb_map; 58static AV *cb_global, *cb_object, *cb_player, *cb_type, *cb_map;
60 59
61////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 60//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
81 80
82 if (!obj->self) 81 if (!obj->self)
83 obj->self = newSVptr (obj, klass); 82 obj->self = newSVptr (obj, klass);
84 83
85 return newSVsv (obj->self); 84 return newSVsv (obj->self);
86}
87
88static void
89SVptr_cache_set (void *ptr, SV *sv)
90{
91 hv_store (obj_cache, (char *)&ptr, sizeof (ptr), sv, 0);
92}
93
94static SV *
95SVptr_cache_get (void *ptr)
96{
97 SV **he = hv_fetch (obj_cache, (char *)&ptr, sizeof (ptr), 0);
98
99 return he ? *he : 0;
100}
101
102static SV *
103newSVptr_cached (void *ptr, const char *klass)
104{
105 SV *sv;
106
107 if (!ptr)
108 return &PL_sv_undef;
109
110 sv = SVptr_cache_get (ptr);
111
112 if (!sv)
113 {
114 HV *hv = newHV ();
115 sv_magic ((SV *)hv, 0, PERL_MAGIC_ext, (char *)ptr, 0);
116 sv = sv_bless (newRV_noinc ((SV *)hv), gv_stashpv (klass, 1));
117
118 SVptr_cache_set (ptr, sv);
119 }
120
121 return newSVsv (sv);
122} 85}
123 86
124static void 87static void
125clearSVptr (SV *sv) 88clearSVptr (SV *sv)
126{ 89{
182 145
183//TODO: 146//TODO:
184inline SV *to_sv (New_Face * v) { return to_sv (v->name); } 147inline SV *to_sv (New_Face * v) { return to_sv (v->name); }
185inline SV *to_sv (treasurelist * v) { return to_sv (v->name); } 148inline SV *to_sv (treasurelist * v) { return to_sv (v->name); }
186 149
150inline SV *to_sv (UUID v)
151{
152 char buf[128];
153 snprintf (buf, 128, "<1,%llx>", (unsigned long long)v.seq);
154 return newSVpv (buf, 0);
155}
156
187inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? SvPV_nolen (sv) : 0; } 157inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? SvPV_nolen (sv) : 0; }
188inline void sv_to (SV *sv, char * &v) { free (v); v = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; } //TODO: verify that all simple pointers are strdup-managed 158inline void sv_to (SV *sv, char * &v) { free (v); v = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; } //TODO: verify that all simple pointers are strdup-managed
189inline void sv_to (SV *sv, bool &v) { v = SvIV (sv); } 159inline void sv_to (SV *sv, bool &v) { v = SvIV (sv); }
190inline void sv_to (SV *sv, signed char &v) { v = SvIV (sv); } 160inline void sv_to (SV *sv, signed char &v) { v = SvIV (sv); }
191inline void sv_to (SV *sv, unsigned char &v) { v = SvIV (sv); } 161inline void sv_to (SV *sv, unsigned char &v) { v = SvIV (sv); }
214inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; } 184inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; }
215 185
216template<int N> 186template<int N>
217inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); } 187inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); }
218 188
189inline void sv_to (SV *sv, UUID &v)
190{
191 unsigned int version;
192 unsigned long long seq;
193
194 if (2 != sscanf (SvPV_nolen (sv), "<%d.%llx>", &version, &seq) || 1 != version)
195 croak ("unparsable uuid: %s", SvPV_nolen (sv));
196
197 v.seq = seq;
198}
199
219static SV * 200static SV *
220newSVdt_va (va_list &ap, data_type type) 201newSVdt_va (va_list &ap, data_type type)
221{ 202{
222 SV *sv; 203 SV *sv;
223 204
900 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl)) 881 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl))
901 { 882 {
902 printf ("unable to initialize perl-interpreter, aborting.\n"); 883 printf ("unable to initialize perl-interpreter, aborting.\n");
903 exit (EXIT_FAILURE); 884 exit (EXIT_FAILURE);
904 } 885 }
905
906 obj_cache = newHV ();
907} 886}
908 887
909void cfperl_main () 888void cfperl_main ()
910{ 889{
911 dSP; 890 dSP;
2041void kill_player (object *op) 2020void kill_player (object *op)
2042 2021
2043void esrv_update_item (object *op, int what, object *item) 2022void esrv_update_item (object *op, int what, object *item)
2044 C_ARGS: what, op, item 2023 C_ARGS: what, op, item
2045 2024
2025void clear_los (object *op)
2026
2027int command_reset (object *op, char *params)
2028
2029int command_teleport (object *op, char *params)
2030
2031int command_summon (object *op, char *params)
2032
2033int command_arrest (object *op, char *params)
2034
2035int command_kick (object *op, char *params)
2036
2037int command_banish (object *op, char *params)
2038
2039
2046MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ 2040MODULE = cf PACKAGE = cf::player PREFIX = cf_player_
2047 2041
2048INCLUDE: $PERL genacc player ../include/newserver.h ../include/player.h | 2042INCLUDE: $PERL genacc player ../include/newserver.h ../include/player.h |
2049 2043
2050char * 2044char *
2319 case 7: RETVAL = newSVuv ( GET_MAP_MOVE_OFF (obj, x, y)); break; 2313 case 7: RETVAL = newSVuv ( GET_MAP_MOVE_OFF (obj, x, y)); break;
2320 } 2314 }
2321 OUTPUT: 2315 OUTPUT:
2322 RETVAL 2316 RETVAL
2323 2317
2318void fix_walls (maptile *map, int x, int y)
2319
2320void fix_walls_around (maptile *map, int x, int y)
2324 2321
2325MODULE = cf PACKAGE = cf::arch 2322MODULE = cf PACKAGE = cf::arch
2326 2323
2327archetype *find (const char *name) 2324archetype *find (const char *name)
2328 CODE: 2325 CODE:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines