Skip to content

Commit 2146ca7

Browse files
committed
Support C++20
1 parent 3b071b6 commit 2146ca7

17 files changed

Lines changed: 70 additions & 42 deletions

Applications/Sfx/Sfx.lpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ the last is C code to be copied verbatim to the output.
6969
{
7070
insert_line_statement++;
7171
}
72+
bool charisspace(char c)
73+
{
74+
return std::isspace((int)c);
75+
}
7276
float ToFloat(const char * txr)
7377
{
7478
std::string yytextStr=yytext;
@@ -78,7 +82,7 @@ the last is C code to be copied verbatim to the output.
7882
// Clang/Gcc still doesn't implement the standard function std::from_chars properly.
7983
float value=atof(yytextStr.c_str());
8084
#else
81-
yytextStr.erase(std::remove_if(yytextStr.begin(),yytextStr.end(),std::isspace),yytextStr.end());
85+
yytextStr.erase(std::remove_if(yytextStr.begin(),yytextStr.end(),charisspace),yytextStr.end());
8286
float value=0.0f;
8387
std::from_chars(yytextStr.data(),yytextStr.data()+yytextStr.size(),value,std::chars_format::general);
8488
#endif

CMake/Include.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
include_guard()
22

3-
set( PLATFORM_CPP_VERSION 17 CACHE STRING "Set the C++ version to compile." )
3+
set( PLATFORM_CPP_VERSION 20 CACHE STRING "Set the C++ version to compile." )
44
set( CMAKE_CXX_STANDARD_REQUIRED ON )
55
set( CMAKE_CXX_EXTENSIONS ON )
66
set_property(GLOBAL PROPERTY USE_FOLDERS ON)

Core/DefaultFileLoader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ uint64_t DefaultFileLoader::GetFileDate(const char *filename_utf8) const
176176
// https://stackoverflow.com/questions/61030383/how-to-convert-stdfilesystemfile-time-type-to-time-t
177177
// https://stackoverflow.com/questions/51273205/how-to-compare-time-t-and-stdfilesystemfile-time-type
178178
fs::file_time_type fileTime = fs::last_write_time(filename_utf8);
179-
#if PLATFORM_CXX20
179+
#if PLATFORM_CXX20_OR_ABOVE
180180
const std::chrono::system_clock systemTime = std::chrono::clock_cast<std::chrono::system_clock>(fileTime);
181181
const time_t time = std::chrono::system_clock::to_time_t(systemTime);
182182
#else

Core/RuntimeError.h

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
1-
#ifndef PLATFORM_RUNTIMEERROR_H
2-
#define PLATFORM_RUNTIMEERROR_H
1+
#pragma once
2+
3+
// C++ Versions
4+
#if defined(_WIN64)
5+
#define PLATFORM_CXX20_OR_ABOVE _HAS_CXX20
6+
#define PLATFORM_CXX17_OR_ABOVE _HAS_CXX17
7+
#elif defined(__linux__)
8+
#define PLATFORM_CXX20_OR_ABOVE (__cplusplus >= 202002L)
9+
#define PLATFORM_CXX17_OR_ABOVE (__cplusplus >= 201703L)
10+
#endif
311

412
#include "Export.h"
513

614
#include <string>
15+
#include <string_view>
716
#include <string.h>
817
#include <iostream>
918
#include <cerrno>
1019
#include <assert.h>
20+
#if PLATFORM_CXX20_OR_ABOVE
21+
#include <format>
22+
#include <fmt/core.h>
23+
#else
1124
#include <fmt/core.h>
25+
#endif
1226

1327
#ifndef SIMUL_INTERNAL_CHECKS
1428
#define SIMUL_INTERNAL_CHECKS 0
@@ -35,14 +49,6 @@
3549
#endif
3650
#include <stdexcept> // for runtime_error
3751

38-
// C++ Versions
39-
#if defined(_WIN64)
40-
#define PLATFORM_CXX20 _HAS_CXX20
41-
#define PLATFORM_CXX17 _HAS_CXX17
42-
#elif defined(__linux__)
43-
#define PLATFORM_CXX20 (__cplusplus == 202002L)
44-
#define PLATFORM_CXX17 (__cplusplus == 201703L)
45-
#endif
4652

4753
#define SIMUL_COUT \
4854
std::cout << __FILE__ << "(" << std::dec << __LINE__ << "): info: "
@@ -121,13 +127,22 @@ namespace platform
121127
#endif
122128

123129
#define PLATFORM_ERROR(txt, ...) \
124-
platform::core::Error(txt, __FILE__, __LINE__, ##__VA_ARGS__)
130+
{\
131+
std::string str = fmt::format(txt, ##__VA_ARGS__);\
132+
std::cerr << fmt::format("{} ({}): error: {}", __FILE__, __LINE__, str) << "\n";\
133+
}
125134

126135
#define PLATFORM_WARN(txt, ...) \
127-
platform::core::Warn(txt, __FILE__, __LINE__, ##__VA_ARGS__)
136+
{\
137+
std::string str = fmt::format(txt, ##__VA_ARGS__);\
138+
std::cerr << fmt::format("{} ({}): warn: {}", __FILE__, __LINE__, str) << "\n";\
139+
}
128140

129141
#define PLATFORM_LOG(txt, ...) \
130-
platform::core::Info(txt, __FILE__, __LINE__, ##__VA_ARGS__)
142+
{\
143+
std::string str = fmt::format(txt, ##__VA_ARGS__);\
144+
std::cout << fmt::format("{} ({}): info: {}", __FILE__, __LINE__, str) << "\n";\
145+
}
131146

132147

133148
#define SIMUL_INTERNAL_COUT \
@@ -187,7 +202,7 @@ namespace platform
187202

188203
#define SIMUL_BREAK(msg, ...) \
189204
{ \
190-
platform::core::Error(msg, __FILE__, __LINE__, ##__VA_ARGS__); \
205+
PLATFORM_ERROR(msg, ##__VA_ARGS__); \
191206
BREAK_IF_DEBUGGING \
192207
}
193208

@@ -196,7 +211,7 @@ namespace platform
196211
static bool done = false; \
197212
if (!done) \
198213
{ \
199-
platform::core::Error(msg, __FILE__, __LINE__, ##__VA_ARGS__); \
214+
PLATFORM_ERROR(msg, ##__VA_ARGS__); \
200215
BREAK_IF_DEBUGGING; \
201216
done = true; \
202217
} \
@@ -347,4 +362,3 @@ namespace platform
347362
#pragma warning(pop)
348363
#endif
349364

350-
#endif

Core/TrackingAllocator.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
#include "Platform/Core/StringFunctions.h"
33
#include "Platform/Core/RuntimeError.h"
44
#include <string.h> // for strlen
5+
#if PLATFORM_CXX20_OR_ABOVE
6+
#include <format>
57
#include <fmt/format.h>
8+
#else
9+
#include <fmt/format.h>
10+
#endif
611

712
using namespace platform;
813
using namespace core;

CrossPlatform/Effect.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ crossplatform::SamplerStateDesc::Wrapping stringToWrapping(string s)
674674
return crossplatform::SamplerStateDesc::CLAMP;
675675
if(is_equal(s,"MIRROR"))
676676
return crossplatform::SamplerStateDesc::MIRROR;
677-
SIMUL_BREAK_ONCE((string("Invalid string")+s).c_str());
677+
SIMUL_BREAK_ONCE("Invalid string: {}",s);
678678
return crossplatform::SamplerStateDesc::WRAP;
679679
}
680680

@@ -686,7 +686,7 @@ crossplatform::SamplerStateDesc::Filtering stringToFilter(string s)
686686
return crossplatform::SamplerStateDesc::LINEAR;
687687
if(is_equal(s,"ANISOTROPIC"))
688688
return crossplatform::SamplerStateDesc::ANISOTROPIC;
689-
SIMUL_BREAK((string("Invalid string: ")+s).c_str());
689+
SIMUL_BREAK("Invalid string: {}",s);
690690
return crossplatform::SamplerStateDesc::POINT;
691691
}
692692

@@ -706,7 +706,7 @@ static crossplatform::CullFaceMode toCullFadeMode(string s)
706706
return crossplatform::CULL_FACE_FRONTANDBACK;
707707
else if(is_equal(s,"CULL_NONE"))
708708
return crossplatform::CULL_FACE_NONE;
709-
SIMUL_BREAK((string("Invalid string")+s).c_str());
709+
SIMUL_BREAK("Invalid string: {}",s);
710710
return crossplatform::CULL_FACE_NONE;
711711
}
712712

@@ -730,7 +730,7 @@ static crossplatform::Topology toTopology(string s)
730730
return crossplatform::Topology::TRIANGLELIST_ADJ;
731731
else if(is_equal(s,"TriangleStripAdjacency"))
732732
return crossplatform::Topology::TRIANGLESTRIP_ADJ;
733-
SIMUL_BREAK((string("Invalid string")+s).c_str());
733+
SIMUL_BREAK("Invalid string: {}",s);
734734
return crossplatform::Topology::UNDEFINED;
735735
}
736736

@@ -1015,8 +1015,7 @@ bool Effect::Load(crossplatform::RenderPlatform *r, const char *filename_utf8)
10151015
std::transform(binFilenameUtf8.begin(), binFilenameUtf8.end(), binFilenameUtf8.begin(), ::tolower);
10161016
if(!platform::core::FileLoader::GetFileLoader()->FileExists(binFilenameUtf8.c_str()))
10171017
{
1018-
string err= platform::core::QuickFormat("Shader effect file not found: %s",binFilenameUtf8.c_str());
1019-
SIMUL_BREAK_ONCE(err.c_str());
1018+
SIMUL_BREAK_ONCE("Shader effect file not found: {}",binFilenameUtf8);
10201019
static bool already = false;
10211020
if (!already)
10221021
{
@@ -1515,7 +1514,7 @@ bool Effect::Load(crossplatform::RenderPlatform *r, const char *filename_utf8)
15151514
platform::core::FileLoader::GetFileLoader()->AcquireFileContents(bin_ptr, bin_num_bytes, sfxbFilenameUtf8.c_str(), true);
15161515
if (!bin_ptr)
15171516
{
1518-
SIMUL_BREAK(platform::core::QuickFormat("Failed to load combined shader binary: %s\n", sfxbFilenameUtf8.c_str()));
1517+
SIMUL_BREAK("Failed to load combined shader binary: {}\n", sfxbFilenameUtf8);
15191518
}
15201519
}
15211520
}
@@ -1701,7 +1700,7 @@ bool Effect::Load(crossplatform::RenderPlatform *r, const char *filename_utf8)
17011700
}
17021701
else
17031702
{
1704-
SIMUL_BREAK(platform::core::QuickFormat("Unknown shader type or command: %s\n",type.c_str()));
1703+
SIMUL_BREAK("Unknown shader type or command: {}\n",type);
17051704
continue;
17061705
}
17071706
Shader *s = nullptr;

CrossPlatform/PlatformStructuredBuffer.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ namespace platform
7171
public:
7272
virtual ~BaseStructuredBuffer() = default;
7373
PlatformStructuredBuffer* platformStructuredBuffer=nullptr;
74+
int count=0;
7475
};
7576
class PlatformStructuredBuffer;
7677
/// Templated structured buffer, which uses platform-specific implementations of PlatformStructuredBuffer.
@@ -83,7 +84,6 @@ namespace platform
8384
{
8485
public:
8586
StructuredBuffer()
86-
:count(0)
8787
{
8888
}
8989
~StructuredBuffer()
@@ -187,8 +187,6 @@ namespace platform
187187
if (platformStructuredBuffer)
188188
platformStructuredBuffer->ResetCopies();
189189
}
190-
191-
int count;
192190
};
193191

194192
}

CrossPlatform/RenderPlatform.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
#include <algorithm>
3232
#include <array>
3333
#include <atomic>
34-
#include <fmt/core.h>
3534

3635
using namespace std::literals;
3736
using namespace std::string_literals;
@@ -2061,7 +2060,7 @@ std::shared_ptr<Effect> RenderPlatform::GetOrCreateEffect(const char *filename_u
20612060
bool success = e->Load(this,filename_utf8);
20622061
if (!success)
20632062
{
2064-
SIMUL_BREAK(platform::core::QuickFormat("Failed to load effect file: %s. Effect will be placeholder.\n", filename_utf8));
2063+
SIMUL_BREAK("Failed to load effect file: {}. Effect will be placeholder.\n", filename_utf8);
20652064
return e;
20662065
}
20672066
return e;

CrossPlatform/Shaders/vec2.sl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ struct tvector2
223223
}
224224
friend tvector2 operator/(const T &m, const tvector2 &v)
225225
{
226-
tvector3 r;
226+
tvector2 r;
227227
r.x = m / v.x;
228228
r.y = m / v.y;
229229
return r;

CrossPlatform/Shaders/vec4.sl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ struct tvector4
291291
}
292292
friend tvector4 operator/(const T &m, const tvector4 &v)
293293
{
294-
tvector3 r;
294+
tvector4 r;
295295
r.x = m / v.x;
296296
r.y = m / v.y;
297297
r.z = m / v.z;

0 commit comments

Comments
 (0)