Commit graph

5711 commits

Author SHA1 Message Date
Kp 4c681c40fd Factor out the slider font smoothing hack
Move the test from the innermost loop to one layer farther out, since it
was conditional on two specific passes of the innermost loop.
2021-09-04 12:17:14 +00:00
Kp 6172b69329 Convert more font.cpp sites to use xrange 2021-09-04 12:17:14 +00:00
Kp c99b67e359 Switch callers to unchecked_partial_range(range) where possible
Use unchecked_partial_range(range) instead of
unchecked_partial_range(iterator), since the range form can preserve the
underlying index_type.
2021-09-04 12:17:14 +00:00
Kp ef1c3d20c6 Compute required_buffer_size earlier in partial_range call tree
Push the computation up, so that invocations that differ only in the
length of their expression strings will resolve to the same template.

Rework unchecked_partial_range not to take expression strings if they
will not be used.
2021-09-04 12:17:14 +00:00
Kp 1354099b0d Move Computed_colors into gr_find_closest_color
- Inline add_computed_color into gr_find_closest_color, and then only
  one function will need access to Computed_colors.
- Allow the recent-choice bubble-up logic to apply to all elements
- If all entries are in use, always overwrite the last element in
  Computed_colors instead of picking one randomly.
2021-09-04 12:17:14 +00:00
Kp ae3dc7f934 Simplify computed color reset
gr_find_closest_color did not need it.  Remove it.  For the others,
resetting the count is sufficient.  There is no need to reset the
individual elements.
2021-09-04 12:17:14 +00:00
Kp 347b8d9f77 Factor out palette color search code 2021-09-04 12:17:14 +00:00
Kp fb3c2a4808 Narrow grs_canvas fg/bg color fields 2021-09-04 12:17:14 +00:00
Kp 35c7684200 Cache text color change control code
This generates the same code in an optimized build, but makes the intent
clearer.
2021-09-04 12:17:14 +00:00
Kp 21f736ec37 Require grs_subcanvas for gr_init_sub_canvas
Prevent passing a canvas that is not specifically typed as a
grs_subcanvas.
2021-09-04 12:17:14 +00:00
Kp 8eabce8f27 Disallow direct construction of grs_canvas
Require use of grs_main_canvas or grs_subcanvas instead.
2021-09-04 12:17:14 +00:00
Kp 1c90863d63 Move grs_main_bitmap earlier in the header 2021-09-04 12:17:14 +00:00
Kp 3cf612fe53 Simplify say_unused_tmaps
Reduce the number of physfs calls.  Use zip+range-for to iterate all the
sequences at once.
2021-09-04 12:17:14 +00:00
Kp 983ad86e4b Use enum class for trigger number 2021-09-04 12:17:14 +00:00
Kp 6ab3fb262b Add convenience function underlying_value
Add a helper to deduce the enum type of a value, and use an appropriate
std::underlying_type<T> expression for that enum type.  This avoids the
need to repeat the type of the enum at the site of each cast, and moves
the casts into the helper to make the callers easier to read.
2021-09-04 12:17:14 +00:00
Kp c58d26a791 Use trgnum_t more consistently 2021-09-04 12:17:14 +00:00
Kp 6dcd89d494 Try harder to pick distant segments for thief/powerup respawn 2021-09-04 12:17:14 +00:00
Kp 810be506a3 Inline AI path shuffle
- Use std::iota to initialize the translation array
- Switch from conditionally using either a linear count or the array to
  always using the array.  In non-random mode, the array is initialized
  and never shuffled, so it should produce the same effect as using the
  linear count, but avoids a branch in the loop.
- Switch to using std::shuffle driven by std::minstd_rand, rather than
  an inline swap loop using d_rand() to pick indices.
- Reorder the shuffle logic to have exactly one invocation in each game,
  so that the shuffle call itself can be eligible for inlining.
- Use std::uniform_int_distribution to decide whether to reshuffle in
  Descent 2.  Maintain the original logic that reshuffling happens 25%
  of the time.
