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

Optimize inbounds #27825

Merged
merged 3 commits into from
Jan 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -344,11 +344,12 @@ inline bool generic_inbounds( const tripoint &p,
const box &boundaries,
const box &clearance = box_zero )
{
return p.x >= ( boundaries.p_min + clearance.p_min ).x &&
p.x <= ( boundaries.p_max - clearance.p_max ).x &&
p.y >= ( boundaries.p_min + clearance.p_min ).y &&
p.y <= ( boundaries.p_max - clearance.p_max ).y &&
p.z >= ( boundaries.p_min + clearance.p_min ).z && p.z <= ( boundaries.p_max - clearance.p_max ).z;
return p.x >= boundaries.p_min.x + clearance.p_min.x &&
p.x <= boundaries.p_max.x - clearance.p_max.x &&
p.y >= boundaries.p_min.y + clearance.p_min.y &&
p.y <= boundaries.p_max.y - clearance.p_max.y &&
p.z >= boundaries.p_min.z + clearance.p_min.z &&
p.z <= boundaries.p_max.z - clearance.p_max.z;
}

/** Checks if given point is inbounds of given min and max point using given clearance **/
Expand Down
25 changes: 19 additions & 6 deletions src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7227,13 +7227,26 @@ const std::vector<tripoint> &map::trap_locations( const trap_id type ) const

bool map::inbounds( const tripoint &p ) const
{
const tripoint map_boundary_min( 0, 0, -OVERMAP_DEPTH );
const tripoint map_boundary_max( SEEY * my_MAPSIZE, SEEX * my_MAPSIZE, OVERMAP_HEIGHT );
const tripoint map_clearance_min( tripoint_zero );
const tripoint map_clearance_max( 1, 1, 0 );
constexpr tripoint map_boundary_min( 0, 0, -OVERMAP_DEPTH );
constexpr tripoint map_boundary_max( MAPSIZE_Y, MAPSIZE_X, OVERMAP_HEIGHT );
constexpr tripoint map_clearance_min( tripoint_zero );
constexpr tripoint map_clearance_max( 1, 1, 0 );

const box map_boundaries( map_boundary_min, map_boundary_max );
const box map_clearance( map_clearance_min, map_clearance_max );
constexpr box map_boundaries( map_boundary_min, map_boundary_max );
constexpr box map_clearance( map_clearance_min, map_clearance_max );

return generic_inbounds( p, map_boundaries, map_clearance );
}

bool tinymap::inbounds( const tripoint &p ) const
{
constexpr tripoint map_boundary_min( tripoint_zero );
constexpr tripoint map_boundary_max( SEEY * 2, SEEX * 2, 0 );
constexpr tripoint map_clearance_min( tripoint_zero );
constexpr tripoint map_clearance_max( 1, 1, 0 );

constexpr box map_boundaries( map_boundary_min, map_boundary_max );
constexpr box map_clearance( map_clearance_min, map_clearance_max );

return generic_inbounds( p, map_boundaries, map_clearance );
}
Expand Down
1 change: 1 addition & 0 deletions src/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -1617,6 +1617,7 @@ class tinymap : public map
friend class editmap;
public:
tinymap( int mapsize = 2, bool zlevels = false );
bool inbounds( const tripoint &p ) const;
};

#endif
1 change: 1 addition & 0 deletions src/veh_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ static const std::unordered_map<std::string, vpart_bitflags> vpart_bitflag_map =
{ "ENABLED_DRAINS_EPOWER", VPFLAG_ENABLED_DRAINS_EPOWER },
{ "WASHING_MACHINE", VPFLAG_WASHING_MACHINE },
{ "FLUIDTANK", VPFLAG_FLUIDTANK },
{ "REACTOR", VPFLAG_REACTOR },
};

static const std::vector<std::pair<std::string, int>> standard_terrain_mod = {{
Expand Down
1 change: 1 addition & 0 deletions src/veh_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ enum vpart_bitflags : int {
VPFLAG_ENABLED_DRAINS_EPOWER,
VPFLAG_WASHING_MACHINE,
VPFLAG_FLUIDTANK,
VPFLAG_REACTOR,

NUM_VPFLAGS
};
Expand Down
4 changes: 2 additions & 2 deletions src/vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ void vehicle::init_state( int init_veh_fuel, int init_veh_status )
const size_t p = vp.part_index();
vehicle_part &pt = vp.part();

if( vp.has_feature( "REACTOR" ) ) {
if( vp.has_feature( VPFLAG_REACTOR ) ) {
// De-hardcoded reactors. Should always start active
pt.enabled = true;
}
Expand Down Expand Up @@ -4368,7 +4368,7 @@ void vehicle::refresh()
if( vpi.has_flag( VPFLAG_ENGINE ) ) {
engines.push_back( p );
}
if( vpi.has_flag( "REACTOR" ) ) {
if( vpi.has_flag( VPFLAG_REACTOR ) ) {
reactors.push_back( p );
}
if( vpi.has_flag( VPFLAG_SOLAR_PANEL ) ) {
Expand Down
2 changes: 1 addition & 1 deletion src/vehicle_part.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ bool vehicle_part::is_battery() const

bool vehicle_part::is_reactor() const
{
return info().has_flag( "REACTOR" );
return info().has_flag( VPFLAG_REACTOR );
}

bool vehicle_part::is_turret() const
Expand Down