diff options
-rw-r--r-- | scumm/camera.cpp | 257 | ||||
-rw-r--r-- | scumm/intern.h | 3 | ||||
-rw-r--r-- | scumm/scumm.h | 4 |
3 files changed, 133 insertions, 131 deletions
diff --git a/scumm/camera.cpp b/scumm/camera.cpp index 5e21944ef1..7a9fab4714 100644 --- a/scumm/camera.cpp +++ b/scumm/camera.cpp @@ -147,167 +147,168 @@ void Scumm::clampCameraPos(ScummVM::Point *pt) { } void Scumm::moveCamera() { - if (_features & GF_AFTER_V7) { - ScummVM::Point old = camera._cur; - Actor *a = NULL; + int pos = camera._cur.x; + int actorx, t; + Actor *a = NULL; + + camera._cur.x &= 0xFFF8; - if (camera._follows) { - a = derefActor(camera._follows, "moveCamera"); - if (abs(camera._cur.x - a->x) > VAR(VAR_CAMERA_THRESHOLD_X) || - abs(camera._cur.y - a->y) > VAR(VAR_CAMERA_THRESHOLD_Y)) { + if (camera._cur.x < VAR(VAR_CAMERA_MIN_X)) { + if (VAR_CAMERA_FAST_X != 0xFF && VAR(VAR_CAMERA_FAST_X)) + camera._cur.x = (short) VAR(VAR_CAMERA_MIN_X); + else + camera._cur.x += 8; + cameraMoved(); + return; + } + + if (camera._cur.x > VAR(VAR_CAMERA_MAX_X)) { + if (VAR_CAMERA_FAST_X != 0xFF && VAR(VAR_CAMERA_FAST_X)) + camera._cur.x = (short) VAR(VAR_CAMERA_MAX_X); + else + camera._cur.x -= 8; + cameraMoved(); + return; + } + + if (camera._mode == CM_FOLLOW_ACTOR) { + a = derefActor(camera._follows, "moveCamera"); + + actorx = a->x; + t = (actorx >> 3) - _screenStartStrip; + + if (t < camera._leftTrigger || t > camera._rightTrigger) { + if (VAR_CAMERA_FAST_X != 0xFF && VAR(VAR_CAMERA_FAST_X)) { + if (t > 35) + camera._dest.x = actorx + 80; + if (t < 5) + camera._dest.x = actorx - 80; + } else camera._movingToActor = true; - if (VAR(VAR_CAMERA_THRESHOLD_X) == 0) - camera._cur.x = a->x; - if (VAR(VAR_CAMERA_THRESHOLD_Y) == 0) - camera._cur.y = a->y; - clampCameraPos(&camera._cur); - } - } else { - camera._movingToActor = false; } + } - if (camera._movingToActor) { - VAR(VAR_CAMERA_DEST_X) = camera._dest.x = a->x; - VAR(VAR_CAMERA_DEST_Y) = camera._dest.y = a->y; - } + if (camera._movingToActor) { + a = derefActor(camera._follows, "moveCamera(2)"); + camera._dest.x = a->x; + } - assert(camera._cur.x >= (_screenWidth / 2) && camera._cur.y >= (_screenHeight / 2)); + if (camera._dest.x < VAR(VAR_CAMERA_MIN_X)) + camera._dest.x = (short) VAR(VAR_CAMERA_MIN_X); - clampCameraPos(&camera._dest); + if (camera._dest.x > VAR(VAR_CAMERA_MAX_X)) + camera._dest.x = (short) VAR(VAR_CAMERA_MAX_X); - if (camera._cur.x < camera._dest.x) { - camera._cur.x += (short) VAR(VAR_CAMERA_SPEED_X); - if (camera._cur.x > camera._dest.x) - camera._cur.x = camera._dest.x; - } + if (VAR_CAMERA_FAST_X != 0xFF && VAR(VAR_CAMERA_FAST_X)) { + camera._cur.x = camera._dest.x; + } else { + if (camera._cur.x < camera._dest.x) + camera._cur.x += 8; + if (camera._cur.x > camera._dest.x) + camera._cur.x -= 8; + } - if (camera._cur.x > camera._dest.x) { - camera._cur.x -= (short) VAR(VAR_CAMERA_SPEED_X); - if (camera._cur.x < camera._dest.x) - camera._cur.x = camera._dest.x; - } + /* a is set a bit above */ + if (camera._movingToActor && (camera._cur.x >> 3) == (a->x >> 3)) { + camera._movingToActor = false; + } - if (camera._cur.y < camera._dest.y) { - camera._cur.y += (short) VAR(VAR_CAMERA_SPEED_Y); - if (camera._cur.y > camera._dest.y) - camera._cur.y = camera._dest.y; - } + cameraMoved(); - if (camera._cur.y > camera._dest.y) { - camera._cur.y -= (short) VAR(VAR_CAMERA_SPEED_Y); - if (camera._cur.y < camera._dest.y) - camera._cur.y = camera._dest.y; - } + if (VAR_SCROLL_SCRIPT != 0xFF && VAR(VAR_SCROLL_SCRIPT) && pos != camera._cur.x) { + if (_features & GF_AFTER_V2) + VAR(VAR_CAMERA_POS_X) = camera._cur.x / 8; + else + VAR(VAR_CAMERA_POS_X) = camera._cur.x; + runScript(VAR(VAR_SCROLL_SCRIPT), 0, 0, 0); + } +} - if (camera._cur.x == camera._dest.x && camera._cur.y == camera._dest.y) { +void Scumm_v7::moveCamera() { + ScummVM::Point old = camera._cur; + Actor *a = NULL; + + if (camera._follows) { + a = derefActor(camera._follows, "moveCamera"); + if (abs(camera._cur.x - a->x) > VAR(VAR_CAMERA_THRESHOLD_X) || + abs(camera._cur.y - a->y) > VAR(VAR_CAMERA_THRESHOLD_Y)) { + camera._movingToActor = true; + if (VAR(VAR_CAMERA_THRESHOLD_X) == 0) + camera._cur.x = a->x; + if (VAR(VAR_CAMERA_THRESHOLD_Y) == 0) + camera._cur.y = a->y; + clampCameraPos(&camera._cur); + } + } else { + camera._movingToActor = false; + } - camera._movingToActor = false; - camera._accel.x = camera._accel.y = 0; - VAR(VAR_CAMERA_SPEED_X) = VAR(VAR_CAMERA_SPEED_Y) = 0; - } else { + if (camera._movingToActor) { + VAR(VAR_CAMERA_DEST_X) = camera._dest.x = a->x; + VAR(VAR_CAMERA_DEST_Y) = camera._dest.y = a->y; + } - camera._accel.x += (short) VAR(VAR_CAMERA_ACCEL_X); - camera._accel.y += (short) VAR(VAR_CAMERA_ACCEL_Y); + assert(camera._cur.x >= (_screenWidth / 2) && camera._cur.y >= (_screenHeight / 2)); - VAR(VAR_CAMERA_SPEED_X) += camera._accel.x / 100; - VAR(VAR_CAMERA_SPEED_Y) += camera._accel.y / 100; + clampCameraPos(&camera._dest); - if (VAR(VAR_CAMERA_SPEED_X) < 8) - VAR(VAR_CAMERA_SPEED_X) = 8; + if (camera._cur.x < camera._dest.x) { + camera._cur.x += (short) VAR(VAR_CAMERA_SPEED_X); + if (camera._cur.x > camera._dest.x) + camera._cur.x = camera._dest.x; + } - if (VAR(VAR_CAMERA_SPEED_Y) < 8) - VAR(VAR_CAMERA_SPEED_Y) = 8; + if (camera._cur.x > camera._dest.x) { + camera._cur.x -= (short) VAR(VAR_CAMERA_SPEED_X); + if (camera._cur.x < camera._dest.x) + camera._cur.x = camera._dest.x; + } - } + if (camera._cur.y < camera._dest.y) { + camera._cur.y += (short) VAR(VAR_CAMERA_SPEED_Y); + if (camera._cur.y > camera._dest.y) + camera._cur.y = camera._dest.y; + } - cameraMoved(); + if (camera._cur.y > camera._dest.y) { + camera._cur.y -= (short) VAR(VAR_CAMERA_SPEED_Y); + if (camera._cur.y < camera._dest.y) + camera._cur.y = camera._dest.y; + } - if (camera._cur.x != old.x || camera._cur.y != old.y) { - VAR(VAR_CAMERA_POS_X) = camera._cur.x; - VAR(VAR_CAMERA_POS_Y) = camera._cur.y; + if (camera._cur.x == camera._dest.x && camera._cur.y == camera._dest.y) { - if (VAR(VAR_SCROLL_SCRIPT)) - runScript(VAR(VAR_SCROLL_SCRIPT), 0, 0, 0); - } + camera._movingToActor = false; + camera._accel.x = camera._accel.y = 0; + VAR(VAR_CAMERA_SPEED_X) = VAR(VAR_CAMERA_SPEED_Y) = 0; } else { - int pos = camera._cur.x; - int actorx, t; - Actor *a = NULL; - - camera._cur.x &= 0xFFF8; - - if (camera._cur.x < VAR(VAR_CAMERA_MIN_X)) { - if (VAR_CAMERA_FAST_X != 0xFF && VAR(VAR_CAMERA_FAST_X)) - camera._cur.x = (short) VAR(VAR_CAMERA_MIN_X); - else - camera._cur.x += 8; - cameraMoved(); - return; - } - if (camera._cur.x > VAR(VAR_CAMERA_MAX_X)) { - if (VAR_CAMERA_FAST_X != 0xFF && VAR(VAR_CAMERA_FAST_X)) - camera._cur.x = (short) VAR(VAR_CAMERA_MAX_X); - else - camera._cur.x -= 8; - cameraMoved(); - return; - } + camera._accel.x += (short) VAR(VAR_CAMERA_ACCEL_X); + camera._accel.y += (short) VAR(VAR_CAMERA_ACCEL_Y); - if (camera._mode == CM_FOLLOW_ACTOR) { - a = derefActor(camera._follows, "moveCamera"); - - actorx = a->x; - t = (actorx >> 3) - _screenStartStrip; - - if (t < camera._leftTrigger || t > camera._rightTrigger) { - if (VAR_CAMERA_FAST_X != 0xFF && VAR(VAR_CAMERA_FAST_X)) { - if (t > 35) - camera._dest.x = actorx + 80; - if (t < 5) - camera._dest.x = actorx - 80; - } else - camera._movingToActor = true; - } - } + VAR(VAR_CAMERA_SPEED_X) += camera._accel.x / 100; + VAR(VAR_CAMERA_SPEED_Y) += camera._accel.y / 100; - if (camera._movingToActor) { - a = derefActor(camera._follows, "moveCamera(2)"); - camera._dest.x = a->x; - } + if (VAR(VAR_CAMERA_SPEED_X) < 8) + VAR(VAR_CAMERA_SPEED_X) = 8; - if (camera._dest.x < VAR(VAR_CAMERA_MIN_X)) - camera._dest.x = (short) VAR(VAR_CAMERA_MIN_X); + if (VAR(VAR_CAMERA_SPEED_Y) < 8) + VAR(VAR_CAMERA_SPEED_Y) = 8; - if (camera._dest.x > VAR(VAR_CAMERA_MAX_X)) - camera._dest.x = (short) VAR(VAR_CAMERA_MAX_X); + } - if (VAR_CAMERA_FAST_X != 0xFF && VAR(VAR_CAMERA_FAST_X)) { - camera._cur.x = camera._dest.x; - } else { - if (camera._cur.x < camera._dest.x) - camera._cur.x += 8; - if (camera._cur.x > camera._dest.x) - camera._cur.x -= 8; - } + cameraMoved(); - /* a is set a bit above */ - if (camera._movingToActor && (camera._cur.x >> 3) == (a->x >> 3)) { - camera._movingToActor = false; - } + if (camera._cur.x != old.x || camera._cur.y != old.y) { + VAR(VAR_CAMERA_POS_X) = camera._cur.x; + VAR(VAR_CAMERA_POS_Y) = camera._cur.y; - cameraMoved(); - - if (VAR_SCROLL_SCRIPT != 0xFF && VAR(VAR_SCROLL_SCRIPT) && pos != camera._cur.x) { - if (_features & GF_AFTER_V2) - VAR(VAR_CAMERA_POS_X) = camera._cur.x / 8; - else - VAR(VAR_CAMERA_POS_X) = camera._cur.x; + if (VAR(VAR_SCROLL_SCRIPT)) runScript(VAR(VAR_SCROLL_SCRIPT), 0, 0, 0); - } } } + void Scumm::cameraMoved() { if (_features & GF_AFTER_V7) { assert(camera._cur.x >= (_screenWidth / 2) && camera._cur.y >= (_screenHeight / 2)); diff --git a/scumm/intern.h b/scumm/intern.h index efd16eb17f..55216fb80b 100644 --- a/scumm/intern.h +++ b/scumm/intern.h @@ -522,8 +522,9 @@ protected: virtual void setupScummVars(); virtual void setCameraAt(int pos_x, int pos_y); - virtual void panCameraTo(int x, int y); virtual void setCameraFollows(Actor *a); + virtual void moveCamera(); + virtual void panCameraTo(int x, int y); }; class Scumm_v8 : public Scumm_v7 { diff --git a/scumm/scumm.h b/scumm/scumm.h index 2b9f208049..fda5c68b2d 100644 --- a/scumm/scumm.h +++ b/scumm/scumm.h @@ -816,12 +816,12 @@ protected: void redrawBGStrip(int start, int num); void redrawBGAreas(); - void moveCamera(); void cameraMoved(); void setCameraAtEx(int at); virtual void setCameraAt(int pos_x, int pos_y); - virtual void panCameraTo(int x, int y); virtual void setCameraFollows(Actor *a); + virtual void moveCamera(); + virtual void panCameraTo(int x, int y); void clampCameraPos(ScummVM::Point *pt); void actorFollowCamera(int act); |