diff options
Diffstat (limited to 'scene/2d')
-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 |
6 files changed, 97 insertions, 146 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; |