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