4949#include " statistics.h"
5050#include < wwprofile.h>
5151#include < algorithm>
52+ #include < list>
5253
5354
5455bool SortingRendererClass::_EnableTriangleDraw=true ;
@@ -150,7 +151,7 @@ void Sort(TempIndexStruct *begin, TempIndexStruct *end)
150151
151152// ----------------------------------------------------------------------------
152153
153- class SortingNodeStruct : public DLNodeClass <SortingNodeStruct>
154+ class SortingNodeStruct
154155{
155156 W3DMPO_CODE (SortingNodeStruct)
156157
@@ -166,20 +167,18 @@ class SortingNodeStruct : public DLNodeClass<SortingNodeStruct>
166167 unsigned short vertex_count; // Number of vertices used in vb
167168};
168169
169- static DLListClass <SortingNodeStruct> sorted_list;
170- static DLListClass <SortingNodeStruct> clean_list;
170+ static std::list <SortingNodeStruct* > sorted_list;
171+ static std::list <SortingNodeStruct* > clean_list;
171172static unsigned total_sorting_vertices;
172173
173174static SortingNodeStruct* Get_Sorting_Struct ()
174175{
175-
176- SortingNodeStruct* state=clean_list.Head ();
177- if (state) {
178- state->Remove ();
176+ if (!clean_list.empty ()) {
177+ SortingNodeStruct* state = clean_list.front ();
178+ clean_list.pop_front ();
179179 return state;
180180 }
181- state=W3DNEW SortingNodeStruct ();
182- return state;
181+ return W3DNEW SortingNodeStruct ();
183182}
184183
185184// ----------------------------------------------------------------------------
@@ -258,18 +257,15 @@ void SortingRendererClass::Insert_Triangles(
258257
259258 // / @todo lorenzen sez use a bucket sort here... and stop copying so much data so many times
260259
261- SortingNodeStruct* node=sorted_list.Head ();
262- while (node) {
263- if (state->transformed_center .Z >node->transformed_center .Z ) {
264- if (sorted_list.Head ()==sorted_list.Tail ())
265- sorted_list.Add_Head (state);
266- else
267- state->Insert_Before (node);
260+ std::list<SortingNodeStruct*>::iterator node = sorted_list.begin ();
261+ while (node != sorted_list.end ()) {
262+ if (state->transformed_center .Z > (*node)->transformed_center .Z ) {
263+ sorted_list.insert (node, state);
268264 break ;
269265 }
270- node=node-> Succ () ;
266+ ++ node;
271267 }
272- if (! node) sorted_list.Add_Tail (state);
268+ if (node == sorted_list. end ()) sorted_list.push_back (state);
273269
274270#ifdef WWDEBUG
275271 unsigned short * indices=nullptr ;
@@ -577,7 +573,7 @@ void SortingRendererClass::Flush_Sorting_Pool()
577573 for (unsigned node_id=0 ;node_id<overlapping_node_count;++node_id) {
578574 SortingNodeStruct* state=overlapping_nodes[node_id];
579575 Release_Refs (state);
580- clean_list.Add_Head (state);
576+ clean_list.push_front (state);
581577 }
582578 overlapping_node_count=0 ;
583579 overlapping_polygon_count=0 ;
@@ -597,8 +593,9 @@ void SortingRendererClass::Flush()
597593 DX8Wrapper::Get_Transform (D3DTS_VIEW ,old_view);
598594 DX8Wrapper::Get_Transform (D3DTS_WORLD ,old_world);
599595
600- while (SortingNodeStruct* state=sorted_list.Head ()) {
601- state->Remove ();
596+ while (!sorted_list.empty ()) {
597+ SortingNodeStruct* state = sorted_list.front ();
598+ sorted_list.pop_front ();
602599
603600 if ((state->sorting_state .index_buffer_type ==BUFFER_TYPE_SORTING || state->sorting_state .index_buffer_type ==BUFFER_TYPE_DYNAMIC_SORTING ) &&
604601 (state->sorting_state .vertex_buffer_types [0 ]==BUFFER_TYPE_SORTING || state->sorting_state .vertex_buffer_types [0 ]==BUFFER_TYPE_DYNAMIC_SORTING )) {
@@ -609,7 +606,7 @@ void SortingRendererClass::Flush()
609606 DX8Wrapper::Draw_Triangles (state->start_index ,state->polygon_count ,state->min_vertex_index ,state->vertex_count );
610607 DX8Wrapper::Release_Render_State ();
611608 Release_Refs (state);
612- clean_list.Add_Head (state);
609+ clean_list.push_front (state);
613610 }
614611 }
615612
@@ -635,22 +632,20 @@ void SortingRendererClass::Flush()
635632
636633void SortingRendererClass::Deinit ()
637634{
638- SortingNodeStruct *head = nullptr ;
639-
640635 //
641636 // Flush the sorted list
642637 //
643- while ((head = sorted_list.Head ()) != nullptr ) {
644- sorted_list.Remove_Head ();
645- delete head ;
638+ while (! sorted_list.empty () ) {
639+ delete sorted_list.front ();
640+ sorted_list. pop_front () ;
646641 }
647642
648643 //
649644 // Flush the clean list
650645 //
651- while ((head = clean_list.Head ()) != nullptr ) {
652- clean_list.Remove_Head ();
653- delete head ;
646+ while (! clean_list.empty () ) {
647+ delete clean_list.front ();
648+ clean_list. pop_front () ;
654649 }
655650
656651 delete[] temp_index_array;
@@ -717,16 +712,13 @@ void SortingRendererClass::Insert_VolumeParticle(
717712
718713 // / @todo lorenzen sez use a bucket sort here... and stop copying so much data so many times
719714
720- SortingNodeStruct* node=sorted_list.Head ();
721- while (node) {
722- if (state->transformed_center .Z >node->transformed_center .Z ) {
723- if (sorted_list.Head ()==sorted_list.Tail ())
724- sorted_list.Add_Head (state);
725- else
726- state->Insert_Before (node);
715+ std::list<SortingNodeStruct*>::iterator node = sorted_list.begin ();
716+ while (node != sorted_list.end ()) {
717+ if (state->transformed_center .Z > (*node)->transformed_center .Z ) {
718+ sorted_list.insert (node, state);
727719 break ;
728720 }
729- node=node-> Succ () ;
721+ ++ node;
730722 }
731- if (! node) sorted_list.Add_Tail (state);
723+ if (node == sorted_list. end ()) sorted_list.push_back (state);
732724}
0 commit comments