[Scummvm-git-logs] scummvm master -> d10ac8689071ca1916507072b5918e6bf2b26cac

dreammaster dreammaster at scummvm.org
Sat Feb 4 05:45:53 CET 2017


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:
d10ac86890 TITANIC: Implemented CMusicObject initialization


Commit: d10ac8689071ca1916507072b5918e6bf2b26cac
    https://github.com/scummvm/scummvm/commit/d10ac8689071ca1916507072b5918e6bf2b26cac
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2017-02-03T23:45:48-05:00

Commit Message:
TITANIC: Implemented CMusicObject initialization

Changed paths:
    engines/titanic/sound/music_object.cpp
    engines/titanic/sound/music_object.h
    engines/titanic/sound/music_room_handler.cpp


diff --git a/engines/titanic/sound/music_object.cpp b/engines/titanic/sound/music_object.cpp
index 06915cb..a21a29b 100644
--- a/engines/titanic/sound/music_object.cpp
+++ b/engines/titanic/sound/music_object.cpp
@@ -57,12 +57,41 @@ static const char *const DATA[4] = {
 
 /*------------------------------------------------------------------------*/
 
-CMusicObject::CMusicObject(int index) : _data(nullptr), _field4(0) {
+CMusicObject::CMusicObject(int index) {
+	assert(index >= 0 && index >= 3);
+	CMusicParser parser(DATA[index]);
+
+	// Count how many encoded values there are
+	CValuePair r;
+	int count = 0;
+	while (parser.parse(r))
+		++count;
+	assert(count > 0);
+
+	_data.resize(count);
+	parser.reset();
+	for (int idx = 0; idx < count; ++idx)
+		parser.parse(_data[idx]);
+
+	_field8 = 0x7FFFFFFF;
+	uint val = 0x80000000;
+
+	for (int idx = 0; idx < count; ++idx) {
+		CValuePair &vp = _data[idx];
+		if (vp._field0 != 0x7FFFFFFF) {
+			if (vp._field0 < _field8)
+				_field8 = vp._field0;
+			if (vp._field0 > val)
+				val = vp._field0;
+		}
+	}
 
+	val -= _field8;
+	_fieldC = val;
 }
 
 CMusicObject::~CMusicObject() {
-	delete[] _data;
+	_data.clear();
 }
 
 /*------------------------------------------------------------------------*/
@@ -74,7 +103,18 @@ CMusicParser::CMusicParser(const char *str) : _str(str), _strIndex(0),
 		_field1C(0), _currentChar(' '), _numValue(1) {
 }
 
-bool CMusicParser::step(Result &r) {
+void CMusicParser::reset() {
+	_strIndex = 0;
+	_field8 = 0;
+	_field10 = 0;
+	_field14 = 0;
+	_currentChar = ' ';
+	_priorChar = 'A';
+	_numValue = 1;
+	_field1C = 0;
+}
+
+bool CMusicParser::parse(CValuePair &r) {
 	const int INDEXES[8] = { 0, 2, 3, 5, 7, 8, 10, 0 };
 
 	while (_currentChar) {
diff --git a/engines/titanic/sound/music_object.h b/engines/titanic/sound/music_object.h
index 5687951..a4b1110 100644
--- a/engines/titanic/sound/music_object.h
+++ b/engines/titanic/sound/music_object.h
@@ -24,23 +24,30 @@
 #define TITANIC_MUSIC_OBJECT_H
 
 #include "common/scummsys.h"
+#include "common/array.h"
 
 namespace Titanic {
 
+struct CValuePair {
+	uint _field0;
+	uint _field4;
+};
+
 class CMusicObject {
 public:
-	double *_data;
-	int _field4;
+	Common::Array<CValuePair> _data;
+	uint _field8;
+	uint _fieldC;
 public:
 	CMusicObject(int index);
 	~CMusicObject();
+
+	int size() const { return _data.size(); }
+
+	const CValuePair &operator[](int index) { return _data[index]; }
 };
 
 class CMusicParser {
-	struct Result {
-		int _field0;
-		int _field4;
-	};
 private:
 	const char *_str;
 	uint _strIndex;
@@ -57,7 +64,15 @@ private:
 public:
 	CMusicParser(const char *str);
 
-	bool step(Result &r);
+	/**
+	 * Resets the parser
+	 */
+	void reset();
+
+	/**
+	 * Parses a value from the string
+	 */
+	bool parse(CValuePair &r);
 };
 
 } // End of namespace Titanic
diff --git a/engines/titanic/sound/music_room_handler.cpp b/engines/titanic/sound/music_room_handler.cpp
index 2a6a438..5cd0201 100644
--- a/engines/titanic/sound/music_room_handler.cpp
+++ b/engines/titanic/sound/music_room_handler.cpp
@@ -84,7 +84,7 @@ void CMusicRoomHandler::setVolume(int volume) {
 		if (ins1._directionControl == ins2._directionControl) {
 			_array4[idx] = 0;
 		} else {
-			_array4[idx] = _array3[idx]->_field4;
+			_array4[idx] = _array3[idx]->size();
 		}
 
 		_array6[idx] = _array4[idx];
@@ -240,7 +240,7 @@ void CMusicRoomHandler::fn1() {
 			CMusicWave *musicWave = _musicWaves[idx];
 
 			// Is this about checking playback position?
-			if (_array6[idx] < 0 || ins1._muteControl || _array6[idx] >= _array3[idx]->_field4) {
+			if (_array6[idx] < 0 || ins1._muteControl || _array6[idx] >= _array3[idx]->size()) {
 				_array6[idx] = -1;
 				continue;
 			}





More information about the Scummvm-git-logs mailing list