--- deliantra/server/common/utils.C 2006/09/16 22:24:12 1.16 +++ deliantra/server/common/utils.C 2006/12/16 03:08:25 1.23 @@ -29,6 +29,8 @@ #include #include +#include +#include #include /* @@ -99,11 +101,7 @@ if (max < 1 || diff < 1) { -#ifndef WIN32 - LOG (llevError, "Calling random_roll with min=%lld max=%lld\n", min, max); -#else - LOG (llevError, "Calling random_roll with min=%I64d max=%I64d\n", min, max); -#endif + LOG (llevError, "Calling random_roll with min=%" PRId64 " max=%" PRId64 "\n", min, max); return (min); /* avoids a float exception */ } @@ -260,10 +258,7 @@ } /* adjust overall chance below */ if (destroy && rndm (0, 1)) - { - remove_ob (op); - free_object (op); - } + op->destroy (); } } @@ -547,14 +542,40 @@ ///////////////////////////////////////////////////////////////////////////// -void *alloc (int s) throw (std::bad_alloc) +#if 0 +refcounted *refcounted::rc_first; + +refcounted::refcounted () { - void *p = g_slice_alloc (s); + refcnt = 0; + rc_next = rc_first; + rc_first = this; +} - if (!p) +refcounted::~refcounted () +{ + assert (!rc_next); + assert (!refcnt); +} +#endif + +void *salloc (int size) throw (std::bad_alloc) +{ + void *ptr = g_slice_alloc (size); + + if (!ptr) throw std::bad_alloc (); - return p; + return ptr; +} + +void *salloc (int size, void *src) throw (std::bad_alloc) +{ + void *ptr = salloc (size); + + memcpy (ptr, src, size); + + return ptr; } void assign (char *dst, const char *src, int maxlen) @@ -581,3 +602,11 @@ memcpy (dst, src, len + 1); } +tstamp now () +{ + struct timeval tv; + + gettimeofday (&tv, 0); + return tstamp (tv.tv_sec) + tstamp (tv.tv_usec) * tstamp (1e-6); +} +