Skip to content

Commit 43387ca

Browse files
authored
Fix flickering turrets in techroom (scp-fs2open#7527)
Turrets with initial animations flip animation angles every frame in the techroom. The commit returns TriStateBool from model_get_cached_ui_render_instance specifically so callers can run setup only when a new instance is created, but only `render_tech_model` (the Lua path) actually checks it. Since the instance is cached and persists across frames, every frame re-runs clearShipData + initial-animation start on an already-animated instance, re-applying the initial animations relative to the current (already-animated) pose. This is what seems to produces the per-frame flip/jitter. This PR caches it to prevent this, and fixes scp-fs2open#7526. Tests confirm it works as expected.
1 parent 3e41e5b commit 43387ca

3 files changed

Lines changed: 16 additions & 8 deletions

File tree

code/menuui/techmenu.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -600,8 +600,11 @@ void techroom_ships_render(float frametime)
600600
render_info.set_detail_level_lock(0);
601601

602602
int model_instance = -1;
603-
model_get_cached_ui_render_instance(Techroom_modelnum, &model_instance);
604-
if (Tab == SHIPS_DATA_TAB) {
603+
auto cache_result = model_get_cached_ui_render_instance(Techroom_modelnum, &model_instance);
604+
// Only set up the instance when it was freshly created; the cached instance persists across
605+
// frames, so re-running this every frame would re-apply initial animations on top of the
606+
// already-animated pose and make animated submodels (e.g. turrets) flip/jitter.
607+
if (Tab == SHIPS_DATA_TAB && cache_result == TriStateBool::TRUE_) {
605608
model_set_up_techroom_instance(&Ship_info[Cur_entry_index], model_instance);
606609
}
607610

code/missionui/missionscreencommon.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,8 +1665,9 @@ void draw_model_icon(int model_id, uint64_t flags, int x, int y, int w, int h, s
16651665
Glowpoint_override = true;
16661666
model_clear_instance(model_id);
16671667
int model_instance = -1;
1668-
model_get_cached_ui_render_instance(model_id, &model_instance);
1669-
if (sip != nullptr) {
1668+
auto cache_result = model_get_cached_ui_render_instance(model_id, &model_instance);
1669+
// Only set up the instance when it was freshly created; the cached instance persists across frames.
1670+
if (sip != nullptr && cache_result == TriStateBool::TRUE_) {
16701671
model_set_up_techroom_instance(sip, model_instance);
16711672
}
16721673

@@ -1688,8 +1689,9 @@ void draw_model_rotating(model_render_params *render_info, int ship_class, int m
16881689
return;
16891690

16901691
int model_instance = -1;
1691-
model_get_cached_ui_render_instance(model_id, &model_instance);
1692-
if (!(flags & MR_IS_MISSILE) && SCP_vector_inbounds(Ship_info, ship_class)) {
1692+
auto cache_result = model_get_cached_ui_render_instance(model_id, &model_instance);
1693+
// Only set up the instance when it was freshly created; the cached instance persists across frames.
1694+
if (!(flags & MR_IS_MISSILE) && SCP_vector_inbounds(Ship_info, ship_class) && cache_result == TriStateBool::TRUE_) {
16931695
model_set_up_techroom_instance(&Ship_info[ship_class], model_instance);
16941696
}
16951697

code/missionui/missionweaponchoice.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -828,8 +828,11 @@ void draw_3d_overhead_view(int model_num,
828828

829829
model_clear_instance(model_num);
830830
int model_instance = -1;
831-
model_get_cached_ui_render_instance(model_num, &model_instance);
832-
model_set_up_techroom_instance(sip, model_instance);
831+
auto cache_result = model_get_cached_ui_render_instance(model_num, &model_instance);
832+
// Only set up the instance when it was freshly created; the cached instance persists across frames.
833+
if (cache_result == TriStateBool::TRUE_) {
834+
model_set_up_techroom_instance(sip, model_instance);
835+
}
833836
polymodel* pm = model_get(model_num);
834837

835838
if (sip->replacement_textures.size() > 0) {

0 commit comments

Comments
 (0)