Esempio n. 1
0
/*
 * Add controller mappings from the specified file
 */
void S2D_AddControllerMappingsFromFile(const char *path) {
  if (!S2D_FileExists(path)) {
    S2D_Log(S2D_WARN, "Controller mappings file not found: %s", path);
    return;
  }

  int mappings_added = SDL_GameControllerAddMappingsFromFile(path);
  if (mappings_added == -1) {
    S2D_Error("SDL_GameControllerAddMappingsFromFile", SDL_GetError());
  } else {
    S2D_Log(S2D_INFO, "Added %i controller mapping(s)", mappings_added);
  }
}
Esempio n. 2
0
/*
 * Create a sound, given an audio file path
 */
S2D_Sound *S2D_CreateSound(const char *path) {
  S2D_Init();

  // Check if sound file exists
  if (!S2D_FileExists(path)) {
    S2D_Error("S2D_CreateSound", "Sound file not found");
    return NULL;
  }

  // Allocate the sound structure
  S2D_Sound *sound = (S2D_Sound *) malloc(sizeof(S2D_Sound));

  // Load the sound data from file
  sound->data = Mix_LoadWAV(path);
  if (!sound->data) {
    S2D_Error("Mix_LoadWAV", Mix_GetError());
    free(sound);
    return NULL;
  }

  return sound;
}