Commit Graph

36 Commits

Author SHA1 Message Date
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 2684dcbcf1 Merge pull request #42480 from ZhilkinSerg/sa-2020-06-29
Code optimizations reported by static code analysis (2020-06-29)
2020-07-29 23:55:24 +00: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 6a96a7ffdb Get rid of autos (+ constify) 2020-07-28 22:08:34 +03:00
John Bytheway 3c67e804d7 Refactor overmap-scale code to new point types (#41693)
Put the new point types through their paces by changing the types for
overmap and overmapbuffer, and dealing with all the consequent fallout.

Involves more changes than I originally anticipated, but serves as a
good demonstration of the new point type features.

Fixed some bugs along the way that were discovered by this new point
type safety.  The ones I remember are:
* The evacuation shelter now correctly calculates the distance and
  direction to the refugee center, previously it was mostly nonsense
  (this only affects the message it prints out).
* Weather conditions for NPC-planted crops are calculated more
  reasonably.  Previously they were passing an overmap location as a
  map-square location, which could have caused all sorts of strangeness.
* Translocators were similarly confusing map_square and overmap_terrain
  scales, so they might not have been working properly.
* Two places were using map::points_in_radius which truncates to the map
  boundaries, but were using it for overmap-scale points, so it would
  only have worked correctly for some regions of the overmap.
2020-07-20 08:27:11 +00:00
John Bytheway 9fc62e133b Appease clang-3.8 2020-06-12 09:34:02 -04:00
John Bytheway 78cb7c199a Automated refactoring of remaining code 2020-06-12 08:29:42 -04:00
John Bytheway 9034951f0c Stop supporting comparing string_id wiwth literals
There was an overload for operator== between string_id and const char*,
allowing direct comparison with literals.  This goes against most of the
other properties of string_id in that you must usually be explicit about
conversions between it and strings.

Also, it hampers refactoring, because you might not notice that a
comparison has become incorrect when changing the type of a variable.

Remove that operator overload and update code using it accordingly.
2020-05-14 20:40:01 -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
Eric Pierce f85be5792f Merge branch 'master' into test-helpers 2020-04-02 19:06:16 -06:00
Eric Pierce d017afbbb5 Overmap and mapgen: testing, cleanup, and documentation (#39107)
* Add unit tests for is_ot_match

Includes sections for exact, type, prefix, and contains match types.

* Link other docs and format x,y,z examples

* Add connects_to test case and comments

As the comment above connects_to has indicated for years, this function
is hideous. I must have stared at it for 10 minutes before I understood
what it was doing. Now it remains hideous, but with marginally better
documentation and a fairly comprehensive test case.

* Reformat MAPGEN.md

This is a first pass at reformatting, including:

- Using `preformatted` strings where appropriate
- JSON syntax for code blocks
- Formatting value/description lists as tables
- Wrapping most text to 120 columns
- Simplifying to make vim Markdown syntax highligher happier

* Add table and JSON formatting

* Reformat MAPGEN.md with tables, heading levels

* Format more tables and clean things up

* Format tables, relabel heading, remove quotes

* Format and tidy up tables

* Rewrite headings and eliminate remaining numbers

* Add table of contents

* Add table of top-level JSON fields with links

* Document field intensity

* Align table columns

* Remove JSON table

All these are already referenced in the main TOC; they are redundant
(and possibly misleading) being in this section, and need a more careful
explanation.
2020-04-03 01:17:29 +03:00
Eric Pierce 721581d9ba Tag slow-running test cases
Based on running `tests/cata_test -d yes` to see durations:

22.254 s: grenade_lethality
9.236 s: starting_items
7.887 s: starve_test
5.416 s: all_nutrition_starve_test
2.904 s: starve_test_hunger3
1.496 s: unskilled_shooter_accuracy
1.490 s: an unskilled shooter with an inaccurate shotgun
1.167 s: default_overmap_generation_always_succeeds
0.953 s: default_overmap_generation_has_non_mandatory_specials_at_origin
2020-04-02 15:46:20 -06:00
ZhilkinSerg fbaae72067 Refactor closest_(tri)points_first functions (#37108)
* Refactored `closest_(tri)points_first` functions
- moved into `point` file;
- rearranged function parameters;
- removed duplicate code;
- get rid of some `auto` and one time use variables;
2020-01-17 07:57:04 +00:00
BevapDin c2ff911ad1 Remove redundant overmap::get_ter and use overmap::ter instead. 2019-09-27 18:25:10 +02: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 31261251c1 Port overmap API to points / tripoints
Convert all overmap member functions taking x, y, z arguments to take
points or tripoints instead.

Port all calling code to use these new APIs.

Add a couple of helpers to aid with this process:

- om_to_omt_copy in coordinate_conversions.h
- manhattan_dist in line.h
- tripoint_above, tripoint_below, four_adjacent_offsets in point.h
2019-07-26 13:22:02 -04:00
John Bytheway 5355c06fab Overmapbuffer function refactoring (#32300)
* Typo

* Add some point / tripoint overloads for APIs

A bunch of map / overmap functions take x, y, z coordinates.  Add
overloads to (some of) those taking a point or tripoint.

For now, those overloads just forward to the original function, but the
ultimate goal is to remove the originals and only have the new
overloads.

* Overhaul overmapbuffer APIs

Remove almost all (x, y, z) APIs and replace wityh point / tripoint
APIs.

This is a first step towards making these APIs type-safe (#32017).

A couple of APIs remain because they're more complex to change and this
commit was already very big.
2019-07-11 08:21:28 +03: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
ZhilkinSerg 285fa7ef43 Updated tests 2019-06-25 14:58:54 +03:00
John Bytheway ff714b2fb9 Use std::make_unique (#31487)
* Remove cata::make_unique

We are on C++14 now, and have std::make_unique.

* Use std::make_unique in a bunch of places

I don't believe any of these is needed for correctness, but it's
considered good practice, and in some cases it makes the code neater.

The main advantage is that it removes raw new, making it easier to find
and fix other, potentially more dangerous uses of raw new.
2019-06-16 00:41:18 +03:00
John Bytheway aff4636618 Run IWYU
Having refactored the type ids into a single header, IWYU is now able to
find many places where other headers can be removed.
2019-05-06 22:47:10 +01: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 040eb39d4c String optimizations
- used `.empty()` instead of empty string compare;
- used `.clear()` instead of empty string assignment;
- seek char rather than a string;
- removed excessive type casting (string->char->string);
- removed unused variable.
2018-10-05 22:24:58 +03:00
Jason Jones fce44d9569 Add test for mapgen optional specials at origin 2018-08-27 11:46:33 -08:00
BevapDin 540bc3f451 Change scent_trace::creation_turn to be time_point
And rename it to `creation_time`.
2018-05-26 13:46:12 +02:00
Kevin Granade dd707981e5 Astyling, the revenge. 2017-08-02 05:11:39 +00:00
Kevin Granade 267f264c14 Move overmap special enumeration from overmap class to overmap_specials namespace. 2017-07-26 05:04:47 +00:00
Kevin Granade 0ec5b9527e Limit special placement recursion by tracking origin coordinates. 2017-07-26 02:39:02 +00:00
Kevin Granade f266c3df93 Add (failing) test case for validating overmaps create with all required specials. 2017-07-26 02:39:02 +00:00
Kevin Granade fa831c7d5e Inject list of specials into overmap instead of retrieving it from configuration. 2017-07-26 02:39:02 +00:00
Kevin Granade 5bf8723069 Fixes for misc issues found by valgrind. 2017-07-22 20:29:07 +00:00
Kevin Granade a0ece50a81 Add scent trail unit test. 2016-01-27 00:09:23 -06:00