From 8582b140f7b4d5b310d05a7accc2cbd0dbe592de Mon Sep 17 00:00:00 2001 From: Pawel Piecuch Date: Thu, 12 Oct 2023 23:07:39 +0200 Subject: [PATCH] cleanup formatting; update audio plugins --- editor/audio_stream_preview.cpp | 31 +++-- modules/gdextensions/common/gd_core.h | 76 +++++++++++++ .../editor/power_station_plugin.cpp | 107 ++++++++++++++++-- .../submodules/editor/power_station_plugin.h | 32 +++++- 4 files changed, 216 insertions(+), 30 deletions(-) diff --git a/editor/audio_stream_preview.cpp b/editor/audio_stream_preview.cpp index e9db4bb35dd3..af6c8ec75f8c 100644 --- a/editor/audio_stream_preview.cpp +++ b/editor/audio_stream_preview.cpp @@ -31,10 +31,10 @@ #include "audio_stream_preview.h" #include "core/os/keyboard.h" -#include "scene/gui/box_container.h" -#include "editor/editor_settings.h" -#include "editor/editor_scale.h" #include "editor/editor_node.h" +#include "editor/editor_scale.h" +#include "editor/editor_settings.h" +#include "scene/gui/box_container.h" // BEGIN AudioStreamPreview @@ -106,7 +106,6 @@ AudioStreamPreview::AudioStreamPreview() { // END AudioStreamPreview - // BEGIN AudioStreamPreviewGenerator void AudioStreamPreviewGenerator::_update_emit(ObjectID p_id) { @@ -256,20 +255,21 @@ AudioStreamPreviewGenerator::AudioStreamPreviewGenerator() { // END AudioStreamPreviewGenerator - // BEGIN AudioStreamPlayerControl void AudioStreamPlayerControl::_play() { - if (_player->is_playing()) { - // '_pausing' variable indicates that we want to pause the audio player, not stop it. See '_on_finished()'. - _pausing = true; - _player->stop(); - _play_button->set_icon(get_icon("MainPlay", "EditorIcons")); - set_process(false); - } else { - _player->play(_current); - _play_button->set_icon(get_icon("Pause", "EditorIcons")); - set_process(true); + if (!stream.is_null()) { + if (_player->is_playing()) { + // '_pausing' variable indicates that we want to pause the audio player, not stop it. See '_on_finished()'. + _pausing = true; + _player->stop(); + _play_button->set_icon(get_icon("MainPlay", "EditorIcons")); + set_process(false); + } else { + _player->play(_current); + _play_button->set_icon(get_icon("Pause", "EditorIcons")); + set_process(true); + } } } @@ -371,7 +371,6 @@ void AudioStreamPlayerControl::_on_input_indicator(Ref p_event) { } } - void AudioStreamPlayerControl::_seek_to(real_t p_x) { _current = p_x / _preview->get_rect().size.x * stream->get_length(); _current = CLAMP(_current, 0, stream->get_length()); diff --git a/modules/gdextensions/common/gd_core.h b/modules/gdextensions/common/gd_core.h index 880726f542fe..eb2c85ffcf51 100644 --- a/modules/gdextensions/common/gd_core.h +++ b/modules/gdextensions/common/gd_core.h @@ -289,4 +289,80 @@ _FORCE_INLINE_ static uint8_t g_alpha(uint32_t rgb) { return rgb >> 24; } _FORCE_INLINE_ static uint32_t g_rgba(uint8_t r, uint8_t g, uint8_t b, uint8_t a) { return ((a & 0xff) << 24) | ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff); } _FORCE_INLINE_ static uint8_t g_gray(uint8_t r, uint8_t g, uint8_t b) { return (r * 11 + g * 16 + b * 5) / 32; } // convert R,G,B to gray 0..255 +// Passthrough Script for dynamic scripting + +class PassthroughScriptInstance : public PlaceHolderScriptInstance { +public: + virtual Variant call(const StringName &p_method, const Variant **p_args, int p_argcount, Variant::CallError &r_error) { + return get_owner()->call(p_method, p_args, p_argcount, r_error); + } +}; + +template +class PassthroughScript : public Script { + Receiver *recv; + +#ifdef TOOLS_ENABLED + Set placeholders; + virtual void _placeholder_erased(PlaceHolderScriptInstance *p_placeholder) { + placeholders.erase(p_placeholder); + } +#endif + +public: + void remove_instance(Object *p_object) {} + virtual bool can_instance() const { return false; } + + virtual StringName get_instance_base_type() const { return InstanceBaseClass::get_class_static(); } + virtual ScriptInstance *instance_create(Object *p_this) { return nullptr; } + virtual bool instance_has(const Object *p_this) const { return false; } + + virtual PlaceHolderScriptInstance *placeholder_instance_create(Object *p_this) { +#ifdef TOOLS_ENABLED + PlaceHolderScriptInstance *sins = memnew(PlaceHolderScriptInstance(nullptr, Ref