diff --git a/Source/Urho3D/Audio/BufferedSoundStream.cpp b/Source/Urho3D/Audio/BufferedSoundStream.cpp index 499a8a1653..6ea3d7921c 100644 --- a/Source/Urho3D/Audio/BufferedSoundStream.cpp +++ b/Source/Urho3D/Audio/BufferedSoundStream.cpp @@ -42,10 +42,10 @@ unsigned BufferedSoundStream::GetData(signed char* dest, unsigned numBytes) unsigned outBytes = 0; - while (numBytes && buffers_.Size()) + while (numBytes && buffers_.size()) { // Copy as much from the front buffer as possible, then discard it and move to the next - List, unsigned> >::Iterator front = buffers_.Begin(); + auto front = buffers_.begin(); unsigned copySize = front->second_ - position_; if (copySize > numBytes) @@ -55,7 +55,7 @@ unsigned BufferedSoundStream::GetData(signed char* dest, unsigned numBytes) position_ += copySize; if (position_ >= front->second_) { - buffers_.PopFront(); + buffers_.pop_front(); position_ = 0; } @@ -75,7 +75,7 @@ void BufferedSoundStream::AddData(void* data, unsigned numBytes) SharedArrayPtr newBuffer(new signed char[numBytes]); memcpy(newBuffer.Get(), data, numBytes); - buffers_.Push(MakePair(newBuffer, numBytes)); + buffers_.push_back(MakePair(newBuffer, numBytes)); } } @@ -85,7 +85,7 @@ void BufferedSoundStream::AddData(const SharedArrayPtr& data, unsig { MutexLock lock(bufferMutex_); - buffers_.Push(MakePair(data, numBytes)); + buffers_.push_back(MakePair(data, numBytes)); } } @@ -95,7 +95,7 @@ void BufferedSoundStream::AddData(const SharedArrayPtr& data, unsi { MutexLock lock(bufferMutex_); - buffers_.Push(MakePair(ReinterpretCast(data), numBytes)); + buffers_.push_back(MakePair(ReinterpretCast(data), numBytes)); } } @@ -103,7 +103,7 @@ void BufferedSoundStream::Clear() { MutexLock lock(bufferMutex_); - buffers_.Clear(); + buffers_.clear(); position_ = 0; } @@ -112,8 +112,8 @@ unsigned BufferedSoundStream::GetBufferNumBytes() const MutexLock lock(bufferMutex_); unsigned ret = 0; - for (List, unsigned> >::ConstIterator i = buffers_.Begin(); i != buffers_.End(); ++i) - ret += i->second_; + for (const auto& buffer : buffers_) + ret += buffer.second_; // Subtract amount of sound data played from the front buffer ret -= position_; diff --git a/Source/Urho3D/Audio/BufferedSoundStream.h b/Source/Urho3D/Audio/BufferedSoundStream.h index c17bef4469..bf61b17296 100644 --- a/Source/Urho3D/Audio/BufferedSoundStream.h +++ b/Source/Urho3D/Audio/BufferedSoundStream.h @@ -22,9 +22,10 @@ #pragma once +#include + #include "../Audio/SoundStream.h" #include "../Container/ArrayPtr.h" -#include "../Container/List.h" #include "../Core/Mutex.h" #include "../Container/Pair.h" @@ -59,7 +60,7 @@ class URHO3D_API BufferedSoundStream : public SoundStream private: /// Buffers and their sizes. - List, unsigned> > buffers_; + stl::list, unsigned> > buffers_; /// Byte position in the front most buffer. unsigned position_; /// Mutex for buffer data. diff --git a/Source/Urho3D/Container/ForEach.h b/Source/Urho3D/Container/ForEach.h index 6bab5d742e..80d5f2479c 100644 --- a/Source/Urho3D/Container/ForEach.h +++ b/Source/Urho3D/Container/ForEach.h @@ -23,7 +23,6 @@ #pragma once #include "../Container/Vector.h" -#include "../Container/List.h" #include "../Container/HashSet.h" #include "../Container/HashMap.h" diff --git a/Source/Urho3D/Container/List.h b/Source/Urho3D/Container/List.h deleted file mode 100644 index 13c07cb8cb..0000000000 --- a/Source/Urho3D/Container/List.h +++ /dev/null @@ -1,520 +0,0 @@ -// -// Copyright (c) 2008-2019 the Urho3D project. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// - -#pragma once - -#include "../Container/ListBase.h" -#include "../Core/Macros.h" -#include - -namespace Urho3D -{ - -/// Doubly-linked list template class. -template class List : public ListBase -{ -public: - /// %List node. - struct Node : public ListNodeBase - { - /// Construct undefined. - Node() = default; - - /// Construct with value. - explicit Node(const T& value) : - value_(value) - { - } - - /// Node value. - T value_; - - /// Return next node. - Node* Next() const { return static_cast(next_); } - - /// Return previous node. - Node* Prev() { return static_cast(prev_); } - }; - - /// %List iterator. - struct Iterator : public ListIteratorBase - { - /// Construct. - Iterator() = default; - - /// Construct with a node pointer. - explicit Iterator(Node* ptr) : - ListIteratorBase(ptr) - { - } - - /// Preincrement the pointer. - Iterator& operator ++() - { - GotoNext(); - return *this; - } - - /// Postincrement the pointer. - Iterator operator ++(int) - { - Iterator it = *this; - GotoNext(); - return it; - } - - /// Predecrement the pointer. - Iterator& operator --() - { - GotoPrev(); - return *this; - } - - /// Postdecrement the pointer. - Iterator operator --(int) - { - Iterator it = *this; - GotoPrev(); - return it; - } - - /// Point to the node value. - T* operator ->() const { return &(static_cast(ptr_))->value_; } - - /// Dereference the node value. - T& operator *() const { return (static_cast(ptr_))->value_; } - }; - - /// %List const iterator. - struct ConstIterator : public ListIteratorBase - { - /// Construct. - ConstIterator() = default; - - /// Construct with a node pointer. - explicit ConstIterator(Node* ptr) : - ListIteratorBase(ptr) - { - } - - /// Construct from a non-const iterator. - ConstIterator(const Iterator& rhs) : // NOLINT(google-explicit-constructor) - ListIteratorBase(rhs.ptr_) - { - } - - /// Assign from a non-const iterator. - ConstIterator& operator =(const Iterator& rhs) - { - ptr_ = rhs.ptr_; - return *this; - } - - /// Preincrement the pointer. - ConstIterator& operator ++() - { - GotoNext(); - return *this; - } - - /// Postincrement the pointer. - ConstIterator operator ++(int) - { - ConstIterator it = *this; - GotoNext(); - return it; - } - - /// Predecrement the pointer. - ConstIterator& operator --() - { - GotoPrev(); - return *this; - } - - /// Postdecrement the pointer. - ConstIterator operator --(int) - { - ConstIterator it = *this; - GotoPrev(); - return it; - } - - /// Point to the node value. - const T* operator ->() const { return &(static_cast(ptr_))->value_; } - - /// Dereference the node value. - const T& operator *() const { return (static_cast(ptr_))->value_; } - }; - - /// Construct empty. - List() - { - } - - /// Construct from another list. - List(const List& list) - { - // Reserve the tail node + initial capacity according to the list's size - Initialize(list.Size() + 1); - *this = list; - } - - /// Move-construct from another list. - List(List && list) noexcept - { - Swap(list); - } - - /// Aggregate initialization constructor. - List(const std::initializer_list& list) : List() - { - for (auto it = list.begin(); it != list.end(); it++) - { - Push(*it); - } - } - - /// Destruct. - ~List() - { - if (allocator_) - { - Clear(); - FreeNode(Tail()); - AllocatorUninitialize(allocator_); - } - } - - /// Assign from another list. - List& operator =(const List& rhs) - { - // Clear, then insert the nodes of the other list. In case of self-assignment do nothing - if (&rhs != this) - { - Clear(); - Insert(End(), rhs); - } - return *this; - } - - /// Move-assign from another list. - List& operator =(List && rhs) noexcept - { - assert(&rhs != this); - Swap(rhs); - return *this; - } - - /// Add-assign an element. - List& operator +=(const T& rhs) - { - Push(rhs); - return *this; - } - - /// Add-assign a list. - List& operator +=(const List& rhs) - { - Insert(End(), rhs); - return *this; - } - - /// Test for equality with another list. - bool operator ==(const List& rhs) const - { - if (rhs.size_ != size_) - return false; - - ConstIterator i = Begin(); - ConstIterator j = rhs.Begin(); - while (i != End()) - { - if (*i != *j) - return false; - ++i; - ++j; - } - - return true; - } - - /// Test for inequality with another list. - bool operator !=(const List& rhs) const - { - if (rhs.size_ != size_) - return true; - - ConstIterator i = Begin(); - ConstIterator j = rhs.Begin(); - while (i != End()) - { - if (*i != *j) - return true; - ++i; - ++j; - } - - return false; - } - - /// Insert an element to the end. - void Push(const T& value) { InsertNode(Tail(), value); } - - /// Insert an element to the beginning. - void PushFront(const T& value) { InsertNode(Head(), value); } - - /// Insert an element at position. - void Insert(const Iterator& dest, const T& value) { InsertNode(static_cast(dest.ptr_), value); } - - /// Insert a list at position. - void Insert(const Iterator& dest, const List& list) - { - auto* destNode = static_cast(dest.ptr_); - ConstIterator it = list.Begin(); - ConstIterator end = list.End(); - while (it != end) - InsertNode(destNode, *it++); - } - - /// Insert elements by iterators. - void Insert(const Iterator& dest, const ConstIterator& start, const ConstIterator& end) - { - auto* destNode = static_cast(dest.ptr_); - ConstIterator it = start; - while (it != end) - InsertNode(destNode, *it++); - } - - /// Insert elements. - void Insert(const Iterator& dest, const T* start, const T* end) - { - auto* destNode = static_cast(dest.ptr_); - const T* ptr = start; - while (ptr != end) - InsertNode(destNode, *ptr++); - } - - /// Erase the last element. - void Pop() - { - if (size_) - Erase(--End()); - } - - /// Erase the first element. - void PopFront() - { - if (size_) - Erase(Begin()); - } - - /// Erase an element by iterator. Return iterator to the next element. - Iterator Erase(Iterator it) - { - return Iterator(EraseNode(static_cast(it.ptr_))); - } - - /// Erase a range by iterators. Return an iterator to the next element. - Iterator Erase(const Iterator& start, const Iterator& end) - { - Iterator it = start; - while (it != end) - it = Erase(it); - - return it; - } - - /// Clear the list. - void Clear() - { - if (Size()) - { - for (Iterator i = Begin(); i != End();) - { - FreeNode(static_cast(i++.ptr_)); - i.ptr_->prev_ = 0; - } - - head_ = tail_; - size_ = 0; - } - } - - /// Resize the list by removing or adding items at the end. - void Resize(unsigned newSize) - { - while (size_ > newSize) - Pop(); - - while (size_ < newSize) - InsertNode(Tail(), T()); - } - - /// Return iterator to value, or to the end if not found. - Iterator Find(const T& value) - { - Iterator it = Begin(); - while (it != End() && *it != value) - ++it; - return it; - } - - /// Return const iterator to value, or to the end if not found. - ConstIterator Find(const T& value) const - { - ConstIterator it = Begin(); - while (it != End() && *it != value) - ++it; - return it; - } - - /// Return whether contains a specific value. - bool Contains(const T& value) const { return Find(value) != End(); } - - /// Return iterator to the first element. - Iterator Begin() { return Iterator(Head()); } - - /// Return iterator to the first element. - ConstIterator Begin() const { return ConstIterator(Head()); } - - /// Return iterator to the end. - Iterator End() { return Iterator(Tail()); } - - /// Return iterator to the end. - ConstIterator End() const { return ConstIterator(Tail()); } - - /// Return first element. - T& Front() { return *Begin(); } - - /// Return const first element. - const T& Front() const { return *Begin(); } - - /// Return last element. - T& Back() { return *(--End()); } - - /// Return const last element. - const T& Back() const { return *(--End()); } - - /// Return number of elements. - unsigned Size() const { return size_; } - - /// Return whether list is empty. - bool Empty() const { return size_ == 0; } - -private: - /// Return the head node. - Node* Head() const { return static_cast(head_); } - - /// Return the tail node. - Node* Tail() const { return static_cast(tail_); } - - /// Allocate and insert a node into the list. - void InsertNode(Node* dest, const T& value) - { - if (URHO3D_UNLIKELY(allocator_ == nullptr)) - { - Initialize(); - dest = Tail(); - } - - if (!dest) - return; - - Node* newNode = ReserveNode(value); - Node* prev = dest->Prev(); - newNode->next_ = dest; - newNode->prev_ = prev; - if (prev) - prev->next_ = newNode; - dest->prev_ = newNode; - - // Reassign the head node if necessary - if (dest == Head()) - head_ = newNode; - - ++size_; - } - - /// Erase and free a node. Return pointer to the next node, or to the end if could not erase. - Node* EraseNode(Node* node) - { - // The tail node can not be removed - if (!node || node == tail_) - return Tail(); - - Node* prev = node->Prev(); - Node* next = node->Next(); - if (prev) - prev->next_ = next; - next->prev_ = prev; - - // Reassign the head node if necessary - if (node == Head()) - head_ = next; - - FreeNode(node); - --size_; - - return next; - } - - /// Reserve a node. - Node* ReserveNode() - { - auto* newNode = static_cast(AllocatorReserve(allocator_)); - new(newNode) Node(); - return newNode; - } - - /// Reserve a node with initial value. - Node* ReserveNode(const T& value) - { - auto* newNode = static_cast(AllocatorReserve(allocator_)); - new(newNode) Node(value); - return newNode; - } - - /// Free a node. - void FreeNode(Node* node) - { - (node)->~Node(); - AllocatorFree(allocator_, node); - } - - /// Reserve the tail node. - void Initialize(unsigned initialCapacity = 1) - { - allocator_ = AllocatorInitialize((unsigned)sizeof(Node), initialCapacity); - head_ = tail_ = ReserveNode(); - } -}; - -template typename Urho3D::List::ConstIterator begin(const Urho3D::List& v) { return v.Begin(); } - -template typename Urho3D::List::ConstIterator end(const Urho3D::List& v) { return v.End(); } - -template typename Urho3D::List::Iterator begin(Urho3D::List& v) { return v.Begin(); } - -template typename Urho3D::List::Iterator end(Urho3D::List& v) { return v.End(); } - -} diff --git a/Source/Urho3D/Core/Tasks.h b/Source/Urho3D/Core/Tasks.h index 4fcb6d3b8b..7dd9c317a1 100644 --- a/Source/Urho3D/Core/Tasks.h +++ b/Source/Urho3D/Core/Tasks.h @@ -27,7 +27,6 @@ #include "../Core/Object.h" #include "../Core/Timer.h" #include "../Core/Thread.h" -#include "../Container/List.h" #if URHO3D_TASKS diff --git a/Source/Urho3D/Core/WorkQueue.cpp b/Source/Urho3D/Core/WorkQueue.cpp index 0d7dc1e2d7..805f37be83 100644 --- a/Source/Urho3D/Core/WorkQueue.cpp +++ b/Source/Urho3D/Core/WorkQueue.cpp @@ -111,10 +111,10 @@ void WorkQueue::CreateThreads(unsigned numThreads) SharedPtr WorkQueue::GetFreeItem() { - if (poolItems_.Size() > 0) + if (!poolItems_.empty()) { - SharedPtr item = poolItems_.Front(); - poolItems_.PopFront(); + SharedPtr item = poolItems_.front(); + poolItems_.pop_front(); return item; } else @@ -135,11 +135,11 @@ void WorkQueue::AddWorkItem(const SharedPtr& item) } // Check for duplicate items. - assert(!workItems_.Contains(item)); + assert(stl::find(workItems_.begin(), workItems_.end(), item) == workItems_.end()); // Push to the main thread list to keep item alive // Clear completed flag in case item is reused - workItems_.Push(item); + workItems_.push_back(item); item->completed_ = false; // Make sure worker threads' list is safe to modify @@ -147,24 +147,24 @@ void WorkQueue::AddWorkItem(const SharedPtr& item) queueMutex_.Acquire(); // Find position for new item - if (queue_.Empty()) - queue_.Push(item); + if (queue_.empty()) + queue_.push_back(item); else { bool inserted = false; - for (List::Iterator i = queue_.Begin(); i != queue_.End(); ++i) + for (auto i = queue_.begin(); i != queue_.end(); ++i) { if ((*i)->priority_ <= item->priority_) { - queue_.Insert(i, item); + queue_.insert(i, item); inserted = true; break; } } if (!inserted) - queue_.Push(item); + queue_.push_back(item); } if (threads_.Size()) @@ -192,15 +192,15 @@ bool WorkQueue::RemoveWorkItem(SharedPtr item) MutexLock lock(queueMutex_); // Can only remove successfully if the item was not yet taken by threads for execution - List::Iterator i = queue_.Find(item.Get()); - if (i != queue_.End()) + auto i = stl::find(queue_.begin(), queue_.end(), item.Get()); + if (i != queue_.end()) { - List >::Iterator j = workItems_.Find(item); - if (j != workItems_.End()) + auto j = stl::find(workItems_.begin(), workItems_.end(), item); + if (j != workItems_.end()) { - queue_.Erase(i); + queue_.erase(i); ReturnToPool(item); - workItems_.Erase(j); + workItems_.erase(j); return true; } } @@ -215,15 +215,15 @@ unsigned WorkQueue::RemoveWorkItems(const Vector >& items) for (Vector >::ConstIterator i = items.Begin(); i != items.End(); ++i) { - List::Iterator j = queue_.Find(i->Get()); - if (j != queue_.End()) + auto j = stl::find(queue_.begin(), queue_.end(), i->Get()); + if (j != queue_.end()) { - List >::Iterator k = workItems_.Find(*i); - if (k != workItems_.End()) + auto k = stl::find(workItems_.begin(), workItems_.end(), *i); + if (k != workItems_.end()) { - queue_.Erase(j); + queue_.erase(j); ReturnToPool(*k); - workItems_.Erase(k); + workItems_.erase(k); ++removed; } } @@ -264,13 +264,13 @@ void WorkQueue::Complete(unsigned priority) Resume(); // Take work items also in the main thread until queue empty or no high-priority items anymore - while (!queue_.Empty()) + while (!queue_.empty()) { queueMutex_.Acquire(); - if (!queue_.Empty() && queue_.Front()->priority_ >= priority) + if (!queue_.empty() && queue_.front()->priority_ >= priority) { - WorkItem* item = queue_.Front(); - queue_.PopFront(); + WorkItem* item = queue_.front(); + queue_.pop_front(); queueMutex_.Release(); item->workFunction_(item, 0); item->completed_ = true; @@ -288,16 +288,16 @@ void WorkQueue::Complete(unsigned priority) } // If no work at all remaining, pause worker threads by leaving the mutex locked - if (queue_.Empty()) + if (queue_.empty()) Pause(); } else { // No worker threads: ensure all high-priority items are completed in the main thread - while (!queue_.Empty() && queue_.Front()->priority_ >= priority) + while (!queue_.empty() && queue_.front()->priority_ >= priority) { - WorkItem* item = queue_.Front(); - queue_.PopFront(); + WorkItem* item = queue_.front(); + queue_.pop_front(); item->workFunction_(item, 0); item->completed_ = true; } @@ -310,9 +310,9 @@ void WorkQueue::Complete(unsigned priority) unsigned WorkQueue::GetNumIncomplete(unsigned priority) const { unsigned incomplete = 0; - for (List >::ConstIterator i = workItems_.Begin(); i != workItems_.End(); ++i) + for (const auto& workItem : workItems_) { - if ((*i)->priority_ >= priority && !(*i)->completed_) + if (workItem->priority_ >= priority && !workItem->completed_) ++incomplete; } @@ -321,9 +321,9 @@ unsigned WorkQueue::GetNumIncomplete(unsigned priority) const bool WorkQueue::IsCompleted(unsigned priority) const { - for (List >::ConstIterator i = workItems_.Begin(); i != workItems_.End(); ++i) + for (const auto & workItem : workItems_) { - if ((*i)->priority_ >= priority && !(*i)->completed_) + if (workItem->priority_ >= priority && !workItem->completed_) return false; } @@ -344,12 +344,12 @@ void WorkQueue::ProcessItems(unsigned threadIndex) else { queueMutex_.Acquire(); - if (!queue_.Empty()) + if (!queue_.empty()) { wasActive = true; - WorkItem* item = queue_.Front(); - queue_.PopFront(); + WorkItem* item = queue_.front(); + queue_.pop_front(); queueMutex_.Release(); item->workFunction_(item, threadIndex); item->completed_ = true; @@ -370,7 +370,7 @@ void WorkQueue::PurgeCompleted(unsigned priority) // Purge completed work items and send completion events. Do not signal items lower than priority threshold, // as those may be user submitted and lead to eg. scene manipulation that could happen in the middle of the // render update, which is not allowed - for (List >::Iterator i = workItems_.Begin(); i != workItems_.End();) + for (auto i = workItems_.begin(); i != workItems_.end();) { if ((*i)->completed_ && (*i)->priority_ >= priority) { @@ -384,7 +384,7 @@ void WorkQueue::PurgeCompleted(unsigned priority) } ReturnToPool(*i); - i = workItems_.Erase(i); + i = workItems_.erase(i); } else ++i; @@ -393,12 +393,12 @@ void WorkQueue::PurgeCompleted(unsigned priority) void WorkQueue::PurgePool() { - unsigned currentSize = poolItems_.Size(); + unsigned currentSize = poolItems_.size(); int difference = lastSize_ - currentSize; // Difference tolerance, should be fairly significant to reduce the pool size. - for (unsigned i = 0; poolItems_.Size() > 0 && difference > tolerance_ && i < (unsigned)difference; i++) - poolItems_.PopFront(); + for (unsigned i = 0; !poolItems_.empty() && difference > tolerance_ && i < (unsigned)difference; i++) + poolItems_.pop_front(); lastSize_ = currentSize; } @@ -420,23 +420,23 @@ void WorkQueue::ReturnToPool(SharedPtr& item) item->sendEvent_ = false; item->completed_ = false; - poolItems_.Push(item); + poolItems_.push_back(item); } } void WorkQueue::HandleBeginFrame(StringHash eventType, VariantMap& eventData) { // If no worker threads, complete low-priority work here - if (threads_.Empty() && !queue_.Empty()) + if (threads_.Empty() && !queue_.empty()) { URHO3D_PROFILE("CompleteWorkNonthreaded"); HiresTimer timer; - while (!queue_.Empty() && timer.GetUSec(false) < maxNonThreadedWorkMs_ * 1000LL) + while (!queue_.empty() && timer.GetUSec(false) < maxNonThreadedWorkMs_ * 1000LL) { - WorkItem* item = queue_.Front(); - queue_.PopFront(); + WorkItem* item = queue_.front(); + queue_.pop_front(); item->workFunction_(item, 0); item->completed_ = true; } diff --git a/Source/Urho3D/Core/WorkQueue.h b/Source/Urho3D/Core/WorkQueue.h index f5774aef89..89b0598fea 100644 --- a/Source/Urho3D/Core/WorkQueue.h +++ b/Source/Urho3D/Core/WorkQueue.h @@ -22,10 +22,9 @@ #pragma once - +#include #include -#include "../Container/List.h" #include "../Core/Mutex.h" #include "../Core/Object.h" @@ -136,11 +135,11 @@ class URHO3D_API WorkQueue : public Object /// Worker threads. Vector > threads_; /// Work item pool for reuse to cut down on allocation. The bool is a flag for item pooling and whether it is available or not. - List > poolItems_; + stl::list > poolItems_; /// Work item collection. Accessed only by the main thread. - List > workItems_; + stl::list > workItems_; /// Work item prioritized queue for worker threads. Pointers are guaranteed to be valid (point to workItems.) - List queue_; + stl::list queue_; /// Worker queue mutex. Mutex queueMutex_; /// Shutting down flag. diff --git a/Source/Urho3D/Graphics/DecalSet.cpp b/Source/Urho3D/Graphics/DecalSet.cpp index 7330db9f91..e9f45fcc9e 100644 --- a/Source/Urho3D/Graphics/DecalSet.cpp +++ b/Source/Urho3D/Graphics/DecalSet.cpp @@ -262,7 +262,7 @@ void DecalSet::SetMaxVertices(unsigned num) bufferDirty_ = true; maxVertices_ = num; - while (decals_.Size() && numVertices_ > maxVertices_) + while (decals_.size() && numVertices_ > maxVertices_) RemoveDecals(1); MarkNetworkUpdate(); @@ -280,7 +280,7 @@ void DecalSet::SetMaxIndices(unsigned num) bufferDirty_ = true; maxIndices_ = num; - while (decals_.Size() && numIndices_ > maxIndices_) + while (decals_.size() && numIndices_ > maxIndices_) RemoveDecals(1); MarkNetworkUpdate(); @@ -379,8 +379,8 @@ bool DecalSet::AddDecal(Drawable* target, const Vector3& worldPosition, const Qu Vector3 decalNormal = (targetTransform * Vector4(worldRotation * Vector3::BACK, 0.0f)).Normalized(); - decals_.Resize(decals_.Size() + 1); - Decal& newDecal = decals_.Back(); + decals_.resize(decals_.size() + 1); + Decal& newDecal = decals_.back(); newDecal.timeToLive_ = timeToLive; Vector > faces; @@ -429,7 +429,7 @@ bool DecalSet::AddDecal(Drawable* target, const Vector3& worldPosition, const Qu // Check if resulted in no triangles if (newDecal.vertices_.Empty()) { - decals_.Pop(); + decals_.pop_back(); return true; } @@ -437,14 +437,14 @@ bool DecalSet::AddDecal(Drawable* target, const Vector3& worldPosition, const Qu { URHO3D_LOGWARNING("Can not add decal, vertex count " + String(newDecal.vertices_.Size()) + " exceeds maximum " + String(maxVertices_)); - decals_.Pop(); + decals_.pop_back(); return false; } if (newDecal.indices_.Size() > maxIndices_) { URHO3D_LOGWARNING("Can not add decal, index count " + String(newDecal.indices_.Size()) + " exceeds maximum " + String(maxIndices_)); - decals_.Pop(); + decals_.pop_back(); return false; } @@ -469,7 +469,7 @@ bool DecalSet::AddDecal(Drawable* target, const Vector3& worldPosition, const Qu numIndices_ += newDecal.indices_.Size(); // Remove oldest decals if total vertices exceeded - while (decals_.Size() && (numVertices_ > maxVertices_ || numIndices_ > maxIndices_)) + while (decals_.size() && (numVertices_ > maxVertices_ || numIndices_ > maxIndices_)) RemoveDecals(1); URHO3D_LOGDEBUG("Added decal with " + String(newDecal.vertices_.Size()) + " vertices"); @@ -484,15 +484,15 @@ bool DecalSet::AddDecal(Drawable* target, const Vector3& worldPosition, const Qu void DecalSet::RemoveDecals(unsigned num) { - while (num-- && decals_.Size()) - RemoveDecal(decals_.Begin()); + while (num-- && decals_.size()) + RemoveDecal(decals_.begin()); } void DecalSet::RemoveAllDecals() { - if (!decals_.Empty()) + if (!decals_.empty()) { - decals_.Clear(); + decals_.clear(); numVertices_ = 0; numIndices_ = 0; MarkDecalsDirty(); @@ -535,8 +535,8 @@ void DecalSet::SetDecalsAttr(const PODVector& value) while (numDecals--) { - decals_.Resize(decals_.Size() + 1); - Decal& newDecal = decals_.Back(); + decals_.resize(decals_.size() + 1); + Decal& newDecal = decals_.back(); newDecal.timer_ = buffer.ReadFloat(); newDecal.timeToLive_ = buffer.ReadFloat(); @@ -604,9 +604,9 @@ PODVector DecalSet::GetDecalsAttr() const VectorBuffer ret; ret.WriteBool(skinned_); - ret.WriteVLE(decals_.Size()); + ret.WriteVLE(decals_.size()); - for (List::ConstIterator i = decals_.Begin(); i != decals_.End(); ++i) + for (auto i = decals_.begin(); i != decals_.end(); ++i) { ret.WriteFloat(i->timer_); ret.WriteFloat(i->timeToLive_); @@ -981,12 +981,12 @@ void DecalSet::TransformVertices(Decal& decal, const Matrix3x4& transform) } } -List::Iterator DecalSet::RemoveDecal(List::Iterator i) +stl::list::iterator DecalSet::RemoveDecal(stl::list::iterator i) { numVertices_ -= i->vertices_.Size(); numIndices_ -= i->indices_.Size(); MarkDecalsDirty(); - return decals_.Erase(i); + return decals_.erase(i); } void DecalSet::MarkDecalsDirty() @@ -1002,7 +1002,7 @@ void DecalSet::MarkDecalsDirty() void DecalSet::CalculateBoundingBox() { boundingBox_.Clear(); - for (List::ConstIterator i = decals_.Begin(); i != decals_.End(); ++i) + for (auto i = decals_.begin(); i != decals_.end(); ++i) boundingBox_.Merge(i->boundingBox_); boundingBoxDirty_ = false; @@ -1028,7 +1028,7 @@ void DecalSet::UpdateBuffers() { unsigned short indexStart = 0; - for (List::ConstIterator i = decals_.Begin(); i != decals_.End(); ++i) + for (auto i = decals_.begin(); i != decals_.end(); ++i) { for (unsigned j = 0; j < i->vertices_.Size(); ++j) { @@ -1131,7 +1131,7 @@ void DecalSet::UpdateEventSubscription(bool checkAllDecals) { bool hasTimeLimitedDecals = false; - for (List::ConstIterator i = decals_.Begin(); i != decals_.End(); ++i) + for (auto i = decals_.begin(); i != decals_.end(); ++i) { if (i->timeToLive_ > 0.0f) { @@ -1162,7 +1162,7 @@ void DecalSet::HandleScenePostUpdate(StringHash eventType, VariantMap& eventData float timeStep = eventData[P_TIMESTEP].GetFloat(); - for (List::Iterator i = decals_.Begin(); i != decals_.End();) + for (auto i = decals_.begin(); i != decals_.end();) { i->timer_ += timeStep; diff --git a/Source/Urho3D/Graphics/DecalSet.h b/Source/Urho3D/Graphics/DecalSet.h index 32c328e9bb..06cbafb053 100644 --- a/Source/Urho3D/Graphics/DecalSet.h +++ b/Source/Urho3D/Graphics/DecalSet.h @@ -22,7 +22,8 @@ #pragma once -#include "../Container/List.h" +#include + #include "../Graphics/Drawable.h" #include "../Graphics/Skeleton.h" #include "../Math/Frustum.h" @@ -158,7 +159,7 @@ class URHO3D_API DecalSet : public Drawable Material* GetMaterial() const; /// Return number of decals. - unsigned GetNumDecals() const { return decals_.Size(); } + unsigned GetNumDecals() const { return decals_.size(); } /// Retur number of vertices in the decals. unsigned GetNumVertices() const { return numVertices_; } @@ -209,7 +210,7 @@ class URHO3D_API DecalSet : public Drawable /// Transform decal's vertices from the target geometry to the decal set local space. void TransformVertices(Decal& decal, const Matrix3x4& transform); /// Remove a decal by iterator and return iterator to the next decal. - List::Iterator RemoveDecal(List::Iterator i); + stl::list::iterator RemoveDecal(stl::list::iterator i); /// Mark decals and the bounding box dirty. void MarkDecalsDirty(); /// Recalculate the local-space bounding box. @@ -234,7 +235,7 @@ class URHO3D_API DecalSet : public Drawable /// Index buffer. SharedPtr indexBuffer_; /// Decals. - List decals_; + stl::list decals_; /// Bones used for skinned decals. Vector bones_; /// Skinning matrices. diff --git a/Source/Urho3D/Graphics/Octree.h b/Source/Urho3D/Graphics/Octree.h index 7978b94861..0a523394cd 100644 --- a/Source/Urho3D/Graphics/Octree.h +++ b/Source/Urho3D/Graphics/Octree.h @@ -22,7 +22,6 @@ #pragma once -#include "../Container/List.h" #include "../Core/Mutex.h" #include "../Graphics/Drawable.h" #include "../Graphics/OctreeQuery.h" diff --git a/Source/Urho3D/Graphics/View.h b/Source/Urho3D/Graphics/View.h index 96a6a52bf9..a1810aa6e1 100644 --- a/Source/Urho3D/Graphics/View.h +++ b/Source/Urho3D/Graphics/View.h @@ -23,7 +23,6 @@ #pragma once #include "../Container/HashSet.h" -#include "../Container/List.h" #include "../Core/Object.h" #include "../Graphics/Batch.h" #include "../Graphics/Light.h" diff --git a/Source/Urho3D/IO/FileSystem.cpp b/Source/Urho3D/IO/FileSystem.cpp index 7bfb0b1d21..1dfdbca511 100644 --- a/Source/Urho3D/IO/FileSystem.cpp +++ b/Source/Urho3D/IO/FileSystem.cpp @@ -392,12 +392,12 @@ FileSystem::FileSystem(Context* context) : FileSystem::~FileSystem() { // If any async exec items pending, delete them - if (asyncExecQueue_.Size()) + if (asyncExecQueue_.size()) { - for (List::Iterator i = asyncExecQueue_.Begin(); i != asyncExecQueue_.End(); ++i) + for (auto i = asyncExecQueue_.begin(); i != asyncExecQueue_.end(); ++i) delete(*i); - asyncExecQueue_.Clear(); + asyncExecQueue_.clear(); } } @@ -515,7 +515,7 @@ unsigned FileSystem::SystemCommandAsync(const String& commandLine) { unsigned requestID = nextAsyncExecID_; auto* cmd = new AsyncSystemCommand(nextAsyncExecID_, commandLine); - asyncExecQueue_.Push(cmd); + asyncExecQueue_.push_back(cmd); return requestID; } else @@ -536,7 +536,7 @@ unsigned FileSystem::SystemRunAsync(const String& fileName, const Vector { unsigned requestID = nextAsyncExecID_; auto* cmd = new AsyncSystemRun(nextAsyncExecID_, fileName, arguments); - asyncExecQueue_.Push(cmd); + asyncExecQueue_.push_back(cmd); return requestID; } else @@ -1041,7 +1041,7 @@ void FileSystem::ScanDirInternal(Vector& result, String path, const Stri void FileSystem::HandleBeginFrame(StringHash eventType, VariantMap& eventData) { /// Go through the execution queue and post + remove completed requests - for (List::Iterator i = asyncExecQueue_.Begin(); i != asyncExecQueue_.End();) + for (auto i = asyncExecQueue_.begin(); i != asyncExecQueue_.end();) { AsyncExecRequest* request = *i; if (request->IsCompleted()) @@ -1054,7 +1054,7 @@ void FileSystem::HandleBeginFrame(StringHash eventType, VariantMap& eventData) SendEvent(E_ASYNCEXECFINISHED, newEventData); delete request; - i = asyncExecQueue_.Erase(i); + i = asyncExecQueue_.erase(i); } else ++i; diff --git a/Source/Urho3D/IO/FileSystem.h b/Source/Urho3D/IO/FileSystem.h index 2054b37c10..42b2765c93 100644 --- a/Source/Urho3D/IO/FileSystem.h +++ b/Source/Urho3D/IO/FileSystem.h @@ -22,8 +22,9 @@ #pragma once +#include + #include "../Container/HashSet.h" -#include "../Container/List.h" #include "../Core/Object.h" namespace Urho3D @@ -137,7 +138,7 @@ class URHO3D_API FileSystem : public Object /// Allowed directories. HashSet allowedPaths_; /// Async execution queue. - List asyncExecQueue_; + stl::list asyncExecQueue_; /// Next async execution ID. unsigned nextAsyncExecID_{1}; /// Flag for executing engine console commands as OS-specific system command. Default to true. diff --git a/Source/Urho3D/IO/FileWatcher.h b/Source/Urho3D/IO/FileWatcher.h index 794a92fc5e..1bbc28c606 100644 --- a/Source/Urho3D/IO/FileWatcher.h +++ b/Source/Urho3D/IO/FileWatcher.h @@ -22,7 +22,6 @@ #pragma once -#include "../Container/List.h" #include "../Core/Mutex.h" #include "../Core/Object.h" #include "../Core/Thread.h" diff --git a/Source/Urho3D/IO/Log.cpp b/Source/Urho3D/IO/Log.cpp index 112a07143b..c63fd9ddea 100644 --- a/Source/Urho3D/IO/Log.cpp +++ b/Source/Urho3D/IO/Log.cpp @@ -318,7 +318,7 @@ void Log::SendMessageEvent(LogLevel level, time_t timestamp, const String& logge if (logInstance) { MutexLock lock(logMutex_); - threadMessages_.Push(StoredLogMessage(level, timestamp, logger, message)); + threadMessages_.push_back(StoredLogMessage(level, timestamp, logger, message)); } return; @@ -358,11 +358,11 @@ void Log::PumpThreadMessages() MutexLock lock(logMutex_); // Process messages accumulated from other threads (if any) - while (!threadMessages_.Empty()) + while (!threadMessages_.empty()) { - const StoredLogMessage& stored = threadMessages_.Front(); + const StoredLogMessage& stored = threadMessages_.front(); SendMessageEvent(stored.level_, stored.timestamp_, stored.logger_, stored.message_); - threadMessages_.PopFront(); + threadMessages_.pop_front(); } } diff --git a/Source/Urho3D/IO/Log.h b/Source/Urho3D/IO/Log.h index f91018279f..910ce55c80 100644 --- a/Source/Urho3D/IO/Log.h +++ b/Source/Urho3D/IO/Log.h @@ -22,7 +22,8 @@ #pragma once -#include "../Container/List.h" +#include + #include "../Core/Mutex.h" #include "../Core/Object.h" #include "../Core/StringUtils.h" @@ -171,7 +172,7 @@ class URHO3D_API Log : public Object /// Mutex for threaded operation. Mutex logMutex_{}; /// Log messages from other threads. - List threadMessages_{}; + stl::list threadMessages_{}; /// Logging level. #ifdef _DEBUG LogLevel level_ = LOG_DEBUG; diff --git a/Source/Urho3D/Input/Input.cpp b/Source/Urho3D/Input/Input.cpp index 334f591f93..723949b413 100644 --- a/Source/Urho3D/Input/Input.cpp +++ b/Source/Urho3D/Input/Input.cpp @@ -384,7 +384,7 @@ Input::Input(Context* context) : context_->RequireSDL(SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER); for (int i = 0; i < TOUCHID_MAX; i++) - availableTouchIDs_.Push(i); + availableTouchIDs_.push_back(i); SubscribeToEvent(E_SCREENMODE, URHO3D_HANDLER(Input, HandleScreenMode)); @@ -1679,9 +1679,9 @@ void Input::ResetTouches() touches_.Clear(); touchIDMap_.Clear(); - availableTouchIDs_.Clear(); + availableTouchIDs_.clear(); for (int i = 0; i < TOUCHID_MAX; i++) - availableTouchIDs_.Push(i); + availableTouchIDs_.push_back(i); } @@ -1700,11 +1700,11 @@ unsigned Input::GetTouchIndexFromID(int touchID) unsigned Input::PopTouchIndex() { - if (availableTouchIDs_.Empty()) + if (availableTouchIDs_.empty()) return 0; - auto index = (unsigned)availableTouchIDs_.Front(); - availableTouchIDs_.PopFront(); + auto index = (unsigned)availableTouchIDs_.front(); + availableTouchIDs_.pop_front(); return index; } @@ -1719,7 +1719,7 @@ void Input::PushTouchIndex(int touchID) // Sorted insertion bool inserted = false; - for (List::Iterator i = availableTouchIDs_.Begin(); i != availableTouchIDs_.End(); ++i) + for (auto i = availableTouchIDs_.begin(); i != availableTouchIDs_.end(); ++i) { if (*i == index) { @@ -1730,7 +1730,7 @@ void Input::PushTouchIndex(int touchID) if (*i > index) { - availableTouchIDs_.Insert(i, index); + availableTouchIDs_.insert(i, index); inserted = true; break; } @@ -1738,7 +1738,7 @@ void Input::PushTouchIndex(int touchID) // If empty, or the lowest value then insert at end. if (!inserted) - availableTouchIDs_.Push(index); + availableTouchIDs_.push_back(index); } void Input::SendInputFocusEvent() diff --git a/Source/Urho3D/Input/Input.h b/Source/Urho3D/Input/Input.h index 2c501c27db..e999a4465a 100644 --- a/Source/Urho3D/Input/Input.h +++ b/Source/Urho3D/Input/Input.h @@ -22,11 +22,12 @@ #pragma once +#include + #include "../Container/FlagSet.h" #include "../Container/HashSet.h" #include "../Core/Mutex.h" #include "../Core/Object.h" -#include "../Container/List.h" #include "../Input/InputEvents.h" #include "../UI/Cursor.h" @@ -378,7 +379,7 @@ class URHO3D_API Input : public Object /// Active finger touches. HashMap touches_; /// List that maps between event touch IDs and normalised touch IDs - List availableTouchIDs_; + stl::list availableTouchIDs_; /// Mapping of touch indices HashMap touchIDMap_; /// String for text input. diff --git a/Source/Urho3D/Resource/ResourceCache.h b/Source/Urho3D/Resource/ResourceCache.h index c1ee21cc70..b38c4d60f8 100644 --- a/Source/Urho3D/Resource/ResourceCache.h +++ b/Source/Urho3D/Resource/ResourceCache.h @@ -23,7 +23,6 @@ #pragma once #include "../Container/HashSet.h" -#include "../Container/List.h" #include "../Core/Mutex.h" #include "../IO/File.h" #include "../Resource/Resource.h" diff --git a/Source/Urho3D/UI/FontFace.h b/Source/Urho3D/UI/FontFace.h index 87a128739d..e3493e782b 100644 --- a/Source/Urho3D/UI/FontFace.h +++ b/Source/Urho3D/UI/FontFace.h @@ -24,7 +24,6 @@ #include "../Container/ArrayPtr.h" #include "../Container/HashMap.h" -#include "../Container/List.h" #include "../Container/Ptr.h" #include "../Math/AreaAllocator.h"