diff options
Diffstat (limited to 'scene')
-rw-r--r-- | scene/2d/canvas_item.cpp | 40 | ||||
-rw-r--r-- | scene/2d/canvas_item.h | 2 | ||||
-rw-r--r-- | scene/2d/cpu_particles_2d.cpp | 151 | ||||
-rw-r--r-- | scene/2d/cpu_particles_2d.h | 2 | ||||
-rw-r--r-- | scene/2d/navigation_polygon.cpp | 44 | ||||
-rw-r--r-- | scene/2d/navigation_polygon.h | 4 | ||||
-rw-r--r-- | scene/3d/cpu_particles.cpp | 187 | ||||
-rw-r--r-- | scene/3d/cpu_particles.h | 2 | ||||
-rw-r--r-- | scene/resources/dynamic_font.cpp | 59 | ||||
-rw-r--r-- | scene/resources/dynamic_font.h | 2 | ||||
-rw-r--r-- | scene/resources/material.cpp | 40 | ||||
-rw-r--r-- | scene/resources/material.h | 2 | ||||
-rw-r--r-- | scene/resources/particles_material.cpp | 40 | ||||
-rw-r--r-- | scene/resources/particles_material.h | 2 |
14 files changed, 219 insertions, 358 deletions
diff --git a/scene/2d/canvas_item.cpp b/scene/2d/canvas_item.cpp index 942b63898d..ef7aa9ba01 100644 --- a/scene/2d/canvas_item.cpp +++ b/scene/2d/canvas_item.cpp @@ -41,17 +41,13 @@ #include "servers/visual/visual_server_raster.h" #include "servers/visual_server.h" -Mutex *CanvasItemMaterial::material_mutex = NULL; +Mutex CanvasItemMaterial::material_mutex; SelfList<CanvasItemMaterial>::List *CanvasItemMaterial::dirty_materials = NULL; Map<CanvasItemMaterial::MaterialKey, CanvasItemMaterial::ShaderData> CanvasItemMaterial::shader_map; CanvasItemMaterial::ShaderNames *CanvasItemMaterial::shader_names = NULL; void CanvasItemMaterial::init_shaders() { -#ifndef NO_THREADS - material_mutex = Mutex::create(); -#endif - dirty_materials = memnew(SelfList<CanvasItemMaterial>::List); shader_names = memnew(ShaderNames); @@ -66,10 +62,6 @@ void CanvasItemMaterial::finish_shaders() { memdelete(dirty_materials); memdelete(shader_names); dirty_materials = NULL; - -#ifndef NO_THREADS - memdelete(material_mutex); -#endif } void CanvasItemMaterial::_update_shader() { @@ -156,44 +148,28 @@ void CanvasItemMaterial::_update_shader() { void CanvasItemMaterial::flush_changes() { - if (material_mutex) - material_mutex->lock(); + MutexLock lock(material_mutex); while (dirty_materials->first()) { dirty_materials->first()->self()->_update_shader(); } - - if (material_mutex) - material_mutex->unlock(); } void CanvasItemMaterial::_queue_shader_change() { - if (material_mutex) - material_mutex->lock(); + MutexLock lock(material_mutex); if (!element.in_list()) { dirty_materials->add(&element); } - - if (material_mutex) - material_mutex->unlock(); } bool CanvasItemMaterial::_is_shader_dirty() const { - bool dirty = false; - - if (material_mutex) - material_mutex->lock(); - - dirty = element.in_list(); + MutexLock lock(material_mutex); - if (material_mutex) - material_mutex->unlock(); - - return dirty; + return element.in_list(); } void CanvasItemMaterial::set_blend_mode(BlendMode p_blend_mode) { @@ -332,8 +308,7 @@ CanvasItemMaterial::CanvasItemMaterial() : CanvasItemMaterial::~CanvasItemMaterial() { - if (material_mutex) - material_mutex->lock(); + MutexLock lock(material_mutex); if (shader_map.has(current_key)) { shader_map[current_key].users--; @@ -345,9 +320,6 @@ CanvasItemMaterial::~CanvasItemMaterial() { VS::get_singleton()->material_set_shader(_get_material(), RID()); } - - if (material_mutex) - material_mutex->unlock(); } /////////////////////////////////////////////////////////////////// diff --git a/scene/2d/canvas_item.h b/scene/2d/canvas_item.h index 3cd8e6ef74..c7f9500ea1 100644 --- a/scene/2d/canvas_item.h +++ b/scene/2d/canvas_item.h @@ -108,7 +108,7 @@ private: return mk; } - static Mutex *material_mutex; + static Mutex material_mutex; static SelfList<CanvasItemMaterial>::List *dirty_materials; SelfList<CanvasItemMaterial> element; diff --git a/scene/2d/cpu_particles_2d.cpp b/scene/2d/cpu_particles_2d.cpp index 35df6c8945..f781f06b0f 100644 --- a/scene/2d/cpu_particles_2d.cpp +++ b/scene/2d/cpu_particles_2d.cpp @@ -970,118 +970,103 @@ void CPUParticles2D::_particles_process(float p_delta) { } void CPUParticles2D::_update_particle_data_buffer() { -#ifndef NO_THREADS - update_mutex->lock(); -#endif + MutexLock lock(update_mutex); - { - - int pc = particles.size(); + int pc = particles.size(); - int *ow; - int *order = NULL; + int *ow; + int *order = NULL; - float *w = particle_data.ptrw(); - const Particle *r = particles.ptr(); - float *ptr = w; + float *w = particle_data.ptrw(); + const Particle *r = particles.ptr(); + float *ptr = w; - if (draw_order != DRAW_ORDER_INDEX) { - ow = particle_order.ptrw(); - order = ow; + if (draw_order != DRAW_ORDER_INDEX) { + ow = particle_order.ptrw(); + order = ow; - for (int i = 0; i < pc; i++) { - order[i] = i; - } - if (draw_order == DRAW_ORDER_LIFETIME) { - SortArray<int, SortLifetime> sorter; - sorter.compare.particles = r; - sorter.sort(order, pc); - } + for (int i = 0; i < pc; i++) { + order[i] = i; + } + if (draw_order == DRAW_ORDER_LIFETIME) { + SortArray<int, SortLifetime> sorter; + sorter.compare.particles = r; + sorter.sort(order, pc); } + } - for (int i = 0; i < pc; i++) { + for (int i = 0; i < pc; i++) { - int idx = order ? order[i] : i; + int idx = order ? order[i] : i; - Transform2D t = r[idx].transform; + Transform2D t = r[idx].transform; - if (!local_coords) { - t = inv_emission_transform * t; - } + if (!local_coords) { + t = inv_emission_transform * t; + } - if (r[idx].active) { + if (r[idx].active) { - ptr[0] = t.elements[0][0]; - ptr[1] = t.elements[1][0]; - ptr[2] = 0; - ptr[3] = t.elements[2][0]; - ptr[4] = t.elements[0][1]; - ptr[5] = t.elements[1][1]; - ptr[6] = 0; - ptr[7] = t.elements[2][1]; + ptr[0] = t.elements[0][0]; + ptr[1] = t.elements[1][0]; + ptr[2] = 0; + ptr[3] = t.elements[2][0]; + ptr[4] = t.elements[0][1]; + ptr[5] = t.elements[1][1]; + ptr[6] = 0; + ptr[7] = t.elements[2][1]; - } else { - zeromem(ptr, sizeof(float) * 8); - } + } else { + zeromem(ptr, sizeof(float) * 8); + } - Color c = r[idx].color; + Color c = r[idx].color; - ptr[8] = c.r; - ptr[9] = c.g; - ptr[10] = c.b; - ptr[11] = c.a; + ptr[8] = c.r; + ptr[9] = c.g; + ptr[10] = c.b; + ptr[11] = c.a; - ptr[12] = r[idx].custom[0]; - ptr[13] = r[idx].custom[1]; - ptr[14] = r[idx].custom[2]; - ptr[15] = r[idx].custom[3]; + ptr[12] = r[idx].custom[0]; + ptr[13] = r[idx].custom[1]; + ptr[14] = r[idx].custom[2]; + ptr[15] = r[idx].custom[3]; - ptr += 16; - } + ptr += 16; } - -#ifndef NO_THREADS - update_mutex->unlock(); -#endif } void CPUParticles2D::_set_redraw(bool p_redraw) { if (redraw == p_redraw) return; redraw = p_redraw; -#ifndef NO_THREADS - update_mutex->lock(); -#endif - if (redraw) { - VS::get_singleton()->connect_compat("frame_pre_draw", this, "_update_render_thread"); - VS::get_singleton()->canvas_item_set_update_when_visible(get_canvas_item(), true); - - VS::get_singleton()->multimesh_set_visible_instances(multimesh, -1); - } else { - if (VS::get_singleton()->is_connected_compat("frame_pre_draw", this, "_update_render_thread")) { - VS::get_singleton()->disconnect_compat("frame_pre_draw", this, "_update_render_thread"); - } - VS::get_singleton()->canvas_item_set_update_when_visible(get_canvas_item(), false); - VS::get_singleton()->multimesh_set_visible_instances(multimesh, 0); + { + MutexLock lock(update_mutex); + + if (redraw) { + VS::get_singleton()->connect_compat("frame_pre_draw", this, "_update_render_thread"); + VS::get_singleton()->canvas_item_set_update_when_visible(get_canvas_item(), true); + + VS::get_singleton()->multimesh_set_visible_instances(multimesh, -1); + } else { + if (VS::get_singleton()->is_connected_compat("frame_pre_draw", this, "_update_render_thread")) { + VS::get_singleton()->disconnect_compat("frame_pre_draw", this, "_update_render_thread"); + } + VS::get_singleton()->canvas_item_set_update_when_visible(get_canvas_item(), false); + + VS::get_singleton()->multimesh_set_visible_instances(multimesh, 0); + } } -#ifndef NO_THREADS - update_mutex->unlock(); -#endif + update(); // redraw to update render list } void CPUParticles2D::_update_render_thread() { -#ifndef NO_THREADS - update_mutex->lock(); -#endif + MutexLock lock(update_mutex); VS::get_singleton()->multimesh_set_buffer(multimesh, particle_data); - -#ifndef NO_THREADS - update_mutex->unlock(); -#endif } void CPUParticles2D::_notification(int p_what) { @@ -1494,18 +1479,10 @@ CPUParticles2D::CPUParticles2D() { set_color(Color(1, 1, 1, 1)); -#ifndef NO_THREADS - update_mutex = Mutex::create(); -#endif - _update_mesh_texture(); } CPUParticles2D::~CPUParticles2D() { VS::get_singleton()->free(multimesh); VS::get_singleton()->free(mesh); - -#ifndef NO_THREADS - memdelete(update_mutex); -#endif } diff --git a/scene/2d/cpu_particles_2d.h b/scene/2d/cpu_particles_2d.h index 6f85631fe1..18d0caceed 100644 --- a/scene/2d/cpu_particles_2d.h +++ b/scene/2d/cpu_particles_2d.h @@ -178,7 +178,7 @@ private: void _particles_process(float p_delta); void _update_particle_data_buffer(); - Mutex *update_mutex; + Mutex update_mutex; void _update_render_thread(); diff --git a/scene/2d/navigation_polygon.cpp b/scene/2d/navigation_polygon.cpp index 6754c1c9a6..41f29c4072 100644 --- a/scene/2d/navigation_polygon.cpp +++ b/scene/2d/navigation_polygon.cpp @@ -82,9 +82,10 @@ bool NavigationPolygon::_edit_is_selected_on_click(const Point2 &p_point, double void NavigationPolygon::set_vertices(const Vector<Vector2> &p_vertices) { - navmesh_generation->lock(); - navmesh.unref(); - navmesh_generation->unlock(); + { + MutexLock lock(navmesh_generation); + navmesh.unref(); + } vertices = p_vertices; rect_cache_dirty = true; } @@ -96,9 +97,10 @@ Vector<Vector2> NavigationPolygon::get_vertices() const { void NavigationPolygon::_set_polygons(const Array &p_array) { - navmesh_generation->lock(); - navmesh.unref(); - navmesh_generation->unlock(); + { + MutexLock lock(navmesh_generation); + navmesh.unref(); + } polygons.resize(p_array.size()); for (int i = 0; i < p_array.size(); i++) { polygons.write[i].indices = p_array[i]; @@ -141,9 +143,10 @@ void NavigationPolygon::add_polygon(const Vector<int> &p_polygon) { Polygon polygon; polygon.indices = p_polygon; polygons.push_back(polygon); - navmesh_generation->lock(); - navmesh.unref(); - navmesh_generation->unlock(); + { + MutexLock lock(navmesh_generation); + navmesh.unref(); + } } void NavigationPolygon::add_outline_at_index(const Vector<Vector2> &p_outline, int p_index) { @@ -164,13 +167,15 @@ Vector<int> NavigationPolygon::get_polygon(int p_idx) { void NavigationPolygon::clear_polygons() { polygons.clear(); - navmesh_generation->lock(); - navmesh.unref(); - navmesh_generation->unlock(); + { + MutexLock lock(navmesh_generation); + navmesh.unref(); + } } Ref<NavigationMesh> NavigationPolygon::get_mesh() { - navmesh_generation->lock(); + MutexLock lock(navmesh_generation); + if (navmesh.is_null()) { navmesh.instance(); Vector<Vector3> verts; @@ -190,7 +195,7 @@ Ref<NavigationMesh> NavigationPolygon::get_mesh() { navmesh->add_polygon(get_polygon(i)); } } - navmesh_generation->unlock(); + return navmesh; } @@ -230,9 +235,10 @@ void NavigationPolygon::clear_outlines() { } void NavigationPolygon::make_polygons_from_outlines() { - navmesh_generation->lock(); - navmesh.unref(); - navmesh_generation->unlock(); + { + MutexLock lock(navmesh_generation); + navmesh.unref(); + } List<TriangulatorPoly> in_poly, out_poly; Vector2 outside_point(-1e10, -1e10); @@ -362,12 +368,10 @@ void NavigationPolygon::_bind_methods() { } NavigationPolygon::NavigationPolygon() : - rect_cache_dirty(true), - navmesh_generation(Mutex::create()) { + rect_cache_dirty(true) { } NavigationPolygon::~NavigationPolygon() { - memdelete(navmesh_generation); } void NavigationPolygonInstance::set_enabled(bool p_enabled) { diff --git a/scene/2d/navigation_polygon.h b/scene/2d/navigation_polygon.h index 557ce4b3e7..70804358f6 100644 --- a/scene/2d/navigation_polygon.h +++ b/scene/2d/navigation_polygon.h @@ -34,8 +34,6 @@ #include "scene/2d/node_2d.h" #include "scene/resources/navigation_mesh.h" -class Mutex; - class NavigationPolygon : public Resource { GDCLASS(NavigationPolygon, Resource); @@ -50,7 +48,7 @@ class NavigationPolygon : public Resource { mutable Rect2 item_rect; mutable bool rect_cache_dirty; - Mutex *navmesh_generation; + Mutex navmesh_generation; // Navigation mesh Ref<NavigationMesh> navmesh; diff --git a/scene/3d/cpu_particles.cpp b/scene/3d/cpu_particles.cpp index cddbe4bbbb..eefda96caa 100644 --- a/scene/3d/cpu_particles.cpp +++ b/scene/3d/cpu_particles.cpp @@ -1017,140 +1017,125 @@ void CPUParticles::_particles_process(float p_delta) { } void CPUParticles::_update_particle_data_buffer() { -#ifndef NO_THREADS - update_mutex->lock(); -#endif + MutexLock lock(update_mutex); - { + int pc = particles.size(); - int pc = particles.size(); + int *ow; + int *order = NULL; - int *ow; - int *order = NULL; + float *w = particle_data.ptrw(); + const Particle *r = particles.ptr(); + float *ptr = w; - float *w = particle_data.ptrw(); - const Particle *r = particles.ptr(); - float *ptr = w; + if (draw_order != DRAW_ORDER_INDEX) { + ow = particle_order.ptrw(); + order = ow; - if (draw_order != DRAW_ORDER_INDEX) { - ow = particle_order.ptrw(); - order = ow; + for (int i = 0; i < pc; i++) { + order[i] = i; + } + if (draw_order == DRAW_ORDER_LIFETIME) { + SortArray<int, SortLifetime> sorter; + sorter.compare.particles = r; + sorter.sort(order, pc); + } else if (draw_order == DRAW_ORDER_VIEW_DEPTH) { + Camera *c = get_viewport()->get_camera(); + if (c) { + Vector3 dir = c->get_global_transform().basis.get_axis(2); //far away to close + + if (local_coords) { + + // will look different from Particles in editor as this is based on the camera in the scenetree + // and not the editor camera + dir = inv_emission_transform.xform(dir).normalized(); + } else { + dir = dir.normalized(); + } - for (int i = 0; i < pc; i++) { - order[i] = i; - } - if (draw_order == DRAW_ORDER_LIFETIME) { - SortArray<int, SortLifetime> sorter; + SortArray<int, SortAxis> sorter; sorter.compare.particles = r; + sorter.compare.axis = dir; sorter.sort(order, pc); - } else if (draw_order == DRAW_ORDER_VIEW_DEPTH) { - Camera *c = get_viewport()->get_camera(); - if (c) { - Vector3 dir = c->get_global_transform().basis.get_axis(2); //far away to close - - if (local_coords) { - - // will look different from Particles in editor as this is based on the camera in the scenetree - // and not the editor camera - dir = inv_emission_transform.xform(dir).normalized(); - } else { - dir = dir.normalized(); - } - - SortArray<int, SortAxis> sorter; - sorter.compare.particles = r; - sorter.compare.axis = dir; - sorter.sort(order, pc); - } } } + } - for (int i = 0; i < pc; i++) { - - int idx = order ? order[i] : i; + for (int i = 0; i < pc; i++) { - Transform t = r[idx].transform; + int idx = order ? order[i] : i; - if (!local_coords) { - t = inv_emission_transform * t; - } + Transform t = r[idx].transform; - if (r[idx].active) { - ptr[0] = t.basis.elements[0][0]; - ptr[1] = t.basis.elements[0][1]; - ptr[2] = t.basis.elements[0][2]; - ptr[3] = t.origin.x; - ptr[4] = t.basis.elements[1][0]; - ptr[5] = t.basis.elements[1][1]; - ptr[6] = t.basis.elements[1][2]; - ptr[7] = t.origin.y; - ptr[8] = t.basis.elements[2][0]; - ptr[9] = t.basis.elements[2][1]; - ptr[10] = t.basis.elements[2][2]; - ptr[11] = t.origin.z; - } else { - zeromem(ptr, sizeof(float) * 12); - } + if (!local_coords) { + t = inv_emission_transform * t; + } - Color c = r[idx].color; + if (r[idx].active) { + ptr[0] = t.basis.elements[0][0]; + ptr[1] = t.basis.elements[0][1]; + ptr[2] = t.basis.elements[0][2]; + ptr[3] = t.origin.x; + ptr[4] = t.basis.elements[1][0]; + ptr[5] = t.basis.elements[1][1]; + ptr[6] = t.basis.elements[1][2]; + ptr[7] = t.origin.y; + ptr[8] = t.basis.elements[2][0]; + ptr[9] = t.basis.elements[2][1]; + ptr[10] = t.basis.elements[2][2]; + ptr[11] = t.origin.z; + } else { + zeromem(ptr, sizeof(float) * 12); + } - ptr[12] = c.r; - ptr[13] = c.g; - ptr[14] = c.b; - ptr[15] = c.a; + Color c = r[idx].color; - ptr[16] = r[idx].custom[0]; - ptr[17] = r[idx].custom[1]; - ptr[18] = r[idx].custom[2]; - ptr[19] = r[idx].custom[3]; + ptr[12] = c.r; + ptr[13] = c.g; + ptr[14] = c.b; + ptr[15] = c.a; - ptr += 20; - } + ptr[16] = r[idx].custom[0]; + ptr[17] = r[idx].custom[1]; + ptr[18] = r[idx].custom[2]; + ptr[19] = r[idx].custom[3]; - can_update = true; + ptr += 20; } -#ifndef NO_THREADS - update_mutex->unlock(); -#endif + can_update = true; } void CPUParticles::_set_redraw(bool p_redraw) { if (redraw == p_redraw) return; redraw = p_redraw; -#ifndef NO_THREADS - update_mutex->lock(); -#endif - if (redraw) { - VS::get_singleton()->connect_compat("frame_pre_draw", this, "_update_render_thread"); - VS::get_singleton()->instance_geometry_set_flag(get_instance(), VS::INSTANCE_FLAG_DRAW_NEXT_FRAME_IF_VISIBLE, true); - VS::get_singleton()->multimesh_set_visible_instances(multimesh, -1); - } else { - if (VS::get_singleton()->is_connected_compat("frame_pre_draw", this, "_update_render_thread")) { - VS::get_singleton()->disconnect_compat("frame_pre_draw", this, "_update_render_thread"); + + { + MutexLock lock(update_mutex); + + if (redraw) { + VS::get_singleton()->connect_compat("frame_pre_draw", this, "_update_render_thread"); + VS::get_singleton()->instance_geometry_set_flag(get_instance(), VS::INSTANCE_FLAG_DRAW_NEXT_FRAME_IF_VISIBLE, true); + VS::get_singleton()->multimesh_set_visible_instances(multimesh, -1); + } else { + if (VS::get_singleton()->is_connected_compat("frame_pre_draw", this, "_update_render_thread")) { + VS::get_singleton()->disconnect_compat("frame_pre_draw", this, "_update_render_thread"); + } + VS::get_singleton()->instance_geometry_set_flag(get_instance(), VS::INSTANCE_FLAG_DRAW_NEXT_FRAME_IF_VISIBLE, false); + VS::get_singleton()->multimesh_set_visible_instances(multimesh, 0); } - VS::get_singleton()->instance_geometry_set_flag(get_instance(), VS::INSTANCE_FLAG_DRAW_NEXT_FRAME_IF_VISIBLE, false); - VS::get_singleton()->multimesh_set_visible_instances(multimesh, 0); } -#ifndef NO_THREADS - update_mutex->unlock(); -#endif } void CPUParticles::_update_render_thread() { -#ifndef NO_THREADS - update_mutex->lock(); -#endif + MutexLock lock(update_mutex); + if (can_update) { VS::get_singleton()->multimesh_set_buffer(multimesh, particle_data); can_update = false; //wait for next time } - -#ifndef NO_THREADS - update_mutex->unlock(); -#endif } void CPUParticles::_notification(int p_what) { @@ -1556,16 +1541,8 @@ CPUParticles::CPUParticles() { can_update = false; set_color(Color(1, 1, 1, 1)); - -#ifndef NO_THREADS - update_mutex = Mutex::create(); -#endif } CPUParticles::~CPUParticles() { VS::get_singleton()->free(multimesh); - -#ifndef NO_THREADS - memdelete(update_mutex); -#endif } diff --git a/scene/3d/cpu_particles.h b/scene/3d/cpu_particles.h index 1a5537e4f2..231e1f1ad9 100644 --- a/scene/3d/cpu_particles.h +++ b/scene/3d/cpu_particles.h @@ -178,7 +178,7 @@ private: void _particles_process(float p_delta); void _update_particle_data_buffer(); - Mutex *update_mutex; + Mutex update_mutex; void _update_render_thread(); diff --git a/scene/resources/dynamic_font.cpp b/scene/resources/dynamic_font.cpp index 79a1500129..fc53dfe376 100644 --- a/scene/resources/dynamic_font.cpp +++ b/scene/resources/dynamic_font.cpp @@ -990,7 +990,7 @@ void DynamicFont::_bind_methods() { BIND_ENUM_CONSTANT(SPACING_SPACE); } -Mutex *DynamicFont::dynamic_font_mutex = NULL; +Mutex DynamicFont::dynamic_font_mutex; SelfList<DynamicFont>::List *DynamicFont::dynamic_fonts = NULL; @@ -1004,29 +1004,21 @@ DynamicFont::DynamicFont() : spacing_char = 0; spacing_space = 0; outline_color = Color(1, 1, 1); - if (dynamic_font_mutex) { - dynamic_font_mutex->lock(); - dynamic_fonts->add(&font_list); - dynamic_font_mutex->unlock(); - } + + MutexLock lock(dynamic_font_mutex); + dynamic_fonts->add(&font_list); } DynamicFont::~DynamicFont() { - if (dynamic_font_mutex) { - dynamic_font_mutex->lock(); - dynamic_fonts->remove(&font_list); - dynamic_font_mutex->unlock(); - } + MutexLock lock(dynamic_font_mutex); + dynamic_fonts->remove(&font_list); } void DynamicFont::initialize_dynamic_fonts() { dynamic_fonts = memnew(SelfList<DynamicFont>::List()); - dynamic_font_mutex = Mutex::create(); } void DynamicFont::finish_dynamic_fonts() { - memdelete(dynamic_font_mutex); - dynamic_font_mutex = NULL; memdelete(dynamic_fonts); dynamic_fonts = NULL; } @@ -1034,39 +1026,36 @@ void DynamicFont::finish_dynamic_fonts() { void DynamicFont::update_oversampling() { Vector<Ref<DynamicFont> > changed; + { + MutexLock lock(dynamic_font_mutex); - if (dynamic_font_mutex) - dynamic_font_mutex->lock(); - - SelfList<DynamicFont> *E = dynamic_fonts->first(); - while (E) { + SelfList<DynamicFont> *E = dynamic_fonts->first(); + while (E) { - if (E->self()->data_at_size.is_valid()) { - E->self()->data_at_size->update_oversampling(); + if (E->self()->data_at_size.is_valid()) { + E->self()->data_at_size->update_oversampling(); - if (E->self()->outline_data_at_size.is_valid()) { - E->self()->outline_data_at_size->update_oversampling(); - } + if (E->self()->outline_data_at_size.is_valid()) { + E->self()->outline_data_at_size->update_oversampling(); + } - for (int i = 0; i < E->self()->fallback_data_at_size.size(); i++) { - if (E->self()->fallback_data_at_size[i].is_valid()) { - E->self()->fallback_data_at_size.write[i]->update_oversampling(); + for (int i = 0; i < E->self()->fallback_data_at_size.size(); i++) { + if (E->self()->fallback_data_at_size[i].is_valid()) { + E->self()->fallback_data_at_size.write[i]->update_oversampling(); - if (E->self()->has_outline() && E->self()->fallback_outline_data_at_size[i].is_valid()) { - E->self()->fallback_outline_data_at_size.write[i]->update_oversampling(); + if (E->self()->has_outline() && E->self()->fallback_outline_data_at_size[i].is_valid()) { + E->self()->fallback_outline_data_at_size.write[i]->update_oversampling(); + } } } + + changed.push_back(Ref<DynamicFont>(E->self())); } - changed.push_back(Ref<DynamicFont>(E->self())); + E = E->next(); } - - E = E->next(); } - if (dynamic_font_mutex) - dynamic_font_mutex->unlock(); - for (int i = 0; i < changed.size(); i++) { changed.write[i]->emit_changed(); } diff --git a/scene/resources/dynamic_font.h b/scene/resources/dynamic_font.h index fa6db370f8..6a0b51fb93 100644 --- a/scene/resources/dynamic_font.h +++ b/scene/resources/dynamic_font.h @@ -285,7 +285,7 @@ public: SelfList<DynamicFont> font_list; - static Mutex *dynamic_font_mutex; + static Mutex dynamic_font_mutex; static SelfList<DynamicFont>::List *dynamic_fonts; static void initialize_dynamic_fonts(); diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp index ff51cab0a4..54e9067abb 100644 --- a/scene/resources/material.cpp +++ b/scene/resources/material.cpp @@ -290,17 +290,13 @@ ShaderMaterial::~ShaderMaterial() { ///////////////////////////////// -Mutex *BaseMaterial3D::material_mutex = NULL; +Mutex BaseMaterial3D::material_mutex; SelfList<BaseMaterial3D>::List *BaseMaterial3D::dirty_materials = NULL; Map<BaseMaterial3D::MaterialKey, BaseMaterial3D::ShaderData> BaseMaterial3D::shader_map; BaseMaterial3D::ShaderNames *BaseMaterial3D::shader_names = NULL; void BaseMaterial3D::init_shaders() { -#ifndef NO_THREADS - material_mutex = Mutex::create(); -#endif - dirty_materials = memnew(SelfList<BaseMaterial3D>::List); shader_names = memnew(ShaderNames); @@ -379,10 +375,6 @@ void BaseMaterial3D::finish_shaders() { materials_for_2d[i].unref(); } -#ifndef NO_THREADS - memdelete(material_mutex); -#endif - memdelete(dirty_materials); dirty_materials = NULL; @@ -1133,44 +1125,28 @@ void BaseMaterial3D::_update_shader() { void BaseMaterial3D::flush_changes() { - if (material_mutex) - material_mutex->lock(); + MutexLock lock(material_mutex); while (dirty_materials->first()) { dirty_materials->first()->self()->_update_shader(); } - - if (material_mutex) - material_mutex->unlock(); } void BaseMaterial3D::_queue_shader_change() { - if (material_mutex) - material_mutex->lock(); + MutexLock lock(material_mutex); if (!element.in_list()) { dirty_materials->add(&element); } - - if (material_mutex) - material_mutex->unlock(); } bool BaseMaterial3D::_is_shader_dirty() const { - bool dirty = false; - - if (material_mutex) - material_mutex->lock(); - - dirty = element.in_list(); + MutexLock lock(material_mutex); - if (material_mutex) - material_mutex->unlock(); - - return dirty; + return element.in_list(); } void BaseMaterial3D::set_albedo(const Color &p_albedo) { @@ -2580,8 +2556,7 @@ BaseMaterial3D::BaseMaterial3D(bool p_orm) : BaseMaterial3D::~BaseMaterial3D() { - if (material_mutex) - material_mutex->lock(); + MutexLock lock(material_mutex); if (shader_map.has(current_key)) { shader_map[current_key].users--; @@ -2593,9 +2568,6 @@ BaseMaterial3D::~BaseMaterial3D() { VS::get_singleton()->material_set_shader(_get_material(), RID()); } - - if (material_mutex) - material_mutex->unlock(); } ////////////////////// diff --git a/scene/resources/material.h b/scene/resources/material.h index 927334c74d..fc77226fb9 100644 --- a/scene/resources/material.h +++ b/scene/resources/material.h @@ -388,7 +388,7 @@ private: StringName texture_names[TEXTURE_MAX]; }; - static Mutex *material_mutex; + static Mutex material_mutex; static SelfList<BaseMaterial3D>::List *dirty_materials; static ShaderNames *shader_names; diff --git a/scene/resources/particles_material.cpp b/scene/resources/particles_material.cpp index e820aec2ed..f18e8956f1 100644 --- a/scene/resources/particles_material.cpp +++ b/scene/resources/particles_material.cpp @@ -30,17 +30,13 @@ #include "particles_material.h" -Mutex *ParticlesMaterial::material_mutex = NULL; +Mutex ParticlesMaterial::material_mutex; SelfList<ParticlesMaterial>::List *ParticlesMaterial::dirty_materials = NULL; Map<ParticlesMaterial::MaterialKey, ParticlesMaterial::ShaderData> ParticlesMaterial::shader_map; ParticlesMaterial::ShaderNames *ParticlesMaterial::shader_names = NULL; void ParticlesMaterial::init_shaders() { -#ifndef NO_THREADS - material_mutex = Mutex::create(); -#endif - dirty_materials = memnew(SelfList<ParticlesMaterial>::List); shader_names = memnew(ShaderNames); @@ -107,10 +103,6 @@ void ParticlesMaterial::init_shaders() { void ParticlesMaterial::finish_shaders() { -#ifndef NO_THREADS - memdelete(material_mutex); -#endif - memdelete(dirty_materials); dirty_materials = NULL; @@ -612,44 +604,28 @@ void ParticlesMaterial::_update_shader() { void ParticlesMaterial::flush_changes() { - if (material_mutex) - material_mutex->lock(); + MutexLock lock(material_mutex); while (dirty_materials->first()) { dirty_materials->first()->self()->_update_shader(); } - - if (material_mutex) - material_mutex->unlock(); } void ParticlesMaterial::_queue_shader_change() { - if (material_mutex) - material_mutex->lock(); + MutexLock lock(material_mutex); if (!element.in_list()) { dirty_materials->add(&element); } - - if (material_mutex) - material_mutex->unlock(); } bool ParticlesMaterial::_is_shader_dirty() const { - bool dirty = false; + MutexLock lock(material_mutex); - if (material_mutex) - material_mutex->lock(); - - dirty = element.in_list(); - - if (material_mutex) - material_mutex->unlock(); - - return dirty; + return element.in_list(); } void ParticlesMaterial::set_direction(Vector3 p_direction) { @@ -1298,8 +1274,7 @@ ParticlesMaterial::ParticlesMaterial() : ParticlesMaterial::~ParticlesMaterial() { - if (material_mutex) - material_mutex->lock(); + MutexLock lock(material_mutex); if (shader_map.has(current_key)) { shader_map[current_key].users--; @@ -1311,7 +1286,4 @@ ParticlesMaterial::~ParticlesMaterial() { VS::get_singleton()->material_set_shader(_get_material(), RID()); } - - if (material_mutex) - material_mutex->unlock(); } diff --git a/scene/resources/particles_material.h b/scene/resources/particles_material.h index 246ce58a21..c6c8316995 100644 --- a/scene/resources/particles_material.h +++ b/scene/resources/particles_material.h @@ -126,7 +126,7 @@ private: return mk; } - static Mutex *material_mutex; + static Mutex material_mutex; static SelfList<ParticlesMaterial>::List *dirty_materials; struct ShaderNames { |