Commit graph

316 commits

Author SHA1 Message Date
Kp 97f0c5a6d0 Pass std::span to decode_data 2022-09-24 17:47:52 +00:00
Kp e5dcb8a505 Prefer C++20 std::span over internal span for decode_row
This generates the same code before and after.
2022-07-30 17:42:59 +00:00
Kp a70188e7a5 Move various static functions into anonymous namespace 2022-07-09 13:39:29 +00:00
Kp b6a26ddc8c Fix high score background truncation
Commit 4d6affd74d ("Fix SDL-only briefing crash") added a hack to
prevent a crash when the briefing window is automatically resized.
However, a logic error in that hack causes some subcanvases that were
not wrong to be truncated.  Change the logic to fix those subcanvases,
such as the one used for rendering a background in the High Scores
window.  The new logic still avoids the crash in in SDL-only mode.

Fixes: 4d6affd74d ("Fix SDL-only briefing crash")
2021-12-01 03:08:27 +00:00
Kp 4d6affd74d Fix SDL-only briefing crash
Trim the bitmap's current width and height to be not more than its
parent.  Otherwise, an automatic screen resize, such as triggered when
playing the robot briefings in Descent 2, will give the window a new
smaller bm_data, but continue to use the old dimensions.  This then
causes load_briefing_screen -> gr_bitmap_scale_to -> scale_line to write
off the end of the smaller bm_data, causing memory corruption and
eventually a crash.
2021-11-01 03:37:20 +00:00
Kp 3cca690728 Assign weakly-typed symbolic names to ogl_ubitmapm_cs special cases 2021-11-01 03:37:18 +00:00
Kp 961aae074a Remove unused ogl_ubitmapm_cs argument scale
Every caller passes `F1_0`.  Remove the argument, and propagate its
results through the function.
2021-11-01 03:37:18 +00:00
Kp aba5fce3a9 Use enum class for gr fade_level 2021-09-19 10:53:48 +00:00
Kp 3c37552e5b Use enum class bm_mode for grs_bitmap::type 2021-09-12 16:20:52 +00:00
Kp 5881af50dd Use __builtin_FILE,LINE for canvas location debugging
This avoids declaring macros for gr_set_default_canvas,
gr_set_current_canvas.
2021-09-12 16:20:52 +00:00
Kp 2c2ef3fa33 Factor out common logic in rle conditionals 2021-09-04 12:17:14 +00:00
Kp 3697aabcdd RLE processing: use varying pointer types instead of multiplication 2021-09-04 12:17:14 +00:00
Kp 5bd093b3cb Rework gr_rle_getsize
- Add a limiter to let it return early when the result is predictable.
  The first caller checks only whether the returned value is above a
  threshold.  Once the value goes above that threshold, its precise
  value will not matter, so stop counting and return early.
- Add comments explaining some of the logic.
2021-09-04 12:17:14 +00:00
Kp 15f944b0b6 Skip trying to rle compress a paged-out bitmap
This would crash if it ever happened, so skip such bitmaps.
2021-09-04 12:17:14 +00:00
Kp 99e14b4100 Factor out common paths in gr_rle_encode 2021-09-04 12:17:14 +00:00
Kp 21f736ec37 Require grs_subcanvas for gr_init_sub_canvas
Prevent passing a canvas that is not specifically typed as a
grs_subcanvas.
2021-09-04 12:17:14 +00:00
Kp 3b5134896f Remove unused return value of gr_bitmap_rle_compress 2021-08-26 03:13:45 +00:00
Kp ec4d75d44e Switch decode_row from xrange to span to better express its operation 2021-06-28 03:37:51 +00:00
Kp 73c3474f8e Reduce uses of RAIIdmem for local variables 2021-06-28 03:37:49 +00:00
Kp ee07a45712 Simplify MALLOC invocations
Remove overload for C array decay, and fix up the call sites that
required it.
2021-06-28 03:37:48 +00:00
Kp 32b7899059 Remove const qualifier from gr_init_bitmap
gr_init_bitmap can be passed a pointer to uninitialized memory, and
will save that pointer into the bitmap for the underlying memory to be
initialized later.  In gcc-11, this triggers a warning because the
`const` qualifier leads gcc to expect that the memory will only be read
(while uninitialized) and not written.

