[Scummvm-cvs-logs] SF.net SVN: scummvm: [29927] scummvm/trunk/engines/saga

thebluegr at users.sourceforge.net thebluegr at users.sourceforge.net
Thu Dec 20 20:00:10 CET 2007


Revision: 29927
          http://scummvm.svn.sourceforge.net/scummvm/?rev=29927&view=rev
Author:   thebluegr
Date:     2007-12-20 11:00:10 -0800 (Thu, 20 Dec 2007)

Log Message:
-----------
Removed clamp() and used the common CLIP template instead

Modified Paths:
--------------
    scummvm/trunk/engines/saga/actor.cpp
    scummvm/trunk/engines/saga/actor_walk.cpp
    scummvm/trunk/engines/saga/gfx.cpp
    scummvm/trunk/engines/saga/interface.cpp
    scummvm/trunk/engines/saga/isomap.cpp
    scummvm/trunk/engines/saga/saga.h
    scummvm/trunk/engines/saga/scene.cpp

Modified: scummvm/trunk/engines/saga/actor.cpp
===================================================================
--- scummvm/trunk/engines/saga/actor.cpp	2007-12-20 18:52:05 UTC (rev 29926)
+++ scummvm/trunk/engines/saga/actor.cpp	2007-12-20 19:00:10 UTC (rev 29927)
@@ -1102,12 +1102,12 @@
 			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 @@
 	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;

Modified: scummvm/trunk/engines/saga/actor_walk.cpp
===================================================================
--- scummvm/trunk/engines/saga/actor_walk.cpp	2007-12-20 18:52:05 UTC (rev 29926)
+++ scummvm/trunk/engines/saga/actor_walk.cpp	2007-12-20 19:00:10 UTC (rev 29927)
@@ -422,7 +422,7 @@
 				}
 
 				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 @@
 						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 @@
 					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 @@
 						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 @@
 			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 @@
 					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 @@
 					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);
 			}

Modified: scummvm/trunk/engines/saga/gfx.cpp
===================================================================
--- scummvm/trunk/engines/saga/gfx.cpp	2007-12-20 18:52:05 UTC (rev 29926)
+++ scummvm/trunk/engines/saga/gfx.cpp	2007-12-20 19:00:10 UTC (rev 29927)
@@ -407,8 +407,8 @@
 	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

Modified: scummvm/trunk/engines/saga/interface.cpp
===================================================================
--- scummvm/trunk/engines/saga/interface.cpp	2007-12-20 18:52:05 UTC (rev 29926)
+++ scummvm/trunk/engines/saga/interface.cpp	2007-12-20 19:00:10 UTC (rev 29927)
@@ -1394,7 +1394,7 @@
 					(_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 @@
 			}
 		}
 
-		_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) {

Modified: scummvm/trunk/engines/saga/isomap.cpp
===================================================================
--- scummvm/trunk/engines/saga/isomap.cpp	2007-12-20 18:52:05 UTC (rev 29926)
+++ scummvm/trunk/engines/saga/isomap.cpp	2007-12-20 19:00:10 UTC (rev 29927)
@@ -403,10 +403,10 @@
 	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 @@
 					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 @@
 					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 @@
 			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:

Modified: scummvm/trunk/engines/saga/saga.h
===================================================================
--- scummvm/trunk/engines/saga/saga.h	2007-12-20 18:52:05 UTC (rev 29926)
+++ scummvm/trunk/engines/saga/saga.h	2007-12-20 19:00:10 UTC (rev 29927)
@@ -473,18 +473,6 @@
 	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;
 }

Modified: scummvm/trunk/engines/saga/scene.cpp
===================================================================
--- scummvm/trunk/engines/saga/scene.cpp	2007-12-20 18:52:05 UTC (rev 29926)
+++ scummvm/trunk/engines/saga/scene.cpp	2007-12-20 19:00:10 UTC (rev 29927)
@@ -553,8 +553,8 @@
 		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;
 	}


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list