Sources/CryGame C++/Solution1/CryGame/XDemoMgr.cpp
//////////////////////////////////////////////////////////////////////////
// Opens a recorded demo for playback.

Opens a recorded demo for playback.
Opens a recorded demo for playback .
bool CXDemoMgr::StartDemoPlay(const char *sFileName, CXGame *pGame)
{
	Stop();
	m_pGame = pGame;
	m_pFile=fopen(sFileName,"rb");
	if(m_pFile==NULL)
		return false;
	fseek(m_pFile,0,SEEK_END);
	m_nFileSize=ftell(m_pFile);
	fseek(m_pFile,0,SEEK_SET);
	char magic[32];
	if(fread(magic, strlen(DEMOMAGIC1)+1, 1, m_pFile)!=1 || strcmp(magic, DEMOMAGIC1))
		return false;
	int hd[2];
	if(fread(hd, sizeof(hd), 1, m_pFile)!=1 || hd[0]!=DEMOVERSION)
		return false;
	int nNumBits = hd[1];
	int nNumBytes = BITS2BYTES(nNumBits);
	CDefaultStreamAllocator sa;
	CStream stm(300, &sa); 
	stm.SetSize(nNumBits);
	if(fread(stm.GetPtr(), nNumBytes, 1, m_pFile)!=1)
		return false;
	if(!pGame->LoadFromStream(stm, true))
		return false;
	if(fread(magic, strlen(DEMOMAGIC2)+1, 1, m_pFile)!=1 || strcmp(magic, DEMOMAGIC2))
		return false;
	if(!ReadChunk(m_ChunkToPlay.stm, m_ChunkToPlay.fTimestamp, m_ChunkToPlay.angles))
		return false;
	m_ChunkToPlay.bPlayed=false;
	m_fCurrTime=m_ChunkToPlay.fTimestamp;
	pGame->GetSystem()->GetIConsole()->ShowConsole(false);
	bStreamStarted = true;
	return true;
}
bool CXDemoMgr :: StartDemoPlay ( const char * sFileName , CXGame * pGame ) { Stop ( ) ; m_pGame = pGame ; m_pFile = fopen ( sFileName , " " ) ; if ( m_pFile == NULL ) return false ; fseek ( m_pFile , 0 , SEEK_END ) ; m_nFileSize = ftell ( m_pFile ) ; fseek ( m_pFile , 0 , SEEK_SET ) ; char magic [ 32 ] ; if ( fread ( magic , strlen ( DEMOMAGIC1 ) + 1 , 1 , m_pFile ) != 1 || strcmp ( magic , DEMOMAGIC1 ) ) return false ; int hd [ 2 ] ; if ( fread ( hd , sizeof ( hd ) , 1 , m_pFile ) != 1 || hd [ 0 ] != DEMOVERSION ) return false ; int nNumBits = hd [ 1 ] ; int nNumBytes = BITS2BYTES ( nNumBits ) ; CDefaultStreamAllocator sa ; CStream stm ( 300 , & sa ) ; stm . SetSize ( nNumBits ) ; if ( fread ( stm . GetPtr ( ) , nNumBytes , 1 , m_pFile ) != 1 ) return false ; if ( ! pGame -> LoadFromStream ( stm , true ) ) return false ; if ( fread ( magic , strlen ( DEMOMAGIC2 ) + 1 , 1 , m_pFile ) != 1 || strcmp ( magic , DEMOMAGIC2 ) ) return false ; if ( ! ReadChunk ( m_ChunkToPlay . stm , m_ChunkToPlay . fTimestamp , m_ChunkToPlay . angles ) ) return false ; m_ChunkToPlay . bPlayed = false ; m_fCurrTime = m_ChunkToPlay . fTimestamp ; pGame -> GetSystem ( ) -> GetIConsole ( ) -> ShowConsole ( false ) ; bStreamStarted = true ; return true ; }
Opens a recorded demo for playback.
Opens a recorded demo for playback .
//measure the file size
 //read the first chunk
 //set the chunk as non played
 //set the first chunk timestamp as "base time"
