Commit graph

1063 commits

Author SHA1 Message Date
Kp 132612de35 Use enum class for wall_is_doorway_mask 2023-01-29 20:42:03 +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 165b50bcc7 Use mve_audio_spec to track whether audio can play
This is nullptr in all the cases that audio is disabled, and non-nullptr
in all the cases where it is enabled.  Use it instead of a separate flag
variable.
2023-01-07 22:17:31 +00:00
Kp 095b19e450 Use standard new[]/delete[] for movie audio buffer 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 5700cc28e7 Pass std::span to decodeFrame16 2023-01-07 22:17:31 +00:00
Kp 870c85ceab Pass std::span to decodeFrame8 2023-01-07 22:17:31 +00:00
Kp 38ff4a7b19 Use std::span for MVE g_pCurMap, g_nMapLength 2023-01-07 22:17:31 +00:00
Kp e6bba24737 Disable MVE mixer when movie ends
The global variables that control it configure the callback to do
nothing, but SDL_mixer would still call it and still acquire the SDL
mutex that protects the call.  Such calls are a waste, so disable them.
This should also fix
<https://github.com/dxx-rebirth/dxx-rebirth/issues/684>, which appears
to be caused by the MVE mixer callback being run during gameplay, and
the callback not returning immediately.  This is suspected to be because
a race condition between MVE_rmEndMovie and the callback caused the
global variables not to be placed in a state that causes the callback to
return immediately.
2022-12-17 13:16:28 +00:00
Kp a00a1ce59a Use mve_audio_spec to detect whether MVE audio has been created 2022-12-10 18:09:54 +00:00
Kp 3d5de92058 Fix OS X clang build
OS X still uses clang-14, which lacks sufficient std::ranges support for
recent Rebirth changes.

- Rewrite uses of std::ranges::SYMBOL to ranges::SYMBOL
- Add a stub header that, on gcc, provides for each SYMBOL a statement
  `using std::ranges::SYMBOL;`, to delegate back to the standard library
  implementation.
- On clang, define a minimal implementation of the required symbols,
  without constraint enforcement.  Compile-testing with gcc will catch
  constraint violations.

Once OS X clang ships a standard library with the required features,
this stub header will be removed and the uses changed back to their full
names.
2022-10-31 00:51:32 +00:00
Kp 7fc6879555 Fix various Win32 build failures due to ambiguous operator[]()
gcc reports:

```
ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second
```

Fix the ambiguity by using an unsigned integer constant.
2022-10-23 23:00:24 +00:00
Kp e385ff1c3b Use std::ranges::find_if instead of std::find_if
std::ranges::find_if permits use of a sentinel instead of a full
iterator, and supports std::ranges::find as an alternative to certain
simple uses of std::find_if.

Where possible, use the form that takes a range, rather than the form
that takes two iterators.

Add a declared, but not defined, default constructor for
self_return_iterator to satisfy the standard library's concept
`semiregular`, which insists that sentinels be default-constructible,
even for those functions that never need to do so.

Add a defined, but unused, operator++(postfix) for zip_iterator to
satisfy a standard library concept for `forward_iterator`.
2022-10-09 23:15:20 +00:00
Kp 0ebcc64ac5 Test whether change_filename_extension succeeded before using its output 2022-10-09 23:15:20 +00:00
Kp a9142bb65a Use std::span for change_filename_extension arguments 2022-10-09 23:15:20 +00:00
Kp 1d475d106c Use std::span for init_subtitles argument filename 2022-10-09 23:15:20 +00:00
Kp 38adcc7729 Simplify change_filename_extension
The called function skipped over a leading dot in the extension.  Remove
that logic and change all callers not to supply a leading dot.
2022-10-09 23:15:20 +00:00
Kp 1365d0796c Use std::span for RunMovie argument subtitles 2022-10-02 19:51:35 +00:00
Kp 1101b02f84 Use std::span for PlayMovie argument subtitles 2022-10-02 19:51:35 +00:00
Kp 81b77d2f28 Pass std::span to create_bfs_list 2022-09-24 17:47:53 +00:00
Kp ad7057be87 Add hack for case mismatch in Vertigo robot movies
PhysFS 3 is case-sensitive for movie filename lookup.  The consequence
of this was first reported in [1].  In [2], @icculus stated this was a
bug in PhysFS 3 that would be fixed in PhysFS 3.0.2.  However, [3] and
[4] assert that the fix was never included.  The existence of [5] seems
to support this.  The original problem was reported in 2019.  As of
2022, user @AlumiuN, running PhysFS 3.0.2, is affected.  Therefore, this
commit adds code to detect the relevant robot movies and adjust the case
in the Rebirth code.

