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.71 by root, Sun Apr 20 06:20:38 2008 UTC vs.
Revision 1.77 by root, Thu May 8 14:20:19 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.
224 g_slice_free1 (n * sizeof (T), (void *)ptr); 224 g_slice_free1 (n * sizeof (T), (void *)ptr);
225 assert (slice_alloc >= 0);//D 225 assert (slice_alloc >= 0);//D
226 } 226 }
227} 227}
228 228
229// nulls the pointer
230template<typename T>
231inline void sfree0 (T *&ptr, int n = 1) throw ()
232{
233 sfree<T> (ptr, n);
234 ptr = 0;
235}
236
229// makes dynamically allocated objects zero-initialised 237// makes dynamically allocated objects zero-initialised
230struct zero_initialised 238struct zero_initialised
231{ 239{
232 void *operator new (size_t s, void *p) 240 void *operator new (size_t s, void *p)
233 { 241 {
241 } 249 }
242 250
243 void *operator new[] (size_t s) 251 void *operator new[] (size_t s)
244 { 252 {
245 return salloc0<char> (s); 253 return salloc0<char> (s);
254 }
255
256 void operator delete (void *p, size_t s)
257 {
258 sfree ((char *)p, s);
259 }
260
261 void operator delete[] (void *p, size_t s)
262 {
263 sfree ((char *)p, s);
264 }
265};
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);
246 } 283 }
247 284
248 void operator delete (void *p, size_t s) 285 void operator delete (void *p, size_t s)
249 { 286 {
250 sfree ((char *)p, s); 287 sfree ((char *)p, s);
328 } 365 }
329 366
330 void seed (uint32_t seed); 367 void seed (uint32_t seed);
331 uint32_t next (); 368 uint32_t next ();
332 369
333 // uniform distribution 370 // uniform distribution, 0 .. max (0, num - 1)
334 uint32_t operator ()(uint32_t num) 371 uint32_t operator ()(uint32_t num)
335 { 372 {
336 return is_constant (num) 373 return is_constant (num)
337 ? (next () * (uint64_t)num) >> 32U 374 ? (next () * (uint64_t)num) >> 32U
338 : get_range (num); 375 : get_range (num);
356 int get_range (int r_min, int r_max); 393 int get_range (int r_min, int r_max);
357}; 394};
358 395
359typedef tausworthe_random_generator rand_gen; 396typedef tausworthe_random_generator rand_gen;
360 397
361extern rand_gen rndm; 398extern rand_gen rndm, rmg_rndm;
362 399
363INTERFACE_CLASS (attachable) 400INTERFACE_CLASS (attachable)
364struct refcnt_base 401struct refcnt_base
365{ 402{
366 typedef int refcnt_t; 403 typedef int refcnt_t;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines