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.65 by root, Thu May 24 03:33:29 2007 UTC vs.
Revision 1.66 by root, Sat May 26 15:44:03 2007 UTC

110#define ARG_CLIENT(o) DT_CLIENT, (void *)(static_cast<client *> (o)) 110#define ARG_CLIENT(o) DT_CLIENT, (void *)(static_cast<client *> (o))
111#define ARG_PARTY(o) DT_PARTY , (void *)(static_cast<party *> (o)) 111#define ARG_PARTY(o) DT_PARTY , (void *)(static_cast<party *> (o))
112#define ARG_REGION(o) DT_REGION, (void *)(static_cast<region *> (o)) 112#define ARG_REGION(o) DT_REGION, (void *)(static_cast<region *> (o))
113 113
114// the ", ## __VA_ARGS" is, unfortunately, a gnu-cpp extension 114// the ", ## __VA_ARGS" is, unfortunately, a gnu-cpp extension
115 115#define INVOKE(obj,event, ...) (expect_false ((obj)->should_invoke (event)) ? (obj)->invoke (event, ## __VA_ARGS__, DT_END) : 0)
116// all these return true when the normal event processing should be skipped (if any)
117#define INVOKE_GLOBAL(event, ...) gbl_ev.invoke (EVENT_ ## GLOBAL ## _ ## event, ## __VA_ARGS__, DT_END) 116#define INVOKE_GLOBAL(event, ...) INVOKE (&gbl_ev, EVENT_ ## GLOBAL ## _ ## event, ## __VA_ARGS__)
118#define INVOKE_ATTACHABLE(event, obj, ...) (obj)->invoke (EVENT_ ## ATTACHABLE ## _ ## event, ## __VA_ARGS__, DT_END) 117#define INVOKE_ATTACHABLE(event, obj, ...) INVOKE (obj , EVENT_ ## ATTACHABLE ## _ ## event, ## __VA_ARGS__)
119#define INVOKE_OBJECT(event, obj, ...) (obj)->invoke (EVENT_ ## OBJECT ## _ ## event, ## __VA_ARGS__, DT_END) 118#define INVOKE_OBJECT(event, obj, ...) INVOKE (obj , EVENT_ ## OBJECT ## _ ## event, ## __VA_ARGS__)
120#define INVOKE_CLIENT(event, obj, ...) (obj)->invoke (EVENT_ ## CLIENT ## _ ## event, ## __VA_ARGS__, DT_END) 119#define INVOKE_CLIENT(event, obj, ...) INVOKE (obj , EVENT_ ## CLIENT ## _ ## event, ## __VA_ARGS__)
121#define INVOKE_PLAYER(event, obj, ...) (obj)->invoke (EVENT_ ## PLAYER ## _ ## event, ## __VA_ARGS__, DT_END) 120#define INVOKE_PLAYER(event, obj, ...) INVOKE (obj , EVENT_ ## PLAYER ## _ ## event, ## __VA_ARGS__)
122#define INVOKE_MAP(event, obj, ...) (obj)->invoke (EVENT_ ## MAP ## _ ## event, ## __VA_ARGS__, DT_END) 121#define INVOKE_MAP(event, obj, ...) INVOKE (obj , EVENT_ ## MAP ## _ ## event, ## __VA_ARGS__)
123 122
124//TODO should index into @result 123//TODO should index into @result
125#define RESULT(idx,type) cfperl_result_ ## type (idx) 124#define RESULT(idx,type) cfperl_result_ ## type (idx)
126#define RESULT_DOUBLE(idx) RESULT(idx, DOUBLE) 125#define RESULT_DOUBLE(idx) RESULT(idx, DOUBLE)
127#define RESULT_INT(idx) RESULT(idx, INT) 126#define RESULT_INT(idx) RESULT(idx, INT)
190 189
191 virtual ~attachable (); 190 virtual ~attachable ();
192 191
193 attachable &operator =(const attachable &src); 192 attachable &operator =(const attachable &src);
194 193
195 bool vinvoke (event_type event, va_list &ap); 194 // used to _quickly_ device wether to shortcut the evaluation
195 bool should_invoke (event_type event)
196 {
197 return ev_want_event [event] || cb;
198 }
199
196 bool invoke (event_type event, ...) 200 bool invoke (event_type event, ...);
197 {
198 if (ev_want_event [event] || cb)
199 {
200 va_list ap;
201 va_start (ap, event);
202 vinvoke (event, ap);
203 va_end (ap);
204 }
205 }
206 201
207 MTH void instantiate (); 202 MTH void instantiate ();
208 void reattach (); 203 void reattach ();
209 204
210protected: 205protected:
237 // used only for user-defined key-value pairs 232 // used only for user-defined key-value pairs
238 void put (const shstr &k, const shstr &v) 233 void put (const shstr &k, const shstr &v)
239 { 234 {
240 add (k); 235 add (k);
241 236
242 if (v) 237 if (expect_true (v))
243 add (' '), add (v); 238 add (' '), add (v);
244 239
245 add ('\n'); 240 add ('\n');
246 } 241 }
247 242
262 257
263 char *p = (char *)alloc (klen + vlen + 1); 258 char *p = (char *)alloc (klen + vlen + 1);
264 259
265 memcpy (p, keyword_str [k], klen); p += klen; 260 memcpy (p, keyword_str [k], klen); p += klen;
266 261
267 if (v) 262 if (expect_true (v))
268 { 263 {
269 *p++ = ' '; vlen--; 264 *p++ = ' '; vlen--;
270 memcpy (p, v, vlen); p += vlen; 265 memcpy (p, v, vlen); p += vlen;
271 } 266 }
272 267
310 305
311 void put (keyword kbeg, keyword kend, const shstr &v) 306 void put (keyword kbeg, keyword kend, const shstr &v)
312 { 307 {
313 add (keyword_str [kbeg], keyword_len [kbeg]); add ('\n'); 308 add (keyword_str [kbeg], keyword_len [kbeg]); add ('\n');
314 309
315 if (v) 310 if (expect_true (v))
316 { 311 {
317 add (v); 312 add (v);
318 add ('\n'); 313 add ('\n');
319 } 314 }
320 315
334 void put (keyword k, unsigned long long v) { put_(k, (sint64)v); } 329 void put (keyword k, unsigned long long v) { put_(k, (sint64)v); }
335 330
336 template<typename T> 331 template<typename T>
337 void put (keyword k, const T *v) 332 void put (keyword k, const T *v)
338 { 333 {
339 if (v) 334 if (expect_true (v))
340 put (k, v->name); 335 put (k, v->name);
341 else 336 else
342 put (k, (const char *)0); 337 put (k, (const char *)0);
343 } 338 }
344 339
358void fprintf (object_freezer &freezer, const char *format, ...); 353void fprintf (object_freezer &freezer, const char *format, ...);
359void fputs (const char *s, object_freezer &freezer); 354void fputs (const char *s, object_freezer &freezer);
360 355
361struct object_thawer 356struct object_thawer
362{ 357{
358 char *line; // current beginning of line
363 SV *text; // text part 359 SV *text; // text part
364 AV *av; // perl part 360 AV *av; // perl part
365 int linenum; 361 int linenum;
366 char *line; // current beginning of line
367 keyword kw; 362 keyword kw;
368 char *kw_str, *value; 363 char *kw_str; // the keyword parsed, as string
364 char *value; // the value, or 0 if no value
365 char *value_nn; // the value, or the empty string if no value
369 const char *name; 366 const char *name;
370 367
371 operator bool () { return !!text; } 368 operator bool () { return !!text; }
372 369
373 object_thawer (const char *path = 0); 370 object_thawer (const char *path = 0);
388 next (); 385 next ();
389 return kw; 386 return kw;
390 } 387 }
391 388
392 char *get_str () { return value; } // may be 0 389 char *get_str () { return value; } // may be 0
390 void get_ml (keyword kend, shstr &sh);
393 391
394 void get (shstr &sh) const;
395 void get_ornull (shstr &sh) const { sh = value; } 392 void get_ornull (shstr &sh) const { sh = value; }
396 void get_ml (keyword kend, shstr &sh); 393 void get (shstr &sh) const { sh = value; } // might want to check for non-null here
397 394
395 bool get_bool () const { return *value_nn == '1'; }
398 sint32 get_sint32 () const; 396 sint32 get_sint32 () const;
399 sint64 get_sint64 () const; 397 sint64 get_sint64 () const { return atoll (value_nn); }
400 double get_double () const; 398 double get_double () const { return atof (value_nn); }
401 399
402 void get (float &v) { v = get_double (); } 400 void get (float &v) { v = get_double (); }
403 void get (double &v) { v = get_double (); } 401 void get (double &v) { v = get_double (); }
404 402
405 void get (bool &i) { i = get_sint32 (); } 403 void get (bool &i) { i = get_bool (); }
406 void get (sint8 &i) { i = get_sint32 (); } 404 void get (sint8 &i) { i = get_sint32 (); }
407 void get (uint8 &i) { i = get_sint32 (); } 405 void get (uint8 &i) { i = get_sint32 (); }
408 void get (sint16 &i) { i = get_sint32 (); } 406 void get (sint16 &i) { i = get_sint32 (); }
409 void get (uint16 &i) { i = get_sint32 (); } 407 void get (uint16 &i) { i = get_sint32 (); }
410 void get (sint32 &i) { i = get_sint32 (); } 408 void get (sint32 &i) { i = get_sint32 (); }
434 static void do_cede_to_tick (); 432 static void do_cede_to_tick ();
435 static void do_cede_to_tick_every (); 433 static void do_cede_to_tick_every ();
436 434
437 static void cede_every (int count) 435 static void cede_every (int count)
438 { 436 {
439 if (++cede_counter >= count) 437 if (expect_false (++cede_counter >= count))
440 do_cede_every (); 438 do_cede_every ();
441 } 439 }
442 440
443 static void cede_to_tick () 441 static void cede_to_tick ()
444 { 442 {
445 if (time () >= next_cede) 443 if (expect_false (time () >= next_cede))
446 do_cede_to_tick (); 444 do_cede_to_tick ();
447 } 445 }
448 446
449 static void cede_to_tick_every (int count) 447 static void cede_to_tick_every (int count)
450 { 448 {
451 if (++cede_counter >= count) 449 if (expect_false (++cede_counter >= count))
452 cede_to_tick (); 450 cede_to_tick ();
453 } 451 }
454 452
455 static void wait_for_tick (); 453 static void wait_for_tick ();
456 static void wait_for_tick_begin (); 454 static void wait_for_tick_begin ();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines