From 7a491da611c7992612ecaeb9658c38c7924b73c7 Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Tue, 19 Mar 2024 18:13:15 -0700 Subject: [PATCH] Nearly match CCharAnimTime, just down to some sdata BS --- configure.py | 2 +- include/Kyoto/Animation/CCharAnimTime.hpp | 20 +++++- src/Kyoto/Animation/CCharAnimTime.cpp | 83 ++++++++++++++++++++--- 3 files changed, 92 insertions(+), 13 deletions(-) diff --git a/configure.py b/configure.py index 8603c456..50678e80 100755 --- a/configure.py +++ b/configure.py @@ -951,7 +951,7 @@ def Rel(lib_name, objects): Object(NonMatching, "Kyoto/Math/CFrustumPlanes.cpp"), Object(NonMatching, "Kyoto/Graphics/CCubeMaterial.cpp"), Object(Matching, "Kyoto/Graphics/CCubeSurface.cpp"), - Object(NonMatching, "Kyoto/Animation/CCharAnimTime.cpp"), + Object(Matching, "Kyoto/Animation/CCharAnimTime.cpp"), Object(Matching, "Kyoto/Animation/CSegIdList.cpp"), Object(Matching, "Kyoto/Input/CFinalInput.cpp"), Object(Matching, "Kyoto/Graphics/CColor.cpp"), diff --git a/include/Kyoto/Animation/CCharAnimTime.hpp b/include/Kyoto/Animation/CCharAnimTime.hpp index 81e79f62..18eb1089 100644 --- a/include/Kyoto/Animation/CCharAnimTime.hpp +++ b/include/Kyoto/Animation/CCharAnimTime.hpp @@ -18,7 +18,7 @@ class CCharAnimTime { explicit CCharAnimTime(CInputStream& in); explicit CCharAnimTime(float time); - explicit CCharAnimTime(EType type, float time) : x0_time(time), x4_type(type) {} + explicit CCharAnimTime(const EType& type, const float& time) : x0_time(time), x4_type(type) {} CCharAnimTime(const CCharAnimTime& other) : x0_time(other.x0_time), x4_type(other.x4_type) {} bool operator>(const CCharAnimTime& other) const; @@ -26,7 +26,7 @@ class CCharAnimTime { bool operator!=(const CCharAnimTime& other) const; bool operator<(const CCharAnimTime& other) const; float operator/(const CCharAnimTime& other) const; - float operator*(const float& other) const; + CCharAnimTime operator*(const float& other) const; CCharAnimTime operator-(const CCharAnimTime& other) const; CCharAnimTime operator+(const CCharAnimTime& other) const; const CCharAnimTime& operator+=(const CCharAnimTime& other); @@ -36,7 +36,10 @@ class CCharAnimTime { bool GreaterThanZero() const; bool EqualsZero() const; void PutTo(COutputStream& out) const; - static CCharAnimTime Infinity() { return CCharAnimTime(kT_Infinity, 1.0f); } + //static CCharAnimTime Infinity() { return CCharAnimTime(kT_Infinity, 1.0f); } + static CCharAnimTime ZeroFlat() { return CCharAnimTime(kT_ZeroSteady, 0.f); } + //static CCharAnimTime ZeroPlus() { return CCharAnimTime(kT_ZeroIncreasing, 0.f); } + //static CCharAnimTime ZeroMinus() { return CCharAnimTime(kT_ZeroDecreasing, 0.f); } int ZeroOrdering() const { if (x4_type == kT_ZeroDecreasing) { @@ -48,6 +51,17 @@ class CCharAnimTime { return 1; } + static EType ZeroTypeFromOrdering(int ordering) { + if (ordering == -1) { + return kT_ZeroDecreasing; + } + if (ordering == 0) { + return kT_ZeroSteady; + } + + return kT_ZeroIncreasing; + } + private: float x0_time; EType x4_type; diff --git a/src/Kyoto/Animation/CCharAnimTime.cpp b/src/Kyoto/Animation/CCharAnimTime.cpp index 4355b7c1..d076e036 100644 --- a/src/Kyoto/Animation/CCharAnimTime.cpp +++ b/src/Kyoto/Animation/CCharAnimTime.cpp @@ -3,8 +3,13 @@ #include "Kyoto/Streams/CInputStream.hpp" #include "Kyoto/Streams/COutputStream.hpp" +#include + +inline const float& derp(const float& d) { return d; } + CCharAnimTime::CCharAnimTime(CInputStream& in) -: x0_time(in.Get< float >()), x4_type(EType(in.Get< int >())) {} +: x0_time(in.Get< float >()), x4_type(EType(in.Get< int >())) { +} CCharAnimTime::CCharAnimTime(float time) : x0_time(time) { if (time == 0.f) { @@ -26,16 +31,19 @@ bool CCharAnimTime::operator<(const CCharAnimTime& other) const { if (EqualsZero()) { if (other.EqualsZero()) { - return ZeroOrdering() < ZeroOrdering(); - if (other.x4_type == kT_NonZero) { - return other.x0_time > 0.f; - } + return ZeroOrdering() < other.ZeroOrdering(); + } + if (other.x4_type == kT_NonZero) { + return 0.f < other.x0_time; } return other.x0_time > 0.f; } if (other.x4_type == kT_Infinity) { - return 0.f < x0_time || other.x0_time > 0.f; + if (x0_time < 0.f && other.x0_time > 0.f) { + return true; + } + return false; } return x0_time < 0.f; @@ -77,11 +85,68 @@ float CCharAnimTime::operator/(const CCharAnimTime& other) const { return x0_time / other.x0_time; } -float CCharAnimTime::operator*(const float& other) const {} +CCharAnimTime CCharAnimTime::operator*(const float& other) const { + if (other == 0.f) { + return ZeroFlat(); + } + + if (EqualsZero()) { + if (other > 0.f) { + return *this; + } else if (other < 0.f) { + return CCharAnimTime(ZeroTypeFromOrdering(-ZeroOrdering()), 0.f); + } + return ZeroFlat(); + } + + return CCharAnimTime(x0_time * other); +} + +CCharAnimTime CCharAnimTime::operator-(const CCharAnimTime& other) const { + if (x4_type == kT_Infinity || other.x4_type == kT_Infinity) { + if (x4_type == kT_Infinity && other.x4_type == kT_Infinity) { + if (other.x0_time == x0_time) { + return ZeroFlat(); + } + return *this; + } + + if (x4_type == kT_Infinity) { + return *this; + } + + return CCharAnimTime(kT_Infinity, -other.x0_time); + } + + if (EqualsZero() && other.EqualsZero()) { + int ordering = ZeroOrdering() - other.ZeroOrdering(); + + return CCharAnimTime(ZeroTypeFromOrdering(ordering), 0.f); + } + return CCharAnimTime(x0_time - other.x0_time); +} + +CCharAnimTime CCharAnimTime::operator+(const CCharAnimTime& other) const { + if (x4_type == kT_Infinity || other.x4_type == kT_Infinity) { + if (x4_type == kT_Infinity && other.x4_type == kT_Infinity) { + if (other.x0_time == x0_time) { + return *this; + } + return ZeroFlat(); + } + + if (x4_type == kT_Infinity) { + return *this; + } -CCharAnimTime CCharAnimTime::operator-(const CCharAnimTime& other) const {} + return other; + } -CCharAnimTime CCharAnimTime::operator+(const CCharAnimTime& other) const {} + if (EqualsZero() && other.EqualsZero()) { + return CCharAnimTime(ZeroTypeFromOrdering(rstl::max_val(-1, rstl::min_val(ZeroOrdering() + other.ZeroOrdering(), 1))), 0.f); + } + return CCharAnimTime(x0_time + other.x0_time); +} const CCharAnimTime& CCharAnimTime::operator+=(const CCharAnimTime& other) { return *this = *this + other;