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.45 by root, Sun Dec 31 17:17:23 2006 UTC vs.
Revision 1.58 by pippijn, Thu Mar 1 12:28:16 2007 UTC

60 60
61////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 61//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
62 62
63void cfperl_init (); 63void cfperl_init ();
64void cfperl_main (); 64void cfperl_main ();
65void cfperl_emergency_save ();
66void cfperl_cleanup (int make_core);
65 67
66////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 68//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
67 69
68// virtual server time, excluding time jumps and lag 70// virtual server time, excluding time jumps and lag
69extern double runtime; 71extern double runtime;
120double cfperl_result_DOUBLE (int idx); 122double cfperl_result_DOUBLE (int idx);
121int cfperl_result_INT (int idx); 123int cfperl_result_INT (int idx);
122 124
123////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 125//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
124 126
127INTERFACE_CLASS (attachable)
125struct attachable 128struct attachable
126{ 129{
127 static MGVTBL vtbl; 130 static MGVTBL vtbl;
128 131
129 static unordered_vector<attachable *> mortals; 132 static unordered_vector<attachable *> mortals;
130 static void check_mortals (); 133 MTH static void check_mortals ();
131 134
132 enum { 135 enum {
133 F_DESTROYED = 0x01, 136 F_DESTROYED = 0x01,
134 F_BORROWED = 0x02, 137 F_DEBUG_TRACE = 0x02,
135 }; 138 };
136 139
137 // object is delete'd after the refcount reaches 0 140 // object is delete'd after the refcount reaches 0
141 int ACC (RW, flags);
138 mutable int refcnt; 142 mutable int ACC (RW, refcnt);
139 int flags;
140 143
141 void refcnt_inc () const { ++refcnt; } 144 MTH void refcnt_inc () const { ++refcnt; }
142 void refcnt_dec () const { --refcnt; } 145 MTH void refcnt_dec () const { --refcnt; }
143 146
147 MTH int refcnt_cnt () const;
144 // check wether the object has died and destroy 148 // check wether the object has died and destroy
145 void refcnt_chk () { if (refcnt <= 0) do_check (); } 149 MTH void refcnt_chk () { if (refcnt <= 0) do_check (); }
146 150
147 // destroy the object unless it was already destroyed 151 // destroy the object unless it was already destroyed
148 // this politely asks everybody interested the reduce 152 // this politely asks everybody interested the reduce
149 // the refcount to 0 as soon as possible. 153 // the refcount to 0 as soon as possible.
150 void destroy (); 154 MTH void destroy ();
151 155
152 // return wether an object was destroyed already 156 // return wether an object was destroyed already
153 bool destroyed () const { return flags & F_DESTROYED; } 157 MTH bool destroyed () const { return flags & F_DESTROYED; }
154 158
155 virtual void gather_callbacks (AV *&callbacks, event_type event) const; 159 virtual void gather_callbacks (AV *&callbacks, event_type event) const;
156 160
157#if 0 161#if 0
158private: 162private:
162 166
163 HV *self; // CF+ perl self 167 HV *self; // CF+ perl self
164 AV *cb; // CF+ callbacks 168 AV *cb; // CF+ callbacks
165 shstr attach; // generic extension attachment information 169 shstr attach; // generic extension attachment information
166 170
171 void sever_self (); // sever this object from its self, if it has one.
167 void optimise (); // possibly save some memory by destroying unneeded data 172 void optimise (); // possibly save some memory by destroying unneeded data
168 173
169 attachable () 174 attachable ()
170 : flags (0), refcnt (0), self (0), cb (0), attach (0) 175 : flags (0), refcnt (0), self (0), cb (0), attach (0)
171 { 176 {
172 } 177 }
179 virtual ~attachable (); 184 virtual ~attachable ();
180 185
181 attachable &operator =(const attachable &src); 186 attachable &operator =(const attachable &src);
182 187
183 bool invoke (event_type event, ...); 188 bool invoke (event_type event, ...);
184 void instantiate (); 189 MTH void instantiate ();
185 void reattach (); 190 void reattach ();
186 191
187protected: 192protected:
188 // do the real refcount checking work 193 // do the real refcount checking work
189 void do_check (); 194 void do_check ();
323 void put (keyword k, const refptr<T> &v) 328 void put (keyword k, const refptr<T> &v)
324 { 329 {
325 put (k, (T *)v); 330 put (k, (T *)v);
326 } 331 }
327 332
328 bool save (const char *filename); 333 bool save (const char *path);
329 char *as_string (); // like strdup 334 char *as_string (); // like strdup
330 335
331 operator bool () { return !!av; } 336 operator bool () { return !!av; }
332}; 337};
333 338
337 342
338struct object_thawer 343struct object_thawer
339{ 344{
340 SV *text; // text part 345 SV *text; // text part
341 AV *av; // perl part 346 AV *av; // perl part
347 int linenum;
342 char *line; // current beginning of line 348 char *line; // current beginning of line
343 char *last_keyword, *last_value; 349 keyword kw;
350 char *kw_str, *value;
351 const char *name;
344 352
345 operator bool () { return !!text; } 353 operator bool () { return !!text; }
346 354
347 object_thawer (const char *filename = 0); 355 object_thawer (const char *path = 0);
348 object_thawer (const char *data, AV *perlav); 356 object_thawer (const char *data, AV *perlav);
349 ~object_thawer (); 357 ~object_thawer ();
350 358
351 void get (attachable *obj, int oid); 359 void get (attachable *obj, int oid);
352 360
353 keyword get_kv (); // also parse value for later use 361 // parse next line
354 void skip_kv (keyword kw); 362 void next ();
363 // skip the current key-value (usually fetch next line, for
364 // multiline-fields, skips untilt he corresponding end-kw
365 void skip ();
355 366
367 //TODO: remove, deprecated
368 keyword get_kv ()
369 {
370 next ();
371 return kw;
372 }
373
374
356 const char *get_str () { return last_value; } // may be 0 375 char *get_str () { return value; } // may be 0
357 376
358 void get (shstr &sh) const; 377 void get (shstr &sh) const;
359 void get_ornull (shstr &sh) const { sh = last_value; } 378 void get_ornull (shstr &sh) const { sh = value; }
360 void get_ml (keyword kend, shstr &sh); 379 void get_ml (keyword kend, shstr &sh);
361 380
362 sint32 get_sint32 () const; 381 sint32 get_sint32 () const;
363 sint64 get_sint64 () const; 382 sint64 get_sint64 () const;
364 double get_double () const; 383 double get_double () const;
373 void get (uint16 &i) { i = get_sint32 (); } 392 void get (uint16 &i) { i = get_sint32 (); }
374 void get (sint32 &i) { i = get_sint32 (); } 393 void get (sint32 &i) { i = get_sint32 (); }
375 394
376 void get (uint32 &i) { i = get_sint64 (); } 395 void get (uint32 &i) { i = get_sint64 (); }
377 void get (sint64 &i) { i = get_sint64 (); } 396 void get (sint64 &i) { i = get_sint64 (); }
378};
379 397
398 bool parse_error (const char *type = 0, const char *name = 0, bool skip = true);
399};
400
401//TODO: remove
380char *fgets (char *s, int n, object_thawer &thawer); 402char *fgets (char *s, int n, object_thawer &thawer);
381 403
382////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 404//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
383 405
384struct coroapi { 406struct coroapi {
385 static struct CoroAPI *GCoroAPI; 407 static struct CoroAPI *GCoroAPI;
386 408
387 static int nready () { return CORO_NREADY; } 409 static int nready () { return CORO_NREADY; }
388 static int cede () { return CORO_CEDE ; } 410 static int cede () { return CORO_CEDE ; }
411
412 static int cede_counter;
413
414 static void cede_every (int count)
415 {
416 if (++cede_counter >= count)
417 {
418 cede_counter = 0;
419
420 if (coroapi::nready ())
421 coroapi::cede ();
422 }
423 }
389}; 424};
390 425
391struct watcher_base 426struct watcher_base
392{ 427{
393 static struct EventAPI *GEventAPI; 428 static struct EventAPI *GEventAPI;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines