Skip to content

Commit

Permalink
Merge pull request #77668 from CLIDragon/map-get-abs-perf
Browse files Browse the repository at this point in the history
[Perf] Cache the absolute map square position of the first submap
  • Loading branch information
akrieger authored Nov 9, 2024
2 parents 9764ff0 + ba8a73c commit b8793ea
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10036,18 +10036,19 @@ tripoint_abs_ms map::getglobal( const tripoint &p ) const

tripoint_abs_ms map::getglobal( const tripoint_bub_ms &p ) const
{
return project_to<coords::ms>( abs_sub.xy() ) + p.raw();
return tripoint_abs_ms{ p.x() + abs_ms.x(), p.y() + abs_ms.y(), p.z() };
}

tripoint_bub_ms map::bub_from_abs( const tripoint_abs_ms &p ) const
{
return tripoint_bub_ms() + ( p - project_to<coords::ms>( abs_sub.xy() ) );
return tripoint_bub_ms { p.x() - abs_ms.x(), p.y() - abs_ms.y(), p.z()};
}

void map::set_abs_sub( const tripoint_abs_sm &p )
{
abs_sub = p;
}
abs_ms = point_abs_ms{ project_to<coords::ms>( abs_sub.xy() ) };
};

tripoint_abs_sm map::get_abs_sub() const
{
Expand Down
2 changes: 2 additions & 0 deletions src/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -2251,6 +2251,8 @@ class map
* - shifting the map with @ref shift
*/
tripoint_abs_sm abs_sub;
// Cached value of project_to<coords::ms>( abs_sub.xy() )
point_abs_ms abs_ms;
/**
* Sets @ref abs_sub, see there. Uses the same coordinate system as @ref abs_sub.
*/
Expand Down

0 comments on commit b8793ea

Please sign in to comment.