… | |
… | |
61 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
61 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
62 | |
62 | |
63 | void cfperl_init (); |
63 | void cfperl_init (); |
64 | void cfperl_main (); |
64 | void cfperl_main (); |
65 | void cfperl_emergency_save (); |
65 | void cfperl_emergency_save (); |
|
|
66 | void cfperl_cleanup (int make_core); |
66 | |
67 | |
67 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
68 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
68 | |
69 | |
69 | // virtual server time, excluding time jumps and lag |
70 | // virtual server time, excluding time jumps and lag |
70 | extern double runtime; |
71 | extern double runtime; |
… | |
… | |
130 | |
131 | |
131 | static unordered_vector<attachable *> mortals; |
132 | static unordered_vector<attachable *> mortals; |
132 | MTH static void check_mortals (); |
133 | MTH static void check_mortals (); |
133 | |
134 | |
134 | enum { |
135 | enum { |
135 | F_DESTROYED = 0x01, |
136 | F_DESTROYED = 0x01, |
|
|
137 | F_DEBUG_TRACE = 0x02, |
136 | }; |
138 | }; |
137 | |
139 | |
138 | // object is delete'd after the refcount reaches 0 |
140 | // object is delete'd after the refcount reaches 0 |
|
|
141 | int ACC (RW, flags); |
139 | mutable int ACC (RW, refcnt); |
142 | mutable int ACC (RW, refcnt); |
140 | int ACC (RW, flags); |
|
|
141 | |
143 | |
142 | MTH void refcnt_inc () const { ++refcnt; } |
144 | MTH void refcnt_inc () const { ++refcnt; } |
143 | MTH void refcnt_dec () const { --refcnt; } |
145 | MTH void refcnt_dec () const { --refcnt; } |
144 | |
146 | |
145 | MTH int refcnt_cnt () const; |
147 | MTH int refcnt_cnt () const; |
… | |
… | |
333 | |
335 | |
334 | operator bool () { return !!av; } |
336 | operator bool () { return !!av; } |
335 | }; |
337 | }; |
336 | |
338 | |
337 | // compatibility support, should be removed when no longer needed |
339 | // compatibility support, should be removed when no longer needed |
338 | int fprintf (object_freezer &freezer, const char *format, ...); |
340 | void fprintf (object_freezer &freezer, const char *format, ...); |
339 | int fputs (const char *s, object_freezer &freezer); |
341 | void fputs (const char *s, object_freezer &freezer); |
340 | |
342 | |
341 | struct object_thawer |
343 | struct object_thawer |
342 | { |
344 | { |
343 | SV *text; // text part |
345 | SV *text; // text part |
344 | AV *av; // perl part |
346 | AV *av; // perl part |
|
|
347 | int linenum; |
345 | char *line; // current beginning of line |
348 | char *line; // current beginning of line |
346 | char *last_keyword, *last_value; |
349 | keyword kw; |
|
|
350 | char *kw_str, *value; |
347 | const char *name; |
351 | const char *name; |
348 | |
352 | |
349 | operator bool () { return !!text; } |
353 | operator bool () { return !!text; } |
350 | |
354 | |
351 | object_thawer (const char *path = 0); |
355 | object_thawer (const char *path = 0); |
352 | object_thawer (const char *data, AV *perlav); |
356 | object_thawer (const char *data, AV *perlav); |
353 | ~object_thawer (); |
357 | ~object_thawer (); |
354 | |
358 | |
355 | void get (attachable *obj, int oid); |
359 | void get (attachable *obj, int oid); |
356 | |
360 | |
357 | keyword get_kv (); // also parse value for later use |
361 | // parse next line |
358 | 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 (); |
359 | |
366 | |
|
|
367 | //TODO: remove, deprecated |
|
|
368 | keyword get_kv () |
|
|
369 | { |
|
|
370 | next (); |
|
|
371 | return kw; |
|
|
372 | } |
|
|
373 | |
360 | const char *get_str () { return last_value; } // may be 0 |
374 | char *get_str () { return value; } // may be 0 |
361 | |
375 | |
362 | void get (shstr &sh) const; |
376 | void get (shstr &sh) const; |
363 | void get_ornull (shstr &sh) const { sh = last_value; } |
377 | void get_ornull (shstr &sh) const { sh = value; } |
364 | void get_ml (keyword kend, shstr &sh); |
378 | void get_ml (keyword kend, shstr &sh); |
365 | |
379 | |
366 | sint32 get_sint32 () const; |
380 | sint32 get_sint32 () const; |
367 | sint64 get_sint64 () const; |
381 | sint64 get_sint64 () const; |
368 | double get_double () const; |
382 | double get_double () const; |
… | |
… | |
377 | void get (uint16 &i) { i = get_sint32 (); } |
391 | void get (uint16 &i) { i = get_sint32 (); } |
378 | void get (sint32 &i) { i = get_sint32 (); } |
392 | void get (sint32 &i) { i = get_sint32 (); } |
379 | |
393 | |
380 | void get (uint32 &i) { i = get_sint64 (); } |
394 | void get (uint32 &i) { i = get_sint64 (); } |
381 | void get (sint64 &i) { i = get_sint64 (); } |
395 | void get (sint64 &i) { i = get_sint64 (); } |
382 | }; |
|
|
383 | |
396 | |
|
|
397 | bool parse_error (const char *type = 0, const char *name = 0, bool skip = true); |
|
|
398 | }; |
|
|
399 | |
|
|
400 | //TODO: remove |
384 | char *fgets (char *s, int n, object_thawer &thawer); |
401 | char *fgets (char *s, int n, object_thawer &thawer); |
385 | |
402 | |
386 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
403 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
387 | |
404 | |
388 | struct coroapi { |
405 | struct coroapi { |
389 | static struct CoroAPI *GCoroAPI; |
406 | static struct CoroAPI *GCoroAPI; |
390 | |
407 | |
391 | static int nready () { return CORO_NREADY; } |
408 | static int nready () { return CORO_NREADY; } |
392 | static int cede () { return CORO_CEDE ; } |
409 | static int cede () { return CORO_CEDE ; } |
393 | |
410 | |
|
|
411 | static double (*time)(); |
|
|
412 | static double next_cede; |
394 | static int cede_counter; |
413 | static int cede_counter; |
395 | |
414 | |
|
|
415 | static void do_cede_every (); |
|
|
416 | static void do_cede_to_tick (); |
|
|
417 | static void do_cede_to_tick_every (); |
|
|
418 | |
396 | static void cede_every (int count) |
419 | static void cede_every (int count) |
397 | { |
420 | { |
398 | if (++cede_counter >= count) |
421 | if (++cede_counter >= count) |
399 | { |
422 | do_cede_every (); |
400 | cede_counter = 0; |
|
|
401 | |
|
|
402 | if (coroapi::nready ()) |
|
|
403 | coroapi::cede (); |
|
|
404 | } |
|
|
405 | } |
423 | } |
|
|
424 | |
|
|
425 | static void cede_to_tick () |
|
|
426 | { |
|
|
427 | if (time () >= next_cede) |
|
|
428 | do_cede_to_tick (); |
|
|
429 | } |
|
|
430 | |
|
|
431 | static void cede_to_tick_every (int count) |
|
|
432 | { |
|
|
433 | if (++cede_counter >= count) |
|
|
434 | cede_to_tick (); |
|
|
435 | } |
|
|
436 | |
|
|
437 | static void wait_for_tick (); |
|
|
438 | static void wait_for_tick_begin (); |
406 | }; |
439 | }; |
407 | |
440 | |
408 | struct watcher_base |
441 | struct watcher_base |
409 | { |
442 | { |
410 | static struct EventAPI *GEventAPI; |
443 | static struct EventAPI *GEventAPI; |