From 335e9da41dfe5f019c83478f8ffe95b0a8807dd4 Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Thu, 20 Dec 2007 19:00:10 +0000 Subject: Removed clamp() and used the common CLIP template instead svn-id: r29927 --- engines/saga/actor.cpp | 10 +++++----- engines/saga/actor_walk.cpp | 18 +++++++++--------- engines/saga/gfx.cpp | 4 ++-- engines/saga/interface.cpp | 4 ++-- engines/saga/isomap.cpp | 20 ++++++++++---------- engines/saga/saga.h | 12 ------------ engines/saga/scene.cpp | 4 ++-- 7 files changed, 30 insertions(+), 42 deletions(-) diff --git a/engines/saga/actor.cpp b/engines/saga/actor.cpp index 8e289ae4b6..93e0297343 100644 --- a/engines/saga/actor.cpp +++ b/engines/saga/actor.cpp @@ -1102,12 +1102,12 @@ void Actor::drawSpeech(void) { actor = getActor(_activeSpeech.actorIds[i]); calcScreenPosition(actor); - textPoint.x = clamp(10, actor->_screenPosition.x - width / 2, _vm->getDisplayWidth() - 10 - width); + textPoint.x = CLIP(actor->_screenPosition.x - width / 2, 10, _vm->getDisplayWidth() - 10 - width); if (_vm->getGameType() == GType_ITE) - textPoint.y = clamp(10, actor->_screenPosition.y - 58, _vm->_scene->getHeight(true) - 10 - height); + textPoint.y = CLIP(actor->_screenPosition.y - 58, 10, _vm->_scene->getHeight(true) - 10 - height); else if (_vm->getGameType() == GType_IHNM) - textPoint.y = 10; // clamp(10, actor->_screenPosition.y - 160, _vm->_scene->getHeight(true) - 10 - height); + textPoint.y = 10; // CLIP(actor->_screenPosition.y - 160, 10, _vm->_scene->getHeight(true) - 10 - height); _vm->_font->textDraw(kKnownFontScript, backBuffer, outputString, textPoint, _activeSpeech.speechColor[i], _activeSpeech.outlineColor[i], _activeSpeech.getFontFlags(i)); @@ -1144,9 +1144,9 @@ void Actor::actorSpeech(uint16 actorId, const char **strings, int stringsCount, dist = MIN(actor->_screenPosition.x - 10, _vm->getDisplayWidth() - 10 - actor->_screenPosition.x); if (_vm->getGameType() == GType_ITE) - dist = clamp(60, dist, 150); + dist = CLIP(dist, 60, 150); else - dist = clamp(120, dist, 300); + dist = CLIP(dist, 120, 300); _activeSpeech.speechBox.left = actor->_screenPosition.x - dist; _activeSpeech.speechBox.right = actor->_screenPosition.x + dist; diff --git a/engines/saga/actor_walk.cpp b/engines/saga/actor_walk.cpp index ec958d28e4..4c23d4bf93 100644 --- a/engines/saga/actor_walk.cpp +++ b/engines/saga/actor_walk.cpp @@ -422,7 +422,7 @@ void Actor::handleActions(int msec, bool setup) { } if (ABS(delta.v()) > ABS(delta.u())) { - addDelta.v() = clamp(-speed, delta.v(), speed); + addDelta.v() = CLIP(delta.v(), -speed, speed); if (addDelta.v() == delta.v()) { addDelta.u() = delta.u(); } else { @@ -431,7 +431,7 @@ void Actor::handleActions(int msec, bool setup) { addDelta.u() /= delta.v(); } } else { - addDelta.u() = clamp(-speed, delta.u(), speed); + addDelta.u() = CLIP(delta.u(), -speed, speed); if (addDelta.u() == delta.u()) { addDelta.v() = delta.v(); } else { @@ -484,7 +484,7 @@ void Actor::handleActions(int msec, bool setup) { speed = speed / 2; if ((actor->_actionDirection == kDirUp) || (actor->_actionDirection == kDirDown)) { - addDelta.y = clamp(-speed, delta.y, speed); + addDelta.y = CLIP(delta.y, -speed, speed); if (addDelta.y == delta.y) { addDelta.x = delta.x; } else { @@ -494,7 +494,7 @@ void Actor::handleActions(int msec, bool setup) { actor->_facingDirection = actor->_actionDirection; } } else { - addDelta.x = clamp(-2 * speed, delta.x, 2 * speed); + addDelta.x = CLIP(delta.x, -2 * speed, 2 * speed); if (addDelta.x == delta.x) { addDelta.y = delta.y; } else { @@ -785,8 +785,8 @@ bool Actor::followProtagonist(ActorData *actor) { prefU /= 2; prefV /= 2; - newU = clamp(-prefU, delta.u(), prefU) + protagonistLocation.u(); - newV = clamp(-prefV, delta.v(), prefV) + protagonistLocation.v(); + newU = CLIP(delta.u(), -prefU, prefU) + protagonistLocation.u(); + newV = CLIP(delta.v(), -prefV, prefV) + protagonistLocation.v(); newLocation.u() = newU + _vm->_rnd.getRandomNumber(prefU - 1) - prefU / 2; newLocation.v() = newV + _vm->_rnd.getRandomNumber(prefV - 1) - prefV / 2; @@ -841,11 +841,11 @@ bool Actor::followProtagonist(ActorData *actor) { delta.x = (delta.x > 0) ? prefer3.x : -prefer3.x; newLocation.x = delta.x + protagonistLocation.x; - newLocation.y = clamp(-prefer2.y, delta.y, prefer2.y) + protagonistLocation.y; + newLocation.y = CLIP(delta.y, -prefer2.y, prefer2.y) + protagonistLocation.y; } else { delta.y = (delta.y > 0) ? prefer3.y : -prefer3.y; - newLocation.x = clamp(-prefer2.x, delta.x, prefer2.x) + protagonistLocation.x; + newLocation.x = CLIP(delta.x, -prefer2.x, prefer2.x) + protagonistLocation.x; newLocation.y = delta.y + protagonistLocation.y; } newLocation.z = 0; @@ -855,7 +855,7 @@ bool Actor::followProtagonist(ActorData *actor) { newLocation.y += _vm->_rnd.getRandomNumber(prefer1.y - 1) - prefer1.y / 2; } - newLocation.x = clamp(-31 * 4, newLocation.x, (_vm->getDisplayWidth() + 31) * 4); + newLocation.x = CLIP(newLocation.x, -31 * 4, (_vm->getDisplayWidth() + 31) * 4); return actorWalkTo(actor->_id, newLocation); } diff --git a/engines/saga/gfx.cpp b/engines/saga/gfx.cpp index b8af79cca3..5cac60d415 100644 --- a/engines/saga/gfx.cpp +++ b/engines/saga/gfx.cpp @@ -407,8 +407,8 @@ void Gfx::palFade(PalEntry *srcPal, int16 from, int16 to, int16 start, int16 num PalEntry *palE; double fpercent; - from = CLIP((int)from, 0, 256); - to = CLIP((int)to, 0, 256); + from = CLIP(from, 0, 256); + to = CLIP(to, 0, 256); if (from == 0 || to == 0) { // This case works like palToBlack or blackToPal, so no changes are needed diff --git a/engines/saga/interface.cpp b/engines/saga/interface.cpp index fce8807681..543e2dba9f 100644 --- a/engines/saga/interface.cpp +++ b/engines/saga/interface.cpp @@ -1394,7 +1394,7 @@ void Interface::handleOptionUpdate(const Point& mousePoint) { (_optionSaveFileSlider->height - _optionSaveRectSlider.height()); } - _optionSaveFileTop = clamp(0, _optionSaveFileTop, _vm->getSaveFilesCount() - _vm->getDisplayInfo().optionSaveFileVisible); + _optionSaveFileTop = CLIP(_optionSaveFileTop, 0, _vm->getSaveFilesCount() - _vm->getDisplayInfo().optionSaveFileVisible); calcOptionSaveSlider(); } } @@ -1441,7 +1441,7 @@ void Interface::handleOptionClick(const Point& mousePoint) { } } - _optionSaveFileTop = clamp(0, _optionSaveFileTop, _vm->getSaveFilesCount() - _vm->getDisplayInfo().optionSaveFileVisible); + _optionSaveFileTop = CLIP(_optionSaveFileTop, 0, _vm->getSaveFilesCount() - _vm->getDisplayInfo().optionSaveFileVisible); calcOptionSaveSlider(); } else { if (_optionPanel.currentButton == _optionSaveFilePanel) { diff --git a/engines/saga/isomap.cpp b/engines/saga/isomap.cpp index b49a9e1d0a..b6eb69b313 100644 --- a/engines/saga/isomap.cpp +++ b/engines/saga/isomap.cpp @@ -403,10 +403,10 @@ void IsoMap::drawSprite(Surface *ds, SpriteList &spriteList, int spriteNumber, c spritePointer.x = screenPosition.x + xAlign; spritePointer.y = screenPosition.y + yAlign; - _tileClip.left = CLIP((int)spritePointer.x, 0, _vm->getDisplayWidth()); - _tileClip.right = CLIP((int)spritePointer.x + width, 0, _vm->getDisplayWidth()); - _tileClip.top = CLIP((int)spritePointer.y, 0, _vm->_scene->getHeight()); - _tileClip.bottom = CLIP((int)spritePointer.y + height, 0, _vm->_scene->getHeight()); + _tileClip.left = CLIP(spritePointer.x, 0, _vm->getDisplayWidth()); + _tileClip.right = CLIP(spritePointer.x + width, 0, _vm->getDisplayWidth()); + _tileClip.top = CLIP(spritePointer.y, 0, _vm->_scene->getHeight()); + _tileClip.bottom = CLIP(spritePointer.y + height, 0, _vm->_scene->getHeight()); _vm->_sprite->drawClip(ds, clip, spritePointer, width, height, spriteBuffer); drawTiles(ds, &location); @@ -465,8 +465,8 @@ void IsoMap::drawTiles(Surface *ds, const Location *location) { metaTileIndex = 1; break; case kEdgeTypeRpt: - uc = clamp( 0, u2, SAGA_TILEMAP_W - 1); - vc = clamp( 0, v2, SAGA_TILEMAP_W - 1); + uc = CLIP(u2, 0, SAGA_TILEMAP_W - 1); + vc = CLIP(v2, 0, SAGA_TILEMAP_W - 1); metaTileIndex = _tileMap.tilePlatforms[uc][vc]; break; case kEdgeTypeWrap: @@ -509,8 +509,8 @@ void IsoMap::drawTiles(Surface *ds, const Location *location) { metaTileIndex = 1; break; case kEdgeTypeRpt: - uc = clamp( 0, u2, SAGA_TILEMAP_W - 1); - vc = clamp( 0, v2, SAGA_TILEMAP_W - 1); + uc = CLIP(u2, 0, SAGA_TILEMAP_W - 1); + vc = CLIP(v2, 0, SAGA_TILEMAP_W - 1); metaTileIndex = _tileMap.tilePlatforms[uc][vc]; break; case kEdgeTypeWrap: @@ -1010,8 +1010,8 @@ int16 IsoMap::getTileIndex(int16 u, int16 v, int16 z) { metaTileIndex = 1; break; case kEdgeTypeRpt: - uc = clamp( 0, mtileU, SAGA_TILEMAP_W - 1); - vc = clamp( 0, mtileV, SAGA_TILEMAP_W - 1); + uc = CLIP(mtileU, 0, SAGA_TILEMAP_W - 1); + vc = CLIP(mtileV, 0, SAGA_TILEMAP_W - 1); metaTileIndex = _tileMap.tilePlatforms[uc][vc]; break; case kEdgeTypeWrap: diff --git a/engines/saga/saga.h b/engines/saga/saga.h index cac2b911db..a920a154c0 100644 --- a/engines/saga/saga.h +++ b/engines/saga/saga.h @@ -473,18 +473,6 @@ struct SaveGameHeader { char name[SAVE_TITLE_SIZE]; }; -inline int clamp(int minValue, int value, int maxValue) { - if (value <= minValue) { - return minValue; - } else { - if (value >= maxValue) { - return maxValue; - } else { - return value; - } - } -} - inline int objectTypeId(uint16 objectId) { return objectId >> OBJECT_TYPE_SHIFT; } diff --git a/engines/saga/scene.cpp b/engines/saga/scene.cpp index 336399eefa..1ae9c4e3c3 100644 --- a/engines/saga/scene.cpp +++ b/engines/saga/scene.cpp @@ -553,8 +553,8 @@ bool Scene::offscreenPath(Point &testPoint) { return false; } - point.x = clamp(0, testPoint.x, _vm->getDisplayWidth() - 1); - point.y = clamp(0, testPoint.y, _bgMask.h - 1); + point.x = CLIP(testPoint.x, 0, _vm->getDisplayWidth() - 1); + point.y = CLIP(testPoint.y, 0, _bgMask.h - 1); if (point == testPoint) { return false; } -- cgit v1.2.3