Permalink
Browse files

Move map memory capacity cache to player object

This avoids a rare collision where loading a new player at the same turn as
the previous player would apply the wrong map memory capacity value.
  • Loading branch information...
kevingranade committed Jan 5, 2019
1 parent 980b56d commit 51c23abaa134e7fdc64ab20a283430ad0c2b1418
Showing with 10 additions and 9 deletions.
  1. +7 −9 src/player.cpp
  2. +3 −0 src/player.h
@@ -11574,21 +11574,19 @@ long player::get_memorized_symbol( const tripoint &p ) const
size_t player::max_memorized_tiles() const
{
// Only check traits once a turn since this is called a huge number of times.
static time_point current_turn = calendar::before_time_starts;
static size_t current_max = 0;
if( current_turn != calendar::turn ) {
current_turn = calendar::turn;
if( current_map_memory_turn != calendar::turn ) {
current_map_memory_turn = calendar::turn;
if( has_active_bionic( bio_memory ) ) {
current_max = SEEX * SEEY * 20000; // 5000 overmap tiles
current_map_memory_capacity = SEEX * SEEY * 20000; // 5000 overmap tiles
} else if( has_trait( trait_FORGETFUL ) ) {
current_max = SEEX * SEEY * 200; // 50 overmap tiles
current_map_memory_capacity = SEEX * SEEY * 200; // 50 overmap tiles
} else if( has_trait( trait_GOODMEMORY ) ) {
current_max = SEEX * SEEY * 800; // 200 overmap tiles
current_map_memory_capacity = SEEX * SEEY * 800; // 200 overmap tiles
} else {
current_max = SEEX * SEEY * 400; // 100 overmap tiles
current_map_memory_capacity = SEEX * SEEY * 400; // 100 overmap tiles
}
}
return current_max;
return current_map_memory_capacity;
}

bool player::sees( const tripoint &t, bool ) const
@@ -1123,6 +1123,9 @@ class player : public Character
private:
/** last time we checked for sleep */
time_point last_sleep_check = calendar::time_of_cataclysm;
/** Used in max_memorized_tiles to cache memory capacity. **/
mutable time_point current_map_memory_turn = calendar::before_time_starts;
mutable size_t current_map_memory_capacity = 0;

public:
/** Returns a value from 1.0 to 5.0 that acts as a multiplier

0 comments on commit 51c23ab

Please sign in to comment.