Skip to content

Commit

Permalink
Input: bind parse_input_event()
Browse files Browse the repository at this point in the history
When using get_tree().input_event(ev), the engine will JUST send the event down the SceneTree.
However, you won't get any of the benefits of the Input singleton:
- No InputMap actions will be emitted
- The internal input state won't be modified, so methods like `Input.get_mouse_pos()` or `Input.is_joy_button_pressed` won't return the expected output after sending the event.

This is fixed by using `Input.parse_input_event(ev)` instead.
I guess we'll also have to update the docs to reflect that this is the preferred method of sending custom InputEvents.
  • Loading branch information
27thLiz committed Mar 19, 2017
1 parent 7eb8a67 commit a69e449
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions core/os/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ void Input::_bind_methods() {
ClassDB::bind_method(D_METHOD("action_press", "action"), &Input::action_press);
ClassDB::bind_method(D_METHOD("action_release", "action"), &Input::action_release);
ClassDB::bind_method(D_METHOD("set_custom_mouse_cursor", "image:Texture", "hotspot"), &Input::set_custom_mouse_cursor, DEFVAL(Vector2()));
ClassDB::bind_method(D_METHOD("parse_input_event", "event"), &Input::parse_input_event);

BIND_CONSTANT(MOUSE_MODE_VISIBLE);
BIND_CONSTANT(MOUSE_MODE_HIDDEN);
Expand Down
2 changes: 2 additions & 0 deletions core/os/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ class Input : public Object {
virtual int get_joy_button_index_from_string(String p_button) = 0;
virtual int get_joy_axis_index_from_string(String p_axis) = 0;

virtual void parse_input_event(const InputEvent &p_event) = 0;

Input();
};

Expand Down
3 changes: 2 additions & 1 deletion main/input_default.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ class InputDefault : public Input {

virtual void warp_mouse_pos(const Vector2 &p_to);

void parse_input_event(const InputEvent &p_event);
virtual void parse_input_event(const InputEvent &p_event);

void set_gravity(const Vector3 &p_gravity);
void set_accelerometer(const Vector3 &p_accel);
void set_magnetometer(const Vector3 &p_magnetometer);
Expand Down

0 comments on commit a69e449

Please sign in to comment.