]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - cl_video.c
cmd: Check for empty cbuf when inserting too
[xonotic/darkplaces.git] / cl_video.c
index 7dbc4d2825dd219718956c62facc0e1ff3488c5c..2804661b2b8c38c437ac6a51a779a27ee89b32e0 100644 (file)
@@ -3,24 +3,24 @@
 #include "cl_video.h"
 
 // cvars
-cvar_t cl_video_subtitles = {CVAR_SAVE, "cl_video_subtitles", "0", "show subtitles for videos (if they are present)"};
-cvar_t cl_video_subtitles_lines = {CVAR_SAVE, "cl_video_subtitles_lines", "4", "how many lines to occupy for subtitles"};
-cvar_t cl_video_subtitles_textsize = {CVAR_SAVE, "cl_video_subtitles_textsize", "16", "textsize for subtitles"};
-cvar_t cl_video_scale = {CVAR_SAVE, "cl_video_scale", "1", "scale of video, 1 = fullscreen, 0.75 - 3/4 of screen etc."};
-cvar_t cl_video_scale_vpos = {CVAR_SAVE, "cl_video_scale_vpos", "0", "vertical align of scaled video, -1 is top, 1 is bottom"};
-cvar_t cl_video_stipple = {CVAR_SAVE, "cl_video_stipple", "0", "draw interlacing-like effect on videos, similar to scr_stipple but static and used only with video playing."};
-cvar_t cl_video_brightness = {CVAR_SAVE, "cl_video_brightness", "1", "brightness of video, 1 = fullbright, 0.75 - 3/4 etc."};
-cvar_t cl_video_keepaspectratio = {CVAR_SAVE, "cl_video_keepaspectratio", "0", "keeps aspect ratio of fullscreen videos, leaving black color on unfilled areas, a value of 2 let video to be stretched horizontally with top & bottom being sliced out"};
-cvar_t cl_video_fadein = {CVAR_SAVE, "cl_video_fadein", "0", "fading-from-black effect once video is started, in seconds"};
-cvar_t cl_video_fadeout = {CVAR_SAVE, "cl_video_fadeout", "0", "fading-to-black effect once video is ended, in seconds"};
-
-cvar_t v_glslgamma_video = {CVAR_SAVE, "v_glslgamma_video", "1", "applies GLSL gamma to played video, could be a fraction, requires r_glslgamma_2d 1."};
+cvar_t cl_video_subtitles = {CF_CLIENT | CF_ARCHIVE, "cl_video_subtitles", "0", "show subtitles for videos (if they are present)"};
+cvar_t cl_video_subtitles_lines = {CF_CLIENT | CF_ARCHIVE, "cl_video_subtitles_lines", "4", "how many lines to occupy for subtitles"};
+cvar_t cl_video_subtitles_textsize = {CF_CLIENT | CF_ARCHIVE, "cl_video_subtitles_textsize", "16", "textsize for subtitles"};
+cvar_t cl_video_scale = {CF_CLIENT | CF_ARCHIVE, "cl_video_scale", "1", "scale of video, 1 = fullscreen, 0.75 - 3/4 of screen etc."};
+cvar_t cl_video_scale_vpos = {CF_CLIENT | CF_ARCHIVE, "cl_video_scale_vpos", "0", "vertical align of scaled video, -1 is top, 1 is bottom"};
+cvar_t cl_video_stipple = {CF_CLIENT | CF_ARCHIVE, "cl_video_stipple", "0", "draw interlacing-like effect on videos, similar to scr_stipple but static and used only with video playing."};
+cvar_t cl_video_brightness = {CF_CLIENT | CF_ARCHIVE, "cl_video_brightness", "1", "brightness of video, 1 = fullbright, 0.75 - 3/4 etc."};
+cvar_t cl_video_keepaspectratio = {CF_CLIENT | CF_ARCHIVE, "cl_video_keepaspectratio", "0", "keeps aspect ratio of fullscreen videos, leaving black color on unfilled areas, a value of 2 let video to be stretched horizontally with top & bottom being sliced out"};
+cvar_t cl_video_fadein = {CF_CLIENT | CF_ARCHIVE, "cl_video_fadein", "0", "fading-from-black effect once video is started, in seconds"};
+cvar_t cl_video_fadeout = {CF_CLIENT | CF_ARCHIVE, "cl_video_fadeout", "0", "fading-to-black effect once video is ended, in seconds"};
+
+cvar_t v_glslgamma_video = {CF_CLIENT | CF_ARCHIVE, "v_glslgamma_video", "1", "applies GLSL gamma to played video, could be a fraction, requires r_glslgamma_2d 1."};
 
 // DPV stream decoder
 #include "dpvsimpledecode.h"
 
 // VorteX: libavcodec implementation
-#include "cl_video_libavw.c"
+#include "cl_video_libavw.h"
 
 // JAM video decoder used by Blood Omnicide
 #ifdef JAMVIDEO
@@ -46,7 +46,7 @@ static clvideo_t *FindUnusedVid( void )
        return NULL;
 }
 
