[Scummvm-cvs-logs] scummvm master -> c386a5520ff389b77dd004f55ae78fc5f24856e2

lordhoto lordhoto at gmail.com
Thu Sep 8 00:26:31 CEST 2011


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
c386a5520f SWORD1: Replace inRange with CLIP.


Commit: c386a5520ff389b77dd004f55ae78fc5f24856e2
    https://github.com/scummvm/scummvm/commit/c386a5520ff389b77dd004f55ae78fc5f24856e2
Author: Johannes Schickel (lordhoto at scummvm.org)
Date: 2011-09-07T15:19:43-07:00

Commit Message:
SWORD1: Replace inRange with CLIP.

Changed paths:
    engines/sword1/logic.cpp
    engines/sword1/logic.h
    engines/sword1/screen.cpp
    engines/sword1/screen.h



diff --git a/engines/sword1/logic.cpp b/engines/sword1/logic.cpp
index d8933bc..d1c69c8 100644
--- a/engines/sword1/logic.cpp
+++ b/engines/sword1/logic.cpp
@@ -1189,8 +1189,8 @@ int Logic::fnISpeak(Object *cpt, int32 id, int32 cdt, int32 textNo, int32 spr, i
 		textTopMargin    = SCREEN_TOP_EDGE    + TEXT_MARGIN + _scriptVars[SCROLL_OFFSET_Y];
 		textBottomMargin = SCREEN_BOTTOM_EDGE - TEXT_MARGIN + _scriptVars[SCROLL_OFFSET_Y] - textSpriteHeight;
 
-		textCpt->o_anim_x = textCpt->o_xcoord = inRange(textLeftMargin, textX, textRightMargin);
-		textCpt->o_anim_y = textCpt->o_ycoord = inRange(textTopMargin,  textY, textBottomMargin);
+		textCpt->o_anim_x = textCpt->o_xcoord = CLIP<uint16>(textX, textLeftMargin, textRightMargin);
+		textCpt->o_anim_y = textCpt->o_ycoord = CLIP<uint16>(textY, textTopMargin, textBottomMargin);
 	}
 	return SCRIPT_STOP;
 }
@@ -1689,10 +1689,6 @@ int Logic::fnBlack(Object *cpt, int32 id, int32 a, int32 b, int32 c, int32 d, in
 	return SCRIPT_CONT;
 }
 
