Skip to content

Commit

Permalink
std::optional in skeleton::findpitchcorrect (#268)
Browse files Browse the repository at this point in the history
  • Loading branch information
no-lex committed Aug 16, 2024
1 parent eb908af commit 5f1814d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 7 additions & 5 deletions src/engine/model/skelmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,16 +432,16 @@ std::optional<size_t> skelmodel::skeleton::findpitchdep(int bone) const
return std::nullopt;
}

int skelmodel::skeleton::findpitchcorrect(int bone) const
std::optional<size_t> skelmodel::skeleton::findpitchcorrect(int bone) const
{
for(uint i = 0; i < pitchcorrects.size(); i++)
{
if(bone <= pitchcorrects[i].bone)
{
return bone == pitchcorrects[i].bone ? i : -1;
return bone == pitchcorrects[i].bone ? std::optional<uint>(i) : std::optional<uint>(std::nullopt);
}
}
return -1;
return std::nullopt;
}

void skelmodel::skeleton::initpitchdeps()
Expand Down Expand Up @@ -480,7 +480,8 @@ void skelmodel::skeleton::initpitchdeps()
t.corrects = -1;
for(int parent = t.bone; parent >= 0; parent = bones[parent].parent)
{
t.corrects = findpitchcorrect(parent);
std::optional<size_t> newpitchcorrect = findpitchcorrect(parent);
t.corrects = newpitchcorrect ? newpitchcorrect.value() : -1;
if(t.corrects >= 0)
{
break;
Expand All @@ -499,7 +500,8 @@ void skelmodel::skeleton::initpitchdeps()
{
break;
}
c.parent = findpitchcorrect(parent);
std::optional<size_t> newpitchcorrect = findpitchcorrect(parent);
c.parent = newpitchcorrect ? newpitchcorrect.value() : -1;
if(c.parent >= 0)
{
break;
Expand Down
2 changes: 1 addition & 1 deletion src/engine/model/skelmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ struct skelmodel : animmodel
bool addtag(std::string_view name, int bone, const matrix4x3 &matrix);
void addpitchdep(int bone, int frame);
std::optional<size_t> findpitchdep(int bone) const;
int findpitchcorrect(int bone) const;
std::optional<size_t> findpitchcorrect(int bone) const;
void initpitchdeps();
void optimize();
void expandbonemask(uchar *expansion, int bone, int val) const;
Expand Down

0 comments on commit 5f1814d

Please sign in to comment.