can use fallback mapping on all platforms

This commit is contained in:
hondres 2016-01-24 18:01:37 +01:00
parent e7c920fdba
commit 285bcac224
3 changed files with 20 additions and 17 deletions

View file

@ -157,19 +157,13 @@ void InputDefault::joy_connection_changed(int p_idx, bool p_connected, String p_
}; };
js.uid = uidname; js.uid = uidname;
//printf("looking for mappings for guid %ls\n", uidname.c_str()); //printf("looking for mappings for guid %ls\n", uidname.c_str());
int mapping = -1; int mapping = fallback_mapping;
for (int i=0; i < map_db.size(); i++) { for (int i=0; i < map_db.size(); i++) {
if (js.uid == map_db[i].uid) { if (js.uid == map_db[i].uid) {
mapping = i; mapping = i;
//printf("found mapping\n"); //printf("found mapping\n");
}; };
}; };
#ifdef ANDROID_ENABLED
//Use a default mapping for Android, as we recieve events using indices of a SDL_GAMECONTROLLER.
//So we need to map those to our own joystick layout
if (mapping == -1)
mapping = 0;
#endif
js.mapping = mapping; js.mapping = mapping;
}; };
joy_names[p_idx] = js; joy_names[p_idx] = js;
@ -519,10 +513,8 @@ InputDefault::InputDefault() {
hat_map_default[HAT_LEFT].index = JOY_DPAD_LEFT; hat_map_default[HAT_LEFT].index = JOY_DPAD_LEFT;
hat_map_default[HAT_LEFT].value = 0; hat_map_default[HAT_LEFT].value = 0;
#ifdef ANDROID_ENABLED fallback_mapping = -1;
//add the default mapping first, in case someone actually sets the env variable on their phone
parse_mapping("Default Android Gamepad,Default Controller,leftx:a0,lefty:a1,dpdown:h0.4,rightstick:b8,rightshoulder:b10,rightx:a2,start:b6,righty:a3,dpleft:h0.8,lefttrigger:a4,x:b2,dpup:h0.1,back:b4,leftstick:b7,leftshoulder:b9,y:b3,a:b0,dpright:h0.2,righttrigger:a5,b:b1,");
#endif
String env_mapping = OS::get_singleton()->get_environment("SDL_GAMECONTROLLERCONFIG"); String env_mapping = OS::get_singleton()->get_environment("SDL_GAMECONTROLLERCONFIG");
if (env_mapping != "") { if (env_mapping != "") {
@ -875,10 +867,8 @@ String InputDefault::get_joy_guid(int p_device) const {
//platforms that use the remapping system can override and call to these ones //platforms that use the remapping system can override and call to these ones
bool InputDefault::is_joy_mapped(int p_device) { bool InputDefault::is_joy_mapped(int p_device) {
#ifdef ANDROID_ENABLED if (joy_names[p_device].mapping == fallback_mapping)
if (joy_names[p_device].mapping == 0)
return false; return false;
#endif
return joy_names[p_device].mapping != -1 ? true : false; return joy_names[p_device].mapping != -1 ? true : false;
} }
@ -886,3 +876,16 @@ String InputDefault::get_joy_guid_remapped(int p_device) const {
return joy_names[p_device].uid; return joy_names[p_device].uid;
} }
void InputDefault::set_fallback_mapping(String p_mapping) {
int prev_fallback = fallback_mapping;
parse_mapping(p_mapping);
fallback_mapping = map_db.size() -1;
for (int i = 0; i < joy_names.size(); i++) {
if (joy_names[i].mapping == prev_fallback) {
joy_names[i].mapping = fallback_mapping;
}
}
}

View file

@ -18,7 +18,6 @@ class InputDefault : public Input {
MainLoop *main_loop; MainLoop *main_loop;
bool emulate_touch; bool emulate_touch;
struct SpeedTrack { struct SpeedTrack {
uint64_t last_tick; uint64_t last_tick;
@ -62,6 +61,7 @@ class InputDefault : public Input {
SpeedTrack mouse_speed_track; SpeedTrack mouse_speed_track;
Map<int, Joystick> joy_names; Map<int, Joystick> joy_names;
int fallback_mapping;
RES custom_cursor; RES custom_cursor;
public: public:
enum HatMask { enum HatMask {
@ -169,7 +169,7 @@ public:
bool is_joy_mapped(int p_device); bool is_joy_mapped(int p_device);
String get_joy_guid_remapped(int p_device) const; String get_joy_guid_remapped(int p_device) const;
void set_fallback_mapping(String p_mapping);
InputDefault(); InputDefault();
}; };

View file

@ -178,7 +178,7 @@ void OS_Android::initialize(const VideoMode& p_desired,int p_video_driver,int p_
physics_2d_server->init(); physics_2d_server->init();
input = memnew( InputDefault ); input = memnew( InputDefault );
input->set_fallback_mapping("Default Android Gamepad,Default Controller,leftx:a0,lefty:a1,dpdown:h0.4,rightstick:b8,rightshoulder:b10,rightx:a2,start:b6,righty:a3,dpleft:h0.8,lefttrigger:a4,x:b2,dpup:h0.1,back:b4,leftstick:b7,leftshoulder:b9,y:b3,a:b0,dpright:h0.2,righttrigger:a5,b:b1,");
} }
void OS_Android::set_main_loop( MainLoop * p_main_loop ) { void OS_Android::set_main_loop( MainLoop * p_main_loop ) {