18 Commits

Author SHA1 Message Date
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
John Bytheway 3e920a092b Migrate some JSON APIs to string_view (#64971)
* Start porting JSON code to string_view

This is an initial effort towards porting the JSON code to use
string_view.  The big advantage of using string_view here is that we no
longer need separate char* and std::string overloads of functions,
reducing code bloat.

But the conversion is quite viral; it's necessary to convert all the
APIs used by the JSON code to string_view too.
2023-04-14 10:18:20 -07:00
Binrui Dong e885763abb Simplify StringMaker<T> template specialization in tests (#54075) 2022-01-05 16:35:35 -08:00
Binrui Dong 3acbcaaaf8 Move some template specializations of StringMaker<T>::convert<T> to a cpp file 2022-01-04 02:22:29 +08:00
John Bytheway a17ccb1888 Sunlight angle (#48090)
* Make turn_zero constexpr

* Add features to rl_vec3d

* Construct from rl_vec2d and z-coord
* Extract xy as rl_vec2d
* In-place scaling

* StringMaker support for rl_vec2d

* Add StringMaker specialization for time_point

* Add atan2( rl_vec2d ) overload

* Add units::asin returning units::angle

* Add sunlight angle calculation and tests

This is an initial implementation of sunlight_angle, which should work
OK for the first few days, but will break down before the end of the
first year.

One test plots the path of the sun through the sky at each solstice and
an equinox.  This is intended as a simple smell test that's easy for a
human to see when something has gone wrong with the sun angle algorithm.

* Add analemma unit test

* Tweak sunlight calculation away from reality

Because the game years don't match real-world years, we need to make
some adjustments to the sunlight angle calculations to allow for that.

* Use logical origin of sidereal time

We had an origin of 177, but 180 makes logical sense, so switch to that
as it's easier to understand.

* Derive sidereal time from angle_per_day

Removing one magic constant.

* mean_long, mean_anomaly in terms of angle_per_day

Remove more arbitrary constants from the calculation, and document those
which remain.

* Use game year length, not real-world one

This removes one more arbitrary constant and means that the sunlight
angle calculations ought to work for other season lengths.

* Unit test for handling season length

* Base sunrise and sunset on astronomical maths

This is the first change that allows the sun angle calculations to
actually influence the game.

We switch the sunrise and sunset times to match the sun positions as
calculated by the astronomical equations surrounding the location of the
sun.

This requires changing a few other places in the code, and updating a
lot of tests.

Heavinly inspired by Hirmuolio's work in #47570, but reimplemented
rather than cherry-picked.

Co-authored-by: Hirmuolio <hirmuolio@gmail.com>

* Support eternal season for new Sun calculations

When eternal season is set, always have the Sun behave as it does on
whatever day the game starts.

* Update some comments in sun_test.cpp

* Appease clang 3.8

* Improve comments and variable names

Based on Github review.

Co-authored-by: actual-nh <74678550+actual-nh@users.noreply.github.com>

* Fix clang-tidy issues

* Assume solar time rather than timezone

Previously the sunlight angle code required you to pass a timezone.
Now, instead, it assumes the timezone is local solar time (determined by
the longitude).  This makes some of the calculations simpler and the API
less confusing.

It does mean that the test cases have drifted a little further from the
'true' Boston sunrise and sunset times, but they're still fairly close.

Co-authored-by: Hirmuolio <hirmuolio@gmail.com>
Co-authored-by: actual-nh <74678550+actual-nh@users.noreply.github.com>
2021-07-18 07:57:39 -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 27f4b43c5f Test body_part sorting 2020-08-11 00:56:41 -04: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 273482e551 Add Catch2 StringMaker definition for point 2020-07-07 09:46:13 -04:00
John Bytheway b83fc88b9e Convert itype_id to string_id<itype>
itype_id is (presumably) one of the oldest type ids in the game.  In
particular, it predates string_id, and was simply a typedef of
std::string.

This is bad for type safety.

Make it be a string_id specialization instead, and update the rest of
the code accordingly.
2020-05-19 21:07:40 -04:00
John Bytheway af875611e2 StringMaker specialization for talk_response 2020-04-12 19:56:46 -04:00
John Bytheway 346a794d16 Be more permissive in season length assertion
This was failing on Mingw, probably due to -ffast-math optimizations.
2019-12-31 15:18:29 -05:00
John Bytheway cb5769d40b StringMaker for cata_variant 2019-12-15 15:34:10 -05: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 7493e9b5ad Closing namespace comment 2019-06-24 21:29:16 +01:00
John Bytheway 835421c774 Add a test for item_location stale item handling
This test failed before the changes to use safe_reference.
2019-06-24 08:25:45 +01:00