[Scummvm-cvs-logs] SF.net SVN: scummvm:[44836] scummvm/trunk/engines/sci

thebluegr at users.sourceforge.net thebluegr at users.sourceforge.net
Fri Oct 9 19:41:59 CEST 2009


Revision: 44836
          http://scummvm.svn.sourceforge.net/scummvm/?rev=44836&view=rev
Author:   thebluegr
Date:     2009-10-09 17:41:59 +0000 (Fri, 09 Oct 2009)

Log Message:
-----------
Moved actor movement detection in state.cpp, together with the other detections and rewrote it to work in a similar fashion to the other detections

Modified Paths:
--------------
    scummvm/trunk/engines/sci/engine/kmovement.cpp
    scummvm/trunk/engines/sci/engine/state.cpp
    scummvm/trunk/engines/sci/engine/state.h
    scummvm/trunk/engines/sci/sci.h

Modified: scummvm/trunk/engines/sci/engine/kmovement.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/kmovement.cpp	2009-10-09 17:34:52 UTC (rev 44835)
+++ scummvm/trunk/engines/sci/engine/kmovement.cpp	2009-10-09 17:41:59 UTC (rev 44836)
@@ -234,55 +234,6 @@
 #define MOVING_ON_X (((axis == _K_BRESEN_AXIS_X)&&bi1) || dx)
 #define MOVING_ON_Y (((axis == _K_BRESEN_AXIS_Y)&&bi1) || dy)
 
-enum Movecnt {
-	IGNORE_MOVECNT,
-	INCREMENT_MOVECNT,
-	UNINITIALIZED
-};
-
-static Movecnt handle_movecnt = UNINITIALIZED;	// FIXME: Avoid non-const global vars
-
-static int checksum_bytes(byte *data, int size) {
-	int result = 0;
-	int i;
-
-	for (i = 0; i < size; i++) {
-		result += *data;
-		data++;
-	}
-
-	return result;
-}
-
-static void bresenham_autodetect(EngineState *s) {
-	reg_t motionClass = s->_segMan->findObjectByName("Motion");
-
-	if (!motionClass.isNull()) {
-		Object *obj = s->_segMan->getObject(motionClass);
-		reg_t fptr;
-		byte *buf;
-
-		if (obj == NULL) {
-			warning("bresenham_autodetect failed");
-			handle_movecnt = INCREMENT_MOVECNT; // Most games do this, so best guess
-			return;
-		}
-
-		if (lookup_selector(s->_segMan, motionClass, s->_kernel->_selectorCache.doit, NULL, &fptr) != kSelectorMethod) {
-			warning("bresenham_autodetect failed");
-			handle_movecnt = INCREMENT_MOVECNT; // Most games do this, so best guess
-			return;
-		}
-
-		buf = s->_segMan->getScript(fptr.segment)->_buf + fptr.offset;
-		handle_movecnt = (getSciVersion() <= SCI_VERSION_01 || checksum_bytes(buf, 8) == 0x216) ? INCREMENT_MOVECNT : IGNORE_MOVECNT;
-		printf("b-moveCnt action based on checksum: %s\n", handle_movecnt == IGNORE_MOVECNT ? "ignore" : "increment");
-	} else {
-		warning("bresenham_autodetect failed");
-		handle_movecnt = INCREMENT_MOVECNT; // Most games do this, so best guess
-	}
-}
-
 reg_t kDoBresen(EngineState *s, int argc, reg_t *argv) {
 	SegManager *segMan = s->_segMan;
 	reg_t mover = argv[0];
@@ -298,9 +249,6 @@
 	if (getSciVersion() > SCI_VERSION_01)
 		signal &= ~_K_VIEW_SIG_FLAG_HIT_OBSTACLE;
 
-	if (handle_movecnt == UNINITIALIZED)
-		bresenham_autodetect(s);
-
 	PUT_SEL32(client, signal, make_reg(0, signal)); // This is a NOP for SCI0
 	oldx = x;
 	oldy = y;
@@ -317,7 +265,7 @@
 
 	//printf("movecnt %d, move speed %d\n", movcnt, max_movcnt);
 
-	if (handle_movecnt) {
+	if (s->handleMoveCount()) {
 		if (max_movcnt > movcnt) {
 			++movcnt;
 			PUT_SEL32V(mover, b_movCnt, movcnt); // Needed for HQ1/Ogre?

Modified: scummvm/trunk/engines/sci/engine/state.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/state.cpp	2009-10-09 17:34:52 UTC (rev 44835)
+++ scummvm/trunk/engines/sci/engine/state.cpp	2009-10-09 17:41:59 UTC (rev 44836)
@@ -111,6 +111,7 @@
 	_doSoundType = SCI_VERSION_AUTODETECT;
 	_lofsType = SCI_VERSION_AUTODETECT;
 	_gfxFunctionsType = SCI_VERSION_AUTODETECT;
+	_moveCountType = kMoveCountUninitialized;
 }
 
 EngineState::~EngineState() {
@@ -633,4 +634,40 @@
 	return _gfxFunctionsType;
 }
 
+MoveCountType EngineState::detectMoveCountType() {
+	if (_moveCountType == kMoveCountUninitialized) {
+		// SCI0/SCI01 games always increment move count
+		if (getSciVersion() <= SCI_VERSION_01) {
+			_moveCountType = kIncrementMoveCount;
+			return _moveCountType;
+		}
+
+		reg_t motionClass = _segMan->findObjectByName("Motion");
+		bool found = false;
+
+		if (!motionClass.isNull()) {
+			Object *obj = _segMan->getObject(motionClass);
+			reg_t fptr;
+
+			if (obj && lookup_selector(_segMan, motionClass, _kernel->_selectorCache.doit, NULL, &fptr) == kSelectorMethod) {
+				byte *buf = _segMan->getScript(fptr.segment)->_buf + fptr.offset;
+				int checksum = 0;
+				for (int i = 0; i < 8; i++)
+					checksum += *(buf++);
+				_moveCountType = (checksum == 0x216) ? kIncrementMoveCount : kIgnoreMoveCount;
+				found = true;
+			}
+		}
+
+		if (!found) {
+			warning("Move count autodetection failed");
+			_moveCountType = kIncrementMoveCount;	// Most games do this, so best guess
+		}
+
+		debugC(1, kDebugLevelVM, "Detected move count handling: %s", (_moveCountType == kIncrementMoveCount) ? "increment" : "ignore");
+	}
+
+	return _moveCountType;
+}
+
 } // End of namespace Sci

Modified: scummvm/trunk/engines/sci/engine/state.h
===================================================================
--- scummvm/trunk/engines/sci/engine/state.h	2009-10-09 17:34:52 UTC (rev 44835)
+++ scummvm/trunk/engines/sci/engine/state.h	2009-10-09 17:41:59 UTC (rev 44836)
@@ -288,12 +288,27 @@
 
 	/**
 	 * Autodetects the graphics functions used
-	 * @return Lofs type, SCI_VERSION_0_EARLY / SCI_VERSION_0_LATE
+	 * @return Graphics functions type, SCI_VERSION_0_EARLY / SCI_VERSION_0_LATE
 	 */
 	SciVersion detectGfxFunctionsType();
 
+	/**
+	 * Applies to all versions before 0.000.502
+	 * Old SCI versions used to interpret the third DrawPic() parameter inversely,
+	 * with the opposite default value (obviously).
+	 * Also, they used 15 priority zones from 42 to 200 instead of 14 priority
+	 * zones from 42 to 190.
+	 */
 	bool usesOldGfxFunctions() { return detectGfxFunctionsType() == SCI_VERSION_0_EARLY; }
 
+	/**
+	 * Autodetects the Bresenham routine used in the actor movement functions
+	 * @return Move count type, kIncrementMoveCnt / kIgnoreMoveCnt
+	 */
+	MoveCountType detectMoveCountType();
+
+	bool handleMoveCount() { return detectMoveCountType() == kIncrementMoveCount; }
+
 	/* Debugger data: */
 	Breakpoint *bp_list;   /**< List of breakpoints */
 	int have_bp;  /**< Bit mask specifying which types of breakpoints are used in bp_list */
@@ -316,6 +331,7 @@
 	Common::String getLanguageString(const char *str, kLanguage lang) const;
 private:
 	SciVersion _doSoundType, _setCursorType, _lofsType, _gfxFunctionsType;
+	MoveCountType _moveCountType;
 	kLanguage charToLanguage(const char c) const;
 	int methodChecksum(reg_t objAddress, Selector sel, int offset, uint size) const;
 	uint16 firstRetOffset(reg_t objectAddress) const;

Modified: scummvm/trunk/engines/sci/sci.h
===================================================================
--- scummvm/trunk/engines/sci/sci.h	2009-10-09 17:34:52 UTC (rev 44835)
+++ scummvm/trunk/engines/sci/sci.h	2009-10-09 17:41:59 UTC (rev 44836)
@@ -95,6 +95,12 @@
 	SCI_VERSION_3 // LSL7, RAMA, Lighthouse
 };
 
+enum MoveCountType {
+	kMoveCountUninitialized,
+	kIgnoreMoveCount,
+	kIncrementMoveCount
+};
+
 class SciEngine : public Engine {
 	friend class Console;
 public:


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