Removed clamp() and used the common CLIP template instead
svn-id: r29927
This commit is contained in:
parent
0e744e491b
commit
335e9da41d
7 changed files with 30 additions and 42 deletions
|
@ -1102,12 +1102,12 @@ void Actor::drawSpeech(void) {
|
||||||
actor = getActor(_activeSpeech.actorIds[i]);
|
actor = getActor(_activeSpeech.actorIds[i]);
|
||||||
calcScreenPosition(actor);
|
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)
|
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)
|
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,
|
_vm->_font->textDraw(kKnownFontScript, backBuffer, outputString, textPoint,
|
||||||
_activeSpeech.speechColor[i], _activeSpeech.outlineColor[i], _activeSpeech.getFontFlags(i));
|
_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);
|
dist = MIN(actor->_screenPosition.x - 10, _vm->getDisplayWidth() - 10 - actor->_screenPosition.x);
|
||||||
|
|
||||||
if (_vm->getGameType() == GType_ITE)
|
if (_vm->getGameType() == GType_ITE)
|
||||||
dist = clamp(60, dist, 150);
|
dist = CLIP<int16>(dist, 60, 150);
|
||||||
else
|
else
|
||||||
dist = clamp(120, dist, 300);
|
dist = CLIP<int16>(dist, 120, 300);
|
||||||
|
|
||||||
_activeSpeech.speechBox.left = actor->_screenPosition.x - dist;
|
_activeSpeech.speechBox.left = actor->_screenPosition.x - dist;
|
||||||
_activeSpeech.speechBox.right = actor->_screenPosition.x + dist;
|
_activeSpeech.speechBox.right = actor->_screenPosition.x + dist;
|
||||||
|
|
|
@ -422,7 +422,7 @@ void Actor::handleActions(int msec, bool setup) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ABS(delta.v()) > ABS(delta.u())) {
|
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()) {
|
if (addDelta.v() == delta.v()) {
|
||||||
addDelta.u() = delta.u();
|
addDelta.u() = delta.u();
|
||||||
} else {
|
} else {
|
||||||
|
@ -431,7 +431,7 @@ void Actor::handleActions(int msec, bool setup) {
|
||||||
addDelta.u() /= delta.v();
|
addDelta.u() /= delta.v();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
addDelta.u() = clamp(-speed, delta.u(), speed);
|
addDelta.u() = CLIP(delta.u(), -speed, speed);
|
||||||
if (addDelta.u() == delta.u()) {
|
if (addDelta.u() == delta.u()) {
|
||||||
addDelta.v() = delta.v();
|
addDelta.v() = delta.v();
|
||||||
} else {
|
} else {
|
||||||
|
@ -484,7 +484,7 @@ void Actor::handleActions(int msec, bool setup) {
|
||||||
speed = speed / 2;
|
speed = speed / 2;
|
||||||
|
|
||||||
if ((actor->_actionDirection == kDirUp) || (actor->_actionDirection == kDirDown)) {
|
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) {
|
if (addDelta.y == delta.y) {
|
||||||
addDelta.x = delta.x;
|
addDelta.x = delta.x;
|
||||||
} else {
|
} else {
|
||||||
|
@ -494,7 +494,7 @@ void Actor::handleActions(int msec, bool setup) {
|
||||||
actor->_facingDirection = actor->_actionDirection;
|
actor->_facingDirection = actor->_actionDirection;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
addDelta.x = clamp(-2 * speed, delta.x, 2 * speed);
|
addDelta.x = CLIP(delta.x, -2 * speed, 2 * speed);
|
||||||
if (addDelta.x == delta.x) {
|
if (addDelta.x == delta.x) {
|
||||||
addDelta.y = delta.y;
|
addDelta.y = delta.y;
|
||||||
} else {
|
} else {
|
||||||
|
@ -785,8 +785,8 @@ bool Actor::followProtagonist(ActorData *actor) {
|
||||||
prefU /= 2;
|
prefU /= 2;
|
||||||
prefV /= 2;
|
prefV /= 2;
|
||||||
|
|
||||||
newU = clamp(-prefU, delta.u(), prefU) + protagonistLocation.u();
|
newU = CLIP<int32>(delta.u(), -prefU, prefU) + protagonistLocation.u();
|
||||||
newV = clamp(-prefV, delta.v(), prefV) + protagonistLocation.v();
|
newV = CLIP<int32>(delta.v(), -prefV, prefV) + protagonistLocation.v();
|
||||||
|
|
||||||
newLocation.u() = newU + _vm->_rnd.getRandomNumber(prefU - 1) - prefU / 2;
|
newLocation.u() = newU + _vm->_rnd.getRandomNumber(prefU - 1) - prefU / 2;
|
||||||
newLocation.v() = newV + _vm->_rnd.getRandomNumber(prefV - 1) - prefV / 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;
|
delta.x = (delta.x > 0) ? prefer3.x : -prefer3.x;
|
||||||
|
|
||||||
newLocation.x = delta.x + protagonistLocation.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 {
|
} else {
|
||||||
delta.y = (delta.y > 0) ? prefer3.y : -prefer3.y;
|
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.y = delta.y + protagonistLocation.y;
|
||||||
}
|
}
|
||||||
newLocation.z = 0;
|
newLocation.z = 0;
|
||||||
|
@ -855,7 +855,7 @@ bool Actor::followProtagonist(ActorData *actor) {
|
||||||
newLocation.y += _vm->_rnd.getRandomNumber(prefer1.y - 1) - prefer1.y / 2;
|
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);
|
return actorWalkTo(actor->_id, newLocation);
|
||||||
}
|
}
|
||||||
|
|
|
@ -407,8 +407,8 @@ void Gfx::palFade(PalEntry *srcPal, int16 from, int16 to, int16 start, int16 num
|
||||||
PalEntry *palE;
|
PalEntry *palE;
|
||||||
double fpercent;
|
double fpercent;
|
||||||
|
|
||||||
from = CLIP((int)from, 0, 256);
|
from = CLIP<int16>(from, 0, 256);
|
||||||
to = CLIP((int)to, 0, 256);
|
to = CLIP<int16>(to, 0, 256);
|
||||||
|
|
||||||
if (from == 0 || to == 0) {
|
if (from == 0 || to == 0) {
|
||||||
// This case works like palToBlack or blackToPal, so no changes are needed
|
// This case works like palToBlack or blackToPal, so no changes are needed
|
||||||
|
|
|
@ -1394,7 +1394,7 @@ void Interface::handleOptionUpdate(const Point& mousePoint) {
|
||||||
(_optionSaveFileSlider->height - _optionSaveRectSlider.height());
|
(_optionSaveFileSlider->height - _optionSaveRectSlider.height());
|
||||||
}
|
}
|
||||||
|
|
||||||
_optionSaveFileTop = clamp(0, _optionSaveFileTop, _vm->getSaveFilesCount() - _vm->getDisplayInfo().optionSaveFileVisible);
|
_optionSaveFileTop = CLIP<uint>(_optionSaveFileTop, 0, _vm->getSaveFilesCount() - _vm->getDisplayInfo().optionSaveFileVisible);
|
||||||
calcOptionSaveSlider();
|
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();
|
calcOptionSaveSlider();
|
||||||
} else {
|
} else {
|
||||||
if (_optionPanel.currentButton == _optionSaveFilePanel) {
|
if (_optionPanel.currentButton == _optionSaveFilePanel) {
|
||||||
|
|
|
@ -403,10 +403,10 @@ void IsoMap::drawSprite(Surface *ds, SpriteList &spriteList, int spriteNumber, c
|
||||||
spritePointer.x = screenPosition.x + xAlign;
|
spritePointer.x = screenPosition.x + xAlign;
|
||||||
spritePointer.y = screenPosition.y + yAlign;
|
spritePointer.y = screenPosition.y + yAlign;
|
||||||
|
|
||||||
_tileClip.left = CLIP((int)spritePointer.x, 0, _vm->getDisplayWidth());
|
_tileClip.left = CLIP<int>(spritePointer.x, 0, _vm->getDisplayWidth());
|
||||||
_tileClip.right = CLIP((int)spritePointer.x + width, 0, _vm->getDisplayWidth());
|
_tileClip.right = CLIP<int>(spritePointer.x + width, 0, _vm->getDisplayWidth());
|
||||||
_tileClip.top = CLIP((int)spritePointer.y, 0, _vm->_scene->getHeight());
|
_tileClip.top = CLIP<int>(spritePointer.y, 0, _vm->_scene->getHeight());
|
||||||
_tileClip.bottom = CLIP((int)spritePointer.y + height, 0, _vm->_scene->getHeight());
|
_tileClip.bottom = CLIP<int>(spritePointer.y + height, 0, _vm->_scene->getHeight());
|
||||||
|
|
||||||
_vm->_sprite->drawClip(ds, clip, spritePointer, width, height, spriteBuffer);
|
_vm->_sprite->drawClip(ds, clip, spritePointer, width, height, spriteBuffer);
|
||||||
drawTiles(ds, &location);
|
drawTiles(ds, &location);
|
||||||
|
@ -465,8 +465,8 @@ void IsoMap::drawTiles(Surface *ds, const Location *location) {
|
||||||
metaTileIndex = 1;
|
metaTileIndex = 1;
|
||||||
break;
|
break;
|
||||||
case kEdgeTypeRpt:
|
case kEdgeTypeRpt:
|
||||||
uc = clamp( 0, u2, SAGA_TILEMAP_W - 1);
|
uc = CLIP<int16>(u2, 0, SAGA_TILEMAP_W - 1);
|
||||||
vc = clamp( 0, v2, SAGA_TILEMAP_W - 1);
|
vc = CLIP<int16>(v2, 0, SAGA_TILEMAP_W - 1);
|
||||||
metaTileIndex = _tileMap.tilePlatforms[uc][vc];
|
metaTileIndex = _tileMap.tilePlatforms[uc][vc];
|
||||||
break;
|
break;
|
||||||
case kEdgeTypeWrap:
|
case kEdgeTypeWrap:
|
||||||
|
@ -509,8 +509,8 @@ void IsoMap::drawTiles(Surface *ds, const Location *location) {
|
||||||
metaTileIndex = 1;
|
metaTileIndex = 1;
|
||||||
break;
|
break;
|
||||||
case kEdgeTypeRpt:
|
case kEdgeTypeRpt:
|
||||||
uc = clamp( 0, u2, SAGA_TILEMAP_W - 1);
|
uc = CLIP<int16>(u2, 0, SAGA_TILEMAP_W - 1);
|
||||||
vc = clamp( 0, v2, SAGA_TILEMAP_W - 1);
|
vc = CLIP<int16>(v2, 0, SAGA_TILEMAP_W - 1);
|
||||||
metaTileIndex = _tileMap.tilePlatforms[uc][vc];
|
metaTileIndex = _tileMap.tilePlatforms[uc][vc];
|
||||||
break;
|
break;
|
||||||
case kEdgeTypeWrap:
|
case kEdgeTypeWrap:
|
||||||
|
@ -1010,8 +1010,8 @@ int16 IsoMap::getTileIndex(int16 u, int16 v, int16 z) {
|
||||||
metaTileIndex = 1;
|
metaTileIndex = 1;
|
||||||
break;
|
break;
|
||||||
case kEdgeTypeRpt:
|
case kEdgeTypeRpt:
|
||||||
uc = clamp( 0, mtileU, SAGA_TILEMAP_W - 1);
|
uc = CLIP<int16>(mtileU, 0, SAGA_TILEMAP_W - 1);
|
||||||
vc = clamp( 0, mtileV, SAGA_TILEMAP_W - 1);
|
vc = CLIP<int16>(mtileV, 0, SAGA_TILEMAP_W - 1);
|
||||||
metaTileIndex = _tileMap.tilePlatforms[uc][vc];
|
metaTileIndex = _tileMap.tilePlatforms[uc][vc];
|
||||||
break;
|
break;
|
||||||
case kEdgeTypeWrap:
|
case kEdgeTypeWrap:
|
||||||
|
|
|
@ -473,18 +473,6 @@ struct SaveGameHeader {
|
||||||
char name[SAVE_TITLE_SIZE];
|
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) {
|
inline int objectTypeId(uint16 objectId) {
|
||||||
return objectId >> OBJECT_TYPE_SHIFT;
|
return objectId >> OBJECT_TYPE_SHIFT;
|
||||||
}
|
}
|
||||||
|
|
|
@ -553,8 +553,8 @@ bool Scene::offscreenPath(Point &testPoint) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
point.x = clamp(0, testPoint.x, _vm->getDisplayWidth() - 1);
|
point.x = CLIP<int>(testPoint.x, 0, _vm->getDisplayWidth() - 1);
|
||||||
point.y = clamp(0, testPoint.y, _bgMask.h - 1);
|
point.y = CLIP<int>(testPoint.y, 0, _bgMask.h - 1);
|
||||||
if (point == testPoint) {
|
if (point == testPoint) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue