Commit graph

4937 commits

Author SHA1 Message Date
Kp 9ebb32c111 Pass d_level_shared_segment_state to trace_segs 2018-09-19 02:13:30 +00:00
Kp c2944896de Pass vertex factory to create_shortpos_native 2018-09-19 02:13:30 +00:00
Kp 9cedc53f52 Pass vertex factory to extract_orient_from_segment 2018-09-19 02:13:30 +00:00
Kp 1527785efd Pass vertex factory to validate_segment_side 2018-09-19 02:13:29 +00:00
Kp adf41c19c2 Pass vertex factory to check_for_degenerate_segment 2018-09-19 02:13:29 +00:00
Kp 68de87c0e5 Pass vertex factory to check_for_degenerate_side 2018-09-19 02:13:29 +00:00
Kp d71938e1a7 Pass vertex factory to create_walls_on_side 2018-09-19 02:13:29 +00:00
Kp bd58d5f825 Pass vertex factory to extract_*_vector_from_segment 2018-09-19 02:13:29 +00:00
Kp 82a2fa525c Pass Robot_info, valptridx factories to more methods 2018-09-19 02:13:29 +00:00
Kp 01512015a8 Move Num_segments to new d_level_shared_segment_state 2018-09-19 02:13:29 +00:00
Kp c56223ced4 Eliminate more uses of valptridx::operator-> 2018-09-19 02:13:29 +00:00
Kp a65068fed1 Move OGL RLE bitmap buffer to stack
Shrink it from 1MB to 300KB.  Add a diagnostic if the expansion fails
due to insufficient capacity.

300KB is required for the ship cockpit bitmap.  Everything else seems to
be smaller.
2018-09-19 02:13:29 +00:00
Kp 56d44459d4 Enable SHAREPATH for non-LinuxPlatformSettings 2018-09-14 02:20:55 +00:00
Kp e6ea981ab4 Generalize marker object number init 2018-09-09 01:00:39 +00:00
Kp c4cb930f8e Pass ObjectState to obj_delete 2018-09-09 01:00:39 +00:00
Kp 0df57f5b0f Fix retail bug that prevented marker spinning
Markers were given a spin rate, but a movement type of MT_NONE, so the
spin rate was ignored.  Change movement type to MT_SPINNING.
2018-09-06 02:03:29 +00:00
Kp 12b57e84e6 Switch most in-tree http:// links to https://
For each link given as http://, verify that the site is accessible over
https:// and, if so, switch to it.  These domains were converted:

* llvm.org
* clang.llvm.org
* en.cppreference.com
* www.dxx-rebirth.com
* www.libsdl.org
* www.scons.org
2018-09-02 00:57:29 +00:00
Kp 97ad0b0be4 Fix editor non-PCH build of similar/main/piggy.cpp 2018-08-29 01:47:42 +00:00
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
Kp 0886aee3ea Always destroy control center when kill goal timer expires
Prior releases destroyed the control center when the kill goal timer
expired, even if no player had scored any kills.  General cleanup of
kill goal quirks eliminated this odd rule, but players liked the old
rule and want it back.  Restore it.
2018-06-20 04:16:06 +00:00
Kp 1d6ff380f7 Jump thread wall_is_doorway 2018-06-20 04:16:06 +00:00
Kp 946d5e19cb Pass screen width/height to HUD_SCALE_X/HUD_SCALE_Y explicitly 2018-06-20 04:16:06 +00:00
Kp a0fd264133 Tighten checks on create_path_points parameters 2018-06-20 04:16:06 +00:00
Kp fa8253fe22 Fix -Wsign-compare warnings in morph.cpp 2018-06-18 04:11:40 +00:00
Kp c8b04d0c83 Allow more items on screen in a listbox 2018-06-18 04:11:39 +00:00
Kp 6f4270ecd8 Store mission list filenames inside mission_menu 2018-06-18 04:11:39 +00:00
Kp 2f4524d3c2 Add screenshot=none to disable screenshot support
Per comment from kreator, some Apple systems now ship without a working
print screen key.  It makes no sense to provide print screen support
bound to a key which does not exist.  Add `screenshot=none` and activate
it on OS X to remove the unreachable screenshot support.
2018-06-16 04:13:37 +00:00
Kp d7bb190621 Fix assertion on close of game over window 2018-06-15 02:58:01 +00:00
Kp c991f8b107 Prevent Point_segs underflow on player death
If the player commits suicide in Descent 2, Point_segs[-2] is accessed
because aip->hide_index = -1, aip->path_length = 0.  As a spot fix,
check for underflow and skip the access if it would be out of bounds.
2018-06-14 02:39:15 +00:00
Kp 8690bf4ca7 Change handling of explicitly blank briefings
Prior versions of Descent had a bug that specifying `briefing=` did not
inhibit a briefing.  Instead the directive was completely ignored.  The
engine would then use the auto-detected briefing if one was found.  This
quirk was eliminated during refactoring of the mission parsing code.
Unfortunately, some published missions relied on this bug: they ship a
briefing, but their mission file explicitly states that there is no
briefing.  Players expect the briefing to play despite the mission
stating that there is none.

Reorder the logic to restore the bug that `briefing=` is ignored.

Reported-by: Calmarius <https://forum.dxx-rebirth.com/showthread.php?tid=1054>
Fixes: 6020c9c013 ("Use d_fname for DOS filenames")
2018-06-13 02:02:58 +00:00
Kp 5526de4c10 Simplify case insensitive lookups 2018-06-13 02:02:58 +00:00
Kp d5bfeb0813 Fix OS X build break
Github user bdamm (Rebirth forum user dammfine) reports[1][2][3] a build
failure on OS X, likely caused by clang failing to implement forwarding
constructors fully.  The Rebirth fallback to variadic constructor
forwarding is imperfect, and in this case caused a failure.  Add an
explicit conversion to disambiguate the ternary expression's type.

[1]: Rebirth forum report: https://forum.dxx-rebirth.com/showthread.php?tid=1055
[2]: Github commit comment: ccc2a288f1?diff=unified#commitcomment-29322121
[3]: Github issue: https://github.com/dxx-rebirth/dxx-rebirth/issues/391

Reported-by: bdamm <https://github.com/dxx-rebirth/dxx-rebirth/issues/391>
Fixes: ccc2a288f1 ("Simplify HUD_SCALE_X_AR, HUD_SCALE_Y_AR")
2018-06-12 02:53:06 +00:00
Kp d786122b37 Force type of ternary expressions
When using variadic forwarding constructors
(`sconf_cxx11_inherit_constructor=force-failure`) instead of inheriting
constructors, some ternary expressions become ambiguous due to the
inability to forward the `explicit` modifier from the base class
constructor to the derived class.  Add explicit type overrides to
disambiguate these expressions to the result that the compiler would
have picked on its own when using inheriting constructors.
2018-06-12 02:53:06 +00:00
Kp 9b17450914 Fix up long broken glmprintf support
Switch the macro so that the result is always checked for correct
syntax.  This will prevent future bitrot.
2018-06-08 04:04:05 +00:00
Kp f51b7b6b20 Enforce separation of font X/Y scaling 2018-06-08 04:04:05 +00:00
Kp 93789f0666 Use valptridx for Dl_indices 2018-06-06 04:53:45 +00:00
Kp 1c1d92b399 Move valptridx factory iterator out to be generally available 2018-06-06 04:53:45 +00:00
Kp c04ae08c2e Preserve sign in HUD_SCALE_X,HUD_SCALE_Y
Fixes: ccc2a288f1 ("Simplify HUD_SCALE_X_AR, HUD_SCALE_Y_AR")
2018-06-06 04:53:45 +00:00
Kp b1ba7c27d1 Improve error handling/reporting for excessive blown bitmaps
Ill-formed levels can provoke this exception.  Downgrade the error from
a fatal exception to a CON_URGENT message.

