Commit graph

9835 commits

Author SHA1 Message Date
Kp c816a79c47 Always check external levels for connectivity errors
Players keep reporting errors that trace to the game rejecting invalid
data from user-made maps.  In this case, asymmetric connectivity in
_Descent Vignettes_[1] level _Stalactite Volcano_ (level 15 in Descent,
level 14 in Descent 2) caused an exception when trying to render part of
the first big room.

The debug build shipped with function `check_segment_connections` to
detect some types of connectivity errors.  Expose this function to
release builds, and call it for user-made maps.  It already checked for
asymmetric segment links.  Extend that to hotfix those links by breaking
the asymmetric connection.  Log an URGENT class message when this
happens, so that users are aware that the level was modified at load.
Move the `NDEBUG` guards into `check_segment_connections` so that
non-debug builds check only for segment symmetry, but do not check for
normals and face count errors.

[1] http://www.enspiar.com/dmdb/viewMission.php?id=724
```
sha1sum vignette.hog vignette.msn
3cd659e6dd5927b41157dfb7d1dd87d90e781f01  vignette.hog
1f7d140ffab11816364040dd6da71a1568393a16  vignette.msn

stat -c '%s %Y %n' vignette.hog vignette.msn
5717889 1251643308 vignette.hog
956 1250212930 vignette.msn
```

Reported-by: MegaDescent <http://forum.dxx-rebirth.com/showthread.php?tid=970>
2017-07-26 03:15:59 +00:00
Kp e8d82d7d85 Pass valptridx factories to static functions 2017-07-26 03:15:59 +00:00
Kp 20a61be716 Flatten serial.h type hierarchy 2017-07-26 03:15:59 +00:00
Kp 988d16c51f Clean up resolution input error handling
Revert to the user's chosen resolution, not to 0x0, which would then be
coerced to the minimum resolution.  When the text says revert, it should
revert, not just pick a size.

Change the "OK" label to say "Revert to NxM" for the resolution it is
reverting to.

Tighten input validation so that a blank width or blank height produce
the correct error message, rather than being coerced to 0, then
rejecting 0 as too small.
2017-07-26 03:15:59 +00:00
Kp eff53bfa90 Tighten OGL cache parameter validation 2017-07-26 03:15:59 +00:00
Kp 4128ce2971 Use compiler-provided integer_sequence when it is depth-efficient
Early implementations of integer_sequence used a naive implementation
that required one level of template depth per additional integer in the
sequence.  Rebirth uses a private alternate implementation named
make_tree_index_sequence that requires only log(N) steps for an
N-element index_sequence.  Recent versions of gcc ship a log(N) version
of integer_sequence.  Probe for that version and, if found, use it
instead of the private implementation, on the theory that the compiler
writers did at least as good a job as I did, and possibly better if they
were able to leverage compiler implementation details.
2017-07-26 03:15:59 +00:00
Kp 3d4d224ca9 Fix valptridx compound statement emulation on non-gcc compilers
Fixes: 53bf638c2c ("Cache valptridx success check")
2017-07-26 03:15:59 +00:00
Kp 8ccf0e5301 Add PHYSFS_read wrapper support
- Add wrappers for PHYSFS_read and its convenience functions.  Poison
  the memory before calling PHYSFS, so that any uninitialized bytes
  (likely caused by a short read) are reported if the caller tries to
  access the value anyway.
- Add SConstruct options to enable wrapping, so that users do not need
  to enumerate the wrapped functions manually.
- Fix link failure when using LTO+wrappers.
2017-07-26 03:15:58 +00:00
Kp d1c6b89f17 Move dsx::segment -> dcx::segment
d2x::segment has all members of d1x::segment, as well as two new members
exclusive to d2x::segment.  Structure layout is such that d1x::segment
requires the same size allocation, and places anonymous pad members in
the locations that become named members in d2x::segment.  Thus, reusing
d2x::segment for d1x::segment does not change the size of the structure
nor the offsets of any members used.  This reuse may enable some
functions to be better shared by the dsx project.
2017-07-26 03:15:58 +00:00
Kp 2d430596c5 Disallow misnesting for d1x+d2x, not for dsx
Future work will introduce uses of d1x/d2x in the other game when the
types can be usefully shared.  Extend the anti-nesting guards to cover
mistakes that might arise when referring to the namespaces by their
real name, rather than the alias name dsx.
2017-07-26 03:15:58 +00:00
Kp 8b713978fc Ignore bogus POF counts
Instead of blacklisting two specific bad N_save_pof_names values, ignore
all N_save_pof_names that would overrun the Save_pof_names array.

This allows Rebirth to load broken levels such as "Hazard Zone"[1].  In
the case of Hazard Zone, the POF count is simply missing, so the first
two characters of the first POF name were taken as a count.  This led to
a massive overrun of the Save_pof_names array.

