Skip to content

Commit 6633ccc

Browse files
a1batrossSNMetamorph
authored andcommitted
client: basic adaption of movie playback to the new API
1 parent 61b3612 commit 6633ccc

File tree

4 files changed

+66
-50
lines changed

4 files changed

+66
-50
lines changed

client/enginecallback.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,11 @@ inline void PlaySound( int iSound, float vol ) { gEngfuncs.pfnPlaySoundByIndex(
115115
#define FREE_CINEMATIC (*gRenderfuncs.AVI_FreeVideo)
116116
#define CIN_IS_ACTIVE (*gRenderfuncs.AVI_IsActive)
117117
#define CIN_GET_VIDEO_INFO (*gRenderfuncs.AVI_GetVideoInfo)
118-
#define CIN_GET_FRAME_NUMBER (*gRenderfuncs.AVI_GetVideoFrameNumber)
119-
#define CIN_GET_FRAMEDATA (*gRenderfuncs.AVI_GetVideoFrame)
120-
#define CIN_UPDATE_SOUND (*gRenderfuncs.AVI_StreamSound)
118+
// #define CIN_GET_FRAME_NUMBER (*gRenderfuncs.AVI_GetVideoFrameNumber)
119+
// #define CIN_GET_FRAMEDATA (*gRenderfuncs.AVI_GetVideoFrame)
120+
// #define CIN_UPDATE_SOUND (*gRenderfuncs.AVI_StreamSound)
121+
#define CIN_THINK (*gRenderfuncs.AVI_Think)
122+
#define CIN_SET_PARM (*gRenderfuncs.AVI_SetParm)
121123

122124
// glcommands
123125
#define GL_SelectTexture (*gRenderfuncs.GL_SelectTexture)

client/render/gl_local.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,13 @@ typedef struct gl_fbo_s
229229
typedef struct gl_movie_s
230230
{
231231
char name[32];
232-
void *state;
232+
struct movie_state_s *state;
233233
float length; // total cinematic length
234234
int xres, yres; // size of cinematic
235+
236+
bool finished;
237+
bool sound_set;
238+
bool texture_set;
235239
} gl_movie_t;
236240

237241
typedef struct gl_texbuffer_s

client/render/gl_movie.cpp

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -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

8082
void 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+
}

client/render/gl_scene.cpp

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -496,19 +496,28 @@ static bool R_HandleLightEntity(cl_entity_t *ent)
496496
return true;
497497
}
498498

499+
// TODO: move this to a common function in gl_movie.cpp
499500
gl_movie_t *cin = &tr.cinematics[hCin];
500501

501-
// advances cinematic time
502-
float cin_time = fmod(entity.GetCinTime(), cin->length);
503-
504-
// read the next frame
505-
int cin_frame = CIN_GET_FRAME_NUMBER(cin->state, cin_time);
506-
if (cin_frame != dlight->lastframe)
502+
if( !cin->finished )
507503
{
508-
// upload the new frame
509-
byte *raw = CIN_GET_FRAMEDATA(cin->state, cin_frame);
510-
CIN_UPLOAD_FRAME(tr.cinTextures[dlight->cinTexturenum - 1], cin->xres, cin->yres, cin->xres, cin->yres, raw);
511-
dlight->lastframe = cin_frame;
504+
if( !cin->texture_set )
505+
{
506+
CIN_SET_PARM( cin->state, AVI_RENDER_TEXNUM, tr.cinTextures[dlight->cinTexturenum - 1],
507+
AVI_RENDER_W, cin->xres,
508+
AVI_RENDER_H, cin->yres,
509+
AVI_PARM_LAST );
510+
cin->texture_set = true;
511+
}
512+
513+
// running think here because we're usually thinking with audio, but dlight doesn't have audio
514+
515+
if( !CIN_THINK( cin->state )); // probably should be moved to some kind of global manager that will tick each frame
516+
{
517+
if( FBitSet( RI->currententity->curstate.iuser1, CF_LOOPED_MOVIE ))
518+
CIN_SET_PARM( cin->state, AVI_REWIND, AVI_PARM_LAST );
519+
else cin->finished = true;
520+
}
512521
}
513522

514523
if (entity.DisableShadows())

0 commit comments

Comments
 (0)