Skip to content

Commit

Permalink
Cache the absolute position of the top-left map square
Browse files Browse the repository at this point in the history
In the case of a character waiting in the refugee centre, calls are in
the order of 10,000,000 each in-game hour.
  • Loading branch information
CLIDragon committed Nov 8, 2024
1 parent 60cf27e commit fee4f96
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10045,17 +10045,18 @@ 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 abs_ms + p.raw();
}

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 = tripoint_abs_ms{ project_to<coords::ms>(abs_sub.xy()), abs_sub.z()};
}

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 tripoint_abs_ms { project_to<coords::ms>( abs_sub.xy() ), abs_sub.z() }
tripoint_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 fee4f96

Please sign in to comment.