Commit graph

6356 commits

Author SHA1 Message Date
Kp 7ddc095c9c Fix misspelling in filter_fir comment 2022-11-12 19:31:52 +00:00
Kp f6eb8edd59 Remove unnecessary zero fill in upsample
`std::make_unique` already value-initializes the array.
2022-11-12 19:31:52 +00:00
Kp d21ea16d2b Allocate output buffer in upsample
Take the length from the caller and allocate it locally, rather than
requiring the caller to provide the buffer.
2022-11-12 19:31:52 +00:00
Kp 4eff9d3ffc Merge master into pull/651
Pull #651 predates the switch to C++20.  Pull in master to provide the
C++20 support needed by some tuning commits.
2022-11-12 19:02:17 +00:00
Kp e42cd300af Use auto & for coeffs, since it is never changed 2022-11-12 19:00:21 +00:00
Kp 713b3baf99 Remove unnecessary commented variable 2022-11-12 19:00:21 +00:00
Kp 7a6870d610 Move buffer pointer directly from unique_ptr to RAIIMix_Chunk
Avoid transferring the pointer into a local variable, so that there are
no points where a stack unwind could lose the pointer to the allocated
memory.
2022-11-12 19:00:21 +00:00
Kp fe5dacb759 Move resample code into namespace dcx 2022-11-12 19:00:21 +00:00
Kp 30500cbaa8 Add inttypes.h to bmread.cpp for PRIuFAST32
bmread.cpp uses PRIuFAST32, so it should include inttypes.h to get the
definition of this macro.  Some platforms happened to include inttypes.h
as an implementation detail, but for portability, it needs to be
included explicitly in this file.

Reported-by: AlumiuN <https://github.com/dxx-rebirth/dxx-rebirth/issues/678#issuecomment-1304962448>
2022-11-10 02:04:09 +00:00
Kp cb53ce8c0e Replace strcpy with std::move in multi_message_input_sub
The documentation for `strcpy` states in part:

```
The strings may not overlap
```

However, for this use, the strings do overlap.  Switch to `std::move`,
which is documented to handle this so long as the destination iterator
is outside the source range, which it will be for this use.
2022-11-08 02:55:09 +00:00
Kp 1e093bacae Preserve trailing space in ": " in a long message
Previously, the `strcpy` would preserve the `:`, but overwrite the ` `.
This is probably not what the player wants, since the first `": "` in
the line can direct a message to specific recipients, but a bare `":"`
will not.  As a result, the old system would send the first part
privately, but then mangle the directed-message prefix such that
subsequent parts were sent publicly.  Switch to preserve the trailing
space so that the `": "` retains its special meaning in subsequent
messages.
2022-11-08 02:55:09 +00:00
Kp 1a2ca399b3 Use iterators to examine Network_message 2022-11-08 02:55:08 +00:00
Kp ad8f75b0dd Cache Player_num result in multi_message_input_sub
Save a reference to the appropriate multi_sending_message for reuse
later.
2022-11-08 02:55:08 +00:00
Kp 98cb7bf923 Use size_t for multi_message_index
As an index, it can never be negative.
2022-11-08 02:55:08 +00:00
Kp e2c61f6aee Pass context to init_morphs 2022-11-07 01:59:34 +00:00
Kp 70505e69d0 Use enum class for delta_light_index 2022-11-07 01:59:34 +00:00
Kp e9b4711d87 Inline object_create_explosion into callers
`object_create_explosion` delegated to
`object_create_explosion_without_damage`, adding one parameter that
callers ought to provide instead.  Inline `object_create_explosion` into
callers and change them to provide `Vclip`.
2022-11-07 01:59:34 +00:00
Kp 8d329c0f54 Pass std::span to net_udp_process_game_info_light 2022-11-07 01:59:34 +00:00
Kp b8cc509cbe Fix tracker upid values
Commit 0512ea8d65 changed the value of the tracker_ upid codes when
they were converted from `#define` statements with explicit values to
`enum` members with implicit values.  The tracker program is maintained
separately, and continues to use the old values, so games with this
commit use the wrong numbers when requesting service from the tracker.
Switch the upid codes back to their previous values, and add a warning
comment about the special compatibility concerns for tracker upid
codes, relative to game-to-game codes.

