X-Git-Url: https://de.git.xonotic.org/?p=xonotic%2Fdarkplaces.git;a=blobdiff_plain;f=cl_video.c;h=692dc9410425ae467e22e9af84a511aa77e8be44;hp=7707dd77e96fceca59c288eb0e79ae45297a917b;hb=95e0893e5dec7501a4ff07d7522dd4ce24b645aa;hpb=59d5ffaf49cffaec27871bfe53c9472d1f3d4259 diff --git a/cl_video.c b/cl_video.c index 7707dd77..692dc941 100644 --- a/cl_video.c +++ b/cl_video.c @@ -10,7 +10,6 @@ static int cl_videogmask; static int cl_videobytesperpixel; static clvideo_t videoarray[ MAXCLVIDEOS ]; -static mempool_t *cl_videomempool; static rtexturepool_t *cl_videotexturepool; static clvideo_t *FindUnusedVid( void ) @@ -44,8 +43,8 @@ static void SuspendVideo( clvideo_t * video ) // free the image data Mem_Free( video->imagedata ); // if we are in firstframe mode, also close the stream - if( video->state == CLVIDEO_FIRSTFRAME ) - dpvsimpledecode_close( video->stream ); + if( video->state == CLVIDEO_FIRSTFRAME ) + dpvsimpledecode_close( video->stream ); } static qboolean WakeVideo( clvideo_t * video ) @@ -59,10 +58,10 @@ static qboolean WakeVideo( clvideo_t * video ) video->state = CLVIDEO_UNUSED; return false; } - - video->imagedata = Mem_Alloc( cl_videomempool, video->cpif.width * video->cpif.height * cl_videobytesperpixel ); - video->cpif.tex = R_LoadTexture2D( cl_videotexturepool, video->cpif.name, - video->cpif.width, video->cpif.height, NULL, TEXTYPE_RGBA, 0, NULL ); + + video->imagedata = Mem_Alloc( cl_mempool, video->cpif.width * video->cpif.height * cl_videobytesperpixel ); + video->cpif.tex = R_LoadTexture2D( cl_videotexturepool, video->cpif.name, + video->cpif.width, video->cpif.height, NULL, TEXTYPE_RGBA, 0, NULL ); // update starttime video->starttime += realtime - video->lasttime; @@ -70,7 +69,7 @@ static qboolean WakeVideo( clvideo_t * video ) return true; } -static clvideo_t* OpenVideo( clvideo_t *video, char *filename, char *name, int owner ) +static clvideo_t* OpenVideo( clvideo_t *video, const char *filename, const char *name, int owner ) { strncpy( video->filename, filename, MAX_QPATH ); video->ownertag = owner; @@ -88,15 +87,15 @@ static clvideo_t* OpenVideo( clvideo_t *video, char *filename, char *name, int o video->cpif.width = dpvsimpledecode_getwidth( video->stream ); video->cpif.height = dpvsimpledecode_getheight( video->stream ); - video->cpif.tex = R_LoadTexture2D( cl_videotexturepool, video->cpif.name, + video->cpif.tex = R_LoadTexture2D( cl_videotexturepool, video->cpif.name, video->cpif.width, video->cpif.height, NULL, TEXTYPE_RGBA, 0, NULL ); - video->imagedata = Mem_Alloc( cl_videomempool, video->cpif.width * video->cpif.height * cl_videobytesperpixel ); + video->imagedata = Mem_Alloc( cl_mempool, video->cpif.width * video->cpif.height * cl_videobytesperpixel ); return video; } -clvideo_t* CL_OpenVideo( char *filename, char *name, int owner ) +clvideo_t* CL_OpenVideo( const char *filename, const char *name, int owner ) { clvideo_t *video; @@ -108,13 +107,13 @@ clvideo_t* CL_OpenVideo( char *filename, char *name, int owner ) return OpenVideo( video, filename, name, owner ); } -clvideo_t* CL_GetVideo( char *name ) +clvideo_t* CL_GetVideo( const char *name ) { int i; clvideo_t *video; for( i = 0 ; i < MAXCLVIDEOS ; i++ ) - if( videoarray[ i ].state != CLVIDEO_UNUSED + if( videoarray[ i ].state != CLVIDEO_UNUSED && !strcmp( videoarray[ i ].cpif.name , name ) ) break; if( i == MAXCLVIDEOS ) @@ -122,10 +121,12 @@ clvideo_t* CL_GetVideo( char *name ) video = &videoarray[ i ]; if( video->suspended ) + { if( !WakeVideo( video ) ) return NULL; - else if( video->state == CLVIDEO_RESETONWAKEUP ) + else if( video->state == CLVIDEO_RESETONWAKEUP ) video->framenum = -1; + } video->lasttime = realtime; @@ -147,7 +148,7 @@ void CL_RestartVideo( clvideo_t *video ) { if( !video ) return; - + video->starttime = video->lasttime = realtime; video->framenum = -1; @@ -184,9 +185,9 @@ static void VideoFrame( clvideo_t *video ) if( video->framenum < destframe ) { do { video->framenum++; - if( dpvsimpledecode_video( video->stream, video->imagedata, cl_videormask, - cl_videogmask, cl_videobmask, cl_videobytesperpixel, - cl_videobytesperpixel * video->cpif.width ) + if( dpvsimpledecode_video( video->stream, video->imagedata, cl_videormask, + cl_videogmask, cl_videobmask, cl_videobytesperpixel, + cl_videobytesperpixel * video->cpif.width ) ) { // finished? CL_RestartVideo( video ); if( video->state == CLVIDEO_PLAY ) @@ -195,7 +196,7 @@ static void VideoFrame( clvideo_t *video ) } } while( video->framenum < destframe ); R_UpdateTexture( video->cpif.tex, video->imagedata ); - } + } } void CL_VideoFrame( void ) // update all videos @@ -205,12 +206,14 @@ void CL_VideoFrame( void ) // update all videos for( video = videoarray, i = 0 ; i < MAXCLVIDEOS ; video++, i++ ) if( video->state != CLVIDEO_UNUSED && !video->suspended ) + { if( realtime - video->lasttime > CLTHRESHOLD ) SuspendVideo( video ); else if( video->state == CLVIDEO_PAUSE ) - video->starttime = realtime + video->framenum * video->framerate; - else + video->starttime = realtime - video->framenum * video->framerate; + else VideoFrame( video ); + } if( videoarray->state == CLVIDEO_FIRSTFRAME ) CL_VideoStop(); @@ -221,9 +224,6 @@ void CL_Video_Shutdown( void ) int i; for( i = 0 ; i < MAXCLVIDEOS ; i++ ) CL_CloseVideo( &videoarray[ i ] ); - - R_FreeTexturePool( &cl_videotexturepool ); - Mem_FreePool( &cl_videomempool ); } void CL_PurgeOwner( int owner ) @@ -239,11 +239,13 @@ int cl_videoplaying = false; // old, but still supported void CL_DrawVideo(void) { if (cl_videoplaying) - DrawQ_Pic(0, 0, videoarray->cpif.name, vid.conwidth, vid.conheight, 1, 1, 1, 1, 0); + DrawQ_Pic(0, 0, videoarray->cpif.name, vid_conwidth.integer, vid_conheight.integer, 1, 1, 1, 1, 0); } void CL_VideoStart(char *filename) { + Host_StartVideo(); + if( videoarray->state != CLVIDEO_UNUSED ) CL_CloseVideo( videoarray ); if( !OpenVideo( videoarray, filename, va( CLVIDEOPREFIX "%s", filename ), 0 ) ) @@ -266,6 +268,8 @@ static void CL_PlayVideo_f(void) { char name[1024]; + Host_StartVideo(); + if (Cmd_Argc() != 2) { Con_Print("usage: playvideo \nplays video named video/.dpv\n"); @@ -281,6 +285,28 @@ static void CL_StopVideo_f(void) CL_VideoStop(); } +static void cl_video_start( void ) +{ + int i; + clvideo_t *video; + + cl_videotexturepool = R_AllocTexturePool(); + + for( video = videoarray, i = 0 ; i < MAXCLVIDEOS ; i++, video++ ) + if( video->state != CLVIDEO_UNUSED && !video->suspended ) + video->cpif.tex = R_LoadTexture2D( cl_videotexturepool, video->cpif.name, + video->cpif.width, video->cpif.height, NULL, TEXTYPE_RGBA, 0, NULL ); +} + +static void cl_video_shutdown( void ) +{ + R_FreeTexturePool( &cl_videotexturepool ); +} + +static void cl_video_newmap( void ) +{ +} + void CL_Video_Init( void ) { cl_videobytesperpixel = 4; @@ -288,9 +314,9 @@ void CL_Video_Init( void ) cl_videogmask = BigLong(0x00FF0000); cl_videobmask = BigLong(0x0000FF00); - cl_videomempool = Mem_AllocPool( "CL_Video", 0, NULL ); - cl_videotexturepool = R_AllocTexturePool(); - Cmd_AddCommand( "playvideo", CL_PlayVideo_f ); Cmd_AddCommand( "stopvideo", CL_StopVideo_f ); + + R_RegisterModule( "CL_Video", cl_video_start, cl_video_shutdown, cl_video_newmap ); } +