ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/include/util.h
(Generate patch)

Comparing deliantra/server/include/util.h (file contents):
Revision 1.38 by root, Thu Feb 15 18:09:34 2007 UTC vs.
Revision 1.43 by root, Mon Apr 23 18:09:57 2007 UTC

18 18
19#include <shstr.h> 19#include <shstr.h>
20#include <traits.h> 20#include <traits.h>
21 21
22// use a gcc extension for auto declarations until ISO C++ sanctifies them 22// use a gcc extension for auto declarations until ISO C++ sanctifies them
23#define AUTODECL(var,expr) typeof(expr) var = (expr) 23#define auto(var,expr) typeof(expr) var = (expr)
24 24
25// very ugly macro that basicaly declares and initialises a variable 25// very ugly macro that basicaly declares and initialises a variable
26// that is in scope for the next statement only 26// that is in scope for the next statement only
27// works only for stuff that can be assigned 0 and converts to false 27// works only for stuff that can be assigned 0 and converts to false
28// (note: works great for pointers) 28// (note: works great for pointers)
262 262
263 void seed (uint32_t seed); 263 void seed (uint32_t seed);
264 uint32_t next (); 264 uint32_t next ();
265 265
266 // uniform distribution 266 // uniform distribution
267 uint32_t operator ()(uint32_t r_max) 267 uint32_t operator ()(uint32_t num)
268 { 268 {
269 return is_constant (r_max) 269 return is_constant (num)
270 ? this->next () % r_max 270 ? (next () * (uint64_t)num) >> 32U
271 : get_range (r_max); 271 : get_range (num);
272 } 272 }
273 273
274 // return a number within (min .. max) 274 // return a number within (min .. max)
275 int operator () (int r_min, int r_max) 275 int operator () (int r_min, int r_max)
276 { 276 {
277 return is_constant (r_min) && is_constant (r_max) 277 return is_constant (r_min) && is_constant (r_max) && r_min <= r_max
278 ? r_min + (*this) (max (r_max - r_min + 1, 1)) 278 ? r_min + operator ()(r_max - r_min + 1)
279 : get_range (r_min, r_max); 279 : get_range (r_min, r_max);
280 } 280 }
281 281
282 double operator ()() 282 double operator ()()
283 { 283 {
399 } 399 }
400 400
401 void erase (T *obj) 401 void erase (T *obj)
402 { 402 {
403 assert (obj->*index); 403 assert (obj->*index);
404 int pos = obj->*index; 404 unsigned int pos = obj->*index;
405 obj->*index = 0; 405 obj->*index = 0;
406 406
407 if (pos < this->size ()) 407 if (pos < this->size ())
408 { 408 {
409 (*this)[pos - 1] = (*this)[this->size () - 1]; 409 (*this)[pos - 1] = (*this)[this->size () - 1];
434// return current time as timestampe 434// return current time as timestampe
435tstamp now (); 435tstamp now ();
436 436
437int similar_direction (int a, int b); 437int similar_direction (int a, int b);
438 438
439// like printf, but returns a std::string
440const std::string format (const char *format, ...);
441
439#endif 442#endif
440 443

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines