Skip to content

Commit 14332fd

Browse files
committed
refactor(loadscreen): Refactor the single player load screen to use TheDisplay for intro video playback (#2273)
1 parent 8b2a58c commit 14332fd

10 files changed

Lines changed: 92 additions & 169 deletions

File tree

Generals/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

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

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

108108
UnicodeString m_unicodeObjectiveLines[MAX_OBJECTIVE_LINES];
109109

110-
VideoBuffer *m_videoBuffer;
111-
VideoStreamInterface *m_videoStream;
112-
113110
void moveWindows( Int frame );
114111

115112
AudioEventRTS m_ambientLoop;

Generals/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
//============================================================================

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

Lines changed: 25 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,6 @@ SinglePlayerLoadScreen::SinglePlayerLoadScreen( void )
161161
m_currentObjectiveWidthOffset = 0;
162162
m_progressBar = nullptr;
163163
m_percent = nullptr;
164-
m_videoStream = nullptr;
165-
m_videoBuffer = nullptr;
166164
m_objectiveWin = nullptr;
167165
for(Int i = 0; i < MAX_OBJECTIVE_LINES; ++i)
168166
m_objectiveLines[i] = nullptr;
@@ -177,15 +175,6 @@ SinglePlayerLoadScreen::~SinglePlayerLoadScreen( void )
177175
for(Int i = 0; i < MAX_OBJECTIVE_LINES; ++i)
178176
m_objectiveLines[i] = nullptr;
179177

180-
delete m_videoBuffer;
181-
m_videoBuffer = nullptr;
182-
183-
if ( m_videoStream )
184-
{
185-
m_videoStream->close();
186-
m_videoStream = nullptr;
187-
}
188-
189178
TheAudio->removeAudioEvent( m_ambientLoopHandle );
190179
m_ambientLoopHandle = 0;
191180

@@ -455,41 +444,20 @@ void SinglePlayerLoadScreen::init( GameInfo *game )
455444
456445
*/
457446
m_ambientLoop.setEventName("LoadScreenAmbient");
458-
// create the new stream
459-
m_videoStream = TheVideoPlayer->open( TheCampaignManager->getCurrentMission()->m_movieLabel );
460-
if ( m_videoStream == nullptr )
461-
{
462-
m_percent->winHide(TRUE);
463-
return;
464-
}
465447

466-
// Create the new buffer
467-
m_videoBuffer = TheDisplay->createVideoBuffer();
468-
if ( m_videoBuffer == nullptr ||
469-
!m_videoBuffer->allocate( m_videoStream->width(),
470-
m_videoStream->height())
471-
)
472-
{
473-
delete m_videoBuffer;
474-
m_videoBuffer = nullptr;
475-
476-
if ( m_videoStream )
477-
{
478-
m_videoStream->close();
479-
m_videoStream = nullptr;
480-
}
481-
482-
return;
483-
}
484448

485449
if(TheGameLODManager && TheGameLODManager->didMemPass())
486450
{
487451
// TheSuperHackers @bugfix Originally this movie render loop stopped rendering when the game window was inactive.
488452
// This either skipped the movie or caused decompression artifacts. Now the video just keeps playing until it done.
489453

490-
Int progressUpdateCount = m_videoStream->frameCount() / FRAME_FUDGE_ADD;
491-
Int shiftedPercent = -FRAME_FUDGE_ADD + 1;
492-
while (m_videoStream->frameIndex() < m_videoStream->frameCount() - 1 )
454+
// Show video progress bar
455+
m_progressBar->winEnable(true);
456+
457+
// TheSuperHackers @info We now make use of movie playback within the display object
458+
TheDisplay->playMovie(TheCampaignManager->getCurrentMission()->m_movieLabel);
459+
460+
while(TheDisplay->isMoviePlaying())
493461
{
494462
// TheSuperHackers @feature User can now skip video by pressing ESC
495463
if (TheKeyboard)
@@ -505,64 +473,27 @@ void SinglePlayerLoadScreen::init( GameInfo *game )
505473

506474
TheGameEngine->serviceWindowsOS();
507475

508-
if(!m_videoStream->isFrameReady())
509-
{
510-
Sleep(1);
511-
continue;
512-
}
513-
514-
m_videoStream->frameDecompress();
515-
m_videoStream->frameRender(m_videoBuffer);
516-
moveWindows( m_videoStream->frameIndex());
517-
m_videoStream->frameNext();
476+
// Update the video progress in the progress bar
477+
Int percentValue = TheDisplay->getMovieProgress() * 100.0f;
478+
UnicodeString percentText;
479+
percentText.format(L"%d%%", percentValue);
480+
TheMouse->setCursorTooltip(UnicodeString::TheEmptyString);
481+
GadgetProgressBarSetProgress(m_progressBar, percentValue);
482+
GadgetStaticTextSetText(m_percent, percentText);
518483

519-
if(m_videoBuffer)
520-
m_loadScreen->winGetInstanceData()->setVideoBuffer(m_videoBuffer);
521-
if(m_videoStream->frameIndex() % progressUpdateCount == 0)
522-
{
523-
shiftedPercent++;
524-
if(shiftedPercent >0)
525-
shiftedPercent = 0;
526-
Int percent = (shiftedPercent + FRAME_FUDGE_ADD)/1.3;
527-
UnicodeString per;
528-
per.format(L"%d%%",percent);
529-
TheMouse->setCursorTooltip(UnicodeString::TheEmptyString);
530-
GadgetProgressBarSetProgress(m_progressBar, percent);
531-
GadgetStaticTextSetText(m_percent, per);
532-
533-
}
534-
TheWindowManager->update();
535-
536-
//TheShell->update();
537-
//TheDisplay->update();
538484
// redraw all views, update the GUI
485+
TheWindowManager->update();
486+
TheDisplay->update();
539487
TheDisplay->draw();
540488
}
489+
490+
// let the background image show through
491+
TheDisplay->stopMovie();
492+
TheDisplay->draw();
541493
}
542494
else
543495
{
544-
// if we're min speced
545-
m_videoStream->frameGoto(m_videoStream->frameCount()); // zero based
546-
while(!m_videoStream->isFrameReady())
547-
Sleep(1);
548-
m_videoStream->frameDecompress();
549-
m_videoStream->frameRender(m_videoBuffer);
550-
if(m_videoBuffer)
551-
m_loadScreen->winGetInstanceData()->setVideoBuffer(m_videoBuffer);
552-
553-
m_objectiveWin->winHide(FALSE);
554-
for(i = 0; i < MAX_DISPLAYED_UNITS; ++i)
555-
m_unitDesc[i]->winHide(FALSE);
556-
m_location->winHide(FALSE);
557-
558-
// Audio was choppy so, I chopped it out!
559-
TheAudio->friend_forcePlayAudioEventRTS(&TheCampaignManager->getCurrentMission()->m_briefingVoice);
560-
561-
for(Int i = 0; i < MAX_OBJECTIVE_LINES; ++i)
562-
{
563-
GadgetStaticTextSetText(m_objectiveLines[i], m_unicodeObjectiveLines[i]);
564-
}
565-
496+
// if we're min spec'ed don't play a movie
566497
Int delay = mission->m_voiceLength * 1000;
567498
Int begin = timeGetTime();
568499
Int currTime = begin;
@@ -583,6 +514,10 @@ void SinglePlayerLoadScreen::init( GameInfo *game )
583514
TheDisplay->draw();
584515

585516
}
517+
518+
GadgetProgressBarSetProgress(m_progressBar, 0);
519+
GadgetStaticTextSetText(m_percent, UnicodeString::TheEmptyString);
520+
586521
setFPMode();
587522
m_percent->winHide(TRUE);
588523
m_ambientLoopHandle = TheAudio->addAudioEvent(&m_ambientLoop);

Generals/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

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
//============================================================================

0 commit comments

Comments
 (0)