Browse Source

[macOS] Process joypad input directly in the embedded process.

Pāvels Nadtočajevs 1 tháng trước cách đây
mục cha
commit
b9bafbd2ca

+ 0 - 5
platform/macos/display_server_embedded.h

@@ -144,11 +144,6 @@ public:
 	virtual Point2i mouse_get_position() const override;
 	virtual BitField<MouseButtonMask> mouse_get_button_state() const override;
 
-	// MARK: - Joystick
-
-	void joy_add(int p_idx, const String &p_name);
-	void joy_del(int p_idx);
-
 	// MARK: - Window
 
 	virtual bool has_feature(Feature p_feature) const override;

+ 0 - 28
platform/macos/display_server_embedded.mm

@@ -389,36 +389,8 @@ void DisplayServerEmbedded::window_set_drop_files_callback(const Callable &p_cal
 	// Not supported
 }
 
-void DisplayServerEmbedded::joy_add(int p_idx, const String &p_name) {
-	Joy *joy = joysticks.getptr(p_idx);
-	if (joy == nullptr) {
-		joysticks[p_idx] = Joy(p_name);
-		Input::get_singleton()->joy_connection_changed(p_idx, true, p_name);
-	}
-}
-
-void DisplayServerEmbedded::joy_del(int p_idx) {
-	if (joysticks.erase(p_idx)) {
-		Input::get_singleton()->joy_connection_changed(p_idx, false, String());
-	}
-}
-
 void DisplayServerEmbedded::process_events() {
 	Input *input = Input::get_singleton();
-	for (KeyValue<int, Joy> &kv : joysticks) {
-		uint64_t ts = input->get_joy_vibration_timestamp(kv.key);
-		if (ts > kv.value.timestamp) {
-			kv.value.timestamp = ts;
-			Vector2 strength = input->get_joy_vibration_strength(kv.key);
-			if (strength == Vector2()) {
-				EngineDebugger::get_singleton()->send_message("game_view:joy_stop", { kv.key });
-			} else {
-				float duration = input->get_joy_vibration_duration(kv.key);
-				EngineDebugger::get_singleton()->send_message("game_view:joy_start", { kv.key, duration, strength });
-			}
-		}
-	}
-
 	input->flush_buffered_events();
 }
 

+ 0 - 2
platform/macos/editor/embedded_game_view_plugin.mm

@@ -131,8 +131,6 @@ void GameViewDebuggerMacOS::_init_capture_message_handlers() {
 	parse_message_handlers["game_view:mouse_set_mode"] = &GameViewDebuggerMacOS::_msg_mouse_set_mode;
 	parse_message_handlers["game_view:window_set_ime_active"] = &GameViewDebuggerMacOS::_msg_window_set_ime_active;
 	parse_message_handlers["game_view:window_set_ime_position"] = &GameViewDebuggerMacOS::_msg_window_set_ime_position;
-	parse_message_handlers["game_view:joy_start"] = &GameViewDebuggerMacOS::_msg_joy_start;
-	parse_message_handlers["game_view:joy_stop"] = &GameViewDebuggerMacOS::_msg_joy_stop;
 	parse_message_handlers["game_view:warp_mouse"] = &GameViewDebuggerMacOS::_msg_warp_mouse;
 }
 

+ 0 - 1
platform/macos/editor/embedded_process_macos.h

