metaforce/Runtime/Character/CCharAnimTime.cpp

293 lines
6.7 KiB
C++
Raw Normal View History

2016-02-26 22:03:39 -08:00
#include "CCharAnimTime.hpp"
2016-04-11 00:10:28 -07:00
#include <algorithm>
2016-08-21 13:39:18 -07:00
#include <cmath>
2017-12-29 00:08:12 -08:00
#include <cfloat>
2016-02-26 22:03:39 -08:00
2018-12-07 21:30:43 -08:00
namespace urde {
2016-02-26 22:03:39 -08:00
2018-12-07 21:30:43 -08:00
CCharAnimTime CCharAnimTime::Infinity() {
CCharAnimTime ret(1.f);
ret.x4_type = EType::Infinity;
return ret;
2016-04-10 20:59:54 -07:00
}
2018-12-07 21:30:43 -08:00
bool CCharAnimTime::EqualsZero() const {
if (x4_type == EType::ZeroIncreasing || x4_type == EType::ZeroSteady || x4_type == EType::ZeroDecreasing)
return true;
2016-04-10 20:59:54 -07:00
2018-12-07 21:30:43 -08:00
return (x0_time == 0.f);
2016-04-10 20:59:54 -07:00
}
2018-12-07 21:30:43 -08:00
bool CCharAnimTime::EpsilonZero() const { return (std::fabs(x0_time) < 0.00001f); }
2016-08-21 13:39:18 -07:00
2018-12-07 21:30:43 -08:00
bool CCharAnimTime::GreaterThanZero() const {
if (EqualsZero())
return false;
return (x0_time > 0.f);
2016-04-10 20:59:54 -07:00
}
2018-12-07 21:30:43 -08:00
bool CCharAnimTime::operator==(const CCharAnimTime& other) const {
if (x4_type == EType::NonZero) {
if (other.x4_type == EType::NonZero)
return x0_time == other.x0_time;
2019-01-19 22:43:11 -08:00
return false;
2018-12-07 21:30:43 -08:00
}
if (EqualsZero()) {
if (other.EqualsZero()) {
int type = -1;
if (x4_type != EType::ZeroDecreasing) {
if (x4_type != EType::ZeroSteady)
type = 1;
else
type = 0;
}
int otherType = -1;
if (other.x4_type != EType::ZeroDecreasing) {
if (other.x4_type != EType::ZeroSteady)
otherType = 1;
else
otherType = 0;
}
2016-04-10 20:59:54 -07:00
2018-12-07 21:30:43 -08:00
return type == otherType;
2016-04-10 20:59:54 -07:00
}
2018-12-07 21:30:43 -08:00
return false;
}
2016-04-10 20:59:54 -07:00
2018-12-07 21:30:43 -08:00
if (other.x4_type == EType::Infinity)
return x0_time * other.x0_time < 0.f;
2016-04-10 20:59:54 -07:00
2018-12-07 21:30:43 -08:00
return false;
2016-04-10 20:59:54 -07:00
}
2018-12-07 21:30:43 -08:00
bool CCharAnimTime::operator!=(const CCharAnimTime& other) const { return !(*this == other); }
2016-04-10 20:59:54 -07:00
2018-12-07 21:30:43 -08:00
bool CCharAnimTime::operator>=(const CCharAnimTime& other) const {
if (*this == other)
return true;
2016-04-10 20:59:54 -07:00
2018-12-07 21:30:43 -08:00
return (*this > other);
2016-04-10 20:59:54 -07:00
}
2018-12-07 21:30:43 -08:00
bool CCharAnimTime::operator<=(const CCharAnimTime& other) const {
if (*this == other)
return true;
2016-04-10 20:59:54 -07:00
2018-12-07 21:30:43 -08:00
return (*this < other);
2016-04-10 20:59:54 -07:00
}
2018-12-07 21:30:43 -08:00
bool CCharAnimTime::operator>(const CCharAnimTime& other) const { return (!(*this == other) && !(*this < other)); }
2016-04-10 20:59:54 -07:00
2018-12-07 21:30:43 -08:00
bool CCharAnimTime::operator<(const CCharAnimTime& other) const {
if (x4_type == EType::NonZero) {
if (other.x4_type == EType::NonZero)
return x0_time < other.x0_time;
if (other.EqualsZero())
return x0_time < 0.f;
else
return other.x0_time > 0.f;
}
if (EqualsZero()) {
if (other.EqualsZero()) {
int type = -1;
if (x4_type != EType::ZeroDecreasing) {
if (x4_type != EType::ZeroSteady)
type = 1;
2016-04-10 20:59:54 -07:00
else
2018-12-07 21:30:43 -08:00
type = 0;
}
2016-04-10 20:59:54 -07:00
2018-12-07 21:30:43 -08:00
int otherType = -1;
if (other.x4_type != EType::ZeroDecreasing) {
if (other.x4_type != EType::ZeroSteady)
otherType = 1;
else
otherType = 0;
}
return type < otherType;
2016-04-10 20:59:54 -07:00
}
2018-12-07 21:30:43 -08:00
if (other.x4_type == EType::NonZero)
return other.x0_time > 0.f;
return other.x0_time < 0.f;
} else {
if (x4_type == EType::Infinity)
return x0_time < 0.f && other.x0_time > 0.f;
return x0_time < other.x0_time;
}
2016-04-10 20:59:54 -07:00
}
2018-12-07 21:30:43 -08:00
CCharAnimTime& CCharAnimTime::operator*=(const CCharAnimTime& other) {
*this = *this * other;
return *this;
2016-04-10 20:59:54 -07:00
}
2018-12-07 21:30:43 -08:00
CCharAnimTime& CCharAnimTime::operator+=(const CCharAnimTime& other) {
*this = *this + other;
return *this;
2016-04-10 20:59:54 -07:00
}
2018-12-07 21:30:43 -08:00
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 *this;
} else if (x4_type == EType::Infinity)
return *this;
else if (other.x4_type == EType::Infinity)
return other;
2016-04-10 20:59:54 -07:00
2018-12-07 21:30:43 -08:00
if (!EqualsZero() || !other.EqualsZero())
return CCharAnimTime(x0_time + other.x0_time);
2016-04-10 20:59:54 -07:00
2018-12-07 21:30:43 -08:00
int type = -1;
if (x4_type != EType::ZeroDecreasing) {
if (x4_type != EType::ZeroSteady)
type = 1;
else
type = 0;
}
2016-04-10 20:59:54 -07:00
2018-12-07 21:30:43 -08:00
int otherType = -1;
if (other.x4_type != EType::ZeroDecreasing) {
if (other.x4_type != EType::ZeroSteady)
otherType = 1;
else
otherType = 0;
}
2016-04-10 20:59:54 -07:00
2018-12-07 21:30:43 -08:00
type += otherType;
otherType = std::max(-1, std::min(type, 1));
2016-04-10 20:59:54 -07:00
2018-12-07 21:30:43 -08:00
CCharAnimTime ret;
if (otherType == -1)
ret.x4_type = EType::ZeroDecreasing;
else if (otherType == 0)
ret.x4_type = EType::ZeroSteady;
else
ret.x4_type = EType::ZeroIncreasing;
2016-04-10 20:59:54 -07:00
2018-12-07 21:30:43 -08:00
return ret;
2016-04-10 20:59:54 -07:00
}
2018-12-07 21:30:43 -08:00
CCharAnimTime& CCharAnimTime::operator-=(const CCharAnimTime& other) {
*this = *this - other;
return *this;
2016-04-10 20:59:54 -07:00
}
2018-12-07 21:30:43 -08:00
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 *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;
}
2016-04-10 20:59:54 -07:00
2018-12-07 21:30:43 -08:00
if (!EqualsZero() || !other.EqualsZero())
return CCharAnimTime(x0_time - other.x0_time);
2016-04-10 20:59:54 -07:00
2018-12-07 21:30:43 -08:00
int type = -1;
if (x4_type != EType::ZeroDecreasing) {
if (x4_type != EType::ZeroSteady)
type = 1;
2016-04-10 20:59:54 -07:00
else
2018-12-07 21:30:43 -08:00
type = 0;
}
2016-04-10 20:59:54 -07:00
2018-12-07 21:30:43 -08:00
int otherType = -1;
if (other.x4_type != EType::ZeroDecreasing) {
if (other.x4_type != EType::ZeroSteady)
otherType = 1;
else
otherType = 0;
}
CCharAnimTime ret;
type -= otherType;
if (type == -1)
ret.x4_type = EType::ZeroDecreasing;
else if (type == 0)
ret.x4_type = EType::ZeroSteady;
else
ret.x4_type = EType::ZeroIncreasing;
return ret;
2016-04-10 20:59:54 -07:00
}
2018-12-07 21:30:43 -08:00
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 *this;
} else if (x4_type == EType::Infinity)
return *this;
else if (other.x4_type == EType::Infinity)
return other;
2016-04-10 20:59:54 -07:00
2018-12-07 21:30:43 -08:00
if (!EqualsZero() || !other.EqualsZero())
return CCharAnimTime(x0_time * other.x0_time);
2016-04-10 20:59:54 -07:00
2018-12-07 21:30:43 -08:00
int type = -1;
if (x4_type != EType::ZeroDecreasing) {
if (x4_type != EType::ZeroSteady)
type = 1;
else
type = 0;
}
2016-04-10 20:59:54 -07:00
2018-12-07 21:30:43 -08:00
int otherType = -1;
if (other.x4_type != EType::ZeroDecreasing) {
if (other.x4_type != EType::ZeroSteady)
otherType = 1;
2016-04-10 20:59:54 -07:00
else
2018-12-07 21:30:43 -08:00
otherType = 0;
}
type += otherType;
otherType = std::max(-1, std::min(type, 1));
CCharAnimTime ret;
if (otherType == -1)
ret.x4_type = EType::ZeroDecreasing;
else if (otherType == 0)
ret.x4_type = EType::ZeroSteady;
else
ret.x4_type = EType::ZeroIncreasing;
return ret;
2016-04-10 20:59:54 -07:00
}
2018-12-07 21:30:43 -08:00
CCharAnimTime CCharAnimTime::operator*(const float& other) const {
CCharAnimTime ret;
if (other == 0.f)
return ret;
2016-04-10 20:59:54 -07:00
2018-12-07 21:30:43 -08:00
if (!EqualsZero())
return CCharAnimTime(x0_time * other);
2016-04-10 20:59:54 -07:00
2018-12-07 21:30:43 -08:00
if (other > 0.f)
return *this;
else if (other == 0.f)
2016-04-10 20:59:54 -07:00
return ret;
2018-12-07 21:30:43 -08:00
ret.x4_type = x4_type;
return ret;
2016-04-10 20:59:54 -07:00
}
2018-12-07 21:30:43 -08:00
float CCharAnimTime::operator/(const CCharAnimTime& other) const {
if (other.EqualsZero())
return 0.f;
2016-04-10 20:59:54 -07:00
2018-12-07 21:30:43 -08:00
return x0_time / other.x0_time;
2016-04-10 20:59:54 -07:00
}
2018-12-07 21:30:43 -08:00
} // namespace urde