52 Commits

Author SHA1 Message Date
Kromgart 09a75ac67d Fix item duplication from spilling (#88854)
* Fix item duplication from spilling

* IWYU again

* Appease clang-tidy, who doesn't agree with IWYU
2026-10-05 15:38:14 +02: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
Procyonae 982df19d0f Change /tests remaining uses of raw string item initialisation to use itype_id s
"remaining uses" being somewhat of an understatement -_-
2025-01-10 15:31:15 +00:00
Paul Harvey 31013881af Body heat temperature refactor to standard units. (#68796)
* Replace the arbitrary body tempurature ints with units::temperature. This does not affect save files or JSON in order to be forwards/backwards compatible, and non-debug displays also use the old format.

* Fix the BMI heat bonus.

* Fix one constant, and remove some uses of auto/default constructor that I missed.

* Replace a C-style cast with a static_cast.

* Refactor the convergence code to be easier to understand, and remove another use of auto I had missed.

* Remove yet more uses of auto. Maybe I have a problem.

* Change ambient temperature calculation be to be closer to the original. Only do the bugged scaling on the delta, not the original ambient temperature.
2023-10-25 21:16:11 -05:00
Kamayana 6a46c5a421 Cache results of item search functions (#67835)
* Cache results of `has_item_with_flag` and `all_items_with_flag`

Adds new functions `add_to_flagged_item_cache` and `remove_from_flagged_item_cache`, as well as new overloads in `visitable` to accomplish this

* Replace some `items_with` with `all_items_with_flag`

* Add special handling for the unique LIGHT flag

* Handle flagged item cache in `item::convert`

* Add note to flag_LIGHT that it's not a real flag

* Open the cache up to expansion beyond just `flag_id`s

* Rename "cache" to "caches"

* Add function `all_items_with` for inventory searches. Replaces `all_items_with_flag`.

There are three overloads for this function. One searches for an item flag, as `all_items_with_flag` did. One searches for all items that pass a specified boolean function. The last one does both. All three add the results to the cache.

* Fix cache handling for item contents

* Embed cache clearing into more item removal functions

Replaces `Character.worn.clear()` with `Character.clear_worn()`. `Character` is now a friend of `outfit` to accomplish this

* Use inv search cache for seeds

* Use inv search cache for cash cards

* Use inv search cache for npc food

* Update some implementations of `all_items_with`

* Use inv search cache for relic processing

* Change cache names to use the function name for simplicity

* Use `all_items_with` for relics in `recalculate_enchantment_cache`

* Include `set` in iexamine

* Use `on_item_acquire` in `convert`

* Handle `i_add` with charged items directly in the function itself

This lets us always assume that calls to the `try_add` overload with copies should, in fact, be doing so

* Adjust `try_add` copies to add all added items to the cache

It used to only add the first item. There's a CPU impact of this change when spawning huge amounts of items, but it's very slight

* Use `has_item_with_flag` instead of `all_items_with` in `link_up_actor`

* Use `all_items_with` for bionic cable functions

* Make `get_cable_vehicle` const

* Make `all_items_with` key use a const reference

* Add `clear_inv` for clearing Character's inventory and cache

* astyle invlet test

* Revert "Add `clear_inv` for clearing Character's inventory and cache"

This reverts commit 944d768dd1.

* Make cache use vectors of items instead of sets

* Deduplicate code in `all_items_with` overloads

Co-authored-by: andrei <68240139+andrei8l@users.noreply.github.com>

* Fix iteration in `remove_from_inv_search_caches`

Temporary measure while I rethink how the cache works. Co-authored-by: andrei <68240139+andrei8l@users.noreply.github.com>

* Greatly rework the item search cache and all its functions

The cache now uses safe references rather than direct item pointers. `all_items_with` replaced with `do_on_items_with`, a function that iterates through the cache, applying a given function to the items and removing invalid item pointers as it goes. There's also an overload that gives the function a boolean `abort` parameter that, if ever set to true, exits the loop immediately and returns true. Also adds `get_items_with` for creating a vector of all the cached item pointers.

* Remove `remove_from_inv_search_caches`

Also reverts changes that were made earlier to accomodate manual cache removal

* Replace `has_item_with_flag` with `has_any_item_with`

I went with a unique function name rather than overloading `read_only_visitable::has_item_with` since visitable can't use the caches, so they're worth differentiating

* Consolidate `do_to_items_with_until` and `has_any_item_with`

They basically did the same thing

* Leftover debug line

* Add `do_and_check_func` to `get_items_with`. Adds const versions

* Rename `get_items_with` to `all_items_with`

* Make `has_any_item_with` use const item references.

The const_cast added to radiocontrol is temporary

* Fix returns

* Fix radio control handling

Specifically, fixes the game letting you activate an RC with a bomb in your inventory (it doesn't activate but it also doesn't warn you). Adds a const version of the item pocket chain's `get_item_with`s to accomplish this

* Add additional overload to inv search functions that looks for an item type id

* Only cache flags of the item's type, not the item specifically.

We should only use const flags for caches, not ones that can be set/unset

* Add `can_link_up` for optimizing cable finding

* Implement inv search cache functions

* Temporary fix for item tests

I need to think about how to handle non-type flags

* Change all the item search function names to specifically mention the cache

I grew to dislike the "almost but not quite the same as visitable" names I've been using. These names are clearer

* Make separate const versions of `cache_visit_items_with`

It's better design to do this; `inv_search_caches` being mutable was causing ambiguity

* Bring back `has_item_with_flag`

Now that `cache_visit_items_with` only accepts item type flags, the original functionality to check for non-type flags like WET has been lost. This brings that back.

* Unused lambda captures

* Reference the references

---------

Co-authored-by: andrei <68240139+andrei8l@users.noreply.github.com>
2023-09-04 23:47:42 -05: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
Zhilkin Serg e44f38af40 Remove excessive empty lines 2022-12-06 10:42:15 +03:00
Dillon Matchett 09d7a966a0 updated fixes for temperature regulation (#62392) 2022-11-25 19:03:28 -05:00
Hirmuolio e547ae781f Make environment temperature to use units::temperature (#58852)
* update get_temperature

* update print_temperature

* tests

* get_local_windchill

* tests run

* make tests pass

* astyle

* cleanup

* weather_generator temperature

* astyle

* cleanup

* get_heat_radiation

* get_convection_temperature

* map temperature mod

* astyle

* weather.temperature

* avoid integer division

* clean get_local_windchill

* unused converts

* get_water_temperature

* unused converts

* windchill tests

* delta F corrected

* wrong unit

* astyle

* dTand wetness morale

* misc cleanup

* astyle

Co-authored-by: Fris0uman <41293484+Fris0uman@users.noreply.github.com>
2022-08-17 12:43:54 +02: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
John Bytheway b285a13080 Make time_point( int ) constructor explicit
Resolves a TODO on that constructor, and one more TODO elsewhere due to
the resulting refactoring.

time_point was implicitly convertible from int.  This led to unclear
code.  In particular, the item constructor took a time_point and a
quantity, and these two ints appeared adjacent with no obvious way to
see what they meant at call sites.

Make the constructor explicit, so the conversion is no longer implicit.
Update the rest of the code accordingly.

In most cases switched from 0 to calendar::turn_zero, which is
equivalent.  In a couple of places, used start_of_cataclysm instead,
when it seemed more appropriate (such as birthday of toilet water).
It's possible there are more cases which should have been something
other than turn_zero.
2020-11-10 11:21:02 -08: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
Fris0uman 00baf2b753 Move remaining enum arrays to bodypart (#41877) 2020-07-20 01:09:33 +00:00
Kevin Granade 501f14189b Map reference migration part nine (#41717)
* Map reference migration part nine

* Downgrade avatar references to Character

Reducing inclusions of avatar.h and player.h
2020-07-01 14:14:36 +03:00
Kevin Granade 438774d386 Global getters (#41347)
* Make Character::stat into a standalone enum class

Enables forward declaration

* Remove player centric overload and unecessary include

* Remove player.h dependency from trap.cpp

* Add singleton-like accessors for avatar, map, weather and event_bus

* use accessors to remove includes of game.h
2020-06-16 16:48:45 +03:00
ZhilkinSerg 85c2e889a1 Remove empty statements 2020-05-27 02:10:24 +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
KorGgenT f42afc59d4 test includes 2019-05-21 10:25:49 -04:00
KorGgenT 23660d628d encapsulate weather 2019-05-14 14:36:41 -07:00
John Bytheway e3e7700aef Apply IWYU changes
This is a run of IWYU followed by astyle.
2019-04-22 11:42:51 +01:00
ZhilkinSerg c0bce91fa1 Used const where appropriate 2019-01-06 23:00:08 +03:00
John Bytheway b0576393e3 Sort headers according to IWYU conventions
A first step towards IWYU support.  Doing the sorting first because it
makes reviewing any additions or removals of headers much simpler.

The IWYU order is:
- Associated headers
- Misc system headers
- C++ STL headers
- Other project headers

The biggest change is moving system headers before project headers (they
are usually afterwards in Cata at the moment.

The associated header for a cpp file is the header file which declares
the functions defined in that cpp file.  Normally that's the one which
shares the same name (up to extension), and if so IWYU figures it out
automatically.

However, in this project there are many corner cases, so we need to use
IWYU pragma: associated to tell it which header (or, in some cases,
which headers) is the associated header.  We are unusual in having
multiple associated headers for some files, which might lead to
discovering some interesting IWYU bugs later, but in theory it is
supported.
2019-01-05 14:03:31 +00:00
ZhilkinSerg f8eb2acd05 Optimized includes (tests) 2018-11-07 03:55:47 +03:00
ZhilkinSerg 7fe5e49120 Used constant references instead of copying (tests) 2018-10-05 22:44:10 +03:00
Kevin Granade fd98255b78 Low hanging astyling, the return of the revenge. 2017-09-28 03:13:04 +00:00
Kevin Granade f649a4c056 Disable and loosen requirements of the last of the flaky tests. 2017-05-25 03:00:58 +00:00
Oliver Jowett f6130dc153 Tag known-to-fail unit tests with [!mayfail] (#19025) 2016-10-30 13:12:37 +00:00
codemime 1c937dd97b Replace lambda with list 2016-07-04 00:22:46 +03:00
codemime 4ed58fa423 Fix unit tests 2016-07-04 00:22:45 +03:00
Coolthulhu 5092f4f140 Adjustments to metabolic rate, remove obsolete test 2016-02-14 21:50:29 +01:00
Coolthulhu 0c1e2bcf56 Fix test 2016-01-07 06:04:54 +01:00
Coolthulhu 56bd5e81e4 Correct nutrition_for thresholds 2015-12-24 11:38:49 +01:00
Coolthulhu c23895cfa6 Unbreak tests 2015-09-16 00:27:14 +02:00
illi-kun 723ff70365 typo_fixes 2015-08-09 11:21:26 +03:00
Octav Sandulescu eaf8580152 Nitpicks from the Jenkins machine 2015-08-01 10:23:53 +00:00
Kevin Granade a6e5796b7a Get player test working as a regression test at least. 2015-07-27 22:07:22 +00:00
Kevin Granade 345896d35c Merge tests into a single executable. 2015-07-22 21:10:56 +00:00
Kevin Granade f48f788d4c Fix up unit tests again. 2015-05-14 23:12:02 +00:00
Kevin Granade 67e46a24cc Initial integration of unit tests with Catch, plater_test is still broken. 2015-05-14 21:47:03 +00:00
Kevin Granade a76ce6e746 Get unit tests building again. 2015-05-14 21:44:05 +00:00
Kevin Granade b77633c916 Silence some warnings. 2015-04-10 22:25:34 -05:00
Kevin Granade 6b3040cf79 Get temperature unit test compiling again. 2015-04-10 22:25:32 -05:00
Kevin Granade d52d92dc00 Switch testing dependencies to libtap++ and get tests at least building again. 2014-03-16 17:45:10 -05:00
Shoes01 1bb2d8c0a4 Loose ends regarding ice labs and get_temperature function 2013-08-24 15:17:06 -07:00
Shoes01 e1e17dd304 Made appropriate changes to use get_temperature() function 2013-08-24 14:07:40 -07:00
Octav Sandulescu 3625b660e4 Remove unused map.itypes; use g->itypes where needed.
It was only two places.
2013-07-05 19:21:20 +01:00
cib 155b363140 Removed the mapitems global and all references to it.
This global has been superceded by data/raw/item_groups.json
2013-07-04 10:05:40 +02:00
Kevin Granade b0345c2f7b Update unit test to use overmapbuffer. 2013-05-16 19:13:43 -05:00