From ef1ee7b3a0e3118bf43d49e0071bb7b0ebfac821 Mon Sep 17 00:00:00 2001 From: Nordup Date: Mon, 22 May 2023 01:12:33 +0300 Subject: [PATCH] gd: send_fd --- .../the_gates/resources/command_events.res | Bin 0 -> 220 bytes project/the_gates/resources/ui_events.res | Bin 0 -> 216 bytes project/the_gates/resources/ui_events.tres | 6 -- project/the_gates/scenes/app.tscn | 2 +- project/the_gates/scenes/world.tscn | 25 +++++-- .../the_gates/scripts/loading/pack_loader.gd | 58 +--------------- .../scripts/resources/command_events.gd | 8 +++ .../the_gates/scripts/sandbox/command_sync.gd | 23 +++++++ .../scripts/{input => sandbox}/input_sync.gd | 0 .../scripts/sandbox/render_result.gd | 65 ++++++++++++++++++ 10 files changed, 118 insertions(+), 69 deletions(-) create mode 100644 project/the_gates/resources/command_events.res create mode 100644 project/the_gates/resources/ui_events.res delete mode 100644 project/the_gates/resources/ui_events.tres create mode 100644 project/the_gates/scripts/resources/command_events.gd create mode 100644 project/the_gates/scripts/sandbox/command_sync.gd rename project/the_gates/scripts/{input => sandbox}/input_sync.gd (100%) create mode 100644 project/the_gates/scripts/sandbox/render_result.gd diff --git a/project/the_gates/resources/command_events.res b/project/the_gates/resources/command_events.res new file mode 100644 index 0000000000000000000000000000000000000000..19a435008ed2d3bd6397537840d10041897a6474 GIT binary patch literal 220 zcmV<203-iWQ$s@n000005C8y60RRBR0000ewJ-f(O90gc08$AcDUd~J4F8w!?oNCc zH{WONUN*aTgC$&U`}Jzkf@;8Xsn~$RK-0gqMpDp<*1uq8aidUgm+JE;29_qqGN)3d z%AIXu8=0z4BYNgJkyK9phW9n-yl|alaWbm8NU`cy{Db9$Yk^3xy%(Y1X)cZc00G3~ zZ(dhbqTKZ#{=$S0764BRa5Q;0R#eaf_&paRVz47ASb(R7S;H^GV+;gqI(`X*fe~e1 W;SUEU&ZGg8g9iX^184(MQ$s`6L|oMX literal 0 HcmV?d00001 diff --git a/project/the_gates/resources/ui_events.res b/project/the_gates/resources/ui_events.res new file mode 100644 index 0000000000000000000000000000000000000000..b6dc41fbcdd32ed047468649cc20b7509b36e304 GIT binary patch literal 216 zcmWFvc6MfB00IF921iB)h66yR##a5m362a~Ss4zUkkgo;-OIT7KM2%4ui0d%Fo~eFLRWc#D@KdsFWxk={1Ov#P3d zX5g;+K1r_T-@;)%DY9YS5BF*B^J)tJx}p9fyIIt#i2)+*4FzhwN1mCl5jef>>NoL! z2b=iC8N9d^Oe)R8bS^OeuoY4k+OSwHqG5Slq;_&eMDUOKQan8xpSkKSI11GmBOR0j Qr?Ig#Tx7ez76kMY06WfBUjP6A literal 0 HcmV?d00001 diff --git a/project/the_gates/resources/ui_events.tres b/project/the_gates/resources/ui_events.tres deleted file mode 100644 index 2d646ec..0000000 --- a/project/the_gates/resources/ui_events.tres +++ /dev/null @@ -1,6 +0,0 @@ -[gd_resource type="Resource" script_class="UiEvents" load_steps=2 format=3 uid="uid://h1gdyodd66gv"] - -[ext_resource type="Script" path="res://the_gates/scripts/resources/ui_events.gd" id="1_kqets"] - -[resource] -script = ExtResource("1_kqets") diff --git a/project/the_gates/scenes/app.tscn b/project/the_gates/scenes/app.tscn index 546bcd5..dcfd76a 100644 --- a/project/the_gates/scenes/app.tscn +++ b/project/the_gates/scenes/app.tscn @@ -3,7 +3,7 @@ [ext_resource type="Script" path="res://the_gates/scripts/app.gd" id="1_skc7d"] [ext_resource type="Resource" uid="uid://b1xvdym0qh6td" path="res://the_gates/resources/gate_events.res" id="2_cdryv"] [ext_resource type="PackedScene" uid="uid://5btb7nvgmfhl" path="res://the_gates/scenes/menu.tscn" id="3_o1f7b"] -[ext_resource type="PackedScene" uid="uid://dagj0celx6tjq" path="res://the_gates/scenes/world.tscn" id="4_cmlvo"] +[ext_resource type="PackedScene" uid="uid://dle3s7sp53jat" path="res://the_gates/scenes/world.tscn" id="4_cmlvo"] [ext_resource type="Script" path="res://the_gates/scripts/bookmark_saver.gd" id="5_ev0ch"] [ext_resource type="Resource" uid="uid://bewhdj6jugt6q" path="res://the_gates/resources/bookmarks.tres" id="6_rupvx"] [ext_resource type="PackedScene" uid="uid://byrcbqat0n2px" path="res://the_gates/scenes/debug.tscn" id="7_3xeb8"] diff --git a/project/the_gates/scenes/world.tscn b/project/the_gates/scenes/world.tscn index c6bf4c9..5682185 100644 --- a/project/the_gates/scenes/world.tscn +++ b/project/the_gates/scenes/world.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=33 format=3 uid="uid://dagj0celx6tjq"] +[gd_scene load_steps=36 format=3 uid="uid://dle3s7sp53jat"] [ext_resource type="Script" path="res://the_gates/scripts/loading/pack_loader.gd" id="1_5swiq"] [ext_resource type="Script" path="res://the_gates/scripts/loading/gate_loader.gd" id="1_coscx"] @@ -10,7 +10,6 @@ [ext_resource type="Script" path="res://the_gates/scripts/ui/world/loading_ui.gd" id="5_vcmvs"] [ext_resource type="Script" path="res://the_gates/scripts/ui/world/gate_info.gd" id="6_iwanm"] [ext_resource type="Texture2D" uid="uid://bvvgx8ij2mdna" path="res://the_gates/textures/star.png" id="6_mtwek"] -[ext_resource type="Resource" uid="uid://h1gdyodd66gv" path="res://the_gates/resources/ui_events.tres" id="7_bmkgi"] [ext_resource type="Script" path="res://the_gates/scripts/ui/world/home.gd" id="8_bo3qr"] [ext_resource type="Texture2D" uid="uid://c5hu6cmvuipg7" path="res://the_gates/textures/star_filled.png" id="8_gho7k"] [ext_resource type="Resource" uid="uid://bewhdj6jugt6q" path="res://the_gates/resources/bookmarks.tres" id="8_wox3p"] @@ -18,7 +17,11 @@ [ext_resource type="Texture2D" uid="uid://cykx425p6ylwr" path="res://the_gates/textures/background.png" id="9_req2b"] [ext_resource type="Script" path="res://the_gates/scripts/ui/world/release_focus.gd" id="10_6a8ws"] [ext_resource type="PackedScene" path="res://the_gates/scenes/components/hint.tscn" id="11_cltj4"] -[ext_resource type="Script" path="res://the_gates/scripts/input/input_sync.gd" id="18_rsdyb"] +[ext_resource type="Script" path="res://the_gates/scripts/sandbox/input_sync.gd" id="19_7opuh"] +[ext_resource type="Script" path="res://the_gates/scripts/sandbox/render_result.gd" id="19_vfqxk"] +[ext_resource type="Script" path="res://the_gates/scripts/sandbox/command_sync.gd" id="20_js3fi"] +[ext_resource type="Resource" uid="uid://l1quiaghft2f" path="res://the_gates/resources/command_events.res" id="22_lfk5j"] +[ext_resource type="Resource" uid="uid://crjhix0osmtnf" path="res://the_gates/resources/ui_events.res" id="22_ryq4n"] [sub_resource type="StyleBoxFlat" id="StyleBoxFlat_shmbc"] bg_color = Color(0.3384, 0.188, 0.47, 1) @@ -81,7 +84,6 @@ gate_events = ExtResource("2_ot8b0") script = ExtResource("1_5swiq") gate_events = ExtResource("2_ot8b0") render_result = NodePath("../../WorldCanvas/RenderResult") -splash_screen = ExtResource("9_req2b") [node name="UICanvas" type="CanvasLayer" parent="."] follow_viewport_enabled = true @@ -168,7 +170,7 @@ anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 script = ExtResource("4_xatjs") -ui_events = ExtResource("7_bmkgi") +ui_events = ExtResource("22_ryq4n") [node name="Blur" type="Panel" parent="UICanvas/UI"] material = SubResource("ShaderMaterial_kc7rv") @@ -719,11 +721,20 @@ anchor_right = 1.0 anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 +script = ExtResource("19_vfqxk") +gate_events = ExtResource("2_ot8b0") +command_events = ExtResource("22_lfk5j") +splash_screen = ExtResource("9_req2b") [node name="InputSync" type="Node" parent="WorldCanvas"] -script = ExtResource("18_rsdyb") +script = ExtResource("19_7opuh") gate_events = ExtResource("2_ot8b0") -ui_events = ExtResource("7_bmkgi") +ui_events = ExtResource("22_ryq4n") + +[node name="CommandSync" type="CommandSync" parent="WorldCanvas"] +script = ExtResource("20_js3fi") +gate_events = ExtResource("2_ot8b0") +command_events = ExtResource("22_lfk5j") [connection signal="pressed" from="UICanvas/UI/Blur/HideOnPress" to="UICanvas/UI" method="hide_ui"] [connection signal="pressed" from="UICanvas/UI/GateInfo/Bookmark/Star" to="UICanvas/UI/GateInfo" method="_on_star_pressed"] diff --git a/project/the_gates/scripts/loading/pack_loader.gd b/project/the_gates/scripts/loading/pack_loader.gd index 660383d..8f4015c 100644 --- a/project/the_gates/scripts/loading/pack_loader.gd +++ b/project/the_gates/scripts/loading/pack_loader.gd @@ -2,37 +2,14 @@ extends Node class_name PackLoader @export var gate_events: GateEvents -@export var render_result: TextureRect -@export var splash_screen: Texture2D +@export var render_result: RenderResult var gate: Gate var pid: int -@onready var width = get_viewport().size.x -@onready var height = get_viewport().size.y - -var rd: RenderingDevice -var ext_texure: ExternalTexture -var result_texture_rid: RID - func _ready() -> void: gate_events.gate_loaded.connect(create_process) - initialize() - - -func _process(_delta: float) -> void: - texture_update() - - -func initialize() -> void: - rd = RenderingServer.get_rendering_device() - - var image = Image.create(width, height, false, Image.FORMAT_RGB8) - render_result.texture = ImageTexture.create_from_image(image) - result_texture_rid = RenderingServer.texture_get_rd_texture(render_result.texture.get_rid()) - if not result_texture_rid.is_valid(): Debug.logerr("Cannot create ImageTexture") - else: Debug.logclr("Render result texture created", Color.AQUAMARINE) func create_process(_gate: Gate) -> void: @@ -41,15 +18,11 @@ func create_process(_gate: Gate) -> void: var sandbox_path = "/home/nordup/projects/godot/the-gates-folder/the-gates/bin/godot.linuxbsd.editor.dev.sandbox.x86_64.llvm" var pack_file = ProjectSettings.globalize_path(gate.resource_pack) var main_pid = OS.get_process_id() - var fd = create_external_texture() - if fd == -1: Debug.logerr("Cannot create external texture"); return - else: Debug.logclr("External texture created " + str(fd), Color.AQUAMARINE) var args = [ "--main-pack", pack_file, - "--resolution", "%dx%d" % [width, height], - "--external-image", fd, - "--main-pid", main_pid + "--resolution", "%dx%d" % [render_result.width, render_result.height], + "--fd-path", render_result.fd_path ] Debug.logclr(sandbox_path + " " + " ".join(args), Color.DARK_VIOLET) pid = OS.create_process(sandbox_path, args) @@ -57,31 +30,6 @@ func create_process(_gate: Gate) -> void: gate_events.gate_entered_emit() -func create_external_texture() -> int: - var t_format: RDTextureFormat = RDTextureFormat.new() - t_format.format = RenderingDevice.DATA_FORMAT_R8G8B8A8_UNORM - t_format.usage_bits = RenderingDevice.TEXTURE_USAGE_CAN_COPY_FROM_BIT | \ - RenderingDevice.TEXTURE_USAGE_CAN_UPDATE_BIT - t_format.width = width - t_format.height = height - t_format.depth = 1 - var t_view: RDTextureView = RDTextureView.new() - - var image = splash_screen.get_image() - image.convert(Image.FORMAT_RGBA8) - image.clear_mipmaps() - - ext_texure = ExternalTexture.new() - ext_texure.create(t_format, t_view, [image.get_data()]) - return ext_texure.get_fd() - - -func texture_update() -> void: - if ext_texure == null or not ext_texure.get_rid().is_valid(): return - if not result_texture_rid.is_valid(): return - ext_texure.copy_to(result_texture_rid) - - func kill_process() -> void: if OS.is_process_running(pid): OS.kill(pid) diff --git a/project/the_gates/scripts/resources/command_events.gd b/project/the_gates/scripts/resources/command_events.gd new file mode 100644 index 0000000..98f0f71 --- /dev/null +++ b/project/the_gates/scripts/resources/command_events.gd @@ -0,0 +1,8 @@ +extends Resource +class_name CommandEvents + +signal send_fd + + +func send_fd_emit() -> void: + send_fd.emit() diff --git a/project/the_gates/scripts/sandbox/command_sync.gd b/project/the_gates/scripts/sandbox/command_sync.gd new file mode 100644 index 0000000..3006d53 --- /dev/null +++ b/project/the_gates/scripts/sandbox/command_sync.gd @@ -0,0 +1,23 @@ +extends CommandSync + +@export var gate_events: GateEvents +@export var command_events: CommandEvents + + +func _ready() -> void: + gate_events.gate_entered.connect(bind) + execute_function = _execute_function + + +func _physics_process(delta: float) -> void: + receive_commands() + + +func _execute_function(command: String) -> String: + print("Recieved command: " + command) + match command: + "send_fd": + command_events.send_fd_emit() + _: + print("Command %s not implemented" % [command]) + return "" diff --git a/project/the_gates/scripts/input/input_sync.gd b/project/the_gates/scripts/sandbox/input_sync.gd similarity index 100% rename from project/the_gates/scripts/input/input_sync.gd rename to project/the_gates/scripts/sandbox/input_sync.gd diff --git a/project/the_gates/scripts/sandbox/render_result.gd b/project/the_gates/scripts/sandbox/render_result.gd new file mode 100644 index 0000000..ce0a700 --- /dev/null +++ b/project/the_gates/scripts/sandbox/render_result.gd @@ -0,0 +1,65 @@ +extends TextureRect +class_name RenderResult + +@export var gate_events: GateEvents +@export var command_events: CommandEvents +@export var splash_screen: Texture2D + +@onready var width = get_viewport().size.x +@onready var height = get_viewport().size.y +var fd_path = "/tmp/external_texture" + +var rd: RenderingDevice +var ext_texure: ExternalTexture +var texture_rid: RID + + +func _ready() -> void: + gate_events.gate_entered.connect(create_external_texture) + command_events.send_fd.connect(send_fd) + initialize() + + +func initialize() -> void: + rd = RenderingServer.get_rendering_device() + + var image = Image.create(width, height, false, Image.FORMAT_RGB8) + self.texture = ImageTexture.create_from_image(image) + texture_rid = RenderingServer.texture_get_rd_texture(self.texture.get_rid()) + if not texture_rid.is_valid(): Debug.logerr("Cannot create ImageTexture") + else: Debug.logclr("Render result texture created", Color.AQUAMARINE) + + +func create_external_texture() -> void: + var t_format: RDTextureFormat = RDTextureFormat.new() + t_format.format = RenderingDevice.DATA_FORMAT_R8G8B8A8_UNORM + t_format.usage_bits = RenderingDevice.TEXTURE_USAGE_CAN_COPY_FROM_BIT | \ + RenderingDevice.TEXTURE_USAGE_CAN_UPDATE_BIT + t_format.width = width + t_format.height = height + t_format.depth = 1 + var t_view: RDTextureView = RDTextureView.new() + + var image = splash_screen.get_image() + image.convert(Image.FORMAT_RGBA8) + image.clear_mipmaps() + + ext_texure = ExternalTexture.new() + var err = ext_texure.create(t_format, t_view, [image.get_data()]) + if err: Debug.logerr("Cannot create external texture"); return + else: Debug.logclr("External texture created " + str(ext_texure.get_fd()), Color.AQUAMARINE) + + +func send_fd() -> void: + print("Sending fd...") + var sent = false + while not sent: + sent = ext_texure.send_fd(fd_path) + await get_tree().create_timer(0.1).timeout + print("fd was sent") + + +func _process(_delta: float) -> void: + if ext_texure == null or not ext_texure.get_rid().is_valid(): return + if not texture_rid.is_valid(): return + ext_texure.copy_to(texture_rid)