summaryrefslogtreecommitdiff
path: root/main/input_default.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'main/input_default.cpp')
-rw-r--r--main/input_default.cpp87
1 files changed, 69 insertions, 18 deletions
diff --git a/main/input_default.cpp b/main/input_default.cpp
index f93a142c54..ea08bfc2ef 100644
--- a/main/input_default.cpp
+++ b/main/input_default.cpp
@@ -71,13 +71,13 @@ InputDefault::SpeedTrack::SpeedTrack() {
reset();
}
-bool InputDefault::is_key_pressed(int p_scancode) {
+bool InputDefault::is_key_pressed(int p_scancode) const {
_THREAD_SAFE_METHOD_
return keys_pressed.has(p_scancode);
}
-bool InputDefault::is_mouse_button_pressed(int p_button) {
+bool InputDefault::is_mouse_button_pressed(int p_button) const {
_THREAD_SAFE_METHOD_
return (mouse_button_mask&(1<<p_button))!=0;
@@ -89,14 +89,16 @@ 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) {
+bool InputDefault::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 InputDefault::is_action_pressed(const StringName& p_action) const{
+ return action_state.has(p_action) && action_state[p_action].pressed;
+#if 0
if (custom_action_press.has(p_action))
return true; //simpler
@@ -147,9 +149,37 @@ bool InputDefault::is_action_pressed(const StringName& p_action) {
}
return false;
+#endif
}
-float InputDefault::get_joy_axis(int p_device,int p_axis) {
+bool InputDefault::is_action_just_pressed(const StringName& p_action) const {
+
+ const Map<StringName,Action>::Element *E=action_state.find(p_action);
+ if (!E)
+ return false;
+
+ if (OS::get_singleton()->is_in_fixed_frame()) {
+ return E->get().pressed && E->get().fixed_frame==OS::get_singleton()->get_fixed_frames();
+ } else {
+ return E->get().pressed && E->get().idle_frame==OS::get_singleton()->get_idle_frames();
+ }
+}
+
+bool InputDefault::is_action_just_released(const StringName& p_action) const{
+
+ const Map<StringName,Action>::Element *E=action_state.find(p_action);
+ if (!E)
+ return false;
+
+ if (OS::get_singleton()->is_in_fixed_frame()) {
+ return !E->get().pressed && E->get().fixed_frame==OS::get_singleton()->get_fixed_frames();
+ } else {
+ return !E->get().pressed && E->get().idle_frame==OS::get_singleton()->get_idle_frames();
+ }
+}
+
+
+float InputDefault::get_joy_axis(int p_device,int p_axis) const{
_THREAD_SAFE_METHOD_
int c = _combine_device(p_axis,p_device);
@@ -247,19 +277,19 @@ void InputDefault::joy_connection_changed(int p_idx, bool p_connected, String p_
emit_signal("joy_connection_changed", p_idx, p_connected);
};
-Vector3 InputDefault::get_accelerometer() {
+Vector3 InputDefault::get_accelerometer() const{
_THREAD_SAFE_METHOD_
return accelerometer;
}
-Vector3 InputDefault::get_magnetometer() {
+Vector3 InputDefault::get_magnetometer() const{
_THREAD_SAFE_METHOD_
return magnetometer;
}
-Vector3 InputDefault::get_gyroscope() {
+Vector3 InputDefault::get_gyroscope() const {
_THREAD_SAFE_METHOD_
return gyroscope;
@@ -341,6 +371,23 @@ void InputDefault::parse_input_event(const InputEvent& p_event) {
}
+
+ if (!p_event.is_echo()) {
+ for (const Map<StringName,InputMap::Action>::Element *E=InputMap::get_singleton()->get_action_map().front();E;E=E->next()) {
+
+ if (InputMap::get_singleton()->event_is_action(p_event,E->key())) {
+
+ Action action;
+ action.fixed_frame=OS::get_singleton()->get_fixed_frames();
+ action.idle_frame=OS::get_singleton()->get_idle_frames();
+ action.pressed=p_event.is_pressed();
+
+ action_state[E->key()]=action;
+
+ }
+ }
+ }
+
if (main_loop)
main_loop->input_event(p_event);
@@ -441,21 +488,25 @@ void InputDefault::iteration(float p_step) {
void InputDefault::action_press(const StringName& p_action) {
- if (custom_action_press.has(p_action)) {
+ Action action;
+
+ action.fixed_frame=OS::get_singleton()->get_fixed_frames();
+ action.idle_frame=OS::get_singleton()->get_idle_frames();
+ action.pressed=true;
+
+ action_state[p_action]=action;
- custom_action_press[p_action]++;
- } else {
- custom_action_press[p_action]=1;
- }
}
void InputDefault::action_release(const StringName& p_action){
- ERR_FAIL_COND(!custom_action_press.has(p_action));
- custom_action_press[p_action]--;
- if (custom_action_press[p_action]==0) {
- custom_action_press.erase(p_action);
- }
+ Action action;
+
+ action.fixed_frame=OS::get_singleton()->get_fixed_frames();
+ action.idle_frame=OS::get_singleton()->get_idle_frames();
+ action.pressed=true;
+
+ action_state[p_action]=action;
}
void InputDefault::set_emulate_touch(bool p_emulate) {