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.53 by root, Thu Feb 1 19:15:39 2007 UTC vs.
Revision 1.64 by root, Sat May 19 00:08:11 2007 UTC

2// cfperl.h perl interface 2// cfperl.h perl interface
3// 3//
4#ifndef CFPERL_H__ 4#ifndef CFPERL_H__
5#define CFPERL_H__ 5#define CFPERL_H__
6 6
7#include <cstdarg>
7#include <cstdio> 8#include <cstdio>
9#include <bitset>
8 10
9using namespace std; 11using namespace std;
10 12
11#include <EXTERN.h> 13#include <EXTERN.h>
12#include <perl.h> 14#include <perl.h>
61////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 63//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
62 64
63void cfperl_init (); 65void cfperl_init ();
64void cfperl_main (); 66void cfperl_main ();
65void cfperl_emergency_save (); 67void cfperl_emergency_save ();
68void cfperl_cleanup (int make_core);
66 69
67////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 70//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
68 71
69// virtual server time, excluding time jumps and lag 72// virtual server time, excluding time jumps and lag
70extern double runtime; 73extern double runtime;
86# define def(klass,name) EVENT_ ## klass ## _ ## name, 89# define def(klass,name) EVENT_ ## klass ## _ ## name,
87# include "eventinc.h" 90# include "eventinc.h"
88# undef def 91# undef def
89 NUM_EVENT_TYPES 92 NUM_EVENT_TYPES
90}; 93};
94
95// in which global events or per-type events are we interested
96extern bitset<NUM_EVENT_TYPES> ev_want_event;
97extern bitset<NUM_TYPES> ev_want_type;
91 98
92#define ARG_AV(o) DT_AV , static_cast<AV *> (o) 99#define ARG_AV(o) DT_AV , static_cast<AV *> (o)
93#define ARG_INT(v) DT_INT , static_cast<int> (v) 100#define ARG_INT(v) DT_INT , static_cast<int> (v)
94#define ARG_INT64(v) DT_INT64 , static_cast<sint64> (v) 101#define ARG_INT64(v) DT_INT64 , static_cast<sint64> (v)
95#define ARG_DOUBLE(v) DT_DOUBLE, static_cast<double> (v) 102#define ARG_DOUBLE(v) DT_DOUBLE, static_cast<double> (v)
130 137
131 static unordered_vector<attachable *> mortals; 138 static unordered_vector<attachable *> mortals;
132 MTH static void check_mortals (); 139 MTH static void check_mortals ();
133 140
134 enum { 141 enum {
135 F_DESTROYED = 0x01, 142 F_DESTROYED = 0x01,
143 F_DEBUG_TRACE = 0x02,
136 }; 144 };
137 145
138 // object is delete'd after the refcount reaches 0 146 // object is delete'd after the refcount reaches 0
147 int ACC (RW, flags);
139 mutable int ACC (RW, refcnt); 148 mutable int ACC (RW, refcnt);
140 int ACC (RW, flags);
141 149
142 MTH void refcnt_inc () const { ++refcnt; } 150 MTH void refcnt_inc () const { ++refcnt; }
143 MTH void refcnt_dec () const { --refcnt; } 151 MTH void refcnt_dec () const { --refcnt; }
144 152
145 MTH int refcnt_cnt () const; 153 MTH int refcnt_cnt () const;
181 189
182 virtual ~attachable (); 190 virtual ~attachable ();
183 191
184 attachable &operator =(const attachable &src); 192 attachable &operator =(const attachable &src);
185 193
194 bool vinvoke (event_type event, va_list &ap);
186 bool invoke (event_type event, ...); 195 bool invoke (event_type event, ...)
196 {
197 if (ev_want_event [event] || cb)
198 {
199 va_list ap;
200 va_start (ap, event);
201 vinvoke (event, ap);
202 va_end (ap);
203 }
204 }
205
187 MTH void instantiate (); 206 MTH void instantiate ();
188 void reattach (); 207 void reattach ();
189 208
190protected: 209protected:
191 // do the real refcount checking work 210 // do the real refcount checking work
203 222
204extern struct global gbl_ev; 223extern struct global gbl_ev;
205 224
206////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 225//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
207 226
208struct object_freezer : dynbuf 227struct object_freezer : dynbuf_text
209{ 228{
210 AV *av; 229 AV *av;
211 230
212 object_freezer (); 231 object_freezer ();
213 ~object_freezer (); 232 ~object_freezer ();
333 352
334 operator bool () { return !!av; } 353 operator bool () { return !!av; }
335}; 354};
336 355
337// compatibility support, should be removed when no longer needed 356// compatibility support, should be removed when no longer needed
338int fprintf (object_freezer &freezer, const char *format, ...); 357void fprintf (object_freezer &freezer, const char *format, ...);
339int fputs (const char *s, object_freezer &freezer); 358void fputs (const char *s, object_freezer &freezer);
340 359
341struct object_thawer 360struct object_thawer
342{ 361{
343 SV *text; // text part 362 SV *text; // text part
344 AV *av; // perl part 363 AV *av; // perl part
345 int linenum; 364 int linenum;
346 char *line; // current beginning of line 365 char *line; // current beginning of line
347 char *last_keyword, *last_value; 366 keyword kw;
367 char *kw_str, *value;
348 const char *name; 368 const char *name;
349 369
350 operator bool () { return !!text; } 370 operator bool () { return !!text; }
351 371
352 object_thawer (const char *path = 0); 372 object_thawer (const char *path = 0);
353 object_thawer (const char *data, AV *perlav); 373 object_thawer (const char *data, AV *perlav);
354 ~object_thawer (); 374 ~object_thawer ();
355 375
356 void get (attachable *obj, int oid); 376 void get (attachable *obj, int oid);
357 377
358 keyword get_kv (); // also parse value for later use 378 // parse next line
359 void skip_kv (keyword kw); 379 void next ();
380 // skip the current key-value (usually fetch next line, for
381 // multiline-fields, skips untilt he corresponding end-kw
382 void skip ();
360 383
384 //TODO: remove, deprecated
385 keyword get_kv ()
386 {
387 next ();
388 return kw;
389 }
390
361 const char *get_str () { return last_value; } // may be 0 391 char *get_str () { return value; } // may be 0
362 392
363 void get (shstr &sh) const; 393 void get (shstr &sh) const;
364 void get_ornull (shstr &sh) const { sh = last_value; } 394 void get_ornull (shstr &sh) const { sh = value; }
365 void get_ml (keyword kend, shstr &sh); 395 void get_ml (keyword kend, shstr &sh);
366 396
367 sint32 get_sint32 () const; 397 sint32 get_sint32 () const;
368 sint64 get_sint64 () const; 398 sint64 get_sint64 () const;
369 double get_double () const; 399 double get_double () const;
379 void get (sint32 &i) { i = get_sint32 (); } 409 void get (sint32 &i) { i = get_sint32 (); }
380 410
381 void get (uint32 &i) { i = get_sint64 (); } 411 void get (uint32 &i) { i = get_sint64 (); }
382 void get (sint64 &i) { i = get_sint64 (); } 412 void get (sint64 &i) { i = get_sint64 (); }
383 413
384 bool parse_error (keyword kw, const char *type = 0, const char *name = 0, bool skip = true); 414 bool parse_error (const char *type = 0, const char *name = 0, bool skip = true);
385}; 415};
386 416
387//TODO: remove 417//TODO: remove
388char *fgets (char *s, int n, object_thawer &thawer); 418char *fgets (char *s, int n, object_thawer &thawer);
389 419
393 static struct CoroAPI *GCoroAPI; 423 static struct CoroAPI *GCoroAPI;
394 424
395 static int nready () { return CORO_NREADY; } 425 static int nready () { return CORO_NREADY; }
396 static int cede () { return CORO_CEDE ; } 426 static int cede () { return CORO_CEDE ; }
397 427
428 static double (*time)();
429 static double next_cede;
398 static int cede_counter; 430 static int cede_counter;
399 431
432 static void do_cede_every ();
433 static void do_cede_to_tick ();
434 static void do_cede_to_tick_every ();
435
400 static void cede_every (int count) 436 static void cede_every (int count)
401 { 437 {
402 if (++cede_counter >= count) 438 if (++cede_counter >= count)
403 { 439 do_cede_every ();
404 cede_counter = 0;
405
406 if (coroapi::nready ())
407 coroapi::cede ();
408 }
409 } 440 }
441
442 static void cede_to_tick ()
443 {
444 if (time () >= next_cede)
445 do_cede_to_tick ();
446 }
447
448 static void cede_to_tick_every (int count)
449 {
450 if (++cede_counter >= count)
451 cede_to_tick ();
452 }
453
454 static void wait_for_tick ();
455 static void wait_for_tick_begin ();
410}; 456};
411 457
412struct watcher_base 458struct watcher_base
413{ 459{
414 static struct EventAPI *GEventAPI; 460 static struct EventAPI *GEventAPI;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines