@@ -48,22 +48,41 @@ namespace worldmap {
48
48
49
49
WorldMap::WorldMap (const std::string& filename, Savegame& savegame,
50
50
const std::string& force_sector, const std::string& force_spawnpoint) :
51
- m_sector (),
51
+ m_sector (nullptr ),
52
52
m_sectors (),
53
- m_force_spawnpoint (force_spawnpoint ),
54
- m_savegame (savegame ),
55
- m_tileset (),
53
+ m_force_spawnpoint (),
54
+ m_savegame (nullptr ),
55
+ m_tileset (nullptr ),
56
56
m_name (),
57
- m_map_filename (physfsutil::realpath(filename) ),
58
- m_levels_path (FileSystem::dirname(m_map_filename) ),
59
- m_next_worldmap ( ),
57
+ m_map_filename (),
58
+ m_levels_path (),
59
+ m_has_next_worldmap ( false ),
60
60
m_passive_message (),
61
61
m_passive_message_timer (),
62
62
m_allow_item_pocket (true ),
63
63
m_enter_level (false ),
64
64
m_in_level (false ),
65
- m_in_world_select (false )
65
+ m_in_world_select (false ),
66
+ m_next_filename (),
67
+ m_next_force_sector (),
68
+ m_next_force_spawnpoint ()
66
69
{
70
+ load (filename, savegame, force_sector, force_spawnpoint);
71
+ }
72
+
73
+ void
74
+ WorldMap::load (const std::string& filename, Savegame& savegame,
75
+ const std::string& force_sector, const std::string& force_spawnpoint)
76
+ {
77
+ m_map_filename = physfsutil::realpath (filename);
78
+ m_levels_path = FileSystem::dirname (m_map_filename);
79
+ /* We are reloading, so save now. */
80
+ if (m_has_next_worldmap)
81
+ m_savegame->get_player_status ().last_worldmap = m_map_filename;
82
+ m_savegame = &savegame;
83
+ m_force_spawnpoint = force_spawnpoint;
84
+ m_sector = nullptr ;
85
+ m_sectors.clear ();
67
86
SoundManager::current ()->preload (" sounds/warp.wav" );
68
87
69
88
/* * Parse worldmap */
@@ -95,10 +114,13 @@ WorldMap::WorldMap(const std::string& filename, Savegame& savegame,
95
114
96
115
/* * Force the initial sector, if provided */
97
116
if (!force_sector.empty ())
117
+ {
98
118
set_sector (force_sector, " " , false );
119
+ }
120
+ if (m_has_next_worldmap)
121
+ setup ();
99
122
}
100
123
101
-
102
124
void
103
125
WorldMap::setup ()
104
126
{
@@ -142,11 +164,10 @@ WorldMap::update(float dt_sec, const Controller& controller)
142
164
if (m_in_level) return ;
143
165
if (MenuManager::instance ().is_active ()) return ;
144
166
145
- if (m_next_worldmap ) // A worldmap is scheduled to be changed to.
167
+ if (m_has_next_worldmap ) // A worldmap is scheduled to be changed to.
146
168
{
147
- m_savegame.get_player_status ().last_worldmap = m_next_worldmap->m_map_filename ;
148
- ScreenManager::current ()->pop_screen ();
149
- ScreenManager::current ()->push_screen (std::move (m_next_worldmap));
169
+ load (m_next_filename, *m_savegame, m_next_force_sector, m_next_force_spawnpoint);
170
+ m_has_next_worldmap = false ;
150
171
return ;
151
172
}
152
173
@@ -258,7 +279,10 @@ WorldMap::change(const std::string& filename, const std::string& force_sector,
258
279
const std::string& force_spawnpoint)
259
280
{
260
281
// Schedule worldmap to be changed to next frame.
261
- m_next_worldmap = std::make_unique<WorldMap>(filename, m_savegame, force_sector, force_spawnpoint);
282
+ m_next_filename = filename;
283
+ m_next_force_sector = force_sector;
284
+ m_next_force_spawnpoint = force_spawnpoint;
285
+ m_has_next_worldmap = true ;
262
286
}
263
287
264
288
0 commit comments