-uint16 Logic::inRange(uint16 a, uint16 b, uint16 c) {
-	return (a > b) ? a : (((b > c) ? c : b));
-}
-
 void Logic::startPosCallFn(uint8 fnId, uint32 param1, uint32 param2, uint32 param3) {
 	Object *obj = NULL;
 	switch (fnId) {
diff --git a/engines/sword1/logic.h b/engines/sword1/logic.h
index d4b297e..a146d34 100644
--- a/engines/sword1/logic.h
+++ b/engines/sword1/logic.h
@@ -97,8 +97,6 @@ private:
 	void setupMcodeTable();
 	const BSMcodeTable *_mcodeTable;
 
-	uint16 inRange(uint16 a, uint16 b, uint16 c);
-
 //- mcodeTable:
 	int fnBackground(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
 	int fnForeground(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
diff --git a/engines/sword1/screen.cpp b/engines/sword1/screen.cpp
index c7368c9..ae128b8 100644
--- a/engines/sword1/screen.cpp
+++ b/engines/sword1/screen.cpp
@@ -78,13 +78,9 @@ void Screen::useTextManager(Text *pTextMan) {
 	_textMan = pTextMan;
 }
 
-int32 Screen::inRange(int32 a, int32 b, int32 c) { // return b(!) so that: a <= b <= c
-	return (a > b) ? (a) : ((b < c) ? b : c);
-}
-
 void Screen::setScrolling(int16 offsetX, int16 offsetY) {
-	offsetX = inRange(0, offsetX, Logic::_scriptVars[MAX_SCROLL_OFFSET_X]);
-	offsetY = inRange(0, offsetY, Logic::_scriptVars[MAX_SCROLL_OFFSET_Y]);
+	offsetX = CLIP<int32>(offsetX, 0, Logic::_scriptVars[MAX_SCROLL_OFFSET_X]);
+	offsetY = CLIP<int32>(offsetY, 0, Logic::_scriptVars[MAX_SCROLL_OFFSET_Y]);
 
 	if (Logic::_scriptVars[SCROLL_FLAG] == 2) { // first time on this screen - need absolute scroll immediately!
 		_oldScrollX = Logic::_scriptVars[SCROLL_OFFSET_X] = (uint32)offsetX;
@@ -101,18 +97,18 @@ void Screen::setScrolling(int16 offsetX, int16 offsetY) {
 		_oldScrollY = Logic::_scriptVars[SCROLL_OFFSET_Y];
 		int dx = offsetX - Logic::_scriptVars[SCROLL_OFFSET_X];
 		int dy = offsetY - Logic::_scriptVars[SCROLL_OFFSET_Y];
-		int scrlDistX = inRange(-MAX_SCROLL_DISTANCE, (((SCROLL_FRACTION - 1) + ABS(dx)) / SCROLL_FRACTION) * ((dx > 0) ? 1 : -1), MAX_SCROLL_DISTANCE);
-		int scrlDistY = inRange(-MAX_SCROLL_DISTANCE, (((SCROLL_FRACTION - 1) + ABS(dy)) / SCROLL_FRACTION) * ((dy > 0) ? 1 : -1), MAX_SCROLL_DISTANCE);
+		int scrlDistX = CLIP<int32>((((SCROLL_FRACTION - 1) + ABS(dx)) / SCROLL_FRACTION) * ((dx > 0) ? 1 : -1), -MAX_SCROLL_DISTANCE, MAX_SCROLL_DISTANCE);
+		int scrlDistY = CLIP<int32>((((SCROLL_FRACTION - 1) + ABS(dy)) / SCROLL_FRACTION) * ((dy > 0) ? 1 : -1), -MAX_SCROLL_DISTANCE, MAX_SCROLL_DISTANCE);
 		if ((scrlDistX != 0) || (scrlDistY != 0))
 			_fullRefresh = true;
-		Logic::_scriptVars[SCROLL_OFFSET_X] = inRange(0, Logic::_scriptVars[SCROLL_OFFSET_X] + scrlDistX, Logic::_scriptVars[MAX_SCROLL_OFFSET_X]);
-		Logic::_scriptVars[SCROLL_OFFSET_Y] = inRange(0, Logic::_scriptVars[SCROLL_OFFSET_Y] + scrlDistY, Logic::_scriptVars[MAX_SCROLL_OFFSET_Y]);
+		Logic::_scriptVars[SCROLL_OFFSET_X] = CLIP<int32>(Logic::_scriptVars[SCROLL_OFFSET_X] + scrlDistX, 0, Logic::_scriptVars[MAX_SCROLL_OFFSET_X]);
+		Logic::_scriptVars[SCROLL_OFFSET_Y] = CLIP<int32>(Logic::_scriptVars[SCROLL_OFFSET_Y] + scrlDistY, 0, Logic::_scriptVars[MAX_SCROLL_OFFSET_Y]);
 	} else {
 		// SCROLL_FLAG == 0, this usually means that the screen is smaller than 640x400 and doesn't need scrolling at all
 		// however, it can also mean that the gamescript overwrote the scrolling flag to take care of scrolling directly,
 		// (see bug report #1345130) so we ignore the offset arguments in this case
-		Logic::_scriptVars[SCROLL_OFFSET_X] = inRange(0, Logic::_scriptVars[SCROLL_OFFSET_X], Logic::_scriptVars[MAX_SCROLL_OFFSET_X]);
-		Logic::_scriptVars[SCROLL_OFFSET_Y] = inRange(0, Logic::_scriptVars[SCROLL_OFFSET_Y], Logic::_scriptVars[MAX_SCROLL_OFFSET_Y]);
+		Logic::_scriptVars[SCROLL_OFFSET_X] = CLIP<int32>(Logic::_scriptVars[SCROLL_OFFSET_X], 0, Logic::_scriptVars[MAX_SCROLL_OFFSET_X]);
+		Logic::_scriptVars[SCROLL_OFFSET_Y] = CLIP<int32>(Logic::_scriptVars[SCROLL_OFFSET_Y], 0, Logic::_scriptVars[MAX_SCROLL_OFFSET_Y]);
 		if ((Logic::_scriptVars[SCROLL_OFFSET_X] != _oldScrollX) || (Logic::_scriptVars[SCROLL_OFFSET_Y] != _oldScrollY)) {
 			_fullRefresh = true;
 			_oldScrollX = Logic::_scriptVars[SCROLL_OFFSET_X];
diff --git a/engines/sword1/screen.h b/engines/sword1/screen.h
index 4560853..7586e93 100644
--- a/engines/sword1/screen.h
+++ b/engines/sword1/screen.h
@@ -126,7 +126,6 @@ private:
 	void decompressRLE0(uint8 *src, uint32 compSize, uint8 *dest);
 	void decompressTony(uint8 *src, uint32 compSize, uint8 *dest);
 	void fastShrink(uint8 *src, uint32 width, uint32 height, uint32 scale, uint8 *dest);
-	int32 inRange(int32 a, int32 b, int32 c);
 	void fadePalette();
 
 	void flushPsxCache();






More information about the Scummvm-git-logs mailing list