diff --git a/project/instruments.gd b/project/instruments.gd index 28a25e6..bf0cbe8 100644 --- a/project/instruments.gd +++ b/project/instruments.gd @@ -1,12 +1,31 @@ extends Node -const PFD_PATH: String = "pfd#adi,vsi,alt,ias,rht,rpm,hsi" -const CONTROLS_PATH: String = "controls#collective,cyclic,rudder" - -@export var lidia_hostname: String = "localhost" -@export var lidia_port: int = 5555 +@export var browser_name: String = "browser" +@export var url: String = "http://192.168.1.2:5555/pfd" +# ============================================================================== +# Create a single browser named "browser_name" that is attached as child node to $CEF. +# ============================================================================== func _ready(): + # See API.md for more details. CEF Configuration is: + # resource_path := {"artifacts", CEF_ARTIFACTS_FOLDER} + # resource_path := {"exported_artifacts", application_real_path()} + # {"incognito":false} + # {"cache_path", resource_path / "cache"} + # {"root_cache_path", resource_path / "cache"} + # {"browser_subprocess_path", resource_path / SUBPROCESS_NAME } + # {"log_file", resource_path / "debug.log"} + # {log_severity", "warning"} + # {"remote_debugging_port", 7777} + # {"exception_stack_size", 5} + # {"enable_media_stream", false} + # + # Configurate CEF. In incognito mode cache directories not used and in-memory + # caches are used instead and no data is persisted to disk. + # + # artifacts: allows path such as "build" or "res://cef_artifacts/". Note that "res://" + # will use ProjectSettings.globalize_path but exported projects don't support globalize_path: + # https://docs.godotengine.org/en/3.5/classes/class_projectsettings.html#class-projectsettings-method-globalize-path if !$CEF.initialize({"incognito":true, "locale":"en-US"}): push_error($CEF.get_error()) get_tree().quit() @@ -16,18 +35,40 @@ func _ready(): # Wait one frame for the texture rect to get its size await get_tree().process_frame - var browser_pfd = $CEF.create_browser( - "http://{}:{}/{}".format([lidia_hostname, lidia_port, PFD_PATH], "{}"), - $SubViewport/TextureRect, - { "frame_rate": 90, "javascript": true }, - ) - browser_pfd.name = "pfd" - browser_pfd.enable_ad_block(false) # Required for lidia static assets + # See API.md for more details. Browser configuration is: + # {"frame_rate", 30} + # {"javascript", true} + # {"javascript_close_windows", false} + # {"javascript_access_clipboard", false} + # {"javascript_dom_paste", false} + # {"image_loading", true} + # {"databases", true} + # {"webgl", true} + var browser = $CEF.create_browser(url, $SubViewport/TextureRect, { + "frame_rate": 90, + "javascript": true, + }) + browser.name = browser_name + browser.connect("on_page_loaded", _on_page_loaded) + browser.connect("on_page_failed_loading", _on_page_failed_loading) + #browser.set_zoom_level(0.05) - var browser_ctrl = $CEF.create_browser( - "http://{}:{}/{}".format([lidia_hostname, lidia_port, CONTROLS_PATH], "{}"), - $SubViewport2/TextureRect, - { "frame_rate": 90, "javascript": true }, - ) - browser_ctrl.name = "controls" - browser_ctrl.enable_ad_block(false) # Required for lidia static assets + # Required for lidia static assets + browser.enable_ad_block(false) + +# ============================================================================== +# Callback when a page has ended to load: we print a message +# ============================================================================== +func _on_page_loaded(node): + print(node.name + ": page " + node.get_url() + " loaded") + +# ============================================================================== +# Callback when a page has ended to load with failure. +# Display a load error message using a data: URI. +# ============================================================================== +func _on_page_failed_loading(err_code, err_msg, node): + if err_code == -3: + return + push_error("The browser " + node.name + " failed loading " + \ + node.get_url() + ": " + err_msg) + pass diff --git a/project/instruments.tscn b/project/instruments.tscn index 584584a..6128408 100644 --- a/project/instruments.tscn +++ b/project/instruments.tscn @@ -1,8 +1,9 @@ -[gd_scene load_steps=7 format=3 uid="uid://cis4s43ubuynp"] +[gd_scene load_steps=5 format=3 uid="uid://cis4s43ubuynp"] [ext_resource type="Script" uid="uid://01bmfj4wthwg" path="res://instruments.gd" id="1_h5at3"] [sub_resource type="QuadMesh" id="QuadMesh_nowl7"] +size = Vector2(1, 0.75) [sub_resource type="ViewportTexture" id="ViewportTexture_8lpkn"] viewport_path = NodePath("SubViewport") @@ -11,38 +12,19 @@ viewport_path = NodePath("SubViewport") resource_local_to_scene = true albedo_texture = SubResource("ViewportTexture_8lpkn") -[sub_resource type="ViewportTexture" id="ViewportTexture_h5at3"] -viewport_path = NodePath("SubViewport2") - -[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_8lpkn"] -resource_local_to_scene = true -albedo_texture = SubResource("ViewportTexture_h5at3") - [node name="Instruments" type="Node3D"] script = ExtResource("1_h5at3") [node name="SubViewport" type="SubViewport" parent="."] +size = Vector2i(800, 600) [node name="TextureRect" type="TextureRect" parent="SubViewport"] -offset_right = 512.0 -offset_bottom = 512.0 +offset_right = 800.0 +offset_bottom = 600.0 expand_mode = 5 [node name="Quad" type="MeshInstance3D" parent="."] -transform = Transform3D(0.8, 0, 0, 0, 0.8, 0, 0, 0, 0.8, -0.35, 0, 0) mesh = SubResource("QuadMesh_nowl7") surface_material_override/0 = SubResource("StandardMaterial3D_h5at3") -[node name="SubViewport2" type="SubViewport" parent="."] - -[node name="TextureRect" type="TextureRect" parent="SubViewport2"] -offset_right = 512.0 -offset_bottom = 512.0 -expand_mode = 5 - -[node name="Quad2" type="MeshInstance3D" parent="."] -transform = Transform3D(0.6, 0, 0, 0, 0.6, 0, 0, 0, 0.6, 0.425, 0, 0) -mesh = SubResource("QuadMesh_nowl7") -surface_material_override/0 = SubResource("StandardMaterial3D_8lpkn") - [node name="CEF" type="GDCef" parent="."] diff --git a/project/project.godot b/project/project.godot index 949b555..1e0fa8b 100644 --- a/project/project.godot +++ b/project/project.godot @@ -15,10 +15,6 @@ run/main_scene="uid://crq3o0eu4y8ya" config/features=PackedStringArray("4.4", "GL Compatibility") config/icon="res://icon.svg" -[display] - -window/stretch/mode="viewport" - [editor_plugins] enabled=PackedStringArray() @@ -31,8 +27,6 @@ common/enable_object_picking=false renderer/rendering_method="gl_compatibility" renderer/rendering_method.mobile="gl_compatibility" -anti_aliasing/quality/msaa_2d=1 -anti_aliasing/quality/msaa_3d=1 [xr] diff --git a/src/marshconnector.cpp b/src/marshconnector.cpp index cdd5aca..cac39ae 100644 --- a/src/marshconnector.cpp +++ b/src/marshconnector.cpp @@ -6,9 +6,7 @@ #include "godot_cpp/classes/packet_peer_udp.hpp" #include "godot_cpp/core/math.hpp" #include "godot_cpp/core/memory.hpp" -#include "godot_cpp/core/object.hpp" #include "godot_cpp/core/print_string.hpp" -#include "godot_cpp/core/property_info.hpp" #include "godot_cpp/variant/basis.hpp" #include "godot_cpp/variant/packed_byte_array.hpp" #include "godot_cpp/variant/quaternion.hpp" @@ -36,13 +34,6 @@ void MarshConnector::_bind_methods() { ClassDB::bind_method(D_METHOD("get_manager_connected"), &MarshConnector::get_manager_connected); - // Properties - ClassDB::bind_method(D_METHOD("get_hostname"), &MarshConnector::get_hostname); - ClassDB::bind_method(D_METHOD("set_hostname", "p_hostname"), - &MarshConnector::set_hostname); - ADD_PROPERTY(PropertyInfo(Variant::STRING, "hostname"), "set_hostname", - "get_hostname"); - // Timer callbacks ClassDB::bind_method(D_METHOD("send_heartbeat"), &MarshConnector::send_heartbeat); @@ -65,7 +56,6 @@ MarshConnector::MarshConnector() { socket = memnew(PacketPeerUDP); - manager_hostname = "127.0.0.1"; manager_connected = false; manager_timer = memnew(Timer); @@ -95,7 +85,7 @@ void MarshConnector::_process(double delta) { time_passed += delta; if (!socket->is_socket_connected()) { - socket->connect_to_host(manager_hostname, 24400); + socket->connect_to_host("192.168.1.2", 24400); } else { while (socket->get_available_packet_count() > 0) { const PackedByteArray data = socket->get_packet(); @@ -104,19 +94,6 @@ void MarshConnector::_process(double delta) { } } -String MarshConnector::get_hostname() const { return manager_hostname; } - -void MarshConnector::set_hostname(const String hostname) { - // Socket's destination address is not available, so discard useless updates - // and recreate socket when needed - if (hostname == manager_hostname) - return; - - manager_hostname = hostname; - if (socket->is_socket_connected()) - socket->close(); -} - Error MarshConnector::send_heartbeat() { // print_line("Sending HEARTBEAT at ", time_passed, " seconds"); diff --git a/src/marshconnector.h b/src/marshconnector.h index e1a3e78..9e86eac 100644 --- a/src/marshconnector.h +++ b/src/marshconnector.h @@ -25,9 +25,6 @@ public: void _ready() override; void _process(double delta) override; - void set_hostname(const String hostname); - String get_hostname() const; - // Returns the error from put_packet Error send_heartbeat(); // Handle MAVLink messages fully contained in data @@ -112,7 +109,6 @@ private: Timer *heartbeat_timer; PacketPeerUDP *socket; - String manager_hostname; bool manager_connected; Timer *manager_timer; bool model_connected;