Commit graph

4283 commits

Author SHA1 Message Date
Kp 5735175999 Merge 'refs/pull/516/head' into master 2020-07-09 02:47:18 +00:00
Kp a20551191a Remove useless D1 test for TRIGGER_ONE_SHOT
This block previously was used to clear TRIGGER_ON, but that change was
removed because TRIGGER_ON was a write-only flag.  This block is now
useless, so remove it.  This should also fix an obscure crash reported
by AlumiuN.

AlumiuN proposed adding a test that seg->children[side] is still valid,
but since the logic to execute would be useless even when the test
succeeds, it is simpler to remove this code entirely.

Reported-by: AlumiuN <https://github.com/dxx-rebirth/dxx-rebirth/issues/515>
Suggested-by: AlumiuN <https://github.com/dxx-rebirth/dxx-rebirth/pull/518#issue-443277182>
2020-07-07 04:09:44 +00:00
Kp 738e4a740e Remove TRIGGER_FLAG::ON; it is write-only
The game clears it in various cases, but never tests for it.  Remove it.
2020-07-07 04:09:44 +00:00
Kp b814434181 Revert "fix invalid polymodels if words_need_alignment=1"
This reverts commit 60edaa7dce.

This commit was brought in through a merge to obtain a different change,
and was supposed to be suppressed in preference to the change from
dfcb0fcdc.  Revert it here, since reloading the variable suffices to fix
the problem, and this commit forces a reload on all platforms, rather
than only reloading on platforms that need it.
2020-07-07 04:09:44 +00:00
Kp 2e979c954d Merge 'refs/pull/519/head' into master 2020-07-05 23:34:33 +00:00
Kp 569802e00f Convert kconfig array lookups to require correct enumerated type
This ensures that an array is indexed by the appropriate type.  Indexing
a mouse array with a joystick index is undefined behavior, and with this
change, such undefined behavior is now a compilation error.
2020-07-05 23:34:33 +00:00
Kp a27b50a357 Use symbolic names to look up kconfig offsets 2020-07-05 23:34:33 +00:00
Kp caf3a71aa2 Remove plx special case for version 0.56.0
That version was a long time ago.  Assume anyone who has not run a build
newer than 0.56.0 by now will not do so.
2020-07-05 23:34:33 +00:00
Kp be1a539898 Reduce lookups of descent.hog size in briefings 2020-07-05 23:34:33 +00:00
Kp 85f0dcde01 Avoid repeatedly reopening descent.hog during briefings
PHYSFSX_fsize opens the file, reads its length, and closes it.  Calling
PHYSFSX_fsize in a loop is wasteful, since the file size should not
change while the game is playing.
2020-07-05 23:34:33 +00:00
Kp c0daa89ad5 Avoid reopening descent.sng
If !canUseExtensions, then fp is already open to descent.sng.  There is
no need to reopen it just to get its length.
2020-07-05 23:34:33 +00:00
Kp 3f951cf45f Use A.size() or std::size instead of sizeof(A)/sizeof(A[0]) 2020-07-05 23:34:33 +00:00
Kp 7e36beb30c Move polymodel alignment code to interp.cpp
This makes the alignment data structure `chunk` private to interp.cpp,
and allows most files to ignore whether DXX_WORDS_NEED_ALIGNMENT is
enabled, thus improving the ccache hit rate.
2020-07-05 23:34:33 +00:00
Kp dfcb0fcdc1 Fix truncated polymodel data on words_need_alignment=1 systems
kajott reports that on Raspberry Pi systems, "Medium Hulk and Heavy Hulk
models were missing their heads".  This impacts all systems with
words_need_alignment=1, and was introduced by logic that tried to
truncate invalid polygon models, which was added because such models
often crashed the game.  The validation logic used the original size of
the polygon model data, which is correct on systems with
words_need_alignment=0, but can be too small on systems with
words_need_alignment=1 if the polygon model was enlarged as part of
aligning it.  Such systems would refuse to read past the original,
shorter, length, and then declare the model to be broken and truncate
it.  Fix this by reloading the length from the polymodel structure after
the alignment logic is applied.

