X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fgui%2Fprofile.cpp;h=71e694666f1567bab13d0fefb61a95b24b2ec5d5;hb=d1e404e2f488610a99f844783dca15a7525c3813;hp=05d173d84407f716eda3c4adf6a29bf7dc5f5ced;hpb=69effddb777c2009d32f70e3315d5570973446ef;p=virtualjaguar diff --git a/src/gui/profile.cpp b/src/gui/profile.cpp index 05d173d..71e6946 100644 --- a/src/gui/profile.cpp +++ b/src/gui/profile.cpp @@ -15,6 +15,7 @@ #include "profile.h" #include #include "gamepad.h" +#include "log.h" #include "settings.h" @@ -36,6 +37,10 @@ uint32_t defaultMap[21] = { '3', 'L', 'K', 'J', 'O', 'P' }; +// Function Prototypes +int ConnectProfileToDevice(int deviceNum); +int FindProfileForDevice(int deviceNum, int preferred, int * found); + void ReadProfiles(QSettings * set) { @@ -131,6 +136,37 @@ void WriteProfiles(QSettings * set) } +int GetFreeProfile(void) +{ + // Check for too many, return -1 if so + if (numberOfProfiles == MAX_PROFILES) + return -1; + + int profileNum = numberOfProfiles; + numberOfProfiles++; + return profileNum; +} + + +void DeleteProfile(int profileToDelete) +{ + // Sanity check + if (profileToDelete >= numberOfProfiles) + return; + + // Trivial case: Profile at end of the array + if (profileToDelete == (numberOfProfiles - 1)) + { + numberOfProfiles--; + return; + } + +// memmove(dest, src, bytesToMove); + memmove(&profile[profileToDelete], &profile[profileToDelete + 1], ((numberOfProfiles - 1) - profileToDelete) * sizeof(Profile)); + numberOfProfiles--; +} + + int FindDeviceNumberForName(const char * name) { for(int i=0; iaddItem(QString("Keyboard::%1").arg(profile[j].mapName), j); + found++; + } + } + + // Check for connected host devices next + for(int i=0; iaddItem(QString("%1::%2").arg(Gamepad::GetJoystickName(i)).arg(profile[j].mapName), j); + found++; + } + } + } + + return found; +} + + bool ConnectProfileToController(int profileNum, int controllerNum) { if (profile[profileNum].device == -1) @@ -200,7 +271,7 @@ bool ConnectProfileToController(int profileNum, int controllerNum) for(int i=0; i<21; i++) dest[i] = profile[profileNum].map[i]; -printf("Successfully mapped device '%s' (%s) to controller #%u...\n", deviceNames[profile[profileNum].device], profile[profileNum].mapName, controllerNum); + WriteLog("PROFILE: Successfully mapped device '%s' (%s) to controller #%u...\n", deviceNames[profile[profileNum].device], profile[profileNum].mapName, controllerNum); return true; } @@ -215,6 +286,13 @@ printf("Successfully mapped device '%s' (%s) to controller #%u...\n", deviceName // should be ATM... :-P // /* +Here's the rules: If preferred Jaguar controller is not checked, the profile is +skipped. If one or the other is checked, it's put into that slot. If *both* are +checked, it will take over any slot that isn't claimed by another gamepad. If +there are ties, present it to the user *once* and ask them which gamepad should +be #1; don't ask again unless a), they change the profiles and b), the +situation warrants it. + Also, there is a problem with this approach and having multiple devices that are the same. Currently, if two of the same device are plugged in and the profile is set to both controllers, it will broadcast buttons @@ -234,51 +312,94 @@ different, but we still run into problems with the handling in the MainWin because it's hardwired to take pad 0 in slot 0 and pad 1 in slot 1. If you have them configured other than this, you won't get anything. So we need to also map the physical devices to their respective slots. + + +Steps: + +1) Make a list of all devices attached to the system. + +2) Make a list of all profiles belonging to those devices, as long as they have + one or more Jaguar controllers that are "mapped to". + +3) See if there are any conflicts. If there are, see if the user has already + been asked to resolve and chosen a resolution; otherwise, ask the user to + resolve. + + a) Loop through all found profiles. If they are set to a single controller, + set it in the appropriate list (one list for controller 1, another for + controller 2). + + b) Loop through all found profiles. If they are set to both controllers, + ... (first stab at it:) + Check for list #1. If nothing there, assign it to list #1. + Else, check for List #2. If nothing there, assign to list #2. + [But the wording of it implies that it will assign it to both. + Does that mean we should make another combobox will all the possible + combinations laid out? Probably. Not many people will understand that + checking both means "assign to either one that's free".] + +4) Connect profiles to controllers, and set gamepad slots (for the MainWin + handler). + */ void AutoConnectProfiles(void) { + int foundProfiles[MAX_PROFILES]; int controller1Profile = -1; int controller2Profile = -1; - // Nothing plugged in, we fall back to the default keyboard device profiles -// if (Gamepad::numJoysticks == 0) + // Check for Keyboard device profiles first, if anything else is plugged in + // it will default to it instead. +#if 0 + for(int i=0; i