ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/include/cfperl.h
Revision: 1.4
Committed: Fri Aug 25 15:21:56 2006 UTC (17 years, 9 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.3: +3 -1 lines
Log Message:
Move callback checks to C++ and short-circuit when no callback exists
for an event: No perl is touched when an event doesn't have a callback registered,
so this is very fast (compared to the old way).

File Contents

# User Rev Content
1 root 1.1 //
2     // cfperl.h perl interface
3     //
4 root 1.2 #ifndef CFPERL_H__
5     #define CFPERL_H__
6    
7     // could have used templates, but a more traditional C api
8     // uses more explicit typing which is ok for this purpose.
9     enum data_type {
10     DT_END, // no further arguments
11     DT_INT,
12     DT_LONG,
13     DT_DOUBLE,
14     DT_STRING, // 0-terminated string
15     DT_DATA, // string + length
16     DT_OBJECT,
17     DT_MAP,
18     DT_PLAYER,
19     DT_ARCH,
20     DT_PARTY,
21     DT_REGION,
22     };
23    
24 root 1.3 enum event_klass {
25     KLASS_GLOBAL,
26     KLASS_PLAYER,
27     KLASS_OBJECT,
28     KLASS_MAP,
29     };
30    
31 root 1.2 enum event_type {
32 root 1.3 # define def(klass,name) EV_ ## klass ## name,
33 root 1.2 # include "eventinc.h"
34     # undef def
35 root 1.4 NUM_EVENT_TYPES
36 root 1.2 };
37    
38 root 1.3 #define ARG_INT(v) DT_INT , static_cast<int> (v)
39     #define ARG_LONG(v) DT_LONG , static_cast<long> (v)
40     #define ARG_DOUBLE(v) DT_DOUBLE, static_cast<double> (v)
41     #define ARG_STRING(v) DT_STRING, static_cast<char *> (v)
42     #define ARG_DATA(s,l) DT_DATA , static_cast<void *> (s), (l)
43     #define ARG_OBJECT(o) DT_OBJECT, static_cast<struct object *> (o)
44     #define ARG_MAP(o) DT_MAP , static_cast<struct mapstruct *> (o)
45     #define ARG_PLAYER(o) DT_PLAYER, static_cast<struct pl *> (o)
46     #define ARG_ARCH(o) DT_ARCH , static_cast<struct archetype *> (o)
47     #define ARG_PARTY(o) DT_PARTY , static_cast<struct party *> (o)
48     #define ARG_REGION(o) DT_REGION, static_cast<struct region *> (o)
49    
50     // the ", ## __VA_ARGS" is, unfortunately, a gnu-cpp extension
51 root 1.2
52 root 1.4 // all these return true when the normal event processing should be skipped (if any)
53 root 1.3 #define INVOKE(klass, event, ...) cfperl_invoke (EV_ ## klass ## event, ## __VA_ARGS__, DT_END)
54 root 1.1
55 root 1.3 #define INVOKE_GLOBAL(event, ...) INVOKE (GLOBAL, event, ## __VA_ARGS__)
56     #define INVOKE_OBJECT(event, op, ...) INVOKE (OBJECT, event, ARG_OBJECT (op), ## __VA_ARGS__)
57     #define INVOKE_PLAYER(event, pl, ...) INVOKE (PLAYER, event, ARG_PLAYER (pl), ## __VA_ARGS__)
58     #define INVOKE_MAP(event, map, ...) INVOKE (MAP , event, ARG_MAP (map) , ## __VA_ARGS__)
59    
60 root 1.4 bool cfperl_invoke (event_type event, ...);
61 root 1.3 void cfperl_free_ob (object *op);
62    
63     void cfperl_init ();
64 root 1.1 void cfperl_main ();
65 root 1.2
66     #endif
67 root 1.3