2020-01-15 12:07:48 +00:00
|
|
|
#include "Runtime/Character/CCharAnimTime.hpp"
|
|
|
|
|
2020-03-09 16:21:08 +00:00
|
|
|
#include <algorithm>
|
2016-08-21 20:39:18 +00:00
|
|
|
#include <cmath>
|
2016-02-27 06:03:39 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
namespace urde {
|
2016-02-27 06:03:39 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CCharAnimTime::EqualsZero() const {
|
|
|
|
if (x4_type == EType::ZeroIncreasing || x4_type == EType::ZeroSteady || x4_type == EType::ZeroDecreasing)
|
|
|
|
return true;
|
2016-04-11 03:59:54 +00:00
|
|
|
|
2020-03-09 16:09:54 +00:00
|
|
|
return x0_time == 0.f;
|
2016-04-11 03:59:54 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CCharAnimTime::EpsilonZero() const { return (std::fabs(x0_time) < 0.00001f); }
|
2016-08-21 20:39:18 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CCharAnimTime::GreaterThanZero() const {
|
|
|
|
if (EqualsZero())
|
|
|
|
return false;
|
2020-03-09 16:09:54 +00:00
|
|
|
return x0_time > 0.f;
|
2016-04-11 03:59:54 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00: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-20 06:43:11 +00:00
|
|
|
return false;
|
2018-12-08 05:30:43 +00: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-11 03:59:54 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
return type == otherType;
|
2016-04-11 03:59:54 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-04-11 03:59:54 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (other.x4_type == EType::Infinity)
|
2020-08-24 06:28:18 +00:00
|
|
|
return x0_time * other.x0_time > 0.f;
|
2016-04-11 03:59:54 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
return false;
|
2016-04-11 03:59:54 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CCharAnimTime::operator!=(const CCharAnimTime& other) const { return !(*this == other); }
|
2016-04-11 03:59:54 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CCharAnimTime::operator>=(const CCharAnimTime& other) const {
|
|
|
|
if (*this == other)
|
|
|
|
return true;
|
2016-04-11 03:59:54 +00:00
|
|
|
|
2020-03-09 16:09:54 +00:00
|
|
|
return *this > other;
|
2016-04-11 03:59:54 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CCharAnimTime::operator<=(const CCharAnimTime& other) const {
|
|
|
|
if (*this == other)
|
|
|
|
return true;
|
2016-04-11 03:59:54 +00:00
|
|
|
|
2020-03-09 16:09:54 +00:00
|
|
|
return *this < other;
|
2016-04-11 03:59:54 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CCharAnimTime::operator>(const CCharAnimTime& other) const { return (!(*this == other) && !(*this < other)); }
|
2016-04-11 03:59:54 +00:00
|
|
|
|
2018-12-08 05:30:43 +00: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-11 03:59:54 +00:00
|
|
|
else
|
2018-12-08 05:30:43 +00:00
|
|
|
type = 0;
|
|
|
|
}
|
2016-04-11 03:59:54 +00:00
|
|
|
|
2018-12-08 05:30:43 +00: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-11 03:59:54 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
if (other.x4_type == EType::NonZero)
|
|
|
|
return other.x0_time > 0.f;
|
2020-08-24 22:42:43 +00:00
|
|
|
return other.x0_time > 0.f; // ?
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2020-08-24 22:42:43 +00:00
|
|
|
|
|
|
|
if (other.x4_type == EType::Infinity)
|
|
|
|
return x0_time < 0.f && other.x0_time > 0.f;
|
|
|
|
return x0_time < 0.f;
|
2016-04-11 03:59:54 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CCharAnimTime& CCharAnimTime::operator*=(const CCharAnimTime& other) {
|
2020-03-09 16:09:54 +00:00
|
|
|
return *this = *this * other;
|
2016-04-11 03:59:54 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CCharAnimTime& CCharAnimTime::operator+=(const CCharAnimTime& other) {
|
2020-03-09 16:09:54 +00:00
|
|
|
return *this = *this + other;
|
2016-04-11 03:59:54 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CCharAnimTime CCharAnimTime::operator+(const CCharAnimTime& other) const {
|
|
|
|
if (x4_type == EType::Infinity && other.x4_type == EType::Infinity) {
|
|
|
|
if (other.x0_time != x0_time)
|
2020-03-09 16:09:54 +00:00
|
|
|
return {};
|
2018-12-08 05:30:43 +00:00
|
|
|
return *this;
|
|
|
|
} else if (x4_type == EType::Infinity)
|
|
|
|
return *this;
|
|
|
|
else if (other.x4_type == EType::Infinity)
|
|
|
|
return other;
|
2016-04-11 03:59:54 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (!EqualsZero() || !other.EqualsZero())
|
2020-03-09 16:09:54 +00:00
|
|
|
return {x0_time + other.x0_time};
|
2016-04-11 03:59:54 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
int type = -1;
|
|
|
|
if (x4_type != EType::ZeroDecreasing) {
|
2020-03-09 16:09:54 +00:00
|
|
|
type = x4_type == EType::ZeroSteady ? 0 : 1;
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2016-04-11 03:59:54 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
int otherType = -1;
|
|
|
|
if (other.x4_type != EType::ZeroDecreasing) {
|
2020-03-09 16:09:54 +00:00
|
|
|
otherType = other.x4_type == EType::ZeroSteady ? 0 : 1;
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2016-04-11 03:59:54 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
type += otherType;
|
|
|
|
otherType = std::max(-1, std::min(type, 1));
|
2016-04-11 03:59:54 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (otherType == -1)
|
2020-03-09 16:09:54 +00:00
|
|
|
return {EType::ZeroDecreasing, 0.f};
|
2018-12-08 05:30:43 +00:00
|
|
|
else if (otherType == 0)
|
2020-03-09 16:09:54 +00:00
|
|
|
return {EType::ZeroSteady, 0.f};
|
2018-12-08 05:30:43 +00:00
|
|
|
else
|
2020-03-09 16:09:54 +00:00
|
|
|
return {EType::ZeroIncreasing, 0.f};
|
2016-04-11 03:59:54 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CCharAnimTime& CCharAnimTime::operator-=(const CCharAnimTime& other) {
|
2020-03-09 16:09:54 +00:00
|
|
|
return *this = *this - other;
|
2016-04-11 03:59:54 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CCharAnimTime CCharAnimTime::operator-(const CCharAnimTime& other) const {
|
|
|
|
if (x4_type == EType::Infinity && other.x4_type == EType::Infinity) {
|
|
|
|
if (other.x0_time == x0_time)
|
2020-03-09 16:09:54 +00:00
|
|
|
return {};
|
2018-12-08 05:30:43 +00:00
|
|
|
return *this;
|
|
|
|
} else if (x4_type == EType::Infinity)
|
|
|
|
return *this;
|
|
|
|
else if (other.x4_type == EType::Infinity) {
|
2020-03-09 16:09:54 +00:00
|
|
|
return {EType::Infinity, -other.x0_time};
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2016-04-11 03:59:54 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (!EqualsZero() || !other.EqualsZero())
|
2020-03-09 16:09:54 +00:00
|
|
|
return {x0_time - other.x0_time};
|
2016-04-11 03:59:54 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
int type = -1;
|
|
|
|
if (x4_type != EType::ZeroDecreasing) {
|
|
|
|
if (x4_type != EType::ZeroSteady)
|
|
|
|
type = 1;
|
2016-04-11 03:59:54 +00:00
|
|
|
else
|
2018-12-08 05:30:43 +00:00
|
|
|
type = 0;
|
|
|
|
}
|
2016-04-11 03:59:54 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
int otherType = -1;
|
|
|
|
if (other.x4_type != EType::ZeroDecreasing) {
|
|
|
|
if (other.x4_type != EType::ZeroSteady)
|
|
|
|
otherType = 1;
|
|
|
|
else
|
|
|
|
otherType = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
type -= otherType;
|
|
|
|
if (type == -1)
|
2020-03-09 16:09:54 +00:00
|
|
|
return {EType::ZeroDecreasing, 0.f};
|
2018-12-08 05:30:43 +00:00
|
|
|
else if (type == 0)
|
2020-03-09 16:09:54 +00:00
|
|
|
return {EType::ZeroSteady, 0.f};
|
2018-12-08 05:30:43 +00:00
|
|
|
else
|
2020-03-09 16:09:54 +00:00
|
|
|
return {EType::ZeroIncreasing, 0.f};
|
2016-04-11 03:59:54 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CCharAnimTime CCharAnimTime::operator*(const CCharAnimTime& other) const {
|
|
|
|
if (x4_type == EType::Infinity && other.x4_type == EType::Infinity) {
|
|
|
|
if (other.x0_time != x0_time)
|
2020-03-09 16:09:54 +00:00
|
|
|
return {};
|
2018-12-08 05:30:43 +00:00
|
|
|
return *this;
|
|
|
|
} else if (x4_type == EType::Infinity)
|
|
|
|
return *this;
|
|
|
|
else if (other.x4_type == EType::Infinity)
|
|
|
|
return other;
|
2016-04-11 03:59:54 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (!EqualsZero() || !other.EqualsZero())
|
2020-03-09 16:09:54 +00:00
|
|
|
return {x0_time * other.x0_time};
|
2016-04-11 03:59:54 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
int type = -1;
|
|
|
|
if (x4_type != EType::ZeroDecreasing) {
|
|
|
|
if (x4_type != EType::ZeroSteady)
|
|
|
|
type = 1;
|
|
|
|
else
|
|
|
|
type = 0;
|
|
|
|
}
|
2016-04-11 03:59:54 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
int otherType = -1;
|
|
|
|
if (other.x4_type != EType::ZeroDecreasing) {
|
|
|
|
if (other.x4_type != EType::ZeroSteady)
|
|
|
|
otherType = 1;
|
2016-04-11 03:59:54 +00:00
|
|
|
else
|
2018-12-08 05:30:43 +00:00
|
|
|
otherType = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
type += otherType;
|
|
|
|
otherType = std::max(-1, std::min(type, 1));
|
|
|
|
|
|
|
|
if (otherType == -1)
|
2020-03-09 16:09:54 +00:00
|
|
|
return {EType::ZeroDecreasing, 0.f};
|
2018-12-08 05:30:43 +00:00
|
|
|
else if (otherType == 0)
|
2020-03-09 16:09:54 +00:00
|
|
|
return {EType::ZeroSteady, 0.f};
|
2018-12-08 05:30:43 +00:00
|
|
|
else
|
2020-03-09 16:09:54 +00:00
|
|
|
return {EType::ZeroIncreasing, 0.f};
|
2016-04-11 03:59:54 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CCharAnimTime CCharAnimTime::operator*(const float& other) const {
|
|
|
|
if (other == 0.f)
|
2020-03-09 16:09:54 +00:00
|
|
|
return {};
|
2016-04-11 03:59:54 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (!EqualsZero())
|
2020-03-09 16:09:54 +00:00
|
|
|
return {x0_time * other};
|
2016-04-11 03:59:54 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (other > 0.f)
|
|
|
|
return *this;
|
|
|
|
|
2020-03-09 16:09:54 +00:00
|
|
|
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};
|
|
|
|
}
|
2016-04-11 03:59:54 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
float CCharAnimTime::operator/(const CCharAnimTime& other) const {
|
|
|
|
if (other.EqualsZero())
|
|
|
|
return 0.f;
|
2016-04-11 03:59:54 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
return x0_time / other.x0_time;
|
2016-04-11 03:59:54 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
} // namespace urde
|