Commit graph

2302 commits

Author SHA1 Message Date
Kp 686fa1ba21 Simplify segment_object_range_t construction 2023-05-20 16:37:26 +00:00
Kp b4e3d67725 Recompute guidebot index on game load
The index of the guidebot is set by loading the level data, and this is
usually sufficient.  However, if the user kills the guidebot, then uses
cheats to create a new one, the new guidebot will often have a different
index than the original guidebot.  If such a game is saved and then
reloaded, then after the reload, the computed guidebot index will be
reverted to the index of the original dead guidebot.  This causes
various problems, including potentially a crash.  Recompute the guidebot
index after loading the objects from the save file, so that it matches
the live guidebot.

Reported-by: GitInMotion <https://github.com/dxx-rebirth/dxx-rebirth/issues/713>
2023-05-14 18:41:36 +00:00
Kp 397d582031 Use NSDMI for zero-initialized Mission members
Prefer non-static data member initializers over leaving the member
undefined in the constructor and relying on the caller to zero the
member afterward.
2023-05-14 18:41:36 +00:00
Kp 26d8c2881e Move compress_objects into #if DXX_USE_EDITOR
This is only called in the editor build, so exclude it from being built
in the non-editor build.
2023-05-14 18:41:36 +00:00
Kp 796c387ee4 Use enum class for Mission::anarchy_only_flag 2023-05-14 18:41:36 +00:00
Kp 3c9c855779 Use enum class for descent_hog_size 2023-05-14 18:41:36 +00:00
Kp e7d73e8493 Use RAII to manage SDL_LockAudio state 2023-05-13 15:02:55 +00:00
Kp 697ef5c32a Use std::array for last_palette_loaded_pig 2023-04-15 19:11:14 +00:00
Kp 0b066d23b4 Use enum class for load_palette arguments 2023-04-15 19:11:14 +00:00
Kreeblah 980c03b9ae
Fix Apple Clang errors and warnings 2023-04-06 16:42:49 -07:00
Kp 89e89c8afb Move global constants from mglobal.cpp to cglobal.cpp
These constants can be useful in unit tests, so move them out to their
own file.
2023-03-12 10:40:25 +00:00
Kp 452a50f80b Move WID_* constants into wall_is_doorway_result
This allows them to be reported symbolically in a debugger when a
variable is of type wall_is_doorway_result.
2023-02-18 14:30:59 +00:00
Kp 56d1814489 Add alternative mixer resamplers
SDL2_mixer changed how it upsamples sounds, and some users complained
about the difference.  Add an internal resampler that emulates how
SDL_mixer upsamples sounds.  Since all Rebirth upsampling is an integer
upsample (11Khz -> 44KHz, 22KHz -> 44Khz), this internal emulation is
considerably simpler than a general purpose resampler.

With this commit, the builder can choose which resamplers to enable.
The available resamplers are chosen by preprocessor directive, and
presently do not have an SConstruct flag.  For each resampler, if no
choice is made, then the resampler will be enabled if it is reasonable.
At least one of the resamplers must be enabled, or the build will fail
with a `#error` message.

The user may choose at program start time which of the available
resamplers to use for that execution of the program, through passing one
of the command line arguments:
- `-sdlmixer-resampler=sdl-native`
- `-sdlmixer-resampler=emulate-sdl1`
- `-sdlmixer-resampler=emulate-soundblaster16`

Runtime switching is not supported.  If the user does not choose, then
the first enabled resampler from the list below will be used.  The
available resamplers are:
- sdl_native (DXX_FEATURE_EXTERNAL_RESAMPLER_SDL_NATIVE) - delegates to
  SDL_mixer / SDL2_mixer, the way Rebirth has historically done.
- emulate_sdl1 (DXX_FEATURE_INTERNAL_RESAMPLER_EMULATE_SDL1) - an
  internal resampler that emulates how SDL_mixer worked.  This should be
  equivalent to sdl_native when using SDL_mixer, so by default it is
  enabled when Rebirth is built to use SDL2_mixer and disabled when
  Rebirth is built to use SDL_mixer.  It can still be enabled manually
  even when building for SDL_mixer, but this does not seem likely to be
  useful.