Increase the array size to 32 from D1:7, D2:20, since each element is
only an int.

Switch from an assertion on bitmask overflow to a CON_URGENT warning.

Fixes: f7f416c3cb ("Trap blown bitmap overflow")
2018-05-30 02:43:22 +00:00
Kp d355ef4030 Pass font to various drawing functions 2018-05-19 23:21:42 +00:00
Kp fda1eb851e Pass fonts to LINE_SPACING 2018-05-19 23:21:42 +00:00
Kp 08446f0ab6 Pass font to gr_string,gr_printf 2018-05-19 23:21:42 +00:00
Kp a19d4157e2 Prevent reloading cv_font in font.cpp internal functions
Callers usually have cv_font already loaded, so pass it down instead of
reloading from memory.
2018-05-19 23:21:42 +00:00
Kp 893e8cde06 Combine hud gauge parameters
Many gauge functions take the same parameters, and pass those parameters
on to child functions in turn.  Bundle common parameters into a few
standard structures, so that adding new context does not need to involve
every function in the chain for every new context value.
2018-05-19 23:21:42 +00:00
Kp f2f41cd60e Fix capitalization of MVE entries
Reported-by: ryusei117 <https://github.com/dxx-rebirth/dxx-rebirth/issues/379#issuecomment-390058146>
Fixes: 6e439e17fd ("Match case for MVE files in MVL archives")
2018-05-18 02:47:32 +00:00
Kp 09cebc080c Undefine blank SHAREPATH
If user_settings.sharepath is configured to be blank in SConstruct, omit
the C preprocessor macro SHAREPATH instead of defining it to expand to
an empty string.  Adjust the C++ code that uses the macro SHAREPATH to
handle its absence:
- Clearer output in help text
- Skip adding blank SHAREPATH to the PhysFS search path.

As a nice side effect, this enables SHAREPATH on Windows, which could be
helpful for builds shipped with an installer that places game files in a
well-known location (such as "C:\Games\Descent").  Previously,
!defined(__unix__) systems did not add SHAREPATH to the PhysFS search
path, even when one was defined.
2018-05-17 02:49:15 +00:00
Kp 6e439e17fd Match case for MVE files in MVL archives
PhysFS 3 requires a case match.  PhysFS 2 did not.  Match the case in
the archive, which should work in both PhysFS 2 and PhysFS 3.

Reported-by: ryusei117 <https://github.com/dxx-rebirth/dxx-rebirth/issues/379>
Useful-hint-from: Manuel-K <https://github.com/dxx-rebirth/dxx-rebirth/issues/379#issuecomment-388849440>
2018-05-15 03:12:45 +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 12cc5860fe Cache user's last chosen host/port for direct_join
Define global copies of the user's chosen host address, host port, and
local port.  When these are non-empty, prefer them to the values from
-udp_hostaddr, -udp_hostport, and -udp_myport.  When the user attempts a
connection, update the global copies from the user's data.  If the user
abandons the connect dialog, do not update the globals.

Requested-by: Mako88 <https://github.com/dxx-rebirth/dxx-rebirth/issues/73>
2018-05-12 21:13:05 +00:00
Kp 3796c46440 Improve default keybindings
Slide left/right: A/D
Slide up/down: C/X
Accelerate/reverse: W/S
Afterburner (D2 only): Left-Shift

This produces the more FPS-typical WASD layout for
forward/left/back/right movement, and maps the crouch/stand bindings to
slide up/down.  This ticket sat for longer than it should have (though
it never missed a release).  Several competing designs were suggested,
but only one could be made active.  After consideration, I used my own
bindings on the basis that, while some other bindings may be better,
every other configuration repurposed a classic weapons-fire key to
movement.  Returning players who get the "new defaults" on a newly
created pilot profile might be very surprised by having their fire keys
move.  Since these are only defaults, and can be rebound by the player
with a few minutes work, these defaults do not need to be perfect.  They
just need to be an improvement over original Descent.

Delete unexpand-cpp-kconfig-key.py.  It will likely never be needed, and
was added in the prior commit solely to have a file to recover if it
ever is needed.

Requested-by: Mako88 <https://github.com/dxx-rebirth/dxx-rebirth/issues/214>
2018-05-12 21:13:05 +00:00
Kp 1fd8c184fd Convert kconfig default keys to their CPP define equivalents 2018-05-12 21:13:05 +00:00
Kp e63bbe8c52 Set d_event type at construction 2018-05-12 18:24:19 +00:00
Kp 6ab28cb8cb Use enum for Difficulty_level 2018-05-12 18:24:19 +00:00
Kp ccc2a288f1 Simplify HUD_SCALE_X_AR, HUD_SCALE_Y_AR 2018-05-12 18:24:19 +00:00
Kp 926a7f2a92 Remove useless const qualifier on meddraw static_cast
gcc-8 warns that static_cast<const T>(var) is useless.  Remove the const
qualifier.

References: <https://github.com/dxx-rebirth/dxx-rebirth/issues/388>
2018-05-05 22:33:56 +00:00
Kp e69e195a3a Remove useless static_cast<float> in kconfig
gcc-8 warns that static_cast<float>(float_var + 1) is useless.  Remove
the cast.

References: <https://github.com/dxx-rebirth/dxx-rebirth/issues/388>
2018-05-05 22:33:55 +00:00
Kp a2be4a89c9 Remove useless parentheses in gamecntl pointer-to-member declarations
gcc-8 warns for useless parentheses around the variable name.  Remove
the parentheses.

References: <https://github.com/dxx-rebirth/dxx-rebirth/issues/388>
2018-05-05 22:33:55 +00:00
Kp 6a8930cef0 Remove unnecessary inclusions of compiler-static_assert.h
Various files included compiler-static_assert.h to use the compatibility
macros for compilers that lacked a working C++11 static_assert.
However, some source files used static_assert without this inclusion,
and no one ever reported problems.  From this, assume that no one uses a
compiler which lacks C++11 static_assert.  Remove the inclusions that
were only for the compatibility macro.  Keep the inclusions that use the
assert_equal helper.
2018-05-05 22:33:55 +00:00
Kp 5cafec2268 Use enum for gauges weapon_type 2018-04-30 05:31:16 +00:00
Kp 14dac5042a Factor out count_number_of_objects_of_type predicate
count_number_of_objects_of_type is dsx due to object differences, but
the predicate can be dcx.
2018-04-30 05:31:16 +00:00
Kp 0a5e9eb592 Adapt to Python 3 strict bytes vs str rules 2018-04-30 05:31:16 +00:00
Kp 6dd25cc064 Update num_kills_level/num_kills_total for remote kills
When a remote player destroys a robot, account it on player #0 so that
materialization centers track destroyed robots.  This is required since
player #0 is the only one to generate new robots.

Reported-by: Mako88 <https://github.com/dxx-rebirth/dxx-rebirth/issues/132>
Reported-by: Sirius-TR <https://github.com/dxx-rebirth/dxx-rebirth/issues/386>
2018-04-30 01:11:29 +00:00
Kp eec2fb39d6 Update num_kills_level/num_kills_total in multiplayer
Materialization centers ("Matcens") have a governor to prevent
overrunning the level in robots.  However, due to a logic ordering
error, multiplayer games failed to record how many robots had been
destroyed, so for the purpose of detecting whether there were currently
"too many" robots in play, the game pretended that no robots had ever
been destroyed.  Therefore, once enough robots had been created to reach
the "too many" threshold, matcens stopped generating robots, regardless
of how efficiently the player(s) had been destroying robots.

Reported-by: Mako88 <https://github.com/dxx-rebirth/dxx-rebirth/issues/132>
Reported-by: Sirius-TR <https://github.com/dxx-rebirth/dxx-rebirth/issues/386>
2018-04-30 00:54:16 +00:00
Kp 685137d5f5 Fix infinite loop in newmenu default handler
If no character matches the typed character, the loop should exit when
`lb->citem == cc`, which should happen after every entry is visited
once.  However, if no item is selected, `lb->citem == -1`, and `cc` is
never `-1`, so the exit path never triggers.  Rewrite the loop to be
bounded by number of steps, rather than bounded by returning to a
particular offset.  This also protects against undefined behavior if the
menu had zero elements.
2018-04-28 21:58:46 +00:00
Kp 9be90bffde Merge pull #383 "Fix FPS." to github/master 2018-04-28 04:08:28 +00:00
Ronald M. Clifford 6aff08408a Ensure FrameTime > 0 before starting the frame. 2018-04-26 20:27:50 -07:00
Ronald M. Clifford c514e650c3 Fix FPS locking and FPS display implementations. 2018-04-23 15:33:43 -07:00
Ronald M. Clifford a9fb3c9df9 Add missing glDisableClientState call. 2018-04-22 23:31:27 -07:00
Ronald M. Clifford e9d36a29c1 Fix Blocky Filtered option.
[Kp: as discussed in pull #377
<https://github.com/dxx-rebirth/dxx-rebirth/pull/377>, the previous
implementation requested a parameter combination not permitted by
OpenGL.  At best, this error was silently ignored.  Fix the error by
falling through to a switch case statement that sets valid parameters.]
2018-04-23 05:07:15 +00:00
derhass 38815ba10b change SYNC_GL_AUTO mode to disable GL sync if VSync is turned off
Users with disabled VSync might not expect any forced waiting on the GPU,
and the GL sync methods were intented to fix issues with VSync only,
so the new heuristic for SYNC_GL_AUTO is to enable GL sync only if
VSync is enabled, too.

Users can still request to use a specific GL sync method via the
-gl_syncmethod switch, independent of the VSync setting.

