Commit graph

11736 commits

Author SHA1 Message Date
Kp bbd49251cf Simplify susegment constructor overloads
Use a single constructor that accepts anything convertible to both of
the required types, rather than special constructors for:
- Accepting a qualified_segment
- Accepting a variant of susegment with compatible const qualifiers
- Accepting a type T that converts to qualified_segment

This reduces the number of constructors to consider, which improves
error messages when an invalid input is used.
2022-04-17 22:27:19 +00:00
Kp 06a0de1c90 Remove write-only legacy trigger field time
v29_trigger and v30_trigger define a field `time`.  v29_trigger never
initializes it.  v30_trigger initializes it from the uninitialized
v29_trigger in legacy mode, and from a file field otherwise.  No program
logic ever reads this member, so remove it.
2022-04-16 19:38:02 +00:00
Kp 600a4f9d62 Remove special case for negative crc32
According to the documentation, starting in Python 3, the result is
always unsigned.
2022-04-16 19:38:02 +00:00
Kp 87cc4c79c8 Fix off-by-one in mission string count
Commit 7f2df64649 converted `mission_menu` to inherit from `listbox`,
but introduced an off-by-one bug in the handling of subdirectories.
`listbox` must be told how many strings it is given.  Subdirectories
have one extra string, to represent the `listbox_go_up` element.  The
count passed to `listbox` incorrectly failed to adjust for the generated
go-up element, causing listbox not to show the last string in the list.
Change the logic to adjust the count to include the extra element.