- emulate_soundblaster16
  (DXX_FEATURE_INTERNAL_RESAMPLER_EMULATE_SOUNDBLASTER16) - an internal
  resampler submitted by @raptor in
  5165efbc46.  Some users reported audio
  quality issues with this resampler, so it is not presently the
  default.
2023-02-11 10:50:21 +00:00
Kp 1f5e9808e5 Pass std::span to rotate_list 2023-02-04 19:21:25 +00:00
Kp 580fe803f0 Make tmapinfo_flags a complete type
For the same reason as 26ab08d55f884ae77ba0e1d400a2d6a92d1c0831: gdb
refuses to fully show an instance of an enum that has incomplete type,
even when the size is known.
2023-01-29 20:42:03 +00:00
Kp fecc1f102f Use enum class for clwallnum_t 2023-01-29 20:42:03 +00:00
Kp 031a4b166c Use enum class for wall_is_doorway_result 2023-01-29 20:42:03 +00:00
Kp 132612de35 Use enum class for wall_is_doorway_mask 2023-01-29 20:42:03 +00:00
Kp 27586fe0b9 Track newmenu return value using std::shared_ptr
JoeNotCharles reports that gcc-12 (architecture unspecified) warns
because `newmenu::process_until_closed` stores the address of a stack
local into a heap-allocated structure.  Switch to a less efficient
implementation that does not provoke a compiler warning:

- Store `shared_ptr<int>`, not `int *`, in the `newmenu`
- `shared_ptr::operator*()` and `shared_ptr::operator bool()` allow most
  use sites to be unchanged relative to a bare pointer
- Load the return value from the `shared_ptr<int>`.  If the newmenu
  terminated before return, as should always happen, this is a slightly
  less efficient version of the same code as before.  If the newmenu was
  still open despite its `exists` flag claiming otherwise, then the
  returned value may be incorrect, but the read will be well-formed, the
  `newmenu`'s eventual write will write to the heap-backed int (rather
  than writing into the stack allocated to
  `newmenu::process_until_closed`), and the memory will be freed when
  both `process_until_closed` has returned and the `newmenu` has been
  destroyed.

Reported-by: JoeNotCharles <10a2b2d337>
2023-01-14 19:05:37 +00:00
Kp 407ab585a8 Move window existence flag to a mixin, and track using std::shared_ptr
gcc-12 does enough escape analysis to notice that
newmenu::process_until_closed stores the address of a stack local into a
heap-allocated structure, but not enough analysis to notice that the
stack variable always outlives the escaped address.  The compiler then
warns about the address escaping the local scope.  Reworking the calling
code not to do this is somewhat invasive, and gcc seems unlikely to
change behavior.  Switch to a less efficient implementation that does
not provoke a compiler warning:

- Store a shared_ptr<bool> in the object
- In the object's destructor, write through the pointer to clear the
  shared boolean
- In the caller, store a copy of the shared_ptr<bool> as a local, and
  use that copy to monitor the shared boolean

This is similar to a change proposed by JoeNotCharles
<10a2b2d337>,
but differs in its details.  Among other things, this version takes the
opportunity to move the variable out to a mixin, so that only windows
which expect to be tracked can be tracked.  Previously, all windows were
capable of this, even though most never needed it.
2023-01-14 19:05:37 +00:00
Kp 9839ca185b Merge branch 'osx-clang-missing-ranges' to master 2023-01-14 19:05:37 +00:00
Kp 99b98bb555 Rework convert_integer to return result in some cases
Prefer returning the result in a std::optional<T> over returning a flag
value and taking a non-const reference to the result.
2023-01-14 19:05:37 +00:00
Kp 34046216a2 Make enumerate() iterator suitable for use with std::ranges
std::ranges algorithms include requires() clauses that:
- rejected enumerated_sentinel: not default-constructible
- rejected enumerated_sentinel: not assignable due to `const` member
- rejected enumerated_iterator: no postfix operator++