[1]: https://github.com/dxx-rebirth/dxx-rebirth/issues/379
[2]: https://github.com/dxx-rebirth/dxx-rebirth/issues/379#issuecomment-389400528
[3]: https://github.com/dxx-rebirth/dxx-rebirth/issues/379#issuecomment-462083489
[4]: https://github.com/dxx-rebirth/dxx-rebirth/issues/379#issuecomment-477790175
[5]: https://github.com/dxx-rebirth/dxx-rebirth/issues/644
2022-09-24 17:47:52 +00:00
Kp 9fa97573c4 Move RoboFile to briefing scope 2022-09-24 17:47:52 +00:00
Kp d797072596 Make vector magnitude constant in more cases
Introduce a helper to obtain both the magnitude of a vector and the
corresponding normalized vector.  Use it to capture both values as const
when possible.
2022-09-24 17:47:52 +00:00
Kp 2ecad00e90 Pass std::span to load_palette 2022-09-24 17:47:52 +00:00
Kp daebb32925 Merge commit 'github-packaging' into master 2022-08-14 22:53:35 +00:00
raptor 0e03692ec3 Packages for Windows, Linux, and macOS. Uses Github's Actions 2022-08-01 09:39:41 -06:00
Kp 4141e04359 Pass thief stolen item storage to drop_stolen_items 2022-07-23 20:58:10 +00:00
Kp a3a2f7cc9a Pass context to drop_stolen_items
Pass the specific object fields needed, rather than the entire object.
2022-07-23 20:58:10 +00:00
Kp b61add4765 Pass context to drop_powerup 2022-07-23 20:58:10 +00:00
Kp 6ff9c9029d Use specific type in MVEFILE instead of void *
Replace `void *stream` with a typedef and `stream_type *stream`, so that
the original type information is propagated down.
2022-07-23 20:58:10 +00:00
Kp 51219d3607 Use enum class for PlayMovie flag must_have 2022-07-23 20:58:10 +00:00
Kp 6215ef8e06 Pass LevelSharedRobotInfoState to various functions that need it 2022-07-09 13:39:29 +00:00
Kp af05991821 Simplify thief retry loop
Instead of forcing one call, then conditionally doing 3 more, make the
loop run for 4 passes, and make the call after the conditional exit,
instead of before.
2022-07-09 13:39:29 +00:00
Kp 522c696af0 Remove unnecessary members in splitpath_t
splitpath_t is designed for MS-DOS paths, even though Rebirth now runs
on many platforms that never used DOS conventions.  Most of the members
of splitpath_t are unused on all platforms.  Remove them, and switch to
returning an initialized version of the structure.
2022-06-11 15:00:02 +00:00
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
Kp bdff6f7a00 Remove unused return value of attempt_to_steal_item 2022-05-05 02:59:11 +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 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 f51755c2e6 Use enum class for MBTN_* constants 2022-02-27 14:23:53 +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 29d6072f60 Pass context to drop_stolen_items 2022-02-05 13:30:56 +00:00
Kp 36e956cd9f Preprocess out unused-but-set variable d2x-rebirth/libmve/mveplay.cpp total
This variable is only used in a print statement which is itself
commented out.  Move the declaration, assignment, and commented print
into a preprocessor guard.
2022-01-15 20:39:10 +00:00
Kp 1c57e1032d Use enumerated_array for shared_segment::sides 2022-01-15 20:39:10 +00:00
Kp d2478d0708 Require support for C++17 attribute [[fallthrough]] 2022-01-09 15:25:42 +00:00
Kp 078a9affa0 Make MAX_SIDES_PER_SEGMENT an iterable range
Iterating over it returns each side number in turn.  This allows
converting many loops of the form:

```
	for (int i = 0; i < MAX_SIDES_PER_SEGMENT; ++i)
```

to the compact form:

```
	for (const auto i : MAX_SIDES_PER_SEGMENT)
```

The compact form brings the usual benefit of range-based for: delegating
iteration to the compiler prevents the loop body from skipping a step,
and makes clear in the code that this is the case.
2022-01-09 15:25:42 +00:00
Kp 3862edfb6c Use enum class for segment_special 2021-11-01 03:37:19 +00:00
Kp f64ed06a9d Use enum class for wall flag constants 2021-11-01 03:37:19 +00:00
Kp 21c530a3e2 Use enumerated_array for difficulty-level-specific arrays 2021-09-19 10:53:48 +00:00
Kp c01a51fd8b Remove PlayMovie special case for .MVE
Only one caller needed this special case.  Remove the special case, and
adjust that caller to include the `.MVE` as a static suffix on its
inputs.
2021-09-19 10:53:48 +00:00