Skip to content

Commit

Permalink
Nearly match CCharAnimTime, just down to some sdata BS
Browse files Browse the repository at this point in the history
  • Loading branch information
Antidote committed Mar 20, 2024
1 parent 9f7d939 commit 7a491da
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 13 deletions.
2 changes: 1 addition & 1 deletion configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
20 changes: 17 additions & 3 deletions include/Kyoto/Animation/CCharAnimTime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ 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;
bool operator==(const CCharAnimTime& other) const;
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);
Expand All @@ -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) {
Expand All @@ -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;
Expand Down
83 changes: 74 additions & 9 deletions src/Kyoto/Animation/CCharAnimTime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
#include "Kyoto/Streams/CInputStream.hpp"
#include "Kyoto/Streams/COutputStream.hpp"

#include <rstl/math.hpp>

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) {
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 7a491da

Please sign in to comment.