Skip to content

Commit

Permalink
Resync nw4hbm with nw4r files
Browse files Browse the repository at this point in the history
  • Loading branch information
CelestialAmber committed Sep 16, 2024
1 parent 756cd5a commit 8b46507
Show file tree
Hide file tree
Showing 35 changed files with 2,683 additions and 1,935 deletions.
27 changes: 21 additions & 6 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"${workspaceFolder}/libs/monolib/include",
"${workspaceFolder}/libs/NdevExi2A/include",
"${workspaceFolder}/libs/nw4r/include",
"${workspaceFolder}/libs/nw4r/include/nw4r/",
"${workspaceFolder}/libs/nw4r/include/nw4r",
"${workspaceFolder}/libs/nw4r/include/nw4r/db",
"${workspaceFolder}/libs/nw4r/include/nw4r/g3d",
"${workspaceFolder}/libs/nw4r/include/nw4r/ut",
Expand All @@ -18,7 +18,12 @@
"${workspaceFolder}/libs/nw4r/include/nw4r/math",
"${workspaceFolder}/libs/PowerPC_EABI_Support/include",
"${workspaceFolder}/libs/PowerPC_EABI_Support/include/stl",
"${workspaceFolder}/libs/RVL_SDK/include"
"${workspaceFolder}/libs/RVL_SDK/include",
"${workspaceFolder}/libs/RVL_SDK/src/revolution/hbm/include",
"${workspaceFolder}/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm",
"${workspaceFolder}/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/ut",
"${workspaceFolder}/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/lyt",
"${workspaceFolder}/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/math"
],
"cStandard": "c99",
"cppStandard": "c++98",
Expand All @@ -38,7 +43,7 @@
"${workspaceFolder}/libs/monolib/include",
"${workspaceFolder}/libs/NdevExi2A/include",
"${workspaceFolder}/libs/nw4r/include",
"${workspaceFolder}/libs/nw4r/include/nw4r/",
"${workspaceFolder}/libs/nw4r/include/nw4r",
"${workspaceFolder}/libs/nw4r/include/nw4r/db",
"${workspaceFolder}/libs/nw4r/include/nw4r/g3d",
"${workspaceFolder}/libs/nw4r/include/nw4r/ut",
Expand All @@ -47,7 +52,12 @@
"${workspaceFolder}/libs/nw4r/include/nw4r/math",
"${workspaceFolder}/libs/PowerPC_EABI_Support/include",
"${workspaceFolder}/libs/PowerPC_EABI_Support/include/stl",
"${workspaceFolder}/libs/RVL_SDK/include"
"${workspaceFolder}/libs/RVL_SDK/include",
"${workspaceFolder}/libs/RVL_SDK/src/revolution/hbm/include",
"${workspaceFolder}/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm",
"${workspaceFolder}/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/ut",
"${workspaceFolder}/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/lyt",
"${workspaceFolder}/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/math"
],
"cStandard": "c99",
"cppStandard": "c++98",
Expand All @@ -67,7 +77,7 @@
"${workspaceFolder}/libs/monolib/include",
"${workspaceFolder}/libs/NdevExi2A/include",
"${workspaceFolder}/libs/nw4r/include",
"${workspaceFolder}/libs/nw4r/include/nw4r/",
"${workspaceFolder}/libs/nw4r/include/nw4r",
"${workspaceFolder}/libs/nw4r/include/nw4r/db",
"${workspaceFolder}/libs/nw4r/include/nw4r/g3d",
"${workspaceFolder}/libs/nw4r/include/nw4r/ut",
Expand All @@ -76,7 +86,12 @@
"${workspaceFolder}/libs/nw4r/include/nw4r/math",
"${workspaceFolder}/libs/PowerPC_EABI_Support/include",
"${workspaceFolder}/libs/PowerPC_EABI_Support/include/stl",
"${workspaceFolder}/libs/RVL_SDK/include"
"${workspaceFolder}/libs/RVL_SDK/include",
"${workspaceFolder}/libs/RVL_SDK/src/revolution/hbm/include",
"${workspaceFolder}/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm",
"${workspaceFolder}/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/ut",
"${workspaceFolder}/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/lyt",
"${workspaceFolder}/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/math"
],
"cStandard": "c99",
"cppStandard": "c++98",
Expand Down
4 changes: 2 additions & 2 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@
"-sdata 0",
"-sdata2 0",
"-RTTI on",
"-i libs/RVL_SDK/src/revolution/hbm/include/",
"-ir libs/RVL_SDK/src/revolution/hbm/include/",
]

