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.53 by root, Thu Feb 1 19:15:39 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,
135 }; 136 };
136 137
137 // object is delete'd after the refcount reaches 0 138 // object is delete'd after the refcount reaches 0
138 mutable int refcnt; 139 mutable int ACC (RW, refcnt);
139 int flags; 140 int ACC (RW, flags);
140 141
141 void refcnt_inc () const { ++refcnt; } 142 MTH void refcnt_inc () const { ++refcnt; }
142 void refcnt_dec () const { --refcnt; } 143 MTH void refcnt_dec () const { --refcnt; }
143 144
145 MTH int refcnt_cnt () const;
144 // check wether the object has died and destroy 146 // check wether the object has died and destroy
145 void refcnt_chk () { if (refcnt <= 0) do_check (); } 147 MTH void refcnt_chk () { if (refcnt <= 0) do_check (); }
146 148
147 // destroy the object unless it was already destroyed 149 // destroy the object unless it was already destroyed
148 // this politely asks everybody interested the reduce 150 // this politely asks everybody interested the reduce
149 // the refcount to 0 as soon as possible. 151 // the refcount to 0 as soon as possible.
150 void destroy (); 152 MTH void destroy ();
151 153
152 // return wether an object was destroyed already 154 // return wether an object was destroyed already
153 bool destroyed () const { return flags & F_DESTROYED; } 155 MTH bool destroyed () const { return flags & F_DESTROYED; }
154 156
155 virtual void gather_callbacks (AV *&callbacks, event_type event) const; 157 virtual void gather_callbacks (AV *&callbacks, event_type event) const;
156 158
157#if 0 159#if 0
158private: 160private:
162 164
163 HV *self; // CF+ perl self 165 HV *self; // CF+ perl self
164 AV *cb; // CF+ callbacks 166 AV *cb; // CF+ callbacks
165 shstr attach; // generic extension attachment information 167 shstr attach; // generic extension attachment information
166 168
169 void sever_self (); // sever this object from its self, if it has one.
167 void optimise (); // possibly save some memory by destroying unneeded data 170 void optimise (); // possibly save some memory by destroying unneeded data
168 171
169 attachable () 172 attachable ()
170 : flags (0), refcnt (0), self (0), cb (0), attach (0) 173 : flags (0), refcnt (0), self (0), cb (0), attach (0)
171 { 174 {
172 } 175 }
179 virtual ~attachable (); 182 virtual ~attachable ();
180 183
181 attachable &operator =(const attachable &src); 184 attachable &operator =(const attachable &src);
182 185
183 bool invoke (event_type event, ...); 186 bool invoke (event_type event, ...);
184 void instantiate (); 187 MTH void instantiate ();
185 void reattach (); 188 void reattach ();
186 189
187protected: 190protected:
188 // do the real refcount checking work 191 // do the real refcount checking work
189 void do_check (); 192 void do_check ();
248 } 251 }
249 252
250 *p = '\n'; 253 *p = '\n';
251 } 254 }
252 255
253 void put (keyword k, const char *v) 256 void put (keyword k, const char *v = 0)
254 { 257 {
255 put_string (k, v); 258 put_string (k, v);
256 } 259 }
257 260
258 void put (keyword k, const shstr &v) 261 void put (keyword k, const shstr &v)
323 void put (keyword k, const refptr<T> &v) 326 void put (keyword k, const refptr<T> &v)
324 { 327 {
325 put (k, (T *)v); 328 put (k, (T *)v);
326 } 329 }
327 330
328 bool save (const char *filename); 331 bool save (const char *path);
329 char *as_string (); // like strdup 332 char *as_string (); // like strdup
330 333
331 operator bool () { return !!av; } 334 operator bool () { return !!av; }
332}; 335};
333 336
337 340
338struct object_thawer 341struct object_thawer
339{ 342{
340 SV *text; // text part 343 SV *text; // text part
341 AV *av; // perl part 344 AV *av; // perl part
345 int linenum;
342 char *line; // current beginning of line 346 char *line; // current beginning of line
343 char *last_keyword, *last_value; 347 char *last_keyword, *last_value;
348 const char *name;
344 349
345 operator bool () { return !!text; } 350 operator bool () { return !!text; }
346 351
347 object_thawer (const char *filename = 0); 352 object_thawer (const char *path = 0);
348 object_thawer (const char *data, AV *perlav); 353 object_thawer (const char *data, AV *perlav);
349 ~object_thawer (); 354 ~object_thawer ();
350 355
351 void get (attachable *obj, int oid); 356 void get (attachable *obj, int oid);
352 357
373 void get (uint16 &i) { i = get_sint32 (); } 378 void get (uint16 &i) { i = get_sint32 (); }
374 void get (sint32 &i) { i = get_sint32 (); } 379 void get (sint32 &i) { i = get_sint32 (); }
375 380
376 void get (uint32 &i) { i = get_sint64 (); } 381 void get (uint32 &i) { i = get_sint64 (); }
377 void get (sint64 &i) { i = get_sint64 (); } 382 void get (sint64 &i) { i = get_sint64 (); }
378};
379 383
384 bool parse_error (keyword kw, const char *type = 0, const char *name = 0, bool skip = true);
385};
386
387//TODO: remove
380char *fgets (char *s, int n, object_thawer &thawer); 388char *fgets (char *s, int n, object_thawer &thawer);
381 389
382////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 390//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
383 391
384struct coroapi { 392struct coroapi {
385 static struct CoroAPI *GCoroAPI; 393 static struct CoroAPI *GCoroAPI;
386 394
387 static int nready () { return CORO_NREADY; } 395 static int nready () { return CORO_NREADY; }
388 static int cede () { return CORO_CEDE ; } 396 static int cede () { return CORO_CEDE ; }
397
398 static int cede_counter;
399
400 static void cede_every (int count)
401 {
402 if (++cede_counter >= count)
403 {
404 cede_counter = 0;
405
406 if (coroapi::nready ())
407 coroapi::cede ();
408 }
409 }
389}; 410};
390 411
391struct watcher_base 412struct watcher_base
392{ 413{
393 static struct EventAPI *GEventAPI; 414 static struct EventAPI *GEventAPI;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines