Skip to content

Commit 2fa7ddc

Browse files
authored
Merge pull request #3481 from MageKing17/bugfix/mainhall-misc-apng-animations
Fix APNG misc mainhall animations.
2 parents a6f821d + 43f9a48 commit 2fa7ddc

File tree

3 files changed

+28
-11
lines changed

3 files changed

+28
-11
lines changed

code/graphics/generic.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ void generic_anim_render_variable_frame_delay(generic_anim* ga, float frametime,
630630
else {
631631
// playing forwards
632632
ga->anim_time += frametime;
633-
if(ga->anim_time >= ga->total_time && ga->png.anim->current_frame >= ga->png.anim->nframes-1) {
633+
if(ga->anim_time >= ga->total_time && ga->png.anim->current_frame >= ga->png.anim->nframes) {
634634
if(ga->direction & GENERIC_ANIM_DIRECTION_NOLOOP) {
635635
ga->anim_time = ga->total_time; // stop on last frame when playing
636636
}
@@ -660,7 +660,7 @@ void generic_anim_render_variable_frame_delay(generic_anim* ga, float frametime,
660660
}
661661
else {
662662
if (ga->anim_time >= ga->png.previous_frame_time + ga->png.anim->frame.delay &&
663-
ga->png.anim->current_frame < ga->png.anim->nframes-1) {
663+
ga->png.anim->current_frame < ga->png.anim->nframes) {
664664
ga->png.previous_frame_time += ga->png.anim->frame.delay;
665665
ga->current_frame++;
666666
}
@@ -725,3 +725,17 @@ void generic_anim_render(generic_anim *ga, float frametime, int x, int y, bool m
725725
}
726726
}
727727
}
728+
729+
/*
730+
* @brief reset an animation back to the start
731+
*
732+
* @param [in] *ga animation data
733+
*/
734+
void generic_anim_reset(generic_anim *ga) {
735+
ga->anim_time = 0.0f;
736+
ga->current_frame = 0;
737+
if (ga->type == BM_TYPE_PNG) {
738+
ga->png.previous_frame_time = 0.0f;
739+
ga->png.anim->goto_start();
740+
}
741+
}

code/graphics/generic.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,5 @@ int generic_anim_stream(generic_anim *ga, const bool cache = true);
8989
int generic_bitmap_load(generic_bitmap *gb);
9090
void generic_anim_unload(generic_anim *ga);
9191
void generic_anim_render(generic_anim *ga, float frametime, int x, int y, bool menu = false, const generic_extras *ge = nullptr);
92-
92+
void generic_anim_reset(generic_anim *ga);
9393
#endif

code/menuui/mainhallmenu.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,7 @@ void main_hall_do(float frametime)
736736
Main_hall_misc_anim.at(idx).direction |= GENERIC_ANIM_DIRECTION_NOLOOP;
737737
}
738738

739+
// TODO: generic_anim_skip_to(cur_frame, anim_time);
739740
Main_hall_misc_anim.at(idx).current_frame = cur_frame;
740741
Main_hall_misc_anim.at(idx).anim_time = anim_time;
741742

@@ -764,6 +765,7 @@ void main_hall_do(float frametime)
764765
Main_hall_door_anim.at(idx).direction = GENERIC_ANIM_DIRECTION_BACKWARDS | GENERIC_ANIM_DIRECTION_NOLOOP;
765766
}
766767

768+
// TODO: generic_anim_skip_to(cur_frame, anim_time);
767769
Main_hall_door_anim.at(idx).current_frame = cur_frame;
768770
Main_hall_door_anim.at(idx).anim_time = anim_time;
769771

@@ -1251,8 +1253,7 @@ void main_hall_render_misc_anims(float frametime, bool over_doors)
12511253
// if the timestamp is not -1 and has popped, play the anim and make the timestamp -1
12521254
} else if (timestamp_elapsed(Main_hall->misc_anim_delay.at(idx).at(0))) {
12531255
Main_hall->misc_anim_paused.at(idx) = false;
1254-
Main_hall_misc_anim.at(idx).current_frame = 0;
1255-
Main_hall_misc_anim.at(idx).anim_time = 0.0;
1256+
generic_anim_reset(&Main_hall_misc_anim.at(idx));
12561257

12571258
// kill the timestamp
12581259
Main_hall->misc_anim_delay.at(idx).at(0) = -1;
@@ -1417,12 +1418,14 @@ void main_hall_mouse_release_region(int region)
14171418
sound_pair->second = snd_play(sound_pair->first, Main_hall->door_sound_pan.at(region));
14181419
}
14191420

1420-
// TODO: track current frame
1421-
snd_set_pos(sound_pair->second,
1422-
(float) ((Main_hall_door_anim.at(region).keyframe) ? Main_hall_door_anim.at(region).keyframe :
1423-
Main_hall_door_anim.at(region).num_frames - Main_hall_door_anim.at(region).current_frame)
1424-
/ (float) Main_hall_door_anim.at(region).num_frames,
1425-
1);
1421+
// start the sound playing at the right spot relative to the completion of the animation
1422+
if ( Main_hall_door_anim.at(region).current_frame != -1 ) {
1423+
snd_set_pos(sound_pair->second,
1424+
(float) ((Main_hall_door_anim.at(region).keyframe) ? Main_hall_door_anim.at(region).keyframe :
1425+
Main_hall_door_anim.at(region).num_frames - Main_hall_door_anim.at(region).current_frame)
1426+
/ (float) Main_hall_door_anim.at(region).num_frames,
1427+
1);
1428+
}
14261429
}
14271430
}
14281431

0 commit comments

Comments
 (0)