Commit graph

6437 commits

Author SHA1 Message Date
Kp 606790f1c5 Inline read-only Do_dynamic_light 2023-05-27 13:19:31 +00:00
Kp 695e8b9ba1 Use memcpy for font filename
Prefer memcpy with a predetermined length, rather than strncpy, which
could leave the buffer without a terminator.  No current callers could
cause the lack of a terminator, but gcc-13 warns about it, so rearrange
the code to fix the warning.
2023-05-20 16:37:26 +00:00
Kp 3330b17cdb Use enum class for gamefont_conf::font_index 2023-05-20 16:37:26 +00:00
Kp c6e14fa74f Use std::array for font filenames 2023-05-20 16:37:26 +00:00
Kp bd050d73b2 Shrink a_gamefont_conf::name
Callers always load a DOS 8.3 filename into name, so shrink it from
64 characters to 16 characters.
2023-05-20 16:37:26 +00:00
Kp 5ca2f59619 Validate last_hitobj on game load
Testing for `object_none` is insufficient.  Games saved before the fix
for 14cdf1b352 may have a `last_hitobj` of
`0x1ff`, which triggers an exception when constructing `icobjidx_t`.
Treat any invalid object index as `object_none`.

Reported-by: Quix0r <https://github.com/dxx-rebirth/dxx-rebirth/issues/716>
2023-05-15 23:52:18 +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 c21c317441 Reset Buddy_objnum when buddy is deleted
Various code assumes that Buddy_objnum maintains the invariants:
- If the guidebot exists, Buddy_objnum must refer to it.
- If no guidebot exists, Buddy_objnum must be object_none.

This was not enforced, so if the guidebot is killed, Buddy_objnum can
continue to refer to its last index.  That can cause spurious errors
later.  For example, when the player enters an energy center, if the
guidebot is dead and the guidebot's last goal was "Find energy center",
then the console reports:

```
BUG: buddy is object 28, but that object is type 255.
```

Fix that by clearing the guidebot index when the guidebot is killed.
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 da39846514 Remove unnecessary pointer in savegame_newmenu_items
The pointer is only used by the constructor, so there is no need to
store it in the object.

Rework the allocation of the trailing storage to avoid the use of
placement new on a uint8_t[].
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 c0c4ee7049 Inline obj_link into compress_objects
This is only called in one place, so manually inline it to keep the
logic together.
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 8eec1dc810 Eliminate unnecessary string copy in PHYSFSX_addRelToSearchPath
Pass a mutable buffer from the caller, and allow
PHYSFSX_addRelToSearchPath to adjust the capitalization in that buffer,
rather than creating a copy in a stack local.  This can slightly affect
status messages that use the name, but otherwise should have no effect
on the game.
2023-05-13 15:02:55 +00:00
Kp e7d73e8493 Use RAII to manage SDL_LockAudio state 2023-05-13 15:02:55 +00:00
Kp 4bdc31a729 Simplify movie stream ownership
Store an owned pointer in MVEFILE instead of storing an unowned pointer
there and requiring the caller to keep the owned pointer alive for the
lifetime of the MVEFILE.
2023-05-06 19:26:19 +00:00
Kp 60a36a881f Move bmread texture_count into local scope 2023-04-29 16:10:28 +00:00
Kp e5a8393cc3 Pass context to set_texture_name 2023-04-29 16:10:28 +00:00
Kp 5b4bf16bfa Remove support for -DSWAP_0_255
This has been broken since b1c5307eb1
changed the type of gr_palette from `uint8_t[256*3]` to
`array<rgb_t, 256>`.  Remove it, since no one has reported it in 10
years.
2023-04-23 21:45:31 +00:00
Kp f37845b483 Move Descent 2 specific automap colors to d2x 2023-04-23 21:45:31 +00:00
Kp 03a06d71d5 Merge branch 'd2-superlaser-no-penalty' into master 2023-04-22 15:02:12 +00:00
Kp 5534e10d74 Add further comments around the laser damage penalty logic
Due to original game bugs, which Rebirth intentionally replicates in
order to match the balance of the original game, the logic looks odd.
Add comments explaining that the oddity is intentional.
2023-04-22 15:02:12 +00:00
Kp c98b30ca23 Reduce console colors to in-range values
`gr_find_closest_color` takes inputs in the range [0, 63].  Clamp input
values to fit in that range.
2023-04-22 14:56:35 +00:00
Kp e55bd77472 Document type of gr_find_closest_color_15bpp input 2023-04-22 14:56:35 +00:00
Kp 44086eb539 Remove unused macro BM_RGB 2023-04-22 14:56:35 +00:00
AlumiuN d93787d942 Fix inaccurate handling of D2 super laser damage with quad-lasers (as D2 was bugged and didn't apply the intended penalty to them) 2023-04-21 12:16:54 +12:00
Kp 0b066d23b4 Use enum class for load_palette arguments 2023-04-15 19:11:14 +00:00
Kp f10a79f157 Pass menu_filename to nm_draw_background1 2023-04-15 19:11:14 +00:00
Kp c49598d5f5 Merge commit 'clang-warnings' into master 2023-04-08 20:12:32 +00:00
Kp 51bb01f9f4 Merge commit 'sdl2-audio-Windows' into master 2023-04-08 20:12:07 +00:00
Kp 8c718335b8 Merge commit 'windows-shift-alt-f4' into master 2023-04-08 20:10:52 +00:00
Kreeblah 980c03b9ae
Fix Apple Clang errors and warnings 2023-04-06 16:42:49 -07:00
Arne de Bruijn 0de6290cd6 Make sure SDL2 uses specified audio format
Use extended open function Mix_OpenAudioDevice to set allowed_changes
to 0.
Prevents higher pitched sound on Windows.
2023-04-06 19:27:43 +02:00
Arne de Bruijn 4832fc319e Support Alt+Shift+F4 with SDL2 on Windows 2023-04-05 19:16:16 +02:00
Kp ae3f4ab533 Return computed filename from removeext 2023-04-02 10:15:20 +00:00
Kp 488278ddfe Fix build for sdlimage=0
Fixes: 2ded2b2d0c ("Make kmatrix background optional")
2023-03-25 12:41:29 +00: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 114cdef1d2 Remove unused argument to parse_bmhd
clang-15 warns for a write-only parameter.  The parameter is only used
in a debug print, which has been commented out since the code was
originally imported.  Remove the parameter and the commented print.
2023-02-26 18:42:12 +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 f2acbf443a Move digi_mixer_init to namespace dcx 2023-02-04 19:21:25 +00:00
Kp f0f669e8ab Use sentinel for null_sentinel_iterator end() 2023-02-04 19:21:25 +00:00
Kp 3aef1ee569 Tighten PHYSFSX_counted_list_template reset rules
Prefer move-assignment over use of reset() so that the count cannot go
out of sync from the list.

Shorten lifetime of some lists.
2023-02-04 19:21:25 +00:00
Kp da90b6801e Move JukeboxSongs.num_songs into local scope
It is only needed briefly during loading, so do not store it in a global
variable.
2023-02-04 19:21:25 +00:00
Kp 1f5e9808e5 Pass std::span to rotate_list 2023-02-04 19:21:25 +00:00
Kp a582b4ee82 Remove write-only g3d_interp_outline 2023-02-04 19:21:25 +00:00
Kp 0e1219a66b Factor out texture setup to get_texture 2023-01-29 20:42:03 +00:00
Kp 4f37720882 Use enumerated_array for ambient sound depth tracking 2023-01-29 20:42:03 +00:00
Kp fecc1f102f Use enum class for clwallnum_t 2023-01-29 20:42:03 +00:00