Commit graph

4719 commits

Author SHA1 Message Date
Kp ec1cf005b6 Enable -Wformat-truncation
Add macro cf_assert ("control flow" assert) to hint to gcc that certain
conditions are impossible.  Use it to avoid generating range checks for
situations that never happen.  If the event did happen, the only
consequence would be truncated UI text, rather than a correctness
problem.
2018-08-26 18:10:36 +00:00
Kp dc0a405222 Factor out piggy bitmap loading code 2018-08-26 18:10:36 +00:00
Kp 32561c5d0a Use partial_range for piggy_does_bitmap_exist_slow 2018-08-26 18:10:36 +00:00
Kp 047ddaf9ea Prevent buffer overrun in removeext 2018-08-26 18:10:36 +00:00
Kp 6a96e30495 Merge commit 'Quiet FSRef warnings' into master 2018-08-26 16:14:02 +00:00
C.W. Betts b9c6d59f11 Remove the forcing of null-termination of fullPath on OS X:
CFURLGetFileSystemRepresentation should already null-terminate its buffer.
2018-08-23 22:12:56 -06:00
C.W. Betts 0c48d99d2b Match the coding style of the rest of the document. 2018-08-23 21:29:03 -06:00
C.W. Betts 9cfa12c0fe Use sizeof(fullPath), as suggested by @vLKp. 2018-08-23 21:28:04 -06:00
Kp bba8a327a0 Remove use of -Wno-implicit-fallthrough 2018-08-24 02:58:21 +00:00
C.W. Betts 746b61da8d Wrap the gobbler up in a preprocessor guard. 2018-08-22 12:10:33 -06:00
C.W. Betts e2a33dc81f Replace FSRef-dependant calls to CoreFoundation equivalents. 2018-08-21 13:40:25 -06:00
C.W. Betts fdf5a37c35 gobble up -psn command line options.
Should fix #387.
2018-08-21 13:04:21 -06:00
Kp a8d5f83770 Remove reset_walls
Nothing should access the unassigned walls, so there is no need to clear
them.
2018-08-12 21:08:07 +00:00
Kp 36ada21c0c Fold exploding walls into regular walls 2018-08-12 21:08:07 +00:00
Kp dc4fcf8a35 Flip sense of is_door_free 2018-08-12 21:08:07 +00:00
Kp 8257232ecc Pass wclip & to wall_set_tmap_num 2018-08-12 21:08:07 +00:00
Kp b316afc30f Clear exploding walls during init 2018-08-12 21:08:07 +00:00
Kp 8bbdeedeb2 Consolidate stuck object state
Move it to a structure.  Make all the modifiers methods.  Change all
callers of those methods to pass the structure.  This makes the stuck
object handling free of direct access to global game data.
2018-08-04 17:52:57 +00:00
Kp 57334255ac Simplify stuck object cleanup 2018-08-04 17:52:57 +00:00
Kp eff80c2d13 Fix format string warnings for win64 2018-08-03 04:08:12 +00:00
Kp 1b8ff6ac77 SDL2-mixer: fix noise from reading undefined sound data
Commit a833d73d44 added the SDL_mixer backend for Rebirth sound.  That
commit set the length of the converted sound equal to the size of the
buffer that SDL requested as a work area.  No one ever touched that
logic, until now.  In SDL1, that choice worked fine.  In SDL2, this
causes garbage to play after the sound, because SDL2 considers the
buffer to be defined only up to the length returned in
`SDL_AudioCVT::cvt_len`.  Bytes beyond that length are undefined[1], and
in practice contain garbage.  Fix the noise by setting the sound length
equal to the length returned by SDL2, so that the undefined bytes are
not treated as sound.  SDL1 also maintains this length value, so no
version-specific logic is required.

[1]: https://wiki.libsdl.org/SDL_ConvertAudio

Reported-by: heftig <https://github.com/dxx-rebirth/dxx-rebirth/issues/396>
2018-07-30 00:49:59 +00:00
Kp 726233e043 Fix sdlmixer=0 build of songs.cpp 2018-07-30 00:49:59 +00:00
Kp f491059ed7 Enable building with SDL2
This commit enables Rebirth to build with SDL2, but the result is not
perfect.

- SDL2 removed some sticky key support.  Rebirth may behave differently
  now in this area.
- SDL2 removed some key-repeat related support.  Rebirth may behave
  differently now in this area.
- SDL2 gained the ability to make a window fullscreen by sizing it to
  the desktop instead of by changing the desktop resolution.  Rebirth
  uses this, and it mostly works.
  - Resizing while in the automap does not notify the automap code, so
    the view is wrong until the player switches out of automap mode and
    back in.
- SDL2 changed how to enumerate available resolutions.  Since
  fitting the window to the desktop is generally more useful than
  fitting the desktop to the window, I chose to drop support for
  enumerating resolutions instead of porting to the new API.  Users can
  now enter an arbitrary window dimension and Rebirth will make an
  attempt to use it.
  - It might be useful to cap the window dimension at the desktop
    dimension, but that is not done yet.
  - Entering fullscreen mode through the Controls->Graphics submenu
    failed to notify the relevant subsystems, causing the rendered
    content not to rescale.  For now, compile out the option to toggle
    full screen through that menu.  Toggling through Alt+Enter works
    properly.

