… | |
… | |
51 | |
51 | |
52 | static f_plug_api gethook = cfapi_get_hooks; |
52 | static f_plug_api gethook = cfapi_get_hooks; |
53 | static f_plug_api object_set_property = cfapi_object_set_property; |
53 | static f_plug_api object_set_property = cfapi_object_set_property; |
54 | static f_plug_api object_insert = cfapi_object_insert; |
54 | static f_plug_api object_insert = cfapi_object_insert; |
55 | |
55 | |
56 | static HV *obj_cache; |
|
|
57 | static PerlInterpreter *perl; |
56 | static PerlInterpreter *perl; |
58 | |
57 | |
59 | static AV *cb_global, *cb_object, *cb_player, *cb_type, *cb_map; |
58 | static 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 | |
|
|
88 | static void |
|
|
89 | SVptr_cache_set (void *ptr, SV *sv) |
|
|
90 | { |
|
|
91 | hv_store (obj_cache, (char *)&ptr, sizeof (ptr), sv, 0); |
|
|
92 | } |
|
|
93 | |
|
|
94 | static SV * |
|
|
95 | SVptr_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 | |
|
|
102 | static SV * |
|
|
103 | newSVptr_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 | |
124 | static void |
87 | static void |
125 | clearSVptr (SV *sv) |
88 | clearSVptr (SV *sv) |
126 | { |
89 | { |
… | |
… | |
182 | |
145 | |
183 | //TODO: |
146 | //TODO: |
184 | inline SV *to_sv (New_Face * v) { return to_sv (v->name); } |
147 | inline SV *to_sv (New_Face * v) { return to_sv (v->name); } |
185 | inline SV *to_sv (treasurelist * v) { return to_sv (v->name); } |
148 | inline SV *to_sv (treasurelist * v) { return to_sv (v->name); } |
186 | |
149 | |
|
|
150 | inline 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 | |
187 | inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? SvPV_nolen (sv) : 0; } |
157 | inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? SvPV_nolen (sv) : 0; } |
188 | inline 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 |
158 | inline 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 |
189 | inline void sv_to (SV *sv, bool &v) { v = SvIV (sv); } |
159 | inline void sv_to (SV *sv, bool &v) { v = SvIV (sv); } |
190 | inline void sv_to (SV *sv, signed char &v) { v = SvIV (sv); } |
160 | inline void sv_to (SV *sv, signed char &v) { v = SvIV (sv); } |
191 | inline void sv_to (SV *sv, unsigned char &v) { v = SvIV (sv); } |
161 | inline void sv_to (SV *sv, unsigned char &v) { v = SvIV (sv); } |
… | |
… | |
214 | inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; } |
184 | inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; } |
215 | |
185 | |
216 | template<int N> |
186 | template<int N> |
217 | inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); } |
187 | inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); } |
218 | |
188 | |
|
|
189 | inline 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 | |
219 | static SV * |
200 | static SV * |
220 | newSVdt_va (va_list &ap, data_type type) |
201 | newSVdt_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 | |
909 | void cfperl_main () |
888 | void cfperl_main () |
910 | { |
889 | { |
911 | dSP; |
890 | dSP; |
… | |
… | |
2043 | void esrv_update_item (object *op, int what, object *item) |
2022 | void esrv_update_item (object *op, int what, object *item) |
2044 | C_ARGS: what, op, item |
2023 | C_ARGS: what, op, item |
2045 | |
2024 | |
2046 | void clear_los (object *op) |
2025 | void clear_los (object *op) |
2047 | |
2026 | |
|
|
2027 | int command_reset (object *op, char *params) |
|
|
2028 | |
|
|
2029 | int command_teleport (object *op, char *params) |
|
|
2030 | |
|
|
2031 | int command_summon (object *op, char *params) |
|
|
2032 | |
|
|
2033 | int command_arrest (object *op, char *params) |
|
|
2034 | |
|
|
2035 | int command_kick (object *op, char *params) |
|
|
2036 | |
|
|
2037 | int command_banish (object *op, char *params) |
|
|
2038 | |
2048 | |
2039 | |
2049 | MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ |
2040 | MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ |
2050 | |
2041 | |
2051 | INCLUDE: $PERL genacc player ../include/newserver.h ../include/player.h | |
2042 | INCLUDE: $PERL genacc player ../include/newserver.h ../include/player.h | |
2052 | |
2043 | |
… | |
… | |
2322 | 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; |
2323 | } |
2314 | } |
2324 | OUTPUT: |
2315 | OUTPUT: |
2325 | RETVAL |
2316 | RETVAL |
2326 | |
2317 | |
|
|
2318 | void fix_walls (maptile *map, int x, int y) |
|
|
2319 | |
|
|
2320 | void fix_walls_around (maptile *map, int x, int y) |
2327 | |
2321 | |
2328 | MODULE = cf PACKAGE = cf::arch |
2322 | MODULE = cf PACKAGE = cf::arch |
2329 | |
2323 | |
2330 | archetype *find (const char *name) |
2324 | archetype *find (const char *name) |
2331 | CODE: |
2325 | CODE: |