Reformat the code, using:

find -type f |  # list all regular files
  grep -E '\.(h|cpp|mm)$' |  # filter for source files
  grep -v '/mt_' |  # filter out generated files
  grep -v '/vendor/' | # and vendored GL
  grep -v '/test/image_loader_test.cpp' |  # and this file (has giant literals arrays)
  xargs -n 1 -P $(nproc) clang-format -i  # reformat everything

Co-authored-by: numzero <numzer0@yandex.ru>
This commit is contained in:
Desour
2024-03-20 19:35:52 +01:00
committed by sfan5
parent 9814510b1b
commit f5c6d3e945
292 changed files with 37376 additions and 42421 deletions

View File

@ -15,51 +15,47 @@ namespace core
#define IRR_ATOF_TABLE_SIZE 17
// we write [IRR_ATOF_TABLE_SIZE] here instead of [] to work around a swig bug
const float fast_atof_table[17] = {
0.f,
0.1f,
0.01f,
0.001f,
0.0001f,
0.00001f,
0.000001f,
0.0000001f,
0.00000001f,
0.000000001f,
0.0000000001f,
0.00000000001f,
0.000000000001f,
0.0000000000001f,
0.00000000000001f,
0.000000000000001f,
0.0000000000000001f
};
0.f,
0.1f,
0.01f,
0.001f,
0.0001f,
0.00001f,
0.000001f,
0.0000001f,
0.00000001f,
0.000000001f,
0.0000000001f,
0.00000000001f,
0.000000000001f,
0.0000000000001f,
0.00000000000001f,
0.000000000000001f,
0.0000000000000001f};
//! Convert a simple string of base 10 digits into an unsigned 32 bit integer.
/** \param[in] in: The string of digits to convert. No leading chars are
allowed, only digits 0 to 9. Parsing stops at the first non-digit.
\param[out] out: (optional) If provided, it will be set to point at the
first character not used in the calculation.
\return The unsigned integer value of the digits. If the string specifies
too many digits to encode in an u32 then INT_MAX will be returned.
allowed, only digits 0 to 9. Parsing stops at the first non-digit.
\param[out] out: (optional) If provided, it will be set to point at the
first character not used in the calculation.
\return The unsigned integer value of the digits. If the string specifies
too many digits to encode in an u32 then INT_MAX will be returned.
*/
inline u32 strtoul10(const char* in, const char** out=0)
inline u32 strtoul10(const char *in, const char **out = 0)
{
if (!in)
{
if (!in) {
if (out)
*out = in;
return 0;
}
bool overflow=false;
bool overflow = false;
u32 unsignedValue = 0;
while ( ( *in >= '0') && ( *in <= '9' ))
{
const u32 tmp = ( unsignedValue * 10 ) + ( *in - '0' );
if (tmp<unsignedValue)
{
unsignedValue=(u32)0xffffffff;
overflow=true;
while ((*in >= '0') && (*in <= '9')) {
const u32 tmp = (unsignedValue * 10) + (*in - '0');
if (tmp < unsignedValue) {
unsignedValue = (u32)0xffffffff;
overflow = true;
}
if (!overflow)
unsignedValue = tmp;
@ -74,18 +70,17 @@ inline u32 strtoul10(const char* in, const char** out=0)
//! Convert a simple string of base 10 digits into a signed 32 bit integer.
/** \param[in] in: The string of digits to convert. Only a leading - or +
followed by digits 0 to 9 will be considered. Parsing stops at the first
non-digit.
\param[out] out: (optional) If provided, it will be set to point at the
first character not used in the calculation.
\return The signed integer value of the digits. If the string specifies
too many digits to encode in an s32 then +INT_MAX or -INT_MAX will be
returned.
followed by digits 0 to 9 will be considered. Parsing stops at the first
non-digit.
\param[out] out: (optional) If provided, it will be set to point at the
first character not used in the calculation.
\return The signed integer value of the digits. If the string specifies
too many digits to encode in an s32 then +INT_MAX or -INT_MAX will be
returned.
*/
inline s32 strtol10(const char* in, const char** out=0)
inline s32 strtol10(const char *in, const char **out = 0)
{
if (!in)
{
if (!in) {
if (out)
*out = in;
return 0;
@ -95,16 +90,13 @@ inline s32 strtol10(const char* in, const char** out=0)
if (negative || ('+' == *in))
++in;
const u32 unsignedValue = strtoul10(in,out);
if (unsignedValue > (u32)INT_MAX)
{
const u32 unsignedValue = strtoul10(in, out);
if (unsignedValue > (u32)INT_MAX) {
if (negative)
return (s32)INT_MIN;
else
return (s32)INT_MAX;
}
else
{
} else {
if (negative)
return -((s32)unsignedValue);
else
@ -114,9 +106,9 @@ inline s32 strtol10(const char* in, const char** out=0)
//! Convert a hex-encoded character to an unsigned integer.
/** \param[in] in The digit to convert. Only digits 0 to 9 and chars A-F,a-f
will be considered.
\return The unsigned integer value of the digit. 0xffffffff if the input is
not hex
will be considered.
\return The unsigned integer value of the digit. 0xffffffff if the input is
not hex
*/
inline u32 ctoul16(char in)
{
@ -132,26 +124,24 @@ inline u32 ctoul16(char in)
//! Convert a simple string of base 16 digits into an unsigned 32 bit integer.
/** \param[in] in: The string of digits to convert. No leading chars are
allowed, only digits 0 to 9 and chars A-F,a-f are allowed. Parsing stops
at the first illegal char.
\param[out] out: (optional) If provided, it will be set to point at the
first character not used in the calculation.
\return The unsigned integer value of the digits. If the string specifies
too many digits to encode in an u32 then INT_MAX will be returned.
allowed, only digits 0 to 9 and chars A-F,a-f are allowed. Parsing stops
at the first illegal char.
\param[out] out: (optional) If provided, it will be set to point at the
first character not used in the calculation.
\return The unsigned integer value of the digits. If the string specifies
too many digits to encode in an u32 then INT_MAX will be returned.
*/
inline u32 strtoul16(const char* in, const char** out=0)
inline u32 strtoul16(const char *in, const char **out = 0)
{
if (!in)
{
if (!in) {
if (out)
*out = in;
return 0;
}
bool overflow=false;
bool overflow = false;
u32 unsignedValue = 0;
while (true)
{
while (true) {
u32 tmp = 0;
if ((*in >= '0') && (*in <= '9'))
tmp = (unsignedValue << 4u) + (*in - '0');
@ -161,10 +151,9 @@ inline u32 strtoul16(const char* in, const char** out=0)
tmp = (unsignedValue << 4u) + (*in - 'a') + 10;
else
break;
if (tmp<unsignedValue)
{
unsignedValue=(u32)INT_MAX;
overflow=true;
if (tmp < unsignedValue) {
unsignedValue = (u32)INT_MAX;
overflow = true;
}
if (!overflow)
unsignedValue = tmp;
@ -179,35 +168,32 @@ inline u32 strtoul16(const char* in, const char** out=0)
//! Convert a simple string of base 8 digits into an unsigned 32 bit integer.
/** \param[in] in The string of digits to convert. No leading chars are
allowed, only digits 0 to 7 are allowed. Parsing stops at the first illegal
char.
\param[out] out (optional) If provided, it will be set to point at the
first character not used in the calculation.
\return The unsigned integer value of the digits. If the string specifies
too many digits to encode in an u32 then INT_MAX will be returned.
allowed, only digits 0 to 7 are allowed. Parsing stops at the first illegal
char.
\param[out] out (optional) If provided, it will be set to point at the
first character not used in the calculation.
\return The unsigned integer value of the digits. If the string specifies
too many digits to encode in an u32 then INT_MAX will be returned.
*/
inline u32 strtoul8(const char* in, const char** out=0)
inline u32 strtoul8(const char *in, const char **out = 0)
{
if (!in)
{
if (!in) {
if (out)
*out = in;
return 0;
}
bool overflow=false;
bool overflow = false;
u32 unsignedValue = 0;
while (true)
{
while (true) {
u32 tmp = 0;
if ((*in >= '0') && (*in <= '7'))
tmp = (unsignedValue << 3u) + (*in - '0');
else
break;
if (tmp<unsignedValue)
{
unsignedValue=(u32)INT_MAX;
overflow=true;
if (tmp < unsignedValue) {
unsignedValue = (u32)INT_MAX;
overflow = true;
}
if (!overflow)
unsignedValue = tmp;
@ -222,39 +208,37 @@ inline u32 strtoul8(const char* in, const char** out=0)
//! Convert a C-style prefixed string (hex, oct, integer) into an unsigned 32 bit integer.
/** \param[in] in The string of digits to convert. If string starts with 0x the
hex parser is used, if only leading 0 is used, oct parser is used. In all
other cases, the usual unsigned parser is used.
\param[out] out (optional) If provided, it will be set to point at the
first character not used in the calculation.
\return The unsigned integer value of the digits. If the string specifies
too many digits to encode in an u32 then INT_MAX will be returned.
hex parser is used, if only leading 0 is used, oct parser is used. In all
other cases, the usual unsigned parser is used.
\param[out] out (optional) If provided, it will be set to point at the
first character not used in the calculation.
\return The unsigned integer value of the digits. If the string specifies
too many digits to encode in an u32 then INT_MAX will be returned.
*/
inline u32 strtoul_prefix(const char* in, const char** out=0)
inline u32 strtoul_prefix(const char *in, const char **out = 0)
{
if (!in)
{
if (!in) {
if (out)
*out = in;
return 0;
}
if ('0'==in[0])
return ('x'==in[1] ? strtoul16(in+2,out) : strtoul8(in+1,out));
return strtoul10(in,out);
if ('0' == in[0])
return ('x' == in[1] ? strtoul16(in + 2, out) : strtoul8(in + 1, out));
return strtoul10(in, out);
}
//! Converts a sequence of digits into a whole positive floating point value.
/** Only digits 0 to 9 are parsed. Parsing stops at any other character,
including sign characters or a decimal point.
\param in: the sequence of digits to convert.
\param out: (optional) will be set to point at the first non-converted
character.
\return The whole positive floating point representation of the digit
sequence.
including sign characters or a decimal point.
\param in: the sequence of digits to convert.
\param out: (optional) will be set to point at the first non-converted
character.
\return The whole positive floating point representation of the digit
sequence.
*/
inline f32 strtof10(const char* in, const char** out = 0)
inline f32 strtof10(const char *in, const char **out = 0)
{
if (!in)
{
if (!in) {
if (out)
*out = in;
return 0.f;
@ -265,8 +249,7 @@ inline f32 strtof10(const char* in, const char** out = 0)
// Use integer arithmetic for as long as possible, for speed
// and precision.
while ( ( *in >= '0') && ( *in <= '9' ) )
{
while ((*in >= '0') && (*in <= '9')) {
// If it looks like we're going to overflow, bail out
// now and start using floating point.
if (intValue >= MAX_SAFE_U32_VALUE)
@ -280,8 +263,7 @@ inline f32 strtof10(const char* in, const char** out = 0)
// If there are any digits left to parse, then we need to use
// floating point arithmetic from here.
while ( ( *in >= '0') && ( *in <= '9' ) )
{
while ((*in >= '0') && (*in <= '9')) {
floatValue = (floatValue * 10.f) + (f32)(*in - '0');
++in;
if (floatValue > FLT_MAX) // Just give up.
@ -296,13 +278,13 @@ inline f32 strtof10(const char* in, const char** out = 0)
//! Provides a fast function for converting a string into a float.
/** This is not guaranteed to be as accurate as atof(), but is
approximately 6 to 8 times as fast.
\param[in] in The string to convert.
\param[out] result The resultant float will be written here.
\return Pointer to the first character in the string that wasn't used
to create the float value.
approximately 6 to 8 times as fast.
\param[in] in The string to convert.
\param[out] result The resultant float will be written here.
\return Pointer to the first character in the string that wasn't used
to create the float value.
*/
inline const char* fast_atof_move(const char* in, f32& result)
inline const char *fast_atof_move(const char *in, f32 &result)
{
// Please run the regression test when making any modifications to this function.
@ -311,29 +293,24 @@ inline const char* fast_atof_move(const char* in, f32& result)
return 0;
const bool negative = ('-' == *in);
if (negative || ('+'==*in))
if (negative || ('+' == *in))
++in;
f32 value = strtof10(in, &in);
if ( *in == '.' )
{
const char* afterDecimal = ++in;
if (*in == '.') {
const char *afterDecimal = ++in;
const f32 decimal = strtof10(in, &afterDecimal);
const size_t numDecimals = afterDecimal - in;
if (numDecimals < IRR_ATOF_TABLE_SIZE)
{
if (numDecimals < IRR_ATOF_TABLE_SIZE) {
value += decimal * fast_atof_table[numDecimals];
}
else
{
} else {
value += decimal * (f32)pow(10.f, -(float)numDecimals);
}
in = afterDecimal;
}
if ('e' == *in || 'E' == *in)
{
if ('e' == *in || 'E' == *in) {
++in;
// Assume that the exponent is a whole number.
// strtol10() will deal with both + and - signs,
@ -342,21 +319,21 @@ inline const char* fast_atof_move(const char* in, f32& result)
value *= (f32)pow(10.f, (f32)strtol10(in, &in));
}
result = negative?-value:value;
result = negative ? -value : value;
return in;
}
//! Convert a string to a floating point number
/** \param floatAsString The string to convert.
\param out Optional pointer to the first character in the string that
wasn't used to create the float value.
\result Float value parsed from the input string
\param out Optional pointer to the first character in the string that
wasn't used to create the float value.
\result Float value parsed from the input string
*/
inline float fast_atof(const char* floatAsString, const char** out=0)
inline float fast_atof(const char *floatAsString, const char **out = 0)
{
float ret;
if (out)
*out=fast_atof_move(floatAsString, ret);
*out = fast_atof_move(floatAsString, ret);
else
fast_atof_move(floatAsString, ret);
return ret;