Skip to content

Commit

Permalink
Make coord_point into coord_point_ob and parent class of coord_point_ib
Browse files Browse the repository at this point in the history
  • Loading branch information
akrieger committed Aug 1, 2024
1 parent 0b942b3 commit 57ca0ab
Show file tree
Hide file tree
Showing 8 changed files with 412 additions and 246 deletions.
13 changes: 13 additions & 0 deletions src/cata_inline.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once
#ifndef CATA_SRC_CATA_INLINE_H
#define CATA_SRC_CATA_INLINE_H

#ifndef CATA_FORCEINLINE
#ifdef _MSC_VER
#define CATA_FORCEINLINE __forceinline
#else
#define CATA_FORCEINLINE inline __attribute__((always_inline))
#endif
#endif

#endif

Check failure on line 13 in src/cata_inline.h

View workflow job for this annotation

GitHub Actions / build (src)

#endif for a header guard should reference the guard macro in a comment. [cata-header-guard,-warnings-as-errors]

Check failure on line 13 in src/cata_inline.h

View workflow job for this annotation

GitHub Actions / build (src)

#endif for a header guard should reference the guard macro in a comment. [cata-header-guard,-warnings-as-errors]

Check failure on line 13 in src/cata_inline.h

View workflow job for this annotation

GitHub Actions / build (other)

#endif for a header guard should reference the guard macro in a comment. [cata-header-guard,-warnings-as-errors]

Check failure on line 13 in src/cata_inline.h

View workflow job for this annotation

GitHub Actions / build (other)

#endif for a header guard should reference the guard macro in a comment. [cata-header-guard,-warnings-as-errors]
587 changes: 364 additions & 223 deletions src/coordinates.h

Large diffs are not rendered by default.

13 changes: 11 additions & 2 deletions src/coords_fwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#ifndef CATA_SRC_COORDS_FWD_H
#define CATA_SRC_COORDS_FWD_H

#include <type_traits>

struct point;
struct tripoint;

Expand Down Expand Up @@ -32,8 +34,15 @@ constexpr scale omt = scale::overmap_terrain;
constexpr scale seg = scale::segment;
constexpr scale om = scale::overmap;

template<typename Point, origin Origin, scale Scale>
class coord_point_ob;

template<typename Point, origin Origin, scale Scale>
class coord_point_ib;

template<typename Point, origin Origin, scale Scale, bool InBounds = false>
class coord_point;
using coord_point =
std::conditional_t<InBounds, coord_point_ib<Point, Origin, Scale>, coord_point_ob<Point, Origin, Scale>>;

} // namespace coords

Expand Down Expand Up @@ -76,7 +85,7 @@ using point_abs_om = coords::coord_point<point, coords::origin::abs, coords::om>
using tripoint_rel_ms = coords::coord_point<tripoint, coords::origin::relative, coords::ms>;
using tripoint_abs_ms = coords::coord_point<tripoint, coords::origin::abs, coords::ms>;
using tripoint_sm_ms = coords::coord_point<tripoint, coords::origin::submap, coords::ms>;
using tripoint_sm_ms_ib = coords::coord_point<tripoint, coords::origin::submap, coords::ms, true>;
using tripoint_sm_ms_ib = coords::coord_point_ib<tripoint, coords::origin::submap, coords::ms>;
using tripoint_omt_ms = coords::coord_point<tripoint, coords::origin::overmap_terrain, coords::ms>;
using tripoint_bub_ms = coords::coord_point<tripoint, coords::origin::reality_bubble, coords::ms>;
using tripoint_bub_ms_ib =
Expand Down
4 changes: 2 additions & 2 deletions src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1805,7 +1805,7 @@ furn_id map::furn( const tripoint &p ) const
return furn( tripoint_bub_ms( p ) );
}

