Using HashMap to track touches on web

Modified how display_server_web.h stores info about touches to fix bug described by issue https://github.com/godotengine/godot/issues/94346.
This commit is contained in:
Brandon Yi 2024-07-28 21:31:32 -07:00
parent 88d9325065
commit 00555a54c5
2 changed files with 8 additions and 3 deletions

View File

@ -673,7 +673,7 @@ void DisplayServerWeb::_touch_callback(int p_type, int p_count) {
ev->set_index(touch_event.identifier[i]); ev->set_index(touch_event.identifier[i]);
ev->set_position(point); ev->set_position(point);
Point2 &prev = ds->touches[i]; Point2 &prev = ds->touches[touch_event.identifier[i]];
ev->set_relative(ev->get_position() - prev); ev->set_relative(ev->get_position() - prev);
ev->set_relative_screen_position(ev->get_relative()); ev->set_relative_screen_position(ev->get_relative());
prev = ev->get_position(); prev = ev->get_position();
@ -690,7 +690,12 @@ void DisplayServerWeb::_touch_callback(int p_type, int p_count) {
ev->set_index(touch_event.identifier[i]); ev->set_index(touch_event.identifier[i]);
ev->set_position(point); ev->set_position(point);
ev->set_pressed(p_type == 0); ev->set_pressed(p_type == 0);
ds->touches[i] = point;
if (p_type == 0) {
ds->touches[touch_event.identifier[i]] = point;
} else {
ds->touches.erase(touch_event.identifier[i]);
}
Input::get_singleton()->parse_input_event(ev); Input::get_singleton()->parse_input_event(ev);

View File

@ -71,7 +71,7 @@ private:
Callable drop_files_callback; Callable drop_files_callback;
String clipboard; String clipboard;
Point2 touches[32]; HashMap<uint32_t, Point2> touches;
Array voices; Array voices;