Skip to content

Commit 39c7788

Browse files
committed
refactor(loadscreen): Use TheDisplay for video playback of single player intro videos
1 parent df5756a commit 39c7788

5 files changed

Lines changed: 47 additions & 76 deletions

File tree

GeneralsMD/Code/GameEngine/Include/GameClient/Display.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ class Display : public SubsystemInterface
151151
virtual void playLogoMovie( AsciiString movieName, Int minMovieLength, Int minCopyrightLength );
152152
virtual void playMovie( AsciiString movieName );
153153
virtual void stopMovie( void );
154+
virtual Real getMovieProgress(); ///< returns the playback progress in the range 0.0 to 1.0
154155
virtual Bool isMoviePlaying(void);
155156

156157
/// Register debug display callback

GeneralsMD/Code/GameEngine/Include/GameClient/LoadScreen.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,6 @@ class SinglePlayerLoadScreen : public LoadScreen
110110

111111
UnicodeString m_unicodeObjectiveLines[MAX_OBJECTIVE_LINES];
112112

113-
VideoBuffer *m_videoBuffer;
114-
VideoStreamInterface *m_videoStream;
115-
116113
void moveWindows( Int frame );
117114

118115
AudioEventRTS m_ambientLoop;

GeneralsMD/Code/GameEngine/Source/GameClient/Display.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,16 @@ void Display::reset()
360360
v->reset();
361361
}
362362

363+
//============================================================================
364+
// Display::getMovieProgress
365+
//============================================================================
366+
367+
Real Display::getMovieProgress()
368+
{
369+
return m_videoStream && m_videoStream->frameCount() > 0 ?
370+
(Real)m_videoStream->frameIndex() / (Real)m_videoStream->frameCount() : 0.0f;
371+
}
372+
363373
//============================================================================
364374
// Display::isMoviePlaying
365375
//============================================================================

GeneralsMD/Code/GameEngine/Source/GameClient/GUI/LoadScreen.cpp

Lines changed: 27 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,6 @@ SinglePlayerLoadScreen::SinglePlayerLoadScreen( void )
182182
m_currentObjectiveWidthOffset = 0;
183183
m_progressBar = nullptr;
184184
m_percent = nullptr;
185-
m_videoStream = nullptr;
186-
m_videoBuffer = nullptr;
187185
m_objectiveWin = nullptr;
188186
for(Int i = 0; i < MAX_OBJECTIVE_LINES; ++i)
189187
m_objectiveLines[i] = nullptr;
@@ -198,15 +196,6 @@ SinglePlayerLoadScreen::~SinglePlayerLoadScreen( void )
198196
for(Int i = 0; i < MAX_OBJECTIVE_LINES; ++i)
199197
m_objectiveLines[i] = nullptr;
200198

201-
delete m_videoBuffer;
202-
m_videoBuffer = nullptr;
203-
204-
if ( m_videoStream )
205-
{
206-
m_videoStream->close();
207-
m_videoStream = nullptr;
208-
}
209-
210199
TheAudio->removeAudioEvent( m_ambientLoopHandle );
211200
m_ambientLoopHandle = 0;
212201

@@ -476,32 +465,6 @@ void SinglePlayerLoadScreen::init( GameInfo *game )
476465
477466
*/
478467
m_ambientLoop.setEventName("LoadScreenAmbient");
479-
// create the new stream
480-
m_videoStream = TheVideoPlayer->open( TheCampaignManager->getCurrentMission()->m_movieLabel );
481-
if ( m_videoStream == nullptr )
482-
{
483-
m_percent->winHide(TRUE);
484-
return;
485-
}
486-
487-
// Create the new buffer
488-
m_videoBuffer = TheDisplay->createVideoBuffer();
489-
if ( m_videoBuffer == nullptr ||
490-
!m_videoBuffer->allocate( m_videoStream->width(),
491-
m_videoStream->height())
492-
)
493-
{
494-
delete m_videoBuffer;
495-
m_videoBuffer = nullptr;
496-
497-
if ( m_videoStream )
498-
{
499-
m_videoStream->close();
500-
m_videoStream = nullptr;
501-
}
502-
503-
return;
504-
}
505468

506469
// format the progress bar: USA to blue, GLA to green, China to red
507470
// and set the background image
@@ -530,9 +493,16 @@ void SinglePlayerLoadScreen::init( GameInfo *game )
530493
// TheSuperHackers @bugfix Originally this movie render loop stopped rendering when the game window was inactive.
531494
// This either skipped the movie or caused decompression artifacts. Now the video just keeps playing until it done.
532495

