Skip to content

Commit 163d693

Browse files
Merge remote-tracking branch 'remotes/origin/master' into hlsl-compiler-impl
2 parents f0e54e4 + e11cbe8 commit 163d693

File tree

4 files changed

+62
-8
lines changed

4 files changed

+62
-8
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#ifndef _NBL_SYSTEM_C_COLORED_STDOUT_LOGGER_ANSI_INCLUDED_
2+
#define _NBL_SYSTEM_C_COLORED_STDOUT_LOGGER_ANSI_INCLUDED_
3+
4+
#include "nbl/system/IThreadsafeLogger.h"
5+
6+
#include <string_view>
7+
8+
namespace nbl::system
9+
{
10+
11+
// logging using ANSI escape codes
12+
class NBL_API2 CColoredStdoutLoggerANSI : public IThreadsafeLogger
13+
{
14+
public:
15+
CColoredStdoutLoggerANSI(core::bitflag<E_LOG_LEVEL> logLevelMask = ILogger::defaultLogMask()) : IThreadsafeLogger(logLevelMask) {}
16+
17+
private:
18+
// more info about how this works: https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797
19+
virtual void threadsafeLog_impl(const std::string_view &fmt, E_LOG_LEVEL logLevel, va_list args) override
20+
{
21+
auto str = constructLogString(fmt, logLevel, args);
22+
switch (logLevel)
23+
{
24+
case ELL_DEBUG:
25+
printf("\x1b[37m%s", str.data()); // White
26+
break;
27+
case ELL_INFO:
28+
printf("\x1b[37m%s", str.data()); // White
29+
break;
30+
case ELL_WARNING:
31+
printf("\x1b[33m%s", str.data()); // yellow
32+
break;
33+
case ELL_ERROR:
34+
printf("\x1b[31m%s", str.data()); // red
35+
break;
36+
case ELL_PERFORMANCE:
37+
printf("\x1b[34m%s", str.data()); // blue
38+
break;
39+
case ELL_NONE:
40+
assert(false);
41+
break;
42+
}
43+
fflush(stdout);
44+
}
45+
};
46+
47+
} // namespace nbl::system
48+
49+
#endif

include/nbl/system/ISystemPOSIX.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
namespace nbl::system
77
{
88

9-
#if defined(__unix__)
9+
#if defined(_NBL_PLATFORM_LINUX_) || defined (_NBL_PLATFORM_ANDROID_)
1010
class ISystemPOSIX : public ISystem
1111
{
1212
protected:

src/nbl/system/CSystemLinux.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@ using namespace nbl;
44
using namespace nbl::system;
55

66
#ifdef _NBL_PLATFORM_LINUX_
7+
8+
#include <sys/sysinfo.h>
79
ISystem::SystemInfo CSystemLinux::getSystemInfo() const
810
{
911
SystemInfo info;
1012

1113
// TODO
12-
info.cpuFrequencyHz = 3000000000u;
14+
// info.cpuFrequencyHz = 3000000000u;
1315

14-
sysinfo linuxSystemInfo;
16+
struct sysinfo linuxSystemInfo;
1517
sysinfo(&linuxSystemInfo);
1618
info.totalMemory = linuxSystemInfo.totalram;
1719
info.availableMemory = linuxSystemInfo.freeram;

src/nbl/system/ISystemPOSIX.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
#include "nbl/system/ISystemPOSIX.h"
22
#include "nbl/system/CFilePOSIX.h"
33

4+
#include "nbl/system/IFile.h"
5+
46
using namespace nbl;
57
using namespace nbl::system;
68

7-
#if defined(__unix__)
9+
#if defined(_NBL_PLATFORM_LINUX_) || defined (_NBL_PLATFORM_ANDROID_)
10+
811
#include <fcntl.h>
912
#include <sys/mman.h>
1013
#include <sys/stat.h>
@@ -13,7 +16,7 @@ core::smart_refctd_ptr<ISystemFile> ISystemPOSIX::CCaller::createFile(const std:
1316
{
1417
const bool writeAccess = flags.value&IFile::ECF_WRITE;
1518
int createFlags = O_LARGEFILE|(writeAccess ? O_CREAT:0);
16-
switch (_flags.value&IFile::ECF_READ_WRITE))
19+
switch (flags.value&IFile::ECF_READ_WRITE)
1720
{
1821
case IFile::ECF_READ:
1922
createFlags |= O_RDONLY;
@@ -30,7 +33,7 @@ core::smart_refctd_ptr<ISystemFile> ISystemPOSIX::CCaller::createFile(const std:
3033
}
3134

3235
CFilePOSIX::native_file_handle_t _native = -1;
33-
auto filenameStream = _filename.string();
36+
auto filenameStream = filename.string();
3437
const char* name_c_str = filenameStream.c_str();
3538
// only create a new file if we're going to be writing
3639
if (writeAccess)
@@ -60,7 +63,7 @@ core::smart_refctd_ptr<ISystemFile> ISystemPOSIX::CCaller::createFile(const std:
6063

6164
// map if needed
6265
void* _mappedPtr = nullptr;
63-
if (_flags.value & ECF_MAPPABLE)
66+
if (flags.value & IFile::ECF_MAPPABLE)
6467
{
6568
const int mappingFlags = ((flags.value&IFile::ECF_READ) ? PROT_READ:0)|(writeAccess ? PROT_WRITE:0);
6669
_mappedPtr = mmap((caddr_t)0, _size, mappingFlags, MAP_PRIVATE, _native, 0);
@@ -71,6 +74,6 @@ core::smart_refctd_ptr<ISystemFile> ISystemPOSIX::CCaller::createFile(const std:
7174
}
7275
}
7376

74-
return core::make_smart_refctd_ptr<CFilePOSIX>(core::smart_refctd_ptr<ISystem>(m_system),filename,flags,_mappedPtr,_size,_native);
77+
return core::make_smart_refctd_ptr<CFilePOSIX>(core::smart_refctd_ptr<ISystem>(m_system),path(filename),flags,_mappedPtr,_size,_native);
7578
}
7679
#endif

0 commit comments

Comments
 (0)