2021-09-04 12:17:14 +00:00
Kp 9dca02a723 Report libpng version information in -verbose startup output 2021-08-31 02:20:06 +00:00
Kp 2c3a258d17 Fix bogus clang -Wunused-variable warning 2021-08-26 03:13:46 +00:00
Kp 5d39c52b0c Remote write-only field UI_GADGET::status 2021-08-26 03:13:46 +00:00
Kp 2a5562e671 Fix clang -Wformat warning in segment selection dialog
clang warns because %hu was used to format a value that is `unsigned`.
Change the format accordingly.
2021-08-26 03:13:46 +00:00
Kp 2b29f91edc Convert various PHYSFSX_printf to PHYSFSX_puts_literal
clang-12 warns when the format string checking logic indexes off the end
of a very short format string to PHYSFSX_printf.  In each case, the call
had no variadic arguments, so it can be switched to PHYSFSX_puts_literal
to make the code simpler and eliminate the warning.
2021-08-26 03:13:46 +00:00
Kp fb63a73bd1 Filter out robots at render time, not wakeup time
A robot that is rendered may be woken later, subject to some conditions.
Move the easily checked conditions into the renderer, so that robots
which will not be woken are never recorded.
2021-08-26 03:13:45 +00:00
Kp 40c22d0663 Move render_frame helper inline
Most call sites had the correct lifetime already, and those that did not
can easily gain it with an extra block scope.
2021-08-26 03:13:45 +00:00
Kp f047629051 Move glow special-case above g3_check_normal_facing
Checking the glow special case should be cheaper than computing and
checking the normal, so check the glow case first.  Also, when the glow
values are defined, cache the result of reading from it to avoid
repeating the indexing logic farther down.
2021-08-26 03:13:45 +00:00
Kp f9ed412ba6 Move use of SQUARE into a helper
Give the compiler discretion over whether to inline the multiplications.
2021-08-26 03:13:45 +00:00
Kp 172c183d83 Reduce scope of font rendering variables 2021-08-26 03:13:45 +00:00
Kp 517919a473 Remove unused return value of gr_internal_color_string, ogl_internal_string 2021-08-26 03:13:45 +00:00
Kp 4b062bd7b2 Reorder check_effect_blowup tests to reduce D2 redundancy
Switch from ((a && b) || (!a && c)) to (!a ? c : b).
2021-08-26 03:13:45 +00:00
Kp e0820e2825 Skip autosave while in demo playback modes
Reported-by: polstomo <https://github.com/dxx-rebirth/dxx-rebirth/issues/598>
2021-07-25 23:00:56 +00:00
Kp 56c98f5345 Improve error reporting for PHYSFSX_openWriteBuffered
Return the PHYSFS error code on failure, so that callers can report why
the open failed.
2021-07-25 23:00:56 +00:00
Kp 1c13d3c8d3 Improve error reporting for PHYSFSX_openReadBuffered
Return the PHYSFS error code on failure, so that callers can report why
the open failed.
2021-07-25 23:00:56 +00:00
Kp b2968c55da Improve error reporting for read_sndfile
Move error reporting down into read_sndfile, so that individual failure
paths can have specific error messages.
2021-07-25 23:00:56 +00:00
Kp a7cbf60922 Return error code from PHYSFSRWOPS_openRead*
This improves error reporting for movies.
2021-07-25 23:00:56 +00:00
Kp b814301120 Pass PhysFS error code to callers of PHYSFSX_addRelToSearchPath
Use PHYSFS_getLastErrorCode on the result.  This allows init_movie to
report the reason a movie was unavailable.
2021-07-25 23:00:56 +00:00
Kp 1227625e7c Remove unused return code of PHYSFSX_removeRelFromSearchPath 2021-07-25 23:00:56 +00:00
Kp c26fd86450 Keep builtin movies loaded until the end of main
Commit d0d7545ec1 ("Unload robot movies on exit") intended to shorten
the lifetime of the loaded data, but failed to save the unique_ptr, so
the lifetime was shortened more than intended.  Save the unique_ptr so
that the movies remain loaded.

Also, add a [[nodiscard]] annotation so that the compiler can warn if
this mistake is repeated.

Reported-by: Q3BFG10K <https://github.com/dxx-rebirth/dxx-rebirth/issues/599>
Fixes: d0d7545ec1 ("Unload robot movies on exit")
2021-07-25 23:00:56 +00:00
Kp cae9c5f26c Reduce intensity of player spawn sound 2021-06-28 03:37:51 +00:00
Kp 679d2fc494 Reduce intensity of weapon fire sounds 2021-06-28 03:37:51 +00:00
Kp 5ca182f4da Link robot sounds to the object, not a position
This should produce more reasonable results if a robot is moved rapidly
while the sound plays.
2021-06-28 03:37:51 +00:00
Kp 20372ad3f3 Reduce intensity of Robot_sound_volume
Recent work increased the effective intensity of various sounds.  Reduce
this one to compensate.
2021-06-28 03:37:51 +00:00
Kp bc210c2c05 Halve the volume of weapon changes
The previous commit removed an incorrect double scaling of the player's
weapon sounds, which will make all such sounds louder.  Players with
their FX volume set to maximum will now have twice as loud a sound.
Halve the intensity in the source to return to the volume such players
would have had before.  Players with an FX volume less than maximum will
still get a somewhat louder sound than before.
2021-06-28 03:37:51 +00:00
Kp 20a0166cf4 Avoid double-scaling sounds at start time
The SDL_mixer library has already been instructed, via Mix_Volume, to
scale the volume of sounds on all channels, by an amount based on
digi_volume.  There is no need to manipulate the effective distance of a
particular sound to further scale it by digi_volume.  Even if this
second scale was needed, it was done incorrectly, because it was only
applied when the sound was started, but not re-applied when the sound's
volume was updated due to positional changes.  As a result, any sound
which was updated would switch to an unscaled version.  Sounds which
were never updated, such as those attached to the viewer object, would
retain their original scaled volume.

Update the implementation of digi_mixer_set_channel_volume to call
Mix_SetDistance in the same way as digi_mixer_start_sound, for
readability and consistency.
2021-06-28 03:37:51 +00:00
Kp 659be87a5b Saturate return value of fix2byte 2021-06-28 03:37:51 +00:00
Kp 7cba352c19 Split digi_get_sound_loc
Some callers need to update an existing sound_object.  Other callers
need a temporary copy of the data for external use.  Rearrange the code
so that the latter type of caller can obtain the data without a pointer
indirection.
2021-06-28 03:37:51 +00:00
Kp e0008cceb3 Use enum class for sound angle parameter 2021-06-28 03:37:51 +00:00
Kp f233115d84 Make savegame menu inherit from newmenu 2021-06-28 03:37:51 +00:00
Kp d980648823 Use structured bindings for more zip calls 2021-06-28 03:37:51 +00:00
Kp 9c08b233a5 Move collision functions into namespaces 2021-06-28 03:37:51 +00:00