]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - cl_video.c
fix incredibly stupid bug in Memory_Init, it was clearing the pool chain AFTER alloca...
[xonotic/darkplaces.git] / cl_video.c
index 692dc9410425ae467e22e9af84a511aa77e8be44..64e023070ee1adf3cbc4506de68a8107a6d9de75 100644 (file)
@@ -9,6 +9,7 @@ static int  cl_videobmask;
 static int  cl_videogmask;
 static int     cl_videobytesperpixel;
 
+static int cl_activevideos;
 static clvideo_t videoarray[ MAXCLVIDEOS ];
 static rtexturepool_t *cl_videotexturepool;
 
@@ -104,21 +105,16 @@ clvideo_t* CL_OpenVideo( const char *filename, const char *name, int owner )
                Con_Printf( "unable to open video \"%s\" - video limit reached\n", filename );
                return NULL;
        }
-       return OpenVideo( video, filename, name, owner );
+       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;
 }
 
-clvideo_t* CL_GetVideo( const char *name )
+static clvideo_t* CL_GetVideoBySlot( int slot )
 {
-       int i;
-       clvideo_t *video;
-
-       for( i = 0 ; i < MAXCLVIDEOS ; i++ )
-               if( videoarray[ i ].state != CLVIDEO_UNUSED
-                       &&      !strcmp( videoarray[ i ].cpif.name , name ) )
-                       break;
-       if( i == MAXCLVIDEOS )
-               return NULL;
-       video = &videoarray[ i ];
+       clvideo_t *video = &videoarray[ slot ];
 
        if( video->suspended )
        {
@@ -133,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 )
@@ -195,7 +205,7 @@ static void VideoFrame( clvideo_t *video )
                                return;
                        }
                } while( video->framenum < destframe );
-               R_UpdateTexture( video->cpif.tex, video->imagedata );
+               R_UpdateTexture( video->cpif.tex, (unsigned char *)video->imagedata );
        }
 }
 
@@ -204,7 +214,10 @@ void CL_VideoFrame( void ) // update all videos
        int i;
        clvideo_t *video;
 
-       for( video = videoarray, i = 0 ; i < MAXCLVIDEOS ; video++, i++ )
+       if (!cl_activevideos)
+               return;
+
+       for( video = videoarray, i = 0 ; i < cl_activevideos ; video++, i++ )
                if( video->state != CLVIDEO_UNUSED && !video->suspended )
                {
                        if( realtime - video->lasttime > CLTHRESHOLD )
@@ -217,19 +230,23 @@ void CL_VideoFrame( void ) // update all videos
 
        if( videoarray->state == CLVIDEO_FIRSTFRAME )
                CL_VideoStop();
+
+       // reduce range to exclude unnecessary entries
+       while (cl_activevideos > 0 && videoarray[cl_activevideos-1].state == CLVIDEO_UNUSED)
+               cl_activevideos--;
 }
 
 void CL_Video_Shutdown( void )
 {
        int i;
-       for( i = 0 ; i < MAXCLVIDEOS ; i++ )
+       for( i = 0 ; i < cl_activevideos ; i++ )
                CL_CloseVideo( &videoarray[ i ] );
 }
 
 void CL_PurgeOwner( int owner )
 {
        int i;
-       for( i = 0 ; i < MAXCLVIDEOS ; i++ )
+       for( i = 0 ; i < cl_activevideos ; i++ )
                if( videoarray[ i ].ownertag == owner )
                        CL_CloseVideo( &videoarray[ i ] );
 }
@@ -239,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)
@@ -250,6 +267,8 @@ void CL_VideoStart(char *filename)
                CL_CloseVideo( videoarray );
        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;
 
@@ -266,7 +285,7 @@ void CL_VideoStop(void)
 
 static void CL_PlayVideo_f(void)
 {
-       char name[1024];
+       char name[MAX_QPATH];
 
        Host_StartVideo();
 
@@ -292,7 +311,7 @@ static void cl_video_start( void )
 
        cl_videotexturepool = R_AllocTexturePool();
 
-       for( video = videoarray, i = 0 ; i < MAXCLVIDEOS ; i++, video++ )
+       for( video = videoarray, i = 0 ; i < cl_activevideos ; 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 );
@@ -309,13 +328,14 @@ static void cl_video_newmap( void )
 
 void CL_Video_Init( void )
 {
+       cl_activevideos = 0;
        cl_videobytesperpixel = 4;
        cl_videormask = BigLong(0xFF000000);
        cl_videogmask = BigLong(0x00FF0000);
        cl_videobmask = BigLong(0x0000FF00);
 
-       Cmd_AddCommand( "playvideo", CL_PlayVideo_f );
-       Cmd_AddCommand( "stopvideo", CL_StopVideo_f );
+       Cmd_AddCommand( "playvideo", CL_PlayVideo_f, "play a .dpv video file" );
+       Cmd_AddCommand( "stopvideo", CL_StopVideo_f, "stop playing a .dpv video file" );
 
        R_RegisterModule( "CL_Video", cl_video_start, cl_video_shutdown, cl_video_newmap );
 }