Skip to content

armgit / godot

Public Imported from GitHub
0

Godot Engine – Multi-platform 2D and 3D game engine

Add iterators and range-for support to `SelfList`

Mikael Hermanssone1080e78df27
diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp
index bcb653c4413..be050c9c78f 100644
--- a/core/io/resource_loader.cpp
+++ b/core/io/resource_loader.cpp
@@ -1544,11 +1544,8 @@ void ResourceLoader::reload_translation_remaps() {
{
MutexLock lock(ResourceCache::lock);
- SelfList<Resource> *E = remapped_list.first();
-
- while (E) {
- to_reload.push_back(E->self());
- E = E->next();
+ for (Resource &remapped : remapped_list) {
+ to_reload.push_back(&remapped);
}
}
diff --git a/core/object/worker_thread_pool.cpp b/core/object/worker_thread_pool.cpp
index e0b6756f6f4..87be597b89f 100644
--- a/core/object/worker_thread_pool.cpp
+++ b/core/object/worker_thread_pool.cpp
@@ -861,10 +861,8 @@ void WorkerThreadPool::finish() {
{
MutexLock lock(task_mutex);
- SelfList<Task> *E = low_priority_task_queue.first();
- while (E) {
- print_error("Task waiting was never re-claimed: " + E->self()->description);
- E = E->next();
+ for (const Task &task : low_priority_task_queue) {
+ print_error("Task waiting was never re-claimed: " + task.description);
}
_switch_runlevel(RUNLEVEL_EXIT);
diff --git a/core/templates/self_list.h b/core/templates/self_list.h
index d8f75ca9686..417e83c4185 100644
--- a/core/templates/self_list.h
+++ b/core/templates/self_list.h
@@ -124,6 +124,66 @@ public:
sorter.sort(_first, _last);
}
+ struct ConstIterator {
+ _FORCE_INLINE_ const T &operator*() const { return *E->self(); }
+ _FORCE_INLINE_ const T *operator->() const { return E->self(); }
+
+ _FORCE_INLINE_ ConstIterator &operator++() {
+ E = E->next();
+ return *this;
+ }
+
+ _FORCE_INLINE_ ConstIterator &operator--() {
+ E = E->prev();
+ return *this;
+ }
+
+ _FORCE_INLINE_ bool operator==(const ConstIterator &p_other) const { return E == p_other.E; }
+ _FORCE_INLINE_ bool operator!=(const ConstIterator &p_other) const { return E != p_other.E; }
+
+ _FORCE_INLINE_ ConstIterator(const SelfList<T> *p_elem) { E = p_elem; }
+ _FORCE_INLINE_ ConstIterator() {}
+ _FORCE_INLINE_ ConstIterator(const ConstIterator &p_it) { E = p_it.E; }
+
+ private:
+ const SelfList<T> *E = nullptr;
+ };
+
+ struct Iterator {
+ _FORCE_INLINE_ T &operator*() const { return *E->self(); }
+ _FORCE_INLINE_ T *operator->() const { return E->self(); }
+
+ _FORCE_INLINE_ Iterator &operator++() {
+ E = E->next();
+ return *this;
+ }
+
+ _FORCE_INLINE_ Iterator &operator--() {
+ E = E->prev();
+ return *this;
+ }
+
+ _FORCE_INLINE_ bool operator==(const Iterator &p_other) const { return E == p_other.E; }
+ _FORCE_INLINE_ bool operator!=(const Iterator &p_other) const { return E != p_other.E; }
+
+ Iterator(SelfList<T> *p_elem) { E = p_elem; }
+ Iterator() {}
+ Iterator(const Iterator &p_it) { E = p_it.E; }
+
+ operator ConstIterator() const {
+ return ConstIterator(E);
+ }
+
+ private:
+ SelfList<T> *E = nullptr;
+ };
+
+ _FORCE_INLINE_ Iterator begin() { return Iterator(first()); }
+ _FORCE_INLINE_ Iterator end() { return Iterator(nullptr); }
+
+ _FORCE_INLINE_ ConstIterator begin() const { return ConstIterator(first()); }
+ _FORCE_INLINE_ ConstIterator end() const { return ConstIterator(nullptr); }
+
_FORCE_INLINE_ SelfList<T> *first() { return _first; }
_FORCE_INLINE_ const SelfList<T> *first() const { return _first; }
diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp
index 30b1a4d1ea3..728894d222a 100644
--- a/modules/gdscript/gdscript.cpp
+++ b/modules/gdscript/gdscript.cpp
@@ -2303,20 +2303,18 @@ void GDScriptLanguage::profiling_start() {
#ifdef DEBUG_ENABLED
MutexLock lock(mutex);
- SelfList<GDScriptFunction> *elem = function_list.first();
- while (elem) {
- elem->self()->profile.call_count.set(0);
- elem->self()->profile.self_time.set(0);
- elem->self()->profile.total_time.set(0);
- elem->self()->profile.frame_call_count.set(0);
- elem->self()->profile.frame_self_time.set(0);
- elem->self()->profile.frame_total_time.set(0);
- elem->self()->profile.last_frame_call_count = 0;
- elem->self()->profile.last_frame_self_time = 0;
- elem->self()->profile.last_frame_total_time = 0;
- elem->self()->profile.native_calls.clear();
- elem->self()->profile.last_native_calls.clear();
- elem = elem->next();
+ for (GDScriptFunction &func : function_list) {
+ func.profile.call_count.set(0);
+ func.profile.self_time.set(0);
+ func.profile.total_time.set(0);
+ func.profile.frame_call_count.set(0);
+ func.profile.frame_self_time.set(0);
+ func.profile.frame_total_time.set(0);
+ func.profile.last_frame_call_count = 0;
+ func.profile.last_frame_self_time = 0;
+ func.profile.last_frame_total_time = 0;
+ func.profile.native_calls.clear();
+ func.profile.last_native_calls.clear();
}
profiling = true;
@@ -2345,20 +2343,20 @@ int GDScriptLanguage::profiling_get_accumulated_data(ProfilingInfo *r_info_arr,
MutexLock lock(mutex);
profiling_collate_native_call_data(true);
- SelfList<GDScriptFunction> *elem = function_list.first();
- while (elem) {
+
+ for (const GDScriptFunction &func : function_list) {
if (current >= p_info_max) {
break;
}
int last_non_internal = current;
- r_info_arr[current].call_count = elem->self()->profile.call_count.get();
- r_info_arr[current].self_time = elem->self()->profile.self_time.get();
- r_info_arr[current].total_time = elem->self()->profile.total_time.get();
- r_info_arr[current].signature = elem->self()->profile.signature;
+ r_info_arr[current].call_count = func.profile.call_count.get();
+ r_info_arr[current].self_time = func.profile.self_time.get();
+ r_info_arr[current].total_time = func.profile.total_time.get();
+ r_info_arr[current].signature = func.profile.signature;
current++;
int nat_time = 0;
- HashMap<String, GDScriptFunction::Profile::NativeProfile>::ConstIterator nat_calls = elem->self()->profile.native_calls.begin();
+ HashMap<String, GDScriptFunction::Profile::NativeProfile>::ConstIterator nat_calls = func.profile.native_calls.begin();
while (nat_calls) {
r_info_arr[current].call_count = nat_calls->value.call_count;
r_info_arr[current].total_time = nat_calls->value.total_time;
@@ -2369,7 +2367,6 @@ int GDScriptLanguage::profiling_get_accumulated_data(ProfilingInfo *r_info_arr,
++nat_calls;
}
r_info_arr[last_non_internal].internal_time = nat_time;
- elem = elem->next();
}
#endif
@@ -2383,21 +2380,21 @@ int GDScriptLanguage::profiling_get_frame_data(ProfilingInfo *r_info_arr, int p_
MutexLock lock(mutex);
profiling_collate_native_call_data(false);
- SelfList<GDScriptFunction> *elem = function_list.first();
- while (elem) {
+
+ for (const GDScriptFunction &func : function_list) {
if (current >= p_info_max) {
break;
}
- if (elem->self()->profile.last_frame_call_count > 0) {
+ if (func.profile.last_frame_call_count > 0) {
int last_non_internal = current;
- r_info_arr[current].call_count = elem->self()->profile.last_frame_call_count;
- r_info_arr[current].self_time = elem->self()->profile.last_frame_self_time;
- r_info_arr[current].total_time = elem->self()->profile.last_frame_total_time;
- r_info_arr[current].signature = elem->self()->profile.signature;
+ r_info_arr[current].call_count = func.profile.last_frame_call_count;
+ r_info_arr[current].self_time = func.profile.last_frame_self_time;
+ r_info_arr[current].total_time = func.profile.last_frame_total_time;
+ r_info_arr[current].signature = func.profile.signature;
current++;
int nat_time = 0;
- HashMap<String, GDScriptFunction::Profile::NativeProfile>::ConstIterator nat_calls = elem->self()->profile.last_native_calls.begin();
+ HashMap<String, GDScriptFunction::Profile::NativeProfile>::ConstIterator nat_calls = func.profile.last_native_calls.begin();
while (nat_calls) {
r_info_arr[current].call_count = nat_calls->value.call_count;
r_info_arr[current].total_time = nat_calls->value.total_time;
@@ -2410,7 +2407,6 @@ int GDScriptLanguage::profiling_get_frame_data(ProfilingInfo *r_info_arr, int p_
}
r_info_arr[last_non_internal].internal_time = nat_time;
}
- elem = elem->next();
}
#endif
@@ -2422,9 +2418,8 @@ void GDScriptLanguage::profiling_collate_native_call_data(bool p_accumulated) {
// The same native call can be called from multiple functions, so join them together here.
// Only use the name of the function (ie signature.split[2]).
HashMap<String, GDScriptFunction::Profile::NativeProfile *> seen_nat_calls;
- SelfList<GDScriptFunction> *elem = function_list.first();
- while (elem) {
- HashMap<String, GDScriptFunction::Profile::NativeProfile> *nat_calls = p_accumulated ? &elem->self()->profile.native_calls : &elem->self()->profile.last_native_calls;
+ for (GDScriptFunction &func : function_list) {
+ HashMap<String, GDScriptFunction::Profile::NativeProfile> *nat_calls = p_accumulated ? &func.profile.native_calls : &func.profile.last_native_calls;
HashMap<String, GDScriptFunction::Profile::NativeProfile>::Iterator it = nat_calls->begin();
while (it != nat_calls->end()) {
@@ -2433,13 +2428,12 @@ void GDScriptLanguage::profiling_collate_native_call_data(bool p_accumulated) {
if (already_found) {
already_found->value->total_time += it->value.total_time;
already_found->value->call_count += it->value.call_count;
- elem->self()->profile.last_native_calls.remove(it);
+ func.profile.last_native_calls.remove(it);
} else {
seen_nat_calls.insert(sig[2], &it->value);
}
++it;
}
- elem = elem->next();
}
#endif
}
@@ -2471,13 +2465,11 @@ void GDScriptLanguage::reload_all_scripts() {
{
MutexLock lock(mutex);
- SelfList<GDScript> *elem = script_list.first();
- while (elem) {
- if (elem->self()->get_path().is_resource_file()) {
- print_verbose("GDScript: Found: " + elem->self()->get_path());
- scripts.push_back(Ref<GDScript>(elem->self())); //cast to gdscript to avoid being erased by accident
+ for (GDScript &script : script_list) {
+ if (script.get_path().is_resource_file()) {
+ print_verbose("GDScript: Found: " + script.get_path());
+ scripts.push_back(Ref<GDScript>(&script)); //cast to gdscript to avoid being erased by accident
}
- elem = elem->next();
}
#ifdef TOOLS_ENABLED
@@ -2505,13 +2497,11 @@ void GDScriptLanguage::reload_scripts(const Array &p_scripts) {
{
MutexLock lock(mutex);
- SelfList<GDScript> *elem = script_list.first();
- while (elem) {
+ for (GDScript &script : script_list) {
// Scripts will reload all subclasses, so only reload root scripts.
- if (elem->self()->is_root_script() && !elem->self()->get_path().is_empty()) {
- scripts.push_back(Ref<GDScript>(elem->self())); //cast to gdscript to avoid being erased by accident
+ if (script.is_root_script() && !script.get_path().is_empty()) {
+ scripts.push_back(Ref<GDScript>(&script)); //cast to gdscript to avoid being erased by accident
}
- elem = elem->next();
}
}
@@ -2602,17 +2592,15 @@ void GDScriptLanguage::frame() {
if (profiling) {
MutexLock lock(mutex);
- SelfList<GDScriptFunction> *elem = function_list.first();
- while (elem) {
- elem->self()->profile.last_frame_call_count = elem->self()->profile.frame_call_count.get();
- elem->self()->profile.last_frame_self_time = elem->self()->profile.frame_self_time.get();
- elem->self()->profile.last_frame_total_time = elem->self()->profile.frame_total_time.get();
- elem->self()->profile.last_native_calls = elem->self()->profile.native_calls;
- elem->self()->profile.frame_call_count.set(0);
- elem->self()->profile.frame_self_time.set(0);
- elem->self()->profile.frame_total_time.set(0);
- elem->self()->profile.native_calls.clear();
- elem = elem->next();
+ for (GDScriptFunction &func : function_list) {
+ func.profile.last_frame_call_count = func.profile.frame_call_count.get();
+ func.profile.last_frame_self_time = func.profile.frame_self_time.get();
+ func.profile.last_frame_total_time = func.profile.frame_total_time.get();
+ func.profile.last_native_calls = func.profile.native_calls;
+ func.profile.frame_call_count.set(0);
+ func.profile.frame_self_time.set(0);
+ func.profile.frame_total_time.set(0);
+ func.profile.native_calls.clear();
}
}
diff --git a/modules/gdscript/gdscript_compiler.cpp b/modules/gdscript/gdscript_compiler.cpp
index 790b25ced51..4fd867f903c 100644
--- a/modules/gdscript/gdscript_compiler.cpp
+++ b/modules/gdscript/gdscript_compiler.cpp
@@ -3068,8 +3068,8 @@ Error GDScriptCompiler::_compile_class(GDScript *p_script, const GDScriptParser:
//validate instances if keeping state
if (p_keep_state) {
- for (SelfList<GDScriptInstance> *E = p_script->instances.first(); E; E = E->next()) {
- E->self()->reload_members();
+ for (GDScriptInstance &instance : p_script->instances) {
+ instance.reload_members();
}
}
#endif //DEBUG_ENABLED
diff --git a/modules/jolt_physics/spaces/jolt_contact_listener_3d.cpp b/modules/jolt_physics/spaces/jolt_contact_listener_3d.cpp
index b356bbc8639..d7450ce2e28 100644
--- a/modules/jolt_physics/spaces/jolt_contact_listener_3d.cpp
+++ b/modules/jolt_physics/spaces/jolt_contact_listener_3d.cpp
@@ -412,8 +412,8 @@ void JoltContactListener3D::_evaluate_area_overlap(const JoltArea3D &p_area, con
void JoltContactListener3D::_flush_contacts() {
thread_local AHashMap<JPH::SubShapeIDPair, Manifold *, ShapePairHasher> deepest_manifolds;
- for (SelfList<ThreadLocals> *tl = ThreadLocals::instances.first(); tl != nullptr; tl = tl->next()) {
- for (Manifold &manifold : tl->self()->manifolds) {
+ for (ThreadLocals &tl : ThreadLocals::instances) {
+ for (Manifold &manifold : tl.manifolds) {
Manifold *&deepest_manifold = deepest_manifolds[manifold.shape_pair];
if (deepest_manifold == nullptr || manifold.depth > deepest_manifold->depth) {
deepest_manifold = &manifold;
@@ -442,38 +442,38 @@ void JoltContactListener3D::_flush_contacts() {
deepest_manifolds.clear();
- for (SelfList<ThreadLocals> *tl = ThreadLocals::instances.first(); tl != nullptr; tl = tl->next()) {
- tl->self()->manifolds.clear();
+ for (ThreadLocals &tl : ThreadLocals::instances) {
+ tl.manifolds.clear();
}
}
void JoltContactListener3D::_flush_area_body_events() {
uint32_t new_overlap_count = area_overlaps.size();
- for (SelfList<ThreadLocals> *tl = ThreadLocals::instances.first(); tl != nullptr; tl = tl->next()) {
- new_overlap_count -= tl->self()->area_exits.size();
- new_overlap_count += tl->self()->area_enters.size();
+ for (const ThreadLocals &tl : ThreadLocals::instances) {
+ new_overlap_count -= tl.area_exits.size();
+ new_overlap_count += tl.area_enters.size();
}
// Exits must be dispatched before enters, as shape-shifting relies on it.
- for (SelfList<ThreadLocals> *tl = ThreadLocals::instances.first(); tl != nullptr; tl = tl->next()) {
- for (const JPH::SubShapeIDPair &shape_pair : tl->self()->area_exits) {
+ for (ThreadLocals &tl : ThreadLocals::instances) {
+ for (const JPH::SubShapeIDPair &shape_pair : tl.area_exits) {
area_overlaps.erase(shape_pair);
_dispatch_area_exit(shape_pair);
}
- tl->self()->area_exits.clear();
+ tl.area_exits.clear();
}
area_overlaps.reserve(new_overlap_count);
- for (SelfList<ThreadLocals> *tl = ThreadLocals::instances.first(); tl != nullptr; tl = tl->next()) {
- for (const JPH::SubShapeIDPair &shape_pair : tl->self()->area_enters) {
+ for (ThreadLocals &tl : ThreadLocals::instances) {
+ for (const JPH::SubShapeIDPair &shape_pair : tl.area_enters) {
area_overlaps.insert(shape_pair);
_dispatch_area_enter(shape_pair);
}
- tl->self()->area_enters.clear();
+ tl.area_enters.clear();
}
}
@@ -481,8 +481,8 @@ void JoltContactListener3D::_flush_area_soft_body_events() {
int current_count = area_soft_body_overlaps.size();
int persisting_count = 0;
int entered_count = 0;
- for (SelfList<ThreadLocals> *tl = ThreadLocals::instances.first(); tl != nullptr; tl = tl->next()) {
- for (const JPH::SubShapeIDPair &shape_pair : tl->self()->area_soft_body_overlaps) {
+ for (const ThreadLocals &tl : ThreadLocals::instances) {
+ for (const JPH::SubShapeIDPair &shape_pair : tl.area_soft_body_overlaps) {
if (area_soft_body_overlaps.has(shape_pair)) {
persisting_count += 1;
} else {
@@ -498,8 +498,8 @@ void JoltContactListener3D::_flush_area_soft_body_events() {
HashSet<JPH::SubShapeIDPair, ShapePairHasher> new_overlaps;
new_overlaps.reserve(persisting_count + entered_count);
- for (SelfList<ThreadLocals> *tl = ThreadLocals::instances.first(); tl != nullptr; tl = tl->next()) {
- for (const JPH::SubShapeIDPair &shape_pair : tl->self()->area_soft_body_overlaps) {
+ for (const ThreadLocals &tl : ThreadLocals::instances) {
+ for (const JPH::SubShapeIDPair &shape_pair : tl.area_soft_body_overlaps) {
new_overlaps.insert(shape_pair);
}
}
@@ -515,8 +515,8 @@ void JoltContactListener3D::_flush_area_soft_body_events() {
ERR_PRINT_ONCE("Duplicate area soft body overlaps found. This should not happen. Please report this.");
}
- for (SelfList<ThreadLocals> *tl = ThreadLocals::instances.first(); tl != nullptr; tl = tl->next()) {
- tl->self()->area_soft_body_overlaps.clear();
+ for (ThreadLocals &tl : ThreadLocals::instances) {
+ tl.area_soft_body_overlaps.clear();
}
}
diff --git a/modules/mono/csharp_script.cpp b/modules/mono/csharp_script.cpp
index 79181e96b44..2024ab2ca3c 100644
--- a/modules/mono/csharp_script.cpp
+++ b/modules/mono/csharp_script.cpp
@@ -643,10 +643,10 @@ void CSharpLanguage::reload_assemblies() {
{
MutexLock lock(script_instances_mutex);
- for (SelfList<CSharpScript> *elem = script_list.first(); elem; elem = elem->next()) {
+ for (CSharpScript &script : script_list) {
// Do not reload scripts with only non-collectible instances to avoid disrupting event subscriptions and such.
- bool is_reloadable = elem->self()->instances.is_empty();
- for (Object *obj : elem->self()->instances) {
+ bool is_reloadable = script.instances.is_empty();
+ for (Object *obj : script.instances) {
ERR_CONTINUE(!obj->get_script_instance());
CSharpInstance *csi = static_cast<CSharpInstance *>(obj->get_script_instance());
if (GDMonoCache::managed_callbacks.GCHandleBridge_GCHandleIsTargetCollectible(csi->get_gchandle_intptr())) {
@@ -656,7 +656,7 @@ void CSharpLanguage::reload_assemblies() {
}
if (is_reloadable) {
// Cast to CSharpScript to avoid being erased by accident.
- scripts.push_back(Ref<CSharpScript>(elem->self()));
+ scripts.push_back(Ref<CSharpScript>(&script));
}
}
}
@@ -667,22 +667,20 @@ void CSharpLanguage::reload_assemblies() {
{
MutexLock lock(ManagedCallable::instances_mutex);
- for (SelfList<ManagedCallable> *elem = ManagedCallable::instances.first(); elem; elem = elem->next()) {
- ManagedCallable *managed_callable = elem->self();
+ for (ManagedCallable &managed_callable : ManagedCallable::instances) {
+ ERR_CONTINUE(managed_callable.delegate_handle.value == nullptr);
- ERR_CONTINUE(managed_callable->delegate_handle.value == nullptr);
-
- if (!GDMonoCache::managed_callbacks.GCHandleBridge_GCHandleIsTargetCollectible(managed_callable->delegate_handle)) {
+ if (!GDMonoCache::managed_callbacks.GCHandleBridge_GCHandleIsTargetCollectible(managed_callable.delegate_handle)) {
continue;
}
Array serialized_data;
bool success = GDMonoCache::managed_callbacks.DelegateUtils_TrySerializeDelegateWithGCHandle(
- managed_callable->delegate_handle, &serialized_data);
+ managed_callable.delegate_handle, &serialized_data);
if (success) {
- ManagedCallable::instances_pending_reload.insert(managed_callable, serialized_data);
+ ManagedCallable::instances_pending_reload.insert(&managed_callable, serialized_data);
} else {
if (OS::get_singleton()->is_stdout_verbose()) {
OS::get_singleton()->print("Failed to serialize delegate.\n");
@@ -690,7 +688,7 @@ void CSharpLanguage::reload_assemblies() {
// We failed to serialize the delegate but we still have to release it;
// otherwise, we won't be able to unload the assembly.
- managed_callable->release_delegate_handle();
+ managed_callable.release_delegate_handle();
}
}
}
diff --git a/modules/navigation_2d/nav_map_2d.cpp b/modules/navigation_2d/nav_map_2d.cpp
index 51c429336fb..a85a68bddea 100644
--- a/modules/navigation_2d/nav_map_2d.cpp
+++ b/modules/navigation_2d/nav_map_2d.cpp
@@ -675,8 +675,8 @@ void NavMap2D::_sync_dirty_map_update_requests() {
// Sync NavRegions.
RWLockWrite write_lock_regions(sync_dirty_requests.regions.rwlock);
- for (SelfList<NavRegion2D> *element = sync_dirty_requests.regions.list.first(); element; element = element->next()) {
- bool requires_map_update = element->self()->sync();
+ for (NavRegion2D &region : sync_dirty_requests.regions.list) {
+ bool requires_map_update = region.sync();
if (requires_map_update) {
iteration_dirty = true;
}
@@ -685,8 +685,8 @@ void NavMap2D::_sync_dirty_map_update_requests() {
// Sync NavLinks.
RWLockWrite write_lock_links(sync_dirty_requests.links.rwlock);
- for (SelfList<NavLink2D> *element = sync_dirty_requests.links.list.first(); element; element = element->next()) {
- bool requires_map_update = element->self()->sync();
+ for (NavLink2D &link : sync_dirty_requests.links.list) {
+ bool requires_map_update = link.sync();
if (requires_map_update) {
iteration_dirty = true;
}
@@ -699,8 +699,8 @@ void NavMap2D::_sync_dirty_avoidance_update_requests() {
if (!agents_dirty) {
agents_dirty = sync_dirty_requests.agents.list.first();
}
- for (SelfList<NavAgent2D> *element = sync_dirty_requests.agents.list.first(); element; element = element->next()) {
- element->self()->sync();
+ for (NavAgent2D &agent : sync_dirty_requests.agents.list) {
+ agent.sync();
}
sync_dirty_requests.agents.list.clear();
@@ -708,8 +708,8 @@ void NavMap2D::_sync_dirty_avoidance_update_requests() {
if (!obstacles_dirty) {
obstacles_dirty = sync_dirty_requests.obstacles.list.first();
}
- for (SelfList<NavObstacle2D> *element = sync_dirty_requests.obstacles.list.first(); element; element = element->next()) {
- element->self()->sync();
+ for (NavObstacle2D &obstacle : sync_dirty_requests.obstacles.list) {
+ obstacle.sync();
}
sync_dirty_requests.obstacles.list.clear();
}
@@ -733,8 +733,8 @@ void NavMap2D::remove_region_async_thread_join_request(SelfList<NavRegion2D> *p_
void NavMap2D::_sync_async_tasks() {
// Sync NavRegions that run async thread tasks.
RWLockWrite write_lock_regions(async_dirty_requests.regions.rwlock);
- for (SelfList<NavRegion2D> *element = async_dirty_requests.regions.list.first(); element; element = element->next()) {
- element->self()->sync_async_tasks();
+ for (NavRegion2D &region : async_dirty_requests.regions.list) {
+ region.sync_async_tasks();
}
}
diff --git a/modules/navigation_3d/nav_map_3d.cpp b/modules/navigation_3d/nav_map_3d.cpp
index cfc767ca421..d24d57524aa 100644
--- a/modules/navigation_3d/nav_map_3d.cpp
+++ b/modules/navigation_3d/nav_map_3d.cpp
@@ -777,8 +777,8 @@ void NavMap3D::_sync_dirty_map_update_requests() {
// Sync NavRegions.
RWLockWrite write_lock_regions(sync_dirty_requests.regions.rwlock);
- for (SelfList<NavRegion3D> *element = sync_dirty_requests.regions.list.first(); element; element = element->next()) {
- bool requires_map_update = element->self()->sync();
+ for (NavRegion3D &region : sync_dirty_requests.regions.list) {
+ bool requires_map_update = region.sync();
if (requires_map_update) {
iteration_dirty = true;
}
@@ -787,8 +787,8 @@ void NavMap3D::_sync_dirty_map_update_requests() {
// Sync NavLinks.
RWLockWrite write_lock_links(sync_dirty_requests.links.rwlock);
- for (SelfList<NavLink3D> *element = sync_dirty_requests.links.list.first(); element; element = element->next()) {
- bool requires_map_update = element->self()->sync();
+ for (NavLink3D &link : sync_dirty_requests.links.list) {
+ bool requires_map_update = link.sync();
if (requires_map_update) {
iteration_dirty = true;
}
@@ -801,8 +801,8 @@ void NavMap3D::_sync_dirty_avoidance_update_requests() {
if (!agents_dirty) {
agents_dirty = sync_dirty_requests.agents.list.first();
}
- for (SelfList<NavAgent3D> *element = sync_dirty_requests.agents.list.first(); element; element = element->next()) {
- element->self()->sync();
+ for (NavAgent3D &agent : sync_dirty_requests.agents.list) {
+ agent.sync();
}
sync_dirty_requests.agents.list.clear();
@@ -810,8 +810,8 @@ void NavMap3D::_sync_dirty_avoidance_update_requests() {
if (!obstacles_dirty) {
obstacles_dirty = sync_dirty_requests.obstacles.list.first();
}
- for (SelfList<NavObstacle3D> *element = sync_dirty_requests.obstacles.list.first(); element; element = element->next()) {
- element->self()->sync();
+ for (NavObstacle3D &obstacle : sync_dirty_requests.obstacles.list) {
+ obstacle.sync();
}
sync_dirty_requests.obstacles.list.clear();
}
@@ -835,8 +835,8 @@ void NavMap3D::remove_region_async_thread_join_request(SelfList<NavRegion3D> *p_
void NavMap3D::_sync_async_tasks() {
// Sync NavRegions that run async thread tasks.
RWLockWrite write_lock_regions(async_dirty_requests.regions.rwlock);
- for (SelfList<NavRegion3D> *element = async_dirty_requests.regions.list.first(); element; element = element->next()) {
- element->self()->sync_async_tasks();
+ for (NavRegion3D &region : async_dirty_requests.regions.list) {
+ region.sync_async_tasks();
}
}
diff --git a/modules/tilemap/tile_map_layer.cpp b/modules/tilemap/tile_map_layer.cpp
index aa526f3bcb0..416474c80d0 100644
--- a/modules/tilemap/tile_map_layer.cpp
+++ b/modules/tilemap/tile_map_layer.cpp
@@ -115,8 +115,7 @@ void TileMapLayer::_debug_update(bool p_force_cleanup) {
}
} else {
// Update dirty cells.
- for (SelfList<CellData> *cell_data_list_element = dirty.cell_list.first(); cell_data_list_element; cell_data_list_element = cell_data_list_element->next()) {
- CellData &cell_data = *cell_data_list_element->self();
+ for (CellData &cell_data : dirty.cell_list) {
quadrants_to_updates.insert(_coords_to_quadrant_coords(cell_data.coords, TILE_MAP_DEBUG_QUADRANT_SIZE));
#ifndef PHYSICS_2D_DISABLED
// Physics quadrants are drawn from their origin.
@@ -147,8 +146,7 @@ void TileMapLayer::_debug_update(bool p_force_cleanup) {
}
}
} else {
- for (SelfList<CellData> *cell_data_list_element = dirty.cell_list.first(); cell_data_list_element; cell_data_list_element = cell_data_list_element->next()) {
- CellData &cell_data = *cell_data_list_element->self();
+ for (CellData &cell_data : dirty.cell_list) {
Ref<DebugQuadrant> debug_quadrant = debug_quadrant_map[_coords_to_quadrant_coords(cell_data.coords, TILE_MAP_DEBUG_QUADRANT_SIZE)];
if (!cell_data.debug_quadrant_list_element.in_list()) {
debug_quadrant->cells.add(&cell_data.debug_quadrant_list_element);
@@ -183,8 +181,7 @@ void TileMapLayer::_debug_update(bool p_force_cleanup) {
#endif // PHYSICS_2D_DISABLED
// Draw debug info.
- for (SelfList<CellData> *cell_data_list_element = debug_quadrant->cells.first(); cell_data_list_element; cell_data_list_element = cell_data_list_element->next()) {
- CellData &cell_data = *cell_data_list_element->self();
+ for (CellData &cell_data : debug_quadrant->cells) {
if (cell_data.cell.source_id != TileSet::INVALID_SOURCE) {
_rendering_draw_cell_debug(ci, quadrant_pos, cell_data);
#ifndef NAVIGATION_2D_DISABLED
@@ -277,8 +274,7 @@ void TileMapLayer::_rendering_update(bool p_force_cleanup) {
}
} else {
// Update dirty cells.
- for (SelfList<CellData> *cell_data_list_element = dirty.cell_list.first(); cell_data_list_element; cell_data_list_element = cell_data_list_element->next()) {
- CellData &cell_data = *cell_data_list_element->self();
+ for (CellData &cell_data : dirty.cell_list) {
_rendering_quadrants_update_cell(cell_data, dirty_rendering_quadrant_list);
}
}
@@ -292,8 +288,7 @@ void TileMapLayer::_rendering_update(bool p_force_cleanup) {
// Check if the quadrant has a tile.
bool has_a_tile = false;
- for (SelfList<CellData> *cell_data_list_element = rendering_quadrant->cells.first(); cell_data_list_element; cell_data_list_element = cell_data_list_element->next()) {
- CellData &cell_data = *cell_data_list_element->self();
+ for (const CellData &cell_data : rendering_quadrant->cells) {
if (cell_data.cell.source_id != TileSet::INVALID_SOURCE) {
has_a_tile = true;
break;
@@ -321,9 +316,7 @@ void TileMapLayer::_rendering_update(bool p_force_cleanup) {
int prev_z_index = 0;
RID prev_ci;
- for (SelfList<CellData> *cell_data_quadrant_list_element = rendering_quadrant->cells.first(); cell_data_quadrant_list_element; cell_data_quadrant_list_element = cell_data_quadrant_list_element->next()) {
- CellData &cell_data = *cell_data_quadrant_list_element->self();
-
+ for (const CellData &cell_data : rendering_quadrant->cells) {
TileSetAtlasSource *atlas_source = Object::cast_to<TileSetAtlasSource>(*tile_set->get_source(cell_data.cell.source_id));
// Get the tile data.
@@ -481,8 +474,7 @@ void TileMapLayer::_rendering_update(bool p_force_cleanup) {
}
} else {
// Update dirty cells.
- for (SelfList<CellData> *cell_data_list_element = dirty.cell_list.first(); cell_data_list_element; cell_data_list_element = cell_data_list_element->next()) {
- CellData &cell_data = *cell_data_list_element->self();
+ for (CellData &cell_data : dirty.cell_list) {
_rendering_occluders_update_cell(cell_data);
}
}
@@ -802,8 +794,7 @@ void TileMapLayer::_physics_update(bool p_force_cleanup) {
}
} else {
// Update dirty cells.
- for (SelfList<CellData> *cell_data_list_element = dirty.cell_list.first(); cell_data_list_element; cell_data_list_element = cell_data_list_element->next()) {
- CellData &cell_data = *cell_data_list_element->self();
+ for (CellData &cell_data : dirty.cell_list) {
_physics_quadrants_update_cell(cell_data, dirty_physics_quadrant_list);
}
}
@@ -816,8 +807,7 @@ void TileMapLayer::_physics_update(bool p_force_cleanup) {
// Check if the quadrant has a tile.
bool has_a_tile = false;
- for (SelfList<CellData> *cell_data_list_element = physics_quadrant->cells.first(); cell_data_list_element; cell_data_list_element = cell_data_list_element->next()) {
- CellData &cell_data = *cell_data_list_element->self();
+ for (const CellData &cell_data : physics_quadrant->cells) {
if (cell_data.cell.source_id != TileSet::INVALID_SOURCE) {
has_a_tile = true;
break;
@@ -849,9 +839,7 @@ void TileMapLayer::_physics_update(bool p_force_cleanup) {
uint32_t physics_mask = tile_set->get_physics_layer_collision_mask(tile_set_physics_layer);
// Merge polygons together for each quadrant.
- for (SelfList<CellData> *cell_data_quadrant_list_element = physics_quadrant->cells.first(); cell_data_quadrant_list_element; cell_data_quadrant_list_element = cell_data_quadrant_list_element->next()) {
- CellData &cell_data = *cell_data_quadrant_list_element->self();
-
+ for (const CellData &cell_data : physics_quadrant->cells) {
TileSetAtlasSource *atlas_source = Object::cast_to<TileSetAtlasSource>(*tile_set->get_source(cell_data.cell.source_id));
// Get the tile data.
@@ -1343,8 +1331,7 @@ void TileMapLayer::_navigation_update(bool p_force_cleanup) {
}
} else {
// Update dirty cells.
- for (SelfList<CellData> *cell_data_list_element = dirty.cell_list.first(); cell_data_list_element; cell_data_list_element = cell_data_list_element->next()) {
- CellData &cell_data = *cell_data_list_element->self();
+ for (CellData &cell_data : dirty.cell_list) {
_navigation_update_cell(cell_data);
}
}
@@ -1592,8 +1579,7 @@ void TileMapLayer::_scenes_update(bool p_force_cleanup) {
}
} else {
// Update dirty cells.
- for (SelfList<CellData> *cell_data_list_element = dirty.cell_list.first(); cell_data_list_element; cell_data_list_element = cell_data_list_element->next()) {
- CellData &cell_data = *cell_data_list_element->self();
+ for (CellData &cell_data : dirty.cell_list) {
_scenes_update_cell(cell_data);
}
}
@@ -1748,8 +1734,7 @@ void TileMapLayer::_build_runtime_update_tile_data(bool p_force_cleanup) {
_build_runtime_update_tile_data_for_cell(E.value, use_tilemap_for_runtime, true);
}
} else {
- for (SelfList<CellData> *cell_data_list_element = dirty.cell_list.first(); cell_data_list_element; cell_data_list_element = cell_data_list_element->next()) {
- CellData &cell_data = *cell_data_list_element->self();
+ for (CellData &cell_data : dirty.cell_list) {
_build_runtime_update_tile_data_for_cell(cell_data, use_tilemap_for_runtime);
}
}
@@ -1816,9 +1801,8 @@ void TileMapLayer::_clear_runtime_update_tile_data() {
}
_runtime_update_needs_all_cells_cleaned_up = false;
} else {
- for (SelfList<CellData> *cell_data_list_element = dirty.cell_list.first(); cell_data_list_element; cell_data_list_element = cell_data_list_element->next()) {
- CellData &r_cell_data = *cell_data_list_element->self();
- _clear_runtime_update_tile_data_for_cell(r_cell_data);
+ for (CellData &cell_data : dirty.cell_list) {
+ _clear_runtime_update_tile_data_for_cell(cell_data);
}
}
}
@@ -1841,8 +1825,7 @@ void TileMapLayer::_update_cells_callback(bool p_force_cleanup) {
// List all the dirty cell's positions to notify script of cell updates.
TypedArray<Vector2i> dirty_cell_positions;
- for (SelfList<CellData> *cell_data_list_element = dirty.cell_list.first(); cell_data_list_element; cell_data_list_element = cell_data_list_element->next()) {
- CellData &cell_data = *cell_data_list_element->self();
+ for (const CellData &cell_data : dirty.cell_list) {
dirty_cell_positions.push_back(cell_data.coords);
}
@@ -2088,8 +2071,7 @@ void TileMapLayer::_internal_update(bool p_force_cleanup) {
// List the cells to delete definitely.
Vector<Vector2i> to_delete;
- for (SelfList<CellData> *cell_data_list_element = dirty.cell_list.first(); cell_data_list_element; cell_data_list_element = cell_data_list_element->next()) {
- CellData &cell_data = *cell_data_list_element->self();
+ for (const CellData &cell_data : dirty.cell_list) {
// Select the cell from tile_map if it is invalid.
if (cell_data.cell.source_id == TileSet::INVALID_SOURCE) {
to_delete.push_back(cell_data.coords);
diff --git a/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp b/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp
index 17f027cb36c..b781271fd75 100644
--- a/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp
+++ b/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp
@@ -4964,17 +4964,13 @@ void RenderForwardClustered::_update_dirty_geometry_instances() {
void RenderForwardClustered::_update_dirty_geometry_pipelines() {
if (global_pipeline_data_required.key != global_pipeline_data_compiled.key) {
// Go through the entire list of surfaces and compile pipelines for everything again.
- SelfList<GeometryInstanceSurfaceDataCache> *list = geometry_surface_compilation_all_list.first();
- while (list != nullptr) {
- GeometryInstanceSurfaceDataCache *surface_cache = list->self();
- _mesh_generate_all_pipelines_for_surface_cache(surface_cache, global_pipeline_data_required);
+ for (GeometryInstanceSurfaceDataCache &surface_cache : geometry_surface_compilation_all_list) {
+ _mesh_generate_all_pipelines_for_surface_cache(&surface_cache, global_pipeline_data_required);
- if (surface_cache->compilation_dirty_element.in_list()) {
+ if (surface_cache.compilation_dirty_element.in_list()) {
// Remove any elements from the dirty list as they don't need to be processed again.
- geometry_surface_compilation_dirty_list.remove(&surface_cache->compilation_dirty_element);
+ geometry_surface_compilation_dirty_list.remove(&surface_cache.compilation_dirty_element);
}
-
- list = list->next();
}
global_pipeline_data_compiled.key = global_pipeline_data_required.key;
diff --git a/servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.cpp b/servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.cpp
index eda7d9fba6c..28084935004 100644
--- a/servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.cpp
+++ b/servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.cpp
@@ -1030,8 +1030,8 @@ void fragment() {
void SceneShaderForwardClustered::set_default_specialization(const ShaderSpecialization &p_specialization) {
default_specialization = p_specialization;
- for (SelfList<ShaderData> *E = shader_list.first(); E; E = E->next()) {
- E->self()->pipeline_hash_map.clear_pipelines();
+ for (ShaderData &shader_data : shader_list) {
+ shader_data.pipeline_hash_map.clear_pipelines();
}
}
diff --git a/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp b/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp
index 16e15828dd4..84e08c9583b 100644
--- a/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp
+++ b/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp
@@ -3498,17 +3498,13 @@ void RenderForwardMobile::_update_dirty_geometry_instances() {
void RenderForwardMobile::_update_dirty_geometry_pipelines() {
if (global_pipeline_data_required.key != global_pipeline_data_compiled.key) {
// Go through the entire list of surfaces and compile pipelines for everything again.
- SelfList<GeometryInstanceSurfaceDataCache> *list = geometry_surface_compilation_all_list.first();
- while (list != nullptr) {
- GeometryInstanceSurfaceDataCache *surface_cache = list->self();
- _mesh_generate_all_pipelines_for_surface_cache(surface_cache, global_pipeline_data_required);
+ for (GeometryInstanceSurfaceDataCache &surface_cache : geometry_surface_compilation_all_list) {
+ _mesh_generate_all_pipelines_for_surface_cache(&surface_cache, global_pipeline_data_required);
- if (surface_cache->compilation_dirty_element.in_list()) {
+ if (surface_cache.compilation_dirty_element.in_list()) {
// Remove any elements from the dirty list as they don't need to be processed again.
- geometry_surface_compilation_dirty_list.remove(&surface_cache->compilation_dirty_element);
+ geometry_surface_compilation_dirty_list.remove(&surface_cache.compilation_dirty_element);
}
-
- list = list->next();
}
global_pipeline_data_compiled.key = global_pipeline_data_required.key;
diff --git a/servers/rendering/renderer_rd/forward_mobile/scene_shader_forward_mobile.cpp b/servers/rendering/renderer_rd/forward_mobile/scene_shader_forward_mobile.cpp
index 5c28a4d3aec..52edd245f43 100644
--- a/servers/rendering/renderer_rd/forward_mobile/scene_shader_forward_mobile.cpp
+++ b/servers/rendering/renderer_rd/forward_mobile/scene_shader_forward_mobile.cpp
@@ -960,8 +960,8 @@ void fragment() {
void SceneShaderForwardMobile::set_default_specialization(const ShaderSpecialization &p_specialization) {
default_specialization = p_specialization;
- for (SelfList<ShaderData> *E = shader_list.first(); E; E = E->next()) {
- E->self()->pipeline_hash_map.clear_pipelines();
+ for (ShaderData &shader_data : shader_list) {
+ shader_data.pipeline_hash_map.clear_pipelines();
}
}