@@ -26,13 +26,9 @@ int R_PrecacheCinematic( const char *cinname )
2626 if ( !cinname || !*cinname )
2727 return -1 ;
2828
29- if ( *cinname == ' *' )
30- {
31- cinname++;
32- }
33-
3429 // not AVI file
35- if ( Q_stricmp ( UTIL_FileExtension ( cinname ), " avi" ))
30+ const char *ext = UTIL_FileExtension ( cinname );
31+ if ( Q_stricmp ( ext, " avi" ) && Q_stricmp ( ext, " webm" )) // with ffmpeg we don't really have a limit here
3632 return -1 ;
3733
3834 int i;
@@ -68,7 +64,13 @@ int R_PrecacheCinematic( const char *cinname )
6864 }
6965
7066 ALERT ( at_console, " Loading cinematic %s [%s]\n " , cinname, " sound" );
71- tr.cinematics [i].state = OPEN_CINEMATIC ( tr.cinematics [i].name , true );
67+
68+ // FIXME: engine is hardcoded to load file in media/ folder, must be fixed on engine side
69+ const char *p = tr.cinematics [i].name ;
70+ if ( !Q_strnicmp ( p, " media/" , 6 ))
71+ p += 6 ;
72+
73+ tr.cinematics [i].state = (movie_state_s *)OPEN_CINEMATIC ( p, true );
7274
7375 // grab info about movie
7476 if ( tr.cinematics [i].state != NULL )
@@ -79,6 +81,8 @@ int R_PrecacheCinematic( const char *cinname )
7981
8082void R_InitCinematics ( void )
8183{
84+ // a1ba: this function is useless lmao
85+ // it's called before WORLD_HAS_MOVIES bit set
8286 const char *name, *ext;
8387
8488 // make sure what we have texture to draw cinematics
@@ -162,6 +166,7 @@ void R_UpdateCinematic( const msurface_t *surf )
162166 if ( cinhandle >= 0 && es->cintexturenum <= 0 )
163167 es->cintexturenum = R_AllocateCinematicTexture ( TF_NOMIPMAP );
164168
169+ // a1ba: isn't this kinda stupid? If movie isn't active anymore, we will never draw movie on it again
165170 if ( cinhandle == -1 || es->cintexturenum <= 0 || CIN_IS_ACTIVE ( tr.cinematics [cinhandle].state ) == false )
166171 {
167172 // cinematic textures limit exceeded, so remove SURF_MOVIE flag
@@ -170,28 +175,18 @@ void R_UpdateCinematic( const msurface_t *surf )
170175 }
171176
172177 gl_movie_t *cin = &tr.cinematics [cinhandle];
173- float cin_time;
174-
175- if ( FBitSet ( RI->currententity ->curstate .iuser1 , CF_LOOPED_MOVIE ))
176- {
177- // advances cinematic time
178- cin_time = fmod ( RI->currententity ->curstate .fuser2 , cin->length );
179- }
180- else
181- {
182- cin_time = RI->currententity ->curstate .fuser2 ;
183- }
184178
185- // read the next frame
186- int cin_frame = CIN_GET_FRAME_NUMBER ( cin-> state , cin_time ) ;
179+ if ( cin-> finished )
180+ return ;
187181
188- // upload the new frame
189- if ( cin_frame != es->checkcount )
182+ if ( !cin->texture_set )
190183 {
191- GL_SelectTexture ( GL_TEXTURE0 ); // doesn't matter. select 0-th unit just as default
192- byte *raw = CIN_GET_FRAMEDATA ( cin->state , cin_frame );
193- CIN_UPLOAD_FRAME ( tr.cinTextures [es->cintexturenum -1 ], cin->xres , cin->yres , cin->xres , cin->yres , raw );
194- es->checkcount = cin_frame;
184+ CIN_SET_PARM ( cin->state ,
185+ AVI_RENDER_TEXNUM, tr.cinTextures [es->cintexturenum -1 ],
186+ AVI_RENDER_W, cin->xres ,
187+ AVI_RENDER_H, cin->yres ,
188+ AVI_PARM_LAST );
189+ cin->texture_set = true ;
195190 }
196191}
197192
@@ -208,18 +203,24 @@ void R_UpdateCinSound( cl_entity_t *e )
208203 return ;
209204
210205 gl_movie_t *cin = &tr.cinematics [cinhandle];
211- float cin_time;
212206
213- if ( FBitSet ( e->curstate .iuser1 , CF_LOOPED_MOVIE ))
207+ if ( cin->finished )
208+ return ;
209+
210+ if ( !cin->sound_set )
214211 {
215- // advances cinematic time
216- cin_time = fmod ( e->curstate .fuser2 , cin->length );
212+ CIN_SET_PARM ( cin->state ,
213+ AVI_ENTNUM, e->index ,
214+ AVI_VOLUME, static_cast <int >( VOL_NORM * 255 ),
215+ AVI_ATTN, ATTN_NORM,
216+ AVI_PARM_LAST );
217+ cin->sound_set = true ;
217218 }
218- else
219+
220+ if ( !CIN_THINK ( cin->state )) // TODO: make a video manager that will call this each frame
219221 {
220- cin_time = e->curstate .fuser2 ;
222+ if ( FBitSet ( RI->currententity ->curstate .iuser1 , CF_LOOPED_MOVIE ))
223+ CIN_SET_PARM ( cin->state , AVI_REWIND, AVI_PARM_LAST );
224+ else cin->finished = true ;
221225 }
222-
223- // stream avi sound
224- CIN_UPDATE_SOUND ( cin->state , e->index , VOL_NORM, ATTN_IDLE, cin_time );
225- }
226+ }
0 commit comments