None of these need to be satisfied for enumerate to work properly, but
this commit satisfies and models these requirements, so that future use
of std::ranges algorithms will work.
2023-01-14 19:05:37 +00:00
Kp 9188c72b34 Reduce maximum nm_messagebox strings
Nothing uses 5 strings.
2023-01-14 19:05:37 +00:00
Kp 97c8a7a081 Remove macro wrapper around nm_messagebox
Construct the nm_messagebox_tie directly, without use of a macro.  This
produces simpler compiler error messages when nm_messagebox is called
incorrectly.
2023-01-14 19:05:37 +00:00
Kp 28bb251eea Remove unused return value for select_mission 2023-01-14 19:05:37 +00:00
Kp 8538a96451 Remove write-only multi_protocol 2023-01-14 19:05:37 +00:00
Kp dfce7ed40d Simplify SDL_QUIT handling
Remove the global `Quitting` and instead run the window close loop
immediately upon receiving SDL_QUIT.
2023-01-14 19:05:37 +00:00
Kp 3f1aa85ad6 Make partial_range_t inherit from ranges::subrange
Delegate work to the standard library where possible.
2023-01-14 19:05:37 +00:00
Kp 932c8370d5 Make iterator_result_converter satisfy std::ranges::range
std::ranges::range requires the iterator to be default-constructible and
have postfix operator++.  Add those to satisfy the concept.
2023-01-14 19:05:37 +00:00
Kreeblah 476affd806
Fix macOS compilation 2023-01-07 15:47:23 -08:00
Kp 06bb1b74ad Harden bm_read_alias against bad input 2023-01-07 22:17:31 +00:00
Kp 91496e1d4a Use enum class for properties_init result 2023-01-07 22:17:31 +00:00
Kp 5ce4d49004 Use enum class for sound_sample_rate 2023-01-07 22:17:31 +00:00
Kp 60adb6ecd8 Hold digi_sample_rate const
In any given run of the program, either the SDL_mixer code will be used,
or it will not be used.  `digi_sample_rate` only needs to vary if a
single run both uses SDL_mixer and avoids it.  Make `digi_sample_rate` a
`static const` with an appropriate value for each path.
2023-01-07 22:17:31 +00:00
Kp 7b602efedc Pass std::span to mveaudio_uncompress 2023-01-07 22:17:31 +00:00
Kp 05eea350a0 Move unique_span to d_uspan.h 2023-01-07 22:17:31 +00:00
Kp 9ba1c13d9f Flatten type information for zip<> 2022-12-31 16:21:47 +00:00
Kp 1fcb02f100 Inline zip sentinel type resolution 2022-12-31 16:21:47 +00:00
Kp a56ceca502 Use distinct sentinel type on zip<> 2022-12-31 16:21:47 +00:00
Kp 14b222e2a6 Allow distinct sentinel type on enumerated range 2022-12-31 16:21:47 +00:00
Kp 5eff03dd88 Store ranges::subrange in newmenu_layout 2022-12-31 16:21:47 +00:00
Kp 3bba60d1b7 Pass ranges::subrange to multi_all_players_alive 2022-12-31 16:21:47 +00:00
Kp 86515f6903 Pass ranges::subrange to multi_interactive_deny_save_game 2022-12-31 16:21:47 +00:00
Kp 0decae2328 Pass ranges::subrange to multi_common_deny_save_game 2022-12-31 16:21:47 +00:00
Kp c428fdee0f Pass ranges::subrange to bitmap_index_read_n 2022-12-31 16:21:47 +00:00
Kp f804d98825 Make enumerate inherit ranges::subrange directly
Remove the intermediate layer of partial_range_t.
2022-12-31 16:21:47 +00:00
Kp 41184654e8 Pass ranges::subrange to reactor_read_n 2022-12-31 16:21:47 +00:00
Kp ca913240d0 Return ranges::subrange from robot_get_anim_state 2022-12-31 16:21:47 +00:00
Kp d3ffcb0dab Store range_type, not range_iterator_type, in zip<> signature
This is initial setup to enabling use of zip() on sentinel based ranges.
Store the range's type in the zip signature, and store the types of
std::begin/std::end for the iterators, rather than assuming that
std::begin and std::end return the same type.
2022-12-31 16:21:47 +00:00