mirror of
https://github.com/johndoe6345789/SDL3CPlusPlus.git
synced 2026-05-04 10:34:55 +00:00
better docs and things
This commit is contained in:
@@ -64,6 +64,9 @@ if(CMAKE_GENERATOR MATCHES "Ninja" OR CMAKE_GENERATOR MATCHES "Ninja Multi-Confi
|
||||
if(DEFINED CMAKE_GENERATOR_PLATFORM)
|
||||
set(CMAKE_GENERATOR_PLATFORM "" CACHE STRING "" FORCE)
|
||||
endif()
|
||||
if(DEFINED CMAKE_GENERATOR_TOOLSET)
|
||||
set(CMAKE_GENERATOR_TOOLSET "" CACHE STRING "" FORCE)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(BUILD_SDL3_APP)
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
},
|
||||
"include": [
|
||||
"build/CMakePresets.json",
|
||||
"build-ninja/CMakePresets.json"
|
||||
"build-ninja/CMakePresets.json",
|
||||
"build-ninja-msvc/CMakePresets.json"
|
||||
]
|
||||
}
|
||||
@@ -15,12 +15,21 @@ A minimal SDL3 + Vulkan spinning cube demo.
|
||||
2. **Configure**
|
||||
- Default (Visual Studio): `cmake -B build -S .`
|
||||
* This uses the Visual Studio 2022 generator.
|
||||
- Ninja: configure into a clean folder, e.g., `cmake -G Ninja -B build-ninja -S .`
|
||||
- Ninja (clang/MinGW): configure into a clean folder, e.g., `cmake -G Ninja -B build-ninja -S .`
|
||||
* CMake already appends `C:\ProgramData\chocolatey\bin` to `CMAKE_PROGRAM_PATH`, so Ninja and Chocolatey LLVM tools are discoverable without extra `PATH` edits.
|
||||
* Ninja is a single-config generator. When no multi-config generator has been used, the project defaults `CMAKE_BUILD_TYPE=Release`; override it with `-DCMAKE_BUILD_TYPE=Debug` if you need another configuration in that folder.
|
||||
- Ninja with MSVC: open a Developer Command Prompt (call `"%VSINSTALLDIR%VC\\Auxiliary\\Build\\vcvarsall.bat" x64` or run that batch file from PowerShell) and configure with
|
||||
```
|
||||
cmake -G Ninja -B build-ninja-msvc -S . -DCMAKE_BUILD_TYPE=Release
|
||||
```
|
||||
Keep using the same prompt (so `cl.exe` carries the SDK/CRT paths) and build with `cmake --build build-ninja-msvc --config Release`.
|
||||
* Quick one-liner that initializes the MSVC environment and runs the Release build from a regular shell:
|
||||
```
|
||||
cmd /c "call \"%VSINSTALLDIR%VC\Auxiliary\Build\vcvarsall.bat\" x64 && cmake --build build-ninja-msvc --config Release"
|
||||
```
|
||||
- Optional clang-tidy: add `-DENABLE_CLANG_TIDY=ON`
|
||||
* CMake searches both `C:\Program Files\LLVM\bin` and `C:\ProgramData\chocolatey\bin`, so standard LLVM/Chocolatey installs are found automatically.
|
||||
* The wrapped clang-tidy binary prints `[clang-tidy] starting …` and `[clang-tidy] finished (exit …)` markers so you can spot linting in verbose logs even when no diagnostics appear.
|
||||
* The wrapped clang-tidy binary prints `[clang-tidy] starting .` and `[clang-tidy] finished (exit .)` markers so you can spot linting in verbose logs even when no diagnostics appear.
|
||||
|
||||
3. **Build**
|
||||
- `cmake --build build --config Release --target sdl3_app` (or point at `build-ninja` if you used Ninja).
|
||||
@@ -37,9 +46,18 @@ If you rely on the Conan runtime environment (some dependencies export env vars)
|
||||
|
||||
## Runtime configuration
|
||||
|
||||
1. `main.cpp` now uses a JSON-driven entrypoint. Run `sdl3_app --json-file-in <path>` to load a config that points at the Lua script and defines window dimensions.
|
||||
2. Generate a starter JSON peppered with the default script locations via `sdl3_app --create-seed-json config/seed_runtime.json` (it assumes `scripts/cube_logic.lua` is next to the executable).
|
||||
3. Copy a JSON into the platform default by running `sdl3_app --set-default-json [path]` (APPDATA on Windows, `XDG_CONFIG_HOME`/`~/.config` elsewhere). When the default file exists, the app picks it up automatically; otherwise it discovers `scripts/cube_logic.lua` next to the binary.
|
||||
1. `main.cpp` now uses a JSON-driven entrypoint.
|
||||
- Pass `sdl3_app --json-file-in <path>` to load runtime settings such as the Lua script path, window size, and `lua_debug`.
|
||||
- The loader enforces valid types and resolves relative scripts next to the configuration file.
|
||||
2. Generate a starter JSON with the shipped script locations:
|
||||
```
|
||||
sdl3_app --create-seed-json config/seed_runtime.json
|
||||
```
|
||||
The helper assumes `scripts/cube_logic.lua` lives beside the executable and writes normalized paths.
|
||||
3. Store or override the app-wide config with `sdl3_app --set-default-json [path]`.
|
||||
- Windows uses `%APPDATA%/sdl3cpp`; other platforms use `$XDG_CONFIG_HOME/sdl3cpp/default_runtime.json`, falling back to `~/.config/sdl3cpp`.
|
||||
- Providing a `path` duplicates that JSON into the platform default without editing the runtime values.
|
||||
- When the default file exists the executable reads it automatically; otherwise it falls back to the built-in script discovery logic.
|
||||
|
||||
### GUI Demo
|
||||
`scripts/gui_demo.lua` shows off the Lua GUI framework (buttons, text boxes, list views, and SVG icons) rendered on top of the Vulkan scene. Launch it with `./build/sdl3_app --json-file-in config/gui_runtime.json` (or use that config via `sdl3_app --set-default-json`) to run the interactive overlay in the window.
|
||||
|
||||
+16
-16
@@ -6,6 +6,8 @@
|
||||
#include <rapidjson/prettywriter.h>
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstdint>
|
||||
#include <exception>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
@@ -243,36 +245,34 @@ void WriteRuntimeConfigJson(const RuntimeConfig& runtimeConfig,
|
||||
document.SetObject();
|
||||
auto& allocator = document.GetAllocator();
|
||||
|
||||
auto addStringMember = [&](const char* name, const std::string& value) {
|
||||
rapidjson::Value nameValue(name, allocator);
|
||||
rapidjson::Value stringValue(value.c_str(), allocator);
|
||||
document.AddMember(nameValue, stringValue, allocator);
|
||||
};
|
||||
|
||||
document.AddMember("window_width", runtimeConfig.width, allocator);
|
||||
document.AddMember("window_height", runtimeConfig.height, allocator);
|
||||
document.AddMember("lua_script",
|
||||
rapidjson::Value(runtimeConfig.scriptPath.string().c_str(), allocator),
|
||||
allocator);
|
||||
addStringMember("lua_script", runtimeConfig.scriptPath.string());
|
||||
|
||||
std::filesystem::path scriptsDir = runtimeConfig.scriptPath.parent_path();
|
||||
document.AddMember("scripts_directory",
|
||||
rapidjson::Value(scriptsDir.string().c_str(), allocator), allocator);
|
||||
addStringMember("scripts_directory", scriptsDir.string());
|
||||
|
||||
std::filesystem::path projectRoot = scriptsDir.parent_path();
|
||||
if (!projectRoot.empty()) {
|
||||
document.AddMember(
|
||||
"project_root",
|
||||
rapidjson::Value(projectRoot.string().c_str(), allocator), allocator);
|
||||
document.AddMember(
|
||||
"shaders_directory",
|
||||
rapidjson::Value((projectRoot / "shaders").string().c_str(), allocator), allocator);
|
||||
addStringMember("project_root", projectRoot.string());
|
||||
addStringMember("shaders_directory", (projectRoot / "shaders").string());
|
||||
} else {
|
||||
document.AddMember("shaders_directory",
|
||||
rapidjson::Value("shaders", allocator), allocator);
|
||||
addStringMember("shaders_directory", "shaders");
|
||||
}
|
||||
|
||||
rapidjson::Value extensionArray(rapidjson::kArrayType);
|
||||
for (const char* extension : sdl3cpp::app::kDeviceExtensions) {
|
||||
extensionArray.PushBack(rapidjson::Value(extension, allocator), allocator);
|
||||
rapidjson::Value extensionValue(extension, allocator);
|
||||
extensionArray.PushBack(extensionValue, allocator);
|
||||
}
|
||||
document.AddMember("device_extensions", extensionArray, allocator);
|
||||
document.AddMember("config_file",
|
||||
rapidjson::Value(configPath.string().c_str(), allocator), allocator);
|
||||
addStringMember("config_file", configPath.string());
|
||||
|
||||
rapidjson::StringBuffer buffer;
|
||||
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
|
||||
|
||||
Reference in New Issue
Block a user