From 122caf547e4d37b132bccb4248e8958f5fe50891 Mon Sep 17 00:00:00 2001 From: Aaron M Date: Sat, 9 Nov 2019 07:17:51 +1300 Subject: [PATCH] Remove WaitEvent from HOTD4 --- Game Files/HOTD4.cpp | 97 ++++++++++++++++++++++---------------------- 1 file changed, 49 insertions(+), 48 deletions(-) diff --git a/Game Files/HOTD4.cpp b/Game Files/HOTD4.cpp index f2c4637..2b6bde8 100644 --- a/Game Files/HOTD4.cpp +++ b/Game Files/HOTD4.cpp @@ -27,6 +27,7 @@ static Helpers *myHelpers; extern HINSTANCE gl_cgGLDll; static bool HealthA = false; static bool HealthB = false; +static bool init = false; SDL_Event e; static int RunningThread(void *ptr) @@ -274,59 +275,59 @@ static int RunningThread(void *ptr) void HOTD4::FFBLoop(EffectConstants *constants, Helpers *helpers, EffectTriggers* triggers) { - SDL_Thread *thread; - thread = SDL_CreateThread(RunningThread, "RunningThread", (void *)NULL); - - for (int i = 0; i < SDL_NumJoysticks(); i++) - { - wchar_t* deviceGUIDString2 = new wchar_t[256]; - int Device2GUID = GetPrivateProfileString(TEXT("Settings"), TEXT("Device2GUID"), NULL, deviceGUIDString2, 256, settingsFilename); - char joystick_guid[256]; - sprintf(joystick_guid, "%S", deviceGUIDString2); - SDL_JoystickGUID guid, dev_guid; - int numJoysticks = SDL_NumJoysticks(); - std::string njs = std::to_string(numJoysticks); - ((char)njs.c_str()); - for (int i = 0; i < SDL_NumJoysticks(); i++) - { - extern int joystick1Index; - if (i == joystick1Index) - { - continue; - } - SDL_Joystick* js2 = SDL_JoystickOpen(i); - joystick_index2 = SDL_JoystickInstanceID(js2); - SDL_JoystickGUID guid = SDL_JoystickGetGUID(js2); - char guid_str[1024]; - SDL_JoystickGetGUIDString(guid, guid_str, sizeof(guid_str)); - const char* name = SDL_JoystickName(js2); - char text[256]; - sprintf(text, "Joystick: %d / Name: %s / GUID: %s\n", i, name, guid_str); - guid = SDL_JoystickGetGUIDFromString(joystick_guid); - dev_guid = SDL_JoystickGetGUID(js2); - if (!memcmp(&guid, &dev_guid, sizeof(SDL_JoystickGUID))) - { - GameController2 = SDL_JoystickOpen(i); - ControllerHaptic2 = SDL_HapticOpenFromJoystick(GameController2); - break; - } - SDL_JoystickClose(js2); - } - haptic2 = ControllerHaptic2; - if ((SDL_HapticRumbleSupported(haptic2) == SDL_TRUE)) - { - SDL_HapticRumbleInit; - SDL_HapticRumbleInit(ControllerHaptic2); - } - } - - while (SDL_WaitEvent(&e) != 0) + if (!init) { myTriggers = triggers; myConstants = constants; myHelpers = helpers; - } + SDL_Thread* thread; + thread = SDL_CreateThread(RunningThread, "RunningThread", (void*)NULL); + for (int i = 0; i < SDL_NumJoysticks(); i++) + { + wchar_t* deviceGUIDString2 = new wchar_t[256]; + int Device2GUID = GetPrivateProfileString(TEXT("Settings"), TEXT("Device2GUID"), NULL, deviceGUIDString2, 256, settingsFilename); + char joystick_guid[256]; + sprintf(joystick_guid, "%S", deviceGUIDString2); + SDL_JoystickGUID guid, dev_guid; + int numJoysticks = SDL_NumJoysticks(); + std::string njs = std::to_string(numJoysticks); + ((char)njs.c_str()); + for (int i = 0; i < SDL_NumJoysticks(); i++) + { + extern int joystick1Index; + if (i == joystick1Index) + { + continue; + } + SDL_Joystick* js2 = SDL_JoystickOpen(i); + joystick_index2 = SDL_JoystickInstanceID(js2); + SDL_JoystickGUID guid = SDL_JoystickGetGUID(js2); + char guid_str[1024]; + SDL_JoystickGetGUIDString(guid, guid_str, sizeof(guid_str)); + const char* name = SDL_JoystickName(js2); + char text[256]; + sprintf(text, "Joystick: %d / Name: %s / GUID: %s\n", i, name, guid_str); + guid = SDL_JoystickGetGUIDFromString(joystick_guid); + dev_guid = SDL_JoystickGetGUID(js2); + if (!memcmp(&guid, &dev_guid, sizeof(SDL_JoystickGUID))) + { + GameController2 = SDL_JoystickOpen(i); + ControllerHaptic2 = SDL_HapticOpenFromJoystick(GameController2); + break; + } + SDL_JoystickClose(js2); + } + haptic2 = ControllerHaptic2; + if ((SDL_HapticRumbleSupported(haptic2) == SDL_TRUE)) + { + SDL_HapticRumbleInit; + SDL_HapticRumbleInit(ControllerHaptic2); + } + } + init = true; + } + myTriggers = triggers; myConstants = constants; myHelpers = helpers;