Despite these quirks, this is a substantial improvement over the prior
commit, where SDL2 cannot be used at all.  The remaining issues can be
resolved in future work.

References: <https://github.com/dxx-rebirth/dxx-rebirth/issues/82>
2018-07-28 23:22:58 +00:00
Kp 289e984e10 Reduce scope of function-local constants 2018-07-22 04:46:19 +00:00
Kp 75d7eb6dce Skip paging in vclip entries with invalid num_frames
User Nemesis reported an unspecified crash, but never responded to
inquiries to provide more data.  Users Tourmeister and Buff Skeleton
reported a fatal exception thrown while paging in a vclip, with initial
triggering conditions matching the report from Nemesis.  Both
Tourmeister and Buff Skeleton are using v1.0 Descent 2 data.  No one
with more recent data has reported a problem.

Add a try { ... } catch { ... } block to trap the partial_range
exception, log it, and then ignore paging in that vclip.  This should
approximate what 0.58.1 did, assuming that the crash is due to a
negative `num_frames`.  If the crash is due to a large positive
`num_frames`, this change will still prevent the previously reported
crash, but may only move the crash elsewhere.  Various other subsystems
react badly to using a vclip that has not been paged in.

This change is tested not to break an otherwise working game.  It is not
tested to confirm that it produces a working game for users who
experienced a crash without it.

Reported-by: Tourmeister <https://forum.dxx-rebirth.com/showthread.php?tid=943&pid=12159#pid12159>
Reported-by: Buff Skeleton <https://forum.dxx-rebirth.com/showthread.php?tid=943&pid=12290#pid12290>
References: <https://github.com/dxx-rebirth/dxx-rebirth/issues/371>
2018-07-18 04:39:28 +00:00
Kp 19699037ce Move d2x-rebirth/main/bmread.cpp -> similar/main/bmread.cpp 2018-07-18 04:39:28 +00:00
Kp 20f1934312 Move Redbook audio behind DXX_USE_SDL_REDBOOK_AUDIO
Currently, DXX_USE_SDL_REDBOOK_AUDIO is an alias for !SDL2.  However,
this patch enables interested users to readily patch out Redbook even
for SDL1.

References: <https://github.com/dxx-rebirth/dxx-rebirth/issues/82>
2018-07-14 17:23:15 +00:00
Kp 5d74fd48b5 Fix player appearance sound truncation
The player appearance sound was tied to the player appearance vclip,
but this is wrong because the vclip has a shorter lifetime than the
sound.  This mistake was previously hidden by the hack that caused
non-permanent sounds to be routed off to a separate queue that lost the
association between object and sound.  Commit 4a98e79 eliminated that
hack because it complicated the work of that commit.  However, without
the hack, object sound effects cannot outlive their host object.

Fix this by binding the sound to the position of the appearance effect,
not to the appearance object.  This works since the appearance effect
cannot move, so there was no value to binding the sound to the object.
This solution could not be used for objects that move and terminate
before their associated sound effect.

Reported-by: Ryusei117 <https://github.com/dxx-rebirth/dxx-rebirth/issues/88#issuecomment-390054173>
Fixes: 4a98e796ab ("Prevent stacking weapon rotation sounds")
2018-07-14 17:23:15 +00:00
Kp d97afc2ad5 Retain directory structure in New Game dialog
User jcotton42 suggested copying a D2X-XL feature: preserving the
directory structure of the user's missions area when showing a New Game
dialog.  This was substantially more trouble than it should have been,
but the result is good.

Previously, the dialog presented all missions at any depth below the
starting point, and sorted them as if they were all in the root
directory.

Now:
- Empty directories are hidden entirely.  There is nothing for the user
  to do in them, so there is no point showing them.
- A directory with exactly one entry has that entry promoted into the
  parent, since there is no ambiguity about what the user would want.
  If the parent in turn has only that one promoted element when the scan
  of the parent finishes, then the element can be promoted up again.
  This continues until the root is reached or until a level has more
  than one entry.  For this purpose, both missions and directories count
  as entries.
- Directory entries are decorated to inform the user how many
  immediate subdirectories are present, how many missions are present
  immediately in the directory, and how many missions total are present,
  counting all subdirectories.  If there are zero immediate
  subdirectories, then the directory count is not shown.  For this
  purpose, directories that were hidden due to a lack of missions are
  not counted.
- Sub-dialog boxes for inner directories use a title that reminds the
  user of the path so far, and recaps the directory/mission statistics.
- On entry to the New Game dialog, if the last played mission is in a
  sub-dialog, appropriate sub-dialogs are opened so that the last played
  mission can be pre-selected.

Currently, there is no in-game override to return to the prior rollup
rules.

