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.56 by root, Thu Feb 15 21:07:49 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>
87# define def(klass,name) EVENT_ ## klass ## _ ## name, 89# define def(klass,name) EVENT_ ## klass ## _ ## name,
88# include "eventinc.h" 90# include "eventinc.h"
89# undef def 91# undef def
90 NUM_EVENT_TYPES 92 NUM_EVENT_TYPES
91}; 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;
92 98
93#define ARG_AV(o) DT_AV , static_cast<AV *> (o) 99#define ARG_AV(o) DT_AV , static_cast<AV *> (o)
94#define ARG_INT(v) DT_INT , static_cast<int> (v) 100#define ARG_INT(v) DT_INT , static_cast<int> (v)
95#define ARG_INT64(v) DT_INT64 , static_cast<sint64> (v) 101#define ARG_INT64(v) DT_INT64 , static_cast<sint64> (v)
96#define ARG_DOUBLE(v) DT_DOUBLE, static_cast<double> (v) 102#define ARG_DOUBLE(v) DT_DOUBLE, static_cast<double> (v)
136 F_DESTROYED = 0x01, 142 F_DESTROYED = 0x01,
137 F_DEBUG_TRACE = 0x02, 143 F_DEBUG_TRACE = 0x02,
138 }; 144 };
139 145
140 // object is delete'd after the refcount reaches 0 146 // object is delete'd after the refcount reaches 0
147 int ACC (RW, flags);
141 mutable int ACC (RW, refcnt); 148 mutable int ACC (RW, refcnt);
142 int ACC (RW, flags);
143 149
144 MTH void refcnt_inc () const { ++refcnt; } 150 MTH void refcnt_inc () const { ++refcnt; }
145 MTH void refcnt_dec () const { --refcnt; } 151 MTH void refcnt_dec () const { --refcnt; }
146 152
147 MTH int refcnt_cnt () const; 153 MTH int refcnt_cnt () const;
183 189
184 virtual ~attachable (); 190 virtual ~attachable ();
185 191
186 attachable &operator =(const attachable &src); 192 attachable &operator =(const attachable &src);
187 193
194 bool vinvoke (event_type event, va_list &ap);
188 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
189 MTH void instantiate (); 206 MTH void instantiate ();
190 void reattach (); 207 void reattach ();
191 208
192protected: 209protected:
193 // do the real refcount checking work 210 // do the real refcount checking work
205 222
206extern struct global gbl_ev; 223extern struct global gbl_ev;
207 224
208////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 225//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
209 226
210struct object_freezer : dynbuf 227struct object_freezer : dynbuf_text
211{ 228{
212 AV *av; 229 AV *av;
213 230
214 object_freezer (); 231 object_freezer ();
215 ~object_freezer (); 232 ~object_freezer ();
335 352
336 operator bool () { return !!av; } 353 operator bool () { return !!av; }
337}; 354};
338 355
339// compatibility support, should be removed when no longer needed 356// compatibility support, should be removed when no longer needed
340int fprintf (object_freezer &freezer, const char *format, ...); 357void fprintf (object_freezer &freezer, const char *format, ...);
341int fputs (const char *s, object_freezer &freezer); 358void fputs (const char *s, object_freezer &freezer);
342 359
343struct object_thawer 360struct object_thawer
344{ 361{
345 SV *text; // text part 362 SV *text; // text part
346 AV *av; // perl part 363 AV *av; // perl part
357 ~object_thawer (); 374 ~object_thawer ();
358 375
359 void get (attachable *obj, int oid); 376 void get (attachable *obj, int oid);
360 377
361 // parse next line 378 // parse next line
362 void next_kv (); 379 void next ();
363 //TODO: remove
364 keyword get_kv ()
365 {
366 next_kv ();
367 return kw;
368 }
369
370 // skip the current key-value (usually fetch next line, for 380 // skip the current key-value (usually fetch next line, for
371 // multiline-fields, skips untilt he corresponding end-kw 381 // multiline-fields, skips untilt he corresponding end-kw
372 void skip_kv (); 382 void skip ();
373 383
384 //TODO: remove, deprecated
385 keyword get_kv ()
386 {
387 next ();
388 return kw;
389 }
390
374 const char *get_str () { return value; } // may be 0 391 char *get_str () { return value; } // may be 0
375 392
376 void get (shstr &sh) const; 393 void get (shstr &sh) const;
377 void get_ornull (shstr &sh) const { sh = value; } 394 void get_ornull (shstr &sh) const { sh = value; }
378 void get_ml (keyword kend, shstr &sh); 395 void get_ml (keyword kend, shstr &sh);
379 396
406 static struct CoroAPI *GCoroAPI; 423 static struct CoroAPI *GCoroAPI;
407 424
408 static int nready () { return CORO_NREADY; } 425 static int nready () { return CORO_NREADY; }
409 static int cede () { return CORO_CEDE ; } 426 static int cede () { return CORO_CEDE ; }
410 427
428 static double (*time)();
429 static double next_cede;
411 static int cede_counter; 430 static int cede_counter;
412 431
432 static void do_cede_every ();
433 static void do_cede_to_tick ();
434 static void do_cede_to_tick_every ();
435
413 static void cede_every (int count) 436 static void cede_every (int count)
414 { 437 {
415 if (++cede_counter >= count) 438 if (++cede_counter >= count)
416 { 439 do_cede_every ();
417 cede_counter = 0;
418
419 if (coroapi::nready ())
420 coroapi::cede ();
421 }
422 } 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 ();
423}; 456};
424 457
425struct watcher_base 458struct watcher_base
426{ 459{
427 static struct EventAPI *GEventAPI; 460 static struct EventAPI *GEventAPI;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines