Skip to content

Commit fe7e3e3

Browse files
authored
Merge pull request #8 into Untitled-Psych-Fork/lime-UPF/8.1.2
add controller rumble support openfl#1739 add amazon android device support Goose-Git/lime@e9433f9 implement openfl#1965 fixes GitHub actions as somethings broke a39b0a2 87d0967
2 parents 1c8ecd3 + cc77c83 commit fe7e3e3

File tree

14 files changed

+589
-94
lines changed

14 files changed

+589
-94
lines changed

.github/workflows/main.yml

Lines changed: 56 additions & 49 deletions
Large diffs are not rendered by default.

ndll/windows64/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

project/include/ui/Gamepad.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ namespace lime {
1212
static void AddMapping (const char* content);
1313
static const char* GetDeviceGUID (int id);
1414
static const char* GetDeviceName (int id);
15+
static void Rumble (int id, double lowFrequencyRumble, double highFrequencyRumble, int duration);
1516

1617
};
1718

project/src/ExternalInterface.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1678,6 +1678,20 @@ namespace lime {
16781678
}
16791679

16801680

1681+
void lime_gamepad_rumble (int id, double lowFrequencyRumble, double highFrequencyRumble, int duration) {
1682+
1683+
Gamepad::Rumble (id, lowFrequencyRumble, highFrequencyRumble, duration);
1684+
1685+
}
1686+
1687+
1688+
HL_PRIM void HL_NAME(hl_gamepad_rumble) (int id, double lowFrequencyRumble, double highFrequencyRumble, int duration) {
1689+
1690+
Gamepad::Rumble (id, lowFrequencyRumble, highFrequencyRumble, duration);
1691+
1692+
}
1693+
1694+
16811695
value lime_gzip_compress (value buffer, value bytes) {
16821696

16831697
#ifdef LIME_ZLIB
@@ -3970,6 +3984,7 @@ namespace lime {
39703984
DEFINE_PRIME2v (lime_gamepad_event_manager_register);
39713985
DEFINE_PRIME1 (lime_gamepad_get_device_guid);
39723986
DEFINE_PRIME1 (lime_gamepad_get_device_name);
3987+
DEFINE_PRIME4v (lime_gamepad_rumble);
39733988
DEFINE_PRIME2 (lime_gzip_compress);
39743989
DEFINE_PRIME2 (lime_gzip_decompress);
39753990
DEFINE_PRIME2v (lime_haptic_vibrate);
@@ -4159,6 +4174,7 @@ namespace lime {
41594174
DEFINE_HL_PRIM (_VOID, hl_gamepad_event_manager_register, _FUN(_VOID, _NO_ARG) _TGAMEPAD_EVENT);
41604175
DEFINE_HL_PRIM (_BYTES, hl_gamepad_get_device_guid, _I32);
41614176
DEFINE_HL_PRIM (_BYTES, hl_gamepad_get_device_name, _I32);
4177+
DEFINE_HL_PRIM (_VOID, hl_gamepad_rumble, _I32 _I32 _F64 _F64);
41624178
DEFINE_HL_PRIM (_TBYTES, hl_gzip_compress, _TBYTES _TBYTES);
41634179
DEFINE_HL_PRIM (_TBYTES, hl_gzip_decompress, _TBYTES _TBYTES);
41644180
DEFINE_HL_PRIM (_VOID, hl_haptic_vibrate, _I32 _I32);

project/src/backend/sdl/SDLGamepad.cpp

Lines changed: 53 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,48 +4,40 @@
44
namespace lime {
55

66

7-
std::map<int, SDL_GameController*> gameControllers = std::map<int, SDL_GameController*> ();
8-
std::map<int, int> gameControllerIDs = std::map<int, int> ();
7+
std::map<int, SDL_GameController*> gameControllers;
8+
std::map<int, int> gameControllerIDs;
99

1010

1111
bool SDLGamepad::Connect (int deviceID) {
1212

13-
if (SDL_IsGameController (deviceID)) {
13+
if (!SDL_IsGameController (deviceID))
14+
return false;
1415

15-
SDL_GameController *gameController = SDL_GameControllerOpen (deviceID);
16+
SDL_GameController *gameController = SDL_GameControllerOpen (deviceID);
17+
if (gameController == nullptr)
18+
return false;
1619

17-
if (gameController) {
20+
SDL_Joystick *joystick = SDL_GameControllerGetJoystick (gameController);
21+
int id = SDL_JoystickInstanceID (joystick);
1822

19-
SDL_Joystick *joystick = SDL_GameControllerGetJoystick (gameController);
20-
int id = SDL_JoystickInstanceID (joystick);
23+
gameControllers[id] = gameController;
24+
gameControllerIDs[deviceID] = id;
2125

22-
gameControllers[id] = gameController;
23-
gameControllerIDs[deviceID] = id;
24-
25-
return true;
26-
27-
}
28-
29-
}
30-
31-
return false;
26+
return true;
3227

3328
}
3429

3530

3631
bool SDLGamepad::Disconnect (int id) {
3732

38-
if (gameControllers.find (id) != gameControllers.end ()) {
33+
auto it = gameControllers.find (id);
34+
if (it == gameControllers.end ())
35+
return false;
3936

40-
SDL_GameController *gameController = gameControllers[id];
41-
SDL_GameControllerClose (gameController);
42-
gameControllers.erase (id);
37+
SDL_GameControllerClose (it->second);
38+
gameControllers.erase (id);
4339

44-
return true;
45-
46-
}
47-
48-
return false;
40+
return true;
4941

5042
}
5143

@@ -66,26 +58,51 @@ namespace lime {
6658

6759
const char* Gamepad::GetDeviceGUID (int id) {
6860

69-
SDL_Joystick* joystick = SDL_GameControllerGetJoystick (gameControllers[id]);
61+
auto it = gameControllers.find (id);
62+
if (it == gameControllers.end ())
63+
return nullptr;
7064

71-
if (joystick) {
65+
SDL_Joystick* joystick = SDL_GameControllerGetJoystick (it->second);
66+
if (joystick == nullptr)
67+
return nullptr;
7268

73-
char* guid = new char[64];
74-
SDL_JoystickGetGUIDString (SDL_JoystickGetGUID (joystick), guid, 64);
75-
return guid;
69+
char* guid = new char[64];
70+
SDL_JoystickGetGUIDString (SDL_JoystickGetGUID (joystick), guid, 64);
71+
return guid;
7672

77-
}
73+
}
7874

79-
return 0;
75+
76+
const char* Gamepad::GetDeviceName (int id) {
77+
78+
auto it = gameControllers.find (id);
79+
if (it == gameControllers.end ())
80+
return nullptr;
81+
82+
return SDL_GameControllerName (it->second);
8083

8184
}
8285

8386

84-
const char* Gamepad::GetDeviceName (int id) {
87+
void Gamepad::Rumble (int id, double lowFrequencyRumble, double highFrequencyRumble, int duration) {
88+
89+
auto it = gameControllers.find (id);
90+
if (it == gameControllers.end ())
91+
return;
92+
93+
if (highFrequencyRumble < 0.0f)
94+
highFrequencyRumble = 0.0f;
95+
else if (highFrequencyRumble > 1.0f)
96+
highFrequencyRumble = 1.0f;
97+
98+
if (lowFrequencyRumble < 0.0f)
99+
lowFrequencyRumble = 0.0f;
100+
else if (lowFrequencyRumble > 1.0f)
101+
lowFrequencyRumble = 1.0f;
85102

86-
return SDL_GameControllerName (gameControllers[id]);
103+
SDL_GameControllerRumble (it->second, lowFrequencyRumble * 0xFFFF, highFrequencyRumble * 0xFFFF, duration);
87104

88105
}
89106

90107

91-
}
108+
}

project/src/media/openal/OpenALBindings.cpp

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3504,6 +3504,101 @@ namespace lime {
35043504

35053505
}
35063506

3507+
value lime_alc_capture_open_device (HxString devicename, int frequency, int format, int buffersize) {
3508+
3509+
ALCdevice* alcDevice = alcCaptureOpenDevice (devicename.__s, frequency, format, buffersize);
3510+
3511+
value ptr = CFFIPointer (alcDevice, gc_alc_object);
3512+
alcObjects[alcDevice] = ptr;
3513+
return ptr;
3514+
3515+
}
3516+
3517+
3518+
HL_PRIM HL_CFFIPointer* HL_NAME(hl_alc_capture_open_device) (hl_vstring* devicename, int frequency, int format, int buffersize) {
3519+
3520+
ALCdevice* alcDevice = alcCaptureOpenDevice (devicename ? (char*)hl_to_utf8 ((const uchar*)devicename->bytes) : 0, frequency, format, buffersize);
3521+
3522+
HL_CFFIPointer* ptr = HLCFFIPointer (alcDevice, (hl_finalizer)hl_gc_alc_object);
3523+
alcObjects[alcDevice] = ptr;
3524+
return ptr;
3525+
3526+
}
3527+
3528+
3529+
bool lime_alc_capture_close_device (value device) {
3530+
3531+
al_gc_mutex.Lock ();
3532+
ALCdevice* alcDevice = (ALCdevice*)val_data (device);
3533+
alcObjects.erase (alcDevice);
3534+
al_gc_mutex.Unlock ();
3535+
3536+
return alcCaptureCloseDevice (alcDevice);
3537+
3538+
}
3539+
3540+
3541+
HL_PRIM bool HL_NAME(hl_alc_capture_close_device) (HL_CFFIPointer* device) {
3542+
3543+
al_gc_mutex.Lock ();
3544+
ALCdevice* alcDevice = (ALCdevice*)device->ptr;
3545+
alcObjects.erase (alcDevice);
3546+
al_gc_mutex.Unlock ();
3547+
3548+
return alcCaptureCloseDevice (alcDevice);
3549+
3550+
}
3551+
3552+
3553+
void lime_alc_capture_start (value device) {
3554+
3555+
ALCdevice* alcDevice = (ALCdevice*)val_data (device);
3556+
alcCaptureStart (alcDevice);
3557+
3558+
}
3559+
3560+
3561+
HL_PRIM void HL_NAME(hl_alc_capture_start) (HL_CFFIPointer* device) {
3562+
3563+
ALCdevice* alcDevice = (ALCdevice*)device->ptr;
3564+
alcCaptureStart (alcDevice);
3565+
3566+
}
3567+
3568+
3569+
void lime_alc_capture_stop (value device) {
3570+
3571+
ALCdevice* alcDevice = (ALCdevice*)val_data (device);
3572+
alcCaptureStop (alcDevice);
3573+
3574+
}
3575+
3576+
3577+
HL_PRIM void HL_NAME(hl_alc_capture_stop) (HL_CFFIPointer* device) {
3578+
3579+
ALCdevice* alcDevice = (ALCdevice*)device->ptr;
3580+
alcCaptureStop (alcDevice);
3581+
3582+
}
3583+
3584+
3585+
void lime_alc_capture_samples (value device, value buffer, int samples) {
3586+
3587+
ALCdevice* alcDevice = (ALCdevice*)val_data (device);
3588+
Bytes bytes (buffer);
3589+
alcCaptureSamples (alcDevice, bytes.b, samples);
3590+
3591+
}
3592+
3593+
3594+
HL_PRIM void HL_NAME(hl_alc_capture_samples) (HL_CFFIPointer* device, Bytes* buffer, int samples) {
3595+
3596+
ALCdevice* alcDevice = (ALCdevice*)device->ptr;
3597+
alcCaptureSamples (alcDevice, buffer->b, samples);
3598+
3599+
}
3600+
3601+
35073602

35083603

35093604

@@ -3621,6 +3716,11 @@ namespace lime {
36213716
DEFINE_PRIME1v (lime_alc_process_context);
36223717
DEFINE_PRIME1v (lime_alc_resume_device);
36233718
DEFINE_PRIME1v (lime_alc_suspend_context);
3719+
DEFINE_PRIME4 (lime_alc_capture_open_device);
3720+
DEFINE_PRIME1 (lime_alc_capture_close_device);
3721+
DEFINE_PRIME1v (lime_alc_capture_start);
3722+
DEFINE_PRIME1v (lime_alc_capture_stop);
3723+
DEFINE_PRIME3v (lime_alc_capture_samples);
36243724

36253725

36263726
#define _TBYTES _OBJ (_I32 _BYTES)
@@ -3745,6 +3845,11 @@ namespace lime {
37453845
DEFINE_HL_PRIM (_VOID, hl_alc_process_context, _TCFFIPOINTER);
37463846
DEFINE_HL_PRIM (_VOID, hl_alc_resume_device, _TCFFIPOINTER);
37473847
DEFINE_HL_PRIM (_VOID, hl_alc_suspend_context, _TCFFIPOINTER);
3848+
DEFINE_HL_PRIM (_TCFFIPOINTER, hl_alc_capture_open_device, _STRING _I32 _I32 _I32);
3849+
DEFINE_HL_PRIM (_BOOL, hl_alc_capture_close_device, _TCFFIPOINTER);
3850+
DEFINE_HL_PRIM (_VOID, hl_alc_capture_start, _TCFFIPOINTER);
3851+
DEFINE_HL_PRIM (_VOID, hl_alc_capture_stop, _TCFFIPOINTER);
3852+
DEFINE_HL_PRIM (_VOID, hl_alc_capture_samples, _TCFFIPOINTER _TBYTES _I32);
37483853

37493854

37503855
}

0 commit comments

Comments
 (0)