Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 24 additions & 23 deletions Core/GameEngine/Source/GameClient/GUI/LoadScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
#include "Common/GameEngine.h"
#include "Common/GameLOD.h"
#include "Common/GameState.h"
#include "Common/MessageStream.h"
#include "Common/MultiplayerSettings.h"
#include "Common/Player.h"
#include "Common/PlayerList.h"
Expand All @@ -68,6 +69,7 @@
#include "GameClient/Display.h"
#include "GameClient/GadgetProgressBar.h"
#include "GameClient/GadgetStaticText.h"
#include "GameClient/GameClient.h"
#include "GameClient/GameText.h"
#include "GameClient/GameWindowManager.h"
#include "GameClient/GameWindowTransitions.h"
Expand Down Expand Up @@ -157,7 +159,8 @@ LoadScreen::~LoadScreen()
void LoadScreen::update( Int percent )
{
TheGameEngine->serviceWindowsOS();
if (TheGameEngine->getQuitting())
TheMessageStream->propagateMessages();
if (TheGameEngine->getQuitting() || (TheGameLogic && TheGameLogic->m_quitToDesktopAfterMatch))
return; //don't bother with any of this if the player is exiting game.

TheWindowManager->update();
Expand Down Expand Up @@ -539,20 +542,11 @@ void SinglePlayerLoadScreen::init( GameInfo *game )
Int shiftedPercent = -FRAME_FUDGE_ADD + 1;
while (m_videoStream->frameIndex() < m_videoStream->frameCount() - 1 )
{
// TheSuperHackers @feature User can now skip video by pressing ESC
if (TheKeyboard)
if (GameClient::isMovieAbortRequested())
{
TheKeyboard->UPDATE();
KeyboardIO *io = TheKeyboard->findKey(KEY_ESC, KeyboardIO::STATUS_UNUSED);
if (io && BitIsSet(io->state, KEY_STATE_DOWN))
{
io->setUsed();
break;
}
break;
}

TheGameEngine->serviceWindowsOS();

if(!m_videoStream->isFrameReady())
{
Sleep(1);
Expand Down Expand Up @@ -634,6 +628,11 @@ void SinglePlayerLoadScreen::init( GameInfo *game )
fudgeFactor = 30 * ((currTime - begin)/ INT_TO_REAL(delay ));
GadgetProgressBarSetProgress(m_progressBar, fudgeFactor);

if (GameClient::isMovieAbortRequested())
{
break;
}

TheWindowManager->update();
TheDisplay->draw();
Sleep(100);
Expand Down Expand Up @@ -1054,20 +1053,11 @@ void ChallengeLoadScreen::init( GameInfo *game )
Int shiftedPercent = -FRAME_FUDGE_ADD + 1;
while (m_videoStream->frameIndex() < m_videoStream->frameCount() - 1 )
{
// TheSuperHackers @feature User can now skip video by pressing ESC
if (TheKeyboard)
if (GameClient::isMovieAbortRequested())
{
TheKeyboard->UPDATE();
KeyboardIO *io = TheKeyboard->findKey(KEY_ESC, KeyboardIO::STATUS_UNUSED);
if (io && BitIsSet(io->state, KEY_STATE_DOWN))
{
io->setUsed();
break;
}
break;
}

TheGameEngine->serviceWindowsOS();

if(!m_videoStream->isFrameReady())
{
Sleep(1);
Expand Down Expand Up @@ -1109,7 +1099,13 @@ void ChallengeLoadScreen::init( GameInfo *game )
// if we're min speced
m_videoStream->frameGoto(m_videoStream->frameCount()); // zero based
while(!m_videoStream->isFrameReady())
{
if (GameClient::isMovieAbortRequested())
{
break;
}
Sleep(1);
}
m_videoStream->frameDecompress();
m_videoStream->frameRender(m_videoBuffer);
if(m_videoBuffer)
Expand All @@ -1126,6 +1122,11 @@ void ChallengeLoadScreen::init( GameInfo *game )
fudgeFactor = 30 * ((currTime - begin)/ INT_TO_REAL(delay ));
GadgetProgressBarSetProgress(m_progressBar, fudgeFactor);

if (GameClient::isMovieAbortRequested())
{
break;
}

TheWindowManager->update();
TheDisplay->draw();
Sleep(100);
Expand Down
2 changes: 1 addition & 1 deletion Generals/Code/GameEngine/Include/Common/MessageStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ class GameMessage : public MemoryPoolObject
MSG_META_TOGGLE_PAUSE_ALT, ///< TheSuperHackers @feature Toggle game pause (alternative mapping)
MSG_META_STEP_FRAME, ///< TheSuperHackers @feature Step one frame
MSG_META_STEP_FRAME_ALT, ///< TheSuperHackers @feature Step one frame (alternative mapping)
MSG_META_DEMO_INSTANT_QUIT, ///< bail out of game immediately


// META items that are really for debug/demo/development use only...
Expand All @@ -289,7 +290,6 @@ class GameMessage : public MemoryPoolObject
MSG_META_DEMO_LOD_INCREASE, ///< increase LOD by 1
MSG_META_DEMO_TOGGLE_ZOOM_LOCK, ///< Toggle the camera zoom lock on/off
MSG_META_DEMO_PLAY_CAMEO_MOVIE, ///< Play a movie in the cameo spot
MSG_META_DEMO_INSTANT_QUIT, ///< bail out of game immediately
MSG_META_DEMO_TOGGLE_SPECIAL_POWER_DELAYS, ///< Toggle special power delays on/off
MSG_META_DEMO_BATTLE_CRY, ///< battle cry
MSG_META_DEMO_SWITCH_TEAMS, ///< switch local control to another team
Expand Down
2 changes: 2 additions & 0 deletions Generals/Code/GameEngine/Include/GameClient/GameClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ class GameClient : public SubsystemInterface,
UnsignedInt getRenderedObjectCount() const { return m_renderedObjectCount; }
void incrementRenderedObjectCount() { m_renderedObjectCount++; }

static Bool isMovieAbortRequested();

protected:

// snapshot methods
Expand Down
3 changes: 3 additions & 0 deletions Generals/Code/GameEngine/Include/GameLogic/GameLogic.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ class GameLogic : public SubsystemInterface, public Snapshot
UnsignedInt getFrameObjectsChangedTriggerAreas() {return m_frameObjectsChangedTriggerAreas;}

void exitGame();
void quit(Bool toDesktop);
void clearGameData(Bool showScoreScreen = TRUE); ///< Clear the game data
void closeWindows();

Expand Down Expand Up @@ -243,6 +244,8 @@ class GameLogic : public SubsystemInterface, public Snapshot
// this should be called only by UpdateModule, thanks.
void friend_awakenUpdateModule(Object* obj, UpdateModulePtr update, UnsignedInt whenToWakeUp);

Bool m_quitToDesktopAfterMatch;

protected:

// snapshot methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,21 +139,7 @@ static void exitQuitMenu()
{
// destroy the quit menu
destroyQuitMenu();

// clear out all the game data
if ( TheGameLogic->isInMultiplayerGame() && !TheGameLogic->isInSkirmishGame() && !TheGameInfo->isSandbox() )
{
GameMessage *msg = TheMessageStream->appendMessage(GameMessage::MSG_SELF_DESTRUCT);
msg->appendBooleanArgument(TRUE);
}
TheGameLogic->exitGame();
// TheGameLogic->clearGameData();
// display the menu on top of the shell stack
// TheShell->showShell();

// this will trigger an exit
// TheGameEngine->setQuitting( TRUE );
TheInGameUI->setClientQuiet( TRUE );
TheGameLogic->quit(FALSE);
}
static void noExitQuitMenu()
{
Expand All @@ -164,18 +150,7 @@ static void quitToDesktopQuitMenu()
{
// destroy the quit menu
destroyQuitMenu();

if (TheGameLogic->isInGame())
{
if (TheRecorder->getMode() == RECORDERMODETYPE_RECORD)
{
TheRecorder->stopRecording();
}
TheGameLogic->clearGameData();
}
TheGameEngine->setQuitting(TRUE);
TheInGameUI->setClientQuiet( TRUE );

TheGameLogic->quit(TRUE);
}

static void surrenderQuitMenu()
Expand Down
31 changes: 31 additions & 0 deletions Generals/Code/GameEngine/Source/GameClient/GameClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,11 @@ void GameClient::update()
Int beginTime = timeGetTime();
while(beginTime + 4000 > timeGetTime() )
{
if (GameClient::isMovieAbortRequested())
{
break;
}

TheWindowManager->update();
// redraw all views, update the GUI
TheDisplay->draw();
Expand Down Expand Up @@ -755,6 +760,32 @@ void GameClient::updateHeadless()
TheParticleSystemManager->reset();
}

Bool GameClient::isMovieAbortRequested()
{
// TheSuperHackers @feature User can skip video by pressing ESC
if (TheKeyboard)
{
TheKeyboard->UPDATE();
KeyboardIO *io = TheKeyboard->findKey(KEY_ESC, KeyboardIO::STATUS_UNUSED);
if (io && BitIsSet(io->state, KEY_STATE_DOWN))
{
io->setUsed();
return TRUE;
}
}

// TheSuperHackers @feature Service OS for Window Close / Alt-F4 events
TheGameEngine->serviceWindowsOS();
TheMessageStream->propagateMessages();

if (TheGameEngine->getQuitting() || (TheGameLogic && TheGameLogic->m_quitToDesktopAfterMatch))
{
return TRUE;
}

return FALSE;
}

/** -----------------------------------------------------------------------------------------------
* Call the given callback function for each object contained within the given region.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3697,27 +3697,15 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessage
break;

}


#if defined(RTS_DEBUG)
//------------------------------------------------------------------------- BEGIN DEMO MESSAGES
//------------------------------------------------------------------------- BEGIN DEMO MESSAGES
//------------------------------------------------------------------------- BEGIN DEMO MESSAGES
//------------------------------------------------------------------------------- DEMO MESSAGES
//-----------------------------------------------------------------------------------------

case GameMessage::MSG_META_DEMO_INSTANT_QUIT:
if (TheGameLogic->isInGame())
{
if (TheRecorder->getMode() == RECORDERMODETYPE_RECORD)
{
TheRecorder->stopRecording();
}
TheGameLogic->clearGameData();
}
TheGameEngine->setQuitting(TRUE);
{
TheGameLogic->quit(TRUE);
disp = DESTROY_MESSAGE;
break;
}

#if defined(RTS_DEBUG)
//------------------------------------------------------------------------------- DEMO MESSAGES
//-----------------------------------------------------------------------------------------
case GameMessage::MSG_META_DEMO_SWITCH_TEAMS:
Expand Down Expand Up @@ -5053,6 +5041,7 @@ static Bool isSystemMessage( const GameMessage *msg )
case GameMessage::MSG_LOGIC_CRC:
case GameMessage::MSG_SET_REPLAY_CAMERA:
case GameMessage::MSG_FRAME_TICK:
case GameMessage::MSG_META_DEMO_INSTANT_QUIT:
return TRUE;
}
return FALSE;
Expand Down
73 changes: 72 additions & 1 deletion Generals/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ GameLogic::GameLogic()
m_logicTimeScaleEnabledMemory = FALSE;
m_loadScreen = nullptr;
m_forceGameStartByTimeOut = FALSE;
m_quitToDesktopAfterMatch = FALSE;
#ifdef DUMP_PERF_STATS
m_overallFailedPathfinds = 0;
#endif
Expand Down Expand Up @@ -911,6 +912,8 @@ static void populateRandomStartPosition( GameInfo *game )
}
}

struct QuitGameException {};

// ------------------------------------------------------------------------------------------------
/** Update the load screen progress */
// ------------------------------------------------------------------------------------------------
Expand All @@ -920,6 +923,10 @@ void GameLogic::updateLoadProgress( Int progress )
if( m_loadScreen )
m_loadScreen->update( progress );

if (TheGameEngine->getQuitting() || m_quitToDesktopAfterMatch)
{
throw QuitGameException();
}
}

// ------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -966,6 +973,8 @@ void GameLogic::setGameMode( GameMode mode )
// ------------------------------------------------------------------------------------------------
void GameLogic::startNewGame( Bool saveGame )
{
try
{
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps do

void GameLogic::startNewGame( Bool saveGame )
{
  try
  {
    tryStartNewGame(saveGame);
  }
  catch ..
  {
  }
}


#ifdef DUMP_PERF_STATS
__int64 startTime64;
Expand Down Expand Up @@ -2067,7 +2076,11 @@ void GameLogic::startNewGame( Bool saveGame )
TheInGameUI->messageNoFormat( TheGameText->FETCH_OR_SUBSTITUTE( "GUI:FastForwardInstructions", L"Press F to toggle Fast Forward" ) );
}


}
catch (QuitGameException&)
{
// TheSuperHackers @info The application is cleanly aborting the loading process
}
}

//-----------------------------------------------------------------------------------------
Expand Down Expand Up @@ -3619,6 +3632,64 @@ void GameLogic::exitGame()
TheMessageStream->appendMessage(GameMessage::MSG_CLEAR_GAME_DATA);
}

// ------------------------------------------------------------------------------------------------
void GameLogic::quit(Bool toDesktop)
{
if (isInGame())
{
const Bool isSandbox = TheGameInfo && TheGameInfo->isSandbox();

if (isInMultiplayerGame() && TheGameInfo && !isSandbox)
{
GameMessage *msg = TheMessageStream->appendMessage(GameMessage::MSG_SELF_DESTRUCT);
msg->appendBooleanArgument(TRUE);
}

if (TheRecorder && TheRecorder->getMode() == RECORDERMODETYPE_RECORD)
{
TheRecorder->stopRecording();
}

setGamePaused(FALSE);

if (TheScriptEngine)
{
TheScriptEngine->forceUnfreezeTime();
TheScriptEngine->doUnfreezeTime();
}

if (toDesktop)
{
if (isInMultiplayerGame())
{
m_quitToDesktopAfterMatch = TRUE;
exitGame();
}
else
{
clearGameData();
}
}
else
{
exitGame();
}
}

if (toDesktop)
{
if (!isInMultiplayerGame())
{
TheGameEngine->setQuitting(TRUE);
}
}

if (TheInGameUI)
{
TheInGameUI->setClientQuiet(TRUE);
}
}

// ------------------------------------------------------------------------------------------------
/** A new GameLogic object has been constructed, therefore create
* a corresponding drawable and bind them together. */
Expand Down
Loading
Loading