Using "type\nfunction(args)" confuses some parsing scripts. Switch to
the standard "type function(args)" style. Fix sites where keyword
"static" was used after the return type.
No caller passes a key value other than [KEY_F9, KEY_F12]. If one did,
an invalid array reference would occur. Restructure the code to return
on invalid inputs. This fixes a flow control analysis warning.
Per request from Mako88, remove unused loadgl typedefs. loadgl.h
was imported from elsewhere and defines typedefs for many functions
that Descent does not use. Some of these are guarded by WINVER
conditionals and, in Mako88's unspecified environment, defining WINVER
to expose these results in a build failure because the guarded typedef
requires a type that is not defined by the environment.
Compensate for that by removing all unused gl typedefs.
# Save the results to a file, then run the file separately. This
# avoids any chance that sed might try to edit the file while later
# searches are still running.
git grep 'typedef .*OGLFUNCCALL \*' common/include/loadgl.h | sed -e 's/^.*OGLFUNCCALL \*//' -e 's/).*$//' | while read f; do
if ! git grep -q 'DEFVAR\s'"$f"'\>' -- common/include/loadgl.h; then
echo "/\\<$f\\>/d"
fi
done > unused.sed
sed -i common/include/loadgl.h -f unused.sed
Per request from Mako88, remove unused loadgl indirections. loadgl.h
was imported from elsewhere and defines indirections for many functions
that Descent does not use. Some of these are guarded by WINVER
conditionals and, in Mako88's unspecified environment, defining WINVER
to expose these results in a build failure because the guarded typedef
requires a type that is not defined by the environment.
Compensate for that, and likely improve the generated code, by removing
all unused gl symbols.
# Save the results to a file, then run the file separately. This
# avoids any chance that sed might try to edit the file while later
# searches are still running.
s=( `git ls-files '*.h' '*.cpp' | grep -v -F common/include/loadgl.h` )
git grep '#define w\?gl[A-Z]\w\+ dw\?gl' common/include/loadgl.h |
gawk '{print $2;}' | while read f; do
if ! git grep -q -l '\<d\?'"$f"'\>' -- "${s[@]}"; then
echo "/\\<d\?$f\\>/d"
fi
done > unused.sed
sed -i common/include/loadgl.h -f unused.sed
Mako88 reports that an unspecified environment fails to build
playsave.cpp. The failure is because PRIuFAST32 is undefined. In most
environments, SDL automatically includes inttypes.h, which provides
PRIuFAST32. In this unspecified environment, SDL does not include
inttypes.h. Include it explicitly to ensure the definition is
available.
As described in commit 674a921 ("Add workaround for Win32 wrong type for
size_t"), std::array on Win32 returns type std::size_t, which is
`unsigned int` instead of the `unsigned long` seen on Linux. Calling
std::min requires both arguments to have the same type. On Linux, this
required casting the result of size() to `unsigned` to match the other
input. On Win32, that cast provokes a -Wuseless-cast warning. Add a
workaround by removing the cast and instead explicitly setting the type
of std::min's arguments to `unsigned`, then relying on the compiler to
perform an implicit conversion from `unsigned long` to `unsigned int`
on Linux. The value is always small enough to fit in an `unsigned int`,
so no precision loss will occur.
Field width conversion `.*` always takes an `int`.
On Win32, casting `long` to `int` triggers a `-Wuseless-cast` warning.
Omitting the cast works correctly.
On Linux/amd64, casting `long` to `int` works correctly.
Omitting the cast triggers a `-Wformat` warning.
Add a macro that conditionally expands to `static_cast<int>` or to ``,
as necessary for the target platform.
Most 64-bit systems use `unsigned long` for `uint_fast32_t`. Some
32-bit systems use `unsigned int` for `uint_fast32_t`. To handle this,
write_netgame_profile used casts to `unsigned` and a format string of
`%u`. Switch to inttypes format macros so that the format strings are
correct without requiring a cast to handle systems where `uint_fast32_t`
is not `unsigned`.
Most 64-bit systems use `unsigned long` for `uint_fast32_t`. Some
32-bit systems use `unsigned int` for `uint_fast32_t`. To handle this,
ab_load used casts to `unsigned long` and a format string of `%lu`.
Switch to inttypes format macro so that the format string is correct
without requiring a cast to handle systems where `uint_fast32_t` is not
`unsigned long`.
Most 64-bit systems use `unsigned long` for `uint_fast32_t`. Some
32-bit systems use `unsigned int` for `uint_fast32_t`. To handle this,
multi_process_bigdata used casts to `unsigned long` and a format string
of `%lu`. Switch to inttypes format macros so that the format strings
are correct without requiring a cast to handle systems where
`uint_fast32_t` is not `unsigned long`.
Both Primary_weapon and Secondary_weapon should use the underlying enum
type. Primary_weapon uses its enum type now. Secondary_weapon will use
its enum type eventually. Add appropriate casts to newdemo.cpp to keep
it working when those changes are made.
Newer SCons applied a performance optimization that breaks a technique
used in the check_header_includes=1 build. Switch to a technique that
should work reliably on old and new SCons, although with slightly
reduced efficiency in both cases. The effective performance penalty
should be unnoticeable and only applies to developers building with
check_header_includes=1.
The C++11 required feature string was computed once per configured
environment. When two or more environments were configured in a single
run, this was wasteful. Reorder the SConf tests to precompute the
string.