Skip to content
Merged
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
18 changes: 18 additions & 0 deletions code/decals/decals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ Decal::Decal() {
vm_vec_make(&scale, 1.f, 1.f, 1.f);
}

void Decal::markForDeletion() {
orig_obj_type = OBJ_NONE;
}

bool Decal::isValid() const {
if (!object.isValid()) {
return false;
Expand All @@ -193,6 +197,11 @@ bool Decal::isValid() const {
return false;
}

if (orig_obj_type == OBJ_NONE) {
//Decal should be cleared
return false;
}

if (orig_obj_type != object.objp()->type) {
mprintf(("Decal object type for object %d has changed from %s to %s. Please let m!m know about this\n",
object.objnum, Object_type_names[orig_obj_type], Object_type_names[object.objp()->type]));
Expand Down Expand Up @@ -536,4 +545,13 @@ void addSingleFrameDecal(Decal&& info) {
active_single_frame_decals.push_back(info);
}

void invalidateForShip(const ship* shipp) {
int objnum = shipp->objnum;
for (Decal& decal : active_decals) {
if (decal.object.objnum == objnum) {
decal.markForDeletion();
}
}
}

}
4 changes: 4 additions & 0 deletions code/decals/decals.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ struct Decal {

Decal();

void markForDeletion();

bool isValid() const;
};

Expand Down Expand Up @@ -160,4 +162,6 @@ void addDecal(creation_info& info,

void addSingleFrameDecal(Decal&& info);

void invalidateForShip(const ship* shipp);

}
10 changes: 10 additions & 0 deletions code/ship/ship.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11766,10 +11766,18 @@ static void ship_model_change(int n, int ship_type)
}

model_delete_instance(sp->model_instance_num);
if (sp->cockpit_model_instance >= 0) {
model_delete_instance(sp->cockpit_model_instance);
}

// create new model instance data
// note: this is needed for both subsystem stuff and submodel animation stuff
sp->model_instance_num = model_create_instance(OBJ_INDEX(objp), sip->model_num);
if (sip->cockpit_model_num >= 0)
sp->cockpit_model_instance = model_create_instance(model_objnum_special::OBJNUM_COCKPIT, sip->cockpit_model_num);
else
sp->cockpit_model_instance = -1;

pmi = model_get_instance(sp->model_instance_num);

// Goober5000 - deal with texture replacement by re-applying the same code we used during parsing
Expand Down Expand Up @@ -12069,6 +12077,8 @@ void change_ship_type(int n, int ship_type, int by_sexp)
Assertion(weapon_turret_matches.empty(), "Failed to find matches for every turret a projectile was fired from on ship %s in change_ship_type(); get a coder!\n", sp->ship_name);
Assertion(last_targeted_matches.empty(), "Somehow failed to find every subsystem a player was previously targeting on ship %s in change_ship_type(); get a coder!\n", sp->ship_name);

decals::invalidateForShip(sp);

// point to new ship data
ship_model_change(n, ship_type);
sp->ship_info_index = ship_type;
Expand Down