Reported-by: kajott <https://github.com/dxx-rebirth/dxx-rebirth/pull/519>
Fixes: 42a2e3ab0b ("Avoid crash loading polymodels with invalid subcalls")
2020-07-05 23:34:33 +00:00
Kp 316a4740a6 Move words_bigendian into if constexpr
`words_bigendian` is `constexpr`, so move the tests on it behind `if
constexpr` to encourage the compiler to prune unreachable paths.
2020-07-05 23:34:33 +00:00
Kp b948da1a1f Replace uses of enumerate with zip where appropriate
In some places, enumerate was used only to get an index value because
zip was not available.  Switch those sites to use zip directly.
2020-07-05 23:34:33 +00:00
Kp d959eeca8f Use zip in kconfig to allow use of range-based for 2020-07-05 23:34:33 +00:00
Kp 6e4b63e098 Use C++17 std::size instead of custom lengthof
lengthof was added to provide the size of C arrays.  C++17 std::size is
now available, and can serve the same purpose.  Remove the custom
lengthof.

The generated code is the same in both cases, other than the change in
line numbers caused by removal of the #include directives.
2020-07-05 23:34:32 +00:00
Kp 0a1f2ad55e Tighten type for trigger action values 2020-07-05 23:34:32 +00:00
Kp a98ddfbe9b Tighten type for trigger behavior flags
Use an enum class to prevent implicit conversion between trigger
behavior flags and other integers.  Fix up various resulting breaks,
which look like bugs:

- Descent 2 editor mode could modify trigger::flags, but used
  TRIGGER_FLAG_* values, which specify the actions for a Descent 1
  trigger when it executes, not the behavior properties for a trigger.
- Adding a trigger set its flags to 0, then cleared all flags except
  TRIGGER_ON.  Since the flags were just set to 0, the mask operation is
  useless.  Remove it.
- trigger_turn_all_ON cleared all flags except TRIGGER_ON.  This seems
  to be completely wrong.  Change it to remove
  trigger_behavior_flags::disabled.  Descent 1 has no (working) support
  for disabling triggers, so make trigger_turn_all_ON exclusive to
  Descent 2.
- wall_restore_all would enable TRIGGER_ON in both games.  Descent 1
  never reads TRIGGER_ON.  Descent 2 uses this field for trigger
  behavior flags, and TRIGGER_ON is not a behavior flag.
  - For Descent 1 builds, remove the modification of the field.
  - For Descent 2 builds, change it to clear
    trigger_behavior_flags::disabled.
2020-07-05 23:34:32 +00:00
Martin Fiedler 60edaa7dce fix invalid polymodels if words_need_alignment=1
If compiled with words_need_alignment=1, the
model data was correctly converted and expanded,
but the old size was still used for validating
and initializing the model.

This caused funky effects on affected platforms,
e.g. some robots missing their heads on Raspberry Pi.
2020-07-02 21:56:11 +02:00
Martin Fiedler f67026de9a avoid empty savegame descriptions
It's possible to enter empty savegame descriptions,
which is no problem itself, but it looks quite
confusing in the save/load menus: you can't see
the currently selected item, for instance.

This commit replaces an empty description with a
placeholder text ("no title") upon saving.

This is particularly useful when controlling
the game only with a joystick, where entering
a proper description isn't possible.
2020-06-30 21:46:06 +02:00
AlumiuN 4425f07e9d Prevent the destruction of one-sided prison doors from causing a crash 2020-06-30 21:40:09 +12:00
Martin Fiedler 853a0c41e1 added joystick binding for showing ingame menu
A new configurable joystick button binding is
introduced that opens the ingame menu, i.e. the
menu that appears when pressing the Escape key.

Fortunately, there was still enough space left
in the button binding maps for both games. The
configuration screen, however, needed to be
extended by a row to make room for the new
binding on d2x.

One known issue: When using an old player
configuration file, the menu button bindings
are initially set to J1 B1, because the unused
slots in DefaultKeySettings used to be
initialized that way. There's not much we can
do about that; the player needs to remove
these bogus assignments by hand. We can (and
do) prevent that from happening again, though,
by initializing new player files with correct
unmapped buttons.
2020-06-29 23:16:04 +02:00
Martin Fiedler c24864b180 make menus controllable with joystick
In most menus, keyboard commands are synthesized
from controller buttons, leveraging the existing
axis-to-button translation.

