… | |
… | |
33 | |
33 | |
34 | enum event_klass |
34 | enum event_klass |
35 | { |
35 | { |
36 | KLASS_NONE, |
36 | KLASS_NONE, |
37 | KLASS_GLOBAL, |
37 | KLASS_GLOBAL, |
|
|
38 | KLASS_SOCKET, |
38 | KLASS_PLAYER, |
39 | KLASS_PLAYER, |
39 | KLASS_OBJECT, |
40 | KLASS_OBJECT, |
40 | KLASS_MAP, |
41 | KLASS_MAP, |
|
|
42 | KLASS_COMMAND, |
41 | }; |
43 | }; |
42 | |
44 | |
43 | enum event_type |
45 | enum event_type |
44 | { |
46 | { |
45 | # define def(klass,name) EVENT_ ## klass ## _ ## name, |
47 | # define def(klass,name) EVENT_ ## klass ## _ ## name, |
… | |
… | |
58 | #define ARG_MAP(o) DT_MAP , (void *)static_cast<maptile *> (o) |
60 | #define ARG_MAP(o) DT_MAP , (void *)static_cast<maptile *> (o) |
59 | #define ARG_PLAYER(o) DT_PLAYER, (void *)static_cast<player *> (o) |
61 | #define ARG_PLAYER(o) DT_PLAYER, (void *)static_cast<player *> (o) |
60 | #define ARG_ARCH(o) DT_ARCH , (void *)static_cast<archetype *> (o) |
62 | #define ARG_ARCH(o) DT_ARCH , (void *)static_cast<archetype *> (o) |
61 | #define ARG_PARTY(o) DT_PARTY , (void *)static_cast<party *> (o) |
63 | #define ARG_PARTY(o) DT_PARTY , (void *)static_cast<party *> (o) |
62 | #define ARG_REGION(o) DT_REGION, (void *)static_cast<region *> (o) |
64 | #define ARG_REGION(o) DT_REGION, (void *)static_cast<region *> (o) |
|
|
65 | #define ARG_SOCKET(o) DT_SOCKET, (void *)static_cast<client_socket *> (o) |
63 | |
66 | |
64 | // the ", ## __VA_ARGS" is, unfortunately, a gnu-cpp extension |
67 | // the ", ## __VA_ARGS" is, unfortunately, a gnu-cpp extension |
65 | |
68 | |
66 | // all these return true when the normal event processing should be skipped (if any) |
69 | // all these return true when the normal event processing should be skipped (if any) |
67 | #define INVOKE_(event, ...) cfperl_invoke (event, ## __VA_ARGS__, DT_END) |
70 | #define INVOKE_(event, ...) cfperl_invoke (event, ## __VA_ARGS__, DT_END) |
68 | |
71 | |
69 | #define INVOKE(klass, event, ...) INVOKE_(EVENT_ ## klass ## _ ## event, ## __VA_ARGS__) |
72 | #define INVOKE(klass, event, ...) INVOKE_(EVENT_ ## klass ## _ ## event, ## __VA_ARGS__) |
70 | #define INVOKE_GLOBAL(event, ...) INVOKE_(EVENT_ ## GLOBAL ## _ ## event, ## __VA_ARGS__) |
73 | #define INVOKE_GLOBAL(event, ...) INVOKE_(EVENT_ ## GLOBAL ## _ ## event, ## __VA_ARGS__) |
71 | #define INVOKE_OBJECT(event, op, ...) INVOKE_(EVENT_ ## OBJECT ## _ ## event, ARG_OBJECT (op), ## __VA_ARGS__) |
74 | #define INVOKE_OBJECT(event, op, ...) INVOKE_(EVENT_ ## OBJECT ## _ ## event, ARG_OBJECT (op), ## __VA_ARGS__) |
|
|
75 | #define INVOKE_SOCKET(event, ns, ...) INVOKE_(EVENT_ ## SOCKET ## _ ## event, ARG_SOCKET (ns), ## __VA_ARGS__) |
72 | #define INVOKE_PLAYER(event, pl, ...) INVOKE_(EVENT_ ## PLAYER ## _ ## event, ARG_PLAYER (pl), ## __VA_ARGS__) |
76 | #define INVOKE_PLAYER(event, pl, ...) INVOKE_(EVENT_ ## PLAYER ## _ ## event, ARG_PLAYER (pl), ## __VA_ARGS__) |
73 | #define INVOKE_MAP(event, map, ...) INVOKE_(EVENT_ ## MAP ## _ ## event, ARG_MAP (map) , ## __VA_ARGS__) |
77 | #define INVOKE_MAP(event, map, ...) INVOKE_(EVENT_ ## MAP ## _ ## event, ARG_MAP (map) , ## __VA_ARGS__) |
74 | |
78 | |
75 | //TODO should index into @result |
79 | //TODO should index into @result |
76 | #define RESULT(idx,type) cfperl_result_ ## type (idx) |
80 | #define RESULT(idx,type) cfperl_result_ ## type (idx) |
|
|
81 | #define RESULT_DOUBLE(idx) RESULT(idx, DOUBLE) |
77 | #define RESULT_INT(idx) RESULT(idx, INT) |
82 | #define RESULT_INT(idx) RESULT(idx, INT) |
78 | #define RESULT_MAP(idx) RESULT(idx, MAP) |
|
|
79 | |
83 | |
80 | bool cfperl_invoke (event_type event, ...); |
84 | bool cfperl_invoke (event_type event, ...); |
|
|
85 | double cfperl_result_DOUBLE (int idx); |
81 | int cfperl_result_INT (int idx); |
86 | int cfperl_result_INT (int idx); |
82 | int cfperl_result_MAP (int idx); |
|
|
83 | |
87 | |
84 | struct attachable_base |
88 | struct attachable_base |
85 | { |
89 | { |
86 | SV *self; |
90 | SV *self; // CF+ perl self |
87 | AV *cb; // CF+ perl self and callback |
91 | AV *cb; // CF+ callbacks |
88 | shstr attach; // generic extension attachment information |
92 | shstr attach; // generic extension attachment information |
89 | |
93 | |
90 | void clear (); // called when free'ing objects |
94 | void clear (); // called when free'ing objects |
91 | void optimise (); // possibly save some memory by destroying unneeded data |
95 | void optimise (); // possibly save some memory by destroying unneeded data |
92 | void instantiate (data_type type, void *obj); |
96 | void instantiate (data_type type, void *obj); |
… | |
… | |
111 | attachable_base (const attachable_base &src) |
115 | attachable_base (const attachable_base &src) |
112 | : self (0), cb (0), attach (src.attach) |
116 | : self (0), cb (0), attach (src.attach) |
113 | { |
117 | { |
114 | } |
118 | } |
115 | |
119 | |
116 | attachable_base &operator = (const attachable_base &src) |
120 | attachable_base &operator =(const attachable_base &src) |
117 | { |
121 | { |
118 | clear (); |
122 | clear (); |
119 | attach = src.attach; |
123 | attach = src.attach; |
120 | return *this; |
124 | return *this; |
121 | } |
125 | } |
122 | }; |
126 | }; |
123 | |
127 | |
124 | // objects attachable from perl (or any other extension) should include or |
128 | // objects attachable from perl (or any other extension) should include or |
125 | // derive using the curiously recurring template pattern, to avoid |
129 | // derive using the curiously recurring template pattern, to avoid |
… | |
… | |
247 | void put (keyword k, unsigned long v) { put_(k, (sint64)v); } |
251 | void put (keyword k, unsigned long v) { put_(k, (sint64)v); } |
248 | void put (keyword k, signed long long v) { put_(k, (sint64)v); } |
252 | void put (keyword k, signed long long v) { put_(k, (sint64)v); } |
249 | void put (keyword k, unsigned long long v) { put_(k, (sint64)v); } |
253 | void put (keyword k, unsigned long long v) { put_(k, (sint64)v); } |
250 | |
254 | |
251 | template<typename T> |
255 | template<typename T> |
252 | void put (keyword k, T *v) |
256 | void put (keyword k, const T *v) |
253 | { |
257 | { |
254 | if (v) |
258 | if (v) |
255 | put (k, v->name); |
259 | put (k, v->name); |
256 | else |
260 | else |
257 | put (k, (const char *)0); |
261 | put (k, (const char *)0); |
|
|
262 | } |
|
|
263 | |
|
|
264 | template<typename T> |
|
|
265 | void put (keyword k, const refptr<T> &v) |
|
|
266 | { |
|
|
267 | put (k, (T *)v); |
258 | } |
268 | } |
259 | |
269 | |
260 | bool save (const char *filename); |
270 | bool save (const char *filename); |
261 | char *as_string (); // like strdup |
271 | char *as_string (); // like strdup |
262 | |
272 | |