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.72 by root, Wed Apr 30 16:26:28 2008 UTC vs.
Revision 1.76 by root, Thu May 8 11:39:23 2008 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * 5 *
6 * Deliantra is free software: you can redistribute it and/or modify 6 * Deliantra is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or 8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version. 9 * (at your option) any later version.
262 { 262 {
263 sfree ((char *)p, s); 263 sfree ((char *)p, s);
264 } 264 }
265}; 265};
266 266
267// makes dynamically allocated objects zero-initialised
268struct slice_allocated
269{
270 void *operator new (size_t s, void *p)
271 {
272 return p;
273 }
274
275 void *operator new (size_t s)
276 {
277 return salloc<char> (s);
278 }
279
280 void *operator new[] (size_t s)
281 {
282 return salloc<char> (s);
283 }
284
285 void operator delete (void *p, size_t s)
286 {
287 sfree ((char *)p, s);
288 }
289
290 void operator delete[] (void *p, size_t s)
291 {
292 sfree ((char *)p, s);
293 }
294};
295
267// a STL-compatible allocator that uses g_slice 296// a STL-compatible allocator that uses g_slice
268// boy, this is verbose 297// boy, this is verbose
269template<typename Tp> 298template<typename Tp>
270struct slice_allocator 299struct slice_allocator
271{ 300{
336 } 365 }
337 366
338 void seed (uint32_t seed); 367 void seed (uint32_t seed);
339 uint32_t next (); 368 uint32_t next ();
340 369
341 // uniform distribution 370 // uniform distribution, 0 .. num - 1
342 uint32_t operator ()(uint32_t num) 371 uint32_t operator ()(uint32_t num)
343 { 372 {
344 return is_constant (num) 373 return is_constant (num)
345 ? (next () * (uint64_t)num) >> 32U 374 ? (next () * (uint64_t)num) >> 32U
346 : get_range (num); 375 : get_range (num);
364 int get_range (int r_min, int r_max); 393 int get_range (int r_min, int r_max);
365}; 394};
366 395
367typedef tausworthe_random_generator rand_gen; 396typedef tausworthe_random_generator rand_gen;
368 397
369extern rand_gen rndm; 398extern rand_gen rndm, rmg_rndm;
370 399
371INTERFACE_CLASS (attachable) 400INTERFACE_CLASS (attachable)
372struct refcnt_base 401struct refcnt_base
373{ 402{
374 typedef int refcnt_t; 403 typedef int refcnt_t;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines