104 Commits

Author SHA1 Message Date
dobbry-vechur 3251a77a07 Keep the crouch cover and own-tile view with the avatar
- crouch cover and the always-visible own tile are overrides on the
  avatar's copy of the transparency cache
- they were reapplied only when that cache was rebuilt, so they stayed
  where the avatar had been; in fog a map shift showed a 4x3 patch
- each build now restores the cells it overrode last time and applies
  the new ones; the manual dirty calls for crouching go away
2026-10-02 06:36:11 +04:00
dumb-kevin 05ab42807e tests/: wrap TU-local test fixture types in anon namespaces
- addiction_test: wrap addict_effect_totals
- battery_density_test: wrap battery_chemistry_family
- comestible_test: wrap all_stats
- encumbrance_test: wrap add_trait
- invlet_test: fuse inventory_location + invlet_state + test_action enums
- throwing_test: fuse throw_test_data + throw_test_pstats, move operator<< inside anon-ns
- vehicle_test: wrap vehicle_preset, damage_preset, folded_item_damage_preset, fuse rack_activation + rack_preset
- vision_test: wrap vision_test_case
- water_movement_test: fuse 6 swimmer/swim structs into one block
- weakpoint_test: wrap weakpoint_test_data, weakpoint_expectation, weakpoint_report
2026-05-12 10:53:28 +04:00
dumb-kevin 77a999f2fa Mark TU-local helper templates static
- use_amount_stack template in map.cpp is only used inside the TU
- npc_pickup_from_stack template in npcmove.cpp is only used inside the TU
- silences misc-use-internal-linkage
2026-05-09 10:02:28 +04:00
dumb-kevin 7c59e73417 Skip color blur when no colored lights, LUT for castLight distances
Skip the 3x3 color blur in generate_lightmap when no colored light
source was applied. Track via level_cache::has_colored_lights flag
set in apply_light_source and apply_light_arc.

