From 8b46507088ffbf8e30e2b1650ae10dd6ae17106c Mon Sep 17 00:00:00 2001 From: Amber Brault Date: Mon, 16 Sep 2024 16:28:54 -0400 Subject: [PATCH] Resync nw4hbm with nw4r files --- .vscode/c_cpp_properties.json | 27 +- configure.py | 4 +- .../hbm/include/nw4hbm/lyt/lyt_drawInfo.h | 12 +- .../include/nw4hbm/lyt/lyt_resourceAccessor.h | 18 +- .../src/revolution/hbm/include/nw4hbm/math.h | 9 + .../hbm/include/nw4hbm/math/math_arithmetic.h | 129 +++ .../hbm/include/nw4hbm/math/math_geometry.h | 93 +++ .../hbm/include/nw4hbm/math/math_triangular.h | 87 ++ .../hbm/include/nw4hbm/math/math_types.h | 781 ++++++++++++------ .../hbm/include/nw4hbm/types_nw4hbm.h | 139 +++- .../src/revolution/hbm/include/nw4hbm/ut.h | 17 + .../hbm/include/nw4hbm/ut/ut_CharStrmReader.h | 96 +-- .../hbm/include/nw4hbm/ut/ut_CharWriter.h | 324 ++++---- .../hbm/include/nw4hbm/ut/ut_Color.h | 123 +-- .../hbm/include/nw4hbm/ut/ut_Font.h | 138 ++-- .../hbm/include/nw4hbm/ut/ut_Glyph.h | 29 - .../hbm/include/nw4hbm/ut/ut_LinkList.h | 624 +++++++++----- .../hbm/include/nw4hbm/ut/ut_NonCopyable.h | 20 + .../hbm/include/nw4hbm/ut/ut_Rect.h | 86 +- .../hbm/include/nw4hbm/ut/ut_ResFont.h | 37 +- .../hbm/include/nw4hbm/ut/ut_ResFontBase.h | 228 +++-- .../include/nw4hbm/ut/ut_TagProcessorBase.h | 80 +- .../hbm/include/nw4hbm/ut/ut_TextWriterBase.h | 148 ++-- .../include/nw4hbm/ut/ut_binaryFileFormat.h | 51 +- .../hbm/nw4hbm/ut/ut_CharStrmReader.cpp | 128 ++- .../src/revolution/hbm/nw4hbm/ut/ut_Font.cpp | 48 +- .../revolution/hbm/nw4hbm/ut/ut_LinkList.cpp | 128 +-- .../revolution/hbm/nw4hbm/ut/ut_ResFont.cpp | 208 ++--- .../hbm/nw4hbm/ut/ut_ResFontBase.cpp | 414 +++++----- .../hbm/nw4hbm/ut/ut_TagProcessorBase.cpp | 272 ++---- .../hbm/nw4hbm/ut/ut_binaryFileFormat.cpp | 54 +- libs/nw4r/include/nw4r/math.h | 1 - libs/nw4r/include/nw4r/math/math_triangular.h | 27 + libs/nw4r/include/nw4r/math/triangular.h | 36 - libs/nw4r/src/db/db_assert.cpp | 2 + 35 files changed, 2683 insertions(+), 1935 deletions(-) create mode 100644 libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/math.h create mode 100644 libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/math/math_arithmetic.h create mode 100644 libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/math/math_geometry.h create mode 100644 libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/math/math_triangular.h create mode 100644 libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/ut.h delete mode 100644 libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/ut/ut_Glyph.h create mode 100644 libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/ut/ut_NonCopyable.h delete mode 100644 libs/nw4r/include/nw4r/math/triangular.h diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 86ddc6495..f1e0ca5fb 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", diff --git a/configure.py b/configure.py index f5d02df7c..fdc5100b3 100644 --- a/configure.py +++ b/configure.py @@ -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 @@ -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( diff --git a/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/lyt/lyt_drawInfo.h b/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/lyt/lyt_drawInfo.h index e977b4ee0..08ffccaa9 100644 --- a/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/lyt/lyt_drawInfo.h +++ b/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/lyt/lyt_drawInfo.h @@ -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 { @@ -21,3 +21,5 @@ namespace nw4hbm }; } } + +#endif diff --git a/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/lyt/lyt_resourceAccessor.h b/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/lyt/lyt_resourceAccessor.h index b0a9d13e9..8f9521298 100644 --- a/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/lyt/lyt_resourceAccessor.h +++ b/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/lyt/lyt_resourceAccessor.h @@ -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 diff --git a/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/math.h b/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/math.h new file mode 100644 index 000000000..03032b5c3 --- /dev/null +++ b/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/math.h @@ -0,0 +1,9 @@ +#ifndef NW4HBM_PUBLIC_MATH_H +#define NW4HBM_PUBLIC_MATH_H + +#include +#include +#include +#include + +#endif diff --git a/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/math/math_arithmetic.h b/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/math/math_arithmetic.h new file mode 100644 index 000000000..941d8c90d --- /dev/null +++ b/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/math/math_arithmetic.h @@ -0,0 +1,129 @@ +#ifndef NW4HBM_MATH_ARITHMETIC_H +#define NW4HBM_MATH_ARITHMETIC_H +#include +#include +#include + +#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(&arg); } + +inline f32 U32AsF32(u32 arg) { return *reinterpret_cast(&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 diff --git a/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/math/math_geometry.h b/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/math/math_geometry.h new file mode 100644 index 000000000..cab21968c --- /dev/null +++ b/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/math/math_geometry.h @@ -0,0 +1,93 @@ +#ifndef NW4HBM_MATH_GEOMETRY_H +#define NW4HBM_MATH_GEOMETRY_H +#include +#include + +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 diff --git a/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/math/math_triangular.h b/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/math/math_triangular.h new file mode 100644 index 000000000..dfc2e95f8 --- /dev/null +++ b/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/math/math_triangular.h @@ -0,0 +1,87 @@ +#ifndef NW4HBM_MATH_TRIANGULAR_H +#define NW4HBM_MATH_TRIANGULAR_H +#include +#include + +#define NW4R_MATH_PI 3.141592653589793f +#define NW4R_MATH_LN_2 0.69314718056f + +// [0, 65535] -> [0.0, 256.0f] +#define NW4R_MATH_IDX_TO_FIDX(x) ((x) * (1.0f / 256.0f)) + +// Convert degrees <-> lookup-table index +#define NW4R_MATH_DEG_TO_FIDX(x) ((x) * (256.0f / 360.0f)) +#define NW4R_MATH_FIDX_TO_DEG(x) ((x) * (360.0f / 256.0f)) + +// Convert radians <-> lookup-table index +#define NW4R_MATH_RAD_TO_FIDX(x) ((x) * (128.0f / NW4R_MATH_PI)) +#define NW4R_MATH_FIDX_TO_RAD(x) ((x) * (NW4R_MATH_PI / 128.0f)) + +namespace nw4hbm { +namespace math { + +/** + * sin + */ +f32 SinFIdx(f32 fidx); + +inline f32 SinIdx(u16 idx) { + return SinFIdx(NW4R_MATH_IDX_TO_FIDX(U16ToF32(idx))); +} + +inline f32 SinDeg(f32 deg) { return SinFIdx(NW4R_MATH_DEG_TO_FIDX(deg)); } +inline f32 SinRad(f32 rad) { return SinFIdx(NW4R_MATH_RAD_TO_FIDX(rad)); } + +/** + * cos + */ +f32 CosFIdx(f32 fidx); + +inline f32 CosDeg(f32 deg) { return CosFIdx(NW4R_MATH_DEG_TO_FIDX(deg)); } +inline f32 CosRad(f32 rad) { return CosFIdx(NW4R_MATH_RAD_TO_FIDX(rad)); } + +/** + * tan + */ +inline f32 TanFIdx(f32 fidx) { return std::tanf(NW4R_MATH_FIDX_TO_RAD(fidx)); } +inline f32 TanDeg(f32 deg) { return TanFIdx(NW4R_MATH_DEG_TO_FIDX(deg)); } +inline f32 TanRad(f32 rad) { return TanFIdx(NW4R_MATH_RAD_TO_FIDX(rad)); } + +/** + * sin/cos + */ +void SinCosFIdx(f32* pSin, f32* pCos, f32 fidx); + +inline void SinCosDeg(f32* pSin, f32* pCos, f32 deg) { + return SinCosFIdx(pSin, pCos, NW4R_MATH_DEG_TO_FIDX(deg)); +} + +inline void SinCosRad(f32* pSin, f32* pCos, f32 rad) { + return SinCosFIdx(pSin, pCos, NW4R_MATH_RAD_TO_FIDX(rad)); +} + +/** + * atan + */ +f32 AtanFIdx(f32 x); + +inline f32 AtanDeg(f32 x) { return NW4R_MATH_FIDX_TO_DEG(AtanFIdx(x)); } +inline f32 AtanRad(f32 x) { return NW4R_MATH_FIDX_TO_RAD(AtanFIdx(x)); } + +/** + * atan2 + */ +f32 Atan2FIdx(f32 y, f32 x); + +inline f32 Atan2Deg(f32 y, f32 x) { + return NW4R_MATH_FIDX_TO_DEG(Atan2FIdx(y, x)); +} + +inline f32 Atan2Rad(f32 y, f32 x) { + return NW4R_MATH_FIDX_TO_RAD(Atan2FIdx(y, x)); +} + +} // namespace math +} // namespace nw4hbm + +#endif diff --git a/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/math/math_types.h b/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/math/math_types.h index fe3c95375..af1e14ca9 100644 --- a/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/math/math_types.h +++ b/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/math/math_types.h @@ -1,306 +1,543 @@ -#pragma once - -#include "nw4hbm/types_nw4hbm.h" +#ifndef NW4HBM_MATH_TYPES_H +#define NW4HBM_MATH_TYPES_H +#include +#include +#include #include -#define NW4R_PI_F32 3.1415927f -#define NW4R_DEG_TO_FIDX (256.0f / 360.0f) -#define NW4R_FIDX_TO_DEG (2.0f * NW4R_PI_F32 / 256.0f) -#define NW4R_MATH_BLOG_TO_LN 1.442695f -#define NW4R_LN_2 0.6931472f - -namespace nw4hbm -{ - // TODO: Implement objects accurately - namespace math - { - struct _VEC2 - { - f32 x, y; - }; - - struct VEC2 - { - _VEC2 mCoords; +namespace nw4hbm { +namespace math { - inline VEC2() {} +/****************************************************************************** + * + * VEC2 structure + * + ******************************************************************************/ +// Optimization: Forces copy by lwz/stw +struct _VEC2 { + f32 x, y; +}; - inline VEC2(f32 x, f32 y) - { - mCoords.x = x; - mCoords.y = y; - } - }; - - struct _VEC3 - { - f32 x, y, z; - }; - - inline void VEC3Add(register VEC3 * destVec, register const VEC3 * srcVec1, register const VEC3 * srcVec2) - { - asm - { - psq_l f2, 0x0(srcVec1), 0, 0 - psq_l f2, 0x0(srcVec2), 0, 0 - ps_add f0, f2, f1 - psq_l f2, 0x8(srcVec1), 1, 0 - psq_l f2, 0x8(srcVec2), 1, 0 - psq_st f0, 0x0(destVec), 0, 0 - ps_add f0, f2, f1 - psq_st f0, 0x8(destVec), 1, 0 - } - } - - inline void VEC3Sub(register VEC3 * destVec, register const VEC3 * srcVec1, register const VEC3 * srcVec2) - { - asm - { - psq_l f2, 0x0(srcVec1), 0, 0 - psq_l f2, 0x0(srcVec2), 0, 0 - ps_sub f0, f2, f1 - psq_l f2, 0x8(srcVec1), 1, 0 - psq_l f2, 0x8(srcVec2), 1, 0 - psq_st f0, 0x0(destVec), 0, 0 - ps_sub f0, f2, f1 - psq_st f0, 0x8(destVec), 1, 0 - } - } - - inline void VEC3Scale(register VEC3 * outVec, register const VEC3 * inVec, register f32 scalar) - { - asm - { - psq_l f2, 0x0(inVec), 0, 0 - ps_muls0 f1, f2, scalar - psq_l f2, 0x8(inVec), 0, 1 - psq_st f1, 0x0(outVec), 0, 0 - ps_muls0 f1, f2, scalar - psq_st f1, 0x8(outVec), 1, 0 - } - } - - inline f32 VEC3Dot(register const VEC3 * vec1, register const VEC3 * vec2) - { - register f32 a, b, d, c, e; - asm - { - psq_l a, 0x4(vec1), 0, 0 - psq_l b, 0x4(vec2), 0, 0 - ps_mul a, a, b - psq_l c, 0(vec1), 1, 0 - psq_l d, 0(vec2), 1, 0 - ps_madd b, c, d, a - ps_sum0 e, b, a, a - } - return e; - } - - struct VEC3 - { - _VEC3 mCoords; - - inline VEC3() {} - - inline VEC3(const VEC3 & other) : mCoords(other.mCoords) {} - - inline VEC3 & operator=(const VEC3 & other) - { - mCoords = other.mCoords; - return *this; - } - - inline VEC3(f32 x, f32 y, f32 z) - { - mCoords.x = x; - mCoords.y = y; - mCoords.z = z; - } - - inline VEC3 operator-(register const VEC3 & other) const - { - VEC3 ret; - - VEC3Sub(&ret, this, &other); - - return ret; - } - - inline bool operator!=(const VEC3 & other) const - { - return mCoords.x != other.mCoords.x || mCoords.y != other.mCoords.y || mCoords.z != other.mCoords.z; - } - - inline operator Vec *() - { - return reinterpret_cast(this); - } - - inline operator const Vec *() const - { - return reinterpret_cast(this); - } - }; - - struct _MTX33 - { - f32 tbl[3][3]; - }; +struct VEC2 : _VEC2 { + VEC2() {} + VEC2(f32 fx, f32 fy) { + x = fx; + y = fy; + } - struct MTX33 - { - _MTX33 mEntries; - - typedef f32 (* MtxRef)[3]; - typedef const f32 (* MtxRefConst)[3]; - - inline operator MtxRef() - { - return mEntries.tbl; - } - - inline operator MtxRefConst() const - { - return mEntries.tbl; - } - }; + operator f32*() { return reinterpret_cast(this); } + operator const f32*() const { return reinterpret_cast(this); } - struct _MTX34 - { - f32 tbl[3][4]; - }; - - struct MTX34 - { - _MTX34 mEntries; - - typedef f32 (* MtxRef)[4]; - typedef const f32 (* MtxRefConst)[4]; - - inline operator MtxRef() - { - return mEntries.tbl; - } - - inline operator MtxRefConst() const - { - return mEntries.tbl; - } - }; + VEC2 operator+(const VEC2& rhs) const { return VEC2(x + rhs.x, y + rhs.y); } + VEC2 operator-(const VEC2& rhs) const { return VEC2(x - rhs.x, y - rhs.y); } + + VEC2& operator+=(const VEC2& rhs) { + x += rhs.x; + y += rhs.y; + return *this; + } + VEC2& operator-=(const VEC2& rhs) { + x -= rhs.x; + y -= rhs.y; + return *this; + } + + bool operator==(const VEC2& rhs) const { return x == rhs.x && y == rhs.y; } + bool operator!=(const VEC2& rhs) const { return x != rhs.x || y != rhs.y; } +}; + +/****************************************************************************** + * + * VEC3 structure + * + ******************************************************************************/ +// Forward declarations +VEC3* VEC3Add(VEC3* out, const VEC3* a, const VEC3* b); +VEC3* VEC3Sub(VEC3* out, const VEC3* a, const VEC3* b); +VEC3* VEC3Scale(VEC3* out, const VEC3* in, f32 scale); + +// Optimization: Forces copy by lwz/stw +struct _VEC3 { + f32 x, y, z; +}; + +struct VEC3 : _VEC3 { + VEC3() {} + VEC3(f32 fx, f32 fy, f32 fz) { + x = fx; + y = fy; + z = fz; + } + VEC3(const Vec& vec) { + x = vec.x; + y = vec.y; + z = vec.z; + } + VEC3(const f32* p) { + x = p[0]; + y = p[1]; + z = p[2]; + } + + operator Vec*() { return reinterpret_cast(this); } + operator const Vec*() const { return reinterpret_cast(this); } - struct _MTX44 - { - f32 tbl[4][4]; + f32 LenSq() const { return x * x + y * y + z * z; } + + VEC3 operator-() const { return VEC3(-x, -y, -z); } + + VEC3 operator+(const VEC3& rhs) const { + VEC3 out; + VEC3Add(&out, this, &rhs); + return out; + } + VEC3 operator-(const VEC3& rhs) const { + VEC3 out; + VEC3Sub(&out, this, &rhs); + return out; + } + VEC3 operator*(f32 x) const { + VEC3 out; + VEC3Scale(&out, this, x); + return out; + } + VEC3 operator/(f32 x) const { + f32 r = 1 / x; + return *this * r; + } + + VEC3& operator+=(const VEC3& rhs) { + VEC3Add(this, this, &rhs); + return *this; + } + VEC3& operator-=(const VEC3& rhs) { + VEC3Sub(this, this, &rhs); + return *this; + } + VEC3& operator*=(f32 x) { + VEC3Scale(this, this, x); + return *this; + } + VEC3& operator/=(f32 x) { return *this *= (1 / x); } + + bool operator==(const VEC3& rhs) const { + return x == rhs.x && y == rhs.y && z == rhs.z; + } + bool operator!=(const VEC3& rhs) const { + return x != rhs.x || y != rhs.y || z != rhs.z; + } +}; + +/****************************************************************************** + * + * MTX33 structure + * + ******************************************************************************/ +// Optimization: Forces copy by lwz/stw +struct _MTX33 { + union { + struct { + f32 _00, _01, _02; + f32 _10, _11, _12; + f32 _20, _21, _22; }; - struct MTX44 - { - _MTX44 mEntries; - - typedef f32 (* MtxRef)[4]; - typedef const f32 (* MtxRefConst)[4]; - - inline operator MtxRef() - { - return mEntries.tbl; - } - - inline operator MtxRefConst() const - { - return mEntries.tbl; - } + f32 m[3][3]; + f32 a[3 * 3]; + }; +}; + +struct MTX33 : _MTX33 { + MTX33() {} +}; + +/****************************************************************************** + * + * MTX34 structure + * + ******************************************************************************/ +// Optimization: Forces copy by lwz/stw +struct _MTX34 { + union { + struct { + f32 _00, _01, _02, _03; + f32 _10, _11, _12, _13; + f32 _20, _21, _22, _23; }; - inline void VEC3Cross(VEC3 * out, const VEC3 * in1, const VEC3 * in2) - { - PSVECCrossProduct(*in1, *in2, *out); - } + f32 m[3][4]; + f32 a[3 * 4]; + Mtx mtx; + }; +}; - void VEC3Maximize(VEC3 *, const VEC3 *, const VEC3 *); - void VEC3Minimize(VEC3 *, const VEC3 *, const VEC3 *); +struct MTX34 : _MTX34 { + typedef f32 (*MtxRef)[4]; + typedef const f32 (*MtxRefConst)[4]; - inline void VEC3Normalize(VEC3 * out, const VEC3 * in) - { - PSVECNormalize(*in, *out); - } - - inline f32 VEC3DistSq(const VEC3 * point1, const VEC3 * point2) - { - return PSVECSquareDistance(*point1, *point2); - } - - inline void VEC3Transform(VEC3 * outVec, const MTX34 * mtx, const VEC3 * inVec) - { - PSMTXMultVec(*mtx, *inVec, *outVec); - } - - void MTX33Identity(register MTX33 *); + MTX34() {} + + // clang-format off + MTX34(f32 f00, f32 f01, f32 f02, f32 f03, + f32 f10, f32 f11, f32 f12, f32 f13, + f32 f20, f32 f21, f32 f22, f32 f23) { + _00 = f00; _01 = f01; _02 = f02; _03 = f03; + _10 = f10; _11 = f11; _12 = f12; _13 = f13; + _20 = f20; _21 = f21; _22 = f22; _23 = f23; + } + // clang-format on + + operator MtxRef() { return mtx; } + operator MtxRefConst() const { return mtx; } +}; - int MTX34InvTranspose(register MTX33 *, register const MTX34 *); +/****************************************************************************** + * + * MTX44 structure + * + ******************************************************************************/ +// Optimization: Forces copy by lwz/stw +struct _MTX44 { + union { + struct { + f32 _00, _01, _02, _03; + f32 _10, _11, _12, _13; + f32 _20, _21, _22, _23; + f32 _30, _31, _32, _33; + }; - void MTX34ToMTX33(register MTX33 *, register const MTX34 *); + f32 m[4][4]; + f32 a[4 * 4]; + Mtx44 mtx; + }; +}; - void MTX34Zero(register MTX34 *); +struct MTX44 : _MTX44 { + typedef f32 (*Mtx44Ref)[4]; + typedef const f32 (*Mtx44RefConst)[4]; - inline void MTX34Inv(MTX34 * out, const MTX34 * in) - { - PSMTXInverse(*in, *out); - } - - void MTX34Mult(MTX34 * outMtx, const MTX34 * inMtx1, const MTX34 * inMtx2) - { - PSMTXConcat(*inMtx1, *inMtx2, *outMtx); - } + MTX44() {} - void MTX34Add(MTX34* out, const MTX34* mtx1, const MTX34* mtx2); + operator Mtx44Ref() { return mtx; } + operator Mtx44RefConst() const { return mtx; } +}; - void MTX34Mult(MTX34* out, const MTX34* in, f32 factor); +/****************************************************************************** + * + * QUAT structure + * + ******************************************************************************/ +// Optimization: Forces copy by lwz/stw +struct _QUAT { + f32 x, y, z, w; +}; - void MTX34Scale(register MTX34 *, register const MTX34 *, register const VEC3 *); +struct QUAT : _QUAT { + QUAT() {} + QUAT(f32 fx, f32 fy, f32 fz, f32 fw) { + x = fx; + y = fy; + z = fz; + w = fw; + } - void MTX34Trans(register MTX34 *, register const MTX34 *, register const VEC3 *); + // These are not real AFAIK. Do they really manually cast the QUAT? + operator Quaternion*() { return reinterpret_cast(this); } + operator const Quaternion*() const { + return reinterpret_cast(this); + } +}; - MTX34 * MTX34RotAxisFIdx(MTX34 *, const VEC3 *, f32 ); +/****************************************************************************** + * + * VEC2 functions + * + ******************************************************************************/ +inline f32 VEC2Len(const VEC2* vec) { + return FSqrt(vec->x * vec->x + vec->y * vec->y); +} - MTX34 * MTX34RotXYZFIdx(MTX34 *, f32, f32, f32); +/****************************************************************************** + * + * VEC3 functions + * + ******************************************************************************/ +VEC3* VEC3Maximize(VEC3* out, const VEC3* a, const VEC3* b); +VEC3* VEC3Minimize(VEC3* out, const VEC3* a, const VEC3* b); +VEC3* VEC3TransformNormal(VEC3* out, const MTX34* mtx, const VEC3* vec); - inline void MTX34Identity(MTX34 * mtx) - { - PSMTXIdentity(*mtx); - } - - inline void MTX34Copy(MTX34 * out, const MTX34 * in) - { - PSMTXCopy(*in, *out); - } +inline VEC3* VEC3Add(register VEC3* out, register const VEC3* a, + register const VEC3* b) { + register f32 work0, work1, work2; + + // clang-format off + asm { + // Add XY + psq_l work0, VEC3.x(a), 0, 0 + psq_l work1, VEC3.x(b), 0, 0 + ps_add work2, work0, work1 + psq_st work2, VEC3.x(out), 0, 0 - VEC3 * VEC3TransformNormal(VEC3 *, const MTX34 *, const VEC3 *); + // Add Z + psq_l work0, VEC3.z(a), 1, 0 + psq_l work1, VEC3.z(b), 1, 0 + ps_add work2, work0, work1 + psq_st work2, VEC3.z(out), 1, 0 + } + // clang-format on - void MTX44Identity(register MTX44 *); + return out; +} - void MTX44Copy(register MTX44 *, register const MTX44 *); +inline f32 VEC3Dot(register const VEC3* a, register const VEC3* b) { + register f32 dot; + register f32 work0, work1, work2, work3; - //UNKTYPE GetDirMtxY(MTX34 *, const VEC3 &); - - MTX34 * MTX34RotXYZFIdx(MTX34 *, f32, f32, f32); + // clang-format off + asm { + // YZ product + psq_l work0, VEC3.y(a), 0, 0 + psq_l work1, VEC3.y(b), 0, 0 + ps_mul work0, work0, work1 - inline void MTX34Scale(MTX34 * outMtx, const VEC3 * vec, const MTX34 * inMtx) - { - PSMTXScaleApply(*inMtx, *outMtx, vec->mCoords.x, vec->mCoords.y, vec->mCoords.z); - } + // X product + YZ product + psq_l work3, VEC3.x(a), 1, 0 + psq_l work2, VEC3.x(b), 1, 0 + ps_madd work1, work3, work2, work0 - //UNKTYPE MtxGetRotation(const MTX34 &, VEC3 *); - - f32 FrSqrt(f32); + // Dot product + ps_sum0 dot, work1, work0, work0 + } + // clang-format on + + return dot; +} + +inline f32 VEC3LenSq(register const VEC3* vec) { + register f32 work0, work1, work2; + + // clang-format off + asm { + // Square XY + psq_l work0, VEC3.x(vec), 0, 0 + ps_mul work0, work0, work0 + + // Square Z + lfs work1, VEC3.z(vec) + ps_madd work2, work1, work1, work0 + + // Sum products + ps_sum0 work2, work2, work0, work0 + } + // clang-format on + + return work2; +} + +inline VEC3* VEC3Lerp(register VEC3* out, register const VEC3* vec1, + register const VEC3* vec2, register f32 t) { + register f32 work0, work1, work2; + + // clang-format off + asm { + // X/Y delta + psq_l work0, VEC3.x(vec1), 0, 0 + psq_l work1, VEC3.x(vec2), 0, 0 + ps_sub work2, work1, work0 + // Scale with time and add to v0 + ps_madds0 work2, work2, t, work0 + psq_st work2, VEC3.x(out), 0, 0 - inline f32 FSqrt(f32 f) - { - return f * FrSqrt(f); - } + // Z delta + psq_l work0, VEC3.z(vec1), 1, 0 + psq_l work1, VEC3.z(vec2), 1, 0 + ps_sub work2, work1, work0 + // Scale with time and add to v0 + ps_madds0 work2, work2, t, work0 + psq_st work2, VEC3.z(out), 1, 0 + } + // clang-format on + + return out; +} + +inline VEC3* VEC3Scale(register VEC3* out, register const VEC3* in, + register f32 scale) { + register f32 work0, work1; + + // clang-format off + asm { + // Scale XY + psq_l work0, VEC3.x(in), 0, 0 + ps_muls0 work1, work0, scale + psq_st work1, VEC3.x(out), 0, 0 + + // Scale Z + psq_l work0, VEC3.z(in), 1, 0 + ps_muls0 work1, work0, scale + psq_st work1, VEC3.z(out), 1, 0 + } + // clang-format on + + return out; +} + +inline VEC3* VEC3Sub(register VEC3* out, register const VEC3* a, + register const VEC3* b) { + register f32 work0, work1, work2; + + // clang-format off + asm { + // Sub XY + psq_l work0, VEC3.x(a), 0, 0 + psq_l work1, VEC3.x(b), 0, 0 + ps_sub work2, work0, work1 + psq_st work2, VEC3.x(out), 0, 0 - inline f32 VEC3Len(const VEC3 * in) - { - return PSVECMag(*in); - } + // Sub Z + psq_l work0, VEC3.z(a), 1, 0 + psq_l work1, VEC3.z(b), 1, 0 + ps_sub work2, work0, work1 + psq_st work2, VEC3.z(out), 1, 0 } + // clang-format on + + return out; +} + +inline VEC3* VEC3Cross(VEC3* out, const VEC3* a, const VEC3* b) { + PSVECCrossProduct(*a, *b, *out); + return out; +} + +inline f32 VEC3DistSq(const VEC3* a, const VEC3* b) { + return PSVECSquareDistance(*a, *b); } + +inline f32 VEC3Len(const VEC3* vec) { return PSVECMag(*vec); } + +inline VEC3* VEC3Normalize(VEC3* out, const VEC3* in) { + PSVECNormalize(*in, *out); + return out; +} + +inline VEC3* VEC3Transform(VEC3* out, const MTX34* mtx, const VEC3* vec) { + PSMTXMultVec(*mtx, *vec, *out); + return out; +} + +inline VEC3* VEC3TransformCoord(VEC3* out, const MTX34* mtx, const VEC3* vec) { + PSMTXMultVec(*mtx, *vec, *out); + return out; +} + +/****************************************************************************** + * + * MTX33 functions + * + ******************************************************************************/ +MTX33* MTX33Identity(MTX33* mtx); + +/****************************************************************************** + * + * MTX34 functions + * + ******************************************************************************/ +MTX33* MTX34ToMTX33(MTX33* out, const MTX34* in); +bool MTX34InvTranspose(MTX33* out, const MTX34* in); +MTX34* MTX34Zero(MTX34* mtx); +MTX34* MTX34Scale(MTX34* out, const MTX34* in, const VEC3* scale); +MTX34* MTX34Trans(MTX34* out, const MTX34* in, const VEC3* trans); +MTX34* MTX34RotAxisFIdx(MTX34* mtx, const VEC3* axis, f32 fidx); +MTX34* MTX34RotXYZFIdx(MTX34* mtx, f32 fx, f32 fy, f32 fz); + +inline MTX34* MTX34Copy(MTX34* out, const MTX34* in) { + PSMTXCopy(*in, *out); + return out; +} + +inline MTX34* MTX34Identity(MTX34* mtx) { + PSMTXIdentity(*mtx); + return mtx; +} + +inline MTX34* MTX34Inv(MTX34* out, const MTX34* in) { + PSMTXInverse(*in, *out); + return out; +} + +inline MTX34* MTX34LookAt(MTX34* mtx, const VEC3* pos, const VEC3* up, + const VEC3* target) { + C_MTXLookAt(*mtx, *pos, *up, *target); + return mtx; +} + +inline MTX34* MTX34Mult(MTX34* out, const MTX34* a, const MTX34* b) { + PSMTXConcat(*a, *b, *out); + return out; +} + +inline MTX34* MTX34MultArray(MTX34* out, const MTX34* p1, const MTX34* src, + u32 len) { + PSMTXConcatArray(*p1, *src, *out, len); + return out; +} + +inline MTX34* MTX34RotAxisRad(MTX34* out, const VEC3* axis, f32 frad) { + return MTX34RotAxisFIdx(out, axis, NW4R_MATH_RAD_TO_FIDX(frad)); +} + +inline MTX34* MTX34RotXYZDeg(MTX34* mtx, f32 dx, f32 dy, f32 dz) { + return MTX34RotXYZFIdx(mtx, NW4R_MATH_DEG_TO_FIDX(dx), + NW4R_MATH_DEG_TO_FIDX(dy), + NW4R_MATH_DEG_TO_FIDX(dz)); +} + +inline MTX34* MTX34RotXYZRad(MTX34* mtx, f32 rx, f32 ry, f32 rz) { + return MTX34RotXYZFIdx(mtx, NW4R_MATH_RAD_TO_FIDX(rx), + NW4R_MATH_RAD_TO_FIDX(ry), + NW4R_MATH_RAD_TO_FIDX(rz)); +} + +inline MTX34* MTX34Scale(MTX34* out, const VEC3* scale, const MTX34* in) { + PSMTXScaleApply(*in, *out, scale->x, scale->y, scale->z); + return out; +} + +inline QUAT* MTX34ToQUAT(QUAT* quat, const MTX34* mtx) { + C_QUATMtx(*quat, *mtx); + return quat; +} + +inline MTX34* MTX34Trans(MTX34* out, const VEC3* trans, const MTX34* in) { + PSMTXTransApply(*in, *out, trans->x, trans->y, trans->z); + return out; +} + +/****************************************************************************** + * + * MTX44 functions + * + ******************************************************************************/ +MTX44* MTX44Identity(MTX44* mtx); +MTX44* MTX44Copy(MTX44* dst, const MTX44* src); + +/****************************************************************************** + * + * QUAT functions + * + ******************************************************************************/ +inline MTX34* QUATToMTX34(MTX34* mtx, const QUAT* quat) { + PSMTXQuat(*mtx, *quat); + return mtx; +} + +inline QUAT* C_QUATSlerp(QUAT* out, const QUAT* q1, const QUAT* q2, f32 t) { + ::C_QUATSlerp(*q1, *q2, *out, t); + return out; +} + +} // namespace math +} // namespace nw4hbm + +#endif diff --git a/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/types_nw4hbm.h b/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/types_nw4hbm.h index 90a7cea1e..2de990ae8 100644 --- a/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/types_nw4hbm.h +++ b/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/types_nw4hbm.h @@ -1,45 +1,100 @@ -#pragma once - +#ifndef NW4HBM_TYPES_H +#define NW4HBM_TYPES_H #include -namespace nw4hbm -{ - namespace ut - { - template struct TextWriterBase; - template struct TagProcessorBase; - } - - namespace math - { - struct VEC2; - struct VEC3; - struct MTX34; - } - - namespace lyt - { - struct Size; - - namespace detail - { - struct PaneBase; - } - - namespace res - { - struct Pane; - struct AnimationBlock; - } - - struct Pane; - struct DrawInfo; - struct AnimResource; - struct AnimTransform; - struct AnimTransformBasic; - struct AnimationLink; - struct ResourceAccessor; - struct ArcResourceAccessor; - struct Material; - } +#define NW4R_BYTEORDER_BIG 0xFEFF +#define NW4R_BYTEORDER_LITTLE 0xFFFE + +#define NW4HBM_VERSION(major, minor) ((major & 0xFF) << 8 | minor & 0xFF) + +namespace nw4hbm { +namespace ut { +namespace detail { + +struct RuntimeTypeInfo; +struct ResFontBase; + +} // namespace detail + +template struct AutoLock; +struct AutoInterruptLock; +struct BinaryBlockHeader; +struct BinaryFileHeader; +struct CharStrmReader; +struct CharWidths; +struct CharWriter; +struct Color; +struct DvdFileStream; +struct DvdLockedFileStream; +struct FileStream; +struct Font; +struct Glyph; +struct IOStream; +template struct LinkList; +struct List; +struct NandFileStream; +template struct PrintContext; +struct Rect; +struct ResFont; +struct RomFont; +template struct TagProcessorBase; +template struct TextWriterBase; + +} // namespace ut + +namespace db { +namespace detail { +struct ConsoleHead; } +} // namespace db + +namespace math { + +struct VEC2; +struct VEC3; +struct MTX33; +struct MTX34; +struct MTX44; +struct QUAT; +struct PLANE; +struct AABB; +struct FRUSTUM; + +} // namespace math + +namespace lyt { +struct Size; + +namespace detail { +struct PaneBase; +struct TexCoordAry; +} // namespace detail + +namespace res { +struct Group; +struct Pane; +struct Bounding; +struct AnimationBlock; +struct BinaryFileHeader; +} // namespace res + +struct Group; +struct GroupContainer; +struct Pane; +struct DrawInfo; +struct AnimResource; +struct AnimTransform; +struct AnimTransformBasic; +struct AnimationLink; +struct ResourceAccessor; +struct ArcResourceAccessor; +struct FontRefLink; +struct Material; +struct Layout; +struct Bounding; +struct ResBlockSet; +struct TexMap; +} // namespace lyt +} // namespace nw4hbm + +#endif diff --git a/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/ut.h b/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/ut.h new file mode 100644 index 000000000..480e749bc --- /dev/null +++ b/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/ut.h @@ -0,0 +1,17 @@ +#ifndef NW4HBM_PUBLIC_UT_H +#define NW4HBM_PUBLIC_UT_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#endif diff --git a/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/ut/ut_CharStrmReader.h b/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/ut/ut_CharStrmReader.h index 2eb3eadfe..0356e97d8 100644 --- a/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/ut/ut_CharStrmReader.h +++ b/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/ut/ut_CharStrmReader.h @@ -1,53 +1,43 @@ -#pragma once - -#include "nw4hbm/types_nw4hbm.h" - -namespace nw4hbm -{ - namespace ut - { - struct CharStrmReader - { - const char * mStrm; - u16 (CharStrmReader::* mFunc)(); - - inline CharStrmReader(u16 (CharStrmReader::* func)()) : mStrm(NULL), mFunc(func) - { - - } - - u16 ReadNextCharUTF8(); - u16 ReadNextCharUTF16(); - u16 ReadNextCharCP1252(); - u16 ReadNextCharSJIS(); - - template - inline T GetChar(int offset) const - { - const T * strm = reinterpret_cast(mStrm); - return strm[offset]; - } - - template - inline void StepStrm(int offset) volatile - { - mStrm += sizeof(T) * offset; - } - - inline u16 Next() - { - return (this->*mFunc)(); - } - - inline void Set(const char * pStrm) - { - mStrm = pStrm; - } - - inline void Set(const wchar_t * pStrm) - { - mStrm = reinterpret_cast(pStrm); - } - }; - } -} +#ifndef NW4HBM_UT_CHAR_STRM_READER_H +#define NW4HBM_UT_CHAR_STRM_READER_H +#include + +namespace nw4hbm { +namespace ut { + +class CharStrmReader { +public: + typedef u16 (CharStrmReader::*ReadFunc)(); + + CharStrmReader(ReadFunc func) : mCharStrm(NULL), mReadFunc(func) {} + ~CharStrmReader() {} + + u16 ReadNextCharUTF8(); + u16 ReadNextCharUTF16(); + u16 ReadNextCharCP1252(); + u16 ReadNextCharSJIS(); + + const void* GetCurrentPos() const { return mCharStrm; } + + template T GetChar(int offset) const { + return static_cast(mCharStrm)[offset]; + } + + template void StepStrm(int offset) { + static_cast(mCharStrm) += offset; + } + + u16 Next() { return (this->*mReadFunc)(); } + + void Set(const char* strm) { mCharStrm = strm; } + void Set(const wchar_t* strm) { mCharStrm = strm; } + +private: + const void* mCharStrm; // at 0x0 + ReadFunc mReadFunc; // at 0x4 +}; + +} // namespace ut +} // namespace nw4hbm + +#endif diff --git a/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/ut/ut_CharWriter.h b/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/ut/ut_CharWriter.h index 85f1aa880..e15ddb41f 100644 --- a/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/ut/ut_CharWriter.h +++ b/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/ut/ut_CharWriter.h @@ -1,166 +1,162 @@ -#pragma once - -#include "nw4hbm/types_nw4hbm.h" -#include "nw4hbm/math/math_types.h" -#include "nw4hbm/ut/ut_Color.h" -#include "nw4hbm/ut/ut_Font.h" +#ifndef NW4HBM_UT_CHAR_WRITER_H +#define NW4HBM_UT_CHAR_WRITER_H +#include +#include +#include #include -namespace nw4hbm -{ - namespace ut - { - // TODO: Implement the object accurately - struct CharWriter - { - struct ColorMapping - { - Color COLOR_0x0; - Color COLOR_0x4; - }; - - struct VertexColor - { - Color mTopLeft; - Color mTopRight; - Color mBottomLeft; - Color mBottomRight; - }; - - struct TextureFilter - { - GXTexFilter WORD_0x0; - GXTexFilter WORD_0x4; - - inline bool operator!=(const TextureFilter & other) const - { - return WORD_0x0 != other.WORD_0x0 || WORD_0x4 != other.WORD_0x4; - } - }; - - //sizeof(LoadingTexture) = 0x10 - struct LoadingTexture - { - s32 s32_0x0; - u8 * PTR_0x4; - TextureFilter mFilter; - - inline bool operator!=(const LoadingTexture & other) const - { - return s32_0x0 != other.s32_0x0 || PTR_0x4 != other.PTR_0x4 || mFilter != other.mFilter; - } - - inline void Reset() - { - s32_0x0 = 0xFF; - PTR_0x4 = 0; - } - }; - - struct TextColor - { - Color mStart; - Color mEnd; - }; - - enum GradationMode - { - GradMode_None, - GradMode_Horizontal, - GradMode_Vertical - }; - - static LoadingTexture mLoadingTexture; - - ColorMapping mColorMapping; // at 0x0 - - VertexColor mVertexColor; // at 0x8 - TextColor mTextColor; // at 0x18 - GradationMode mGradationMode; // at 0x20 - math::VEC2 mScale; // at 0x24 - math::VEC3 mCursor; // at 0x2c - TextureFilter mFilter; // at 0x38 - u8 BYTE_0x40; - u8 BYTE_0x41; - u8 BYTE_0x42; - bool mWidthFixedFlag; - f32 mFixedWidth; - Font * mFont; // at 0x48 - - CharWriter(); - ~CharWriter(); - - void SetColorMapping(Color, Color); - void SetTextColor(Color); - - void UpdateVertexColor(); - - f32 GetFontWidth() const; - f32 GetFontHeight() const; - - f32 GetFontAscent() const; - f32 GetFontDescent() const; - - void EnableLinearFilter(bool, bool); - - f32 Print(u16); - - void LoadTexture(const Glyph &);//inlined - - void PrintGlyph(f32, f32, f32, const Glyph &); - - inline f32 GetFixedWidth() const { return mFixedWidth; } - inline bool IsWidthFixed() const { return mWidthFixedFlag; } - inline void SetCursorX(f32 x) { mCursor.mCoords.x = x; } - inline void SetCursorY(f32 y) { mCursor.mCoords.y = y; } - inline void MoveCursorX(f32 x) { mCursor.mCoords.x += x; } - inline void MoveCursorY(f32 y) { mCursor.mCoords.y += y; } - inline f32 GetCursorX() const { return mCursor.mCoords.x; } - inline f32 GetCursorY() const { return mCursor.mCoords.y; } - - void SetupGX(); - static void SetupGXWithColorMapping(Color, Color); - void SetupGXDefault(); //inlined - - void SetFontSize(f32, f32); - - inline void SetScale(f32 x, f32 y) - { - mScale.mCoords.x = x; - mScale.mCoords.y = y; - } - - inline void SetCursor(f32 x, f32 y) - { - mCursor.mCoords.x = x; - mCursor.mCoords.y = y; - } - inline void SetCursor(f32 x, f32 y, f32 z) - { - mCursor.mCoords.x = x; - mCursor.mCoords.y = y; - mCursor.mCoords.z = z; - } - - inline void ResetColorMapping() - { - SetColorMapping(Color(0), Color()); - } - - inline void SetGradationMode(GradationMode gradationMode) - { - mGradationMode = gradationMode; - - mVertexColor.mTopLeft = mTextColor.mStart; - mVertexColor.mTopRight = (mGradationMode != GradMode_Horizontal) ? mTextColor.mStart : mTextColor.mEnd; - mVertexColor.mBottomLeft = (mGradationMode != GradMode_Vertical) ? mTextColor.mStart : mTextColor.mEnd; - mVertexColor.mBottomRight = (mGradationMode == GradMode_None) ? mTextColor.mStart : mTextColor.mEnd; - - mVertexColor.mTopLeft.mChannels.a = (mVertexColor.mTopLeft.mChannels.a * BYTE_0x42) / 0xFF, - mVertexColor.mTopRight.mChannels.a = (mVertexColor.mTopRight.mChannels.a * BYTE_0x42) / 0xFF; - mVertexColor.mBottomLeft.mChannels.a = (mVertexColor.mBottomLeft.mChannels.a * BYTE_0x42) / 0xFF; - mVertexColor.mBottomRight.mChannels.a = (mVertexColor.mBottomRight.mChannels.a * BYTE_0x42) / 0xFF; - } - }; - } -} +namespace nw4hbm { +namespace ut { + +class CharWriter { +public: + enum GradationMode { GRADMODE_NONE, GRADMODE_H, GRADMODE_V }; + + struct ColorMapping { + Color min; // at 0x0 + Color max; // at 0x4 + }; + + struct VertexColor { + Color tl; // at 0x0 + Color tr; // at 0x4 + Color bl; // at 0x8 + Color br; // at 0xC + }; + + struct TextColor { + Color start; // at 0x0 + Color end; // at 0x4 + GradationMode gradMode; // at 0x8 + }; + + struct TextureFilter { + GXTexFilter atSmall; // at 0x0 + GXTexFilter atLarge; // at 0x4 + + bool operator!=(const TextureFilter& other) const { + return atSmall != other.atSmall || atLarge != other.atLarge; + } + }; + + struct LoadingTexture { + GXTexMapID slot; // at 0x0 + void* texture; // at 0x4 + TextureFilter filter; // at 0x8 + + bool operator!=(const LoadingTexture& other) const { + return slot != other.slot || texture != other.texture || + filter != other.filter; + } + + void Reset() { + slot = GX_TEXMAP_NULL; + texture = NULL; + } + }; + +public: + static void SetupVertexFormat(); + static void SetupGXDefault(); + static void SetupGXWithColorMapping(Color min, Color max); + static void SetupGXForI(); + static void SetupGXForRGBA(); + + CharWriter(); + ~CharWriter(); + + void SetColorMapping(Color min, Color max) { + mColorMapping.min = min; + mColorMapping.max = max; + } + + void ResetColorMapping() { + SetColorMapping(Color(0x00000000), Color(0xFFFFFFFF)); + } + + void SetTextColor(Color start) { + mTextColor.start = start; + UpdateVertexColor(); + } + + void SetTextColor(Color start, Color end) { + mTextColor.start = start; + mTextColor.end = end; + UpdateVertexColor(); + } + + void SetGradationMode(GradationMode mode) { + mTextColor.gradMode = mode; + UpdateVertexColor(); + } + + f32 GetScaleH() const { return mScale.x; } + f32 GetScaleV() const { return mScale.y; } + + void SetScale(f32 x, f32 y) { + mScale.x = x; + mScale.y = y; + } + + f32 GetCursorX() const DECOMP_DONT_INLINE { return mCursorPos.x; } + void SetCursorX(f32 x) DECOMP_DONT_INLINE { mCursorPos.x = x; } + + f32 GetCursorY() const DECOMP_DONT_INLINE { return mCursorPos.y; } + void SetCursorY(f32 y) { mCursorPos.y = y; } + + void SetCursor(f32 x, f32 y) DECOMP_DONT_INLINE { + mCursorPos.x = x; + mCursorPos.y = y; + } + void SetCursor(f32 x, f32 y, f32 z) { + mCursorPos.x = x; + mCursorPos.y = y; + mCursorPos.z = z; + } + + void MoveCursorX(f32 dx) { mCursorPos.x += dx; } + void MoveCursorY(f32 dy) { mCursorPos.y += dy; } + + void EnableFixedWidth(bool enable) { mIsWidthFixed = enable; } + bool IsWidthFixed() const DECOMP_DONT_INLINE { return mIsWidthFixed; } + + void SetFixedWidth(f32 width) { mFixedWidth = width; } + f32 GetFixedWidth() const DECOMP_DONT_INLINE { return mFixedWidth; } + + void SetFont(const Font& font) { mFont = &font; } + const Font* GetFont() const { return mFont; } + + void ResetTextureCache() { mLoadingTexture.Reset(); } + + void SetupGX(); + void SetFontSize(f32 width, f32 height); + f32 GetFontWidth() const; + f32 GetFontHeight() const; + f32 GetFontAscent() const; + f32 GetFontDescent() const; + void EnableLinearFilter(bool atSmall, bool atLarge); + f32 Print(u16 ch); + void PrintGlyph(f32 x, f32 y, f32 z, const Glyph& glyph); + void LoadTexture(const Glyph& glyph, GXTexMapID slot); + void UpdateVertexColor(); + +private: + ColorMapping mColorMapping; // at 0x0 + VertexColor mVertexColor; // at 0x8 + TextColor mTextColor; // at 0x18 + math::VEC2 mScale; // at 0x24 + math::VEC3 mCursorPos; // at 0x2C + TextureFilter mFilter; // at 0x38 + u8 padding[2]; // at 0x40 + u8 mAlpha; // at 0x42 + bool mIsWidthFixed; // at 0x43 + f32 mFixedWidth; // at 0x44 + const Font* mFont; // at 0x48 + + static LoadingTexture mLoadingTexture; +}; + +} // namespace ut +} // namespace nw4hbm + +#endif diff --git a/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/ut/ut_Color.h b/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/ut/ut_Color.h index e668f32d7..ad11fea51 100644 --- a/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/ut/ut_Color.h +++ b/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/ut/ut_Color.h @@ -1,81 +1,44 @@ -#pragma once - -#include "nw4hbm/types_nw4hbm.h" +#ifndef NW4HBM_UT_COLOR_H +#define NW4HBM_UT_COLOR_H +#include #include -/* -#define r channels[0] -#define g channels[1] -#define b channels[2] -#define a channels[3] -/**/ -namespace nw4hbm -{ - namespace ut - { - struct Color - { - GXColor mChannels; - - inline u32 & ToU32ref() - { - return *reinterpret_cast(this); - } - - inline const u32 & ToU32ref() const - { - return *reinterpret_cast(this); - } - - inline Color & operator=(u32 value) - { - ToU32ref() = value; - return *this; - } - - inline Color() - { - *this = 0xFFFFFFFF; - } - - inline Color(const Color & other) - { - mChannels.r = other.mChannels.r; - mChannels.g = other.mChannels.g; - mChannels.b = other.mChannels.b; - mChannels.a = other.mChannels.a; - } - - inline Color & operator=(const Color & other) - { - mChannels = other.mChannels; - - return *this; - } - - inline Color(u32 rgba) - { - *this = rgba; - } - - inline Color(int red, int green, int blue, int alpha) - { - mChannels.r = red; - mChannels.g = green; - mChannels.b = blue; - mChannels.a = alpha; - } - - inline operator u32() const - { - return ToU32ref(); - } - - inline operator GXColor() const - { - return mChannels; - } - - inline ~Color() {} - }; - } -} + +namespace nw4hbm { +namespace ut { + +class Color : public GXColor { +public: + Color() { *this = 0xFFFFFFFF; } + Color(u32 color) { *this = color; } + Color(int red, int green, int blue, int alpha) { + Set(red, green, blue, alpha); + } + ~Color() {} + + void Set(int red, int green, int blue, int alpha) { + r = red; + g = green; + b = blue; + a = alpha; + } + + Color& operator=(u32 color) { + ToU32ref() = color; + return *this; + } + + Color operator|(u32 color) { return Color(ToU32() | color); } + Color operator&(u32 color) { return Color(ToU32() & color); } + + u32& ToU32ref() { return *reinterpret_cast(this); } + const u32& ToU32ref() const { return *reinterpret_cast(this); } + + u32 ToU32() const { return ToU32ref(); } + + operator u32() const { return ToU32ref(); } +}; + +} // namespace ut +} // namespace nw4hbm + +#endif diff --git a/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/ut/ut_Font.h b/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/ut/ut_Font.h index 97edf3a33..c2dab0275 100644 --- a/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/ut/ut_Font.h +++ b/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/ut/ut_Font.h @@ -1,63 +1,75 @@ -#pragma once - -#include "nw4hbm/ut/ut_CharStrmReader.h" -#include "nw4hbm/ut/ut_Glyph.h" - -namespace nw4hbm -{ - namespace ut - { - struct CharWidths - { - char BYTE_0x0; - char BYTE_0x1; - char BYTE_0x2; - }; - - enum FontEncoding - { - FontEnc_UTF8, - FontEnc_UTF16, - FontEnc_SJIS, - FontEnc_CP1252 - }; - - struct Font - { - inline virtual ~Font() {} - - virtual int GetWidth() const = 0; - virtual int GetHeight() const = 0; - virtual int GetAscent() const = 0; - virtual int GetDescent() const = 0; - virtual int GetBaselinePos() const = 0; - virtual int GetCellHeight() const = 0; - virtual int GetCellWidth() const = 0; - virtual int GetMaxCharWidth() const = 0; - virtual int GetType() const = 0; - virtual int GetTextureFormat() const = 0; - virtual int GetLineFeed() const = 0; - virtual CharWidths GetDefaultCharWidths() const = 0; - virtual void SetDefaultCharWidths(const CharWidths &) = 0; - virtual bool SetAlternateChar(u16) = 0; - virtual void SetLineFeed(int) = 0; - virtual int GetCharWidth(u16) const = 0; - virtual CharWidths GetCharWidths(u16) const = 0; - virtual void GetGlyph(Glyph *, u16) const = 0; - virtual FontEncoding GetEncoding() const = 0; - - u16 (CharStrmReader::* mReaderFunc)(); - - void InitReaderFunc(FontEncoding); - - - inline CharStrmReader GetCharStrmReader() const __attribute__((never_inline)) - { - return CharStrmReader(mReaderFunc); - } - - - inline Font() : mReaderFunc(&CharStrmReader::ReadNextCharCP1252) {} - }; - } -} +#ifndef NW4HBM_UT_FONT_H +#define NW4HBM_UT_FONT_H +#include +#include +#include + +namespace nw4hbm { +namespace ut { + +struct CharWidths { + s8 leftSpacing; // at 0x0 + u8 glyphWidth; // at 0x1 + s8 charWidth; // at 0x2 +}; + +struct Glyph { + void* texture; // at 0x0 + CharWidths widths; // at 0x4 + u8 height; // at 0x7 + GXTexFmt format; // at 0x8 + u16 texWidth; // at 0xC + u16 texHeight; // at 0xE + u16 cellX; // at 0x10 + u16 cellY; // at 0x12 +}; + +enum FontEncoding { + FONT_ENCODE_UTF8, + FONT_ENCODE_UTF16, + FONT_ENCODE_SJIS, + FONT_ENCODE_CP1252 +}; + +class Font { +public: + enum Type { TYPE_NULL, TYPE_ROM, TYPE_RESOURCE, TYPE_PAIR }; + +public: + Font() : mReadFunc(&CharStrmReader::ReadNextCharCP1252) {} + virtual ~Font() {} // at 0x8 + + virtual int GetWidth() const = 0; // at 0xC + virtual int GetHeight() const = 0; // at 0x10 + virtual int GetAscent() const = 0; // at 0x14 + virtual int GetDescent() const = 0; // at 0x18 + virtual int GetBaselinePos() const = 0; // at 0x1C + virtual int GetCellHeight() const = 0; // at 0x20 + virtual int GetCellWidth() const = 0; // at 0x24 + virtual int GetMaxCharWidth() const = 0; // at 0x28 + virtual Type GetType() const = 0; // at 0x2C + virtual GXTexFmt GetTextureFormat() const = 0; // at 0x30 + virtual int GetLineFeed() const = 0; // at 0x34 + virtual CharWidths GetDefaultCharWidths() const = 0; // at 0x38 + virtual void SetDefaultCharWidths(const CharWidths& widths) = 0; // at 0x3C + virtual bool SetAlternateChar(u16 c) = 0; // at 0x40 + virtual void SetLineFeed(int lf) = 0; // at 0x44 + virtual int GetCharWidth(u16 c) const = 0; // at 0x48 + virtual CharWidths GetCharWidths(u16 c) const = 0; // at 0x4C + virtual void GetGlyph(Glyph* out, u16 c) const = 0; // at 0x50 + virtual FontEncoding GetEncoding() const = 0; // at 0x54 + + void InitReaderFunc(FontEncoding encode); + + CharStrmReader GetCharStrmReader() const { + return CharStrmReader(mReadFunc); + } + +private: + CharStrmReader::ReadFunc mReadFunc; // at 0x4 +}; + +} // namespace ut +} // namespace nw4hbm + +#endif diff --git a/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/ut/ut_Glyph.h b/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/ut/ut_Glyph.h deleted file mode 100644 index 1c3c38da9..000000000 --- a/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/ut/ut_Glyph.h +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - -#include -#include - -namespace nw4hbm -{ - namespace ut - { - struct Glyph - { - u8 * PTR_0x0; - - s8 BYTE_0x4; - u8 cellWidth; // at 0x5 - s8 BYTE_0x6; - u8 cellHeight; // at 0x7 - - //char BYTES_0x4[4]; - - GXTexFmt WORD_0x8; - - unsigned short SHORT_0xC; - unsigned short SHORT_0xE; - unsigned short SHORT_0x10; - unsigned short SHORT_0x12; - }; - } -} diff --git a/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/ut/ut_LinkList.h b/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/ut/ut_LinkList.h index b86cb1a59..80ad65bf7 100644 --- a/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/ut/ut_LinkList.h +++ b/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/ut/ut_LinkList.h @@ -1,214 +1,412 @@ -#pragma once - -#include "nw4hbm/types_nw4hbm.h" - -namespace nw4hbm -{ - namespace ut - { - struct LinkListNode - { - LinkListNode * mNext; - LinkListNode * mPrev; - - inline LinkListNode() : mNext(NULL), mPrev(NULL) {} - }; - - namespace detail - { - struct LinkListImpl - { - int mCount; - - LinkListNode mEndNode; - - struct Iterator - { - LinkListNode * mNode; - inline Iterator(LinkListNode * pNode) : mNode(pNode) {} - - inline Iterator & operator++() - { - mNode = mNode->mNext; - return *this; - } - - inline LinkListNode * operator->() const - { - return mNode; - } - }; - - inline Iterator GetEndIter() - { - return Iterator(&mEndNode); - } - - inline Iterator GetBeginIter() - { - return Iterator(mEndNode.mNext); - } - - LinkListNode * Erase(Iterator); - LinkListNode * Erase(LinkListNode *); - inline LinkListNode * Erase(Iterator iBegin, Iterator iEnd) - { - LinkListNode * pPrev; - LinkListNode * pNext; - - LinkListNode * pCurNode; - - LinkListNode * pEndNode; - LinkListNode * pBeginNode; - - pBeginNode = iBegin.mNode; - pEndNode = iEnd.mNode; - - pCurNode = pBeginNode; - - while (pCurNode != pEndNode) - { - pNext = pCurNode->mNext; - pPrev = pCurNode->mPrev; - - pNext->mPrev = pPrev; - pPrev->mNext = pNext; - - this->mCount--; - - pCurNode->mNext = NULL; - pCurNode->mPrev = NULL; - - pCurNode = pNext; - } - - return pEndNode; - } - - void Clear(); - - LinkListNode * Insert(Iterator, LinkListNode *); - - inline void Initialize_() volatile - { - mEndNode.mNext = NULL; - mEndNode.mPrev = NULL; - mCount = 0; - } - - LinkListImpl() : mCount(0), mEndNode() - { - LinkListNode *lp = &mEndNode; - Initialize_(); - mEndNode.mNext = lp; - mEndNode.mPrev = lp; - } - - ~LinkListImpl(); - }; - - inline bool operator ==(LinkListImpl::Iterator iter1, LinkListImpl::Iterator iter2) - { - return iter1.mNode == iter2.mNode; - } - } - - template - struct LinkList : detail::LinkListImpl - { - static inline LinkListNode * GetNodeFromPointer(T * ptr) - { - return (LinkListNode *)((char *)ptr + I); - } - - static inline T * GetPointerFromNode(LinkListNode * node) - { - return (T *)((char *)node - I); - } - - struct Iterator - { - detail::LinkListImpl::Iterator mIterator; // at 0x0 - - inline Iterator(detail::LinkListImpl::Iterator iter) : mIterator(iter) {} - - inline bool operator ==(Iterator other) - { - return detail::operator==(mIterator, other.mIterator); - } - - inline bool operator !=(Iterator other) - { - return !(*this == other); - } - - inline Iterator & operator ++() - { - mIterator.operator++(); - return *this; - } - - inline Iterator & operator --() - { - mIterator.mNode = mIterator.mNode->mPrev; - return *this; - } - - inline Iterator operator ++(int) - { - Iterator ret = *this; - ++*this; - return ret; - } - - inline T * operator->() const - { - return GetPointerFromNode(mIterator.mNode); - } - - inline T & operator*() const - { - return *GetPointerFromNode(mIterator.mNode); - } - }; - - inline Iterator GetEndIter() - { - return Iterator(detail::LinkListImpl::GetEndIter()); - } - - inline Iterator GetBeginIter() - { - return Iterator(detail::LinkListImpl::GetBeginIter()); - } - - //TODO: determine function type for Insert/PushBack/Erase - - inline void Insert(Iterator iter, T * ptr) - { - detail::LinkListImpl::Insert(iter.mIterator, GetNodeFromPointer(ptr)); - } - - inline void PushBack(T * ptr) - { - Insert(GetEndIter(), ptr); - } - - inline void Erase(T * ptr) - { - detail::LinkListImpl::Erase(GetNodeFromPointer(ptr)); - } - - inline T * GetBack() - { - return &*--GetEndIter(); - } - - ~LinkList(); - inline LinkList() {} - }; - - template LinkList::~LinkList() {} - //template inline LinkList::LinkList() {} - } +#ifndef NW4HBM_UT_LINK_LIST_H +#define NW4HBM_UT_LINK_LIST_H +#include +#include + +/** + * Declare typedef for linked-list specialization. + */ +#define NW4R_UT_LIST_TYPEDEF_DECL(T) \ + typedef nw4hbm::ut::LinkList T##List; + +/** + * Declare typedef for linked-list specialization. + * + * Use the specified link node (name suffix) for classes with multiple nodes. + */ +#define NW4R_UT_LIST_TYPEDEF_DECL_EX(T, SUFFIX) \ + typedef nw4hbm::ut::LinkList T##SUFFIX##List; + +/** + * Declare a member LinkListNode for use with the typedef. + */ +#define NW4R_UT_LIST_NODE_DECL() nw4hbm::ut::LinkListNode node + +/** + * Declare a member LinkListNode for use with the typedef. + * + * Use the specified link node (name suffix) for classes with multiple nodes. + */ +#define NW4R_UT_LIST_NODE_DECL_EX(SUFFIX) nw4hbm::ut::LinkListNode node##SUFFIX + +/** + * Explicitly instantiate a linked list specialization. + * (RESERVED FOR MATCHING DECOMP HACKS) + */ +#ifndef __DECOMP_NON_MATCHING +#define NW4R_UT_LIST_TYPEDEF_FORCE(T) \ + template struct nw4hbm::ut::LinkList +#else +#define NW4R_UT_LIST_TYPEDEF_FORCE(T) +#endif + +namespace nw4hbm { +namespace ut { + +// Forward declarations +namespace detail { +class LinkListImpl; } + +class LinkListNode : private NonCopyable { + friend class detail::LinkListImpl; + +public: + LinkListNode() : mNext(NULL), mPrev(NULL) {} + + LinkListNode* GetNext() const { + return mNext; + } + LinkListNode* GetPrev() const { + return mPrev; + } + +private: + LinkListNode* mNext; // at 0x0 + LinkListNode* mPrev; // at 0x4 +}; + +namespace detail { + +class LinkListImpl : private NonCopyable { +public: + // Forward declarations + class ConstIterator; + + class Iterator { + friend class LinkListImpl; + friend class ConstIterator; + + public: + Iterator() : mNode(NULL) {} + Iterator(LinkListNode* node) : mNode(node) {} + + Iterator& operator++() { + mNode = mNode->GetNext(); + return *this; + } + + Iterator& operator--() { + mNode = mNode->GetPrev(); + return *this; + } + + LinkListNode* operator->() const { + return mNode; + } + + friend bool operator==(LinkListImpl::Iterator lhs, + LinkListImpl::Iterator rhs) { + return lhs.mNode == rhs.mNode; + } + + private: + LinkListNode* mNode; // at 0x0 + }; + + class ConstIterator { + friend class LinkListImpl; + + public: + ConstIterator(Iterator it) : mNode(it.mNode) {} + + ConstIterator& operator++() { + mNode = mNode->GetNext(); + return *this; + } + + ConstIterator& operator--() { + mNode = mNode->GetPrev(); + return *this; + } + + const LinkListNode* operator->() const { + return mNode; + } + + friend bool operator==(LinkListImpl::ConstIterator lhs, + LinkListImpl::ConstIterator rhs) { + return lhs.mNode == rhs.mNode; + } + + private: + LinkListNode* mNode; // at 0x0 + }; + +protected: + static Iterator GetIteratorFromPointer(LinkListNode* node) { + return Iterator(node); + } + + LinkListImpl() { + Initialize_(); + } + ~LinkListImpl(); + + Iterator GetBeginIter() { + return Iterator(mNode.GetNext()); + } + Iterator GetEndIter() { + return Iterator(&mNode); + } + + Iterator Insert(Iterator it, LinkListNode* node); + + Iterator Erase(Iterator it); + Iterator Erase(LinkListNode* node); + Iterator Erase(Iterator begin, Iterator end); + +public: + u32 GetSize() const { + return mSize; + } + bool IsEmpty() const { + return mSize == 0; + } + + void PopFront() { + Erase(GetBeginIter()); + } + void PopBack() { + Erase(GetEndIter()); + } + + void Clear(); + +private: + void Initialize_() { + mSize = 0; + mNode.mNext = &mNode; + mNode.mPrev = &mNode; + } + +private: + u32 mSize; // at 0x0 + LinkListNode mNode; // at 0x4 +}; + +template class ReverseIterator { +public: + ReverseIterator(TIter it) : mCurrent(it) {} + + TIter GetBase() const { + return mCurrent; + } + + ReverseIterator& operator++() { + --mCurrent; + return *this; + } + + const TIter::TElem* operator->() const { + return &this->operator*(); + } + + TIter::TElem& operator*() const { + TIter it = mCurrent; + --it; + return *it; + } + + friend bool operator==(const ReverseIterator& lhs, + const ReverseIterator& rhs) { + return lhs.mCurrent == rhs.mCurrent; + } + + friend bool operator!=(const ReverseIterator& lhs, + const ReverseIterator& rhs) { + return !(lhs.mCurrent == rhs.mCurrent); + } + +private: + TIter mCurrent; // at 0x0 +}; + +} // namespace detail + +template class LinkList : public detail::LinkListImpl { +public: + // Forward declarations + class ConstIterator; + + class Iterator { + friend class LinkList; + friend class ConstIterator; + + public: + // Element type must be visible to ReverseIterator + typedef T TElem; + + public: + Iterator() : mIterator(NULL) {} + Iterator(LinkListImpl::Iterator it) : mIterator(it) {} + + Iterator& operator++() { + ++mIterator; + return *this; + } + + Iterator& operator--() { + --mIterator; + return *this; + } + + Iterator operator++(int) { + Iterator ret = *this; + ++*this; + return ret; + } + + T* operator->() const { + return GetPointerFromNode(mIterator.operator->()); + } + + T& operator*() const { + return *this->operator->(); + } + + friend bool operator==(Iterator lhs, Iterator rhs) { + return lhs.mIterator == rhs.mIterator; + } + + friend bool operator!=(Iterator lhs, Iterator rhs) { + return !(lhs == rhs); + } + + private: + LinkListImpl::Iterator mIterator; // at 0x0 + }; + + class ConstIterator { + friend class LinkList; + + public: + // Element type must be visible to ReverseIterator + typedef T TElem; + + public: + ConstIterator(LinkListImpl::Iterator it) : mIterator(it) {} + ConstIterator(Iterator it) : mIterator(it.mIterator) {} + + ConstIterator& operator++() { + ++mIterator; + return *this; + } + + ConstIterator& operator--() { + --mIterator; + return *this; + } + + ConstIterator operator++(int) { + ConstIterator ret = *this; + ++*this; + return ret; + } + + const T* operator->() const { + return GetPointerFromNode(mIterator.operator->()); + } + + const T& operator*() const { + return *this->operator->(); + } + + friend bool operator==(ConstIterator lhs, ConstIterator rhs) { + return lhs.mIterator == rhs.mIterator; + } + + friend bool operator!=(ConstIterator lhs, ConstIterator rhs) { + return !(lhs == rhs); + } + + private: + LinkListImpl::ConstIterator mIterator; // at 0x0 + }; + +public: + // Shorthand names for reverse iterator types + typedef detail::ReverseIterator RevIterator; + typedef detail::ReverseIterator RevConstIterator; + +public: + LinkList() {} + ~LinkList() {} + + Iterator GetBeginIter() { + return Iterator(LinkListImpl::GetBeginIter()); + } + ConstIterator GetBeginIter() const { + return ConstIterator(const_cast(this)->GetBeginIter()); + } + detail::ReverseIterator GetBeginReverseIter() { + return detail::ReverseIterator(GetBeginIter()); + } + + Iterator GetEndIter() { + return Iterator(LinkListImpl::GetEndIter()); + } + ConstIterator GetEndIter() const { + return ConstIterator(const_cast(this)->GetEndIter()); + } + detail::ReverseIterator GetEndReverseIter() { + return detail::ReverseIterator(GetEndIter()); + } + + Iterator Insert(Iterator it, T* p) { + return Iterator( + LinkListImpl::Insert(it.mIterator, GetNodeFromPointer(p))); + } + + Iterator Erase(T* p) { + return Iterator(LinkListImpl::Erase(GetNodeFromPointer(p))); + } + Iterator Erase(Iterator it) { + return Iterator(LinkListImpl::Erase(it.mIterator)); + } + + void PushBack(T* p) { + Insert(GetEndIter(), p); + } + + T& GetFront() { + return *GetBeginIter(); + } + const T& GetFront() const { + return *GetBeginIter(); + } + + T& GetBack() { + return *--GetEndIter(); + } + const T& GetBack() const { + return *--GetEndIter(); + } + + static Iterator GetIteratorFromPointer(T* p) { + return GetIteratorFromPointer(GetNodeFromPointer(p)); + } + + static Iterator GetIteratorFromPointer(LinkListNode* node) { + return Iterator(LinkListImpl::GetIteratorFromPointer(node)); + } + + static LinkListNode* GetNodeFromPointer(T* p) { + return reinterpret_cast(reinterpret_cast(p) + + Ofs); + } + + static T* GetPointerFromNode(LinkListNode* node) { + return reinterpret_cast(reinterpret_cast(node) - Ofs); + } + + static const T* GetPointerFromNode(const LinkListNode* node) { + return reinterpret_cast(reinterpret_cast(node) - + Ofs); + } +}; + +} // namespace ut +} // namespace nw4hbm + +#endif diff --git a/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/ut/ut_NonCopyable.h b/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/ut/ut_NonCopyable.h new file mode 100644 index 000000000..5b9b71d07 --- /dev/null +++ b/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/ut/ut_NonCopyable.h @@ -0,0 +1,20 @@ +#ifndef NW4HBM_UT_NON_COPYABLE_H +#define NW4HBM_UT_NON_COPYABLE_H +#include + +namespace nw4hbm { +namespace ut { +namespace { + +class NonCopyable { +protected: + NonCopyable() {} + NonCopyable(const NonCopyable&) {} + ~NonCopyable() {} +}; + +} // namespace +} // namespace ut +} // namespace nw4hbm + +#endif diff --git a/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/ut/ut_Rect.h b/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/ut/ut_Rect.h index b7775950c..68393d66c 100644 --- a/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/ut/ut_Rect.h +++ b/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/ut/ut_Rect.h @@ -1,38 +1,48 @@ -#pragma once - -namespace nw4hbm -{ - namespace ut - { - // TODO: Implement the object properly - struct Rect - { - f32 FLOAT_0x0; - f32 FLOAT_0x4; - f32 FLOAT_0x8; - f32 FLOAT_0xC; - - inline Rect(f32 F_0x0, f32 F_0x4, f32 F_0x8, f32 F_0xC) - : FLOAT_0x0(F_0x0), FLOAT_0x4(F_0x4), - FLOAT_0x8(F_0x8), FLOAT_0xC(F_0xC) - {} - - inline Rect() : FLOAT_0x0(), FLOAT_0x4(), FLOAT_0x8(), FLOAT_0xC() {} - - inline Rect & operator=(const Rect & other) - { - FLOAT_0x0 = other.FLOAT_0x0; - FLOAT_0x4 = other.FLOAT_0x4; - FLOAT_0x8 = other.FLOAT_0x8; - FLOAT_0xC = other.FLOAT_0xC; - - return *this; - } - - inline f32 GetWidth() const - { - return FLOAT_0x8 - FLOAT_0x0; - } - }; - } -} +#ifndef NW4HBM_UT_RECT_H +#define NW4HBM_UT_RECT_H +#include +#include + +namespace nw4hbm { +namespace ut { + +struct Rect { + f32 left; // at 0x0 + f32 top; // at 0x4 + f32 right; // at 0x8 + f32 bottom; // at 0xC + + Rect() : left(0.0f), top(0.0f), right(0.0f), bottom(0.0f) {} + Rect(f32 l, f32 t, f32 r, f32 b) : left(l), top(t), right(r), bottom(b) {} + ~Rect() {} + + void SetWidth(f32 width) { right = left + width; } + f32 GetWidth() const { return right - left; } + + void SetHeight(f32 height) { bottom = top + height; } + f32 GetHeight() const { return bottom - top; } + + void Normalize() { + f32 l = left; + f32 t = top; + f32 r = right; + f32 b = bottom; + + left = math::FSelect(r - l, l, r); // min(r, l) + right = math::FSelect(r - l, r, l); // max(r, l) + top = math::FSelect(b - t, t, b); // min(b, t) + bottom = math::FSelect(b - t, b, t); // max(b, t) + } + + void MoveTo(f32 x, f32 y) { + right = GetWidth() + x; + left = x; + bottom = GetHeight() + y; + top = y; + } +}; + +} // namespace ut +} // namespace nw4hbm + +#endif diff --git a/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/ut/ut_ResFont.h b/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/ut/ut_ResFont.h index 8d64f043a..e06c15e2b 100644 --- a/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/ut/ut_ResFont.h +++ b/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/ut/ut_ResFont.h @@ -1,19 +1,22 @@ -#pragma once +#ifndef NW4HBM_UT_RES_FONT_H +#define NW4HBM_UT_RES_FONT_H +#include +#include -#include "nw4hbm/ut/ut_ResFontBase.h" -#include "nw4hbm/ut/ut_binaryFileFormat.h" +namespace nw4hbm { +namespace ut { -namespace nw4hbm -{ - namespace ut - { - struct ResFont : detail::ResFontBase - { - ResFont(); - ~ResFont(); - - bool SetResource(void *); - static FontInformation * Rebuild(BinaryFileHeader *); - }; - } -} +class ResFont : public detail::ResFontBase { +public: + static FontInformation* Rebuild(BinaryFileHeader* header); + + ResFont(); + ~ResFont(); + + bool SetResource(void* buffer); +}; + +} // namespace ut +} // namespace nw4hbm + +#endif diff --git a/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/ut/ut_ResFontBase.h b/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/ut/ut_ResFontBase.h index 2f739ae59..ac122ee82 100644 --- a/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/ut/ut_ResFontBase.h +++ b/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/ut/ut_ResFontBase.h @@ -1,115 +1,113 @@ -#pragma once - -#include "nw4hbm/ut/ut_Font.h" - -namespace nw4hbm -{ - namespace ut - { - struct FontWidth - { - u16 mFirstChar; - u16 mLastChar; - FontWidth * mNext; // at 0x4 - CharWidths mWidthTable[]; // at 0x8 (flexible array member) - }; - - enum FontMapping - { - FontMap_Linear, - FontMap_Array, - FontMap_Morphism - }; - - struct FontCodeMap - { - u16 mFirstChar; - u16 mLastChar; - u16 mType; - FontCodeMap * mNext; // at 0x8 - u16 mGlyphTable[]; // at 0xc (flexible array member) - }; - - struct FontTextureGlyph - { - u8 mCellWidth; // at 0x0 - u8 mCellHeight; // at 0x1 - - s8 mBaselinePos; // at 0x2 - - u8 mMaxCharWidth; // at 0x3 - - u32 WORD_0x4; // at 0x4 - - short UNK_0x8; - u16 mFormat; // at 0xa - - u16 SHORT_0xC; - u16 SHORT_0xE; - u16 SHORT_0x10; - u16 SHORT_0x12; - u8 * PTR_0x14; - }; - - struct FontInformation - { - char UNK_0x0; - s8 mLineFeed; // at 0x1 - - u16 mAlternateChar; - - CharWidths mDefaultCharWidths; // at 0x4 - u8 mEncoding; // at 0x7 - FontTextureGlyph * mTextureGlyph; - FontWidth * mWidthList; - FontCodeMap * mCodeMapList; - u8 mHeight; // at 0x14 - u8 mWidth; // at 0x15 - - u8 mAscent; // at 0x16 - }; - - namespace detail - { - struct ResFontBase : Font - { - void * mBuffer; - FontInformation * mFontInfo; - - ResFontBase(); - ~ResFontBase(); - - void SetResourceBuffer(void *, FontInformation *); - int GetWidth() const; - int GetHeight() const; - int GetAscent() const; - int GetDescent() const; - int GetBaselinePos() const; - int GetCellHeight() const; - int GetCellWidth() const; - int GetMaxCharWidth() const; - int GetType() const; - int GetTextureFormat() const; - int GetLineFeed() const; - CharWidths GetDefaultCharWidths() const; - void SetDefaultCharWidths(const CharWidths &); - bool SetAlternateChar(u16); - void SetLineFeed(int); - int GetCharWidth(u16) const; - CharWidths GetCharWidths(u16) const; - void GetGlyph(Glyph *, u16) const; - FontEncoding GetEncoding() const; - - u16 FindGlyphIndex(const FontCodeMap *, u16) const; - void GetGlyphFromIndex(Glyph *, u16) const; - - // Inlined functions - u16 FindGlyphIndex(u16) const; - u16 GetGlyphIndex(u16) const; - - const CharWidths & GetCharWidthsFromIndex(u16) const; - const CharWidths & GetCharWidthsFromIndex(const FontWidth *, u16) const; - }; - } - } -} +#ifndef NW4HBM_UT_RES_FONT_BASE_H +#define NW4HBM_UT_RES_FONT_BASE_H +#include +#include + +namespace nw4hbm { +namespace ut { + +enum FontMapMethod { + FONT_MAPMETHOD_LINEAR, + FONT_MAPMETHOD_ARRAY, + FONT_MAPMETHOD_SCAN +}; + +struct FontTextureGlyph { + u8 cellWidth; // at 0x0 + u8 cellHeight; // at 0x1 + s8 baselinePos; // at 0x2 + u8 maxCharWidth; // at 0x3 + u32 sheetSize; // at 0x4 + u16 sheetNum; // at 0x8 + u16 sheetFormat; // at 0xA + u16 sheetRow; // at 0xC + u16 sheetLine; // at 0xE + u16 sheetWidth; // at 0x10 + u16 sheetHeight; // at 0x12 + u8* sheetImage; // at 0x14 +}; + +struct FontWidth { + u16 firstChar; // at 0x0 + u16 lastChar; // at 0x2 + FontWidth* next; // at 0x4 + CharWidths widthTable[]; // at 0x8 +}; + +struct FontCodeMap { + u16 firstChar; // at 0x0 + u16 lastChar; // at 0x2 + u16 mappingMethod; // at 0x4 + u16 reserved; // at 0x6 + FontCodeMap* next; // at 0x8 + u16 mapInfo[]; // at 0xc +}; + +struct FontInformation { + u8 type; // at 0x0 + s8 lineFeed; // at 0x1 + u16 alterCharIndex; // at 0x2 + CharWidths defaultWidth; // at 0x4 + u8 encoding; // at 0x7 + FontTextureGlyph* fontGlyph; // at 0x8 + FontWidth* fontWidth; // at 0xC + FontCodeMap* fontMap; // at 0x10 + u8 height; // at 0x14 + u8 width; // at 0x15 + u8 ascent; // at 0x16 +}; + +namespace detail { + +class ResFontBase : public Font { +public: + ResFontBase(); + virtual ~ResFontBase(); // at 0x8 + + virtual int GetWidth() const; // at 0xC + virtual int GetHeight() const; // at 0x10 + virtual int GetAscent() const; // at 0x14 + virtual int GetDescent() const; // at 0x18 + virtual int GetBaselinePos() const; // at 0x1C + virtual int GetCellHeight() const; // at 0x20 + virtual int GetCellWidth() const; // at 0x24 + virtual int GetMaxCharWidth() const; // at 0x28 + virtual Type GetType() const; // at 0x2C + virtual GXTexFmt GetTextureFormat() const; // at 0x30 + virtual int GetLineFeed() const; // at 0x34 + virtual CharWidths GetDefaultCharWidths() const; // at 0x38 + virtual void SetDefaultCharWidths(const CharWidths& widths); // at 0x3C + virtual bool SetAlternateChar(u16 c); // at 0x40 + virtual void SetLineFeed(int lf); // at 0x44 + virtual int GetCharWidth(u16 c) const; // at 0x48 + virtual CharWidths GetCharWidths(u16 c) const; // at 0x4C + virtual void GetGlyph(Glyph* out, u16 c) const; // at 0x50 + virtual FontEncoding GetEncoding() const; // at 0x54 + + bool IsManaging(const void* buffer) const { return mResource == buffer; } + + void SetResourceBuffer(void* buffer, FontInformation* info); + + u16 GetGlyphIndex(u16 c) const; + + u16 FindGlyphIndex(u16 c) const; + u16 FindGlyphIndex(const FontCodeMap* map, u16 c) const; + + const CharWidths& GetCharWidthsFromIndex(u16 index) const; + const CharWidths& GetCharWidthsFromIndex(const FontWidth* width, + u16 index) const; + + void GetGlyphFromIndex(Glyph* out, u16 index) const; + +private: + void* mResource; // at 0x10 + FontInformation* mFontInfo; // at 0x14 + u16 mLastCharCode; // at 0x18 + u16 mLastGlyphIndex; // at 0x18 +}; + +} // namespace detail +} // namespace ut +} // namespace nw4hbm + +#endif diff --git a/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/ut/ut_TagProcessorBase.h b/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/ut/ut_TagProcessorBase.h index 379eaa828..de8e21b1d 100644 --- a/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/ut/ut_TagProcessorBase.h +++ b/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/ut/ut_TagProcessorBase.h @@ -1,35 +1,45 @@ -#pragma once - -#include "nw4hbm/types_nw4hbm.h" -#include "nw4hbm/ut/ut_Rect.h" - -namespace nw4hbm -{ - namespace ut - { - template - struct PrintContext - { - TextWriterBase * mTextWriter; - - const T * PTR_0x4; - - f32 FLOAT_0x8; - f32 FLOAT_0xC; - int WORD_0x10; - }; - - template - struct TagProcessorBase - { - TagProcessorBase(); - virtual ~TagProcessorBase(); - - virtual int Process(u16, PrintContext *); - virtual int CalcRect(register Rect *, u16, PrintContext *); - - void ProcessTab(PrintContext *); //inlined - void ProcessLinefeed(PrintContext *); //inlined - }; - } -} +#ifndef NW4HBM_UT_TAG_PROCESSOR_BASE_H +#define NW4HBM_UT_TAG_PROCESSOR_BASE_H +#include +#include + +namespace nw4hbm { +namespace ut { + +enum PrintFlags { + PRINTFLAGS_CHARSPACE = (1 << 0), +}; + +template struct PrintContext { + TextWriterBase* writer; // at 0x0 + const T* str; // at 0x4 + f32 x; // at 0x8 + f32 y; // at 0xC + u32 flags; // at 0x10 +}; + +enum Operation { + OPERATION_DEFAULT, + OPERATION_NO_CHAR_SPACE, + OPERATION_CHAR_SPACE, + OPERATION_NEXT_LINE, + OPERATION_END_DRAW +}; + +template class TagProcessorBase { +public: + TagProcessorBase(); + virtual ~TagProcessorBase(); // at 0x8 + + virtual Operation Process(u16 ch, PrintContext* ctx); // at 0xC + virtual Operation CalcRect(Rect* rect, u16 ch, + PrintContext* ctx); // at 0x10 + + void ProcessLinefeed(PrintContext* ctx); + void ProcessTab(PrintContext* ctx); +}; + +} // namespace ut +} // namespace nw4hbm + +#endif diff --git a/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/ut/ut_TextWriterBase.h b/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/ut/ut_TextWriterBase.h index 85bd3ec36..bbd332feb 100644 --- a/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/ut/ut_TextWriterBase.h +++ b/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/ut/ut_TextWriterBase.h @@ -1,53 +1,97 @@ -#pragma once - -#include -#include "nw4hbm/ut/ut_TagProcessorBase.h" -#include "nw4hbm/ut/ut_CharWriter.h" -#include "nw4hbm/ut/ut_Rect.h" - -namespace nw4hbm -{ - namespace ut - { - template - struct TextWriterBase : CharWriter - { - static TagProcessorBase mDefaultTagProcessor; - static T * mFormatBuffer; - static u32 mFormatBufferSize; - f32 FLOAT_0x4C; - f32 FLOAT_0x50; - f32 FLOAT_0x54; - u32 mTabWidth; // at 0x58 - u32 WORD_0x5C; - TagProcessorBase * mTagProcessor; // at 0x60 - - TextWriterBase(); - ~TextWriterBase(); - - inline u32 GetTabWidth() const - { - return mTabWidth; - } - - f32 GetLineHeight() const; - int VSNPrintf(T *, u32, const T *, va_list); - - f32 AdjustCursor(f32 *, f32 *, const T *, int); - f32 PrintImpl(const T *, int); - bool CalcStringRectImpl(Rect *, const T *, int) __attribute__((never_inline)); - bool CalcLineRectImpl(Rect *, const T **, int); - f32 Print(const T *, int); - f32 VPrintf(const T *, va_list); - - void CalcStringRect(Rect *, const T *, int) const; - f32 CalcStringWidth(const T *, int) const; - f32 CalcLineWidth(const T *, int); - - inline bool IsDrawFlagSet(u32 mask, u32 flags) const - { - return (WORD_0x5C & mask) == flags; - } - }; - } +#ifndef NW4HBM_UT_TEXT_WRITER_BASE_H +#define NW4HBM_UT_TEXT_WRITER_BASE_H +#include +#include +#include +#include +#include +#include + +namespace nw4hbm { +namespace ut { + +template class TextWriterBase : public CharWriter { +public: + static T* GetBuffer() { return mFormatBuffer; } + static T* SetBuffer(T* buffer, u32 size) { + T* old = mFormatBuffer; + mFormatBuffer = buffer; + mFormatBufferSize = size; + return old; + } + + static u32 GetBufferSize() { return mFormatBufferSize; } + + TextWriterBase(); + ~TextWriterBase(); + + f32 GetWidthLimit() const { return mWidthLimit; } + void SetWidthLimit(f32 limit) { mWidthLimit = limit; } + void ResetWidthLimit() { mWidthLimit = NW4R_MATH_FLT_MAX; } + + f32 GetCharSpace() const { return mCharSpace; } + void SetCharSpace(f32 space) { mCharSpace = space; } + + f32 GetLineSpace() const { return mLineSpace; } + void SetLineSpace(f32 space) { mLineSpace = space; } + + int GetTabWidth() const DECOMP_DONT_INLINE { return mTabWidth; } + void SetTabWidth(int width) { mTabWidth = width; } + + void SetDrawFlag(u32 flag) { mDrawFlag = flag; } + bool IsDrawFlagSet(u32 mask, u32 flag) const { + return (mDrawFlag & mask) == flag; + } + + TagProcessorBase* GetTagProcessor() const { return mTagProcessor; } + void SetTagProcessor(TagProcessorBase* processor) { + mTagProcessor = processor; + } + void ResetTagProcessor() { mTagProcessor = &mDefaultTagProcessor; } + + f32 GetLineHeight() const; + + f32 CalcLineWidth(const T* str, int len); + f32 CalcStringWidth(const T* str, int len) const; + void CalcStringRect(Rect* rect, const T* str, int len) const; + + int VSNPrintf(T* buffer, u32 count, const T* fmt, std::va_list args); + f32 VPrintf(const T* str, std::va_list args); + f32 Print(const T* str, int len); + + bool CalcLineRectImpl(Rect* rect, const T** str, int len); + void CalcStringRectImpl(Rect* rect, const T* str, int len); + + f32 PrintImpl(const T* str, int len); + f32 AdjustCursor(f32* x1, f32* y1, const T* str, int len); + +private: + f32 mWidthLimit; // at 0x4C + f32 mCharSpace; // at 0x50 + f32 mLineSpace; // at 0x54 + int mTabWidth; // at 0x58 + u32 mDrawFlag; // at 0x5C + TagProcessorBase* mTagProcessor; // at 0x60 + + static T* mFormatBuffer; + static u32 mFormatBufferSize; + static TagProcessorBase mDefaultTagProcessor; +}; + +template <> +inline int TextWriterBase::VSNPrintf(char* buffer, u32 count, + const char* fmt, std::va_list args) { + return std::vsnprintf(buffer, count, fmt, args); +} + +template <> +inline int TextWriterBase::VSNPrintf(wchar_t* buffer, u32 count, + const wchar_t* fmt, + std::va_list args) { + return std::vswprintf(buffer, count, fmt, args); } + +} // namespace ut +} // namespace nw4hbm + +#endif diff --git a/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/ut/ut_binaryFileFormat.h b/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/ut/ut_binaryFileFormat.h index 83bae4a61..246f91bde 100644 --- a/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/ut/ut_binaryFileFormat.h +++ b/libs/RVL_SDK/src/revolution/hbm/include/nw4hbm/ut/ut_binaryFileFormat.h @@ -1,27 +1,28 @@ -#pragma once +#ifndef NW4HBM_UT_BINARY_FILE_FORMAT_H +#define NW4HBM_UT_BINARY_FILE_FORMAT_H +#include -#include "nw4hbm/types_nw4hbm.h" +namespace nw4hbm { +namespace ut { -namespace nw4hbm -{ - namespace ut - { - struct BinaryBlockHeader - { - u32 magic; // File magic - u32 length; // Length of the block (including header) - }; - - struct BinaryFileHeader - { - u32 magic; // File magic - u16 bom; // Byte Order Mark - u16 version; // File version - u32 length; // Length of the file (including header) - u16 headerLen; // Length of the header - u16 blockCount; // Number of blocks - }; - - bool IsValidBinaryFile(const BinaryFileHeader *, u32, u16, u16); - } -} +struct BinaryBlockHeader { + u32 magic; // at 0x0 + u32 length; // at 0x4 +}; + +struct BinaryFileHeader { + u32 magic; // at 0x0 + u16 byteOrder; // at 0x4 + u16 version; // at 0x6 + u32 fileSize; // at 0x8 + u16 headerSize; // at 0xC + u16 numBlocks; // at 0xE +}; + +bool IsValidBinaryFile(const BinaryFileHeader* header, u32 magic, u16 version, + u16 numBlocks); + +} // namespace ut +} // namespace nw4hbm + +#endif diff --git a/libs/RVL_SDK/src/revolution/hbm/nw4hbm/ut/ut_CharStrmReader.cpp b/libs/RVL_SDK/src/revolution/hbm/nw4hbm/ut/ut_CharStrmReader.cpp index ef0fc75ca..e4c0a1547 100644 --- a/libs/RVL_SDK/src/revolution/hbm/nw4hbm/ut/ut_CharStrmReader.cpp +++ b/libs/RVL_SDK/src/revolution/hbm/nw4hbm/ut/ut_CharStrmReader.cpp @@ -1,74 +1,60 @@ -#include "nw4hbm/ut/ut_CharStrmReader.h" +#pragma ipa file // TODO: REMOVE AFTER REFACTOR -namespace nw4hbm -{ - namespace ut - { - namespace - { - static inline bool IsSJISLeadByte(u8 byte) - { - return 0x81 <= byte && byte < 0xa0 || 0xe0 <= byte; - } - } - - u16 CharStrmReader::ReadNextCharUTF8() - { - u16 ret; - - if ((GetChar(0) & 0x80) == 0) - { - ret = GetChar(0); - StepStrm(1); - } - else if ((GetChar(0) & 0xE0) == 0xC0) - { - ret = ((GetChar(0) & 0x1f) << 6) | (GetChar(1) & 0x3f); - StepStrm(2); - } - else - { - ret = ((GetChar(0) & 0x1f) << 12) | ((GetChar(1) & 0x3f) << 6) | (GetChar(2) & 0x3f); - StepStrm(3); - } - - return ret; - } - - u16 CharStrmReader::ReadNextCharUTF16() - { - u16 ret = GetChar(0); - - StepStrm(1); - - return ret; - } - - u16 CharStrmReader::ReadNextCharCP1252() - { - u16 ret = GetChar(0); - - StepStrm(1); - - return ret; - } - - u16 CharStrmReader::ReadNextCharSJIS() - { - u16 ret; - - if (IsSJISLeadByte(GetChar(0))) - { - ret = (GetChar(0) << 8) | GetChar(1); - StepStrm(2); - } - else - { - ret = GetChar(0); - StepStrm(1); - } - - return ret; - } +#include + +namespace nw4hbm { +namespace ut { +namespace { + +bool IsSJISLeadByte(u8 byte){ + return 0x81 <= byte && byte < 0xa0 || 0xe0 <= byte; +} + +} // namespace + +u16 CharStrmReader::ReadNextCharUTF8() { + u16 ret; + + if ((GetChar(0) & 0x80) == 0) { + ret = GetChar(0); + StepStrm(1); + } else if ((GetChar(0) & 0xE0) == 0xC0) { + ret = ((GetChar(0) & 0x1F) << 6) | (GetChar(1) & 0x3F); + StepStrm(2); + } else { + ret = ((GetChar(0) & 0x1F) << 12) | ((GetChar(1) & 0x3F) << 6) | + (GetChar(2) & 0x3F); + StepStrm(3); } + + return ret; +} + +u16 CharStrmReader::ReadNextCharUTF16() { + u16 ret = GetChar(0); + StepStrm(1); + return ret; } + +u16 CharStrmReader::ReadNextCharCP1252() { + u16 ret = GetChar(0); + StepStrm(1); + return ret; +} + +u16 CharStrmReader::ReadNextCharSJIS() { + u16 ret; + + if (IsSJISLeadByte(GetChar(0))) { + ret = (GetChar(0) << 8) | GetChar(1); + StepStrm(2); + } else { + ret = GetChar(0); + StepStrm(1); + } + + return ret; +} + +} // namespace ut +} // namespace nw4hbm diff --git a/libs/RVL_SDK/src/revolution/hbm/nw4hbm/ut/ut_Font.cpp b/libs/RVL_SDK/src/revolution/hbm/nw4hbm/ut/ut_Font.cpp index 156819729..f23b19849 100644 --- a/libs/RVL_SDK/src/revolution/hbm/nw4hbm/ut/ut_Font.cpp +++ b/libs/RVL_SDK/src/revolution/hbm/nw4hbm/ut/ut_Font.cpp @@ -1,27 +1,27 @@ -#include "nw4hbm/ut/ut_Font.h" +#pragma ipa file // TODO: REMOVE AFTER REFACTOR -namespace nw4hbm -{ - namespace ut - { - void Font::InitReaderFunc(FontEncoding enc) - { - switch (enc) - { - case FontEnc_UTF8: - mReaderFunc = &CharStrmReader::ReadNextCharUTF8; - return; - case FontEnc_UTF16: - mReaderFunc = &CharStrmReader::ReadNextCharUTF16; - return; - case FontEnc_SJIS: - mReaderFunc = &CharStrmReader::ReadNextCharSJIS; - return; - case FontEnc_CP1252: - default: - mReaderFunc = &CharStrmReader::ReadNextCharCP1252; - return; - } - } +#include + +namespace nw4hbm { +namespace ut { + +void Font::InitReaderFunc(FontEncoding encode) { + switch (encode) { + case FONT_ENCODE_UTF8: + mReadFunc = &CharStrmReader::ReadNextCharUTF8; + break; + case FONT_ENCODE_UTF16: + mReadFunc = &CharStrmReader::ReadNextCharUTF16; + break; + case FONT_ENCODE_SJIS: + mReadFunc = &CharStrmReader::ReadNextCharSJIS; + break; + case FONT_ENCODE_CP1252: + default: + mReadFunc = &CharStrmReader::ReadNextCharCP1252; + break; } } + +} // namespace ut +} // namespace nw4hbm diff --git a/libs/RVL_SDK/src/revolution/hbm/nw4hbm/ut/ut_LinkList.cpp b/libs/RVL_SDK/src/revolution/hbm/nw4hbm/ut/ut_LinkList.cpp index a395165fc..a46a549d6 100644 --- a/libs/RVL_SDK/src/revolution/hbm/nw4hbm/ut/ut_LinkList.cpp +++ b/libs/RVL_SDK/src/revolution/hbm/nw4hbm/ut/ut_LinkList.cpp @@ -1,66 +1,68 @@ +#pragma ipa file // TODO: REMOVE AFTER REFACTOR -#include "nw4hbm/ut/ut_LinkList.h" - -namespace nw4hbm -{ - namespace ut - { - namespace detail - { - LinkListImpl::~LinkListImpl() - { - Iterator iBegin = this->GetBeginIter(); - Iterator iEnd = this->GetEndIter(); - Erase(iBegin, iEnd); - } - - LinkListNode * LinkListImpl::Erase(LinkListImpl::Iterator iNode) - { - Iterator iBegin(iNode.mNode); - - return Erase(iBegin, iBegin->mNext); - } - - void LinkListImpl::Clear() - { - Iterator iBegin = this->GetBeginIter(); - Iterator iEnd = this->GetEndIter(); - Erase(iBegin, iEnd); - } - - LinkListNode * LinkListImpl::Insert(Iterator i, LinkListNode * pNode) - { - LinkListNode * r4 = i.mNode; - LinkListNode * r6; - - r6 = r4->mPrev; - pNode->mNext = r4; - pNode->mPrev = r6; - r4->mPrev = pNode; - r6->mNext = pNode; - this->mCount++; - - return pNode; - } - - LinkListNode * LinkListImpl::Erase(LinkListNode * pNode) - { - LinkListNode * pPrev; - LinkListNode * pNext; - - pNext = pNode->mNext; - pPrev = pNode->mPrev; - - pNext->mPrev = pPrev; - pPrev->mNext = pNext; - - this->mCount--; - - pNode->mNext = NULL; - pNode->mPrev = NULL; - - return pNext; - } - } +#include + +namespace nw4hbm { +namespace ut { +namespace detail { + +LinkListImpl::~LinkListImpl() { Clear(); } + +LinkListImpl::Iterator LinkListImpl::Erase(LinkListImpl::Iterator it) { + Iterator copy(it); + return Erase(it, ++copy); +} + +void LinkListImpl::Clear() { Erase(GetBeginIter(), GetEndIter()); } + +LinkListImpl::Iterator LinkListImpl::Insert(Iterator it, LinkListNode* p) { + LinkListNode* next = it.mNode; + LinkListNode* prev = next->mPrev; + + // prev <- p -> next + p->mNext = next; + p->mPrev = prev; + // prev <-> p <-> next + next->mPrev = p; + prev->mNext = p; + + mSize++; + + return Iterator(p); +} + +LinkListImpl::Iterator LinkListImpl::Erase(LinkListNode* p) { + LinkListNode* next = p->mNext; + LinkListNode* prev = p->mPrev; + + // Remove connections to node + next->mPrev = prev; + prev->mNext = next; + + mSize--; + + // Isolate node + p->mNext = NULL; + p->mPrev = NULL; + + return Iterator(next); +} + +LinkListImpl::Iterator LinkListImpl::Erase(Iterator begin, Iterator end) { + LinkListNode* pCur = begin.mNode; + LinkListNode* pEnd = end.mNode; + + while (pCur != pEnd) { + // Preserve next node before erasing pointers + LinkListNode* pNext = pCur->mNext; + // Erase current node + Erase(pCur); + pCur = pNext; } + + return Iterator(pEnd); } + +} // namespace detail +} // namespace ut +} // namespace nw4hbm diff --git a/libs/RVL_SDK/src/revolution/hbm/nw4hbm/ut/ut_ResFont.cpp b/libs/RVL_SDK/src/revolution/hbm/nw4hbm/ut/ut_ResFont.cpp index f69f94900..6c92ead7f 100644 --- a/libs/RVL_SDK/src/revolution/hbm/nw4hbm/ut/ut_ResFont.cpp +++ b/libs/RVL_SDK/src/revolution/hbm/nw4hbm/ut/ut_ResFont.cpp @@ -1,99 +1,123 @@ -#include "nw4hbm/ut/ut_ResFont.h" - -namespace nw4hbm -{ - namespace ut - { - template - inline void ResolveOffset(T *& t, void * v) - { - t = reinterpret_cast((u8 *)v + (s32)t); - } - - ResFont::ResFont() {} - ResFont::~ResFont() {} - - bool ResFont::SetResource(void * pBuffer) - { - BinaryFileHeader * file = static_cast(pBuffer); - - FontInformation * pFontInfo = NULL; - - if (mBuffer) return false; - - if (file->magic == 'RFNU') //IsManaging? - { - BinaryBlockHeader * pCurBlock = (BinaryBlockHeader *)((u8 *)file + file->headerLen); - - for (int i = 0; i < file->blockCount; i++) - { - if (pCurBlock->magic == 'FINF') - { - pFontInfo = (FontInformation *)(pCurBlock + 1); - break; - } - pCurBlock = (BinaryBlockHeader *)((u8 *)pCurBlock + pCurBlock->length); - } +#include + +const u32 MAGIC_RESFONT = 'RFNT'; +const u32 MAGIC_UNPACKED = 'RFNU'; + +const u32 MAGIC_FONTINFO = 'FINF'; +const u32 MAGIC_TEXGLYPH = 'TGLP'; +const u32 MAGIC_CHARWIDTH = 'CWDH'; +const u32 MAGIC_CHARMAP = 'CMAP'; +const u32 MAGIC_GLGR = 'GLGR'; + +namespace nw4hbm { +namespace ut { +namespace { + +template void ResolveOffset(T*& ptr, void* base) { + ptr = reinterpret_cast(static_cast(base) + + reinterpret_cast(ptr)); +} + +} // namespace + +ResFont::ResFont() {} + +ResFont::~ResFont() {} + +bool ResFont::SetResource(void* buffer) { + BinaryFileHeader* header = static_cast(buffer); + FontInformation* info = NULL; + + if (!IsManaging(NULL)) { + return false; + } + + if (header->magic == MAGIC_UNPACKED) { + BinaryBlockHeader* block = reinterpret_cast( + reinterpret_cast(header) + header->headerSize); + + for (int i = 0; i < header->numBlocks; i++) { + if (block->magic == MAGIC_FONTINFO) { + info = reinterpret_cast(block + 1); + break; } - else - { - if (file->version == 0x0104) - { - if (!IsValidBinaryFile(file, 'RFNT', 0x0104, 2)) return false; - } - else - { - if (!IsValidBinaryFile(file, 'RFNT', 0x0102, 2)) return false; - } - pFontInfo = Rebuild(file); + + block = reinterpret_cast( + reinterpret_cast(block) + block->length); + } + } else { + if (header->version == NW4R_VERSION(1, 04)) { + if (!IsValidBinaryFile(header, MAGIC_RESFONT, NW4R_VERSION(1, 04), + 2)) { + return false; } - - if (pFontInfo == NULL) return false; - - SetResourceBuffer(pBuffer, pFontInfo); - InitReaderFunc(GetEncoding()); - - return true; + } else if (!IsValidBinaryFile(header, MAGIC_RESFONT, + NW4R_VERSION(1, 02), 2)) { + return false; } - - //TODO: fix mwcc warnings - FontInformation * ResFont::Rebuild(BinaryFileHeader * file) - { - BinaryBlockHeader * pCurBlock = (BinaryBlockHeader *)((u8 *)file + file->headerLen); - FontInformation * pFontInfo = NULL; - - for (int i = 0; i < file->blockCount; i++) - { - switch (pCurBlock->magic) - { - case 'FINF': //8000ABD8 - pFontInfo = reinterpret_cast(pCurBlock + 1); - ResolveOffset(pFontInfo->mTextureGlyph, file); - if (pFontInfo->mWidthList) ResolveOffset(pFontInfo->mWidthList, file); - if (pFontInfo->mCodeMapList) ResolveOffset(pFontInfo->mCodeMapList, file); - break; - case 'TGLP': //8000AC14 - ResolveOffset(reinterpret_cast(pCurBlock + 1)->PTR_0x14, file); - break; - case 'CWDH': //8000AC24 - FontWidth * pWidths = reinterpret_cast(pCurBlock + 1); - if (pWidths->mNext) ResolveOffset(pWidths->mNext, file); - break; - case 'CMAP': //8000AC3C - FontCodeMap * pMap = reinterpret_cast(pCurBlock + 1); - if (pMap->mNext) ResolveOffset(pMap->mNext, file); - break; - case 'GLGR': - break; - default: - return NULL; - } - - pCurBlock = (BinaryBlockHeader *)((u8 *)pCurBlock + pCurBlock->length); + + info = Rebuild(header); + } + + if (info == NULL) { + return false; + } + + SetResourceBuffer(header, info); + InitReaderFunc(GetEncoding()); + + return true; +} + +FontInformation* ResFont::Rebuild(BinaryFileHeader* header) { + BinaryBlockHeader* block = reinterpret_cast( + reinterpret_cast(header) + header->headerSize); + FontInformation* info = NULL; + + for (int i = 0; i < header->numBlocks; i++) { + switch (block->magic) { + case MAGIC_FONTINFO: + info = reinterpret_cast(block + 1); + ResolveOffset(info->fontGlyph, header); + + if (info->fontWidth != 0) { + ResolveOffset(info->fontWidth, header); + } + + if (info->fontMap != 0) { + ResolveOffset(info->fontMap, header); + } + break; + case MAGIC_TEXGLYPH: + ResolveOffset( + reinterpret_cast(block + 1)->sheetImage, + header); + break; + case MAGIC_CHARWIDTH: + FontWidth* width = reinterpret_cast(block + 1); + if (width->next != 0) { + ResolveOffset(width->next, header); } - - file->magic = 'RFNU'; - return pFontInfo; + break; + case MAGIC_CHARMAP: + FontCodeMap* map = reinterpret_cast(block + 1); + if (map->next != 0) { + ResolveOffset(map->next, header); + } + break; + case MAGIC_GLGR: + break; + default: + return NULL; } + + block = reinterpret_cast( + reinterpret_cast(block) + block->length); } + + header->magic = MAGIC_UNPACKED; + return info; } + +} // namespace ut +} // namespace nw4hbm diff --git a/libs/RVL_SDK/src/revolution/hbm/nw4hbm/ut/ut_ResFontBase.cpp b/libs/RVL_SDK/src/revolution/hbm/nw4hbm/ut/ut_ResFontBase.cpp index e9bd44e3b..915f16364 100644 --- a/libs/RVL_SDK/src/revolution/hbm/nw4hbm/ut/ut_ResFontBase.cpp +++ b/libs/RVL_SDK/src/revolution/hbm/nw4hbm/ut/ut_ResFontBase.cpp @@ -1,229 +1,195 @@ -#include "nw4hbm/ut/ut_ResFontBase.h" -#include - -namespace nw4hbm -{ - namespace ut - { - namespace detail - { - ResFontBase::ResFontBase() : mBuffer(), mFontInfo() {} - ResFontBase::~ResFontBase() {} - - u16 ResFontBase::FindGlyphIndex(u16 ch) const - { - for (FontCodeMap * pCodeMap = mFontInfo->mCodeMapList; pCodeMap; pCodeMap = pCodeMap->mNext) - { - if (pCodeMap->mFirstChar <= ch && ch <= pCodeMap->mLastChar) return FindGlyphIndex(pCodeMap, ch); - } - - return 0xFFFF; - } - - u16 ResFontBase::GetGlyphIndex(u16 ch) const - { - u16 glyphIndex = FindGlyphIndex(ch); - - return (glyphIndex != 0xFFFF) ? glyphIndex : mFontInfo->mAlternateChar; - } - - const CharWidths & ResFontBase::GetCharWidthsFromIndex(const FontWidth * pWidths, u16 ch) const - { - return pWidths->mWidthTable[ch - pWidths->mFirstChar]; - } - - const CharWidths & ResFontBase::GetCharWidthsFromIndex(u16 ch) const - { - for (const FontWidth * pWidth = mFontInfo->mWidthList; pWidth; pWidth = pWidth->mNext) - { - if (pWidth->mFirstChar <= ch && ch <= pWidth->mLastChar) return GetCharWidthsFromIndex(pWidth, ch); - } - - return mFontInfo->mDefaultCharWidths; - } - - void ResFontBase::SetResourceBuffer(void * pBuffer, FontInformation * pFontInfo) - { - mBuffer = pBuffer; - mFontInfo = pFontInfo; - } - - int ResFontBase::GetWidth() const - { - return mFontInfo->mWidth; - } - - int ResFontBase::GetHeight() const - { - return mFontInfo->mHeight; - } - - int ResFontBase::GetAscent() const - { - return mFontInfo->mAscent; - } - - int ResFontBase::GetDescent() const - { - return mFontInfo->mHeight - mFontInfo->mAscent; - } - - int ResFontBase::GetBaselinePos() const - { - return mFontInfo->mTextureGlyph->mBaselinePos; - } - - int ResFontBase::GetCellHeight() const - { - return mFontInfo->mTextureGlyph->mCellHeight; - } - - int ResFontBase::GetCellWidth() const - { - return mFontInfo->mTextureGlyph->mCellWidth; - } - - int ResFontBase::GetMaxCharWidth() const - { - return mFontInfo->mTextureGlyph->mMaxCharWidth; - } - - int ResFontBase::GetType() const - { - return 2; - } - - int ResFontBase::GetTextureFormat() const - { - return mFontInfo->mTextureGlyph->mFormat; - } - - int ResFontBase::GetLineFeed() const - { - return mFontInfo->mLineFeed; - } - - CharWidths ResFontBase::GetDefaultCharWidths() const - { - return mFontInfo->mDefaultCharWidths; - } - - void ResFontBase::SetDefaultCharWidths(const CharWidths & rDefaultCharWidths) - { - mFontInfo->mDefaultCharWidths = rDefaultCharWidths; - } - - bool ResFontBase::SetAlternateChar(u16 ch) - { - u16 r5; - - r5 = FindGlyphIndex(ch); - - if (r5 != 0xFFFF) - { - mFontInfo->mAlternateChar = r5; - return true; - } - - return false; - } - - void ResFontBase::SetLineFeed(int lf) - { - mFontInfo->mLineFeed = lf; - } - - int ResFontBase::GetCharWidth(u16 ch) const - { - return GetCharWidths(ch).BYTE_0x2; - } - - CharWidths ResFontBase::GetCharWidths(u16 ch) const - { - return GetCharWidthsFromIndex(GetGlyphIndex(ch)); - } - - void ResFontBase::GetGlyph(Glyph * pGlyph, u16 ch) const - { - GetGlyphFromIndex(pGlyph, GetGlyphIndex(ch)); - } +#pragma ipa file // TODO: REMOVE AFTER REFACTOR - FontEncoding ResFontBase::GetEncoding() const - { - return (FontEncoding)mFontInfo->mEncoding; - } - - u16 ResFontBase::FindGlyphIndex(const FontCodeMap * pMap, u16 ch) const - { - struct Pair - { - u16 chr; - u16 glph; - }; - - u16 ret = 0xFFFF; - - switch (pMap->mType) - { - case FontMap_Linear: - ret = pMap->mGlyphTable[0] + (ch - pMap->mFirstChar); - break; - case FontMap_Array: - ret = pMap->mGlyphTable[ch - pMap->mFirstChar]; - break; - case FontMap_Morphism: - const u16 * pTable = pMap->mGlyphTable; - - const Pair * s = reinterpret_cast(pTable + 1); - const Pair * e = reinterpret_cast(++pTable + (2 * (*pTable - 1))); - - while (s <= e) - { - const Pair * m = s + (e - s) / 2; - - if (m->chr < ch) s = m + 1; - else if (ch < m->chr) e = m - 1; - else return m->glph; - } - - break; - } - - return ret; - } - - void ResFontBase::GetGlyphFromIndex(Glyph * pGlyph, u16 glyphIndex) const - { - FontTextureGlyph * r3 = mFontInfo->mTextureGlyph; - - u32 r31 = r3->SHORT_0xC * r3->SHORT_0xE; - - u32 r30 = glyphIndex % r31; - u32 r11 = glyphIndex / r31; - - u32 i = r30 / r3->SHORT_0xC; - u32 j = r30 % r3->SHORT_0xC; - - u32 r8 = j * (r3->mCellWidth + 1); - u32 r9 = i * (r3->mCellHeight + 1); - pGlyph->PTR_0x0 = r3->PTR_0x14 + (r11 * r3->WORD_0x4); //stw r0,0(r4) - - const CharWidths & r7_2 = GetCharWidthsFromIndex(glyphIndex); - - pGlyph->BYTE_0x4 = r7_2.BYTE_0x0; - pGlyph->cellWidth = r7_2.BYTE_0x1; - pGlyph->BYTE_0x6 = r7_2.BYTE_0x2; - - pGlyph->cellHeight = r3->mCellHeight; - - pGlyph->WORD_0x8 = (GXTexFmt)r3->mFormat; - - pGlyph->SHORT_0xC = r3->SHORT_0x10; - pGlyph->SHORT_0xE = r3->SHORT_0x12; - - pGlyph->SHORT_0x10 = r8 + 1; - pGlyph->SHORT_0x12 = r9 + 1; +#include + +namespace nw4hbm { +namespace ut { +namespace detail { + +ResFontBase::ResFontBase() : mResource(NULL), mFontInfo(NULL) {} + +ResFontBase::~ResFontBase() {} + +void ResFontBase::SetResourceBuffer(void* buffer, FontInformation* info) { + mResource = buffer; + mFontInfo = info; +} + +int ResFontBase::GetWidth() const { return mFontInfo->width; } + +int ResFontBase::GetHeight() const { return mFontInfo->height; } + +int ResFontBase::GetAscent() const { return mFontInfo->ascent; } + +int ResFontBase::GetDescent() const { + return mFontInfo->height - mFontInfo->ascent; +} + +int ResFontBase::GetBaselinePos() const { + return mFontInfo->fontGlyph->baselinePos; +} + +int ResFontBase::GetCellHeight() const { + return mFontInfo->fontGlyph->cellHeight; +} + +int ResFontBase::GetCellWidth() const { + return mFontInfo->fontGlyph->cellWidth; +} + +int ResFontBase::GetMaxCharWidth() const { + return mFontInfo->fontGlyph->maxCharWidth; +} + +Font::Type ResFontBase::GetType() const { return TYPE_RESOURCE; } + +GXTexFmt ResFontBase::GetTextureFormat() const { + return static_cast(mFontInfo->fontGlyph->sheetFormat); +} + +int ResFontBase::GetLineFeed() const { return mFontInfo->lineFeed; } + +CharWidths ResFontBase::GetDefaultCharWidths() const { + return mFontInfo->defaultWidth; +} + +void ResFontBase::SetDefaultCharWidths(const CharWidths& widths) { + mFontInfo->defaultWidth = widths; +} + +bool ResFontBase::SetAlternateChar(u16 ch) { + u16 index = FindGlyphIndex(ch); + + if (index != 0xFFFF) { + mFontInfo->alterCharIndex = index; + return true; + } + + return false; +} + +void ResFontBase::SetLineFeed(int lf) { mFontInfo->lineFeed = lf; } + +int ResFontBase::GetCharWidth(u16 ch) const { + return GetCharWidths(ch).charWidth; +} + +CharWidths ResFontBase::GetCharWidths(u16 ch) const { + return GetCharWidthsFromIndex(GetGlyphIndex(ch)); +} + +void ResFontBase::GetGlyph(Glyph* out, u16 ch) const { + GetGlyphFromIndex(out, GetGlyphIndex(ch)); +} + +FontEncoding ResFontBase::GetEncoding() const { + return static_cast(mFontInfo->encoding); +} + +u16 ResFontBase::GetGlyphIndex(u16 c) const { + u16 index = FindGlyphIndex(c); + return (index != 0xFFFF) ? index : mFontInfo->alterCharIndex; +} + +u16 ResFontBase::FindGlyphIndex(u16 c) const { + for (FontCodeMap* it = mFontInfo->fontMap; it != NULL; it = it->next) { + if (it->firstChar <= c && c <= it->lastChar) { + return FindGlyphIndex(it, c); + } + } + + return 0xFFFF; +} + +u16 ResFontBase::FindGlyphIndex(const FontCodeMap* map, u16 c) const { + struct CMapScanEntry { + u16 code; // at 0x0 + u16 index; // at 0x2 + }; + + struct CMapInfoScan { + u16 num; // at 0x0 + CMapScanEntry entries[]; // at 0x2 + }; + + u16 index = 0xFFFF; + + switch (map->mappingMethod) { + case FONT_MAPMETHOD_LINEAR: + index = map->mapInfo[0] + (c - map->firstChar); + break; + case FONT_MAPMETHOD_ARRAY: + index = map->mapInfo[c - map->firstChar]; + break; + case FONT_MAPMETHOD_SCAN: + const CMapInfoScan* info = + reinterpret_cast(map->mapInfo); + + const CMapScanEntry* s = info->entries; + const CMapScanEntry* e = &info->entries[info->num - 1]; + + while (s <= e) { + const CMapScanEntry* m = s + (e - s) / 2; + + if (m->code < c) { + s = m + 1; + } else if (c < m->code) { + e = m - 1; + } else { + return m->index; } } + + break; } + + return index; +} + +const CharWidths& ResFontBase::GetCharWidthsFromIndex(u16 index) const { + for (const FontWidth* it = mFontInfo->fontWidth; it != NULL; + it = it->next) { + if (it->firstChar <= index && index <= it->lastChar) { + return GetCharWidthsFromIndex(it, index); + } + } + + return mFontInfo->defaultWidth; +} + +const CharWidths& ResFontBase::GetCharWidthsFromIndex(const FontWidth* width, + u16 index) const { + return width->widthTable[index - width->firstChar]; } + +void ResFontBase::GetGlyphFromIndex(Glyph* out, u16 index) const { + const FontTextureGlyph* texGlyph = mFontInfo->fontGlyph; + + u32 cellsInASheet = texGlyph->sheetRow * texGlyph->sheetLine; + + u32 glyphCell = index % cellsInASheet; + u32 glyphSheet = index / cellsInASheet; + + u32 unitX = glyphCell % texGlyph->sheetRow; + u32 unitY = glyphCell / texGlyph->sheetRow; + + u32 pixelX = unitX * (texGlyph->cellWidth + 1); + u32 pixelY = unitY * (texGlyph->cellHeight + 1); + + out->texture = texGlyph->sheetImage + (glyphSheet * texGlyph->sheetSize); + + out->widths = GetCharWidthsFromIndex(index); + out->height = texGlyph->cellHeight; + + out->format = static_cast(texGlyph->sheetFormat); + + out->texWidth = texGlyph->sheetWidth; + out->texHeight = texGlyph->sheetHeight; + + out->cellX = pixelX + 1; + out->cellY = pixelY + 1; +} + +} // namespace detail +} // namespace ut +} // namespace nw4hbm diff --git a/libs/RVL_SDK/src/revolution/hbm/nw4hbm/ut/ut_TagProcessorBase.cpp b/libs/RVL_SDK/src/revolution/hbm/nw4hbm/ut/ut_TagProcessorBase.cpp index 1e1c70168..9d52cb6af 100644 --- a/libs/RVL_SDK/src/revolution/hbm/nw4hbm/ut/ut_TagProcessorBase.cpp +++ b/libs/RVL_SDK/src/revolution/hbm/nw4hbm/ut/ut_TagProcessorBase.cpp @@ -1,186 +1,90 @@ -#include "nw4hbm/ut/ut_TagProcessorBase.h" -#include "nw4hbm/ut/ut_TextWriterBase.h" -#include "nw4hbm/ut/ut_CharWriter.h" - -namespace nw4hbm -{ - namespace ut - { - template - void TagProcessorBase::ProcessLinefeed(PrintContext * pContext) - { - TextWriterBase * r31; - - f32 f0; - f32 f31; - f32 f30; - - r31 = pContext->mTextWriter; - f31 = pContext->FLOAT_0x8; - f30 = r31->GetCursorY(); - - f0 = f30 + r31->GetLineHeight(); - - r31->SetCursorX(f31); - r31->SetCursorY(f0); - } - - template - void TagProcessorBase::ProcessTab(PrintContext * pContext) - { - s32 r30; - TextWriterBase * r31; - - f32 f0; - f32 f1; - f32 f4; - f32 f3; - - r31 = pContext->mTextWriter; - r30 = r31->GetTabWidth(); - - if (r30 <= 0) return; - - f1 = r31->IsWidthFixed() ? r31->GetFixedWidth() : r31->GetFontWidth(); - f4 = r31->GetCursorX(); - f3 = pContext->FLOAT_0x8; - f1 = r30 * f1; - f4 -= f3; - f0 = (s32)(f4 / f1) + 1; - r31->SetCursorX(f3 + (f1 * f0)); - } - - template TagProcessorBase::TagProcessorBase() {} - template TagProcessorBase::~TagProcessorBase() {} - - template - int TagProcessorBase::Process(u16 procCh, PrintContext * pContext) - { - switch(procCh) - { - case '\n': - ProcessLinefeed(pContext); - return 3; - case '\t': - ProcessTab(pContext); - return 1; - } - return 0; - } - - template - int TagProcessorBase::CalcRect(register Rect * pRect, u16 procCh, PrintContext * pContext) - { - switch(procCh) - { - case '\n': - { - TextWriterBase * r30_newline; - - r30_newline = pContext->mTextWriter; - - pRect->FLOAT_0x8 = r30_newline->GetCursorX(); - pRect->FLOAT_0x4 = r30_newline->GetCursorY(); - - ProcessLinefeed(pContext); - - pRect->FLOAT_0x0 = r30_newline->GetCursorX(); - - pRect->FLOAT_0xC = r30_newline->GetCursorY() + pContext->mTextWriter->GetFontHeight(); - - register f32 out_0x4; - - register f32 dif1; - register f32 dif2; - - register f32 out_0x0; - register f32 out_0x8; - register f32 out_0xc; - - register f32 in_0xc; - register f32 in_0x8; - register f32 in_0x4; - register f32 in_0x0; - - in_0x0 = pRect->FLOAT_0x0; - in_0x4 = pRect->FLOAT_0x4; - in_0x8 = pRect->FLOAT_0x8; - in_0xc = pRect->FLOAT_0xC; - - dif1 = in_0xc - in_0x4; - dif2 = in_0x8 - in_0x0; - - asm - { - fsel out_0x4, dif1, in_0x4, in_0xc - fsel out_0x0, dif2, in_0x0, in_0x8 - fsel out_0x8, dif2, in_0x8, in_0x0 - fsel out_0xc, dif1, in_0xc, in_0x4 - stfs out_0x4, 0x4(pRect) - stfs out_0x0, 0x0(pRect) - stfs out_0x8, 0x8(pRect) - stfs out_0xc, 0xc(pRect) - } - - return 3; - } - case '\t': - { - TextWriterBase * r29_tab; - - r29_tab = pContext->mTextWriter; - - pRect->FLOAT_0x0 = r29_tab->GetCursorX(); - - ProcessTab(pContext); - - pRect->FLOAT_0x8 = r29_tab->GetCursorX(); - pRect->FLOAT_0x4 = r29_tab->GetCursorY(); - - pRect->FLOAT_0xC = pRect->FLOAT_0x4 + r29_tab->GetFontHeight(); - - register f32 out_0x4; - - register f32 dif1; - register f32 dif2; - - register f32 in_0x8; - - register f32 out_0x0; - register f32 out_0x8; - register f32 out_0xc; - - register f32 in_0xc; - register f32 in_0x4; - register f32 in_0x0; - - in_0x0 = pRect->FLOAT_0x0; - in_0x4 = pRect->FLOAT_0x4; - in_0x8 = pRect->FLOAT_0x8; - in_0xc = pRect->FLOAT_0xC; - - dif2 = in_0x8 - in_0x0; - dif1 = in_0xc - in_0x4; - - asm - { - fsel out_0x0, dif2, in_0x0, in_0x8 - fsel out_0x8, dif2, in_0x8, in_0x0 - fsel out_0x4, dif1, in_0x4, in_0xc - fsel out_0xc, dif1, in_0xc, in_0x4 - stfs out_0x0, 0x0(pRect) - stfs out_0x8, 0x8(pRect) - stfs out_0x4, 0x4(pRect) - stfs out_0xc, 0xc(pRect) - } - return 1; - } - } - - return 0; - } - - template struct TagProcessorBase; - template struct TagProcessorBase; +#pragma ipa file // TODO: REMOVE AFTER REFACTOR + +#include + +namespace nw4hbm { +namespace ut { + +template TagProcessorBase::TagProcessorBase() {} + +template TagProcessorBase::~TagProcessorBase() {} + +template +Operation TagProcessorBase::Process(u16 ch, PrintContext* ctx) { + switch (ch) { + case '\n': + ProcessLinefeed(ctx); + return OPERATION_NEXT_LINE; + case '\t': + ProcessTab(ctx); + return OPERATION_NO_CHAR_SPACE; + } + + return OPERATION_DEFAULT; +} + +template +Operation TagProcessorBase::CalcRect(Rect* rect, u16 ch, + PrintContext* ctx) { + + switch (ch) { + case '\n': { + const TextWriterBase& writer = *ctx->writer; + rect->right = writer.GetCursorX(); + rect->top = writer.GetCursorY(); + ProcessLinefeed(ctx); + rect->left = writer.GetCursorX(); + rect->bottom = writer.GetCursorY() + ctx->writer->GetFontHeight(); + rect->Normalize(); + return OPERATION_NEXT_LINE; + } + case '\t': { + const TextWriterBase& writer = *ctx->writer; + rect->left = writer.GetCursorX(); + ProcessTab(ctx); + rect->right = writer.GetCursorX(); + rect->top = writer.GetCursorY(); + rect->bottom = rect->top + writer.GetFontHeight(); + rect->Normalize(); + return OPERATION_NO_CHAR_SPACE; + } + } + + return OPERATION_DEFAULT; +} + +template +void TagProcessorBase::ProcessLinefeed(PrintContext* ctx) { + TextWriterBase& writer = *ctx->writer; + + f32 x = ctx->x; + f32 y = writer.GetCursorY() + writer.GetLineHeight(); + + writer.SetCursor(x, y); +} + +template +void TagProcessorBase::ProcessTab(PrintContext* ctx) { + TextWriterBase& writer = *ctx->writer; + + int tabWidth = writer.GetTabWidth(); + if (tabWidth <= 0) { + return; } + + f32 charWidth = + writer.IsWidthFixed() ? writer.GetFixedWidth() : writer.GetFontWidth(); + + f32 dx = writer.GetCursorX() - ctx->x; + f32 tabPixel = tabWidth * charWidth; + int numTab = static_cast(dx / tabPixel) + 1; + f32 x = ctx->x + (tabPixel * numTab); + + writer.SetCursorX(x); } + +template class TagProcessorBase; +template class TagProcessorBase; + +} // namespace ut +} // namespace nw4hbm diff --git a/libs/RVL_SDK/src/revolution/hbm/nw4hbm/ut/ut_binaryFileFormat.cpp b/libs/RVL_SDK/src/revolution/hbm/nw4hbm/ut/ut_binaryFileFormat.cpp index 7df0fa336..e599fa358 100644 --- a/libs/RVL_SDK/src/revolution/hbm/nw4hbm/ut/ut_binaryFileFormat.cpp +++ b/libs/RVL_SDK/src/revolution/hbm/nw4hbm/ut/ut_binaryFileFormat.cpp @@ -1,23 +1,35 @@ -#include "nw4hbm/ut/ut_binaryFileFormat.h" - -#define BOM_BIG_ENDIAN 0xFEFF -#define BOM_LITTLE_ENDIAN 0xFFFE - -namespace nw4hbm -{ - namespace ut - { - bool IsValidBinaryFile(const BinaryFileHeader * header, u32 fileMagic, u16 fileVersion, u16 r6) - { - if (header->magic != fileMagic) return false; - - if (header->bom != BOM_BIG_ENDIAN) return false; - - if (header->version != fileVersion) return false; - - if (header->length < sizeof(BinaryFileHeader) + (r6 << 3)) return false; - - return header->blockCount >= r6; - } +#pragma ipa file // TODO: REMOVE AFTER REFACTOR + +#include + +namespace nw4hbm { +namespace ut { + +bool IsValidBinaryFile(const BinaryFileHeader* header, u32 magic, u16 version, + u16 numBlocks) { + if (header->magic != magic) { + return false; + } + + if (header->byteOrder != NW4R_BYTEORDER_BIG) { + return false; + } + + if (header->version != version) { + return false; } + + if (header->fileSize < + sizeof(BinaryFileHeader) + (numBlocks * sizeof(BinaryBlockHeader))) { + return false; + } + + if (header->numBlocks < numBlocks) { + return false; + } + + return true; } + +} // namespace ut +} // namespace nw4hbm diff --git a/libs/nw4r/include/nw4r/math.h b/libs/nw4r/include/nw4r/math.h index 33646a621..ea99d35f2 100644 --- a/libs/nw4r/include/nw4r/math.h +++ b/libs/nw4r/include/nw4r/math.h @@ -5,6 +5,5 @@ #include #include #include -#include #endif diff --git a/libs/nw4r/include/nw4r/math/math_triangular.h b/libs/nw4r/include/nw4r/math/math_triangular.h index 12704be44..afda3e65d 100644 --- a/libs/nw4r/include/nw4r/math/math_triangular.h +++ b/libs/nw4r/include/nw4r/math/math_triangular.h @@ -2,6 +2,7 @@ #define NW4R_MATH_TRIANGULAR_H #include #include +#include #define NW4R_MATH_PI 3.141592653589793f #define NW4R_MATH_LN_2 0.69314718056f @@ -81,6 +82,32 @@ inline f32 Atan2Rad(f32 y, f32 x) { return NW4R_MATH_FIDX_TO_RAD(Atan2FIdx(y, x)); } +/** + * asin + */ +inline f32 AsinRad(f32 x){ + bool inRange = x <= 1.0f && x >= -1.0f; + + if(!inRange){ + db::Warning("triangular.h",0xe4,"AsinRad: Input is out of the domain."); + } + + return asin(x); +} + +/** + * acos + */ +inline f32 AcosRad(f32 x){ + bool inRange = x <= 1.0f && x >= -1.0f; + + if(!inRange){ + db::Warning("triangular.h",0xef,"AcosRad: Input is out of the domain."); + } + + return acos(x); +} + } // namespace math } // namespace nw4r diff --git a/libs/nw4r/include/nw4r/math/triangular.h b/libs/nw4r/include/nw4r/math/triangular.h deleted file mode 100644 index ca2e4f40b..000000000 --- a/libs/nw4r/include/nw4r/math/triangular.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef _NW4R_TRIANGULAR_H -#define _NW4R_TRIANGULAR_H - -#include -#include -#include - -namespace nw4r{ - namespace math{ - - using namespace db; - - inline f32 AsinRad(f32 x){ - bool inRange = x <= 1.0f && x >= -1.0f; - - if(!inRange){ - Warning("triangular.h",0xe4,"AsinRad: Input is out of the domain."); - } - - return asin(x); - } - - inline f32 AcosRad(f32 x){ - bool inRange = x <= 1.0f && x >= -1.0f; - - if(!inRange){ - Warning("triangular.h",0xef,"AcosRad: Input is out of the domain."); - } - - return acos(x); - } - - } -} - -#endif diff --git a/libs/nw4r/src/db/db_assert.cpp b/libs/nw4r/src/db/db_assert.cpp index d3101b221..ca3c6ff0a 100644 --- a/libs/nw4r/src/db/db_assert.cpp +++ b/libs/nw4r/src/db/db_assert.cpp @@ -1,3 +1,5 @@ +#pragma ipa file // TODO: REMOVE AFTER REFACTOR + #include "db_assert.h" #include "db_console.h" #include