From 73e25c287584fc33b4a5f5ef73a512b1e5b8e78f Mon Sep 17 00:00:00 2001 From: DmitriySalnikov Date: Sun, 31 Dec 2023 01:14:39 +0300 Subject: [PATCH] updated updater added connector for telemetry --- .../actions/compile_gdextension/action.yml | 24 +- .github/workflows/gdextension_build.yml | 10 +- .github/workflows/util_update_libs.yml | 7 +- .vscode/c_cpp_properties.json | 5 +- addons/debug_draw_3d/LICENSE | 2 +- examples_dd3d/DebugDrawDemoScene.gd | 24 +- examples_dd3d/DebugDrawDemoScene.tscn | 358 +----------------- examples_dd3d/demo_camera_movement.gd | 56 +++ examples_dd3d/demo_music_visualizer.gd | 152 ++++++++ examples_dd3d/demo_settings_panel.gd | 84 ++++ examples_dd3d/demo_web_docs_version_select.gd | 42 ++ lib_utils.py | 21 +- src/3d/debug_draw_3d.h | 8 +- src/debug_draw_manager.cpp | 19 +- src/debug_draw_manager.h | 11 + src/editor/asset_library_update_checker.cpp | 47 ++- src/editor/asset_library_update_checker.h | 11 +- src/register_types.cpp | 4 +- 18 files changed, 480 insertions(+), 405 deletions(-) create mode 100644 examples_dd3d/demo_camera_movement.gd create mode 100644 examples_dd3d/demo_music_visualizer.gd create mode 100644 examples_dd3d/demo_settings_panel.gd create mode 100644 examples_dd3d/demo_web_docs_version_select.gd diff --git a/.github/actions/compile_gdextension/action.yml b/.github/actions/compile_gdextension/action.yml index f0d449f6..a87d612e 100644 --- a/.github/actions/compile_gdextension/action.yml +++ b/.github/actions/compile_gdextension/action.yml @@ -29,6 +29,11 @@ inputs: use_cache: description: Use cache default: "true" + token: + description: Secrets token + telemetry_version: + description: Telemetry version + default: 2fcd3ec9e528d1cd26978d0d27e9c6a3b2006270 runs: using: composite steps: @@ -38,6 +43,17 @@ runs: run: | echo "sha=$(git rev-parse @:./godot-cpp)" >> $GITHUB_OUTPUT + - name: Checkout telemetry repo + uses: actions/checkout@v4 + id: checkout_tele_repo + if: ${{env.PRODUCTION_BUILD == 'true' && inputs.target == 'editor'}} + continue-on-error: true + with: + repository: ${{github.repository_owner}}/my_telemetry_modules + token: ${{inputs.token}} + ref: ${{inputs.telemetry_version}} + path: src/editor/my_telemetry_modules + - name: Restore .scons_cache directory if: inputs.use_cache != 'false' id: restore_scons_cache @@ -83,7 +99,13 @@ runs: git apply --ignore-space-change --ignore-whitespace ../patches/godot_cpp_exclude_unused_classes.patch git apply --ignore-space-change --ignore-whitespace ../patches/unity_build.patch cd .. - scons platform=${{inputs.platform}} arch=${{inputs.arch}} target=${{inputs.target}} addon_output_dir=${{inputs.output_libs_path}} ${{inputs.additional}} + + telemetry_args="" + if [ "${{env.PRODUCTION_BUILD}}" == "true" ] && [ "${{inputs.target}}" == "editor" ] && [ "${{steps.checkout_tele_repo.conclusion}}" == "success" ]; then + telemetry_args="telemetry_enabled=yes" + fi + + scons platform=${{inputs.platform}} arch=${{inputs.arch}} target=${{inputs.target}} addon_output_dir=${{inputs.output_libs_path}} ${{inputs.additional}} $telemetry_args if [ "${{inputs.target}}" == "template_release" ] && [ "${{inputs.additional_enabled_dd3d}}" == "true" ]; then scons platform=${{inputs.platform}} arch=${{inputs.arch}} target=${{inputs.target}} addon_output_dir=${{inputs.output_libs_path}} force_enabled_dd3d=yes ${{inputs.additional}} fi diff --git a/.github/workflows/gdextension_build.yml b/.github/workflows/gdextension_build.yml index 00fd99d4..784d8efb 100644 --- a/.github/workflows/gdextension_build.yml +++ b/.github/workflows/gdextension_build.yml @@ -6,6 +6,10 @@ on: paths: [src/**, .github/**, "!.github/**/util_*", "patches/**", lib_utils.py, SConstruct] workflow_dispatch: inputs: + production_build: + description: Production build + default: true + type: boolean use_cache: description: Use Cache default: true @@ -22,6 +26,7 @@ permissions: env: SCONS_CACHE: ${{github.workspace}}/.scons-cache/ USE_CACHE: ${{!format('{0}', inputs.use_cache) && 'true' || format('{0}', inputs.use_cache)}} # Default true + PRODUCTION_BUILD: ${{!format('{0}', inputs.production_build) && 'false' || format('{0}', inputs.production_build)}} # Default false OUTPUT_LIBS_PATH: bin FORCE_DISABLE_UNITY: yes GH_TOKEN: ${{ github.token }} @@ -54,6 +59,7 @@ jobs: additional: lto=yes output_libs_path: ${{env.OUTPUT_LIBS_PATH}} use_cache: ${{env.USE_CACHE}} + token: ${{secrets.TELEMETRY_TOKEN}} # ============================================ @@ -84,6 +90,7 @@ jobs: additional: lto=yes output_libs_path: ${{env.OUTPUT_LIBS_PATH}} use_cache: ${{env.USE_CACHE}} + token: ${{secrets.TELEMETRY_TOKEN}} # ============================================ @@ -114,6 +121,7 @@ jobs: additional: lto=yes macos_deployment_target=10.14 output_libs_path: ${{env.OUTPUT_LIBS_PATH}} use_cache: ${{env.USE_CACHE}} + token: ${{secrets.TELEMETRY_TOKEN}} # ============================================ @@ -247,6 +255,6 @@ jobs: - name: Upload GDExtension uses: actions/upload-artifact@v4 with: - name: .gdextension_libs + name: ${{env.PRODUCTION_BUILD == 'true' && '.gdextension_libs_production' || '.gdextension_libs'}} retention-days: 7 path: extracted_files/* diff --git a/.github/workflows/util_update_libs.yml b/.github/workflows/util_update_libs.yml index d66c1189..6c0f5eab 100644 --- a/.github/workflows/util_update_libs.yml +++ b/.github/workflows/util_update_libs.yml @@ -20,12 +20,13 @@ jobs: lfs: true - name: Download GDExtension Binaries - uses: dawidd6/action-download-artifact@v2 + uses: dawidd6/action-download-artifact@v3 with: workflow: gdextension_build.yml branch: ${{github.ref_name}} - name: .gdextension_libs + name: .gdextension_libs_production path: extracted_files/ + event: workflow_dispatch - name: Replace with new files shell: bash @@ -41,7 +42,7 @@ jobs: git config --global user.email 'github-actions-auto-updater[bot]@users.noreply.github.com' git diff git add -A - git commit --allow-empty -am "[CI] ↗️ Updated Binaries: ${{github.sha}}" + git commit -am "[CI] ↗️ Updated Binaries: ${{github.sha}}" git push echo "## Changed files:" >> $GITHUB_STEP_SUMMARY diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 5820f945..45b01a44 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -10,12 +10,15 @@ ], "defines": [ "DEBUG_ENABLED", + "DEV_ENABLED", "UNICODE", "_UNICODE", "GDEXTENSION_LIBRARY", "NOMINMAX", "TYPED_METHOD_BIND", - "HOT_RELOAD_ENABLED" + "HOT_RELOAD_ENABLED", + "TOOLS_ENABLED", + "TELEMETRY_ENABLED" ], "cStandard": "c17", "cppStandard": "c++17", diff --git a/addons/debug_draw_3d/LICENSE b/addons/debug_draw_3d/LICENSE index d5bafad5..617a15b3 100644 --- a/addons/debug_draw_3d/LICENSE +++ b/addons/debug_draw_3d/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2023 DmitriySalnikov +Copyright (c) 2024 DmitriySalnikov Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the Software), to deal diff --git a/examples_dd3d/DebugDrawDemoScene.gd b/examples_dd3d/DebugDrawDemoScene.gd index dffcd7c9..93f9bacf 100644 --- a/examples_dd3d/DebugDrawDemoScene.gd +++ b/examples_dd3d/DebugDrawDemoScene.gd @@ -36,16 +36,18 @@ extends Node3D var button_presses := {} var frame_rendered := false -var phys_frame_called := false +var physics_tick_processed := false var timer_1 := 0.0 var timer_2 := 0.0 var timer_3 := 0.0 var timer_text := 0.0 +var is_4_2_and_higher = Engine.get_version_info()["major"] >= 4 && Engine.get_version_info()["minor"] >= 2 + func _process(delta) -> void: - phys_frame_called = false + physics_tick_processed = false if !update_in_physics: main_update(delta) _update_timers(delta) @@ -55,8 +57,8 @@ func _process(delta) -> void: ## there is an additional check to ensure that a new frame has been drawn before updating the data. func _physics_process(delta: float) -> void: if update_in_physics: - if !phys_frame_called: - phys_frame_called = true + if !physics_tick_processed: + physics_tick_processed = true main_update(delta) _update_timers(delta) @@ -386,8 +388,9 @@ func _more_tests(): var plane = Plane(normal, xf.origin.dot(normal)) var vp: Viewport = get_viewport() - if Engine.is_editor_hint() and Engine.get_singleton(&"EditorInterface").get_editor_viewport_3d(0): - vp = Engine.get_singleton(&"EditorInterface").get_editor_viewport_3d(0) + if is_4_2_and_higher: + if Engine.is_editor_hint() and Engine.get_singleton(&"EditorInterface").get_editor_viewport_3d(0): + vp = Engine.get_singleton(&"EditorInterface").get_editor_viewport_3d(0) var cam = vp.get_camera_3d() if cam: @@ -395,10 +398,11 @@ func _more_tests(): var intersect = plane.intersects_ray(cam.global_position, dir) DebugDraw3D.draw_plane(plane, Color.CORAL * Color(1,1,1, 0.4), pl_node.global_position) - if intersect and intersect.distance_to(pl_node.global_position) < _s11.get_plane_size() * 0.5: - # Need to test different colors on both sides of the plane - var col = Color.FIREBRICK if plane.is_point_over(cam.global_position) else Color.AQUAMARINE - DebugDraw3D.draw_sphere(intersect, 0.3, col) + if is_4_2_and_higher: + if intersect and intersect.distance_to(pl_node.global_position) < _s11.get_plane_size() * 0.5: + # Need to test different colors on both sides of the plane + var col = Color.FIREBRICK if plane.is_point_over(cam.global_position) else Color.AQUAMARINE + DebugDraw3D.draw_sphere(intersect, 0.3, col) func _draw_array_of_boxes(): diff --git a/examples_dd3d/DebugDrawDemoScene.tscn b/examples_dd3d/DebugDrawDemoScene.tscn index 7a11d548..da06d8bb 100644 --- a/examples_dd3d/DebugDrawDemoScene.tscn +++ b/examples_dd3d/DebugDrawDemoScene.tscn @@ -2,6 +2,10 @@ [ext_resource type="Script" path="res://examples_dd3d/DebugDrawDemoScene.gd" id="1"] [ext_resource type="FontFile" uid="uid://erdgllynwqkw" path="res://examples_dd3d/Roboto-Bold.ttf" id="2_aedbq"] +[ext_resource type="Script" path="res://examples_dd3d/demo_camera_movement.gd" id="3_3m1mp"] +[ext_resource type="Script" path="res://examples_dd3d/demo_music_visualizer.gd" id="4_eq2lt"] +[ext_resource type="Script" path="res://examples_dd3d/demo_settings_panel.gd" id="5_31v5h"] +[ext_resource type="Script" path="res://examples_dd3d/demo_web_docs_version_select.gd" id="6_07f7q"] [sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_87638"] sky_horizon_color = Color(0.64625, 0.65575, 0.67075, 1) @@ -14,65 +18,6 @@ sky_material = SubResource("ProceduralSkyMaterial_87638") sky = SubResource("Sky_4jfme") tonemap_mode = 2 -[sub_resource type="GDScript" id="GDScript_yp7g8"] -script/source = "extends Camera3D - -@export var mouse_sensitivity := 0.25 -@export var camera_speed := 10.0 -@export var camera_speed_fast := 30.0 - -var btn_clicked := false -const hPI := PI/2 -var rot_x := 0.0 -var rot_y := 0.0 - - -func _ready(): - rot_x = rotation.y - rot_y = rotation.x - - -func _unhandled_input(event) -> void: - if event is InputEventMouseButton: - btn_clicked = event.pressed - - -func _input(event) -> void: - if btn_clicked: - if event is InputEventMouseMotion: - if event.button_mask == MOUSE_BUTTON_LEFT: - rot_x += -deg_to_rad(event.relative.x * mouse_sensitivity) - rot_y += -deg_to_rad(event.relative.y * mouse_sensitivity) - rot_y = clamp(rot_y, -hPI, hPI) - - transform.basis = Basis() - rotate_object_local(Vector3.UP, rot_x) - rotate_object_local(Vector3.RIGHT, rot_y) - - -func get_axis(neg : Array[Key], pos : Array[Key]) -> float: - var pressed = func (arr: Array[Key]): - var p: float = 0 - for k in arr: - if Input.is_physical_key_pressed(k): - p = 1 - break - return p - - return pressed.call(pos) - pressed.call(neg) - - -func _process(delta) -> void: - var motion := Vector2(get_axis([KEY_S], [KEY_W]), get_axis([KEY_A], [KEY_D])) - var lift := get_axis([KEY_Q, KEY_CTRL], [KEY_E, KEY_SPACE]) - var speed := camera_speed_fast if Input.is_physical_key_pressed(KEY_SHIFT) else camera_speed - motion = motion.limit_length() - - var b := global_transform.basis - var v := (-b.z * motion.x) + (b.x * motion.y) + (b.y * lift) - global_position += v.limit_length() * speed * delta -" - [sub_resource type="Animation" id="9"] resource_name = "New Anim" length = 1.5 @@ -269,161 +214,6 @@ _data = { "RESET": SubResource("8") } -[sub_resource type="GDScript" id="GDScript_atshy"] -script/source = "@tool -extends VBoxContainer - -@export_range(1, 128) var bars_count := 32 -var transform: Transform3D: - get: - return %AudioVisualizer.global_transform -@export_exp_easing(\"inout\") var motion_smoothing := 0.025 -@export_range(0, 0.5) var bar_thickness := 0.065 -@export_range(0, 10) var bars_separation := 0.325 -@export_exp_easing(\"inout\") var color_offset_speed := 0.4 -@export var colors: Gradient = null - -var MusicBus := &\"MusicVisualizer\" -var MAX_HZ := 16000.0 -var MIN_HZ := 50.0 -var MIN_DB := 60.0 -var spectrum: AudioEffectSpectrumAnalyzerInstance = null - -var smoothed_energy: Array[float] = [] -var color_offset := 0.0 - -var _on_data_loaded_callback = null - -func _ready(): - var bus = AudioServer.get_bus_index(MusicBus) - if bus == -1: - print(\"'MusicVisualizer' audio bus not found.\\nSet 'VisualizerAudioBus.tres' as the default bus to use the audio visualizer.\") - - spectrum = AudioServer.get_bus_effect_instance(bus, 0) - %MuteMaster.button_pressed = AudioServer.is_bus_mute(AudioServer.get_bus_index(&\"Master\")) - %VolumeSlider.value = db_to_linear(AudioServer.get_bus_volume_db(AudioServer.get_bus_index(&\"Master\"))) - - if OS.has_feature('web'): - _on_data_loaded_callback = JavaScriptBridge.create_callback(_on_data_loaded) - - # Retrieve the 'gd_callbacks' object - var gdcallbacks: JavaScriptObject = JavaScriptBridge.get_interface(\"gd_callbacks\") - - # Assign the callbacks - gdcallbacks.dataLoaded = _on_data_loaded_callback - - -func _process(_delta): - if %MusicPlayer.playing: - draw_spectrum() - - -func _pressed(): - if DisplayServer.has_feature(DisplayServer.FEATURE_NATIVE_DIALOG): - DisplayServer.file_dialog_show(\"Select audio file\", \"\", \"\", true, DisplayServer.FILE_DIALOG_MODE_OPEN_FILE, [\"*.mp3\"], - func (status: bool, selected: PackedStringArray, _fileter: int): - if status and selected.size(): - print(selected) - var file = FileAccess.open(selected[0], FileAccess.READ) - var data = file.get_buffer(file.get_length()) - open_stream(selected[0].get_extension(), data) - ) - elif OS.has_feature('web'): - JavaScriptBridge.eval(\"loadData()\") - else: - print(\"Not implemented!\") - -func _on_data_loaded(data: Array) -> void: - # Make sure there is something - if (data.size() == 0): - return - - var file_name: String = data[0] - print(\"Opening %s\" % file_name) - - var arr: PackedByteArray = JavaScriptBridge.eval(\"gd_callbacks.dataLoadedResult;\") - open_stream(file_name.get_extension(), arr) - - -func open_stream(file_ext: String, data: PackedByteArray): - var stream: AudioStream = null - if file_ext == \"mp3\": - stream = AudioStreamMP3.new() - stream.data = data - - if not stream.data: - print(\"Failed to load MP3!\") - return - - if not stream: - print(\"Failed to load music!\") - return - - %MusicPlayer.stream = stream - %MusicPlayer.bus = MusicBus - %MusicPlayer.play() - - # Debugging frequencies - for ih in range(1, bars_count + 1): - var _hz: float = log_freq(ih / float(bars_count), MIN_HZ, MAX_HZ) - #print(\"%.0f hz %.2f\" % [_hz, ih / float(bars_count)]) - - -func draw_spectrum(): - var _s1 = DebugDraw3D.scoped_config().set_thickness(bar_thickness).set_center_brightness(0.9) - var prev_hz = MIN_HZ - smoothed_energy.resize(bars_count) - - var xf := transform - var y := xf.basis.y - var h := y.length() - var x := xf.basis.x - var z := xf.basis.z - var origin := xf.origin - (x * bars_count + (x * bars_separation) * (bars_count - 1)) * 0.5 - var sum := 0.0 - - for ih in range(1, bars_count + 1): - var i := ih - 1 - var hz: float = log_freq(ih / float(bars_count), MIN_HZ, MAX_HZ) - var magnitude: float = spectrum.get_magnitude_for_frequency_range(prev_hz, hz, AudioEffectSpectrumAnalyzerInstance.MAGNITUDE_AVERAGE).length() - var energy: float = clampf((MIN_DB + linear_to_db(magnitude)) / MIN_DB, 0, 1) - var e: float = lerp(smoothed_energy[i], energy, clampf(get_process_delta_time() / motion_smoothing if motion_smoothing else 1.0, 0, 1)) - smoothed_energy[i] = e - var height: float = e * h - sum += e - - var s := x * bars_separation - - var a := origin + x * i + s * i + (z * 0.5) - var b := origin + x * (i + 1) + s * i + (z * -0.5) + xf.basis.y.normalized() * clampf(height, 0.001, h) - var c := Color.HOT_PINK - if colors: - c = colors.sample(wrapf(float(ih) / bars_count + color_offset, 0, 1)) - c.s = smoothed_energy[i] * 0.3 + 0.7 - - DebugDraw3D.draw_box_ab(a, b, y, c) - - prev_hz = hz - - color_offset = wrapf(color_offset + sum / smoothed_energy.size() * clampf(get_process_delta_time() / color_offset_speed if color_offset_speed else 1.0, 0, 1), 0, 1) - - -func log10(val: float) -> float: - return log(val) / 2.302585 - - -func log_freq(pos: float, min_hz: float, max_hz: float) -> float: - return pow(10, log10(min_hz) + (log10(max_hz) - log10(min_hz)) * pos) - - -func _on_volume_slider_value_changed(value): - AudioServer.set_bus_volume_db(AudioServer.get_bus_index(&\"Master\"), linear_to_db(value)) - - -func _on_mute_master_toggled(toggled_on): - AudioServer.set_bus_mute(AudioServer.get_bus_index(&\"Master\"), toggled_on) -" - [sub_resource type="Gradient" id="Gradient_tup4c"] offsets = PackedFloat32Array(0.00471698, 0.316038, 0.646226, 1) colors = PackedColorArray(0, 0.0156863, 1, 1, 0.0988327, 1, 0.122977, 1, 1, 0.111986, 0.118936, 1, 0, 0.0156863, 1, 1) @@ -450,138 +240,6 @@ _data = { [sub_resource type="Theme" id="3"] -[sub_resource type="GDScript" id="2"] -script/source = "@tool -extends Control - -@export var switch_to_scene = \"\" -var is_ready := false - -func _ready(): - if Engine.is_editor_hint(): - return - - if ProjectSettings.has_setting(\"application/config/no_csharp_support\"): - %SwitchLang.visible = false - - %SwitchLang.disabled = true - - var test := DebugDraw2D.get_graph(&\"FPS\") - if test: - %FPSEnabled.button_pressed = test.enabled - %FPSMS.button_pressed = test.frame_time_mode - %WidthSlider.value = test.size.x - %BufferSlider.value = test.buffer_size - - %ThicknessSlider.value = get_parent().debug_thickness - %UpdateInPhysics.text = \"Update in physics (%d Ticks) *\" % ProjectSettings.get_setting(\"physics/common/physics_ticks_per_second\") - %UpdateInPhysics.button_pressed = get_parent().update_in_physics - - %ShowStats.button_pressed = get_parent().text_groups_show_stats - %DrawBoxes.button_pressed = get_parent().draw_array_of_boxes - - if get_tree(): - await get_tree().create_timer(0.2).timeout - - %SwitchLang.disabled = false - is_ready = true - - -func _on_CheckBox_toggled(button_pressed: bool) -> void: - if not is_ready: return - - var cfg = DebugDraw2D.get_graph(&\"FPS\") - if cfg: - cfg.enabled = button_pressed - - -func _on_FPSMS_toggled(button_pressed: bool) -> void: - if not is_ready: return - - var cfg = DebugDraw2D.get_graph(&\"FPS\") - if cfg: - cfg.frame_time_mode = button_pressed - - -func _on_Button_pressed() -> void: - get_tree().call_deferred(\"change_scene_to_file\", switch_to_scene) - - -func _on_width_slider_value_changed(value): - if not is_ready: return - - get_parent().graph_size = Vector2i(int(value), get_parent().graph_size.y) - - -func _on_buffer_slider_value_changed(value): - if not is_ready: return - - get_parent().graph_buffer_size = int(value) - - -func _on_thickness_slider_value_changed(value): - if not is_ready: return - - get_parent().debug_thickness = value - - -func _on_update_in_physics_toggled(toggled_on): - get_parent().update_in_physics = toggled_on - - -func _on_show_stats_toggled(toggled_on): - get_parent().text_groups_show_stats = toggled_on - - -func _on_draw_boxes_toggled(toggled_on): - get_parent().draw_array_of_boxes = toggled_on -" - -[sub_resource type="GDScript" id="GDScript_h0fpq"] -script/source = "extends HBoxContainer - -var _on_versions_loaded_callback = null -@onready var btn: OptionButton = $OptionButton - -func _enter_tree(): - hide() - - -func _ready(): - if OS.has_feature('web'): - _on_versions_loaded_callback = JavaScriptBridge.create_callback(_on_versions_loaded) - var versions_callbacks: JavaScriptObject = JavaScriptBridge.get_interface(\"versions_callbacks\") - versions_callbacks.loaded = _on_versions_loaded_callback - - JavaScriptBridge.eval(\"loadVersions()\") - - -func _on_versions_loaded(args: Array) -> void: - if (args.size() == 0): - return - - var current_version: String = args[0] - - var versions_str: String = JavaScriptBridge.eval(\"versions_callbacks.versions;\") - var version_urls_str: String = JavaScriptBridge.eval(\"versions_callbacks.version_urls;\") - var versions: PackedStringArray = versions_str.split(\";\", false) - var version_urls: PackedStringArray = version_urls_str.split(\";\", false) - - if versions: - show() - btn.clear() - btn.item_selected.connect(func(idx): - # move to another version - JavaScriptBridge.eval(\"window.location.href = \\\"%s\\\"\" % version_urls[idx]) - ) - - for i in range(versions.size()): - btn.add_item(versions[i], i) - - if versions[i] == current_version: - btn.select(i) -" - [sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_oj5gf"] content_margin_top = 5.0 content_margin_bottom = 7.0 @@ -617,7 +275,7 @@ cull_mask = 1 current = true fov = 53.0 far = 100.0 -script = SubResource("GDScript_yp7g8") +script = ExtResource("3_3m1mp") [node name="Panel" type="PanelContainer" parent="."] visible = false @@ -933,7 +591,7 @@ offset_left = 10.0 offset_top = 10.0 offset_right = 50.0 offset_bottom = 50.0 -script = SubResource("GDScript_atshy") +script = ExtResource("4_eq2lt") colors = SubResource("Gradient_tup4c") [node name="OpenFile" type="Button" parent="MusicVisualizer"] @@ -1001,7 +659,7 @@ grow_horizontal = 2 grow_vertical = 2 mouse_filter = 2 theme = SubResource("3") -script = SubResource("2") +script = ExtResource("5_31v5h") switch_to_scene = "res://examples_dd3d/DebugDrawDemoSceneCS.tscn" metadata/_edit_lock_ = true @@ -1027,7 +685,7 @@ size_flags_vertical = 8 [node name="VersionBlock" type="HBoxContainer" parent="Settings/HBox/VBoxContainer"] unique_name_in_owner = true layout_mode = 2 -script = SubResource("GDScript_h0fpq") +script = ExtResource("6_07f7q") [node name="Label" type="Label" parent="Settings/HBox/VBoxContainer/VersionBlock"] layout_mode = 2 diff --git a/examples_dd3d/demo_camera_movement.gd b/examples_dd3d/demo_camera_movement.gd new file mode 100644 index 00000000..7fb1e134 --- /dev/null +++ b/examples_dd3d/demo_camera_movement.gd @@ -0,0 +1,56 @@ +extends Camera3D + +@export var mouse_sensitivity := 0.25 +@export var camera_speed := 10.0 +@export var camera_speed_fast := 30.0 + +var btn_clicked := false +const hPI := PI/2 +var rot_x := 0.0 +var rot_y := 0.0 + + +func _ready(): + rot_x = rotation.y + rot_y = rotation.x + + +func _unhandled_input(event) -> void: + if event is InputEventMouseButton: + btn_clicked = event.pressed + + +func _input(event) -> void: + if btn_clicked: + if event is InputEventMouseMotion: + if event.button_mask == MOUSE_BUTTON_LEFT: + rot_x += -deg_to_rad(event.relative.x * mouse_sensitivity) + rot_y += -deg_to_rad(event.relative.y * mouse_sensitivity) + rot_y = clamp(rot_y, -hPI, hPI) + + transform.basis = Basis() + rotate_object_local(Vector3.UP, rot_x) + rotate_object_local(Vector3.RIGHT, rot_y) + + +func get_axis(neg : Array[Key], pos : Array[Key]) -> float: + var pressed = func (arr: Array[Key]): + var p: float = 0 + for k in arr: + if Input.is_physical_key_pressed(k): + p = 1 + break + return p + + return pressed.call(pos) - pressed.call(neg) + + +func _process(delta) -> void: + var motion := Vector2(get_axis([KEY_S], [KEY_W]), get_axis([KEY_A], [KEY_D])) + var lift := get_axis([KEY_Q, KEY_CTRL], [KEY_E, KEY_SPACE]) + var speed := camera_speed_fast if Input.is_physical_key_pressed(KEY_SHIFT) else camera_speed + motion = motion.limit_length() + + var b := global_transform.basis + var v := (-b.z * motion.x) + (b.x * motion.y) + (b.y * lift) + global_position += v.limit_length() * speed * delta diff --git a/examples_dd3d/demo_music_visualizer.gd b/examples_dd3d/demo_music_visualizer.gd new file mode 100644 index 00000000..019b182b --- /dev/null +++ b/examples_dd3d/demo_music_visualizer.gd @@ -0,0 +1,152 @@ +@tool +extends VBoxContainer + +@export_range(1, 128) var bars_count := 32 +var transform: Transform3D: + get: + return %AudioVisualizer.global_transform +@export_exp_easing("inout") var motion_smoothing := 0.025 +@export_range(0, 0.5) var bar_thickness := 0.065 +@export_range(0, 10) var bars_separation := 0.325 +@export_exp_easing("inout") var color_offset_speed := 0.4 +@export var colors: Gradient = null + +var MusicBus := &"MusicVisualizer" +var MAX_HZ := 16000.0 +var MIN_HZ := 50.0 +var MIN_DB := 60.0 +var spectrum: AudioEffectSpectrumAnalyzerInstance = null + +var smoothed_energy: Array[float] = [] +var color_offset := 0.0 + +var _on_data_loaded_callback = null + +func _ready(): + var bus = AudioServer.get_bus_index(MusicBus) + if bus == -1: + print("'MusicVisualizer' audio bus not found.\nSet 'VisualizerAudioBus.tres' as the default bus to use the audio visualizer.") + + spectrum = AudioServer.get_bus_effect_instance(bus, 0) + %MuteMaster.button_pressed = AudioServer.is_bus_mute(AudioServer.get_bus_index(&"Master")) + %VolumeSlider.value = db_to_linear(AudioServer.get_bus_volume_db(AudioServer.get_bus_index(&"Master"))) + + if OS.has_feature('web'): + _on_data_loaded_callback = JavaScriptBridge.create_callback(_on_data_loaded) + + # Retrieve the 'gd_callbacks' object + var gdcallbacks: JavaScriptObject = JavaScriptBridge.get_interface("gd_callbacks") + + # Assign the callbacks + gdcallbacks.dataLoaded = _on_data_loaded_callback + + +func _process(_delta): + if %MusicPlayer.playing: + draw_spectrum() + + +func _pressed(): + if DisplayServer.has_feature(DisplayServer.FEATURE_NATIVE_DIALOG): + DisplayServer.file_dialog_show("Select audio file", "", "", true, DisplayServer.FILE_DIALOG_MODE_OPEN_FILE, ["*.mp3"], + func (status: bool, selected: PackedStringArray, _fileter: int): + if status and selected.size(): + print(selected) + var file = FileAccess.open(selected[0], FileAccess.READ) + var data = file.get_buffer(file.get_length()) + open_stream(selected[0].get_extension(), data) + ) + elif OS.has_feature('web'): + JavaScriptBridge.eval("loadData()") + else: + print("Not implemented!") + +func _on_data_loaded(data: Array) -> void: + # Make sure there is something + if (data.size() == 0): + return + + var file_name: String = data[0] + print("Opening %s" % file_name) + + var arr: PackedByteArray = JavaScriptBridge.eval("gd_callbacks.dataLoadedResult;") + open_stream(file_name.get_extension(), arr) + + +func open_stream(file_ext: String, data: PackedByteArray): + var stream: AudioStream = null + if file_ext == "mp3": + stream = AudioStreamMP3.new() + stream.data = data + + if not stream.data: + print("Failed to load MP3!") + return + + if not stream: + print("Failed to load music!") + return + + %MusicPlayer.stream = stream + %MusicPlayer.bus = MusicBus + %MusicPlayer.play() + + # Debugging frequencies + for ih in range(1, bars_count + 1): + var _hz: float = log_freq(ih / float(bars_count), MIN_HZ, MAX_HZ) + #print("%.0f hz %.2f" % [_hz, ih / float(bars_count)]) + + +func draw_spectrum(): + var _s1 = DebugDraw3D.scoped_config().set_thickness(bar_thickness).set_center_brightness(0.9) + var prev_hz = MIN_HZ + smoothed_energy.resize(bars_count) + + var xf := transform + var y := xf.basis.y + var h := y.length() + var x := xf.basis.x + var z := xf.basis.z + var origin := xf.origin - (x * bars_count + (x * bars_separation) * (bars_count - 1)) * 0.5 + var sum := 0.0 + + for ih in range(1, bars_count + 1): + var i := ih - 1 + var hz: float = log_freq(ih / float(bars_count), MIN_HZ, MAX_HZ) + var magnitude: float = spectrum.get_magnitude_for_frequency_range(prev_hz, hz, AudioEffectSpectrumAnalyzerInstance.MAGNITUDE_AVERAGE).length() + var energy: float = clampf((MIN_DB + linear_to_db(magnitude)) / MIN_DB, 0, 1) + var e: float = lerp(smoothed_energy[i], energy, clampf(get_process_delta_time() / motion_smoothing if motion_smoothing else 1.0, 0, 1)) + smoothed_energy[i] = e + var height: float = e * h + sum += e + + var s := x * bars_separation + + var a := origin + x * i + s * i + (z * 0.5) + var b := origin + x * (i + 1) + s * i + (z * -0.5) + xf.basis.y.normalized() * clampf(height, 0.001, h) + var c := Color.HOT_PINK + if colors: + c = colors.sample(wrapf(float(ih) / bars_count + color_offset, 0, 1)) + c.s = clamp(c.s - smoothed_energy[i] * 0.3, 0, 1.0) + + DebugDraw3D.draw_box_ab(a, b, y, c) + + prev_hz = hz + + color_offset = wrapf(color_offset + sum / smoothed_energy.size() * clampf(get_process_delta_time() / color_offset_speed if color_offset_speed else 1.0, 0, 1), 0, 1) + + +func log10(val: float) -> float: + return log(val) / 2.302585 + + +func log_freq(pos: float, min_hz: float, max_hz: float) -> float: + return pow(10, log10(min_hz) + (log10(max_hz) - log10(min_hz)) * pos) + + +func _on_volume_slider_value_changed(value): + AudioServer.set_bus_volume_db(AudioServer.get_bus_index(&"Master"), linear_to_db(value)) + + +func _on_mute_master_toggled(toggled_on): + AudioServer.set_bus_mute(AudioServer.get_bus_index(&"Master"), toggled_on) diff --git a/examples_dd3d/demo_settings_panel.gd b/examples_dd3d/demo_settings_panel.gd new file mode 100644 index 00000000..3e73f9b0 --- /dev/null +++ b/examples_dd3d/demo_settings_panel.gd @@ -0,0 +1,84 @@ +@tool +extends Control + +@export var switch_to_scene = "" +var is_ready := false + +func _ready(): + if Engine.is_editor_hint(): + return + + if ProjectSettings.has_setting("application/config/no_csharp_support"): + %SwitchLang.visible = false + + %SwitchLang.disabled = true + + var test := DebugDraw2D.get_graph(&"FPS") + if test: + %FPSEnabled.button_pressed = test.enabled + %FPSMS.button_pressed = test.frame_time_mode + %WidthSlider.value = test.size.x + %BufferSlider.value = test.buffer_size + + %ThicknessSlider.value = get_parent().debug_thickness + %UpdateInPhysics.text = "Update in physics (%d Ticks) *" % ProjectSettings.get_setting("physics/common/physics_ticks_per_second") + %UpdateInPhysics.button_pressed = get_parent().update_in_physics + + %ShowStats.button_pressed = get_parent().text_groups_show_stats + %DrawBoxes.button_pressed = get_parent().draw_array_of_boxes + + if get_tree(): + await get_tree().create_timer(0.2).timeout + + %SwitchLang.disabled = false + is_ready = true + + +func _on_CheckBox_toggled(button_pressed: bool) -> void: + if not is_ready: return + + var cfg = DebugDraw2D.get_graph(&"FPS") + if cfg: + cfg.enabled = button_pressed + + +func _on_FPSMS_toggled(button_pressed: bool) -> void: + if not is_ready: return + + var cfg = DebugDraw2D.get_graph(&"FPS") + if cfg: + cfg.frame_time_mode = button_pressed + + +func _on_Button_pressed() -> void: + get_tree().call_deferred("change_scene_to_file", switch_to_scene) + + +func _on_width_slider_value_changed(value): + if not is_ready: return + + get_parent().graph_size = Vector2i(int(value), get_parent().graph_size.y) + + +func _on_buffer_slider_value_changed(value): + if not is_ready: return + + get_parent().graph_buffer_size = int(value) + + +func _on_thickness_slider_value_changed(value): + if not is_ready: return + + get_parent().debug_thickness = value + + +func _on_update_in_physics_toggled(toggled_on): + get_parent().update_in_physics = toggled_on + + +func _on_show_stats_toggled(toggled_on): + get_parent().text_groups_show_stats = toggled_on + + +func _on_draw_boxes_toggled(toggled_on): + get_parent().draw_array_of_boxes = toggled_on diff --git a/examples_dd3d/demo_web_docs_version_select.gd b/examples_dd3d/demo_web_docs_version_select.gd new file mode 100644 index 00000000..c63bc496 --- /dev/null +++ b/examples_dd3d/demo_web_docs_version_select.gd @@ -0,0 +1,42 @@ +extends HBoxContainer + +var _on_versions_loaded_callback = null +@onready var btn: OptionButton = $OptionButton + +func _enter_tree(): + hide() + + +func _ready(): + if OS.has_feature('web'): + _on_versions_loaded_callback = JavaScriptBridge.create_callback(_on_versions_loaded) + var versions_callbacks: JavaScriptObject = JavaScriptBridge.get_interface("versions_callbacks") + versions_callbacks.loaded = _on_versions_loaded_callback + + JavaScriptBridge.eval("loadVersions()") + + +func _on_versions_loaded(args: Array) -> void: + if (args.size() == 0): + return + + var current_version: String = args[0] + + var versions_str: String = JavaScriptBridge.eval("versions_callbacks.versions;") + var version_urls_str: String = JavaScriptBridge.eval("versions_callbacks.version_urls;") + var versions: PackedStringArray = versions_str.split(";", false) + var version_urls: PackedStringArray = version_urls_str.split(";", false) + + if versions: + show() + btn.clear() + btn.item_selected.connect(func(idx): + # move to another version + JavaScriptBridge.eval("window.location.href = \"%s\"" % version_urls[idx]) + ) + + for i in range(versions.size()): + btn.add_item(versions[i], i) + + if versions[i] == current_version: + btn.select(i) diff --git a/lib_utils.py b/lib_utils.py index 466d1baf..ede79084 100644 --- a/lib_utils.py +++ b/lib_utils.py @@ -3,10 +3,9 @@ import os import json from patches import unity_tools -from pathlib import Path lib_name = "dd3d" -output_dir = Path("addons") / "debug_draw_3d" / "libs" +output_dir = os.path.join("addons", "debug_draw_3d", "libs") src_folder = "src" @@ -15,6 +14,7 @@ def setup_options(env, arguments, gen_help): opts = Variables([], arguments) + opts.Add(BoolVariable("telemetry_enabled", "Enable the telemetry module", False)) opts.Add(BoolVariable("tracy_enabled", "Enable tracy profiler", False)) opts.Add(BoolVariable("force_enabled_dd3d", "Keep the rendering code in the release build", False)) opts.Add(BoolVariable("lto", "Link-time optimization", False)) @@ -30,6 +30,15 @@ def setup_defines_and_flags(env, src_out): if "release" in env["target"] and not env["force_enabled_dd3d"]: env.Append(CPPDEFINES=["DISABLE_DEBUG_RENDERING"]) + if env["telemetry_enabled"]: + tele_src = "src/editor/my_telemetry_modules/GDExtension/usage_time_reporter.cpp" + if os.path.exists(tele_src): + env.Append(CPPDEFINES=["TELEMETRY_ENABLED"]) + src_out.append(tele_src) + print("Compiling with telemetry support!") + else: + print("No telemetry source file found. telemetry_enabled will be ignored!") + if env["lto"]: if env.get("is_msvc", False): env.AppendUnique(CCFLAGS=["/GL"]) @@ -40,11 +49,9 @@ def setup_defines_and_flags(env, src_out): env.AppendUnique(LINKFLAGS=["-flto"]) if env["tracy_enabled"]: - env.Append(CPPDEFINES=["TRACY_ENABLE"]) - env.Append(CPPDEFINES=["TRACY_ON_DEMAND"]) - env.Append(CPPDEFINES=["TRACY_DELAYED_INIT"]) - env.Append(CPPDEFINES=["TRACY_MANUAL_LIFETIME"]) + env.Append(CPPDEFINES=["TRACY_ENABLE", "TRACY_ON_DEMAND", "TRACY_DELAYED_INIT", "TRACY_MANUAL_LIFETIME"]) src_out.append("src/thirdparty/tracy/public/TracyClient.cpp") + print() # A utility function for getting the name of an unblocked file @@ -195,7 +202,7 @@ def generate_resources_cpp_h_files(input_files, namespace, output_no_ext, src_ou gen_dir = "gen/" out_dir = src_folder + "/" + gen_dir - Path(out_dir).mkdir(parents=True, exist_ok=True) + os.makedirs(out_dir, exist_ok=True) cpp_name = output_no_ext + ".cpp" h_name = output_no_ext + ".h" diff --git a/src/3d/debug_draw_3d.h b/src/3d/debug_draw_3d.h index 6e358b3d..df2f7a5b 100644 --- a/src/3d/debug_draw_3d.h +++ b/src/3d/debug_draw_3d.h @@ -59,15 +59,15 @@ enum class ConvertableInstanceType : char; * It is worth mentioning that physics ticks may not be called every frame or may be called several times in one frame. * So if you want to avoid multiple identical `draw_` calls, you can call `draw_` methods in `_process` or use such a check: * ```python - * var physics_frame_called := false + * var physics_tick_processed := false * func _process(delta: float) -> void: * # Reset after rendering frame - * physics_frame_called = false + * physics_tick_processed = false * # some logic * * func _physics_process(delta: float) -> void: - * if not physics_frame_called: - * physics_frame_called = true + * if not physics_tick_processed: + * physics_tick_processed = true * # some DD3D logic * ``` */ diff --git a/src/debug_draw_manager.cpp b/src/debug_draw_manager.cpp index b8ce1f0e..46afa748 100644 --- a/src/debug_draw_manager.cpp +++ b/src/debug_draw_manager.cpp @@ -60,6 +60,12 @@ void DebugDrawManager::_bind_methods() { #define REG_CLASS_NAME DebugDrawManager +#ifdef TOOLS_ENABLED +#ifdef TELEMETRY_ENABLED + ClassDB::bind_method(D_METHOD(NAMEOF(_on_telemetry_sending_completed)), &DebugDrawManager::_on_telemetry_sending_completed); +#endif +#endif + // TODO use CALLABLE_MP in 4.2! ClassDB::bind_method(D_METHOD(NAMEOF(_integrate_into_engine)), &DebugDrawManager::_integrate_into_engine); ClassDB::bind_method(D_METHOD(NAMEOF(_on_scene_changed)), &DebugDrawManager::_on_scene_changed); @@ -325,8 +331,13 @@ void DebugDrawManager::_integrate_into_engine() { #endif #ifdef TOOLS_ENABLED - if (IS_EDITOR_HINT()) + if (IS_EDITOR_HINT()) { _try_to_update_cs_bindings(); + +#ifdef TELEMETRY_ENABLED + time_usage_reporter = std::make_unique([&]() { call_deferred(NAMEOF(_on_telemetry_sending_completed)); }); +#endif + } #endif } @@ -392,4 +403,10 @@ void DebugDrawManager::_try_to_update_cs_bindings() { g.generate(); } } + +#ifdef TELEMETRY_ENABLED +void DebugDrawManager::_on_telemetry_sending_completed() { + time_usage_reporter->stop_thread(); +} +#endif #endif diff --git a/src/debug_draw_manager.h b/src/debug_draw_manager.h index b4669ef3..d602782c 100644 --- a/src/debug_draw_manager.h +++ b/src/debug_draw_manager.h @@ -2,6 +2,12 @@ #include "utils/compiler.h" +#ifdef TOOLS_ENABLED +#ifdef TELEMETRY_ENABLED +#include "editor/my_telemetry_modules/GDExtension/usage_time_reporter.h" +#endif +#endif + GODOT_WARNING_DISABLE() #include GODOT_WARNING_RESTORE() @@ -92,6 +98,11 @@ class DebugDrawManager : public CanvasLayer { #ifdef TOOLS_ENABLED void _try_to_update_cs_bindings(); + +#ifdef TELEMETRY_ENABLED + std::unique_ptr time_usage_reporter; + void _on_telemetry_sending_completed(); +#endif #endif // TEST C# API GENERATOR diff --git a/src/editor/asset_library_update_checker.cpp b/src/editor/asset_library_update_checker.cpp index 7a62d521..717e9109 100644 --- a/src/editor/asset_library_update_checker.cpp +++ b/src/editor/asset_library_update_checker.cpp @@ -12,8 +12,8 @@ GODOT_WARNING_DISABLE() GODOT_WARNING_RESTORE() using namespace godot; -void AssetLibraryUpdateChecker::_bind_methods() { -#define REG_CLASS_NAME AssetLibraryUpdateChecker +void _DebugDraw3DAssetLibraryUpdateChecker::_bind_methods() { +#define REG_CLASS_NAME _DebugDraw3DAssetLibraryUpdateChecker REG_METHOD(request_completed); REG_METHOD(init); @@ -21,15 +21,24 @@ void AssetLibraryUpdateChecker::_bind_methods() { #undef REG_CLASS_NAME } -void AssetLibraryUpdateChecker::request_completed(PackedByteArray body) { +void _DebugDraw3DAssetLibraryUpdateChecker::request_completed(String body) { ZoneScoped; if (http_thread.joinable()) { is_thread_closing = true; http_thread.join(); - http.unref(); } - Dictionary dict = JSON::parse_string(body.get_string_from_utf8()); + Ref json; + json.instantiate(); + Error err = json->parse(body); + Variant p = json->get_data(); + + if (err != Error::OK || p.get_type() != Variant::Type::DICTIONARY) { + DEV_PRINT_STD_ERR(NAMEOF(_DebugDraw3DAssetLibraryUpdateChecker) ": Failed to parse the response body.\n"); + return; + } + + Dictionary dict = p; String ver = dict["version_string"]; String download_url = dict["download_url"]; String addon_godot_version = dict["godot_version"]; @@ -95,11 +104,13 @@ void AssetLibraryUpdateChecker::request_completed(PackedByteArray body) { } } -void AssetLibraryUpdateChecker::init() { +void _DebugDraw3DAssetLibraryUpdateChecker::init() { ZoneScoped; - http.instantiate(); http_thread = std::thread([&]() { + Ref http = nullptr; + http.instantiate(); + Error err = Error::OK; if (http.is_valid() && !is_thread_closing) { @@ -107,7 +118,7 @@ void AssetLibraryUpdateChecker::init() { err = http->poll(); if (err != Error::OK) { - PRINT_ERROR("Update checker: Failed to initialize connection. Error: {0}", UtilityFunctions::error_string(err)); + PRINT_ERROR(NAMEOF(_DebugDraw3DAssetLibraryUpdateChecker) ": Failed to initialize connection. Error: {0}", UtilityFunctions::error_string(err)); return; } } else { @@ -118,7 +129,7 @@ void AssetLibraryUpdateChecker::init() { while (http.is_valid() && !is_thread_closing) { err = http->poll(); if (err != Error::OK) { - PRINT_ERROR("Update checker: Failed to connect. Error: {0}", UtilityFunctions::error_string(err)); + PRINT_ERROR(NAMEOF(_DebugDraw3DAssetLibraryUpdateChecker) ": Failed to connect. Error: {0}", UtilityFunctions::error_string(err)); return; } @@ -129,7 +140,7 @@ void AssetLibraryUpdateChecker::init() { case godot::HTTPClient::STATUS_CANT_RESOLVE: case godot::HTTPClient::STATUS_CANT_CONNECT: case godot::HTTPClient::STATUS_TLS_HANDSHAKE_ERROR: - PRINT_ERROR("Update checker: Connection error: {0}", status); + PRINT_ERROR(NAMEOF(_DebugDraw3DAssetLibraryUpdateChecker) ": Connection error: {0}", status); return; case godot::HTTPClient::STATUS_RESOLVING: case godot::HTTPClient::STATUS_CONNECTING: @@ -137,7 +148,7 @@ void AssetLibraryUpdateChecker::init() { case godot::HTTPClient::STATUS_BODY: default: if (status != prev_status) { - DEV_PRINT_STD("Update checker: Connecting status: %d\n", status); + DEV_PRINT_STD(NAMEOF(_DebugDraw3DAssetLibraryUpdateChecker) ": Connecting status: %d\n", status); } break; case godot::HTTPClient::STATUS_CONNECTED: @@ -156,7 +167,7 @@ void AssetLibraryUpdateChecker::init() { String request_url = "/asset-library/api/asset/" + String::num_int64(addon_id); err = http->request(HTTPClient::METHOD_GET, request_url, PackedStringArray()); if (err != Error::OK) { - PRINT_ERROR("Update checker: Failed to create a request. Error: {0}", UtilityFunctions::error_string(err)); + PRINT_ERROR(NAMEOF(_DebugDraw3DAssetLibraryUpdateChecker) ": Failed to create a request. Error: {0}", UtilityFunctions::error_string(err)); return; } @@ -164,7 +175,7 @@ void AssetLibraryUpdateChecker::init() { err = http->poll(); if (err != Error::OK) { - PRINT_ERROR("Update checker: Failed to get a response from \"{0}\". Error: {1}", godot_domain + request_url, UtilityFunctions::error_string(err)); + PRINT_ERROR(NAMEOF(_DebugDraw3DAssetLibraryUpdateChecker) ": Failed to get a response from \"{0}\". Error: {1}", godot_domain + request_url, UtilityFunctions::error_string(err)); return; } @@ -180,11 +191,11 @@ void AssetLibraryUpdateChecker::init() { tmp = http->read_response_body_chunk(); } - call_deferred(NAMEOF(request_completed), res); + call_deferred(NAMEOF(request_completed), res.get_string_from_utf8()); return; } else { if (code != 0) { - PRINT_ERROR("Update checker: Failed to get a response from \"{0}\". Code: {1}", godot_domain + request_url, code); + PRINT_ERROR(NAMEOF(_DebugDraw3DAssetLibraryUpdateChecker) ": Failed to get a response from \"{0}\". Code: {1}", godot_domain + request_url, code); return; } } @@ -192,11 +203,11 @@ void AssetLibraryUpdateChecker::init() { std::this_thread::sleep_for(std::chrono::milliseconds(100)); } - DEV_PRINT_STD("Update checker: Thread finished\n"); + DEV_PRINT_STD(NAMEOF(_DebugDraw3DAssetLibraryUpdateChecker) ": Thread finished\n"); }); } -AssetLibraryUpdateChecker::AssetLibraryUpdateChecker() { +_DebugDraw3DAssetLibraryUpdateChecker::_DebugDraw3DAssetLibraryUpdateChecker() { addon_id = 1766; addon_name = "Debug Draw 3D"; repository_name = "godot_debug_draw_3d"; @@ -215,7 +226,7 @@ AssetLibraryUpdateChecker::AssetLibraryUpdateChecker() { call_deferred(NAMEOF(init)); } -AssetLibraryUpdateChecker::~AssetLibraryUpdateChecker() { +_DebugDraw3DAssetLibraryUpdateChecker::~_DebugDraw3DAssetLibraryUpdateChecker() { if (http_thread.joinable()) { is_thread_closing = true; http_thread.join(); diff --git a/src/editor/asset_library_update_checker.h b/src/editor/asset_library_update_checker.h index 75fcc610..05f1d1eb 100644 --- a/src/editor/asset_library_update_checker.h +++ b/src/editor/asset_library_update_checker.h @@ -13,13 +13,12 @@ GODOT_WARNING_DISABLE() GODOT_WARNING_RESTORE() using namespace godot; -class AssetLibraryUpdateChecker : public RefCounted { - GDCLASS(AssetLibraryUpdateChecker, RefCounted) +class _DebugDraw3DAssetLibraryUpdateChecker : public RefCounted { + GDCLASS(_DebugDraw3DAssetLibraryUpdateChecker, RefCounted) private: std::thread http_thread; bool is_thread_closing = false; - Ref http = nullptr; int addon_id; String addon_name; String repository_name; @@ -34,11 +33,11 @@ class AssetLibraryUpdateChecker : public RefCounted { static void _bind_methods(); public: - void request_completed(PackedByteArray body); + void request_completed(String body); void init(); - AssetLibraryUpdateChecker(); - ~AssetLibraryUpdateChecker(); + _DebugDraw3DAssetLibraryUpdateChecker(); + ~_DebugDraw3DAssetLibraryUpdateChecker(); }; #endif diff --git a/src/register_types.cpp b/src/register_types.cpp index f2edd40c..0dc382d1 100644 --- a/src/register_types.cpp +++ b/src/register_types.cpp @@ -22,7 +22,7 @@ GODOT_WARNING_RESTORE() #include "editor/editor_menu_extensions.h" #include "editor/asset_library_update_checker.h" -Ref upd_checker; +Ref<_DebugDraw3DAssetLibraryUpdateChecker> upd_checker; #endif #endif using namespace godot; @@ -64,7 +64,7 @@ void initialize_debug_draw_3d_module(ModuleInitializationLevel p_level) { EditorPlugins::add_by_type(); // TODO register as unexposed - ClassDB::register_class(); + ClassDB::register_class<_DebugDraw3DAssetLibraryUpdateChecker>(); upd_checker.instantiate(); } #endif