# Ndev flags
Expand Down Expand Up @@ -1392,7 +1392,7 @@ def nw4rLib(lib_name, objects, extra_cflags=[]):
[
Object(Matching, "db/db_console.cpp"),
Object(Matching, "db/db_DbgPrintBase.cpp"),
Object(Matching, "db/db_assert.cpp", extra_cflags=["-ipa file"]),
Object(Matching, "db/db_assert.cpp"),
],
),
nw4rLib(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once

#include "nw4hbm/types_nw4hbm.h"
#include "nw4hbm/math/math_types.h"
#include "nw4hbm/ut/ut_Rect.h"
#ifndef NW4HBM_LYT_DRAWINFO_H
#define NW4HBM_LYT_DRAWINFO_H
#include "types_nw4hbm.h"
#include "math_types.h"
#include "ut_Rect.h"

namespace nw4hbm
{
Expand All @@ -21,3 +21,5 @@ namespace nw4hbm
};
}
}

#endif
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
#pragma once

#include "nw4hbm/types_nw4hbm.h"
#include "nw4hbm/ut/ut_Font.h"
#ifndef NW4HBM_LYT_RESOURCE_ACCESSOR_H
#define NW4HBM_LYT_RESOURCE_ACCESSOR_H
#include "types_nw4hbm.h"
#include "ut_Font.h"

namespace nw4hbm
{
namespace lyt
{
struct ResourceAccessor
class ResourceAccessor
{
public:
ResourceAccessor();
virtual ~ResourceAccessor();
virtual void GetResource(u32, const char *, u32 *) = 0;
virtual ut::Font * GetFont(const char *);
virtual ~ResourceAccessor(); // at 0x8
virtual UNKTYPE * GetResource(u32, const char *, u32 *) = 0; // at 0xC
virtual ut::Font * GetFont(const char *); // at 0x10
};
}
}

#endif
9 changes: 9 additions & 0 deletions libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/math.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef NW4HBM_PUBLIC_MATH_H
#define NW4HBM_PUBLIC_MATH_H

#include <nw4hbm/math/math_arithmetic.h>
#include <nw4hbm/math/math_geometry.h>
#include <nw4hbm/math/math_triangular.h>
#include <nw4hbm/math/math_types.h>

#endif
129 changes: 129 additions & 0 deletions libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/math/math_arithmetic.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
#ifndef NW4HBM_MATH_ARITHMETIC_H
#define NW4HBM_MATH_ARITHMETIC_H
#include <cmath>
#include <nw4hbm/types_nw4hbm.h>
#include <revolution/OS.h>

#define NW4R_MATH_QNAN (-(0.0f / 0.0f))
#define NW4R_MATH_FLT_MAX 3.402823466e+38f

