yupplemayham/YuppleMayham/include/util.h

51 lines
1.1 KiB
C++

#ifndef _H_UTIL_H
#define _H_UTIL_H
#include <SDL_video.h>
#include <random>
namespace UTIL
{
namespace AUDIO {
constexpr size_t CHUNK_SIZE = 4096;
constexpr int SAMPLE_RATE = 44100;
}
constexpr float INF_TIME = -99.6875f;
constexpr auto split = [](const std::string& s, size_t *left, size_t *right, std::string *out) {
if ((*right = s.find("/", *left)) != std::string::npos) {
if (out) {
*out = s.substr(*left, *right - *left);
}
*left = *right + 1;
} else {
if (out) {
out->append(s.substr(*left));
}
}
};
constexpr auto get_type = [](const std::string& id) {
auto pos = id.find_last_of("/");
return (pos != std::string::npos) ? id.substr(pos + 1) : id;
};
void flip_surface(SDL_Surface* surface);
std::string parsePrefix(const std::string& id);
class RandomGenerator
{
public:
RandomGenerator(float min, float max) :
rd(),
gen(rd()),
dist(min, max) {};
float genFloat() { return dist(gen); }
private:
std::random_device rd;
std::mt19937 gen;
std::uniform_real_distribution<float> dist;
};
}
#endif // _H_UTIL_H