Inexor
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
tools.hpp
Go to the documentation of this file.
1 
4 #pragma once
5 
6 
7 #include <boost/algorithm/clamp.hpp> // for clamp
8 #include <algorithm> // for max, min
9 #include <cstddef>
10 #include <map> // for swap
11 #include <new>
12 
24 #include "inexor/util/random.hpp" // for rnd, deterministic_rnd
25 
26 // TODO:
27 // Replace swap in sources
28 // Replace rnd in sources (+ friends)
29 // Remove stringslice (replace with std::string methods)
30 
31 using std::swap;
32 using std::min;
33 using std::max;
34 
35 using boost::algorithm::clamp;
36 
39 #ifdef __GNUC__
40 #define bitscan(mask) (__builtin_ffs(mask)-1)
41 #else
42 #ifdef WIN32
43 #pragma intrinsic(_BitScanForward)
44 static inline int bitscan(uint mask)
45 {
46  ulong i;
47  return _BitScanForward(&i, mask) ? i : -1;
48 }
49 #else
50 static inline int bitscan(uint mask)
51 {
52  if(!mask) return -1;
53  int i = 1;
54  if(!(mask&0xFFFF)) { i += 16; mask >>= 16; }
55  if(!(mask&0xFF)) { i += 8; mask >>= 8; }
56  if(!(mask&0xF)) { i += 4; mask >>= 4; }
57  if(!(mask&3)) { i += 2; mask >>= 2; }
58  return i - (mask&1);
59 }
60 #endif
61 #endif
62 
64 inline int rnd(int Rmax) {
65  return inexor::util::rnd<int>(Rmax);
66 }
67 inline float rndscale(float Rmax) {
68  return inexor::util::rnd<float>(Rmax);
69 }
70 inline float detrnd(int seed, int Rmax) {
71  return inexor::util::deterministic_rnd<int>(seed, Rmax);
72 }
73 
74 
const T & max(const inexor::rpc::SharedVar< T > &a, const T &b)
Definition: SharedVar.hpp:224
unsigned long ulong
Definition: cube_types.hpp:10
unsigned int uint
Definition: cube_types.hpp:9
static int bitscan(uint mask)
Search the mask data from least significant bit(LSB) to the most significant bit(MSB) for a set bit(1...
Definition: tools.hpp:50
GLint GLint GLint GLint GLint GLint GLint GLbitfield mask
Definition: glexts.hpp:299
float detrnd(int seed, int Rmax)
Definition: tools.hpp:70
float rndscale(float Rmax)
Definition: tools.hpp:67
int rnd(int Rmax)
Function alias. Should be replaced inline actually!
Definition: tools.hpp:64
const T & min(const inexor::rpc::SharedVar< T > &a, const T &b)
Definition: SharedVar.hpp:210