Commit graph

115 commits

Author SHA1 Message Date
Kp 15e8ceeaa4 Use std::span to bound read_model_file valid bytes 2022-08-22 01:24:49 +00:00
Kp 42caec7e58 Use std::span for pof reading functions 2022-08-22 01:24:49 +00:00
Kp c5c5e8ea39 Simplify pof_read_angs
The caller passes a length of 1, so inline that and simplify the
function.
2022-08-22 01:24:49 +00:00
Kp 69579df368 Simplify pof_read_short
Use the general little-endian helper.
2022-08-22 01:24:49 +00:00
Kp 87c79206e8 Simplify pof_cfread
All callers pass a value of 1 for one of the two length terms, so inline
that and eliminate the multiplication.
2022-08-22 01:24:49 +00:00
Kp bfb7ed7efc Simplify pof_read_vecs
All callers pass a count of 1, so inline that and eliminate the loop.
2022-08-22 01:24:49 +00:00
Kp a70188e7a5 Move various static functions into anonymous namespace 2022-07-09 13:39:29 +00:00
Kp fdf5836031 Move g3 instance contexts onto the stack 2021-09-04 12:17:14 +00:00
Kp 1c13d3c8d3 Improve error reporting for PHYSFSX_openReadBuffered
Return the PHYSFS error code on failure, so that callers can report why
the open failed.
2021-07-25 23:00:56 +00:00
Dmitry Grigoryev fbd05a1592 optimize include files (include what you use) 2021-02-06 21:38:50 +01:00
Kp c96671f763 Move Pof_names to d_level_shared_polygon_model_state 2020-08-24 01:31:28 +00:00
Kp 8a1bc7f318 Move Exit_models_loaded into d_level_shared_polygon_model_state 2020-08-24 01:31:28 +00:00
Kp 0eaabdb2fb Move N_polygon_models into d_level_shared_polygon_model_state 2020-08-24 01:31:28 +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 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
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
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 db7b4b3f88 Refer to <memory> directly, not through "compiler-make_unique.h" 2020-05-02 21:18:43 +00:00
Kp cc38cdf4b8 Qualify uses of std::make_unique 2020-05-02 21:18:42 +00:00
Kp 53761500f1 Qualify uses of std::array 2020-05-02 21:18:42 +00:00
ziplantil 0a21784aa7 some changes as per comments in #479 2019-12-18 13:44:43 +02:00
ziplantil cb2b844af3 do not free extra models when loading exit stuff on D2 2019-12-12 17:25:11 +02:00
Kp 87125c5053 Fix Descent 1 laser color
Descent 1 mangles colors during `g3_init_polygon_model`, so this must
not be called on polygons not designed for mangling.  Rearrange the
logic to allow Descent 1 to verify that polygon models are well-formed
without using the functions that mangle the colors.

Fixes: 42a2e3ab0b ("Avoid crash loading polymodels with invalid subcalls")
Reported-by: derhass <https://github.com/dxx-rebirth/dxx-rebirth/issues/416>
2019-03-20 03:57:15 +00:00
Kp 42a2e3ab0b Avoid crash loading polymodels with invalid subcalls
Truncate the model at the first error.  This allows the level to load,
but makes some or all of the model invisible.
2019-03-06 05:03:48 +00:00
Kp 03fe3a6696 Move Polygon_models into LevelSharedPolygonModelState 2018-12-30 00:43:59 +00:00
Kp 1831148092 Split g3_start_instance_matrix usage
Most uses pass an orientation matrix.  All sites are deterministic about
whether a matrix is passed.  Make the matrix mandatory for sites that
passed it, and split out a separate version of g3_start_instance_matrix
for the 2 sites which do not provide orientation.
2017-08-26 19:47:51 +00:00
Kp c3a438b750 Pass draw_polygon_model orient by reference 2017-08-11 23:43:54 +00:00
Kp 1a1e669bc6 Pass vms_angvec &to draw_model_picture 2017-04-30 16:25:16 +00:00
Kp a6cd87613c Pass polymodel &to free_model 2017-02-19 19:33:44 +00:00
Kp 1a7659897a Pass canvas to draw_model_picture 2017-02-19 19:33:44 +00:00
Kp b02e2e9a3a Use range_for in draw_polygon_model 2017-02-19 19:33:44 +00:00
Kp 39071d124d Pass canvas to draw_polygon_model 2017-02-19 19:33:43 +00:00
Kp 85da2c0013 Pass canvas to g3_draw_polygon_model 2017-02-11 21:42:40 +00:00
Kp 590a025a89 Pass canvas to g3_start_frame 2017-02-11 21:42:34 +00:00
Kp 22e364e030 Pass canvas to gr_clear_canvas 2017-01-01 00:45:45 +00:00
Kp b02375bfbd Rename WORDS_NEED_ALIGNMENT to DXX_WORDS_NEED_ALIGNMENT
Rename symbol WORDS_NEED_ALIGNMENT to DXX_WORDS_NEED_ALIGNMENT to show that it is a DXX
symbol, not one inherited from a library.

