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.44 by root, Sun Dec 31 10:28:36 2006 UTC vs.
Revision 1.54 by root, Sun Feb 11 01:38:48 2007 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines