Skip to content

Commit

Permalink
refactor(VirtualObject): simplify null-paramater check
Browse files Browse the repository at this point in the history
  • Loading branch information
lmichaelis committed Dec 5, 2023
1 parent 189d05a commit c285d10
Showing 1 changed file with 32 additions and 158 deletions.
190 changes: 32 additions & 158 deletions src/vobs/VirtualObject.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
#include <zenkit/Archive.hh>

ZkVirtualObject* ZkVirtualObject_load(ZkRead* buf, ZkGameVersion version) {
if (buf == nullptr) {
ZKC_LOG_WARN_NULL("ZkVirtualObject_load");
return nullptr;
}
ZKC_CHECK_NULL(buf);

try {
auto ar = zenkit::ReadArchive::from(buf);
Expand All @@ -28,10 +25,7 @@ ZkVirtualObject* ZkVirtualObject_load(ZkRead* buf, ZkGameVersion version) {
}

ZkVirtualObject* ZkVirtualObject_loadPath(ZkString path, ZkGameVersion version) {
if (path == nullptr) {
ZKC_LOG_WARN_NULL("ZkVirtualObject_loadPath");
return nullptr;
}
ZKC_CHECK_NULL(path);

try {
auto buf = zenkit::Read::from(path);
Expand All @@ -54,173 +48,97 @@ void ZkVirtualObject_del(ZkVirtualObject* slf) {
}

ZkVobType ZkVirtualObject_getType(ZkVirtualObject const* slf) {
if (slf == nullptr) {
ZKC_LOG_WARN_NULL("ZkVirtualObject_getType");
return {};
}

ZKC_CHECK_NULL(slf);
return static_cast<ZkVobType>(slf->type);
}

uint32_t ZkVirtualObject_getId(ZkVirtualObject const* slf) {
if (slf == nullptr) {
ZKC_LOG_WARN_NULL("ZkVirtualObject_getId");
return {};
}

ZKC_CHECK_NULL(slf);
return slf->id;
}

ZkAxisAlignedBoundingBox ZkVirtualObject_getBbox(ZkVirtualObject const* slf) {
if (slf == nullptr) {
ZKC_LOG_WARN_NULL("ZkAxisAlignedBoundingBox");
return {};
}

ZKC_CHECK_NULL(slf);
return slf->bbox;
}

ZkVec3f ZkVirtualObject_getPosition(ZkVirtualObject const* slf) {
if (slf == nullptr) {
ZKC_LOG_WARN_NULL("ZkVirtualObject_getPosition");
return {};
}

ZKC_CHECK_NULL(slf);
return slf->position;
}

ZkMat3x3 ZkVirtualObject_getRotation(ZkVirtualObject const* slf) {
if (slf == nullptr) {
ZKC_LOG_WARN_NULL("ZkVirtualObject_getRotation");
return {};
}

ZKC_CHECK_NULL(slf);
return slf->rotation;
}

ZkBool ZkVirtualObject_getShowVisual(ZkVirtualObject const* slf) {
if (slf == nullptr) {
ZKC_LOG_WARN_NULL("ZkVirtualObject_getShowVisual");
return {};
}

ZKC_CHECK_NULL(slf);
return slf->show_visual;
}

ZkSpriteAlignment ZkVirtualObject_getSpriteCameraFacingMode(ZkVirtualObject const* slf) {
if (slf == nullptr) {
ZKC_LOG_WARN_NULL("ZkVirtualObject_getSpriteCameraFacingMode");
return {};
}

ZKC_CHECK_NULL(slf);
return static_cast<ZkSpriteAlignment>(slf->sprite_camera_facing_mode);
}

ZkBool ZkVirtualObject_getCdStatic(ZkVirtualObject const* slf) {
if (slf == nullptr) {
ZKC_LOG_WARN_NULL("ZkVirtualObject_getCdStatic");
return {};
}

ZKC_CHECK_NULL(slf);
return slf->cd_static;
}

ZkBool ZkVirtualObject_getCdDynamic(ZkVirtualObject const* slf) {
if (slf == nullptr) {
ZKC_LOG_WARN_NULL("ZkVirtualObject_getCdDynamic");
return {};
}

ZKC_CHECK_NULL(slf);
return slf->cd_dynamic;
}

ZkBool ZkVirtualObject_getVobStatic(ZkVirtualObject const* slf) {
if (slf == nullptr) {
ZKC_LOG_WARN_NULL("ZkVirtualObject_getVobStatic");
return {};
}

ZKC_CHECK_NULL(slf);
return slf->vob_static;
}

ZkShadowType ZkVirtualObject_getDynamicShadows(ZkVirtualObject const* slf) {
if (slf == nullptr) {
ZKC_LOG_WARN_NULL("ZkVirtualObject_getDynamicShadows");
return {};
}

ZKC_CHECK_NULL(slf);
return static_cast<ZkShadowType>(slf->dynamic_shadows);
}

ZkBool ZkVirtualObject_getPhysicsEnabled(ZkVirtualObject const* slf) {
if (slf == nullptr) {
ZKC_LOG_WARN_NULL("ZkVirtualObject_getPhysicsEnabled");
return {};
}

ZKC_CHECK_NULL(slf);
return slf->physics_enabled;
}

ZkAnimationType ZkVirtualObject_getAnimMode(ZkVirtualObject const* slf) {
if (slf == nullptr) {
ZKC_LOG_WARN_NULL("ZkVirtualObject_getAnimMode");
return {};
}

ZKC_CHECK_NULL(slf);
return static_cast<ZkAnimationType>(slf->anim_mode);
}

int32_t ZkVirtualObject_getBias(ZkVirtualObject const* slf) {
if (slf == nullptr) {
ZKC_LOG_WARN_NULL("ZkVirtualObject_getBias");
return {};
}

ZKC_CHECK_NULL(slf);
return slf->bias;
}

ZkBool ZkVirtualObject_getAmbient(ZkVirtualObject const* slf) {
if (slf == nullptr) {
ZKC_LOG_WARN_NULL("ZkVirtualObject_getAmbient");
return {};
}

ZKC_CHECK_NULL(slf);
return slf->ambient;
}

float ZkVirtualObject_getAnimStrength(ZkVirtualObject const* slf) {
if (slf == nullptr) {
ZKC_LOG_WARN_NULL("ZkVirtualObject_getAnimStrength");
return {};
}

ZKC_CHECK_NULL(slf);
return slf->anim_strength;
}

float ZkVirtualObject_getFarClipScale(ZkVirtualObject const* slf) {
if (slf == nullptr) {
ZKC_LOG_WARN_NULL("ZkVirtualObject_getFarClipScale");
return {};
}

ZKC_CHECK_NULL(slf);
return slf->far_clip_scale;
}

ZkString ZkVirtualObject_getPresetName(ZkVirtualObject const* slf) {
if (slf == nullptr) {
ZKC_LOG_WARN_NULL("ZkVirtualObject_getPresetName");
return {};
}

ZKC_CHECK_NULL(slf);
return slf->preset_name.c_str();
}

ZkString ZkVirtualObject_getName(ZkVirtualObject const* slf) {
if (slf == nullptr) {
ZKC_LOG_WARN_NULL("ZkVirtualObject_getName");
return {};
}

ZKC_CHECK_NULL(slf);
return slf->vob_name.c_str();
}

Expand All @@ -230,25 +148,13 @@ ZkVisual const* ZkVirtualObject_getVisual(ZkVirtualObject const* slf) {
}

ZkSize ZkVirtualObject_getChildCount(ZkVirtualObject const* slf) {
if (slf == nullptr) {
ZKC_LOG_WARN_NULL("ZkVirtualObject_getChildCount");
return 0;
}

ZKC_CHECK_NULL(slf);
return slf->children.size();
}

ZkVirtualObject const* ZkVirtualObject_getChild(ZkVirtualObject const* slf, ZkSize i) {
if (slf == nullptr) {
ZKC_LOG_WARN_NULL("ZkVirtualObject_getChild");
return nullptr;
}

if (i >= slf->children.size()) {
ZKC_LOG_ERROR("ZkVirtualObject_getChild() failed: index out of range");
return nullptr;
}

ZKC_CHECK_NULL(slf);
ZKC_CHECK_LEN(slf->children, i);
return slf->children[i].get();
}

Expand All @@ -274,73 +180,41 @@ ZkVisualType ZkVisual_getType(ZkVisual const* slf) {
}

ZkString ZkDecal_getName(ZkDecal const* slf) {
if (slf == nullptr) {
ZKC_LOG_WARN_NULL("ZkDecal_getName");
return {};
}

ZKC_CHECK_NULL(slf);
return slf->name.c_str();
}

ZkVec2f ZkDecal_getDimension(ZkDecal const* slf) {
if (slf == nullptr) {
ZKC_LOG_WARN_NULL("ZkDecal_getDimension");
return {};
}

ZKC_CHECK_NULL(slf);
return slf->dimension;
}

ZkVec2f ZkDecal_getOffset(ZkDecal const* slf) {
if (slf == nullptr) {
ZKC_LOG_WARN_NULL("ZkDecal_getOffset");
return {};
}

ZKC_CHECK_NULL(slf);
return slf->offset;
}

ZkBool ZkDecal_getTwoSided(ZkDecal const* slf) {
if (slf == nullptr) {
ZKC_LOG_WARN_NULL("ZkDecal_getTwoSided");
return {};
}

ZKC_CHECK_NULL(slf);
return slf->two_sided;
}

ZkAlphaFunction ZkDecal_getAlphaFunc(ZkDecal const* slf) {
if (slf == nullptr) {
ZKC_LOG_WARN_NULL("ZkDecal_getAlphaFunc");
return {};
}

ZKC_CHECK_NULL(slf);
return static_cast<ZkAlphaFunction>(slf->alpha_func);
}

float ZkDecal_getTextureAnimFps(ZkDecal const* slf) {
if (slf == nullptr) {
ZKC_LOG_WARN_NULL("ZkDecal_getTextureAnimFps");
return {};
}

ZKC_CHECK_NULL(slf);
return slf->texture_anim_fps;
}

uint8_t ZkDecal_getAlphaWeight(ZkDecal const* slf) {
if (slf == nullptr) {
ZKC_LOG_WARN_NULL("ZkDecal_getAlphaWeight");
return {};
}

ZKC_CHECK_NULL(slf);
return slf->alpha_weight;
}

ZkBool ZkDecal_getIgnoreDaylight(ZkDecal const* slf) {
if (slf == nullptr) {
ZKC_LOG_WARN_NULL("ZkDecal_getIgnoreDaylight");
return {};
}

ZKC_CHECK_NULL(slf);
return slf->ignore_daylight;
}

0 comments on commit c285d10

Please sign in to comment.