diff --git a/Core/GameEngine/CMakeLists.txt b/Core/GameEngine/CMakeLists.txt index 24f2d356c15..18ef14be1bd 100644 --- a/Core/GameEngine/CMakeLists.txt +++ b/Core/GameEngine/CMakeLists.txt @@ -13,8 +13,8 @@ set(GAMEENGINE_SRC Include/Common/AudioRequest.h Include/Common/AudioSettings.h # Include/Common/BattleHonors.h -# Include/Common/BezFwdIterator.h -# Include/Common/BezierSegment.h + Include/Common/BezFwdIterator.h + Include/Common/BezierSegment.h # Include/Common/BitFlags.h # Include/Common/BitFlagsIO.h # Include/Common/BorderColors.h @@ -566,8 +566,8 @@ set(GAMEENGINE_SRC Source/Common/Audio/GameSounds.cpp #Source/Common/Audio/simpleplayer.cpp # unused #Source/Common/Audio/urllaunch.cpp # unused -# Source/Common/Bezier/BezFwdIterator.cpp -# Source/Common/Bezier/BezierSegment.cpp + Source/Common/Bezier/BezFwdIterator.cpp + Source/Common/Bezier/BezierSegment.cpp # Source/Common/BitFlags.cpp Source/Common/CommandLine.cpp Source/Common/crc.cpp diff --git a/GeneralsMD/Code/GameEngine/Include/Common/BezFwdIterator.h b/Core/GameEngine/Include/Common/BezFwdIterator.h similarity index 100% rename from GeneralsMD/Code/GameEngine/Include/Common/BezFwdIterator.h rename to Core/GameEngine/Include/Common/BezFwdIterator.h diff --git a/GeneralsMD/Code/GameEngine/Include/Common/BezierSegment.h b/Core/GameEngine/Include/Common/BezierSegment.h similarity index 100% rename from GeneralsMD/Code/GameEngine/Include/Common/BezierSegment.h rename to Core/GameEngine/Include/Common/BezierSegment.h diff --git a/GeneralsMD/Code/GameEngine/Source/Common/Bezier/BezFwdIterator.cpp b/Core/GameEngine/Source/Common/Bezier/BezFwdIterator.cpp similarity index 100% rename from GeneralsMD/Code/GameEngine/Source/Common/Bezier/BezFwdIterator.cpp rename to Core/GameEngine/Source/Common/Bezier/BezFwdIterator.cpp diff --git a/GeneralsMD/Code/GameEngine/Source/Common/Bezier/BezierSegment.cpp b/Core/GameEngine/Source/Common/Bezier/BezierSegment.cpp similarity index 100% rename from GeneralsMD/Code/GameEngine/Source/Common/Bezier/BezierSegment.cpp rename to Core/GameEngine/Source/Common/Bezier/BezierSegment.cpp diff --git a/Generals/Code/GameEngine/CMakeLists.txt b/Generals/Code/GameEngine/CMakeLists.txt index e9373cec104..9400c1a820c 100644 --- a/Generals/Code/GameEngine/CMakeLists.txt +++ b/Generals/Code/GameEngine/CMakeLists.txt @@ -11,8 +11,8 @@ set(GAMEENGINE_SRC # Include/Common/AudioRequest.h # Include/Common/AudioSettings.h Include/Common/BattleHonors.h - Include/Common/BezFwdIterator.h - Include/Common/BezierSegment.h +# Include/Common/BezFwdIterator.h +# Include/Common/BezierSegment.h Include/Common/BitFlags.h Include/Common/BitFlagsIO.h Include/Common/BuildAssistant.h @@ -517,8 +517,8 @@ set(GAMEENGINE_SRC # Source/Common/Audio/GameSounds.cpp #Source/Common/Audio/simpleplayer.cpp # unused #Source/Common/Audio/urllaunch.cpp # unused - Source/Common/Bezier/BezFwdIterator.cpp - Source/Common/Bezier/BezierSegment.cpp +# Source/Common/Bezier/BezFwdIterator.cpp +# Source/Common/Bezier/BezierSegment.cpp Source/Common/BitFlags.cpp # Source/Common/CommandLine.cpp # Source/Common/crc.cpp diff --git a/Generals/Code/GameEngine/Include/Common/BezFwdIterator.h b/Generals/Code/GameEngine/Include/Common/BezFwdIterator.h deleted file mode 100644 index 8ef83229de6..00000000000 --- a/Generals/Code/GameEngine/Include/Common/BezFwdIterator.h +++ /dev/null @@ -1,51 +0,0 @@ -/* -** Command & Conquer Generals(tm) -** Copyright 2025 Electronic Arts Inc. -** -** This program is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program. If not, see . -*/ - -//////////////////////////////////////////////////////////////////////////////// -// // -// (c) 2001-2003 Electronic Arts Inc. // -// // -//////////////////////////////////////////////////////////////////////////////// - -#pragma once - -#include "Common/BezierSegment.h" - -class BezFwdIterator -{ - protected: - Int mStep; - Int mStepsDesired; - - BezierSegment mBezSeg; - Coord3D mCurrPoint; - - Coord3D mDq; // First Derivative - Coord3D mDDq; // Second Derivative - Coord3D mDDDq; // Third Derivative - - public: - BezFwdIterator(); - BezFwdIterator(Int stepsDesired, const BezierSegment *bezSeg); - - void start(); - Bool done(); - const Coord3D& getCurrent() const; - - void next(); -}; diff --git a/Generals/Code/GameEngine/Include/Common/BezierSegment.h b/Generals/Code/GameEngine/Include/Common/BezierSegment.h deleted file mode 100644 index b16df7d8cee..00000000000 --- a/Generals/Code/GameEngine/Include/Common/BezierSegment.h +++ /dev/null @@ -1,69 +0,0 @@ -/* -** Command & Conquer Generals(tm) -** Copyright 2025 Electronic Arts Inc. -** -** This program is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program. If not, see . -*/ - -//////////////////////////////////////////////////////////////////////////////// -// // -// (c) 2001-2003 Electronic Arts Inc. // -// // -//////////////////////////////////////////////////////////////////////////////// - -// BezierSegment.h //////////////////////////////////////////////////////////////////////////////// -// John K McDonald, Jr. -// September 2002 -// DO NOT DISTRIBUTE - -#pragma once - -#include -#include "Common/STLTypedefs.h" - -#define USUAL_TOLERANCE 1.0f - -class BezierSegment -{ - protected: - static const D3DXMATRIX s_bezBasisMatrix; - Coord3D m_controlPoints[4]; - - public: // Constructors - BezierSegment(); - BezierSegment(Real x0, Real y0, Real z0, - Real x1, Real y1, Real z1, - Real x2, Real y2, Real z2, - Real x3, Real y3, Real z3); - - BezierSegment(Real cp[12]); - - - BezierSegment(const Coord3D& cp0, - const Coord3D& cp1, - const Coord3D& cp2, - const Coord3D& cp3); - - BezierSegment(Coord3D cp[4]); - - public: - void evaluateBezSegmentAtT(Real tValue, Coord3D *outResult) const; - void getSegmentPoints(Int numSegments, VecCoord3D *outResult) const; - Real getApproximateLength(Real withinTolerance = USUAL_TOLERANCE) const; - - void splitSegmentAtT(Real tValue, BezierSegment &outSeg1, BezierSegment &outSeg2) const; - - public: // He get's friendly access. - friend class BezFwdIterator; -}; diff --git a/Generals/Code/GameEngine/Source/Common/Bezier/BezFwdIterator.cpp b/Generals/Code/GameEngine/Source/Common/Bezier/BezFwdIterator.cpp deleted file mode 100644 index 3df2a515fc6..00000000000 --- a/Generals/Code/GameEngine/Source/Common/Bezier/BezFwdIterator.cpp +++ /dev/null @@ -1,120 +0,0 @@ -/* -** Command & Conquer Generals(tm) -** Copyright 2025 Electronic Arts Inc. -** -** This program is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program. If not, see . -*/ - -//////////////////////////////////////////////////////////////////////////////// -// // -// (c) 2001-2003 Electronic Arts Inc. // -// // -//////////////////////////////////////////////////////////////////////////////// - -#include "PreRTS.h" -#include "Common/BezFwdIterator.h" - -//------------------------------------------------------------------------------------------------- -BezFwdIterator::BezFwdIterator(): mStep(0), mStepsDesired(0) -{ - mCurrPoint.zero(); - mDDDq.zero(); - mDDq.zero(); - mDq.zero(); -} - -//------------------------------------------------------------------------------------------------- -BezFwdIterator::BezFwdIterator(Int stepsDesired, const BezierSegment *bezSeg) -{ - mCurrPoint.zero(); - mDDDq.zero(); - mDDq.zero(); - mDq.zero(); - mStepsDesired = stepsDesired; - mBezSeg = (*bezSeg); -} - -//------------------------------------------------------------------------------------------------- -void BezFwdIterator::start() -{ - mStep = 0; - - if (mStepsDesired <= 1) - return; - - float d = 1.0f / (mStepsDesired - 1); - float d2 = d * d; - float d3 = d * d2; - - D3DXVECTOR4 px(mBezSeg.m_controlPoints[0].x, mBezSeg.m_controlPoints[1].x, mBezSeg.m_controlPoints[2].x, mBezSeg.m_controlPoints[3].x); - D3DXVECTOR4 py(mBezSeg.m_controlPoints[0].y, mBezSeg.m_controlPoints[1].y, mBezSeg.m_controlPoints[2].y, mBezSeg.m_controlPoints[3].y); - D3DXVECTOR4 pz(mBezSeg.m_controlPoints[0].z, mBezSeg.m_controlPoints[1].z, mBezSeg.m_controlPoints[2].z, mBezSeg.m_controlPoints[3].z); - - D3DXVECTOR4 cVec[3]; - D3DXVec4Transform(&cVec[0], &px, &BezierSegment::s_bezBasisMatrix); - D3DXVec4Transform(&cVec[1], &py, &BezierSegment::s_bezBasisMatrix); - D3DXVec4Transform(&cVec[2], &pz, &BezierSegment::s_bezBasisMatrix); - - mCurrPoint = mBezSeg.m_controlPoints[0]; - - int i = 3; - while (i--) { - float a = cVec[i].x; - float b = cVec[i].y; - float c = cVec[i].z; - - float *pD, *pDD, *pDDD; - - if (i == 2) { - pD = &mDq.z; - pDD = &mDDq.z; - pDDD = &mDDDq.z; - } else if (i == 1) { - pD = &mDq.y; - pDD = &mDDq.y; - pDDD = &mDDDq.y; - } else if (i == 0) { - pD = &mDq.x; - pDD = &mDDq.x; - pDDD = &mDDDq.x; - } - - (*pD) = a * d3 + b * d2 + c * d; - (*pDD) = 6 * a * d3 + 2 * b * d2; - (*pDDD) = 6 * a * d3; - } -} - -//------------------------------------------------------------------------------------------------- -Bool BezFwdIterator::done() -{ - return (mStep >= mStepsDesired); -} - -//------------------------------------------------------------------------------------------------- -const Coord3D& BezFwdIterator::getCurrent() const -{ - return mCurrPoint; -} - -//------------------------------------------------------------------------------------------------- -void BezFwdIterator::next() -{ - mCurrPoint.add(mDq); - mDq.add(mDDq); - mDDq.add(mDDDq); - - ++mStep; -} - diff --git a/Generals/Code/GameEngine/Source/Common/Bezier/BezierSegment.cpp b/Generals/Code/GameEngine/Source/Common/Bezier/BezierSegment.cpp deleted file mode 100644 index 639b6d1bf2b..00000000000 --- a/Generals/Code/GameEngine/Source/Common/Bezier/BezierSegment.cpp +++ /dev/null @@ -1,246 +0,0 @@ -/* -** Command & Conquer Generals(tm) -** Copyright 2025 Electronic Arts Inc. -** -** This program is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program. If not, see . -*/ - -//////////////////////////////////////////////////////////////////////////////// -// // -// (c) 2001-2003 Electronic Arts Inc. // -// // -//////////////////////////////////////////////////////////////////////////////// - - -#include "PreRTS.h" -#include "Common/BezierSegment.h" -#include "Common/BezFwdIterator.h" - -#include - -//------------------------------------------------------------------------------------------------- -BezierSegment::BezierSegment() -{ - for(int i=0; i < 4; i++) - m_controlPoints[i].zero(); -} - -//------------------------------------------------------------------------------------------------- -BezierSegment::BezierSegment(Real x0, Real y0, Real z0, - Real x1, Real y1, Real z1, - Real x2, Real y2, Real z2, - Real x3, Real y3, Real z3) -{ - m_controlPoints[0].x = x0; - m_controlPoints[0].y = y0; - m_controlPoints[0].z = z0; - - m_controlPoints[1].x = x1; - m_controlPoints[1].y = y1; - m_controlPoints[1].z = z1; - - m_controlPoints[2].x = x2; - m_controlPoints[2].y = y2; - m_controlPoints[2].z = z2; - - m_controlPoints[3].x = x3; - m_controlPoints[3].y = y3; - m_controlPoints[3].z = z3; -} - -BezierSegment::BezierSegment(Real cp[12]) -{ - m_controlPoints[0].x = cp[0]; - m_controlPoints[0].y = cp[1]; - m_controlPoints[0].z = cp[2]; - - m_controlPoints[1].x = cp[3]; - m_controlPoints[1].y = cp[4]; - m_controlPoints[1].z = cp[5]; - - m_controlPoints[2].x = cp[6]; - m_controlPoints[2].y = cp[7]; - m_controlPoints[2].z = cp[8]; - - m_controlPoints[3].x = cp[9]; - m_controlPoints[3].y = cp[10]; - m_controlPoints[3].z = cp[11]; -} - -BezierSegment::BezierSegment(const Coord3D& cp0, const Coord3D& cp1, const Coord3D& cp2, const Coord3D& cp3) -{ - m_controlPoints[0] = cp0; - m_controlPoints[1] = cp1; - m_controlPoints[2] = cp2; - m_controlPoints[3] = cp3; -} - -BezierSegment::BezierSegment(Coord3D cp[4]) -{ - m_controlPoints[0] = cp[0]; - m_controlPoints[1] = cp[1]; - m_controlPoints[2] = cp[2]; - m_controlPoints[3] = cp[3]; -} - - -//------------------------------------------------------------------------------------------------- -void BezierSegment::evaluateBezSegmentAtT(Real tValue, Coord3D *outResult) const - -{ - if (!outResult) - return; - - D3DXVECTOR4 tVec(tValue * tValue * tValue, tValue * tValue, tValue, 1); - - D3DXVECTOR4 xCoords(m_controlPoints[0].x, m_controlPoints[1].x, m_controlPoints[2].x, m_controlPoints[3].x); - D3DXVECTOR4 yCoords(m_controlPoints[0].y, m_controlPoints[1].y, m_controlPoints[2].y, m_controlPoints[3].y); - D3DXVECTOR4 zCoords(m_controlPoints[0].z, m_controlPoints[1].z, m_controlPoints[2].z, m_controlPoints[3].z); - - D3DXVECTOR4 tResult; - D3DXVec4Transform(&tResult, &tVec, &BezierSegment::s_bezBasisMatrix); - - outResult->x = D3DXVec4Dot(&xCoords, &tResult); - outResult->y = D3DXVec4Dot(&yCoords, &tResult); - outResult->z = D3DXVec4Dot(&zCoords, &tResult); -} - -//------------------------------------------------------------------------------------------------- -void BezierSegment::getSegmentPoints(Int numSegments, VecCoord3D *outResult) const -{ - if (!outResult) { - return; - } - - outResult->clear(); - outResult->resize(numSegments); - - BezFwdIterator iter(numSegments, this); - iter.start(); - Int i = 0; - while (!iter.done()) { - (*outResult)[i] = iter.getCurrent(); - ++i; - iter.next(); - } -} - -//------------------------------------------------------------------------------------------------- -// This function isn't terribly fast. There are alternatives, and if this is too slow, we can -// take a look at the other approximations. -// There is no known close-form solution to this problem. -Real BezierSegment::getApproximateLength(Real withinTolerance) const -{ - /* - How this works: - We can determine the approximate length of a bezier segment by - L0 = |(P0,P1)| + |(P1,P2)| + |(P2,P3)| - L1 = |(P0,P3)| - - The length of the segment is approximately 1/2 L0 + 1/2 L1 - - P1__P2 - / \ - P0----P3 - - The error in this is L1 - L0. If the error is too much, then we subdivide the curve and - try again. - */ - - Coord3D p0p1 = { m_controlPoints[1].x - m_controlPoints[0].x, - m_controlPoints[1].y - m_controlPoints[0].y, - m_controlPoints[1].z - m_controlPoints[0].z, }; - - Coord3D p1p2 = { m_controlPoints[2].x - m_controlPoints[1].x, - m_controlPoints[2].y - m_controlPoints[1].y, - m_controlPoints[2].z - m_controlPoints[1].z, }; - - Coord3D p2p3 = { m_controlPoints[3].x - m_controlPoints[2].x, - m_controlPoints[3].y - m_controlPoints[2].y, - m_controlPoints[3].z - m_controlPoints[2].z, }; - - Coord3D p0p3 = { m_controlPoints[3].x - m_controlPoints[0].x, - m_controlPoints[3].y - m_controlPoints[0].y, - m_controlPoints[3].z - m_controlPoints[0].z, }; - - Real length0 = p0p3.length(); - Real length1 = p0p1.length() + p1p2.length() + p2p3.length(); - - if ((length1 - length0) > withinTolerance) { - BezierSegment seg1, seg2; - splitSegmentAtT(0.5f, seg1, seg2); - return (seg1.getApproximateLength(withinTolerance) + seg2.getApproximateLength(withinTolerance)); - } - - return (INT_TO_REAL(length0 + length1) / 2.0f); -} - -//------------------------------------------------------------------------------------------------- -void BezierSegment::splitSegmentAtT(Real tValue, BezierSegment &outSeg1, BezierSegment &outSeg2) const -{ - // I think there are faster ways to do this. Could someone clue me in? - - Coord3D p0p1 = { m_controlPoints[1].x - m_controlPoints[0].x, - m_controlPoints[1].y - m_controlPoints[0].y, - m_controlPoints[1].z - m_controlPoints[0].z, }; - - Coord3D p1p2 = { m_controlPoints[2].x - m_controlPoints[1].x, - m_controlPoints[2].y - m_controlPoints[1].y, - m_controlPoints[2].z - m_controlPoints[1].z, }; - - Coord3D p2p3 = { m_controlPoints[3].x - m_controlPoints[2].x, - m_controlPoints[3].y - m_controlPoints[2].y, - m_controlPoints[3].z - m_controlPoints[2].z, }; - - p0p1.scale(tValue); - p1p2.scale(tValue); - p2p3.scale(tValue); - - p0p1.add(m_controlPoints[0]); - p1p2.add(m_controlPoints[1]); - p2p3.add(m_controlPoints[2]); - - Coord3D triLeft = { p1p2.x - p0p1.x, - p1p2.y - p0p1.y, - p1p2.z - p0p1.z, }; - - Coord3D triRight = { p2p3.x - p1p2.x, - p2p3.y - p1p2.y, - p2p3.z - p1p2.z, }; - - triLeft.scale(tValue); - triRight.scale(tValue); - - triLeft.add(p0p1); - triRight.add(p1p2); - - outSeg1.m_controlPoints[0] = m_controlPoints[0]; - outSeg1.m_controlPoints[1] = p0p1; - outSeg1.m_controlPoints[2] = triLeft; - evaluateBezSegmentAtT(tValue, &outSeg1.m_controlPoints[3]); - - outSeg2.m_controlPoints[0] = outSeg1.m_controlPoints[3]; - outSeg2.m_controlPoints[1] = triRight; - outSeg2.m_controlPoints[2] = p2p3; - outSeg2.m_controlPoints[3] = m_controlPoints[3]; -} - -//------------------------------------------------------------------------------------------------- -// The Basis Matrix for a bezier segment -const D3DXMATRIX BezierSegment::s_bezBasisMatrix( - -1.0f, 3.0f, -3.0f, 1.0f, - 3.0f, -6.0f, 3.0f, 0.0f, - -3.0f, 3.0f, 0.0f, 0.0f, - 1.0f, 0.0f, 0.0f, 0.0f -); diff --git a/GeneralsMD/Code/GameEngine/CMakeLists.txt b/GeneralsMD/Code/GameEngine/CMakeLists.txt index 694f7d267d8..044bfe6c17c 100644 --- a/GeneralsMD/Code/GameEngine/CMakeLists.txt +++ b/GeneralsMD/Code/GameEngine/CMakeLists.txt @@ -12,8 +12,8 @@ set(GAMEENGINE_SRC # Include/Common/AudioRequest.h # Include/Common/AudioSettings.h Include/Common/BattleHonors.h - Include/Common/BezFwdIterator.h - Include/Common/BezierSegment.h +# Include/Common/BezFwdIterator.h +# Include/Common/BezierSegment.h Include/Common/BitFlags.h Include/Common/BitFlagsIO.h Include/Common/BorderColors.h @@ -556,8 +556,8 @@ set(GAMEENGINE_SRC # Source/Common/Audio/GameSounds.cpp #Source/Common/Audio/simpleplayer.cpp # unused #Source/Common/Audio/urllaunch.cpp # unused - Source/Common/Bezier/BezFwdIterator.cpp - Source/Common/Bezier/BezierSegment.cpp +# Source/Common/Bezier/BezFwdIterator.cpp +# Source/Common/Bezier/BezierSegment.cpp Source/Common/BitFlags.cpp # Source/Common/CommandLine.cpp # Source/Common/crc.cpp diff --git a/scripts/cpp/unify_move_files.py b/scripts/cpp/unify_move_files.py index 1bfb3539700..29d16c2b2bb 100644 --- a/scripts/cpp/unify_move_files.py +++ b/scripts/cpp/unify_move_files.py @@ -643,6 +643,11 @@ def main(): #unify_file(Game.ZEROHOUR, "GameEngine/Include/Common/CommandLine.h", Game.CORE, "GameEngine/Include/Common/CommandLine.h") #unify_file(Game.ZEROHOUR, "GameEngine/Source/Common/CommandLine.cpp", Game.CORE, "GameEngine/Source/Common/CommandLine.cpp") + #unify_file(Game.ZEROHOUR, "GameEngine/Include/Common/BezFwdIterator.h", Game.CORE, "GameEngine/Include/Common/BezFwdIterator.h") + #unify_file(Game.ZEROHOUR, "GameEngine/Include/Common/BezierSegment.h", Game.CORE, "GameEngine/Include/Common/BezierSegment.h") + #unify_file(Game.ZEROHOUR, "GameEngine/Source/Common/Bezier/BezFwdIterator.cpp", Game.CORE, "GameEngine/Source/Common/Bezier/BezFwdIterator.cpp") + #unify_file(Game.ZEROHOUR, "GameEngine/Source/Common/Bezier/BezierSegment.cpp", Game.CORE, "GameEngine/Source/Common/Bezier/BezierSegment.cpp") + return