ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/include/cfperl.h
(Generate patch)

Comparing deliantra/server/include/cfperl.h (file contents):
Revision 1.5 by root, Fri Aug 25 17:11:53 2006 UTC vs.
Revision 1.6 by root, Sat Aug 26 08:44:06 2006 UTC

2// cfperl.h perl interface 2// cfperl.h perl interface
3// 3//
4#ifndef CFPERL_H__ 4#ifndef CFPERL_H__
5#define CFPERL_H__ 5#define CFPERL_H__
6 6
7struct pl;
8struct object;
9struct mapstruct;
10
7// could have used templates, but a more traditional C api 11// could have used templates, but a more traditional C api
8// uses more explicit typing which is ok for this purpose. 12// uses more explicit typing which is ok for this purpose.
9enum data_type { 13enum data_type
14{
10 DT_END, // no further arguments 15 DT_END, // no further arguments
11 DT_INT, 16 DT_INT,
12 DT_INT64, 17 DT_INT64,
13 DT_DOUBLE, 18 DT_DOUBLE,
14 DT_STRING, // 0-terminated string 19 DT_STRING, // 0-terminated string
24 DT_INT_PTR, 29 DT_INT_PTR,
25 DT_INT64_PTR, 30 DT_INT64_PTR,
26 DT_DOUBLE_PTR, 31 DT_DOUBLE_PTR,
27}; 32};
28 33
29enum event_klass { 34enum event_klass
35{
30 KLASS_GLOBAL, 36 KLASS_GLOBAL,
31 KLASS_PLAYER, 37 KLASS_PLAYER,
32 KLASS_OBJECT, 38 KLASS_OBJECT,
33 KLASS_MAP, 39 KLASS_MAP,
34}; 40};
35 41
36enum event_type { 42enum event_type
43{
37# define def(klass,name) EV_ ## klass ## _ ## name, 44# define def(klass,name) EV_ ## klass ## _ ## name,
38# include "eventinc.h" 45# include "eventinc.h"
39# undef def 46# undef def
40 NUM_EVENT_TYPES 47 NUM_EVENT_TYPES
41}; 48};
43#define ARG_INT(v) DT_INT , static_cast<int> (v) 50#define ARG_INT(v) DT_INT , static_cast<int> (v)
44#define ARG_INT64(v) DT_INT64 , static_cast<sint64> (v) 51#define ARG_INT64(v) DT_INT64 , static_cast<sint64> (v)
45#define ARG_DOUBLE(v) DT_DOUBLE, static_cast<double> (v) 52#define ARG_DOUBLE(v) DT_DOUBLE, static_cast<double> (v)
46#define ARG_STRING(v) DT_STRING, static_cast<const char *> (v) 53#define ARG_STRING(v) DT_STRING, static_cast<const char *> (v)
47#define ARG_DATA(s,l) DT_DATA , static_cast<const void *> (s), (l) 54#define ARG_DATA(s,l) DT_DATA , static_cast<const void *> (s), (l)
48#define ARG_OBJECT(o) DT_OBJECT, static_cast<struct object *> (o) 55#define ARG_OBJECT(o) DT_OBJECT, (void *)static_cast<struct object *> (o)
49#define ARG_MAP(o) DT_MAP , static_cast<struct mapstruct *> (o) 56#define ARG_MAP(o) DT_MAP , (void *)static_cast<struct mapstruct *> (o)
50#define ARG_PLAYER(o) DT_PLAYER, static_cast<struct pl *> (o) 57#define ARG_PLAYER(o) DT_PLAYER, (void *)static_cast<struct pl *> (o)
51#define ARG_ARCH(o) DT_ARCH , static_cast<struct archetype *> (o) 58#define ARG_ARCH(o) DT_ARCH , (void *)static_cast<struct archetype *> (o)
52#define ARG_PARTY(o) DT_PARTY , static_cast<struct party *> (o) 59#define ARG_PARTY(o) DT_PARTY , (void *)static_cast<struct party *> (o)
53#define ARG_REGION(o) DT_REGION, static_cast<struct region *> (o) 60#define ARG_REGION(o) DT_REGION, (void *)static_cast<struct region *> (o)
54 61
55// the ", ## __VA_ARGS" is, unfortunately, a gnu-cpp extension 62// the ", ## __VA_ARGS" is, unfortunately, a gnu-cpp extension
56 63
57// all these return true when the normal event processing should be skipped (if any) 64// all these return true when the normal event processing should be skipped (if any)
58#define INVOKE(klass, event, ...) cfperl_invoke (EV_ ## klass ## _ ## event, ## __VA_ARGS__, DT_END) 65#define INVOKE(klass, event, ...) cfperl_invoke (EV_ ## klass ## _ ## event, ## __VA_ARGS__, DT_END)
60#define INVOKE_GLOBAL(event, ...) INVOKE (GLOBAL, event, ## __VA_ARGS__) 67#define INVOKE_GLOBAL(event, ...) INVOKE (GLOBAL, event, ## __VA_ARGS__)
61#define INVOKE_OBJECT(event, op, ...) INVOKE (OBJECT, event, ARG_OBJECT (op), ## __VA_ARGS__) 68#define INVOKE_OBJECT(event, op, ...) INVOKE (OBJECT, event, ARG_OBJECT (op), ## __VA_ARGS__)
62#define INVOKE_PLAYER(event, pl, ...) INVOKE (PLAYER, event, ARG_PLAYER (pl), ## __VA_ARGS__) 69#define INVOKE_PLAYER(event, pl, ...) INVOKE (PLAYER, event, ARG_PLAYER (pl), ## __VA_ARGS__)
63#define INVOKE_MAP(event, map, ...) INVOKE (MAP , event, ARG_MAP (map) , ## __VA_ARGS__) 70#define INVOKE_MAP(event, map, ...) INVOKE (MAP , event, ARG_MAP (map) , ## __VA_ARGS__)
64 71
72struct extendable_base
73{
74 void *self, *cb; // CF+ perl self and callback
75 const char *attach; // generic extension attachment information
76
77 void clear (); // called when free'ing objects
78 void optimise (); // possibly save some memory by destroying unneeded data
79 void reattach (data_type type, void *self); // called after swapin
80 void instantiate (data_type type, void *self); // called on first instantiation
81 void clone (data_type type, void *self, void *dest);
82};
83
84// objects extendable from perl (or any other extension) should include or
85// derive using the curiously recurring template pattern, to avoid
86// virtual method calls etc.
87template<class subclass>
88struct extendable : extendable_base
89{
90 void clear ()
91 {
92 if (self || cb)
93 extendable_base::clear ();
94 }
95 void instantiate ()
96 {
97 if (attach)
98 extendable_base::instantiate (
99 static_cast<subclass *>(this)->get_dt (),
100 static_cast<subclass *>(this)
101 );
102 }
103 void reattach ()
104 {
105 if (attach)
106 extendable_base::reattach (
107 static_cast<subclass *>(this)->get_dt (),
108 static_cast<subclass *>(this)
109 );
110 }
111 void clone (subclass *destination)
112 {
113 if (self || cb)
114 extendable_base::clone (
115 static_cast<subclass *>(this)->get_dt (),
116 static_cast<subclass *>(this),
117 destination
118 );
119 }
120};
121
65bool cfperl_invoke (event_type event, ...); 122bool cfperl_invoke (event_type event, ...);
66void cfperl_free_ob (object *op); 123void cfperl_free_ob (struct object *op);
67 124
68void cfperl_init (); 125void cfperl_init ();
69void cfperl_main (); 126void cfperl_main ();
70 127
71#endif 128#endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines