- 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
Serialize and deserialize units::temperature values as degrees celsius
offset from 0 degrees celsius. This means that temperature values are
saved with milli degrees celsius precision, which should not be plenty.
Add a round trip test to load/save/load units::temperature values and
ensure the in-memory values are not affected, and all the formats are
supported.
The legacy format "\"%f\"" needs to be supported because it exists in
save files as part of bodypart temperature calculations.
Maps often require custom serialization code, as they only understand a
limited set of types as their keys.
Expand the set of allowed types to include tripoints by adding a
key_from_json_string specialization for types with a to_string_writeable
function, that writes the value as a string suitable for
serialization/deserialization.
Also add a JsonOut::write_as_string specialization for types with this
to_string writeable, as these are required for
deserialization/serialization respectively.
Add a limited set of test cases for this. There could be more, but the
rest should be covered by more specific test cases.
Also add a <typed_tripoint>::from_string, as is necessary for the
key_from_json_string specialization to easily encompass more than
untyped points.
* Improve error reporting
-JSON syntax errors say they are syntax errors, to help people understand how to resolve them.
-The line and character offset of JSON errors has been made explicit, instead of requiring you to guess what the numbers mean.
-The C++ source file names/etc were made more explicit as well, which should hopefully reduce people asking "I can't find this .cpp file on my game, where is it"
* Update tests to new error messages
* Colorize JSON errors
* Make formatter feed source filename to TextJsonIn
* Throw exception instead of dumping output to std::cerr
* Adjust math parser's caret appearance
* Set color in chkjson
* Adjust tests and formatters
* Add json error cursor check for unicode string
* Squelch global state lint for entry points
* Adjust stream offset so the buffer for utf8_width is pointing at a codepoint
* 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)
It turns out that a lot of loading code depends on
the availability of certain damage types.
I see two ways to resolve this:
1) Juggle the loading order of JSON types so that damage
types always load first.
2) Add deferred processing for every type with inline
damage type definitions.
I went with option 2, which is better but still
not great since new code that loads damage/resistance
definitions would need to also call finalize_damage_map
in the finalizing stage. Option 1 would cause problems
for mods, especially because the load order would matter.
None of this can be done piecemeal, it has to all be ripped
out in one go unless we want commits that don't compile
on their own.
These are mostly automated changes. My automation tries to be
conservative, but I did have to do manual fixup of a few things.
I plan to PR the clang-tidy check that automates these changes later,
but I think more changes may be needed before that.
Some of the manual changes:
- Added svto<T> where T is an integer type, which parses integers in
string_views. This is our first use of the low-level C++17 int
conversion functions.
- Added a shortcut to lcmatch for empty queries, to allow for
refactoring overmapbuffer searches.
- Fixed an apparent bug in overmapbuffer::get_notes and get_extras,
where it was inverting the match result. As far as I can tell, these
functions aren't actually used anywhere, so I guess this bug wasn't
breaking anything.
- Allow use of string_view in JSON serialization. Previously these were
misidentified as sequences and appeared as a list of integers rather
than a string.
The various JSON error functions tended to have a signature where the
error message string was followed by an optional string member name
and/or an optional integer offset.
This made it really easy to accidentally think that the functions
supported string formatting, if you added an extra string and/or int,
and it compiled. But this was not so.
I made this mistake in #58527 and I've made it before. As part of this
overhaul I found several places where this mistake persisted in the
codebase.
We can prevent this confusion by re-ordering the arguments to these
functions so that the error message is always last.
Do that, and fix the mistakes discovered along the way.
Remove one overload that was never used (using member name and offset).
Our string_id constants were a mixture of temporaries, locals, and
globals. Pull them all out as globals, for consistency and efficiency.
The efficiency comes from the fact that each string_id instance caches
its respective int_id, and sharing one instance means that value need
not be recomputed.
Two issues with serialization:
- If the entire stream was just a single integer then it would cause an
infinite loop when reading.
- When reading a sequence of optionals, if one optional was empty, it
would cause the sequence to grow until memory was exhausted without
ever consuming that input.
Fix both these issues, and add unit 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.
* 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++
* 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>