mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-10 02:53:51 +00:00
refactor(editor): extract optional-arg parse helpers
Some checks are pending
Build / Build (arm64) (push) Waiting to run
Build / Build (x86-64) (push) Waiting to run
Build / Build (macOS arm64) (push) Waiting to run
Build / Build (windows-arm64) (push) Waiting to run
Build / Build (windows-x86-64) (push) Waiting to run
Security / CodeQL (C/C++) (push) Waiting to run
Security / Semgrep (push) Waiting to run
Security / Sanitizer Build (ASan/UBSan) (push) Waiting to run
Some checks are pending
Build / Build (arm64) (push) Waiting to run
Build / Build (x86-64) (push) Waiting to run
Build / Build (macOS arm64) (push) Waiting to run
Build / Build (windows-arm64) (push) Waiting to run
Build / Build (windows-x86-64) (push) Waiting to run
Security / CodeQL (C/C++) (push) Waiting to run
Security / Semgrep (push) Waiting to run
Security / Sanitizer Build (ASan/UBSan) (push) Waiting to run
Every --gen-texture-* and --gen-mesh-* handler had its own
copy of the same 3-line "if there's another arg AND it
doesn't look like a switch, parse it; otherwise keep the
default" block. 458 sites across cli_gen_texture.cpp and
cli_gen_mesh.cpp duplicated this pattern.
Hoist into cli_arg_parse.hpp as inline parseOpt{Int,Float,Uint}
(int& i, int argc, char** argv, T& value). Each call site
collapses from 3 lines to 1:
if (i + 1 < argc && argv[i + 1][0] != '-') {
try { width = std::stof(argv[++i]); } catch (...) {}
}
becomes
parseOptFloat(i, argc, argv, width);
cli_gen_mesh.cpp drops by ~250 lines, cli_gen_texture.cpp
by ~430 lines. Output bytes verified identical: firepit
default-arg surface area 2.1100 m² unchanged.
Future texture/mesh primitives now opt in by including one
header instead of pasting the lambda.
This commit is contained in:
parent
e23b3faa1c
commit
56c12bc252
3 changed files with 505 additions and 1374 deletions
45
tools/editor/cli_arg_parse.hpp
Normal file
45
tools/editor/cli_arg_parse.hpp
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
namespace wowee {
|
||||
namespace editor {
|
||||
namespace cli {
|
||||
|
||||
// Common pattern across cli_gen_texture and cli_gen_mesh handlers:
|
||||
// "if there's another arg AND it doesn't look like a switch, parse
|
||||
// it into <var>; otherwise leave <var> at its default". 465+ copies
|
||||
// across the two files were each writing this 3-line block manually.
|
||||
//
|
||||
// Each helper silently no-ops on parse failure so the caller's
|
||||
// default value is preserved — matches the prior try/catch
|
||||
// behavior exactly.
|
||||
|
||||
inline bool parseOptArg(int& i, int argc, char** argv) {
|
||||
return i + 1 < argc && argv[i + 1][0] != '-';
|
||||
}
|
||||
|
||||
inline void parseOptInt(int& i, int argc, char** argv, int& value) {
|
||||
if (parseOptArg(i, argc, argv)) {
|
||||
try { value = std::stoi(argv[++i]); } catch (...) {}
|
||||
}
|
||||
}
|
||||
|
||||
inline void parseOptFloat(int& i, int argc, char** argv, float& value) {
|
||||
if (parseOptArg(i, argc, argv)) {
|
||||
try { value = std::stof(argv[++i]); } catch (...) {}
|
||||
}
|
||||
}
|
||||
|
||||
inline void parseOptUint(int& i, int argc, char** argv, uint32_t& value) {
|
||||
if (parseOptArg(i, argc, argv)) {
|
||||
try { value = static_cast<uint32_t>(std::stoul(argv[++i])); }
|
||||
catch (...) {}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace cli
|
||||
} // namespace editor
|
||||
} // namespace wowee
|
||||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue