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.7 by root, Sat Aug 26 23:36:32 2006 UTC vs.
Revision 1.9 by root, Sun Aug 27 15:24:21 2006 UTC

26 DT_PLAYER, 26 DT_PLAYER,
27 DT_ARCH, 27 DT_ARCH,
28 DT_PARTY, 28 DT_PARTY,
29 DT_REGION, 29 DT_REGION,
30 DT_AV, // av that needs to be flattened out 30 DT_AV, // av that needs to be flattened out
31
32 NUM_DATA_TYPES
31}; 33};
32 34
33enum event_klass 35enum event_klass
34{ 36{
35 KLASS_GLOBAL, 37 KLASS_GLOBAL,
59#define ARG_REGION(o) DT_REGION, (void *)static_cast<struct region *> (o) 61#define ARG_REGION(o) DT_REGION, (void *)static_cast<struct region *> (o)
60 62
61// the ", ## __VA_ARGS" is, unfortunately, a gnu-cpp extension 63// the ", ## __VA_ARGS" is, unfortunately, a gnu-cpp extension
62 64
63// all these return true when the normal event processing should be skipped (if any) 65// all these return true when the normal event processing should be skipped (if any)
64#define INVOKE(klass, event, ...) cfperl_invoke (EVENT_ ## klass ## _ ## event, ## __VA_ARGS__, DT_END) 66#define INVOKE_(event, ...) cfperl_invoke (event, ## __VA_ARGS__, DT_END)
65 67
68#define INVOKE(klass, event, ...) INVOKE_(EVENT_ ## klass ## _ ## event, ## __VA_ARGS__)
66#define INVOKE_GLOBAL(event, ...) INVOKE (GLOBAL, event, ## __VA_ARGS__) 69#define INVOKE_GLOBAL(event, ...) INVOKE_(EVENT_ ## GLOBAL ## _ ## event, ## __VA_ARGS__)
67#define INVOKE_OBJECT(event, op, ...) INVOKE (OBJECT, event, ARG_OBJECT (op), ## __VA_ARGS__) 70#define INVOKE_OBJECT(event, op, ...) INVOKE_(EVENT_ ## OBJECT ## _ ## event, ARG_OBJECT (op), ## __VA_ARGS__)
68#define INVOKE_PLAYER(event, pl, ...) INVOKE (PLAYER, event, ARG_PLAYER (pl), ## __VA_ARGS__) 71#define INVOKE_PLAYER(event, pl, ...) INVOKE_(EVENT_ ## PLAYER ## _ ## event, ARG_PLAYER (pl), ## __VA_ARGS__)
69#define INVOKE_MAP(event, map, ...) INVOKE (MAP , event, ARG_MAP (map) , ## __VA_ARGS__) 72#define INVOKE_MAP(event, map, ...) INVOKE_(EVENT_ ## MAP ## _ ## event, ARG_MAP (map) , ## __VA_ARGS__)
70 73
71//TODO should index into @result 74//TODO should index into @result
72#define RESULT(idx,type) cfperl_result_ ## type (idx) 75#define RESULT(idx,type) cfperl_result_ ## type (idx)
73#define RESULT_INT(idx) RESULT(idx, INT) 76#define RESULT_INT(idx) RESULT(idx, INT)
74 77
80 void *self, *cb; // CF+ perl self and callback 83 void *self, *cb; // CF+ perl self and callback
81 const char *attach; // generic extension attachment information 84 const char *attach; // generic extension attachment information
82 85
83 void clear (); // called when free'ing objects 86 void clear (); // called when free'ing objects
84 void optimise (); // possibly save some memory by destroying unneeded data 87 void optimise (); // possibly save some memory by destroying unneeded data
85 void reattach (data_type type, void *self); // called after swapin 88
89 void extendable_init ()
90 {
91 self = cb = 0;
92 attach = 0;
93 }
86}; 94};
87 95
88// objects extendable from perl (or any other extension) should include or 96// objects extendable from perl (or any other extension) should include or
89// derive using the curiously recurring template pattern, to avoid 97// derive using the curiously recurring template pattern, to avoid
90// virtual method calls etc. 98// virtual method calls etc.
91template<class subclass> 99template<class subclass>
92struct extendable : extendable_base 100struct extendable : extendable_base
93{ 101{
94 void reattach () 102 static data_type get_dt ()
95 { 103 {
96 if (attach) 104 subclass::get_dt ();
97 extendable_base::reattach (
98 static_cast<subclass *>(this)->get_dt (),
99 static_cast<subclass *>(this)
100 );
101 } 105 }
102}; 106};
103 107
104struct object_freezer 108struct object_freezer
105{ 109{
106 const char *filename; 110 const char *filename;
107 void *av; 111 void *av;
112 int idx;
108 113
109 object_freezer (const char *filename) : filename (filename) { } 114 object_freezer (const char *filename);
115 ~object_freezer ();
116
110 void put (extendable_base *object); 117 void put (extendable_base *ext);
118
119 template<class subclass>
120 void put (extendable<subclass> *obj)
121 {
122 put ((extendable_base *)obj);
123 }
124
111 void finish (); 125 void finish ();
112}; 126};
113 127
114struct object_thawer 128struct object_thawer
115{ 129{
116 void *av; 130 void *av;
131 int idx;
117 132
118 object_thawer (const char *filename); 133 object_thawer (const char *filename = 0);
134 ~object_thawer ();
135
136 void get (data_type type, void *obj, extendable_base *ext);
137
138 template<class subclass>
119 void get (extendable_base *object); 139 void get (extendable<subclass> *obj)
140 {
141 if (av)
142 get (subclass::get_dt (), (subclass *)obj, obj);
143 }
144
120 void finish (); 145 void finish ();
121}; 146};
122 147
123#endif 148#endif
124 149

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines