Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MorsGames
GitHub Repository: MorsGames/sm64plus
Path: blob/master/src/pc/controller/controller_entry_point.c
7861 views
1
#include "macros.h"
2
3
#include "lib/src/libultra_internal.h"
4
#include "lib/src/osContInternal.h"
5
6
#include "controller_recorded_tas.h"
7
#include "controller_sdl.h"
8
#include "controller_keyboard.h"
9
10
#include "game/settings.h"
11
12
static struct ControllerAPI *controller_implementations[] = {
13
&controller_recorded_tas,
14
&controller_sdl,
15
&controller_keyboard,
16
};
17
18
s32 osContInit(UNUSED OSMesgQueue *mq, u8 *controllerBits, UNUSED OSContStatus *status) {
19
for (size_t i = 0; i < sizeof(controller_implementations) / sizeof(struct ControllerAPI *); i++) {
20
controller_implementations[i]->init();
21
}
22
*controllerBits = 1;
23
return 0;
24
}
25
26
s32 osContStartReadData(UNUSED OSMesgQueue *mesg) {
27
return 0;
28
}
29
30
s32 osMotorStart(UNUSED void *pfs) {
31
// Since rumble stops by osMotorStop, its duration is not nessecary.
32
// Set it to 5 seconds and hope osMotorStop() is called in time.
33
if (configRumbleStrength > 0.0f)
34
controller_rumble_play(configRumbleStrength, 5.0f);
35
return 0;
36
}
37
38
s32 osMotorStop(UNUSED void *pfs) {
39
if (configRumbleStrength > 0.0f)
40
controller_rumble_stop();
41
return 0;
42
}
43
44
u32 osMotorInit(UNUSED OSMesgQueue *mq, UNUSED void *pfs, UNUSED s32 port) {
45
return 0; // rumble is initialized in the specific backend's init function
46
}
47
48
void osContGetReadData(OSContPad *pad) {
49
pad->button = 0;
50
pad->stick_x = 0;
51
pad->stick_y = 0;
52
pad->stick2_x = 0;
53
pad->stick2_y = 0;
54
pad->errnum = 0;
55
56
for (size_t i = 0; i < sizeof(controller_implementations) / sizeof(struct ControllerAPI *); i++) {
57
controller_implementations[i]->read(pad);
58
}
59
}
60
61
void controller_rumble_play(float str, float time) {
62
for (size_t i = 0; i < sizeof(controller_implementations) / sizeof(struct ControllerAPI *); i++) {
63
if (controller_implementations[i]->rumble_play)
64
controller_implementations[i]->rumble_play(str, time);
65
}
66
}
67
68
void controller_rumble_stop(void) {
69
for (size_t i = 0; i < sizeof(controller_implementations) / sizeof(struct ControllerAPI *); i++) {
70
if (controller_implementations[i]->rumble_stop)
71
controller_implementations[i]->rumble_stop();
72
}
73
}
74