Skip to content

Commit

Permalink
chore: graphics.cpp is a mess
Browse files Browse the repository at this point in the history
  • Loading branch information
intns committed Dec 16, 2024
1 parent 2e0fc62 commit afe6708
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 142 deletions.
20 changes: 19 additions & 1 deletion include/std/Math.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,25 @@ inline f32 sqrtf(f32 x)
return x;
}

void fmodf(f32, f32);
#ifdef __MWERKS__
#define fabs(x) __fabs(x)
#define fabsf(x) __fabsf(x)
#else
double fabs(double x);
float fabsf(float x);
#endif

inline float fmodf(float x, float m)
{
float a = fabsf(m);
float b = fabsf(x);
if (a > b)
return x;
else {
long long c = (long long)(x / m);
return x - m * c;
}
}

} // namespace std

Expand Down
64 changes: 32 additions & 32 deletions src/plugPikiOgawa/ogMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,40 +437,40 @@ int zen::ogScrMapMgr::update(Controller*)
* Address: 8018331C
* Size: 000060
*/
void std::fmodf(f32, f32)
{
/*
.loc_0x0:
mflr r0
stw r0, 0x4(r1)
stwu r1, -0x28(r1)
stfd f31, 0x20(r1)
fmr f31, f2
stfd f30, 0x18(r1)
fmr f30, f1
fabs f1, f31
fabs f0, f30
fcmpo cr0, f1, f0
ble- .loc_0x34
fmr f1, f30
b .loc_0x48
// f32 std::fmodf(f32, f32)
// {
/*
.loc_0x0:
mflr r0
stw r0, 0x4(r1)
stwu r1, -0x28(r1)
stfd f31, 0x20(r1)
fmr f31, f2
stfd f30, 0x18(r1)
fmr f30, f1
fabs f1, f31
fabs f0, f30
fcmpo cr0, f1, f0
ble- .loc_0x34
fmr f1, f30
b .loc_0x48
.loc_0x34:
fdivs f1, f30, f31
bl 0x920A0
bl 0x91FE8
fmuls f0, f31, f1
fsubs f1, f30, f0
.loc_0x34:
fdivs f1, f30, f31
bl 0x920A0
bl 0x91FE8
fmuls f0, f31, f1
fsubs f1, f30, f0
.loc_0x48:
lwz r0, 0x2C(r1)
lfd f31, 0x20(r1)
lfd f30, 0x18(r1)
addi r1, r1, 0x28
mtlr r0
blr
*/
}
.loc_0x48:
lwz r0, 0x2C(r1)
lfd f31, 0x20(r1)
lfd f30, 0x18(r1)
addi r1, r1, 0x28
mtlr r0
blr
*/
// }

/*
* --INFO--
Expand Down
12 changes: 3 additions & 9 deletions src/sysCommon/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,21 @@
#include "Controller.h"
#include "system.h"
#include "dolphin/os.h"
#include "DebugLog.h"

/*
* --INFO--
* Address: ........
* Size: 00009C
*/
static void _Error(char*, ...)
{
// UNUSED FUNCTION
OSReport("controller.cpp");
}
DEFINE_ERROR();

/*
* --INFO--
* Address: ........
* Size: 0000F4
*/
static void _Print(char*, ...)
{
// UNUSED FUNCTION
}
DEFINE_PRINT("");

/*
* --INFO--
Expand Down
190 changes: 90 additions & 100 deletions src/sysCommon/graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,160 +9,150 @@
#include "Texture.h"
#include "Shape.h"
#include "sysNew.h"
#include "stl/math.h"
#include "DebugLog.h"

/*
* --INFO--
* Address: ........
* Size: 00009C
*/
static void _Error(char*, ...)
{
// UNUSED FUNCTION
}
DEFINE_ERROR();

/*
* --INFO--
* Address: ........
* Size: 0000F4
*/
static void _Print(char*, ...)
{
// UNUSED FUNCTION
}
DEFINE_PRINT("Graphics");

/*
* --INFO--
* Address: ........
* Size: 000094
*/
void Colour::write(Stream&)
void Colour::write(Stream& s)
{
// UNUSED FUNCTION
r = s.readByte();
g = s.readByte();
b = s.readByte();
a = s.readByte();
}

/*
* --INFO--
* Address: ........
* Size: 000064
*/
void PVWLightingInfo::read(RandomAccessStream&)
void PVWLightingInfo::read(RandomAccessStream& s)
{
// UNUSED FUNCTION
_00 = s.readInt();
_08 = s.readFloat();
}