This is a mostly automated transform, but the changes to SConstruct were
manual.

git grep -wl WORDS_NEED_ALIGNMENT -- '*.h' '*.cpp' | xargs sed -i -e 's/^\s*#ifdef \(WORDS_NEED_ALIGNMENT\)\>/#if DXX_\1/' -e 's/\s*#\(el\)\?if \(.*\)defined(\(WORDS_NEED_ALIGNMENT\))/#\1if \2DXX_\3/' -e 's/^\s*#ifndef \(WORDS_NEED_ALIGNMENT\)\>/#if !DXX_\1/'
2016-10-09 17:35:03 +00:00
Kp 62b58e9890 Move OGL to dxxsconf.h; rename to DXX_USE_OGL
Rename symbol OGL to DXX_USE_OGL to show that it is a DXX
symbol, not one inherited from a library.  Move it to dxxsconf.h to
shorten the command line.

This is a mostly automated transform, but the changes to SConstruct were
manual.

git grep -lzw OGL -- '*.h' '*.cpp' | xargs -0 sed -i -e 's/\(\s*#\s*if\)def\s*OGL/\1 DXX_USE_OGL/' -e 's/\(\s*#\s*if\)ndef OGL/\1 !DXX_USE_OGL/' -e 's/\(\s*#\s*if !\?\)defined(OGL)/\1DXX_USE_OGL/'
2016-09-24 18:06:11 +00:00
Kp ee1003f29f Move conditionally compiled code into namespace dsx 2016-08-25 04:05:32 +00:00
Kp b35a893d9a Rewrite simple pointer casts from C style to reinterpret_cast<>
s/(\s*\(\w\+\s*\*\+\)\s*)\s*(/reinterpret_cast<\1>(/g
2016-07-03 00:54:15 +00:00
Kp f5aed82d83 Rewrite simple pointer casts from C style to reinterpret_cast<>
This pass only targets int16_t and uint16_t.

s/(\s*\(u\?int16_t\s*\*\+\)\s*)\s*(/reinterpret_cast<\1>(/g
2016-07-03 00:54:14 +00:00
Kp 3469ff8c34 Change (short*) to (int16_t*)
Uses of `(short*)` usually want exactly a 16-bit signed integer.  Most
platforms provide that as `short`, but that is not guaranteed.

s/(short \(*\+\)\s*)/(int16_t \1)/g
2016-06-27 04:11:13 +00:00
Kp a4967ffceb Move various robot data into namespaces 2016-06-25 23:21:36 +00:00
Kp a3e65f64ea Use range_for for polyobj_find_min_max 2016-06-25 23:21:36 +00:00
Kp 89ddc1b911 Add parentheses around casts of simple array subscripts
C casts do not require parentheses.  C++ casts require grouping around
the target.  Prepare for conversion to C++ casts by adding otherwise
unnecessary parentheses around the target of simple C casts.

s/\((\s*\(\(un\)\?signed\|int\|char\|short\|long\|float\|double\|s\?size_t\|\(u\?int[[:digit:]]\+_t\)\)\s*\**\s*)\s*\)\([&+-]\?\)\([[:alnum:]_.]\+\s*->\s*\)*\([[:alnum:]_.]\+\)\(\s*\[[^][]*\]\)*\(\s*\([];+>)*\/^%,|&<>]\)\|$\|\(\s*-\s*[^>]\)\)/\1(\5\6\7\8)\9/g
2016-06-25 23:21:36 +00:00
Kp 231223895d Rewrite simple pointer casts from C style to reinterpret_cast<>
This pass only targets commonly used standard types.

s/(\(\s*\(\(un\)\?signed\|int\|char\|short\|long\|float\|double\|s\?size_t\|\(u\?int[[:digit:]]\+_t\)\)\s*\*\)\s*)\s*(/reinterpret_cast<\1>(/g
2016-06-05 01:04:26 +00:00