Core: Move platform-specific code to PlatformImpl namespace
This commit is contained in:
parent
3557040246
commit
373309d6d9
|
|
@ -28,7 +28,10 @@ namespace Nz
|
|||
{
|
||||
using DynLibFunc = void (*)(void); // "Generic" type of pointer to function
|
||||
|
||||
class DynLibImpl;
|
||||
namespace PlatformImpl
|
||||
{
|
||||
class DynLibImpl;
|
||||
}
|
||||
|
||||
class NAZARA_CORE_API DynLib
|
||||
{
|
||||
|
|
@ -51,7 +54,7 @@ namespace Nz
|
|||
|
||||
private:
|
||||
mutable std::string m_lastError;
|
||||
std::unique_ptr<DynLibImpl> m_impl;
|
||||
std::unique_ptr<PlatformImpl::DynLibImpl> m_impl;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,10 @@
|
|||
|
||||
namespace Nz
|
||||
{
|
||||
class FileImpl;
|
||||
namespace PlatformImpl
|
||||
{
|
||||
class FileImpl;
|
||||
}
|
||||
|
||||
class NAZARA_CORE_API File : public Stream
|
||||
{
|
||||
|
|
@ -70,7 +73,7 @@ namespace Nz
|
|||
std::size_t WriteBlock(const void* buffer, std::size_t size) override;
|
||||
|
||||
std::filesystem::path m_filePath;
|
||||
std::unique_ptr<FileImpl> m_impl;
|
||||
std::unique_ptr<PlatformImpl::FileImpl> m_impl;
|
||||
};
|
||||
|
||||
NAZARA_CORE_API bool HashAppend(AbstractHash& hash, const File& originalFile);
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ namespace Nz
|
|||
if (libraryPath.extension() != NAZARA_DYNLIB_EXTENSION)
|
||||
libraryPath += NAZARA_DYNLIB_EXTENSION;
|
||||
|
||||
auto impl = std::make_unique<DynLibImpl>();
|
||||
auto impl = std::make_unique<PlatformImpl::DynLibImpl>();
|
||||
if (!impl->Load(libraryPath, &m_lastError))
|
||||
{
|
||||
NazaraErrorFmt("failed to load library: {0}", m_lastError);
|
||||
|
|
|
|||
|
|
@ -188,7 +188,7 @@ namespace Nz
|
|||
return true;
|
||||
}
|
||||
|
||||
std::unique_ptr<FileImpl> impl = std::make_unique<FileImpl>(this);
|
||||
std::unique_ptr<PlatformImpl::FileImpl> impl = std::make_unique<PlatformImpl::FileImpl>(this);
|
||||
if (!impl->Open(m_filePath, openMode))
|
||||
{
|
||||
ErrorFlags flags(ErrorMode::Silent); // Silent by default
|
||||
|
|
@ -240,7 +240,7 @@ namespace Nz
|
|||
if (filePath.empty())
|
||||
return false;
|
||||
|
||||
std::unique_ptr<FileImpl> impl = std::make_unique<FileImpl>(this);
|
||||
std::unique_ptr<PlatformImpl::FileImpl> impl = std::make_unique<PlatformImpl::FileImpl>(this);
|
||||
if (!impl->Open(filePath, m_openMode))
|
||||
{
|
||||
NazaraErrorFmt("failed to open new file; {0}", Error::GetLastSystemError());
|
||||
|
|
|
|||
|
|
@ -117,31 +117,31 @@ namespace Nz
|
|||
|
||||
void HardwareInfo::Cpuid(UInt32 functionId, UInt32 subFunctionId, UInt32 result[4])
|
||||
{
|
||||
return HardwareInfoImpl::Cpuid(functionId, subFunctionId, result);
|
||||
return PlatformImpl::HardwareInfoImpl::Cpuid(functionId, subFunctionId, result);
|
||||
}
|
||||
|
||||
bool HardwareInfo::IsCpuidSupported()
|
||||
{
|
||||
return HardwareInfoImpl::IsCpuidSupported();
|
||||
return PlatformImpl::HardwareInfoImpl::IsCpuidSupported();
|
||||
}
|
||||
|
||||
void HardwareInfo::FetchCPUInfo()
|
||||
{
|
||||
NAZARA_USE_ANONYMOUS_NAMESPACE
|
||||
|
||||
m_cpuThreadCount = std::max(HardwareInfoImpl::GetProcessorCount(), 1U);
|
||||
m_cpuThreadCount = std::max(PlatformImpl::HardwareInfoImpl::GetProcessorCount(), 1U);
|
||||
|
||||
m_cpuCapabilities.fill(false);
|
||||
m_cpuVendor = ProcessorVendor::Unknown;
|
||||
|
||||
std::strcpy(m_cpuBrandString.data(), "CPU from unknown vendor - cpuid not supported");
|
||||
|
||||
if (!HardwareInfoImpl::IsCpuidSupported())
|
||||
if (!PlatformImpl::HardwareInfoImpl::IsCpuidSupported())
|
||||
return;
|
||||
|
||||
// To begin, we get the id of the constructor and the id of maximal functions supported by the CPUID
|
||||
std::array<UInt32, 4> registers;
|
||||
HardwareInfoImpl::Cpuid(0, 0, registers.data());
|
||||
PlatformImpl::HardwareInfoImpl::Cpuid(0, 0, registers.data());
|
||||
|
||||
UInt32& eax = registers[0];
|
||||
UInt32& ebx = registers[1];
|
||||
|
|
@ -159,7 +159,7 @@ namespace Nz
|
|||
if (eax >= 1)
|
||||
{
|
||||
// Retrieval of certain capacities of the processor (ECX and EDX, function 1)
|
||||
HardwareInfoImpl::Cpuid(1, 0, registers.data());
|
||||
PlatformImpl::HardwareInfoImpl::Cpuid(1, 0, registers.data());
|
||||
|
||||
m_cpuCapabilities[ProcessorCap::AES] = (ecx & (1U << 25)) != 0;
|
||||
m_cpuCapabilities[ProcessorCap::AVX] = (ecx & (1U << 28)) != 0;
|
||||
|
|
@ -176,13 +176,13 @@ namespace Nz
|
|||
}
|
||||
|
||||
// Retrieval of biggest extended function handled (EAX, function 0x80000000)
|
||||
HardwareInfoImpl::Cpuid(0x80000000, 0, registers.data());
|
||||
PlatformImpl::HardwareInfoImpl::Cpuid(0x80000000, 0, registers.data());
|
||||
|
||||
UInt32 maxSupportedExtendedFunction = eax;
|
||||
if (maxSupportedExtendedFunction >= 0x80000001)
|
||||
{
|
||||
// Retrieval of extended capabilities of the processor (ECX and EDX, function 0x80000001)
|
||||
HardwareInfoImpl::Cpuid(0x80000001, 0, registers.data());
|
||||
PlatformImpl::HardwareInfoImpl::Cpuid(0x80000001, 0, registers.data());
|
||||
|
||||
m_cpuCapabilities[ProcessorCap::x64] = (edx & (1U << 29)) != 0; // Support of 64bits, doesn't mean executable is 64bits
|
||||
m_cpuCapabilities[ProcessorCap::FMA4] = (ecx & (1U << 16)) != 0;
|
||||
|
|
@ -195,7 +195,7 @@ namespace Nz
|
|||
char* ptr = &m_cpuBrandString[0];
|
||||
for (UInt32 code = 0x80000002; code <= 0x80000004; ++code)
|
||||
{
|
||||
HardwareInfoImpl::Cpuid(code, 0, registers.data());
|
||||
PlatformImpl::HardwareInfoImpl::Cpuid(code, 0, registers.data());
|
||||
std::memcpy(ptr, ®isters[0], 4*sizeof(UInt32)); // We add the 16 bytes to the string
|
||||
|
||||
ptr += 4 * sizeof(UInt32);
|
||||
|
|
@ -208,6 +208,6 @@ namespace Nz
|
|||
|
||||
void HardwareInfo::FetchMemoryInfo()
|
||||
{
|
||||
m_systemTotalMemory = HardwareInfoImpl::GetTotalMemory();
|
||||
m_systemTotalMemory = PlatformImpl::HardwareInfoImpl::GetTotalMemory();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
#include <cstring>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
namespace Nz::PlatformImpl
|
||||
{
|
||||
DynLibImpl::~DynLibImpl()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -12,10 +12,8 @@
|
|||
#include <filesystem>
|
||||
#include <string>
|
||||
|
||||
namespace Nz
|
||||
namespace Nz::PlatformImpl
|
||||
{
|
||||
class String;
|
||||
|
||||
class DynLibImpl
|
||||
{
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
#include <sys/stat.h>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
namespace Nz::PlatformImpl
|
||||
{
|
||||
FileImpl::FileImpl(const File* parent) :
|
||||
m_fileDescriptor(-1),
|
||||
|
|
|
|||
|
|
@ -37,8 +37,10 @@
|
|||
namespace Nz
|
||||
{
|
||||
class File;
|
||||
class String;
|
||||
}
|
||||
|
||||
namespace Nz::PlatformImpl
|
||||
{
|
||||
class FileImpl
|
||||
{
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
#include <unistd.h>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
namespace Nz::PlatformImpl
|
||||
{
|
||||
void HardwareInfoImpl::Cpuid(UInt32 functionId, UInt32 subFunctionId, UInt32 registers[4])
|
||||
{
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
|
||||
namespace Nz
|
||||
namespace Nz::PlatformImpl
|
||||
{
|
||||
class HardwareInfoImpl
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
#include <time.h>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
namespace Nz::PlatformImpl
|
||||
{
|
||||
bool InitializeHighPrecisionTimer()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Time.hpp>
|
||||
|
||||
namespace Nz
|
||||
namespace Nz::PlatformImpl
|
||||
{
|
||||
bool InitializeHighPrecisionTimer();
|
||||
Time GetElapsedNanosecondsImpl();
|
||||
|
|
|
|||
|
|
@ -22,15 +22,15 @@ namespace Nz
|
|||
{
|
||||
Time GetElapsedNanosecondsFirstRun()
|
||||
{
|
||||
if (InitializeHighPrecisionTimer())
|
||||
GetElapsedNanoseconds = GetElapsedNanosecondsImpl;
|
||||
if (PlatformImpl::InitializeHighPrecisionTimer())
|
||||
GetElapsedNanoseconds = PlatformImpl::GetElapsedNanosecondsImpl;
|
||||
else
|
||||
GetElapsedNanoseconds = GetElapsedMillisecondsImpl;
|
||||
GetElapsedNanoseconds = PlatformImpl::GetElapsedMillisecondsImpl;
|
||||
|
||||
return GetElapsedNanoseconds();
|
||||
}
|
||||
}
|
||||
|
||||
GetElapsedTimeFunction GetElapsedMilliseconds = GetElapsedMillisecondsImpl;
|
||||
GetElapsedTimeFunction GetElapsedMilliseconds = PlatformImpl::GetElapsedMillisecondsImpl;
|
||||
GetElapsedTimeFunction GetElapsedNanoseconds = NAZARA_ANONYMOUS_NAMESPACE_PREFIX(GetElapsedNanosecondsFirstRun);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
#include <memory>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
namespace Nz::PlatformImpl
|
||||
{
|
||||
DynLibImpl::~DynLibImpl()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
#include <filesystem>
|
||||
#include <Windows.h>
|
||||
|
||||
namespace Nz
|
||||
namespace Nz::PlatformImpl
|
||||
{
|
||||
class DynLibImpl
|
||||
{
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
#include <memory>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
namespace Nz::PlatformImpl
|
||||
{
|
||||
FileImpl::FileImpl(const File* parent) :
|
||||
m_endOfFile(false),
|
||||
|
|
|
|||
|
|
@ -12,11 +12,8 @@
|
|||
#include <ctime>
|
||||
#include <Windows.h>
|
||||
|
||||
namespace Nz
|
||||
namespace Nz::PlatformImpl
|
||||
{
|
||||
class File;
|
||||
class String;
|
||||
|
||||
class FileImpl
|
||||
{
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
namespace Nz::PlatformImpl
|
||||
{
|
||||
void HardwareInfoImpl::Cpuid(UInt32 functionId, UInt32 subFunctionId, UInt32 registers[4])
|
||||
{
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
|
||||
namespace Nz
|
||||
namespace Nz::PlatformImpl
|
||||
{
|
||||
class HardwareInfoImpl
|
||||
{
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
#include <Windows.h>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
namespace Nz::PlatformImpl
|
||||
{
|
||||
namespace NAZARA_ANONYMOUS_NAMESPACE
|
||||
{
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Time.hpp>
|
||||
|
||||
namespace Nz
|
||||
namespace Nz::PlatformImpl
|
||||
{
|
||||
bool InitializeHighPrecisionTimer();
|
||||
Time GetElapsedNanosecondsImpl();
|
||||
|
|
|
|||
Loading…
Reference in New Issue