From 9a3960daa59a728f2620f64ad182aa332059489c Mon Sep 17 00:00:00 2001 From: kobewi Date: Wed, 30 Nov 2022 16:40:50 +0100 Subject: Simplify GDVIRTUAL_REQUIRED_CALL calls --- editor/export/editor_export_plugin.cpp | 24 +++---- scene/resources/material.cpp | 15 ++-- scene/resources/mesh.cpp | 100 +++++++++----------------- scene/resources/style_box.cpp | 12 ++-- scene/resources/texture.cpp | 126 ++++++++++++--------------------- servers/audio/audio_effect.cpp | 10 +-- servers/audio/audio_stream.cpp | 27 +++---- servers/movie_writer/movie_writer.cpp | 43 +++++------ 8 files changed, 124 insertions(+), 233 deletions(-) diff --git a/editor/export/editor_export_plugin.cpp b/editor/export/editor_export_plugin.cpp index 78d4f93dfe..f0e841f307 100644 --- a/editor/export/editor_export_plugin.cpp +++ b/editor/export/editor_export_plugin.cpp @@ -148,10 +148,8 @@ bool EditorExportPlugin::_begin_customize_resources(const Ref EditorExportPlugin::_customize_resource(const Ref &p_resource, const String &p_path) { Ref ret; - if (GDVIRTUAL_REQUIRED_CALL(_customize_resource, p_resource, p_path, ret)) { - return ret; - } - return Ref(); + GDVIRTUAL_REQUIRED_CALL(_customize_resource, p_resource, p_path, ret); + return ret; } bool EditorExportPlugin::_begin_customize_scenes(const Ref &p_platform, const Vector &p_features) const { @@ -162,18 +160,14 @@ bool EditorExportPlugin::_begin_customize_scenes(const Ref Node *EditorExportPlugin::_customize_scene(Node *p_root, const String &p_path) { Node *ret = nullptr; - if (GDVIRTUAL_REQUIRED_CALL(_customize_scene, p_root, p_path, ret)) { - return ret; - } - return nullptr; + GDVIRTUAL_REQUIRED_CALL(_customize_scene, p_root, p_path, ret); + return ret; } uint64_t EditorExportPlugin::_get_customization_configuration_hash() const { uint64_t ret = 0; - if (GDVIRTUAL_REQUIRED_CALL(_get_customization_configuration_hash, ret)) { - return ret; - } - return 0; + GDVIRTUAL_REQUIRED_CALL(_get_customization_configuration_hash, ret); + return ret; } void EditorExportPlugin::_end_customize_scenes() { @@ -186,10 +180,8 @@ void EditorExportPlugin::_end_customize_resources() { String EditorExportPlugin::_get_name() const { String ret; - if (GDVIRTUAL_REQUIRED_CALL(_get_name, ret)) { - return ret; - } - return ""; + GDVIRTUAL_REQUIRED_CALL(_get_name, ret); + return ret; } void EditorExportPlugin::_export_file(const String &p_path, const String &p_type, const HashSet &p_features) { diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp index 10d193f950..e457b2d377 100644 --- a/scene/resources/material.cpp +++ b/scene/resources/material.cpp @@ -92,18 +92,13 @@ void Material::inspect_native_shader_code() { RID Material::get_shader_rid() const { RID ret; - if (GDVIRTUAL_REQUIRED_CALL(_get_shader_rid, ret)) { - return ret; - } - return RID(); + GDVIRTUAL_REQUIRED_CALL(_get_shader_rid, ret); + return ret; } Shader::Mode Material::get_shader_mode() const { - Shader::Mode ret; - if (GDVIRTUAL_REQUIRED_CALL(_get_shader_mode, ret)) { - return ret; - } - - return Shader::MODE_MAX; + Shader::Mode ret = Shader::MODE_MAX; + GDVIRTUAL_REQUIRED_CALL(_get_shader_mode, ret); + return ret; } bool Material::_can_do_next_pass() const { diff --git a/scene/resources/mesh.cpp b/scene/resources/mesh.cpp index 4f68a6f69b..a5e7602c8b 100644 --- a/scene/resources/mesh.cpp +++ b/scene/resources/mesh.cpp @@ -40,119 +40,83 @@ Mesh::ConvexDecompositionFunc Mesh::convex_decomposition_function = nullptr; int Mesh::get_surface_count() const { - int ret; - if (GDVIRTUAL_REQUIRED_CALL(_get_surface_count, ret)) { - return ret; - } - return 0; + int ret = 0; + GDVIRTUAL_REQUIRED_CALL(_get_surface_count, ret); + return ret; } int Mesh::surface_get_array_len(int p_idx) const { - int ret; - if (GDVIRTUAL_REQUIRED_CALL(_surface_get_array_len, p_idx, ret)) { - return ret; - } - return 0; + int ret = 0; + GDVIRTUAL_REQUIRED_CALL(_surface_get_array_len, p_idx, ret); + return ret; } int Mesh::surface_get_array_index_len(int p_idx) const { - int ret; - if (GDVIRTUAL_REQUIRED_CALL(_surface_get_array_index_len, p_idx, ret)) { - return ret; - } - return 0; + int ret = 0; + GDVIRTUAL_REQUIRED_CALL(_surface_get_array_index_len, p_idx, ret); + return ret; } Array Mesh::surface_get_arrays(int p_surface) const { Array ret; - if (GDVIRTUAL_REQUIRED_CALL(_surface_get_arrays, p_surface, ret)) { - return ret; - } - return Array(); + GDVIRTUAL_REQUIRED_CALL(_surface_get_arrays, p_surface, ret); + return ret; } TypedArray Mesh::surface_get_blend_shape_arrays(int p_surface) const { TypedArray ret; - if (GDVIRTUAL_REQUIRED_CALL(_surface_get_blend_shape_arrays, p_surface, ret)) { - return ret; - } - - return TypedArray(); + GDVIRTUAL_REQUIRED_CALL(_surface_get_blend_shape_arrays, p_surface, ret); + return ret; } Dictionary Mesh::surface_get_lods(int p_surface) const { Dictionary ret; - if (GDVIRTUAL_REQUIRED_CALL(_surface_get_lods, p_surface, ret)) { - return ret; - } - - return Dictionary(); + GDVIRTUAL_REQUIRED_CALL(_surface_get_lods, p_surface, ret); + return ret; } uint32_t Mesh::surface_get_format(int p_idx) const { - uint32_t ret; - if (GDVIRTUAL_REQUIRED_CALL(_surface_get_format, p_idx, ret)) { - return ret; - } - - return 0; + uint32_t ret = 0; + GDVIRTUAL_REQUIRED_CALL(_surface_get_format, p_idx, ret); + return ret; } Mesh::PrimitiveType Mesh::surface_get_primitive_type(int p_idx) const { - uint32_t ret; - if (GDVIRTUAL_REQUIRED_CALL(_surface_get_primitive_type, p_idx, ret)) { - return (Mesh::PrimitiveType)ret; - } - - return PRIMITIVE_MAX; + uint32_t ret = PRIMITIVE_MAX; + GDVIRTUAL_REQUIRED_CALL(_surface_get_primitive_type, p_idx, ret); + return (Mesh::PrimitiveType)ret; } void Mesh::surface_set_material(int p_idx, const Ref &p_material) { - if (GDVIRTUAL_REQUIRED_CALL(_surface_set_material, p_idx, p_material)) { - return; - } + GDVIRTUAL_REQUIRED_CALL(_surface_set_material, p_idx, p_material); } Ref Mesh::surface_get_material(int p_idx) const { Ref ret; - if (GDVIRTUAL_REQUIRED_CALL(_surface_get_material, p_idx, ret)) { - return ret; - } - - return Ref(); + GDVIRTUAL_REQUIRED_CALL(_surface_get_material, p_idx, ret); + return ret; } int Mesh::get_blend_shape_count() const { - int ret; - if (GDVIRTUAL_REQUIRED_CALL(_get_blend_shape_count, ret)) { - return ret; - } - - return 0; + int ret = 0; + GDVIRTUAL_REQUIRED_CALL(_get_blend_shape_count, ret); + return ret; } StringName Mesh::get_blend_shape_name(int p_index) const { StringName ret; - if (GDVIRTUAL_REQUIRED_CALL(_get_blend_shape_name, p_index, ret)) { - return ret; - } - - return StringName(); + GDVIRTUAL_REQUIRED_CALL(_get_blend_shape_name, p_index, ret); + return ret; } void Mesh::set_blend_shape_name(int p_index, const StringName &p_name) { - if (GDVIRTUAL_REQUIRED_CALL(_set_blend_shape_name, p_index, p_name)) { - return; - } + GDVIRTUAL_REQUIRED_CALL(_set_blend_shape_name, p_index, p_name); } AABB Mesh::get_aabb() const { AABB ret; - if (GDVIRTUAL_REQUIRED_CALL(_get_aabb, ret)) { - return ret; - } - - return AABB(); + GDVIRTUAL_REQUIRED_CALL(_get_aabb, ret); + return ret; } Ref Mesh::generate_triangle_mesh() const { diff --git a/scene/resources/style_box.cpp b/scene/resources/style_box.cpp index f379f88bed..ea341152e6 100644 --- a/scene/resources/style_box.cpp +++ b/scene/resources/style_box.cpp @@ -35,11 +35,9 @@ #include float StyleBox::get_style_margin(Side p_side) const { - float ret; - if (GDVIRTUAL_REQUIRED_CALL(_get_style_margin, p_side, ret)) { - return ret; - } - return 0; + float ret = 0; + GDVIRTUAL_REQUIRED_CALL(_get_style_margin, p_side, ret); + return ret; } bool StyleBox::test_mask(const Point2 &p_point, const Rect2 &p_rect) const { @@ -49,9 +47,7 @@ bool StyleBox::test_mask(const Point2 &p_point, const Rect2 &p_rect) const { } void StyleBox::draw(RID p_canvas_item, const Rect2 &p_rect) const { - if (GDVIRTUAL_REQUIRED_CALL(_draw, p_canvas_item, p_rect)) { - return; - } + GDVIRTUAL_REQUIRED_CALL(_draw, p_canvas_item, p_rect); } void StyleBox::set_default_margin(Side p_side, float p_value) { diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp index b5754caa6a..2106619a6b 100644 --- a/scene/resources/texture.cpp +++ b/scene/resources/texture.cpp @@ -40,19 +40,15 @@ #include "servers/camera/camera_feed.h" int Texture2D::get_width() const { - int ret; - if (GDVIRTUAL_REQUIRED_CALL(_get_width, ret)) { - return ret; - } - return 0; + int ret = 0; + GDVIRTUAL_REQUIRED_CALL(_get_width, ret); + return ret; } int Texture2D::get_height() const { - int ret; - if (GDVIRTUAL_REQUIRED_CALL(_get_height, ret)) { - return ret; - } - return 0; + int ret = 0; + GDVIRTUAL_REQUIRED_CALL(_get_height, ret); + return ret; } Size2 Texture2D::get_size() const { @@ -1092,57 +1088,44 @@ TypedArray Texture3D::_get_datai() const { } Image::Format Texture3D::get_format() const { - Image::Format ret; - if (GDVIRTUAL_REQUIRED_CALL(_get_format, ret)) { - return ret; - } - return Image::FORMAT_MAX; + Image::Format ret = Image::FORMAT_MAX; + GDVIRTUAL_REQUIRED_CALL(_get_format, ret); + return ret; } int Texture3D::get_width() const { - int ret; - if (GDVIRTUAL_REQUIRED_CALL(_get_width, ret)) { - return ret; - } - return 0; + int ret = 0; + GDVIRTUAL_REQUIRED_CALL(_get_width, ret); + return ret; } int Texture3D::get_height() const { - int ret; - if (GDVIRTUAL_REQUIRED_CALL(_get_height, ret)) { - return ret; - } - return 0; + int ret = 0; + GDVIRTUAL_REQUIRED_CALL(_get_height, ret); + return ret; } int Texture3D::get_depth() const { - int ret; - if (GDVIRTUAL_REQUIRED_CALL(_get_depth, ret)) { - return ret; - } - - return 0; + int ret = 0; + GDVIRTUAL_REQUIRED_CALL(_get_depth, ret); + return ret; } bool Texture3D::has_mipmaps() const { - bool ret; - if (GDVIRTUAL_REQUIRED_CALL(_has_mipmaps, ret)) { - return ret; - } - return false; + bool ret = false; + GDVIRTUAL_REQUIRED_CALL(_has_mipmaps, ret); + return ret; } Vector> Texture3D::get_data() const { TypedArray ret; - if (GDVIRTUAL_REQUIRED_CALL(_get_data, ret)) { - Vector> data; - data.resize(ret.size()); - for (int i = 0; i < data.size(); i++) { - data.write[i] = ret[i]; - } - return data; + GDVIRTUAL_REQUIRED_CALL(_get_data, ret); + Vector> data; + data.resize(ret.size()); + for (int i = 0; i < data.size(); i++) { + data.write[i] = ret[i]; } - return Vector>(); + return data; } void Texture3D::_bind_methods() { ClassDB::bind_method(D_METHOD("get_format"), &Texture3D::get_format); @@ -2859,60 +2842,45 @@ AnimatedTexture::~AnimatedTexture() { /////////////////////////////// Image::Format TextureLayered::get_format() const { - Image::Format ret; - if (GDVIRTUAL_REQUIRED_CALL(_get_format, ret)) { - return ret; - } - return Image::FORMAT_MAX; + Image::Format ret = Image::FORMAT_MAX; + GDVIRTUAL_REQUIRED_CALL(_get_format, ret); + return ret; } TextureLayered::LayeredType TextureLayered::get_layered_type() const { - uint32_t ret; - if (GDVIRTUAL_REQUIRED_CALL(_get_layered_type, ret)) { - return (LayeredType)ret; - } - return LAYERED_TYPE_2D_ARRAY; + uint32_t ret = LAYERED_TYPE_2D_ARRAY; + GDVIRTUAL_REQUIRED_CALL(_get_layered_type, ret); + return (LayeredType)ret; } int TextureLayered::get_width() const { - int ret; - if (GDVIRTUAL_REQUIRED_CALL(_get_width, ret)) { - return ret; - } - return 0; + int ret = 0; + GDVIRTUAL_REQUIRED_CALL(_get_width, ret); + return ret; } int TextureLayered::get_height() const { - int ret; - if (GDVIRTUAL_REQUIRED_CALL(_get_height, ret)) { - return ret; - } - return 0; + int ret = 0; + GDVIRTUAL_REQUIRED_CALL(_get_height, ret); + return ret; } int TextureLayered::get_layers() const { - int ret; - if (GDVIRTUAL_REQUIRED_CALL(_get_layers, ret)) { - return ret; - } - - return 0; + int ret = 0; + GDVIRTUAL_REQUIRED_CALL(_get_layers, ret); + return ret; } bool TextureLayered::has_mipmaps() const { - bool ret; - if (GDVIRTUAL_REQUIRED_CALL(_has_mipmaps, ret)) { - return ret; - } - return false; + bool ret = false; + GDVIRTUAL_REQUIRED_CALL(_has_mipmaps, ret); + return ret; } Ref TextureLayered::get_layer_data(int p_layer) const { Ref ret; - if (GDVIRTUAL_REQUIRED_CALL(_get_layer_data, p_layer, ret)) { - return ret; - } - return Ref(); + GDVIRTUAL_REQUIRED_CALL(_get_layer_data, p_layer, ret); + return ret; } void TextureLayered::_bind_methods() { diff --git a/servers/audio/audio_effect.cpp b/servers/audio/audio_effect.cpp index ef0e3197e1..870a77806b 100644 --- a/servers/audio/audio_effect.cpp +++ b/servers/audio/audio_effect.cpp @@ -31,9 +31,7 @@ #include "audio_effect.h" void AudioEffectInstance::process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count) { - if (GDVIRTUAL_REQUIRED_CALL(_process, p_src_frames, p_dst_frames, p_frame_count)) { - return; - } + GDVIRTUAL_REQUIRED_CALL(_process, p_src_frames, p_dst_frames, p_frame_count); } bool AudioEffectInstance::process_silence() const { bool ret = false; @@ -50,10 +48,8 @@ void AudioEffectInstance::_bind_methods() { Ref AudioEffect::instantiate() { Ref ret; - if (GDVIRTUAL_REQUIRED_CALL(_instantiate, ret)) { - return ret; - } - return Ref(); + GDVIRTUAL_REQUIRED_CALL(_instantiate, ret); + return ret; } void AudioEffect::_bind_methods() { GDVIRTUAL_BIND(_instantiate); diff --git a/servers/audio/audio_stream.cpp b/servers/audio/audio_stream.cpp index 33d4c816f2..4b68515e18 100644 --- a/servers/audio/audio_stream.cpp +++ b/servers/audio/audio_stream.cpp @@ -71,12 +71,9 @@ void AudioStreamPlayback::seek(double p_time) { } int AudioStreamPlayback::mix(AudioFrame *p_buffer, float p_rate_scale, int p_frames) { - int ret; - if (GDVIRTUAL_REQUIRED_CALL(_mix, p_buffer, p_rate_scale, p_frames, ret)) { - return ret; - } - - return 0; + int ret = 0; + GDVIRTUAL_REQUIRED_CALL(_mix, p_buffer, p_rate_scale, p_frames, ret); + return ret; } void AudioStreamPlayback::tag_used_streams() { @@ -107,20 +104,14 @@ void AudioStreamPlaybackResampled::begin_resample() { } int AudioStreamPlaybackResampled::_mix_internal(AudioFrame *p_buffer, int p_frames) { - int ret; - if (GDVIRTUAL_REQUIRED_CALL(_mix_resampled, p_buffer, p_frames, ret)) { - return ret; - } - - return 0; + int ret = 0; + GDVIRTUAL_REQUIRED_CALL(_mix_resampled, p_buffer, p_frames, ret); + return ret; } float AudioStreamPlaybackResampled::get_stream_sampling_rate() { - float ret; - if (GDVIRTUAL_REQUIRED_CALL(_get_stream_sampling_rate, ret)) { - return ret; - } - - return 0; + float ret = 0; + GDVIRTUAL_REQUIRED_CALL(_get_stream_sampling_rate, ret); + return ret; } void AudioStreamPlaybackResampled::_bind_methods() { diff --git a/servers/movie_writer/movie_writer.cpp b/servers/movie_writer/movie_writer.cpp index 0edce4ced6..419943f2d2 100644 --- a/servers/movie_writer/movie_writer.cpp +++ b/servers/movie_writer/movie_writer.cpp @@ -52,34 +52,26 @@ MovieWriter *MovieWriter::find_writer_for_file(const String &p_file) { } uint32_t MovieWriter::get_audio_mix_rate() const { - uint32_t ret = 0; - if (GDVIRTUAL_REQUIRED_CALL(_get_audio_mix_rate, ret)) { - return ret; - } - return 48000; + uint32_t ret = 48000; + GDVIRTUAL_REQUIRED_CALL(_get_audio_mix_rate, ret); + return ret; } AudioServer::SpeakerMode MovieWriter::get_audio_speaker_mode() const { AudioServer::SpeakerMode ret = AudioServer::SPEAKER_MODE_STEREO; - if (GDVIRTUAL_REQUIRED_CALL(_get_audio_speaker_mode, ret)) { - return ret; - } - return AudioServer::SPEAKER_MODE_STEREO; + GDVIRTUAL_REQUIRED_CALL(_get_audio_speaker_mode, ret); + return ret; } Error MovieWriter::write_begin(const Size2i &p_movie_size, uint32_t p_fps, const String &p_base_path) { - Error ret = OK; - if (GDVIRTUAL_REQUIRED_CALL(_write_begin, p_movie_size, p_fps, p_base_path, ret)) { - return ret; - } - return ERR_UNCONFIGURED; + Error ret = ERR_UNCONFIGURED; + GDVIRTUAL_REQUIRED_CALL(_write_begin, p_movie_size, p_fps, p_base_path, ret); + return ret; } Error MovieWriter::write_frame(const Ref &p_image, const int32_t *p_audio_data) { - Error ret = OK; - if (GDVIRTUAL_REQUIRED_CALL(_write_frame, p_image, p_audio_data, ret)) { - return ret; - } - return ERR_UNCONFIGURED; + Error ret = ERR_UNCONFIGURED; + GDVIRTUAL_REQUIRED_CALL(_write_frame, p_image, p_audio_data, ret); + return ret; } void MovieWriter::write_end() { @@ -88,18 +80,15 @@ void MovieWriter::write_end() { bool MovieWriter::handles_file(const String &p_path) const { bool ret = false; - if (GDVIRTUAL_REQUIRED_CALL(_handles_file, p_path, ret)) { - return ret; - } - return false; + GDVIRTUAL_REQUIRED_CALL(_handles_file, p_path, ret); + return ret; } void MovieWriter::get_supported_extensions(List *r_extensions) const { Vector exts; - if (GDVIRTUAL_REQUIRED_CALL(_get_supported_extensions, exts)) { - for (int i = 0; i < exts.size(); i++) { - r_extensions->push_back(exts[i]); - } + GDVIRTUAL_REQUIRED_CALL(_get_supported_extensions, exts); + for (int i = 0; i < exts.size(); i++) { + r_extensions->push_back(exts[i]); } } -- cgit v1.2.3