use less R_Mesh_ResetTextureState calls for more performance
[divverent/darkplaces.git] / cl_video.c
1
2 #include "quakedef.h"
3 #include "cl_dyntexture.h"
4 #include "cl_video.h"
5 #include "dpvsimpledecode.h"
6
7 // cvars
8 cvar_t cl_video_subtitles = {CVAR_SAVE, "cl_video_subtitles", "0", "show subtitles for videos (if they are presented)"};
9 cvar_t cl_video_subtitles_lines = {CVAR_SAVE, "cl_video_subtitles_lines", "4", "how many lines to occupy for subtitles"};
10 cvar_t cl_video_subtitles_textsize = {CVAR_SAVE, "cl_video_subtitles_textsize", "16", "textsize for subtitles"};
11 cvar_t cl_video_scale = {CVAR_SAVE, "cl_video_scale", "1", "scale of video, 1 = fullscreen, 0.75 - 3/4 of screen etc."};
12 cvar_t cl_video_scale_vpos = {CVAR_SAVE, "cl_video_scale_vpos", "0", "vertial align of scaled video, -1 is top, 1 is bottom"};
13 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."};
14 cvar_t cl_video_brightness = {CVAR_SAVE, "cl_video_brightness", "1", "brightness of video, 1 = fullbright, 0.75 - 3/4 etc."};
15 cvar_t cl_video_keepaspectratio = {CVAR_SAVE, "cl_video_keepaspectratio", "0", "keeps aspect ratio of fullscreen videos, leaving black color on unfilled areas"};
16
17 // constants (and semi-constants)
18 static int  cl_videormask;
19 static int  cl_videobmask;
20 static int  cl_videogmask;
21 static int      cl_videobytesperpixel;
22
23 static int cl_num_videos;
24 static clvideo_t cl_videos[ MAXCLVIDEOS ];
25 static rtexturepool_t *cl_videotexturepool;
26
27 static clvideo_t *FindUnusedVid( void )
28 {
29         int i;
30         for( i = 1 ; i < MAXCLVIDEOS ; i++ )
31                 if( cl_videos[ i ].state == CLVIDEO_UNUSED )
32                         return &cl_videos[ i ];
33         return NULL;
34 }
35
36 static qboolean OpenStream( clvideo_t * video )
37 {
38         const char *errorstring;
39         video->stream = dpvsimpledecode_open( video->filename, &errorstring);
40         if (!video->stream )
41         {
42                 Con_Printf("unable to open \"%s\", error: %s\n", video->filename, errorstring);
43                 return false;
44         }
45         return true;
46 }
47
48 static void VideoUpdateCallback(rtexture_t *rt, void *data) {
49         clvideo_t *video = (clvideo_t *) data;
50         R_UpdateTexture( video->cpif.tex, (unsigned char *)video->imagedata, 0, 0, video->cpif.width, video->cpif.height );
51 }
52
53 static void LinkVideoTexture( clvideo_t *video )
54 {
55         video->cpif.tex = R_LoadTexture2D( cl_videotexturepool, video->cpif.name,
56                 video->cpif.width, video->cpif.height, NULL, TEXTYPE_BGRA, TEXF_PERSISTENT | TEXF_CLAMP, -1, NULL );
57         R_MakeTextureDynamic( video->cpif.tex, VideoUpdateCallback, video );
58         CL_LinkDynTexture( video->cpif.name, video->cpif.tex );
59 }
60
61 static void UnlinkVideoTexture( clvideo_t *video ) {
62         CL_UnlinkDynTexture( video->cpif.name );
63         // free the texture
64         R_FreeTexture( video->cpif.tex );
65         video->cpif.tex = NULL;
66         // free the image data
67         Mem_Free( video->imagedata );
68 }
69
70 static void SuspendVideo( clvideo_t * video )
71 {
72         if( video->suspended )
73                 return;
74         video->suspended = true;
75         UnlinkVideoTexture( video );
76         // if we are in firstframe mode, also close the stream
77         if( video->state == CLVIDEO_FIRSTFRAME )
78                 dpvsimpledecode_close( video->stream );
79 }
80
81 static qboolean WakeVideo( clvideo_t * video )
82 {
83         if( !video->suspended )
84                 return true;
85         video->suspended = false;
86
87         if( video->state == CLVIDEO_FIRSTFRAME )
88                 if( !OpenStream( video ) ) {
89                         video->state = CLVIDEO_UNUSED;
90                         return false;
91                 }
92
93         video->imagedata = Mem_Alloc( cls.permanentmempool, video->cpif.width * video->cpif.height * cl_videobytesperpixel );
94         LinkVideoTexture( video );
95
96         // update starttime
97         video->starttime += realtime - video->lasttime;
98
99         return true;
100 }
101
102 static void LoadSubtitles( clvideo_t *video, const char *subtitlesfile )
103 {
104         char *subtitle_text;
105         const char *data;
106         float subtime, sublen;
107         int numsubs = 0;
108
109         if (gamemode == GAME_BLOODOMNICIDE)
110         {
111                 char overridename[MAX_QPATH];
112                 cvar_t *langcvar;
113
114                 langcvar = Cvar_FindVar("language");
115                 subtitle_text = NULL;
116                 if (langcvar)
117                 {
118                         dpsnprintf(overridename, sizeof(overridename), "script/locale/%s/%s", langcvar->string, subtitlesfile);
119                         subtitle_text = (char *)FS_LoadFile(overridename, cls.permanentmempool, false, NULL);
120                 }
121                 if (!subtitle_text)
122                         subtitle_text = (char *)FS_LoadFile(subtitlesfile, cls.permanentmempool, false, NULL);
123         }
124         else
125         {
126                 subtitle_text = (char *)FS_LoadFile(subtitlesfile, cls.permanentmempool, false, NULL);
127         }
128         if (!subtitle_text)
129         {
130                 Con_DPrintf( "LoadSubtitles: can't open subtitle file '%s'!\n", subtitlesfile );
131                 return;
132         }
133
134         // parse subtitle_text
135         // line is: x y "text" where
136         //    x - start time
137         //    y - seconds last (if 0 - last thru next sub, if negative - last to next sub - this amount of seconds)
138
139         data = subtitle_text;
140         for (;;)
141         {
142                 if (!COM_ParseToken_QuakeC(&data, false))
143                         break;
144                 subtime = atof( com_token );
145                 if (!COM_ParseToken_QuakeC(&data, false))
146                         break;
147                 sublen = atof( com_token );
148                 if (!COM_ParseToken_QuakeC(&data, false))
149                         break;
150                 if (!com_token[0])
151                         continue;
152                 // check limits
153                 if (video->subtitles == CLVIDEO_MAX_SUBTITLES)
154                 {
155                         Con_Printf("WARNING: CLVIDEO_MAX_SUBTITLES = %i reached when reading subtitles from '%s'\n", CLVIDEO_MAX_SUBTITLES, subtitlesfile);
156                         break;  
157                 }
158                 // add a sub
159                 video->subtitle_text[numsubs] = (char *) Mem_Alloc(cls.permanentmempool, strlen(com_token) + 1);
160                 memcpy(video->subtitle_text[numsubs], com_token, strlen(com_token) + 1);
161                 video->subtitle_start[numsubs] = subtime;
162                 video->subtitle_end[numsubs] = sublen;
163                 if (numsubs > 0) // make true len for prev sub, autofix overlapping subtitles
164                 {
165                         if (video->subtitle_end[numsubs-1] <= 0)
166                                 video->subtitle_end[numsubs-1] = max(video->subtitle_start[numsubs-1], video->subtitle_start[numsubs] + video->subtitle_end[numsubs-1]);
167                         else
168                                 video->subtitle_end[numsubs-1] = min(video->subtitle_start[numsubs-1] + video->subtitle_end[numsubs-1], video->subtitle_start[numsubs]);
169                 }
170                 numsubs++;
171                 // todo: check timing for consistency?
172         }
173         if (numsubs > 0) // make true len for prev sub, autofix overlapping subtitles
174         {
175                 if (video->subtitle_end[numsubs-1] <= 0)
176                         video->subtitle_end[numsubs-1] = 99999999; // fixme: make it end when video ends?
177                 else
178                         video->subtitle_end[numsubs-1] = video->subtitle_start[numsubs-1] + video->subtitle_end[numsubs-1];
179         }
180         Z_Free( subtitle_text );
181         video->subtitles = numsubs;
182 /*
183         Con_Printf( "video->subtitles: %i\n", video->subtitles );
184         for (numsubs = 0; numsubs < video->subtitles; numsubs++)
185                 Con_Printf( "  %03.2f %03.2f : %s\n", video->subtitle_start[numsubs], video->subtitle_end[numsubs], video->subtitle_text[numsubs] );
186 */
187 }
188
189 static clvideo_t* OpenVideo( clvideo_t *video, const char *filename, const char *name, int owner, const char *subtitlesfile )
190 {
191         strlcpy( video->filename, filename, sizeof(video->filename) );
192         video->ownertag = owner;
193         if( strncmp( name, CLVIDEOPREFIX, sizeof( CLVIDEOPREFIX ) - 1 ) )
194                 return NULL;
195         strlcpy( video->cpif.name, name, sizeof(video->cpif.name) );
196
197         if( !OpenStream( video ) )
198                 return NULL;
199
200         video->state = CLVIDEO_FIRSTFRAME;
201         video->framenum = -1;
202         video->framerate = dpvsimpledecode_getframerate( video->stream );
203         video->lasttime = realtime;
204         video->subtitles = 0;
205
206         video->cpif.width = dpvsimpledecode_getwidth( video->stream );
207         video->cpif.height = dpvsimpledecode_getheight( video->stream );
208         video->imagedata = Mem_Alloc( cls.permanentmempool, video->cpif.width * video->cpif.height * cl_videobytesperpixel );
209         LinkVideoTexture( video );
210
211         // VorteX: load simple subtitle_text file
212         if (subtitlesfile[0])
213                 LoadSubtitles( video, subtitlesfile );
214
215         return video;
216 }
217
218 clvideo_t* CL_OpenVideo( const char *filename, const char *name, int owner, const char *subtitlesfile )
219 {
220         clvideo_t *video;
221         // sanity check
222         if( !name || !*name || strncmp( name, CLVIDEOPREFIX, sizeof( CLVIDEOPREFIX ) - 1 ) != 0 ) {
223                 Con_DPrintf( "CL_OpenVideo: Bad video texture name '%s'!\n", name );
224                 return NULL;
225         }
226
227         video = FindUnusedVid();
228         if( !video ) {
229                 Con_Printf( "CL_OpenVideo: unable to open video \"%s\" - video limit reached\n", filename );
230                 return NULL;
231         }
232         video = OpenVideo( video, filename, name, owner, subtitlesfile );
233         // expand the active range to include the new entry
234         if (video) {
235                 cl_num_videos = max(cl_num_videos, (int)(video - cl_videos) + 1);
236         }
237         return video;
238 }
239
240 static clvideo_t* CL_GetVideoBySlot( int slot )
241 {
242         clvideo_t *video = &cl_videos[ slot ];
243
244         if( video->suspended )
245         {
246                 if( !WakeVideo( video ) )
247                         return NULL;
248                 else if( video->state == CLVIDEO_RESETONWAKEUP )
249                         video->framenum = -1;
250         }
251
252         video->lasttime = realtime;
253
254         return video;
255 }
256
257 clvideo_t *CL_GetVideoByName( const char *name )
258 {
259         int i;
260
261         for( i = 0 ; i < cl_num_videos ; i++ )
262                 if( cl_videos[ i ].state != CLVIDEO_UNUSED
263                         &&      !strcmp( cl_videos[ i ].cpif.name , name ) )
264                         break;
265         if( i != cl_num_videos )
266                 return CL_GetVideoBySlot( i );
267         else
268                 return NULL;
269 }
270
271 void CL_SetVideoState( clvideo_t *video, clvideostate_t state )
272 {
273         if( !video )
274                 return;
275
276         video->lasttime = realtime;
277         video->state = state;
278         if( state == CLVIDEO_FIRSTFRAME )
279                 CL_RestartVideo( video );
280 }
281
282 void CL_RestartVideo( clvideo_t *video )
283 {
284         if( !video )
285                 return;
286
287         video->starttime = video->lasttime = realtime;
288         video->framenum = -1;
289
290         dpvsimpledecode_close( video->stream );
291         if( !OpenStream( video ) )
292                 video->state = CLVIDEO_UNUSED;
293 }
294
295 void CL_CloseVideo( clvideo_t * video )
296 {
297         int i;
298
299         if( !video || video->state == CLVIDEO_UNUSED )
300                 return;
301
302         if( !video->suspended || video->state != CLVIDEO_FIRSTFRAME )
303                 dpvsimpledecode_close( video->stream );
304         if( !video->suspended )
305                 UnlinkVideoTexture( video );
306         if (video->subtitles)
307         {
308                 for (i = 0; i < video->subtitles; i++)
309                         Z_Free( video->subtitle_text[i] );
310                 video->subtitles = 0;
311         }
312
313         video->state = CLVIDEO_UNUSED;
314 }
315
316 static void VideoFrame( clvideo_t *video )
317 {
318         int destframe;
319
320         if( video->state == CLVIDEO_FIRSTFRAME )
321                 destframe = 0;
322         else
323                 destframe = (int)((realtime - video->starttime) * video->framerate);
324         if( destframe < 0 )
325                 destframe = 0;
326         if( video->framenum < destframe ) {
327                 do {
328                         video->framenum++;
329                         if( dpvsimpledecode_video( video->stream, video->imagedata, cl_videormask,
330                                 cl_videogmask, cl_videobmask, cl_videobytesperpixel,
331                                 cl_videobytesperpixel * video->cpif.width )
332                                 ) { // finished?
333                                 CL_RestartVideo( video );
334                                 if( video->state == CLVIDEO_PLAY )
335                                                 video->state = CLVIDEO_FIRSTFRAME;
336                                 return;
337                         }
338                 } while( video->framenum < destframe );
339                 R_MarkDirtyTexture( video->cpif.tex );
340         }
341 }
342
343 void CL_Video_Frame( void ) // update all videos
344 {
345         int i;
346         clvideo_t *video;
347
348         if (!cl_num_videos)
349                 return;
350
351         for( video = cl_videos, i = 0 ; i < cl_num_videos ; video++, i++ )
352                 if( video->state != CLVIDEO_UNUSED && !video->suspended )
353                 {
354                         if( realtime - video->lasttime > CLTHRESHOLD )
355                                 SuspendVideo( video );
356                         else if( video->state == CLVIDEO_PAUSE )
357                                 video->starttime = realtime - video->framenum * video->framerate;
358                         else
359                                 VideoFrame( video );
360                 }
361
362         if( cl_videos->state == CLVIDEO_FIRSTFRAME )
363                 CL_VideoStop();
364
365         // reduce range to exclude unnecessary entries
366         while (cl_num_videos > 0 && cl_videos[cl_num_videos-1].state == CLVIDEO_UNUSED)
367                 cl_num_videos--;
368 }
369
370 void CL_Video_Shutdown( void )
371 {
372         int i;
373         for( i = 0 ; i < cl_num_videos ; i++ )
374                 CL_CloseVideo( &cl_videos[ i ] );
375 }
376
377 void CL_PurgeOwner( int owner )
378 {
379         int i;
380         for( i = 0 ; i < cl_num_videos ; i++ )
381                 if( cl_videos[ i ].ownertag == owner )
382                         CL_CloseVideo( &cl_videos[ i ] );
383 }
384
385 typedef struct
386 {
387         dp_font_t *font;
388         float x;
389         float y;
390         float width;
391         float height;
392         float alignment; // 0 = left, 0.5 = center, 1 = right
393         float fontsize;
394         float textalpha;
395 }
396 cl_video_subtitle_info_t;
397
398 float CL_DrawVideo_WordWidthFunc(void *passthrough, const char *w, size_t *length, float maxWidth)
399 {
400         cl_video_subtitle_info_t *si = (cl_video_subtitle_info_t *) passthrough;
401
402         if(w == NULL)
403                 return si->fontsize * si->font->maxwidth;
404         if(maxWidth >= 0)
405                 return DrawQ_TextWidth_UntilWidth(w, length, si->fontsize, si->fontsize, false, si->font, -maxWidth); // -maxWidth: we want at least one char
406         else if(maxWidth == -1)
407                 return DrawQ_TextWidth(w, *length, si->fontsize, si->fontsize, false, si->font);
408         else
409                 return 0;
410 }
411
412 int CL_DrawVideo_DisplaySubtitleLine(void *passthrough, const char *line, size_t length, float width, qboolean isContinuation)
413 {
414         cl_video_subtitle_info_t *si = (cl_video_subtitle_info_t *) passthrough;
415
416         int x = (int) (si->x + (si->width - width) * si->alignment);
417         if (length > 0)
418                 DrawQ_String(x, si->y, line, length, si->fontsize, si->fontsize, 1.0, 1.0, 1.0, si->textalpha, 0, NULL, false, si->font);
419         si->y += si->fontsize;
420         return 1;
421 }
422
423 int cl_videoplaying = false; // old, but still supported
424
425 void CL_DrawVideo(void)
426 {
427         clvideo_t *video;
428         float videotime, px, py, sx, sy;
429         cl_video_subtitle_info_t si;
430         int i;
431
432         if (!cl_videoplaying)
433                 return;
434
435         video = CL_GetVideoBySlot( 0 );
436
437         // fix cvars
438         if (cl_video_scale.value <= 0 || cl_video_scale.value > 1)
439                 Cvar_SetValueQuick( &cl_video_scale, 1);
440         if (cl_video_brightness.value <= 0 || cl_video_brightness.value > 10)
441                 Cvar_SetValueQuick( &cl_video_brightness, 1);
442
443         // calc video proportions
444         px = 0;
445         py = 0;
446         sx = vid_conwidth.integer;
447         sy = vid_conheight.integer;
448         if (cl_video_keepaspectratio.integer)
449         {
450                 float a = ((float)video->cpif.width / (float)video->cpif.height) / ((float)vid.width / (float)vid.height);
451                 if (a < 1.0) // scale horizontally
452                 {
453                         px += sx * (1 - a) * 0.5;
454                         sx *= a;
455                 }
456                 else if (a > 1.0) // scale vertically
457                 {
458                         a = 1 / a;
459                         py += sy * (1 - a);
460                         sy *= a;
461                 }
462         }
463         if (cl_video_scale.value != 1)
464         {
465                 px += sx * (1 - cl_video_scale.value) * 0.5;
466                 py += sy * (1 - cl_video_scale.value) * ((bound(-1, cl_video_scale_vpos.value, 1) + 1) / 2);
467                 sx *= cl_video_scale.value;
468                 sy *= cl_video_scale.value;
469         }
470
471         // draw black bg in case stipple is active or video is scaled
472         if (cl_video_stipple.integer || px != 0 || py != 0 || sx != vid_conwidth.integer || sy != vid_conheight.integer)
473                 DrawQ_Fill(0, 0, vid_conwidth.integer, vid_conheight.integer, 0, 0, 0, 1, 0);
474
475         // enable video-only polygon stipple (of global stipple is not active)
476         if (qglPolygonStipple && !scr_stipple.integer && cl_video_stipple.integer)
477         {
478                 GLubyte stipple[128];
479                 int i, s, width, parts;
480         
481                 s = cl_video_stipple.integer;
482                 parts = (s & 007);
483                 width = (s & 070) >> 3;
484                 qglEnable(GL_POLYGON_STIPPLE);CHECKGLERROR // 0x0B42
485                 for(i = 0; i < 128; ++i)
486                 {
487                         int line = i/4;
488                         stipple[i] = ((line >> width) & ((1 << parts) - 1)) ? 0x00 : 0xFF;
489                 }
490                 qglPolygonStipple(stipple);CHECKGLERROR
491         }
492
493         // draw video
494         DrawQ_Pic(px, py, &video->cpif, sx, sy, cl_video_brightness.value, cl_video_brightness.value, cl_video_brightness.value, 1, 0);
495
496         // disable video-only stipple
497         if (qglPolygonStipple && !scr_stipple.integer && cl_video_stipple.integer)
498                 qglDisable(GL_POLYGON_STIPPLE);CHECKGLERROR
499
500         // VorteX: draw subtitle_text
501         if (!video->subtitles || !cl_video_subtitles.integer)
502                 return;
503
504         // find current subtitle
505         videotime = realtime - video->starttime;
506         for (i = 0; i < video->subtitles; i++)
507         {
508                 if (videotime >= video->subtitle_start[i] && videotime <= video->subtitle_end[i])
509                 {
510                         // found, draw it
511                         si.font = FONT_NOTIFY;
512                         si.x = vid_conwidth.integer * 0.1;
513                         si.y = vid_conheight.integer - (max(1, cl_video_subtitles_lines.value) * cl_video_subtitles_textsize.value);
514                         si.width = vid_conwidth.integer * 0.8;
515                         si.height = max(1, cl_video_subtitles_lines.integer) * cl_video_subtitles_textsize.value;
516                         si.alignment = 0.5;
517                         si.fontsize = cl_video_subtitles_textsize.value;
518                         si.textalpha = min(1, (videotime - video->subtitle_start[i])/0.5) * min(1, ((video->subtitle_end[i] - videotime)/0.3)); // fade in and fade out
519                         COM_Wordwrap(video->subtitle_text[i], strlen(video->subtitle_text[i]), 0, si.width, CL_DrawVideo_WordWidthFunc, &si, CL_DrawVideo_DisplaySubtitleLine, &si);
520                         break;
521                 }
522         }
523 }
524
525 void CL_VideoStart(char *filename, const char *subtitlesfile)
526 {
527         Host_StartVideo();
528
529         if( cl_videos->state != CLVIDEO_UNUSED )
530                 CL_CloseVideo( cl_videos );
531         // already contains video/
532         if( !OpenVideo( cl_videos, filename, va( CLDYNTEXTUREPREFIX "%s", filename ), 0, subtitlesfile ) )
533                 return;
534         // expand the active range to include the new entry
535         cl_num_videos = max(cl_num_videos, 1);
536
537         cl_videoplaying = true;
538
539         CL_SetVideoState( cl_videos, CLVIDEO_PLAY );
540         CL_RestartVideo( cl_videos );
541 }
542
543 void CL_Video_KeyEvent( int key, int ascii, qboolean down ) 
544 {
545         // only react to up events, to allow the user to delay the abortion point if it suddenly becomes interesting..
546         if( !down ) {
547                 if( key == K_ESCAPE || key == K_ENTER || key == K_SPACE ) {
548                         CL_VideoStop();
549                 }
550         }
551 }
552
553 void CL_VideoStop(void)
554 {
555         cl_videoplaying = false;
556
557         CL_CloseVideo( cl_videos );
558 }
559
560 static void CL_PlayVideo_f(void)
561 {
562         char name[MAX_QPATH], subtitlesfile[MAX_QPATH];
563
564         Host_StartVideo();
565
566         if (Cmd_Argc() < 2)
567         {
568                 Con_Print("usage: playvideo <videoname> [custom_subtitles_file]\nplays video named video/<videoname>.dpv\nif custom subtitles file is not presented\nit tries video/<videoname>.sub");
569                 return;
570         }
571
572         dpsnprintf(name, sizeof(name), "video/%s.dpv", Cmd_Argv(1));
573         if ( Cmd_Argc() > 2)
574                 CL_VideoStart(name, Cmd_Argv(2));
575         else
576         {
577                 dpsnprintf(subtitlesfile, sizeof(subtitlesfile), "video/%s.dpsubs", Cmd_Argv(1));
578                 CL_VideoStart(name, subtitlesfile);
579         }
580 }
581
582 static void CL_StopVideo_f(void)
583 {
584         CL_VideoStop();
585 }
586
587 static void cl_video_start( void )
588 {
589         int i;
590         clvideo_t *video;
591
592         cl_videotexturepool = R_AllocTexturePool();
593
594         for( video = cl_videos, i = 0 ; i < cl_num_videos ; i++, video++ )
595                 if( video->state != CLVIDEO_UNUSED && !video->suspended )
596                         LinkVideoTexture( video );
597 }
598
599 static void cl_video_shutdown( void )
600 {
601         int i;
602         clvideo_t *video;
603
604         for( video = cl_videos, i = 0 ; i < cl_num_videos ; i++, video++ )
605                 if( video->state != CLVIDEO_UNUSED && !video->suspended )
606                         SuspendVideo( video );
607         R_FreeTexturePool( &cl_videotexturepool );
608 }
609
610 static void cl_video_newmap( void )
611 {
612 }
613
614 void CL_Video_Init( void )
615 {
616         union
617         {
618                 unsigned char b[4];
619                 unsigned int i;
620         }
621         bgra;
622
623         cl_num_videos = 0;
624         cl_videobytesperpixel = 4;
625
626         // set masks in an endian-independent way (as they really represent bytes)
627         bgra.i = 0;bgra.b[0] = 0xFF;cl_videobmask = bgra.i;
628         bgra.i = 0;bgra.b[1] = 0xFF;cl_videogmask = bgra.i;
629         bgra.i = 0;bgra.b[2] = 0xFF;cl_videormask = bgra.i;
630
631         Cmd_AddCommand( "playvideo", CL_PlayVideo_f, "play a .dpv video file" );
632         Cmd_AddCommand( "stopvideo", CL_StopVideo_f, "stop playing a .dpv video file" );
633
634         Cvar_RegisterVariable(&cl_video_subtitles);
635         Cvar_RegisterVariable(&cl_video_subtitles_lines);
636         Cvar_RegisterVariable(&cl_video_subtitles_textsize);
637         Cvar_RegisterVariable(&cl_video_scale);
638         Cvar_RegisterVariable(&cl_video_scale_vpos);
639         Cvar_RegisterVariable(&cl_video_brightness);
640         Cvar_RegisterVariable(&cl_video_stipple);
641         Cvar_RegisterVariable(&cl_video_keepaspectratio);
642
643         R_RegisterModule( "CL_Video", cl_video_start, cl_video_shutdown, cl_video_newmap, NULL, NULL );
644 }