CCharAnimTime: Fixes & cleanup

This commit is contained in:
Luke Street 2020-03-09 12:09:54 -04:00
parent 5c9dd55b80
commit 24817d6b01
1 changed files with 35 additions and 56 deletions

View File

@ -1,22 +1,18 @@
#include "Runtime/Character/CCharAnimTime.hpp" #include "Runtime/Character/CCharAnimTime.hpp"
#include <algorithm>
#include <cmath> #include <cmath>
#include <cfloat>
namespace urde { namespace urde {
CCharAnimTime CCharAnimTime::Infinity() { CCharAnimTime CCharAnimTime::Infinity() {
CCharAnimTime ret(1.f); return {EType::Infinity, 1.f};
ret.x4_type = EType::Infinity;
return ret;
} }
bool CCharAnimTime::EqualsZero() const { bool CCharAnimTime::EqualsZero() const {
if (x4_type == EType::ZeroIncreasing || x4_type == EType::ZeroSteady || x4_type == EType::ZeroDecreasing) if (x4_type == EType::ZeroIncreasing || x4_type == EType::ZeroSteady || x4_type == EType::ZeroDecreasing)
return true; return true;
return (x0_time == 0.f); return x0_time == 0.f;
} }
bool CCharAnimTime::EpsilonZero() const { return (std::fabs(x0_time) < 0.00001f); } bool CCharAnimTime::EpsilonZero() const { return (std::fabs(x0_time) < 0.00001f); }
@ -24,7 +20,7 @@ bool CCharAnimTime::EpsilonZero() const { return (std::fabs(x0_time) < 0.00001f)
bool CCharAnimTime::GreaterThanZero() const { bool CCharAnimTime::GreaterThanZero() const {
if (EqualsZero()) if (EqualsZero())
return false; return false;
return (x0_time > 0.f); return x0_time > 0.f;
} }
bool CCharAnimTime::operator==(const CCharAnimTime& other) const { bool CCharAnimTime::operator==(const CCharAnimTime& other) const {
@ -69,14 +65,14 @@ bool CCharAnimTime::operator>=(const CCharAnimTime& other) const {
if (*this == other) if (*this == other)
return true; return true;
return (*this > other); return *this > other;
} }
bool CCharAnimTime::operator<=(const CCharAnimTime& other) const { bool CCharAnimTime::operator<=(const CCharAnimTime& other) const {
if (*this == other) if (*this == other)
return true; return true;
return (*this < other); return *this < other;
} }
bool CCharAnimTime::operator>(const CCharAnimTime& other) const { return (!(*this == other) && !(*this < other)); } bool CCharAnimTime::operator>(const CCharAnimTime& other) const { return (!(*this == other) && !(*this < other)); }
@ -123,19 +119,17 @@ bool CCharAnimTime::operator<(const CCharAnimTime& other) const {
} }
CCharAnimTime& CCharAnimTime::operator*=(const CCharAnimTime& other) { CCharAnimTime& CCharAnimTime::operator*=(const CCharAnimTime& other) {
*this = *this * other; return *this = *this * other;
return *this;
} }
CCharAnimTime& CCharAnimTime::operator+=(const CCharAnimTime& other) { CCharAnimTime& CCharAnimTime::operator+=(const CCharAnimTime& other) {
*this = *this + other; return *this = *this + other;
return *this;
} }
CCharAnimTime CCharAnimTime::operator+(const CCharAnimTime& other) const { CCharAnimTime CCharAnimTime::operator+(const CCharAnimTime& other) const {
if (x4_type == EType::Infinity && other.x4_type == EType::Infinity) { if (x4_type == EType::Infinity && other.x4_type == EType::Infinity) {
if (other.x0_time != x0_time) if (other.x0_time != x0_time)
return CCharAnimTime(); return {};
return *this; return *this;
} else if (x4_type == EType::Infinity) } else if (x4_type == EType::Infinity)
return *this; return *this;
@ -143,58 +137,46 @@ CCharAnimTime CCharAnimTime::operator+(const CCharAnimTime& other) const {
return other; return other;
if (!EqualsZero() || !other.EqualsZero()) if (!EqualsZero() || !other.EqualsZero())
return CCharAnimTime(x0_time + other.x0_time); return {x0_time + other.x0_time};
int type = -1; int type = -1;
if (x4_type != EType::ZeroDecreasing) { if (x4_type != EType::ZeroDecreasing) {
if (x4_type != EType::ZeroSteady) type = x4_type == EType::ZeroSteady ? 0 : 1;
type = 1;
else
type = 0;
} }
int otherType = -1; int otherType = -1;
if (other.x4_type != EType::ZeroDecreasing) { if (other.x4_type != EType::ZeroDecreasing) {
if (other.x4_type != EType::ZeroSteady) otherType = other.x4_type == EType::ZeroSteady ? 0 : 1;
otherType = 1;
else
otherType = 0;
} }
type += otherType; type += otherType;
otherType = std::max(-1, std::min(type, 1)); otherType = std::max(-1, std::min(type, 1));
CCharAnimTime ret;
if (otherType == -1) if (otherType == -1)
ret.x4_type = EType::ZeroDecreasing; return {EType::ZeroDecreasing, 0.f};
else if (otherType == 0) else if (otherType == 0)
ret.x4_type = EType::ZeroSteady; return {EType::ZeroSteady, 0.f};
else else
ret.x4_type = EType::ZeroIncreasing; return {EType::ZeroIncreasing, 0.f};
return ret;
} }
CCharAnimTime& CCharAnimTime::operator-=(const CCharAnimTime& other) { CCharAnimTime& CCharAnimTime::operator-=(const CCharAnimTime& other) {
*this = *this - other; return *this = *this - other;
return *this;
} }
CCharAnimTime CCharAnimTime::operator-(const CCharAnimTime& other) const { CCharAnimTime CCharAnimTime::operator-(const CCharAnimTime& other) const {
if (x4_type == EType::Infinity && other.x4_type == EType::Infinity) { if (x4_type == EType::Infinity && other.x4_type == EType::Infinity) {
if (other.x0_time == x0_time) if (other.x0_time == x0_time)
return CCharAnimTime(); return {};
return *this; return *this;
} else if (x4_type == EType::Infinity) } else if (x4_type == EType::Infinity)
return *this; return *this;
else if (other.x4_type == EType::Infinity) { else if (other.x4_type == EType::Infinity) {
CCharAnimTime ret(-other.x0_time); return {EType::Infinity, -other.x0_time};
ret.x4_type = EType::Infinity;
return ret;
} }
if (!EqualsZero() || !other.EqualsZero()) if (!EqualsZero() || !other.EqualsZero())
return CCharAnimTime(x0_time - other.x0_time); return {x0_time - other.x0_time};
int type = -1; int type = -1;
if (x4_type != EType::ZeroDecreasing) { if (x4_type != EType::ZeroDecreasing) {
@ -212,22 +194,19 @@ CCharAnimTime CCharAnimTime::operator-(const CCharAnimTime& other) const {
otherType = 0; otherType = 0;
} }
CCharAnimTime ret;
type -= otherType; type -= otherType;
if (type == -1) if (type == -1)
ret.x4_type = EType::ZeroDecreasing; return {EType::ZeroDecreasing, 0.f};
else if (type == 0) else if (type == 0)
ret.x4_type = EType::ZeroSteady; return {EType::ZeroSteady, 0.f};
else else
ret.x4_type = EType::ZeroIncreasing; return {EType::ZeroIncreasing, 0.f};
return ret;
} }
CCharAnimTime CCharAnimTime::operator*(const CCharAnimTime& other) const { CCharAnimTime CCharAnimTime::operator*(const CCharAnimTime& other) const {
if (x4_type == EType::Infinity && other.x4_type == EType::Infinity) { if (x4_type == EType::Infinity && other.x4_type == EType::Infinity) {
if (other.x0_time != x0_time) if (other.x0_time != x0_time)
return CCharAnimTime(); return {};
return *this; return *this;
} else if (x4_type == EType::Infinity) } else if (x4_type == EType::Infinity)
return *this; return *this;
@ -235,7 +214,7 @@ CCharAnimTime CCharAnimTime::operator*(const CCharAnimTime& other) const {
return other; return other;
if (!EqualsZero() || !other.EqualsZero()) if (!EqualsZero() || !other.EqualsZero())
return CCharAnimTime(x0_time * other.x0_time); return {x0_time * other.x0_time};
int type = -1; int type = -1;
if (x4_type != EType::ZeroDecreasing) { if (x4_type != EType::ZeroDecreasing) {
@ -256,31 +235,31 @@ CCharAnimTime CCharAnimTime::operator*(const CCharAnimTime& other) const {
type += otherType; type += otherType;
otherType = std::max(-1, std::min(type, 1)); otherType = std::max(-1, std::min(type, 1));
CCharAnimTime ret;
if (otherType == -1) if (otherType == -1)
ret.x4_type = EType::ZeroDecreasing; return {EType::ZeroDecreasing, 0.f};
else if (otherType == 0) else if (otherType == 0)
ret.x4_type = EType::ZeroSteady; return {EType::ZeroSteady, 0.f};
else else
ret.x4_type = EType::ZeroIncreasing; return {EType::ZeroIncreasing, 0.f};
return ret;
} }
CCharAnimTime CCharAnimTime::operator*(const float& other) const { CCharAnimTime CCharAnimTime::operator*(const float& other) const {
CCharAnimTime ret;
if (other == 0.f) if (other == 0.f)
return ret; return {};
if (!EqualsZero()) if (!EqualsZero())
return CCharAnimTime(x0_time * other); return {x0_time * other};
if (other > 0.f) if (other > 0.f)
return *this; return *this;
else if (other == 0.f)
return ret;
ret.x4_type = x4_type; if (x4_type == EType::ZeroDecreasing) {
return ret; return {EType::ZeroIncreasing, 0.f};
} else if (x4_type == EType::ZeroSteady) {
return {EType::ZeroSteady, 0.f};
} else {
return {EType::ZeroDecreasing, 0.f};
}
} }
float CCharAnimTime::operator/(const CCharAnimTime& other) const { float CCharAnimTime::operator/(const CCharAnimTime& other) const {