Menu controls are currently fixed:
- button 0 (A) is confirm (Enter)
- button 1 (B) is cancel (Esc)
- button 2 (X) is switch (Space)
- button 3 (Y) is delete (Delete)
- axes 0 and 1 (main analog pad) maps to cursor keys
- all hats (D-pads) map to cursor keys

Title screens and credits can be confirmed
with any joystick button or axis motion too.
2020-06-28 17:08:26 +02:00
Kp 096a678ff7 Ignore effects with frame_time=0
If the effect is not ignored, then the game enters an infinite loop
because ec.time_left never increases.

Reported-by: murphy83 <https://github.com/dxx-rebirth/dxx-rebirth/issues/513>
2020-06-19 01:46:54 +00:00
Kp 79e7143254 Reset autosave timer on game load 2020-06-10 02:25:33 +00: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 665713f315 Remove static inline declarations from fwd-partial_range.h
A declaration is useful if it declares an external function.  A static
inline declaration, if not followed by the definition later in the same
translation unit, will not be useful.  Remove such declarations, and
rely on using the definition as a declaration for those files that
actually call partial_range() or similar functions.
2020-06-10 02:25:32 +00:00
Kp 81119f0445 Use enum class for LevelMusicPlayOrder 2020-05-31 23:04:25 +00:00
Kp d06ad449b8 Always ignore from_hog_only
This fixes PCX loading in the non-editor build.  PCX loading broke in
3114874713 because it switched from PHYSFSX_openReadBuffered to a call
which did not handle the presence of the marker byte in the filename.

The from_hog_only flag has not been properly supported since the
introduction of PHYSFSX_openReadBuffered in
8b323e7214.  Editor builds ignored it on
purpose, and non-editor builds pretended to respect it, only to then
ignore it down inside PHYSFSX_openReadBuffered.  For consistency with
code paths that do not use PHYSFSX_openReadBuffered, disable the bypass
in PHYSFSX_openReadBuffered and remove the code in show_title_screen
that applied the flag.

Reported-by: Jayman2000 <https://github.com/dxx-rebirth/dxx-rebirth/issues/510>
Fixes: 3114874713 ("Delegate PCX loading to SDL_image")
2020-05-28 03:21:22 +00:00
Kp b08620292d Fix input handling in automap
The automap code keeps a mostly-private secondary copy of control_info.
The change to reset control_info before the event loop reset the main
copy of control_info for the automap, not the copy that the automap
actually used.  Fix this by passing the desired control_info to relevant
functions instead of always using the global variable Controls.

Fixes: c621a970c6 ("Reset kconfig counters once, before the event loop")
2020-05-28 03:21:22 +00:00
Kp c621a970c6 Reset kconfig counters once, before the event loop 2020-05-27 03:07:17 +00:00
Kp 954a235d13 Discard decoded cockpit buffer when no longer needed 2020-05-27 03:07:17 +00:00
Kp 5dbdc65ee6 Fix D2 crash on blank line in bitmaps.tbl
Reported-by: InsanityBringer <https://github.com/dxx-rebirth/dxx-rebirth/issues/464#issuecomment-632443732>
2020-05-22 02:40:26 +00:00
Kp 7b52b1fe1d Move grs_bitmap::avg_color into #if !DXX_USE_OGL
This field is used in the SDL build for rendering.  In the GL build, its
only purpose is for the editor to write it to a PIG file.  Change that
one use to compute the value as needed.  Move all other references
behind a preprocessor test for !DXX_USE_OGL.  This shrinks the size of
grs_bitmap by 1 pointer, since the compiler added padding after
avg_color up to the size of the next aligned pointer.
2020-05-22 02:40:26 +00:00
Kp 3d0f333b34 Unify object texture setup
Move the load of &GameBitmaps to the common loop used for paging in.
Add range checks on the loops.
2020-05-22 02:40:26 +00:00
Kp c1181b7be5 Move texture_list out of global scope 2020-05-22 02:40:26 +00:00
Kp f413017317 Delegate bald_guy_load PCX to SDL image 2020-05-17 23:35:26 +00:00
Kp 3114874713 Delegate PCX loading to SDL_image
This adds a new dependency, but most systems likely already have
SDL_image installed.  Use of SDL_image can be disabled, but this is
discouraged, because various in-game interfaces assume the use of the
original background.

