This repository has been archived on 2022-06-27. You can view files and clone it, but cannot push or open issues or pull requests.
Xash3DArchive/engine/client/cl_video.c

270 lines
5.2 KiB
C
Raw Normal View History

2009-11-23 22:00:00 +01:00
//=======================================================================
// Copyright XashXT Group 2009 <20>
// cl_video.c - roq video player
//=======================================================================
#include "common.h"
#include "client.h"
2010-09-30 22:00:00 +02:00
#include <vfw.h> // video for windows
2009-11-23 22:00:00 +01:00
/*
=================================================================
2010-09-30 22:00:00 +02:00
AVI PLAYING
2009-11-23 22:00:00 +01:00
=================================================================
*/
2010-09-30 22:00:00 +02:00
cvar_t *vid_gamma;
static long xres, yres;
static float video_duration;
static float cin_time;
static int cin_frame;
static char *cin_data; // dynamically allocated array
static wavdata_t cin_audio;
static movie_state_t *cin_state;
void SCR_RebuildGammaTable( void )
{
float g;
int i;
g = bound( 0.5f, vid_gamma->value, 2.3f );
// screenshots gamma
for( i = 0; i < 256; i++ )
{
if( g == 1 ) clgame.ds.gammaTable[i] = i;
else clgame.ds.gammaTable[i] = bound( 0, pow( i * ( 1.0f / 255.0f ), g ) * 255.0f, 255 );
}
}
2009-11-23 22:00:00 +01:00
/*
==================
2010-09-30 22:00:00 +02:00
SCR_NextMovie
Called when a demo or cinematic finishes
If the "nextmovie" cvar is set, that command will be issued
2009-11-23 22:00:00 +01:00
==================
*/
2010-09-30 22:00:00 +02:00
bool SCR_NextMovie( void )
2009-11-23 22:00:00 +01:00
{
2010-09-30 22:00:00 +02:00
string str;
2009-11-23 22:00:00 +01:00
2010-09-30 22:00:00 +02:00
S_StopAllSounds();
SCR_StopCinematic();
2009-11-23 22:00:00 +01:00
2010-09-30 22:00:00 +02:00
if( cls.movienum == -1 )
return false; // don't play movies
2009-11-23 22:00:00 +01:00
2010-09-30 22:00:00 +02:00
if( !cls.movies[cls.movienum][0] || cls.movienum == MAX_MOVIES )
2009-11-23 22:00:00 +01:00
{
2010-09-30 22:00:00 +02:00
cls.movienum = -1;
return false;
2009-11-23 22:00:00 +01:00
}
2010-09-30 22:00:00 +02:00
com.snprintf( str, MAX_STRING, "movie %s\n", cls.movies[cls.movienum] );
2009-11-23 22:00:00 +01:00
2010-09-30 22:00:00 +02:00
Cbuf_InsertText( str );
cls.movienum++;
2009-11-23 22:00:00 +01:00
2010-09-30 22:00:00 +02:00
return true;
2009-11-23 22:00:00 +01:00
}
/*
==================
2010-09-30 22:00:00 +02:00
SCR_StartMovies_f
2009-11-23 22:00:00 +01:00
==================
*/
2010-09-30 22:00:00 +02:00
void SCR_StartMovies_f( void )
2009-11-23 22:00:00 +01:00
{
2010-09-30 22:00:00 +02:00
int i, c;
if( host.developer >= 2 )
{
// don't run movies where we in developer-mode
cls.movienum = -1;
return;
}
c = Cmd_Argc() - 1;
if( c > MAX_MOVIES )
{
MsgDev( D_WARN, "Host_StartMovies: max %i movies in StartupVids\n", MAX_DEMOS );
c = MAX_MOVIES;
}
2009-11-23 22:00:00 +01:00
2010-09-30 22:00:00 +02:00
for( i = 1; i < c + 1; i++ )
com.strncpy( cls.movies[i-1], Cmd_Argv( i ), sizeof( cls.movies[0] ));
if( !SV_Active() && cls.movienum != -1 && cls.state != ca_cinematic )
{
cls.movienum = 0;
SCR_NextMovie ();
}
else cls.movienum = -1;
}
2009-11-23 22:00:00 +01:00
/*
==================
SCR_RunCinematic
==================
*/
void SCR_RunCinematic( void )
{
2010-09-30 22:00:00 +02:00
if( !AVI_IsActive( cin_state ))
2009-11-23 22:00:00 +01:00
return;
2010-09-30 22:00:00 +02:00
if( vid_gamma->modified )
2009-11-23 22:00:00 +01:00
{
2010-09-30 22:00:00 +02:00
SCR_RebuildGammaTable();
vid_gamma->modified = false;
2009-11-23 22:00:00 +01:00
}
2010-09-30 22:00:00 +02:00
// advances cinematic time
cin_time += cls.frametime;
2009-11-23 22:00:00 +01:00
2010-09-30 22:00:00 +02:00
// stop the video after it finishes
if( cin_time > video_duration + 0.1f )
2009-11-23 22:00:00 +01:00
{
2010-09-30 22:00:00 +02:00
SCR_NextMovie( );
2009-11-23 22:00:00 +01:00
return;
}
2010-09-30 22:00:00 +02:00
// read the next frame
cin_frame = AVI_GetVideoFrameNumber( cin_state, cin_time );
2009-11-23 22:00:00 +01:00
}
/*
==================
SCR_DrawCinematic
Returns true if a cinematic is active, meaning the view rendering
should be skipped
==================
*/
bool SCR_DrawCinematic( void )
{
2010-09-30 22:00:00 +02:00
static int last_frame = -1;
bool redraw = false;
if( !re || cin_time <= 0.0f )
2009-11-23 22:00:00 +01:00
return false;
2010-06-17 22:00:00 +02:00
2010-09-30 22:00:00 +02:00
if( cin_frame != last_frame )
{
AVI_GetVideoFrame( cin_state, cin_data, cin_frame );
last_frame = cin_frame;
redraw = true;
}
2009-11-23 22:00:00 +01:00
2010-09-30 22:00:00 +02:00
re->DrawStretchRaw( 0, 0, scr_width->integer, scr_height->integer, xres, yres, cin_data, redraw );
2009-11-23 22:00:00 +01:00
return true;
}
2010-09-30 22:00:00 +02:00
2009-11-23 22:00:00 +01:00
/*
==================
SCR_PlayCinematic
==================
*/
bool SCR_PlayCinematic( const char *arg )
{
2010-09-30 22:00:00 +02:00
string path;
const char *fullpath;
com.snprintf( path, sizeof( path ), "media/%s.avi", arg );
fullpath = FS_GetDiskPath( path );
2009-11-23 22:00:00 +01:00
2010-09-30 22:00:00 +02:00
if( FS_FileExists( path ) && !fullpath )
2009-11-23 22:00:00 +01:00
{
2010-09-30 22:00:00 +02:00
MsgDev( D_ERROR, "couldn't load %s from packfile. Please extract it\n", path );
return false;
2009-11-23 22:00:00 +01:00
}
2010-09-30 22:00:00 +02:00
AVI_OpenVideo( cin_state, fullpath, true, true );
if( !AVI_IsActive( cin_state ))
{
AVI_CloseVideo( cin_state );
return false;
}
2009-11-23 22:00:00 +01:00
2010-09-30 22:00:00 +02:00
if( !( AVI_GetVideoInfo( cin_state, &xres, &yres, &video_duration ))) // couldn't open this at all.
2009-11-23 22:00:00 +01:00
{
2010-09-30 22:00:00 +02:00
AVI_CloseVideo( cin_state );
2009-11-23 22:00:00 +01:00
return false;
}
2010-09-30 22:00:00 +02:00
cin_data = Mem_Realloc( cls.mempool, cin_data, xres * yres * 3 );
2009-11-23 22:00:00 +01:00
2010-09-30 22:00:00 +02:00
if( AVI_GetAudioInfo( cin_state, &cin_audio ))
2009-11-23 22:00:00 +01:00
{
2010-09-30 22:00:00 +02:00
// begin streaming
S_StopAllSounds();
S_StartStreaming();
2009-11-23 22:00:00 +01:00
}
2010-07-18 22:00:00 +02:00
UI_SetActiveMenu( false );
2010-09-30 22:00:00 +02:00
SCR_RebuildGammaTable();
2009-11-23 22:00:00 +01:00
cls.state = ca_cinematic;
2010-09-30 22:00:00 +02:00
cin_time = 0.0f;
return true;
}
2009-11-23 22:00:00 +01:00
2010-09-30 22:00:00 +02:00
long SCR_GetAudioChunk( char *rawdata, long length )
{
int r;
2009-11-23 22:00:00 +01:00
2010-09-30 22:00:00 +02:00
r = AVI_GetAudioChunk( cin_state, rawdata, cin_audio.loopStart, length );
cin_audio.loopStart += r; // advance play position
return r;
}
wavdata_t *SCR_GetMovieInfo( void )
{
if( AVI_IsActive( cin_state ))
return &cin_audio;
return NULL;
}
/*
==================
SCR_StopCinematic
==================
*/
void SCR_StopCinematic( void )
{
AVI_CloseVideo( cin_state );
S_StopStreaming();
cin_time = 0.0f;
cls.state = ca_disconnected;
UI_SetActiveMenu( true );
}
/*
==================
SCR_InitCinematic
==================
*/
void SCR_InitCinematic( void )
{
AVIFileInit();
// used for movie gamma correction
vid_gamma = Cvar_Get( "vid_gamma", "1.0", CVAR_ARCHIVE, "gamma amount" );
cin_state = AVI_GetState( CIN_MAIN );
}
/*
==================
SCR_FreeCinematic
==================
*/
void SCR_FreeCinematic( void )
{
AVIFileExit();
2009-11-23 22:00:00 +01:00
}