533-
Int progressUpdateCount = m_videoStream->frameCount() / FRAME_FUDGE_ADD;
534-
Int shiftedPercent = -FRAME_FUDGE_ADD + 1;
535-
while (m_videoStream->frameIndex() < m_videoStream->frameCount() - 1 )
496+
// Hide the background window while the movie is playing
497+
backgroundWin->winEnable(false);
498+
499+
// Show video progress bar
500+
m_progressBar->winEnable(true);
501+
502+
// TheSuperHackers @info We now make use of movie playback within the display object
503+
TheDisplay->playMovie(TheCampaignManager->getCurrentMission()->m_movieLabel);
504+
505+
while(TheDisplay->isMoviePlaying())
536506
{
537507
// TheSuperHackers @feature User can now skip video by pressing ESC
538508
if (TheKeyboard)
@@ -548,51 +518,31 @@ void SinglePlayerLoadScreen::init( GameInfo *game )
548518

549519
TheGameEngine->serviceWindowsOS();
550520

551-
if(!m_videoStream->isFrameReady())
552-
{
553-
Sleep(1);
554-
continue;
555-
}
556-
557-
m_videoStream->frameDecompress();
558-
m_videoStream->frameRender(m_videoBuffer);
559-
560-
// PULLED FROM THE MISSION DISK
561-
// moveWindows( m_videoStream->frameIndex());
562-
563-
m_videoStream->frameNext();
564-
565-
if(m_videoBuffer)
566-
m_loadScreen->winGetInstanceData()->setVideoBuffer(m_videoBuffer);
567-
if(m_videoStream->frameIndex() % progressUpdateCount == 0)
568-
{
569-
shiftedPercent++;
570-
if(shiftedPercent >0)
571-
shiftedPercent = 0;
572-
Int percent = (shiftedPercent + FRAME_FUDGE_ADD)/1.3;
573-
UnicodeString per;
574-
per.format(L"%d%%",percent);
575-
TheMouse->setCursorTooltip(UnicodeString::TheEmptyString);
576-
GadgetProgressBarSetProgress(m_progressBar, percent);
577-
GadgetStaticTextSetText(m_percent, per);
578-
579-
}
580-
TheWindowManager->update();
521+
// Update the video progress in the progress bar
522+
Int percentValue = TheDisplay->getMovieProgress() * 100.0f;
523+
UnicodeString percentText;
524+
percentText.format(L"%d%%", percentValue);
525+
TheMouse->setCursorTooltip(UnicodeString::TheEmptyString);
526+
GadgetProgressBarSetProgress(m_progressBar, percentValue);
527+
GadgetStaticTextSetText(m_percent, percentText);
581528

582529
// redraw all views, update the GUI
530+
TheWindowManager->update();
531+
TheDisplay->update();
583532
TheDisplay->draw();
584533
}
585534

586535
// let the background image show through
587-
m_videoStream->close();
588-
m_videoStream = nullptr;
589-
m_loadScreen->winGetInstanceData()->setVideoBuffer( nullptr );
536+
TheDisplay->stopMovie();
537+
backgroundWin->winEnable(true);
590538
TheDisplay->draw();
591539
}
592540
else
593541
{
594542
// if we're min spec'ed don't play a movie
595543

544+
backgroundWin->winEnable(true);
545+
596546
Int delay = mission->m_voiceLength * 1000;
597547
Int begin = timeGetTime();
598548
Int currTime = begin;
@@ -613,6 +563,10 @@ void SinglePlayerLoadScreen::init( GameInfo *game )
613563
TheDisplay->draw();
614564

615565
}
566+
567+
GadgetProgressBarSetProgress(m_progressBar, 0);
568+
GadgetStaticTextSetText(m_percent, UnicodeString::TheEmptyString);
569+
616570
setFPMode();
617571
m_percent->winHide(TRUE);
618572
m_ambientLoopHandle = TheAudio->addAudioEvent(&m_ambientLoop);

GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/W3DGameWindow.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ void W3DGameWinDefaultDraw( GameWindow *window, WinInstanceData *instData )
379379
}
380380

381381
// if we have a video buffer, draw the video buffer
382+
// else if the display has a movie playing then we need to draw the displays video buffer
382383
if ( instData->m_videoBuffer )
383384
{
384385
ICoord2D pos, size;
@@ -387,6 +388,14 @@ void W3DGameWinDefaultDraw( GameWindow *window, WinInstanceData *instData )
387388

388389
TheDisplay->drawVideoBuffer( instData->m_videoBuffer, pos.x, pos.y, pos.x + size.x, pos.y + size.y );
389390
}
391+
else if (TheDisplay->isMoviePlaying())
392+
{
393+
ICoord2D pos, size;
394+
window->winGetScreenPosition(&pos.x, &pos.y);
395+
window->winGetSize(&size.x, &size.y);
396+
397+
TheDisplay->drawVideoBuffer(pos.x, pos.y, pos.x + size.x, pos.y + size.y);
398+
}
390399

391400
}
392401

0 commit comments

Comments
 (0)