[Kp: folded `else { if () }` into `else if ()` to avoid moving
`ogl_have_ARB_sync` lines.  Original change visible at
<https://github.com/dxx-rebirth/dxx-rebirth/pull/381>.]
2018-04-23 04:57:48 +00:00
Ronald M. Clifford 19dbc3c13c
Fix FPS. 2018-04-22 19:28:20 -07:00
Kp 8a16296eb4 Fix -Wunused-variable warning in PNG screenshot code
Global `Viewer` was copied to local `viewer`, and the local should have
been used in this block.  Instead, the global was incorrectly used.
gcc-5 warns for this unused variable.  gcc-6 and gcc-7 incorrectly do
not warn.

Reported-by: Jayman2000 <https://github.com/dxx-rebirth/dxx-rebirth/issues/375>
Fixes: 131c1b9f4d ("Add support for PNG screenshots")
2018-04-15 19:43:38 +00:00
Kp 48b31d84f3 Move FPS to right side and low
Mako88 requests, as have others in the Rebirth forum, that the FPS
indicator be placed on the right side.  Moving to the right side was
quick.  Moving it low, handling all the different rendering combinations
(cockpit, statusbar, fullscreen; standard vs alternate; single player vs
multiplayer), and not overlapping anything in any of them was time
consuming.

If anyone wants more changes in this area, the existing modes ought to
be revisited and unified.  As is, there are pointless inconsistencies
among the modes, which makes it unnecessarily difficult to position an
element correctly.

Requested-by: Mako88 <https://github.com/dxx-rebirth/dxx-rebirth/issues/122>
2018-04-14 21:36:50 +00:00
Kp 8096af91da Add support for shuffling powerups in anarchy games 2018-04-12 04:19:35 +00:00
Kp ce5d1005dd Restore padding to workaround menu sizing bug
Commit d580328 eliminated junk whitespace in the individual line items
for joinable games.  Unfortunately, this whitespace was not junk.  It
was an undocumented workaround (possibly even unknowing workaround) for
a bug that undercounts the space required to show the header.  Restore
the "junk" padding to force the window back to its old width.

Reported-by: Mako88 <https://github.com/dxx-rebirth/dxx-rebirth/issues/374>
Fixes: d580328698 ("Combine direct_join allocations")
2018-04-11 04:18:37 +00:00
Kp 732bbd3395 Round screen width/height up to next multiple of 4
Mako88 reports incorrect images captured when using a screen resolution
of 1366x768.  1366 is not a multiple of 4.  Debugging also shows memory
corruption at this resolution, as Mesa writes off the end of the
allocated buffer.  Padding the buffer to tolerate these writes is
insufficient, as libpng then crashes with an alignment fault trying to
read unaligned data from the buffer.  All these problems are eliminated
by rounding the width and height to the next multiple of 4.

Reported-by: Mako88 <https://github.com/dxx-rebirth/dxx-rebirth/issues/373>
Fixes: 131c1b9f4d ("Add support for PNG screenshots")
2018-04-10 04:13:49 +00:00
Kp 771eecf695 Fix ambient sound effects
Ambient sound effects have always been buggy in certain topologies,
since `ambient_mark_bfs` refuses to cross its own path.  Consider a
corridor:

 L _ _ _ _ _ _ _ _ _ _
     _     _
     _     L

Where L is a lavafall emitting sound, whitespace is insignificant, _ is
a segment, * is a tagged segment, and / is a segment that should be
tagged, but is not.  Let the leftmost L be a lower number segment than
the lower L.  Sound propagation after the first step is:

 L * * * * * _ _ _ _ _
     *     _
     *     L

After the second step, it should be:

 L * * * * * * * * _ _
     *     *
     *     L

However, `ambient_mark_bfs` will stop when it hits the intersection, so
instead the result is:

 L * * * * * / / / _ _
     *     *
     *     L

To further confuse the issue, emitter segments are processed in memory
order, so if the leftmost L is a higher index segment than the lower L,
the lower L will be processed first and the steps will be:

 L _ * * * * * * * _ _
     _     *
     _     L

 L * * * * * * * * _ _
     /     *
     /     L

Rewrite the propagation to record the travel depth remaining at each
node, and permit it to cross a segment with a lower depth remaining than
the current step.  This still stops early when traversal attempts to
backtrack over itself, but permits it to visit, tag, and cross segments
that were previously visited by a different emitter.
2018-04-09 00:58:28 +00:00
Kp 90d2a61c1d Simplify visited_segment_mask_t 2018-04-09 00:58:28 +00:00
Kp 6e9208efcd Simplify test for corrupt IFF file
clang rightly warns for `if (!var&1)`, which parses as `if (!(var &
1))`, which is probably not what the original author intended.
Unfortunately, the author never commented what *was* intended.  The
author might have meant to reject any row with an even length (`if
(!(var & 1))`, but that seems strange in this context.  Remove the `&
1`, which retains the sense of what the code has always done.
2018-04-03 03:20:08 +00:00
Kp 91e7d2960e Switch do_silly_animation robot angle to reference
clang warns for taking the address of unaligned data, but not for taking
a reference to it.  It should warn for both.  The data should be fixed
not to be unaligned, but for now, this change will quiet the warning.
2018-04-03 03:20:08 +00:00
Kp c9da856a90 Fix struct/class class-key mismatch in mglobal
clang warns when a type is declared with `struct`, then instantiated
with `class`.  Change the declaration to `class` to match the
instantiation.
2018-04-03 03:20:08 +00:00
Kp f869a16e35 Move Debris_object_count into d_level_object_state 2018-04-02 03:39:51 +00:00
Kp 64690c3ce8 Fix clang build of similar/main/weapon.cpp
OS X clang warns when a variable is captured but not used.  Linux gcc
does not.  Remove the unused variable.

Reported-by: kreatordxx <https://github.com/dxx-rebirth/dxx-rebirth/issues/368>
Fixes: 7da64d3782 ("Add new autoselect-while-firing mode: "when firing stops"")
2018-04-02 03:39:51 +00:00
Kp e08ea9f29a Clear weapon hitobj list on level load 2018-03-31 21:53:01 +00:00
Kp 813d73eedd Pass vms_matrix &to vms_matrix_from_quaternion 2018-03-31 21:53:01 +00:00
Kp 45f59c384b Pass vms_matrix &to vms_quaternion_from_matrix 2018-03-31 21:53:01 +00:00
Kp 18af84a0ab Remove __attribute__((packed)) from quaternionpos
Packed structures cannot be passed by reference, may fail on
alignment-strict architectures, and are bad for performance even on
alignment-tolerant architectures.  Using them for anything other than an
abstract layout declaration is a mistake.  Remove
__attribute__((packed)).
2018-03-31 21:53:01 +00:00
Kp 9b028f26f2 Make eclip_num unsigned 2018-03-31 21:53:01 +00:00
Kp a3871cfefd Tighten eclip::dest_bm_num handling
Instead of testing for -1, test for any out-of-range value.
2018-03-31 21:53:01 +00:00
Kp 29c6d63daa Move flickering light state into structure 2018-03-31 21:53:01 +00:00
Kp c368cf5ddd Simplify ai predicate functions
Many predicate functions only need to return zero/nonzero, and the
callers do not care about the particular value of nonzero.  Use this to
eliminate loads of explicit `1`, instead returning a nonzero value
generated by the test.
2018-03-27 03:49:34 +00:00
Kp 57008a7164 Read/write flickering_light by reference 2018-03-27 03:49:34 +00:00
Kp ac29854007 Reset boss teleport time on boss initialization
User roncli reports[1] an original game bug that prevents boss
teleportation from operating correctly if the program is not restarted
between each campaign.  This is another case of a global variable being
used improperly.  Reset the relevant variables when the boss is
initialized.

[1] https://github.com/dxx-rebirth/dxx-rebirth/issues/366#issuecomment-373199624
2018-03-15 04:05:42 +00:00
Kp e8645b2062 Pass vertex factory to compute_center_point_on_side 2018-03-12 03:43:47 +00:00
Kp 53a1d5f9ce Pass vertex factory to compute_segment_center 2018-03-12 03:43:47 +00:00
Kp ad8fd0f871 Pass valptridx factories to obj_relink 2018-03-12 03:43:46 +00:00
Kp e2b24b37d5 Pass d_level_object_state to reset_objects 2018-03-12 03:43:46 +00:00
Kp 44bba9d2a2 Pass valptridx object factory to obj_link 2018-03-12 03:43:46 +00:00
Kp daf87ac23a Pass valptridx object factory to obj_link_unchecked 2018-03-12 03:43:46 +00:00
Kp 0db5a2104e Pass valptridx factories to obj_unlink 2018-03-12 03:43:46 +00:00
Kp d2bad9845c Pass weapon_info_array to object_is_clearable_weapon 2018-03-12 03:43:46 +00:00
Kp 15b59a4b44 Pass d_level_object_state to obj_free 2018-03-12 03:43:46 +00:00
Kp 652b69f2a8 Pass Objects to obj_detach_all 2018-03-12 03:43:46 +00:00
Kp b00317bb1f Pass Objects to obj_detach_one 2018-03-12 03:43:46 +00:00
Kp d09478d88c Pass Objects to obj_attach 2018-03-12 03:43:46 +00:00
Kp 0067e33a8c Pass ObjectState to special_reset_objects 2018-03-12 03:43:46 +00:00
Kp a6b169afcc Move free_obj_list into d_level_object_state 2018-03-12 03:43:46 +00:00
Kp b63633db51 Move num_objects into d_level_object_state 2018-03-12 03:43:46 +00:00
Kp 1c92b448c8 Add d_level_object_state to wrap Objects and related data 2018-03-12 03:43:46 +00:00
Kp 2cac55d6c7 Raise max marker limit to 4 for cooperative games 2018-03-10 22:45:04 +00:00
Kp 49a4ac1c0e Move more marker state to d_marker_state 2018-03-10 22:45:04 +00:00
Kp 4d6b796874 Store MarkerObject as imobjidx, not objnum 2018-03-10 18:32:02 +00:00
Kp 7dee4ca49f Move MarkerMessage[] into wrapper d_marker_state
Also, fix an ancient bug with the automap handling of markers caused by
WET anti-pattern.
2018-03-10 18:32:02 +00:00
Kp ca2b1e0cf0 Remove build_colormap_good parameter used
`build_colormap_good` only took `used` to clear it.  Only one caller
needed it cleared.  Move the clear into that caller.  Remove the
parameter from all calls.
2018-03-08 04:21:18 +00:00
Kp b6e2205b9f Simplify palette color tracking
Callers only care whether a color is used, not how often it is used.
2018-03-08 04:21:18 +00:00
Kp fa5d8b0be0 Move fvi.cpp fvi_hit_object out of global scope 2018-03-05 01:40:44 +00:00
Kp ba81e0becb Move fvi.cpp fvi_hit_side_seg out of global scope 2018-03-05 01:40:44 +00:00
Kp 2686bdc32b Move fvi.cpp fvi_hit_seg2 out of global scope
Rename to fvi_hit_pt_seg based on comment explaining its purpose.
2018-03-05 01:40:44 +00:00
Kp 7ffd54377c Move fvi.cpp fvi_hit_side out of global scope 2018-03-05 01:40:44 +00:00
Kp f640917052 Move fvi.cpp wall_norm out of global scope 2018-03-05 01:40:44 +00:00
Kp ad654648a6 Move fvi.cpp fvi_nest_count out of global scope 2018-03-05 01:40:44 +00:00
Kp 852ab312d5 Remove global Network_laser_track 2018-03-05 01:40:44 +00:00
Kp 5c2408faaa In SDL2 mode, exclude test for SDL1-only feature (Redbook) 2018-03-03 18:47:23 +00:00
Kp 007ba90817 Support SDL2 style version lookup
The results are the same, but the way to obtain them was changed.
2018-03-03 18:47:23 +00:00
Kp 869fea9498 Make SDL-only SDL_Surface pointers static 2018-03-02 03:19:02 +00:00
Kp b16cf4e60a Fix Windows build
The Windows build did not explicitly include <time.h> or equivalent, but
used `time` and `gmtime`, which are only available when <time.h> is
included.  Other platforms include <time.h> incidentally.

Fixes: 131c1b9f4d ("Add support for PNG screenshots")
2018-02-18 18:52:22 +00:00
Kp 131c1b9f4d Add support for PNG screenshots 2018-02-18 00:42:42 +00:00
Kp 2571081962 Rewrite UI table to use symbolic constants for positioning 2018-02-01 05:38:47 +00:00
Kp 36f5e6103b Remove incorrect text "warning: " on generate-kconfig-udlr.py exception
This is not a warning.  It is a fatal error.
2018-02-01 05:38:47 +00:00
Kp 6e5c5f5c49 Mark some ogl parameters const 2018-02-01 05:38:47 +00:00
Kp 1ba2550b7e Defer restoring player ID to after object type is restored
`set_player_id` warns for setting the ID on non-players, including
ghosts.  Move the `set_player_id` call below the assignment to ->type,
so that `set_player_id` does not warn.

Reported-by: cfeuersaenger <https://github.com/dxx-rebirth/dxx-rebirth/issues/364#issuecomment-361096800>
2018-01-29 01:56:40 +00:00
Kp 5c5ee068ae Allow non-players to use OMEGA_ID weapon
User TRUEpiiiicness reports that valptridx<player>::check_index_range
traps when "The Apocalyptic Factor"[1] level 14 boss fires its Omega-based
weapon.  Code inspection shows that this is expected, since the original
designers assumed OMEGA_ID would only ever be used by players, and coded
various shortcuts accordingly.  No one told the level author this.  The
boss is an interesting concept and not difficult to support, so adjust
the code to handle this situation correctly:

- Check that the shooter is a player before checking its player ID.
  Without this, a robot that happened to have the same ID as the player
  would interpret robot data as player data, likely causing corruption
  when it tried to update the omega cannon charge.  Even if the robot ID
  does not match, this step causes a diagnostic[2] reporting that a
  robot ID is being misused as a player ID.
- Remove the shortcut that assumes the shooter is a player.  Store the
  shooter's actual type.
- Remove the unnecessary and counterproductive path that:
  1. Uses the object pointer to get the player's ID
  2. Uses that player ID to get a player pointer
  3. Uses that player pointer to get an object number
  4. Uses that object number to get an object pointer
  When invariants are maintained, the pointer derived in step 4 is equal
  to the pointer used at the start of step 1.  Use that pointer directly
  instead of rederiving it.  The reported exception was due to step 2,
  which requires that the player ID is in range.  When the shooter is a
  player, this is true.  When the shooter is not a player, it may not
  be true.

[1] http://www.enspiar.com/dmdb/viewMission.php?id=418
```
sha1sum af.hog af.mn2
133c52fb4b4e5fd40bf7b2321789841b727d1d0b  af.hog
0bb5f0dd1803b0fc1aac7c2023eacc97e9ab872b  af.mn2

stat -c '%s %Y %n' af.hog af.mn2
4024838 1094445016 af.hog
566 1013524628 af.mn2
```
[2] `similar/main/laser.cpp:560: BUG: object 0x555556078958 has type 2, expected 4`

Reported-by: TRUEpiiiicness <https://forum.dxx-rebirth.com/showthread.php?tid=1038>
2018-01-29 01:56:40 +00:00
Kp 22fe81666a Unify some control_info fields 2018-01-29 01:56:40 +00:00
Kp 1ffefa3029 Use partial_range for robot_get_anim_state 2018-01-29 01:56:40 +00:00
Kp 3f9b670fa3 Default to full template instantiation for AddressSanitizer builds
AddressSanitizer in gcc-7 inhibits deletion of certain otherwise
unnecessary nullptr checks, causing otherwise absent references to
class null_pointer_exception.  As a convenience to AddressSanitizer
users, instantiate all valptridx templates when AddressSanitizer is
enabled.  This is slightly excessive, but users building for
sanitization are not aiming for a minimal size build anyway.
2017-12-31 21:11:25 +00:00
Kp c179b2f783 Load robot customizations before use
AlexanderBorisov reported[1] a broken demo that ultimately traced to
incorrect reuse of stale data.  The campaign[2] includes per-level robot
definitions for level 3.  Descent incorrectly accessed Robot_info before
reloading it for the new level, so it used the level 3 data on level 4
robots during a warm start of level 4 for regular play, but used only
the level 4 data for a cold start of level 4 for regular play and for
playback of a demo recorded solely on level 4.  The particular
customizations applied on level 3 caused a level 4 demo recorded with
level 3 robot customizations to use different record lengths than a
level 4 demo recorded with level 4 robot customizations.  Since demos do
not record their record lengths, mismatched record lengths lead to
effectively corrupt demos.  In this case, it manifested as writing 8
anim_angles (per model_num 108, the model incorrectly inherited from
level 3) instead of 1 anim_angles (per model_num 37, used only on cold
starts).  The extra anim_angles were then misinterpreted as a run of 42
ND_EVENT_EOF, because the extra angles were unused and the newdemo code
defines the null byte as EOF (separate from receiving an actual EOF
indicator from the file I/O library).  That run of spurious EOF caused
the demo playback code to refuse to play past the spurious EOF,
resulting in a seemingly broken demo.

As an unfortunate, but unavoidable, consequence, this change modifies
the common path (warm playthrough of every level in the campaign) to
work like the uncommon path (cold start of each level).  Further, the
affected robot triggers a trap in d2x::do_silly_animation[3] when using
the correct model_num, because that polygon model has too few models for
the joints used by the robot.  When using the incorrect level 3 data,
the robot animates without trapping.

[1] https://forum.dxx-rebirth.com/showthread.php?tid=1023
[2] http://www.enspiar.com/dmdb/viewMission.php?id=212
```
sha1sum ENTROPY.HOG ENTROPY.MN2
7bc7a12d00a1ddd3ae92ce90eb67d581ecab004a  ENTROPY.HOG
f2688a634f22b30a02c43d8fa1a049deb5a03f70  ENTROPY.MN2

stat -c '%s %Y %n' ENTROPY.HOG ENTROPY.MN2
2402638 875757712 ENTROPY.HOG
511 875757164 ENTROPY.MN2
```
[3]
```
   799				if (jointnum >= Polygon_models[objp.rtype.pobj_info.model_num].n_models) {
   800					Int3();		// Contact Mike: incompatible data, illegal jointnum, problem in pof file?
   801					continue;
   802				}
```
2017-12-31 21:11:25 +00:00
Kp e8d53ca487 Add optional support for printing console timestamps to stdout 2017-12-25 05:44:27 +00:00
Kp 2b058c7150 Treat OpenBSD as Linux for msgbox handling
Requested-by: thfrwn <https://github.com/dxx-rebirth/dxx-rebirth/pull/359>
2017-12-24 00:28:35 +00:00
Kp 071a1dd486 Remove unused lambda capture in draw_all_edges
gcc silently permits this, as does every clang version I tested.
However, in issue #360, thfrwn referenced an e-mail thread that claims
OpenBSD clang warns for this. [1]  This capture is not needed, and as
far as I can tell, was not needed even when it was added.  It was likely
required in an earlier iteration of the code, but should not have been
pushed.  Remove it.

[1] https://marc.info/?l=openbsd-ports&m=151402743101761&w=2

Fixes: d4df692d30 ("Use range_for in draw_all_edges")
2017-12-24 00:28:35 +00:00
Kp 66b0f6bf37 Compile out unused joystick entries
Presently, user profiles are not portable between a build with
max_axes_per_joystick=0 and one with max_axes_per_joystick!=0.
Attempting to do so causes some buttons to be assigned to the wrong
action.  Since the intended use case for max_axes_per_joystick=0 and
similar is to completely remove joystick support on a system that will
never use a joystick, this is acceptable for now.  A future overhaul to
improve storage of user kconfig settings may fix this.
2017-12-24 00:28:35 +00:00
Kp f73b783095 Generate kconfig udlr relations at build time 2017-12-24 00:28:35 +00:00
Kp 0106833538 Move kconfig ui tables to separate file 2017-12-24 00:28:35 +00:00
Kp 44154f155a Fix max_joysticks=0 build
Fixes: 7311712399 ("Compile out joystick key settings when DXX_MAX_JOYSTICKS=0")
2017-12-24 00:28:34 +00:00
Kp 0a95ecc3a6 Mark changed values in kconfig UI 2017-12-15 04:47:30 +00:00
Kp 07895c086a Enforce anarchy-only flag for D1
hengyn45 reports that D1 improperly allows cooperative games on anarchy
only maps.

D1 seems not to have implemented this for a very long time, if ever,
although the code existed in commented out form.  When the trees were
combined, the commented out form was treated as blank, so the
restriction was placed inside a #if-d2 guard.  There is no reason to
make this D2-only.  Remove the guard so that D1 enforces anarchy-only.

Reported-by: hengyn45 <https://forum.dxx-rebirth.com/showthread.php?tid=1017>
2017-12-14 04:41:35 +00:00
Kp 0edf08cfbc do_powerup_frame: reject invalid vclip frametime
vclip::frame_time equal to 0 would cause an infinite loop.
vclip::frame_time less than 0 would cause the loop to run until
underflow, which could be very slow if frame_time is near 0.
2017-12-07 05:45:41 +00:00
Kp 544fc0f893 Add support for increased precision of gamelog timestamps
- Enable display of subsecond (Linux: microseconds; Windows:
  milliseconds) precision on gamelog timestamps.
- Add disabled support for YYYY-MM-DD leaders on gamelog timestamps.
  Activate it by defining DXX_CONSOLE_TIME_FORMAT_YMD to true.
- Add disabled support for capturing caller __FILE__, __LINE__ in calls
  to con_printf, con_puts.  Activate it by defining
  DXX_CONSOLE_SHOW_FILE_LINE to true.  If captured, write those to
  gamelog after the timestamp and before the text.  This feature (and
  only this feature) requires that DXX_HAVE_CXX_BUILTIN_FILE_LINE be
  defined, which is conditional on if the compiler has __builtin_FILE()
  and __builtin_LINE().  If the compiler lacks this support, attempts to
  enable this feature are ignored.
- Switch to using GetLocalTime on Windows.
2017-12-06 05:14:32 +00:00
Kp 01e1b28d71 Replace useless printf with puts 2017-12-05 05:29:55 +00:00
Kp 7311712399 Compile out joystick key settings when DXX_MAX_JOYSTICKS=0 2017-12-05 05:29:55 +00:00
Kp 35bd791d32 Remove obsolete kconfig TABLE_CREATION code
It generates code different from the current definitions, even when no
logical changes are present.  This code has not been used in at least 2
years, since commit bc7c469ab2 ("Use
array<> for more globals") changed the definitions of some variables
that this code regenerates, and this code still generates the old
definition.  Future changes will cause further deviation.
2017-12-05 05:29:55 +00:00
Kp 1f333868eb Fix proximity bomb failure-to-spin
Commit 7d36df315e restructured
draw_weapon_vclip, but unintentionally broke the spin of proximity bombs
because `modtime` could exceed `play_time * 2`, causing
`draw_vclip_object` to clamp `bitmapnum` to the last frame of the
animation.  Switch from `-=` to `%=` so that modtime is always brought
back in range.

Reported-by: Descender1032 <https://forum.dxx-rebirth.com/showthread.php?tid=1005>
Fixes: 7d36df315e ("Simplify draw_weapon_vclip")
2017-12-02 04:31:26 +00:00
Kp bcb3f6b486 apply_force_damage: check object type before accessing ctype union
When `apply_force_damage` was called to damage a robot, it tested if the
`ctype.laser_info.parent_signature` of the other object matched
`ConsoleObject->signature` and, if so, awarded points to the console
player.  This allowed the player to sometimes get points for ramming a
robot to death, but was buggy.  When the player rams a robot, the player
is the other object, so accessing `ctype.laser_info` is wrong.
Historically, the player's signature was zero and player
`ctype.laser_info.parent_signature` (an inactive and therefore incorrect
branch of the union) happened to be zero, so the test succeeded.  Commit
44753209d6 changed the layout of
`struct player_info` such that
`ConsoleObject->ctype.laser_info.parent_signature` was not zero, causing
the player not to be his own parent.  Prior to this commit, the player
could still wrongly fail the test if the `player_info` member that
aliased `laser_info.parent_signature` was nonzero.  In the commit
preceding the obvious break, `player_info.player_flags` aliased
`laser_info.parent_signature`, so a player with certain flags (such as
invulnerability) would wrongly fail the test.  The exact manifestation
has changed over time as `struct player_info` gained members.

Restructure the test so that a ramming kill always awards points,
without checking ancestry.

Reported-by: Descender1032 <https://forum.dxx-rebirth.com/showthread.php?tid=1006> (no commit identifiers given)
Fixes: 44753209d6 ("Move homing_object_dist to object.ctype.player_info")
2017-12-02 04:31:26 +00:00
Kp 8ae4ef9eb5 Fix traps due to invalid level data
`Descent 2: Counterstrike` level 9 specifies a control center trigger on
a side with no wall.  This is not valid.  In normal play, wall_toggle
silently ignored this, and newdemo_pop_ctrlcen_triggers had undefined
behavior.  Add a warning in wall_toggle to report levels like this.  Add
handling in newdemo_pop_ctrlcen_triggers to detect and suppress this
bogus data.

`Descent 2: Counterstrike` level 11 specifies a control center trigger
on a side with no child segment.  This is not valid, so
newdemo_pop_ctrlcen_triggers again had undefined behavior.  Add handling
to detect and suppress this bogus data.

Reported-by: Descender1032 <https://forum.dxx-rebirth.com/showthread.php?tid=992>
2017-11-25 01:56:51 +00:00
Kp c60c0352f0 Fix songs_play_file use for sdlmixer=0 2017-11-25 01:56:51 +00:00
Kp 8376504a34 Fix menu.cpp build failure for sdlmixer=0
When sdlmixer=0, opt_sm_mtype1 is not defined, but was used.  Preprocess
out the use.
2017-11-25 01:56:51 +00:00
Kp e5496d3aaf Consume trailing newline for Rebirth.rotate.robot directive 2017-11-18 04:45:50 +00:00
Kp 479ac8761f Add experimental D2 support for D1 style robot briefings 2017-11-13 01:59:49 +00:00
Kp 425b78b8a6 Fix clang build failure on flicker_timer_disabled
clang rejects 0x80000000 as a non-type template argument of type `int`
due to narrowing.  Use `INT32_MIN` instead, which has the same numeric
value, and should be accepted without requiring narrowing.

Reported-by: Havner <https://github.com/dxx-rebirth/dxx-rebirth/issues/353>
Fixes: 88832e3679 ("Use constexpr integral_constant for various magic numbers")
2017-11-07 00:44:59 +00:00
Kp 09963e8b5a Remove write-only Seg_scale 2017-11-05 20:49:09 +00:00
Kp f742e44091 Simplify lighting test 2017-11-05 20:49:09 +00:00
Kp c33f343d0b Return side_none for openable_doors_in_segment failure path 2017-11-05 20:49:09 +00:00
Kp a4ed8d5c9c Hold morph_rate constexpr 2017-11-05 20:49:09 +00:00
Kp d049f738c8 Convert various gr_set_current_canvas calls to reference form 2017-11-05 20:49:08 +00:00
Kp ca804d5186 Clear canvas to fix missing exit tunnel movie
Global variable `grd_curcanv` is set to a variety of canvases, some of
which are local stack variables.  Use of global variables in this way is
fragile, but works as long as the global is not used beyond the life of
the backing local.

Unfortunately, some existing uses do access the canvas beyond the
lifetime of the backing local.  Playing movies sets the font of the
current canvas.  If the current canvas is an expired stack variable,
setting the font overwrites other stack data.  This data corruption
causes various symptoms, such as inability to play the escape tunnel
movie.

Prior to 03cca2b3dc, the corruption on
playing the endlevel movie had no user-visible effect.  That commit
created a large local variable, which changed stack layout.  Starting
with that commit, the corruption causes the movie to play as all black.

Fix this, and protect against some other data corruption possiblities,
by clearing the global when the local goes out of scope.

Reported-by: Havner <https://github.com/dxx-rebirth/dxx-rebirth/issues/345> (only as cutscene failure to play, not as the underlying corruption issue)
2017-11-05 20:49:08 +00:00
Kp 49c0cdae2e Simplify calls to gr_set_default_canvas
Rather than use an inline wrapper and rely on the compiler optimizer to
redirect gr_set_current_canvas(nullptr) to gr_set_default_canvas,
rewrite all relevant calls directly in the source.

git grep -l 'gr_set_current_canvas' | xargs sed -i -e 's:gr_set_current_canvas(\s*NULL\|nullptr\s*);:gr_set_default_canvas();:'
2017-11-05 20:49:08 +00:00
Kp 6043168d51 Move various SDL-only texture mapping functions to !DXX_USE_OGL
The OGL build compiles, but does not use, various texture mapping
functions.  Move these to be built only for the SDL build.
2017-11-01 02:01:21 +00:00
Kp f598542f35 Simplify helix orientation calculation 2017-11-01 02:01:21 +00:00
Kp 5d4d3347e6 Remove unused found_poly 2017-11-01 02:01:20 +00:00
Kp 3fbc710ec5 Move various SDL-only scanline functions to !DXX_USE_OGL
The OGL build compiles, but does not use, various scanline functions.
Move these to be built only for the SDL build.
2017-11-01 02:01:20 +00:00
Kp 92c6196396 Remove long-dead SLEW_ON code
Defining SLEW_ON breaks the build due to use of member variable names
not used since before the D2X import in 2001.

`unifdef -USLEW_ON -m -- similar/main/endlevel.cpp`
2017-11-01 02:01:20 +00:00
Kp 8d80300e0a Remove obsolete D1 hostage editor code
This code was part of a feature abandoned before retail.  It cannot be
usefully used in campaigns.  Remove it to reduce code size and simplify
later changes.
2017-10-14 17:10:31 +00:00
Kp 96bc6f2047 Use enumerate for medrobot AI mode boxes 2017-10-14 17:10:31 +00:00
Kp 255655e8e7 Reduce scope of switch.cpp for loop variables 2017-10-14 17:10:31 +00:00
Kp 2e7dce83c6 Use enumerate for gamefont arrays 2017-10-14 17:10:31 +00:00
Kp 22b22a4a70 Use enumerate for verifying Effects 2017-10-14 17:10:31 +00:00
Kp e58956ddeb Simplify digi_audio_stop_all_channels 2017-10-14 17:10:31 +00:00
Kp 4d271f6d5e Simplify wiping Cyberman field 2017-10-14 17:10:30 +00:00
Kp 450d2f727c Use range_for for endlevel array stars 2017-10-14 17:10:30 +00:00
Kp 88832e3679 Use constexpr integral_constant for various magic numbers 2017-10-14 17:10:30 +00:00
Kp 8291391b7f Fix D2 emulation of D1 boss teleport handling
Descent 1 bosses could always teleport, but were only placed in large
areas where free teleporting was always permitted.

Descent 2 boss 1 was placed in a confined segment and not permitted to
teleport out of it until it was opened.  This was implemented by a
two-part change relative to Descent 1 rules:

- Descent 1 bosses were always permitted to teleport to any teleport
  destination segment.  Descent 2 bosses were only permitted to teleport
  if the player was visible or the boss had recently been hit.
- When computing the permitted list of teleport destination segments,
  Descent 1 used directly connected accessible segments, then stopped.
  Descent 2 started with this rule, but if the list had at most 1 entry,
  then it would assume this is the confined boss and recompute the list
  with the first wall ignored.  This recomputed list allowed the boss to
  teleport to any segment in the larger arena outside its starting
  segment.

After D2X-Rebirth support for emulating Descent 1 bosses was enhanced in
28bd4c1650, Descent 1 bosses gained the ability to teleport out of a
confining cube early, but only in D2X-Rebirth when emulating Descent 1.
In D1X-Rebirth, when a boss is placed in a confining cube, it can always
teleport, but only to that confining cube.  In D2X-Rebirth, Descent 1
bosses retain the always-teleport rule of Descent 1, but gained the
Descent 2 rule for expanding its search to the surrounding arena.  It
should only use the expanded search when it also abides by the Descent 2
restriction not to teleport before the first wall is opened.  It did not
abide by that rule.  This commit adds that restriction for Descent 1
bosses.

Reported-by: ef314159 <https://github.com/dxx-rebirth/dxx-rebirth/issues/348>
Fixes: 28bd4c1650 ("Enable D1 boss behavior in d2x build. So we get correct boss behavior when emulating D1, and 3rd party mn2s can include D1 bosses.")
2017-10-06 01:59:09 +00:00
Kp c3434e61d3 Enable PF_USES_THRUST when reseting multiplayer flags
Commit b1b5de4 switched from enabling select physics flags to setting
those flags and clearing all others.  Unfortunately, flag PF_USES_THRUST
was omitted from the enabled list, so it was disabled on reset.  It is
required to let player ships move.

Reported-by: Sottises <https://github.com/dxx-rebirth/dxx-rebirth/issues/347>
Fixes: b1b5de4297 ("Additional safeguard for bug #306")
2017-10-03 01:31:33 +00:00
Kp f60c783ef5 Move marker preservation into object lifeleft update 2017-09-30 18:00:15 +00:00
Kp 2665869c24 Mark editor groups broken
Editor groups write `struct segment` to a file in raw form, but had no
code to enforce that this raw form remained stable over time.  Various
changes to `struct segment` have repeatedly changed its internal
structure.  Each change created an incompatible dialect of the editor
group file, and all the dialects share the same version number.

According to
```
git log -p -L'/struct segment {/,/};/:common/main/segment.h' HEAD --not 0.58.1-d1x 0.58.1-d2x --
```
`struct segment` changed layout in:

* d1c6b89f17 ("Move dsx::segment -> dcx::segment")	[D1 only]
* 596ecbb38d ("Rename segment::value to segment::station_idx")	[D1 only]
* 6f10a67c09 ("Move segment::sides to end")
* c53b734abb ("Compute slide segments early")	[D2 only]
* 40e90fea22 ("Move Light_subtracted[] to Segments[].light_subtracted")
* a65d774c83 ("Improve packing of struct segment")
* c70c6c98b3 ("Remove obsolete segment::degenerated flag")

Mark editor groups as broken to avoid making the mess worse.  If anyone
cares about group support, it needs to be rewritten not to depend on the
internal layout of `struct segment`.
2017-09-30 18:00:15 +00:00
Kp 7bae498c45 Cache bitset::operator[] result 2017-09-30 18:00:15 +00:00
Kp 657bd59012 Use array<>+move for draw_model sort_list 2017-09-30 18:00:15 +00:00
Kp 4cfd5f3324 Pass canvas to menubar_init 2017-09-26 04:15:50 +00:00
Kp 6bd653bb16 Drop useless test in render_side
Descent 2, but not Descent 1, had a useless test in render_side:

	type == QUAD ? 0 :
		type == TRI_13 ? 1 :
		0

This is useless since, if type is not QUAD, the second expression will
apply.  If type is QUAD, then the type is not TRI_13, so the second
expression would choose the same result as the first.  The extra
comparison does not save any work, so it is useless.  Remove it.
2017-09-26 04:15:50 +00:00
Kp d7e97ca299 Remove write-only Escort_kill_object
Parallax never implemented Escort_kill_object because it was considered
too much work.  Remove the write-only vestiges of that feature.
2017-09-26 04:15:50 +00:00
Kp bba7e3a153 Move menu_number_bias_wrapper bias into type signature 2017-09-26 04:15:50 +00:00
Kp 1641c87765 Reuse WALL_IS_DOORWAY result in render_side 2017-09-26 04:15:50 +00:00
Kp 783bd90a72 Make automap PCX optional 2017-09-10 04:28:41 +00:00
Kp 7c0cdd6c51 Fix crash loading Vertigo briefing
Commit 1335af4b51 restructured briefing number parsing, but
unintentionally changed the parser not to drop the newline after a
number.  The briefing parsing code is very sensitive to minor changes,
so this broke parsing some briefing screens, including Vertigo briefing
screens after the first.  After the change, clicking through the Vertigo
briefing aborts on failure to load a PCX file.

Fix this by consuming the newline before returning.  This matches the
previous semantics.

Reported-by: Havner <https://github.com/dxx-rebirth/dxx-rebirth/issues/343>
Fixes: 1335af4b51 ("Simplify get_message_num")
2017-09-08 00:56:37 +00:00
Kp 456e239ae3 Use reference for ai_local 2017-09-08 00:56:37 +00:00
Kp 0548384d2a Fix excessive lavafall damage
Like many things in the main game loop, lavafall handling was
historically done on a per-frame basis, then its effects were scaled to
FrameTime to normalize the results.  Ignoring rounding errors, this
produced roughly equivalent damage for high framerate users (who
experienced many but small damage hits) and low framerate users (who
experienced few but large damage hits).  However, the randomized
movement was not scaled to FrameTime, which caused differing results for
high framerate users versus low framerate users.  Commit b36c6f20c7
tried to fix this by forcing scrape_player_on_wall to run at a capped
maximum effective frame rate, then scaling the damage in
check_volatile_wall accordingly, so that high framerate users would
experience fewer damage hits, but the ones they received were larger,
thus maintaining approximately the same damage as before.

Prior to b36c6f20c7, damage was always scaled to FrameTime.  In
b36c6f20c7 and later, damage scaled to max(FrameTime,
DESIGNATED_GAME_FRAMETIME), causing users with a high frame rate (and
thus low FrameTime) to take more damage on each pass.  This damage
increase was balanced by an added hack in scrape_player_on_wall to limit
the frequency of the scrape so that high framerate users would skip some
scrapes, giving them a virtual frame rate appropriate to
DESIGNATED_GAME_FRAMETIME.  However, the damage is only balanced if the
new governor is used consistently.  It is not used consistently, so it
caused a regression for passable lava surfaces.  Scraping on a solid
lava surface goes through scrape_player_on_wall and respects the
governor.  Touching a passable lava surface (only available in Descent
2) bypasses scrape_player_on_wall and jumps directly to
check_volatile_wall, thereby bypassing the governor.  This allows high
framerate users touching a passable lava surface to take many hits (as
they always did), but not receive the full benefit of downward scaling
the damage (as they once did) due to the new max() expression.  Thus,
they are damaged frequently, but still take damage consistent with being
damaged infrequently.

Fix this by moving the hack from scrape_player_on_wall to
check_volatile_wall, so that both solid lava surfaces and passable lava
surfaces respect the governor.  The governor is still an ugly hack that
should not be global, but this is a spot fix for the immediate problem.

Fixes: b36c6f20c7 ("Made scrape_player_on_wall() based on a timer. Due to the player being pushed away from the lava/water surface in every frame in a random vector (wrong, too), player movement per frame was not enough to counter this on FPS rates > ~120 which made damage scaling per frame nonsensical in these situations. Instead, execute scrape results in intevals based on DESIGNATED_GAME_FRAMETIME (or per frame if FrameTime>DESIGNATED_GAME_FRAMETIME) which fixes the issues and generally works much better for the purpose of this function.")
2017-09-08 00:56:37 +00:00
Kp aeedadba89 Unify D1/D2 scrape_player_on_wall 2017-09-08 00:56:37 +00:00
Kp a24490033f Allow players to remove thief at level start
Commit f4b21088a0 ("Track vulcan ammo explicitly") fixed an original
retail bug that prevented the thief from stealing energy weapons,
because the thief could only steal weapons for which the player had ammo
and energy weapons never have ammo.  This went unremarked for several
years, until a recent report of the new semantics as a game-breaking
regression because the thief is now "ridiculously potent".

Address this report, as well as an intermittently raised issue from
various users over time, by adding two new knobs to both the single
player "Gameplay" menu and the multiplayer setup screen: "Remove Thief
at level start" and "Prevent Thief Stealing Energy Weapons".

"Remove Thief" deletes the thief object during level load.  It has no
impact on save games, and changing it after entering a level has no
effect on any thief already in the level.

"Prevent Thief Stealing" is checked at the moment of theft and, when
enabled, prevents stealing primary weapons other than Vulcan/Gauss.
This can be changed at will in single player and is immediately
effective.  In multiplayer, this option can only be changed by the game
host in the pre-game setup.

For both knobs, there is one pair of checkboxes to control this as a
player preference, which applies in single player games.  There is a
second pair of checkboxes in the multiplayer setup, which applies only
to multiplayer games.  Therefore, in multiplayer, the host chooses thief
settings and all clients use the host's choice.  The host may configure
the thief differently in multiplayer from how the host plays in single
player.

For users who wanted to remove the thief, no specific tally has been
kept for who requested it or when.  Now that the code is being updated,
this is thrown in as an easy addition.

Reported-by: MegaDescent <http://forum.dxx-rebirth.com/showthread.php?tid=980> (for the thief stealing energy weapons as a game-breaking regression)
2017-08-26 19:47:52 +00:00
Kp 4ea9ef5b0c Use reference for robot_info 2017-08-26 19:47:51 +00:00
Kp 3bcee35c7b Shrink some Netgame fields
For protocol compatibility, zero-pad the outbound messages.  Previously,
the upper bits were zero because the value fit in a byte.
2017-08-26 19:47:51 +00:00
Kp 3340a6c16c Report compiled/loaded library versions at verbose level
When reporting use of SDL_mixer, report its loaded version.  When
running in verbose mode, report both the compile-time and load-time
versions of PhysFS, libSDL, and SDL_mixer.
2017-08-26 19:47:51 +00:00
Kp 6b209c8713 Decorate OpenGL messages
Some Linux libraries print their own messages to stdout/stderr,
particularly in case of severe errors.  Decorate messages generated by
Rebirth to distinguish them from library generated messages.

For specific blacklisted renderers, add a message informing the user
that the blacklist matched and changed settings.
2017-08-26 19:47:51 +00:00
Kp b5b5cbd4d7 Pass canvas to meddraw draw_listed_segments 2017-08-26 19:47:51 +00:00