MCPcopy Create free account
hub / github.com/IppClub/Dora-SSR / initInRender

Method initInRender

Source/Input/Controller.cpp:52–126  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

50Controller::~Controller() { }
51
52bool Controller::initInRender() {
53 SDL_SetHint(SDL_HINT_ACCELEROMETER_AS_JOYSTICK, "0");
54 auto time = SharedApplication.getCurrentTime();
55 if (SharedContent.exist("gamecontrollerdb.txt"_slice)) {
56 int64_t size = 0;
57 uint8_t* buffer = SharedContent.loadUnsafe("gamecontrollerdb.txt"_slice, size);
58 OwnArray<uint8_t> data(buffer);
59 if (size > 0) {
60 const char* platform = SDL_GetPlatform();
61 auto str = std::string{r_cast<const char*>(data.get()), s_cast<size_t>(size)};
62 char *line, *line_end, *tmp, *comma, line_platform[64];
63 size_t db_size = str.size(), platform_len;
64 char* buf = &str[0];
65 line = buf;
66 auto platformStr = "platform:"sv;
67 while (line < buf + db_size) {
68 line_end = SDL_strchr(line, '\n');
69 if (line_end != nullptr) {
70 *line_end = '\0';
71 } else {
72 line_end = buf + db_size;
73 }
74 tmp = SDL_strstr(line, platformStr.data());
75 if (tmp != nullptr) {
76 tmp += platformStr.size();
77 comma = SDL_strchr(tmp, ',');
78 if (comma != nullptr) {
79 platform_len = comma - tmp + 1;
80 if (platform_len + 1 < SDL_arraysize(line_platform)) {
81 SDL_strlcpy(line_platform, tmp, platform_len);
82 if (SDL_strncasecmp(line_platform, platform, platform_len) == 0) {
83 if (SDL_GameControllerAddMapping(line) < 0) {
84 Error("failed to load controller mapping: {}", line);
85 }
86 }
87 }
88 }
89 }
90 line = line_end + 1;
91 }
92 auto deltaTime = SharedApplication.getCurrentTime() - time;
93 SharedApplication.invokeInLogic([deltaTime]() {
94 Event::send(Profiler::EventName, "Loader"s, "gamecontrollerdb.txt"s, 0, deltaTime);
95 });
96 }
97 }
98 for (int i = 0; i < SDL_NumJoysticks(); ++i) {
99 addControllerInRender(i);
100 }
101#if DORA_DEV_VIRTUAL_CONTROLLER
102 if (isDevVirtualControllerEnabled()) {
103#if SDL_VERSION_ATLEAST(2, 24, 0)
104 SDL_VirtualJoystickDesc desc;
105 SDL_zero(desc);
106 desc.version = SDL_VIRTUAL_JOYSTICK_DESC_VERSION;
107 desc.type = SDL_JOYSTICK_TYPE_GAMECONTROLLER;
108 desc.naxes = SDL_CONTROLLER_AXIS_MAX;
109 desc.nbuttons = SDL_CONTROLLER_BUTTON_MAX;

Callers 1

runMethod · 0.80

Calls 15

SDL_SetHintFunction · 0.85
SDL_GetPlatformFunction · 0.85
SDL_strchrFunction · 0.85
SDL_strstrFunction · 0.85
SDL_strlcpyFunction · 0.85
SDL_strncasecmpFunction · 0.85
SDL_NumJoysticksFunction · 0.85
makeControllerButtonMaskFunction · 0.85
makeControllerAxisMaskFunction · 0.85

Tested by

no test coverage detected