[1]:
```
sha1sum hazard.msn hazard.rdl
25abe7ba1aca91f0bd09551e65cfadeabfcb73df  hazard.msn
f5e6761b674b595550b27733fd83eeb2eff5e8f8  hazard.rdl
```
2017-07-15 21:50:22 +00:00
Kp d4f1c894aa Remove write-only global Connected_segment_distance 2017-07-08 18:17:50 +00:00
Kp 30b0ebebb8 Simplify trace_seg visited update 2017-07-08 18:17:49 +00:00
Kp dc33a58225 Use array<> in more places 2017-07-08 18:17:49 +00:00
Kp a7e0e05e19 Rename vertex_array -> vertices
Future work will introduce a typedef vertex_array.  That typedef would
cause these uses to trigger a -Wshadow warning.
2017-07-08 18:17:49 +00:00
Kp 75476e0b1d Simplify D1 Countdown_timer reload 2017-07-08 18:17:49 +00:00
Kp f16c4def1d Unify AI cloak setup
- Initialize AI cloak data in D1, too.
- Initialize reactor's idea of player position from init_ai_for_ship
2017-07-08 18:17:49 +00:00
Kp 596ecbb38d Rename segment::value to segment::station_idx
`value` is generic and unclear.  It is always meant to be used as an
index into the Station array, so rename it `station_idx` to show this.

Define and consistently use `station_none` to represent that no station
is assigned.
2017-07-08 18:17:49 +00:00
Kp 6767045a41 Shrink FuelCenter::Type to uint8_t to match special from struct segment 2017-07-08 18:17:49 +00:00
Kp bc04f3d172 Simplify dumpmine trigger iteration 2017-07-08 18:17:48 +00:00
Kp 0645642465 Fix gcc-4.9 pch=1 extern conflict
Using precompiled headers includes vers_id.h into
similar/main/newdemo.cpp.  gcc-4.9 reports a conflict between vers_id.h
`extern const char g_descent_build_datetime[21]` and newdemo.cpp macro
generated `extern const char g_descent_build_datetime[]`.  The size is
only needed in the definition, so remove it from the declaration to
align with the macro-generated extern.
2017-07-08 18:17:48 +00:00
Kp 0259378860 Pass valptridx factories to static AI functions 2017-06-30 04:09:27 +00:00
Kp 54c573fb22 Adjust valptridx auto-instantiate for -O2 -fno-inline 2017-06-30 04:09:26 +00:00
Kp 117d777c3e Shrink serial debuginfo 2017-06-25 20:46:03 +00:00
Kp 103e4a4fb6 Simplify tree_index_sequence 2017-06-25 20:46:03 +00:00
Kp 1e5bf33fc0 Simplify exact_type
exact_type has only one use of its second template parameter.  Move that
use inline to remove it from the type signature.
2017-06-25 20:46:03 +00:00
Kp 9421c31b5a Replace "compiler-type_traits.h" with <type_traits>
Delete stub "compiler-type_traits.h" header.  Redirect all uses to the
standard <type_traits> header.