Reported-by: TheDemonicSurfer <https://github.com/dxx-rebirth/dxx-rebirth/issues/593>
2021-06-12 21:07:32 +00:00
Kp 537e9fef37 Throw if a bitmap starts outside its parents boundaries
Such bitmaps will, at best, fail to render due to clipping.  These
should never happen, so report it with an exception if it does.
2021-02-25 03:53:49 +00:00
Dmitry Grigoryev fbd05a1592 optimize include files (include what you use) 2021-02-06 21:38:50 +01:00
Kp 775d039083 Expand gcc memcpy workaround to gcc-10
The upstream bug is still not fixed.
2021-01-17 22:23:23 +00:00
Kp fc63029833 Move more symbols into namespaces 2020-12-26 21:17:29 +00:00
Kp 6285878c4c Add color_palette_index type alias, to note palette-related uint8_t 2020-07-16 02:31:04 +00:00
Kp 8cc7be4986 Use std::bitset to track used colors
This reduces memory usage over using std::array<bool> for the same
number of bits.
2020-07-16 02:31:04 +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 8839f538e0 Refer to <array> directly, not through "compiler-array.h" 2020-05-02 21:18:42 +00:00
Kp 53761500f1 Qualify uses of std::array 2020-05-02 21:18:42 +00:00
Kp 9cee93abb1 Require support for C++14 std::exchange 2020-05-02 21:18:42 +00:00
Kp 334da8e8e6 Move some SDL-only symbols into !DXX_USE_OGL 2019-08-06 02:59:41 +00:00
Kp dd8cfa763f Expand gcc memcpy workaround
Add link to upstream bug report.
2019-07-22 00:51:01 +00:00
Kp e2692d26ab Clear grs_main_bitmap before initializing
No code path has been observed causing a leak by reinitializing without
resetting, but add an explicit reset to prevent future mistakes.
2019-07-07 22:00:02 +00:00
Kp a52d8106ce Use xrange for loops with simple identifier start and simple identifier end
s/for\s*(\s*\(\w\+\)\s\+\(\w\+\)\s*=\s*\([A-Za-z_0-9]\+\)\s*;\s*\2\s*!=\s*\([A-Za-z_0-9]\+\)u\?\s*;\s*\(++\s*\2\|\2\s*++\s*\))/range_for (const \1 \2, xrange(\3, \4))/
2019-05-04 18:27:37 +00:00
Kp 3bd10610fc Use xrange for loops with zero start and simple identifier end
s/for\s*(\s*\(\w\+\)\s\+\(\w\+\)\s*=\s*0\+u\?\s*;\s*\2\s*!=\s*\([A-Za-z_0-9]\+\)u\?\s*;\s*\(++\s*\2\|\2\s*++\s*\))/range_for (const \1 \2, xrange(\3))/
2019-05-04 18:27:37 +00:00
Kp 15ac8a5ac6 Add utility xrange for range-based loops with precomputed bounds
Utility xrange, inspired by the Python2 feature of the same name,
provides an object that returns successive values from [start, end).  It
is useful when the end index is known in advance, and is particularly
helpful when that index is expensive to recompute.
2019-05-04 18:27:36 +00:00
Kp 7bcbaae230 Tighten protection against grs_bitmap bm_data confusion
Bitmaps based on grs_main_bitmap own their data.  Bitmaps based on
grs_bitmap do not.  Adjust prototypes to prevent initializing a
grs_main_bitmap with data it will not own.
2019-02-02 18:36:39 +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 b53be4943c Update memcpy blacklist 2018-08-20 00:34:16 +00:00
Kp f33877d379 Make grs_main_bitmap::grs_main_bitmap() clear the whole structure 2018-07-14 17:23:15 +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 ff49e949d4 Fix savegame thumbnail previews
Transposed arguments to fill_n caused rls_stretch_scanline to write
garbage to the preview buffer.

Reported-by: Havner <https://github.com/dxx-rebirth/dxx-rebirth/issues/354>
Fixes: 8aadb4be5b ("Use fill_n instead of inline loop to write scanline")
2017-11-06 04:24:16 +00:00
Kp 7eadc218a6 Add debugging code to trace global canvas updates 2017-11-05 20:49:09 +00:00
Kp 8684cf5571 Remove unused gr_bitblt_dest_step_shift
It is always 0, and has been since it was imported in D2X.
2017-11-01 02:01:20 +00:00
Kp 0909b126ac Simplify gr_rle_expand_scanline_generic
Both the `if` and `else` paths had the same loop and post-loop
processing.  The `if` path was a strict subset of the `else` path.  The
`else` path had one setup statement, and was otherwise equal to the `if`
path.  Move the shared statements outside the guarded path.
2017-10-06 01:59:09 +00:00
Kp 8aadb4be5b Use fill_n instead of inline loop to write scanline 2017-10-06 01:59:09 +00:00
Kp 49cc3aa324 Work around i686-w64-mingw32-g++ compiler crash 2017-04-22 21:23:55 +00:00