/*
* --INFO--
* Address: 80025914
* Size: 000120
*/
void PVWPolygonColourInfo::animate(f32*, Colour&)
void PVWPolygonColourInfo::animate(f32* data, Colour& col)
{
/*
.loc_0x0:
mflr r0
stw r0, 0x4(r1)
stwu r1, -0x48(r1)
stfd f31, 0x40(r1)
stfd f30, 0x38(r1)
stw r31, 0x34(r1)
addi r31, r5, 0
stw r30, 0x30(r1)
mr r30, r3
lwz r0, 0x4(r3)
cmplwi r0, 0
beq- .loc_0x100
cmplwi r4, 0
beq- .loc_0x84
stw r0, 0x2C(r1)
lis r0, 0x4330
lfs f31, 0x0(r4)
stw r0, 0x28(r1)
lfd f1, -0x7DD0(r2)
fabs f2, f31
lfd f0, 0x28(r1)
fsubs f30, f0, f1
fabs f0, f30
fcmpo cr0, f0, f2
ble- .loc_0x68
b .loc_0x7C
.loc_0x68:
fdivs f1, f31, f30
bl 0x1EFA74
bl 0x1EF9BC
fmuls f0, f30, f1
fsubs f31, f31, f0
.loc_0x7C:
stfs f31, 0x1C(r30)
b .loc_0xE0
.loc_0x84:
lfs f1, -0x7DD8(r2)
lis r0, 0x4330
lfs f0, 0x8(r30)
lwz r3, 0x2DEC(r13)
fmuls f1, f1, f0
lfs f2, 0x1C(r30)
lfs f0, 0x28C(r3)
fmuls f0, f1, f0
fadds f0, f2, f0
stfs f0, 0x1C(r30)
lwz r3, 0x4(r30)
lfd f1, -0x7DD0(r2)
subi r3, r3, 0x1
lfs f2, 0x1C(r30)
stw r3, 0x2C(r1)
stw r0, 0x28(r1)
lfd f0, 0x28(r1)
fsubs f0, f0, f1
fcmpo cr0, f2, f0
cror 2, 0x1, 0x2
bne- .loc_0xE0
lfs f0, -0x7DD4(r2)
stfs f0, 0x1C(r30)
// If there is no animation loaded, don't do anything
if (mTotalFrameCount == 0) {
return;
}

.loc_0xE0:
lfs f1, 0x1C(r30)
addi r4, r31, 0
addi r3, r30, 0xC
bl .loc_0x120
lfs f1, 0x1C(r30)
addi r4, r31, 0
addi r3, r30, 0x14
bl 0x4BC
if (data) {
mCurrentFrame = std::fmodf(data[0], mTotalFrameCount);
} else {
// If no new data is provided, increment the current frame
mCurrentFrame += gsys->getFrameTime() * (30.0f * mSpeed);

.loc_0x100:
lwz r0, 0x4C(r1)
lfd f31, 0x40(r1)
lfd f30, 0x38(r1)
lwz r31, 0x34(r1)
lwz r30, 0x30(r1)
addi r1, r1, 0x48
mtlr r0
blr
// Wrap around if we've reached the end of the animation
if (mCurrentFrame >= mTotalFrameCount - 1) {
mCurrentFrame = 0.0f;
}
}

.loc_0x120:
*/
// Animate colour and transparency separately
mColourInfo.extract(mCurrentFrame, col);
mAlphaInfo.extract(mCurrentFrame, col);
}

/*
* --INFO--
* Address: ........
* Size: 0000A0
*/
void subExtract(f32, struct AKeyInfo&, AKeyInfo&)
f32 subExtract(f32 time, AKeyInfo& source, AKeyInfo& destination)
{
// UNUSED FUNCTION
// Calculate differences and inverses
f32 delta = destination.mKeyframePosition - source.mKeyframePosition;
f32 invDelta = 1.0f / delta;

// Compute common terms
f32 t = (time - source.mKeyframePosition) * invDelta; // Normalized parameter
f32 t2 = t * t; // t squared
f32 t3 = t2 * t; // t cubed

// Hermite basis functions
f32 h00 = 2.0f * t3 - 3.0f * t2 + 1.0f;
f32 h10 = t3 - 2.0f * t2 + t;
f32 h01 = -2.0f * t3 + 3.0f * t2;
f32 h11 = t3 - t2;

// Compute the final interpolated value
return h00 * source.mValue + // Interpolation from b
h01 * destination.mValue + // Interpolation from c
h10 * source.mStartTangent * delta + // Tangent contribution from b
h11 * destination.mEndTangent * delta; // Tangent contribution from c
}

/*
* --INFO--
* Address: 80025A34
* Size: 000498
*/
void PVWColourAnimInfo::extract(f32, Colour&)
void PVWColourAnimInfo::extract(f32 value, Colour& target)
{
// If there is no animation data, return without modification
if (mTotalFrameCount == 0) {
return;
}

// If there is only one frame, use its values directly
if (mTotalFrameCount == 1) {
target.r = static_cast<uint8_t>((_04[0] < 0.0f) ? 0.0f : (_04[0] > 255.0f ? 255.0f : _04[0]));
target.g = static_cast<uint8_t>((_04[1] < 0.0f) ? 0.0f : (_04[1] > 255.0f ? 255.0f : _04[1]));
target.b = static_cast<uint8_t>((_04[2] < 0.0f) ? 0.0f : (_04[2] > 255.0f ? 255.0f : _04[2]));
return;
}

// Find the two keyframes to interpolate between
int index = 0;
for (int i = 0; i < static_cast<int>(mTotalFrameCount) - 1; ++i) {
f32 startTime = _04[i * 4];
f32 endTime = _04[(i + 1) * 4];
if (startTime <= value && value <= endTime) {
index = i;
break;
}
}

// Construct keyframe data for interpolation
AKeyInfo startKey(_04[index * 4], _04[index * 4 + 1], _04[index * 4 + 2], _04[index * 4 + 3]);
AKeyInfo endKey(_04[(index + 1) * 4], _04[(index + 1) * 4 + 1], _04[(index + 1) * 4 + 2], _04[(index + 1) * 4 + 3]);

// Interpolate each color channel
f32 r = subExtract(value, startKey, endKey);
f32 g = subExtract(value, startKey, endKey);
f32 b = subExtract(value, startKey, endKey);

// Clamp and assign to target
target.r = static_cast<u8>(r < 0.0f ? 0 : (r > 255.0f ? 255 : r));
target.g = static_cast<u8>(g < 0.0f ? 0 : (g > 255.0f ? 255 : g));
target.b = static_cast<u8>(b < 0.0f ? 0 : (b > 255.0f ? 255 : b));

/*
.loc_0x0:
stwu r1, -0x1F8(r1)
Expand Down

0 comments on commit afe6708

Please sign in to comment.