From 4f358e7615f7d68887eb3ab608a9d7ce1d9a4d93 Mon Sep 17 00:00:00 2001 From: Matthew Hoops Date: Mon, 26 Sep 2011 12:36:50 -0400 Subject: PEGASUS: Begin populating the Neighborhood class with more useful functions --- engines/pegasus/ai/ai_condition.cpp | 1 + engines/pegasus/elements.h | 1 - engines/pegasus/energymonitor.cpp | 1 + engines/pegasus/fader.cpp | 1 + engines/pegasus/neighborhood/neighborhood.cpp | 97 ++++++++++++++++++++++++++- engines/pegasus/neighborhood/neighborhood.h | 45 ++++++++++++- 6 files changed, 141 insertions(+), 5 deletions(-) diff --git a/engines/pegasus/ai/ai_condition.cpp b/engines/pegasus/ai/ai_condition.cpp index dbb66ddf0f..f01d5f9380 100755 --- a/engines/pegasus/ai/ai_condition.cpp +++ b/engines/pegasus/ai/ai_condition.cpp @@ -28,6 +28,7 @@ #include "pegasus/energymonitor.h" #include "pegasus/gamestate.h" #include "pegasus/ai/ai_condition.h" +#include "pegasus/items/itemlist.h" #include "pegasus/items/biochips/biochipitem.h" #include "pegasus/items/inventory/inventoryitem.h" diff --git a/engines/pegasus/elements.h b/engines/pegasus/elements.h index 46b3bc5927..f806f26a17 100644 --- a/engines/pegasus/elements.h +++ b/engines/pegasus/elements.h @@ -32,7 +32,6 @@ #include "graphics/pict.h" #include "graphics/surface.h" -#include "pegasus/pegasus.h" #include "pegasus/timers.h" #include "pegasus/util.h" diff --git a/engines/pegasus/energymonitor.cpp b/engines/pegasus/energymonitor.cpp index b1ea04435b..9a82e36d84 100755 --- a/engines/pegasus/energymonitor.cpp +++ b/engines/pegasus/energymonitor.cpp @@ -24,6 +24,7 @@ */ #include "pegasus/energymonitor.h" +#include "pegasus/pegasus.h" #include "pegasus/surface.h" namespace Pegasus { diff --git a/engines/pegasus/fader.cpp b/engines/pegasus/fader.cpp index 3d8305b2c9..8eb1c0176a 100755 --- a/engines/pegasus/fader.cpp +++ b/engines/pegasus/fader.cpp @@ -24,6 +24,7 @@ */ #include "pegasus/fader.h" +#include "pegasus/sound.h" #include "pegasus/util.h" namespace Pegasus { diff --git a/engines/pegasus/neighborhood/neighborhood.cpp b/engines/pegasus/neighborhood/neighborhood.cpp index 6f0bf79959..cba6fd96ee 100644 --- a/engines/pegasus/neighborhood/neighborhood.cpp +++ b/engines/pegasus/neighborhood/neighborhood.cpp @@ -26,6 +26,7 @@ #include "common/debug.h" #include "common/stream.h" +#include "pegasus/compass.h" #include "pegasus/gamestate.h" #include "pegasus/input.h" #include "pegasus/pegasus.h" @@ -33,9 +34,21 @@ namespace Pegasus { +StriderCallBack::StriderCallBack(Neighborhood *neighborhood) { + _neighborhood = neighborhood; +} + +void StriderCallBack::callBack() { + _neighborhood->checkStriding(); +} + +static const TimeValue kStridingSlop = 39; + Neighborhood *g_neighborhood = 0; -Neighborhood::Neighborhood(InputHandler *nextHandler, PegasusEngine *vm, const Common::String &resName, tNeighborhoodID id) : InputHandler(nextHandler), IDObject(id), _vm(vm), _resName(resName) { +Neighborhood::Neighborhood(InputHandler *nextHandler, PegasusEngine *vm, const Common::String &resName, tNeighborhoodID id) + : InputHandler(nextHandler), IDObject(id), _vm(vm), _resName(resName), _navMovie(kNavMovieID), _stridingCallBack(this), + _neighborhoodNotification(kNeighborhoodNotificationID, (NotificationManager *)vm) { GameState.setOpenDoorLocation(kNoRoomID, kNoDirection); _currentAlternate = 0; _interruptionFilter = kFilterAllInput; @@ -435,4 +448,86 @@ tAirQuality Neighborhood::getAirQuality(const tRoomID) { return kAirQualityGood; } +void Neighborhood::checkStriding() { + if (stillMoveForward()) { + ExitTable::Entry nextExit; + getExitEntry(GameState.getNextRoom(), GameState.getNextDirection(), nextExit); + keepStriding(nextExit); + } else { + stopStriding(); + } +} + +bool Neighborhood::stillMoveForward() { + Input input; + + InputHandler::readInputDevice(input); + return input.upButtonAnyDown(); +} + +void Neighborhood::keepStriding(ExitTable::Entry &nextExitEntry) { + FaderMoveSpec compassMove; + + // TODO: Map + if (g_compass) + getExitCompassMove(nextExitEntry, compassMove); + + GameState.setCurrentRoom(GameState.getNextRoom()); + GameState.setCurrentDirection(GameState.getNextDirection()); + GameState.setNextRoom(nextExitEntry.exitRoom); + GameState.setNextDirection(nextExitEntry.exitDirection); + + if (nextExitEntry.movieEnd == nextExitEntry.exitEnd) + scheduleNavCallBack(kNeighborhoodMovieCompletedFlag | kMoveForwardCompletedFlag); + else + scheduleStridingCallBack(nextExitEntry.movieEnd - kStridingSlop, kStrideCompletedFlag); + + if (g_compass) + g_compass->startFader(compassMove); +} + +void Neighborhood::stopStriding() { + _navMovie.stop(); + _neighborhoodNotification.setNotificationFlags(kNeighborhoodMovieCompletedFlag | + kMoveForwardCompletedFlag, kNeighborhoodMovieCompletedFlag | kMoveForwardCompletedFlag); +} + +// Compass support +uint16 Neighborhood::getStaticCompassAngle(const tRoomID, const tDirectionConstant dir) { + // North, south, east, west + static const uint16 compassAngles[] = { 0, 180, 90, 270 }; + return compassAngles[dir]; +} + +void Neighborhood::getExitCompassMove(const ExitTable::Entry &exitEntry, FaderMoveSpec &compassMove) { + int32 startAngle = getStaticCompassAngle(exitEntry.room, exitEntry.direction); + int32 stopAngle = getStaticCompassAngle(exitEntry.exitRoom, exitEntry.exitDirection); + + if (startAngle > stopAngle) { + if (stopAngle + 180 < startAngle) + stopAngle += 360; + } else { + if (startAngle + 180 < stopAngle) + startAngle += 360; + } + + compassMove.makeTwoKnotFaderSpec(_navMovie.getScale(), exitEntry.movieStart, startAngle, exitEntry.movieEnd, stopAngle); +} + +void Neighborhood::scheduleNavCallBack(tNotificationFlags flags) { + _navMovieCallBack.cancelCallBack(); + + if (flags != 0) { + _navMovieCallBack.setCallBackFlag(flags); + _navMovieCallBack.scheduleCallBack(kTriggerAtStop, 0, 0); + } +} + +void Neighborhood::scheduleStridingCallBack(const TimeValue strideStop, tNotificationFlags flags) { + _stridingCallBack.cancelCallBack(); + + if (flags != 0) + _stridingCallBack.scheduleCallBack(kTriggerTimeFwd, strideStop, _navMovie.getScale()); +} + } // End of namespace Pegasus diff --git a/engines/pegasus/neighborhood/neighborhood.h b/engines/pegasus/neighborhood/neighborhood.h index fcfc833a52..5d3e75bf3a 100644 --- a/engines/pegasus/neighborhood/neighborhood.h +++ b/engines/pegasus/neighborhood/neighborhood.h @@ -29,10 +29,13 @@ #include "common/queue.h" #include "common/str.h" +#include "pegasus/fader.h" #include "pegasus/hotspot.h" #include "pegasus/input.h" +#include "pegasus/movie.h" #include "pegasus/notification.h" #include "pegasus/sound.h" +#include "pegasus/timers.h" #include "pegasus/util.h" #include "pegasus/neighborhood/door.h" #include "pegasus/neighborhood/exit.h" @@ -83,9 +86,24 @@ struct tQueueRequest { bool operator==(const tQueueRequest &arg1, const tQueueRequest &arg2); bool operator!=(const tQueueRequest &arg1, const tQueueRequest &arg2); +class Neighborhood; + +class StriderCallBack : public TimeBaseCallBack { +public: + StriderCallBack(Neighborhood *); + virtual ~StriderCallBack() {} + +protected: + virtual void callBack(); + + Neighborhood *_neighborhood; +}; + typedef Common::Queue NeighborhoodActionQueue; class Neighborhood : public IDObject, public NotificationReceiver, public InputHandler { +friend class StriderCallBack; + public: Neighborhood(InputHandler *nextHandler, PegasusEngine *vm, const Common::String &resName, tNeighborhoodID id); virtual ~Neighborhood(); @@ -131,19 +149,30 @@ public: virtual void shieldOn() {} virtual void shieldOff() {} + virtual void scheduleNavCallBack(tNotificationFlags); + protected: + PegasusEngine *_vm; + Common::String _resName; + virtual void receiveNotification(Notification *, const tNotificationFlags); virtual void createNeighborhoodSpots(); virtual void loadSoundSpots(); + // Nav movie sequences. + virtual void checkStriding(); + virtual void keepStriding(ExitTable::Entry &); + virtual void stopStriding(); + virtual bool stillMoveForward(); + virtual void scheduleStridingCallBack(const TimeValue, tNotificationFlags flags); + + // Action queue stuff void popActionQueue(); void serviceActionQueue(); void requestAction(const tQueueRequestType, const tExtraID, const TimeValue, const TimeValue, const tInputBits, const tNotificationFlags); - PegasusEngine *_vm; - Common::String _resName; - + // Navigation Data DoorTable _doorTable; ExitTable _exitTable; ExtraTable _extraTable; @@ -152,6 +181,16 @@ protected: TurnTable _turnTable; ViewTable _viewTable; ZoomTable _zoomTable; + virtual uint16 getStaticCompassAngle(const tRoomID, const tDirectionConstant dir); + virtual void getExitCompassMove(const ExitTable::Entry &, FaderMoveSpec &); + + // Graphics + Movie _navMovie; + + // Callbacks + Notification _neighborhoodNotification; + NotificationCallBack _navMovieCallBack; + StriderCallBack _stridingCallBack; tAlternateID _currentAlternate; -- cgit v1.2.3