Skip to content

Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.

perf(w3d): stop sorting what has nothing to sort by

Olcay Seygan6f859c645605
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/BaseHeightMap.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/BaseHeightMap.cpp
index b32dd51df..4270d1d98 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/BaseHeightMap.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/BaseHeightMap.cpp
@@ -377,7 +377,7 @@ void BaseHeightMapRenderObjClass::adjustTerrainLOD(Int adj)
m_shroud->reset(); //need reset here since initHeightData will load new shroud.
BaseHeightMapRenderObjClass *newROBJ = NULL;
- if (TheGlobalData->m_terrainLOD==7) {
+ if (TheGlobalData->m_terrainLOD == TERRAIN_LOD_MAX) {
newROBJ = TheHeightMap;
if (newROBJ==NULL) {
newROBJ = NEW_REF( HeightMapRenderObjClass, () );
@@ -388,7 +388,9 @@ void BaseHeightMapRenderObjClass::adjustTerrainLOD(Int adj)
newROBJ = NEW_REF( FlatHeightMapRenderObjClass, () );
}
}
- if (TheGlobalData->m_terrainLOD == 5)
+ // This mode draws no terrain object at all. Upstream deleted the branch along with the mode
+ // itself; here the mode is still reachable from Options.ini, so the branch stays.
+ if (TheGlobalData->m_terrainLOD == TERRAIN_LOD_STRETCH_CLOUDS)
newROBJ = NULL;
RTS3DScene *pMyScene = (RTS3DScene *)Scene;
if (pMyScene) {
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/pointgr.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/pointgr.cpp
index fc4260697..7f8bb0139 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/pointgr.cpp
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/pointgr.cpp
@@ -927,7 +927,12 @@ void PointGroupClass::Render(RenderInfoClass &rinfo)
DX8Wrapper::Set_Texture(0,Texture);
// Enable sorting if the primitives are translucent and alpha testing is not enabled.
- const bool sort = (Shader.Get_Dst_Blend_Func() != ShaderClass::DSTBLEND_ZERO) && (Shader.Get_Alpha_Test() == ShaderClass::ALPHATEST_DISABLE) && (WW3D::Is_Sorting_Enabled());
+ // TheSuperHackers @bugfix Ground-aligned particles are left out of it. They lie flat, so
+ // sorting them against the billboards clips one against the other and costs the sort as well.
+ const bool sort = Billboard &&
+ (Shader.Get_Dst_Blend_Func() != ShaderClass::DSTBLEND_ZERO) &&
+ (Shader.Get_Alpha_Test() == ShaderClass::ALPHATEST_DISABLE) &&
+ (WW3D::Is_Sorting_Enabled());
IndexBufferClass *indexbuffer;
int verticesperprimitive;/// lorenzen fixed
@@ -1836,6 +1841,8 @@ void PointGroupClass::RenderVolumeParticle(RenderInfoClass &rinfo, unsigned int
DX8Wrapper::Set_Texture(0,Texture);
// Enable sorting if the primitives are translucent and alpha testing is not enabled.
+ // Volumetric particles keep it whether they billboard or not: their stacked layers do not
+ // face the camera square on, so the alpha blending needs the order.
const bool sort = (Shader.Get_Dst_Blend_Func() != ShaderClass::DSTBLEND_ZERO) && (Shader.Get_Alpha_Test() == ShaderClass::ALPHATEST_DISABLE) && (WW3D::Is_Sorting_Enabled());
IndexBufferClass *indexbuffer;
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/sortingrenderer.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/sortingrenderer.cpp
index 8786116d8..d5bfff458 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/sortingrenderer.cpp
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/sortingrenderer.cpp
@@ -172,6 +172,9 @@ public:
};
static DLListClass<SortingNodeStruct> sorted_list;
+// Nodes that arrive with no bounding sphere have nothing to sort by; they wait here and go into
+// the sorted list in one piece at flush time, instead of each walking it looking for a place.
+static DLListClass<SortingNodeStruct> unsorted_list;
static DLListClass<SortingNodeStruct> clean_list;
static unsigned total_sorting_vertices;
@@ -251,16 +254,22 @@ void SortingRendererClass::Insert_Triangles(
WWASSERT(vertex_buffer);
WWASSERT(state->vertex_count<=vertex_buffer->Get_Vertex_Count());
+ if (state->bounding_sphere.Radius <= 0.0f) {
+ // Nothing to sort by, so do not pay the walk down the list looking for a place.
+ state->transformed_center=Vector3(0.0f,0.0f,0.0f);
+ unsorted_list.Add_Tail(state);
+ }
+ else {
D3DXMATRIX mtx=(D3DXMATRIX&)state->sorting_state.world*(D3DXMATRIX&)state->sorting_state.view;
D3DXVECTOR3 vec=(D3DXVECTOR3&)state->bounding_sphere.Center;
D3DXVECTOR4 transformed_vec;
D3DXVec3Transform(
&transformed_vec,
&vec,
- &mtx);
+ &mtx);
state->transformed_center=Vector3(transformed_vec[0],transformed_vec[1],transformed_vec[2]);
-
+
/// @todo lorenzen sez use a bucket sort here... and stop copying so much data so many times
SortingNodeStruct* node=sorted_list.Head();
@@ -275,6 +284,7 @@ void SortingRendererClass::Insert_Triangles(
node=node->Succ();
}
if (!node) sorted_list.Add_Tail(state);
+ }
#ifdef WWDEBUG
unsigned short* indices=NULL;
@@ -631,6 +641,22 @@ void SortingRendererClass::Flush()
DX8Wrapper::Get_Transform(D3DTS_VIEW,old_view);
DX8Wrapper::Get_Transform(D3DTS_WORLD,old_world);
+ // Put the unsorted nodes in where the sorted ones cross behind the camera, in the order they
+ // arrived. Insert_Before takes care of the head, so the boundary node can be the head.
+ if (unsorted_list.Head()) {
+ SortingNodeStruct* at=sorted_list.Head();
+ while (at && at->transformed_center.Z > 0.0f)
+ at=at->Succ();
+
+ while (SortingNodeStruct* state=unsorted_list.Head()) {
+ state->Remove();
+ if (at)
+ state->Insert_Before(at);
+ else
+ sorted_list.Add_Tail(state);
+ }
+ }
+
while (SortingNodeStruct* state=sorted_list.Head()) {
state->Remove();
@@ -679,6 +705,14 @@ void SortingRendererClass::Deinit()
delete head;
}
+ //
+ // Flush the unsorted list
+ //
+ while ((head = unsorted_list.Head ()) != NULL) {
+ unsorted_list.Remove_Head ();
+ delete head;
+ }
+
//
// Flush the clean list
//