Skip to content

Commit 94d6d9f

Browse files
committed
clear out map memory when switching dimensions
1 parent ddde436 commit 94d6d9f

File tree

5 files changed

+24
-5
lines changed

5 files changed

+24
-5
lines changed

src/avatar.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,11 @@ void avatar::load_map_memory()
250250
player_map_memory->load( pos_abs() );
251251
}
252252

253+
void avatar::clear_map_memory()
254+
{
255+
player_map_memory->clear();
256+
}
257+
253258
void avatar::prepare_map_memory_region( const tripoint_abs_ms &p1, const tripoint_abs_ms &p2 )
254259
{
255260
player_map_memory->prepare_region( p1, p2 );

src/avatar.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ class avatar : public Character
9999
void deserialize( const JsonObject &data ) override;
100100
bool save_map_memory();
101101
void load_map_memory();
102+
void clear_map_memory();
102103

103104
// newcharacter.cpp
104105
bool create( character_type type, const std::string &tempname = "" );

src/game.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "game.h"
2+
#include "map_memory.h"
23

34
#include <algorithm>
45
#include <bitset>
@@ -12751,6 +12752,7 @@ bool game::travel_to_dimension( const std::string &new_prefix )
1275112752
if( !save_maps() ) {
1275212753
return false;
1275312754
}
12755+
player.save_map_memory();
1275412756
for( int z = -OVERMAP_DEPTH; z <= OVERMAP_HEIGHT; z++ ) {
1275512757
here.clear_vehicle_list( z );
1275612758
}
@@ -12764,10 +12766,10 @@ bool game::travel_to_dimension( const std::string &new_prefix )
1276412766
}
1276512767
// Load in data specific to the dimension (like weather)
1276612768
//if( !load_dimension_data() ) {
12767-
// dimension data file not found/created yet
12768-
/* handle weather instance switching when I have dimensions with different region settings,
12769-
right now they're all the same and it's hard to tell if it's working or not. */
12770-
// weather.set_nextweather( calendar::turn );
12769+
// dimension data file not found/created yet
12770+
/* handle weather instance switching when I have dimensions with different region settings,
12771+
right now they're all the same and it's hard to tell if it's working or not. */
12772+
// weather.set_nextweather( calendar::turn );
1277112773
//}
1277212774
// Ensure the new world has compression files
1277312775
world_generator->active_world->assure_compression_files_present();
@@ -12780,6 +12782,10 @@ bool game::travel_to_dimension( const std::string &new_prefix )
1278012782
overmap_buffer.clear();
1278112783
// load/create new overmap
1278212784
overmap_buffer.get( point_abs_om{} );
12785+
// clear map memory from the previous dimension
12786+
player.clear_map_memory();
12787+
// Load map memory in new dimension, if there is any
12788+
player.load_map_memory();
1278312789
// Loads submaps and invalidate related caches
1278412790
here.load( tripoint_abs_sm( here.get_abs_sub() ), false );
1278512791

src/map_memory.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,12 @@ bool map_memory::save( const tripoint_abs_ms &pos )
554554

555555
return result;
556556
}
557-
557+
void map_memory::clear()
558+
{
559+
clear_cache();
560+
submaps.clear();
561+
dbg( D_INFO ) << "[CLEAR] Done.";
562+
}
558563
void map_memory::clear_cache()
559564
{
560565
cached.clear();

src/map_memory.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ class map_memory
124124
/** Save memorized submaps to disk, drop ones far from given global map square pos. */
125125
bool save( const tripoint_abs_ms &pos );
126126

127+
/** Clear out loaded map memory */
128+
void clear();
127129
/**
128130
* Prepares map memory for rendering and/or memorization of given region.
129131
* @param p1 top-left corner of the region, in global ms coords

0 commit comments

Comments
 (0)