@@ -93,7 +93,6 @@ class EmbeddedProcessMacOS final : public EmbeddedProcessBase {
 
 	void _try_embed_process();
 	void update_embedded_process();
-	void _joy_connection_changed(int p_index, bool p_connected) const;
 
 protected:
 	void _notification(int p_what);

+ 7 - 16
platform/macos/editor/embedded_process_macos.mm

@@ -97,19 +97,6 @@ void EmbeddedProcessMacOS::embed_process(OS::ProcessID p_pid) {
 	_try_embed_process();
 }
 
-void EmbeddedProcessMacOS::_joy_connection_changed(int p_index, bool p_connected) const {
-	if (!script_debugger) {
-		return;
-	}
-
-	if (p_connected) {
-		String name = Input::get_singleton()->get_joy_name(p_index);
-		script_debugger->send_message("embed:joy_add", { p_index, name });
-	} else {
-		script_debugger->send_message("embed:joy_del", { p_index });
-	}
-}
-
 void EmbeddedProcessMacOS::reset() {
 	if (!ds) {
 		ds = static_cast<DisplayServerMacOS *>(DisplayServer::get_singleton());
@@ -218,9 +205,6 @@ EmbeddedProcessMacOS::EmbeddedProcessMacOS() :
 	layer_host->set_anchors_and_offsets_preset(PRESET_FULL_RECT);
 	layer_host->set_custom_minimum_size(Size2(100, 100));
 
-	Input *input = Input::get_singleton();
-	input->connect(SNAME("joy_connection_changed"), callable_mp(this, &EmbeddedProcessMacOS::_joy_connection_changed));
-
 	// This shortcut allows a user to forcibly release a captured mouse from within the editor, regardless of whether
 	// the embedded process has implemented support to release the cursor.
 	ED_SHORTCUT("game_view/release_mouse", TTRC("Release Mouse"), KeyModifierMask::ALT | Key::ESCAPE);
@@ -339,6 +323,13 @@ void LayerHost::gui_input(const Ref<InputEvent> &p_event) {
 		}
 	}
 
+	Ref<InputEventJoypadMotion> jm = p_event;
+	Ref<InputEventJoypadButton> jb = p_event;
+	if (jm.is_valid() || jb.is_valid()) {
+		accept_event();
+		return;
+	}
+
 	PackedByteArray data;
 	if (encode_input_event(p_event, data)) {
 		script_debugger->send_message("embed:event", { data });

+ 0 - 2
platform/macos/embedded_debugger.h

@@ -62,8 +62,6 @@ private:
 	Error _msg_win_event(const Array &p_args);
 	Error _msg_notification(const Array &p_args);
 	Error _msg_ime_update(const Array &p_args);
-	Error _msg_joy_add(const Array &p_args);
-	Error _msg_joy_del(const Array &p_args);
 	Error _msg_ds_state(const Array &p_args);
 
 public:

+ 0 - 17
platform/macos/embedded_debugger.mm

@@ -75,8 +75,6 @@ void EmbeddedDebugger::_init_parse_message_handlers() {
 	parse_message_handlers["win_event"] = &EmbeddedDebugger::_msg_win_event;
 	parse_message_handlers["notification"] = &EmbeddedDebugger::_msg_notification;
 	parse_message_handlers["ime_update"] = &EmbeddedDebugger::_msg_ime_update;
-	parse_message_handlers["joy_add"] = &EmbeddedDebugger::_msg_joy_add;
-	parse_message_handlers["joy_del"] = &EmbeddedDebugger::_msg_joy_del;
 	parse_message_handlers["ds_state"] = &EmbeddedDebugger::_msg_ds_state;
 }
 
@@ -161,21 +159,6 @@ Error EmbeddedDebugger::_msg_notification(const Array &p_args) {
 	return OK;
 }
 
-Error EmbeddedDebugger::_msg_joy_add(const Array &p_args) {
-	ERR_FAIL_COND_V_MSG(p_args.size() != 2, ERR_INVALID_PARAMETER, "Invalid number of arguments for 'joy_add' message.");
-	int idx = p_args[0];
-	String name = p_args[1];
-	ds->joy_add(idx, name);
-	return OK;
-}
-
-Error EmbeddedDebugger::_msg_joy_del(const Array &p_args) {
-	ERR_FAIL_COND_V_MSG(p_args.size() != 1, ERR_INVALID_PARAMETER, "Invalid number of arguments for 'joy_del' message.");
-	int idx = p_args[0];
-	ds->joy_del(idx);
-	return OK;
-}
-
 Error EmbeddedDebugger::_msg_ds_state(const Array &p_args) {
 	ERR_FAIL_COND_V_MSG(p_args.size() != 1, ERR_INVALID_PARAMETER, "Invalid number of arguments for 'ds_state' message.");
 	PackedByteArray data = p_args[0];

+ 5 - 0
platform/macos/os_macos.mm

@@ -1263,6 +1263,11 @@ void OS_MacOS_Embedded::run() {
 				@try {
 					ds->process_events();
 
+#ifdef SDL_ENABLED
+					if (joypad_sdl) {
+						joypad_sdl->process_events();
+					}
+#endif
 					if (Main::iteration()) {
 						break;
 					}