Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions code/hud/hudshield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -697,23 +697,22 @@ void HudGaugeShield::showShields(const object *objp, ShieldGaugeType mode, bool
model_render_params render_info;

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

if (!config) {
model_instance_number = sp->model_instance_num;
render_info.set_replacement_textures(model_get_instance(model_instance_number)->texture_replace);
}

if (model_num < 0 && config) {
model_num = model_load(sip, false);
if (sip->model_num < 0 && config) {
sip->model_num = model_load(sip, false);
}

render_info.set_flags(MR_NO_LIGHTING | MR_AUTOCENTER | MR_NO_FOGGING);
render_info.set_detail_level_lock(1);
render_info.set_object_number(OBJ_INDEX(objp));

model_render_immediate( &render_info, model_num, model_instance_number, &object_orient, &vmd_zero_vector );
model_render_immediate( &render_info, sip->model_num, model_instance_number, &object_orient, &vmd_zero_vector );
}

//We're done
Expand Down
14 changes: 8 additions & 6 deletions code/mission/missionparse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5337,7 +5337,7 @@ void resolve_path_masks(bool path_user_is_ship, const char *path_user, anchor_t
// uninitialized; compute the mask from scratch
if (prp->cached_mask & (1 << MAX_SHIP_BAY_PATHS))
{
int j, bay_path, modelnum;
int j, bay_path;

// get anchor ship
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());
Expand All @@ -5346,13 +5346,13 @@ void resolve_path_masks(bool path_user_is_ship, const char *path_user, anchor_t

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

// resolve names to indexes
*path_mask = 0;
for (j = 0; j < prp->num_paths; j++)
{
bay_path = model_find_bay_path(modelnum, prp->path_names[j]);
bay_path = model_find_bay_path(anchor_sip->model_num, prp->path_names[j]);
if (bay_path < 0)
continue;

Expand Down Expand Up @@ -7074,7 +7074,9 @@ bool post_process_mission(mission *pm)

if (valid) {
ship_info* sip = &Ship_info[icon.ship_class];
stage.icons[j].modelnum = model_load(sip->pof_file, sip);
int modelnum = model_load(sip->pof_file, sip);
stage.icons[j].modelnum = modelnum;
sip->model_num = modelnum;
}
}
}
Expand Down Expand Up @@ -8943,10 +8945,10 @@ void check_anchor_for_hangar_bay(SCP_string &message, SCP_set<anchor_t> &anchors
{
// Load the anchor ship model with subsystems and all; it'll need to be done for this mission anyway
auto anchor_sip = anchor_ship_entry->sip();
int modelnum = model_load(anchor_sip->pof_file, anchor_sip);
anchor_sip->model_num = model_load(anchor_sip->pof_file, anchor_sip);

// Check if this model has a hangar bay
if (!model_has_hangar_bay(modelnum))
if (!model_has_hangar_bay(anchor_sip->model_num))
{
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,
anchor_sip->name, is_arrival ? "n arrival" : " departure", other_is_ship ? "ship" : "wing", other_name);
Expand Down
2 changes: 2 additions & 0 deletions code/model/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -1005,9 +1005,11 @@ void model_free_all();
void model_instance_free_all();

// Alias to model_load, checks if a pof tech model exists and loads it if specified, otherwise loads the default pof. --wookieejedi
// 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.
int model_load(ship_info* sip, bool prefer_tech_model);

// Loads a model from disk and returns the model number it loaded into.
// 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.
int model_load(const char *filename, ship_info* sip = nullptr, ErrorType error_type = ErrorType::FATAL_ERROR, bool allow_redundant_load = false);

int model_create_instance(int objnum, int model_num);
Expand Down
4 changes: 4 additions & 0 deletions code/model/modelread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3245,6 +3245,8 @@ int model_load(const char* filename, ship_info* sip, ErrorType error_type, bool
if (!stricmp(filename , Polygon_models[i]->filename) && !allow_redundant_load) {
// Model already loaded; just return.
Polygon_models[i]->used_this_mission++;
if (sip != nullptr)
sip->model_num = Polygon_models[i]->id;
return Polygon_models[i]->id;
}
} else if ( num == -1 ) {
Expand Down Expand Up @@ -3519,6 +3521,8 @@ int model_load(const char* filename, ship_info* sip, ErrorType error_type, bool
model_set_bay_path_nums(pm);

unpause_parse();
if (sip != nullptr)
sip->model_num = pm->id;
return pm->id;
}

Expand Down
8 changes: 4 additions & 4 deletions freespace2/freespace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7437,11 +7437,11 @@ void Do_model_timings_test()
int model_id[MAX_POLYGON_MODELS];

// Load them all
for (auto & sip : Ship_info) {
sip.model_num = model_load(sip.pof_file);
for (auto & si : Ship_info) {
si.model_num = model_load(&si, false);

model_used[sip.model_num % MAX_POLYGON_MODELS]++;
model_id[sip.model_num % MAX_POLYGON_MODELS] = sip.model_num;
model_used[si.model_num % MAX_POLYGON_MODELS]++;
model_id[si.model_num % MAX_POLYGON_MODELS] = si.model_num;
}

Texture_fp = fopen( NOX("ShipTextures.txt"), "wt" );
Expand Down
Loading