125 Commits

Author SHA1 Message Date
Curtis Merrill 8f20949966 change variables in tests to not be shadowing #defines 2026-10-10 03:42:39 -04:00
dobbry-vechur f2230146c9 Relight each turn only levels whose light can change unnoticed
- do_turn marked every level's light dirty, so seen levels relit every
  turn even when nothing had changed
- now only levels with a blinking lamp or a lit item relight each turn;
  other sources already mark their level when they change
- the dawn, dusk and weather tint is keyed, since nothing marks it
- added a benchmark for a turn with creatures on three floors
2026-10-07 10:23:54 +04:00
dobbry-vechur 208d928b12 Stop forcing a visibility rebuild every turn
- final visibility already rebuilds when its inputs change; the call
  in do_turn only redid the same work
- clairvoyant fields were the one input outside the key; a field
  change now moves its level's field revision, which the key reads
- other callers keep invalidate_visibility_cache for explicit refreshes
2026-10-07 09:20:54 +04:00
dobbry-vechur b8db2350c4 Keep scene caches in step with vehicle changes
- removing a vehicle left its walls, shelter and floors cached, so
  sight checks still hit walls that were gone
- opening an outdoor vehicle door kept its tile sheltered from fog;
  shelter is now rebuilt along with transparency
2026-10-07 08:44:02 +04:00
dobbry-vechur d388e50681 Recast views only for changes they could see
- a scene change recasts only if it touched a tile some view reached,
  including tiles hidden by a ledge
- floor changes always recast, however the floor cache got rebuilt
- a recast clears and scans only the levels that need it
2026-10-07 02:34:39 +04:00
dobbry-vechur a4972d94c8 Cast the avatar's view from its own level
- the cast started on whichever level the caller asked for, so looking
  at another level first changed what the avatar saw
2026-10-06 09:05:30 +04:00
dobbry-vechur 1edec8d1e3 Rebuild final visibility per level when its inputs change
- each level remembers what its visibility was built from: light,
  view, aim, vision threshold and clairvoyance
- a level rebuilds only when one of those changes, replacing the one
  dirty flag shared by all levels
- the published visibility variables always describe the requested
  level
2026-10-06 02:22:32 +04:00
dobbry-vechur ee76be710f Build light per level
- sunlight is built into its own grid per level; each level's light
  starts from it and adds only the sources standing on that level
- building one level no longer writes over another level's light,
  such as its darkness fields
- levels the avatar or a camera sees get full light; the rest get
  sunlight alone, as all levels did before
- open sky above the highest structure is one value, not a full grid
2026-10-05 13:54:21 +04:00
dobbry-vechur c602aca9aa Give each camera its own view
- each camera casts into its own grid, clips ledges from its own
  height, then merges into the camera view
- cameras no longer see through the avatar's crouch cover or erase
  each other's view at ledges
- camera moves, removal and battery loss are tracked per map
2026-10-05 05:17:06 +04:00
dobbry-vechur e045a211f4 Recast the avatar's view only when something it reads changes
- the view keeps what its last cast read: position, range, eye height
  and the mirrors and cameras of the vehicle it stands in
- posture, furniture height and vehicle parts recast the view without
  any caller marking it dirty
- the avatar's own tile stays visible through the display logic
  instead of a cache override
2026-10-05 00:31:50 +04:00
dobbry-vechur f6008130a7 Cache vehicles on the map being built, not the reality bubble
- vehicle caching always used the reality bubble's coordinates
- building another map's caches, as mapgen does, wrote its vehicles
  into the wrong map, corrupted its vehicle list and could hang
2026-10-04 05:58:16 +04:00
dobbry-vechur 3b6a3e04b4 Make line-of-sight checks follow the current scene
- map::sees takes a trace: optical for sight (the default) or physical
  for light and projectiles; flashes, projectiles, sonar and heat use
  physical
- cached answers are dropped whenever the scene changes, not only when
  the avatar's view does
- a check made between two builds first builds pending scene changes
2026-10-03 16:44:01 +04:00
dobbry-vechur 20b6277918 Separate what blocks sight from what blocks light
- new sight caches hold what blocks sight: TRANSLUCENT terrain and
  furniture stop sight but still pass light
- vehicle walls now block sight, light and creature zone flooding
- transparency notices weather, shelter and vehicle changes itself,
  and records revisions that later caches key on
2026-10-03 02:20:28 +04:00
dobbry-vechur 0c4384a787 Add a from-scratch vision oracle and benchmarks
- rebuild_vision_caches_from_scratch builds every vision cache with no
  history, as a reference for tests
- the oracle compares an incremental build after a real change (step,
  door, weather, posture) with that rebuild, cache by cache
