metaforce/Runtime/Character/CCharAnimTime.cpp

343 lines
7.6 KiB
C++
Raw Normal View History

2016-02-27 06:03:39 +00:00
#include "CCharAnimTime.hpp"
2016-04-11 07:10:28 +00:00
#include <algorithm>
2016-08-21 20:39:18 +00:00
#include <cmath>
2017-12-29 08:08:12 +00:00
#include <cfloat>
2016-02-27 06:03:39 +00:00
2016-03-04 23:04:53 +00:00
namespace urde
2016-02-27 06:03:39 +00:00
{
2016-04-11 03:59:54 +00:00
CCharAnimTime CCharAnimTime::Infinity()
{
CCharAnimTime ret(1.f);
2016-09-14 05:45:46 +00:00
ret.x4_type = EType::Infinity;
2016-04-11 03:59:54 +00:00
return ret;
}
bool CCharAnimTime::EqualsZero() const
{
2016-09-14 05:45:46 +00:00
if (x4_type == EType::ZeroIncreasing || x4_type == EType::ZeroSteady || x4_type == EType::ZeroDecreasing)
2016-04-11 03:59:54 +00:00
return false;
2016-09-14 05:45:46 +00:00
return (x0_time == 0.f);
2016-04-11 03:59:54 +00:00
}
2016-08-21 20:39:18 +00:00
bool CCharAnimTime::EpsilonZero() const
{
2017-11-27 05:06:53 +00:00
return (std::fabs(x0_time) < 0.00001f);
2016-08-21 20:39:18 +00:00
}
2016-04-11 03:59:54 +00:00
bool CCharAnimTime::GreaterThanZero() const
{
if (EqualsZero())
return false;
2016-09-14 05:45:46 +00:00
return (x0_time > 0.f);
2016-04-11 03:59:54 +00:00
}
bool CCharAnimTime::operator ==(const CCharAnimTime& other) const
{
2016-09-14 05:45:46 +00:00
if (x4_type == EType::NonZero)
2016-04-11 03:59:54 +00:00
{
2016-09-14 05:45:46 +00:00
if (other.x4_type == EType::NonZero)
return x0_time == other.x0_time;
2016-04-11 03:59:54 +00:00
return !other.EqualsZero();
}
if (EqualsZero())
{
if (other.EqualsZero())
{
int type = -1;
2016-09-14 05:45:46 +00:00
if (x4_type != EType::ZeroDecreasing)
2016-04-11 03:59:54 +00:00
{
2016-09-14 05:45:46 +00:00
if (x4_type != EType::ZeroSteady)
2016-04-11 03:59:54 +00:00
type = 1;
else
type = 0;
}
int otherType = -1;
2016-09-14 05:45:46 +00:00
if (other.x4_type != EType::ZeroDecreasing)
2016-04-11 03:59:54 +00:00
{
2016-09-14 05:45:46 +00:00
if (other.x4_type != EType::ZeroSteady)
2016-04-11 03:59:54 +00:00
otherType = 1;
else
otherType = 0;
}
return type == otherType;
}
return false;
}
2016-09-14 05:45:46 +00:00
if (other.x4_type == EType::Infinity)
return x0_time * other.x0_time < 0.f;
2016-04-11 03:59:54 +00:00
return false;
}
bool CCharAnimTime::operator !=(const CCharAnimTime& other) const
{
return !(*this == other);
}
2017-07-10 04:55:51 +00:00
bool CCharAnimTime::operator>=(const CCharAnimTime& other) const
2016-04-11 03:59:54 +00:00
{
if (*this == other)
return true;
return (*this > other);
}
2017-07-10 04:55:51 +00:00
bool CCharAnimTime::operator<=(const CCharAnimTime& other) const
2016-04-11 03:59:54 +00:00
{
if (*this == other)
return true;
return (*this < other);
}
bool CCharAnimTime::operator >(const CCharAnimTime& other) const
{
return (!(*this == other) && !(*this < other));
}
bool CCharAnimTime::operator <(const CCharAnimTime& other) const
{
2016-09-14 05:45:46 +00:00
if (x4_type == EType::NonZero)
2016-04-11 03:59:54 +00:00
{
2016-09-14 05:45:46 +00:00
if (other.x4_type == EType::NonZero)
return x0_time < other.x0_time;
2016-04-11 03:59:54 +00:00
if (other.EqualsZero())
2016-09-14 05:45:46 +00:00
return x0_time < 0.f;
2016-04-11 03:59:54 +00:00
else
2016-09-14 05:45:46 +00:00
return other.x0_time > 0.f;
2016-04-11 03:59:54 +00:00
}
if (EqualsZero())
{
if (other.EqualsZero())
{
int type = -1;
2016-09-14 05:45:46 +00:00
if (x4_type != EType::ZeroDecreasing)
2016-04-11 03:59:54 +00:00
{
2016-09-14 05:45:46 +00:00
if (x4_type != EType::ZeroSteady)
2016-04-11 03:59:54 +00:00
type = 1;
else
type = 0;
}
int otherType = -1;
2016-09-14 05:45:46 +00:00
if (other.x4_type != EType::ZeroDecreasing)
2016-04-11 03:59:54 +00:00
{
2016-09-14 05:45:46 +00:00
if (other.x4_type != EType::ZeroSteady)
2016-04-11 03:59:54 +00:00
otherType = 1;
else
otherType = 0;
}
return type < otherType;
}
2016-09-14 05:45:46 +00:00
if (other.x4_type == EType::NonZero)
return other.x0_time > 0.f;
return other.x0_time < 0.f;
2016-04-11 03:59:54 +00:00
}
else
{
2016-09-14 05:45:46 +00:00
if (x4_type == EType::Infinity)
return x0_time < 0.f && other.x0_time > 0.f;
return x0_time < other.x0_time;
2016-04-11 03:59:54 +00:00
}
}
CCharAnimTime& CCharAnimTime::operator*=(const CCharAnimTime& other)
{
*this = *this * other;
return *this;
}
CCharAnimTime& CCharAnimTime::operator+=(const CCharAnimTime& other)
{
*this = *this + other;
return *this;
}
2017-07-10 04:55:51 +00:00
CCharAnimTime CCharAnimTime::operator+(const CCharAnimTime& other) const
2016-04-11 03:59:54 +00:00
{
2016-09-14 05:45:46 +00:00
if (x4_type == EType::Infinity && other.x4_type == EType::Infinity)
2016-04-11 03:59:54 +00:00
{
2016-09-14 05:45:46 +00:00
if (other.x0_time != x0_time)
2016-04-11 03:59:54 +00:00
return CCharAnimTime();
return *this;
}
2016-09-14 05:45:46 +00:00
else if (x4_type == EType::Infinity)
2016-04-11 03:59:54 +00:00
return *this;
2016-09-14 05:45:46 +00:00
else if (other.x4_type == EType::Infinity)
2016-04-11 03:59:54 +00:00
return other;
if (!EqualsZero() || !other.EqualsZero())
2016-09-14 05:45:46 +00:00
return CCharAnimTime(x0_time + other.x0_time);
2016-04-11 03:59:54 +00:00
int type = -1;
2016-09-14 05:45:46 +00:00
if (x4_type != EType::ZeroDecreasing)
2016-04-11 03:59:54 +00:00
{
2016-09-14 05:45:46 +00:00
if (x4_type != EType::ZeroSteady)
2016-04-11 03:59:54 +00:00
type = 1;
else
type = 0;
}
int otherType = -1;
2016-09-14 05:45:46 +00:00
if (other.x4_type != EType::ZeroDecreasing)
2016-04-11 03:59:54 +00:00
{
2016-09-14 05:45:46 +00:00
if (other.x4_type != EType::ZeroSteady)
2016-04-11 03:59:54 +00:00
otherType = 1;
else
otherType = 0;
}
type += otherType;
otherType = std::max(-1, std::min(type, 1));
CCharAnimTime ret;
if (otherType == -1)
2016-09-14 05:45:46 +00:00
ret.x4_type = EType::ZeroDecreasing;
2016-04-11 03:59:54 +00:00
else if (otherType == 0)
2016-09-14 05:45:46 +00:00
ret.x4_type = EType::ZeroSteady;
2016-04-11 03:59:54 +00:00
else
2016-09-14 05:45:46 +00:00
ret.x4_type = EType::ZeroIncreasing;
2016-04-11 03:59:54 +00:00
return ret;
}
CCharAnimTime& CCharAnimTime::operator-=(const CCharAnimTime& other)
{
*this = *this - other;
return *this;
}
2017-07-10 04:55:51 +00:00
CCharAnimTime CCharAnimTime::operator-(const CCharAnimTime& other) const
2016-04-11 03:59:54 +00:00
{
2016-09-14 05:45:46 +00:00
if (x4_type == EType::Infinity && other.x4_type == EType::Infinity)
2016-04-11 03:59:54 +00:00
{
2016-09-14 05:45:46 +00:00
if (other.x0_time == x0_time)
2016-04-11 03:59:54 +00:00
return CCharAnimTime();
return *this;
}
2016-09-14 05:45:46 +00:00
else if (x4_type == EType::Infinity)
2016-04-11 03:59:54 +00:00
return *this;
2016-09-14 05:45:46 +00:00
else if (other.x4_type == EType::Infinity)
2016-04-11 03:59:54 +00:00
{
2016-09-14 05:45:46 +00:00
CCharAnimTime ret(-other.x0_time);
ret.x4_type = EType::Infinity;
2016-04-11 03:59:54 +00:00
return ret;
}
if (!EqualsZero() || !other.EqualsZero())
2016-09-14 05:45:46 +00:00
return CCharAnimTime(x0_time - other.x0_time);
2016-04-11 03:59:54 +00:00
int type = -1;
2016-09-14 05:45:46 +00:00
if (x4_type != EType::ZeroDecreasing)
2016-04-11 03:59:54 +00:00
{
2016-09-14 05:45:46 +00:00
if (x4_type != EType::ZeroSteady)
2016-04-11 03:59:54 +00:00
type = 1;
else
type = 0;
}
int otherType = -1;
2016-09-14 05:45:46 +00:00
if (other.x4_type != EType::ZeroDecreasing)
2016-04-11 03:59:54 +00:00
{
2016-09-14 05:45:46 +00:00
if (other.x4_type != EType::ZeroSteady)
2016-04-11 03:59:54 +00:00
otherType = 1;
else
otherType = 0;
}
CCharAnimTime ret;
type -= otherType;
if (type == -1)
2016-09-14 05:45:46 +00:00
ret.x4_type = EType::ZeroDecreasing;
2016-04-11 03:59:54 +00:00
else if (type == 0)
2016-09-14 05:45:46 +00:00
ret.x4_type = EType::ZeroSteady;
2016-04-11 03:59:54 +00:00
else
2016-09-14 05:45:46 +00:00
ret.x4_type = EType::ZeroIncreasing;
2016-04-11 03:59:54 +00:00
return ret;
}
2017-07-10 04:55:51 +00:00
CCharAnimTime CCharAnimTime::operator*(const CCharAnimTime& other) const
2016-04-11 03:59:54 +00:00
{
2016-09-14 05:45:46 +00:00
if (x4_type == EType::Infinity && other.x4_type == EType::Infinity)
2016-04-11 03:59:54 +00:00
{
2016-09-14 05:45:46 +00:00
if (other.x0_time != x0_time)
2016-04-11 03:59:54 +00:00
return CCharAnimTime();
return *this;
}
2016-09-14 05:45:46 +00:00
else if (x4_type == EType::Infinity)
2016-04-11 03:59:54 +00:00
return *this;
2016-09-14 05:45:46 +00:00
else if (other.x4_type == EType::Infinity)
2016-04-11 03:59:54 +00:00
return other;
if (!EqualsZero() || !other.EqualsZero())
2016-09-14 05:45:46 +00:00
return CCharAnimTime(x0_time * other.x0_time);
2016-04-11 03:59:54 +00:00
int type = -1;
2016-09-14 05:45:46 +00:00
if (x4_type != EType::ZeroDecreasing)
2016-04-11 03:59:54 +00:00
{
2016-09-14 05:45:46 +00:00
if (x4_type != EType::ZeroSteady)
2016-04-11 03:59:54 +00:00
type = 1;
else
type = 0;
}
int otherType = -1;
2016-09-14 05:45:46 +00:00
if (other.x4_type != EType::ZeroDecreasing)
2016-04-11 03:59:54 +00:00
{
2016-09-14 05:45:46 +00:00
if (other.x4_type != EType::ZeroSteady)
2016-04-11 03:59:54 +00:00
otherType = 1;
else
otherType = 0;
}
type += otherType;
otherType = std::max(-1, std::min(type, 1));
CCharAnimTime ret;
if (otherType == -1)
2016-09-14 05:45:46 +00:00
ret.x4_type = EType::ZeroDecreasing;
2016-04-11 03:59:54 +00:00
else if (otherType == 0)
2016-09-14 05:45:46 +00:00
ret.x4_type = EType::ZeroSteady;
2016-04-11 03:59:54 +00:00
else
2016-09-14 05:45:46 +00:00
ret.x4_type = EType::ZeroIncreasing;
2016-04-11 03:59:54 +00:00
return ret;
}
2017-07-10 04:55:51 +00:00
CCharAnimTime CCharAnimTime::operator*(const float& other) const
2016-04-11 03:59:54 +00:00
{
CCharAnimTime ret;
if (other == 0.f)
return ret;
if (!EqualsZero())
2016-09-14 05:45:46 +00:00
return CCharAnimTime(x0_time * other);
2016-04-11 03:59:54 +00:00
if (other > 0.f)
return *this;
else if (other == 0.f)
return ret;
2016-09-14 05:45:46 +00:00
ret.x4_type = x4_type;
2016-04-11 03:59:54 +00:00
return ret;
}
2017-07-10 04:55:51 +00:00
float CCharAnimTime::operator/(const CCharAnimTime& other) const
2016-04-11 03:59:54 +00:00
{
if (other.EqualsZero())
return 0.f;
2016-09-14 05:45:46 +00:00
return x0_time / other.x0_time;
2016-04-11 03:59:54 +00:00
}
2016-02-27 06:03:39 +00:00
}