furn_id map::furn( const tripoint_bub_ms &p ) const
furn_id map::furn( const tripoint_bub_ms p ) const
{
if( !inbounds( p ) ) {
return furn_str_id::NULL_ID();
Expand Down Expand Up @@ -2000,7 +2000,7 @@ std::string map::furnname( const tripoint_bub_ms &p )
* retained for high performance comparisons, save/load, and gradual transition
* to string terrain.id
*/
ter_id map::ter( const tripoint &p ) const
ter_id map::ter( const tripoint p ) const
{
if( !inbounds( p ) ) {
return ter_str_id::NULL_ID().id();
Expand Down
16 changes: 6 additions & 10 deletions src/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,7 @@ class map
}
// TODO: fix point types (remove the first overload)
furn_id furn( const tripoint &p ) const;
furn_id furn( const tripoint_bub_ms &p ) const;
furn_id furn( const tripoint_bub_ms p ) const;

Check failure on line 968 in src/map.h

View workflow job for this annotation

GitHub Actions / build (other)

parameter 'p' is const-qualified in the function declaration; const-qualification of parameters only has an effect in function definitions [readability-avoid-const-params-in-decls,-warnings-as-errors]
// TODO: Get rid of untyped overload.
furn_id furn( const point_bub_ms &p ) const {
return furn( tripoint_bub_ms( p, abs_sub.z() ) );
Expand Down Expand Up @@ -1010,7 +1010,7 @@ class map

// Terrain
// TODO: fix point types (remove the first overload)
ter_id ter( const tripoint &p ) const;
ter_id ter( const tripoint p ) const;

Check failure on line 1013 in src/map.h

View workflow job for this annotation

GitHub Actions / build (other)

parameter 'p' is const-qualified in the function declaration; const-qualification of parameters only has an effect in function definitions [readability-avoid-const-params-in-decls,-warnings-as-errors]
ter_id ter( const tripoint_bub_ms &p ) const;
// TODO: Get rid of untyped overload.
ter_id ter( const point &p ) const {
Expand Down Expand Up @@ -2399,11 +2399,9 @@ class map
offset_p.y = p.y % SEEY;
return unsafe_get_submap_at( p );
}
submap *unsafe_get_submap_at( const tripoint_bub_ms &p, point_sm_ms &offset_p ) {
submap *unsafe_get_submap_at( const tripoint_bub_ms p, point_sm_ms &offset_p ) {
tripoint_bub_sm sm;
point_sm_ms_ib l;
std::tie( sm, l ) = project_remain<coords::sm>( p );
offset_p = point_sm_ms( l );
std::tie( sm, offset_p ) = project_remain<coords::sm>( p );
return unsafe_get_submap_at( p );
}
// TODO: fix point types (remove the first overload)
Expand All @@ -2413,11 +2411,9 @@ class map
return unsafe_get_submap_at( p );
}
const submap *unsafe_get_submap_at(
const tripoint_bub_ms &p, point_sm_ms &offset_p ) const {
const tripoint_bub_ms p, point_sm_ms &offset_p ) const {
tripoint_bub_sm sm;
point_sm_ms_ib l;
std::tie( sm, l ) = project_remain<coords::sm>( p );
offset_p = point_sm_ms( l );
std::tie( sm, offset_p ) = project_remain<coords::sm>( p );
return unsafe_get_submap_at( p );
}
// TODO: Get rid of untyped overload
Expand Down
8 changes: 4 additions & 4 deletions src/mdarray.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ namespace cata
template<typename Point>
struct mdarray_default_size_impl;

template<typename Point, coords::scale Scale, bool InBounds>
struct mdarray_default_size_impl<coords::coord_point<Point, coords::origin::reality_bubble, Scale, InBounds>> {
template<template<class, coords::origin, coords::scale> class coord_point, typename Point, coords::scale Scale>
struct mdarray_default_size_impl<coord_point<Point, coords::origin::reality_bubble, Scale>> {
static constexpr size_t value = MAPSIZE_X / map_squares_per( Scale );
static_assert( MAPSIZE_X % map_squares_per( Scale ) == 0, "Scale must be smaller than map" );
};

template<typename Point, coords::origin Origin, coords::scale Scale, bool InBounds>
struct mdarray_default_size_impl<coords::coord_point<Point, Origin, Scale, InBounds>> {
template<template<class, coords::origin, coords::scale> class coord_point, typename Point, coords::origin Origin, coords::scale Scale>
struct mdarray_default_size_impl<coord_point<Point, Origin, Scale>> {
static constexpr coords::scale outer_scale = coords::scale_from_origin( Origin );
static constexpr size_t value = map_squares_per( outer_scale ) / map_squares_per( Scale );
static_assert( value > 0, "Scale must be smaller origin" );
Expand Down
2 changes: 1 addition & 1 deletion src/omdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ std::string name( type dir );
point rotate( const point &p, type dir );
tripoint rotate( const tripoint &p, type dir );
template<typename Point, coords::scale Scale>
auto rotate( const coords::coord_point<Point, coords::origin::relative, Scale> &p, type dir )
auto rotate( const coords::coord_point_ob<Point, coords::origin::relative, Scale> &p, type dir )
-> coords::coord_point<Point, coords::origin::relative, Scale>
{
return coords::coord_point<Point, coords::origin::relative, Scale> { rotate( p.raw(), dir ) };
Expand Down
15 changes: 11 additions & 4 deletions tests/coordinate_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,18 @@ static_assert( tripoint_abs_omt::dimension == 3 );

// Out of bounds coords can be implicitly constructed from inbounds ones. This is used
// to ensure a return type is NOT an inbounds one, before it can be converted.
template <typename Point, coords::origin Origin, coords::scale Scale, bool InBounds>
coords::coord_point<Point, Origin, Scale, InBounds> assert_not_ib( const
coords::coord_point<Point, Origin, Scale, InBounds> &p )
template <typename Point, coords::origin Origin, coords::scale Scale>
coords::coord_point<Point, Origin, Scale, true> assert_not_ib( const
coords::coord_point_ib<Point, Origin, Scale> &p )
{
static_assert( false, "Coordinate is not permitted to be inbounds" );
return p;
}

template <typename Point, coords::origin Origin, coords::scale Scale>
coords::coord_point<Point, Origin, Scale, false> assert_not_ib( const
coords::coord_point_ob<Point, Origin, Scale> &p )
{
static_assert( !InBounds );
return p;
}

Expand Down

0 comments on commit 57ca0ab

Please sign in to comment.