From 7ddbc13bc5260e533b9967fd301926a1725b933f Mon Sep 17 00:00:00 2001 From: Ed_ Date: Sat, 9 Sep 2023 23:58:28 -0400 Subject: [PATCH] Some more dualsense shenanigans --- .vscode/settings.json | 3 +- project/handmade_win32.cpp | 68 +++++++++++++++++++++++++++++++++----- project/platform/macros.h | 24 ++++++++++++++ project/platform/win32.h | 4 +-- 4 files changed, 88 insertions(+), 11 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 5469204..b892a69 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -29,7 +29,8 @@ "vector": "cpp", "list": "cpp", "xhash": "cpp", - // "*.md.html":"markdown" + "shared_mutex": "cpp", + "mutex": "cpp" }, "C_Cpp.intelliSenseEngineFallback": "disabled", "C_Cpp.errorSquiggles": "disabled", // This doesn't work well with how the headers are included. diff --git a/project/handmade_win32.cpp b/project/handmade_win32.cpp index 8e0aa01..0fd763e 100644 --- a/project/handmade_win32.cpp +++ b/project/handmade_win32.cpp @@ -19,6 +19,20 @@ // Using this to get dualsense controllers #include "JoyShockLibrary/JoyShockLibrary.h" +#define congrats( message ) do { \ + JslSetLightColour( 0, (255 << 16) | (215 << 8) ); \ + JslSetRumble( 0, 0, 255 ); \ + MessageBoxA( 0, message, "Congratulations!", MB_OK | MB_ICONEXCLAMATION ); \ + JslSetLightColour( 0, (255 << 8 ) ); \ +} while (0) + +#define fatal(message) do { \ + JslSetLightColour( 0, (255 << 16) ); \ + JslSetRumble( 0, 0, 255 ); \ + MessageBoxA( 0, message, "Fatal Error", MB_OK | MB_ICONERROR ); \ + JslSetLightColour( 0, (255 << 8 ) ); \ +} while (0) + NS_WIN32_BEGIN @@ -317,6 +331,18 @@ WinMain( OutputDebugStringA( "Error: JSLGetConnectedDeviceHandles didn't find as many as were stated with JslConnectDevices\n"); } + if ( jsl_num_devices > 0 ) + { + OutputDebugStringA( "JSL Connected Devices:\n" ); + for ( u32 jsl_device_index = 0; jsl_device_index < jsl_num_devices; ++ jsl_device_index ) + { + JslSetLightColour( device_handles[ jsl_device_index ], (255 << 8) ); + do_once_start + congrats( "GOT THE CONTROLLER BOIS" ); + do_once_end + } + } + // MessageBox( 0, L"First message!", L"Handmade Hero", MB_Ok_Btn | MB_Icon_Information ); WNDCLASS window_class {}; @@ -356,6 +382,8 @@ WinMain( u32 x_offset = 0; u32 y_offset = 0; + bool xinput_detected = false; + // Controller State u8 dpad_up = false; u8 dpad_down = false; @@ -385,7 +413,7 @@ WinMain( } TranslateMessage( & msg_info ); - DispatchMessage( & msg_info ); + DispatchMessageW( & msg_info ); } // XInput Polling @@ -393,7 +421,8 @@ WinMain( for ( DWORD controller_index = 0; controller_index < XUSER_MAX_COUNT; ++ controller_index ) { XINPUT_STATE controller_state; - if ( xinput_get_state( controller_index, & controller_state ) == XI_PluggedIn ) + xinput_detected = xinput_get_state( controller_index, & controller_state ) == XI_PluggedIn; + if ( xinput_detected ) { XINPUT_GAMEPAD* pad = & controller_state.Gamepad; @@ -454,15 +483,29 @@ WinMain( if ( start ) { - XINPUT_VIBRATION vibration; - vibration.wLeftMotorSpeed = 30000; - xinput_set_state( 0, & vibration ); + if ( xinput_detected ) + { + XINPUT_VIBRATION vibration; + vibration.wLeftMotorSpeed = 30000; + xinput_set_state( 0, & vibration ); + } + else + { + JslSetRumble( 0, 1, 0 ); + } } else { - XINPUT_VIBRATION vibration; - vibration.wLeftMotorSpeed = 0; - xinput_set_state( 0, & vibration ); + if ( xinput_detected ) + { + XINPUT_VIBRATION vibration; + vibration.wLeftMotorSpeed = 0; + xinput_set_state( 0, & vibration ); + } + else + { + JslSetRumble( 0, 0, 0 ); + } } render_weird_graident( &BackBuffer, x_offset, y_offset ); @@ -484,5 +527,14 @@ WinMain( // TODO(Ed) : Logging } + if ( jsl_num_devices > 0 ) + { + OutputDebugStringA( "JSL Connected Devices:\n" ); + for ( u32 jsl_device_index = 0; jsl_device_index < jsl_num_devices; ++ jsl_device_index ) + { + JslSetLightColour( device_handles[ jsl_device_index ], 0 ); + } + } + return 0; } diff --git a/project/platform/macros.h b/project/platform/macros.h index 65c363f..7669ce4 100644 --- a/project/platform/macros.h +++ b/project/platform/macros.h @@ -14,3 +14,27 @@ #define pcast( Type, Value ) ( * reinterpret_cast< Type* >( & ( Value ) ) ) #define rcast( Type, Value ) reinterpret_cast< Type >( Value ) #define scast( Type, Value ) static_cast< Type >( Value ) + +#define do_once() \ + do \ + { \ + static \ + bool Done = false; \ + if ( Done ) \ + return; \ + Done = true; \ + } \ + while(0) + +#define do_once_start \ + do \ + { \ + static \ + bool Done = false; \ + if ( Done ) \ + break; \ + Done = true; + +#define do_once_end \ + } \ + while(0); \ No newline at end of file diff --git a/project/platform/win32.h b/project/platform/win32.h index a408443..3abafab 100644 --- a/project/platform/win32.h +++ b/project/platform/win32.h @@ -115,12 +115,12 @@ WIN_LIB_API DWORD WINAPI XInputSetState DWORD WINAPI xinput_get_state_stub( DWORD dwUserIndex, XINPUT_STATE* pVibration ) { OutputDebugStringA( "xinput_get_state stubbed!\n"); - return 0; + return ERROR_CALL_NOT_IMPLEMENTED; } DWORD WINAPI xinput_set_state_stub( DWORD dwUserIndex, XINPUT_VIBRATION* pVibration ) { OutputDebugStringA( "xinput_set_state stubbed!\n"); - return 0; + return ERROR_CALL_NOT_IMPLEMENTED; } using XInputGetStateFn = DWORD WINAPI( DWORD dwUserIndex, XINPUT_STATE* pVibration );