Skip to content

Commit 9dd3279

Browse files
committed
Fix D3D12 crash on ESC, stop benchmark on exit, expand CLI options
1 parent c1ad8ff commit 9dd3279

4 files changed

Lines changed: 87 additions & 15 deletions

File tree

Engine/include/private/Graphics/DirectX/DirectX12Renderer.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class ENGINE_API DirectX12Renderer : public Renderer, public RenderContext {
3131
void BeginRender() override;
3232
void EndRender() override;
3333
void Cleanup() override;
34+
void WaitIdle() override { WaitForGPU(); }
3435

3536
virtual void Resize(uint32_t width, uint32_t height) override;
3637

Engine/include/public/Core/CommandLine.hpp

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,18 @@ namespace Sleak {
1414
//
1515
// Supported flags
1616
// ───────────────
17-
// -r <api> Renderer: vulkan | d3d11 | d3d12 | opengl
18-
// -w <n> Window width (default 1200)
19-
// -h <n> Window height (default 800)
20-
// -t <name> Window title; use _ for spaces
21-
// -world <name> World to open (load if save exists, else create with random seed)
17+
// -r <api> Renderer: vulkan | d3d11 | d3d12 | opengl
18+
// -w <n> Window width (default 1200)
19+
// -h <n> Window height (default 800)
20+
// -t <name> Window title; use _ for spaces
21+
// -world <name> World to open (load if save exists, else create with random seed)
22+
// -seed <n> Seed for new world creation (default: random)
23+
// -rd <n> Initial render distance in chunks (default: 8)
24+
// -msaa <n> MSAA sample count: 1 | 2 | 4 | 8 (default: 1)
25+
// --vsync Enable VSync on launch
26+
// --no-vsync Disable VSync on launch
27+
// --fullscreen Start in fullscreen
28+
// --fly Start in fly mode
2229
// --bench / --benchmark Auto-start benchmark recording on launch
2330
// --help / help Print help and continue
2431
class ENGINE_API CommandLine {
@@ -27,12 +34,18 @@ class ENGINE_API CommandLine {
2734
static void Parse(int argc, char** argv);
2835

2936
// Typed accessors
30-
static int GetWidth(); // -w (default 1200)
31-
static int GetHeight(); // -h (default 800)
32-
static std::string GetTitle(); // -t (underscores → spaces)
33-
static std::string GetRenderer(); // -r
34-
static std::string GetWorldName(); // -world
35-
static bool AutoBenchmark(); // --bench / --benchmark
37+
static int GetWidth(); // -w (default 1200)
38+
static int GetHeight(); // -h (default 800)
39+
static std::string GetTitle(); // -t (underscores → spaces)
40+
static std::string GetRenderer(); // -r
41+
static std::string GetWorldName(); // -world
42+
static int GetSeed(); // -seed (0 = random)
43+
static int GetRenderDistance(); // -rd (0 = use default)
44+
static int GetMSAA(); // -msaa (0 = use default)
45+
static int GetVSync(); // 1=on, -1=off, 0=unset
46+
static bool StartFullscreen(); // --fullscreen
47+
static bool StartFlyMode(); // --fly
48+
static bool AutoBenchmark(); // --bench / --benchmark
3649

3750
// Generic access for custom flags
3851
static bool HasFlag (const std::string& flag);

Engine/src/Application.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,17 @@ namespace Sleak {
142142

143143
Game->Begin();
144144

145+
// Apply CLI graphics settings
146+
{
147+
int vsync = CommandLine::GetVSync();
148+
if (vsync != 0) renderer->SetVSync(vsync > 0);
149+
150+
int msaa = CommandLine::GetMSAA();
151+
if (msaa > 0) renderer->SetMSAASampleCount(static_cast<uint32_t>(msaa));
152+
153+
if (CommandLine::StartFullscreen()) CoreWindow->ToggleFullScreen();
154+
}
155+
145156
// Auto-start benchmark if --bench / --benchmark was passed
146157
if (CommandLine::AutoBenchmark() && m_benchmark)
147158
m_benchmark->ToggleRecording();

Engine/src/CommandLine.cpp

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,44 @@ std::string CommandLine::GetWorldName() {
7575
return (it != s_values.end()) ? it->second : "";
7676
}
7777

78+
int CommandLine::GetSeed() {
79+
auto it = s_values.find("-seed");
80+
if (it != s_values.end() && !it->second.empty()) {
81+
try { return std::stoi(it->second); } catch (...) {}
82+
}
83+
return 0;
84+
}
85+
86+
int CommandLine::GetRenderDistance() {
87+
auto it = s_values.find("-rd");
88+
if (it != s_values.end() && !it->second.empty()) {
89+
try { return std::stoi(it->second); } catch (...) {}
90+
}
91+
return 0;
92+
}
93+
94+
int CommandLine::GetMSAA() {
95+
auto it = s_values.find("-msaa");
96+
if (it != s_values.end() && !it->second.empty()) {
97+
try { return std::stoi(it->second); } catch (...) {}
98+
}
99+
return 0;
100+
}
101+
102+
int CommandLine::GetVSync() {
103+
if (s_flags.count("--vsync")) return 1;
104+
if (s_flags.count("--no-vsync")) return -1;
105+
return 0;
106+
}
107+
108+
bool CommandLine::StartFullscreen() {
109+
return s_flags.count("--fullscreen") > 0;
110+
}
111+
112+
bool CommandLine::StartFlyMode() {
113+
return s_flags.count("--fly") > 0;
114+
}
115+
78116
bool CommandLine::AutoBenchmark() {
79117
return s_flags.count("--bench") || s_flags.count("--benchmark");
80118
}
@@ -100,19 +138,28 @@ void CommandLine::PrintHelp(const char* exe) {
100138
<< " -r d3d12 Use DirectX 12\n"
101139
<< " -r opengl Use OpenGL\n"
102140
<< "\nWindow\n"
103-
<< " -w <pixels> Window width (default: 1200)\n"
104-
<< " -h <pixels> Window height (default: 800)\n"
105-
<< " -t <name> Window title (use _ for spaces)\n"
141+
<< " -w <pixels> Window width (default: 1200)\n"
142+
<< " -h <pixels> Window height (default: 800)\n"
143+
<< " -t <name> Window title (use _ for spaces)\n"
144+
<< " --fullscreen Start in fullscreen\n"
106145
<< "\nWorld\n"
107146
<< " -world <name> Load world if save exists, create new otherwise\n"
147+
<< " -seed <n> Seed for new world creation (default: random)\n"
148+
<< " -rd <n> Initial render distance in chunks (default: 8)\n"
149+
<< " --fly Start in fly mode\n"
150+
<< "\nGraphics\n"
151+
<< " -msaa <n> MSAA sample count: 1, 2, 4, 8 (default: 1)\n"
152+
<< " --vsync Enable VSync on launch\n"
153+
<< " --no-vsync Disable VSync on launch\n"
108154
<< "\nBenchmark\n"
109155
<< " --bench Start benchmark recording immediately on launch\n"
110156
<< "\nMisc\n"
111157
<< " --help Show this message\n"
112158
<< "\nExamples\n"
113159
<< " SleakCraft -r vulkan -world MyWorld\n"
114160
<< " SleakCraft -r d3d11 -world TestWorld --bench\n"
115-
<< " SleakCraft -w 1920 -h 1080 -t My_Game\n\n";
161+
<< " SleakCraft -r d3d12 -world Perf -rd 16 -msaa 4 --bench\n"
162+
<< " SleakCraft -w 1920 -h 1080 --fullscreen --vsync\n\n";
116163
}
117164

118165
} // namespace Sleak

0 commit comments

Comments
 (0)