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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines