aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorPaul Gilbert2017-02-03 23:45:48 -0500
committerPaul Gilbert2017-02-03 23:45:48 -0500
commitd10ac8689071ca1916507072b5918e6bf2b26cac (patch)
tree0beac7c007efec2bf13d7ec23abe4ee915996b61 /engines
parent529680e6f87a6d541635e9761b6ad234dea7094a (diff)
downloadscummvm-rg350-d10ac8689071ca1916507072b5918e6bf2b26cac.tar.gz
scummvm-rg350-d10ac8689071ca1916507072b5918e6bf2b26cac.tar.bz2
scummvm-rg350-d10ac8689071ca1916507072b5918e6bf2b26cac.zip
TITANIC: Implemented CMusicObject initialization
Diffstat (limited to 'engines')
-rw-r--r--engines/titanic/sound/music_object.cpp46
-rw-r--r--engines/titanic/sound/music_object.h29
-rw-r--r--engines/titanic/sound/music_room_handler.cpp4
3 files changed, 67 insertions, 12 deletions
diff --git a/engines/titanic/sound/music_object.cpp b/engines/titanic/sound/music_object.cpp
index 06915cbfdb..a21a29b747 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 5687951a17..a4b11105ea 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 2a6a438aa8..5cd02018c4 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;
}