Commit graph

11971 commits

Author SHA1 Message Date
Kp cf51ac4ee0 Fix BUG on show-path cheat
Players are not robots, but the show-path cheat tried to pretend they
are, and triggered a BUG warning[1] when looking up robot information
from the player object.  Fix this by passing in the robot_info when the
caller is providing a robot, and a named `nullptr` value (as
`create_path_unused_robot_info`) when the caller is providing a
non-robot object.

[1] As below, but repeated many times
```
similar/main/ai.cpp:1905: BUG: object 0x555555858550 has type 4, expected 2
similar/main/ai.cpp:1974: BUG: object 0x555555858550 has type 4, expected 2
```
2022-05-21 19:51:18 +00:00
AlumiuN da0b746037 Set console output priority to highest given option rather than most recently specified 2022-05-16 20:03:34 +12:00
Kp e29cddd524 Cache Difficulty_level during aim-leading calculations 2022-05-11 03:17:23 +00:00
Kp edbdec361c Check return value of check_line_to_line 2022-05-10 01:58:55 +00:00
Kp 2b36332228 Use enum class for intersection_type in fvi 2022-05-10 01:58:55 +00:00
Kp 8c5eff2ba0 Remove unused return value of callsign_t::copy 2022-05-10 01:58:55 +00:00
Kp 7b7145f20a Simplify zeroing callsign on copy-in
Zero the entire array, then overwrite the leading portion with the
received data.  This permits the compiler to do a fixed number of large
stores, instead of a variable number of small stores.
2022-05-10 01:58:55 +00:00
Kp 887851cb99 Make RAIIsocket::closesocket static
It exists as a wrapper for the Windows call of the same name.  Windows
does not require an object, so neither should this method.
2022-05-10 01:58:55 +00:00
Kp 464b5b302f Change RAIIaddrinfo to use using instead of forwarding functions 2022-05-10 01:58:55 +00:00
Kp 163a6222c2 Remove unnecessary endian instances in serial.h
The type aliases are sufficient.  Individual bytebuffer_t
implementations can define a `static constexpr` member `endian` from the
type alias and rely on `std::integral_constant<T, V>::operator()`
instead of defining a `static` method just to return an instance of the
`std::integral_constant`.
2022-05-05 02:59:11 +00:00
Kp bdff6f7a00 Remove unused return value of attempt_to_steal_item 2022-05-05 02:59:11 +00:00
Kp 58deb3c333 Rename check_header_includes object directory to be descriptive
Change from `chi` to `check_header_includes`.
2022-05-05 02:59:11 +00:00
Kp 97f8aea2f8 Use header path for check_header_includes=1 compilation database entries 2022-05-05 02:59:11 +00:00
Kp 9e0431b861 digi_win32_play_midi_song: write hmp_open result directly to global
Commit 3b5b69cb97 changed the logic to store the result of hmp_open
into a local that was destroyed at the end of the function.  This was
incorrect, as destruction of the returned value will immediately halt
the music.  Revert to the previous behavior, where the result is written
to the global `cur_hmp` so that it persists past the end of the
function.

