mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-10 02:53:51 +00:00
refactor(editor): extract initWomDefaults + saveWomOrError
Two more boilerplate patterns repeated across cli_gen_mesh.cpp:
• init: 64 sites set wom.name = path-stem and wom.version = 3
in 3 lines. Hoisted to initWomDefaults(wom, base) — 1 line.
• save: 65 sites had identical 5-line "if save fails, fprintf
stderr and return 1" blocks. Hoisted to saveWomOrError(wom,
base, cmdName) returning bool, used as
`if (!saveWomOrError(...)) return 1;` — also 1 line.
Net cli_gen_mesh.cpp drops by ~254 lines (from 6424 to 6170).
Output bytes verified identical: firepit surface area 2.1100
m² unchanged, cube vertex/index/bounds counts unchanged.
After this batch's prior helpers (addFlatBox, addVertex,
stripExt, finalizeAsSingleBatch, parseOpt*), a typical new
gen-mesh handler now needs zero copy-paste boilerplate to
get a working primitive — every shared bit lives in
cli_box_emitter.hpp and cli_arg_parse.hpp.
This commit is contained in:
parent
a10efed8f5
commit
783b0f167f
2 changed files with 154 additions and 454 deletions
|
|
@ -3,12 +3,37 @@
|
|||
#include "pipeline/wowee_model.hpp"
|
||||
#include <glm/glm.hpp>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
|
||||
namespace wowee {
|
||||
namespace editor {
|
||||
namespace cli {
|
||||
|
||||
// Initialize a fresh WoweeModel with the canonical procedural-
|
||||
// primitive defaults: name derived from the base path's stem and
|
||||
// version 3 (current). 64 handlers in cli_gen_mesh.cpp open-coded
|
||||
// this 3-line block before extraction.
|
||||
inline void initWomDefaults(wowee::pipeline::WoweeModel& wom,
|
||||
const std::string& base) {
|
||||
wom.name = std::filesystem::path(base).stem().string();
|
||||
wom.version = 3;
|
||||
}
|
||||
|
||||
// Save a WoweeModel and report a stderr message on failure.
|
||||
// Returns true on success so the caller can do
|
||||
// `if (!saveWomOrError(...)) return 1;`. The cmdName is included
|
||||
// in the error message for context.
|
||||
inline bool saveWomOrError(const wowee::pipeline::WoweeModel& wom,
|
||||
const std::string& base,
|
||||
const char* cmdName) {
|
||||
if (wowee::pipeline::WoweeModelLoader::save(wom, base)) return true;
|
||||
std::fprintf(stderr, "%s: failed to save %s.wom\n",
|
||||
cmdName, base.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
// Strip a file-extension suffix from a base path if present. Used
|
||||
// pervasively by --gen-mesh-* / --bake-* / --info-* handlers that
|
||||
// accept either `path/foo` or `path/foo.ext` as input — the loader
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue