Skip to content

Commit

Permalink
PEGASUS: Implement the intro timer
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Hoops committed Mar 21, 2012
1 parent 6a78612 commit 1ec7e51
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 11 deletions.
2 changes: 2 additions & 0 deletions engines/pegasus/menu.cpp
Expand Up @@ -1214,6 +1214,8 @@ void PauseMenu::updateDisplay() {
_largeSelect.hide();
break;
}

((PegasusEngine *)g_engine)->resetIntroTimer();
}


Expand Down
89 changes: 78 additions & 11 deletions engines/pegasus/pegasus.cpp
Expand Up @@ -89,6 +89,7 @@ PegasusEngine::PegasusEngine(OSystem *syst, const PegasusGameDescription *gamede
_dragType = kDragNoDrag;
_idlerHead = 0;
_currentCD = 1;
_introTimer = 0;
}

PegasusEngine::~PegasusEngine() {
Expand All @@ -99,11 +100,16 @@ PegasusEngine::~PegasusEngine() {
delete _gameMenu;
delete _neighborhood;
delete _rnd;
delete _introTimer;

// NOTE: This must be deleted last!
delete _gfx;
}

void introTimerExpiredFunction(FunctionPtr *, void *) {
((PegasusEngine *)g_engine)->introTimerExpired();
}

Common::Error PegasusEngine::run() {
_console = new PegasusConsole(this);
_gfx = new GraphicsManager(this);
Expand Down Expand Up @@ -169,6 +175,11 @@ Common::Error PegasusEngine::run() {
// Start up the first notification
_shellNotification.setNotificationFlags(kGameStartingFlag, kGameStartingFlag);

if (!isDemo()) {
_introTimer = new FuseFunction();
_introTimer->setFunctionPtr(&introTimerExpiredFunction, 0);
}

while (!shouldQuit()) {
processShell();
_system->delayMillis(10); // Ease off the CPU
Expand Down Expand Up @@ -270,6 +281,8 @@ void PegasusEngine::createItem(ItemID itemID, NeighborhoodID neighborhoodID, Roo
}

void PegasusEngine::runIntro() {
stopIntroTimer();

bool skipped = false;

Video::SeekableVideoDecoder *video = new Video::QuickTimeDecoder();
Expand Down Expand Up @@ -601,15 +614,18 @@ void PegasusEngine::receiveNotification(Notification *notification, const Notifi
if (&_shellNotification == notification) {
switch (flags) {
case kGameStartingFlag: {
if (!isDemo())
useMenu(new MainMenu());

if (!isDemo()) {
runIntro();
else
resetIntroTimer();
} else {
showTempScreen("Images/Demo/NGsplashScrn.pict");
}

if (shouldQuit())
return;

useMenu(new MainMenu());
_gfx->invalRect(Common::Rect(0, 0, 640, 480));
_gfx->updateDisplay();
((MainMenu *)_gameMenu)->startMainMenuLoop();
Expand All @@ -634,7 +650,54 @@ void PegasusEngine::checkCallBacks() {
}

void PegasusEngine::resetIntroTimer() {
// TODO
if (!isDemo() && _gameMenu && _gameMenu->getObjectID() == kMainMenuID) {
_introTimer->stopFuse();
_introTimer->primeFuse(kIntroTimeOut);
_introTimer->lightFuse();
}
}

void PegasusEngine::introTimerExpired() {
if (_gameMenu && _gameMenu->getObjectID() == kMainMenuID) {
((MainMenu *)_gameMenu)->stopMainMenuLoop();

bool skipped = false;

Video::SeekableVideoDecoder *video = new Video::QuickTimeDecoder();
if (!video->loadFile(_introDirectory + "/LilMovie.movie"))
error("Failed to load little movie");

bool saveAllowed = swapSaveAllowed(false);
bool openAllowed = swapLoadAllowed(false);

skipped = playMovieScaled(video, 0, 0);

delete video;

if (shouldQuit())
return;

if (!skipped) {
runIntro();

if (shouldQuit())
return;
}

resetIntroTimer();
_gfx->invalRect(Common::Rect(0, 0, 640, 480));

swapSaveAllowed(saveAllowed);
swapLoadAllowed(openAllowed);

_gfx->updateDisplay();
((MainMenu *)_gameMenu)->startMainMenuLoop();
}
}

void PegasusEngine::stopIntroTimer() {
if (_introTimer)
_introTimer->stopFuse();
}

void PegasusEngine::delayShell(TimeValue time, TimeScale scale) {
Expand Down Expand Up @@ -681,6 +744,7 @@ void PegasusEngine::doGameMenuCommand(const GameMenuCommand command) {

switch (command) {
case kMenuCmdStartAdventure:
stopIntroTimer();
GameState.setWalkthroughMode(false);
startNewGame();
break;
Expand All @@ -691,7 +755,7 @@ void PegasusEngine::doGameMenuCommand(const GameMenuCommand command) {
_gfx->updateDisplay();
_gfx->doFadeInSync();
} else {
// TODO: Stop intro timer
stopIntroTimer();
_gfx->doFadeOutSync();
useMenu(new CreditsMenu());
_gfx->updateDisplay();
Expand All @@ -705,17 +769,22 @@ void PegasusEngine::doGameMenuCommand(const GameMenuCommand command) {
_system->quit();
break;
case kMenuCmdOverview:
// TODO: Stop intro timer
stopIntroTimer();
doInterfaceOverview();
resetIntroTimer();
break;
case kMenuCmdStartWalkthrough:
stopIntroTimer();
GameState.setWalkthroughMode(true);
startNewGame();
break;
case kMenuCmdRestore:
stopIntroTimer();
// fall through
case kMenuCmdDeathRestore:
showLoadDialog();
result = showLoadDialog();
if (command == kMenuCmdRestore && result.getCode() != Common::kNoError)
resetIntroTimer();
break;
case kMenuCmdCreditsMainMenu:
_gfx->doFadeOutSync();
Expand Down Expand Up @@ -769,8 +838,7 @@ void PegasusEngine::doGameMenuCommand(const GameMenuCommand command) {
_gfx->updateDisplay();
((MainMenu *)_gameMenu)->startMainMenuLoop();
_gfx->doFadeInSync();
if (!isDemo())
resetIntroTimer();
resetIntroTimer();
break;
case kMenuCmdPauseSave:
if (showSaveDialog().getCode() != Common::kUserCanceled)
Expand Down Expand Up @@ -799,8 +867,7 @@ void PegasusEngine::doGameMenuCommand(const GameMenuCommand command) {
_gfx->updateDisplay();
((MainMenu *)_gameMenu)->startMainMenuLoop();
_gfx->doFadeInSync();
if (!isDemo())
resetIntroTimer();
resetIntroTimer();
break;
case kMenuCmdNoCommand:
break;
Expand Down
4 changes: 4 additions & 0 deletions engines/pegasus/pegasus.h
Expand Up @@ -39,6 +39,7 @@
#include "pegasus/hotspot.h"
#include "pegasus/input.h"
#include "pegasus/notification.h"
#include "pegasus/timers.h"
#include "pegasus/items/autodragger.h"
#include "pegasus/items/inventory.h"
#include "pegasus/items/itemdragger.h"
Expand Down Expand Up @@ -99,6 +100,7 @@ friend class InputHandler;
void removeTimeBase(TimeBase *timeBase);
void delayShell(TimeValue time, TimeScale scale);
void resetIntroTimer();
void introTimerExpired();
void refreshDisplay();
bool playerAlive();
void processShell();
Expand Down Expand Up @@ -210,8 +212,10 @@ friend class InputHandler;

// Intro
void runIntro();
void stopIntroTimer();
bool detectOpeningClosingDirectory();
Common::String _introDirectory;
FuseFunction *_introTimer;

// Idlers
Idler *_idlerHead;
Expand Down

0 comments on commit 1ec7e51

Please sign in to comment.