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.101 by root, Wed Apr 28 19:49:50 2010 UTC vs.
Revision 1.104 by root, Thu Apr 29 21:21:34 2010 UTC

102// sign returns -1 or +1 102// sign returns -1 or +1
103template<typename T> 103template<typename T>
104static inline T sign (T v) { return v < 0 ? -1 : +1; } 104static inline T sign (T v) { return v < 0 ? -1 : +1; }
105// relies on 2c representation 105// relies on 2c representation
106template<> 106template<>
107inline sint8 sign (sint8 v) { return 1 - (sint8 (uint8 (v) >> 7) * 2); } 107inline sint8 sign (sint8 v) { return 1 - (sint8 (uint8 (v) >> 7) * 2); }
108template<>
109inline sint16 sign (sint16 v) { return 1 - (sint16 (uint16 (v) >> 15) * 2); }
110template<>
111inline sint32 sign (sint32 v) { return 1 - (sint32 (uint32 (v) >> 31) * 2); }
108 112
109// sign0 returns -1, 0 or +1 113// sign0 returns -1, 0 or +1
110template<typename T> 114template<typename T>
111static inline T sign0 (T v) { return v ? sign (v) : 0; } 115static inline T sign0 (T v) { return v ? sign (v) : 0; }
112 116
482 } 486 }
483 487
484 // return a number within the closed interval [min .. max] 488 // return a number within the closed interval [min .. max]
485 int operator () (int r_min, int r_max) 489 int operator () (int r_min, int r_max)
486 { 490 {
487 return is_constant (r_min) && is_constant (r_max) && r_min <= r_max 491 return is_constant (r_min <= r_max) && r_min <= r_max
488 ? r_min + operator ()(r_max - r_min + 1) 492 ? r_min + operator ()(r_max - r_min + 1)
489 : get_range (r_min, r_max); 493 : get_range (r_min, r_max);
490 } 494 }
491 495
492 // return a number within the closed interval [0..1] 496 // return a number within the closed interval [0..1]
572typedef refptr<maptile> maptile_ptr; 576typedef refptr<maptile> maptile_ptr;
573typedef refptr<object> object_ptr; 577typedef refptr<object> object_ptr;
574typedef refptr<archetype> arch_ptr; 578typedef refptr<archetype> arch_ptr;
575typedef refptr<client> client_ptr; 579typedef refptr<client> client_ptr;
576typedef refptr<player> player_ptr; 580typedef refptr<player> player_ptr;
581typedef refptr<region> region_ptr;
577 582
578#define STRHSH_NULL 2166136261 583#define STRHSH_NULL 2166136261
579 584
580static inline uint32_t 585static inline uint32_t
581strhsh (const char *s) 586strhsh (const char *s)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines