Commit graph

75 commits

Author SHA1 Message Date
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 dd260f234b Use auto type for Viewer in more places 2022-07-09 13:39:29 +00:00
Kp a70188e7a5 Move various static functions into anonymous namespace 2022-07-09 13:39:29 +00:00
Kp 86a32dd0ff Change enum sidenum_t to enum class sidenum_t 2022-06-05 17:44:52 +00:00
Kp 68268e9a1f Use sidenum_t in more places 2022-02-19 14:52:17 +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
Dmitry Grigoryev fbd05a1592 optimize include files (include what you use) 2021-02-06 21:38:50 +01:00
Kp 80fc124a63 Remove unnecessary definitions of static member variables
C++17 permits, but deprecates, this form.  Remove it to simplify the
code.
2020-12-27 22:03:09 +00:00
Kp c68dddd372 Move various definitions into namespaces 2020-12-19 16:13:26 +00:00
Kp 47c33cbd55 Use enum class for WALL_IS_DOORWAY_FLAG
This reduces the size of the debug information substantially.
2020-12-19 16:13:26 +00:00
Kp 038c6aef4d Move d_level_unique_object_state to a separate header
This is required to untangle the cross-inclusion of object.h and
morph.h.
2020-08-10 03:45:14 +00:00
Arne de Bruijn 294d54eb58 Workaround for missing forever flag in sound object demo recording
In the original code there was a 'Hack to keep sounds from building up...'
which changed a non-forever linked sound to a non-linked sound. Therefore
the forever flag wasn't needed in the demo files. The commit
4a98e796ab removed the hack, which caused
non-forever sounds to start looping on demo playback.
This commit restores the hack as far as demo files are concerned.

Reported-by: zicodxx <https://github.com/dxx-rebirth/dxx-rebirth/issues/477>
Fixes: 4a98e796ab ("Prevent stacking weapon rotation sounds")
2020-08-05 15:32:44 +02:00
Kp 46d72a29c0 Retire compiler-begin.h
This was once a compatibility shim, but compiler support for std::begin
has been required since 5e434cbe95 and no
issues have been reported.  Flatten the include tree by removing this
header and using the STL names directly.
2020-06-10 02:25:32 +00:00
Kp 53761500f1 Qualify uses of std::array 2020-05-02 21:18:42 +00:00
Kp 9cee93abb1 Require support for C++14 std::exchange 2020-05-02 21:18:42 +00:00
Kp ddc25b59b7 Explicitly zero-initialize object structure members
C++17 will require this in order for `object::object()` to be constexpr.
Add it here, before switching over.
2020-05-02 21:18:42 +00:00
Kp 30091902af Simplify valptridx types where possible
Switch valptridx::ptr to a reference type.
Switch valptridx::ptridx to a reference type or to ::ptr.

Fix up uses of operator-> accordingly.
2019-12-22 05:34:08 +00:00
Kp d2640462cb Backport D2's Dont_start_sound_objects to D1
Descent 2 has a hack, present as far back as I can trace, that
suppresses starting sounds during level load.  The original reason was
not recorded, but this hack has the useful side effect that it avoids
using uninitialized data when set_sound_sources tries to use a Viewer
that has not been reset for the objects of the new level.

Descent 1 lacks this hack, so an invalid Viewer is used, which may
trigger a valptridx trap if the undefined data has an invalid segment
number, and could cause memory corruption in builds which do not
validate the segment index.  The valptridx trap:

```
terminate called after throwing an instance of 'valptridx<dcx::segment>::index_range_exception'
  what():  similar/main/digiobj.cpp:389: invalid index used in array subscript: base=(nil) size=9000 index=65021
```

The backtrace leading to the trap:
```
d1x::digi_link_sound_common (viewer=..., so=..., pos=..., forever=<optimized out>, max_volume=<optimized out>, max_distance=..., soundnum=42, segnum=...) at similar/main/digiobj.cpp:389
0x00005555555a4e2d in d1x::digi_link_sound_to_pos2 (vcobjptr=..., max_distance=..., max_volume=32768, forever=1, pos=..., sidenum=4, segnum=..., org_soundnum=121) at similar/main/digiobj.cpp:483
d1x::digi_link_sound_to_pos (soundnum=soundnum@entry=121, segnum=..., sidenum=sidenum@entry=4, pos=..., forever=forever@entry=1, max_volume=32768) at similar/main/digiobj.cpp:490
0x00005555555c140d in d1x::set_sound_sources (vcsegptridx=..., vcvertptr=...) at similar/main/gameseq.cpp:817
d1x::LoadLevel (level_num=<optimized out>, page_in_textures=1) at similar/main/gameseq.cpp:1022
0x00005555555c2654 in d1x::StartNewLevelSub (level_num=-1, page_in_textures=<optimized out>) at similar/main/gameseq.cpp:1865
```

Backport this hack into Descent 1.  Ultimately, the hack should go away
and data should be loaded in an order that does not access undefined
memory.

Reported-by: Spacecpp <https://github.com/dxx-rebirth/dxx-rebirth/issues/463>
2019-10-26 23:13:14 +00:00
Kp 8764cad457 Use unsigned in more prototypes 2019-03-03 00:31:09 +00:00
Kp 1008ab397e Move Objects to d_level_unique_object_state 2019-03-03 00:31:08 +00:00
Kp 30a83eec41 Eliminate some uses of valptridx::operator-> 2018-06-24 05:06:15 +00:00
Kp 4a98e796ab Prevent stacking weapon rotation sounds
digi_play_sample_once is supposed to cancel prior instances of the
sound, but that functionality was lost in
21082c6db2.  As a result, the sound can be
stacked up to the limit of the engine.  Even when the functionality
existed, its implementation was wrong.

- Change these sounds to be attached to the player generating them.
- Pass the cancellation flag to other players when sending a sound.
- Send the full value of `volume`, rather than truncating it.
- Implement cancellation by killing and restarting the earlier version of a cancelled sound.
- Delete an ugly hack that prevented the patched logic from ever running.
- Fix an ancient quirk in digi_mixer that caused it to report all sounds as not playing, which then caused digi_sync_sounds to instantly cancel the new sound.

Reported-by: Mako88 <https://github.com/dxx-rebirth/dxx-rebirth/issues/88>
Reported-by: ryusei117 <https://github.com/dxx-rebirth/dxx-rebirth/issues/88#issuecomment-269597361>
Fixes: 21082c6db2 ("Added own channel management to SDL_mixer sound interface since the builtin channel management of this lib cannot handle our needs; Little code cleanup")
2018-05-13 03:14:34 +00:00
Kp 88832e3679 Use constexpr integral_constant for various magic numbers 2017-10-14 17:10:30 +00:00
Kp e8d82d7d85 Pass valptridx factories to static functions 2017-07-26 03:15:59 +00:00
Kp adcf02e454 Expand tt:: indirection to std::
All supported compilers have an acceptable <type_traits>.  Commit
4cb3d46148 ("Move <type_traits> test to Cxx11RequiredFeature") made
<type_traits> support mandatory in August and no one has objected.
Remove the indirection and use namespace std directly for type_traits
members.
2017-06-25 20:46:03 +00:00
Kp 599ac9dee0 Always qualify valptridx type/factory
Previously, valptridx used PREFIX for allow-invalid+mutable, c#PREFIX
for allow-invalid+const, v#PREFIX for require-valid+mutable, vc#PREFIX
for require-valid+const.  Convert the types, factories, and all usage
sites to specify a qualifier for all four combinations:

	im#PREFIX -> allow-invalid+mutable
	ic#PREFIX -> allow-invalid+const
	vm#PREFIX -> require-valid+mutable
	vc#PREFIX -> require-valid+const

Changes to common/include/valptridx.h and common/include/fwd-valptridx.h
are manual.  All other changes are generated by:

	git grep -lz -e '\(obj\|seg\|clwall\|wall\|actdoor\|trg\)\(ptridx\|ptr\|idx\)\(_t\)\?\>' | xargs -0 sed -i -e 's/\<\(v\?\)\(\(obj\|seg\|clwall\|wall\|actdoor\|trg\)\(ptridx\|ptr\|idx\)\(_t\)\?\)\>/\1m\2/g'

