17#define SAFE_DELETE(p) \
23#define SAFE_DELETE_ARRAY(p) \
30#define ZERO(x) memset(&(x), 0, sizeof(x))
33#define ARRAYLEN(a) std::size(a)
43#define SCALE(x, l1, h1, l2, h2) \
44 (((x) - (l1)) * ((h2) - (l2)) / ((h1) - (l1)) + (l2))
46template<
typename T,
typename U>
48lerp(T x, U l, U h) -> U
50 return static_cast<U
>(x * (h - l) + l);
53template<
typename T,
typename U,
typename V>
55CLAMP(T& x, U l, V h) ->
bool
57 if (x >
static_cast<T
>(h)) {
58 x =
static_cast<T
>(h);
61 if (x <
static_cast<T
>(l)) {
62 x =
static_cast<T
>(l);
70ENUM_CLAMP(T& x, T l, T h) ->
bool
83wife2(
float maxms,
float ts) ->
float
85 maxms = maxms * 1000.F;
86 float avedeviation = 95.F * ts;
87 float y = 1 -
static_cast<float>(
88 pow(2, -1 * maxms * maxms / (avedeviation * avedeviation)));
89 y =
static_cast<float>(pow(y, 2));
90 return (2 - -8) * (1 - y) + -8;
93static const float wife3_mine_hit_weight = -7.F;
94static const float wife3_hold_drop_weight = -4.5F;
95static const float wife3_miss_weight = -5.5F;
99werwerwerwerf(
float x) ->
float
101 static const float a1 = 0.254829592F;
102 static const float a2 = -0.284496736F;
103 static const float a3 = 1.421413741F;
104 static const float a4 = -1.453152027F;
105 static const float a5 = 1.061405429F;
106 static const float p = 0.3275911F;
114 auto t = 1.F / (1.F + p * x);
116 1.F - (((((a5 * t + a4) * t) + a3) * t + a2) * t + a1) * t * exp(-x * x);
122wife3(
float maxms,
float ts) ->
float
125 static const float j_pow = 0.75F;
127 static const float max_points = 2.F;
129 float ridic = 5.F * ts;
134 float max_boo_weight = 180.F * ts;
137 maxms = std::abs(maxms * 1000.F);
140 if (maxms <= ridic) {
145 float zero = 65.F * pow(ts, j_pow);
146 float dev = 22.7F * pow(ts, j_pow);
149 return max_points * werwerwerwerf((zero - maxms) / dev);
151 if (maxms <= max_boo_weight) {
152 return (maxms - zero) * wife3_miss_weight / (max_boo_weight - zero);
154 return wife3_miss_weight;
161 x += ((-x / n) + 1) * n;
166wrap(
unsigned& x,
unsigned n)
171wrap(
float& x,
float n)
174 x += truncf(((-x / n) + 1)) * n;
180fracf(
float f) ->
float
182 return f - truncf(f);
187CircularShift(std::vector<T>& v,
int dist)
189 for (
int i = std::abs(dist); i > 0; i--) {
198 v.erase(v.end() - 1);
199 v.insert(v.begin(), t);
205sstolower(
char ch) ->
char
207 return (ch >=
'A' && ch <=
'Z') ?
static_cast<char>(ch +
'a' -
'A') : ch;
212ssicmp(
const CT* pA1,
const CT* pA2) ->
int
218 f = sstolower(*(pA1++));
219 l = sstolower(*(pA2++));
220 }
while ((f) && (f == l));
222 return static_cast<int>(f - l);
226CompareNoCase(
const std::string& a,
const std::string& b) ->
int
228 return ssicmp(a.c_str(), b.c_str());
232EqualsNoCase(
const std::string& a,
const std::string& b) ->
bool
234 return CompareNoCase(a, b) == 0;
238s_replace(std::string& target, std::string
const& from, std::string
const& to);
241ensure_slash_at_end(std::string& s)
243 if (s.back() !=
'/') {
250starts_with(std::string
const& source, std::string
const& target) -> bool;
254ends_with(std::string
const& source, std::string
const& target) -> bool;
258make_upper(std::string
const& source) -> std::string;
262make_lower(std::string
const& source) -> std::string;
264template<
typename Type,
typename Ret>
272template<
typename TO,
typename FROM>
278 m_ToValue =
static_cast<TO
>(*m_pFromValue);
283 auto operator*() -> TO& {
return m_ToValue; }
284 operator TO*() {
return &m_ToValue; }
296template<
typename TO,
typename FROM>
318enum_add(T& val,
int iAmt)
320 val =
static_cast<T
>(val + iAmt);
325enum_add2(T val,
int iAmt) -> T
327 return static_cast<T
>(val + iAmt);
332enum_cycle(T val,
int iMax,
int iAmt = 1) -> T
334 int iVal = val + iAmt;
336 return static_cast<T
>(iVal);
346#ifdef HAVE_BYTE_SWAPS
347#define Swap32 ArchSwap32
348#define Swap24 ArchSwap24
349#define Swap16 ArchSwap16
352Swap32(uint32_t n) -> uint32_t
354 return (n >> 24) | ((n >> 8) & 0x0000FF00) | ((n << 8) & 0x00FF0000) |
359Swap24(uint32_t n) -> uint32_t
361 return Swap32(n) >> 8;
365Swap16(uint16_t n) -> uint16_t
367 return (n >> 8) | (n << 8);
372Swap32LE(uint32_t n) -> uint32_t
377Swap24LE(uint32_t n) -> uint32_t
382Swap16LE(uint16_t n) -> uint16_t
387Swap32BE(uint32_t n) -> uint32_t
392Swap24BE(uint32_t n) -> uint32_t
397Swap16BE(uint16_t n) -> uint16_t
404Quantize(
const float f,
const float fRoundInterval) ->
float
406 return static_cast<int>((f + fRoundInterval / 2) / fRoundInterval) *
411Quantize(
const int i,
const int iRoundInterval) ->
int
413 return static_cast<int>((i + iRoundInterval / 2) / iRoundInterval) *
419ftruncf(
const float f,
const float fTruncInterval) ->
float
421 return static_cast<int>((f) / fTruncInterval) * fTruncInterval;
426QuantizeUp(
int i,
int iInterval) ->
int
428 return static_cast<int>((i + iInterval - 1) / iInterval) * iInterval;
432QuantizeUp(
float i,
float iInterval) ->
float
434 return ceilf(i / iInterval) * iInterval;
439QuantizeDown(
int i,
int iInterval) ->
int
441 return static_cast<int>((i - iInterval + 1) / iInterval) * iInterval;
445QuantizeDown(
float i,
float iInterval) ->
float
447 return floorf(i / iInterval) * iInterval;
452fapproach(
float& val,
float other_val,
float to_move);
456fmodfp(
float x,
float y) ->
float
465power_of_two(
int input) ->
int
492 const auto value = 1 << exp;
493 return input == value ? value : value << 1;
496IsAnInt(
const std::string& s) ->
bool
503 if (i <
'0' || i >
'9') {
511IsHexVal(
const std::string& s) -> bool;
513BinaryToHex(
const void* pData_,
int iNumBytes) -> std::string;
515BinaryToHex(
const std::string& sString) -> std::string;
517HHMMSSToSeconds(
const std::string& sHMS) -> float;
519SecondsToHHMMSS(
float fSecs) -> std::string;
521SecondsToMSSMsMs(
float fSecs) -> std::string;
523SecondsToMMSSMsMs(
float fSecs) -> std::string;
525SecondsToMMSSMsMsMs(
float fSecs) -> std::string;
527SecondsToMSS(
float fSecs) -> std::string;
529SecondsToMMSS(
float fSecs) -> std::string;
531PrettyPercent(
float fNumerator,
float fDenominator) -> std::string;
533PrettyPercent(
int fNumerator,
int fDenominator) -> std::string
535 return PrettyPercent(
float(fNumerator),
float(fDenominator));
538Commify(
int iNum) -> std::string;
540Commify(
const std::string& num,
541 const std::string& sep =
",",
542 const std::string& dot =
".") -> std::string;
544FormatNumberAndSuffix(
int i) -> std::string;
547GetLocalTime() ->
struct tm;
550#if defined(__clang__)
551#pragma clang diagnostic push
552#pragma clang diagnostic ignored "-Wformat-security"
553#elif defined(__GNUC__)
554#pragma GCC diagnostic push
555#pragma GCC diagnostic ignored "-Wformat-security"
556#elif defined(_MSC_VER)
559template<
typename... Args>
561ssprintf(
const char* format, Args... args) -> std::string
564 size_t size = snprintf(
nullptr, 0, format, args...) + 1;
565 std::unique_ptr<char[]> buf(
new char[size]);
566 snprintf(buf.get(), size, format, args...);
568 return std::string(buf.get(), buf.get() + size - 1);
570#if defined(__clang__)
571#pragma clang diagnostic pop
572#elif defined(__GNUC__)
574#elif defined(_MSC_VER)
578template<
typename... Args>
580ssprintf(
const std::string& format, Args... args) -> std::string
582 return ssprintf(format.c_str(), args...);
586vssprintf(
const char* fmt, va_list argList) -> std::string;
588ConvertI64FormatString(
const std::string& sStr) -> std::string;
597splitpath(
const std::string& Path,
599 std::string& Filename,
603SetExtension(
const std::string& path,
const std::string& ext) -> std::string;
605GetExtension(
const std::string& sPath) -> std::string;
607GetFileNameWithoutExtension(
const std::string& sPath) -> std::string;
609MakeValidFilename(std::string& sName);
612FindFirstFilenameContaining(
const std::vector<std::string>& filenames,
614 const std::vector<std::string>& starts_with,
615 const std::vector<std::string>& contains,
616 const std::vector<std::string>& ends_with) -> bool;
618extern const wchar_t INVALID_CHAR;
621utf8_get_char_len(
char p) -> int;
623utf8_to_wchar(
const char* s,
size_t iLength,
unsigned& start,
wchar_t& ch)
626utf8_to_wchar_ec(
const std::string& s,
unsigned& start,
wchar_t& ch) -> bool;
628wchar_to_utf8(
wchar_t ch, std::string& out);
630utf8_get_char(
const std::string& s) -> wchar_t;
632utf8_is_valid(
const std::string& s) -> bool;
634utf8_remove_bom(std::string& s);
636MakeUpper(
char* p,
size_t iLen);
638MakeLower(
char* p,
size_t iLen);
640MakeLower(std::string& data);
642MakeUpper(
wchar_t* p,
size_t iLen);
644MakeLower(
wchar_t* p,
size_t iLen);
650StringToInt(
const std::string& sString) -> int;
656IntToString(
const int& iNum) -> std::string;
658StringToFloat(
const std::string& sString) -> float;
660FloatToString(
const float& num) -> std::string;
662StringToFloat(
const std::string& sString,
float& fOut) -> bool;
666operator>>(
const std::string& lhs, T& rhs) ->
bool
668 return !!(std::istringstream(lhs) >> rhs);
672WStringToString(
const std::wstring& sString) -> std::string;
674WcharToUTF8(
wchar_t c) -> std::string;
676StringToWString(
const std::string& sString) -> std::wstring;
680 const char* szIsoCode;
681 const char* szEnglishName;
684GetLanguageInfos(std::vector<const LanguageInfo*>& vAddTo);
686GetLanguageInfo(
const std::string& sIsoCode) ->
const LanguageInfo*;
691split(
const std::string& sSource,
692 const std::string& sDelimitor,
693 std::vector<std::string>& asAddIt,
694 bool bIgnoreEmpty =
true);
696split(
const std::wstring& sSource,
697 const std::wstring& sDelimitor,
698 std::vector<std::wstring>& asAddIt,
699 bool bIgnoreEmpty =
true);
703split(
const std::string& sSource,
704 const std::string& sDelimitor,
707 bool bIgnoreEmpty =
true);
709split(
const std::wstring& sSource,
710 const std::wstring& sDelimitor,
713 bool bIgnoreEmpty =
true);
717split(
const std::string& sSource,
718 const std::string& sDelimitor,
724split(
const std::wstring& sSource,
725 const std::wstring& sDelimitor,
734join(
const std::string& sDelimitor,
const std::vector<std::string>& sSource)
737join(
const std::string& sDelimitor,
738 std::vector<std::string>::const_iterator begin,
739 std::vector<std::string>::const_iterator end) -> std::string;
742luajoin(
const std::string& sDelimitor,
const std::vector<std::string>& sSource)
745luajoin(
const std::string& sDelimitor,
746 std::vector<std::string>::const_iterator begin,
747 std::vector<std::string>::const_iterator end) -> std::string;
751SmEscape(
const std::string& sUnescaped) -> std::string;
753SmEscape(
const char* cUnescaped,
int len) -> std::string;
758DwiEscape(
const std::string& sUnescaped) -> std::string;
760DwiEscape(
const char* cUnescaped,
int len) -> std::string;
763GetCwd() -> std::string;
766SetCommandlineArguments(
int argc,
char** argv);
768GetCommandLineArguments(
int& argc,
char**& argv);
770GetCommandlineArgument(
const std::string& option,
771 std::string* argument =
nullptr,
772 int iIndex = 0) -> bool;
777CRC32(
unsigned int& iCRC,
const void* pBuffer,
size_t iSize);
779GetHashForString(
const std::string& s) ->
unsigned int;
781GetHashForFile(
const std::string& sPath) ->
unsigned int;
783GetHashForDirectory(
const std::string& sDir)
788DirectoryIsEmpty(
const std::string& sPath) -> bool;
791CompareStringsAsc(
const std::string& sStr1,
const std::string& sStr2) -> bool;
793SortStringArray(std::vector<std::string>& asAddTo,
bool bSortAscending =
true);
797calc_mean(
const float* pStart,
const float* pEnd) -> float;
805calc_stddev(
const float* pStart,
const float* pEnd,
bool bSample =
false)
825compress_string(
const std::string& str,
int compressionLevel = 9) -> std::string;
827decompress_string(
const std::string& str) -> std::string;
829base64_encode(const ::std::string& bindata);
831base64_decode(
const std::string& ascdata);
833TrimLeft(std::string& sStr,
const char* szTrim =
"\r\n\t ");
835TrimRight(std::string& sStr,
const char* szTrim =
"\r\n\t ");
837Trim(std::string& sStr,
const char* szTrim =
"\r\n\t ");
839StripCrnl(std::string& sStr);
841BeginsWith(
const std::string& sTestThis,
const std::string& sBeginning) -> bool;
843EndsWith(
const std::string& sTestThis,
const std::string& sEnding) -> bool;
845URLEncode(
const std::string& sStr) -> std::string;
848DerefRedir(
const std::string& sPath) -> std::string;
850GetFileContents(
const std::string& sPath,
852 bool bOneLine =
false) -> bool;
854GetFileContents(
const std::string& sFile, std::vector<std::string>& asOut)
860 Regex(
const std::string& sPat =
"");
863 auto operator=(
Regex&& rhs)
noexcept ->
Regex&;
865 [[nodiscard]]
auto IsSet()
const ->
bool {
return !m_sPattern.empty(); }
866 void Set(
const std::string& str);
867 auto Compare(
const std::string& sStr) -> bool;
868 auto Compare(
const std::string& sStr, std::vector<std::string>& asMatches)
870 auto Replace(
const std::string& sReplacement,
871 const std::string& sSubject,
872 std::string& sOut) -> bool;
879 unsigned m_iBackrefs;
880 std::string m_sPattern;
884ReplaceEntityText(std::string& sText,
885 const std::map<std::string, std::string>& m);
887ReplaceEntityText(std::string& sText,
const std::map<char, std::string>& m);
889Replace_Unicode_Markers(std::string& Text);
891WcharDisplayText(
wchar_t c) -> std::string;
894Basename(
const std::string& dir) -> std::string;
896Dirname(
const std::string& dir) -> std::string;
898Capitalize(
const std::string& s) -> std::string;
900#if defined(HAVE_UNISTD_H)
904extern unsigned char g_UpperCase[256];
905extern unsigned char g_LowerCase[256];
910 static auto eq(
char c1,
char c2) ->
bool
912 return g_UpperCase[
static_cast<unsigned char>(c1)] ==
913 g_UpperCase[
static_cast<unsigned char>(c2)];
916 static auto ne(
char c1,
char c2) ->
bool
918 return g_UpperCase[
static_cast<unsigned char>(c1)] !=
919 g_UpperCase[
static_cast<unsigned char>(c2)];
922 static auto lt(
char c1,
char c2) ->
bool
924 return g_UpperCase[
static_cast<unsigned char>(c1)] <
925 g_UpperCase[
static_cast<unsigned char>(c2)];
928 static auto compare(
const char* s1,
const char* s2,
size_t n) ->
int
931 while ((n--) != 0U) {
932 ret = fasttoupper(*s1++) - fasttoupper(*s2++);
940 static auto fasttoupper(
char a) ->
char
942 return g_UpperCase[
static_cast<unsigned char>(a)];
945 static auto find(
const char* s,
int n,
char a) ->
const char*
948 while (n-- > 0 && fasttoupper(*s) != a) {
952 if (fasttoupper(*s) == a) {
958using istring = std::basic_string<char, char_traits_char_nocase>;
964GetDirListing(
const std::string& sPath,
965 std::vector<std::string>& addTo,
970GetDirListingRecursive(
const std::string& sDir,
971 const std::string& sMatch,
972 std::vector<std::string>& AddTo);
975 const std::string& sDir,
976 const std::string& sMatch,
977 std::vector<std::string>& AddTo);
979DoesFileExist(
const std::string& sPath) -> bool;
981IsAFile(
const std::string& sPath) -> bool;
983IsADirectory(
const std::string& sPath) -> bool;
985GetFileSizeInBytes(
const std::string& sFilePath) -> int;
992head(std::string
const& source, int32_t length) -> std::string;
999tail(std::string
const& source, int32_t length) -> std::string;
1003FixSlashesInPlace(std::string& sPath);
1005CollapsePath(std::string& sPath,
bool bRemoveLeadingDot =
false);
1011FromString(
const std::string& sValue, T& out) -> bool;
1015ToString(
const T& value) -> std::string;
1019FromString<std::string>(
const std::string& sValue, std::string& out) ->
bool
1026ToString<std::string>(
const std::string& value) -> std::string
1034FileCopy(
const std::string& sSrcFile,
const std::string& sDstFile) -> bool;
1038 std::string& sError,
1039 bool* bReadError =
nullptr) -> bool;
1043GetAsNotInBs(
const std::vector<T>& as,
1044 const std::vector<T>& bs,
1045 std::vector<T>& difference)
1047 std::vector<T> bsUnmatched = bs;
1050 for (
typename std::vector<T>::const_iterator a = as.begin(); a != as.end();
1052 typename std::vector<T>::iterator iter =
1053 find(bsUnmatched.begin(), bsUnmatched.end(), *a);
1054 if (iter != bsUnmatched.end())
1055 bsUnmatched.erase(iter);
1057 difference.push_back(*a);
1063GetConnectsDisconnects(
const std::vector<T>& before,
1064 const std::vector<T>& after,
1065 std::vector<T>& disconnects,
1066 std::vector<T>& connects)
1068 GetAsNotInBs(before, after, disconnects);
1069 GetAsNotInBs(after, before, connects);
Definition RageFileBasic.h:12
Definition RageFileDriver.h:12
Definition RageUtil.h:858
Utilities for converting the Strings.
Definition GameConstantsAndTypes.cpp:49
Definition RageUtil.h:274
Definition RageUtil.h:679
Definition RageUtil.h:909