Fixes: 7f2df64649 ("Make mission_menu inherit from listbox")
Reported-by: AlumiuN <https://github.com/dxx-rebirth/dxx-rebirth/issues/629>
2022-04-12 03:01:48 +00:00
Kp 0142c02edd Use Mix_LoadMUSType_RW for named files, too
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.
2022-03-19 22:55:58 +00:00
Kp f5e9daf7a5 Use Mix_LoadMUSType_RW to unify SDL1/SDL2 call to Mix_LoadMUS_RW
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.
2022-03-19 22:55:58 +00:00
Kp 2099c54ac7 Remove mix_play_file use of PHYSFSX_getRealPath
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.
2022-03-19 22:55:58 +00:00
Kp 9cdf9152bc Always check return value of PHYSFSX_getRealPath
The contents of the output buffer are undefined if PHYSFSX_getRealPath
fails, so mark the function as [[nodiscard]] and modify all callers to
check that the function succeeded.
2022-03-19 22:55:58 +00:00
Kp 3b5b69cb97 Improve error reporting for hmp_open / hmp2mid
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.
2022-03-19 22:55:58 +00:00
Kp d34f7b2ad9 Remove unnecessary tests for current_music_type
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.
2022-03-19 22:55:58 +00:00
Kp d09d30e173 Make mix_play_file only skip hmp for dot-less filenames
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.
2022-03-19 22:55:58 +00:00
Kp c4cc119898 Set music type inside load_mus_file
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`.
2022-03-19 22:55:58 +00:00
Kp f8cf0b10c2 Set music type inside load_mus_data
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.
2022-03-19 22:55:58 +00:00
Kp f12abb938e Factor out setting mixer parameters
- 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.
2022-03-19 22:55:58 +00:00
Kp 61c4d53ae6 Pass canvas to con_draw 2022-03-19 22:55:58 +00:00
Kp 21aae1a352 Tighten symbol visibility for xrange
Switch to using protected inheritance, and expose the two base fields
that are needed outside the class.
2022-03-05 17:23:51 +00:00
Kp dc59b0b2cb Split out xrange init_begin ascending/descending paths
AlumiuN reports that mingw32-w64-gcc-8.1.0 incorrectly reports
`ascending` as unused-but-set.  This is clearly not true.  Reorder the
code to avoid saving `ascending`, and instead use the result of
`detail::get_xrange_ascending` directly.  This also improves the error
message in the DXX_ALWAYS_ERROR_FUNCTION path.

Reported-by: AlumiuN <https://github.com/dxx-rebirth/dxx-rebirth/issues/626>
2022-03-05 17:23:51 +00:00
Kp b3f250f3b6 Fix openable_door_on_near_path for side WLEFT
openable_door_on_near_path should return 0 for no door and any non-zero
value for door-found.  Commit 9fdf6005df changed the logic to return 0
for no door, and the side number value for door-found.  This is wrong,
since WLEFT has integer value 0, so the caller will interpret a return
of door-found, side=WLEFT as no-door-found.

Fixes: 9fdf6005df ("Convert ai_static::GOALSIDE to sidenum_t")
2022-02-27 14:23:53 +00:00
Kp 9e58992296 Flatten constant_xrange hierarchy 2022-02-27 14:23:53 +00:00
Kp f51755c2e6 Use enum class for MBTN_* constants 2022-02-27 14:23:53 +00:00
Kp 6863dd3581 Reduce lifetime of joy_axis
It is only needed for the duration of kconfig_end_loop.  Move it from
the global Controls to local scope.
2022-02-27 14:23:53 +00:00
Kp 197a9cbd98 Move joystick interpretation to happen after the event loop
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.
2022-02-27 14:23:53 +00:00
Kp 9464bdf2e4 Use enumerated_array for indexing player input controls 2022-02-27 14:23:53 +00:00
Kp 165d5b892b Rename pitch -> pitch_ud for consistency
Other code uses pitch_ud.  Rename the kconfig pitch to match.
2022-02-27 14:23:53 +00:00
Kp 43bdfac56a Store copy_sensitivity values as std::integral_constant
Lists of these objects are unrolled by a template parameter pack
regardless of whether they are type compatible, so keeping the types
compatible does not improve code size.  Store more precise types in the
structure, and avoid needing to store the constant values into a
structure at runtime.
2022-02-27 14:23:53 +00:00
Kp e7fd31e3a6 Check return value of find_connect_side in more places 2022-02-19 14:52:17 +00:00
Kp 52403f104f Use symbolic sidenum values in Edge_to_sides 2022-02-19 14:52:17 +00:00
Kp 5611319962 Qualify references to sidenum_t members 2022-02-19 14:52:17 +00:00
Kp 68268e9a1f Use sidenum_t in more places 2022-02-19 14:52:17 +00:00
Kp 91c9055c90 Simplify do_endlevel_flythrough computation of next distance 2022-02-19 14:52:17 +00:00
Kp 2fe9a16613 Use dedicated type for mask of segment side numbers 2022-02-19 14:52:17 +00:00
Kp 8c037b7c26 Split player start generation
Move some of the logic to a separate function to enable use of `return`
instead of a `break` from a composite loop.
2022-02-19 14:52:17 +00:00
Kp b1278b8e39 Flatten type hierarchy for enumerated_iterator
Pass adjust_iterator_dereference_type directly, instead of passing
iterator_dereference_type and letting enumerated_iterator compute
adjust_iterator_dereference_type.
2022-02-19 14:52:17 +00:00
Kp f38a1b95a1 Simplify use of git-archive handling
The result of git-archive expanding `$Format:%H` will always be a valid
string.  Repeat the format specifier, so that the call to `.format()`
can be removed.
2022-02-13 19:13:38 +00:00
Kp 72064c62e7 Add unit tests for enumerate 2022-02-13 19:13:38 +00:00
Kp 17d1c3fb13 Pass range index_type through zip_iterator 2022-02-13 19:13:38 +00:00
Kp 7c2b8e1e6f Save full pkg-config stdout to sconf.log
Select flags parsed from pkg-config stdout were logged to the screen and
to sconf.log.  Add a line in sconf.log which shows the full stdout of
pkg-config.
2022-02-13 19:13:38 +00:00
Kp 3dd050ef98 Remove unused_ui_userdata 2022-02-13 19:13:38 +00:00
Kp c4985b8606 Move UI_GADGET list setup into constructor 2022-02-13 19:13:38 +00:00
Kp f2832e6248 Simplify _sockaddr IPv4/IPv6 logic
- Use std::integral_constant instead of a static function that returns
  the value
- Remove unused protocol_family
- Replace the enum with a typedef for the one type that the enum was
  used to define
2022-02-12 18:57:12 +00:00
Kp 8be306efa7 Use enum class for cockpit_mode_t 2022-02-12 18:57:12 +00:00
Kp 6b8a0a74c6 Fix some check_header_includes=1 failures 2022-02-12 18:57:12 +00:00
Kp 2be1a8ca85 Split game.h to fwd-game.h 2022-02-12 18:57:12 +00:00
Kp 8d9989024e Split inferno.h to fwd-inferno.h 2022-02-12 18:57:12 +00:00
Kp 504cbcc012 Split powerup.h to fwd-powerup.h 2022-02-12 18:57:12 +00:00
Kp f9c876572f Use std::move to compact Netgame.players on quit-joining 2022-02-12 18:57:12 +00:00
Kp 8fa4e6aa46 Simplify net_udp_welcome_player test order
Move the test for closed up, to avoid re-testing it.
2022-02-06 16:12:31 +00:00
Kp fe19f78fcd Simplify some uses of Highest_object_index 2022-02-06 16:12:31 +00:00
Kp da49df78f7 Split drop_powerup to return either an object id or a success code
If exactly one object will always be needed, use an overload that
returns the object id.  Otherwise, use an overload that only returns
whether at least one object was created.  This simplifies callers that
always request exactly one object.
2022-02-06 16:12:31 +00:00
Kp 04f0507942 Fix memory corruption if spit_powerup fails to drop a weapon
If spit_powerup fails, it returns object_none.  object_none is not a
valid index for use by map_objnum_local_to_remote.
2022-02-06 16:12:31 +00:00