16#define SAFE_DELETE(p) \
22#define SAFE_DELETE_ARRAY(p) \
29#define ZERO(x) memset(&(x), 0, sizeof(x))
32#define ARRAYLEN(a) (sizeof(a) / sizeof((a)[0]))
42#define SCALE(x, l1, h1, l2, h2) \
43 (((x) - (l1)) * ((h2) - (l2)) / ((h1) - (l1)) + (l2))
45template<
typename T,
typename U>
47lerp(T x, U l, U h) -> U
49 return static_cast<U
>(x * (h - l) + l);
52template<
typename T,
typename U,
typename V>
54CLAMP(T& x, U l, V h) ->
bool
56 if (x >
static_cast<T
>(h)) {
57 x =
static_cast<T
>(h);
60 if (x <
static_cast<T
>(l)) {
61 x =
static_cast<T
>(l);
69ENUM_CLAMP(T& x, T l, T h) ->
bool
82wife2(
float maxms,
float ts) ->
float
84 maxms = maxms * 1000.F;
85 float avedeviation = 95.F * ts;
86 float y = 1 -
static_cast<float>(
87 pow(2, -1 * maxms * maxms / (avedeviation * avedeviation)));
88 y =
static_cast<float>(pow(y, 2));
89 return (2 - -8) * (1 - y) + -8;
92static const float wife3_mine_hit_weight = -7.F;
93static const float wife3_hold_drop_weight = -4.5F;
94static const float wife3_miss_weight = -5.5F;
98werwerwerwerf(
float x) ->
float
100 static const float a1 = 0.254829592F;
101 static const float a2 = -0.284496736F;
102 static const float a3 = 1.421413741F;
103 static const float a4 = -1.453152027F;
104 static const float a5 = 1.061405429F;
105 static const float p = 0.3275911F;
113 auto t = 1.F / (1.F + p * x);
115 1.F - (((((a5 * t + a4) * t) + a3) * t + a2) * t + a1) * t * exp(-x * x);
121wife3(
float maxms,
float ts) ->
float
124 static const float j_pow = 0.75F;
126 static const float max_points = 2.F;
128 float ridic = 5.F * ts;
133 float max_boo_weight = 180.F * ts;
136 maxms = std::abs(maxms * 1000.F);
139 if (maxms <= ridic) {
144 float zero = 65.F * pow(ts, j_pow);
145 float dev = 22.7F * pow(ts, j_pow);
148 return max_points * werwerwerwerf((zero - maxms) / dev);
150 if (maxms <= max_boo_weight) {
151 return (maxms - zero) * wife3_miss_weight / (max_boo_weight - zero);
153 return wife3_miss_weight;
160 x += ((-x / n) + 1) * n;
165wrap(
unsigned& x,
unsigned n)
170wrap(
float& x,
float n)
173 x += truncf(((-x / n) + 1)) * n;
179fracf(
float f) ->
float
181 return f - truncf(f);
186CircularShift(std::vector<T>& v,
int dist)
188 for (
int i = std::abs(dist); i > 0; i--) {
197 v.erase(v.end() - 1);
198 v.insert(v.begin(), t);
204sstolower(
char ch) ->
char
206 return (ch >=
'A' && ch <=
'Z') ?
static_cast<char>(ch +
'a' -
'A') : ch;
211ssicmp(
const CT* pA1,
const CT* pA2) ->
int
217 f = sstolower(*(pA1++));
218 l = sstolower(*(pA2++));
219 }
while ((f) && (f == l));
221 return static_cast<int>(f - l);
225CompareNoCase(
const std::string& a,
const std::string& b) ->
int
227 return ssicmp(a.c_str(), b.c_str());
231EqualsNoCase(
const std::string& a,
const std::string& b) ->
bool
233 return CompareNoCase(a, b) == 0;
237s_replace(std::string& target, std::string
const& from, std::string
const& to);
240ensure_slash_at_end(std::string& s)
242 if (s.back() !=
'/') {
249starts_with(std::string
const& source, std::string
const& target) -> bool;
253ends_with(std::string
const& source, std::string
const& target) -> bool;
257make_upper(std::string
const& source) -> std::string;
261make_lower(std::string
const& source) -> std::string;
263template<
typename Type,
typename Ret>
271template<
typename TO,
typename FROM>
277 m_ToValue =
static_cast<TO
>(*m_pFromValue);
282 auto operator*() -> TO& {
return m_ToValue; }
283 operator TO*() {
return &m_ToValue; }
295template<
typename TO,
typename FROM>
317enum_add(T& val,
int iAmt)
319 val =
static_cast<T
>(val + iAmt);
324enum_add2(T val,
int iAmt) -> T
326 return static_cast<T
>(val + iAmt);
331enum_cycle(T val,
int iMax,
int iAmt = 1) -> T
333 int iVal = val + iAmt;
335 return static_cast<T
>(iVal);
345#ifdef HAVE_BYTE_SWAPS
346#define Swap32 ArchSwap32
347#define Swap24 ArchSwap24
348#define Swap16 ArchSwap16
351Swap32(uint32_t n) -> uint32_t
353 return (n >> 24) | ((n >> 8) & 0x0000FF00) | ((n << 8) & 0x00FF0000) |
358Swap24(uint32_t n) -> uint32_t
360 return Swap32(n) >> 8;
364Swap16(uint16_t n) -> uint16_t
366 return (n >> 8) | (n << 8);
371Swap32LE(uint32_t n) -> uint32_t
376Swap24LE(uint32_t n) -> uint32_t
381Swap16LE(uint16_t n) -> uint16_t
386Swap32BE(uint32_t n) -> uint32_t
391Swap24BE(uint32_t n) -> uint32_t
396Swap16BE(uint16_t n) -> uint16_t
403Quantize(
const float f,
const float fRoundInterval) ->
float
405 return static_cast<int>((f + fRoundInterval / 2) / fRoundInterval) *
410Quantize(
const int i,
const int iRoundInterval) ->
int
412 return static_cast<int>((i + iRoundInterval / 2) / iRoundInterval) *
418ftruncf(
const float f,
const float fTruncInterval) ->
float
420 return static_cast<int>((f) / fTruncInterval) * fTruncInterval;
425QuantizeUp(
int i,
int iInterval) ->
int
427 return static_cast<int>((i + iInterval - 1) / iInterval) * iInterval;
431QuantizeUp(
float i,
float iInterval) ->
float
433 return ceilf(i / iInterval) * iInterval;
438QuantizeDown(
int i,
int iInterval) ->
int
440 return static_cast<int>((i - iInterval + 1) / iInterval) * iInterval;
444QuantizeDown(
float i,
float iInterval) ->
float
446 return floorf(i / iInterval) * iInterval;
451fapproach(
float& val,
float other_val,
float to_move);
455fmodfp(
float x,
float y) ->
float
464power_of_two(
int input) ->
int
491 const auto value = 1 << exp;
492 return input == value ? value : value << 1;
495IsAnInt(
const std::string& s) ->
bool
502 if (i <
'0' || i >
'9') {
510IsHexVal(
const std::string& s) -> bool;
512BinaryToHex(
const void* pData_,
int iNumBytes) -> std::string;
514BinaryToHex(
const std::string& sString) -> std::string;
516HHMMSSToSeconds(
const std::string& sHMS) -> float;
518SecondsToHHMMSS(
float fSecs) -> std::string;
520SecondsToMSSMsMs(
float fSecs) -> std::string;
522SecondsToMMSSMsMs(
float fSecs) -> std::string;
524SecondsToMMSSMsMsMs(
float fSecs) -> std::string;
526SecondsToMSS(
float fSecs) -> std::string;
528SecondsToMMSS(
float fSecs) -> std::string;
530PrettyPercent(
float fNumerator,
float fDenominator) -> std::string;
532PrettyPercent(
int fNumerator,
int fDenominator) -> std::string
534 return PrettyPercent(
float(fNumerator),
float(fDenominator));
537Commify(
int iNum) -> std::string;
539Commify(
const std::string& num,
540 const std::string& sep =
",",
541 const std::string& dot =
".") -> std::string;
543FormatNumberAndSuffix(
int i) -> std::string;
546GetLocalTime() ->
struct tm;
549#if defined(__clang__)
550#pragma clang diagnostic push
551#pragma clang diagnostic ignored "-Wformat-security"
552#elif defined(__GNUC__)
553#pragma GCC diagnostic push
554#pragma GCC diagnostic ignored "-Wformat-security"
555#elif defined(_MSC_VER)
558template<
typename... Args>
560ssprintf(
const char* format, Args... args) -> std::string
563 size_t size = snprintf(
nullptr, 0, format, args...) + 1;
564 std::unique_ptr<char[]> buf(
new char[size]);
565 snprintf(buf.get(), size, format, args...);
567 return std::string(buf.get(), buf.get() + size - 1);
569#if defined(__clang__)
570#pragma clang diagnostic pop
571#elif defined(__GNUC__)
573#elif defined(_MSC_VER)
577template<
typename... Args>
579ssprintf(
const std::string& format, Args... args) -> std::string
581 return ssprintf(format.c_str(), args...);
585vssprintf(
const char* fmt, va_list argList) -> std::string;
587ConvertI64FormatString(
const std::string& sStr) -> std::string;
596splitpath(
const std::string& Path,
598 std::string& Filename,
602SetExtension(
const std::string& path,
const std::string& ext) -> std::string;
604GetExtension(
const std::string& sPath) -> std::string;
606GetFileNameWithoutExtension(
const std::string& sPath) -> std::string;
608MakeValidFilename(std::string& sName);
611FindFirstFilenameContaining(
const std::vector<std::string>& filenames,
613 const std::vector<std::string>& starts_with,
614 const std::vector<std::string>& contains,
615 const std::vector<std::string>& ends_with) -> bool;
617extern const wchar_t INVALID_CHAR;
620utf8_get_char_len(
char p) -> int;
622utf8_to_wchar(
const char* s,
size_t iLength,
unsigned& start,
wchar_t& ch)
625utf8_to_wchar_ec(
const std::string& s,
unsigned& start,
wchar_t& ch) -> bool;
627wchar_to_utf8(
wchar_t ch, std::string& out);
629utf8_get_char(
const std::string& s) -> wchar_t;
631utf8_is_valid(
const std::string& s) -> bool;
633utf8_remove_bom(std::string& s);
635MakeUpper(
char* p,
size_t iLen);
637MakeLower(
char* p,
size_t iLen);
639MakeLower(std::string& data);
641MakeUpper(
wchar_t* p,
size_t iLen);
643MakeLower(
wchar_t* p,
size_t iLen);
649StringToInt(
const std::string& sString) -> int;
655IntToString(
const int& iNum) -> std::string;
657StringToFloat(
const std::string& sString) -> float;
659FloatToString(
const float& num) -> std::string;
661StringToFloat(
const std::string& sString,
float& fOut) -> bool;
665operator>>(
const std::string& lhs, T& rhs) ->
bool
667 return !!(std::istringstream(lhs) >> rhs);
671WStringToString(
const std::wstring& sString) -> std::string;
673WcharToUTF8(
wchar_t c) -> std::string;
675StringToWString(
const std::string& sString) -> std::wstring;
679 const char* szIsoCode;
680 const char* szEnglishName;
683GetLanguageInfos(std::vector<const LanguageInfo*>& vAddTo);
685GetLanguageInfo(
const std::string& sIsoCode) ->
const LanguageInfo*;
690split(
const std::string& sSource,
691 const std::string& sDelimitor,
692 std::vector<std::string>& asAddIt,
693 bool bIgnoreEmpty =
true);
695split(
const std::wstring& sSource,
696 const std::wstring& sDelimitor,
697 std::vector<std::wstring>& asAddIt,
698 bool bIgnoreEmpty =
true);
702split(
const std::string& sSource,
703 const std::string& sDelimitor,
706 bool bIgnoreEmpty =
true);
708split(
const std::wstring& sSource,
709 const std::wstring& sDelimitor,
712 bool bIgnoreEmpty =
true);
716split(
const std::string& sSource,
717 const std::string& sDelimitor,
723split(
const std::wstring& sSource,
724 const std::wstring& sDelimitor,
733join(
const std::string& sDelimitor,
const std::vector<std::string>& sSource)
736join(
const std::string& sDelimitor,
737 std::vector<std::string>::const_iterator begin,
738 std::vector<std::string>::const_iterator end) -> std::string;
741luajoin(
const std::string& sDelimitor,
const std::vector<std::string>& sSource)
744luajoin(
const std::string& sDelimitor,
745 std::vector<std::string>::const_iterator begin,
746 std::vector<std::string>::const_iterator end) -> std::string;
750SmEscape(
const std::string& sUnescaped) -> std::string;
752SmEscape(
const char* cUnescaped,
int len) -> std::string;
757DwiEscape(
const std::string& sUnescaped) -> std::string;
759DwiEscape(
const char* cUnescaped,
int len) -> std::string;
762GetCwd() -> std::string;
765SetCommandlineArguments(
int argc,
char** argv);
767GetCommandLineArguments(
int& argc,
char**& argv);
769GetCommandlineArgument(
const std::string& option,
770 std::string* argument =
nullptr,
771 int iIndex = 0) -> bool;
776CRC32(
unsigned int& iCRC,
const void* pBuffer,
size_t iSize);
778GetHashForString(
const std::string& s) ->
unsigned int;
780GetHashForFile(
const std::string& sPath) ->
unsigned int;
782GetHashForDirectory(
const std::string& sDir)
787DirectoryIsEmpty(
const std::string& sPath) -> bool;
790CompareStringsAsc(
const std::string& sStr1,
const std::string& sStr2) -> bool;
792SortStringArray(std::vector<std::string>& asAddTo,
bool bSortAscending =
true);
796calc_mean(
const float* pStart,
const float* pEnd) -> float;
804calc_stddev(
const float* pStart,
const float* pEnd,
bool bSample =
false)
824compress_string(
const std::string& str,
int compressionLevel = 9) -> std::string;
826decompress_string(
const std::string& str) -> std::string;
828base64_encode(const ::std::string& bindata);
830base64_decode(
const std::string& ascdata);
832TrimLeft(std::string& sStr,
const char* szTrim =
"\r\n\t ");
834TrimRight(std::string& sStr,
const char* szTrim =
"\r\n\t ");
836Trim(std::string& sStr,
const char* szTrim =
"\r\n\t ");
838StripCrnl(std::string& sStr);
840BeginsWith(
const std::string& sTestThis,
const std::string& sBeginning) -> bool;
842EndsWith(
const std::string& sTestThis,
const std::string& sEnding) -> bool;
844URLEncode(
const std::string& sStr) -> std::string;
847DerefRedir(
const std::string& sPath) -> std::string;
849GetFileContents(
const std::string& sPath,
851 bool bOneLine =
false) -> bool;
853GetFileContents(
const std::string& sFile, std::vector<std::string>& asOut)
859 Regex(
const std::string& sPat =
"");
862 auto operator=(
Regex&& rhs)
noexcept ->
Regex&;
864 [[nodiscard]]
auto IsSet()
const ->
bool {
return !m_sPattern.empty(); }
865 void Set(
const std::string& str);
866 auto Compare(
const std::string& sStr) -> bool;
867 auto Compare(
const std::string& sStr, std::vector<std::string>& asMatches)
869 auto Replace(
const std::string& sReplacement,
870 const std::string& sSubject,
871 std::string& sOut) -> bool;
878 unsigned m_iBackrefs;
879 std::string m_sPattern;
883ReplaceEntityText(std::string& sText,
884 const std::map<std::string, std::string>& m);
886ReplaceEntityText(std::string& sText,
const std::map<char, std::string>& m);
888Replace_Unicode_Markers(std::string& Text);
890WcharDisplayText(
wchar_t c) -> std::string;
893Basename(
const std::string& dir) -> std::string;
895Dirname(
const std::string& dir) -> std::string;
897Capitalize(
const std::string& s) -> std::string;
899#if defined(HAVE_UNISTD_H)
903extern unsigned char g_UpperCase[256];
904extern unsigned char g_LowerCase[256];
909 static auto eq(
char c1,
char c2) ->
bool
911 return g_UpperCase[
static_cast<unsigned char>(c1)] ==
912 g_UpperCase[
static_cast<unsigned char>(c2)];
915 static auto ne(
char c1,
char c2) ->
bool
917 return g_UpperCase[
static_cast<unsigned char>(c1)] !=
918 g_UpperCase[
static_cast<unsigned char>(c2)];
921 static auto lt(
char c1,
char c2) ->
bool
923 return g_UpperCase[
static_cast<unsigned char>(c1)] <
924 g_UpperCase[
static_cast<unsigned char>(c2)];
927 static auto compare(
const char* s1,
const char* s2,
size_t n) ->
int
930 while ((n--) != 0U) {
931 ret = fasttoupper(*s1++) - fasttoupper(*s2++);
939 static auto fasttoupper(
char a) ->
char
941 return g_UpperCase[
static_cast<unsigned char>(a)];
944 static auto find(
const char* s,
int n,
char a) ->
const char*
947 while (n-- > 0 && fasttoupper(*s) != a) {
951 if (fasttoupper(*s) == a) {
957using istring = std::basic_string<char, char_traits_char_nocase>;
963GetDirListing(
const std::string& sPath,
964 std::vector<std::string>& addTo,
969GetDirListingRecursive(
const std::string& sDir,
970 const std::string& sMatch,
971 std::vector<std::string>& AddTo);
974 const std::string& sDir,
975 const std::string& sMatch,
976 std::vector<std::string>& AddTo);
978DoesFileExist(
const std::string& sPath) -> bool;
980IsAFile(
const std::string& sPath) -> bool;
982IsADirectory(
const std::string& sPath) -> bool;
984GetFileSizeInBytes(
const std::string& sFilePath) -> int;
991head(std::string
const& source, int32_t length) -> std::string;
998tail(std::string
const& source, int32_t length) -> std::string;
1002FixSlashesInPlace(std::string& sPath);
1004CollapsePath(std::string& sPath,
bool bRemoveLeadingDot =
false);
1010FromString(
const std::string& sValue, T& out) -> bool;
1014ToString(
const T& value) -> std::string;
1018FromString<std::string>(
const std::string& sValue, std::string& out) ->
bool
1025ToString<std::string>(
const std::string& value) -> std::string
1033FileCopy(
const std::string& sSrcFile,
const std::string& sDstFile) -> bool;
1037 std::string& sError,
1038 bool* bReadError =
nullptr) -> bool;
1042GetAsNotInBs(
const std::vector<T>& as,
1043 const std::vector<T>& bs,
1044 std::vector<T>& difference)
1046 std::vector<T> bsUnmatched = bs;
1049 for (
typename std::vector<T>::const_iterator a = as.begin(); a != as.end();
1051 typename std::vector<T>::iterator iter =
1052 find(bsUnmatched.begin(), bsUnmatched.end(), *a);
1053 if (iter != bsUnmatched.end())
1054 bsUnmatched.erase(iter);
1056 difference.push_back(*a);
1062GetConnectsDisconnects(
const std::vector<T>& before,
1063 const std::vector<T>& after,
1064 std::vector<T>& disconnects,
1065 std::vector<T>& connects)
1067 GetAsNotInBs(before, after, disconnects);
1068 GetAsNotInBs(after, before, connects);
Definition RageFileBasic.h:10
Definition RageFileDriver.h:12
Definition RageUtil.h:857
Utilities for converting the Strings.
Definition GameConstantsAndTypes.cpp:49
Definition RageUtil.h:273
Definition RageUtil.h:678
Definition RageUtil.h:908