summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
authorPedro J. Estébanez <pedrojrulez@gmail.com>2021-02-10 19:22:13 +0100
committerPedro J. Estébanez <pedrojrulez@gmail.com>2021-02-18 17:12:46 +0100
commit8e128726f0eac1982aa75a005554ee5b556b332e (patch)
tree827c2f478e8fb3196ef411f4941fa4e839642e31 /scene
parent8870f43d742e0c48ae543d999856f5989170b62d (diff)
Modernize atomics
- Based on C++11's `atomic` - Reworked `SafeRefCount` (based on the rewrite by @hpvb) - Replaced free atomic functions by the new `SafeNumeric<T>` - Replaced wrong cases of `volatile bool` by the new `SafeFlag` - Platform-specific implementations no longer needed Co-authored-by: Hein-Pieter van Braam-Stewart <hp@tmm.cx>
Diffstat (limited to 'scene')
-rw-r--r--scene/2d/audio_stream_player_2d.cpp56
-rw-r--r--scene/2d/audio_stream_player_2d.h11
-rw-r--r--scene/3d/audio_stream_player_3d.cpp63
-rw-r--r--scene/3d/audio_stream_player_3d.h11
-rw-r--r--scene/3d/cpu_particles_3d.cpp23
-rw-r--r--scene/3d/cpu_particles_3d.h3
-rw-r--r--scene/audio/audio_stream_player.cpp49
-rw-r--r--scene/audio/audio_stream_player.h11
-rw-r--r--scene/main/http_request.cpp34
-rw-r--r--scene/main/http_request.h9
-rw-r--r--scene/resources/visual_shader.cpp11
-rw-r--r--scene/resources/visual_shader.h3
12 files changed, 155 insertions, 129 deletions
diff --git a/scene/2d/audio_stream_player_2d.cpp b/scene/2d/audio_stream_player_2d.cpp
index 79624bf3bf..6d8d6058eb 100644
--- a/scene/2d/audio_stream_player_2d.cpp
+++ b/scene/2d/audio_stream_player_2d.cpp
@@ -35,14 +35,14 @@
#include "scene/main/window.h"
void AudioStreamPlayer2D::_mix_audio() {
- if (!stream_playback.is_valid() || !active ||
+ if (!stream_playback.is_valid() || !active.is_set() ||
(stream_paused && !stream_paused_fade_out)) {
return;
}
- if (setseek >= 0.0) {
- stream_playback->start(setseek);
- setseek = -1.0; //reset seek
+ if (setseek.get() >= 0.0) {
+ stream_playback->start(setseek.get());
+ setseek.set(-1.0); //reset seek
}
//get data
@@ -57,7 +57,8 @@ void AudioStreamPlayer2D::_mix_audio() {
stream_playback->mix(buffer, pitch_scale, buffer_size);
//write all outputs
- for (int i = 0; i < output_count; i++) {
+ int oc = output_count.get();
+ for (int i = 0; i < oc; i++) {
Output current = outputs[i];
//see if current output exists, to keep volume ramp
@@ -130,14 +131,14 @@ void AudioStreamPlayer2D::_mix_audio() {
prev_outputs[i] = current;
}
- prev_output_count = output_count;
+ prev_output_count = oc;
//stream is no longer active, disable this.
if (!stream_playback->is_playing()) {
- active = false;
+ active.clear();
}
- output_ready = false;
+ output_ready.clear();
stream_paused_fade_in = false;
stream_paused_fade_out = false;
}
@@ -168,7 +169,7 @@ void AudioStreamPlayer2D::_notification(int p_what) {
if (p_what == NOTIFICATION_INTERNAL_PHYSICS_PROCESS) {
//update anything related to position first, if possible of course
- if (!output_ready) {
+ if (!output_ready.is_set()) {
List<Viewport *> viewports;
Ref<World2D> world_2d = get_world_2d();
ERR_FAIL_COND(world_2d.is_null());
@@ -240,19 +241,19 @@ void AudioStreamPlayer2D::_notification(int p_what) {
}
}
- output_count = new_output_count;
- output_ready = true;
+ output_count.set(new_output_count);
+ output_ready.set();
}
//start playing if requested
- if (setplay >= 0.0) {
- setseek = setplay;
- active = true;
- setplay = -1;
+ if (setplay.get() >= 0.0) {
+ setseek.set(setplay.get());
+ active.set();
+ setplay.set(-1);
}
//stop playing if no longer active
- if (!active) {
+ if (!active.is_set()) {
set_physics_process_internal(false);
emit_signal("finished");
}
@@ -267,8 +268,8 @@ void AudioStreamPlayer2D::set_stream(Ref<AudioStream> p_stream) {
if (stream_playback.is_valid()) {
stream_playback.unref();
stream.unref();
- active = false;
- setseek = -1;
+ active.clear();
+ setseek.set(-1);
}
if (p_stream.is_valid()) {
@@ -311,29 +312,29 @@ void AudioStreamPlayer2D::play(float p_from_pos) {
}
if (stream_playback.is_valid()) {
- setplay = p_from_pos;
- output_ready = false;
+ setplay.set(p_from_pos);
+ output_ready.clear();
set_physics_process_internal(true);
}
}
void AudioStreamPlayer2D::seek(float p_seconds) {
if (stream_playback.is_valid()) {
- setseek = p_seconds;
+ setseek.set(p_seconds);
}
}
void AudioStreamPlayer2D::stop() {
if (stream_playback.is_valid()) {
- active = false;
+ active.clear();
set_physics_process_internal(false);
- setplay = -1;
+ setplay.set(-1);
}
}
bool AudioStreamPlayer2D::is_playing() const {
if (stream_playback.is_valid()) {
- return active || setplay >= 0;
+ return active.is_set() || setplay.get() >= 0;
}
return false;
@@ -341,8 +342,9 @@ bool AudioStreamPlayer2D::is_playing() const {
float AudioStreamPlayer2D::get_playback_position() {
if (stream_playback.is_valid()) {
- if (setseek >= 0.0) {
- return setseek;
+ float ss = setseek.get();
+ if (ss >= 0.0) {
+ return ss;
}
return stream_playback->get_playback_position();
}
@@ -383,7 +385,7 @@ void AudioStreamPlayer2D::_set_playing(bool p_enable) {
}
bool AudioStreamPlayer2D::_is_active() const {
- return active;
+ return active.is_set();
}
void AudioStreamPlayer2D::_validate_property(PropertyInfo &property) const {
diff --git a/scene/2d/audio_stream_player_2d.h b/scene/2d/audio_stream_player_2d.h
index 6fb8cc414c..21f524c703 100644
--- a/scene/2d/audio_stream_player_2d.h
+++ b/scene/2d/audio_stream_player_2d.h
@@ -31,6 +31,7 @@
#ifndef AUDIO_STREAM_PLAYER_2D_H
#define AUDIO_STREAM_PLAYER_2D_H
+#include "core/templates/safe_refcount.h"
#include "scene/2d/node_2d.h"
#include "servers/audio/audio_stream.h"
#include "servers/audio_server.h"
@@ -52,8 +53,8 @@ private:
};
Output outputs[MAX_OUTPUTS];
- volatile int output_count = 0;
- volatile bool output_ready = false;
+ SafeNumeric<int> output_count;
+ SafeFlag output_ready;
//these are used by audio thread to have a reference of previous volumes (for ramping volume and avoiding clicks)
Output prev_outputs[MAX_OUTPUTS];
@@ -63,9 +64,9 @@ private:
Ref<AudioStream> stream;
Vector<AudioFrame> mix_buffer;
- volatile float setseek = -1.0;
- volatile bool active = false;
- volatile float setplay = -1.0;
+ SafeNumeric<float> setseek{ -1.0 };
+ SafeFlag active;
+ SafeNumeric<float> setplay{ -1.0 };
float volume_db = 0.0;
float pitch_scale = 1.0;
diff --git a/scene/3d/audio_stream_player_3d.cpp b/scene/3d/audio_stream_player_3d.cpp
index dd77221a3f..72392be5bd 100644
--- a/scene/3d/audio_stream_player_3d.cpp
+++ b/scene/3d/audio_stream_player_3d.cpp
@@ -138,15 +138,15 @@ void AudioStreamPlayer3D::_calc_output_vol(const Vector3 &source_dir, real_t tig
}
void AudioStreamPlayer3D::_mix_audio() {
- if (!stream_playback.is_valid() || !active ||
+ if (!stream_playback.is_valid() || !active.is_set() ||
(stream_paused && !stream_paused_fade_out)) {
return;
}
bool started = false;
- if (setseek >= 0.0) {
- stream_playback->start(setseek);
- setseek = -1.0; //reset seek
+ if (setseek.get() >= 0.0) {
+ stream_playback->start(setseek.get());
+ setseek.set(-1.0); //reset seek
started = true;
}
@@ -160,14 +160,14 @@ void AudioStreamPlayer3D::_mix_audio() {
}
// Mix if we're not paused or we're fading out
- if ((output_count > 0 || out_of_range_mode == OUT_OF_RANGE_MIX)) {
+ if ((output_count.get() > 0 || out_of_range_mode == OUT_OF_RANGE_MIX)) {
float output_pitch_scale = 0.0;
- if (output_count) {
+ if (output_count.get()) {
//used for doppler, not realistic but good enough
- for (int i = 0; i < output_count; i++) {
+ for (int i = 0; i < output_count.get(); i++) {
output_pitch_scale += outputs[i].pitch_scale;
}
- output_pitch_scale /= float(output_count);
+ output_pitch_scale /= float(output_count.get());
} else {
output_pitch_scale = 1.0;
}
@@ -176,7 +176,7 @@ void AudioStreamPlayer3D::_mix_audio() {
}
//write all outputs
- for (int i = 0; i < output_count; i++) {
+ for (int i = 0; i < output_count.get(); i++) {
Output current = outputs[i];
//see if current output exists, to keep volume ramp
@@ -285,14 +285,14 @@ void AudioStreamPlayer3D::_mix_audio() {
prev_outputs[i] = current;
}
- prev_output_count = output_count;
+ prev_output_count = output_count.get();
//stream is no longer active, disable this.
if (!stream_playback->is_playing()) {
- active = false;
+ active.clear();
}
- output_ready = false;
+ output_ready.clear();
stream_paused_fade_in = false;
stream_paused_fade_out = false;
}
@@ -360,7 +360,7 @@ void AudioStreamPlayer3D::_notification(int p_what) {
if (p_what == NOTIFICATION_INTERNAL_PHYSICS_PROCESS) {
//update anything related to position first, if possible of course
- if (!output_ready) {
+ if (!output_ready.is_set()) {
Vector3 linear_velocity;
//compute linear velocity for doppler
@@ -596,19 +596,19 @@ void AudioStreamPlayer3D::_notification(int p_what) {
}
}
- output_count = new_output_count;
- output_ready = true;
+ output_count.set(new_output_count);
+ output_ready.set();
}
//start playing if requested
- if (setplay >= 0.0) {
- setseek = setplay;
- active = true;
- setplay = -1;
+ if (setplay.get() >= 0.0) {
+ setseek.set(setplay.get());
+ active.set();
+ setplay.set(-1);
}
//stop playing if no longer active
- if (!active) {
+ if (!active.is_set()) {
set_physics_process_internal(false);
emit_signal("finished");
}
@@ -623,8 +623,8 @@ void AudioStreamPlayer3D::set_stream(Ref<AudioStream> p_stream) {
if (stream_playback.is_valid()) {
stream_playback.unref();
stream.unref();
- active = false;
- setseek = -1;
+ active.clear();
+ setseek.set(-1);
}
if (p_stream.is_valid()) {
@@ -683,29 +683,29 @@ void AudioStreamPlayer3D::play(float p_from_pos) {
}
if (stream_playback.is_valid()) {
- setplay = p_from_pos;
- output_ready = false;
+ setplay.set(p_from_pos);
+ output_ready.clear();
set_physics_process_internal(true);
}
}
void AudioStreamPlayer3D::seek(float p_seconds) {
if (stream_playback.is_valid()) {
- setseek = p_seconds;
+ setseek.set(p_seconds);
}
}
void AudioStreamPlayer3D::stop() {
if (stream_playback.is_valid()) {
- active = false;
+ active.clear();
set_physics_process_internal(false);
- setplay = -1;
+ setplay.set(-1);
}
}
bool AudioStreamPlayer3D::is_playing() const {
if (stream_playback.is_valid()) {
- return active || setplay >= 0;
+ return active.is_set() || setplay.get() >= 0;
}
return false;
@@ -713,8 +713,9 @@ bool AudioStreamPlayer3D::is_playing() const {
float AudioStreamPlayer3D::get_playback_position() {
if (stream_playback.is_valid()) {
- if (setseek >= 0.0) {
- return setseek;
+ float ss = setseek.get();
+ if (ss >= 0.0) {
+ return ss;
}
return stream_playback->get_playback_position();
}
@@ -755,7 +756,7 @@ void AudioStreamPlayer3D::_set_playing(bool p_enable) {
}
bool AudioStreamPlayer3D::_is_active() const {
- return active;
+ return active.is_set();
}
void AudioStreamPlayer3D::_validate_property(PropertyInfo &property) const {
diff --git a/scene/3d/audio_stream_player_3d.h b/scene/3d/audio_stream_player_3d.h
index 33ed758749..70c535bd89 100644
--- a/scene/3d/audio_stream_player_3d.h
+++ b/scene/3d/audio_stream_player_3d.h
@@ -31,6 +31,7 @@
#ifndef AUDIO_STREAM_PLAYER_3D_H
#define AUDIO_STREAM_PLAYER_3D_H
+#include "core/templates/safe_refcount.h"
#include "scene/3d/node_3d.h"
#include "scene/3d/velocity_tracker_3d.h"
#include "servers/audio/audio_filter_sw.h"
@@ -80,8 +81,8 @@ private:
};
Output outputs[MAX_OUTPUTS];
- volatile int output_count = 0;
- volatile bool output_ready = false;
+ SafeNumeric<int> output_count;
+ SafeFlag output_ready;
//these are used by audio thread to have a reference of previous volumes (for ramping volume and avoiding clicks)
Output prev_outputs[MAX_OUTPUTS];
@@ -91,9 +92,9 @@ private:
Ref<AudioStream> stream;
Vector<AudioFrame> mix_buffer;
- volatile float setseek = -1.0;
- volatile bool active = false;
- volatile float setplay = -1.0;
+ SafeNumeric<float> setseek{ -1.0 };
+ SafeFlag active;
+ SafeNumeric<float> setplay{ -1.0 };
AttenuationModel attenuation_model = ATTENUATION_INVERSE_DISTANCE;
float unit_db = 0.0;
diff --git a/scene/3d/cpu_particles_3d.cpp b/scene/3d/cpu_particles_3d.cpp
index 979c6424b8..d22d7ff3ab 100644
--- a/scene/3d/cpu_particles_3d.cpp
+++ b/scene/3d/cpu_particles_3d.cpp
@@ -1074,7 +1074,7 @@ void CPUParticles3D::_update_particle_data_buffer() {
ptr += 20;
}
- can_update = true;
+ can_update.set();
}
void CPUParticles3D::_set_redraw(bool p_redraw) {
@@ -1103,9 +1103,9 @@ void CPUParticles3D::_set_redraw(bool p_redraw) {
void CPUParticles3D::_update_render_thread() {
MutexLock lock(update_mutex);
- if (can_update) {
+ if (can_update.is_set()) {
RS::get_singleton()->multimesh_set_buffer(multimesh, particle_data);
- can_update = false; //wait for next time
+ can_update.clear(); //wait for next time
}
}
@@ -1167,7 +1167,7 @@ void CPUParticles3D::_notification(int p_what) {
ptr += 20;
}
- can_update = true;
+ can_update.set();
}
}
}
@@ -1468,6 +1468,21 @@ CPUParticles3D::CPUParticles3D() {
set_param(PARAM_HUE_VARIATION, 0);
set_param(PARAM_ANIM_SPEED, 0);
set_param(PARAM_ANIM_OFFSET, 0);
+ set_emission_shape(EMISSION_SHAPE_POINT);
+ set_emission_sphere_radius(1);
+ set_emission_box_extents(Vector3(1, 1, 1));
+
+ set_gravity(Vector3(0, -9.8, 0));
+
+ for (int i = 0; i < PARAM_MAX; i++) {
+ set_param_randomness(Parameter(i), 0);
+ }
+
+ for (int i = 0; i < PARTICLE_FLAG_MAX; i++) {
+ particle_flags[i] = false;
+ }
+
+ set_color(Color(1, 1, 1, 1));
}
CPUParticles3D::~CPUParticles3D() {
diff --git a/scene/3d/cpu_particles_3d.h b/scene/3d/cpu_particles_3d.h
index 4af959a7bf..10ac32622d 100644
--- a/scene/3d/cpu_particles_3d.h
+++ b/scene/3d/cpu_particles_3d.h
@@ -32,6 +32,7 @@
#define CPU_PARTICLES_H
#include "core/templates/rid.h"
+#include "core/templates/safe_refcount.h"
#include "scene/3d/visual_instance_3d.h"
class CPUParticles3D : public GeometryInstance3D {
@@ -142,7 +143,7 @@ private:
Transform inv_emission_transform;
- volatile bool can_update = false;
+ SafeFlag can_update;
DrawOrder draw_order = DRAW_ORDER_INDEX;
diff --git a/scene/audio/audio_stream_player.cpp b/scene/audio/audio_stream_player.cpp
index ec0a4b8696..7957571ab7 100644
--- a/scene/audio/audio_stream_player.cpp
+++ b/scene/audio/audio_stream_player.cpp
@@ -99,7 +99,7 @@ void AudioStreamPlayer::_mix_audio() {
use_fadeout = false;
}
- if (!stream_playback.is_valid() || !active ||
+ if (!stream_playback.is_valid() || !active.is_set() ||
(stream_paused && !stream_paused_fade)) {
return;
}
@@ -112,24 +112,24 @@ void AudioStreamPlayer::_mix_audio() {
return;
}
- if (setstop) {
+ if (setstop.is_set()) {
_mix_internal(true);
stream_playback->stop();
- setstop = false;
+ setstop.clear();
}
- if (setseek >= 0.0 && !stop_has_priority) {
+ if (setseek.get() >= 0.0 && !stop_has_priority.is_set()) {
if (stream_playback->is_playing()) {
//fade out to avoid pops
_mix_internal(true);
}
- stream_playback->start(setseek);
- setseek = -1.0; //reset seek
+ stream_playback->start(setseek.get());
+ setseek.set(-1.0); //reset seek
mix_volume_db = volume_db; //reset ramp
}
- stop_has_priority = false;
+ stop_has_priority.clear();
_mix_internal(false);
}
@@ -143,8 +143,8 @@ void AudioStreamPlayer::_notification(int p_what) {
}
if (p_what == NOTIFICATION_INTERNAL_PROCESS) {
- if (!active || (setseek < 0 && !stream_playback->is_playing())) {
- active = false;
+ if (!active.is_set() || (setseek.get() < 0 && !stream_playback->is_playing())) {
+ active.clear();
set_process_internal(false);
emit_signal("finished");
}
@@ -169,7 +169,7 @@ void AudioStreamPlayer::_notification(int p_what) {
void AudioStreamPlayer::set_stream(Ref<AudioStream> p_stream) {
AudioServer::get_singleton()->lock();
- if (active && stream_playback.is_valid() && !stream_paused) {
+ if (active.is_set() && stream_playback.is_valid() && !stream_paused) {
//changing streams out of the blue is not a great idea, but at least
//lets try to somehow avoid a click
@@ -196,9 +196,9 @@ void AudioStreamPlayer::set_stream(Ref<AudioStream> p_stream) {
if (stream_playback.is_valid()) {
stream_playback.unref();
stream.unref();
- active = false;
- setseek = -1;
- setstop = false;
+ active.clear();
+ setseek.set(-1);
+ setstop.clear();
}
if (p_stream.is_valid()) {
@@ -237,29 +237,29 @@ float AudioStreamPlayer::get_pitch_scale() const {
void AudioStreamPlayer::play(float p_from_pos) {
if (stream_playback.is_valid()) {
//mix_volume_db = volume_db; do not reset volume ramp here, can cause clicks
- setseek = p_from_pos;
- stop_has_priority = false;
- active = true;
+ setseek.set(p_from_pos);
+ stop_has_priority.clear();
+ active.set();
set_process_internal(true);
}
}
void AudioStreamPlayer::seek(float p_seconds) {
if (stream_playback.is_valid()) {
- setseek = p_seconds;
+ setseek.set(p_seconds);
}
}
void AudioStreamPlayer::stop() {
- if (stream_playback.is_valid() && active) {
- setstop = true;
- stop_has_priority = true;
+ if (stream_playback.is_valid() && active.is_set()) {
+ setstop.set();
+ stop_has_priority.set();
}
}
bool AudioStreamPlayer::is_playing() const {
if (stream_playback.is_valid()) {
- return active && !setstop; //&& stream_playback->is_playing();
+ return active.is_set() && !setstop.is_set(); //&& stream_playback->is_playing();
}
return false;
@@ -267,8 +267,9 @@ bool AudioStreamPlayer::is_playing() const {
float AudioStreamPlayer::get_playback_position() {
if (stream_playback.is_valid()) {
- if (setseek >= 0.0) {
- return setseek;
+ float ss = setseek.get();
+ if (ss >= 0.0) {
+ return ss;
}
return stream_playback->get_playback_position();
}
@@ -317,7 +318,7 @@ void AudioStreamPlayer::_set_playing(bool p_enable) {
}
bool AudioStreamPlayer::_is_active() const {
- return active;
+ return active.is_set();
}
void AudioStreamPlayer::set_stream_paused(bool p_pause) {
diff --git a/scene/audio/audio_stream_player.h b/scene/audio/audio_stream_player.h
index ab98d41302..d8f83ee38d 100644
--- a/scene/audio/audio_stream_player.h
+++ b/scene/audio/audio_stream_player.h
@@ -31,6 +31,7 @@
#ifndef AUDIO_STREAM_PLAYER_H
#define AUDIO_STREAM_PLAYER_H
+#include "core/templates/safe_refcount.h"
#include "scene/main/node.h"
#include "servers/audio/audio_stream.h"
@@ -49,12 +50,12 @@ private:
Ref<AudioStream> stream;
Vector<AudioFrame> mix_buffer;
Vector<AudioFrame> fadeout_buffer;
- bool use_fadeout = false;
+ bool use_fadeout;
- volatile float setseek = -1.0;
- volatile bool active = false;
- volatile bool setstop = false;
- volatile bool stop_has_priority = false;
+ SafeNumeric<float> setseek{ -1.0 };
+ SafeFlag active;
+ SafeFlag setstop;
+ SafeFlag stop_has_priority;
float mix_volume_db = 0.0;
float pitch_scale = 1.0;
diff --git a/scene/main/http_request.cpp b/scene/main/http_request.cpp
index 384e7d2652..ce7d6ef13c 100644
--- a/scene/main/http_request.cpp
+++ b/scene/main/http_request.cpp
@@ -49,7 +49,7 @@ Error HTTPRequest::_parse_url(const String &p_url) {
got_response = false;
body_len = -1;
body.resize(0);
- downloaded = 0;
+ downloaded.set(0);
redirections = 0;
String url_lower = url.to_lower();
@@ -159,9 +159,9 @@ Error HTTPRequest::request_raw(const String &p_url, const Vector<String> &p_cust
requesting = true;
- if (use_threads) {
- thread_done = false;
- thread_request_quit = false;
+ if (use_threads.is_set()) {
+ thread_done.clear();
+ thread_request_quit.clear();
client->set_blocking_mode(true);
thread.start(_thread_func, this);
} else {
@@ -186,7 +186,7 @@ void HTTPRequest::_thread_func(void *p_userdata) {
if (err != OK) {
hr->call_deferred("_request_done", RESULT_CANT_CONNECT, 0, PackedStringArray(), PackedByteArray());
} else {
- while (!hr->thread_request_quit) {
+ while (!hr->thread_request_quit.is_set()) {
bool exit = hr->_update_connection();
if (exit) {
break;
@@ -195,7 +195,7 @@ void HTTPRequest::_thread_func(void *p_userdata) {
}
}
- hr->thread_done = true;
+ hr->thread_done.set();
}
void HTTPRequest::cancel_request() {
@@ -205,10 +205,10 @@ void HTTPRequest::cancel_request() {
return;
}
- if (!use_threads) {
+ if (!use_threads.is_set()) {
set_process_internal(false);
} else {
- thread_request_quit = true;
+ thread_request_quit.set();
thread.wait_to_finish();
}
@@ -236,7 +236,7 @@ bool HTTPRequest::_handle_response(bool *ret_value) {
List<String> rheaders;
client->get_response_headers(&rheaders);
response_headers.resize(0);
- downloaded = 0;
+ downloaded.set(0);
for (List<String>::Element *E = rheaders.front(); E; E = E->next()) {
response_headers.push_back(E->get());
}
@@ -276,7 +276,7 @@ bool HTTPRequest::_handle_response(bool *ret_value) {
got_response = false;
body_len = -1;
body.resize(0);
- downloaded = 0;
+ downloaded.set(0);
redirections = new_redirs;
*ret_value = false;
return true;
@@ -389,7 +389,7 @@ bool HTTPRequest::_update_connection() {
client->poll();
PackedByteArray chunk = client->read_response_body_chunk();
- downloaded += chunk.size();
+ downloaded.add(chunk.size());
if (file) {
const uint8_t *r = chunk.ptr();
@@ -402,13 +402,13 @@ bool HTTPRequest::_update_connection() {
body.append_array(chunk);
}
- if (body_size_limit >= 0 && downloaded > body_size_limit) {
+ if (body_size_limit >= 0 && downloaded.get() > body_size_limit) {
call_deferred("_request_done", RESULT_BODY_SIZE_LIMIT_EXCEEDED, response_code, response_headers, PackedByteArray());
return true;
}
if (body_len >= 0) {
- if (downloaded == body_len) {
+ if (downloaded.get() == body_len) {
call_deferred("_request_done", RESULT_SUCCESS, response_code, response_headers, body);
return true;
}
@@ -478,7 +478,7 @@ void HTTPRequest::_request_done(int p_status, int p_code, const PackedStringArra
void HTTPRequest::_notification(int p_what) {
if (p_what == NOTIFICATION_INTERNAL_PROCESS) {
- if (use_threads) {
+ if (use_threads.is_set()) {
return;
}
bool done = _update_connection();
@@ -497,11 +497,11 @@ void HTTPRequest::_notification(int p_what) {
void HTTPRequest::set_use_threads(bool p_use) {
ERR_FAIL_COND(get_http_client_status() != HTTPClient::STATUS_DISCONNECTED);
- use_threads = p_use;
+ use_threads.set_to(p_use);
}
bool HTTPRequest::is_using_threads() const {
- return use_threads;
+ return use_threads.is_set();
}
void HTTPRequest::set_accept_gzip(bool p_gzip) {
@@ -555,7 +555,7 @@ int HTTPRequest::get_max_redirects() const {
}
int HTTPRequest::get_downloaded_bytes() const {
- return downloaded;
+ return downloaded.get();
}
int HTTPRequest::get_body_size() const {
diff --git a/scene/main/http_request.h b/scene/main/http_request.h
index 5525ea7912..92b0ff28e9 100644
--- a/scene/main/http_request.h
+++ b/scene/main/http_request.h
@@ -34,6 +34,7 @@
#include "core/io/http_client.h"
#include "core/os/file_access.h"
#include "core/os/thread.h"
+#include "core/templates/safe_refcount.h"
#include "node.h"
#include "scene/main/timer.h"
@@ -74,7 +75,7 @@ private:
bool request_sent = false;
Ref<HTTPClient> client;
PackedByteArray body;
- volatile bool use_threads = false;
+ SafeFlag use_threads;
bool accept_gzip = true;
bool got_response = false;
@@ -86,7 +87,7 @@ private:
FileAccess *file = nullptr;
int body_len = -1;
- volatile int downloaded = 0;
+ SafeNumeric<int> downloaded;
int body_size_limit = -1;
int redirections = 0;
@@ -107,8 +108,8 @@ private:
bool has_header(const PackedStringArray &p_headers, const String &p_header_name);
String get_header_value(const PackedStringArray &p_headers, const String &header_name);
- volatile bool thread_done = false;
- volatile bool thread_request_quit = false;
+ SafeFlag thread_done;
+ SafeFlag thread_request_quit;
Thread thread;
diff --git a/scene/resources/visual_shader.cpp b/scene/resources/visual_shader.cpp
index a296156bf5..d8e63e47be 100644
--- a/scene/resources/visual_shader.cpp
+++ b/scene/resources/visual_shader.cpp
@@ -1400,11 +1400,11 @@ bool VisualShader::has_func_name(RenderingServer::ShaderMode p_mode, const Strin
}
void VisualShader::_update_shader() const {
- if (!dirty) {
+ if (!dirty.is_set()) {
return;
}
- dirty = false;
+ dirty.clear();
StringBuilder global_code;
StringBuilder global_code_per_node;
@@ -1590,11 +1590,11 @@ void VisualShader::_update_shader() const {
}
void VisualShader::_queue_update() {
- if (dirty) {
+ if (dirty.is_set()) {
return;
}
- dirty = true;
+ dirty.set();
call_deferred("_update_shader");
}
@@ -1614,7 +1614,7 @@ void VisualShader::_input_type_changed(Type p_type, int p_id) {
}
void VisualShader::rebuild() {
- dirty = true;
+ dirty.set();
_update_shader();
}
@@ -1668,6 +1668,7 @@ void VisualShader::_bind_methods() {
}
VisualShader::VisualShader() {
+ dirty.set();
for (int i = 0; i < TYPE_MAX; i++) {
Ref<VisualShaderNodeOutput> output;
output.instance();
diff --git a/scene/resources/visual_shader.h b/scene/resources/visual_shader.h
index f3f3caf15e..ef724c7650 100644
--- a/scene/resources/visual_shader.h
+++ b/scene/resources/visual_shader.h
@@ -32,6 +32,7 @@
#define VISUAL_SHADER_H
#include "core/string/string_builder.h"
+#include "core/templates/safe_refcount.h"
#include "scene/gui/control.h"
#include "scene/resources/shader.h"
@@ -99,7 +100,7 @@ private:
static RenderModeEnums render_mode_enums[];
- volatile mutable bool dirty = true;
+ mutable SafeFlag dirty;
void _queue_update();
union ConnectionKey {