Skip to content

Commit d3c4373

Browse files
authored
Merge pull request #6074 from Goober5000/fast_fred_reload
speed up FRED reloading with this one weird trick
2 parents e6b2cbf + 0267fb5 commit d3c4373

File tree

9 files changed

+23
-16
lines changed

9 files changed

+23
-16
lines changed

code/mission/missionparse.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ extern bool check_for_23_3_data();
6060
// mission parse flags used for parse_mission() to tell what kind of information to get from the mission file
6161
#define MPF_ONLY_MISSION_INFO (1 << 0)
6262
#define MPF_IMPORT_FSM (1 << 1)
63+
#define MPF_FAST_RELOAD (1 << 2) // skip clearing some stuff so we can load the mission faster (usually since it's the same mission)
6364

6465
// bitfield definitions for missions game types
6566
#define OLD_MAX_GAME_TYPES 4 // needed for compatibility

fred2/campaigntreewnd.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ BOOL campaign_tree_wnd::OnCreateClient(LPCREATESTRUCT, CCreateContext* pContext)
7171
LoadAccelTable("IDR_ACC_CAMPAIGN");
7272
Mission_filename_cb_format = RegisterClipboardFormat("Mission Filename");
7373
Campaign_modified = 0;
74-
clear_mission();
74+
clear_mission(true);
7575

7676
// create a splitter with 1 row, 2 columns
7777
if (!m_splitter.CreateStatic(this, 1, 2))

fred2/freddoc.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ bool CFREDDoc::autoload() {
115115
}
116116

117117
// Load Backup.002
118-
r = load_mission(name);
118+
r = load_mission(name, MPF_FAST_RELOAD);
119119
Update_window = 1;
120120

121121
// Delete Backup.001
@@ -227,7 +227,7 @@ bool CFREDDoc::load_mission(const char *pathname, int flags) {
227227
// activate the localizer hash table
228228
fhash_flush();
229229

230-
clear_mission();
230+
clear_mission(flags & MPF_FAST_RELOAD);
231231

232232
// message 1: required version
233233
if (!parse_main(pathname, flags)) {
@@ -457,7 +457,7 @@ void CFREDDoc::OnFileImportFSM() {
457457
if (Briefing_dialog)
458458
Briefing_dialog->icon_select(-1);
459459

460-
clear_mission();
460+
clear_mission(true);
461461

462462
int num_files = 0;
463463
int successes = 0;
@@ -490,7 +490,7 @@ void CFREDDoc::OnFileImportFSM() {
490490
strcpy_s(fs1_path, fs1_path_mfc);
491491

492492
// load mission into memory
493-
if (!load_mission(fs1_path, MPF_IMPORT_FSM))
493+
if (!load_mission(fs1_path, MPF_IMPORT_FSM | MPF_FAST_RELOAD))
494494
continue;
495495

496496
// get filename
@@ -652,7 +652,7 @@ BOOL CFREDDoc::OnSaveDocument(LPCTSTR pathname) {
652652
}
653653

654654
SetModifiedFlag(FALSE);
655-
if (!load_mission(pathname))
655+
if (!load_mission(pathname, MPF_FAST_RELOAD))
656656
Error(LOCATION, "Failed attempting to reload mission after saving. Report this bug now!");
657657

658658
if (Briefing_dialog) {

fred2/management.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ void reset_mission()
766766
stars_post_level_init();
767767
}
768768

769-
void clear_mission()
769+
void clear_mission(bool fast_reload)
770770
{
771771
char *str;
772772
int i, j, count;
@@ -782,7 +782,10 @@ void clear_mission()
782782
mission_init(&The_mission);
783783

784784
obj_init();
785-
model_free_all(); // Free all existing models
785+
786+
if (!fast_reload)
787+
model_free_all(); // Free all existing models
788+
786789
ai_init();
787790
asteroid_level_init();
788791
ship_level_init();

fred2/management.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ int create_object(vec3d* pos, int waypoint_instance = -1);
7777
int create_player(vec3d* pos, matrix* orient, int type = -1);
7878
void create_new_mission();
7979
void reset_mission();
80-
void clear_mission();
80+
void clear_mission(bool fast_reload = false);
8181
int query_valid_object(int index = cur_object_index);
8282
int query_valid_ship(int index = cur_object_index);
8383
int query_valid_waypoint(int index = cur_object_index);

qtfred/src/mission/Editor.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ bool Editor::loadMission(const std::string& mission_name, int flags) {
140140
// activate the localizer hash table
141141
fhash_flush();
142142

143-
clearMission();
143+
clearMission(flags & MPF_FAST_RELOAD);
144144

145145
std::string filepath = mission_name;
146146
auto res = cf_find_file_location(filepath.c_str(), CF_TYPE_MISSIONS);
@@ -388,7 +388,7 @@ void Editor::unmarkObject(int obj) {
388388
}
389389
}
390390

391-
void Editor::clearMission() {
391+
void Editor::clearMission(bool fast_reload) {
392392
// clean up everything we need to before we reset back to defaults.
393393
#if 0
394394
if (Briefing_dialog){
@@ -401,7 +401,10 @@ void Editor::clearMission() {
401401
mission_init(&The_mission);
402402

403403
obj_init();
404-
model_free_all(); // Free all existing models
404+
405+
if (!fast_reload)
406+
model_free_all(); // Free all existing models
407+
405408
ai_init();
406409
asteroid_level_init();
407410
ship_level_init();

qtfred/src/mission/Editor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ class Editor : public QObject {
185185
static int getAigoal_list_size();
186186
const char* error_check_initial_orders(ai_goal* goals, int ship, int wing);
187187
private:
188-
void clearMission();
188+
void clearMission(bool fast_reload = false);
189189

190190
void initialSetup();
191191

qtfred/src/ui/FredView.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ FredView::FredView(QWidget* parent) : QMainWindow(parent), ui(new Ui::FredView()
7070
ui->actionUndo->setShortcuts(QKeySequence::Undo);
7171
ui->actionDelete->setShortcuts(QKeySequence::Delete);
7272

73-
connect(ui->actionOpen, &QAction::triggered, this, &FredView::openLoadMissionDIalog);
73+
connect(ui->actionOpen, &QAction::triggered, this, &FredView::openLoadMissionDialog);
7474
connect(ui->actionNew, &QAction::triggered, this, &FredView::newMission);
7575

7676
connect(fredApp, &FredApplication::onIdle, this, &FredView::updateUI);
@@ -152,7 +152,7 @@ void FredView::loadMissionFile(const QString& pathName) {
152152
}
153153
}
154154

155-
void FredView::openLoadMissionDIalog() {
155+
void FredView::openLoadMissionDialog() {
156156
qDebug() << "Loading from directory:" << QDir::currentPath();
157157
QString pathName = QFileDialog::getOpenFileName(this, tr("Load mission"), QString(), tr("FS2 missions (*.fs2)"));
158158

qtfred/src/ui/FredView.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class FredView: public QMainWindow, public IDialogProvider {
3939
void showContextMenu(const QPoint& globalPos);
4040

4141
public slots:
42-
void openLoadMissionDIalog();
42+
void openLoadMissionDialog();
4343

4444
void newMission();
4545

0 commit comments

Comments
 (0)