34 #include "swe_types.h" 35 #include "swe_binarybuf.h" 37 #include "swe_systems.h" 38 #include "swe_serialize.h" 45 void delay(
unsigned int ms);
46 int countBits(
unsigned long);
48 int rand(
int min,
int max);
49 float randf(
float min,
float max);
51 u32 crc32b(
const std::string &);
52 u32 crc32b(
const u8*,
size_t);
53 u32 crc32b(
const u8*,
size_t, u32 magic);
55 int crc16b(
const std::string &);
56 int crc16b(
const u8*,
size_t);
57 int crc16b(
const u8*,
size_t, u16 magic);
65 std::string stringEncode(
const std::string &,
const char* charset);
67 BinaryBuf zlibUncompress(
const char*,
size_t,
size_t real = 0);
68 BinaryBuf zlibCompress(
const char*,
size_t);
70 BinaryBuf zlibUncompress(
const u8*,
size_t,
size_t real = 0);
71 BinaryBuf zlibCompress(
const u8*,
size_t);
73 BinaryBuf base64Decode(
const char*);
74 BinaryBuf base64Decode(
const u8*,
size_t);
76 BinaryBuf base64Encode(
const char*);
77 BinaryBuf base64Encode(
const u8*,
size_t);
79 Points renderCircle(
const Point &,
int,
bool fill =
false);
80 Points renderLine(
const Point &,
const Point &,
int step = 1);
82 template<
typename InputIterator>
83 InputIterator random_n(InputIterator first, InputIterator last)
85 auto dist = std::distance(first, last);
86 InputIterator res = first;
89 std::advance(res, rand(0, dist - 1));
97 class RandQueue :
protected std::vector< std::pair<T, size_t> >
100 size_t getMaxWeight(
void)
const 102 return std::accumulate(this->begin(), this->end(), 0,
103 [](
size_t v,
auto & pair){
return v += pair.second; });
109 if(size) this->reserve(size);
112 void push(
const T & value,
size_t weight)
114 if(weight) this->emplace_back(value, weight);
117 bool isValid(
void)
const 119 return 0 < this->size();
126 std::vector<size_t> percents;
127 percents.reserve(this->size());
129 size_t max = getMaxWeight();
132 for(
auto & pair : *
this)
133 percents.push_back(100 * pair.second / max);
136 max = std::accumulate(percents.begin(), percents.end(), 0,
137 [](
size_t v,
auto & val){
return v += val; });
139 size_t rnd = rand(0, max);
143 auto it = std::find_if(percents.begin(), percents.end(),
144 [&](
auto & val){ amount += val;
return rnd <= amount; });
146 if(it != percents.end())
147 return this->
operator[](std::distance(percents.begin(), it)).first;
150 ERROR(
"weight not found");
160 std::bitset<100> seeds;
166 const int max = seeds.size() - 1;
168 while(seeds.count() < chance)
170 int rnd = rand(min, max);
178 if(chance < 1 || chance > 99) chance = 50;
183 int getChance(
void)
const 190 if(index < seeds.size())
191 return seeds.test(index++);
200 bool last(
void)
const 202 return seeds.test(index);
205 std::string toString(
void)
const 207 return seeds.to_string();
212 std::list<T> AdvancedSplit(
const T & buf,
const T & sep)
215 auto itbeg = buf.begin();
219 auto itend = std::search(itbeg, buf.end(), sep.begin(), sep.end());
220 list.push_back(T(itbeg, itend));
222 if(itend >= buf.end())
break;
225 std::advance(itbeg, sep.size());
237 void operator() (SDL_TimerID* ptr)
239 SDL_RemoveTimer(*ptr);
245 std::unique_ptr<SDL_TimerID, TimerDeleter> ptr;
246 Timer(
const SDL_TimerID &);
251 static Timer create(u32 interval , u32(*)(u32,
void*),
void* param =
nullptr);
253 bool isValid(
void)
const;
263 bool check(u32 ms, u32 period)
const;
265 void disabled(
bool f);
273 KeyValue(
const std::string & str,
const T & val) : std::pair<std::string, T>(str, val) {}
275 const std::string & key(
void)
const 279 const T & value(
void)
const пространство SWE.
Definition: swe_binarybuf.cpp:30
Definition: swe_tools.h:233
Definition: swe_tools.h:257
Definition: swe_tools.h:270