Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DDA Port] Type safe coords and more point-related refactors #941

Merged
merged 10 commits into from
Oct 3, 2021

Conversation

olanti-p
Copy link
Contributor

jbytheway and others added 10 commits September 29, 2021 00:11
(cherry picked from commit 4db4b25129740866577e7ee0d0ed2b370d142686)
The current simple_pathfinding implementation only works for point.  We
want it to word for the various type-safe point types also.  Make the
point type a template parameter to that end.

Because point and coord_point require their members to be accessed in
different ways (p. vs p.x()) this entails introducing a point_traits
helper to dispatch to the correct access type.

Also added a simple pathfinding test.

(cherry picked from commit f97a8476a88f965f024e8f0c4b335595a519776f)
Previously point serialization used free functions and tripoint
serialization used member functions.

For coord_point serialization to work the way we probably want, points
and tripoints need to be serialized the same way.  So, switch points to
member functions.

Because point and label are implicitly convertible to one another, they
also need to use the same serialization technique to avoid ambiguity.
So, also transition label to use member functions for serialization.

(cherry picked from commit 89a8084bcb423eb59eb5501e8c200a126ff05192)
Previously we had separate functions closest_points_first and
closest_tripoints_first.  We'd like to extend this functionality to
coord_point, but it's easier to do if both the raw underlying functions
have the same name (so the generic wrapper can be the same).

To that end, rename closest_tripoints_first to closest_points_first
(they are chosen between based on overload resolution), and add a
wrapper to allow coord_point to be used similarly.

(cherry picked from commit 4f597dc72a631f31835163f383d83b500d06f8b5)
Make the point type of tripoint_range be a template parameter, so that
it can work for coord_point types as well as simple tripoint.

Provide that template parameter wherever needed, and add a test.

(cherry picked from commit 84afc8ef7852f82628af5192ed71aaf5502ca52b)
We don't want to force people to always construct a coord_point from a
point.  Suppress the check in these cases.

(cherry picked from commit b3a7b7863532306c5a885d37240d3e9a3ec157ca)
It was never clear how project_remain should work for tripoints.  Should
the z coordinate be included in the quotient, the remainder, or both?

This implementation allows the client code to choose which of the two
will contain it (you must pick exactly one).

Add project_combine, which is the opposite operation, and a test that
one operation reverses the other.

(cherry picked from commit c1719b1ab3e40170b1258678782ecfa57cb8900b)
Things we want to be able to call on these new point types:
* square_dist
* trig_dist
* rl_dist
* manhattan_dist
* direction_from
* line_to
* midpoint

And tests for all the above.

(cherry picked from commit b66068ac0cfaee189527e9b3ea372ab9fbd8c8cd)
To help people understand the game's coordinate systems and how to use
the new point types, add some documentation

Move the description of coordinate systems out of
coordinate_conversions.h into a markdown file, and reference that new
file from coordinate_conversions.h and coordinates.h.

(cherry picked from commit c1cabb8fa26c5cf4c1e1a65422ab85be3d9cafc7)
@olanti-p olanti-p marked this pull request as ready for review September 28, 2021 21:13
@Coolthulhu Coolthulhu self-assigned this Sep 30, 2021
@Coolthulhu Coolthulhu merged commit 42e3ac4 into cataclysmbnteam:upload Oct 3, 2021
@olanti-p olanti-p deleted the typesafe-coords branch October 4, 2021 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants