Fix code style
This commit is contained in:
@@ -746,15 +746,15 @@ uint64 AndroidPlatform::GetTimeCycles()
|
||||
|
||||
void AndroidPlatform::GetSystemTime(int32& year, int32& month, int32& dayOfWeek, int32& day, int32& hour, int32& minute, int32& second, int32& millisecond)
|
||||
{
|
||||
// Query for calendar time
|
||||
// Get the calendar time
|
||||
struct timeval time;
|
||||
gettimeofday(&time, nullptr);
|
||||
|
||||
// Convert to local time
|
||||
// Convert calendar time to local time
|
||||
struct tm localTime;
|
||||
localtime_r(&time.tv_sec, &localTime);
|
||||
|
||||
// Extract time
|
||||
// Extract time from Unix date
|
||||
year = localTime.tm_year + 1900;
|
||||
month = localTime.tm_mon + 1;
|
||||
dayOfWeek = localTime.tm_wday;
|
||||
|
||||
@@ -18,77 +18,49 @@ const char VolumeSeparatorChar = ':';
|
||||
|
||||
const Char* StringUtils::FindIgnoreCase(const Char* str, const Char* toFind)
|
||||
{
|
||||
// Validate input
|
||||
if (toFind == nullptr || str == nullptr)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Get upper-case first letter of the find string (to reduce the number of full strnicmps)
|
||||
Char findInitial = ToUpper(*toFind);
|
||||
|
||||
// Get length of find string, and increment past first letter
|
||||
int32 length = Length(toFind++) - 1;
|
||||
|
||||
// Get the first letter of the search string, and increment past it
|
||||
Char strChar = *str++;
|
||||
|
||||
// While we aren't at end of string
|
||||
while (strChar)
|
||||
const Char findInitial = ToUpper(*toFind);
|
||||
const int32 length = Length(toFind++) - 1;
|
||||
Char c = *str++;
|
||||
while (c)
|
||||
{
|
||||
// Make sure it's upper-case
|
||||
strChar = ToUpper(strChar);
|
||||
|
||||
// If it matches the first letter of the find string, do a case-insensitive string compare for the length of the find string
|
||||
if (strChar == findInitial && !CompareIgnoreCase(str, toFind, length))
|
||||
c = ToUpper(c);
|
||||
if (c == findInitial && !CompareIgnoreCase(str, toFind, length))
|
||||
{
|
||||
// If we found the string, then return a pointer to the beginning of it in the search string
|
||||
return str - 1;
|
||||
}
|
||||
|
||||
// Go to next letter
|
||||
strChar = *str++;
|
||||
c = *str++;
|
||||
}
|
||||
|
||||
// Nothing found
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const char* StringUtils::FindIgnoreCase(const char* str, const char* toFind)
|
||||
{
|
||||
// Validate input
|
||||
if (toFind == nullptr || str == nullptr)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Get upper-case first letter of the find string (to reduce the number of full strnicmps)
|
||||
char findInitial = (char)ToUpper(*toFind);
|
||||
|
||||
// Get length of find string, and increment past first letter
|
||||
int32 length = Length(toFind++) - 1;
|
||||
|
||||
// Get the first letter of the search string, and increment past it
|
||||
char strChar = *str++;
|
||||
|
||||
// While we aren't at end of string
|
||||
while (strChar)
|
||||
const char findInitial = (char)ToUpper(*toFind);
|
||||
const int32 length = Length(toFind++) - 1;
|
||||
char c = *str++;
|
||||
while (c)
|
||||
{
|
||||
// Make sure it's upper-case
|
||||
strChar = (char)ToUpper(strChar);
|
||||
|
||||
// If it matches the first letter of the find string, do a case-insensitive string compare for the length of the find string
|
||||
if (strChar == findInitial && !CompareIgnoreCase(str, toFind, length))
|
||||
c = (char)ToUpper(c);
|
||||
if (c == findInitial && !CompareIgnoreCase(str, toFind, length))
|
||||
{
|
||||
// If we found the string, then return a pointer to the beginning of it in the search string
|
||||
return str - 1;
|
||||
}
|
||||
|
||||
// Go to next letter
|
||||
strChar = *str++;
|
||||
c = *str++;
|
||||
}
|
||||
|
||||
// Nothing found
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -229,7 +229,7 @@ uint64 LinuxFileSystem::GetFileSize(const StringView& path)
|
||||
const StringAsANSI<> pathANSI(*path, path.Length());
|
||||
if (stat(pathANSI.Get(), &fileInfo) != -1)
|
||||
{
|
||||
// make sure to return -1 for directories
|
||||
// Check for directories
|
||||
if (S_ISDIR(fileInfo.st_mode))
|
||||
{
|
||||
fileInfo.st_size = -1;
|
||||
|
||||
@@ -1329,13 +1329,13 @@ bool LinuxPlatform::Init()
|
||||
Platform::MemoryClear(cpuInfos, sizeof(cpuInfos));
|
||||
int maxCoreId = 0;
|
||||
int maxPackageId = 0;
|
||||
int numCpusAvailable = 0;
|
||||
int cpuCountAvailable = 0;
|
||||
|
||||
for (int32 cpuIdx = 0; cpuIdx < CPU_SETSIZE; cpuIdx++)
|
||||
{
|
||||
if (CPU_ISSET(cpuIdx, &availableCpusMask))
|
||||
{
|
||||
numCpusAvailable++;
|
||||
cpuCountAvailable++;
|
||||
|
||||
sprintf(fileNameBuffer, "/sys/devices/system/cpu/cpu%d/topology/core_id", cpuIdx);
|
||||
if (FILE* coreIdFile = fopen(fileNameBuffer, "r"))
|
||||
@@ -1363,31 +1363,28 @@ bool LinuxPlatform::Init()
|
||||
}
|
||||
}
|
||||
|
||||
int numCores = maxCoreId + 1;
|
||||
int numPackages = maxPackageId + 1;
|
||||
int numPairs = numPackages * numCores;
|
||||
int coresCount = maxCoreId + 1;
|
||||
int packagesCount = maxPackageId + 1;
|
||||
int pairsCount = packagesCount * coresCount;
|
||||
|
||||
// AArch64 topology seems to be incompatible with the above assumptions, particularly, core_id can be all 0 while the cores themselves are obviously independent.
|
||||
// Check if num CPUs available to us is more than 2 per core (i.e. more than reasonable when hyperthreading is involved), and if so, don't trust the topology.
|
||||
if (numCores * 2 < numCpusAvailable)
|
||||
if (coresCount * 2 < cpuCountAvailable)
|
||||
{
|
||||
// Consider all CPUs to be separate
|
||||
numberOfCores = numCpusAvailable;
|
||||
numberOfCores = cpuCountAvailable;
|
||||
}
|
||||
else
|
||||
{
|
||||
byte* pairs = (byte*)Allocator::Allocate(numPairs);
|
||||
Platform::MemoryClear(pairs, numPairs * sizeof(unsigned char));
|
||||
byte* pairs = (byte*)Allocator::Allocate(pairsCount);
|
||||
Platform::MemoryClear(pairs, pairsCount * sizeof(unsigned char));
|
||||
|
||||
for (int32 cpuIdx = 0; cpuIdx < CPU_SETSIZE; cpuIdx++)
|
||||
{
|
||||
if (CPU_ISSET(cpuIdx, &availableCpusMask))
|
||||
{
|
||||
pairs[cpuInfos[cpuIdx].Package * numCores + cpuInfos[cpuIdx].Core] = 1;
|
||||
pairs[cpuInfos[cpuIdx].Package * coresCount + cpuInfos[cpuIdx].Core] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
for (int32 i = 0; i < numPairs; i++)
|
||||
for (int32 i = 0; i < pairsCount; i++)
|
||||
{
|
||||
numberOfCores += pairs[i];
|
||||
}
|
||||
@@ -1395,7 +1392,7 @@ bool LinuxPlatform::Init()
|
||||
Allocator::Free(pairs);
|
||||
}
|
||||
|
||||
UnixCpu.ProcessorPackageCount = numPackages;
|
||||
UnixCpu.ProcessorPackageCount = packagesCount;
|
||||
UnixCpu.ProcessorCoreCount = Math::Max(numberOfCores, 1);
|
||||
UnixCpu.LogicalProcessorCount = CPU_COUNT(&availableCpusMask);
|
||||
}
|
||||
|
||||
@@ -295,7 +295,7 @@ bool WindowsMouse::WndProc(Window* window, const UINT msg, WPARAM wParam, LPARAM
|
||||
float NormalizeXInputAxis(const int16 axisVal)
|
||||
{
|
||||
// Normalize [-32768..32767] -> [-1..1]
|
||||
const float norm = axisVal <= 0 ? 32768.f : 32767.f;
|
||||
const float norm = axisVal <= 0 ? 32768.0f : 32767.0f;
|
||||
return float(axisVal) / norm;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user