git grep -wlz 'compiler-type_traits.h' -- '*.cpp' '*.h' | xargs -0 perl -p -i <<EOF
    BEGIN {
	    $i = 0;
    }
    if (($i == 1 && $_ eq "\n") || ($i < 2 && /^#include "/)) {
	    # First blank line or first user-include after a system-include.
	    # Print, then never again for this file.
	    print "#include <type_traits>\n";
	    $i = 2;
    } elsif ($i == 0) {
	    $i = 1 if (/^#include </);
    } elsif ($_ eq "#include \"compiler-type_traits.h\"\n") {
	    # Remove this line if found.
	    $_ = '';
    }
    # Reset state machine when moving to next file.
    $i = 0 if eof;
EOF
2017-06-25 20:46:03 +00:00
Kp adcf02e454 Expand tt:: indirection to std::
All supported compilers have an acceptable <type_traits>.  Commit
4cb3d46148 ("Move <type_traits> test to Cxx11RequiredFeature") made
<type_traits> support mandatory in August and no one has objected.
Remove the indirection and use namespace std directly for type_traits
members.
2017-06-25 20:46:03 +00:00
Kp b550a5aa13 Unify segment2_read
Early unification efforts missed this one because it was in gamemine.c
for Descent 1, but segment.c for Descent 2.  Move it to gamemine.cpp for
both, so that it can be static for both games.
2017-06-17 23:05:16 +00:00
Kp aa47435009 Remove write-only field FuelCenter::MaxCapacity
This is a remnant of a pre-retail design that allowed fuel centers to
be exhausted.  No one has ever asked for this mechanic, so remove
support for it.
2017-06-17 23:05:16 +00:00
Kp b83ac0acfa Update SConstruct comment regarding gcc bug #70844 (-Wuseless-cast) 2017-06-17 23:05:16 +00:00
Kp 20b8a6738c Use range_for in paging_touch_walls 2017-06-17 23:05:16 +00:00
Kp 73d92bb509 Make wclip::num_frames uint16_t 2017-06-17 23:05:16 +00:00
Kp bca7823423 Use range_for+partial_range in paging_touch_model 2017-06-17 23:05:15 +00:00
Kp 57b67078da Exclude valptridx.tcc from PCH
It is not meant to be included in every file.  Starting in gcc-7, static
functions declared in valptridx.tcc generate -Wunused-function warnings
if the including file does not instantiate any templates that use the
static function.  Avoid these warnings by including the tcc only in a
file that is guaranteed to instantiate templates that use these
functions.
2017-06-10 03:31:04 +00:00
Kp ab98ba6677 Indent medlisp_update_screen test to silence -Wmisleading-indentation
This commit makes only whitespace changes.
2017-06-10 03:31:04 +00:00
Kp c25041fb41 Use array<> for editor Views 2017-06-10 03:31:04 +00:00
Kp 73057ad8ec Suppress unhelpful gcc-7 warnings for now
gcc-7 warning -Wformat-truncation would be good to fix, but the compiler
does not offer an acceptable solution yet.

gcc-7 warning -Wimplicit-fallthrough requires more analysis of the
diagnosed sites to identify which, if any, require a resolution other
than suppressing the warning.
2017-06-10 03:31:04 +00:00
Kp 4e578df4c6 Validate range for d1 bmread ab_load 2017-06-10 03:31:04 +00:00
Kp 8a038de506 Tighten Marker_viewer_num validation 2017-06-10 03:31:03 +00:00
Kp 0e57e9bbf7 Expand macro to fix gcc-7 portability warning
gcc-7 warns:

    similar/main/mglobal.cpp:119:5: error: this use of "defined" may not be portable [-Werror=expansion-to-defined]
     #if DXX_VALPTRIDX_ENABLE_FULL_TEMPLATE_INSTANTIATION

Fix this by using the long form of the definition.
2017-06-10 03:31:03 +00:00
Kp 5b12f28564 Add workaround for unwanted gcc-6 "used but never defined" warning
gcc-6 issues a "used but never defined" warning for functions which are
declared, never defined, and used only in contexts which are later
deleted by the optimizer.  If the function were actually used, the link
would fail.  Switch to a complicated mechanism to define the function
while keeping it out of line so that __attribute__((__error__)) is
triggered as intended.
2017-06-10 03:31:03 +00:00
Kp 2a8e7dc3b1 Simplify game log timestamp 2017-06-10 03:31:03 +00:00
Kp 7b16571cb2 Rename countarray method count -> size 2017-06-10 03:31:03 +00:00
Kp a03291b036 Rename countarray method size -> max_size 2017-06-10 03:31:03 +00:00
Kp 430f7832aa Move valptridx factories into array_managed_type 2017-06-10 03:31:03 +00:00
Kp 599ac9dee0 Always qualify valptridx type/factory
Previously, valptridx used PREFIX for allow-invalid+mutable, c#PREFIX
for allow-invalid+const, v#PREFIX for require-valid+mutable, vc#PREFIX
for require-valid+const.  Convert the types, factories, and all usage
sites to specify a qualifier for all four combinations:

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

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

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

for the 'm' prefix and:

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

for the 'i' prefix.
2017-06-10 03:31:02 +00:00
Kp f455d5b8a6 Reorder valptridx macro structure 2017-06-10 03:31:02 +00:00
Kp 79e4e0a628 Raise MAX_POINTS_PER_POLY to 64
Past releases had a debug-only assertion that 25 was sufficient, but
then dynamically allocated enough storage for larger models as needed.
Commit 22a34809ee ("Move interpreter g3s_lrgb onto stack") added a
hard limit of 25, but did not detect attempts to exceed this.  Custom
models that exceeded 25 would cause a stack buffer overwrite and likely
crash.  Raise the limit to 64 and add sanity checking to refuse to
render models that exceed MAX_POINTS_PER_POLY.

Fixes: 22a34809ee ("Move interpreter g3s_lrgb onto stack")
2017-06-07 02:44:55 +00:00
Kp d077b32201 Disable newdemo strftime -Wformat-nonliteral warning
Disable gcc's -Wformat-nonliteral for this one call since unchecked
format strings are (1) under the user's control, (2) unable to cause
problems, and (3) very difficult to fully support with the warning
enabled.

Reported-by: parkerlreed <https://github.com/dxx-rebirth/dxx-rebirth/issues/338>
2017-06-07 02:44:54 +00:00