]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - cl_video.c
default sv_jumpstep to 0 to not allow players to jump places they should not be able...
[xonotic/darkplaces.git] / cl_video.c
index a6f067de13e59e3310badf08e583a872c2b0f3db..64e023070ee1adf3cbc4506de68a8107a6d9de75 100644 (file)
@@ -13,6 +13,15 @@ static int cl_activevideos;
 static clvideo_t videoarray[ MAXCLVIDEOS ];
 static rtexturepool_t *cl_videotexturepool;
 
+static clvideo_t *FindUnusedVid( void )
+{
+       int i;
+       for( i = 1 ; i < MAXCLVIDEOS ; i++ )
+               if( videoarray[ i ].state == CLVIDEO_UNUSED )
+                       return &videoarray[ i ];
+       return NULL;
+}
+
 static qboolean OpenStream( clvideo_t * video )
 {
        char *errorstring;
@@ -61,34 +70,12 @@ static qboolean WakeVideo( clvideo_t * video )
        return true;
 }
 
-clvideo_t* CL_OpenVideo( const char *filename, const char *name, int owner, qboolean cinematic )
+static clvideo_t* OpenVideo( clvideo_t *video, const char *filename, const char *name, int owner )
 {
-       int i;
-       clvideo_t *video;
-
-       if (cinematic)
-       {
-               video = videoarray;
-               i = 0;
-       }
-       else
-       {
-               for (i = 1, video = videoarray; i < cl_activevideos;i++, video++)
-                       if (videoarray[i].state == CLVIDEO_UNUSED)
-                               break;
-               if (i == MAXCLVIDEOS)
-               {
-                       Con_Printf( "unable to open video \"%s\" - video limit reached\n", filename );
-                       return NULL;
-               }
-       }
-
        strncpy( video->filename, filename, MAX_QPATH );
        video->ownertag = owner;
-
        if( strncmp( name, CLVIDEOPREFIX, sizeof( CLVIDEOPREFIX ) - 1 ) )
                return NULL;
-
        strncpy( video->cpif.name, name, MAX_QPATH );
 
        if( !OpenStream( video ) )
@@ -101,27 +88,33 @@ clvideo_t* CL_OpenVideo( const char *filename, const char *name, int owner, qboo
 
        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.width, video->cpif.height, NULL, TEXTYPE_RGBA, 0, NULL );
+       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->imagedata = Mem_Alloc( cl_mempool, video->cpif.width * video->cpif.height * cl_videobytesperpixel );
 
-       // expand the active range to include the new entry
-       cl_activevideos = max(cl_activevideos, i + 1);
        return video;
 }
 
-clvideo_t* CL_GetVideo( const char *name )
+clvideo_t* CL_OpenVideo( const char *filename, const char *name, int owner )
 {
-       int i;
        clvideo_t *video;
 
-       for( i = 0 ; i < cl_activevideos ; i++ )
-               if( videoarray[ i ].state != CLVIDEO_UNUSED
-                       &&      !strcmp( videoarray[ i ].cpif.name , name ) )
-                       break;
-       if( i == cl_activevideos )
+       video = FindUnusedVid();
+       if( !video ) {
+               Con_Printf( "unable to open video \"%s\" - video limit reached\n", filename );
                return NULL;
-       video = &videoarray[ i ];
+       }
+       video = OpenVideo( video, filename, name, owner );
+       // expand the active range to include the new entry
+       if (video)
+               cl_activevideos = max(cl_activevideos, (int)(video - videoarray) + 1);
+       return video;
+}
+
+static clvideo_t* CL_GetVideoBySlot( int slot )
+{
+       clvideo_t *video = &videoarray[ slot ];
 
        if( video->suspended )
        {
@@ -136,6 +129,20 @@ clvideo_t* CL_GetVideo( const char *name )
        return video;
 }
 
+clvideo_t *CL_GetVideoByName( const char *name )
+{
+       int i;
+
+       for( i = 0 ; i < cl_activevideos ; i++ )
+               if( videoarray[ i ].state != CLVIDEO_UNUSED
+                       &&      !strcmp( videoarray[ i ].cpif.name , name ) )
+                       break;
+       if( i != cl_activevideos )
+               return CL_GetVideoBySlot( i );
+       else
+               return NULL;
+}
+
 void CL_SetVideoState( clvideo_t *video, clvideostate_t state )
 {
        if( !video )
@@ -207,6 +214,9 @@ void CL_VideoFrame( void ) // update all videos
        int i;
        clvideo_t *video;
 
+       if (!cl_activevideos)
+               return;
+
        for( video = videoarray, i = 0 ; i < cl_activevideos ; video++, i++ )
                if( video->state != CLVIDEO_UNUSED && !video->suspended )
                {
@@ -246,7 +256,7 @@ int cl_videoplaying = false; // old, but still supported
 void CL_DrawVideo(void)
 {
        if (cl_videoplaying)
-               DrawQ_Pic(0, 0, videoarray->cpif.name, vid_conwidth.integer, vid_conheight.integer, 1, 1, 1, 1, 0);
+               DrawQ_Pic(0, 0, &CL_GetVideoBySlot( 0 )->cpif, vid_conwidth.integer, vid_conheight.integer, 1, 1, 1, 1, 0);
 }
 
 void CL_VideoStart(char *filename)
@@ -255,8 +265,10 @@ void CL_VideoStart(char *filename)
 
        if( videoarray->state != CLVIDEO_UNUSED )
                CL_CloseVideo( videoarray );
-       if( !CL_OpenVideo( filename, va( CLVIDEOPREFIX "%s", filename ), 0, true ) )
+       if( !OpenVideo( videoarray, filename, va( CLVIDEOPREFIX "%s", filename ), 0 ) )
                return;
+       // expand the active range to include the new entry
+       cl_activevideos = max(cl_activevideos, 1);
 
        cl_videoplaying = true;