- hidden benchmarks time the same changes, to compare with master
2026-10-02 13:30:46 +04:00
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
RenechCDDA da2aaffffd Add quick setup option to clear map 2026-06-22 15:07:51 -04:00
RenechCDDA cb924413e4 Move init_veh_status to an enum (oh god) 2026-05-17 23:11:41 -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
Andrew Krieger 0215b26cce Rewrite all tests to clear map without touching character map memory, for performance. 2026-02-08 23:05:55 -08:00
PatrikLundell 586cf5f1ce Mapify: character etc. sees + sundry others (#79699)
* Mapify: character etc. sees + sundry others

* demanded changes

* Corrected correction
2025-02-18 09:29:22 -06:00
PatrikLundell 7bfa56fa99 Merge branch 'master' into mapify 2025-02-13 08:46:56 +01:00
moxian c44d65a8ae Run IWYU again to pick up the changes 2025-02-11 13:02:19 -08:00
moxian 73ec6e4584 Merge branch 'master' into iwyu-l-27 2025-02-11 10:40:53 -08:00
PatrikLundell 0ac675121c mapified a little item prompting a lot of vehicle 2025-02-11 15:10:00 +01:00
PatrikLundell 470e1312ee mapified a lot of vehicle stuff (#79611)
* mapified a lot of vehicle stuff

* fixed complaint, but properly
2025-02-10 17:25:39 -06: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
PatrikLundell 6a0cc1e154 made more vehicle stuff map aware (#79544)
* made more vehicle stuff map aware

* demanded change

* demanded change
2025-02-06 00:57:40 -06:00
PatrikLundell 537d9d12a1 Standardized get/set pos operations for talker/creature class hierarchy (#79206)
* Standardized get/set pos operations for talker/creature class hierarchy

* sort out merge failure
2025-01-20 08:20:58 +01:00
PatrikLundell c380147ab2 typified creature.h and monster.h (#78565)
* typified creature.h and monster.h

* Update src/monmove.cpp

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

* Update src/monster.h

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

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2024-12-16 22:16:00 -06:00
PatrikLundell c4c4fea51c typified half of game.h (#78357) 2024-12-06 10:52:58 -08:00
Clarence "Sparr" Risher 8b27b967ae Replace point constants with static class members 2024-11-26 10:14:26 -05:00
PatrikLundell afb794bbc5 typified a bit of vehicle.h and dependents 2024-11-03 15:08:15 +01:00
PatrikLundell 456a199f5c typified a bit of map.cpp and dependents 2024-10-08 16:23:15 +02:00
PatrikLundell c5c01140ba typified a bit of map.h/cpp + dependents (#76712)
* typified a bit of map.h/cpp + dependents

* demanded changes

* demanded master changes drawn to its conclusion

* second int should be in corresponding location
2024-10-02 23:34:12 -05:00
Anton Simakov b3a89d8e0c Update tests/vision_test.cpp 2024-09-09 10:49:19 +02:00
GuardianDll 0122f76440 update to master 2024-09-08 18:20:24 +02:00
Brambor 2e783998d2 iwyu: snowball changes 2024-04-15 23:32:46 +02:00
Qrox 46202a92a6 Remove FOV_3D option and default to 3d FOV 2024-01-28 11:06:56 +08:00
andrei 9ec7b9512c map: fix tripoints in pl_sees 2023-12-03 19:24:23 +02:00
Rewryte 0ef2fe12ca Fix visibility not updating properly when moving, peeking and autodriving (#68138)
* add visibility update

* vis update when peeking

* fix autodrive visibility

* revert visibility optimization

* only cache tile visibility on access

* use apparent_light_at to handle visibility cache

* Revert "use apparent_light_at to handle visibility cache"

This reverts commit 37f66fda9e.

* Revert "only cache tile visibility on access"

This reverts commit b52cd59827.

* pos and time visibility invalidation

Co-Authored-By: andrei <68240139+andrei8l@users.noreply.github.com>

* fix peek and look around

* fix tests

---------

Co-authored-by: andrei <68240139+andrei8l@users.noreply.github.com>
2023-09-25 22:23:37 -04: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
irwiss d4061142ea Make vehicle::remove_part use references 2023-07-12 00:38:36 +03: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
Anton Simakov af4a7b3d35 Fog and mist weather (#64954)
* initial commit

* no message

* improve calculations, currently uses test values

* oops

* no message

* no message

* fixing the wrong values, remove debug message

* tests: override weather in tests that need clear vision

* Andrei's fix of vision test

* vision_junction_reciprocity fix

* weather realism test fix

---------

Co-authored-by: andrei <a12l+git@runbox.com>
2023-04-21 16:24:02 -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
Kevin Granade cb4c78b19f Merge pull request #63149 from andrei8l/fake-inactive-camera-is-still-a-camera
map: don't cast vision through removed cameras
2023-03-06 23:22:19 -08:00
andrei 06bb7761b9 tests/vision: invalidate all floor caches 2023-01-22 07:23:13 +02:00
andrei 68f96ed934 map: don't cast vision through removed cameras 2023-01-22 07:23:13 +02:00
Zhilkin Serg e44f38af40 Remove excessive empty lines 2022-12-06 10:42:15 +03:00
Ryan Aldrich 9c9af038aa Fix astyle 2022-10-22 19:06:55 -07:00