-static qboolean OpenStream( clvideo_t * video )
+static qbool OpenStream( clvideo_t * video )
 {
        const char *errorstring;
 
@@ -64,7 +64,7 @@ static qboolean OpenStream( clvideo_t * video )
        if (video->stream)
                return true;
 
-       Con_Printf("unable to open \"%s\", error: %s\n", video->filename, errorstring);
+       Con_Printf(CON_ERROR "unable to open \"%s\", error: %s\n", video->filename, errorstring);
        return false;
 }
 
@@ -104,7 +104,7 @@ static void SuspendVideo( clvideo_t * video )
        }
 }
 
-static qboolean WakeVideo( clvideo_t * video )
+static qbool WakeVideo( clvideo_t * video )
 {
        if( !video->suspended )
                return true;
@@ -120,7 +120,7 @@ static qboolean WakeVideo( clvideo_t * video )
        LinkVideoTexture( video );
 
        // update starttime
-       video->starttime += realtime - video->lasttime;
+       video->starttime += host.realtime - video->lasttime;
 
        return true;
 }
@@ -137,7 +137,7 @@ static void LoadSubtitles( clvideo_t *video, const char *subtitlesfile )
                char overridename[MAX_QPATH];
                cvar_t *langcvar;
 
-               langcvar = Cvar_FindVar("language");
+               langcvar = Cvar_FindVar(&cvars_all, "language", CF_CLIENT | CF_SERVER);
                subtitle_text = NULL;
                if (langcvar)
                {
@@ -178,7 +178,7 @@ static void LoadSubtitles( clvideo_t *video, const char *subtitlesfile )
                // check limits
                if (video->subtitles == CLVIDEO_MAX_SUBTITLES)
                {
-                       Con_Printf("WARNING: CLVIDEO_MAX_SUBTITLES = %i reached when reading subtitles from '%s'\n", CLVIDEO_MAX_SUBTITLES, subtitlesfile);
+                       Con_Printf(CON_WARN "WARNING: CLVIDEO_MAX_SUBTITLES = %i reached when reading subtitles from '%s'\n", CLVIDEO_MAX_SUBTITLES, subtitlesfile);
                        break;  
                }
                // add a sub
@@ -199,7 +199,7 @@ static void LoadSubtitles( clvideo_t *video, const char *subtitlesfile )
        if (numsubs > 0) // make true len for prev sub, autofix overlapping subtitles
        {
                if (video->subtitle_end[numsubs-1] <= 0)
-                       video->subtitle_end[numsubs-1] = 99999999; // fixme: make it end when video ends?
+                       video->subtitle_end[numsubs-1] = (float)99999999; // fixme: make it end when video ends?
                else
                        video->subtitle_end[numsubs-1] = video->subtitle_start[numsubs-1] + video->subtitle_end[numsubs-1];
        }
@@ -227,7 +227,7 @@ static clvideo_t* OpenVideo( clvideo_t *video, const char *filename, const char
        video->state = CLVIDEO_FIRSTFRAME;
        video->framenum = -1;
        video->framerate = video->getframerate( video->stream );
-       video->lasttime = realtime;
+       video->lasttime = host.realtime;
        video->subtitles = 0;
 
        video->width = video->getwidth( video->stream );
@@ -253,7 +253,7 @@ clvideo_t* CL_OpenVideo( const char *filename, const char *name, int owner, cons
 
        video = FindUnusedVid();
        if( !video ) {
-               Con_Printf( "CL_OpenVideo: unable to open video \"%s\" - video limit reached\n", filename );
+               Con_Printf(CON_ERROR "CL_OpenVideo: unable to open video \"%s\" - video limit reached\n", filename );
                return NULL;
        }
        video = OpenVideo( video, filename, name, owner, subtitlesfile );
@@ -276,7 +276,7 @@ static clvideo_t* CL_GetVideoBySlot( int slot )
                        video->framenum = -1;
        }
 
-       video->lasttime = realtime;
+       video->lasttime = host.realtime;
 
        return video;
 }
@@ -300,7 +300,7 @@ void CL_SetVideoState(clvideo_t *video, clvideostate_t state)
        if (!video)
                return;
 
-       video->lasttime = realtime;
+       video->lasttime = host.realtime;
        video->state = state;
        if (state == CLVIDEO_FIRSTFRAME)
                CL_RestartVideo(video);
@@ -312,7 +312,7 @@ void CL_RestartVideo(clvideo_t *video)
                return;
 
        // reset time
-       video->starttime = video->lasttime = realtime;
+       video->starttime = video->lasttime = host.realtime;
        video->framenum = -1;
 
        // reopen stream
@@ -364,21 +364,21 @@ void CL_Video_Frame(void)
        {
                if (video->state != CLVIDEO_UNUSED && !video->suspended)
                {
-                       if (realtime - video->lasttime > CLTHRESHOLD)
+                       if (host.realtime - video->lasttime > CLTHRESHOLD)
                        {
                                SuspendVideo(video);
                                continue;
                        }
                        if (video->state == CLVIDEO_PAUSE)
                        {
-                               video->starttime = realtime - video->framenum * video->framerate;
+                               video->starttime = host.realtime - video->framenum * video->framerate;
                                continue;
                        }
                        // read video frame from stream if time has come
                        if (video->state == CLVIDEO_FIRSTFRAME )
                                destframe = 0;
                        else
-                               destframe = (int)((realtime - video->starttime) * video->framerate);
+                               destframe = (int)((host.realtime - video->starttime) * video->framerate);
                        if (destframe < 0)
                                destframe = 0;
                        if (video->framenum < destframe)
@@ -444,7 +444,7 @@ static float CL_DrawVideo_WordWidthFunc(void *passthrough, const char *w, size_t
                return 0;
 }
 
-static int CL_DrawVideo_DisplaySubtitleLine(void *passthrough, const char *line, size_t length, float width, qboolean isContinuation)
+static int CL_DrawVideo_DisplaySubtitleLine(void *passthrough, const char *line, size_t length, float width, qbool isContinuation)
 {
        cl_video_subtitle_info_t *si = (cl_video_subtitle_info_t *) passthrough;
 
@@ -524,10 +524,10 @@ void CL_DrawVideo(void)
 
        // calc brightness for fadein and fadeout effects
        b = cl_video_brightness.value;
-       if (cl_video_fadein.value && (realtime - video->starttime) < cl_video_fadein.value)
-               b = pow((realtime - video->starttime)/cl_video_fadein.value, 2);
-       else if (cl_video_fadeout.value && ((video->starttime + video->framenum * video->framerate) - realtime) < cl_video_fadeout.value)
-               b = pow(((video->starttime + video->framenum * video->framerate) - realtime)/cl_video_fadeout.value, 2);
+       if (cl_video_fadein.value && (host.realtime - video->starttime) < cl_video_fadein.value)
+               b = pow((host.realtime - video->starttime)/cl_video_fadein.value, 2);
+       else if (cl_video_fadeout.value && ((video->starttime + video->framenum * video->framerate) - host.realtime) < cl_video_fadeout.value)
+               b = pow(((video->starttime + video->framenum * video->framerate) - host.realtime)/cl_video_fadeout.value, 2);
 
        // draw black bg in case stipple is active or video is scaled
        if (cl_video_stipple.integer || px != 0 || py != 0 || sx != vid_conwidth.integer || sy != vid_conheight.integer)
@@ -555,7 +555,7 @@ void CL_DrawVideo(void)
                return;
 
        // find current subtitle
-       videotime = realtime - video->starttime;
+       videotime = host.realtime - video->starttime;
        for (i = 0; i < video->subtitles; i++)
        {
                if (videotime >= video->subtitle_start[i] && videotime <= video->subtitle_end[i])
@@ -577,7 +577,7 @@ void CL_DrawVideo(void)
 
 void CL_VideoStart(char *filename, const char *subtitlesfile)
 {
-       Host_StartVideo();
+       CL_StartVideo();
 
        if( cl_videos->state != CLVIDEO_UNUSED )
                CL_CloseVideo( cl_videos );
@@ -593,7 +593,7 @@ void CL_VideoStart(char *filename, const char *subtitlesfile)
        CL_RestartVideo( cl_videos );
 }
 
-void CL_Video_KeyEvent( int key, int ascii, qboolean down ) 
+void CL_Video_KeyEvent( int key, int ascii, qbool down ) 
 {
        // only react to up events, to allow the user to delay the abortion point if it suddenly becomes interesting..
        if( !down ) {
@@ -615,9 +615,9 @@ static void CL_PlayVideo_f(cmd_state_t *cmd)
        char name[MAX_QPATH], subtitlesfile[MAX_QPATH];
        const char *extension;
 
-       Host_StartVideo();
+       CL_StartVideo();
 
-       if (COM_CheckParm("-benchmark"))
+       if (Sys_CheckParm("-benchmark"))
                return;
 
        if (Cmd_Argc(cmd) < 2)
@@ -689,8 +689,8 @@ void CL_Video_Init( void )
        bgra.i = 0;bgra.b[1] = 0xFF;cl_videogmask = bgra.i;
        bgra.i = 0;bgra.b[2] = 0xFF;cl_videormask = bgra.i;
 
-       Cmd_AddCommand(&cmd_client, "playvideo", CL_PlayVideo_f, "play a .dpv video file" );
-       Cmd_AddCommand(&cmd_client, "stopvideo", CL_StopVideo_f, "stop playing a .dpv video file" );
+       Cmd_AddCommand(CF_CLIENT, "playvideo", CL_PlayVideo_f, "play a .dpv video file" );
+       Cmd_AddCommand(CF_CLIENT, "stopvideo", CL_StopVideo_f, "stop playing a .dpv video file" );
 
        Cvar_RegisterVariable(&cl_video_subtitles);
        Cvar_RegisterVariable(&cl_video_subtitles_lines);