Fixes: 0512ea8d65 ("Use enum class for upid")
2022-11-07 01:59:34 +00:00
Kp 16c86edabc Fix cockpit switch in SDL-only build
The cockpit graphic is not scaled in the SDL build, so it is only
meaningful to show when the game window dimensions match the graphic's
dimensions.  Prior to 4a8d7c7574, this worked, because the
`initial_large_game_screen_mode` was the same as the graphic's
dimensions.  That commit changed `initial_large_game_screen_mode` to
prefer a larger screen resolution for new users.  It should have
retained the original dimensions for this test.  Make that change here.

Fixes: 4a8d7c7574 ("Default to 1024x768 for new users, not 640x480")
2022-11-06 18:18:57 +00:00
Kp 7effca68f0 Use RAII_SDL_Surface to track SDL-only main canvas surface
The Rebirth main screen grd_curscreen borrows the memory allocated by
SDL_CreateRGBSurface to store its data.  Store the pointer to that
surface inside grd_curscreen and make grd_curscreen responsible for
freeing the surface.
2022-11-06 18:18:57 +00:00
Kp ae46a5b3b0 Simplify SDL gr_flip: nullptr implies copy all
Per the header comments, passing nullptr for source or destination
copies the entire region.  Use that instead of explicitly requesting the
entire region.  This should be more efficient, since it bypasses the
source rectangle clipping code that SDL would otherwise run.
2022-11-06 18:18:57 +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
Arne de Bruijn 3567a7bc98
Merge a31519dc08 into 7fc6879555 2022-10-29 18:07:22 +00:00
Arne de Bruijn a31519dc08 Fix score getting mangled after new ship 2022-10-29 20:03:08 +02: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 8501db1e64 Group Network_message GM_TEAM checks 2022-10-23 23:00:24 +00:00
Kp 862c1f0aab Pass std::span to multi_process_bigdata 2022-10-23 23:00:24 +00:00
Kp 2277d90ccd Pass std::span to net_udp_process_mdata 2022-10-23 23:00:24 +00:00
Kp 21cf4b2eb8 Pass std::span to net_udp_noloss_got_ack 2022-10-23 23:00:24 +00:00
Kp cebc645e21 Pass std::span to net_udp_process_pdata 2022-10-23 23:00:24 +00:00
Kp 641a36b9fa Pass std::span to net_udp_process_pong 2022-10-23 23:00:24 +00:00
Kp 89bcb126ab Pass std::span to net_udp_process_ping 2022-10-23 23:00:24 +00:00
Kp 3fb11cecf1 Move net_udp_process_version_deny up
This allows the lower namespace{} block to change scope without changing
the namespace of net_udp_process_version_deny.
2022-10-23 23:00:24 +00:00
Kp 5bb61f71b5 Pass std::span to UDP_sequence_request_packet::build_from_untrusted 2022-10-23 23:00:24 +00:00
Kp d134645d1f Pass std::span to net_udp_process_dump 2022-10-23 23:00:24 +00:00
Kp c1a151fc8f Pass std::span to net_udp_check_game_info_request 2022-10-23 23:00:24 +00:00
Kp 6dfd405d90 Pass std::span to net_udp_process_version_deny 2022-10-23 23:00:24 +00:00
Kp e98650afb9 Pass std::span to net_udp_process_request 2022-10-23 23:00:24 +00:00
Kp 04af38638c Inline effect of object_rw_swap into multi_object_rw_to_object
Change from rewriting the object in place to byte-swap it, then copying
the byte-swapped values into the long term object to instead copy the
values into the object and perform byte-swapping as needed during the
copy.
2022-10-23 23:00:24 +00:00
Kp 23e75f3a45 Pass std::span to multi_do_fire 2022-10-23 23:00:24 +00:00
Kp 5f1877a4d6 multi_do_kill_*: use player number from network layer
The network layer already has the player number.  Use that instead of
reloading it from the message body.
2022-10-23 23:00:24 +00:00
Kp 22444d5377 multi_do_msgsend_state: use player number from network layer
The network layer already has the player number.  Use that instead of
reloading it from the message body.
2022-10-23 23:00:24 +00:00
Kp 8fd6ff2025 multi_do_escape: use player number from network layer
The network layer already has the player number.  Use that instead of
reloading it from the message body.
2022-10-23 23:00:24 +00:00
Kp 49698fbf86 multi_do_quit: use player number from network layer
The network layer already has the player number.  Use that instead of
reloading it from the message body.
2022-10-23 23:00:24 +00:00
Kp 064e971b28 multi_do_fire: use player number from network layer
The network layer already has the player number.  Use that instead of
reloading it from the message body.
2022-10-23 23:00:24 +00:00
Kp f6c45d0f6f Use enum class for multiplayer_command_t 2022-10-23 23:00:24 +00:00
Kp f47bcb5cbc Fix buffer overread at startup
Commit 5b7fb9c402 incorrectly removed the trailing null from
`g_descent_version`.  Add an explicit null, since list initialization
does not imply a null.