Replace rl_dist(tripoint::zero, delta) in castLight inner loop with
a precomputed 61x61 LUT for trigdist mode and inline Chebyshev for
square distance mode. Eliminates sqrt from the hottest code path.
2026-03-26 18:06:23 +04:00
moxian c44d65a8ae Run IWYU again to pick up the changes 2025-02-11 13:02:19 -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
PatrikLundell 456a199f5c typified a bit of map.cpp and dependents 2024-10-08 16:23:15 +02:00
PatrikLundell 128e94132b typified a bit of map.h/cpp + dependencies (#76795)
* typified a bit of map.h/cpp + dependencies

* demanded changes

* sorted out merge mess
2024-10-06 22:42:35 -05:00
PatrikLundell ec028a90be typified lightmap 2024-05-07 16:05:53 +02:00
Rewryte 32e562d880 Ledges provide sight coverage (#67434)
* ledge coverage

* update vision mod formula

* creature size determines eye level

* rename params

* only low to high elevation

* add furniture to calc

* prevent vision mod 0

* typo

* astyle

* rename params in h

* fix tangent calc

* cap minimum coverage

* support ledge coverage looking down

* downwards ledge coverage fixes

* change param to creature

* viewer eye level crouch prone support

* add ledge coverage to lightmap

* fix incorrect ledge distance calculation

* remove redundant calc

* update test

* set default furniture coverage to 0

* separate cache process function

* remove unused includes

* fix tests

* ledge_coverage support tripoint to tripoint

* use origin for post processing

only relevant for tests where origin might not match player position

* fix ledge coverage not applying underground

* update test

previous change in test result was caused by an invalid viewer position used in ledge calculation

* Update tests/shadowcasting_test.cpp

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* make function const

* fix crouch and prone not affecting lightmap

* use 3d range setting

* unify above ledge and below ledge code

* use trig_dist instead of rl_dist

* tweak furniture eye level adjustment

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2023-10-27 00:31:39 -05:00
John Bytheway c000771088 Re-enable cata-almost-never-auto
In LLVM 16 this check was a lot more effective.  So, it was briefly
disabled during the migration.  This fixes all its warnings again, and
re-enables it.
2023-05-20 08:55:37 -04:00
John Bytheway 66746d1e9c Enable clang-tidy check modernize-avoid-c-arrays (#60191)
* Enable clang-tidy check modernize-avoid-c-arrays

Convert various arrays to std::array

* Fix more array warnings

These issues were found in CI due to it compiling with different
features than me.

* Don't us sizeof( std::array )

It's clearer to use .size().
2022-09-02 21:15:39 -03:00
John Bytheway 787f6628b1 Add a default size to cata::mdarray
Some common uses of cata::mdarray have very predictable sizes.  Define
some default sizes for those cases to reduce verbosity at use sites.

For example, when using point_bub_ms coordinates, the size is probably
MAPSIZE_X x MAPSIZE_Y.
2022-08-06 21:31:16 -04:00
John Bytheway 02ead51365 Convert shadowcasting and level caches to mdarray
Use the new mdarray for 2D arrays used in the various level caches.
This also required changing the shadowcasting code.
2022-07-30 12:03:42 -04:00
John Bytheway eb4f31c81b Avoid capture defaults in most new lambdas 2022-07-11 13:03:05 -04:00
John Bytheway 2a4236eb5c Enable clang-tidy check modernize-avoid-bind
This check looks for uses of std::bind and suggests replacement by
lambda expressions.

The replacements were usually pretty ugly and sometimes didn't work at
all so I rewrote them all.

Unfortunately, astyle is not good at formatting lambda expressions, so
the results are still often ugly.  But I claim that they are easier to
follow than the bind expressions, especially for folks who don't know
what bind does.
2022-07-11 08:59:28 -04:00
John Bytheway be19f9b528 Avoid large stack objects
The Windows stack size limit is smaller than Linux, so need to tweak
some code to avoid large objects on the stack.

(Not all of these changes were actually causing stack overflows.  I set
the limit for the clang-tidy check at 100KiB, which is quite
conservative, but also reasonable, IMO.  Such large objects are probably
best not put on the stack.
2021-09-20 11:11:53 -04:00
John Bytheway 159413daa2 Enable clang-tidy bugprone-branch-clone (#49629)
* Enable bugprone-branch-clone

This check looks for multiple branches of an else-if-chain or switch
that are the same.  This is often a sign of a copy/paste error.

The cases that hit in these changes did not include any copy/paste
errors, as far as I could see, but they did highlight quite a few cases
where the code could be usefully refactored.  I did that, and in other
cases I just suppressed the error.

Did fix one small bug related to furniture moving weariness, but that
was just because I happened to be pointed at nearby code, not because it
specifically related to the check.

* Move utf32_to_utf8 to json.cpp

When I deduplicated this function I previously kept the version in
catacharset.cpp, but that breaks the link for the json formatter, so
instead keep the version in json.cpp.

Co-authored-by: actual-nh <74678550+actual-nh@users.noreply.github.com>
Co-authored-by: Kevin Granade <kevin.granade@gmail.com>
2021-07-12 10:17:17 -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
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
ZhilkinSerg 0b6d4f0a7c Use const references in function parameters 2020-10-09 00:49:56 +03:00
ZhilkinSerg 9565c9d085 Removed empty lines, unused and empty declarators 2020-10-09 00:49:55 +03:00
Kevin Granade cdaeab6eeb Simpler array initialization 2020-10-06 20:08:11 +00:00
Kevin Granade a67e7a86ee Bracketses 2020-10-04 03:13:42 +00:00
Kevin Granade 1798da8581 shadowcasting benchmark 2020-10-02 05:02:18 +00:00
Kevin Granade 9f6b2467f7 Clarify some shadowcasting test details 2020-09-27 03:51:08 +00:00
Kevin Granade 88b79eebd1 Add a shadowcasting unit test 2020-09-27 03:51:08 +00:00
Isaac Freund df8ae4a895 Fix memory leak 2020-09-27 03:51:08 +00:00
Kevin Granade 32aa793933 Add some 3D tests. 2020-09-27 03:51:08 +00:00
Kevin Granade b10cb434a2 Extend shadowcasting test to 3D 2020-09-27 03:51:08 +00:00
Ivan Zaitsev 9b2264e1de Fix #44068 (thick smoke causes character sprite to disappear completely) + more (#44112)
* fix #44068 (thick smoke causes character sprite to disappear completely)
fix related issue with character disappearance in the low light
document transparency and related caches

* introduce `VISIBILITY_FULL=1.0f` constant as the starting value for visibility calculation
remove `LIGHT_TRANSPARENCY_CLEAR` usage from tests
fix the crouching case that breaks the tests

* add vision test case for the avatar fully surrounded by walls (or smoke)
2020-09-13 21:40:50 +03:00
John Bytheway bf910e50e3 Declare lots of things static
Use the new clang-tidy check to convert a bunch of declarations to
static.

In a few cases, there were 'secret' dependencies being exposed without
headers.  Convert those to work via headers instead.
2020-09-05 23:13:04 -04: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
ZhilkinSerg e32c4a8b30 Use constexpr instead of macros 2020-06-15 21:24:43 +03:00
John Bytheway 78cb7c199a Automated refactoring of remaining code 2020-06-12 08:29:42 -04:00
John Bytheway 79e544f702 Port even more functions to point
Previously missed things in the test code.
2020-06-09 08:51:05 -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
ZhilkinSerg e1f432d11f Code style (2020-01-13) (#37021)
* Appease clang
* Remove excessive empty lines
* Remove excessive whitespaces before semicolons
* Remove excessive empty lines (tests)
* Remove excessive whitespaces before semicolons (tests)
2020-01-14 01:31:43 +00:00
John Bytheway 9793bfac0e Use point in some more gui code (#34026)
* Consolidate main_menu::LAST_TERM

* Add some point overloads for functions

Also a suppression for an SDL wrapper function

* Refactor calls to new functions

* Port function implementations
2019-09-15 10:30:14 +03:00
John Bytheway ee8d5721bf Refactor callers of line functions 2019-08-18 19:59:00 -04: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 453551807b Omit zero-init of points and tripoints
Explicitly zero-initializing is unnecessary, and to have some code that
does and other code that does not is potentially confusing.
2019-07-30 12:15:18 -04:00
John Bytheway 4321c025d2 IWYU 20190629 (#31990)
* Add IWYU pragma: keep

* Run IWYU and astyle

* Run IWYU a second time

* Prevent #include <cxxabi.h>

Unclear why IWYU thinks this is needed.  It isn't, and it causes
problems on Visual Studio.
2019-07-01 12:25:53 +03:00
John Bytheway a58d75539b Update printf format specifiers
Can't find any format specifier that works portably for int64_t (PRId64
is problematic on MSYS) so just use long longs instead.
2019-06-18 19:10:50 +01:00
John Bytheway e5127560e3 Use int64_t for microsecond counts 2019-06-18 07:43:38 +01:00
ZhilkinSerg 0d06a1316c Used constant references in tests 2019-05-31 17:12:27 +03:00
ZhilkinSerg 913d257b5c Used constant references in tests 2019-05-31 17:12:27 +03:00
John Bytheway f3049e5eea Fix missing declarations (#30739)
* Fix missing declarations
Mark functions with no prior declarations as static, and remove the
unused ones.
* Move debug_is_safe_string definition
Put it inside !WIN32 since it's only used there.
2019-05-22 11:00:54 -07:00