for the 'm' prefix and:

	git grep -lz -e '\(obj\|seg\|clwall\|wall\|actdoor\|trg\)\(ptridx\|ptr\|idx\)\(_t\)\?\>' | xargs -0 sed -i -e 's/\<\([cm]\(obj\|seg\|clwall\|wall\|actdoor\|trg\)\(ptridx\|ptr\|idx\)\(_t\)\?\)\>/i&/g'

for the 'i' prefix.
2017-06-10 03:31:02 +00:00
Kp 0cfd7c8dbd Remove unused variable SOF_PLAYING 2016-07-21 01:43:21 +00:00
Kp 279dc555dd Propagate digiobj MAX_Q 2016-07-15 03:43:02 +00:00
Kp 3ebf1f009f Reorder digiobj channel clear 2016-07-15 03:43:02 +00:00
Kp 946e7bd4ee Move some digi symbols to dcx 2016-07-15 03:43:02 +00:00
Kp 74299f7e88 Encourage tail call optimizations in digiobj 2016-07-15 03:43:01 +00:00
Kp a3ae630829 Remove default argument for basic_ptridx(index) 2016-01-09 16:38:14 +00:00
Kp 9ceedc96a8 Propagate valptridx requirement up 2016-01-09 16:38:14 +00:00
Kp 98f5afa9f8 Remove default argument for basic_ptr(pointer,array &) 2016-01-09 16:38:13 +00:00
Kp 93f3162a41 Move SysLowMem to CArg 2015-12-24 04:01:26 +00:00
Kp 26e948d5f1 Uninline namespace dsx 2015-12-13 18:00:49 +00:00
Kp 232cc324f9 Use inline namespace dsx for similar/arch/sdl/ 2015-12-13 18:00:48 +00:00
Kp ed55763603 Remove unused symbols 2015-12-04 03:36:31 +00:00
Kp fee144261f Add if-D2 to Dont_start_sound_objects
Dont_start_sound_objects is defined for D1, but never set.  Restrict it
to D2 and let D1 skip the test.
2015-11-26 02:56:55 +00:00
Kp 954f0f8603 Remove unused SOUND_3D_THRESHHOLD 2015-11-24 04:05:36 +00:00
Kp 6870b48710 Remove unused return value of digi_link_sound_to_object* 2015-08-05 02:59:02 +00:00
Kp 9fb9aef509 Remove unused return value of digi_link_sound_to_pos 2015-08-05 02:59:02 +00:00
Kp 49b0868230 Fix ambiguous return when constructor inheritance is missing
gcc-4.7 (and, if constructor inheritance is suppressed, later versions)
reject

	return objnum == object_none ? vcobjptr(static_cast<objnum_t>(object_first)) : objnum;

where objnum is a cobjptridx:

similar/main/digiobj.cpp: In lambda function:
similar/main/digiobj.cpp:564:85: error: operands to ?: have different types 'valptridx<object>::vcptr' and 'valptridx<object>::cptridx'
similar/main/digiobj.cpp:564:85: error: inconsistent types '<type error>' and 'valptridx<object>::vcptr' deduced for lambda return type

Fix it by removing the ternary operator and adding an appropriate
conversion cast.
2015-08-03 03:11:25 +00:00
Kp 8eab601e44 Make digi_sync_sounds objp const 2015-07-10 03:22:26 +00:00
Kp 5cc38ea06c Pass vcsegptridx to digi_link_sound_to_pos 2015-05-28 03:08:39 +00:00
Kp ae8b99ae7d Use RAIIdigi_sound for briefing printing_channel 2015-04-02 02:36:55 +00:00
Kp 91d31b1952 Wrap object signature in subtype 2015-03-22 18:49:21 +00:00
Kp c5f6a115ec Add <stdexcept> for files that throw std::runtime_error 2015-03-22 04:16:49 +00:00
Kp 2458078987 Skip digi_sync_sounds loop if !Viewer
If a sound is used, it may dereference Viewer.  If Viewer is null, this
will crash.  In 630f11945e,
digi_sync_sounds changed to assume Viewer is valid.  This crashes during
early startup when not using the SDL_mixer backend, even though no
sounds are in use.

Reported-by: derhass <https://github.com/dxx-rebirth/dxx-rebirth/issues/45>
Fixes: 630f11945e ("Cache Viewer in digiobj")
2015-03-15 18:52:52 +00:00