Fixes: 5b7fb9c402 ("Reduce use of quotes for passing vers_id defines")
2022-10-19 01:17:33 +00:00
Kp 7981fd1b17 Revert incorrect logic changes from std::ranges conversion
Commit e385ff1c3b switched various sites to use projection to extract
a value and avoid use of a predicate.  Two of the converted sites need
to use a predicate in order to test for a value being unequal to a
constant, rather than testing for equality as e385ff1c3b did.

Fixes: e385ff1c3b ("Use std::ranges::find_if instead of std::find_if")
2022-10-16 23:20:34 +00:00
Kp cb8303839c Revert incorrect robot collision logic change
Commit 37132ab887 rearranged the special rules around robot-vs-robot
vector intersection based on an obsolete comment from Descent 1.  In
Descent 2, robot-vs-robot collisions are always disabled, so that the
thief bot does not damage itself when flying past other robots.

Reported-by: Glumduk <https://github.com/dxx-rebirth/dxx-rebirth/issues/665>
Fixes: 37132ab887 ("Pass LevelSharedRobotInfoState in fvi_query")
2022-10-09 23:15:21 +00:00
Kp b3a34f424f Pass std::ranges::subrange to drive_letter_menu 2022-10-09 23:15:21 +00:00
Kp efa3f97a00 Pass std::ranges::subrange to briefing_menu 2022-10-09 23:15:21 +00:00
Kp d9c06e25c5 Pass std::ranges::subrange to multi_execute_save_game 2022-10-09 23:15:21 +00:00
Kp 31b2f1399c Pass std::ranges::subrange to find_hli_entry 2022-10-09 23:15:21 +00:00
Kp 515e0abe11 Pass std::ranges::subrange to PHYSFSX_findFiles 2022-10-09 23:15:21 +00:00
Kp 2c7ed3cfce Pass std::ranges::subrange to PHYSFSX_findabsoluteFiles 2022-10-09 23:15:21 +00:00
Kp 052dff6dae Pass std::ranges::subrange to menu selection functions 2022-10-09 23:15:21 +00:00
Kp 57de180a2e Pass std::ranges::subrange to PHYSFSX_checkMatchingExtension 2022-10-09 23:15:21 +00:00
Kp 90d3d82d8e Default disable VR side-by-side for OpenGL ES
VR requires glDrawBuffer, which Mesa OpenGL ES does not offer.  Default
VR to disabled for OpenGL ES users.  Users who want to try it anyway can
still set use_stereo_render=1 in the SCons environment.
2022-10-09 23:15:20 +00:00
Kp dac2fa22d7 Use std::ranges::subrange for choose_drop_segment
The full functionality of partial_range is not necessary.
2022-10-09 23:15:20 +00:00
Kp b16c5f7a7c Use std::ranges::subrange for sort_seg_children
The full functionality of partial_range is not necessary.
2022-10-09 23:15:20 +00:00
Kp 229766e9cb Use enum class for polygon_simpler_model_index
This type is stored with an off-by-one bias from the regular model
index, so use a distinct enum type to avoid implicit conversions.
2022-10-09 23:15:20 +00:00
Kp 22abc6d4d8 Assert size of serialized weapon_info structure
These are read from a packed binary file shipped with the game, so their
size must not change.  If the size does change, later fields will be
loaded from the wrong offset, causing the in-memory values to be
incorrect.
2022-10-09 23:15:20 +00:00
Kp d5d103bc93 Simplify bm_read_weapon last_model_num handling
The existing handling always wrote to slot 0, but did so in a convoluted
way.  The variable names suggest this was not intended, but no one has
ever reported it as broken, and some otherwise valid data files may
depend on this quirk.
2022-10-09 23:15:20 +00:00
Kp 6ecbd6533a Simplify bm_read_robot last_model_num handling
The existing handling always wrote to slot 0, but did so in a convoluted
way.  The variable names suggest this was not intended, but no one has
ever reported it as broken, and some otherwise valid data files may
depend on this quirk.
2022-10-09 23:15:20 +00:00
Kp 43e1c841f0 Pass polymodel& to polymodel_read 2022-10-09 23:15:20 +00:00
Kp acae546a90 Pass polymodel& to draw_model_picture, draw_polygon_model 2022-10-09 23:15:20 +00:00
Kp 910ac7fd4a Use template alias for per-team arrays 2022-10-09 23:15:20 +00:00
Kp f61db8ae7a Make enumerate() default to std::size_t for index_type
Change from `uint_fast32_t` to `std::size_t` for consistency with how
arrays are typically indexed.

