From fb40a07f993faf83f26d521edd3961c04ef3fcea Mon Sep 17 00:00:00 2001 From: Miran Date: Sat, 28 Mar 2026 20:32:53 +0100 Subject: [PATCH] Base CVector on RwV3d. Get rid of manual conversion methods. --- examples/UnitTests/source/Test_CVector.h | 12 ++------ plugin_II/game_II/CVector2D.h | 2 +- plugin_III/game_III/CVector2D.h | 2 +- plugin_sa/game_sa/CVector2D.h | 2 +- plugin_vc/game_vc/CVector2D.h | 2 +- shared/extensions/FontPrint.cpp | 4 +-- shared/extensions/FontPrint.h | 4 --- shared/game/CVector.h | 27 +++++++++--------- shared/game/CVectorImplementation.h | 36 +++++++++++++++--------- shared/game/CompressedVector.cpp | 28 ------------------ shared/game/CompressedVector.h | 17 ++--------- 11 files changed, 46 insertions(+), 90 deletions(-) diff --git a/examples/UnitTests/source/Test_CVector.h b/examples/UnitTests/source/Test_CVector.h index 12afebf81..a608ecd59 100644 --- a/examples/UnitTests/source/Test_CVector.h +++ b/examples/UnitTests/source/Test_CVector.h @@ -48,7 +48,6 @@ UTEST(CVector, ctor_CVector) EXPECT_EQ(v.z, 3.0f); } -#ifdef RW UTEST(CVector, ctor_RwV3d) { RwV3d src; @@ -61,7 +60,6 @@ UTEST(CVector, ctor_RwV3d) EXPECT_EQ(v.y, 2.0f); EXPECT_EQ(v.z, 3.0f); } -#endif UTEST(CVector, ctor_CVector2D) { @@ -120,8 +118,7 @@ UTEST(CVector, operator_assign) EXPECT_EQ(v.z, 3.0f); } -#ifdef RW -UTEST(CVector, FromRwV3d) +UTEST(CVector, operator_assign_RwV3d) { RwV3d src; src.x = 1.0f; @@ -129,12 +126,11 @@ UTEST(CVector, FromRwV3d) src.z = 3.0f; CVector v; - v.FromRwV3d(src); + v = src; EXPECT_EQ(v.x, 1.0f); EXPECT_EQ(v.y, 2.0f); EXPECT_EQ(v.z, 3.0f); } -#endif UTEST(CVector, From2D) { @@ -239,7 +235,6 @@ UTEST(CVector, FromMultiply3x3) // conversions -#ifdef RW UTEST(CVector, ToRwV3d) { CVector src; @@ -247,12 +242,11 @@ UTEST(CVector, ToRwV3d) src.y = 2.0f; src.z = 3.0f; - RwV3d v = src.ToRwV3d(); + RwV3d v = src; EXPECT_EQ(v.x, 1.0f); EXPECT_EQ(v.y, 2.0f); EXPECT_EQ(v.z, 3.0f); } -#endif UTEST(CVector, To2D) { diff --git a/plugin_II/game_II/CVector2D.h b/plugin_II/game_II/CVector2D.h index 8707cf50b..9a384efd7 100644 --- a/plugin_II/game_II/CVector2D.h +++ b/plugin_II/game_II/CVector2D.h @@ -8,7 +8,7 @@ #pragma once #include "PluginBase.h" -class CVector; +struct CVector; class CVector2D; class CEncodedVector { diff --git a/plugin_III/game_III/CVector2D.h b/plugin_III/game_III/CVector2D.h index 536135d30..ec1529709 100644 --- a/plugin_III/game_III/CVector2D.h +++ b/plugin_III/game_III/CVector2D.h @@ -9,7 +9,7 @@ #include "PluginBase.h" #include -class CVector; +struct CVector; class CVector2D { public: diff --git a/plugin_sa/game_sa/CVector2D.h b/plugin_sa/game_sa/CVector2D.h index 3c0d0b88a..9fadaa24d 100644 --- a/plugin_sa/game_sa/CVector2D.h +++ b/plugin_sa/game_sa/CVector2D.h @@ -8,7 +8,7 @@ #include "PluginBase.h" -class CVector; +struct CVector; class PLUGIN_API CVector2D { diff --git a/plugin_vc/game_vc/CVector2D.h b/plugin_vc/game_vc/CVector2D.h index d3c333910..3f1ce5dfe 100644 --- a/plugin_vc/game_vc/CVector2D.h +++ b/plugin_vc/game_vc/CVector2D.h @@ -9,7 +9,7 @@ #include "PluginBase.h" #include -class CVector; +struct CVector; class CVector2D { public: diff --git a/shared/extensions/FontPrint.cpp b/shared/extensions/FontPrint.cpp index 8057d73a3..d24cae79e 100644 --- a/shared/extensions/FontPrint.cpp +++ b/shared/extensions/FontPrint.cpp @@ -194,7 +194,7 @@ bool Get3dTo2d(CVector const &posn, CVector &out) { #else RwV3d rwvec; float outw, outh; - result = CSprite::CalcScreenCoors(posn.ToRwV3d(), + result = CSprite::CalcScreenCoors(posn, &rwvec, &outw, &outh, @@ -204,7 +204,7 @@ bool Get3dTo2d(CVector const &posn, CVector &out) { #endif ); - out.FromRwV3d(rwvec); + out = rwvec; #endif return result; } diff --git a/shared/extensions/FontPrint.h b/shared/extensions/FontPrint.h index 656f0f6a3..e9d3156e8 100644 --- a/shared/extensions/FontPrint.h +++ b/shared/extensions/FontPrint.h @@ -9,11 +9,7 @@ #include #include #include "CRGBA.h" -#ifdef RW #include "CVector.h" -#elif RAGE -#include "CVector.h" -#endif #include "Screen.h" #ifdef GTA3 diff --git a/shared/game/CVector.h b/shared/game/CVector.h index 5d22d5827..9db66fb33 100644 --- a/shared/game/CVector.h +++ b/shared/game/CVector.h @@ -6,8 +6,14 @@ */ #pragma once #include "PluginBase.h" + #ifdef RW #include "RenderWare.h" +#else + struct RwV3d + { + float x, y, z; + }; #endif #if defined GTA3 || defined GTAVC || defined GTASA @@ -17,21 +23,16 @@ class CVector2D; -class CVector +struct CVector : public RwV3d { public: - float x = 0.0f; - float y = 0.0f; - float z = 0.0f; - // constructors - CVector() = default; + CVector(); explicit CVector(float value); CVector(float x, float y, float z); CVector(const CVector& src); -#ifdef RW CVector(const RwV3d& src); -#endif + explicit CVector(const CVector2D& xy, float z = 0.0f); // assignments @@ -39,9 +40,6 @@ class CVector void Set(float value); // assign value to all components void Set(float x, float y, float z); void operator =(const CVector& src); -#ifdef RW - void FromRwV3d(const RwV3d& src); -#endif void From2D(const CVector2D& xy, float z = 0.0f); void FromSum(const CVector& left, const CVector& right); // store sum of two vectors void FromDiff(const CVector& left, const CVector& right); // store left - right substraction result @@ -53,9 +51,10 @@ class CVector #endif // conversions -#ifdef RW - RwV3d ToRwV3d() const; -#endif + operator RwV3d&(); + operator const RwV3d&() const; + operator RwV3d*(); + operator const RwV3d*() const; CVector2D To2D() const; // get XY // properties diff --git a/shared/game/CVectorImplementation.h b/shared/game/CVectorImplementation.h index beffe2036..01dc3563d 100644 --- a/shared/game/CVectorImplementation.h +++ b/shared/game/CVectorImplementation.h @@ -9,6 +9,12 @@ // constructors +inline CVector::CVector() { + x = 0.0f; + y = 0.0f; + z = 0.0f; +} + inline CVector::CVector(float value) { Set(value); } @@ -18,14 +24,12 @@ inline CVector::CVector(float x, float y, float z) { } inline CVector::CVector(const CVector& src) { - *this = src; + Set(src.x, src.y, src.z); } -#ifdef RW inline CVector::CVector(const RwV3d& src) { - FromRwV3d(src); + Set(src.x, src.y, src.z); } -#endif inline CVector::CVector(const CVector2D& xy, float z) { Set(xy.x, xy.y, z); @@ -51,12 +55,6 @@ inline void CVector::operator =(const CVector& src) { Set(src.x, src.y, src.z); } -#ifdef RW -inline void CVector::FromRwV3d(const RwV3d& src) { - Set(src.x, src.y, src.z); -} -#endif - inline void CVector::From2D(const CVector2D& xy, float z) { Set(xy.x, xy.y, z); } @@ -89,11 +87,21 @@ inline void CVector::FromCross(const CVector& left, const CVector& right) { // conversions -#ifdef RW -inline RwV3d CVector::ToRwV3d() const { - return RwV3d(x, y, z); +inline CVector::operator RwV3d&() { + return *this; +} + +inline CVector::operator const RwV3d&() const { + return *this; +} + +inline CVector::operator RwV3d*() { + return reinterpret_cast(this); +} + +inline CVector::operator const RwV3d*() const { + return reinterpret_cast(this); } -#endif inline CVector2D CVector::To2D() const { return CVector2D(x, y); diff --git a/shared/game/CompressedVector.cpp b/shared/game/CompressedVector.cpp index d8a3d0068..45ad1c0f5 100644 --- a/shared/game/CompressedVector.cpp +++ b/shared/game/CompressedVector.cpp @@ -7,11 +7,7 @@ #pragma once #include "CompressedVector.h" #include "CompressedVector2D.h" - -#ifdef RW -#include "RenderWare.h" #include "CVector.h" -#endif CompressedVector::CompressedVector() { Set(0, 0, 0); @@ -29,16 +25,10 @@ CompressedVector::CompressedVector(CompressedVector2D const & rhs) { Set(rhs); } -#if defined(GTA3) || defined(GTAVC) || defined(GTASA) CompressedVector::CompressedVector(CVector const & rhs) { Set(rhs); } -CompressedVector::CompressedVector(RwV3d const & rhs) { - Set(rhs); -} -#endif - void CompressedVector::Set(short X, short Y, short Z) { x = X; y = Y; @@ -57,41 +47,23 @@ void CompressedVector::Set(CompressedVector2D const & rhs) { z = 0; } -#ifdef RW void CompressedVector::Set(CVector const & rhs) { x = static_cast(rhs.x * 8.0f); y = static_cast(rhs.y * 8.0f); z = static_cast(rhs.z * 8.0f); } -void CompressedVector::Set(RwV3d const & rhs) { - x = static_cast(rhs.x * 8.0f); - y = static_cast(rhs.y * 8.0f); - z = static_cast(rhs.z * 8.0f); -} - CVector CompressedVector::Uncompressed() const { return CVector(static_cast(x) / 8.0f, static_cast(y) / 8.0f, static_cast(z) / 8.0f); } -RwV3d CompressedVector::ToRwV3d() const { - RwV3d result; - result.x = static_cast(x) / 8.0f; - result.y = static_cast(y) / 8.0f; - result.z = static_cast(z) / 8.0f; - return result; -} -#endif - CompressedVector2D CompressedVector::To2D() const { return CompressedVector2D(x, y); } -#if defined(GTA3) || defined(GTAVC) || defined(GTASA) void CompressedVector::Uncompress(CVector &out) const { out = Uncompressed(); } -#endif bool CompressedVector::operator==(CompressedVector const &rhs) const { return x == rhs.x && y == rhs.y && z == rhs.z; diff --git a/shared/game/CompressedVector.h b/shared/game/CompressedVector.h index c1fc1bf03..ca413fde4 100644 --- a/shared/game/CompressedVector.h +++ b/shared/game/CompressedVector.h @@ -8,8 +8,7 @@ #include "PluginBase.h" -class CVector; -struct RwV3d; +struct CVector; class CompressedVector2D; class PLUGIN_API CompressedVector { @@ -22,30 +21,18 @@ class PLUGIN_API CompressedVector { CompressedVector(short X, short Y, short Z); CompressedVector(CompressedVector const &rhs); CompressedVector(CompressedVector2D const &rhs); - -#ifdef RW CompressedVector(CVector const &rhs); - CompressedVector(RwV3d const &rhs); -#endif void Set(short X, short Y, short Z); void Set(CompressedVector const &rhs); void Set(CompressedVector2D const &rhs); - -#ifdef RW void Set(CVector const &rhs); - void Set(RwV3d const &rhs); CVector Uncompressed() const; - RwV3d ToRwV3d() const; -#endif + void Uncompress(CVector &out) const; CompressedVector2D To2D() const; -#ifdef RW - void Uncompress(CVector &out) const; -#endif - bool operator==(CompressedVector const &rhs) const; bool operator!=(CompressedVector const &rhs) const; };