MCPcopy Create free account
hub / github.com/WolfireGames/overgrowth / AddGameControllerDB

Function AddGameControllerDB

Source/UserInput/input.cpp:210–232  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

208}
209
210static void AddGameControllerDB() {
211 // Load mappings from crowd-sourced controller database
212 // Update at:
213 // https://github.com/gabomdq/SDL_GameControllerDB/blob/master/gamecontrollerdb.txt
214 DiskFileDescriptor file;
215 std::vector<char> file_buf;
216 if (!file.Open("Data/gamecontrollerdb.txt", "r")) {
217 return;
218 }
219 int file_size = file.GetSize();
220 file_buf.resize(file_size);
221
222 int bytes_read = file.ReadBytesPartial(&file_buf[0], file_size);
223 file_buf.resize(bytes_read + 1);
224 file_buf.back() = '\0';
225 file.Close();
226
227 SDL_RWops* SDL_file = SDL_RWFromConstMem(&file_buf[0], file_buf.size());
228 if (SDL_file) {
229 int mappings = SDL_GameControllerAddMappingsFromRW(SDL_file, 1);
230 LOGI << "Added " << mappings << " controller mappings." << std::endl;
231 }
232}
233
234void Input::Initialize() {
235 InitKeyTranslator();

Callers 1

InitializeMethod · 0.85

Calls 7

ReadBytesPartialMethod · 0.80
OpenMethod · 0.45
GetSizeMethod · 0.45
resizeMethod · 0.45
backMethod · 0.45
CloseMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected