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.53 by root, Thu Feb 1 19:15:39 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,
134 }; 136 };
135 137
136 // object is delete'd after the refcount reaches 0 138 // object is delete'd after the refcount reaches 0
137 mutable int refcnt; 139 mutable int ACC (RW, refcnt);
138 int flags; 140 int ACC (RW, flags);
139 141
140 void refcnt_inc () const { ++refcnt; } 142 MTH void refcnt_inc () const { ++refcnt; }
141 void refcnt_dec () const { --refcnt; } 143 MTH void refcnt_dec () const { --refcnt; }
142 144
145 MTH int refcnt_cnt () const;
143 // check wether the object has died and destroy 146 // check wether the object has died and destroy
144 void refcnt_chk () { if (refcnt <= 0) do_check (); } 147 MTH void refcnt_chk () { if (refcnt <= 0) do_check (); }
145 148
146 // destroy the object unless it was already destroyed 149 // destroy the object unless it was already destroyed
147 // this politely asks everybody interested the reduce 150 // this politely asks everybody interested the reduce
148 // the refcount to 0 as soon as possible. 151 // the refcount to 0 as soon as possible.
149 void destroy (); 152 MTH void destroy ();
150 153
151 // return wether an object was destroyed already 154 // return wether an object was destroyed already
152 bool destroyed () const { return flags & F_DESTROYED; } 155 MTH bool destroyed () const { return flags & F_DESTROYED; }
153 156
154 virtual void gather_callbacks (AV *&callbacks, event_type event) const; 157 virtual void gather_callbacks (AV *&callbacks, event_type event) const;
155 158
156#if 0 159#if 0
157private: 160private:
161 164
162 HV *self; // CF+ perl self 165 HV *self; // CF+ perl self
163 AV *cb; // CF+ callbacks 166 AV *cb; // CF+ callbacks
164 shstr attach; // generic extension attachment information 167 shstr attach; // generic extension attachment information
165 168
169 void sever_self (); // sever this object from its self, if it has one.
166 void optimise (); // possibly save some memory by destroying unneeded data 170 void optimise (); // possibly save some memory by destroying unneeded data
167 171
168 attachable () 172 attachable ()
169 : flags (0), refcnt (0), self (0), cb (0), attach (0) 173 : flags (0), refcnt (0), self (0), cb (0), attach (0)
170 { 174 {
171 } 175 }
178 virtual ~attachable (); 182 virtual ~attachable ();
179 183
180 attachable &operator =(const attachable &src); 184 attachable &operator =(const attachable &src);
181 185
182 bool invoke (event_type event, ...); 186 bool invoke (event_type event, ...);
183 void instantiate (); 187 MTH void instantiate ();
184 void reattach (); 188 void reattach ();
185 189
186protected: 190protected:
187 // do the real refcount checking work 191 // do the real refcount checking work
188 void do_check (); 192 void do_check ();
247 } 251 }
248 252
249 *p = '\n'; 253 *p = '\n';
250 } 254 }
251 255
252 void put (keyword k, const char *v) 256 void put (keyword k, const char *v = 0)
253 { 257 {
254 put_string (k, v); 258 put_string (k, v);
255 } 259 }
256 260
257 void put (keyword k, const shstr &v) 261 void put (keyword k, const shstr &v)
322 void put (keyword k, const refptr<T> &v) 326 void put (keyword k, const refptr<T> &v)
323 { 327 {
324 put (k, (T *)v); 328 put (k, (T *)v);
325 } 329 }
326 330
327 bool save (const char *filename); 331 bool save (const char *path);
328 char *as_string (); // like strdup 332 char *as_string (); // like strdup
329 333
330 operator bool () { return !!av; } 334 operator bool () { return !!av; }
331}; 335};
332 336
336 340
337struct object_thawer 341struct object_thawer
338{ 342{
339 SV *text; // text part 343 SV *text; // text part
340 AV *av; // perl part 344 AV *av; // perl part
345 int linenum;
341 char *line; // current beginning of line 346 char *line; // current beginning of line
342 char *last_keyword, *last_value; 347 char *last_keyword, *last_value;
348 const char *name;
343 349
344 operator bool () { return !!text; } 350 operator bool () { return !!text; }
345 351
346 object_thawer (const char *filename = 0); 352 object_thawer (const char *path = 0);
347 object_thawer (const char *data, AV *perlav); 353 object_thawer (const char *data, AV *perlav);
348 ~object_thawer (); 354 ~object_thawer ();
349 355
350 void get (attachable *obj, int oid); 356 void get (attachable *obj, int oid);
351 357
372 void get (uint16 &i) { i = get_sint32 (); } 378 void get (uint16 &i) { i = get_sint32 (); }
373 void get (sint32 &i) { i = get_sint32 (); } 379 void get (sint32 &i) { i = get_sint32 (); }
374 380
375 void get (uint32 &i) { i = get_sint64 (); } 381 void get (uint32 &i) { i = get_sint64 (); }
376 void get (sint64 &i) { i = get_sint64 (); } 382 void get (sint64 &i) { i = get_sint64 (); }
377};
378 383
384 bool parse_error (keyword kw, const char *type = 0, const char *name = 0, bool skip = true);
385};
386
387//TODO: remove
379char *fgets (char *s, int n, object_thawer &thawer); 388char *fgets (char *s, int n, object_thawer &thawer);
380 389
381////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 390//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
382 391
383struct coroapi { 392struct coroapi {
384 static struct CoroAPI *GCoroAPI; 393 static struct CoroAPI *GCoroAPI;
385 394
386 static int nready () { return CORO_NREADY; } 395 static int nready () { return CORO_NREADY; }
387 static int cede () { return CORO_CEDE ; } 396 static int cede () { return CORO_CEDE ; }
397
398 static int cede_counter;
399
400 static void cede_every (int count)
401 {
402 if (++cede_counter >= count)
403 {
404 cede_counter = 0;
405
406 if (coroapi::nready ())
407 coroapi::cede ();
408 }
409 }
388}; 410};
389 411
390struct watcher_base 412struct watcher_base
391{ 413{
392 static struct EventAPI *GEventAPI; 414 static struct EventAPI *GEventAPI;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines