Removed clamp() and used the common CLIP template instead

svn-id: r29927
This commit is contained in:
Filippos Karapetis 2007-12-20 19:00:10 +00:00
parent 0e744e491b
commit 335e9da41d
7 changed files with 30 additions and 42 deletions

View File

@ -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<int16>(dist, 60, 150);
else
dist = clamp(120, dist, 300);
dist = CLIP<int16>(dist, 120, 300);
_activeSpeech.speechBox.left = actor->_screenPosition.x - dist;
_activeSpeech.speechBox.right = actor->_screenPosition.x + dist;

View File

@ -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<int32>(delta.u(), -prefU, prefU) + protagonistLocation.u();
newV = CLIP<int32>(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<int32>(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<int32>(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);
}

View File

@ -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<int16>(from, 0, 256);
to = CLIP<int16>(to, 0, 256);
if (from == 0 || to == 0) {
// This case works like palToBlack or blackToPal, so no changes are needed

View File

@ -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<uint>(_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<uint>(_optionSaveFileTop, 0, _vm->getSaveFilesCount() - _vm->getDisplayInfo().optionSaveFileVisible);
calcOptionSaveSlider();
} else {
if (_optionPanel.currentButton == _optionSaveFilePanel) {

View File

@ -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<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());
_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<int16>(u2, 0, SAGA_TILEMAP_W - 1);
vc = CLIP<int16>(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<int16>(u2, 0, SAGA_TILEMAP_W - 1);
vc = CLIP<int16>(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<int16>(mtileU, 0, SAGA_TILEMAP_W - 1);
vc = CLIP<int16>(mtileV, 0, SAGA_TILEMAP_W - 1);
metaTileIndex = _tileMap.tilePlatforms[uc][vc];
break;
case kEdgeTypeWrap:

View File

@ -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;
}

View File

@ -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<int>(testPoint.x, 0, _vm->getDisplayWidth() - 1);
point.y = CLIP<int>(testPoint.y, 0, _bgMask.h - 1);
if (point == testPoint) {
return false;
}