Skip to content

Commit a8b6227

Browse files
committed
add_missing_frames: optimize.
* run after part insertion, within json_load/load_legacy functions * push new frame into item list instead of using vehicle::install_part, which triggers find_external_parts, find_exhaust, precalc_mounts once for every frame added; load does this anyway. * Only run if savegame_loading_version is v10 or below; new saves won't have vehicles with invalid frame config.
1 parent 6be44cd commit a8b6227

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

savegame_json.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,6 +1431,11 @@ void vehicle::json_load(picojson::value & parsed, game * g ) {
14311431
}
14321432
parray = NULL;
14331433
}
1434+
/* After loading, check if the vehicle is from the old rules and is missing
1435+
* frames. */
1436+
if ( savegame_loading_version < 11 ) {
1437+
add_missing_frames();
1438+
}
14341439
find_external_parts ();
14351440
find_exhaust ();
14361441
insides_dirty = true;

savegame_legacy.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,9 @@ void vehicle::load_legacy(std::ifstream &stin) {
10621062
}
10631063
parts.push_back (new_part);
10641064
}
1065+
/* After loading, check if the vehicle is from the old rules and is missing
1066+
* frames. */
1067+
add_missing_frames();
10651068
find_external_parts ();
10661069
find_exhaust ();
10671070
insides_dirty = true;

vehicle.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,6 @@ void vehicle::load (std::ifstream &stin)
7878
} else {
7979
load_legacy(stin);
8080
}
81-
82-
/* After loading, check if the vehicle is from the old rules and is missing
83-
* frames. */
84-
add_missing_frames();
85-
8681
}
8782

8883
/** Checks all parts to see if frames are missing (as they might be when
@@ -108,7 +103,15 @@ void vehicle::add_missing_frames()
108103
}
109104
if(!found) {
110105
//No frame here! Install one.
111-
install_part(next_x, next_y, "frame_vertical", -1, true);
106+
vehicle_part new_part;
107+
new_part.id = "frame_vertical";
108+
new_part.mount_dx = next_x;
109+
new_part.mount_dy = next_y;
110+
new_part.hp = vehicle_part_types["frame_vertical"].durability;
111+
new_part.amount = 0;
112+
new_part.blood = 0;
113+
new_part.bigness = 0;
114+
parts.push_back (new_part);
112115
}
113116
}
114117

0 commit comments

Comments
 (0)