From 1344e39d72a0ee541bfa1465a7d95ad5b33ee1fd Mon Sep 17 00:00:00 2001 From: Luis Michaelis Date: Tue, 2 Jan 2024 17:12:21 +0100 Subject: [PATCH] refactor(*): remove boilerplate --- src/Boxes.cc | 53 +-- src/CutsceneLibrary.cc | 99 +---- src/Font.cc | 92 +--- src/Material.cc | 154 ++----- src/Mesh.cc | 214 ++------- src/Model.cc | 70 +-- src/ModelAnimation.cc | 160 +------ src/ModelHierarchy.cc | 116 +---- src/ModelMesh.cc | 103 +---- src/ModelScript.cc | 872 ++++++++++--------------------------- src/MorphMesh.cc | 181 ++------ src/MultiResolutionMesh.cc | 162 +------ src/SoftSkinMesh.cc | 34 +- src/Stream.cc | 15 +- src/Texture.cc | 144 +----- src/Vfs.cc | 109 +---- src/World.cc | 99 +---- src/world/BspTree.cc | 65 +-- src/world/WayNet.cc | 64 +-- 19 files changed, 520 insertions(+), 2286 deletions(-) diff --git a/src/Boxes.cc b/src/Boxes.cc index fb9f1e8..da67188 100644 --- a/src/Boxes.cc +++ b/src/Boxes.cc @@ -6,61 +6,33 @@ ZkVec3f ZkOrientedBoundingBox_getCenter(ZkOrientedBoundingBox const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkOrientedBoundingBox_getCenter"); - return {}; - } - + ZKC_CHECK_NULL(slf); return slf->center; } ZkVec3f ZkOrientedBoundingBox_getAxis(ZkOrientedBoundingBox const* slf, ZkSize i) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkOrientedBoundingBox_getAxis"); - return {}; - } - - if (i >= 3) { - ZKC_LOG_ERROR("ZkOrientedBoundingBox_getAxis() failed: index out of range (0..2)"); - return {}; - } - + ZKC_CHECK_NULL(slf); + ZKC_CHECK_LENA(3, i); return slf->axes[i]; } ZkVec3f ZkOrientedBoundingBox_getHalfWidth(ZkOrientedBoundingBox const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkOrientedBoundingBox_getHalfWidth"); - return {}; - } - + ZKC_CHECK_NULL(slf); return slf->half_width; } ZkSize ZkOrientedBoundingBox_getChildCount(ZkOrientedBoundingBox const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkOrientedBoundingBox_getChildCount"); - return {}; - } - + ZKC_CHECK_NULL(slf); return slf->children.size(); } ZkOrientedBoundingBox const* ZkOrientedBoundingBox_getChild(ZkOrientedBoundingBox const* slf, ZkSize i) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkOrientedBoundingBox_getChildCount"); - return {}; - } - - if (i >= slf->children.size()) { - ZKC_LOG_ERROR("ZkOrientedBoundingBox_getChild() failed: index out of range"); - return {}; - } - + ZKC_CHECK_NULL(slf); + ZKC_CHECK_LEN(slf->children, i); return &slf->children[i]; } @@ -68,10 +40,7 @@ void ZkOrientedBoundingBox_enumerateChildren(ZkOrientedBoundingBox const* slf, ZkOrientedBoundingBoxEnumerator cb, void* ctx) { ZKC_TRACE_FN(); - if (slf == nullptr || cb == nullptr) { - ZKC_LOG_WARN_NULL("ZkOrientedBoundingBox_enumerateChildren"); - return; - } + ZKC_CHECK_NULLV(slf, cb); for (auto& child : slf->children) { if (cb(ctx, &child)) break; @@ -80,10 +49,6 @@ void ZkOrientedBoundingBox_enumerateChildren(ZkOrientedBoundingBox const* slf, ZkAxisAlignedBoundingBox ZkOrientedBoundingBox_toAabb(ZkOrientedBoundingBox const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkOrientedBoundingBox_toAabb"); - return {}; - } - + ZKC_CHECK_NULL(slf); return slf->as_bbox(); } diff --git a/src/CutsceneLibrary.cc b/src/CutsceneLibrary.cc index 23fc7eb..50a3ede 100644 --- a/src/CutsceneLibrary.cc +++ b/src/CutsceneLibrary.cc @@ -4,77 +4,20 @@ #include "Internal.hh" -ZkCutsceneLibrary* ZkCutsceneLibrary_load(ZkRead* buf) { - ZKC_TRACE_FN(); - if (buf == nullptr) { - ZKC_LOG_WARN_NULL("ZkCutsceneLibrary_load"); - return nullptr; - } - - try { - ZkCutsceneLibrary obj {}; - obj.load(buf); - return ZKC_WRAP_NEW(obj); - } catch (std::exception const& exc) { - ZKC_LOG_ERROR("ZkCutsceneLibrary_load() failed: %s", exc.what()); - return nullptr; - } -} - -ZkCutsceneLibrary* ZkCutsceneLibrary_loadPath(ZkString path) { - ZKC_TRACE_FN(); - if (path == nullptr) { - ZKC_LOG_WARN_NULL("ZkCutsceneLibrary_loadPath"); - return nullptr; - } - - try { - auto buf = zenkit::Read::from(path); - - ZkCutsceneLibrary obj {}; - obj.load(buf.get()); - return ZKC_WRAP_NEW(obj); - } catch (std::exception const& exc) { - ZKC_LOG_ERROR("ZkCutsceneLibrary_loadPath() failed: %s", exc.what()); - return nullptr; - } -} - -ZkCutsceneLibrary* ZkCutsceneLibrary_loadVfs(ZkVfs const* vfs, ZkString name) { - ZKC_TRACE_FN(); - if (vfs == nullptr || name == nullptr) { - ZKC_LOG_WARN_NULL("ZkCutsceneLibrary_loadVfs"); - return nullptr; - } - - auto node = vfs->find(name); - if (node == nullptr) return nullptr; - - auto rd = node->open_read(); - return ZkCutsceneLibrary_load(rd.get()); -} - -void ZkCutsceneLibrary_del(ZkCutsceneLibrary* slf) { - ZKC_TRACE_FN(); - delete slf; -} +ZKC_LOADER(ZkCutsceneLibrary); +ZKC_PATH_LOADER(ZkCutsceneLibrary); +ZKC_VFS_LOADER(ZkCutsceneLibrary); +ZKC_DELETER(ZkCutsceneLibrary); ZkCutsceneBlock const* ZkCutsceneLibrary_getBlock(ZkCutsceneLibrary const* slf, ZkString name) { ZKC_TRACE_FN(); - if (slf == nullptr || name == nullptr) { - ZKC_LOG_WARN_NULL("ZkCutsceneLibrary_getBlock"); - return nullptr; - } - + ZKC_CHECK_NULL(slf); return slf->block_by_name(name); } void ZkCutsceneLibrary_enumerateBlocks(ZkCutsceneLibrary const* slf, ZkCutsceneBlockEnumerator cb, void* ctx) { ZKC_TRACE_FN(); - if (slf == nullptr || cb == nullptr) { - ZKC_LOG_WARN_NULL("ZkCutsceneLibrary_enumerateBlocks"); - return; - } + ZKC_CHECK_NULLV(slf, cb); for (auto& block : slf->blocks) { if (cb(ctx, &block)) break; @@ -83,50 +26,30 @@ void ZkCutsceneLibrary_enumerateBlocks(ZkCutsceneLibrary const* slf, ZkCutsceneB ZkString ZkCutsceneBlock_getName(ZkCutsceneBlock const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkCutsceneBlock_getName"); - return nullptr; - } - + ZKC_CHECK_NULL(slf); return slf->name.c_str(); } ZkCutsceneMessage const* ZkCutsceneBlock_getMessage(ZkCutsceneBlock const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkCutsceneBlock_getMessage"); - return nullptr; - } - + ZKC_CHECK_NULL(slf); return &slf->message; } uint32_t ZkCutsceneMessage_getType(ZkCutsceneMessage const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkCutsceneMessage_getType"); - return 0; - } - + ZKC_CHECK_NULL(slf); return slf->type; } ZkString ZkCutsceneMessage_getText(ZkCutsceneMessage const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkCutsceneMessage_getText"); - return nullptr; - } - + ZKC_CHECK_NULL(slf); return slf->text.c_str(); } ZkString ZkCutsceneMessage_getName(ZkCutsceneMessage const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkCutsceneMessage_getName"); - return nullptr; - } - + ZKC_CHECK_NULL(slf); return slf->name.c_str(); } diff --git a/src/Font.cc b/src/Font.cc index 2b3e029..adaad26 100644 --- a/src/Font.cc +++ b/src/Font.cc @@ -4,102 +4,33 @@ #include "Internal.hh" -ZkFont* ZkFont_load(ZkRead* buf) { - ZKC_TRACE_FN(); - if (buf == nullptr) { - ZKC_LOG_WARN_NULL("ZkFont_load"); - return nullptr; - } - - try { - ZkFont obj {}; - obj.load(buf); - return ZKC_WRAP_NEW(obj); - } catch (std::exception const& exc) { - ZKC_LOG_ERROR("ZkFont_load() failed: %s", exc.what()); - return nullptr; - } -} - -ZkFont* ZkFont_loadPath(ZkString path) { - ZKC_TRACE_FN(); - if (path == nullptr) { - ZKC_LOG_WARN_NULL("ZkFont_loadPath"); - return nullptr; - } - - try { - auto buf = zenkit::Read::from(path); - - ZkFont obj {}; - obj.load(buf.get()); - return ZKC_WRAP_NEW(obj); - } catch (std::exception const& exc) { - ZKC_LOG_ERROR("ZkFont_loadPath() failed: %s", exc.what()); - return nullptr; - } -} - -ZkFont* ZkFont_loadVfs(ZkVfs* vfs, ZkString name) { - ZKC_TRACE_FN(); - if (vfs == nullptr || name == nullptr) { - ZKC_LOG_WARN_NULL("ZkFont_loadVfs"); - return nullptr; - } - - auto node = vfs->find(name); - if (node == nullptr) return nullptr; - - auto rd = node->open_read(); - return ZkFont_load(rd.get()); -} - -void ZkFont_del(ZkFont* slf) { - ZKC_TRACE_FN(); - delete slf; -} +ZKC_LOADER(ZkFont); +ZKC_PATH_LOADER(ZkFont); +ZKC_VFS_LOADER(ZkFont); +ZKC_DELETER(ZkFont); ZkString ZkFont_getName(ZkFont const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkFont_getName"); - return nullptr; - } - + ZKC_CHECK_NULL(slf); return slf->name.c_str(); } uint32_t ZkFont_getHeight(ZkFont const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkFont_getHeight"); - return 0; - } - + ZKC_CHECK_NULL(slf); return slf->height; } ZkSize ZkFont_getGlyphCount(ZkFont const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkFont_getGlyphCount"); - return 0; - } - + ZKC_CHECK_NULL(slf); return slf->glyphs.size(); } ZkFontGlyph ZkFont_getGlyph(ZkFont const* slf, ZkSize i) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkFont_getGlyph"); - return {0, {}, {}}; - } - - if (i >= slf->glyphs.size()) { - ZKC_LOG_ERROR("ZkFont_getGlyph() failed: index out of range"); - return {0, {}, {}}; - } + ZKC_CHECK_NULL(slf); + ZKC_CHECK_LEN(slf->glyphs, i); auto& glyph = slf->glyphs[i]; return {glyph.width, glyph.uv[0], glyph.uv[1]}; @@ -107,10 +38,7 @@ ZkFontGlyph ZkFont_getGlyph(ZkFont const* slf, ZkSize i) { void ZkFont_enumerateGlyphs(ZkFont const* slf, ZkFontGlyphEnumerator cb, void* ctx) { ZKC_TRACE_FN(); - if (slf == nullptr || cb == nullptr) { - ZKC_LOG_WARN_NULL("ZkFont_enumerateGlyphs"); - return; - } + ZKC_CHECK_NULLV(slf, cb); ZkFontGlyph fg {0, {}, {}}; for (auto& glyph : slf->glyphs) { diff --git a/src/Material.cc b/src/Material.cc index 281e511..bab62cb 100644 --- a/src/Material.cc +++ b/src/Material.cc @@ -8,10 +8,7 @@ ZkMaterial* ZkMaterial_load(ZkRead* buf) { ZKC_TRACE_FN(); - if (buf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMaterial_load"); - return nullptr; - } + ZKC_CHECK_NULL(buf); try { auto ar = zenkit::ReadArchive::from(buf); @@ -28,10 +25,7 @@ ZkMaterial* ZkMaterial_load(ZkRead* buf) { ZkMaterial* ZkMaterial_loadPath(ZkString path) { ZKC_TRACE_FN(); - if (path == nullptr) { - ZKC_LOG_WARN_NULL("ZkMaterial_loadPath"); - return nullptr; - } + ZKC_CHECK_NULL(path); try { auto buf = zenkit::Read::from(path); @@ -54,240 +48,144 @@ void ZkMaterial_del(ZkMaterial* slf) { ZkString ZkMaterial_getName(ZkMaterial const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMaterial_getName"); - return nullptr; - } - + ZKC_CHECK_NULL(slf); return slf->name.c_str(); } ZkMaterialGroup ZkMaterial_getGroup(ZkMaterial const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMaterial_getGroup"); - return ZkMaterialGroup_UNDEFINED; - } - + ZKC_CHECK_NULL(slf); return static_cast(slf->group); } ZkColor ZkMaterial_getColor(ZkMaterial const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMaterial_getColor"); - return {}; - } - + ZKC_CHECK_NULL(slf); return slf->color; } float ZkMaterial_getSmoothAngle(ZkMaterial const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMaterial_getSmoothAngle"); - return 0; - } - + ZKC_CHECK_NULL(slf); return slf->smooth_angle; } ZkString ZkMaterial_getTexture(ZkMaterial const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMaterial_getTexture"); - return nullptr; - } - + ZKC_CHECK_NULL(slf); return slf->texture.c_str(); } ZkVec2f ZkMaterial_getTextureScale(ZkMaterial const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMaterial_getTextureScale"); - return {}; - } - + ZKC_CHECK_NULL(slf); return slf->texture_scale; } float ZkMaterial_getTextureAnimationFps(ZkMaterial const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMaterial_getTextureAnimationFps"); - return 0; - } - + ZKC_CHECK_NULL(slf); return slf->texture_anim_fps; } ZkAnimationMapping ZkMaterial_getTextureAnimationMapping(ZkMaterial const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMaterial_getTextureAnimationMapping"); - return ZkAnimationMapping_NONE; - } - + ZKC_CHECK_NULL(slf); return static_cast(slf->texture_anim_map_mode); } ZkVec2f ZkMaterial_getTextureAnimationMappingDirection(ZkMaterial const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMaterial_getTextureAnimationMappingDirection"); - return {}; - } - + ZKC_CHECK_NULL(slf); return slf->texture_anim_map_dir; } ZkBool ZkMaterial_getDisableCollision(ZkMaterial const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMaterial_getDisableCollision"); - return false; - } - + ZKC_CHECK_NULL(slf); return slf->disable_collision; } ZkBool ZkMaterial_getDisableLightmap(ZkMaterial const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMaterial_getDisableLightmap"); - return false; - } - + ZKC_CHECK_NULL(slf); return slf->disable_lightmap; } ZkBool ZkMaterial_getDontCollapse(ZkMaterial const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMaterial_getDontCollapse"); - return false; - } - + ZKC_CHECK_NULL(slf); return slf->dont_collapse; } ZkString ZkMaterial_getDetailObject(ZkMaterial const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMaterial_getDetailObject"); - return nullptr; - } - + ZKC_CHECK_NULL(slf); return slf->detail_object.c_str(); } float ZkMaterial_getDetailObjectScale(ZkMaterial const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMaterial_getDetailObjectScale"); - return 1; - } - + ZKC_CHECK_NULL(slf); return slf->detail_texture_scale; } ZkBool ZkMaterial_getForceOccluder(ZkMaterial const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMaterial_getForceOccluder"); - return false; - } - + ZKC_CHECK_NULL(slf); return slf->force_occluder; } ZkBool ZkMaterial_getEnvironmentMapping(ZkMaterial const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMaterial_getEnvironmentMapping"); - return false; - } - + ZKC_CHECK_NULL(slf); return slf->environment_mapping; } float ZkMaterial_getEnvironmentMappingStrength(ZkMaterial const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMaterial_getEnvironmentMappingStrength"); - return 0; - } - + ZKC_CHECK_NULL(slf); return slf->environment_mapping_strength; } ZkWaveMode ZkMaterial_getWaveMode(ZkMaterial const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMaterial_getWaveMode"); - return ZkWaveMode_NONE; - } - + ZKC_CHECK_NULL(slf); return static_cast(slf->wave_mode); } ZkWaveSpeed ZkMaterial_getWaveSpeed(ZkMaterial const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMaterial_getWaveSpeed"); - return ZkWaveSpeed_NORMAL; - } - + ZKC_CHECK_NULL(slf); return static_cast(slf->wave_speed); } float ZkMaterial_getWaveAmplitude(ZkMaterial const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMaterial_getWaveAmplitude"); - return 0; - } - + ZKC_CHECK_NULL(slf); return slf->wave_max_amplitude; } float ZkMaterial_getWaveGridSize(ZkMaterial const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMaterial_getWaveGridSize"); - return 1; - } - + ZKC_CHECK_NULL(slf); return slf->wave_grid_size; } ZkBool ZkMaterial_getIgnoreSun(ZkMaterial const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMaterial_getIgnoreSun"); - return false; - } - + ZKC_CHECK_NULL(slf); return slf->ignore_sun; } ZkAlphaFunction ZkMaterial_getAlphaFunction(ZkMaterial const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMaterial_getAlphaFunction"); - return ZkAlphaFunction_DEFAULT; - } - + ZKC_CHECK_NULL(slf); return static_cast(slf->alpha_func); } ZkVec2f ZkMaterial_getDefaultMapping(ZkMaterial const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMaterial_getDefaultMapping"); - return {}; - } - + ZKC_CHECK_NULL(slf); return slf->default_mapping; } diff --git a/src/Mesh.cc b/src/Mesh.cc index a50e345..146aae5 100644 --- a/src/Mesh.cc +++ b/src/Mesh.cc @@ -6,10 +6,7 @@ ZkMesh* ZkMesh_load(ZkRead* buf) { ZKC_TRACE_FN(); - if (buf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMesh_load"); - return nullptr; - } + ZKC_CHECK_NULL(buf); try { ZkMesh obj {}; @@ -23,10 +20,7 @@ ZkMesh* ZkMesh_load(ZkRead* buf) { ZkMesh* ZkMesh_loadPath(ZkString path) { ZKC_TRACE_FN(); - if (path == nullptr) { - ZKC_LOG_WARN_NULL("ZkMesh_loadPath"); - return nullptr; - } + ZKC_CHECK_NULL(path); try { auto buf = zenkit::Read::from(path); @@ -41,10 +35,7 @@ ZkMesh* ZkMesh_loadPath(ZkString path) { } ZkMesh* ZkMesh_loadVfs(ZkVfs* vfs, ZkString name) { ZKC_TRACE_FN(); - if (vfs == nullptr || name == nullptr) { - ZKC_LOG_WARN_NULL("ZkMesh_loadVfs"); - return nullptr; - } + ZKC_CHECK_NULL(vfs, name); auto node = vfs->find(name); if (node == nullptr) return nullptr; @@ -60,75 +51,44 @@ void ZkMesh_del(ZkMesh* slf) { ZkDate ZkMesh_getSourceDate(ZkMesh const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMesh_getSourceDate"); - return {}; - } - + ZKC_CHECK_NULL(slf); return slf->date; } ZkString ZkMesh_getName(ZkMesh const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMesh_getName"); - return nullptr; - } - + ZKC_CHECK_NULL(slf); return slf->name.c_str(); } ZkAxisAlignedBoundingBox ZkMesh_getBoundingBox(ZkMesh const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMesh_getBoundingBox"); - return {}; - } - + ZKC_CHECK_NULL(slf); return slf->bbox; } ZkOrientedBoundingBox const* ZkMesh_getOrientedBoundingBox(ZkMesh const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMesh_getOrientedBoundingBox"); - return nullptr; - } - + ZKC_CHECK_NULL(slf); return &slf->obb; } ZkSize ZkMesh_getMaterialCount(ZkMesh const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMesh_getMaterialCount"); - return 0; - } - + ZKC_CHECK_NULL(slf); return slf->materials.size(); } ZkMaterial const* ZkMesh_getMaterial(ZkMesh const* slf, ZkSize i) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMesh_getMaterial"); - return nullptr; - } - - if (i >= slf->materials.size()) { - ZKC_LOG_ERROR("ZkMesh_getMaterial() failed: index out of range"); - return nullptr; - } - + ZKC_CHECK_NULL(slf); + ZKC_CHECK_LEN(slf->materials, i); return &slf->materials[i]; } void ZkMesh_enumerateMaterials(ZkMesh const* slf, ZkMaterialEnumerator cb, void* ctx) { ZKC_TRACE_FN(); - if (slf == nullptr || cb == nullptr) { - ZKC_LOG_WARN_NULL("ZkMesh_enumerateMaterials"); - return; - } + ZKC_CHECK_NULLV(slf, cb); for (auto& mesh : slf->materials) { if (cb(ctx, &mesh)) break; @@ -183,35 +143,20 @@ void ZkMesh_enumerateVertices(ZkMesh const* slf, ZkVertexEnumerator cb, void* ct ZkSize ZkMesh_getLightMapCount(ZkMesh const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMesh_getLightMapCount"); - return 0; - } - + ZKC_CHECK_NULL(slf); return slf->lightmaps.size(); } ZkLightMap const* ZkMesh_getLightMap(ZkMesh const* slf, ZkSize i) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMesh_getLightMap"); - return nullptr; - } - - if (i >= slf->lightmaps.size()) { - ZKC_LOG_ERROR("ZkMesh_getLightMap() failed: index out of range"); - return nullptr; - } - + ZKC_CHECK_NULL(slf); + ZKC_CHECK_LEN(slf->lightmaps, i); return &slf->lightmaps[i]; } void ZkMesh_enumerateLightMaps(ZkMesh const* slf, ZkLightMapEnumerator cb, void* ctx) { ZKC_TRACE_FN(); - if (slf == nullptr || cb == nullptr) { - ZKC_LOG_WARN_NULL("ZkMesh_enumerateLightMaps"); - return; - } + ZKC_CHECK_NULLV(slf, cb); for (auto& lm : slf->lightmaps) { if (cb(ctx, &lm)) break; @@ -220,35 +165,20 @@ void ZkMesh_enumerateLightMaps(ZkMesh const* slf, ZkLightMapEnumerator cb, void* ZkSize ZkMesh_getPolygonCount(ZkMesh const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMesh_getPolygonCount"); - return 0; - } - + ZKC_CHECK_NULL(slf); return slf->geometry.size(); } ZkPolygon const* ZkMesh_getPolygon(ZkMesh const* slf, ZkSize i) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMesh_getPolygon"); - return nullptr; - } - - if (i >= slf->geometry.size()) { - ZKC_LOG_ERROR("ZkMesh_getPolygon() failed: index out of range"); - return nullptr; - } - + ZKC_CHECK_NULL(slf); + ZKC_CHECK_LEN(slf->geometry, i); return &slf->geometry[i]; } void ZkMesh_enumeratePolygons(ZkMesh const* slf, ZkPolygonEnumerator cb, void* ctx) { ZKC_TRACE_FN(); - if (slf == nullptr || cb == nullptr) { - ZKC_LOG_WARN_NULL("ZkMesh_enumeratePolygons"); - return; - } + ZKC_CHECK_NULLV(slf, cb); for (auto& poly : slf->geometry) { if (cb(ctx, &poly)) break; @@ -257,65 +187,38 @@ void ZkMesh_enumeratePolygons(ZkMesh const* slf, ZkPolygonEnumerator cb, void* c ZkTexture const* ZkLightMap_getImage(ZkLightMap const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkLightMap_getImage"); - return nullptr; - } - + ZKC_CHECK_NULL(slf); return slf->image.get(); } ZkVec3f ZkLightMap_getOrigin(ZkLightMap const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkLightMap_getOrigin"); - return {}; - } - + ZKC_CHECK_NULL(slf); return slf->origin; } ZkVec3f ZkLightMap_getNormal(ZkLightMap const* slf, ZkSize i) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkLightMap_getNormal"); - return {}; - } - - if (i >= 2) { - ZKC_LOG_ERROR("ZkLightMap_getNormal() failed: index out of range"); - return {}; - } - + ZKC_CHECK_NULL(slf); + ZKC_CHECK_LENA(2, i); return slf->normals[i]; } uint32_t ZkPolygon_getMaterialIndex(ZkPolygon const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkPolygon_getMaterialIndex"); - return {}; - } - + ZKC_CHECK_NULL(slf); return slf->material; } int32_t ZkPolygon_getLightMapIndex(ZkPolygon const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkPolygon_getLightMapIndex"); - return {}; - } - + ZKC_CHECK_NULL(slf); return slf->lightmap; } uint32_t const* ZkPolygon_getPositionIndices(ZkPolygon const* slf, ZkSize* count) { ZKC_TRACE_FN(); - if (slf == nullptr || count == nullptr) { - ZKC_LOG_WARN_NULL("ZkPolygon_getPositionIndices"); - return {}; - } + ZKC_CHECK_NULL(slf, count); *count = slf->vertices.size(); return slf->vertices.data(); @@ -323,10 +226,7 @@ uint32_t const* ZkPolygon_getPositionIndices(ZkPolygon const* slf, ZkSize* count uint32_t const* ZkPolygon_getFeatureIndices(ZkPolygon const* slf, ZkSize* count) { ZKC_TRACE_FN(); - if (slf == nullptr || count == nullptr) { - ZKC_LOG_WARN_NULL("ZkPolygon_getFeatureIndices"); - return {}; - } + ZKC_CHECK_NULL(slf, count); *count = slf->features.size(); return slf->features.data(); @@ -334,100 +234,60 @@ uint32_t const* ZkPolygon_getFeatureIndices(ZkPolygon const* slf, ZkSize* count) ZkBool ZkPolygon_getIsPortal(ZkPolygon const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkPolygon_getIsPortal"); - return {}; - } - + ZKC_CHECK_NULL(slf); return slf->flags.is_portal; } ZkBool ZkPolygon_getIsOccluder(ZkPolygon const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkPolygon_getIsOccluder"); - return {}; - } - + ZKC_CHECK_NULL(slf); return slf->flags.is_occluder; } ZkBool ZkPolygon_getIsSector(ZkPolygon const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkPolygon_getIsSector"); - return {}; - } - + ZKC_CHECK_NULL(slf); return slf->flags.is_sector; } ZkBool ZkPolygon_getShouldRelight(ZkPolygon const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkPolygon_getShouldRelight"); - return {}; - } - + ZKC_CHECK_NULL(slf); return slf->flags.should_relight; } ZkBool ZkPolygon_getIsOutdoor(ZkPolygon const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkPolygon_getIsOutdoor"); - return {}; - } - + ZKC_CHECK_NULL(slf); return slf->flags.is_outdoor; } ZkBool ZkPolygon_getIsGhostOccluder(ZkPolygon const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkPolygon_getIsGhostOccluder"); - return {}; - } - + ZKC_CHECK_NULL(slf); return slf->flags.is_ghost_occluder; } ZkBool ZkPolygon_getIsDynamicallyLit(ZkPolygon const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkPolygon_getIsDynamicallyLit"); - return {}; - } - + ZKC_CHECK_NULL(slf); return slf->flags.is_dynamically_lit; } ZkBool ZkPolygon_getIsLod(ZkPolygon const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkPolygon_getIsLod"); - return {}; - } - + ZKC_CHECK_NULL(slf); return slf->flags.is_lod; } uint8_t ZkPolygon_getNormalAxis(ZkPolygon const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkPolygon_getNormalAxis"); - return {}; - } - + ZKC_CHECK_NULL(slf); return slf->flags.normal_axis; } int16_t ZkPolygon_getSectorIndex(ZkPolygon const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkPolygon_getSectorIndex"); - return {}; - } - + ZKC_CHECK_NULL(slf); return slf->flags.sector_index; } diff --git a/src/Model.cc b/src/Model.cc index f2ad5ec..4ad54cd 100644 --- a/src/Model.cc +++ b/src/Model.cc @@ -4,77 +4,19 @@ #include "Internal.hh" -ZkModel* ZkModel_load(ZkRead* buf) { - ZKC_TRACE_FN(); - if (buf == nullptr) { - ZKC_LOG_WARN_NULL("ZkModel_load"); - return nullptr; - } - - try { - ZkModel obj {}; - obj.load(buf); - return ZKC_WRAP_NEW(obj); - } catch (std::exception const& exc) { - ZKC_LOG_ERROR("ZkModel_load() failed: %s", exc.what()); - return nullptr; - } -} - -ZkModel* ZkModel_loadPath(ZkString path) { - ZKC_TRACE_FN(); - if (path == nullptr) { - ZKC_LOG_WARN_NULL("ZkModel_loadPath"); - return nullptr; - } - - try { - auto buf = zenkit::Read::from(path); - - ZkModel obj {}; - obj.load(buf.get()); - return ZKC_WRAP_NEW(obj); - } catch (std::exception const& exc) { - ZKC_LOG_ERROR("ZkModel_loadPath() failed: %s", exc.what()); - return nullptr; - } -} - -ZkModel* ZkModel_loadVfs(ZkVfs* vfs, ZkString name) { - ZKC_TRACE_FN(); - if (vfs == nullptr || name == nullptr) { - ZKC_LOG_WARN_NULL("ZkModel_loadVfs"); - return nullptr; - } - - auto node = vfs->find(name); - if (node == nullptr) return nullptr; - - auto rd = node->open_read(); - return ZkModel_load(rd.get()); -} - -void ZkModel_del(ZkModel* slf) { - ZKC_TRACE_FN(); - delete slf; -} +ZKC_LOADER(ZkModel); +ZKC_PATH_LOADER(ZkModel); +ZKC_VFS_LOADER(ZkModel); +ZKC_DELETER(ZkModel); ZkModelHierarchy const* ZkModel_getHierarchy(ZkModel const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkModel_getHierarchy"); - return nullptr; - } - + ZKC_CHECK_NULL(slf); return &slf->hierarchy; } ZkModelMesh const* ZkModel_getMesh(ZkModel const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkModel_getMesh"); - return nullptr; - } - + ZKC_CHECK_NULL(slf); return &slf->mesh; } diff --git a/src/ModelAnimation.cc b/src/ModelAnimation.cc index 176f6d3..4b3ff8b 100644 --- a/src/ModelAnimation.cc +++ b/src/ModelAnimation.cc @@ -4,212 +4,99 @@ #include "Internal.hh" -ZkModelAnimation* ZkModelAnimation_load(ZkRead* buf) { - ZKC_TRACE_FN(); - if (buf == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelAnimation_load"); - return nullptr; - } - - try { - ZkModelAnimation obj {}; - obj.load(buf); - return ZKC_WRAP_NEW(obj); - } catch (std::exception const& exc) { - ZKC_LOG_ERROR("ZkModelAnimation_load() failed: %s", exc.what()); - return nullptr; - } -} - -ZkModelAnimation* ZkModelAnimation_loadPath(ZkString path) { - ZKC_TRACE_FN(); - if (path == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelAnimation_loadPath"); - return nullptr; - } - - try { - auto buf = zenkit::Read::from(path); - - ZkModelAnimation obj {}; - obj.load(buf.get()); - return ZKC_WRAP_NEW(obj); - } catch (std::exception const& exc) { - ZKC_LOG_ERROR("ZkModelAnimation_loadPath() failed: %s", exc.what()); - return nullptr; - } -} - -ZkModelAnimation* ZkModelAnimation_loadVfs(ZkVfs* vfs, ZkString name) { - ZKC_TRACE_FN(); - if (vfs == nullptr || name == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelAnimation_loadVfs"); - return nullptr; - } - - auto node = vfs->find(name); - if (node == nullptr) return nullptr; - - auto rd = node->open_read(); - return ZkModelAnimation_load(rd.get()); -} - -void ZkModelAnimation_del(ZkModelAnimation* slf) { - ZKC_TRACE_FN(); - delete slf; -} +ZKC_LOADER(ZkModelAnimation); +ZKC_PATH_LOADER(ZkModelAnimation); +ZKC_VFS_LOADER(ZkModelAnimation); +ZKC_DELETER(ZkModelAnimation); ZkString ZkModelAnimation_getName(ZkModelAnimation const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelAnimation_getName"); - return nullptr; - } - + ZKC_CHECK_NULL(slf); return slf->name.c_str(); } ZkString ZkModelAnimation_getNext(ZkModelAnimation const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelAnimation_getNext"); - return nullptr; - } - + ZKC_CHECK_NULL(slf); return slf->next.c_str(); } uint32_t ZkModelAnimation_getLayer(ZkModelAnimation const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelAnimation_getLayer"); - return 0; - } - + ZKC_CHECK_NULL(slf); return slf->layer; } uint32_t ZkModelAnimation_getFrameCount(ZkModelAnimation const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelAnimation_getFrameCount"); - return 0; - } - + ZKC_CHECK_NULL(slf); return slf->frame_count; } uint32_t ZkModelAnimation_getNodeCount(ZkModelAnimation const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelAnimation_getNodeCount"); - return 0; - } - + ZKC_CHECK_NULL(slf); return slf->node_count; } float ZkModelAnimation_getFps(ZkModelAnimation const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelAnimation_getFps"); - return 0; - } - + ZKC_CHECK_NULL(slf); return slf->fps; } float ZkModelAnimation_getFpsSource(ZkModelAnimation const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelAnimation_getFpsSource"); - return 0; - } - + ZKC_CHECK_NULL(slf); return slf->fps_source; } ZkAxisAlignedBoundingBox ZkModelAnimation_getBbox(ZkModelAnimation const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelAnimation_getBbox"); - return {}; - } - + ZKC_CHECK_NULL(slf); return slf->bbox; } uint32_t ZkModelAnimation_getChecksum(ZkModelAnimation const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelAnimation_getChecksum"); - return 0; - } - + ZKC_CHECK_NULL(slf); return slf->checksum; } ZkString ZkModelAnimation_getSourcePath(ZkModelAnimation const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelAnimation_getSourcePath"); - return nullptr; - } - + ZKC_CHECK_NULL(slf); return slf->source_path.c_str(); } ZkDate ZkModelAnimation_getSourceDate(ZkModelAnimation const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelAnimation_getSourceDate"); - return {}; - } - + ZKC_CHECK_NULL(slf); return slf->source_date; } ZkString ZkModelAnimation_getSourceScript(ZkModelAnimation const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelAnimation_getSourceScript"); - return nullptr; - } - + ZKC_CHECK_NULL(slf); return slf->source_script.c_str(); } ZkSize ZkModelAnimation_getSampleCount(ZkModelAnimation const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelAnimation_getSampleCount"); - return 0; - } - + ZKC_CHECK_NULL(slf); return slf->samples.size(); } ZkAnimationSample ZkModelAnimation_getSample(ZkModelAnimation const* slf, ZkSize i) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelAnimation_getSample"); - return {}; - } - - if (i >= slf->samples.size()) { - ZKC_LOG_ERROR("ZkModelAnimation_getSample() failed: index out of range"); - return {}; - } - + ZKC_CHECK_NULL(slf); + ZKC_CHECK_LEN(slf->samples, i); return slf->samples[i]; } void ZkModelAnimation_enumerateSamples(ZkModelAnimation const* slf, ZkAnimationSampleEnumerator cb, void* ctx) { ZKC_TRACE_FN(); - if (slf == nullptr || cb == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelAnimation_enumerateSamples"); - return; - } + ZKC_CHECK_NULLV(slf, cb); ZkAnimationSample as {}; for (auto& sample : slf->samples) { @@ -222,12 +109,7 @@ void ZkModelAnimation_enumerateSamples(ZkModelAnimation const* slf, ZkAnimationS uint32_t const* ZkModelAnimation_getNodeIndices(ZkModelAnimation const* slf, ZkSize* length) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelAnimation_getNodeIndices"); - - if (length != nullptr) *length = 0; - return nullptr; - } + ZKC_CHECK_NULL(slf, length); if (length != nullptr) *length = slf->node_indices.size(); return slf->node_indices.data(); diff --git a/src/ModelHierarchy.cc b/src/ModelHierarchy.cc index e908150..79d9ae9 100644 --- a/src/ModelHierarchy.cc +++ b/src/ModelHierarchy.cc @@ -4,82 +4,21 @@ #include "Internal.hh" -ZkModelHierarchy* ZkModelHierarchy_load(ZkRead* buf) { - ZKC_TRACE_FN(); - if (buf == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelHierarchy_load"); - return nullptr; - } - - try { - ZkModelHierarchy obj {}; - obj.load(buf); - return ZKC_WRAP_NEW(obj); - } catch (std::exception const& exc) { - ZKC_LOG_ERROR("ZkModelHierarchy_load() failed: %s", exc.what()); - return nullptr; - } -} - -ZkModelHierarchy* ZkModelHierarchy_loadPath(ZkString path) { - ZKC_TRACE_FN(); - if (path == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelHierarchy_loadPath"); - return nullptr; - } - - try { - auto buf = zenkit::Read::from(path); - - ZkModelHierarchy obj {}; - obj.load(buf.get()); - return ZKC_WRAP_NEW(obj); - } catch (std::exception const& exc) { - ZKC_LOG_ERROR("ZkModelHierarchy_loadPath() failed: %s", exc.what()); - return nullptr; - } -} - -ZkModelHierarchy* ZkModelHierarchy_loadVfs(ZkVfs* vfs, ZkString name) { - ZKC_TRACE_FN(); - if (vfs == nullptr || name == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelHierarchy_loadVfs"); - return nullptr; - } - - auto node = vfs->find(name); - if (node == nullptr) return nullptr; - - auto rd = node->open_read(); - return ZkModelHierarchy_load(rd.get()); -} - -void ZkModelHierarchy_del(ZkModelHierarchy* slf) { - ZKC_TRACE_FN(); - delete slf; -} +ZKC_LOADER(ZkModelHierarchy); +ZKC_PATH_LOADER(ZkModelHierarchy); +ZKC_VFS_LOADER(ZkModelHierarchy); +ZKC_DELETER(ZkModelHierarchy); ZkSize ZkModelHierarchy_getNodeCount(ZkModelHierarchy const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelHierarchy_getNodeCount"); - return 0; - } - + ZKC_CHECK_NULL(slf); return slf->nodes.size(); } ZkModelHierarchyNode ZkModelHierarchy_getNode(ZkModelHierarchy const* slf, ZkSize i) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelHierarchy_getNode"); - return {}; - } - - if (i >= slf->nodes.size()) { - ZKC_LOG_ERROR("ZkModelHierarchy_getNode() failed: index out of range"); - return {}; - } + ZKC_CHECK_NULL(slf); + ZKC_CHECK_LEN(slf->nodes, i); return ZkModelHierarchyNode { slf->nodes[i].parent_index, @@ -90,70 +29,43 @@ ZkModelHierarchyNode ZkModelHierarchy_getNode(ZkModelHierarchy const* slf, ZkSiz ZkAxisAlignedBoundingBox ZkModelHierarchy_getBbox(ZkModelHierarchy const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelHierarchy_getBbox"); - return {}; - } - + ZKC_CHECK_NULL(slf); return slf->bbox; } ZkAxisAlignedBoundingBox ZkModelHierarchy_getCollisionBbox(ZkModelHierarchy const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelHierarchy_getCollisionBbox"); - return {}; - } - + ZKC_CHECK_NULL(slf); return slf->collision_bbox; } ZkVec3f ZkModelHierarchy_getRootTranslation(ZkModelHierarchy const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelHierarchy_getRootTranslation"); - return {}; - } - + ZKC_CHECK_NULL(slf); return slf->root_translation; } uint32_t ZkModelHierarchy_getChecksum(ZkModelHierarchy const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelHierarchy_getChecksum"); - return {}; - } - + ZKC_CHECK_NULL(slf); return slf->checksum; } ZkDate ZkModelHierarchy_getSourceDate(ZkModelHierarchy const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelHierarchy_getSourceDate"); - return {}; - } - + ZKC_CHECK_NULL(slf); return slf->source_date; } ZkString ZkModelHierarchy_getSourcePath(ZkModelHierarchy const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelHierarchy_getSourcePath"); - return {}; - } - + ZKC_CHECK_NULL(slf); return slf->source_path.c_str(); } void ZkModelHierarchy_enumerateNodes(ZkModelHierarchy const* slf, ZkModelHierarchyNodeEnumerator cb, void* ctx) { ZKC_TRACE_FN(); - if (slf == nullptr || cb == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelHierarchy_enumerateNodes"); - return; - } + ZKC_CHECK_NULLV(slf, cb); ZkModelHierarchyNode n; for (auto& node : slf->nodes) { diff --git a/src/ModelMesh.cc b/src/ModelMesh.cc index 9658470..209f015 100644 --- a/src/ModelMesh.cc +++ b/src/ModelMesh.cc @@ -4,92 +4,27 @@ #include "Internal.hh" -ZkModelMesh* ZkModelMesh_load(ZkRead* buf) { - ZKC_TRACE_FN(); - if (buf == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelMesh_load"); - return nullptr; - } - - try { - ZkModelMesh obj {}; - obj.load(buf); - return ZKC_WRAP_NEW(obj); - } catch (std::exception const& exc) { - ZKC_LOG_ERROR("ZkModelMesh_load() failed: %s", exc.what()); - return nullptr; - } -} - -ZkModelMesh* ZkModelMesh_loadPath(ZkString path) { - ZKC_TRACE_FN(); - if (path == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelMesh_loadPath"); - return nullptr; - } - - try { - auto buf = zenkit::Read::from(path); - - ZkModelMesh obj {}; - obj.load(buf.get()); - return ZKC_WRAP_NEW(obj); - } catch (std::exception const& exc) { - ZKC_LOG_ERROR("ZkModelMesh_loadPath() failed: %s", exc.what()); - return nullptr; - } -} - -ZkModelMesh* ZkModelMesh_loadVfs(ZkVfs* vfs, ZkString name) { - ZKC_TRACE_FN(); - if (vfs == nullptr || name == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelMesh_loadVfs"); - return nullptr; - } - - auto node = vfs->find(name); - if (node == nullptr) return nullptr; - - auto rd = node->open_read(); - return ZkModelMesh_load(rd.get()); -} - -void ZkModelMesh_del(ZkModelMesh* slf) { - ZKC_TRACE_FN(); - delete slf; -} +ZKC_LOADER(ZkModelMesh); +ZKC_PATH_LOADER(ZkModelMesh); +ZKC_VFS_LOADER(ZkModelMesh); +ZKC_DELETER(ZkModelMesh); ZkSize ZkModelMesh_getMeshCount(ZkModelMesh const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelMesh_getMeshCount"); - return 0; - } - + ZKC_CHECK_NULL(slf); return slf->meshes.size(); } ZkSoftSkinMesh const* ZkModelMesh_getMesh(ZkModelMesh const* slf, ZkSize i) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelMesh_getMesh"); - return nullptr; - } - - if (i >= slf->meshes.size()) { - ZKC_LOG_ERROR("ZkModelMesh_getMesh() failed: index out of range"); - return nullptr; - } - + ZKC_CHECK_NULL(slf); + ZKC_CHECK_LEN(slf->meshes, i); return &slf->meshes[i]; } void ZkModelMesh_enumerateMeshes(ZkModelMesh const* slf, ZkSoftSkinMeshEnumerator cb, void* ctx) { ZKC_TRACE_FN(); - if (slf == nullptr || cb == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelMesh_enumerateMeshes"); - return; - } + ZKC_CHECK_NULLV(slf, cb); for (auto& mesh : slf->meshes) { if (cb(ctx, &mesh)) break; @@ -98,20 +33,13 @@ void ZkModelMesh_enumerateMeshes(ZkModelMesh const* slf, ZkSoftSkinMeshEnumerato ZkSize ZkModelMesh_getAttachmentCount(ZkModelMesh const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelMesh_getAttachmentCount"); - return 0; - } - + ZKC_CHECK_NULL(slf); return slf->attachments.size(); } ZkMultiResolutionMesh const* ZkModelMesh_getAttachment(ZkModelMesh const* slf, ZkString name) { ZKC_TRACE_FN(); - if (slf == nullptr || name == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelMesh_getAttachment"); - return nullptr; - } + ZKC_CHECK_NULL(slf, name); auto it = slf->attachments.find(name); if (it == slf->attachments.end()) return nullptr; @@ -120,10 +48,7 @@ ZkMultiResolutionMesh const* ZkModelMesh_getAttachment(ZkModelMesh const* slf, Z void ZkModelMesh_enumerateAttachments(ZkModelMesh const* slf, ZkAttachmentEnumerator cb, void* ctx) { ZKC_TRACE_FN(); - if (slf == nullptr || cb == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelMesh_enumerateAttachments"); - return; - } + ZKC_CHECK_NULLV(slf, cb); for (auto& [name, mesh] : slf->attachments) { if (cb(ctx, name.c_str(), &mesh)) break; @@ -132,10 +57,6 @@ void ZkModelMesh_enumerateAttachments(ZkModelMesh const* slf, ZkAttachmentEnumer uint32_t ZkModelMesh_getChecksum(ZkModelMesh const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelMesh_getChecksum"); - return 0; - } - + ZKC_CHECK_NULL(slf); return slf->checksum; } diff --git a/src/ModelScript.cc b/src/ModelScript.cc index dc1028f..86d35fd 100644 --- a/src/ModelScript.cc +++ b/src/ModelScript.cc @@ -2,241 +2,119 @@ // SPDX-License-Identifier: MIT #include "zenkit-capi/ModelScript.h" -ZkModelScript* ZkModelScript_load(ZkRead* buf) { - if (buf == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelScript_load"); - return nullptr; - } - - try { - ZkModelScript obj {}; - obj.load(buf); - return ZKC_WRAP_NEW(obj); - } catch (std::exception const& exc) { - ZKC_LOG_ERROR("ZkModelScript_load() failed: %s", exc.what()); - return nullptr; - } -} - -ZkModelScript* ZkModelScript_loadPath(ZkString path) { - if (path == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelScript_loadPath"); - return nullptr; - } - - try { - auto buf = zenkit::Read::from(path); - - ZkModelScript obj {}; - obj.load(buf.get()); - return ZKC_WRAP_NEW(obj); - } catch (std::exception const& exc) { - ZKC_LOG_ERROR("ZkModelScript_loadPath() failed: %s", exc.what()); - return nullptr; - } -} - -ZkModelScript* ZkModelScript_loadVfs(ZkVfs* vfs, ZkString name) { - if (vfs == nullptr || name == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelScript_loadVfs"); - return nullptr; - } +#include "Internal.hh" - auto node = vfs->find(name); - if (node == nullptr) return nullptr; - - auto rd = node->open_read(); - return ZkModelScript_load(rd.get()); -} - -void ZkModelScript_del(ZkModelScript* slf) { - delete slf; -} +ZKC_LOADER(ZkModelScript); +ZKC_PATH_LOADER(ZkModelScript); +ZKC_VFS_LOADER(ZkModelScript); +ZKC_DELETER(ZkModelScript); ZkString ZkModelScript_getSkeletonName(ZkModelScript const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelScript_getSkeletonName"); - return nullptr; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->skeleton.name.c_str(); } ZkBool ZkModelScript_getSkeletonMeshDisabled(ZkModelScript const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelScript_getSkeletonMeshDisabled"); - return false; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->skeleton.disable_mesh; } ZkSize ZkModelScript_getMeshCount(ZkModelScript const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelScript_getMeshCount"); - return 0; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->meshes.size(); } ZkSize ZkModelScript_getDisabledAnimationsCount(ZkModelScript const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelScript_getDisabledAnimationsCount"); - return 0; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->disabled_animations.size(); } ZkSize ZkModelScript_getAnimationCombineCount(ZkModelScript const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelScript_getAnimationCombineCount"); - return 0; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->combinations.size(); } ZkSize ZkModelScript_getAnimationBlendCount(ZkModelScript const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelScript_getAnimationBlendCount"); - return 0; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->blends.size(); } ZkSize ZkModelScript_getAnimationAliasCount(ZkModelScript const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelScript_getAnimationAliasCount"); - return 0; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->aliases.size(); } ZkSize ZkModelScript_getModelTagCount(ZkModelScript const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelScript_getModelTagCount"); - return 0; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->model_tags.size(); } ZkSize ZkModelScript_getAnimationCount(ZkModelScript const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelScript_getAnimationCount"); - return 0; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->animations.size(); } ZkString ZkModelScript_getDisabledAnimation(ZkModelScript const* slf, ZkSize i) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelScript_getDisabledAnimation"); - return nullptr; - } - - if (i >= slf->disabled_animations.size()) { - ZKC_LOG_ERROR("ZkModelScript_getDisabledAnimation() failed: index out of bounds"); - return nullptr; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); + ZKC_CHECK_LEN(slf->disabled_animations, i); return slf->disabled_animations[i].c_str(); } ZkString ZkModelScript_getMesh(ZkModelScript const* slf, ZkSize i) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelScript_getMesh"); - return nullptr; - } - - if (i >= slf->meshes.size()) { - ZKC_LOG_ERROR("ZkModelScript_getMesh() failed: index out of bounds"); - return nullptr; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); + ZKC_CHECK_LEN(slf->meshes, i); return slf->meshes[i].c_str(); } ZkAnimationCombine const* ZkModelScript_getAnimationCombine(ZkModelScript const* slf, ZkSize i) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelScript_getAnimationCombine"); - return nullptr; - } - - if (i >= slf->combinations.size()) { - ZKC_LOG_ERROR("ZkModelScript_getAnimationCombine() failed: index out of bounds"); - return nullptr; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); + ZKC_CHECK_LEN(slf->combinations, i); return &slf->combinations[i]; } ZkAnimationBlend const* ZkModelScript_getAnimationBlend(ZkModelScript const* slf, ZkSize i) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelScript_getAnimationBlend"); - return nullptr; - } - - if (i >= slf->blends.size()) { - ZKC_LOG_ERROR("ZkModelScript_getAnimationBlend() failed: index out of bounds"); - return nullptr; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); + ZKC_CHECK_LEN(slf->blends, i); return &slf->blends[i]; } ZkAnimationAlias const* ZkModelScript_getAnimationAlias(ZkModelScript const* slf, ZkSize i) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelScript_getAnimationAlias"); - return nullptr; - } - - if (i >= slf->aliases.size()) { - ZKC_LOG_ERROR("ZkModelScript_getAnimationAlias() failed: index out of bounds"); - return nullptr; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); + ZKC_CHECK_LEN(slf->aliases, i); return &slf->aliases[i]; } ZkString ZkModelScript_getModelTag(ZkModelScript const* slf, ZkSize i) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelScript_getModelTag"); - return nullptr; - } - - if (i >= slf->model_tags.size()) { - ZKC_LOG_ERROR("ZkModelScript_getModelTag() failed: index out of bounds"); - return nullptr; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); + ZKC_CHECK_LEN(slf->model_tags, i); return slf->model_tags[i].bone.c_str(); } ZkAnimation const* ZkModelScript_getAnimation(ZkModelScript const* slf, ZkSize i) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelScript_getAnimation"); - return nullptr; - } - - if (i >= slf->animations.size()) { - ZKC_LOG_ERROR("ZkModelScript_getAnimation() failed: index out of bounds"); - return nullptr; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); + ZKC_CHECK_LEN(slf->animations, i); return &slf->animations[i]; } void ZkModelScript_enumerateAnimationCombines(ZkModelScript const* slf, ZkAnimationCombineEnumerator cb, void* ctx) { - if (slf == nullptr || cb == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelScript_enumerateAnimationCombines"); - return; - } + ZKC_TRACE_FN(); + ZKC_CHECK_NULLV(slf, cb); for (auto& v : slf->combinations) { if (cb(ctx, &v)) break; @@ -244,10 +122,8 @@ void ZkModelScript_enumerateAnimationCombines(ZkModelScript const* slf, ZkAnimat } void ZkModelScript_enumerateMeshes(ZkModelScript const* slf, ZkStringEnumerator cb, void* ctx) { - if (slf == nullptr || cb == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelScript_enumerateMeshes"); - return; - } + ZKC_TRACE_FN(); + ZKC_CHECK_NULLV(slf, cb); for (auto& v : slf->meshes) { if (cb(ctx, v.c_str())) break; @@ -255,10 +131,8 @@ void ZkModelScript_enumerateMeshes(ZkModelScript const* slf, ZkStringEnumerator } void ZkModelScript_enumerateDisabledAnimations(ZkModelScript const* slf, ZkStringEnumerator cb, void* ctx) { - if (slf == nullptr || cb == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelScript_enumerateDisabledAnimations"); - return; - } + ZKC_TRACE_FN(); + ZKC_CHECK_NULLV(slf, cb); for (auto& v : slf->disabled_animations) { if (cb(ctx, v.c_str())) break; @@ -266,10 +140,8 @@ void ZkModelScript_enumerateDisabledAnimations(ZkModelScript const* slf, ZkStrin } void ZkModelScript_enumerateAnimationBlends(ZkModelScript const* slf, ZkAnimationBlendEnumerator cb, void* ctx) { - if (slf == nullptr || cb == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelScript_enumerateAnimationBlends"); - return; - } + ZKC_TRACE_FN(); + ZKC_CHECK_NULLV(slf, cb); for (auto& v : slf->blends) { if (cb(ctx, &v)) break; @@ -277,10 +149,8 @@ void ZkModelScript_enumerateAnimationBlends(ZkModelScript const* slf, ZkAnimatio } void ZkModelScript_enumerateAnimationAliases(ZkModelScript const* slf, ZkAnimationAliasEnumerator cb, void* ctx) { - if (slf == nullptr || cb == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelScript_enumerateAnimationAliases"); - return; - } + ZKC_TRACE_FN(); + ZKC_CHECK_NULLV(slf, cb); for (auto& v : slf->aliases) { if (cb(ctx, &v)) break; @@ -288,10 +158,8 @@ void ZkModelScript_enumerateAnimationAliases(ZkModelScript const* slf, ZkAnimati } void ZkModelScript_enumerateModelTags(ZkModelScript const* slf, ZkStringEnumerator cb, void* ctx) { - if (slf == nullptr || cb == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelScript_enumerateModelTags"); - return; - } + ZKC_TRACE_FN(); + ZKC_CHECK_NULLV(slf, cb); for (auto& v : slf->model_tags) { if (cb(ctx, v.bone.c_str())) break; @@ -299,10 +167,8 @@ void ZkModelScript_enumerateModelTags(ZkModelScript const* slf, ZkStringEnumerat } void ZkModelScript_enumerateAnimations(ZkModelScript const* slf, ZkAnimationEnumerator cb, void* ctx) { - if (slf == nullptr || cb == nullptr) { - ZKC_LOG_WARN_NULL("ZkModelScript_enumerateAnimations"); - return; - } + ZKC_TRACE_FN(); + ZKC_CHECK_NULLV(slf, cb); for (auto& v : slf->animations) { if (cb(ctx, &v)) break; @@ -312,288 +178,177 @@ void ZkModelScript_enumerateAnimations(ZkModelScript const* slf, ZkAnimationEnum // ZkAnimation ZkString ZkAnimation_getName(ZkAnimation const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkAnimation_getName"); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->name.c_str(); } uint32_t ZkAnimation_getLayer(ZkAnimation const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkAnimation_getLayer"); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->layer; } ZkString ZkAnimation_getNext(ZkAnimation const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkAnimation_getNext"); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->next.c_str(); } float ZkAnimation_getBlendIn(ZkAnimation const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkAnimation_getBlendIn"); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->blend_in; } float ZkAnimation_getBlendOut(ZkAnimation const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkAnimation_getBlendOut"); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->blend_out; } ZkAnimationFlag ZkAnimation_getFlags(ZkAnimation const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkAnimation_getFlags"); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return static_cast(slf->flags); } ZkString ZkAnimation_getModel(ZkAnimation const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkAnimation_getModel"); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->model.c_str(); } ZkAnimationDirection ZkAnimation_getDirection(ZkAnimation const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkAnimation_getDirection"); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return static_cast(slf->direction); } int32_t ZkAnimation_getFirstFrame(ZkAnimation const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkAnimation_getFirstFrame"); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->first_frame; } int32_t ZkAnimation_getLastFrame(ZkAnimation const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkAnimation_getLastFrame"); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->last_frame; } float ZkAnimation_getFps(ZkAnimation const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkAnimation"); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->fps; } float ZkAnimation_getSpeed(ZkAnimation const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("("); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->speed; } float ZkAnimation_getCollisionVolumeScale(ZkAnimation const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkAnimation_getCollisionVolumeScale"); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->collision_volume_scale; } ZkSize ZkAnimation_getEventTagCount(ZkAnimation const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkAnimation_getEventCountTag"); - return 0; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->events.size(); } ZkSize ZkAnimation_getParticleEffectCount(ZkAnimation const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkAnimation_getParticleEffectCount"); - return 0; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->pfx.size(); } ZkSize ZkAnimation_getParticleEffectStopCount(ZkAnimation const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkAnimation_getParticleEffectStopCount"); - return 0; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->pfx_stop.size(); } ZkSize ZkAnimation_getSoundEffectCount(ZkAnimation const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkAnimation_getSoundEffectCount"); - return 0; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->sfx.size(); } ZkSize ZkAnimation_getSoundEffectGroundCount(ZkAnimation const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkAnimation_getSoundEffectGroundCount"); - return 0; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->sfx_ground.size(); } ZkSize ZkAnimation_getMorphAnimationCount(ZkAnimation const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkAnimation_getMorphAnimationCount"); - return 0; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->morph.size(); } ZkSize ZkAnimation_getCameraTremorCount(ZkAnimation const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkAnimation_getCameraTremorCount"); - return 0; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->tremors.size(); } ZkEventTag const* ZkAnimation_getEventTag(ZkAnimation const* slf, ZkSize i) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkAnimation_getEventTag"); - return nullptr; - } - - if (i >= slf->events.size()) { - ZKC_LOG_ERROR("ZkAnimation_getEventTag() failed: index out of bounds"); - return nullptr; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); + ZKC_CHECK_LEN(slf->events, i); return &slf->events[i]; } ZkEventParticleEffect const* ZkAnimation_getParticleEffect(ZkAnimation const* slf, ZkSize i) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkAnimation_getParticleEffect"); - return nullptr; - } - - if (i >= slf->pfx.size()) { - ZKC_LOG_ERROR("ZkAnimation_getParticleEffect() failed: index out of bounds"); - return nullptr; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); + ZKC_CHECK_LEN(slf->pfx, i); return &slf->pfx[i]; } ZkEventParticleEffectStop const* ZkAnimation_getParticleEffectStop(ZkAnimation const* slf, ZkSize i) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkAnimation_getParticleEffectStop"); - return nullptr; - } - - if (i >= slf->pfx_stop.size()) { - ZKC_LOG_ERROR("ZkAnimation_getParticleEffectStop() failed: index out of bounds"); - return nullptr; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); + ZKC_CHECK_LEN(slf->pfx_stop, i); return &slf->pfx_stop[i]; } ZkEventSoundEffect const* ZkAnimation_getSoundEffect(ZkAnimation const* slf, ZkSize i) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkAnimation_getSoundEffect"); - return nullptr; - } - - if (i >= slf->sfx.size()) { - ZKC_LOG_ERROR("ZkAnimation_getSoundEffect() failed: index out of bounds"); - return nullptr; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); + ZKC_CHECK_LEN(slf->sfx, i); return &slf->sfx[i]; } ZkEventSoundEffectGround const* ZkAnimation_getSoundEffectGround(ZkAnimation const* slf, ZkSize i) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkAnimation_getSoundEffectGround"); - return nullptr; - } - - if (i >= slf->sfx_ground.size()) { - ZKC_LOG_ERROR("ZkAnimation_getSoundEffectGround() failed: index out of bounds"); - return nullptr; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); + ZKC_CHECK_LEN(slf->sfx_ground, i); return &slf->sfx_ground[i]; } ZkEventMorphAnimation const* ZkAnimation_getMorphAnimation(ZkAnimation const* slf, ZkSize i) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkAnimation_getMorphAnimation"); - return nullptr; - } - - if (i >= slf->morph.size()) { - ZKC_LOG_ERROR("ZkAnimation_getMorphAnimation() failed: index out of bounds"); - return nullptr; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); + ZKC_CHECK_LEN(slf->morph, i); return &slf->morph[i]; } ZkEventCameraTremor const* ZkAnimation_getCameraTremor(ZkAnimation const* slf, ZkSize i) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkAnimation_getCameraTremor"); - return nullptr; - } - - if (i >= slf->tremors.size()) { - ZKC_LOG_ERROR("ZkAnimation_getCameraTremor() failed: index out of bounds"); - return nullptr; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); + ZKC_CHECK_LEN(slf->tremors, i); return &slf->tremors[i]; } void ZkAnimation_enumerateEventTags(ZkAnimation const* slf, ZkEventTagEnumerator cb, void* ctx) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkAnimation_enumerateEventTags"); - return; - } + ZKC_TRACE_FN(); + ZKC_CHECK_NULLV(slf, cb); for (auto& v : slf->events) { if (cb(ctx, &v)) break; @@ -601,10 +356,8 @@ void ZkAnimation_enumerateEventTags(ZkAnimation const* slf, ZkEventTagEnumerator } void ZkAnimation_enumerateParticleEffects(ZkAnimation const* slf, ZkEventParticlEffectEnumerator cb, void* ctx) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkAnimation_enumerateParticleEffects"); - return; - } + ZKC_TRACE_FN(); + ZKC_CHECK_NULLV(slf, cb); for (auto& v : slf->pfx) { if (cb(ctx, &v)) break; @@ -614,21 +367,16 @@ void ZkAnimation_enumerateParticleEffects(ZkAnimation const* slf, ZkEventParticl void ZkAnimation_enumerateParticleEffectStops(ZkAnimation const* slf, ZkEventParticleEffectStopEnumerator cb, void* ctx) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkAnimation_enumerateParticleEffectStops"); - return; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULLV(slf, cb); for (auto& v : slf->pfx_stop) { if (cb(ctx, &v)) break; } } void ZkAnimation_enumerateSoundEffects(ZkAnimation const* slf, ZkEventSoundEffectEnumerator cb, void* ctx) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkAnimation_enumerateSoundEffects"); - return; - } + ZKC_TRACE_FN(); + ZKC_CHECK_NULLV(slf, cb); for (auto& v : slf->sfx) { if (cb(ctx, &v)) break; @@ -636,10 +384,8 @@ void ZkAnimation_enumerateSoundEffects(ZkAnimation const* slf, ZkEventSoundEffec } void ZkAnimation_enumerateSoundEffectGrounds(ZkAnimation const* slf, ZkEventSoundEffectGroundEnumerator cb, void* ctx) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkAnimation_enumerateSoundEffectGrounds"); - return; - } + ZKC_TRACE_FN(); + ZKC_CHECK_NULLV(slf, cb); for (auto& v : slf->sfx_ground) { if (cb(ctx, &v)) break; @@ -647,10 +393,8 @@ void ZkAnimation_enumerateSoundEffectGrounds(ZkAnimation const* slf, ZkEventSoun } void ZkAnimation_enumerateMorphAnimations(ZkAnimation const* slf, ZkEventMorphAnimationEnumerator cb, void* ctx) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkAnimation_enumerateMorphAnimations"); - return; - } + ZKC_TRACE_FN(); + ZKC_CHECK_NULLV(slf, cb); for (auto& v : slf->morph) { if (cb(ctx, &v)) break; @@ -658,10 +402,8 @@ void ZkAnimation_enumerateMorphAnimations(ZkAnimation const* slf, ZkEventMorphAn } void ZkAnimation_enumerateCameraTremors(ZkAnimation const* slf, ZkEventCameraTremorEnumerator cb, void* ctx) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkAnimation_enumerateCameraTremors"); - return; - } + ZKC_TRACE_FN(); + ZKC_CHECK_NULLV(slf, cb); for (auto& v : slf->tremors) { if (cb(ctx, &v)) break; @@ -671,28 +413,20 @@ void ZkAnimation_enumerateCameraTremors(ZkAnimation const* slf, ZkEventCameraTre // ZkEventTag int32_t ZkEventTag_getFrame(ZkEventTag const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkEventTag_getFrame"); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->frame; } ZkEventType ZkEventTag_getType(ZkEventTag const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkEventTag_getType"); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return static_cast(slf->type); } ZkString ZkEventTag_getSlot(ZkEventTag const* slf, ZkSize i) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkEventTag_getSlot"); - return {}; - } + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); if (i != 0) { return slf->slot2.c_str(); @@ -702,443 +436,303 @@ ZkString ZkEventTag_getSlot(ZkEventTag const* slf, ZkSize i) { } ZkString ZkEventTag_getItem(ZkEventTag const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkEventTag_getItem"); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->item.c_str(); } int32_t const* ZkEventTag_getFrames(ZkEventTag const* slf, ZkSize* count) { - if (slf == nullptr || count == nullptr) { - ZKC_LOG_WARN_NULL("ZkEventTag_getFrames"); - return {}; - } + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf, count); *count = slf->frames.size(); return slf->frames.data(); } ZkFightMode ZkEventTag_getFightMode(ZkEventTag const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkEventTag_getFightMode"); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return static_cast(slf->fight_mode); } ZkBool ZkEventTag_getIsAttached(ZkEventTag const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkEventTag_getIsAttached"); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->attached; } // ZkEventParticleEffect int32_t ZkEventParticleEffect_getFrame(ZkEventParticleEffect const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkEventParticleEffect_getFrame"); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->frame; } int32_t ZkEventParticleEffect_getIndex(ZkEventParticleEffect const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkEventParticleEffect_getIndex"); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->index; } ZkString ZkEventParticleEffect_getName(ZkEventParticleEffect const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkEventParticleEffect_getName"); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->name.c_str(); } ZkString ZkEventParticleEffect_getPosition(ZkEventParticleEffect const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkEventParticleEffect_getPosition"); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->position.c_str(); } ZkBool ZkEventParticleEffect_getIsAttached(ZkEventParticleEffect const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkEventParticleEffect_getIsAttached"); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->attached; } // ZkEventParticleEffectStop int32_t ZkEventParticleEffectStop_getFrame(ZkEventParticleEffectStop const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkEventParticleEffectStop_getFrame"); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->frame; } int32_t ZkEventParticleEffectStop_getIndex(ZkEventParticleEffectStop const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkEventParticleEffectStop_getIndex"); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->index; } // ZkEventCameraTremor int32_t ZkEventCameraTremor_getFrame(ZkEventCameraTremor const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkEventCameraTremor_getFrame"); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->frame; } int32_t ZkEventCameraTremor_getField1(ZkEventCameraTremor const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkEventCameraTremor_getField1"); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->field1; } int32_t ZkEventCameraTremor_getField2(ZkEventCameraTremor const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkEventCameraTremor_getField2"); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->field2; } int32_t ZkEventCameraTremor_getField3(ZkEventCameraTremor const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkEventCameraTremor_getField3"); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->field3; } int32_t ZkEventCameraTremor_getField4(ZkEventCameraTremor const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkEventCameraTremor_getField4"); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->field4; } // ZkEventSoundEffect int32_t ZkEventSoundEffect_getFrame(ZkEventSoundEffect const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkEventSoundEffect_getFrame"); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->frame; } ZkString ZkEventSoundEffect_getName(ZkEventSoundEffect const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkEventSoundEffect_getName"); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->name.c_str(); } float ZkEventSoundEffect_getRange(ZkEventSoundEffect const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkEventSoundEffect_getRange"); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->range; } ZkBool ZkEventSoundEffect_getEmptySlot(ZkEventSoundEffect const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkEventSoundEffect_getEmptySlot"); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->empty_slot; } // ZkEventSoundEffectGround int32_t ZkEventSoundEffectGround_getFrame(ZkEventSoundEffectGround const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkEventSoundEffectGround_getFrame"); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->frame; } ZkString ZkEventSoundEffectGround_getName(ZkEventSoundEffectGround const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkEventSoundEffectGround_getName"); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->name.c_str(); } float ZkEventSoundEffectGround_getRange(ZkEventSoundEffectGround const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkEventSoundEffectGround_getRange"); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->range; } ZkBool ZkEventSoundEffectGround_getEmptySlot(ZkEventSoundEffectGround const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkEventSoundEffectGround_getEmptySlot"); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->empty_slot; } // ZkMorphAnimation int32_t ZkMorphAnimation_getFrame(ZkEventMorphAnimation const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMorphAnimation_getFrame"); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->frame; } ZkString ZkMorphAnimation_getAnimation(ZkEventMorphAnimation const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMorphAnimation_getAnimation"); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->animation.c_str(); } ZkString ZkMorphAnimation_getNode(ZkEventMorphAnimation const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMorphAnimation_getNode"); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->node.c_str(); } // ZkAnimationCombine ZkString ZkAnimationCombine_getName(ZkAnimationCombine const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkAnimationCombine_getName"); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->name.c_str(); } uint32_t ZkAnimationCombine_getLayer(ZkAnimationCombine const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkAnimationCombine_getLayer"); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->layer; } ZkString ZkAnimationCombine_getNext(ZkAnimationCombine const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkAnimationCombine_getNext"); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->next.c_str(); } float ZkAnimationCombine_getBlendIn(ZkAnimationCombine const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkAnimationCombine_getBlendIn"); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->blend_in; } float ZkAnimationCombine_getBlendOut(ZkAnimationCombine const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkAnimationCombine_getBlendOut"); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->blend_out; } ZkAnimationFlag ZkAnimationCombine_getFlags(ZkAnimationCombine const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkAnimationCombine_getFlags"); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return static_cast(slf->flags); } ZkString ZkAnimationCombine_getModel(ZkAnimationCombine const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkAnimationCombine_getModel"); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->model.c_str(); } int32_t ZkAnimationCombine_getLastFrame(ZkAnimationCombine const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkAnimationCombine_getLastFrame"); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->last_frame; } // ZkAnimationBlend ZkString ZkAnimationBlend_getName(ZkAnimationBlend const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkAnimationBlend_getName"); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->name.c_str(); } ZkString ZkAnimationBlend_getNext(ZkAnimationBlend const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkAnimationBlend_getNext"); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->next.c_str(); } float ZkAnimationBlend_getBlendIn(ZkAnimationBlend const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkAnimationBlend_getBlendIn"); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->blend_in; } float ZkAnimationBlend_getBlendOut(ZkAnimationBlend const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkAnimationBlend_getBlendOut"); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->blend_out; } // ZkAnimationAlias ZkString ZkAnimationAlias_getName(ZkAnimationAlias const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkAnimationAlias_getName"); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->name.c_str(); } uint32_t ZkAnimationAlias_getLayer(ZkAnimationAlias const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkAnimationAlias_getLayer"); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->layer; } ZkString ZkAnimationAlias_getNext(ZkAnimationAlias const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkAnimationAlias_getNext"); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->next.c_str(); } float ZkAnimationAlias_getBlendIn(ZkAnimationAlias const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkAnimationAlias_getBlendIn"); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->blend_in; } float ZkAnimationAlias_getBlendOut(ZkAnimationAlias const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkAnimationAlias_getBlendOut"); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->blend_out; } ZkAnimationFlag ZkAnimationAlias_getFlags(ZkAnimationAlias const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkAnimationAlias_getFlags"); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return static_cast(slf->flags); } ZkString ZkAnimationAlias_getAlias(ZkAnimationAlias const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkAnimationAlias_getAlias"); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return slf->alias.c_str(); } ZkAnimationDirection ZkAnimationAlias_getDirection(ZkAnimationAlias const* slf) { - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkAnimationAlias_getDirection"); - return {}; - } - + ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); return static_cast(slf->direction); } diff --git a/src/MorphMesh.cc b/src/MorphMesh.cc index a8593de..ee26f3b 100644 --- a/src/MorphMesh.cc +++ b/src/MorphMesh.cc @@ -4,78 +4,20 @@ #include "Internal.hh" -ZkMorphMesh* ZkMorphMesh_load(ZkRead* buf) { - ZKC_TRACE_FN(); - if (buf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMorphMesh_load"); - return nullptr; - } - - try { - ZkMorphMesh obj {}; - obj.load(buf); - return ZKC_WRAP_NEW(obj); - } catch (std::exception const& exc) { - ZKC_LOG_ERROR("ZkMorphMesh_load() failed: %s", exc.what()); - return nullptr; - } -} - -ZkMorphMesh* ZkMorphMesh_loadPath(ZkString path) { - ZKC_TRACE_FN(); - if (path == nullptr) { - ZKC_LOG_WARN_NULL("ZkMorphMesh_loadPath"); - return nullptr; - } - - try { - auto buf = zenkit::Read::from(path); - - ZkMorphMesh obj {}; - obj.load(buf.get()); - return ZKC_WRAP_NEW(obj); - } catch (std::exception const& exc) { - ZKC_LOG_ERROR("ZkMorphMesh_loadPath() failed: %s", exc.what()); - return nullptr; - } -} - -ZkMorphMesh* ZkMorphMesh_loadVfs(ZkVfs* vfs, ZkString name) { - ZKC_TRACE_FN(); - if (vfs == nullptr || name == nullptr) { - ZKC_LOG_WARN_NULL("ZkMorphMesh_loadVfs"); - return nullptr; - } - - auto node = vfs->find(name); - if (node == nullptr) return nullptr; - - auto rd = node->open_read(); - return ZkMorphMesh_load(rd.get()); -} - -void ZkMorphMesh_del(ZkMorphMesh* slf) { - ZKC_TRACE_FN(); - delete slf; -} +ZKC_LOADER(ZkMorphMesh); +ZKC_PATH_LOADER(ZkMorphMesh); +ZKC_VFS_LOADER(ZkMorphMesh); +ZKC_DELETER(ZkMorphMesh); ZkString ZkMorphMesh_getName(ZkMorphMesh const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMorphMesh_getName"); - return nullptr; - } - + ZKC_CHECK_NULL(slf); return slf->name.c_str(); } ZkMultiResolutionMesh const* ZkMorphMesh_getMesh(ZkMorphMesh const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMorphMesh_getMesh"); - return nullptr; - } - + ZKC_CHECK_NULL(slf); return &slf->mesh; } @@ -103,35 +45,20 @@ void ZkMorphMesh_enumerateMorphPositions(ZkMorphMesh const* slf, ZkVec3fEnumerat ZkSize ZkMorphMesh_getAnimationCount(ZkMorphMesh const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMorphMesh_getAnimationCount"); - return 0; - } - + ZKC_CHECK_NULL(slf); return slf->animations.size(); } ZkMorphAnimation const* ZkMorphMesh_getAnimation(ZkMorphMesh const* slf, ZkSize i) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMorphMesh_getAnimation"); - return nullptr; - } - - if (i >= slf->animations.size()) { - ZKC_LOG_ERROR("ZkMorphMesh_getAnimation() failed: index out of range"); - return nullptr; - } - + ZKC_CHECK_NULL(slf); + ZKC_CHECK_LEN(slf->animations, i); return &slf->animations[i]; } void ZkMorphMesh_enumerateAnimations(ZkMorphMesh const* slf, ZkMorphAnimationEnumerator cb, void* ctx) { ZKC_TRACE_FN(); - if (slf == nullptr || cb == nullptr) { - ZKC_LOG_WARN_NULL("ZkMorphMesh_enumerateAnimations"); - return; - } + ZKC_CHECK_NULLV(slf, cb); for (auto& ani : slf->animations) { if (cb(ctx, &ani)) break; @@ -140,35 +67,20 @@ void ZkMorphMesh_enumerateAnimations(ZkMorphMesh const* slf, ZkMorphAnimationEnu ZkSize ZkMorphMesh_getSourceCount(ZkMorphMesh const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMorphMesh_getSourceCount"); - return 0; - } - + ZKC_CHECK_NULL(slf); return slf->sources.size(); } ZkMorphSource const* ZkMorphMesh_getSource(ZkMorphMesh const* slf, ZkSize i) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMorphMesh_getSource"); - return nullptr; - } - - if (i >= slf->sources.size()) { - ZKC_LOG_ERROR("ZkMorphMesh_getSource() failed: index out of range"); - return nullptr; - } - + ZKC_CHECK_NULL(slf); + ZKC_CHECK_LEN(slf->sources, i); return &slf->sources[i]; } void ZkMorphMesh_enumerateSources(ZkMorphMesh const* slf, ZkMorphSourceEnumerator cb, void* ctx) { ZKC_TRACE_FN(); - if (slf == nullptr || cb == nullptr) { - ZKC_LOG_WARN_NULL("ZkMorphMesh_enumerateSources"); - return; - } + ZKC_CHECK_NULLV(slf, cb); for (auto& src : slf->sources) { if (cb(ctx, &src)) break; @@ -177,90 +89,55 @@ void ZkMorphMesh_enumerateSources(ZkMorphMesh const* slf, ZkMorphSourceEnumerato ZkString ZkMorphAnimation_getName(ZkMorphAnimation const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMorphAnimation_getName"); - return nullptr; - } - + ZKC_CHECK_NULL(slf); return slf->name.c_str(); } int32_t ZkMorphAnimation_getLayer(ZkMorphAnimation const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMorphAnimation_getLayer"); - return 0; - } - + ZKC_CHECK_NULL(slf); return slf->layer; } float ZkMorphAnimation_getBlendIn(ZkMorphAnimation const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMorphAnimation_getBlendIn"); - return 0; - } - + ZKC_CHECK_NULL(slf); return slf->blend_in; } float ZkMorphAnimation_getBlendOut(ZkMorphAnimation const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMorphAnimation_getBlendOut"); - return 0; - } - + ZKC_CHECK_NULL(slf); return slf->blend_out; } float ZkMorphAnimation_getDuration(ZkMorphAnimation const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMorphAnimation_getDuration"); - return 0; - } - + ZKC_CHECK_NULL(slf); return slf->duration; } float ZkMorphAnimation_getSpeed(ZkMorphAnimation const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMorphAnimation_getSpeed"); - return 0; - } - + ZKC_CHECK_NULL(slf); return slf->speed; } uint8_t ZkMorphAnimation_getFlags(ZkMorphAnimation const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMorphAnimation_getFlags"); - return 0; - } - + ZKC_CHECK_NULL(slf); return slf->flags; } uint32_t ZkMorphAnimation_getFrameCount(ZkMorphAnimation const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMorphAnimation_getFrameCount"); - return 0; - } - + ZKC_CHECK_NULL(slf); return slf->frame_count; } uint32_t const* ZkMorphAnimation_getVertices(ZkMorphAnimation const* slf, ZkSize* count) { ZKC_TRACE_FN(); - if (slf == nullptr || count == nullptr) { - ZKC_LOG_WARN_NULL("ZkMorphAnimation_getVertices"); - return nullptr; - } + ZKC_CHECK_NULL(slf, count); *count = slf->vertices.size(); return slf->vertices.data(); @@ -290,20 +167,12 @@ void ZkMorphAnimation_enumerateSamples(ZkMorphAnimation const* slf, ZkVec3fEnume ZkDate ZkMorphSource_getFileDate(ZkMorphSource const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMorphSource_getFileDate"); - return {}; - } - + ZKC_CHECK_NULL(slf); return slf->file_date; } ZkString ZkMorphSource_getFileName(ZkMorphSource const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMorphSource_getFileName"); - return nullptr; - } - + ZKC_CHECK_NULL(slf); return slf->file_name.c_str(); } diff --git a/src/MultiResolutionMesh.cc b/src/MultiResolutionMesh.cc index 8a3a0ae..d97b385 100644 --- a/src/MultiResolutionMesh.cc +++ b/src/MultiResolutionMesh.cc @@ -4,60 +4,10 @@ #include "Internal.hh" -ZkMultiResolutionMesh* ZkMultiResolutionMesh_load(ZkRead* buf) { - ZKC_TRACE_FN(); - if (buf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMultiResolutionMesh_load"); - return nullptr; - } - - try { - ZkMultiResolutionMesh obj {}; - obj.load(buf); - return ZKC_WRAP_NEW(obj); - } catch (std::exception const& exc) { - ZKC_LOG_ERROR("ZkMultiResolutionMesh_load() failed: %s", exc.what()); - return nullptr; - } -} - -ZkMultiResolutionMesh* ZkMultiResolutionMesh_loadPath(ZkString path) { - ZKC_TRACE_FN(); - if (path == nullptr) { - ZKC_LOG_WARN_NULL("ZkMultiResolutionMesh_loadPath"); - return nullptr; - } - - try { - auto buf = zenkit::Read::from(path); - - ZkMultiResolutionMesh obj {}; - obj.load(buf.get()); - return ZKC_WRAP_NEW(obj); - } catch (std::exception const& exc) { - ZKC_LOG_ERROR("ZkMultiResolutionMesh_loadPath() failed: %s", exc.what()); - return nullptr; - } -} - -ZkMultiResolutionMesh* ZkMultiResolutionMesh_loadVfs(ZkVfs* vfs, ZkString name) { - ZKC_TRACE_FN(); - if (vfs == nullptr || name == nullptr) { - ZKC_LOG_WARN_NULL("ZkMultiResolutionMesh_loadVfs"); - return nullptr; - } - - auto node = vfs->find(name); - if (node == nullptr) return nullptr; - - auto rd = node->open_read(); - return ZkMultiResolutionMesh_load(rd.get()); -} - -void ZkMultiResolutionMesh_del(ZkMultiResolutionMesh* slf) { - ZKC_TRACE_FN(); - delete slf; -} +ZKC_LOADER(ZkMultiResolutionMesh); +ZKC_PATH_LOADER(ZkMultiResolutionMesh); +ZKC_VFS_LOADER(ZkMultiResolutionMesh); +ZKC_DELETER(ZkMultiResolutionMesh); ZkSize ZkMultiResolutionMesh_getPositionCount(ZkMultiResolutionMesh const* slf) { ZKC_TRACE_FN(); @@ -105,35 +55,21 @@ void ZkMultiResolutionMesh_enumerateNormals(ZkMultiResolutionMesh const* slf, Zk ZkSize ZkMultiResolutionMesh_getSubMeshCount(ZkMultiResolutionMesh const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMultiResolutionMesh_getSubMeshCount"); - return 0; - } + ZKC_CHECK_NULL(slf); return slf->sub_meshes.size(); } ZkSubMesh const* ZkMultiResolutionMesh_getSubMesh(ZkMultiResolutionMesh const* slf, ZkSize i) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMultiResolutionMesh_getSubMesh"); - return nullptr; - } - - if (i >= slf->sub_meshes.size()) { - ZKC_LOG_ERROR("ZkMultiResolutionMesh_getSubMesh() failed: index out of range"); - return nullptr; - } - + ZKC_CHECK_NULL(slf); + ZKC_CHECK_LEN(slf->sub_meshes, i); return &slf->sub_meshes[i]; } void ZkMultiResolutionMesh_enumerateSubMeshes(ZkMultiResolutionMesh const* slf, ZkSubMeshEnumerator cb, void* ctx) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMultiResolutionMesh_enumerateSubMeshes"); - return; - } + ZKC_CHECK_NULLV(slf, cb); for (auto& subMesh : slf->sub_meshes) { if (cb(ctx, &subMesh)) return; @@ -142,35 +78,20 @@ void ZkMultiResolutionMesh_enumerateSubMeshes(ZkMultiResolutionMesh const* slf, ZkSize ZkMultiResolutionMesh_getMaterialCount(ZkMultiResolutionMesh const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMultiResolutionMesh_getMaterialCount"); - return 0; - } - + ZKC_CHECK_NULL(slf); return slf->materials.size(); } ZkMaterial const* ZkMultiResolutionMesh_getMaterial(ZkMultiResolutionMesh const* slf, ZkSize i) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMultiResolutionMesh_getMaterial"); - return nullptr; - } - - if (i >= slf->materials.size()) { - ZKC_LOG_ERROR("ZkMultiResolutionMesh_getMaterial() failed: index out of range"); - return nullptr; - } - + ZKC_CHECK_NULL(slf); + ZKC_CHECK_LEN(slf->materials, i); return &slf->materials[i]; } void ZkMultiResolutionMesh_enumerateMaterials(ZkMultiResolutionMesh const* slf, ZkMaterialEnumerator cb, void* ctx) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMultiResolutionMesh_enumerateMaterials"); - return; - } + ZKC_CHECK_NULLV(slf, cb); for (auto& material : slf->materials) { if (cb(ctx, &material)) return; @@ -179,50 +100,31 @@ void ZkMultiResolutionMesh_enumerateMaterials(ZkMultiResolutionMesh const* slf, ZkBool ZkMultiResolutionMesh_getAlphaTest(ZkMultiResolutionMesh const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMultiResolutionMesh_getAlphaTest"); - return false; - } - + ZKC_CHECK_NULL(slf); return slf->alpha_test; } ZkAxisAlignedBoundingBox ZkMultiResolutionMesh_getBbox(ZkMultiResolutionMesh const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMultiResolutionMesh_getBbox"); - return {}; - } - + ZKC_CHECK_NULL(slf); return slf->bbox; } ZkOrientedBoundingBox const* ZkMultiResolutionMesh_getOrientedBbox(ZkMultiResolutionMesh const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkMultiResolutionMesh_getOrientedBbox"); - return nullptr; - } - + ZKC_CHECK_NULL(slf); return &slf->obbox; } ZkMaterial const* ZkSubMesh_getMaterial(ZkSubMesh const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkSubMesh_getMaterial"); - return nullptr; - } - + ZKC_CHECK_NULL(slf); return &slf->mat; } ZkMeshTriangle const* ZkSubMesh_getTriangles(ZkSubMesh const* slf, ZkSize* count) { ZKC_TRACE_FN(); - if (slf == nullptr || count == nullptr) { - ZKC_LOG_WARN_NULL("ZkSubMesh_getTriangles"); - return nullptr; - } + ZKC_CHECK_NULL(slf, count); *count = slf->triangles.size(); return slf->triangles.data(); @@ -254,10 +156,7 @@ void ZkSubMesh_enumerateWedges(ZkSubMesh const* slf, ZkMeshWedgeEnumerator cb, v float const* ZkSubMesh_getColors(ZkSubMesh const* slf, ZkSize* count) { ZKC_TRACE_FN(); - if (slf == nullptr || count == nullptr) { - ZKC_LOG_WARN_NULL("ZkSubMesh_getColors"); - return nullptr; - } + ZKC_CHECK_NULL(slf, count); *count = slf->colors.size(); return slf->colors.data(); @@ -265,10 +164,7 @@ float const* ZkSubMesh_getColors(ZkSubMesh const* slf, ZkSize* count) { uint16_t const* ZkSubMesh_getTrianglePlaneIndices(ZkSubMesh const* slf, ZkSize* count) { ZKC_TRACE_FN(); - if (slf == nullptr || count == nullptr) { - ZKC_LOG_WARN_NULL("ZkSubMesh_getTrianglePlaneIndices"); - return nullptr; - } + ZKC_CHECK_NULL(slf, count); *count = slf->triangle_plane_indices.size(); return slf->triangle_plane_indices.data(); @@ -300,10 +196,7 @@ void ZkSubMesh_enumerateTrianglePlanes(ZkSubMesh const* slf, ZkMeshPlaneEnumerat ZkMeshTriangleEdge const* ZkSubMesh_getTriangleEdges(ZkSubMesh const* slf, ZkSize* count) { ZKC_TRACE_FN(); - if (slf == nullptr || count == nullptr) { - ZKC_LOG_WARN_NULL("ZkSubMesh_getTriangleEdges"); - return nullptr; - } + ZKC_CHECK_NULL(slf, count); *count = slf->triangle_edges.size(); return slf->triangle_edges.data(); @@ -311,10 +204,7 @@ ZkMeshTriangleEdge const* ZkSubMesh_getTriangleEdges(ZkSubMesh const* slf, ZkSiz ZkMeshEdge const* ZkSubMesh_getEdges(ZkSubMesh const* slf, ZkSize* count) { ZKC_TRACE_FN(); - if (slf == nullptr || count == nullptr) { - ZKC_LOG_WARN_NULL("ZkSubMesh_getEdges"); - return nullptr; - } + ZKC_CHECK_NULL(slf, count); *count = slf->edges.size(); return slf->edges.data(); @@ -322,10 +212,7 @@ ZkMeshEdge const* ZkSubMesh_getEdges(ZkSubMesh const* slf, ZkSize* count) { float const* ZkSubMesh_getEdgeScores(ZkSubMesh const* slf, ZkSize* count) { ZKC_TRACE_FN(); - if (slf == nullptr || count == nullptr) { - ZKC_LOG_WARN_NULL("ZkSubMesh_getEdgeScores"); - return nullptr; - } + ZKC_CHECK_NULL(slf, count); *count = slf->edge_scores.size(); return slf->edge_scores.data(); @@ -333,10 +220,7 @@ float const* ZkSubMesh_getEdgeScores(ZkSubMesh const* slf, ZkSize* count) { uint16_t const* ZkSubMesh_getWedgeMap(ZkSubMesh const* slf, ZkSize* count) { ZKC_TRACE_FN(); - if (slf == nullptr || count == nullptr) { - ZKC_LOG_WARN_NULL("ZkSubMesh_getWedgeMap"); - return nullptr; - } + ZKC_CHECK_NULL(slf, count); *count = slf->wedge_map.size(); return slf->wedge_map.data(); diff --git a/src/SoftSkinMesh.cc b/src/SoftSkinMesh.cc index e12bfa9..871343a 100644 --- a/src/SoftSkinMesh.cc +++ b/src/SoftSkinMesh.cc @@ -6,45 +6,26 @@ ZkSize ZkSoftSkinMesh_getNodeCount(ZkSoftSkinMesh const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkSoftSkinMesh_getNodeCount"); - return 0; - } - + ZKC_CHECK_NULL(slf); return slf->nodes.size(); } ZkMultiResolutionMesh const* ZkSoftSkinMesh_getMesh(ZkSoftSkinMesh const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkSoftSkinMesh_getMesh"); - return nullptr; - } - + ZKC_CHECK_NULL(slf); return &slf->mesh; } ZkOrientedBoundingBox const* ZkSoftSkinMesh_getBbox(ZkSoftSkinMesh const* slf, ZkSize node) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkSoftSkinMesh_getBbox"); - return nullptr; - } - - if (node >= slf->bboxes.size()) { - ZKC_LOG_ERROR("ZkSoftSkinMesh_getBbox() failed: index out of range"); - return nullptr; - } - + ZKC_CHECK_NULL(slf); + ZKC_CHECK_LEN(slf->bboxes, node); return &slf->bboxes[node]; } void ZkSoftSkinMesh_enumerateBoundingBoxes(ZkSoftSkinMesh const* slf, ZkOrientedBoundingBoxEnumerator cb, void* ctx) { ZKC_TRACE_FN(); - if (slf == nullptr || cb == nullptr) { - ZKC_LOG_WARN_NULL("ZkSoftSkinMesh_enumerateBoundingBoxes"); - return; - } + ZKC_CHECK_NULLV(slf, cb); for (auto& bbox : slf->bboxes) { if (cb(ctx, &bbox)) break; @@ -108,10 +89,7 @@ void ZkSoftSkinMesh_enumerateWedgeNormals(ZkSoftSkinMesh const* slf, ZkSoftSkinW int32_t const* ZkSoftSkinMesh_getNodes(ZkSoftSkinMesh const* slf, ZkSize* count) { ZKC_TRACE_FN(); - if (slf == nullptr || count == nullptr) { - ZKC_LOG_WARN_NULL("ZkSoftSkinMesh_getNodes"); - return nullptr; - } + ZKC_CHECK_NULL(slf, count); *count = slf->nodes.size(); return slf->nodes.data(); diff --git a/src/Stream.cc b/src/Stream.cc index 4b221e0..419a5c0 100644 --- a/src/Stream.cc +++ b/src/Stream.cc @@ -45,17 +45,26 @@ class ZkReadExtImpl final : public zenkit::Read { ZkRead* ZkRead_newFile(FILE* stream) { ZKC_TRACE_FN(); + ZKC_CHECK_NULL(stream); return zenkit::Read::from(stream).release(); } ZkRead* ZkRead_newMem(ZkByte const* bytes, ZkSize length) { ZKC_TRACE_FN(); + ZKC_CHECK_NULL(bytes); return zenkit::Read::from(reinterpret_cast(bytes), length).release(); } ZkRead* ZkRead_newPath(ZkString path) { ZKC_TRACE_FN(); - return zenkit::Read::from(path).release(); + ZKC_CHECK_NULL(path); + + try { + return zenkit::Read::from(path).release(); + } catch (std::exception const& exc) { + ZKC_LOG_ERROR("ZkRead_newPath() failed: %s", exc.what()); + return nullptr; + } } ZkRead* ZkRead_newExt(ZkReadExt ext, void* ctx) { @@ -70,6 +79,8 @@ void ZkRead_del(ZkRead* slf) { ZkSize ZkRead_getSize(ZkRead* slf) { ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); + auto off = slf->tell(); slf->seek(0, zenkit::Whence::END); auto size = slf->tell(); @@ -79,6 +90,8 @@ ZkSize ZkRead_getSize(ZkRead* slf) { ZkSize ZkRead_getBytes(ZkRead* slf, void* buf, ZkSize length) { ZKC_TRACE_FN(); + ZKC_CHECK_NULL(slf); + auto off = slf->tell(); slf->seek(0, zenkit::Whence::BEG); auto count = slf->read(buf, length); diff --git a/src/Texture.cc b/src/Texture.cc index 4e4621a..86325b4 100644 --- a/src/Texture.cc +++ b/src/Texture.cc @@ -4,158 +4,64 @@ #include "Internal.hh" -ZkTexture* ZkTexture_load(ZkRead* buf) { - ZKC_TRACE_FN(); - if (buf == nullptr) { - ZKC_LOG_WARN_NULL("ZkTexture_load"); - return nullptr; - } - - try { - ZkTexture obj {}; - obj.load(buf); - return ZKC_WRAP_NEW(obj); - } catch (std::exception const& exc) { - ZKC_LOG_ERROR("ZkTexture_load() failed: %s", exc.what()); - return nullptr; - } -} - -ZkTexture* ZkTexture_loadPath(ZkString path) { - ZKC_TRACE_FN(); - if (path == nullptr) { - ZKC_LOG_WARN_NULL("ZkTexture_loadPath"); - return nullptr; - } - - try { - auto buf = zenkit::Read::from(path); - - ZkTexture obj {}; - obj.load(buf.get()); - return ZKC_WRAP_NEW(obj); - } catch (std::exception const& exc) { - ZKC_LOG_ERROR("ZkTexture_loadPath() failed: %s", exc.what()); - return nullptr; - } -} - -ZkTexture* ZkTexture_loadVfs(ZkVfs* vfs, ZkString name) { - ZKC_TRACE_FN(); - if (vfs == nullptr || name == nullptr) { - ZKC_LOG_WARN_NULL("ZkTexture_loadVfs"); - return nullptr; - } - - auto node = vfs->find(name); - if (node == nullptr) return nullptr; - - auto rd = node->open_read(); - return ZkTexture_load(rd.get()); -} - -void ZkTexture_del(ZkTexture* slf) { - ZKC_TRACE_FN(); - delete slf; -} +ZKC_LOADER(ZkTexture); +ZKC_PATH_LOADER(ZkTexture); +ZKC_VFS_LOADER(ZkTexture); +ZKC_DELETER(ZkTexture); ZkTextureFormat ZkTexture_getFormat(ZkTexture const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkTexture_getFormat"); - return ZkTextureFormat_R8G8B8A8; - } - + ZKC_CHECK_NULL(slf); return static_cast(slf->format()); } uint32_t ZkTexture_getWidth(ZkTexture const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkTexture_getWidth"); - return 0; - } - + ZKC_CHECK_NULL(slf); return slf->width(); } uint32_t ZkTexture_getHeight(ZkTexture const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkTexture_getHeight"); - return 0; - } - + ZKC_CHECK_NULL(slf); return slf->height(); } uint32_t ZkTexture_getWidthMipmap(ZkTexture const* slf, ZkSize level) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkTexture_getWidthMipmap"); - return 0; - } - - if (level >= slf->mipmaps()) { - ZKC_LOG_ERROR("ZkTexture_getWidthMipmap() failed: index out of range"); - return 0; - } - + ZKC_CHECK_NULL(slf); + ZKC_CHECK_LENA(slf->mipmaps(), level); return slf->mipmap_width(static_cast(level)); } uint32_t ZkTexture_getHeightMipmap(ZkTexture const* slf, ZkSize level) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkTexture_getHeightMipmap"); - return 0; - } - - if (level >= slf->mipmaps()) { - ZKC_LOG_ERROR("ZkTexture_getHeightMipmap() failed: index out of range"); - return 0; - } - + ZKC_CHECK_NULL(slf); + ZKC_CHECK_LENA(slf->mipmaps(), level); return slf->mipmap_height(static_cast(level)); } uint32_t ZkTexture_getWidthRef(ZkTexture const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkTexture_getWidthRef"); - return 0; - } - + ZKC_CHECK_NULL(slf); return slf->ref_width(); } uint32_t ZkTexture_getHeightRef(ZkTexture const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkTexture_getHeightRef"); - return 0; - } - + ZKC_CHECK_NULL(slf); return slf->ref_height(); } uint32_t ZkTexture_getMipmapCount(ZkTexture const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkTexture_getMipmapCount"); - return 0; - } - + ZKC_CHECK_NULL(slf); return slf->mipmaps(); } uint32_t ZkTexture_getAverageColor(ZkTexture const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkTexture_getAverageColor"); - return 0; - } - + ZKC_CHECK_NULL(slf); return slf->average_color(); } @@ -183,10 +89,7 @@ void ZkTexture_enumeratePaletteItems(ZkTexture const* slf, ZkColorEnumerator cb, uint8_t const* ZkTexture_getMipmapRaw(ZkTexture const* slf, ZkSize level, ZkSize* size) { ZKC_TRACE_FN(); - if (slf == nullptr || size == nullptr) { - ZKC_LOG_WARN_NULL("ZkTexture_getMipmapRaw"); - return nullptr; - } + ZKC_CHECK_NULL(slf, size); *size = slf->data(static_cast(level)).size(); return slf->data(static_cast(level)).data(); @@ -194,10 +97,7 @@ uint8_t const* ZkTexture_getMipmapRaw(ZkTexture const* slf, ZkSize level, ZkSize ZkSize ZkTexture_getMipmapRgba(ZkTexture const* slf, ZkSize level, uint8_t* buf, ZkSize size) { ZKC_TRACE_FN(); - if (slf == nullptr || buf == nullptr) { - ZKC_LOG_WARN_NULL("ZkTexture_getMipmapRgba"); - return 0; - } + ZKC_CHECK_NULL(slf, buf); auto data = slf->as_rgba8(static_cast(level)); if (size < data.size()) { @@ -212,10 +112,7 @@ ZkSize ZkTexture_getMipmapRgba(ZkTexture const* slf, ZkSize level, uint8_t* buf, void ZkTexture_enumerateRawMipmaps(ZkTexture const* slf, ZkTextureMipmapEnumerator cb, void* ctx) { ZKC_TRACE_FN(); - if (slf == nullptr || cb == nullptr) { - ZKC_LOG_WARN_NULL("ZkTexture_enumerateRawMipmaps"); - return; - } + ZKC_CHECK_NULLV(slf, cb); for (auto i = 0u; i < slf->mipmaps(); ++i) { if (cb(ctx, i, slf->data(i).data(), slf->data(i).size())) break; @@ -224,10 +121,7 @@ void ZkTexture_enumerateRawMipmaps(ZkTexture const* slf, ZkTextureMipmapEnumerat void ZkTexture_enumerateRgbaMipmaps(ZkTexture const* slf, ZkTextureMipmapEnumerator cb, void* ctx) { ZKC_TRACE_FN(); - if (slf == nullptr || cb == nullptr) { - ZKC_LOG_WARN_NULL("ZkTexture_enumerateRgbaMipmaps"); - return; - } + ZKC_CHECK_NULLV(slf, cb); for (auto i = 0u; i < slf->mipmaps(); ++i) { auto rgba = slf->as_rgba8(i); diff --git a/src/Vfs.cc b/src/Vfs.cc index 0335408..f03d704 100644 --- a/src/Vfs.cc +++ b/src/Vfs.cc @@ -16,40 +16,25 @@ void ZkVfs_del(ZkVfs* slf) { ZkVfsNode const* ZkVfs_getRoot(ZkVfs const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkVfs_getRoot"); - return nullptr; - } - + ZKC_CHECK_NULL(slf); return &slf->root(); } ZkVfsNode* ZkVfs_mkdir(ZkVfs* slf, ZkString path) { ZKC_TRACE_FN(); - if (slf == nullptr || path == nullptr) { - ZKC_LOG_WARN_NULL("ZkVfs_mkdir"); - return nullptr; - } - + ZKC_CHECK_NULL(slf, path); return &slf->mkdir(path); } ZkBool ZkVfs_remove(ZkVfs* slf, ZkString path) { ZKC_TRACE_FN(); - if (slf == nullptr || path == nullptr) { - ZKC_LOG_WARN_NULL("ZkVfs_mkdir"); - return false; - } - + ZKC_CHECK_NULL(slf, path); return slf->remove(path); } void ZkVfs_mount(ZkVfs* slf, ZkVfsNode* node, ZkString parent, ZkVfsOverwriteBehavior overwrite) { ZKC_TRACE_FN(); - if (slf == nullptr || node == nullptr || parent == nullptr) { - ZKC_LOG_WARN_NULL("ZkVfs_mount"); - return; - } + ZKC_CHECK_NULLV(slf, node, parent); try { slf->mount(*node, parent, static_cast(overwrite)); @@ -60,10 +45,7 @@ void ZkVfs_mount(ZkVfs* slf, ZkVfsNode* node, ZkString parent, ZkVfsOverwriteBeh void ZkVfs_mountHost(ZkVfs* slf, ZkString path, ZkString parent, ZkVfsOverwriteBehavior overwrite) { ZKC_TRACE_FN(); - if (slf == nullptr || path == nullptr || parent == nullptr) { - ZKC_LOG_WARN_NULL("ZkVfs_mountHost"); - return; - } + ZKC_CHECK_NULLV(slf, path, parent); try { slf->mount_host(path, parent, static_cast(overwrite)); @@ -74,10 +56,7 @@ void ZkVfs_mountHost(ZkVfs* slf, ZkString path, ZkString parent, ZkVfsOverwriteB void ZkVfs_mountDisk(ZkVfs* slf, ZkRead* buf, ZkVfsOverwriteBehavior overwrite) { ZKC_TRACE_FN(); - if (slf == nullptr || buf == nullptr) { - ZKC_LOG_WARN_NULL("ZkVfs_mountDisk"); - return; - } + ZKC_CHECK_NULLV(slf, buf); try { slf->mount_disk(buf, static_cast(overwrite)); @@ -88,10 +67,7 @@ void ZkVfs_mountDisk(ZkVfs* slf, ZkRead* buf, ZkVfsOverwriteBehavior overwrite) void ZkVfs_mountDiskHost(ZkVfs* slf, ZkString path, ZkVfsOverwriteBehavior overwrite) { ZKC_TRACE_FN(); - if (slf == nullptr || path == nullptr) { - ZKC_LOG_WARN_NULL("ZkVfs_mountDiskHost"); - return; - } + ZKC_CHECK_NULLV(slf, path); try { slf->mount_disk(path, static_cast(overwrite)); @@ -102,30 +78,19 @@ void ZkVfs_mountDiskHost(ZkVfs* slf, ZkString path, ZkVfsOverwriteBehavior overw ZkVfsNode* ZkVfs_resolvePath(ZkVfs* slf, ZkString path) { ZKC_TRACE_FN(); - if (slf == nullptr || path == nullptr) { - ZKC_LOG_WARN_NULL("ZkVfs_resolvePath"); - return nullptr; - } - + ZKC_CHECK_NULL(slf, path); return slf->resolve(path); } ZkVfsNode* ZkVfs_findNode(ZkVfs* slf, ZkString name) { ZKC_TRACE_FN(); - if (slf == nullptr || name == nullptr) { - ZKC_LOG_WARN_NULL("ZkVfs_findNode"); - return nullptr; - } - + ZKC_CHECK_NULL(slf, name); return slf->find(name); } ZkVfsNode* ZkVfsNode_newFile(ZkString name, ZkByte const* buf, ZkSize size, time_t ts) { ZKC_TRACE_FN(); - if (name == nullptr || buf == nullptr) { - ZKC_LOG_WARN_NULL("ZkVfsNode_newFile"); - return nullptr; - } + ZKC_CHECK_NULL(name, buf); try { auto node = ZkVfsNode::file(name, zenkit::VfsFileDescriptor {(std::byte const*) (buf), size}, ts); @@ -138,10 +103,7 @@ ZkVfsNode* ZkVfsNode_newFile(ZkString name, ZkByte const* buf, ZkSize size, time ZkVfsNode* ZkVfsNode_newDir(ZkString name, time_t ts) { ZKC_TRACE_FN(); - if (name == nullptr) { - ZKC_LOG_WARN_NULL("ZkVfsNode_newDir"); - return nullptr; - } + ZKC_CHECK_NULL(name); try { auto node = ZkVfsNode::directory(name, ts); @@ -159,50 +121,31 @@ void ZkVfsNode_del(ZkVfsNode* slf) { ZkBool ZkVfsNode_isFile(ZkVfsNode const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkVfsNode_isFile"); - return false; - } - + ZKC_CHECK_NULL(slf); return slf->type() == zenkit::VfsNodeType::FILE; } ZkBool ZkVfsNode_isDir(ZkVfsNode const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkVfsNode_isDir"); - return false; - } - + ZKC_CHECK_NULL(slf); return slf->type() == zenkit::VfsNodeType::DIRECTORY; } time_t ZkVfsNode_getTime(ZkVfsNode const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkVfsNode_getTime"); - return 0; - } - + ZKC_CHECK_NULL(slf); return slf->time(); } ZkString ZkVfsNode_getName(ZkVfsNode const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkVfsNode_getName"); - return nullptr; - } - + ZKC_CHECK_NULL(slf); return slf->name().c_str(); } ZkVfsNode* ZkVfsNode_getChild(ZkVfsNode* slf, ZkString name) { ZKC_TRACE_FN(); - if (slf == nullptr || name == nullptr) { - ZKC_LOG_WARN_NULL("ZkVfsNode_getChild"); - return nullptr; - } + ZKC_CHECK_NULL(slf, name); if (ZkVfsNode_isFile(slf)) { ZKC_LOG_ERROR("ZkVfsNode_getChild() failed: not a directory"); @@ -214,10 +157,7 @@ ZkVfsNode* ZkVfsNode_getChild(ZkVfsNode* slf, ZkString name) { ZkVfsNode* ZkVfsNode_create(ZkVfsNode* slf, ZkVfsNode* node) { ZKC_TRACE_FN(); - if (slf == nullptr || node == nullptr) { - ZKC_LOG_WARN_NULL("ZkVfsNode_create"); - return nullptr; - } + ZKC_CHECK_NULL(slf, node); if (ZkVfsNode_isFile(slf)) { ZKC_LOG_ERROR("ZkVfsNode_create() failed: not a directory"); @@ -229,10 +169,7 @@ ZkVfsNode* ZkVfsNode_create(ZkVfsNode* slf, ZkVfsNode* node) { ZkBool ZkVfsNode_remove(ZkVfsNode* slf, ZkString name) { ZKC_TRACE_FN(); - if (slf == nullptr || name == nullptr) { - ZKC_LOG_WARN_NULL("ZkVfsNode_remove"); - return false; - } + ZKC_CHECK_NULL(slf, name); if (ZkVfsNode_isFile(slf)) { ZKC_LOG_ERROR("ZkVfsNode_remove() failed: not a directory"); @@ -244,10 +181,7 @@ ZkBool ZkVfsNode_remove(ZkVfsNode* slf, ZkString name) { ZkRead* ZkVfsNode_open(ZkVfsNode const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkVfsNode_open"); - return nullptr; - } + ZKC_CHECK_NULL(slf); if (!ZkVfsNode_isFile(slf)) { ZKC_LOG_ERROR("ZkVfsNode_open() failed: not a file"); @@ -259,10 +193,7 @@ ZkRead* ZkVfsNode_open(ZkVfsNode const* slf) { void ZkVfsNode_enumerateChildren(ZkVfsNode const* slf, ZkVfsNodeEnumerator callback, void* ctx) { ZKC_TRACE_FN(); - if (slf == nullptr || callback == nullptr) { - ZKC_LOG_WARN_NULL("ZkVfsNode_enumerateChildren"); - return; - } + ZKC_CHECK_NULLV(slf, callback); if (ZkVfsNode_isFile(slf)) { ZKC_LOG_ERROR("ZkVfsNode_enumerateChildren() failed: not a directory"); diff --git a/src/World.cc b/src/World.cc index 2469741..0904835 100644 --- a/src/World.cc +++ b/src/World.cc @@ -4,122 +4,45 @@ #include "Internal.hh" -ZkWorld* ZkWorld_load(ZkRead* buf) { - ZKC_TRACE_FN(); - if (buf == nullptr) { - ZKC_LOG_WARN_NULL("ZkWorld_load"); - return nullptr; - } - - try { - ZkWorld obj {}; - obj.load(buf); - return ZKC_WRAP_NEW(obj); - } catch (std::exception const& exc) { - ZKC_LOG_ERROR("ZkWorld_load() failed: %s", exc.what()); - return nullptr; - } -} - -ZkWorld* ZkWorld_loadPath(ZkString path) { - ZKC_TRACE_FN(); - if (path == nullptr) { - ZKC_LOG_WARN_NULL("ZkWorld_loadPath"); - return nullptr; - } - - try { - auto buf = zenkit::Read::from(path); - - ZkWorld obj {}; - obj.load(buf.get()); - return ZKC_WRAP_NEW(obj); - } catch (std::exception const& exc) { - ZKC_LOG_ERROR("ZkWorld_loadPath() failed: %s", exc.what()); - return nullptr; - } -} - -ZkWorld* ZkWorld_loadVfs(ZkVfs* vfs, ZkString name) { - ZKC_TRACE_FN(); - if (vfs == nullptr || name == nullptr) { - ZKC_LOG_WARN_NULL("ZkWorld_loadVfs"); - return nullptr; - } - - auto node = vfs->find(name); - if (node == nullptr) return nullptr; - - auto rd = node->open_read(); - return ZkWorld_load(rd.get()); -} - -void ZkWorld_del(ZkWorld* slf) { - ZKC_TRACE_FN(); - delete slf; -} +ZKC_LOADER(ZkWorld); +ZKC_PATH_LOADER(ZkWorld); +ZKC_VFS_LOADER(ZkWorld); +ZKC_DELETER(ZkWorld); ZkMesh const* ZkWorld_getMesh(ZkWorld const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkWorld_getMesh"); - return nullptr; - } - + ZKC_CHECK_NULL(slf); return &slf->world_mesh; } ZkWayNet const* ZkWorld_getWayNet(ZkWorld const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkWorld_getWayNet"); - return nullptr; - } - + ZKC_CHECK_NULL(slf); return &slf->world_way_net; } ZkBspTree const* ZkWorld_getBspTree(ZkWorld const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkWorld_getBspTree"); - return nullptr; - } - + ZKC_CHECK_NULL(slf); return &slf->world_bsp_tree; } ZkSize ZkWorld_getRootObjectCount(ZkWorld const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkWorld_getRootObjectCount"); - return 0; - } - + ZKC_CHECK_NULL(slf); return slf->world_vobs.size(); } ZkVirtualObject const* ZkWorld_getRootObject(ZkWorld const* slf, ZkSize i) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkWorld_getRootObject"); - return nullptr; - } - - if (i >= slf->world_vobs.size()) { - ZKC_LOG_ERROR("ZkWorld_getRootObject() failed: index out of range"); - return nullptr; - } - + ZKC_CHECK_NULL(slf); + ZKC_CHECK_LEN(slf->world_vobs, i); return slf->world_vobs[i].get(); } void ZkWorld_enumerateRootObjects(ZkWorld const* slf, ZkVirtualObjectEnumerator cb, void* ctx) { ZKC_TRACE_FN(); - if (slf == nullptr || cb == nullptr) { - ZKC_LOG_WARN_NULL("ZkWorld_enumerateRootObjects"); - return; - } + ZKC_CHECK_NULLV(slf, cb); for (auto& obj : slf->world_vobs) { if (cb(ctx, obj.get())) break; diff --git a/src/world/BspTree.cc b/src/world/BspTree.cc index e26f89f..76f17d2 100644 --- a/src/world/BspTree.cc +++ b/src/world/BspTree.cc @@ -6,20 +6,13 @@ ZkBspTreeType ZkBspTree_getType(ZkBspTree const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkBspTree_getMode"); - return ZkBspTreeType_INDOOR; - } - + ZKC_CHECK_NULL(slf); return static_cast(slf->mode); } uint32_t const* ZkBspTree_getPolygonIndices(ZkBspTree const* slf, ZkSize* count) { ZKC_TRACE_FN(); - if (slf == nullptr || count == nullptr) { - ZKC_LOG_WARN_NULL("ZkBspTree_getPolygonIndices"); - return nullptr; - } + ZKC_CHECK_NULL(slf, count); *count = slf->polygon_indices.size(); return slf->polygon_indices.data(); @@ -27,10 +20,7 @@ uint32_t const* ZkBspTree_getPolygonIndices(ZkBspTree const* slf, ZkSize* count) uint32_t const* ZkBspTree_getLeafPolygonIndices(ZkBspTree const* slf, ZkSize* count) { ZKC_TRACE_FN(); - if (slf == nullptr || count == nullptr) { - ZKC_LOG_WARN_NULL("ZkBspTree_getLeafPolygonIndices"); - return nullptr; - } + ZKC_CHECK_NULL(slf, count); *count = slf->leaf_polygons.size(); return slf->leaf_polygons.data(); @@ -38,10 +28,7 @@ uint32_t const* ZkBspTree_getLeafPolygonIndices(ZkBspTree const* slf, ZkSize* co uint32_t const* ZkBspTree_getPortalPolygonIndices(ZkBspTree const* slf, ZkSize* count) { ZKC_TRACE_FN(); - if (slf == nullptr || count == nullptr) { - ZKC_LOG_WARN_NULL("ZkBspTree_getPortalPolygonIndices"); - return nullptr; - } + ZKC_CHECK_NULL(slf, count); *count = slf->portal_polygon_indices.size(); return slf->portal_polygon_indices.data(); @@ -71,10 +58,7 @@ void ZkBspTree_enumerateLightPoints(ZkBspTree const* slf, ZkVec3fEnumerator cb, uint64_t const* ZkBspTree_getLeafNodeIndices(ZkBspTree const* slf, ZkSize* count) { ZKC_TRACE_FN(); - if (slf == nullptr || count == nullptr) { - ZKC_LOG_WARN_NULL("ZkBspTree_getLeafNodeIndices"); - return nullptr; - } + ZKC_CHECK_NULL(slf, count); *count = slf->leaf_node_indices.size(); return slf->leaf_node_indices.data(); @@ -107,35 +91,20 @@ void ZkBspTree_enumerateNodes(ZkBspTree const* slf, ZkBspNodeEnumerator cb, void ZkSize ZkBspTree_getSectorCount(ZkBspTree const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkBspTree_getSectorCount"); - return 0; - } - + ZKC_CHECK_NULL(slf); return slf->sectors.size(); } ZkBspSector const* ZkBspTree_getSector(ZkBspTree const* slf, ZkSize i) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkBspTree_getSector"); - return nullptr; - } - - if (i >= slf->sectors.size()) { - ZKC_LOG_ERROR("ZkBspTree_getSector() failed: index out of range"); - return nullptr; - } - + ZKC_CHECK_NULL(slf); + ZKC_CHECK_LEN(slf->sectors, i); return &slf->sectors[i]; } void ZkBspTree_enumerateSectors(ZkBspTree const* slf, ZkBspSectorEnumerator cb, void* ctx) { ZKC_TRACE_FN(); - if (slf == nullptr || cb == nullptr) { - ZKC_LOG_WARN_NULL("ZkBspTree_enumerateSectors"); - return; - } + ZKC_CHECK_NULLV(slf, cb); for (auto& sector : slf->sectors) { if (cb(ctx, §or)) break; @@ -144,20 +113,13 @@ void ZkBspTree_enumerateSectors(ZkBspTree const* slf, ZkBspSectorEnumerator cb, ZkString ZkBspSector_getName(ZkBspSector const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkBspSector_getName"); - return nullptr; - } - + ZKC_CHECK_NULL(slf); return slf->name.c_str(); } uint32_t const* ZkBspSector_getNodeIndices(ZkBspSector const* slf, ZkSize* count) { ZKC_TRACE_FN(); - if (slf == nullptr || count == nullptr) { - ZKC_LOG_WARN_NULL("ZkBspSector_getNodeIndices"); - return nullptr; - } + ZKC_CHECK_NULL(slf, count); *count = slf->node_indices.size(); return slf->node_indices.data(); @@ -165,10 +127,7 @@ uint32_t const* ZkBspSector_getNodeIndices(ZkBspSector const* slf, ZkSize* count uint32_t const* ZkBspSector_getPortalPolygonIndices(ZkBspSector const* slf, ZkSize* count) { ZKC_TRACE_FN(); - if (slf == nullptr || count == nullptr) { - ZKC_LOG_WARN_NULL("ZkBspSector_getPortalPolygonIndices"); - return nullptr; - } + ZKC_CHECK_NULL(slf, count); *count = slf->portal_polygon_indices.size(); return slf->portal_polygon_indices.data(); diff --git a/src/world/WayNet.cc b/src/world/WayNet.cc index 3e425ef..f4e87be 100644 --- a/src/world/WayNet.cc +++ b/src/world/WayNet.cc @@ -6,10 +6,7 @@ ZkWayEdge const* ZkWayNet_getEdges(ZkWayNet const* slf, ZkSize* count) { ZKC_TRACE_FN(); - if (slf == nullptr || count == nullptr) { - ZKC_LOG_WARN_NULL("ZkWayNet_getEdges"); - return nullptr; - } + ZKC_CHECK_NULL(slf, count); *count = slf->edges.size(); return slf->edges.data(); @@ -17,35 +14,20 @@ ZkWayEdge const* ZkWayNet_getEdges(ZkWayNet const* slf, ZkSize* count) { ZkSize ZkWayNet_getPointCount(ZkWayNet const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkWayNet_getPointCount"); - return 0; - } - + ZKC_CHECK_NULL(slf); return slf->waypoints.size(); } ZkWayPoint const* ZkWayNet_getPoint(ZkWayNet const* slf, ZkSize i) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkWayNet_getPoint"); - return nullptr; - } - - if (i >= slf->waypoints.size()) { - ZKC_LOG_ERROR("ZkWayNet_getPoint() failed: index out of range"); - return nullptr; - } - + ZKC_CHECK_NULL(slf); + ZKC_CHECK_LEN(slf->waypoints, i); return &slf->waypoints[i]; } void ZkWayNet_enumeratePoints(ZkWayNet const* slf, ZkWayPointEnumerator cb, void* ctx) { ZKC_TRACE_FN(); - if (slf == nullptr || cb == nullptr) { - ZKC_LOG_WARN_NULL("ZkWayNet_enumeratePoints"); - return; - } + ZKC_CHECK_NULLV(slf, cb); for (auto& point : slf->waypoints) { if (cb(ctx, &point)) break; @@ -54,60 +36,36 @@ void ZkWayNet_enumeratePoints(ZkWayNet const* slf, ZkWayPointEnumerator cb, void ZkString ZkWayPoint_getName(ZkWayPoint const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkWayPoint_getName"); - return nullptr; - } - + ZKC_CHECK_NULL(slf); return slf->name.c_str(); } int32_t ZkWayPoint_getWaterDepth(ZkWayPoint const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkWayPoint_getWaterDepth"); - return 0; - } - + ZKC_CHECK_NULL(slf); return slf->water_depth; } ZkBool ZkWayPoint_getUnderWater(ZkWayPoint const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkWayPoint_getUnderWater"); - return 0; - } - + ZKC_CHECK_NULL(slf); return slf->under_water; } ZkVec3f ZkWayPoint_getPosition(ZkWayPoint const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkWayPoint_getPosition"); - return {}; - } - + ZKC_CHECK_NULL(slf); return slf->position; } ZkVec3f ZkWayPoint_getDirection(ZkWayPoint const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkWayPoint_getDirection"); - return {}; - } - + ZKC_CHECK_NULL(slf); return slf->direction; } ZkBool ZkWayPoint_getFreePoint(ZkWayPoint const* slf) { ZKC_TRACE_FN(); - if (slf == nullptr) { - ZKC_LOG_WARN_NULL("ZkWayPoint_getFreePoint"); - return {}; - } - + ZKC_CHECK_NULL(slf); return slf->free_point; }