Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 43 additions & 54 deletions Core/Libraries/Source/WWVegas/WW3D2/sortingrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include "statistics.h"
#include <wwprofile.h>
#include <algorithm>
#include <list>


bool SortingRendererClass::_EnableTriangleDraw=true;
Expand Down Expand Up @@ -150,7 +151,7 @@ void Sort(TempIndexStruct *begin, TempIndexStruct *end)

// ----------------------------------------------------------------------------

class SortingNodeStruct : public DLNodeClass<SortingNodeStruct>
class SortingNodeStruct
{
W3DMPO_CODE(SortingNodeStruct)

Expand All @@ -166,20 +167,19 @@ class SortingNodeStruct : public DLNodeClass<SortingNodeStruct>
unsigned short vertex_count; // Number of vertices used in vb
};

static DLListClass<SortingNodeStruct> sorted_list;
static DLListClass<SortingNodeStruct> clean_list;
typedef std::list<SortingNodeStruct*> SortingNodeStructList;
static SortingNodeStructList sorted_list;
static SortingNodeStructList clean_list;
static unsigned total_sorting_vertices;

static SortingNodeStruct* Get_Sorting_Struct()
{

SortingNodeStruct* state=clean_list.Head();
if (state) {
state->Remove();
if (!clean_list.empty()) {
SortingNodeStruct* state = clean_list.front();
clean_list.pop_front();
return state;
}
state=W3DNEW SortingNodeStruct();
return state;
return W3DNEW SortingNodeStruct();
}

// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -242,10 +242,6 @@ void SortingRendererClass::Insert_Triangles(
state->min_vertex_index=min_vertex_index;
state->vertex_count=vertex_count;

SortingVertexBufferClass* vertex_buffer=static_cast<SortingVertexBufferClass*>(state->sorting_state.vertex_buffers[0]);
WWASSERT(vertex_buffer);
WWASSERT(state->vertex_count<=vertex_buffer->Get_Vertex_Count());

D3DXMATRIX mtx=(D3DXMATRIX&)state->sorting_state.world*(D3DXMATRIX&)state->sorting_state.view;
D3DXVECTOR3 vec=(D3DXVECTOR3&)state->bounding_sphere.Center;
D3DXVECTOR4 transformed_vec;
Expand All @@ -255,23 +251,13 @@ void SortingRendererClass::Insert_Triangles(
&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();
while (node) {
if (state->transformed_center.Z>node->transformed_center.Z) {
if (sorted_list.Head()==sorted_list.Tail())
sorted_list.Add_Head(state);
else
state->Insert_Before(node);
break;
}
node=node->Succ();
}
if (!node) sorted_list.Add_Tail(state);
Insert_To_Sorted_List(state);

#ifdef WWDEBUG
SortingVertexBufferClass* vertex_buffer=static_cast<SortingVertexBufferClass*>(state->sorting_state.vertex_buffers[0]);
WWASSERT(vertex_buffer);
WWASSERT(state->vertex_count<=vertex_buffer->Get_Vertex_Count());

unsigned short* indices=nullptr;
SortingIndexBufferClass* index_buffer=static_cast<SortingIndexBufferClass*>(state->sorting_state.index_buffer);
WWASSERT(index_buffer);
Expand Down Expand Up @@ -335,6 +321,23 @@ static SortingNodeStruct* overlapping_nodes[MAX_OVERLAPPING_NODES];

// ----------------------------------------------------------------------------

void SortingRendererClass::Insert_To_Sorted_List(SortingNodeStruct *state)
{
/// @todo lorenzen sez use a bucket sort here... and stop copying so much data so many times

for (SortingNodeStructList::iterator node = sorted_list.begin(); node != sorted_list.end(); ++node)
{
if (state->transformed_center.Z > (*node)->transformed_center.Z) {
sorted_list.insert(node, state);
return;
}
}

sorted_list.push_back(state);
}

// ----------------------------------------------------------------------------

void SortingRendererClass::Insert_To_Sorting_Pool(SortingNodeStruct* state)
{
if (overlapping_node_count>=MAX_OVERLAPPING_NODES) {
Expand Down Expand Up @@ -577,7 +580,7 @@ void SortingRendererClass::Flush_Sorting_Pool()
for (unsigned node_id=0;node_id<overlapping_node_count;++node_id) {
SortingNodeStruct* state=overlapping_nodes[node_id];
Release_Refs(state);
clean_list.Add_Head(state);
clean_list.push_front(state);
}
overlapping_node_count=0;
overlapping_polygon_count=0;
Expand All @@ -597,8 +600,9 @@ void SortingRendererClass::Flush()
DX8Wrapper::Get_Transform(D3DTS_VIEW,old_view);
DX8Wrapper::Get_Transform(D3DTS_WORLD,old_world);

while (SortingNodeStruct* state=sorted_list.Head()) {
state->Remove();
while (!sorted_list.empty()) {
SortingNodeStruct* state = sorted_list.front();
sorted_list.pop_front();

if ((state->sorting_state.index_buffer_type==BUFFER_TYPE_SORTING || state->sorting_state.index_buffer_type==BUFFER_TYPE_DYNAMIC_SORTING) &&
(state->sorting_state.vertex_buffer_types[0]==BUFFER_TYPE_SORTING || state->sorting_state.vertex_buffer_types[0]==BUFFER_TYPE_DYNAMIC_SORTING)) {
Expand All @@ -609,7 +613,7 @@ void SortingRendererClass::Flush()
DX8Wrapper::Draw_Triangles(state->start_index,state->polygon_count,state->min_vertex_index,state->vertex_count);
DX8Wrapper::Release_Render_State();
Release_Refs(state);
clean_list.Add_Head(state);
clean_list.push_front(state);
}
}

Expand All @@ -635,22 +639,20 @@ void SortingRendererClass::Flush()

void SortingRendererClass::Deinit()
{
SortingNodeStruct *head = nullptr;

//
// Flush the sorted list
//
while ((head = sorted_list.Head ()) != nullptr) {
sorted_list.Remove_Head ();
delete head;
while (!sorted_list.empty()) {
delete sorted_list.front();
sorted_list.pop_front();
}

//
// Flush the clean list
//
while ((head = clean_list.Head ()) != nullptr) {
clean_list.Remove_Head ();
delete head;
while (!clean_list.empty()) {
delete clean_list.front();
clean_list.pop_front();
}

delete[] temp_index_array;
Expand Down Expand Up @@ -715,18 +717,5 @@ void SortingRendererClass::Insert_VolumeParticle(

//THE TRANSFORMED CENTER[2] IS THE ZBUFFER DEPTH

/// @todo lorenzen sez use a bucket sort here... and stop copying so much data so many times

SortingNodeStruct* node=sorted_list.Head();
while (node) {
if (state->transformed_center.Z>node->transformed_center.Z) {
if (sorted_list.Head()==sorted_list.Tail())
sorted_list.Add_Head(state);
else
state->Insert_Before(node);
break;
Comment thread
xezon marked this conversation as resolved.
}
node=node->Succ();
}
if (!node) sorted_list.Add_Tail(state);
Insert_To_Sorted_List(state);
}
1 change: 1 addition & 0 deletions Core/Libraries/Source/WWVegas/WW3D2/sortingrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class SortingRendererClass
static bool _EnableTriangleDraw;

static void Flush_Sorting_Pool();
static void Insert_To_Sorted_List(SortingNodeStruct* state);
static void Insert_To_Sorting_Pool(SortingNodeStruct* state);

public:
Expand Down
Loading