Reported-by: norbert79 <https://github.com/dxx-rebirth/dxx-rebirth/issues/634>
Analyzed-by: AlumiuN <https://github.com/dxx-rebirth/dxx-rebirth/issues/634#issuecomment-1110510761>
Proposed-fix-by: AlumiuN <https://github.com/dxx-rebirth/dxx-rebirth/issues/634#issuecomment-1110510761>
Fixes: 3b5b69cb97 ("Improve error reporting for hmp_open / hmp2mid")
2022-04-28 02:19:26 +00:00
Kp f95bc3193f Fix traceback when using GIT='' and check_header_includes=1
`check_header_includes` requires `git` to be installed and able to list
files from a working copy.  When `GIT=''` is used, SConstruct is told
not to find or run `git`.  This caused a traceback when
`check_header_includes` tried to use git to list headers.  Reorder the
test to report a clear failure message.
2022-04-24 20:42:01 +00:00
Kp 504b38759c Use enum class for weapon_sound_flag
Pass the silent/audible flag as an enum:uint8_t to avoid type confusion
issues.
2022-04-24 20:42:01 +00:00
Kp 34793b5477 Use std::array for find_connected_distance depth array
Zero the entire array, rather than adjusting the loop to account for the
count of segments in the level.  The array may not need to be zeroed at
all, but this is cheap and guarantees consistent results.
2022-04-24 20:42:01 +00:00
Kp 8de9facac1 Lift thief AIM_THIEF_ATTACK check into caller
attempt_to_steal_item_3 always fails if the thief is not in
AIM_THIEF_ATTACK mode.  The caller will call attempt_to_steal_item_3
repeatedly in some cases, but the mode does not change during the calls,
so if one fails for this reason, then all will fail for this reason.
Lift the check into the caller so that the loop of repeated calls can be
skipped if the mode check fails.
2022-04-24 20:42:01 +00:00
Kp a610a7b32d Pass bare object & to thief stealing routines
Use `object &` instead of `vmobjptr_t`.  This should generate equivalent
code, but produce smaller debug information and may require less
inlining by the compiler.
2022-04-24 20:42:01 +00:00
Kp 1c2e1c6946 Tighten type info for d_strdup
The allocated block is part of the dmem subsystem, so return a type that
reflects that.
2022-04-24 20:42:01 +00:00
Kp 81dd23b151 Only charge player for weapons that fire successfully
If creating the weapon object fails, do not charge the player for the
shot that was not created.
2022-04-17 22:27:19 +00:00
Kp 5b29428643 Propagate nfires within do_laser_firing
Previous work made this a local constant.  Propagate that constant now
to eliminate dead conditional paths.
2022-04-17 22:27:19 +00:00
Kp 8f8989e049 Propagate do_laser_firing nfires as 1
Every caller passes `1`, so remove the parameter and always use `1`.
For backward compatibility with the previous network protocol, continue
to send a `1` in the network message.
2022-04-17 22:27:19 +00:00
Kp c4fb3fc30f Defer creating awareness event until weapon is created
If creation of the weapon object fails, do not tell robots that the
weapon was fired.
2022-04-17 22:27:19 +00:00
Kp dde3747ed4 Improve drop-secondary messages
- Write a more specific message on failure
- Defer writing a success message until `spit_powerup` succeeds
- Defer the sound too
- Rewrite the success message to tell how much ammo remains
2022-04-17 22:27:19 +00:00
Kp 834aeea23f Fix drop-primary/drop-secondary keys
Commit 8c8b7419b6 defined Shift-F5 and Shift-F6 to adjust the VR
handling.  However, Shift-F5 and Shift-F6 already had a meaning: drop
primary weapon / drop secondary weapon.  The ordering of the logic
causes the new VR handling to suppress the old drop handling, thus
preventing players from dropping weapons.  Disable the VR meaning for
these keys so that drop-weapon works again, since F1 documents those
keys as drop-weapon.

Fixes: 8c8b7419b6 ("Improved conditionals for stereo vs non-stereo modes.")
2022-04-17 22:27:19 +00:00
Kp f79baf722c Move static obj_* functions into anonymous namespace 2022-04-17 22:27:19 +00:00
Kp cf2c7bbe80 Replace serial byteswap macros with constexpr function
This allows taking the input by-value instead of by-reference, while
still protecting against unwanted type conversion.

Add some basic static_assert tests that the swapped values are correct.
2022-04-17 22:27:19 +00:00
Kp 71b4c11f8c Combine DXX_HAVE_BUILTIN_BSWAP, DXX_HAVE_BUILTIN_BSWAP16
Commit f1606f7747 ("Simplify test for
__builtin_bswap16") changed the SConstruct test to either define both
DXX_HAVE_BUILTIN_BSWAP and DXX_HAVE_BUILTIN_BSWAP16 or to define neither
of them.  Follow up that commit by removing the definition of
DXX_HAVE_BUILTIN_BSWAP16 and redirecting uses of it to
DXX_HAVE_BUILTIN_BSWAP.
2022-04-17 22:27:19 +00:00
Kp 2a6c513ffd Fix LTO ODR build failure in wall.h
The conditional definition of a D2X flag causes a technical ODR
violation.  It is legal, though not useful, to define this flag in D1X
and in common code.  Remove the preprocessor guard so that D2X and
common code use the same definition for the enum.
2022-04-17 22:27:19 +00:00
Kp d0c32b8cf2 Pass LevelUniqueWallSubsystemState to wall_init 2022-04-17 22:27:19 +00:00
Kp 211dcede72 Inline trigger_init
It is used in only one place.  Move it inline.
2022-04-17 22:27:19 +00:00
Kp da85bd4cd1 Optimize check order in find_connected_distance
Checking for a previously visited segment is cheaper than checking
whether a doorway exists.  Reorder the logic to check first for a
previous visit.
2022-04-17 22:27:19 +00:00
Kp d6d7837aa7 Remove dead store of point_seg::segnum in find_connected_distance 2022-04-17 22:27:19 +00:00
Kp 99747e092f Avoid index truncation in check_explicit_index_range_ref
Split check_index_range to check_index_range+check_index_range_size.
Redirect check_explicit_index_range_ref to check_index_range_size, so
that the index_type is not truncated and then extended.
2022-04-17 22:27:19 +00:00
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