Skip to content

Commit 2b6e203

Browse files
committed
assign sip->model_num from inside model_load, plus a few tweaks
1 parent 0642dcc commit 2b6e203

5 files changed

Lines changed: 21 additions & 19 deletions

File tree

code/hud/hudshield.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -697,23 +697,22 @@ void HudGaugeShield::showShields(const object *objp, ShieldGaugeType mode, bool
697697
model_render_params render_info;
698698

699699
// If this comment is here then I have not tested this
700-
int model_num = sip->model_num;
701700
int model_instance_number = -1;
702701

703702
if (!config) {
704703
model_instance_number = sp->model_instance_num;
705704
render_info.set_replacement_textures(model_get_instance(model_instance_number)->texture_replace);
706705
}
707706

708-
if (model_num < 0 && config) {
709-
model_num = model_load(sip, false);
707+
if (sip->model_num < 0 && config) {
708+
sip->model_num = model_load(sip, false);
710709
}
711710

712711
render_info.set_flags(MR_NO_LIGHTING | MR_AUTOCENTER | MR_NO_FOGGING);
713712
render_info.set_detail_level_lock(1);
714713
render_info.set_object_number(OBJ_INDEX(objp));
715714

716-
model_render_immediate( &render_info, model_num, model_instance_number, &object_orient, &vmd_zero_vector );
715+
model_render_immediate( &render_info, sip->model_num, model_instance_number, &object_orient, &vmd_zero_vector );
717716
}
718717

719718
//We're done

code/mission/missionparse.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5337,7 +5337,7 @@ void resolve_path_masks(bool path_user_is_ship, const char *path_user, anchor_t
53375337
// uninitialized; compute the mask from scratch
53385338
if (prp->cached_mask & (1 << MAX_SHIP_BAY_PATHS))
53395339
{
5340-
int j, bay_path, modelnum;
5340+
int j, bay_path;
53415341

53425342
// get anchor ship
53435343
Assertion(anchor.isValid() && !(anchor.value() & ANCHOR_SPECIAL_ARRIVAL), "%s %s anchor %d is invalid or is a special arrival. Get a coder!", path_user_is_ship ? "Ship" : "Wing", path_user, anchor.value());
@@ -5346,14 +5346,13 @@ void resolve_path_masks(bool path_user_is_ship, const char *path_user, anchor_t
53465346

53475347
// Load the anchor ship model with subsystems and all; it'll need to be done for this mission anyway
53485348
auto anchor_sip = anchor_ship_entry->sip();
5349-
modelnum = model_load(anchor_sip->pof_file, anchor_sip);
5350-
anchor_sip->model_num = modelnum;
5349+
anchor_sip->model_num = model_load(anchor_sip->pof_file, anchor_sip);
53515350

53525351
// resolve names to indexes
53535352
*path_mask = 0;
53545353
for (j = 0; j < prp->num_paths; j++)
53555354
{
5356-
bay_path = model_find_bay_path(modelnum, prp->path_names[j]);
5355+
bay_path = model_find_bay_path(anchor_sip->model_num, prp->path_names[j]);
53575356
if (bay_path < 0)
53585357
continue;
53595358

@@ -7075,8 +7074,9 @@ bool post_process_mission(mission *pm)
70757074

70767075
if (valid) {
70777076
ship_info* sip = &Ship_info[icon.ship_class];
7078-
stage.icons[j].modelnum = model_load(sip->pof_file, sip);
7079-
sip->model_num = stage.icons[j].modelnum;
7077+
int modelnum = model_load(sip->pof_file, sip);
7078+
stage.icons[j].modelnum = modelnum;
7079+
sip->model_num = modelnum;
70807080
}
70817081
}
70827082
}
@@ -8945,11 +8945,10 @@ void check_anchor_for_hangar_bay(SCP_string &message, SCP_set<anchor_t> &anchors
89458945
{
89468946
// Load the anchor ship model with subsystems and all; it'll need to be done for this mission anyway
89478947
auto anchor_sip = anchor_ship_entry->sip();
8948-
int modelnum = model_load(anchor_sip->pof_file, anchor_sip);
8949-
anchor_sip->model_num = modelnum;
8948+
anchor_sip->model_num = model_load(anchor_sip->pof_file, anchor_sip);
89508949

89518950
// Check if this model has a hangar bay
8952-
if (!model_has_hangar_bay(modelnum))
8951+
if (!model_has_hangar_bay(anchor_sip->model_num))
89538952
{
89548953
sprintf(message, "%s (%s) is used as a%s anchor by %s %s (and possibly elsewhere too), but it does not have a hangar bay!", anchor_ship_entry->name,
89558954
anchor_sip->name, is_arrival ? "n arrival" : " departure", other_is_ship ? "ship" : "wing", other_name);

code/model/model.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,11 +1005,11 @@ void model_free_all();
10051005
void model_instance_free_all();
10061006

10071007
// Alias to model_load, checks if a pof tech model exists and loads it if specified, otherwise loads the default pof. --wookieejedi
1008-
// NOTE: Each time model_load is called with a ship_info pointer, which causes it to load subsystems, the model number MUST be assigned to the ship_info.
1008+
// NOTE: Each time model_load is called with a ship_info pointer, which causes it to load subsystems, the model number is also assigned to the ship_info.
10091009
int model_load(ship_info* sip, bool prefer_tech_model);
10101010

10111011
// Loads a model from disk and returns the model number it loaded into.
1012-
// NOTE: Each time model_load is called with a ship_info pointer, which causes it to load subsystems, the model number MUST be assigned to the ship_info.
1012+
// NOTE: Each time model_load is called with a ship_info pointer, which causes it to load subsystems, the model number is also assigned to the ship_info.
10131013
int model_load(const char *filename, ship_info* sip = nullptr, ErrorType error_type = ErrorType::FATAL_ERROR, bool allow_redundant_load = false);
10141014

10151015
int model_create_instance(int objnum, int model_num);

code/model/modelread.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3245,6 +3245,8 @@ int model_load(const char* filename, ship_info* sip, ErrorType error_type, bool
32453245
if (!stricmp(filename , Polygon_models[i]->filename) && !allow_redundant_load) {
32463246
// Model already loaded; just return.
32473247
Polygon_models[i]->used_this_mission++;
3248+
if (sip != nullptr)
3249+
sip->model_num = Polygon_models[i]->id;
32483250
return Polygon_models[i]->id;
32493251
}
32503252
} else if ( num == -1 ) {
@@ -3519,6 +3521,8 @@ int model_load(const char* filename, ship_info* sip, ErrorType error_type, bool
35193521
model_set_bay_path_nums(pm);
35203522

35213523
unpause_parse();
3524+
if (sip != nullptr)
3525+
sip->model_num = pm->id;
35223526
return pm->id;
35233527
}
35243528

freespace2/freespace.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7437,11 +7437,11 @@ void Do_model_timings_test()
74377437
int model_id[MAX_POLYGON_MODELS];
74387438

74397439
// Load them all
7440-
for (auto & sip : Ship_info) {
7441-
sip.model_num = model_load(sip.pof_file);
7440+
for (auto & si : Ship_info) {
7441+
si.model_num = model_load(&si, false);
74427442

7443-
model_used[sip.model_num % MAX_POLYGON_MODELS]++;
7444-
model_id[sip.model_num % MAX_POLYGON_MODELS] = sip.model_num;
7443+
model_used[si.model_num % MAX_POLYGON_MODELS]++;
7444+
model_id[si.model_num % MAX_POLYGON_MODELS] = si.model_num;
74457445
}
74467446

74477447
Texture_fp = fopen( NOX("ShipTextures.txt"), "wt" );

0 commit comments

Comments
 (0)