@@ -16,8 +16,8 @@ use image::{codecs::gif, AnimationDecoder, DynamicImage, ImageError};
1616use macroquad:: prelude:: { Color , WHITE } ;
1717use sasa:: AudioClip ;
1818use serde:: Deserialize ;
19- use tracing:: debug;
2019use std:: { cell:: RefCell , collections:: HashMap , future:: IntoFuture , rc:: Rc , str:: FromStr , time:: Duration } ;
20+ use tracing:: debug;
2121
2222pub const RPE_WIDTH : f32 = 1350. ;
2323pub const RPE_HEIGHT : f32 = 900. ;
@@ -283,9 +283,7 @@ fn parse_speed_events(r: &mut BpmList, rpe: &[RPEEventLayer], max_time: f32) ->
283283
284284fn parse_gif_events < V : Clone + Into < f32 > > ( r : & mut BpmList , rpe : & [ RPEEvent < V > ] , bezier_map : & BezierMap , gif : & GifFrames ) -> Result < Anim < f32 > > {
285285 let mut kfs = Vec :: new ( ) ;
286- if rpe[ 0 ] . start_time . beats ( ) != 0.0 {
287- kfs. push ( Keyframe :: new ( 0.0 , 0.0 , 2 ) ) ;
288- }
286+ kfs. push ( Keyframe :: new ( 0.0 , 0.0 , 2 ) ) ;
289287 let mut next_rep_time: u128 = 0 ;
290288 for e in rpe {
291289 while r. time ( & e. start_time ) > next_rep_time as f32 / 1000. {
@@ -312,6 +310,12 @@ fn parse_gif_events<V: Clone + Into<f32>>(r: &mut BpmList, rpe: &[RPEEvent<V>],
312310 kfs. push ( Keyframe :: new ( r. time ( & e. end_time ) , e. end . clone ( ) . into ( ) , 2 ) ) ;
313311 next_rep_time = ( r. time ( & e. end_time ) * 1000. + gif. total_time ( ) as f32 * ( 1. - e. end . clone ( ) . into ( ) ) ) . round ( ) as u128 ;
314312 }
313+ const GIF_MAX_TIME : f32 = 2000. ;
314+ while GIF_MAX_TIME > next_rep_time as f32 / 1000. {
315+ kfs. push ( Keyframe :: new ( next_rep_time as f32 / 1000. , 1.0 , 0 ) ) ;
316+ kfs. push ( Keyframe :: new ( next_rep_time as f32 / 1000. , 0.0 , 2 ) ) ;
317+ next_rep_time += gif. total_time ( ) ;
318+ }
315319 Ok ( Anim :: new ( kfs) )
316320}
317321
@@ -526,18 +530,22 @@ async fn parse_judge_line(
526530 . load_file ( & rpe. texture )
527531 . await
528532 . with_context ( || ptl ! ( "gif-load-failed" , "path" => rpe. texture. clone( ) ) ) ?;
529- let frames = GifFrames :: new ( tokio:: spawn ( async move {
530- let decoder = gif:: GifDecoder :: new ( & data[ ..] ) ?;
531- debug ! ( "decoding gif" ) ;
532- Ok :: < std:: vec:: Vec < _ > , ImageError > ( decoder
533- . into_frames ( ) . collect ( )
534- )
535- } ) . into_future ( ) . await ??. into_iter ( ) . map ( |frame| -> ( u128 , SafeTexture ) {
536- let frame = frame. unwrap ( ) ;
537- let delay: Duration = frame. delay ( ) . into ( ) ;
538- ( delay. as_millis ( ) , SafeTexture :: from ( DynamicImage :: ImageRgba8 ( frame. into_buffer ( ) ) ) )
539- } )
540- . collect ( ) ) ;
533+ let frames = GifFrames :: new (
534+ tokio:: spawn ( async move {
535+ let decoder = gif:: GifDecoder :: new ( & data[ ..] ) ?;
536+ debug ! ( "decoding gif" ) ;
537+ Ok :: < std:: vec:: Vec < _ > , ImageError > ( decoder. into_frames ( ) . collect ( ) )
538+ } )
539+ . into_future ( )
540+ . await ??
541+ . into_iter ( )
542+ . map ( |frame| -> ( u128 , SafeTexture ) {
543+ let frame = frame. unwrap ( ) ;
544+ let delay: Duration = frame. delay ( ) . into ( ) ;
545+ ( delay. as_millis ( ) , SafeTexture :: from ( DynamicImage :: ImageRgba8 ( frame. into_buffer ( ) ) ) )
546+ } )
547+ . collect ( ) ,
548+ ) ;
541549 debug ! ( "gif decoded" ) ;
542550 let events = parse_gif_events ( r, events, bezier_map, & frames) . with_context ( || ptl ! ( "gif-events-parse-failed" ) ) ?;
543551 JudgeLineKind :: TextureGif ( events, frames, rpe. texture . clone ( ) )
0 commit comments