- BORLAND/: Borland C++ 4.52 (chosen over 4.5 by byte-match: CODE/RP/CW32.LIB
is identical to 4.52's install lib). BCC32/TLINK32/TLIB/MAKE run natively on
Win11; CODE/BT/OPT.MAK is the shipped BTL4OPT.EXE's exact flag recipe
(extender = Borland PowerPack DPMI32, not Phar Lap TNT).
- restoration/source410/: the literal 1995-form reconstruction of the missing
BT game source (never mixed into CODE/). Round 1-3 state:
* 6 of 10 surviving original TUs COMPILE CLEAN under the period toolchain
(BTMSSN, BTCNSL, BTSCNRL, BTTEAM, BTL4MODE, BTL4ARND) - first builds
since 1996.
* BT_L4/BTL4APP.CPP pilot reconstruction: 12/12 functions, Fail() lands on
its binary-recorded line 400 exactly.
* BT/BTCNSL.HPP: console wire IDs recovered from the binary's ctors
(Killed=9, Damaged=10, ScoreUpdate=13, DeathWithoutHonor=15 [T1];
TeamScore=12 flagged [T4]).
* MUNGA/: 8 engine-header backfills back-dated from the BT412 WinTesla tree
(VDATA numbering decomp-verified; AUDREND's OpenAL-era virtual removed -
the period compiler is the drift detector).
* Tooling: backdate.py (WinTesla->1995 header transform), compile410.sh
(per-TU verification sweep under authentic OPT.MAK flags).
* README: corrected roadmap - MECH.HPP is the capstone grown with the mech
TU reconstructions; BTREG.CPP green = the header-family milestone.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
291 lines
6.3 KiB
C++
291 lines
6.3 KiB
C++
#if !defined(VECTOR2D_HPP)
|
|
# define VECTOR2D_HPP
|
|
|
|
# if !defined(SCALAR_HPP)
|
|
# include <scalar.hpp>
|
|
# endif
|
|
|
|
template <class T> class Vector2DOf
|
|
{
|
|
public:
|
|
#if defined(USE_SIGNATURE)
|
|
friend int Is_Signature_Bad(const volatile Vector2DOf<T> *p);
|
|
#endif
|
|
|
|
// static const Vector2DOf<T>
|
|
// identity;
|
|
|
|
T x, y;
|
|
|
|
Vector2DOf() {}
|
|
Vector2DOf(T x, T y) : x(x), y(y) {}
|
|
|
|
friend Logical Small_Enough(const Vector2DOf<T> &v, Scalar e);
|
|
Logical operator!() const { return Small_Enough(*this,SMALL); }
|
|
|
|
friend Logical Close_Enough(const Vector2DOf<T> &v1, const Vector2DOf<T> &v2, Scalar e);
|
|
Logical operator==(const Vector2DOf<T>& v) const { return Close_Enough(*this,v,SMALL); }
|
|
Logical operator!=(const Vector2DOf<T>& v) const { return !Close_Enough(*this,v,SMALL); }
|
|
|
|
const T& operator[](size_t index) const
|
|
{
|
|
Check(this);
|
|
Warn(index>Y_Axis);
|
|
return (&x)[index];
|
|
}
|
|
T& operator[](size_t index)
|
|
{
|
|
Check(this);
|
|
Warn(index>Y_Axis);
|
|
return (&x)[index];
|
|
}
|
|
|
|
//
|
|
//-----------------------------------------------------------------------
|
|
// The following operators all assume that this points to the destination
|
|
// of the operation results
|
|
//-----------------------------------------------------------------------
|
|
//
|
|
Vector2DOf<T>& Negate(const Vector2DOf<T> &v);
|
|
|
|
Vector2DOf<T>& Add(const Vector2DOf<T>& v1, const Vector2DOf<T>& v2);
|
|
Vector2DOf<T>& operator+=(const Vector2DOf<T>& v) { return Add(*this,v); }
|
|
|
|
Vector2DOf<T>& Subtract(const Vector2DOf<T>& v1, const Vector2DOf<T>& v2);
|
|
Vector2DOf<T>& operator-=(const Vector2DOf<T>& v) { return Subtract(*this,v); }
|
|
|
|
T operator*(const Vector2DOf<T>& v) const
|
|
{
|
|
Check(this);
|
|
Check(&v);
|
|
return x*v.x + y*v.y;
|
|
}
|
|
|
|
Vector2DOf<T>& Multiply(const Vector2DOf<T>& v, T Scale);
|
|
Vector2DOf<T>& operator*=(T v) { return Multiply(*this,v); }
|
|
|
|
Vector2DOf<T>& Multiply(const Vector2DOf<T>& v1, const Vector2DOf<T>& v2);
|
|
Vector2DOf<T>& operator*=(const Vector2DOf<T> &v) { return Multiply(*this,v); }
|
|
|
|
Vector2DOf<T>& Divide(const Vector2DOf<T>& v, T scale);
|
|
Vector2DOf<T>& operator/=(T v) { return Divide(*this,v); }
|
|
|
|
Vector2DOf<T>& Divide(const Vector2DOf<T>& v1, const Vector2DOf<T>& v2);
|
|
Vector2DOf<T>& operator/=(const Vector2DOf<T> &v) { return Divide(*this,v); }
|
|
|
|
T LengthSquared() const
|
|
{
|
|
Check(this);
|
|
return operator*(*this);
|
|
}
|
|
T Length() const
|
|
{
|
|
Check(this);
|
|
return (T)Sqrt(LengthSquared());
|
|
}
|
|
|
|
Vector2DOf<T>& Normalize(const Vector2DOf<T> &v);
|
|
|
|
#if 0
|
|
Vector2DOf<T>& Combine(const Vector2DOf<T>& v1, Scalar t1, const Vector2DOf<T>& v2, Scalar t2);
|
|
|
|
Vector2DOf<T>& Lerp(const Vector2DOf<T>& v1, const Vector2DOf<T>& v2, Scalar t)
|
|
{
|
|
return Combine(v1,1.0f-t,v2,t);
|
|
}
|
|
#endif
|
|
|
|
friend ostream& operator<<(ostream& stream, const Vector2DOf<T>& v);
|
|
Logical TestInstance() const;
|
|
};
|
|
|
|
#if defined(USE_SIGNATURE)
|
|
template <class T> int Is_Signature_Bad(const volatile Vector2DOf<T> *)
|
|
{
|
|
return False;
|
|
}
|
|
#endif
|
|
|
|
// template <class T> const Vector2DOf<T>
|
|
// Vector2DOf<T>::identity(0.0f,0.0f);
|
|
|
|
template <class T> inline Logical
|
|
Small_Enough(const Vector2DOf<T> &v,Scalar e)
|
|
{
|
|
Check(&v);
|
|
return Small_Enough(v.x,e) && Small_Enough(v.y,e);
|
|
}
|
|
|
|
//REMOVED: RB 1/15/07
|
|
//template <class T> Logical
|
|
// Close_Enough(
|
|
// const Vector2DOf<T> &v1,
|
|
// const Vector2DOf<T> &v2,
|
|
// Scalar e
|
|
// )
|
|
//{
|
|
// Check(&v1);
|
|
// Check(&v2);
|
|
// return Close_Enough(v1.x,v2.x,e) && Close_Enough(v1.y,v2.y,e);
|
|
//}
|
|
|
|
inline Logical Close_Enough(const Vector2DOf<int> &v1, const Vector2DOf<int> &v2, Scalar e)
|
|
{
|
|
Check(&v1);
|
|
Check(&v2);
|
|
return Close_Enough(v1.x, v2.x,e) && Close_Enough(v1.y, v2.y,e);
|
|
}
|
|
|
|
inline Logical Close_Enough(const Vector2DOf<float> &v1, const Vector2DOf<float> &v2, Scalar e)
|
|
{
|
|
Check(&v1);
|
|
Check(&v2);
|
|
return Close_Enough(v1.x, v2.x,e) && Close_Enough(v1.y, v2.y,e);
|
|
}
|
|
|
|
template <class T> inline Vector2DOf<T>&
|
|
Vector2DOf<T>::Negate(const Vector2DOf<T> &v)
|
|
{
|
|
Check(this);
|
|
Check(&v);
|
|
x = -v.x;
|
|
y = -v.y;
|
|
return *this;
|
|
}
|
|
|
|
template <class T> inline Vector2DOf<T>&
|
|
Vector2DOf<T>::Add(
|
|
const Vector2DOf<T>& v1,
|
|
const Vector2DOf<T>& v2
|
|
)
|
|
{
|
|
Check(this);
|
|
Check(&v1);
|
|
Check(&v2);
|
|
x = v1.x + v2.x;
|
|
y = v1.y + v2.y;
|
|
return *this;
|
|
}
|
|
|
|
template <class T> inline Vector2DOf<T>&
|
|
Vector2DOf<T>::Subtract(
|
|
const Vector2DOf<T>& v1,
|
|
const Vector2DOf<T>& v2
|
|
)
|
|
{
|
|
Check(this);
|
|
Check(&v1);
|
|
Check(&v2);
|
|
x = v1.x - v2.x;
|
|
y = v1.y - v2.y;
|
|
return *this;
|
|
}
|
|
|
|
template <class T> inline Vector2DOf<T>&
|
|
Vector2DOf<T>::Multiply(
|
|
const Vector2DOf<T>& v,
|
|
T scale
|
|
)
|
|
{
|
|
Check(this);
|
|
Check(&v);
|
|
x = v.x * scale;
|
|
y = v.y * scale;
|
|
return *this;
|
|
}
|
|
|
|
template <class T> inline Vector2DOf<T>&
|
|
Vector2DOf<T>::Multiply(
|
|
const Vector2DOf<T>& v1,
|
|
const Vector2DOf<T>& v2
|
|
)
|
|
{
|
|
Check(this);
|
|
Check(&v1);
|
|
Check(&v2);
|
|
x = v1.x * v2.x;
|
|
y = v1.y * v2.y;
|
|
return *this;
|
|
}
|
|
|
|
template <class T> inline Vector2DOf<T>&
|
|
Vector2DOf<T>::Divide(
|
|
const Vector2DOf<T>& v,
|
|
T scale
|
|
)
|
|
{
|
|
Check(this);
|
|
Check(&v);
|
|
Verify(!Small_Enough(scale));
|
|
x = v.x / scale;
|
|
y = v.y / scale;
|
|
return *this;
|
|
}
|
|
|
|
template <class T> inline Vector2DOf<T>&
|
|
Vector2DOf<T>::Divide(
|
|
const Vector2DOf<T>& v1,
|
|
const Vector2DOf<T>& v2
|
|
)
|
|
{
|
|
Check(this);
|
|
Check(&v1);
|
|
Check(&v2);
|
|
Verify(!Small_Enough(v2.x));
|
|
Verify(!Small_Enough(v2.y));
|
|
x = v1.x / v2.x;
|
|
y = v1.y / v2.y;
|
|
return *this;
|
|
}
|
|
|
|
template <class T> inline Vector2DOf<T>& Vector2DOf<T>::Normalize(const Vector2DOf<T> &v)
|
|
{
|
|
Check_Pointer(this);
|
|
Check(&v);
|
|
|
|
T len = v.Length();
|
|
Verify(!Small_Enough(len));
|
|
|
|
x = v.x/len;
|
|
y = v.y/len;
|
|
return *this;
|
|
}
|
|
|
|
//template <class T> ostream& operator<<(ostream& stream, const Vector2DOf<T>& v)
|
|
//{
|
|
// Check(&v);
|
|
// return stream << '<' << v.x << ',' << v.y << '>';
|
|
//}
|
|
|
|
template <class T> inline Logical Vector2DOf<T>::TestInstance() const
|
|
{
|
|
return True;
|
|
}
|
|
|
|
inline ostream& operator<<(ostream& stream, const Vector2DOf<int>& v)
|
|
{
|
|
Check(&v);
|
|
return stream << '<' << v.x << ',' << v.y << '>';
|
|
}
|
|
|
|
#if 0
|
|
template <class T> Vector2DOf<T>&
|
|
Combine(
|
|
const Vector2DOf<T>& v1,
|
|
Scalar t1,
|
|
const Vector2DOf<T>& v2,
|
|
Scalar t2
|
|
)
|
|
{
|
|
Check(this);
|
|
Check(&v1);
|
|
Check(&v2);
|
|
|
|
x = v1.x*t1 + v2.x*t2;
|
|
y = v1.y*t1 + v2.y*t2;
|
|
return *this;
|
|
}
|
|
#endif
|
|
|
|
#endif
|