Change the decltype() lookup to use a non-template function for the
fallback case.

Move the remove_reference logic into the caller, to allow fewer
instantiations of `array_index_type`.
2022-10-09 23:15:20 +00:00
Kp 9716d42ea0 Use enum class for pig_hamfile_version 2022-10-09 23:15:20 +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 f754b2d33a Avoid unnecessarily copying player name for display
If the player's name is presented without decoration, then it can be
rendered directly from the callsign buffer.  It only needs to be copied
to a temporary buffer if it will be decorated to reflect use of automap
or in-game messaging.
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 7c0fb7b12a Use std::span for load_bitmap_replacements argument level_name 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 9c4c49fe5e Return std::unique_ptr from d_strdup 2022-10-09 23:15:20 +00:00
Kp fbc184500d Use explicitly defaulted operator== for vms_vector 2022-10-09 23:15:19 +00:00
Kp 37701cf61f Remove unnecessary explicit definition of weapon_index::operator!= 2022-10-09 23:15:19 +00:00
Kp 428fad33c3 Fix clang-14 operator== ambiguity
clang-14 fails with:

```
similar/main/net_udp.cpp:4381:11: error: use of overloaded operator '!=' is ambiguous (with operand types 'exact_type<dcx::player>' and 'exact_type<const dcx::player>')
            if (&i != &self)
                ~~ ^  ~~~~~
common/include/pack.h:28:17: note: candidate function
    constexpr bool operator==(const T *rhs) const { return p == rhs; }
                   ^
common/include/pack.h:28:17: note: candidate function (with reversed parameter order)
1 error generated.
```