The old implementation automatically corrected for filename case.  The
new implementation expects that the supplied filename can be passed to
PYHSFS_openRead as-is.  All known uses in-game have been corrected to
satisfy this requirement.  If the new stricter match requirement becomes
a problem, a variant of PHYSFSRWOPS_openRead that adjusts filename case
could be created for use here.

- Update install instructions
- Update ebuild
- Update Arch PKGBUILD
2020-05-17 23:35:26 +00:00
Kp 71ca1a7553 Do not abort on failure to load PCX
Using assert to check for conditions that can be caused by improper
configuration is wrong.  If the load failed, return.
2020-05-17 23:35:26 +00:00
Kp 16ae2e7b8e Correct case of map PCX files 2020-05-17 23:35:26 +00:00
Kp 699c9bc283 Fix check_header_includes=1 build 2020-05-17 23:35:25 +00:00
Kp df9a2bacf1 Handle gcc-10 truncation warnings in net_udp.cpp
gcc-10 warns that the game information text may be truncated, because it
overestimates the maximum possible length of some strings.  Handle the
warning by changing the format string to explicitly truncate these
strings at their maximum legal lengths.
2020-05-17 23:35:25 +00:00
Kp f30b77c116 Handle gcc-10 truncation warning in mission.cpp
gcc-10 warns that if immediate_directories were very large, the sprintf
result would be truncated.  This is true, but a user is extremely
unlikely to have enough directories to trigger this code path.  Handle
the warning by explicitly returning an empty string if truncation would
otherwise occur.  This is not strictly correct, but it can be handled
with very little code, eliminates the warning, and is unlikely to matter
in practice.
2020-05-17 23:35:25 +00:00
Kp a4f2edfaa9 Move LevelSharedVertexState into d_level_shared_segment_state 2020-05-17 23:35:25 +00:00
Kp fc46e9a97c Only reduce laser power in D2 mode
As reported in pull #507, the D1 implementation of the reduction was
incorrect and never reduced laser power.  Therefore, when D2 emulates
D1, D2 should emulate the effect of the bug, by not reducing laser
power.
2020-05-06 03:04:45 +00:00
Kp 44c4f0bde0 Move is_laser_weapon_type into #ifdef D2
The preceding commit eliminates the only use of is_laser_weapon_type by
D1 code, so now the function can be moved into a #ifdef D2 block.
2020-05-06 03:04:45 +00:00
AlumiuN 072bb54ff2 Exclude D1 player lasers from the quad laser damage reduction
The code that provides the 0.75x multiplier to laser bolts when they're fired
using the quad laser is present in D1 as in D2, however it is incorrect and
results in it not being applied. As such, it is more accurate to exclude the
multiplier when compiling D1.

Thanks to SaladBadger for the tip.
2020-05-04 20:20:41 +12:00
Kp 2f3a76ab15 Revert laser weapon type checking to 0.58.1
Commit 2bcc7bb371 restricted
Laser_create_new to only create lasers for known weapon types.  This
seemed like a good idea, but broke custom levels that use undocumented
laser types.  It also replaced logic that coerced invalid weapon numbers
into a type 1 laser with logic that prevented firing such weapons at
all.  This rendered robots with unknown or broken weapon data unable to
fire.

Commit 0c30fa7cf3 relaxed the logic to
prevent firing only in editor builds, but allow firing unknown or
invalid weapon types in release builds.  Firing unknown weapon types may
work.  Firing invalid weapon types may cause the game to crash when data
is accessed beyond the end of the defined weapon data.  This caused the
crash reported in issue #506.

Revert to the 0.58.1 rule that invalid weapons are coerced to be a
player level 1 laser.  Add a diagnostic when such a weapon is fired,
since the level author should have requested that weapon explicitly if
that was intended.

Reported-by: heftig <https://github.com/dxx-rebirth/dxx-rebirth/issues/506>
Fixes: 2bcc7bb371 ("Only create lasers for known weapon types")
2020-05-02 21:18:43 +00:00