22 Commits

Author SHA1 Message Date
akrieger 6a3b5fd749 Use constexpr structures in headers for units. (#84983)
Co-authored-by: Andrew Krieger <akrieger@users.noreply.github.com>
2026-01-28 19:40:45 -08:00
ehughsbaird cedd8af571 Display time with months instead of seasons
Split the 364 day year up into months as so:
The seasons are
Dec, Jan, Feb, Mar -> Winter
Mar, Apr, May, Jun -> Spring
Jun, Jul, Aug, Sep -> Summer
Sep, Oct, Nov, Dec -> Autumn

The first month of each season has 31 days, and the first day of each
season is on the 20th of the first month (the last day on the 19th of
the last month).

For season settings other than 364 days, season display is broken and I
need to consider how to implement this correctly.

Some additional logic was needed for the year transition correctly on
Dec 31 -> Jan 1, because turn_zero is the first day of Spring.

The calendar code isn't too gross, but is still gross.
2025-08-05 14:25:08 +00: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
Alexey 07356b65a5 Normalize TEST_CASE names (#66241)
* Convert integer parsing test to use normal TEST_CASEs

* Rename test name too similar to another

* Test to enforce normalized test names

* Normalize TEST_CASE names (scripted)
2023-06-17 13:57:19 -03:00
Binrui Dong 32774b37da Migrate from cata::optional<T> to std::optional<T> (#64333)
Co-authored-by: Kevin Granade <kevin.granade@gmail.com>
2023-03-20 20:11:23 -07:00
akrieger 3b22d13aa9 Move scope helpers to cata_scope_helpers.h 2022-09-15 22:04:51 -07:00
Hirmuolio 291fc8cc4d adjust tests 2022-05-30 19:00:26 +03:00
Binrui Dong b3024a13b3 Fix a MSVC type conversion warning in sun_test.cpp (#54444) 2022-01-15 11:28:23 -08:00
nexusmrsep 192f702a78 Eternal Night & Eternal Day options (#53321) 2021-12-22 20:19:30 -08:00
Hirmuolio 6631d5e0f2 Adjust sun and moon light levels (#50068)
* Adjusted light levels
* sun rises at -1 degree
* various fixes to -1° sunrise
* reduce moonlight by 33%
* fix moon tests
2021-07-31 18:41:30 -07:00
Hirmuolio c6f56f7ae2 Slightly simplify sun position code, add sextant to see sun position (#50062)
* add sextant
* sextant works only outside
Co-authored-by: actual-nh <74678550+actual-nh@users.noreply.github.com>
2021-07-21 11:23:56 -07: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
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
Eric Pierce d4bcccae98 Add new is_day function with tests; final cleanup 2020-04-28 21:36:36 -06:00
Eric Pierce 7aca668e0d Make is_night, is_dawn, is_dusk include endpoints 2020-04-28 21:36:36 -06:00
Eric Pierce 8976919565 Expand the sunlight test, clean things up 2020-04-28 21:35:47 -06:00
Eric Pierce 5155fbde87 Rename is_(sunrise|sunset)_now to is_dawn|is_dusk 2020-04-28 21:35:47 -06:00
Eric Pierce aa869cdb21 Add solstices and equinoxes 2020-04-28 21:35:47 -06:00
Eric Pierce 3118ab04ee Add sun tests and many TODOs
This commit adds a rough sketch of tests on the sun, all passing, along
with many TODOs for things I want to refactor.
2020-04-28 21:35:46 -06:00