Skip to content

Commit

Permalink
Rename InputFilter back to Input
Browse files Browse the repository at this point in the history
It changed name as part of the DisplayServer and input refactoring
in #37317, with the rationale that input no longer goes through the
main loop, so the previous Input singleton now only does filtering.

But the gains in consistency are quite limited in the renaming, and
it breaks compatibility for all scripts and tutorials that access
the Input singleton via the scripting language. A temporary option
was suggested to keep the scripting singleton named `Input` even if
its type is `InputFilter`, but that adds inconsistency and breaks C#.

Fixes godotengine/godot-proposals#639.
Fixes #37319.
Fixes #37690.
  • Loading branch information
akien-mga authored and MarcusElg committed Oct 19, 2020
1 parent b65e9dd commit fdc0baf
Show file tree
Hide file tree
Showing 82 changed files with 483 additions and 481 deletions.
12 changes: 6 additions & 6 deletions core/debugger/remote_debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include "core/debugger/debugger_marshalls.h"
#include "core/debugger/engine_debugger.h"
#include "core/debugger/script_debugger.h"
#include "core/input/input_filter.h"
#include "core/input/input.h"
#include "core/os/os.h"
#include "core/project_settings.h"
#include "core/script_language.h"
Expand Down Expand Up @@ -659,9 +659,9 @@ void RemoteDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) {

servers_profiler->skip_profile_frame = true; // Avoid frame time spike in debug.

InputFilter::MouseMode mouse_mode = InputFilter::get_singleton()->get_mouse_mode();
if (mouse_mode != InputFilter::MOUSE_MODE_VISIBLE)
InputFilter::get_singleton()->set_mouse_mode(InputFilter::MOUSE_MODE_VISIBLE);
Input::MouseMode mouse_mode = Input::get_singleton()->get_mouse_mode();
if (mouse_mode != Input::MOUSE_MODE_VISIBLE)
Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE);

uint64_t loop_begin_usec = 0;
uint64_t loop_time_sec = 0;
Expand Down Expand Up @@ -779,8 +779,8 @@ void RemoteDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) {

send_message("debug_exit", Array());

if (mouse_mode != InputFilter::MOUSE_MODE_VISIBLE)
InputFilter::get_singleton()->set_mouse_mode(mouse_mode);
if (mouse_mode != Input::MOUSE_MODE_VISIBLE)
Input::get_singleton()->set_mouse_mode(mouse_mode);
}

void RemoteDebugger::poll_events(bool p_is_idle) {
Expand Down
254 changes: 127 additions & 127 deletions core/input/input_filter.cpp → core/input/input.cpp

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions core/input/input_filter.h → core/input/input.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*************************************************************************/
/* input_filter.h */
/* input.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
Expand Down Expand Up @@ -35,12 +35,12 @@
#include "core/object.h"
#include "core/os/thread_safe.h"

class InputFilter : public Object {
class Input : public Object {

GDCLASS(InputFilter, Object);
GDCLASS(Input, Object);
_THREAD_SAFE_CLASS_

static InputFilter *singleton;
static Input *singleton;

public:
enum MouseMode {
Expand Down Expand Up @@ -239,7 +239,7 @@ class InputFilter : public Object {
MouseMode get_mouse_mode() const;
void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const;

static InputFilter *get_singleton();
static Input *get_singleton();

bool is_key_pressed(int p_keycode) const;
bool is_mouse_button_pressed(int p_button) const;
Expand Down Expand Up @@ -299,7 +299,7 @@ class InputFilter : public Object {
CursorShape get_default_cursor_shape() const;
void set_default_cursor_shape(CursorShape p_shape);
CursorShape get_current_cursor_shape() const;
void set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape = InputFilter::CURSOR_ARROW, const Vector2 &p_hotspot = Vector2());
void set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape = Input::CURSOR_ARROW, const Vector2 &p_hotspot = Vector2());

void parse_mapping(String p_mapping);
void joy_button(int p_device, int p_button, bool p_pressed);
Expand Down Expand Up @@ -328,10 +328,10 @@ class InputFilter : public Object {

void set_event_dispatch_function(EventDispatchFunc p_function);

InputFilter();
Input();
};

VARIANT_ENUM_CAST(InputFilter::MouseMode);
VARIANT_ENUM_CAST(InputFilter::CursorShape);
VARIANT_ENUM_CAST(Input::MouseMode);
VARIANT_ENUM_CAST(Input::CursorShape);

#endif // INPUT_H
4 changes: 2 additions & 2 deletions core/os/midi_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

#include "midi_driver.h"

#include "core/input/input_filter.h"
#include "core/input/input.h"
#include "core/os/os.h"

uint8_t MIDIDriver::last_received_message = 0x00;
Expand Down Expand Up @@ -117,7 +117,7 @@ void MIDIDriver::receive_input_packet(uint64_t timestamp, uint8_t *data, uint32_
break;
}

InputFilter *id = InputFilter::get_singleton();
Input *id = Input::get_singleton();
id->parse_input_event(event);
}

Expand Down
2 changes: 1 addition & 1 deletion core/os/os.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

#include "os.h"

#include "core/input/input_filter.h"
#include "core/input/input.h"
#include "core/os/dir_access.h"
#include "core/os/file_access.h"
#include "core/os/midi_driver.h"
Expand Down
6 changes: 3 additions & 3 deletions core/register_core_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#include "core/crypto/hashing_context.h"
#include "core/engine.h"
#include "core/func_ref.h"
#include "core/input/input_filter.h"
#include "core/input/input.h"
#include "core/input/input_map.h"
#include "core/io/config_file.h"
#include "core/io/dtls_server.h"
Expand Down Expand Up @@ -249,7 +249,7 @@ void register_core_singletons() {
ClassDB::register_class<_ClassDB>();
ClassDB::register_class<_Marshalls>();
ClassDB::register_class<TranslationServer>();
ClassDB::register_virtual_class<InputFilter>();
ClassDB::register_virtual_class<Input>();
ClassDB::register_class<InputMap>();
ClassDB::register_class<_JSON>();
ClassDB::register_class<Expression>();
Expand All @@ -264,7 +264,7 @@ void register_core_singletons() {
Engine::get_singleton()->add_singleton(Engine::Singleton("ClassDB", _classdb));
Engine::get_singleton()->add_singleton(Engine::Singleton("Marshalls", _Marshalls::get_singleton()));
Engine::get_singleton()->add_singleton(Engine::Singleton("TranslationServer", TranslationServer::get_singleton()));
Engine::get_singleton()->add_singleton(Engine::Singleton("Input", InputFilter::get_singleton()));
Engine::get_singleton()->add_singleton(Engine::Singleton("Input", Input::get_singleton()));
Engine::get_singleton()->add_singleton(Engine::Singleton("InputMap", InputMap::get_singleton()));
Engine::get_singleton()->add_singleton(Engine::Singleton("JSON", _JSON::get_singleton()));
}
Expand Down
4 changes: 2 additions & 2 deletions doc/classes/@GlobalScope.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
<member name="IP" type="IP" setter="" getter="">
The [IP] singleton.
</member>
<member name="Input" type="InputFilter" setter="" getter="">
The [InputFilter] singleton.
<member name="Input" type="Input" setter="" getter="">
The [Input] singleton.
</member>
<member name="InputMap" type="InputMap" setter="" getter="">
The [InputMap] singleton.
Expand Down
16 changes: 8 additions & 8 deletions doc/classes/InputFilter.xml → doc/classes/Input.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="InputFilter" inherits="Object" version="4.0">
<class name="Input" inherits="Object" version="4.0">
<brief_description>
A singleton that deals with inputs.
</brief_description>
Expand Down Expand Up @@ -68,7 +68,7 @@
</description>
</method>
<method name="get_current_cursor_shape" qualifiers="const">
<return type="int" enum="InputFilter.CursorShape">
<return type="int" enum="Input.CursorShape">
</return>
<description>
Returns the currently assigned cursor shape (see [enum CursorShape]).
Expand Down Expand Up @@ -193,7 +193,7 @@
</description>
</method>
<method name="get_mouse_mode" qualifiers="const">
<return type="int" enum="InputFilter.MouseMode">
<return type="int" enum="Input.MouseMode">
</return>
<description>
Returns the mouse mode. See the constants for more information.
Expand Down Expand Up @@ -277,7 +277,7 @@
<argument index="3" name="guid" type="String">
</argument>
<description>
Notifies the [InputFilter] singleton that a connection has changed, to update the state for the [code]device[/code] index.
Notifies the [Input] singleton that a connection has changed, to update the state for the [code]device[/code] index.
This is used internally and should not have to be called from user scripts. See [signal joy_connection_changed] for the signal emitted when this is triggered internally.
</description>
</method>
Expand All @@ -293,7 +293,7 @@
var a = InputEventAction.new()
a.action = "ui_cancel"
a.pressed = true
InputFilter.parse_input_event(a)
Input.parse_input_event(a)
[/codeblock]
</description>
</method>
Expand All @@ -311,7 +311,7 @@
</return>
<argument index="0" name="image" type="Resource">
</argument>
<argument index="1" name="shape" type="int" enum="InputFilter.CursorShape" default="0">
<argument index="1" name="shape" type="int" enum="Input.CursorShape" default="0">
</argument>
<argument index="2" name="hotspot" type="Vector2" default="Vector2( 0, 0 )">
</argument>
Expand All @@ -326,7 +326,7 @@
<method name="set_default_cursor_shape">
<return type="void">
</return>
<argument index="0" name="shape" type="int" enum="InputFilter.CursorShape" default="0">
<argument index="0" name="shape" type="int" enum="Input.CursorShape" default="0">
</argument>
<description>
Sets the default cursor shape to be used in the viewport instead of [constant CURSOR_ARROW].
Expand All @@ -337,7 +337,7 @@
<method name="set_mouse_mode">
<return type="void">
</return>
<argument index="0" name="mode" type="int" enum="InputFilter.MouseMode">
<argument index="0" name="mode" type="int" enum="Input.MouseMode">
</argument>
<description>
Sets the mouse mode. See the constants for more information.
Expand Down
4 changes: 2 additions & 2 deletions editor/animation_track_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include "animation_track_editor.h"

#include "animation_track_editor_plugins.h"
#include "core/input/input_filter.h"
#include "core/input/input.h"
#include "core/os/keyboard.h"
#include "editor/animation_bezier_editor.h"
#include "editor/plugins/animation_player_editor_plugin.h"
Expand Down Expand Up @@ -4103,7 +4103,7 @@ bool AnimationTrackEditor::is_selection_active() const {
}

bool AnimationTrackEditor::is_snap_enabled() const {
return snap->is_pressed() ^ InputFilter::get_singleton()->is_key_pressed(KEY_CONTROL);
return snap->is_pressed() ^ Input::get_singleton()->is_key_pressed(KEY_CONTROL);
}

void AnimationTrackEditor::_update_tracks() {
Expand Down
6 changes: 3 additions & 3 deletions editor/code_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

#include "code_editor.h"

#include "core/input/input_filter.h"
#include "core/input/input.h"
#include "core/os/keyboard.h"
#include "core/string_builder.h"
#include "editor/editor_scale.h"
Expand Down Expand Up @@ -513,7 +513,7 @@ void FindReplaceBar::_search_text_changed(const String &p_text) {

void FindReplaceBar::_search_text_entered(const String &p_text) {

if (InputFilter::get_singleton()->is_key_pressed(KEY_SHIFT)) {
if (Input::get_singleton()->is_key_pressed(KEY_SHIFT)) {
search_prev();
} else {
search_next();
Expand All @@ -525,7 +525,7 @@ void FindReplaceBar::_replace_text_entered(const String &p_text) {
if (selection_only->is_pressed() && text_edit->is_selection_active()) {
_replace_all();
_hide_bar();
} else if (InputFilter::get_singleton()->is_key_pressed(KEY_SHIFT)) {
} else if (Input::get_singleton()->is_key_pressed(KEY_SHIFT)) {
_replace();
search_prev();
} else {
Expand Down
6 changes: 3 additions & 3 deletions editor/editor_audio_buses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

#include "editor_audio_buses.h"

#include "core/input/input_filter.h"
#include "core/input/input.h"
#include "core/io/resource_saver.h"
#include "core/os/keyboard.h"
#include "editor_node.h"
Expand Down Expand Up @@ -325,7 +325,7 @@ void EditorAudioBus::_volume_changed(float p_normalized) {

const float p_db = this->_normalized_volume_to_scaled_db(p_normalized);

if (InputFilter::get_singleton()->is_key_pressed(KEY_CONTROL)) {
if (Input::get_singleton()->is_key_pressed(KEY_CONTROL)) {
// Snap the value when holding Ctrl for easier editing.
// To do so, it needs to be converted back to normalized volume (as the slider uses that unit).
slider->set_value(_scaled_db_to_normalized_volume(Math::round(p_db)));
Expand Down Expand Up @@ -386,7 +386,7 @@ float EditorAudioBus::_scaled_db_to_normalized_volume(float db) {
void EditorAudioBus::_show_value(float slider_value) {

float db;
if (InputFilter::get_singleton()->is_key_pressed(KEY_CONTROL)) {
if (Input::get_singleton()->is_key_pressed(KEY_CONTROL)) {
// Display the correct (snapped) value when holding Ctrl
db = Math::round(_normalized_volume_to_scaled_db(slider_value));
} else {
Expand Down
4 changes: 2 additions & 2 deletions editor/editor_help.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

#include "editor_help.h"

#include "core/input/input_filter.h"
#include "core/input/input.h"
#include "core/os/keyboard.h"
#include "doc_data_compressed.gen.h"
#include "editor/plugins/script_editor_plugin.h"
Expand Down Expand Up @@ -1844,7 +1844,7 @@ void FindBar::_search_text_changed(const String &p_text) {

void FindBar::_search_text_entered(const String &p_text) {

if (InputFilter::get_singleton()->is_key_pressed(KEY_SHIFT)) {
if (Input::get_singleton()->is_key_pressed(KEY_SHIFT)) {
search_prev();
} else {
search_next();
Expand Down
12 changes: 6 additions & 6 deletions editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

#include "core/bind/core_bind.h"
#include "core/class_db.h"
#include "core/input/input_filter.h"
#include "core/input/input.h"
#include "core/io/config_file.h"
#include "core/io/image_loader.h"
#include "core/io/resource_loader.h"
Expand Down Expand Up @@ -2366,7 +2366,7 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {

case EDIT_UNDO: {

if (InputFilter::get_singleton()->get_mouse_button_mask() & 0x7) {
if (Input::get_singleton()->get_mouse_button_mask() & 0x7) {
log->add_message("Can't undo while mouse buttons are pressed.", EditorLog::MSG_TYPE_EDITOR);
} else {
String action = editor_data.get_undo_redo().get_current_action_name();
Expand All @@ -2380,7 +2380,7 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
} break;
case EDIT_REDO: {

if (InputFilter::get_singleton()->get_mouse_button_mask() & 0x7) {
if (Input::get_singleton()->get_mouse_button_mask() & 0x7) {
log->add_message("Can't redo while mouse buttons are pressed.", EditorLog::MSG_TYPE_EDITOR);
} else {
if (!editor_data.get_undo_redo().redo()) {
Expand Down Expand Up @@ -5566,7 +5566,7 @@ int EditorNode::execute_and_show_output(const String &p_title, const String &p_p

EditorNode::EditorNode() {

InputFilter::get_singleton()->set_use_accumulated_input(true);
Input::get_singleton()->set_use_accumulated_input(true);
Resource::_get_local_scene_func = _resource_get_edited_scene;

RenderingServer::get_singleton()->set_debug_generate_wireframes(true);
Expand All @@ -5582,7 +5582,7 @@ EditorNode::EditorNode() {
ResourceLoader::clear_translation_remaps(); //no remaps using during editor
ResourceLoader::clear_path_remaps();

InputFilter *id = InputFilter::get_singleton();
Input *id = Input::get_singleton();

if (id) {

Expand All @@ -5593,7 +5593,7 @@ EditorNode::EditorNode() {
}
}

if (!found_touchscreen && InputFilter::get_singleton()) {
if (!found_touchscreen && Input::get_singleton()) {
//only if no touchscreen ui hint, set emulation
id->set_emulate_touch_from_mouse(false); //just disable just in case
}
Expand Down
Loading

0 comments on commit fdc0baf

Please sign in to comment.