| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448 |
- /*
- ** Command & Conquer Generals(tm)
- ** Copyright 2025 Electronic Arts Inc.
- **
- ** This program is free software: you can redistribute it and/or modify
- ** it under the terms of the GNU General Public License as published by
- ** the Free Software Foundation, either version 3 of the License, or
- ** (at your option) any later version.
- **
- ** This program is distributed in the hope that it will be useful,
- ** but WITHOUT ANY WARRANTY; without even the implied warranty of
- ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ** GNU General Public License for more details.
- **
- ** You should have received a copy of the GNU General Public License
- ** along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- ////////////////////////////////////////////////////////////////////////////////
- // //
- // (c) 2001-2003 Electronic Arts Inc. //
- // //
- ////////////////////////////////////////////////////////////////////////////////
- //----------------------------------------------------------------------------
- //
- // Westwood Studios Pacific.
- //
- // Confidential Information
- // Copyright (C) 2001 - All Rights Reserved
- //
- //----------------------------------------------------------------------------
- //
- // Project: Generals
- //
- // Module: VideoDevice
- //
- // File name: BinkDevice.cpp
- //
- // Created: 10/22/01 TR
- //
- //----------------------------------------------------------------------------
- //----------------------------------------------------------------------------
- // Includes
- //----------------------------------------------------------------------------
- #include "Lib/BaseType.h"
- #include "VideoDevice/Bink/BinkVideoPlayer.h"
- #include "Common/AudioAffect.h"
- #include "Common/GameAudio.h"
- #include "Common/GameMemory.h"
- #include "Common/GlobalData.h"
- #include "Common/Registry.h"
- //----------------------------------------------------------------------------
- // Externals
- //----------------------------------------------------------------------------
-
- //----------------------------------------------------------------------------
- // Defines
- //----------------------------------------------------------------------------
- #define VIDEO_LANG_PATH_FORMAT "Data/%s/Movies/%s.%s"
- #define VIDEO_PATH "Data\\Movies"
- #define VIDEO_EXT "bik"
- //----------------------------------------------------------------------------
- // Private Types
- //----------------------------------------------------------------------------
- //----------------------------------------------------------------------------
- // Private Data
- //----------------------------------------------------------------------------
- //----------------------------------------------------------------------------
- // Public Data
- //----------------------------------------------------------------------------
- //----------------------------------------------------------------------------
- // Private Prototypes
- //----------------------------------------------------------------------------
- //----------------------------------------------------------------------------
- // Private Functions
- //----------------------------------------------------------------------------
- //----------------------------------------------------------------------------
- // Public Functions
- //----------------------------------------------------------------------------
- //============================================================================
- // BinkVideoPlayer::BinkVideoPlayer
- //============================================================================
- BinkVideoPlayer::BinkVideoPlayer()
- {
- }
- //============================================================================
- // BinkVideoPlayer::~BinkVideoPlayer
- //============================================================================
- BinkVideoPlayer::~BinkVideoPlayer()
- {
- deinit();
- }
- //============================================================================
- // BinkVideoPlayer::init
- //============================================================================
- void BinkVideoPlayer::init( void )
- {
- // Need to load the stuff from the ini file.
- VideoPlayer::init();
- initializeBinkWithMiles();
- }
- //============================================================================
- // BinkVideoPlayer::deinit
- //============================================================================
- void BinkVideoPlayer::deinit( void )
- {
- TheAudio->releaseHandleForBink();
- VideoPlayer::deinit();
- }
- //============================================================================
- // BinkVideoPlayer::reset
- //============================================================================
- void BinkVideoPlayer::reset( void )
- {
- VideoPlayer::reset();
- }
- //============================================================================
- // BinkVideoPlayer::update
- //============================================================================
- void BinkVideoPlayer::update( void )
- {
- VideoPlayer::update();
- }
- //============================================================================
- // BinkVideoPlayer::loseFocus
- //============================================================================
- void BinkVideoPlayer::loseFocus( void )
- {
- VideoPlayer::loseFocus();
- }
- //============================================================================
- // BinkVideoPlayer::regainFocus
- //============================================================================
- void BinkVideoPlayer::regainFocus( void )
- {
- VideoPlayer::regainFocus();
- }
- //============================================================================
- // BinkVideoPlayer::createStream
- //============================================================================
- VideoStreamInterface* BinkVideoPlayer::createStream( HBINK handle )
- {
- if ( handle == NULL )
- {
- return NULL;
- }
- BinkVideoStream *stream = NEW BinkVideoStream;
- if ( stream )
- {
- stream->m_handle = handle;
- stream->m_next = m_firstStream;
- stream->m_player = this;
- m_firstStream = stream;
- // never let volume go to 0, as Bink will interpret that as "play at full volume".
- Int mod = (Int) ((TheAudio->getVolume(AudioAffect_Speech) * 0.8f) * 100) + 1;
- Int volume = (32768*mod)/100;
- DEBUG_LOG(("BinkVideoPlayer::createStream() - About to set volume (%g -> %d -> %d\n",
- TheAudio->getVolume(AudioAffect_Speech), mod, volume));
- BinkSetVolume( stream->m_handle,0, volume);
- DEBUG_LOG(("BinkVideoPlayer::createStream() - set volume\n"));
- }
- return stream;
- }
- //============================================================================
- // BinkVideoPlayer::open
- //============================================================================
- VideoStreamInterface* BinkVideoPlayer::open( AsciiString movieTitle )
- {
- VideoStreamInterface* stream = NULL;
- const Video* pVideo = getVideo(movieTitle);
- if (pVideo) {
- DEBUG_LOG(("BinkVideoPlayer::createStream() - About to open bink file\n"));
- if (TheGlobalData->m_modDir.isNotEmpty())
- {
- char filePath[ _MAX_PATH ];
- sprintf( filePath, "%s%s\\%s.%s", TheGlobalData->m_modDir.str(), VIDEO_PATH, pVideo->m_filename.str(), VIDEO_EXT );
- HBINK handle = BinkOpen(filePath , BINKPRELOADALL );
- DEBUG_ASSERTLOG(!handle, ("opened bink file %s\n", filePath));
- if (handle)
- {
- return createStream( handle );
- }
- }
- char localizedFilePath[ _MAX_PATH ];
- sprintf( localizedFilePath, VIDEO_LANG_PATH_FORMAT, GetRegistryLanguage().str(), pVideo->m_filename.str(), VIDEO_EXT );
- HBINK handle = BinkOpen(localizedFilePath , BINKPRELOADALL );
- DEBUG_ASSERTLOG(!handle, ("opened localized bink file %s\n", localizedFilePath));
- if (!handle)
- {
- char filePath[ _MAX_PATH ];
- sprintf( filePath, "%s\\%s.%s", VIDEO_PATH, pVideo->m_filename.str(), VIDEO_EXT );
- handle = BinkOpen(filePath , BINKPRELOADALL );
- DEBUG_ASSERTLOG(!handle, ("opened bink file %s\n", localizedFilePath));
- }
- DEBUG_LOG(("BinkVideoPlayer::createStream() - About to create stream\n"));
- stream = createStream( handle );
- }
- return stream;
- }
- //============================================================================
- // BinkVideoPlayer::load
- //============================================================================
- VideoStreamInterface* BinkVideoPlayer::load( AsciiString movieTitle )
- {
- return open(movieTitle); // load() used to have the same body as open(), so I'm combining them. Munkee.
- }
- //============================================================================
- //============================================================================
- void BinkVideoPlayer::notifyVideoPlayerOfNewProvider( Bool nowHasValid )
- {
- if (!nowHasValid) {
- TheAudio->releaseHandleForBink();
- BinkSetSoundTrack(0, 0);
- } else {
- initializeBinkWithMiles();
- }
- }
- //============================================================================
- //============================================================================
- void BinkVideoPlayer::initializeBinkWithMiles()
- {
- Int retVal = 0;
- void *driver = TheAudio->getHandleForBink();
-
- if ( driver )
- {
- retVal = BinkSoundUseDirectSound(driver);
- }
- if( !driver || retVal == 0)
- {
- BinkSetSoundTrack ( 0,0 );
- }
- }
- //============================================================================
- // BinkVideoStream::BinkVideoStream
- //============================================================================
- BinkVideoStream::BinkVideoStream()
- : m_handle(NULL)
- {
- }
- //============================================================================
- // BinkVideoStream::~BinkVideoStream
- //============================================================================
- BinkVideoStream::~BinkVideoStream()
- {
- if ( m_handle != NULL )
- {
- BinkClose( m_handle );
- m_handle = NULL;
- }
- }
- //============================================================================
- // BinkVideoStream::update
- //============================================================================
- void BinkVideoStream::update( void )
- {
- BinkWait( m_handle );
- }
- //============================================================================
- // BinkVideoStream::isFrameReady
- //============================================================================
- Bool BinkVideoStream::isFrameReady( void )
- {
- return !BinkWait( m_handle );
- }
- //============================================================================
- // BinkVideoStream::frameDecompress
- //============================================================================
- void BinkVideoStream::frameDecompress( void )
- {
- BinkDoFrame( m_handle );
- }
- //============================================================================
- // BinkVideoStream::frameRender
- //============================================================================
- void BinkVideoStream::frameRender( VideoBuffer *buffer )
- {
- if ( buffer )
- {
- void *mem = buffer->lock();
- u32 flags;
- switch ( buffer->format())
- {
- case VideoBuffer::TYPE_X8R8G8B8:
- flags = BINKSURFACE32;
- break;
- case VideoBuffer::TYPE_R8G8B8:
- flags = BINKSURFACE24;
- break;
- case VideoBuffer::TYPE_R5G6B5:
- flags = BINKSURFACE565;
- break;
- case VideoBuffer::TYPE_X1R5G5B5:
- flags = BINKSURFACE555;
- break;
- default:
- return;
- }
-
- if ( mem != NULL )
- {
- BinkCopyToBuffer ( m_handle, mem, buffer->pitch(), buffer->height(),
- buffer->xPos(), buffer->yPos(), flags );
- buffer->unlock();
- }
- }
- }
- //============================================================================
- // BinkVideoStream::frameNext
- //============================================================================
- void BinkVideoStream::frameNext( void )
- {
- BinkNextFrame( m_handle );
- }
- //============================================================================
- // BinkVideoStream::frameIndex
- //============================================================================
- Int BinkVideoStream::frameIndex( void )
- {
- return m_handle->FrameNum - 1;
- }
- //============================================================================
- // BinkVideoStream::totalFrames
- //============================================================================
- Int BinkVideoStream::frameCount( void )
- {
- return m_handle->Frames;
- }
- //============================================================================
- // BinkVideoStream::frameGoto
- //============================================================================
- void BinkVideoStream::frameGoto( Int index )
- {
- BinkGoto(m_handle, index, NULL );
- }
- //============================================================================
- // VideoStream::height
- //============================================================================
- Int BinkVideoStream::height( void )
- {
- return m_handle->Height;
- }
- //============================================================================
- // VideoStream::width
- //============================================================================
- Int BinkVideoStream::width( void )
- {
- return m_handle->Width;
- }
|