ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/utils.C
(Generate patch)

Comparing deliantra/server/common/utils.C (file contents):
Revision 1.83 by root, Sun Dec 28 06:59:26 2008 UTC vs.
Revision 1.86 by root, Mon Jan 12 03:40:21 2009 UTC

51 state [1] = state [0] * 69069U; if (state [0] < 8U) state [0] += 8U; 51 state [1] = state [0] * 69069U; if (state [0] < 8U) state [0] += 8U;
52 state [2] = state [1] * 69069U; if (state [0] < 16U) state [0] += 16U; 52 state [2] = state [1] * 69069U; if (state [0] < 16U) state [0] += 16U;
53 state [3] = state [2] * 69069U; if (state [0] < 128U) state [0] += 128U; 53 state [3] = state [2] * 69069U; if (state [0] < 128U) state [0] += 128U;
54 54
55 for (int i = 11; --i; ) 55 for (int i = 11; --i; )
56 operator ()(); 56 next ();
57} 57}
58 58
59uint32_t 59uint32_t
60tausworthe_random_generator::next () 60tausworthe_random_generator::next ()
61{ 61{
65 state [3] = ((state [3] & 0xFFFFFF80U) << 13U) ^ (((state [3] << 3U) ^ state [3]) >> 12U); 65 state [3] = ((state [3] & 0xFFFFFF80U) << 13U) ^ (((state [3] << 3U) ^ state [3]) >> 12U);
66 66
67 return state [0] ^ state [1] ^ state [2] ^ state [3]; 67 return state [0] ^ state [1] ^ state [2] ^ state [3];
68} 68}
69 69
70template<class generator>
70uint32_t 71uint32_t
71tausworthe_random_generator::get_range (uint32_t num) 72random_number_generator<generator>::get_range (uint32_t num)
72{ 73{
73 return (next () * (uint64_t)num) >> 32U; 74 return (this->next () * (uint64_t)num) >> 32U;
74} 75}
75 76
76// return a number within (min .. max) 77// return a number within (min .. max)
78template<class generator>
77int 79int
78tausworthe_random_generator::get_range (int r_min, int r_max) 80random_number_generator<generator>::get_range (int r_min, int r_max)
79{ 81{
80 return r_min + get_range (max (r_max - r_min + 1, 0)); 82 return r_min + get_range (max (r_max - r_min + 1, 0));
81} 83}
84
85template struct random_number_generator<tausworthe_random_generator>;
86template struct random_number_generator<xorshift_random_generator>;
82 87
83/* 88/*
84 * The random functions here take luck into account when rolling random 89 * The random functions here take luck into account when rolling random
85 * dice or numbers. This function has less of an impact the larger the 90 * dice or numbers. This function has less of an impact the larger the
86 * difference becomes in the random numbers. IE, the effect is lessened 91 * difference becomes in the random numbers. IE, the effect is lessened
221 int j; 226 int j;
222 227
223 if (!op->materialname) 228 if (!op->materialname)
224 return; 229 return;
225 230
226 if (change->materialname && strcmp (op->materialname, change->materialname)) 231 if (op->materialname != change->materialname)
227 return; 232 return;
228 233
229 if (!op->is_armor ()) 234 if (!op->is_armor ())
230 return; 235 return;
231 236
554 559
555#endif 560#endif
556 561
557/******************************************************************************/ 562/******************************************************************************/
558 563
564int
559void assign (char *dst, const char *src, int maxlen) 565assign (char *dst, const char *src, int maxsize)
560{ 566{
561 if (!src) 567 if (!src)
562 src = ""; 568 src = "";
563 569
564 int len = strlen (src); 570 int len = strlen (src);
565 571
566 if (len >= maxlen - 1) 572 if (len >= maxsize)
567 { 573 {
568 if (maxlen <= 4) 574 if (maxsize <= 4)
569 { 575 {
570 memset (dst, '.', maxlen - 1); 576 memset (dst, '.', maxsize - 2);
571 dst [maxlen - 1] = 0; 577 dst [maxsize - 1] = 0;
572 } 578 }
573 else 579 else
574 { 580 {
575 memcpy (dst, src, maxlen - 4); 581 memcpy (dst, src, maxsize - 4);
576 memcpy (dst + maxlen - 4, "...", 4); 582 memcpy (dst + maxsize - 4, "...", 4);
577 } 583 }
584
585 len = maxsize;
578 } 586 }
579 else 587 else
580 memcpy (dst, src, len + 1); 588 memcpy (dst, src, ++len);
589
590 return len;
581} 591}
582 592
583const char * 593const char *
584format (const char *format, ...) 594format (const char *format, ...)
585{ 595{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines