From 85c4d85562e66ad98b35cb24e377db895be1e863 Mon Sep 17 00:00:00 2001 From: Ian Curtis Date: Sun, 19 Jun 2016 21:43:09 +0000 Subject: [PATCH] refactor --- Src/Graphics/New3D/New3D.cpp | 31 ++---------------------- Src/Graphics/New3D/New3D.h | 6 +---- Src/Graphics/New3D/R3DFloat.cpp | 39 +++++++++++++++++++++++++++++++ Src/Graphics/New3D/R3DFloat.h | 14 +++++++++++ VS2008/Supermodel.vcxproj | 2 ++ VS2008/Supermodel.vcxproj.filters | 6 +++++ 6 files changed, 64 insertions(+), 34 deletions(-) create mode 100644 Src/Graphics/New3D/R3DFloat.cpp create mode 100644 Src/Graphics/New3D/R3DFloat.h diff --git a/Src/Graphics/New3D/New3D.cpp b/Src/Graphics/New3D/New3D.cpp index 438ffd5..7073b49 100644 --- a/Src/Graphics/New3D/New3D.cpp +++ b/Src/Graphics/New3D/New3D.cpp @@ -5,6 +5,7 @@ #include #include #include +#include "R3DFloat.h" #define MAX_RAM_POLYS 100000 #define MAX_ROM_POLYS 500000 @@ -403,7 +404,7 @@ void CNew3D::DescendCullingNode(UINT32 addr) if (m_nodeAttribs.currentClipStatus != Clip::INSIDE) { - float distance = ToFloat(Convert16BitProFloat(node[9 - m_offset] & 0xFFFF)); + float distance = R3DFloat::GetFloat16(node[9 - m_offset] & 0xFFFF); CalcBox(distance, bbox); TransformBox(m_modelMat, bbox); @@ -578,7 +579,6 @@ void CNew3D::InitMatrixStack(UINT32 matrixBaseAddr, Mat4& mat) m[CMINDEX(2, 0)] =-1.0; m[CMINDEX(2, 1)] = 0.0; m[CMINDEX(2, 2)] = 0.0; m[CMINDEX(2, 3)] = 0.0; m[CMINDEX(3, 0)] = 0.0; m[CMINDEX(3, 1)] = 0.0; m[CMINDEX(3, 2)] = 0.0; m[CMINDEX(3, 3)] = 1.0; - mat.LoadMatrix(m); // Set matrix base address and apply matrix #0 (coordinate system matrix) @@ -1198,33 +1198,6 @@ void CNew3D::CalcTexOffset(int offX, int offY, int page, int x, int y, int& newX newY += ((oldPage + page) & 1) * 1024; // max page 0-1 } -UINT32 CNew3D::ConvertProFloat(UINT32 a1) -{ - int exponent = (a1 & 0x7E000000) >> 25; - - if (exponent <= 31) { // positive - exponent += 127; - } - else { // negative exponent - exponent -= 64; - exponent += 127; - } - - int mantissa = (a1 & 0x1FFFFFF) >> 2; - - return (a1 & 0x80000000) | (exponent << 23) | mantissa; -} - -UINT32 CNew3D::Convert16BitProFloat(UINT32 a1) -{ - return ConvertProFloat(a1 << 15); -} - -float CNew3D::ToFloat(UINT32 a1) -{ - return *(float*)(&a1); -} - void CNew3D::CalcFrustumPlanes(Plane p[6], const float* matrix) { // Left Plane diff --git a/Src/Graphics/New3D/New3D.h b/Src/Graphics/New3D/New3D.h index 19888b5..f5e3737 100644 --- a/Src/Graphics/New3D/New3D.h +++ b/Src/Graphics/New3D/New3D.h @@ -178,11 +178,7 @@ private: bool IsDynamicModel(UINT32 *data); // check if the model has a colour palette bool IsVROMModel(UINT32 modelAddr); - void CalcTexOffset(int offX, int offY, int page, int x, int y, int& newX, int& newY); - - UINT32 ConvertProFloat(UINT32 a1); // return float in hex or integer format - UINT32 Convert16BitProFloat(UINT32 a1); - float ToFloat(UINT32 a1); // integer float to actual IEEE 754 float + void CalcTexOffset(int offX, int offY, int page, int x, int y, int& newX, int& newY); /* * Data diff --git a/Src/Graphics/New3D/R3DFloat.cpp b/Src/Graphics/New3D/R3DFloat.cpp new file mode 100644 index 0000000..75c6346 --- /dev/null +++ b/Src/Graphics/New3D/R3DFloat.cpp @@ -0,0 +1,39 @@ +#include "Types.h" +#include "R3DFloat.h" + +float R3DFloat::GetFloat16(UINT16 f) +{ + return ToFloat(Convert16BitProFloat(f)); +} + +float R3DFloat::GetFloat32(UINT32 f) +{ + return ToFloat(ConvertProFloat(f)); +} + +UINT32 R3DFloat::ConvertProFloat(UINT32 a1) +{ + int exponent = (a1 & 0x7E000000) >> 25; + + if (exponent <= 31) { // positive + exponent += 127; + } + else { // negative exponent + exponent -= 64; + exponent += 127; + } + + int mantissa = (a1 & 0x1FFFFFF) >> 2; + + return (a1 & 0x80000000) | (exponent << 23) | mantissa; +} + +UINT32 R3DFloat::Convert16BitProFloat(UINT32 a1) +{ + return ConvertProFloat(a1 << 15); +} + +float R3DFloat::ToFloat(UINT32 a1) +{ + return *(float*)(&a1); +} \ No newline at end of file diff --git a/Src/Graphics/New3D/R3DFloat.h b/Src/Graphics/New3D/R3DFloat.h new file mode 100644 index 0000000..357cd69 --- /dev/null +++ b/Src/Graphics/New3D/R3DFloat.h @@ -0,0 +1,14 @@ +#ifndef _R3DFLOAT_H_ +#define _R3DFLOAT_H_ + +namespace R3DFloat +{ + float GetFloat16(UINT16 f); + float GetFloat32(UINT32 f); + + UINT32 ConvertProFloat(UINT32 a1); // return float in hex or integer format + UINT32 Convert16BitProFloat(UINT32 a1); + float ToFloat(UINT32 a1); // integer float to actual IEEE 754 float +} + +#endif \ No newline at end of file diff --git a/VS2008/Supermodel.vcxproj b/VS2008/Supermodel.vcxproj index a8d337f..4c8d83a 100644 --- a/VS2008/Supermodel.vcxproj +++ b/VS2008/Supermodel.vcxproj @@ -316,6 +316,7 @@ xcopy /D /Y "$(ProjectDir)\SDL\$(Platform)\$(Configuration)\SDL.dll" "$(TargetDi + @@ -538,6 +539,7 @@ xcopy /D /Y "$(ProjectDir)\SDL\$(Platform)\$(Configuration)\SDL.dll" "$(TargetDi + diff --git a/VS2008/Supermodel.vcxproj.filters b/VS2008/Supermodel.vcxproj.filters index 63c7437..b8fed46 100644 --- a/VS2008/Supermodel.vcxproj.filters +++ b/VS2008/Supermodel.vcxproj.filters @@ -425,6 +425,9 @@ Source Files\Util + + Source Files\Graphics\New + @@ -787,6 +790,9 @@ Source Files\Graphics\New + + Source Files\Graphics\New +