When a file name is available, use SDL_RWFromFile + Mix_LoadMUSType_RW,
rather than calling Mix_LoadMUS(filename). This allows the calling code
to be more consistent.
SDL1 defines Mix_LoadMUS_RW as:
```
Mix_LoadMUS_RW(SDL_RWops *rw)
Mix_LoadMUSType_RW(rw, MUS_NONE, SDL_FALSE);
```
SDL2 defines Mix_LoadMUS_RW as:
```
Mix_LoadMUS_RW(SDL_RWops *src, int freesrc)
Mix_LoadMUSType_RW(src, MUS_NONE, freesrc);
```
The version with freesrc is preferable, and Rebirth used it to set
freesrc=SDL_TRUE in SDL2 mode. For SDL1, Rebirth used special logic
in the reset() call to emulate setting freesrc=SDL_TRUE. SDL1 also
exposes Mix_LoadMUSType_RW, which allows the caller to set freesrc in
both SDL1 and SDL2. Switch to that, so that the same code is used in
SDL1 and SDL2.
If the file is accessible via PhysFS, the next branch, based on
PHYSFS_openRead, will find it and use it. If it is not accessible via
PhysFS, then attempting to resolve its path would fail. Thus, this
attempt is redundant regardless of whether the file is reachable by
PhysFS. Remove it.
Rework the error paths to return path-specific status codes so that the
caller can report exactly which step caused an HMP file to be rejected.
On error, print this reason numerically and, if the reason was a PhysFS
error, also print the PhysFS error code numerically and symbolically.
If the type is not None, an earlier statement will have already
returned. Thus, the type can be assumed to be None if these test
statements are reached.
Previously, if the filename had no dots, then mix_play_file would refuse
to play it at all. This was excessive, as only the check for hmp needs
a filename with a dot in it. Change the logic so that a dot-less file
still is assumed not to be an hmp, but instead of returning, will fall
through and try the other load types.
Return the type for compatibility, but set the music type immediately.
Change callers to return without using a switch to set the music type
based on the returned value. This allows the callers to exit early on a
successful load.
Remove the `switch` in the caller, since now every path that can set
`current_music_type` will either (a) set it to None because the load
failed or (b) set it to non-None and return before reaching the
`switch`.
Return the type for compatibility, but set the music type immediately.
Change callers to return without using a switch to set the music type
based on the returned value. This allows the callers to exit early on a
successful load.
- Centralize the default value for the hook function.
- Move some static functions to the anonymous namespace.
- Define functions for setting the mixer parameters to ADLMIDI mode and
SDL_mixer mode, so that these modes can be set from more places.
If two or more events are delivered in the same loop, the previous
implementation would count joystick motion multiple times. Fix this by
moving the joystick interpretation to occur once, after all the events
have been processed.
On some systems, such as the Apple M1 (ARM-based Macs),
dylibbundler is in $PATH, but not in a directory found by the limited
path that SCons uses for Command() invocations. This causes the SConf
test to succeed (because it uses the full $PATH), but the Command() to
fail (because it uses a reduced path). Fix this by using the user's
$PATH, if defined, for this Command() invocation.
Along the way, rework tool_bundle.py to use SCons' Node() objects in
place of direct path manipulation. This lets SCons produce better error
messages in some cases.
Reported-by: Kreeblah <https://github.com/dxx-rebirth/dxx-rebirth/pull/610>
When joystick support is not present, `event_joystick_get_button` is not
declared in joy.h.
Fixes: c24864b180 ("make menus controllable with joystick")
Testing for buttons||hats||axes is equivalent to testing for
joysticks!=0, since SConstruct forces joysticks=0 when
buttons == 0 && hats == 0 && axes == 0. Remove tests of
buttons||hats||axes when those occur inside a test for joysticks!=0.
If axes!=0 and buttons==0 and hats==0, then the build fails because some
button-related functionality is missing. Move the joystick axis->button
bridge into a conditional to exclude it in this case.
Fixes: 74ef8b02e6 ("Added axis buttons")
Instead of parsing the button name string,
an explicit button-to-key mapping table
is now built and used.
Also fixes a few minor inconsistencies
that were introduced in c24864b1.