summaryrefslogtreecommitdiff
path: root/scene/resources/particles_material.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/resources/particles_material.cpp')
-rw-r--r--scene/resources/particles_material.cpp40
1 files changed, 6 insertions, 34 deletions
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();
}