namespace nw4hbm {
namespace math {
namespace detail {

f32 FExp(f32 x);
f32 FLog(f32 x);

} // namespace detail

f32 FrSqrt(f32 x);

inline f32 FAbs(register f32 x) {
// clang-format off
asm {
fabs x, x
}
// clang-format on

return x;
}

inline f32 FCeil(f32 x) { return std::ceilf(x); }

inline f32 FExp(f32 x) { return detail::FExp(x); }

inline f32 FFloor(f32 x) { return std::floorf(x); }

inline f32 FInv(register f32 x) {
register f32 work0, work1, work2, work3;

// clang-format off
asm {
fmr work1, x // x
fres work0, work1 // 1/x

// Refine estimate
ps_add work2, work0, work0 // 2/x
ps_mul work3, work0, work0 // 1/x^2
ps_nmsub work0, work1, work3, work2 // -(x * 1/x^2 - 2/x)
}
// clang-format on

return work0;
}

inline f32 FMod(f32 x, f32 y) { return std::fmodf(x, y); }

inline f32 FModf(f32 x, f32* y) { return std::modff(x, y); }

inline f32 FSqrt(f32 x) {
if (x < 0.0f) {
return 0.0f;
}

return x * FrSqrt(x);
}

inline f32 FLog(f32 x) {
if (x >= 0.0f) {
return detail::FLog(x);
}

return NW4R_MATH_QNAN;
}

inline f32 FSelect(register f32 value, register f32 ge_zero,
register f32 lt_zero) {
register f32 ret;

// clang-format off
asm {
fsel ret, value, ge_zero, lt_zero
}
// clang-format on

return ret;
}

inline f32 U16ToF32(u16 arg) {
f32 ret;
OSu16tof32(&arg, &ret);
return ret;
}

inline u16 F32ToU16(f32 arg) {
u16 ret;
OSf32tou16(&arg, &ret);
return ret;
}

inline f32 S16ToF32(s16 arg) {
f32 ret;
OSs16tof32(&arg, &ret);
return ret;
}

inline s16 F32ToS16(f32 arg) {
s16 ret;
OSf32tos16(&arg, &ret);
return ret;
}

inline u32 F32AsU32(f32 arg) { return *reinterpret_cast<u32*>(&arg); }

inline f32 U32AsF32(u32 arg) { return *reinterpret_cast<f32*>(&arg); }

inline s32 FGetExpPart(f32 x) {
s32 s = F32AsU32(x);
return ((s >> 23) & 0xFF) - 0x7F;
}

inline f32 FGetMantPart(f32 x) {
u32 u = F32AsU32(x);
return U32AsF32((u & 0x807FFFFF) | 0x3F800000);
}

} // namespace math
} // namespace nw4hbm

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#ifndef NW4HBM_MATH_GEOMETRY_H
#define NW4HBM_MATH_GEOMETRY_H
#include <nw4hbm/math/math_types.h>
#include <nw4hbm/types_nw4hbm.h>

namespace nw4hbm {
namespace math {

enum IntersectionResult {
INTERSECTION_NONE,
INTERSECTION_1,
INTERSECTION_2,

INTERSECTION_LINE3_ON_PLANE = INTERSECTION_2,
INTERSECTION_RAY3_ON_PLANE = INTERSECTION_2,
INTERSECTION_SEGMENT3_ON_PLANE = INTERSECTION_2,

INTERSECTION_OUTSIDE = 0,
INTERSECTION_INSIDE,
INTERSECTION_INTERSECT
};

struct PLANE {
PLANE() {}

f32 Test(const VEC3& point) const { return d + VEC3Dot(&n, &point); }
void Set(const VEC3* p0, const VEC3* p1, const VEC3* p2);

VEC3 n; // at 0x0
f32 d; // at 0xC
};

struct AABB {
AABB() {}

void Set(const VEC3* points, unsigned int num);
void Set(const AABB* box, const MTX34* mtx);

VEC3 min; // at 0x0
VEC3 max; // at 0xC
};

class FRUSTUM {
private:
enum Point {
POINT_NEAR_TL,
POINT_NEAR_TR,
POINT_NEAR_BR,
POINT_NEAR_BL,

POINT_FAR_TL,
POINT_FAR_TR,
POINT_FAR_BR,
POINT_FAR_BL,

POINT_MAX
};

enum Plane {
PLANE_L,
PLANE_R,
PLANE_N,
PLANE_F,
PLANE_T,
PLANE_B,

PLANE_MAX
};

public:
void Set(f32 fovy, f32 aspect, f32 n, f32 f, const MTX34& cam);
void Set(f32 t, f32 b, f32 l, f32 r, f32 n, f32 f, const MTX34& cam);

IntersectionResult IntersectAABB_Ex(const AABB* box) const;

private:
MTX34 mCamMtx; // at 0x0
PLANE mPlaneL; // at 0x30
PLANE mPlaneR; // at 0x40
PLANE mPlaneT; // at 0x50
PLANE mPlaneB; // at 0x60
f32 mNearZ; // at 0x70
f32 mFarZ; // at 0x74
AABB mBox; // at 0x78
PLANE mPlanes[PLANE_MAX]; // at 0x90
};

bool IntersectionAABB(const AABB* a, const AABB* b);

} // namespace math
} // namespace nw4hbm

#endif
Loading

0 comments on commit 8b46507

Please sign in to comment.