gcc handles the old form without error.
2022-10-09 23:15:19 +00:00
Kp cd3c88f4b6 Avoid copying level filename unnecessarily 2022-10-09 23:15:19 +00:00
Kp fc4157f56f Fix MacOS clang build of similar/2d/font.cpp
clang-14 on OSX, but not clang-14 on x86_64-pc-linux-gnu, fails
class template argument deduction when given:

```
	char *c1 = initializer();
	const char *c2 = c1 + 1;
	std::span{c1, c2};
```

clang correctly refuses to match this to `std::span(pointer, pointer)`,
but fails to find the constructor `std::span(iterator, sentinel)`.

Work around this by changing the type of the sentinel from
`const uint8_t *` to `color_palette_index *` (an alias of `uint8_t *`).

Reported-by: Kreeblah <https://github.com/dxx-rebirth/dxx-rebirth/issues/664>
2022-10-02 19:51:36 +00:00
Kp 5b7fb9c402 Reduce use of quotes for passing vers_id defines
Windows shells interpret quoting differently from Linux shells, causing
some of the generated strings to have ugly escape sequences in them.
Switch to passing the defined values as lists of character codes, so
that no quoting is needed.  This makes the command line uglier, but
produces more readable strings in the generated program.
2022-10-02 19:51:36 +00:00
Kp 90879d0796 Pass std::span to con_scrub_markup 2022-10-02 19:51:36 +00:00
Kp 3379078f04 Pass std::span to PHYSFSX_puts 2022-10-02 19:51:36 +00:00
Kp f3fae646f9 Pass std::span to warning_puts 2022-10-02 19:51:36 +00:00
Kp 53c1550254 Remove special case for 0 argument err_printf
Fix the remaining sites that were redirected by this.  Remove the
redirection macro.
2022-10-02 19:51:36 +00:00
Kp 0409e75278 Pass std::span to err_puts 2022-10-02 19:51:36 +00:00
Kp e0123dead5 Remove special case for 0 argument PHYSFSX_printf
Fix the remaining sites that were redirected by this.  Remove the
redirection macro.
2022-10-02 19:51:36 +00:00
Kp 01c07156bd Remove special case for 0 argument HUD_init_message
Fix the one remaining site that was redirected by this.  Remove the
redirection macro, so that the literal and variadic forms can have
differing types for their string field.
2022-10-02 19:51:36 +00:00
Kp f3d4dff941 Use enum class for clipping_code
Adjust code_window_point to use the same masks as clipping_code.
Previously, it had top and bottom swapped.  However, since its output
was only ever compared for equality to 0, this transposition should not
affect the observable behavior.
2022-10-02 19:51:35 +00:00
Kp 1808b6badd Use enum class for projection_flag 2022-10-02 19:51:35 +00:00
Kp e499dd55f7 Use std::span for piggy_write_pigfile argument filename 2022-10-02 19:51:35 +00:00
Kp aaac0e69fa Use std::span for piggy_new_pigfile argument pigname 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 73bcfb6d63 Simplify ogl_ubitblt_i GL array initialization
- Avoid zero-filling arrays that can be directly initialized with real
  values.
- Hold color_array const so it can be stored statically.
2022-10-02 19:51:35 +00:00
Kp eca189e8aa Use enum class for SoundOffset
Change piggy_register_sound to take the sound offset as a parameter,
rather than assuming the caller will set SoundOffset accordingly.

Remove a spurious sound reset in piggy_register_bitmap.  Based on the
duplicated comment, this was probably incorrectly copied from
piggy_register_sound, where it made sense, into piggy_register_bitmap,
where it does not.
2022-10-02 19:51:35 +00:00
Kp 14bf2dc59a Pass std::span to piggy_register_bitmap 2022-10-02 19:51:35 +00:00
Kp f0d118ed42 Use std::span for PHYSFSX_fgets 2022-10-02 19:51:35 +00:00
Kp 8fe9b8322d Check return value of PHYSFSX_fgets 2022-10-02 19:51:35 +00:00