diff --git a/src/engine/model/md5.cpp b/src/engine/model/md5.cpp index e3bcd21a9..70d22576f 100644 --- a/src/engine/model/md5.cpp +++ b/src/engine/model/md5.cpp @@ -15,6 +15,8 @@ #include "../../shared/hashtable.h" #include "../../shared/stream.h" +#include + #include "render/rendergl.h" #include "render/rendermodel.h" #include "render/renderwindow.h" diff --git a/src/engine/model/skelmodel.cpp b/src/engine/model/skelmodel.cpp index e3e54e8ea..583e3aa2b 100644 --- a/src/engine/model/skelmodel.cpp +++ b/src/engine/model/skelmodel.cpp @@ -15,6 +15,7 @@ #include "../../shared/glexts.h" #include "../../shared/hashtable.h" +#include #include "interface/console.h" #include "interface/control.h" @@ -125,7 +126,7 @@ skelmodel::skelanimspec &skelmodel::skeleton::addskelanim(const char *name) return skelanims.back(); } -int skelmodel::skeleton::findbone(const char *name) const +std::optional skelmodel::skeleton::findbone(const char *name) const { for(int i = 0; i < numbones; ++i) { @@ -134,7 +135,7 @@ int skelmodel::skeleton::findbone(const char *name) const return i; } } - return -1; + return std::nullopt; } int skelmodel::skeleton::findtag(const char *name) const diff --git a/src/engine/model/skelmodel.h b/src/engine/model/skelmodel.h index fffbd7ac8..d8995dffb 100644 --- a/src/engine/model/skelmodel.h +++ b/src/engine/model/skelmodel.h @@ -330,7 +330,7 @@ struct skelmodel : animmodel const skelanimspec *findskelanim(const char *name, char sep = '\0') const; skelanimspec &addskelanim(const char *name); - int findbone(const char *name) const; + std::optional findbone(const char *name) const; int findtag(const char *name) const; bool addtag(const char *name, int bone, const matrix4x3 &matrix); void addpitchdep(int bone, int frame); @@ -645,15 +645,15 @@ struct skelcommands : modelcommands return; } part &mdl = *static_cast(MDL::loading->parts.back()); - int i = mdl.meshes ? static_cast(mdl.meshes)->skel->findbone(name) : -1; - if(i >= 0) + std::optional i = mdl.meshes ? static_cast(mdl.meshes)->skel->findbone(name) : std::nullopt; + if(i) { float cx = *rx ? std::cos(*rx/(2*RAD)) : 1, sx = *rx ? std::sin(*rx/(2*RAD)) : 0, cy = *ry ? std::cos(*ry/(2*RAD)) : 1, sy = *ry ? std::sin(*ry/(2*RAD)) : 0, cz = *rz ? std::cos(*rz/(2*RAD)) : 1, sz = *rz ? std::sin(*rz/(2*RAD)) : 0; matrix4x3 m(matrix3(quat(sx*cy*cz - cx*sy*sz, cx*sy*cz + sx*cy*sz, cx*cy*sz - sx*sy*cz, cx*cy*cz + sx*sy*sz)), vec(*tx, *ty, *tz)); - static_cast(mdl.meshes)->skel->addtag(tagname, i, m); + static_cast(mdl.meshes)->skel->addtag(tagname, *i, m); return; } conoutf("could not find bone %s for tag %s", name, tagname); @@ -672,10 +672,10 @@ struct skelcommands : modelcommands if(name[0]) { - int i = mdl.meshes ? static_cast(mdl.meshes)->skel->findbone(name) : -1; - if(i>=0) + std::optional i = mdl.meshes ? static_cast(mdl.meshes)->skel->findbone(name) : std::nullopt; + if(i) { - boneinfo &b = static_cast(mdl.meshes)->skel->bones[i]; + boneinfo &b = static_cast(mdl.meshes)->skel->bones[*i]; b.pitchscale = *pitchscale; b.pitchoffset = *pitchoffset; if(*pitchmin || *pitchmax) @@ -728,21 +728,21 @@ struct skelcommands : modelcommands return; } skeleton *skel = static_cast(mdl.meshes)->skel; - int bone = skel ? skel->findbone(name) : -1; - if(bone < 0) + std::optional bone = skel ? skel->findbone(name) : std::nullopt; + if(!bone) { conoutf("could not find bone %s to pitch target", name); return; } for(uint i = 0; i < skel->pitchtargets.size(); i++) { - if(skel->pitchtargets[i].bone == bone) + if(skel->pitchtargets[i].bone == *bone) { return; } } pitchtarget t; - t.bone = bone; + t.bone = *bone; t.frame = sa->frame + std::clamp(*frameoffset, 0, sa->range-1); t.pitchmin = *pitchmin; t.pitchmax = *pitchmax; @@ -762,37 +762,37 @@ struct skelcommands : modelcommands return; } skeleton *skel = static_cast(mdl.meshes)->skel; - int bone = skel ? skel->findbone(name) : -1; - if(bone < 0) + std::optional bone = skel ? skel->findbone(name) : std::nullopt; + if(!bone) { conoutf("could not find bone %s to pitch correct", name); return; } - if(skel->findpitchcorrect(bone) >= 0) + if(skel->findpitchcorrect(*bone) >= 0) { return; } - int targetbone = skel->findbone(targetname), - target = -1; - if(targetbone >= 0) + std::optional targetbone = skel->findbone(targetname), + target = std::nullopt; + if(targetbone) { for(uint i = 0; i < skel->pitchtargets.size(); i++) { - if(skel->pitchtargets[i].bone == targetbone) + if(skel->pitchtargets[i].bone == *targetbone) { target = i; break; } } } - if(target < 0) + if(!target) { conoutf("could not find pitch target %s to pitch correct %s", targetname, name); return; } pitchcorrect c; - c.bone = bone; - c.target = target; + c.bone = *bone; + c.target = *target; c.pitchmin = *pitchmin; c.pitchmax = *pitchmax; c.pitchscale = *scale; @@ -880,8 +880,8 @@ struct skelcommands : modelcommands for(uint i = 0; i < bonestrs.size(); i++) { char *bonestr = bonestrs[i]; - int bone = p->meshes ? static_cast(p->meshes)->skel->findbone(bonestr[0]=='!' ? bonestr+1 : bonestr) : -1; - if(bone<0) + std::optional bone = p->meshes ? static_cast(p->meshes)->skel->findbone(bonestr[0]=='!' ? bonestr+1 : bonestr) : std::nullopt; + if(!bone) { conoutf("could not find bone %s for anim part mask [%s]", bonestr, maskstr); for(char* j : bonestrs) @@ -890,7 +890,7 @@ struct skelcommands : modelcommands } return; } - bonemask.push_back(bone | (bonestr[0]=='!' ? Bonemask_Not : 0)); + bonemask.push_back(*bone | (bonestr[0]=='!' ? Bonemask_Not : 0)); } for(char* i : bonestrs) { @@ -919,17 +919,17 @@ struct skelcommands : modelcommands { return; } - int i = mdl.meshes ? static_cast(mdl.meshes)->skel->findbone(name) : -1; - if(i < 0) + std::optional i = mdl.meshes ? static_cast(mdl.meshes)->skel->findbone(name) : std::nullopt; + if(!i) { conoutf("could not find bone %s to adjust", name); return; } - while(!(static_cast(MDL::adjustments.size()) > i)) + while(!(static_cast(MDL::adjustments.size()) > *i)) { MDL::adjustments.push_back(skeladjustment(0, 0, 0, vec(0, 0, 0))); } - MDL::adjustments[i] = skeladjustment(*yaw, *pitch, *roll, vec(*tx/4, *ty/4, *tz/4)); + MDL::adjustments[*i] = skeladjustment(*yaw, *pitch, *roll, vec(*tx/4, *ty/4, *tz/4)); } static void sethitzone(int *id, char *maskstr) @@ -956,8 +956,8 @@ struct skelcommands : modelcommands for(uint i = 0; i < bonestrs.size(); i++) { char *bonestr = bonestrs[i]; - int bone = p->meshes ? static_cast(p->meshes)->skel->findbone(bonestr[0]=='!' ? bonestr+1 : bonestr) : -1; - if(bone<0) + std::optional bone = p->meshes ? static_cast(p->meshes)->skel->findbone(bonestr[0]=='!' ? bonestr+1 : bonestr) : std::nullopt; + if(!bone) { conoutf("could not find bone %s for hit zone mask [%s]", bonestr, maskstr); for(char* j : bonestrs) @@ -966,7 +966,7 @@ struct skelcommands : modelcommands } return; } - bonemask.push_back(bone | (bonestr[0]=='!' ? Bonemask_Not : 0)); + bonemask.push_back(*bone | (bonestr[0]=='!' ? Bonemask_Not : 0)); } for(char* i : bonestrs) { diff --git a/src/engine/render/rendermodel.cpp b/src/engine/render/rendermodel.cpp index a9a7114f8..66877417d 100644 --- a/src/engine/render/rendermodel.cpp +++ b/src/engine/render/rendermodel.cpp @@ -13,6 +13,8 @@ #include "../../shared/hashtable.h" #include "../../shared/stream.h" +#include + #include "aa.h" #include "csm.h" #include "radiancehints.h"