diff options
Diffstat (limited to 'engines')
-rw-r--r-- | engines/illusions/backgroundresource.cpp | 36 | ||||
-rw-r--r-- | engines/illusions/backgroundresource.h | 3 | ||||
-rw-r--r-- | engines/illusions/camera.cpp | 140 | ||||
-rw-r--r-- | engines/illusions/camera.h | 17 | ||||
-rw-r--r-- | engines/illusions/illusions.cpp | 2 | ||||
-rw-r--r-- | engines/illusions/illusions.h | 2 |
6 files changed, 193 insertions, 7 deletions
diff --git a/engines/illusions/backgroundresource.cpp b/engines/illusions/backgroundresource.cpp index 11a5957f28..3ac2a58bda 100644 --- a/engines/illusions/backgroundresource.cpp +++ b/engines/illusions/backgroundresource.cpp @@ -22,6 +22,7 @@ #include "illusions/illusions.h" #include "illusions/backgroundresource.h" +#include "illusions/camera.h" #include "common/str.h" namespace Illusions { @@ -215,8 +216,27 @@ void BackgroundItem::unpause() { /* TODO currTime = krnxxxGetCurrentTime(); _vm->_camera.panStartTime = currTime; - _vm->backgroundItem_refreshPan(); */ + _vm->_backgroundItems->refreshPan(); + } +} + +void BackgroundItem::refreshPan(WidthHeight &dimensions) { + Common::Point screenOffs = _vm->_camera->getScreenOffset(); + int x = dimensions._width - 640; + int y = dimensions._height - 480; + for (uint i = 0; i < _bgRes->_bgInfosCount; ++i) { + const BgInfo &bgInfo = _bgRes->_bgInfos[i]; + if (bgInfo._flags & 1) { + _panPoints[i] = screenOffs; + } else { + Common::Point newOffs(0, 0); + if (x > 0 && bgInfo._surfInfo._dimensions._width - 640 > 0) + newOffs.x = screenOffs.x * (bgInfo._surfInfo._dimensions._width - 640) / x; + if (y > 0 && bgInfo._surfInfo._dimensions._height - 480 > 0) + newOffs.y = screenOffs.y * (bgInfo._surfInfo._dimensions._height - 480) / y; + _panPoints[i] = newOffs; + } } } @@ -261,6 +281,20 @@ BackgroundResource *BackgroundItems::getActiveBgResource() { return 0; } +WidthHeight BackgroundItems::getMasterBgDimensions() { + BackgroundItem *backgroundItem = findActiveBackground(); + int16 index = backgroundItem->_bgRes->findMasterBgIndex(); + return backgroundItem->_bgRes->_bgInfos[index - 1]._surfInfo._dimensions; +} + +void BackgroundItems::refreshPan() { + BackgroundItem *backgroundItem = findActiveBackground(); + if (backgroundItem) { + WidthHeight dimensions = getMasterBgDimensions(); + backgroundItem->refreshPan(dimensions); + } +} + BackgroundItem *BackgroundItems::debugFirst() { return *(_items.begin()); } diff --git a/engines/illusions/backgroundresource.h b/engines/illusions/backgroundresource.h index 7fc70ae5c2..a12804bddb 100644 --- a/engines/illusions/backgroundresource.h +++ b/engines/illusions/backgroundresource.h @@ -93,6 +93,7 @@ public: void drawTiles(Graphics::Surface *surface, TileMap &tileMap, byte *tilePixels); void pause(); void unpause(); + void refreshPan(WidthHeight &dimensions); public: IllusionsEngine *_vm; uint32 _tag; @@ -113,6 +114,8 @@ public: void unpauseByTag(uint32 tag); BackgroundItem *findActiveBackground(); BackgroundResource *getActiveBgResource(); + WidthHeight getMasterBgDimensions(); + void refreshPan(); BackgroundItem *debugFirst(); protected: typedef Common::List<BackgroundItem*> Items; diff --git a/engines/illusions/camera.cpp b/engines/illusions/camera.cpp index 76addb6aca..df5de4b083 100644 --- a/engines/illusions/camera.cpp +++ b/engines/illusions/camera.cpp @@ -20,14 +20,17 @@ * */ +#include "illusions/illusions.h" #include "illusions/camera.h" +#include "illusions/backgroundresource.h" #include "illusions/time.h" namespace Illusions { -Camera::Camera() { +Camera::Camera(IllusionsEngine *vm) + : _vm(vm) { _activeState._cameraMode = 6; - _activeState._paused = 0; + _activeState._paused = false; _activeState._panStartTime = getCurrentTime(); _activeState._panSpeed = 1; _activeState._bounds._topLeft.x = 320; @@ -55,7 +58,7 @@ void Camera::clearStack() { void Camera::set(Common::Point &panPoint, WidthHeight &dimensions) { _activeState._cameraMode = 6; - _activeState._paused = 0; + _activeState._paused = false; _activeState._panStartTime = getCurrentTime(); _activeState._panSpeed = 1; _activeState._bounds._topLeft.x = 320; @@ -67,7 +70,7 @@ void Camera::set(Common::Point &panPoint, WidthHeight &dimensions) { _activeState._currPan = _activeState._panTargetPoint; _activeState._panXShl = _activeState._currPan.x << 16; _activeState._panYShl = _activeState._currPan.y << 16; - // TODO largeObj_backgroundItem_refreshPan(); + _vm->_backgroundItems->refreshPan(); _activeState._panToPositionPtr = 0; _activeState._panObjectId = 0; _activeState._panNotifyId = 0; @@ -78,8 +81,137 @@ void Camera::set(Common::Point &panPoint, WidthHeight &dimensions) { _activeState._pt.y = 240; } +void Camera::pause() { + _activeState._pauseStartTime = getCurrentTime(); + _activeState._paused = true; +} + +void Camera::unpause() { + _activeState._paused = false; + uint32 pauseDuration = getCurrentTime() - _activeState._pauseStartTime; + _activeState._time28 += pauseDuration; + _activeState._panStartTime += pauseDuration; +} + +void Camera::update(uint32 currTime) { + + if (_activeState._paused) + return; + + switch (_activeState._cameraMode) { + case 1: + updateMode1(currTime); + break; + case 2: + updateMode2(currTime); + break; + case 3: + updateMode3(currTime); + break; + } + + if (_activeState._cameraMode != 6) { + + if (!isPanFinished() && updatePan(currTime)) { + /* Unused + if (_activeState._cameraMode == 1 || _activeState._cameraMode == 5) + nullsub_2(); + */ + _vm->_backgroundItems->refreshPan(); + } + + if (isPanFinished()) { + if (_activeState._cameraMode == 5) { + // Notify a thread that the camera panning has finished + if (_activeState._panNotifyId) { + // TODO scrmgrNotifyID(_activeState._panNotifyId); + _activeState._panNotifyId = 0; + } + _activeState._cameraMode = 6; + } else if (_activeState._cameraMode == 4) { + _activeState._cameraMode = 3; + } + } + + } + +} + +void Camera::setBounds(Common::Point &minPt, Common::Point &maxPt) { + _activeState._bounds._topLeft = minPt; + _activeState._bounds._bottomRight = maxPt; +} + +void Camera::setBoundsToDimensions(WidthHeight &dimensions) { + // NOTE For the caller dimensions = artdispGetMasterBGDimensions(); + _activeState._bounds._topLeft.x = 320; + _activeState._bounds._topLeft.y = 240; + _activeState._bounds._bottomRight.x = MAX(0, dimensions._width - 640) + 320; + _activeState._bounds._bottomRight.y = MAX(0, dimensions._height - 480) + 240; + // TODO camera_clipPanTargetPoint(); +} + Common::Point Camera::getCurrentPan() { return _activeState._currPan; } +Common::Point Camera::getScreenOffset() { + Common::Point screenOffs = getCurrentPan(); + screenOffs.x -= 320; + screenOffs.y -= 240; + return screenOffs; +} + +void Camera::updateMode1(uint32 currTime) { + Common::Point ptOffs = getPtOffset(*_activeState._panToPositionPtr); + int deltaX = ptOffs.x - _activeState._currPan.x + 320 - _activeState._pt.x; + int deltaY = ptOffs.y - _activeState._currPan.y + 240 - _activeState._pt.y; + int deltaXAbs = ABS(deltaX); + int deltaYAbs = ABS(deltaY); + + if (deltaXAbs > _activeState._trackingLimits.x) { + _activeState._panTargetPoint.x = _activeState._currPan.x + ABS(deltaXAbs - _activeState._trackingLimits.x) * (deltaX >= 0 ? 1 : -1); + } else { + _activeState._panTargetPoint.x = _activeState._currPan.x; + } + + if (deltaYAbs > _activeState._trackingLimits.y) { + _activeState._panTargetPoint.y = _activeState._currPan.y + ABS(deltaYAbs - _activeState._trackingLimits.y) * (deltaY >= 0 ? 1 : -1); + } else { + _activeState._panTargetPoint.y = _activeState._currPan.y; + } + + // TODO Camera_clipPanTargetPoint(); + + if (!isPanFinished()) { + uint32 oldPanTime = _activeState._panStartTime; + _activeState._panStartTime = _activeState._time28; + // TODO Camera_recalcPan(oldPanTime); + } + +} + +void Camera::updateMode2(uint32 currTime) { + // TODO +} + +void Camera::updateMode3(uint32 currTime) { + // TODO +} + +bool Camera::updatePan(uint32 currTime) { + // TODO + return false; +} + +bool Camera::isPanFinished() { + return _activeState._currPan.x == _activeState._panTargetPoint.x && _activeState._currPan.y == _activeState._panTargetPoint.y; +} + +Common::Point Camera::getPtOffset(Common::Point pt) { + pt.x = pt.x - _activeState._pt.x + 320; + pt.y = pt.y - _activeState._pt.y + 240; + return pt; +} + } // End of namespace Illusions diff --git a/engines/illusions/camera.h b/engines/illusions/camera.h index fae3c328ac..816c5dda21 100644 --- a/engines/illusions/camera.h +++ b/engines/illusions/camera.h @@ -32,7 +32,7 @@ namespace Illusions { struct CameraState { int _cameraMode; //field_2 dw - int16 _paused; + bool _paused; int16 _panSpeed; int _someX, _someY; Common::Point _currPan; @@ -55,13 +55,26 @@ struct CameraState { class Camera { public: - Camera(); + Camera(IllusionsEngine *vm); void clearStack(); void set(Common::Point &panPoint, WidthHeight &dimensions); + void pause(); + void unpause(); + void update(uint32 currTime); + void setBounds(Common::Point &minPt, Common::Point &maxPt); + void setBoundsToDimensions(WidthHeight &dimensions); Common::Point getCurrentPan(); + Common::Point getScreenOffset(); protected: + IllusionsEngine *_vm; CameraState _activeState; Common::FixedStack<CameraState, 8> _stack; + void updateMode1(uint32 currTime); + void updateMode2(uint32 currTime); + void updateMode3(uint32 currTime); + bool updatePan(uint32 currTime); + bool isPanFinished(); + Common::Point getPtOffset(Common::Point pt); }; } // End of namespace Illusions diff --git a/engines/illusions/illusions.cpp b/engines/illusions/illusions.cpp index 6bfecd32c4..47ed48cc09 100644 --- a/engines/illusions/illusions.cpp +++ b/engines/illusions/illusions.cpp @@ -79,6 +79,7 @@ Common::Error IllusionsEngine::run() { _resSys = new ResourceSystem(); _resSys->addResourceLoader(0x00110000, new BackgroundResourceLoader(this)); _backgroundItems = new BackgroundItems(this); + _camera = new Camera(this); _resSys->loadResource(0x0011000B, 0, 0); @@ -91,6 +92,7 @@ Common::Error IllusionsEngine::run() { updateEvents(); } + delete _camera; delete _backgroundItems; delete _resSys; diff --git a/engines/illusions/illusions.h b/engines/illusions/illusions.h index 6ebf2e7813..f7348675af 100644 --- a/engines/illusions/illusions.h +++ b/engines/illusions/illusions.h @@ -51,6 +51,7 @@ struct SurfInfo; class BackgroundItem; class BackgroundItems; class BackgroundResource; +class Camera; class IllusionsEngine : public Engine { protected: @@ -71,6 +72,7 @@ public: void updateEvents(); BackgroundItems *_backgroundItems; + Camera *_camera; // Screen functions Graphics::Surface *allocSurface(int16 width, int16 height); |