27 Commits

Author SHA1 Message Date
moxian c44d65a8ae Run IWYU again to pick up the changes 2025-02-11 13:02:19 -08:00
moxian e2f7aaf95f Modernize c headers (stddef.h -> cstddef &co)
Code size:
includes:
$ cat obj/tiles/*.inc | wc
 278247  556494 17375710
$ cat tests/obj/tiles/*.inc | wc
 163745  327490 10307041

post-processed source (clang -E):
./make_preproc.sh src/
65903054 170378741 2049783477
./make_preproc.sh tests/
38434408 100326802 1215849078
2025-02-10 13:56:09 -08:00
moxian 2ee44002fd Mechanically IWYU the tests
python3 ~/github/include-what-you-use/iwyu_tool.py -j5 -p build $( find
src/ tests/ -maxdepth 1 -name '*.cpp' | grep -v -f
tools/iwyu/bad_files.txt )  --  -Xiwyu --comment_style=long -Xiwyu -
-max_line_length=1000 -Xiwyu --cxx17ns -Xiwyu
--mapping_file=../tools/iwyu/cata.imp   | tee out/iwyu/f-a-01.txt >
/dev/null

followed by

cat out/iwyu/f-a-02.txt | python3
~/github/include-what-you-use/fix_includes.py --reorder --nosafe_headers

followed by manual fixups of <stddef.h> -> <cstddef> and similar.

tests/generic_factory_test.cpp gets mangled very badly (IWYU bug) so
it's excluded from the list.

Code size:
includes:
$ cat obj/tiles/*.inc | wc
 288068  576136 17898260
$ cat tests/obj/tiles/*.inc | wc
 167044  334088 10465766

post-processed source (clang -E):
./make_preproc.sh src/
68567896 177775140 2134075721
./make_preproc.sh tests/
39341957 102891720 1243323710
2025-02-10 00:46:57 -08:00
Clarence "Sparr" Risher 8b27b967ae Replace point constants with static class members 2024-11-26 10:14:26 -05:00
andrei 37ed546f5e tests: fix locale-dependent tests (#66065) 2023-06-13 12:28:16 -07:00
John Bytheway ba794fe260 Enable clang-tidy check cert-err33-c
This check looks for unused return values on a variety of C library
functions.

I resolved most of the warnings by printing out some kind of error
message in the event that the function failed.

Many of them are low-level things whose failure indicates some sort of
serious problem, so the errors are simply printed to stderr, because our
usual error reporting infrastructure might not be available.
2023-05-24 07:13:18 -04:00
Kevin Granade d4f1a7dff7 Fix nolint directives 2021-07-10 13:55:36 -07:00
Kevin Granade 955ab31fb5 Silence more clang-tidy warnings 2021-07-10 12:00:08 -07:00
Kevin Granade 789c7a4689 Unlimited map memory (#47253)
* Encapsulate map::drawsq() arguments and clarify their meaning

* Split map memory into submap-sized chunks

Note: this naive implementation significantly lowers FPS

* Optimize map memory access

Move memorized submaps that would be
affected during drawing into a 2d array.

* Save/load memorized submaps; migrate old mm file

* Remove leftovers from map memory limit

* Some map memory cleanup

* Don't save empty mm submaps

* Deallocate far-away mm submaps on save; report save failure

* Rework tests for map memory

* Don't re-allocate region if old region contains required submaps

* Remove map_memory.h from avatar.h

* Rename memorized_submap -> mm_submap

* Rename mm_submap::clean -> mm_submap::empty, add comments.

* Improve drawsq_params interface

* Remove map_memory.h from lru_cache.cpp

* Add function for rectangle overlapping

* Save mm_submaps in regions

* Fix save/load not using avatar's global pos, improve docs.

* When saving, compress mm_submaps using RLE

* Simplify map rendering in ascii mode

Collect map::draw code in one place, simplify indexing/bound checks.
Remove the "batch drawing" optimization: it doesn't help with drawing, but harms code clarity. Instead, convert all relevant draw methods to use 'wputch' and rely on caller to position the cursor properly.

* Memorize off-screen tiles in ascii mode

* Fix copypasted code

* Fix tile memory saving code, minor cleanup.

* Add debug logging for tile memory operations

* Fix broken saving for tile memory submaps with z != 0

* Lazy allocation for tile memory submaps

Co-authored-by: olanti-p <olanti-p@yandex.ru>
2021-07-08 20:08:30 -07:00
John Bytheway ebd549b300 Fix StringMaker ODR violations in tests
Catch2 provides a customization point for converting our types to
strings by specializing the StringMaker template.

We have some specializations in stringmaker.h, but this feature was only
working intermittently.  I finally figured out that was due to an ODR
violation.  The test files that didn't include stringmaker.h were
compiling a different specialization than the ones that did.

Re-jig the test includes so that any file including catch.hpp also
includes stringmaker.h, thereby ensuring that the custom
specializations are used everywhere and there is no ODR violation.

I achieved this by adding a new cata_catch.h header and making all
existing headers include catch.hpp via the new header.
2021-07-03 07:42:06 -07:00
John Bytheway 10b0cbc81a Ensure classic locale when serializing (tri)points
When investigating a savegame corruption issue, it transpired that digit
separators were being inserted into the integer coordinates of point and
tripoint objects when converted to string.  This caused non-UTF-8
characters to appear in a log message, which corrupted the savegame.

Luckily, it only affected saves where the player had travelled more than
1000 submaps from the origin, so it hasn't been a huge issue.

Fix this and add tests to point_test.cpp.
2021-04-21 19:43:32 -04:00
Binrui Dong 9fdb7ef59c Run IWYU
* Change _ctype.h and __locale to cctype and clocale

* Change _wctype.h to cwctype in game.cpp

* Change __functional_base to functional

* Remove libcxx internal headers

* Remove UNIX system headers

* Fix clang-tidy error with -nostdinc++
2021-02-06 00:18:41 -05:00
Kevin Granade c5ccf0c2c7 IWYU for tests (#42806) 2020-08-09 09:46:57 +03:00
Kevin Granade 6d1841ac67 Precompiled Catch2 header (#42453)
* Hoist catch.hpp include to the top of files

* Precompile the catch header in tests
2020-07-29 01:28:26 +03:00
John Bytheway a17dba9c59 Genericise rectangle and cuboid
To make rectangle and cuboid work more smoothly with the new point
types, make their point type a template argument, and update uses
accordingly.

The new flexibility for these types is used in overmap and overmap_ui.
2020-07-23 09:38:01 -04:00
John Bytheway 0270d2e5df box -> cuboid
Turns out box is the name of an ncurses function, so we can't have a
class template with the same name.  Before I can change cox to a class
template, need to either rename it or put it in a namespace.

Chose to go with renaming it to cuboid.
2020-07-22 09:51:25 -04:00
John Bytheway 8ba3cc4be9 Move box and rectangle to a new header
Plan to expand their functionality to the point where it would bloat the
point.h header.
2020-07-22 07:10:57 -04:00
John Bytheway b3a7b78635 Suppress cata-use-point-apis for coord_point
We don't want to force people to always construct a coord_point from a
point.  Suppress the check in these cases.
2020-07-12 15:50:15 -04:00
John Bytheway 4f597dc72a Make closest_points_first work for all point types
Previously we had separate functions closest_points_first and
closest_tripoints_first.  We'd like to extend this functionality to
coord_point, but it's easier to do if both the raw underlying functions
have the same name (so the generic wrapper can be the same).

To that end, rename closest_tripoints_first to closest_points_first
(they are chosen between based on overload resolution), and add a
wrapper to allow coord_point to be used similarly.
2020-07-08 21:30:13 -04:00
John Bytheway 2fc02d5183 Refactor rectangle and box types
Previously rectangle and box were just a min and max.  Determining
whether the upper bound should be considered to be inclusive was done by
which function was called on it.

I now regret that design choice, and am changing it.  Now the inclusive
vs half-open is part of the rectangle or box type, and the functions are
generic.

This leads to less repetition in the code.

Also, the next step is to make it possible to iterate over rectangles
(to simplify a bunch of our nested for loops), and this design fits much
better for that.
2020-06-11 09:32:31 -04:00
John Bytheway 3e855ff303 Add conversion of points from strings 2020-06-01 09:38:30 -04:00
John Bytheway e189957ff2 Run IWYU 20200408 (#39364)
* Helper script to run IWYU

* Run IWYU

* Update deprecated headers

* Run IWYU again

* Re-suppress cxxabi.h

This pragma got accidentally removed because it was deemed to be a
comment attached to a #include.

* Remove extra SDL header includes

* Fix ime.cpp headers

Some tweaks to help IWYU not break this file by messing with
platform-specific stuff not relevant on Linux.

* Update game.h

* Move new point.h includes inside #ifdef

* Re-add platform_win.h to mapsharing.cpp

* Apply suggestions from code review

Co-authored-by: ZhilkinSerg <ZhilkinSerg@users.noreply.github.com>
2020-04-10 12:16:19 +03:00
codemime 36402aab06 Improve overmapbuffer searching routines (#37482)
* Add simple unit tests for `closest_points` functions

* Minor simplification and optimization of `closest_points` functions

* Allow specifying minimal distance in `closest_points` functions

* Use `closest_points` functions for overmap buffer search
2020-01-29 21:50:09 +03:00
John Bytheway 7bda6884c3 Custom clang-tidy check to suggest use of named point constants (#33200)
* Initial version of UseNamedPointConstantsCheck

This is intended to convert hand-rolled point constants like
point( 0, 0 ) into point_zero.

* Apply refactoring pass

* Manual fixup of refactored code

Add various manual tweaks to the automatically refactored code where I
think it makes sense.

* Remove some unnecessary initializations
2019-08-13 23:04:51 +03:00
John Bytheway 62448d28f8 Test for tripoint::xy 2019-07-09 22:14:43 +01:00
John Bytheway 28cbd6f70f Refactor generic_inbounds
Rather than having a free function for generic_inbounds, have two member
functions on each of rectangle and box to test bounds.

Rather than having an optional 'clearance' parameter, have two names for
the two common bounds types (inclusive and half-open ranges).

Refactor all uses to this new API.

The main goal here is to make it easier to use these bounds tests in
fewer lines of code for common cases.  I also think the member function
form reads more smoothly in code.
2019-07-07 20:54:56 +01:00
John Bytheway 3abb2e49de Add (tri)point::to_string() and tripoint::xy()
Some convenience member functions for these types.

And some tests.
2019-07-07 20:53:23 +01:00