diff options
Diffstat (limited to 'scene/resources')
-rw-r--r-- | scene/resources/audio_stream_polyphonic.cpp | 32 | ||||
-rw-r--r-- | scene/resources/audio_stream_polyphonic.h | 5 | ||||
-rw-r--r-- | scene/resources/camera_attributes.cpp | 4 | ||||
-rw-r--r-- | scene/resources/material.cpp | 10 | ||||
-rw-r--r-- | scene/resources/material.h | 3 | ||||
-rw-r--r-- | scene/resources/mesh.cpp | 19 | ||||
-rw-r--r-- | scene/resources/mesh.h | 2 | ||||
-rw-r--r-- | scene/resources/packed_scene.cpp | 19 | ||||
-rw-r--r-- | scene/resources/packed_scene.h | 2 | ||||
-rw-r--r-- | scene/resources/polygon_path_finder.cpp | 4 | ||||
-rw-r--r-- | scene/resources/texture.cpp | 53 | ||||
-rw-r--r-- | scene/resources/texture.h | 19 |
12 files changed, 130 insertions, 42 deletions
diff --git a/scene/resources/audio_stream_polyphonic.cpp b/scene/resources/audio_stream_polyphonic.cpp index 2e56ff3423..f7299b0789 100644 --- a/scene/resources/audio_stream_polyphonic.cpp +++ b/scene/resources/audio_stream_polyphonic.cpp @@ -87,7 +87,6 @@ void AudioStreamPlaybackPolyphonic::stop() { AudioServer::get_singleton()->lock(); } s.active.clear(); - s.finalizing.clear(); s.finish_request.clear(); s.stream_playback.unref(); s.stream.unref(); @@ -137,7 +136,7 @@ int AudioStreamPlaybackPolyphonic::mix(AudioFrame *p_buffer, float p_rate_scale, continue; } - float volume_db = s.volume_db; // Copy because it can be overriden at any time. + float volume_db = s.volume_db; // Copy because it can be overridden at any time. float next_volume = Math::db_to_linear(volume_db); s.prev_volume_db = volume_db; @@ -145,7 +144,6 @@ int AudioStreamPlaybackPolyphonic::mix(AudioFrame *p_buffer, float p_rate_scale, if (s.pending_play.is_set()) { // Did not get the chance to play, was finalized too soon. s.active.clear(); - s.finalizing.set(); continue; } next_volume = 0; @@ -163,6 +161,8 @@ int AudioStreamPlaybackPolyphonic::mix(AudioFrame *p_buffer, float p_rate_scale, int offset = 0; float volume = prev_volume; + bool stream_done = false; + while (todo) { int to_mix = MIN(todo, int(INTERNAL_BUFFER_LEN)); int mixed = s.stream_playback->mix(internal_buffer, s.pitch_scale, to_mix); @@ -175,7 +175,7 @@ int AudioStreamPlaybackPolyphonic::mix(AudioFrame *p_buffer, float p_rate_scale, if (mixed < to_mix) { // Stream is done. s.active.clear(); - s.finalizing.set(); + stream_done = true; break; } @@ -183,34 +183,22 @@ int AudioStreamPlaybackPolyphonic::mix(AudioFrame *p_buffer, float p_rate_scale, offset += to_mix; } + if (stream_done) { + continue; + } + if (s.finish_request.is_set()) { s.active.clear(); - s.finalizing.set(); } } return p_frames; } -void AudioStreamPlaybackPolyphonic::_check_finalized_streams() { - if (!active) { - return; - } - - for (Stream &s : streams) { - if (!s.active.is_set() && s.finalizing.is_set()) { - s.stream_playback.unref(); - s.stream.unref(); - s.finalizing.clear(); - s.finish_request.clear(); - } - } -} - AudioStreamPlaybackPolyphonic::ID AudioStreamPlaybackPolyphonic::play_stream(const Ref<AudioStream> &p_stream, float p_from_offset, float p_volume_db, float p_pitch_scale) { ERR_FAIL_COND_V(p_stream.is_null(), INVALID_ID); for (uint32_t i = 0; i < streams.size(); i++) { - if (!streams[i].active.is_set() && !streams[i].finish_request.is_set() && !streams[i].finalizing.is_set()) { + if (!streams[i].active.is_set()) { // Can use this stream, as it's not active. streams[i].stream = p_stream; streams[i].stream_playback = streams[i].stream->instantiate_playback(); @@ -219,6 +207,7 @@ AudioStreamPlaybackPolyphonic::ID AudioStreamPlaybackPolyphonic::play_stream(con streams[i].prev_volume_db = p_volume_db; streams[i].pitch_scale = p_pitch_scale; streams[i].id = id_counter++; + streams[i].finish_request.clear(); streams[i].pending_play.set(); streams[i].active.set(); return (ID(i) << INDEX_SHIFT) | ID(streams[i].id); @@ -282,5 +271,4 @@ void AudioStreamPlaybackPolyphonic::_bind_methods() { } AudioStreamPlaybackPolyphonic::AudioStreamPlaybackPolyphonic() { - SceneTree::get_singleton()->connect(SNAME("process_frame"), callable_mp(this, &AudioStreamPlaybackPolyphonic::_check_finalized_streams)); } diff --git a/scene/resources/audio_stream_polyphonic.h b/scene/resources/audio_stream_polyphonic.h index b5ccc7eb7f..e414401b6f 100644 --- a/scene/resources/audio_stream_polyphonic.h +++ b/scene/resources/audio_stream_polyphonic.h @@ -63,7 +63,6 @@ class AudioStreamPlaybackPolyphonic : public AudioStreamPlayback { SafeFlag active; SafeFlag pending_play; SafeFlag finish_request; - SafeFlag finalizing; float play_offset = 0; float pitch_scale = 1.0; Ref<AudioStream> stream; @@ -73,7 +72,7 @@ class AudioStreamPlaybackPolyphonic : public AudioStreamPlayback { uint32_t id = 0; Stream() : - active(false), pending_play(false), finish_request(false), finalizing(false) {} + active(false), pending_play(false), finish_request(false) {} }; LocalVector<Stream> streams; @@ -84,8 +83,6 @@ class AudioStreamPlaybackPolyphonic : public AudioStreamPlayback { _FORCE_INLINE_ Stream *_find_stream(int64_t p_id); - void _check_finalized_streams(); - friend class AudioStreamPolyphonic; protected: diff --git a/scene/resources/camera_attributes.cpp b/scene/resources/camera_attributes.cpp index b5e302cce5..61df56523d 100644 --- a/scene/resources/camera_attributes.cpp +++ b/scene/resources/camera_attributes.cpp @@ -286,10 +286,10 @@ void CameraAttributesPractical::_bind_methods() { ADD_GROUP("DOF Blur", "dof_blur_"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "dof_blur_far_enabled"), "set_dof_blur_far_enabled", "is_dof_blur_far_enabled"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "dof_blur_far_distance", PROPERTY_HINT_RANGE, "0.01,8192,0.01,exp,suffix:m"), "set_dof_blur_far_distance", "get_dof_blur_far_distance"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "dof_blur_far_transition", PROPERTY_HINT_RANGE, "0.01,8192,0.01,exp"), "set_dof_blur_far_transition", "get_dof_blur_far_transition"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "dof_blur_far_transition", PROPERTY_HINT_RANGE, "-1,8192,0.01,exp"), "set_dof_blur_far_transition", "get_dof_blur_far_transition"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "dof_blur_near_enabled"), "set_dof_blur_near_enabled", "is_dof_blur_near_enabled"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "dof_blur_near_distance", PROPERTY_HINT_RANGE, "0.01,8192,0.01,exp,suffix:m"), "set_dof_blur_near_distance", "get_dof_blur_near_distance"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "dof_blur_near_transition", PROPERTY_HINT_RANGE, "0.01,8192,0.01,exp"), "set_dof_blur_near_transition", "get_dof_blur_near_transition"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "dof_blur_near_transition", PROPERTY_HINT_RANGE, "-1,8192,0.01,exp"), "set_dof_blur_near_transition", "get_dof_blur_near_transition"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "dof_blur_amount", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_dof_blur_amount", "get_dof_blur_amount"); ADD_GROUP("Auto Exposure", "auto_exposure_"); diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp index db7385428b..f4aa0637f7 100644 --- a/scene/resources/material.cpp +++ b/scene/resources/material.cpp @@ -113,6 +113,12 @@ bool Material::_can_use_render_priority() const { return ret; } +Ref<Resource> Material::create_placeholder() const { + Ref<PlaceholderMaterial> placeholder; + placeholder.instantiate(); + return placeholder; +} + void Material::_bind_methods() { ClassDB::bind_method(D_METHOD("set_next_pass", "next_pass"), &Material::set_next_pass); ClassDB::bind_method(D_METHOD("get_next_pass"), &Material::get_next_pass); @@ -123,6 +129,8 @@ void Material::_bind_methods() { ClassDB::bind_method(D_METHOD("inspect_native_shader_code"), &Material::inspect_native_shader_code); ClassDB::set_method_flags(get_class_static(), _scs_create("inspect_native_shader_code"), METHOD_FLAGS_DEFAULT | METHOD_FLAG_EDITOR); + ClassDB::bind_method(D_METHOD("create_placeholder"), &Material::create_placeholder); + ADD_PROPERTY(PropertyInfo(Variant::INT, "render_priority", PROPERTY_HINT_RANGE, itos(RENDER_PRIORITY_MIN) + "," + itos(RENDER_PRIORITY_MAX) + ",1"), "set_render_priority", "get_render_priority"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "next_pass", PROPERTY_HINT_RESOURCE_TYPE, "Material"), "set_next_pass", "get_next_pass"); @@ -188,7 +196,7 @@ bool ShaderMaterial::_get(const StringName &p_name, Variant &r_ret) const { if (shader.is_valid()) { const StringName *sn = remap_cache.getptr(p_name); if (sn) { - // Only return a parameter if it was previosly set. + // Only return a parameter if it was previously set. r_ret = get_shader_parameter(*sn); return true; } diff --git a/scene/resources/material.h b/scene/resources/material.h index 83c7a09cc4..fe1448cd4c 100644 --- a/scene/resources/material.h +++ b/scene/resources/material.h @@ -74,6 +74,9 @@ public: virtual RID get_rid() const override; virtual RID get_shader_rid() const; virtual Shader::Mode get_shader_mode() const; + + virtual Ref<Resource> create_placeholder() const; + Material(); virtual ~Material(); }; diff --git a/scene/resources/mesh.cpp b/scene/resources/mesh.cpp index c93b51552f..cf9baa2907 100644 --- a/scene/resources/mesh.cpp +++ b/scene/resources/mesh.cpp @@ -615,6 +615,13 @@ Size2i Mesh::get_lightmap_size_hint() const { return lightmap_size_hint; } +Ref<Resource> Mesh::create_placeholder() const { + Ref<PlaceholderMesh> placeholder; + placeholder.instantiate(); + placeholder->set_aabb(get_aabb()); + return placeholder; +} + void Mesh::_bind_methods() { ClassDB::bind_method(D_METHOD("set_lightmap_size_hint", "size"), &Mesh::set_lightmap_size_hint); ClassDB::bind_method(D_METHOD("get_lightmap_size_hint"), &Mesh::get_lightmap_size_hint); @@ -627,6 +634,7 @@ void Mesh::_bind_methods() { ClassDB::bind_method(D_METHOD("surface_get_blend_shape_arrays", "surf_idx"), &Mesh::surface_get_blend_shape_arrays); ClassDB::bind_method(D_METHOD("surface_set_material", "surf_idx", "material"), &Mesh::surface_set_material); ClassDB::bind_method(D_METHOD("surface_get_material", "surf_idx"), &Mesh::surface_get_material); + ClassDB::bind_method(D_METHOD("create_placeholder"), &Mesh::create_placeholder); BIND_ENUM_CONSTANT(PRIMITIVE_POINTS); BIND_ENUM_CONSTANT(PRIMITIVE_LINES); @@ -1122,17 +1130,6 @@ bool ArrayMesh::_set(const StringName &p_name, const Variant &p_value) { } int idx = sname.substr(8, sl - 8).to_int(); - // This is a bit of a hack to ensure compatibility with older material - // overrides that start indexing at 1. - // We assume that idx 0 is always read first, if its not, this won't work. - if (idx == 0) { - surface_index_0 = true; - } - if (!surface_index_0) { - // This means the file was created when the indexing started at 1, so decrease by one. - idx--; - } - String what = sname.get_slicec('/', 1); if (what == "material") { surface_set_material(idx, p_value); diff --git a/scene/resources/mesh.h b/scene/resources/mesh.h index 1baa466312..1b870d996a 100644 --- a/scene/resources/mesh.h +++ b/scene/resources/mesh.h @@ -220,6 +220,8 @@ public: virtual int get_builtin_bind_pose_count() const; virtual Transform3D get_builtin_bind_pose(int p_index) const; + virtual Ref<Resource> create_placeholder() const; + Mesh(); }; diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp index c24186a109..e497a628aa 100644 --- a/scene/resources/packed_scene.cpp +++ b/scene/resources/packed_scene.cpp @@ -1046,6 +1046,25 @@ Ref<SceneState> SceneState::get_base_scene_state() const { return Ref<SceneState>(); } +void SceneState::update_instance_resource(String p_path, Ref<PackedScene> p_packed_scene) { + ERR_FAIL_COND(p_packed_scene.is_null()); + + for (const NodeData &nd : nodes) { + if (nd.instance >= 0) { + if (!(nd.instance & FLAG_INSTANCE_IS_PLACEHOLDER)) { + int instance_id = nd.instance & FLAG_MASK; + Ref<PackedScene> original_packed_scene = variants[instance_id]; + if (original_packed_scene.is_valid()) { + if (original_packed_scene->get_path() == p_path) { + variants.remove_at(instance_id); + variants.insert(instance_id, p_packed_scene); + } + } + } + } + } +} + int SceneState::find_node_by_path(const NodePath &p_node) const { ERR_FAIL_COND_V_MSG(node_path_cache.size() == 0, -1, "This operation requires the node cache to have been built."); diff --git a/scene/resources/packed_scene.h b/scene/resources/packed_scene.h index ef7363dd44..5c53ffdb45 100644 --- a/scene/resources/packed_scene.h +++ b/scene/resources/packed_scene.h @@ -150,6 +150,8 @@ public: Ref<SceneState> get_base_scene_state() const; + void update_instance_resource(String p_path, Ref<PackedScene> p_packed_scene); + //unbuild API int get_node_count() const; diff --git a/scene/resources/polygon_path_finder.cpp b/scene/resources/polygon_path_finder.cpp index 85106883f9..3bbd0a0b5e 100644 --- a/scene/resources/polygon_path_finder.cpp +++ b/scene/resources/polygon_path_finder.cpp @@ -325,7 +325,7 @@ Vector<Vector2> PolygonPathFinder::find_path(const Vector2 &p_from, const Vector } const Point &np = points[least_cost_point]; - //open the neighbours for search + //open the neighbors for search for (const int &E : np.connections) { Point &p = points.write[E]; @@ -339,7 +339,7 @@ Vector<Vector2> PolygonPathFinder::find_path(const Vector2 &p_from, const Vector p.distance = distance; } } else { - //add to open neighbours + //add to open neighbors p.prev = least_cost_point; p.distance = distance; diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp index f106eebff5..85e21d6056 100644 --- a/scene/resources/texture.cpp +++ b/scene/resources/texture.cpp @@ -94,6 +94,13 @@ bool Texture2D::get_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect, Re return true; } +Ref<Resource> Texture2D::create_placeholder() const { + Ref<PlaceholderTexture2D> placeholder; + placeholder.instantiate(); + placeholder->set_size(get_size()); + return placeholder; +} + void Texture2D::_bind_methods() { ClassDB::bind_method(D_METHOD("get_width"), &Texture2D::get_width); ClassDB::bind_method(D_METHOD("get_height"), &Texture2D::get_height); @@ -103,6 +110,7 @@ void Texture2D::_bind_methods() { ClassDB::bind_method(D_METHOD("draw_rect", "canvas_item", "rect", "tile", "modulate", "transpose"), &Texture2D::draw_rect, DEFVAL(Color(1, 1, 1)), DEFVAL(false)); ClassDB::bind_method(D_METHOD("draw_rect_region", "canvas_item", "rect", "src_rect", "modulate", "transpose", "clip_uv"), &Texture2D::draw_rect_region, DEFVAL(Color(1, 1, 1)), DEFVAL(false), DEFVAL(true)); ClassDB::bind_method(D_METHOD("get_image"), &Texture2D::get_image); + ClassDB::bind_method(D_METHOD("create_placeholder"), &Texture2D::create_placeholder); ADD_GROUP("", ""); @@ -1137,6 +1145,7 @@ void Texture3D::_bind_methods() { ClassDB::bind_method(D_METHOD("get_depth"), &Texture3D::get_depth); ClassDB::bind_method(D_METHOD("has_mipmaps"), &Texture3D::has_mipmaps); ClassDB::bind_method(D_METHOD("get_data"), &Texture3D::_get_datai); + ClassDB::bind_method(D_METHOD("create_placeholder"), &Texture3D::create_placeholder); GDVIRTUAL_BIND(_get_format); GDVIRTUAL_BIND(_get_width); @@ -1145,6 +1154,14 @@ void Texture3D::_bind_methods() { GDVIRTUAL_BIND(_has_mipmaps); GDVIRTUAL_BIND(_get_data); } + +Ref<Resource> Texture3D::create_placeholder() const { + Ref<PlaceholderTexture3D> placeholder; + placeholder.instantiate(); + placeholder->set_size(Vector3i(get_width(), get_height(), get_depth())); + return placeholder; +} + ////////////////////////////////////////// Image::Format ImageTexture3D::get_format() const { @@ -3048,6 +3065,42 @@ ImageTextureLayered::~ImageTextureLayered() { } } +void Texture2DArray::_bind_methods() { + ClassDB::bind_method(D_METHOD("create_placeholder"), &Texture2DArray::create_placeholder); +} + +Ref<Resource> Texture2DArray::create_placeholder() const { + Ref<PlaceholderTexture2DArray> placeholder; + placeholder.instantiate(); + placeholder->set_size(Size2i(get_width(), get_height())); + placeholder->set_layers(get_layers()); + return placeholder; +} + +void Cubemap::_bind_methods() { + ClassDB::bind_method(D_METHOD("create_placeholder"), &Cubemap::create_placeholder); +} + +Ref<Resource> Cubemap::create_placeholder() const { + Ref<PlaceholderCubemap> placeholder; + placeholder.instantiate(); + placeholder->set_size(Size2i(get_width(), get_height())); + placeholder->set_layers(get_layers()); + return placeholder; +} + +void CubemapArray::_bind_methods() { + ClassDB::bind_method(D_METHOD("create_placeholder"), &CubemapArray::create_placeholder); +} + +Ref<Resource> CubemapArray::create_placeholder() const { + Ref<PlaceholderCubemapArray> placeholder; + placeholder.instantiate(); + placeholder->set_size(Size2i(get_width(), get_height())); + placeholder->set_layers(get_layers()); + return placeholder; +} + /////////////////////////////////////////// void CompressedTextureLayered::set_path(const String &p_path, bool p_take_over) { diff --git a/scene/resources/texture.h b/scene/resources/texture.h index bb86910c0c..7f74ae6941 100644 --- a/scene/resources/texture.h +++ b/scene/resources/texture.h @@ -82,6 +82,8 @@ public: virtual Ref<Image> get_image() const { return Ref<Image>(); } + virtual Ref<Resource> create_placeholder() const; + Texture2D(); }; @@ -450,25 +452,41 @@ public: class Texture2DArray : public ImageTextureLayered { GDCLASS(Texture2DArray, ImageTextureLayered) + +protected: + static void _bind_methods(); + public: Texture2DArray() : ImageTextureLayered(LAYERED_TYPE_2D_ARRAY) {} + + virtual Ref<Resource> create_placeholder() const; }; class Cubemap : public ImageTextureLayered { GDCLASS(Cubemap, ImageTextureLayered); +protected: + static void _bind_methods(); + public: Cubemap() : ImageTextureLayered(LAYERED_TYPE_CUBEMAP) {} + + virtual Ref<Resource> create_placeholder() const; }; class CubemapArray : public ImageTextureLayered { GDCLASS(CubemapArray, ImageTextureLayered); +protected: + static void _bind_methods(); + public: CubemapArray() : ImageTextureLayered(LAYERED_TYPE_CUBEMAP_ARRAY) {} + + virtual Ref<Resource> create_placeholder() const; }; class CompressedTextureLayered : public TextureLayered { @@ -580,6 +598,7 @@ public: virtual int get_depth() const; virtual bool has_mipmaps() const; virtual Vector<Ref<Image>> get_data() const; + virtual Ref<Resource> create_placeholder() const; }; class ImageTexture3D : public Texture3D { |