mirror of
https://github.com/thegatesbrowser/thegates.git
synced 2025-08-24 20:17:31 -04:00
gd: send_fd
This commit is contained in:
parent
f92a186d54
commit
ef1ee7b3a0
10 changed files with 118 additions and 69 deletions
BIN
project/the_gates/resources/command_events.res
Normal file
BIN
project/the_gates/resources/command_events.res
Normal file
Binary file not shown.
BIN
project/the_gates/resources/ui_events.res
Normal file
BIN
project/the_gates/resources/ui_events.res
Normal file
Binary file not shown.
|
@ -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")
|
|
|
@ -3,7 +3,7 @@
|
||||||
[ext_resource type="Script" path="res://the_gates/scripts/app.gd" id="1_skc7d"]
|
[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="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://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="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="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"]
|
[ext_resource type="PackedScene" uid="uid://byrcbqat0n2px" path="res://the_gates/scenes/debug.tscn" id="7_3xeb8"]
|
||||||
|
|
|
@ -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/pack_loader.gd" id="1_5swiq"]
|
||||||
[ext_resource type="Script" path="res://the_gates/scripts/loading/gate_loader.gd" id="1_coscx"]
|
[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/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="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="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="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="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"]
|
[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="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="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="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"]
|
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_shmbc"]
|
||||||
bg_color = Color(0.3384, 0.188, 0.47, 1)
|
bg_color = Color(0.3384, 0.188, 0.47, 1)
|
||||||
|
@ -81,7 +84,6 @@ gate_events = ExtResource("2_ot8b0")
|
||||||
script = ExtResource("1_5swiq")
|
script = ExtResource("1_5swiq")
|
||||||
gate_events = ExtResource("2_ot8b0")
|
gate_events = ExtResource("2_ot8b0")
|
||||||
render_result = NodePath("../../WorldCanvas/RenderResult")
|
render_result = NodePath("../../WorldCanvas/RenderResult")
|
||||||
splash_screen = ExtResource("9_req2b")
|
|
||||||
|
|
||||||
[node name="UICanvas" type="CanvasLayer" parent="."]
|
[node name="UICanvas" type="CanvasLayer" parent="."]
|
||||||
follow_viewport_enabled = true
|
follow_viewport_enabled = true
|
||||||
|
@ -168,7 +170,7 @@ anchor_bottom = 1.0
|
||||||
grow_horizontal = 2
|
grow_horizontal = 2
|
||||||
grow_vertical = 2
|
grow_vertical = 2
|
||||||
script = ExtResource("4_xatjs")
|
script = ExtResource("4_xatjs")
|
||||||
ui_events = ExtResource("7_bmkgi")
|
ui_events = ExtResource("22_ryq4n")
|
||||||
|
|
||||||
[node name="Blur" type="Panel" parent="UICanvas/UI"]
|
[node name="Blur" type="Panel" parent="UICanvas/UI"]
|
||||||
material = SubResource("ShaderMaterial_kc7rv")
|
material = SubResource("ShaderMaterial_kc7rv")
|
||||||
|
@ -719,11 +721,20 @@ anchor_right = 1.0
|
||||||
anchor_bottom = 1.0
|
anchor_bottom = 1.0
|
||||||
grow_horizontal = 2
|
grow_horizontal = 2
|
||||||
grow_vertical = 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"]
|
[node name="InputSync" type="Node" parent="WorldCanvas"]
|
||||||
script = ExtResource("18_rsdyb")
|
script = ExtResource("19_7opuh")
|
||||||
gate_events = ExtResource("2_ot8b0")
|
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/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"]
|
[connection signal="pressed" from="UICanvas/UI/GateInfo/Bookmark/Star" to="UICanvas/UI/GateInfo" method="_on_star_pressed"]
|
||||||
|
|
|
@ -2,37 +2,14 @@ extends Node
|
||||||
class_name PackLoader
|
class_name PackLoader
|
||||||
|
|
||||||
@export var gate_events: GateEvents
|
@export var gate_events: GateEvents
|
||||||
@export var render_result: TextureRect
|
@export var render_result: RenderResult
|
||||||
@export var splash_screen: Texture2D
|
|
||||||
|
|
||||||
var gate: Gate
|
var gate: Gate
|
||||||
var pid: int
|
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:
|
func _ready() -> void:
|
||||||
gate_events.gate_loaded.connect(create_process)
|
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:
|
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 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 pack_file = ProjectSettings.globalize_path(gate.resource_pack)
|
||||||
var main_pid = OS.get_process_id()
|
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 = [
|
var args = [
|
||||||
"--main-pack", pack_file,
|
"--main-pack", pack_file,
|
||||||
"--resolution", "%dx%d" % [width, height],
|
"--resolution", "%dx%d" % [render_result.width, render_result.height],
|
||||||
"--external-image", fd,
|
"--fd-path", render_result.fd_path
|
||||||
"--main-pid", main_pid
|
|
||||||
]
|
]
|
||||||
Debug.logclr(sandbox_path + " " + " ".join(args), Color.DARK_VIOLET)
|
Debug.logclr(sandbox_path + " " + " ".join(args), Color.DARK_VIOLET)
|
||||||
pid = OS.create_process(sandbox_path, args)
|
pid = OS.create_process(sandbox_path, args)
|
||||||
|
@ -57,31 +30,6 @@ func create_process(_gate: Gate) -> void:
|
||||||
gate_events.gate_entered_emit()
|
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:
|
func kill_process() -> void:
|
||||||
if OS.is_process_running(pid):
|
if OS.is_process_running(pid):
|
||||||
OS.kill(pid)
|
OS.kill(pid)
|
||||||
|
|
8
project/the_gates/scripts/resources/command_events.gd
Normal file
8
project/the_gates/scripts/resources/command_events.gd
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
extends Resource
|
||||||
|
class_name CommandEvents
|
||||||
|
|
||||||
|
signal send_fd
|
||||||
|
|
||||||
|
|
||||||
|
func send_fd_emit() -> void:
|
||||||
|
send_fd.emit()
|
23
project/the_gates/scripts/sandbox/command_sync.gd
Normal file
23
project/the_gates/scripts/sandbox/command_sync.gd
Normal file
|
@ -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 ""
|
65
project/the_gates/scripts/sandbox/render_result.gd
Normal file
65
project/the_gates/scripts/sandbox/render_result.gd
Normal file
|
@ -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)
|
Loading…
Add table
Add a link
Reference in a new issue