Requested-by: jcotton42 <https://github.com/dxx-rebirth/dxx-rebirth/issues/392>
2018-07-03 05:59:40 +00:00
Kp db80a88ad2 Improve error message on failure to load mission 2018-07-03 05:59:39 +00:00
Kp 1da76dde7d Fix SDL-only build of gauges.cpp
Even when empty and default-constructible, const members must be
explicitly constructed.  Add a default constructor to do this.

Fixes: 893e8cde06 ("Combine hud gauge parameters")
2018-06-30 21:53:55 +00:00
Kp da268c6d21 Preprocess out glmprintf in normal builds
Using sizeof(con_printf A) was a trick to avoid code generation, but it
interacts badly with gcc-6 and the other macros that con_printf
produces.  On >=gcc-6, `DXX_ALWAYS_ERROR_FUNCTION` is a complicated hack
to work around undesirable changes in `__builtin_constant_p`.  That hack
includes introducing a dummy type.  gcc-6 rejects declaring a type
inside a statement expression inside a sizeof.  gcc-7 permits this, so
it went unnoticed.

This particular usage was to prevent future regressions in calls that
had been broken for years without anyone noticing.  As such, reverting
to not checking those calls is unlikely to matter.

Reported-by: Ambaire <https://github.com/dxx-rebirth/dxx-rebirth/issues/393#issuecomment-401565872>
Fixes: 9b17450914 ("Fix up long broken glmprintf support")
2018-06-30 21:53:55 +00:00
Kp 90dfedb5cb Fix gauges.cpp for gcc-5
gcc-5 rejects `V == V::E` where the first V is a variable of type V and
the second V is a scope specifier to indicate the member E in the type
V.  gcc-7 permits this.

Fixes: 5cafec2268 ("Use enum for gauges weapon_type")
2018-06-30 21:53:55 +00:00
Kp 9dafe85bbf Simplify clamping color values in SDL palette setup 2018-06-29 03:24:36 +00:00
Kp 60a99f1ea2 Allow longer mission titles in New Game dialog 2018-06-27 03:34:34 +00:00
Kp 30a83eec41 Eliminate some uses of valptridx::operator-> 2018-06-24 05:06:15 +00:00
Kp c97b41404c Factor out pick_connected_drop_segment 2018-06-24 05:06:15 +00:00
Kp 6fca290663 Pass object& to read_flying_controls 2018-06-24 05:06:15 +00:00
Kp 0fd7e0e4ce Pass context arrays to WALL_IS_DOORWAY 2018-06-24 05:06:15 +00:00
Kp 3408e3a0cd Switch to shared_segment arguments where possible 2018-06-24 05:06:15 +00:00
Kp 20caecfa0e Eliminate most uses of segment * 2018-06-24 05:06:15 +00:00
Kp fb68e7f9ec Eliminate use of side * 2018-06-24 05:06:15 +00:00
Kp 0c3e99f14c Split side uses based on shared vs unique 2018-06-24 05:06:15 +00:00
Kp 98e6b36145 Pass shared_segment for some segment I/O 2018-06-24 05:06:15 +00:00
Kp 2de3a1dd06 Pass unique_segment to objects_in 2018-06-24 05:06:14 +00:00
Kp 4ae88b6594 Pass only shared_segment to compute_segment_center 2018-06-24 05:06:14 +00:00
Kp 6d0d68d188 Split some segment uses based on shared vs unique
Leave `sides` in `shared_segment` to minimize churn.  Parts of it must
move to `unique_segment` before this project finishes.
2018-06-24 05:06:14 +00:00
Kp 06f10c88f5 Fix stack buffer overflow in tracker handling
`memcpy(a, b, strlen(b));` is just a complicated way of writing
`strcpy(a, b);`, but even more dangerous since it omits the null
terminator.  `strcpy` on untrusted data is always unsafe, and this data
does not appear to be checked before use.  There is no need to copy the
data before using it, so switch to using it in place.  This eliminates
the security problem and makes the code slightly smaller.

Fixes: 730879d733 ("Updated handling of data sent by tracker. ...")
2018-06-22 04:42:18 +00:00
Kp 144515ff88 Warn users about tracker NAT hole punch feature
The new tracker automatically exposes LAN games to the Internet.  This
surprised one user rather badly, prompting him to think he had been
hacked.  Add a first-host warning explaining the feature and asking the
user to choose whether to enable NAT hole punch.

Reported-by: Tourmeister <https://forum.dxx-rebirth.com/showthread.php?tid=943&pid=12179#pid12179>
References: <https://github.com/dxx-rebirth/dxx-rebirth/issues/372>
Fixes: 730879d733 ("... Added support for handling ACKs from tracker and Hole punching between game clients via tracker. ...")
2018-06-21 03:08:36 +00:00
Kp e3d42913a4 Remove always-disabled editor/segment.cpp code
Various functions are preprocessor-excluded by `BOTTOM_STUFF`, which has
been 0 since btb added it in a196e6d554
(October 2001).  It seems unlikely that anyone will miss it.
2018-06-20 04:16:06 +00:00