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.43 by root, Sat Dec 30 15:07:59 2006 UTC vs.
Revision 1.54 by root, Sun Feb 11 01:38:48 2007 UTC

35 35
36// same here, massive symbol spamming 36// same here, massive symbol spamming
37#undef do_open 37#undef do_open
38#undef do_close 38#undef do_close
39#undef ref 39#undef ref
40#undef seed
40 41
41// perl bug #40256: perl does overwrite those with reentrant versions 42// perl bug #40256: perl does overwrite those with reentrant versions
42// but does not initialise their state structures. 43// but does not initialise their state structures.
43#undef random 44#undef random
44#undef crypt 45#undef crypt
59 60
60////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 61//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
61 62
62void cfperl_init (); 63void cfperl_init ();
63void cfperl_main (); 64void cfperl_main ();
65void cfperl_emergency_save ();
64 66
65////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 67//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
66 68
67// virtual server time, excluding time jumps and lag 69// virtual server time, excluding time jumps and lag
68extern double runtime; 70extern double runtime;
119double cfperl_result_DOUBLE (int idx); 121double cfperl_result_DOUBLE (int idx);
120int cfperl_result_INT (int idx); 122int cfperl_result_INT (int idx);
121 123
122////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 124//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
123 125
126INTERFACE_CLASS (attachable)
124struct attachable 127struct attachable
125{ 128{
126 static MGVTBL vtbl; 129 static MGVTBL vtbl;
127 130
128 static unordered_vector<attachable *> mortals; 131 static unordered_vector<attachable *> mortals;
129 static void check_mortals (); 132 MTH static void check_mortals ();
130 133
131 enum { 134 enum {
132 F_DESTROYED = 0x01, 135 F_DESTROYED = 0x01,
133 F_BORROWED = 0x02, 136 F_DEBUG_TRACE = 0x02,
134 }; 137 };
135 138
136 // object is delete'd after the refcount reaches 0 139 // object is delete'd after the refcount reaches 0
137 mutable int refcnt; 140 mutable int ACC (RW, refcnt);
138 int flags; 141 int ACC (RW, flags);
139 142
140 void refcnt_inc () const { ++refcnt; } 143 MTH void refcnt_inc () const { ++refcnt; }
141 void refcnt_dec () const { --refcnt; } 144 MTH void refcnt_dec () const { --refcnt; }
142 145
146 MTH int refcnt_cnt () const;
143 // check wether the object has died and destroy 147 // check wether the object has died and destroy
144 void refcnt_chk () { if (refcnt <= 0) do_check (); } 148 MTH void refcnt_chk () { if (refcnt <= 0) do_check (); }
145 149
146 // destroy the object unless it was already destroyed 150 // destroy the object unless it was already destroyed
147 // this politely asks everybody interested the reduce 151 // this politely asks everybody interested the reduce
148 // the refcount to 0 as soon as possible. 152 // the refcount to 0 as soon as possible.
149 void destroy (); 153 MTH void destroy ();
150 154
151 // return wether an object was destroyed already 155 // return wether an object was destroyed already
152 bool destroyed () const { return flags & F_DESTROYED; } 156 MTH bool destroyed () const { return flags & F_DESTROYED; }
153 157
154 virtual void gather_callbacks (AV *&callbacks, event_type event) const; 158 virtual void gather_callbacks (AV *&callbacks, event_type event) const;
155 159
156#if 0 160#if 0
157private: 161private:
161 165
162 HV *self; // CF+ perl self 166 HV *self; // CF+ perl self
163 AV *cb; // CF+ callbacks 167 AV *cb; // CF+ callbacks
164 shstr attach; // generic extension attachment information 168 shstr attach; // generic extension attachment information
165 169
170 void sever_self (); // sever this object from its self, if it has one.
166 void optimise (); // possibly save some memory by destroying unneeded data 171 void optimise (); // possibly save some memory by destroying unneeded data
167 172
168 attachable () 173 attachable ()
169 : flags (0), refcnt (0), self (0), cb (0), attach (0) 174 : flags (0), refcnt (0), self (0), cb (0), attach (0)
170 { 175 {
171 } 176 }
178 virtual ~attachable (); 183 virtual ~attachable ();
179 184
180 attachable &operator =(const attachable &src); 185 attachable &operator =(const attachable &src);
181 186
182 bool invoke (event_type event, ...); 187 bool invoke (event_type event, ...);
183 void instantiate (); 188 MTH void instantiate ();
184 void reattach (); 189 void reattach ();
185 190
186protected: 191protected:
187 // do the real refcount checking work 192 // do the real refcount checking work
188 void do_check (); 193 void do_check ();
247 } 252 }
248 253
249 *p = '\n'; 254 *p = '\n';
250 } 255 }
251 256
252 void put (keyword k, const char *v) 257 void put (keyword k, const char *v = 0)
253 { 258 {
254 put_string (k, v); 259 put_string (k, v);
255 } 260 }
256 261
257 void put (keyword k, const shstr &v) 262 void put (keyword k, const shstr &v)
322 void put (keyword k, const refptr<T> &v) 327 void put (keyword k, const refptr<T> &v)
323 { 328 {
324 put (k, (T *)v); 329 put (k, (T *)v);
325 } 330 }
326 331
327 bool save (const char *filename); 332 bool save (const char *path);
328 char *as_string (); // like strdup 333 char *as_string (); // like strdup
329 334
330 operator bool () { return !!av; } 335 operator bool () { return !!av; }
331}; 336};
332 337
336 341
337struct object_thawer 342struct object_thawer
338{ 343{
339 SV *text; // text part 344 SV *text; // text part
340 AV *av; // perl part 345 AV *av; // perl part
346 int linenum;
341 char *line; // current beginning of line 347 char *line; // current beginning of line
342 char *last_keyword, *last_value; 348 char *last_keyword, *last_value;
349 const char *name;
343 350
344 operator bool () { return !!text; } 351 operator bool () { return !!text; }
345 352
346 object_thawer (const char *filename = 0); 353 object_thawer (const char *path = 0);
347 object_thawer (const char *data, AV *perlav); 354 object_thawer (const char *data, AV *perlav);
348 ~object_thawer (); 355 ~object_thawer ();
349 356
350 void get (attachable *obj, int oid); 357 void get (attachable *obj, int oid);
351 358
372 void get (uint16 &i) { i = get_sint32 (); } 379 void get (uint16 &i) { i = get_sint32 (); }
373 void get (sint32 &i) { i = get_sint32 (); } 380 void get (sint32 &i) { i = get_sint32 (); }
374 381
375 void get (uint32 &i) { i = get_sint64 (); } 382 void get (uint32 &i) { i = get_sint64 (); }
376 void get (sint64 &i) { i = get_sint64 (); } 383 void get (sint64 &i) { i = get_sint64 (); }
377};
378 384
385 bool parse_error (keyword kw, const char *type = 0, const char *name = 0, bool skip = true);
386};
387
388//TODO: remove
379char *fgets (char *s, int n, object_thawer &thawer); 389char *fgets (char *s, int n, object_thawer &thawer);
380 390
381////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 391//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
382 392
383struct coroapi { 393struct coroapi {
384 static struct CoroAPI *GCoroAPI; 394 static struct CoroAPI *GCoroAPI;
385 395
386 static int nready () { return CORO_NREADY; } 396 static int nready () { return CORO_NREADY; }
387 static int cede () { return CORO_CEDE ; } 397 static int cede () { return CORO_CEDE ; }
398
399 static int cede_counter;
400
401 static void cede_every (int count)
402 {
403 if (++cede_counter >= count)
404 {
405 cede_counter = 0;
406
407 if (coroapi::nready ())
408 coroapi::cede ();
409 }
410 }
388}; 411};
389 412
390struct watcher_base 413struct watcher_base
391{ 414{
392 static struct EventAPI *GEventAPI; 415 static struct EventAPI *GEventAPI;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines