Added input classes to the build and made them compile.

This commit is contained in:
Relintai 2024-01-03 12:21:46 +01:00
parent 9aad8379a1
commit 116a7d0eaf
17 changed files with 393 additions and 692 deletions

View File

@ -63,6 +63,11 @@ ccache g++ -Wall -D_REENTRANT -g -Isfw -c sfw/render_core/texture.cpp -o sfw/ren
ccache g++ -Wall -D_REENTRANT -g -Isfw -c sfw/render_core/image.cpp -o sfw/render_core/image.o
ccache g++ -Wall -D_REENTRANT -g -Isfw -c sfw/render_core/render_state.cpp -o sfw/render_core/render_state.o
ccache g++ -Wall -D_REENTRANT -g -Isfw -c sfw/render_core/input/keyboard.cpp -o sfw/render_core/input/keyboard.o
ccache g++ -Wall -D_REENTRANT -g -Isfw -c sfw/render_core/input/default_controller_mappings.gen.cpp -o sfw/render_core/input/default_controller_mappings.gen.o
ccache g++ -Wall -D_REENTRANT -g -Isfw -c sfw/render_core/input/input_event.cpp -o sfw/render_core/input/input_event.o
ccache g++ -Wall -D_REENTRANT -g -Isfw -c sfw/render_core/input/input_map.cpp -o sfw/render_core/input/input_map.o
ccache g++ -Wall -D_REENTRANT -g -Isfw -c sfw/render_core/input/input.cpp -o sfw/render_core/input/input.o
ccache g++ -Wall -D_REENTRANT -g -Isfw -c sfw/render_core/input/shortcut.cpp -o sfw/render_core/input/shortcut.o
ccache g++ -Wall -D_REENTRANT -g -Isfw -c sfw/render_objects/camera_3d.cpp -o sfw/render_objects/camera_3d.o
ccache g++ -Wall -D_REENTRANT -g -Isfw -c sfw/render_objects/object_3d.cpp -o sfw/render_objects/object_3d.o
@ -94,7 +99,9 @@ ccache g++ -Wall -lm -ldl -lpthread -lX11 -D_REENTRANT -g sfw/core/aabb.o sfw/c
sfw/render_core/application.o sfw/render_core/scene.o sfw/render_core/window.o \
sfw/render_core/shader.o sfw/render_core/material.o sfw/render_core/mesh.o \
sfw/render_core/mesh_utils.o sfw/render_core/texture.o \
sfw/render_core/input/keyboard.o \
sfw/render_core/input/input_event.o sfw/render_core/input/input_map.o \
sfw/render_core/input/input.o sfw/render_core/input/shortcut.o \
sfw/render_core/input/keyboard.o sfw/render_core/input/default_controller_mappings.gen.o \
sfw/render_objects/camera_3d.o sfw/render_objects/object_3d.o sfw/render_objects/mesh_instance_3d.o \
sfw/render_objects/object_2d.o \
sfw/render_objects/sprite.o sfw/render_objects/tile_map.o \
@ -102,5 +109,4 @@ ccache g++ -Wall -lm -ldl -lpthread -lX11 -D_REENTRANT -g sfw/core/aabb.o sfw/c
game_scene.o main.o \
-o game
#export args="-lm -ldl -lpthread -lX11 -w -Iengine/ $args"

16
sfw/core/thread_safe.h Normal file
View File

@ -0,0 +1,16 @@
#ifndef THREAD_SAFE_H
#define THREAD_SAFE_H
/*************************************************************************/
/* thread_safe.h */
/* From https://github.com/Relintai/pandemonium_engine (MIT) */
/*************************************************************************/
#include "core/mutex.h"
#define _THREAD_SAFE_CLASS_ mutable Mutex _thread_safe_;
#define _THREAD_SAFE_METHOD_ MutexLock _thread_safe_method_(_thread_safe_);
#define _THREAD_SAFE_LOCK_ _thread_safe_.lock();
#define _THREAD_SAFE_UNLOCK_ _thread_safe_.unlock();
#endif

View File

@ -4,8 +4,8 @@
#include "render_core/window.h"
void Application::event() {
scene->event();
void Application::input_event(const Ref<InputEvent> &event) {
scene->input_event(event);
}
void Application::update(float delta) {

View File

@ -1,36 +1,59 @@
#ifndef APPLICATION_H
#define APPLICATION_H
#include "core/int_types.h"
#include <stdio.h>
#include "object/object.h"
#include "object/reference.h"
#include "render_core/scene.h"
class AppWindow;
class InputEvent;
class Application : Object {
SFW_OBJECT(Application, Object);
class Application {
public:
bool running;
int target_fps;
bool running;
int target_fps;
virtual void event();
virtual void update(float delta);
virtual void render();
virtual void input_event(const Ref<InputEvent> &event);
virtual void update(float delta);
virtual void render();
void main_loop();
uint64_t get_idle_frames() const {
return _idle_frames;
}
Application();
virtual ~Application();
uint64_t get_physics_frames() const {
return _physics_frames;
}
Scene *scene;
bool is_in_physics_frame() const {
return _is_in_physics_frame;
}
AppWindow *window;
void main_loop();
static Application *get_singleton();
Application();
virtual ~Application();
double frame_delta;
Scene *scene;
AppWindow *window;
static Application *get_singleton();
double frame_delta;
protected:
static Application * _instance;
static Application *_instance;
uint64_t _idle_frames;
uint64_t _physics_frames;
bool _is_in_physics_frame;
};
#endif // APPLICATION_H

View File

@ -1,6 +1,6 @@
/* THIS FILE IS GENERATED DO NOT EDIT */
#include "core/typedefs.h"
#include "core/input/default_controller_mappings.h"
#include "render_core/input/default_controller_mappings.h"
const char* DefaultControllerMappings::mappings[] = {
#ifdef WINDOWS_ENABLED
"03000000300f00000a01000000000000,3 In 1 Conversion Box,a:b2,b:b1,back:b9,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b6,leftstick:b10,lefttrigger:b4,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b11,righttrigger:b5,rightx:a3,righty:a2,start:b8,x:b3,y:b0,platform:Windows,",

View File

@ -5,37 +5,39 @@
#include "input.h"
#include "core/config/project_settings.h"
#include "core/input/default_controller_mappings.h"
#include "core/input/input_map.h"
#include "core/os/os.h"
#include "scene/resources/texture.h"
#include "servers/rendering_server.h"
#include "render_core/input/default_controller_mappings.h"
#include "render_core/input/input_map.h"
#include "render_core/texture.h"
#include "render_core/application.h"
#include "render_core/window.h"
#include "core/stime.h"
#include "core/logger.h"
Input *Input::get_singleton() {
return singleton;
}
void Input::set_mouse_mode(MouseMode p_mode) {
ERR_FAIL_INDEX((int)p_mode, 4);
OS::get_singleton()->set_mouse_mode((OS::MouseMode)p_mode);
//ERR_FAIL_INDEX((int)p_mode, 4);
//OS::get_singleton()->set_mouse_mode((OS::MouseMode)p_mode);
}
Input::MouseMode Input::get_mouse_mode() const {
return (MouseMode)OS::get_singleton()->get_mouse_mode();
//return (MouseMode)OS::get_singleton()->get_mouse_mode();
return MOUSE_MODE_VISIBLE;
}
bool InputDefault::is_key_pressed(int p_scancode) const {
bool Input::is_key_pressed(int p_scancode) const {
_THREAD_SAFE_METHOD_
return keys_pressed.has(p_scancode);
}
bool InputDefault::is_physical_key_pressed(int p_scancode) const {
bool Input::is_physical_key_pressed(int p_scancode) const {
_THREAD_SAFE_METHOD_
return physical_keys_pressed.has(p_scancode);
}
bool InputDefault::is_mouse_button_pressed(int p_button) const {
bool Input::is_mouse_button_pressed(int p_button) const {
_THREAD_SAFE_METHOD_
return (mouse_button_mask & (1 << (p_button - 1))) != 0;
}
@ -44,17 +46,17 @@ static int _combine_device(int p_value, int p_device) {
return p_value | (p_device << 20);
}
bool InputDefault::is_joy_button_pressed(int p_device, int p_button) const {
bool Input::is_joy_button_pressed(int p_device, int p_button) const {
_THREAD_SAFE_METHOD_
return joy_buttons_pressed.has(_combine_device(p_button, p_device));
}
bool InputDefault::is_action_pressed(const StringName &p_action, bool p_exact) const {
bool Input::is_action_pressed(const StringName &p_action, bool p_exact) const {
ERR_FAIL_COND_V_MSG(!InputMap::get_singleton()->has_action(p_action), false, InputMap::get_singleton()->suggest_actions(p_action));
return action_state.has(p_action) && action_state[p_action].pressed && (p_exact ? action_state[p_action].exact : true);
}
bool InputDefault::is_action_just_pressed(const StringName &p_action, bool p_exact) const {
bool Input::is_action_just_pressed(const StringName &p_action, bool p_exact) const {
ERR_FAIL_COND_V_MSG(!InputMap::get_singleton()->has_action(p_action), false, InputMap::get_singleton()->suggest_actions(p_action));
const RBMap<StringName, Action>::Element *E = action_state.find(p_action);
if (!E) {
@ -68,14 +70,14 @@ bool InputDefault::is_action_just_pressed(const StringName &p_action, bool p_exa
// Backward compatibility for legacy behavior, only return true if currently pressed.
bool pressed_requirement = legacy_just_pressed_behavior ? E->get().pressed : true;
if (Engine::get_singleton()->is_in_physics_frame()) {
return pressed_requirement && E->get().pressed_physics_frame == Engine::get_singleton()->get_physics_frames();
if (Application::get_singleton()->is_in_physics_frame()) {
return pressed_requirement && E->get().pressed_physics_frame == Application::get_singleton()->get_physics_frames();
} else {
return pressed_requirement && E->get().pressed_idle_frame == Engine::get_singleton()->get_idle_frames();
return pressed_requirement && E->get().pressed_idle_frame == Application::get_singleton()->get_idle_frames();
}
}
bool InputDefault::is_action_just_released(const StringName &p_action, bool p_exact) const {
bool Input::is_action_just_released(const StringName &p_action, bool p_exact) const {
ERR_FAIL_COND_V_MSG(!InputMap::get_singleton()->has_action(p_action), false, InputMap::get_singleton()->suggest_actions(p_action));
const RBMap<StringName, Action>::Element *E = action_state.find(p_action);
if (!E) {
@ -89,14 +91,14 @@ bool InputDefault::is_action_just_released(const StringName &p_action, bool p_ex
// Backward compatibility for legacy behavior, only return true if currently released.
bool released_requirement = legacy_just_pressed_behavior ? !E->get().pressed : true;
if (Engine::get_singleton()->is_in_physics_frame()) {
return released_requirement && E->get().released_physics_frame == Engine::get_singleton()->get_physics_frames();
if (Application::get_singleton()->is_in_physics_frame()) {
return released_requirement && E->get().released_physics_frame == Application::get_singleton()->get_physics_frames();
} else {
return released_requirement && E->get().released_idle_frame == Engine::get_singleton()->get_idle_frames();
return released_requirement && E->get().released_idle_frame == Application::get_singleton()->get_idle_frames();
}
}
float InputDefault::get_action_strength(const StringName &p_action, bool p_exact) const {
float Input::get_action_strength(const StringName &p_action, bool p_exact) const {
ERR_FAIL_COND_V_MSG(!InputMap::get_singleton()->has_action(p_action), 0.0, InputMap::get_singleton()->suggest_actions(p_action));
const RBMap<StringName, Action>::Element *E = action_state.find(p_action);
if (!E) {
@ -110,7 +112,7 @@ float InputDefault::get_action_strength(const StringName &p_action, bool p_exact
return E->get().strength;
}
float InputDefault::get_action_raw_strength(const StringName &p_action, bool p_exact) const {
float Input::get_action_raw_strength(const StringName &p_action, bool p_exact) const {
ERR_FAIL_COND_V_MSG(!InputMap::get_singleton()->has_action(p_action), 0.0, InputMap::get_singleton()->suggest_actions(p_action));
const RBMap<StringName, Action>::Element *E = action_state.find(p_action);
if (!E) {
@ -155,7 +157,7 @@ Vector2 Input::get_vector(const StringName &p_negative_x, const StringName &p_po
return vector;
}
float InputDefault::get_joy_axis(int p_device, int p_axis) const {
float Input::get_joy_axis(int p_device, int p_axis) const {
_THREAD_SAFE_METHOD_
int c = _combine_device(p_axis, p_device);
if (_joy_axis.has(c)) {
@ -165,12 +167,12 @@ float InputDefault::get_joy_axis(int p_device, int p_axis) const {
}
}
String InputDefault::get_joy_name(int p_idx) {
String Input::get_joy_name(int p_idx) {
_THREAD_SAFE_METHOD_
return joy_names[p_idx].name;
};
Array InputDefault::get_connected_joypads() {
Array Input::get_connected_joypads() {
Array ret;
RBMap<int, Joypad>::Element *elem = joy_names.front();
while (elem) {
@ -182,7 +184,7 @@ Array InputDefault::get_connected_joypads() {
return ret;
}
void InputDefault::joy_connection_changed(int p_idx, bool p_connected, String p_name, String p_guid) {
void Input::joy_connection_changed(int p_idx, bool p_connected, String p_name, String p_guid) {
_THREAD_SAFE_METHOD_
Joypad js;
js.name = p_connected ? p_name : "";
@ -220,10 +222,12 @@ void InputDefault::joy_connection_changed(int p_idx, bool p_connected, String p_
joy_names[p_idx] = js;
// Ensure this signal is emitted on the main thread, as some platforms (e.g. Linux) call this from a different thread.
call_deferred("emit_signal", "joy_connection_changed", p_idx, p_connected);
//call_deferred("emit_signal", "joy_connection_changed", p_idx, p_connected);
//TODO thread
joy_connection_changed_signal.emit(this, p_idx, p_connected);
}
Vector2 InputDefault::get_joy_vibration_strength(int p_device) {
Vector2 Input::get_joy_vibration_strength(int p_device) {
if (joy_vibration.has(p_device)) {
return Vector2(joy_vibration[p_device].weak_magnitude, joy_vibration[p_device].strong_magnitude);
} else {
@ -231,7 +235,7 @@ Vector2 InputDefault::get_joy_vibration_strength(int p_device) {
}
}
float InputDefault::get_joy_vibration_duration(int p_device) {
float Input::get_joy_vibration_duration(int p_device) {
if (joy_vibration.has(p_device)) {
return joy_vibration[p_device].duration;
} else {
@ -239,7 +243,7 @@ float InputDefault::get_joy_vibration_duration(int p_device) {
}
}
uint64_t InputDefault::get_joy_vibration_timestamp(int p_device) {
uint64_t Input::get_joy_vibration_timestamp(int p_device) {
if (joy_vibration.has(p_device)) {
return joy_vibration[p_device].timestamp;
} else {
@ -247,7 +251,7 @@ uint64_t InputDefault::get_joy_vibration_timestamp(int p_device) {
}
}
void InputDefault::add_joy_mapping(String p_mapping, bool p_update_existing) {
void Input::add_joy_mapping(String p_mapping, bool p_update_existing) {
parse_mapping(p_mapping);
if (p_update_existing) {
Vector<String> entry = p_mapping.split(",");
@ -261,7 +265,7 @@ void InputDefault::add_joy_mapping(String p_mapping, bool p_update_existing) {
}
}
void InputDefault::remove_joy_mapping(String p_guid) {
void Input::remove_joy_mapping(String p_guid) {
for (int i = map_db.size() - 1; i >= 0; i--) {
if (p_guid == map_db[i].uid) {
map_db.remove(i);
@ -276,20 +280,22 @@ void InputDefault::remove_joy_mapping(String p_guid) {
}
//Defaults to simple implementation for platforms with a fixed gamepad layout, like consoles.
bool InputDefault::is_joy_known(int p_device) {
return OS::get_singleton()->is_joy_known(p_device);
bool Input::is_joy_known(int p_device) {
//return OS::get_singleton()->is_joy_known(p_device);
return false;
}
String InputDefault::get_joy_guid(int p_device) const {
return OS::get_singleton()->get_joy_guid(p_device);
String Input::get_joy_guid(int p_device) const {
//return OS::get_singleton()->get_joy_guid(p_device);
return String();
}
bool InputDefault::should_ignore_device(int p_vendor_id, int p_product_id) const {
bool Input::should_ignore_device(int p_vendor_id, int p_product_id) const {
uint32_t full_id = (((uint32_t)p_vendor_id) << 16) | ((uint16_t)p_product_id);
return ignored_device_ids.has(full_id);
}
void InputDefault::start_joy_vibration(int p_device, float p_weak_magnitude, float p_strong_magnitude, float p_duration) {
void Input::start_joy_vibration(int p_device, float p_weak_magnitude, float p_strong_magnitude, float p_duration) {
_THREAD_SAFE_METHOD_
if (p_weak_magnitude < 0.f || p_weak_magnitude > 1.f || p_strong_magnitude < 0.f || p_strong_magnitude > 1.f) {
return;
@ -298,31 +304,31 @@ void InputDefault::start_joy_vibration(int p_device, float p_weak_magnitude, flo
vibration.weak_magnitude = p_weak_magnitude;
vibration.strong_magnitude = p_strong_magnitude;
vibration.duration = p_duration;
vibration.timestamp = OS::get_singleton()->get_ticks_usec();
vibration.timestamp = STime::time_us();
joy_vibration[p_device] = vibration;
}
void InputDefault::stop_joy_vibration(int p_device) {
void Input::stop_joy_vibration(int p_device) {
_THREAD_SAFE_METHOD_
VibrationInfo vibration;
vibration.weak_magnitude = 0;
vibration.strong_magnitude = 0;
vibration.duration = 0;
vibration.timestamp = OS::get_singleton()->get_ticks_usec();
vibration.timestamp = STime::time_us();
joy_vibration[p_device] = vibration;
}
void InputDefault::vibrate_handheld(int p_duration_ms) {
OS::get_singleton()->vibrate_handheld(p_duration_ms);
void Input::vibrate_handheld(int p_duration_ms) {
//OS::get_singleton()->vibrate_handheld(p_duration_ms);
}
void InputDefault::set_joy_axis(int p_device, int p_axis, float p_value) {
void Input::set_joy_axis(int p_device, int p_axis, float p_value) {
_THREAD_SAFE_METHOD_
int c = _combine_device(p_axis, p_device);
_joy_axis[c] = p_value;
}
void InputDefault::parse_mapping(String p_mapping) {
void Input::parse_mapping(String p_mapping) {
_THREAD_SAFE_METHOD_;
JoyDeviceMapping mapping;
@ -382,7 +388,7 @@ void InputDefault::parse_mapping(String p_mapping) {
JoystickList output_axis = _get_output_axis(output);
if (output_button == JOY_INVALID_OPTION && output_axis == JOY_INVALID_OPTION) {
print_verbose(vformat("Unrecognized output string \"%s\" in mapping:\n%s", output, p_mapping));
LOG_TRACE(vformat("Unrecognized output string \"%s\" in mapping:\n%s", output, p_mapping));
}
ERR_CONTINUE_MSG(output_button != JOY_INVALID_OPTION && output_axis != JOY_INVALID_OPTION,
@ -426,7 +432,7 @@ void InputDefault::parse_mapping(String p_mapping) {
map_db.push_back(mapping);
};
void InputDefault::joy_button(int p_device, int p_button, bool p_pressed) {
void Input::joy_button(int p_device, int p_button, bool p_pressed) {
_THREAD_SAFE_METHOD_;
Joypad &joy = joy_names[p_device];
ERR_FAIL_INDEX(p_button, JOY_BUTTON_MAX);
@ -459,7 +465,7 @@ void InputDefault::joy_button(int p_device, int p_button, bool p_pressed) {
// no event?
}
void InputDefault::joy_axis(int p_device, int p_axis, float p_value) {
void Input::joy_axis(int p_device, int p_axis, float p_value) {
_THREAD_SAFE_METHOD_;
ERR_FAIL_INDEX(p_axis, JOY_AXIS_MAX);
@ -527,7 +533,7 @@ void InputDefault::joy_axis(int p_device, int p_axis, float p_value) {
}
}
void InputDefault::joy_hat(int p_device, int p_val) {
void Input::joy_hat(int p_device, int p_val) {
_THREAD_SAFE_METHOD_;
const Joypad &joy = joy_names[p_device];
@ -569,27 +575,27 @@ void InputDefault::joy_hat(int p_device, int p_val) {
joy_names[p_device].hat_current = p_val;
}
Point2 InputDefault::get_mouse_position() const {
Point2 Input::get_mouse_position() const {
return mouse_pos;
}
Point2 InputDefault::get_last_mouse_speed() {
Point2 Input::get_last_mouse_speed() {
mouse_speed_track.update(Vector2());
return mouse_speed_track.speed;
}
int InputDefault::get_mouse_button_mask() const {
int Input::get_mouse_button_mask() const {
return mouse_button_mask; // do not trust OS implementation, should remove it - OS::get_singleton()->get_mouse_button_state();
}
void InputDefault::set_mouse_position(const Point2 &p_posf) {
void Input::set_mouse_position(const Point2 &p_posf) {
mouse_pos = p_posf;
}
void InputDefault::warp_mouse_position(const Vector2 &p_to) {
OS::get_singleton()->warp_mouse_position(p_to);
void Input::warp_mouse_position(const Vector2 &p_to) {
//OS::get_singleton()->warp_mouse_position(p_to);
}
Point2i InputDefault::warp_mouse_motion(const Ref<InputEventMouseMotion> &p_motion, const Rect2 &p_rect) {
Point2i Input::warp_mouse_motion(const Ref<InputEventMouseMotion> &p_motion, const Rect2 &p_rect) {
// The relative distance reported for the next event after a warp is in the boundaries of the
// size of the rect on that axis, but it may be greater, in which case there's not problem as fmod()
// will warp it, but if the pointer has moved in the opposite direction between the pointer relocation
@ -607,92 +613,92 @@ Point2i InputDefault::warp_mouse_motion(const Ref<InputEventMouseMotion> &p_moti
const Point2i pos_local = p_motion->get_global_position() - p_rect.position;
const Point2i pos_warped(Math::fposmod(pos_local.x, p_rect.size.x), Math::fposmod(pos_local.y, p_rect.size.y));
if (pos_warped != pos_local) {
OS::get_singleton()->warp_mouse_position(pos_warped + p_rect.position);
}
//if (pos_warped != pos_local) {
//OS::get_singleton()->warp_mouse_position(pos_warped + p_rect.position);
//}
return rel_warped;
}
Vector3 InputDefault::get_gravity() const {
Vector3 Input::get_gravity() const {
_THREAD_SAFE_METHOD_
return gravity;
}
Vector3 InputDefault::get_accelerometer() const {
Vector3 Input::get_accelerometer() const {
_THREAD_SAFE_METHOD_
return accelerometer;
}
Vector3 InputDefault::get_magnetometer() const {
Vector3 Input::get_magnetometer() const {
_THREAD_SAFE_METHOD_
return magnetometer;
}
Vector3 InputDefault::get_gyroscope() const {
Vector3 Input::get_gyroscope() const {
_THREAD_SAFE_METHOD_
return gyroscope;
}
void InputDefault::set_gravity(const Vector3 &p_gravity) {
void Input::set_gravity(const Vector3 &p_gravity) {
_THREAD_SAFE_METHOD_
gravity = p_gravity;
}
void InputDefault::set_accelerometer(const Vector3 &p_accel) {
void Input::set_accelerometer(const Vector3 &p_accel) {
_THREAD_SAFE_METHOD_
accelerometer = p_accel;
}
void InputDefault::set_magnetometer(const Vector3 &p_magnetometer) {
void Input::set_magnetometer(const Vector3 &p_magnetometer) {
_THREAD_SAFE_METHOD_
magnetometer = p_magnetometer;
}
void InputDefault::set_gyroscope(const Vector3 &p_gyroscope) {
void Input::set_gyroscope(const Vector3 &p_gyroscope) {
_THREAD_SAFE_METHOD_
gyroscope = p_gyroscope;
}
void InputDefault::action_press(const StringName &p_action, float p_strength) {
void Input::action_press(const StringName &p_action, float p_strength) {
// Create or retrieve existing action.
Action &action = action_state[p_action];
action.pressed_physics_frame = Engine::get_singleton()->get_physics_frames();
action.pressed_idle_frame = Engine::get_singleton()->get_idle_frames();
action.pressed_physics_frame = Application::get_singleton()->get_physics_frames();
action.pressed_idle_frame = Application::get_singleton()->get_idle_frames();
action.pressed = true;
action.exact = true;
action.strength = p_strength;
action.raw_strength = p_strength;
}
void InputDefault::action_release(const StringName &p_action) {
void Input::action_release(const StringName &p_action) {
// Create or retrieve existing action.
Action &action = action_state[p_action];
action.released_physics_frame = Engine::get_singleton()->get_physics_frames();
action.released_idle_frame = Engine::get_singleton()->get_idle_frames();
action.released_physics_frame = Application::get_singleton()->get_physics_frames();
action.released_idle_frame = Application::get_singleton()->get_idle_frames();
action.pressed = false;
action.exact = true;
action.strength = 0.0f;
action.raw_strength = 0.0f;
}
void InputDefault::set_emulate_touch_from_mouse(bool p_emulate) {
void Input::set_emulate_touch_from_mouse(bool p_emulate) {
emulate_touch_from_mouse = p_emulate;
}
bool InputDefault::is_emulating_touch_from_mouse() const {
bool Input::is_emulating_touch_from_mouse() const {
return emulate_touch_from_mouse;
}
// Calling this whenever the game window is focused helps unstucking the "touch mouse"
// if the OS or its abstraction class hasn't properly reported that touch pointers raised
void InputDefault::ensure_touch_mouse_raised() {
void Input::ensure_touch_mouse_raised() {
_THREAD_SAFE_METHOD_
if (mouse_from_touch_index != -1) {
mouse_from_touch_index = -1;
@ -711,19 +717,19 @@ void InputDefault::ensure_touch_mouse_raised() {
}
}
void InputDefault::set_emulate_mouse_from_touch(bool p_emulate) {
void Input::set_emulate_mouse_from_touch(bool p_emulate) {
emulate_mouse_from_touch = p_emulate;
}
bool InputDefault::is_emulating_mouse_from_touch() const {
bool Input::is_emulating_mouse_from_touch() const {
return emulate_mouse_from_touch;
}
Input::CursorShape InputDefault::get_default_cursor_shape() const {
Input::CursorShape Input::get_default_cursor_shape() const {
return default_shape;
}
void InputDefault::set_default_cursor_shape(CursorShape p_shape) {
void Input::set_default_cursor_shape(CursorShape p_shape) {
if (default_shape == p_shape) {
return;
}
@ -738,18 +744,15 @@ void InputDefault::set_default_cursor_shape(CursorShape p_shape) {
parse_input_event(mm);
}
Input::CursorShape InputDefault::get_current_cursor_shape() const {
return (Input::CursorShape)OS::get_singleton()->get_cursor_shape();
Input::CursorShape Input::get_current_cursor_shape() const {
//return (Input::CursorShape)OS::get_singleton()->get_cursor_shape();
return CURSOR_ARROW;
}
void InputDefault::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot) {
if (Engine::get_singleton()->is_editor_hint()) {
return;
}
void Input::set_custom_mouse_cursor(const Ref<Reference> &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot) {
ERR_FAIL_INDEX(p_shape, Input::CURSOR_MAX);
OS::get_singleton()->set_custom_mouse_cursor(p_cursor, (OS::CursorShape)p_shape, p_hotspot);
//OS::get_singleton()->set_custom_mouse_cursor(p_cursor, (OS::CursorShape)p_shape, p_hotspot);
}
static const char *_buttons[JOY_BUTTON_MAX] = {
@ -791,12 +794,12 @@ static const char *_axes[JOY_AXIS_MAX] = {
""
};
String InputDefault::get_joy_button_string(int p_button) {
String Input::get_joy_button_string(int p_button) {
ERR_FAIL_INDEX_V(p_button, JOY_BUTTON_MAX, "");
return _buttons[p_button];
}
int InputDefault::get_joy_button_index_from_string(String p_button) {
int Input::get_joy_button_index_from_string(String p_button) {
for (int i = 0; i < JOY_BUTTON_MAX; i++) {
if (_buttons[i] == nullptr) {
break;
@ -809,12 +812,12 @@ int InputDefault::get_joy_button_index_from_string(String p_button) {
ERR_FAIL_V_MSG(-1, vformat("Could not find a button index matching the string \"%s\".", p_button));
}
String InputDefault::get_joy_axis_string(int p_axis) {
String Input::get_joy_axis_string(int p_axis) {
ERR_FAIL_INDEX_V(p_axis, JOY_AXIS_MAX, "");
return _axes[p_axis];
}
int InputDefault::get_joy_axis_index_from_string(String p_axis) {
int Input::get_joy_axis_index_from_string(String p_axis) {
for (int i = 0; i < JOY_AXIS_MAX; i++) {
if (_axes[i] == nullptr) {
break;
@ -827,7 +830,7 @@ int InputDefault::get_joy_axis_index_from_string(String p_axis) {
ERR_FAIL_V_MSG(-1, vformat("Could not find an axis index matching the string \"%s\".", p_axis));
}
int InputDefault::get_unused_joy_id() {
int Input::get_unused_joy_id() {
for (int i = 0; i < JOYPADS_MAX; i++) {
if (!joy_names.has(i) || !joy_names[i].connected) {
return i;
@ -837,7 +840,7 @@ int InputDefault::get_unused_joy_id() {
}
//platforms that use the remapping system can override and call to these ones
bool InputDefault::is_joy_mapped(int p_device) {
bool Input::is_joy_mapped(int p_device) {
if (joy_names.has(p_device)) {
int mapping = joy_names[p_device].mapping;
if (mapping != -1 && mapping != fallback_mapping) {
@ -847,12 +850,12 @@ bool InputDefault::is_joy_mapped(int p_device) {
return false;
}
String InputDefault::get_joy_guid_remapped(int p_device) const {
String Input::get_joy_guid_remapped(int p_device) const {
ERR_FAIL_COND_V(!joy_names.has(p_device), "");
return joy_names[p_device].uid;
}
void InputDefault::set_fallback_mapping(String p_guid) {
void Input::set_fallback_mapping(String p_guid) {
for (int i = 0; i < map_db.size(); i++) {
if (map_db[i].uid == p_guid) {
fallback_mapping = i;
@ -861,7 +864,7 @@ void InputDefault::set_fallback_mapping(String p_guid) {
}
}
void InputDefault::parse_input_event(const Ref<InputEvent> &p_event) {
void Input::parse_input_event(const Ref<InputEvent> &p_event) {
_THREAD_SAFE_METHOD_
ERR_FAIL_COND(p_event.is_null());
@ -877,7 +880,7 @@ void InputDefault::parse_input_event(const Ref<InputEvent> &p_event) {
}
}
void InputDefault::flush_buffered_events() {
void Input::flush_buffered_events() {
_THREAD_SAFE_METHOD_
while (buffered_events.front()) {
@ -893,23 +896,23 @@ void InputDefault::flush_buffered_events() {
}
}
bool InputDefault::is_using_input_buffering() {
bool Input::is_using_input_buffering() {
return use_input_buffering;
}
void InputDefault::set_use_input_buffering(bool p_enable) {
void Input::set_use_input_buffering(bool p_enable) {
use_input_buffering = p_enable;
}
bool InputDefault::is_using_accumulated_input() {
bool Input::is_using_accumulated_input() {
return use_accumulated_input;
}
void InputDefault::set_use_accumulated_input(bool p_enable) {
void Input::set_use_accumulated_input(bool p_enable) {
use_accumulated_input = p_enable;
}
void InputDefault::release_pressed_events() {
void Input::release_pressed_events() {
flush_buffered_events(); // this is needed to release actions strengths
keys_pressed.clear();
@ -917,7 +920,7 @@ void InputDefault::release_pressed_events() {
joy_buttons_pressed.clear();
_joy_axis.clear();
for (RBMap<StringName, InputDefault::Action>::Element *E = action_state.front(); E; E = E->next()) {
for (RBMap<StringName, Input::Action>::Element *E = action_state.front(); E; E = E->next()) {
if (E->get().pressed) {
action_release(E->key());
}
@ -949,11 +952,11 @@ void Input::get_argument_options(const StringName &p_function, int p_idx, List<S
#endif
}
void InputDefault::set_main_loop(MainLoop *p_main_loop) {
void Input::set_main_loop(Application *p_main_loop) {
main_loop = p_main_loop;
}
void InputDefault::iteration(float p_step) {
void Input::iteration(float p_step) {
}
Input::Input() {
@ -965,18 +968,10 @@ Input::Input() {
emulate_touch_from_mouse = false;
emulate_mouse_from_touch = false;
mouse_from_touch_index = -1;
main_loop = nullptr;
//main_loop = nullptr;
default_shape = CURSOR_ARROW;
legacy_just_pressed_behavior = false;
fallback_mapping = -1;
legacy_just_pressed_behavior = GLOBAL_DEF("input_devices/compatibility/legacy_just_pressed_behavior", false);
if (Engine::get_singleton()->is_editor_hint()) {
// Always use standard behaviour in the editor.
legacy_just_pressed_behavior = false;
}
// Parse default mappings.
{
int i = 0;
@ -986,7 +981,7 @@ Input::Input() {
}
// If defined, parse SDL_GAMECONTROLLERCONFIG for possible new mappings/overrides.
String env_mapping = OS::get_singleton()->get_environment("SDL_GAMECONTROLLERCONFIG");
String env_mapping = "";//OS::get_singleton()->get_environment("SDL_GAMECONTROLLERCONFIG");
if (env_mapping != "") {
Vector<String> entries = env_mapping.split("\n");
for (int i = 0; i < entries.size(); i++) {
@ -997,7 +992,7 @@ Input::Input() {
}
}
String env_ignore_devices = OS::get_singleton()->get_environment("SDL_GAMECONTROLLER_IGNORE_DEVICES");
String env_ignore_devices = "";//OS::get_singleton()->get_environment("SDL_GAMECONTROLLER_IGNORE_DEVICES");
if (!env_ignore_devices.empty()) {
Vector<String> entries = env_ignore_devices.split(",");
for (int i = 0; i < entries.size(); i++) {
@ -1007,7 +1002,7 @@ Input::Input() {
continue;
}
print_verbose(vformat("Device Ignored -- Vendor: %s Product: %s", vid_pid[0], vid_pid[1]));
LOG_TRACE(vformat("Device Ignored -- Vendor: %s Product: %s", vid_pid[0], vid_pid[1]));
const uint16_t vid_unswapped = vid_pid[0].hex_to_int();
const uint16_t pid_unswapped = vid_pid[1].hex_to_int();
const uint16_t vid = BSWAP16(vid_unswapped);
@ -1019,7 +1014,7 @@ Input::Input() {
}
}
InputDefault::JoyEvent InputDefault::_get_mapped_button_event(const JoyDeviceMapping &mapping, int p_button) {
Input::JoyEvent Input::_get_mapped_button_event(const JoyDeviceMapping &mapping, int p_button) {
JoyEvent event;
event.type = TYPE_MAX;
@ -1048,14 +1043,14 @@ InputDefault::JoyEvent InputDefault::_get_mapped_button_event(const JoyDeviceMap
}
return event;
default:
ERR_PRINT_ONCE("Joypad button mapping error.");
ERR_PRINT("Joypad button mapping error.");
}
}
}
return event;
}
InputDefault::JoyEvent InputDefault::_get_mapped_axis_event(const JoyDeviceMapping &mapping, int p_axis, float p_value) {
Input::JoyEvent Input::_get_mapped_axis_event(const JoyDeviceMapping &mapping, int p_axis, float p_value) {
JoyEvent event;
event.type = TYPE_MAX;
@ -1117,7 +1112,7 @@ InputDefault::JoyEvent InputDefault::_get_mapped_axis_event(const JoyDeviceMappi
}
return event;
default:
ERR_PRINT_ONCE("Joypad axis mapping error.");
ERR_PRINT("Joypad axis mapping error.");
}
}
}
@ -1125,7 +1120,7 @@ InputDefault::JoyEvent InputDefault::_get_mapped_axis_event(const JoyDeviceMappi
return event;
}
void InputDefault::_get_mapped_hat_events(const JoyDeviceMapping &mapping, int p_hat, JoyEvent r_events[HAT_MAX]) {
void Input::_get_mapped_hat_events(const JoyDeviceMapping &mapping, int p_hat, JoyEvent r_events[HAT_MAX]) {
for (int i = 0; i < mapping.bindings.size(); i++) {
const JoyBinding binding = mapping.bindings[i];
if (binding.inputType == TYPE_HAT && binding.input.hat.hat == p_hat) {
@ -1144,7 +1139,7 @@ void InputDefault::_get_mapped_hat_events(const JoyDeviceMapping &mapping, int p
hat_direction = HAT_LEFT;
break;
default:
ERR_PRINT_ONCE("Joypad button mapping error.");
ERR_PRINT("Joypad button mapping error.");
continue;
}
@ -1170,7 +1165,7 @@ void InputDefault::_get_mapped_hat_events(const JoyDeviceMapping &mapping, int p
}
break;
default:
ERR_PRINT_ONCE("Joypad button mapping error.");
ERR_PRINT("Joypad button mapping error.");
}
}
}
@ -1180,7 +1175,7 @@ void InputDefault::_get_mapped_hat_events(const JoyDeviceMapping &mapping, int p
static const char *_joy_buttons[] = { "a", "b", "x", "y", "leftshoulder", "rightshoulder", "lefttrigger", "righttrigger", "leftstick", "rightstick", "back", "start", "dpup", "dpdown", "dpleft", "dpright", "guide", "misc1", "paddle1", "paddle2", "paddle3", "paddle4", "touchpad", nullptr };
static const char *_joy_axes[] = { "leftx", "lefty", "rightx", "righty", nullptr };
JoystickList InputDefault::_get_output_button(String output) {
JoystickList Input::_get_output_button(String output) {
for (int i = 0; _joy_buttons[i]; i++) {
if (output == _joy_buttons[i]) {
return JoystickList(i);
@ -1189,7 +1184,7 @@ JoystickList InputDefault::_get_output_button(String output) {
return JoystickList::JOY_INVALID_OPTION;
}
JoystickList InputDefault::_get_output_axis(String output) {
JoystickList Input::_get_output_axis(String output) {
for (int i = 0; _joy_axes[i]; i++) {
if (output == _joy_axes[i]) {
return JoystickList(i);
@ -1198,7 +1193,7 @@ JoystickList InputDefault::_get_output_axis(String output) {
return JoystickList::JOY_INVALID_OPTION;
}
void InputDefault::_button_event(int p_device, int p_index, bool p_pressed) {
void Input::_button_event(int p_device, int p_index, bool p_pressed) {
Ref<InputEventJoypadButton> ievent;
ievent.instance();
ievent->set_device(p_device);
@ -1208,7 +1203,7 @@ void InputDefault::_button_event(int p_device, int p_index, bool p_pressed) {
parse_input_event(ievent);
}
void InputDefault::_axis_event(int p_device, int p_axis, float p_value) {
void Input::_axis_event(int p_device, int p_axis, float p_value) {
Ref<InputEventJoypadMotion> ievent;
ievent.instance();
ievent->set_device(p_device);
@ -1218,7 +1213,7 @@ void InputDefault::_axis_event(int p_device, int p_axis, float p_value) {
parse_input_event(ievent);
};
void InputDefault::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_emulated) {
void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_emulated) {
// This function does the final delivery of the input event to user land.
// Regardless where the event came from originally, this has to happen on the main thread.
DEV_ASSERT(Thread::get_caller_id() == Thread::get_main_id());
@ -1405,12 +1400,12 @@ void InputDefault::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool
if (!p_event->is_echo() && is_action_pressed(E->key(), false) != p_event->is_action_pressed(E->key())) {
if (p_event->is_action_pressed(E->key())) {
action.pressed = true;
action.pressed_physics_frame = Engine::get_singleton()->get_physics_frames();
action.pressed_idle_frame = Engine::get_singleton()->get_idle_frames();
action.pressed_physics_frame = Application::get_singleton()->get_physics_frames();
action.pressed_idle_frame = Application::get_singleton()->get_idle_frames();
} else {
action.pressed = false;
action.released_physics_frame = Engine::get_singleton()->get_physics_frames();
action.released_idle_frame = Engine::get_singleton()->get_idle_frames();
action.released_physics_frame = Application::get_singleton()->get_physics_frames();
action.released_idle_frame = Application::get_singleton()->get_idle_frames();
}
action.strength = 0.0f;
@ -1430,7 +1425,7 @@ void InputDefault::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool
}
}
static String Input::_hex_str(uint8_t p_byte) {
String Input::_hex_str(uint8_t p_byte) {
static const char *dict = "0123456789abcdef";
char ret[3];
ret[2] = 0;
@ -1443,8 +1438,8 @@ static String Input::_hex_str(uint8_t p_byte) {
Input *Input::singleton = nullptr;
void InputDefault::SpeedTrack::update(const Vector2 &p_delta_p) {
uint64_t tick = OS::get_singleton()->get_ticks_usec();
void Input::SpeedTrack::update(const Vector2 &p_delta_p) {
uint64_t tick = STime::time_us();
uint32_t tdiff = tick - last_tick;
float delta_t = tdiff / 1000000.0;
last_tick = tick;
@ -1470,14 +1465,14 @@ void InputDefault::SpeedTrack::update(const Vector2 &p_delta_p) {
accum_t = 0;
}
void InputDefault::SpeedTrack::reset() {
last_tick = OS::get_singleton()->get_ticks_usec();
void Input::SpeedTrack::reset() {
last_tick = STime::time_us();
speed = Vector2();
accum = Vector2();
accum_t = 0;
}
InputDefault::SpeedTrack::SpeedTrack() {
Input::SpeedTrack::SpeedTrack() {
min_ref_frame = 0.1;
max_ref_frame = 3.0;
reset();

View File

@ -6,17 +6,26 @@
/* From https://github.com/Relintai/pandemonium_engine (MIT) */
/*************************************************************************/
#include "core/math/vector2i.h"
#include "core/object/object.h"
#include "core/os/main_loop.h"
#include "core/os/thread_safe.h"
#include "core/vector2i.h"
#include "object/object.h"
//#include "core/os/main_loop.h"
#include "core/rb_set.h"
#include "core/rb_map.h"
#include "core/thread_safe.h"
#include "object/reference.h"
#include "object/psignal.h"
#include "render_core/input/input_event.h"
class Application;
class Input : public Object {
GDCLASS(Input, Object);
SFW_OBJECT(Input, Object);
_THREAD_SAFE_CLASS_
public:
Signal joy_connection_changed_signal;
enum MouseMode {
MOUSE_MODE_VISIBLE,
MOUSE_MODE_HIDDEN,
@ -143,7 +152,7 @@ public:
virtual CursorShape get_default_cursor_shape() const;
virtual void set_default_cursor_shape(CursorShape p_shape);
virtual CursorShape get_current_cursor_shape() const;
virtual void set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape = CURSOR_ARROW, const Vector2 &p_hotspot = Vector2());
virtual void set_custom_mouse_cursor(const Ref<Reference> &p_cursor, CursorShape p_shape = CURSOR_ARROW, const Vector2 &p_hotspot = Vector2());
virtual String get_joy_button_string(int p_button);
virtual String get_joy_axis_string(int p_axis);
@ -168,116 +177,12 @@ public:
void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options, const String &quote_style) const;
void set_main_loop(MainLoop *p_main_loop);
void set_main_loop(Application *p_main_loop);
void iteration(float p_step);
Input();
protected:
JoyEvent _get_mapped_button_event(const JoyDeviceMapping &mapping, int p_button);
JoyEvent _get_mapped_axis_event(const JoyDeviceMapping &mapping, int p_axis, float p_value);
void _get_mapped_hat_events(const JoyDeviceMapping &mapping, int p_hat, JoyEvent r_events[HAT_MAX]);
JoystickList _get_output_button(String output);
JoystickList _get_output_axis(String output);
void _button_event(int p_device, int p_index, bool p_pressed);
void _axis_event(int p_device, int p_axis, float p_value);
void _parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_emulated);
static String _hex_str(uint8_t p_byte);
List<Ref<InputEvent>> buffered_events;
bool use_input_buffering;
bool use_accumulated_input;
int mouse_button_mask;
RBSet<int> physical_keys_pressed;
RBSet<int> keys_pressed;
RBSet<int> joy_buttons_pressed;
RBMap<int, float> _joy_axis;
//Map<StringName,int> custom_action_press;
Vector3 gravity;
Vector3 accelerometer;
Vector3 magnetometer;
Vector3 gyroscope;
Vector2 mouse_pos;
MainLoop *main_loop;
bool legacy_just_pressed_behavior;
struct Action {
uint64_t pressed_physics_frame;
uint64_t pressed_idle_frame;
uint64_t released_physics_frame;
uint64_t released_idle_frame;
bool pressed;
bool exact;
float strength;
float raw_strength;
Action() {
pressed_physics_frame = UINT64_MAX;
pressed_idle_frame = UINT64_MAX;
released_physics_frame = UINT64_MAX;
released_idle_frame = UINT64_MAX;
pressed = false;
exact = true;
strength = 0.0f;
raw_strength = 0.0f;
}
};
RBMap<StringName, Action> action_state;
bool emulate_touch_from_mouse;
bool emulate_mouse_from_touch;
int mouse_from_touch_index;
struct SpeedTrack {
uint64_t last_tick;
Vector2 speed;
Vector2 accum;
float accum_t;
float min_ref_frame;
float max_ref_frame;
void update(const Vector2 &p_delta_p);
void reset();
SpeedTrack();
};
struct Joypad {
StringName name;
StringName uid;
bool connected;
bool last_buttons[JOY_BUTTON_MAX + 12]; //apparently SDL specifies 35 possible buttons on android
float last_axis[JOY_AXIS_MAX];
int last_hat;
int mapping;
int hat_current;
Joypad() {
for (int i = 0; i < JOY_AXIS_MAX; i++) {
last_axis[i] = 0.0f;
}
for (int i = 0; i < JOY_BUTTON_MAX + 12; i++) {
last_buttons[i] = false;
}
connected = false;
last_hat = HAT_MASK_CENTER;
mapping = -1;
hat_current = 0;
}
};
SpeedTrack mouse_speed_track;
RBMap<int, SpeedTrack> touch_speed_track;
RBMap<int, Joypad> joy_names;
int fallback_mapping;
CursorShape default_shape;
enum JoyType {
TYPE_BUTTON,
TYPE_AXIS,
@ -333,9 +238,42 @@ protected:
Vector<JoyBinding> bindings;
};
Vector<JoyDeviceMapping> map_db;
struct SpeedTrack {
uint64_t last_tick;
Vector2 speed;
Vector2 accum;
float accum_t;
float min_ref_frame;
float max_ref_frame;
RBSet<uint32_t> ignored_device_ids;
void update(const Vector2 &p_delta_p);
void reset();
SpeedTrack();
};
struct Joypad {
StringName name;
StringName uid;
bool connected;
bool last_buttons[JOY_BUTTON_MAX + 12]; //apparently SDL specifies 35 possible buttons on android
float last_axis[JOY_AXIS_MAX];
int last_hat;
int mapping;
int hat_current;
Joypad() {
for (int i = 0; i < JOY_AXIS_MAX; i++) {
last_axis[i] = 0.0f;
}
for (int i = 0; i < JOY_BUTTON_MAX + 12; i++) {
last_buttons[i] = false;
}
connected = false;
last_hat = HAT_MASK_CENTER;
mapping = -1;
hat_current = 0;
}
};
struct VibrationInfo {
float weak_magnitude;
@ -344,12 +282,80 @@ protected:
uint64_t timestamp;
};
struct Action {
uint64_t pressed_physics_frame;
uint64_t pressed_idle_frame;
uint64_t released_physics_frame;
uint64_t released_idle_frame;
bool pressed;
bool exact;
float strength;
float raw_strength;
Action() {
pressed_physics_frame = UINT64_MAX;
pressed_idle_frame = UINT64_MAX;
released_physics_frame = UINT64_MAX;
released_idle_frame = UINT64_MAX;
pressed = false;
exact = true;
strength = 0.0f;
raw_strength = 0.0f;
}
};
JoyEvent _get_mapped_button_event(const JoyDeviceMapping &mapping, int p_button);
JoyEvent _get_mapped_axis_event(const JoyDeviceMapping &mapping, int p_axis, float p_value);
void _get_mapped_hat_events(const JoyDeviceMapping &mapping, int p_hat, JoyEvent r_events[HAT_MAX]);
JoystickList _get_output_button(String output);
JoystickList _get_output_axis(String output);
void _button_event(int p_device, int p_index, bool p_pressed);
void _axis_event(int p_device, int p_axis, float p_value);
void _parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_emulated);
static String _hex_str(uint8_t p_byte);
List<Ref<InputEvent>> buffered_events;
bool use_input_buffering;
bool use_accumulated_input;
int mouse_button_mask;
RBSet<int> physical_keys_pressed;
RBSet<int> keys_pressed;
RBSet<int> joy_buttons_pressed;
RBMap<int, float> _joy_axis;
//Map<StringName,int> custom_action_press;
Vector3 gravity;
Vector3 accelerometer;
Vector3 magnetometer;
Vector3 gyroscope;
Vector2 mouse_pos;
Application *main_loop;
bool legacy_just_pressed_behavior;
RBMap<StringName, Action> action_state;
bool emulate_touch_from_mouse;
bool emulate_mouse_from_touch;
int mouse_from_touch_index;
SpeedTrack mouse_speed_track;
RBMap<int, SpeedTrack> touch_speed_track;
RBMap<int, Joypad> joy_names;
int fallback_mapping;
CursorShape default_shape;
Vector<JoyDeviceMapping> map_db;
RBSet<uint32_t> ignored_device_ids;
RBMap<int, VibrationInfo> joy_vibration;
static Input *singleton;
};
VARIANT_ENUM_CAST(Input::MouseMode);
VARIANT_ENUM_CAST(Input::CursorShape);
#endif // INPUT_H

View File

@ -5,9 +5,9 @@
#include "input_event.h"
#include "core/input/input_map.h"
#include "core/input/shortcut.h"
#include "core/os/keyboard.h"
#include "render_core/input/input_map.h"
#include "render_core/input/keyboard.h"
#include "render_core/input/shortcut.h"
const int InputEvent::DEVICE_ID_TOUCH_MOUSE = -1;
const int InputEvent::DEVICE_ID_INTERNAL = -2;
@ -84,33 +84,6 @@ bool InputEvent::is_action_type() const {
return false;
}
void InputEvent::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_device", "device"), &InputEvent::set_device);
ClassDB::bind_method(D_METHOD("get_device"), &InputEvent::get_device);
ClassDB::bind_method(D_METHOD("is_action", "action", "exact_match"), &InputEvent::is_action, DEFVAL(false));
ClassDB::bind_method(D_METHOD("is_action_pressed", "action", "allow_echo", "exact_match"), &InputEvent::is_action_pressed, DEFVAL(false), DEFVAL(false));
ClassDB::bind_method(D_METHOD("is_action_released", "action", "exact_match"), &InputEvent::is_action_released, DEFVAL(false));
ClassDB::bind_method(D_METHOD("get_action_strength", "action", "exact_match"), &InputEvent::get_action_strength, DEFVAL(false));
ClassDB::bind_method(D_METHOD("is_canceled"), &InputEvent::is_canceled);
ClassDB::bind_method(D_METHOD("is_pressed"), &InputEvent::is_pressed);
ClassDB::bind_method(D_METHOD("is_released"), &InputEvent::is_released);
ClassDB::bind_method(D_METHOD("is_echo"), &InputEvent::is_echo);
ClassDB::bind_method(D_METHOD("as_text"), &InputEvent::as_text);
ClassDB::bind_method(D_METHOD("shortcut_match", "event", "exact_match"), &InputEvent::shortcut_match, DEFVAL(true));
ClassDB::bind_method(D_METHOD("is_action_type"), &InputEvent::is_action_type);
ClassDB::bind_method(D_METHOD("accumulate", "with_event"), &InputEvent::accumulate);
ClassDB::bind_method(D_METHOD("xformed_by", "xform", "local_ofs"), &InputEvent::xformed_by, DEFVAL(Vector2()));
ADD_PROPERTY(PropertyInfo(Variant::INT, "device"), "set_device", "get_device");
}
InputEvent::InputEvent() {
device = 0;
canceled = false;
@ -179,29 +152,6 @@ uint32_t InputEventWithModifiers::get_modifiers_mask() const {
return mask;
}
void InputEventWithModifiers::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_alt", "enable"), &InputEventWithModifiers::set_alt);
ClassDB::bind_method(D_METHOD("get_alt"), &InputEventWithModifiers::get_alt);
ClassDB::bind_method(D_METHOD("set_shift", "enable"), &InputEventWithModifiers::set_shift);
ClassDB::bind_method(D_METHOD("get_shift"), &InputEventWithModifiers::get_shift);
ClassDB::bind_method(D_METHOD("set_control", "enable"), &InputEventWithModifiers::set_control);
ClassDB::bind_method(D_METHOD("get_control"), &InputEventWithModifiers::get_control);
ClassDB::bind_method(D_METHOD("set_metakey", "enable"), &InputEventWithModifiers::set_metakey);
ClassDB::bind_method(D_METHOD("get_metakey"), &InputEventWithModifiers::get_metakey);
ClassDB::bind_method(D_METHOD("set_command", "enable"), &InputEventWithModifiers::set_command);
ClassDB::bind_method(D_METHOD("get_command"), &InputEventWithModifiers::get_command);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "alt"), "set_alt", "get_alt");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "shift"), "set_shift", "get_shift");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "control"), "set_control", "get_control");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "meta"), "set_metakey", "get_metakey");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "command"), "set_command", "get_command");
}
InputEventWithModifiers::InputEventWithModifiers() {
alt = false;
shift = false;
@ -353,34 +303,6 @@ bool InputEventKey::shortcut_match(const Ref<InputEvent> &p_event, bool p_exact_
}
}
void InputEventKey::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &InputEventKey::set_pressed);
ClassDB::bind_method(D_METHOD("set_scancode", "scancode"), &InputEventKey::set_scancode);
ClassDB::bind_method(D_METHOD("get_scancode"), &InputEventKey::get_scancode);
ClassDB::bind_method(D_METHOD("set_physical_scancode", "scancode"), &InputEventKey::set_physical_scancode);
ClassDB::bind_method(D_METHOD("get_physical_scancode"), &InputEventKey::get_physical_scancode);
ClassDB::bind_method(D_METHOD("set_unicode", "unicode"), &InputEventKey::set_unicode);
ClassDB::bind_method(D_METHOD("get_unicode"), &InputEventKey::get_unicode);
ClassDB::bind_method(D_METHOD("set_echo", "echo"), &InputEventKey::set_echo);
ClassDB::bind_method(D_METHOD("set_action_match_force_exact", "unicode"), &InputEventKey::set_action_match_force_exact);
ClassDB::bind_method(D_METHOD("is_action_match_force_exact"), &InputEventKey::is_action_match_force_exact);
ClassDB::bind_method(D_METHOD("get_scancode_with_modifiers"), &InputEventKey::get_scancode_with_modifiers);
ClassDB::bind_method(D_METHOD("get_physical_scancode_with_modifiers"), &InputEventKey::get_physical_scancode_with_modifiers);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed");
ADD_PROPERTY(PropertyInfo(Variant::INT, "scancode"), "set_scancode", "get_scancode");
ADD_PROPERTY(PropertyInfo(Variant::INT, "physical_scancode"), "set_physical_scancode", "get_physical_scancode");
ADD_PROPERTY(PropertyInfo(Variant::INT, "unicode"), "set_unicode", "get_unicode");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "echo"), "set_echo", "is_echo");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "action_match_force_exact"), "set_action_match_force_exact", "is_action_match_force_exact");
}
InputEventKey::InputEventKey() {
scancode = 0;
physical_scancode = 0;
@ -412,21 +334,6 @@ Vector2 InputEventMouse::get_global_position() const {
return global_pos;
}
void InputEventMouse::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_button_mask", "button_mask"), &InputEventMouse::set_button_mask);
ClassDB::bind_method(D_METHOD("get_button_mask"), &InputEventMouse::get_button_mask);
ClassDB::bind_method(D_METHOD("set_position", "position"), &InputEventMouse::set_position);
ClassDB::bind_method(D_METHOD("get_position"), &InputEventMouse::get_position);
ClassDB::bind_method(D_METHOD("set_global_position", "global_position"), &InputEventMouse::set_global_position);
ClassDB::bind_method(D_METHOD("get_global_position"), &InputEventMouse::get_global_position);
ADD_PROPERTY(PropertyInfo(Variant::INT, "button_mask"), "set_button_mask", "get_button_mask");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "position"), "set_position", "get_position");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "global_position"), "set_global_position", "get_global_position");
}
InputEventMouse::InputEventMouse() {
button_mask = 0;
}
@ -565,26 +472,6 @@ String InputEventMouseButton::as_text() const {
return "InputEventMouseButton : button_index=" + button_index_string + ", pressed=" + (pressed ? "true" : "false") + ", canceled=" + (canceled ? "true" : "false") + ", position=(" + String(get_position()) + "), button_mask=" + itos(get_button_mask()) + ", doubleclick=" + (doubleclick ? "true" : "false");
}
void InputEventMouseButton::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_factor", "factor"), &InputEventMouseButton::set_factor);
ClassDB::bind_method(D_METHOD("get_factor"), &InputEventMouseButton::get_factor);
ClassDB::bind_method(D_METHOD("set_button_index", "button_index"), &InputEventMouseButton::set_button_index);
ClassDB::bind_method(D_METHOD("get_button_index"), &InputEventMouseButton::get_button_index);
ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &InputEventMouseButton::set_pressed);
ClassDB::bind_method(D_METHOD("set_canceled", "canceled"), &InputEventMouseButton::set_canceled);
ClassDB::bind_method(D_METHOD("set_doubleclick", "doubleclick"), &InputEventMouseButton::set_doubleclick);
ClassDB::bind_method(D_METHOD("is_doubleclick"), &InputEventMouseButton::is_doubleclick);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "factor"), "set_factor", "get_factor");
ADD_PROPERTY(PropertyInfo(Variant::INT, "button_index"), "set_button_index", "get_button_index");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "canceled"), "set_canceled", "is_canceled");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "doubleclick"), "set_doubleclick", "is_doubleclick");
}
InputEventMouseButton::InputEventMouseButton() {
factor = 1;
button_index = 0;
@ -726,29 +613,6 @@ bool InputEventMouseMotion::accumulate(const Ref<InputEvent> &p_event) {
return true;
}
void InputEventMouseMotion::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_tilt", "tilt"), &InputEventMouseMotion::set_tilt);
ClassDB::bind_method(D_METHOD("get_tilt"), &InputEventMouseMotion::get_tilt);
ClassDB::bind_method(D_METHOD("set_pressure", "pressure"), &InputEventMouseMotion::set_pressure);
ClassDB::bind_method(D_METHOD("get_pressure"), &InputEventMouseMotion::get_pressure);
ClassDB::bind_method(D_METHOD("set_pen_inverted", "pen_inverted"), &InputEventMouseMotion::set_pen_inverted);
ClassDB::bind_method(D_METHOD("get_pen_inverted"), &InputEventMouseMotion::get_pen_inverted);
ClassDB::bind_method(D_METHOD("set_relative", "relative"), &InputEventMouseMotion::set_relative);
ClassDB::bind_method(D_METHOD("get_relative"), &InputEventMouseMotion::get_relative);
ClassDB::bind_method(D_METHOD("set_speed", "speed"), &InputEventMouseMotion::set_speed);
ClassDB::bind_method(D_METHOD("get_speed"), &InputEventMouseMotion::get_speed);
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "tilt"), "set_tilt", "get_tilt");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "pressure"), "set_pressure", "get_pressure");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pen_inverted"), "set_pen_inverted", "get_pen_inverted");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "relative"), "set_relative", "get_relative");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "speed"), "set_speed", "get_speed");
}
InputEventMouseMotion::InputEventMouseMotion() {
pressure = 0;
pen_inverted = false;
@ -827,17 +691,6 @@ String InputEventJoypadMotion::as_text() const {
return "InputEventJoypadMotion : axis=" + itos(axis) + ", axis_value=" + String(Variant(axis_value));
}
void InputEventJoypadMotion::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_axis", "axis"), &InputEventJoypadMotion::set_axis);
ClassDB::bind_method(D_METHOD("get_axis"), &InputEventJoypadMotion::get_axis);
ClassDB::bind_method(D_METHOD("set_axis_value", "axis_value"), &InputEventJoypadMotion::set_axis_value);
ClassDB::bind_method(D_METHOD("get_axis_value"), &InputEventJoypadMotion::get_axis_value);
ADD_PROPERTY(PropertyInfo(Variant::INT, "axis"), "set_axis", "get_axis");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "axis_value"), "set_axis_value", "get_axis_value");
}
InputEventJoypadMotion::InputEventJoypadMotion() {
axis = 0;
axis_value = 0;
@ -900,20 +753,6 @@ String InputEventJoypadButton::as_text() const {
return "InputEventJoypadButton : button_index=" + itos(button_index) + ", pressed=" + (is_pressed() ? "true" : "false") + ", pressure=" + String(Variant(pressure));
}
void InputEventJoypadButton::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_button_index", "button_index"), &InputEventJoypadButton::set_button_index);
ClassDB::bind_method(D_METHOD("get_button_index"), &InputEventJoypadButton::get_button_index);
ClassDB::bind_method(D_METHOD("set_pressure", "pressure"), &InputEventJoypadButton::set_pressure);
ClassDB::bind_method(D_METHOD("get_pressure"), &InputEventJoypadButton::get_pressure);
ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &InputEventJoypadButton::set_pressed);
ADD_PROPERTY(PropertyInfo(Variant::INT, "button_index"), "set_button_index", "get_button_index");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "pressure"), "set_pressure", "get_pressure");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed");
}
InputEventJoypadButton::InputEventJoypadButton() {
button_index = 0;
pressure = 0;
@ -966,26 +805,6 @@ String InputEventScreenTouch::as_text() const {
return "InputEventScreenTouch : index=" + itos(index) + ", pressed=" + (pressed ? "true" : "false") + ", canceled=" + (canceled ? "true" : "false") + ", position=(" + String(get_position()) + "), double_tap=" + (double_tap ? "true" : "false");
}
void InputEventScreenTouch::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_index", "index"), &InputEventScreenTouch::set_index);
ClassDB::bind_method(D_METHOD("get_index"), &InputEventScreenTouch::get_index);
ClassDB::bind_method(D_METHOD("set_position", "position"), &InputEventScreenTouch::set_position);
ClassDB::bind_method(D_METHOD("get_position"), &InputEventScreenTouch::get_position);
ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &InputEventScreenTouch::set_pressed);
ClassDB::bind_method(D_METHOD("set_canceled", "canceled"), &InputEventScreenTouch::set_canceled);
ClassDB::bind_method(D_METHOD("set_double_tap", "double_tap"), &InputEventScreenTouch::set_double_tap);
ClassDB::bind_method(D_METHOD("is_double_tap"), &InputEventScreenTouch::is_double_tap);
ADD_PROPERTY(PropertyInfo(Variant::INT, "index"), "set_index", "get_index");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "position"), "set_position", "get_position");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "canceled"), "set_canceled", "is_canceled");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "double_tap"), "set_double_tap", "is_double_tap");
}
InputEventScreenTouch::InputEventScreenTouch() {
index = 0;
double_tap = false;
@ -1058,25 +877,6 @@ bool InputEventScreenDrag::accumulate(const Ref<InputEvent> &p_event) {
return true;
}
void InputEventScreenDrag::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_index", "index"), &InputEventScreenDrag::set_index);
ClassDB::bind_method(D_METHOD("get_index"), &InputEventScreenDrag::get_index);
ClassDB::bind_method(D_METHOD("set_position", "position"), &InputEventScreenDrag::set_position);
ClassDB::bind_method(D_METHOD("get_position"), &InputEventScreenDrag::get_position);
ClassDB::bind_method(D_METHOD("set_relative", "relative"), &InputEventScreenDrag::set_relative);
ClassDB::bind_method(D_METHOD("get_relative"), &InputEventScreenDrag::get_relative);
ClassDB::bind_method(D_METHOD("set_speed", "speed"), &InputEventScreenDrag::set_speed);
ClassDB::bind_method(D_METHOD("get_speed"), &InputEventScreenDrag::get_speed);
ADD_PROPERTY(PropertyInfo(Variant::INT, "index"), "set_index", "get_index");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "position"), "set_position", "get_position");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "relative"), "set_relative", "get_relative");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "speed"), "set_speed", "get_speed");
}
InputEventScreenDrag::InputEventScreenDrag() {
index = 0;
}
@ -1140,20 +940,6 @@ String InputEventAction::as_text() const {
return "InputEventAction : action=" + action + ", pressed=(" + (is_pressed() ? "true" : "false");
}
void InputEventAction::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_action", "action"), &InputEventAction::set_action);
ClassDB::bind_method(D_METHOD("get_action"), &InputEventAction::get_action);
ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &InputEventAction::set_pressed);
ClassDB::bind_method(D_METHOD("set_strength", "strength"), &InputEventAction::set_strength);
ClassDB::bind_method(D_METHOD("get_strength"), &InputEventAction::get_strength);
ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "action"), "set_action", "get_action");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "strength", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_strength", "get_strength");
}
InputEventAction::InputEventAction() {
strength = 1.0f;
}
@ -1163,13 +949,6 @@ void InputEventGesture::set_position(const Vector2 &p_pos) {
pos = p_pos;
}
void InputEventGesture::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_position", "position"), &InputEventGesture::set_position);
ClassDB::bind_method(D_METHOD("get_position"), &InputEventGesture::get_position);
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "position"), "set_position", "get_position");
}
Vector2 InputEventGesture::get_position() const {
return pos;
}
@ -1200,13 +979,6 @@ String InputEventMagnifyGesture::as_text() const {
return "InputEventMagnifyGesture : factor=" + rtos(get_factor()) + ", position=(" + String(get_position()) + ")";
}
void InputEventMagnifyGesture::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_factor", "factor"), &InputEventMagnifyGesture::set_factor);
ClassDB::bind_method(D_METHOD("get_factor"), &InputEventMagnifyGesture::get_factor);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "factor"), "set_factor", "get_factor");
}
InputEventMagnifyGesture::InputEventMagnifyGesture() {
factor = 1.0;
}
@ -1237,13 +1009,6 @@ String InputEventPanGesture::as_text() const {
return "InputEventPanGesture : delta=(" + String(get_delta()) + "), position=(" + String(get_position()) + ")";
}
void InputEventPanGesture::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_delta", "delta"), &InputEventPanGesture::set_delta);
ClassDB::bind_method(D_METHOD("get_delta"), &InputEventPanGesture::get_delta);
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "delta"), "set_delta", "get_delta");
}
InputEventPanGesture::InputEventPanGesture() {
delta = Vector2(0, 0);
}
@ -1317,34 +1082,6 @@ String InputEventMIDI::as_text() const {
return "InputEventMIDI : channel=(" + itos(get_channel()) + "), message=(" + itos(get_message()) + ")";
}
void InputEventMIDI::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_channel", "channel"), &InputEventMIDI::set_channel);
ClassDB::bind_method(D_METHOD("get_channel"), &InputEventMIDI::get_channel);
ClassDB::bind_method(D_METHOD("set_message", "message"), &InputEventMIDI::set_message);
ClassDB::bind_method(D_METHOD("get_message"), &InputEventMIDI::get_message);
ClassDB::bind_method(D_METHOD("set_pitch", "pitch"), &InputEventMIDI::set_pitch);
ClassDB::bind_method(D_METHOD("get_pitch"), &InputEventMIDI::get_pitch);
ClassDB::bind_method(D_METHOD("set_velocity", "velocity"), &InputEventMIDI::set_velocity);
ClassDB::bind_method(D_METHOD("get_velocity"), &InputEventMIDI::get_velocity);
ClassDB::bind_method(D_METHOD("set_instrument", "instrument"), &InputEventMIDI::set_instrument);
ClassDB::bind_method(D_METHOD("get_instrument"), &InputEventMIDI::get_instrument);
ClassDB::bind_method(D_METHOD("set_pressure", "pressure"), &InputEventMIDI::set_pressure);
ClassDB::bind_method(D_METHOD("get_pressure"), &InputEventMIDI::get_pressure);
ClassDB::bind_method(D_METHOD("set_controller_number", "controller_number"), &InputEventMIDI::set_controller_number);
ClassDB::bind_method(D_METHOD("get_controller_number"), &InputEventMIDI::get_controller_number);
ClassDB::bind_method(D_METHOD("set_controller_value", "controller_value"), &InputEventMIDI::set_controller_value);
ClassDB::bind_method(D_METHOD("get_controller_value"), &InputEventMIDI::get_controller_value);
ADD_PROPERTY(PropertyInfo(Variant::INT, "channel"), "set_channel", "get_channel");
ADD_PROPERTY(PropertyInfo(Variant::INT, "message"), "set_message", "get_message");
ADD_PROPERTY(PropertyInfo(Variant::INT, "pitch"), "set_pitch", "get_pitch");
ADD_PROPERTY(PropertyInfo(Variant::INT, "velocity"), "set_velocity", "get_velocity");
ADD_PROPERTY(PropertyInfo(Variant::INT, "instrument"), "set_instrument", "get_instrument");
ADD_PROPERTY(PropertyInfo(Variant::INT, "pressure"), "set_pressure", "get_pressure");
ADD_PROPERTY(PropertyInfo(Variant::INT, "controller_number"), "set_controller_number", "get_controller_number");
ADD_PROPERTY(PropertyInfo(Variant::INT, "controller_value"), "set_controller_value", "get_controller_value");
}
InputEventMIDI::InputEventMIDI() {
channel = 0;
message = 0;
@ -1367,13 +1104,6 @@ Ref<ShortCut> InputEventShortCut::get_shortcut() {
return shortcut;
}
void InputEventShortCut::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_shortcut", "shortcut"), &InputEventShortCut::set_shortcut);
ClassDB::bind_method(D_METHOD("get_shortcut"), &InputEventShortCut::get_shortcut);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "shortcut", PROPERTY_HINT_RESOURCE_TYPE, "ShortCut"), "set_shortcut", "get_shortcut");
}
String InputEventShortCut::as_text() const {
ERR_FAIL_COND_V(shortcut.is_null(), "None");

View File

@ -6,9 +6,9 @@
/* From https://github.com/Relintai/pandemonium_engine (MIT) */
/*************************************************************************/
#include "core/math/transform_2d.h"
#include "core/object/resource.h"
#include "core/string/ustring.h"
#include "core/transform_2d.h"
#include "object/resource.h"
#include "core/ustring.h"
#include "core/typedefs.h"
/**
@ -172,7 +172,7 @@ enum MidiMessageList {
*/
class InputEvent : public Resource {
GDCLASS(InputEvent, Resource);
SFW_OBJECT(InputEvent, Resource);
int device;
@ -180,8 +180,6 @@ protected:
bool canceled;
bool pressed;
static void _bind_methods();
public:
static const int DEVICE_ID_TOUCH_MOUSE;
static const int DEVICE_ID_INTERNAL;
@ -214,7 +212,7 @@ public:
};
class InputEventWithModifiers : public InputEvent {
GDCLASS(InputEventWithModifiers, InputEvent);
SFW_OBJECT(InputEventWithModifiers, InputEvent);
bool shift;
bool alt;
@ -234,9 +232,6 @@ class InputEventWithModifiers : public InputEvent {
#endif
protected:
static void _bind_methods();
public:
void set_shift(bool p_enabled);
bool get_shift() const;
@ -261,7 +256,7 @@ public:
};
class InputEventKey : public InputEventWithModifiers {
GDCLASS(InputEventKey, InputEventWithModifiers);
SFW_OBJECT(InputEventKey, InputEventWithModifiers);
uint32_t scancode; ///< check keyboard.h , KeyCode enum, without modifier masks
uint32_t physical_scancode;
@ -271,9 +266,6 @@ class InputEventKey : public InputEventWithModifiers {
bool action_match_force_exact;
protected:
static void _bind_methods();
public:
void set_pressed(bool p_pressed);
@ -306,16 +298,13 @@ public:
};
class InputEventMouse : public InputEventWithModifiers {
GDCLASS(InputEventMouse, InputEventWithModifiers);
SFW_OBJECT(InputEventMouse, InputEventWithModifiers);
int button_mask;
Vector2 pos;
Vector2 global_pos;
protected:
static void _bind_methods();
public:
void set_button_mask(int p_mask);
int get_button_mask() const;
@ -330,15 +319,12 @@ public:
};
class InputEventMouseButton : public InputEventMouse {
GDCLASS(InputEventMouseButton, InputEventMouse);
SFW_OBJECT(InputEventMouseButton, InputEventMouse);
float factor;
int button_index;
bool doubleclick; //last even less than doubleclick time
protected:
static void _bind_methods();
public:
void set_factor(float p_factor);
float get_factor() const;
@ -363,7 +349,7 @@ public:
};
class InputEventMouseMotion : public InputEventMouse {
GDCLASS(InputEventMouseMotion, InputEventMouse);
SFW_OBJECT(InputEventMouseMotion, InputEventMouse);
Vector2 tilt;
float pressure;
@ -371,9 +357,6 @@ class InputEventMouseMotion : public InputEventMouse {
Vector2 speed;
bool pen_inverted;
protected:
static void _bind_methods();
public:
void set_tilt(const Vector2 &p_tilt);
Vector2 get_tilt() const;
@ -399,14 +382,11 @@ public:
};
class InputEventJoypadMotion : public InputEvent {
GDCLASS(InputEventJoypadMotion, InputEvent);
SFW_OBJECT(InputEventJoypadMotion, InputEvent);
int axis; ///< Joypad axis
float axis_value; ///< -1 to 1
protected:
static void _bind_methods();
public:
void set_axis(int p_axis);
int get_axis() const;
@ -424,12 +404,10 @@ public:
};
class InputEventJoypadButton : public InputEvent {
GDCLASS(InputEventJoypadButton, InputEvent);
SFW_OBJECT(InputEventJoypadButton, InputEvent);
int button_index;
float pressure; //0 to 1
protected:
static void _bind_methods();
public:
void set_button_index(int p_index);
@ -450,14 +428,11 @@ public:
};
class InputEventScreenTouch : public InputEvent {
GDCLASS(InputEventScreenTouch, InputEvent);
SFW_OBJECT(InputEventScreenTouch, InputEvent);
int index;
Vector2 pos;
bool double_tap;
protected:
static void _bind_methods();
public:
void set_index(int p_index);
int get_index() const;
@ -478,15 +453,12 @@ public:
};
class InputEventScreenDrag : public InputEvent {
GDCLASS(InputEventScreenDrag, InputEvent);
SFW_OBJECT(InputEventScreenDrag, InputEvent);
int index;
Vector2 pos;
Vector2 relative;
Vector2 speed;
protected:
static void _bind_methods();
public:
void set_index(int p_index);
int get_index() const;
@ -509,14 +481,11 @@ public:
};
class InputEventAction : public InputEvent {
GDCLASS(InputEventAction, InputEvent);
SFW_OBJECT(InputEventAction, InputEvent);
StringName action;
float strength;
protected:
static void _bind_methods();
public:
void set_action(const StringName &p_action);
StringName get_action() const;
@ -538,25 +507,19 @@ public:
};
class InputEventGesture : public InputEventWithModifiers {
GDCLASS(InputEventGesture, InputEventWithModifiers);
SFW_OBJECT(InputEventGesture, InputEventWithModifiers);
Vector2 pos;
protected:
static void _bind_methods();
public:
void set_position(const Vector2 &p_pos);
Vector2 get_position() const;
};
class InputEventMagnifyGesture : public InputEventGesture {
GDCLASS(InputEventMagnifyGesture, InputEventGesture);
SFW_OBJECT(InputEventMagnifyGesture, InputEventGesture);
real_t factor;
protected:
static void _bind_methods();
public:
void set_factor(real_t p_factor);
real_t get_factor() const;
@ -568,12 +531,9 @@ public:
};
class InputEventPanGesture : public InputEventGesture {
GDCLASS(InputEventPanGesture, InputEventGesture);
SFW_OBJECT(InputEventPanGesture, InputEventGesture);
Vector2 delta;
protected:
static void _bind_methods();
public:
void set_delta(const Vector2 &p_delta);
Vector2 get_delta() const;
@ -585,7 +545,7 @@ public:
};
class InputEventMIDI : public InputEvent {
GDCLASS(InputEventMIDI, InputEvent);
SFW_OBJECT(InputEventMIDI, InputEvent);
int channel;
int message;
@ -596,9 +556,6 @@ class InputEventMIDI : public InputEvent {
int controller_number;
int controller_value;
protected:
static void _bind_methods();
public:
void set_channel(const int p_channel);
int get_channel() const;
@ -630,13 +587,10 @@ public:
};
class InputEventShortCut : public InputEvent {
GDCLASS(InputEventShortCut, InputEvent);
SFW_OBJECT(InputEventShortCut, InputEvent);
Ref<ShortCut> shortcut;
protected:
static void _bind_methods();
public:
void set_shortcut(Ref<ShortCut> p_shortcut);
Ref<ShortCut> get_shortcut();

View File

@ -5,31 +5,13 @@
#include "input_map.h"
#include "core/config/project_settings.h"
#include "core/input/input.h"
#include "core/os/keyboard.h"
#include "render_core/input/input.h"
#include "render_core/input/keyboard.h"
InputMap *InputMap::singleton = nullptr;
int InputMap::ALL_DEVICES = -1;
void InputMap::_bind_methods() {
ClassDB::bind_method(D_METHOD("has_action", "action"), &InputMap::has_action);
ClassDB::bind_method(D_METHOD("get_actions"), &InputMap::_get_actions);
ClassDB::bind_method(D_METHOD("add_action", "action", "deadzone"), &InputMap::add_action, DEFVAL(0.5f));
ClassDB::bind_method(D_METHOD("erase_action", "action"), &InputMap::erase_action);
ClassDB::bind_method(D_METHOD("action_set_deadzone", "action", "deadzone"), &InputMap::action_set_deadzone);
ClassDB::bind_method(D_METHOD("action_get_deadzone", "action"), &InputMap::action_get_deadzone);
ClassDB::bind_method(D_METHOD("action_add_event", "action", "event"), &InputMap::action_add_event);
ClassDB::bind_method(D_METHOD("action_has_event", "action", "event"), &InputMap::action_has_event);
ClassDB::bind_method(D_METHOD("action_erase_event", "action", "event"), &InputMap::action_erase_event);
ClassDB::bind_method(D_METHOD("action_erase_events", "action"), &InputMap::action_erase_events);
ClassDB::bind_method(D_METHOD("get_action_list", "action"), &InputMap::_get_action_list);
ClassDB::bind_method(D_METHOD("event_is_action", "event", "action", "exact_match"), &InputMap::event_is_action, DEFVAL(false));
ClassDB::bind_method(D_METHOD("load_from_globals"), &InputMap::load_from_globals);
}
/**
* Returns an nonexistent action error message with a suggestion of the closest
* matching action name (if possible).
@ -236,36 +218,6 @@ const RBMap<StringName, InputMap::Action> &InputMap::get_action_map() const {
return input_map;
}
void InputMap::load_from_globals() {
input_map.clear();
List<PropertyInfo> pinfo;
ProjectSettings::get_singleton()->get_property_list(&pinfo);
for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
const PropertyInfo &pi = E->get();
if (!pi.name.begins_with("input/")) {
continue;
}
String name = pi.name.substr(pi.name.find("/") + 1, pi.name.length());
Dictionary action = ProjectSettings::get_singleton()->get(pi.name);
float deadzone = action.has("deadzone") ? (float)action["deadzone"] : 0.5f;
Array events = action["events"];
add_action(name, deadzone);
for (int i = 0; i < events.size(); i++) {
Ref<InputEvent> event = events[i];
if (event.is_null()) {
continue;
}
action_add_event(name, event);
}
}
}
void InputMap::load_default() {
Ref<InputEventKey> key;

View File

@ -6,11 +6,12 @@
/* From https://github.com/Relintai/pandemonium_engine (MIT) */
/*************************************************************************/
#include "core/input/input_event.h"
#include "core/object/object.h"
#include "render_core/input/input_event.h"
#include "object/object.h"
#include "core/rb_map.h"
class InputMap : public Object {
GDCLASS(InputMap, Object);
SFW_OBJECT(InputMap, Object);
public:
/**
@ -34,9 +35,6 @@ private:
Array _get_action_list(const StringName &p_action);
Array _get_actions();
protected:
static void _bind_methods();
public:
static _FORCE_INLINE_ InputMap *get_singleton() { return singleton; }
@ -57,7 +55,6 @@ public:
bool event_get_action_status(const Ref<InputEvent> &p_event, const StringName &p_action, bool p_exact_match = false, bool *p_pressed = nullptr, float *p_strength = nullptr, float *p_raw_strength = nullptr) const;
const RBMap<StringName, Action> &get_action_map() const;
void load_from_globals();
void load_default();
String suggest_actions(const StringName &p_action) const;

View File

@ -5,7 +5,7 @@
#include "shortcut.h"
#include "core/render_core/input_event.h"
#include "render_core/input/input_event.h"
void ShortCut::set_shortcut(const Ref<InputEvent> &p_shortcut) {
shortcut = p_shortcut;

View File

@ -6,12 +6,12 @@
/* From https://github.com/Relintai/pandemonium_engine (MIT) */
/*************************************************************************/
#include "resource.h"
#include "object/resource.h"
class InputEvent;
class ShortCut : public Resource {
GDCLASS(ShortCut, Resource);
SFW_OBJECT(ShortCut, Resource);
public:
void set_shortcut(const Ref<InputEvent> &p_shortcut);

View File

@ -18,7 +18,7 @@
This class is set apart that it assumes a single surface is always generated for our mesh.
*/
class PrimitiveMesh : public Mesh {
GDCLASS(PrimitiveMesh, Mesh);
SFW_OBJECT(PrimitiveMesh, Mesh);
private:
RID mesh;
@ -74,7 +74,7 @@ public:
Mesh for a simple capsule
*/
class CapsuleMesh : public PrimitiveMesh {
GDCLASS(CapsuleMesh, PrimitiveMesh);
SFW_OBJECT(CapsuleMesh, PrimitiveMesh);
private:
float radius;
@ -108,7 +108,7 @@ public:
Similar to test cube but with subdivision support and different texture coordinates
*/
class CubeMesh : public PrimitiveMesh {
GDCLASS(CubeMesh, PrimitiveMesh);
SFW_OBJECT(CubeMesh, PrimitiveMesh);
private:
Vector3 size;
@ -143,7 +143,7 @@ public:
*/
class CylinderMesh : public PrimitiveMesh {
GDCLASS(CylinderMesh, PrimitiveMesh);
SFW_OBJECT(CylinderMesh, PrimitiveMesh);
private:
float top_radius;
@ -181,7 +181,7 @@ public:
Similar to quadmesh but with tessellation support
*/
class PlaneMesh : public PrimitiveMesh {
GDCLASS(PlaneMesh, PrimitiveMesh);
SFW_OBJECT(PlaneMesh, PrimitiveMesh);
private:
Size2 size;
@ -213,7 +213,7 @@ public:
A prism shapen, handy for ramps, triangles, etc.
*/
class PrismMesh : public PrimitiveMesh {
GDCLASS(PrismMesh, PrimitiveMesh);
SFW_OBJECT(PrismMesh, PrimitiveMesh);
private:
float left_to_right;
@ -250,7 +250,7 @@ public:
*/
class QuadMesh : public PrimitiveMesh {
GDCLASS(QuadMesh, PrimitiveMesh);
SFW_OBJECT(QuadMesh, PrimitiveMesh);
private:
Size2 size;
@ -274,7 +274,7 @@ public:
A sphere..
*/
class SphereMesh : public PrimitiveMesh {
GDCLASS(SphereMesh, PrimitiveMesh);
SFW_OBJECT(SphereMesh, PrimitiveMesh);
private:
float radius;
@ -313,7 +313,7 @@ public:
*/
class PointMesh : public PrimitiveMesh {
GDCLASS(PointMesh, PrimitiveMesh)
SFW_OBJECT(PointMesh, PrimitiveMesh)
protected:
virtual void _create_mesh_array(Array &p_arr) const;
@ -327,7 +327,7 @@ public:
*/
class TextMesh : public PrimitiveMesh {
GDCLASS(TextMesh, PrimitiveMesh);
SFW_OBJECT(TextMesh, PrimitiveMesh);
public:
enum Align {

View File

@ -1,5 +1,14 @@
#include "render_core/scene.h"
#include "render_core/input/input_event.h"
void Scene::input_event(const Ref<InputEvent> &event) {
}
void Scene::update(float delta) {
}
void Scene::render() {
}
Scene::Scene() {
}

View File

@ -1,14 +1,20 @@
#ifndef SCENE_H
#define SCENE_H
class Scene {
public:
virtual void event() = 0;
virtual void update(float delta) = 0;
virtual void render() = 0;
#include "object/reference.h"
Scene();
virtual ~Scene();
class InputEvent;
class Scene : Reference {
SFW_OBJECT(Scene, Reference);
public:
virtual void input_event(const Ref<InputEvent> &event);
virtual void update(float delta);
virtual void render();
Scene();
virtual ~Scene();
};
#endif // APPLICATION_H

View File

@ -65,18 +65,25 @@ public:
void set_focus(); // window attribute using haz catz language for now
int has_focus();
void set_fullscreen(int enabled);
int has_fullscreen();
void set_cursor(int visible);
int has_cursor();
void set_pause(int paused);
int has_pause();
void set_visible(int visible);
int has_visible();
void set_maximize(int enabled);
int has_maximize();
void set_transparent(int enabled);
int has_transparent();
void set_icon(const char *file_icon);
int has_icon();