[Scummvm-git-logs] scummvm master -> 60abac9576ee80bd097285a99b877c5b8635784d
dreammaster
dreammaster at scummvm.org
Tue Dec 29 01:12:00 UTC 2020
This automated email contains information about 10 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
9b74410993 XEEN: create_xeen: Implement varargs prints for error
0826cb3025 XEEN: create_xeen: Fix error detection for file operations
4ede7a43c5 XEEN: files.cpp: Fix issues found by Codacy
38d04decf4 XEEN: debugger.cpp: Simplify to fix Codacy false positive
7bc15237f3 XEEN: debugger.cpp: Fix issues found by Codacy
cdd9aa483d XEEN: dialogs_query.cpp: Fix Codacy issues
ac6220b663 XEEN: sound.cpp: Fix Codacy issues
bb0f6a8cc0 XEEN: please_wait.cpp: Fix Codacy issue
2abfd5c71e XEEN: Deleted member SoundDriver::_exclude7
60abac9576 XEEN: Added class Stream to simplify SoundDriver::execute
Commit: 9b744109935b32463e914d6bdad687dc2d0c96e4
https://github.com/scummvm/scummvm/commit/9b744109935b32463e914d6bdad687dc2d0c96e4
Author: Jonathan Phénix (greaterd at gmail.com)
Date: 2020-12-28T15:11:50-10:00
Commit Message:
XEEN: create_xeen: Implement varargs prints for error
Changed paths:
devtools/create_xeen/create_xeen.cpp
diff --git a/devtools/create_xeen/create_xeen.cpp b/devtools/create_xeen/create_xeen.cpp
index 1cae2ce10c..3518b89177 100644
--- a/devtools/create_xeen/create_xeen.cpp
+++ b/devtools/create_xeen/create_xeen.cpp
@@ -42,7 +42,14 @@
#define VERSION_NUMBER 4
void NORETURN_PRE error(const char *s, ...) {
- fprintf(stderr, "%s\n", s);
+ va_list ap;
+
+ va_start(ap, s);
+ vfprintf(stderr, s, ap);
+ va_end(ap);
+
+ fputc('\n', stderr);
+
exit(1);
}
Commit: 0826cb302542990967b357b7d73750518da4dcfd
https://github.com/scummvm/scummvm/commit/0826cb302542990967b357b7d73750518da4dcfd
Author: Jonathan Phénix (greaterd at gmail.com)
Date: 2020-12-28T15:11:50-10:00
Commit Message:
XEEN: create_xeen: Fix error detection for file operations
These issues were found by Codacy.
Changed paths:
devtools/create_xeen/cc.cpp
devtools/create_xeen/swords.cpp
diff --git a/devtools/create_xeen/cc.cpp b/devtools/create_xeen/cc.cpp
index 1a8fea8fe8..eac0925de5 100644
--- a/devtools/create_xeen/cc.cpp
+++ b/devtools/create_xeen/cc.cpp
@@ -59,10 +59,15 @@ uint16 CCArchive::convertNameToId(const Common::String &resourceName) {
void CCArchive::loadIndex() {
int count = _file.readUint16LE();
+ size_t size = count * 8;
// Read in the data for the archive's index
- byte *rawIndex = new byte[count * 8];
- _file.read(rawIndex, count * 8);
+ byte *rawIndex = new byte[size];
+
+ if (_file.read(rawIndex, size) != size) {
+ delete[] rawIndex;
+ error("Failed to read %zu bytes from CC archive", size);
+ }
// Decrypt the index
int seed = 0xac;
@@ -151,8 +156,11 @@ Common::MemFile CCArchive::getMember(const Common::String &name) {
for (uint idx = 0; idx < _index.size(); ++idx) {
CCEntry &entry = _index[idx];
if (entry._id == id) {
- _file.seek(entry._offset);
- _file.read(entry._data, entry._size);
+ if (_file.seek(entry._offset) != 0)
+ error("Failed to seek to %d for CC archive", entry._offset);
+
+ if (_file.read(entry._data, entry._size) != entry._size)
+ error("Failed to read %hu bytes from CC archive", entry._size);
// Decrypt the entry
for (int i = 0; i < entry._size; ++i)
diff --git a/devtools/create_xeen/swords.cpp b/devtools/create_xeen/swords.cpp
index 838bfc87e6..151989cfa0 100644
--- a/devtools/create_xeen/swords.cpp
+++ b/devtools/create_xeen/swords.cpp
@@ -37,17 +37,22 @@
void writeSwordsData(CCArchive &cc, const char *swordsDatName) {
Common::File f;
Common::MemFile monsters;
- byte buffer[MONSTERS_COUNT * 60];
+ const size_t size = MONSTERS_COUNT * 60;
+ const int32 offset = 0x44200;
+ byte buffer[size];
if (!f.open(swordsDatName, Common::kFileReadMode))
- error("Could not open Swords xeen.dat");
+ error("Could not open '%s'", swordsDatName);
- f.seek(0x44200);
- f.read(buffer, MONSTERS_COUNT * 60);
+ if (f.seek(offset) != 0)
+ error("Failed to seek to 0x%x for '%s'", offset, swordsDatName);
+
+ if (f.read(buffer, size) != size)
+ error("Failed to read %zu bytes from '%s'", size, swordsDatName);
if (strcmp((const char *)buffer + 0x33, "Slime"))
- error("Invalid Swords xeen.dat");
+ error("Invalid '%s'", swordsDatName);
- monsters.write(buffer, MONSTERS_COUNT * 60);
+ monsters.write(buffer, size);
cc.add("monsters.swd", monsters);
}
Commit: 4ede7a43c5606cc01f098f509ddd3fb8634f28cc
https://github.com/scummvm/scummvm/commit/4ede7a43c5606cc01f098f509ddd3fb8634f28cc
Author: Jonathan Phénix (greaterd at gmail.com)
Date: 2020-12-28T15:11:50-10:00
Commit Message:
XEEN: files.cpp: Fix issues found by Codacy
Changed paths:
engines/xeen/files.cpp
diff --git a/engines/xeen/files.cpp b/engines/xeen/files.cpp
index 024c7020e5..b08d144d33 100644
--- a/engines/xeen/files.cpp
+++ b/engines/xeen/files.cpp
@@ -58,10 +58,15 @@ uint16 BaseCCArchive::convertNameToId(const Common::String &resourceName) {
void BaseCCArchive::loadIndex(Common::SeekableReadStream &stream) {
int count = stream.readUint16LE();
+ size_t size = count * 8;
// Read in the data for the archive's index
- byte *rawIndex = new byte[count * 8];
- stream.read(rawIndex, count * 8);
+ byte *rawIndex = new byte[size];
+
+ if (stream.read(rawIndex, size) != size) {
+ delete[] rawIndex;
+ error("Failed to read %zu bytes from CC file", size);
+ }
// Decrypt the index
int seed = 0xac;
@@ -198,9 +203,15 @@ Common::SeekableReadStream *CCArchive::createReadStreamForMember(const Common::S
error("Could not open CC file");
// Read in the data for the specific resource
- f.seek(ccEntry._offset);
+ if (!f.seek(ccEntry._offset))
+ error("Failed to seek to %d bytes in CC file", ccEntry._offset);
+
byte *data = (byte *)malloc(ccEntry._size);
- f.read(data, ccEntry._size);
+
+ if (f.read(data, ccEntry._size) != ccEntry._size) {
+ free(data);
+ error("Failed to read %hu bytes in CC file", ccEntry._size);
+ }
if (_encoded) {
// Decrypt the data
@@ -448,7 +459,7 @@ SaveArchive::SaveArchive(Party *party) : BaseCCArchive(), _party(party), _data(n
}
SaveArchive::~SaveArchive() {
- for (Common::HashMap<uint16, Common::MemoryWriteStreamDynamic *>::iterator it = _newData.begin(); it != _newData.end(); it++) {
+ for (Common::HashMap<uint16, Common::MemoryWriteStreamDynamic *>::iterator it = _newData.begin(); it != _newData.end(); ++it) {
delete (*it)._value;
}
delete[] _data;
@@ -485,8 +496,12 @@ void SaveArchive::load(Common::SeekableReadStream &stream) {
delete[] _data;
_dataSize = stream.size();
_data = new byte[_dataSize];
- stream.seek(0);
- stream.read(_data, _dataSize);
+
+ if (!stream.seek(0))
+ error("Failed to seek to 0 in the save archive");
+
+ if (!stream.read(_data, _dataSize))
+ error("Failed to read %u bytes from save archive", _dataSize);
}
void SaveArchive::loadParty() {
@@ -514,11 +529,17 @@ void SaveArchive::reset(CCArchive *src) {
if (src->hasFile(filename)) {
// Read in the next resource
fIn.open(filename, *src);
- byte *data = new byte[fIn.size()];
- fIn.read(data, fIn.size());
+
+ size_t size = fIn.size();
+ byte *data = new byte[size];
+
+ if (fIn.read(data, size) != size) {
+ delete[] data;
+ error("Failed to read %zu bytes from resource '%s' in save archive", size, filename.c_str());
+ }
// Copy it to the combined savefile resource
- saveFile.write(data, fIn.size());
+ saveFile.write(data, size);
delete[] data;
fIn.close();
}
@@ -559,12 +580,19 @@ void SaveArchive::save(Common::WriteStream &s) {
for (uint idx = 0; idx < _index.size(); ++idx) {
// Get the entry
Common::SeekableReadStream *entry = createReadStreamForMember(_index[idx]._id);
- byte *data = new byte[entry->size()];
- entry->read(data, entry->size());
+
+ size_t size = entry->size();
+ byte *data = new byte[size];
+
+ if (entry->read(data, size) != size) {
+ delete[] data;
+ delete entry;
+ error("Failed to read %zu bytes from entry %hu", size, _index[idx]._id);
+ }
// Write it out to the savegame
assert(dataStream.pos() == _index[idx]._writeOffset);
- dataStream.write(data, entry->size());
+ dataStream.write(data, size);
delete[] data;
delete entry;
}
Commit: 38d04decf4dfe5929091b0d1494a9c884e6a587a
https://github.com/scummvm/scummvm/commit/38d04decf4dfe5929091b0d1494a9c884e6a587a
Author: Jonathan Phénix (greaterd at gmail.com)
Date: 2020-12-28T15:11:50-10:00
Commit Message:
XEEN: debugger.cpp: Simplify to fix Codacy false positive
Changed paths:
engines/xeen/debugger.cpp
diff --git a/engines/xeen/debugger.cpp b/engines/xeen/debugger.cpp
index b73ad77fa2..43affc7a7c 100644
--- a/engines/xeen/debugger.cpp
+++ b/engines/xeen/debugger.cpp
@@ -27,10 +27,13 @@
namespace Xeen {
static int strToInt(const char *s) {
- if (!*s)
+ size_t size = strlen(s);
+
+ if (size == 0)
// No string at all
return 0;
- else if (toupper(s[strlen(s) - 1]) != 'H')
+
+ if (toupper(s[size - 1]) != 'H')
// Standard decimal string
return atoi(s);
Commit: 7bc15237f3bc53ebea280035af6588fbb0d7da95
https://github.com/scummvm/scummvm/commit/7bc15237f3bc53ebea280035af6588fbb0d7da95
Author: Jonathan Phénix (greaterd at gmail.com)
Date: 2020-12-28T15:11:50-10:00
Commit Message:
XEEN: debugger.cpp: Fix issues found by Codacy
Changed paths:
engines/xeen/debugger.cpp
diff --git a/engines/xeen/debugger.cpp b/engines/xeen/debugger.cpp
index 43affc7a7c..71d02c8072 100644
--- a/engines/xeen/debugger.cpp
+++ b/engines/xeen/debugger.cpp
@@ -63,16 +63,13 @@ Debugger::Debugger(XeenEngine *vm) : GUI::Debugger(), _vm(vm),
}
void Debugger::onFrame() {
- Party &party = *_vm->_party;
- Spells &spells = *_vm->_spells;
-
if (_spellId != -1) {
// Cast any specified spell
MagicSpell spellId = (MagicSpell)_spellId;
_spellId = -1;
- Character *c = &party._activeParty[0];
+ Character *c = &_vm->_party->_activeParty[0];
c->_currentSp = 99;
- spells.castSpell(c, spellId);
+ _vm->_spells->castSpell(c, spellId);
}
GUI::Debugger::onFrame();
@@ -120,9 +117,16 @@ bool Debugger::cmdDump(int argc, const char **argv) {
if (f.isOpen()) {
Common::DumpFile df;
df.open(argv[1]);
- byte *data = new byte[f.size()];
- f.read(data, f.size());
- df.write(data, f.size());
+
+ size_t size = f.size();
+ byte *data = new byte[size];
+
+ if (f.read(data, size) == size) {
+ df.write(data, size);
+
+ } else {
+ debugPrintf("Failed to read %zu bytes from '%s'\n", size, argv[1]);
+ }
f.close();
df.close();
@@ -163,13 +167,13 @@ bool Debugger::cmdGems(int argc, const char **argv) {
}
bool Debugger::cmdMap(int argc, const char **argv) {
- Map &map = *g_vm->_map;
- Party &party = *g_vm->_party;
-
if (argc < 2) {
debugPrintf("map mapId [ xp, yp ] [ sideNum ]\n");
return true;
} else {
+ Map &map = *g_vm->_map;
+ Party &party = *g_vm->_party;
+
int mapId = strToInt(argv[1]);
int x = argc < 3 ? 8 : strToInt(argv[2]);
int y = argc < 4 ? 8 : strToInt(argv[3]);
Commit: cdd9aa483d46d82556f7ab0bd0152b8ce6d5a87d
https://github.com/scummvm/scummvm/commit/cdd9aa483d46d82556f7ab0bd0152b8ce6d5a87d
Author: Jonathan Phénix (greaterd at gmail.com)
Date: 2020-12-28T15:11:50-10:00
Commit Message:
XEEN: dialogs_query.cpp: Fix Codacy issues
Changed paths:
engines/xeen/dialogs/dialogs_query.cpp
diff --git a/engines/xeen/dialogs/dialogs_query.cpp b/engines/xeen/dialogs/dialogs_query.cpp
index 475d5129c9..297966b63c 100644
--- a/engines/xeen/dialogs/dialogs_query.cpp
+++ b/engines/xeen/dialogs/dialogs_query.cpp
@@ -102,11 +102,7 @@ bool YesNo::show(XeenEngine *vm, bool type, bool townFlag) {
bool YesNo::execute(bool type, bool townFlag) {
EventsManager &events = *_vm->_events;
Interface &intf = *_vm->_interface;
- Map &map = *_vm->_map;
- Party &party = *_vm->_party;
- Resources &res = *_vm->_resources;
LocationManager &loc = *_vm->_locations;
- Windows &windows = *_vm->_windows;
SpriteResource confirmSprites;
bool result = false;
@@ -116,6 +112,11 @@ bool YesNo::execute(bool type, bool townFlag) {
setWaitBounds();
if (!type) {
+ Map &map = *_vm->_map;
+ Party &party = *_vm->_party;
+ Resources &res = *_vm->_resources;
+ Windows &windows = *_vm->_windows;
+
confirmSprites.load("confirm.icn");
res._globalSprites.draw(0, 7, Common::Point(232, 74));
confirmSprites.draw(0, 0, Common::Point(235, 75));
Commit: ac6220b663fe4b8899a73ac23db7c6de6683f3f9
https://github.com/scummvm/scummvm/commit/ac6220b663fe4b8899a73ac23db7c6de6683f3f9
Author: Jonathan Phénix (greaterd at gmail.com)
Date: 2020-12-28T15:11:50-10:00
Commit Message:
XEEN: sound.cpp: Fix Codacy issues
Changed paths:
engines/xeen/sound.cpp
diff --git a/engines/xeen/sound.cpp b/engines/xeen/sound.cpp
index a9f0ca6fe0..0b7540e75a 100644
--- a/engines/xeen/sound.cpp
+++ b/engines/xeen/sound.cpp
@@ -119,11 +119,16 @@ void Sound::loadEffectsData() {
if (!_effectsData) {
// Load in an entire driver so we have quick access to the effects data that's hardcoded within it
- File file("blastmus");
- byte *effectsData = new byte[file.size()];
- file.seek(0);
- file.read(effectsData, file.size());
- file.close();
+ const char *name = "blastmus";
+ File file(name);
+ size_t size = file.size();
+ byte *effectsData = new byte[size];
+
+ if (file.read(effectsData, size) != size) {
+ delete[] effectsData;
+ error("Failed to read %zu bytes from '%s'", size, name);
+ }
+
_effectsData = effectsData;
// Locate the playFX routine
@@ -170,9 +175,18 @@ void Sound::playSong(Common::SeekableReadStream &stream) {
if (!_musicOn)
return;
- byte *songData = new byte[stream.size()];
- stream.seek(0);
- stream.read(songData, stream.size());
+ if (!stream.seek(0))
+ error("Failed to seek to 0 for song data");
+
+ size_t size = stream.size();
+ byte *songData = new byte[size];
+
+ if (stream.read(songData, size) != size) {
+ delete[] songData;
+ error("Failed to read %zu bytes of song data", size);
+ }
+
+ assert(!_songData);
_songData = songData;
_SoundDriver->playSong(_songData);
Commit: bb0f6a8cc0cc88a004933e869be100f3fc90fd7b
https://github.com/scummvm/scummvm/commit/bb0f6a8cc0cc88a004933e869be100f3fc90fd7b
Author: Jonathan Phénix (greaterd at gmail.com)
Date: 2020-12-28T15:11:50-10:00
Commit Message:
XEEN: please_wait.cpp: Fix Codacy issue
Changed paths:
engines/xeen/dialogs/please_wait.cpp
diff --git a/engines/xeen/dialogs/please_wait.cpp b/engines/xeen/dialogs/please_wait.cpp
index 9186910f07..620264eb1f 100644
--- a/engines/xeen/dialogs/please_wait.cpp
+++ b/engines/xeen/dialogs/please_wait.cpp
@@ -37,14 +37,15 @@ PleaseWait::~PleaseWait() {
}
void PleaseWait::show() {
+ if (g_vm->_mode == MODE_STARTUP) {
+ return;
+ }
+
Windows &windows = *g_vm->_windows;
Window &w = windows[9];
-
- if (g_vm->_mode != MODE_STARTUP) {
- w.open();
- w.writeString(_msg);
- w.update();
- }
+ w.open();
+ w.writeString(_msg);
+ w.update();
}
} // End of namespace Xeen
Commit: 2abfd5c71e6a90fce4e933ea18730ded7d5b2878
https://github.com/scummvm/scummvm/commit/2abfd5c71e6a90fce4e933ea18730ded7d5b2878
Author: Jonathan Phénix (greaterd at gmail.com)
Date: 2020-12-28T15:11:50-10:00
Commit Message:
XEEN: Deleted member SoundDriver::_exclude7
It's always false and makes the code unnecessarily more complex.
Changed paths:
engines/xeen/sound_driver.cpp
engines/xeen/sound_driver.h
engines/xeen/sound_driver_adlib.cpp
diff --git a/engines/xeen/sound_driver.cpp b/engines/xeen/sound_driver.cpp
index 108eba2e5a..f8aa2480bf 100644
--- a/engines/xeen/sound_driver.cpp
+++ b/engines/xeen/sound_driver.cpp
@@ -31,7 +31,7 @@ namespace Xeen {
SoundDriver::SoundDriver() : _musicPlaying(false), _fxPlaying(false),
_musCountdownTimer(0), _fxCountdownTimer(0), _musDataPtr(nullptr),
_fxDataPtr(nullptr), _fxStartPtr(nullptr), _musStartPtr(nullptr),
- _exclude7(false), _frameCtr(0) {
+ _frameCtr(0) {
_channels.resize(CHANNEL_COUNT);
}
@@ -129,15 +129,11 @@ bool SoundDriver::cmdFreezeFrequency(const byte *&srcP, byte param) {
bool SoundDriver::cmdChangeFrequency(const byte *&srcP, byte param) {
debugC(3, kDebugSound, "cmdChangeFrequency %d", param);
- if (param != 7 || !_exclude7) {
- _channels[param]._freqCtrChange = (int8)*srcP++;
- _channels[param]._freqCtr = 0xFF;
- _channels[param]._changeFrequency = true;
- _channels[param]._freqChange = (int16)READ_BE_UINT16(srcP);
- srcP += 2;
- } else {
- srcP += 3;
- }
+ _channels[param]._freqCtrChange = (int8)*srcP++;
+ _channels[param]._freqCtr = 0xFF;
+ _channels[param]._changeFrequency = true;
+ _channels[param]._freqChange = (int16)READ_BE_UINT16(srcP);
+ srcP += 2;
return false;
}
diff --git a/engines/xeen/sound_driver.h b/engines/xeen/sound_driver.h
index 7c82866d0c..e53587d4e5 100644
--- a/engines/xeen/sound_driver.h
+++ b/engines/xeen/sound_driver.h
@@ -91,7 +91,6 @@ private:
bool command(const byte *&srcP);
protected:
Common::Array<Channel> _channels;
- bool _exclude7;
bool _musicPlaying;
bool _fxPlaying;
protected:
diff --git a/engines/xeen/sound_driver_adlib.cpp b/engines/xeen/sound_driver_adlib.cpp
index 4e74b2fc73..3d71d9b982 100644
--- a/engines/xeen/sound_driver_adlib.cpp
+++ b/engines/xeen/sound_driver_adlib.cpp
@@ -139,7 +139,7 @@ void SoundDriverAdlib::pausePostProcess() {
}
}
- for (int channelNum = 8; channelNum > (_exclude7 ? 7 : 6); --channelNum) {
+ for (int channelNum = 8; channelNum > 6; --channelNum) {
Channel &chan = _channels[channelNum];
if (!chan._changeFrequency || (chan._freqCtr += chan._freqCtrChange) >= 0)
continue;
@@ -177,12 +177,10 @@ void SoundDriverAdlib::pausePostProcess() {
}
void SoundDriverAdlib::resetFX() {
- if (!_exclude7) {
- _channels[7]._frequency = 0;
- setFrequency(7, 0);
- _channels[7]._volume = 63;
- setOutputLevel(7, 63);
- }
+ _channels[7]._frequency = 0;
+ setFrequency(7, 0);
+ _channels[7]._volume = 63;
+ setOutputLevel(7, 63);
_channels[8]._frequency = 0;
setFrequency(8, 0);
@@ -340,7 +338,7 @@ bool SoundDriverAdlib::fxSetInstrument(const byte *&srcP, byte param) {
bool SoundDriverAdlib::fxSetVolume(const byte *&srcP, byte param) {
debugC(3, kDebugSound, "fxSetVolume %d", (int)*srcP);
- if (!_field180 && (!_exclude7 || param != 7)) {
+ if (!_field180) {
_channels[param]._volume = *srcP;
setOutputLevel(param, *srcP);
}
@@ -363,11 +361,9 @@ bool SoundDriverAdlib::fxSetPanning(const byte *&srcP, byte param) {
byte note = *srcP++;
debugC(3, kDebugSound, "fxSetPanning - %x", note);
- if (!_exclude7 || param != 7) {
- uint freq = calcFrequency(note);
- setFrequency(param, freq);
- _channels[param]._frequency = freq;
- }
+ uint freq = calcFrequency(note);
+ setFrequency(param, freq);
+ _channels[param]._frequency = freq;
return false;
}
@@ -383,28 +379,21 @@ bool SoundDriverAdlib::fxFade(const byte *&srcP, byte param) {
uint freq = calcFrequency(*srcP++);
debugC(3, kDebugSound, "fxFade %d %x", param, freq);
- if (!_exclude7 || param != 7) {
- _channels[param]._frequency = freq;
- setFrequency(param, freq);
- }
+ _channels[param]._frequency = freq;
+ setFrequency(param, freq);
return false;
}
bool SoundDriverAdlib::fxStartNote(const byte *&srcP, byte param) {
- if (!_exclude7 || param != 7) {
- byte note = *srcP++;
- uint freq = calcFrequency(note);
- debugC(3, kDebugSound, "fxStartNote %x -> %x", note, freq);
+ byte note = *srcP++;
+ uint freq = calcFrequency(note);
+ debugC(3, kDebugSound, "fxStartNote %x -> %x", note, freq);
- setFrequency(param, freq);
- freq |= 0x2000;
- _channels[param]._frequency = freq;
- setFrequency(param, freq);
- } else {
- ++srcP;
- debugC(3, kDebugSound, "fxStartNote skipped");
- }
+ setFrequency(param, freq);
+ freq |= 0x2000;
+ _channels[param]._frequency = freq;
+ setFrequency(param, freq);
return false;
}
@@ -421,8 +410,7 @@ bool SoundDriverAdlib::fxPlayInstrument(const byte *&srcP, byte param) {
byte instrument = *srcP++;
debugC(3, kDebugSound, "fxPlayInstrument %d, %d", param, instrument);
- if (!_exclude7 || param != 7)
- playInstrument(param, _fxInstrumentPtrs[instrument], true);
+ playInstrument(param, _fxInstrumentPtrs[instrument], true);
return false;
}
Commit: 60abac9576ee80bd097285a99b877c5b8635784d
https://github.com/scummvm/scummvm/commit/60abac9576ee80bd097285a99b877c5b8635784d
Author: Jonathan Phénix (greaterd at gmail.com)
Date: 2020-12-28T15:11:50-10:00
Commit Message:
XEEN: Added class Stream to simplify SoundDriver::execute
The current version was complex enough to confuse Codacy.
Changed paths:
engines/xeen/sound_driver.cpp
engines/xeen/sound_driver.h
engines/xeen/sound_driver_adlib.cpp
diff --git a/engines/xeen/sound_driver.cpp b/engines/xeen/sound_driver.cpp
index f8aa2480bf..89a747622e 100644
--- a/engines/xeen/sound_driver.cpp
+++ b/engines/xeen/sound_driver.cpp
@@ -28,44 +28,31 @@
namespace Xeen {
-SoundDriver::SoundDriver() : _musicPlaying(false), _fxPlaying(false),
- _musCountdownTimer(0), _fxCountdownTimer(0), _musDataPtr(nullptr),
- _fxDataPtr(nullptr), _fxStartPtr(nullptr), _musStartPtr(nullptr),
- _frameCtr(0) {
+SoundDriver::SoundDriver() : _frameCtr(0) {
_channels.resize(CHANNEL_COUNT);
+ _streams[MUSIC] = Stream(MUSIC_COMMANDS);
+ _streams[FX] = Stream(FX_COMMANDS);
}
SoundDriver::~SoundDriver() {
- _musicPlaying = _fxPlaying = false;
- _musCountdownTimer = _fxCountdownTimer = 0;
}
-void SoundDriver::execute() {
- bool isFX = false;
- const byte *srcP = nullptr;
- const byte *startP = nullptr;
-
- // Single iteration loop to avoid use of GOTO
- do {
- if (_musicPlaying) {
- startP = _musStartPtr;
- srcP = _musDataPtr;
- isFX = false;
- if (_musCountdownTimer == 0 || --_musCountdownTimer == 0)
- break;
- }
-
- if (_fxPlaying) {
- startP = _fxStartPtr;
- srcP = _fxDataPtr;
- isFX = true;
- if (_fxCountdownTimer == 0 || --_fxCountdownTimer == 0)
- break;
- }
+SoundDriver::Stream *SoundDriver::tickStream() {
+ for (size_t i = 0; i < StreamType::LAST; ++i) {
+ Stream& stream = _streams[i];
+ if (stream._playing && (stream._countdownTimer == 0 || --stream._countdownTimer == 0))
+ return &stream;
+ }
+
+ return nullptr;
+}
+void SoundDriver::execute() {
+ Stream *stream = tickStream();
+ if (!stream) {
pausePostProcess();
return;
- } while (0);
+ }
++_frameCtr;
debugC(3, kDebugSound, "\nSoundDriver frame - #%x", _frameCtr);
@@ -73,13 +60,13 @@ void SoundDriver::execute() {
// Main loop
bool breakFlag = false;
while (!breakFlag) {
- debugCN(3, kDebugSound, "MUSCODE %.4x - %.2x ", (uint)(srcP - startP), (uint)*srcP);
- byte nextByte = *srcP++;
+ debugCN(3, kDebugSound, "MUSCODE %.4x - %.2x ", (uint)(stream->_dataPtr - stream->_startPtr), (uint)*stream->_dataPtr);
+ byte nextByte = *stream->_dataPtr++;
int cmd = (nextByte >> 4) & 15;
int param = (nextByte & 15);
- CommandFn fn = isFX ? FX_COMMANDS[cmd] : MUSIC_COMMANDS[cmd];
- breakFlag = (this->*fn)(srcP, param);
+ CommandFn fn = stream->_commands[cmd];
+ breakFlag = (this->*fn)(stream->_dataPtr, param);
}
}
@@ -88,7 +75,7 @@ bool SoundDriver::musCallSubroutine(const byte *&srcP, byte param) {
debugC(3, kDebugSound, "musCallSubroutine");
if (_musSubroutines.size() < 16) {
const byte *returnP = srcP + 2;
- srcP = _musStartPtr + READ_LE_UINT16(srcP);
+ srcP = _streams[MUSIC]._startPtr + READ_LE_UINT16(srcP);
_musSubroutines.push(Subroutine(returnP, srcP));
}
@@ -100,8 +87,8 @@ bool SoundDriver::musSetCountdown(const byte *&srcP, byte param) {
// Set the countdown timer
if (!param)
param = *srcP++;
- _musCountdownTimer = param;
- _musDataPtr = srcP;
+ _streams[MUSIC]._countdownTimer = param;
+ _streams[MUSIC]._dataPtr = srcP;
debugC(3, kDebugSound, "musSetCountdown %d", param);
// Do paused handling and break out of processing loop
@@ -143,12 +130,12 @@ bool SoundDriver::musEndSubroutine(const byte *&srcP, byte param) {
if (param != 15) {
// Music has ended, so flag it stopped
- _musicPlaying = false;
+ _streams[MUSIC]._playing = false;
return true;
}
// Returning from subroutine, or looping back to start of music
- srcP = _musSubroutines.empty() ? _musStartPtr : _musSubroutines.pop()._returnP;
+ srcP = _musSubroutines.empty() ? _streams[MUSIC]._startPtr : _musSubroutines.pop()._returnP;
return false;
}
@@ -157,7 +144,7 @@ bool SoundDriver::fxCallSubroutine(const byte *&srcP, byte param) {
if (_fxSubroutines.size() < 16) {
const byte *startP = srcP + 2;
- srcP = _musStartPtr + READ_LE_UINT16(srcP);
+ srcP = _streams[MUSIC]._startPtr + READ_LE_UINT16(srcP);
_fxSubroutines.push(Subroutine(startP, srcP));
}
@@ -169,8 +156,8 @@ bool SoundDriver::fxSetCountdown(const byte *&srcP, byte param) {
// Set the countdown timer
if (!param)
param = *srcP++;
- _fxCountdownTimer = param;
- _fxDataPtr = srcP;
+ _streams[FX]._countdownTimer = param;
+ _streams[FX]._dataPtr = srcP;
debugC(3, kDebugSound, "fxSetCountdown %d", param);
// Do paused handling and break out of processing loop
@@ -183,21 +170,21 @@ bool SoundDriver::fxEndSubroutine(const byte *&srcP, byte param) {
if (param != 15) {
// FX has ended, so flag it stopped
- _fxPlaying = false;
+ _streams[FX]._playing = false;
return true;
}
- srcP = _fxSubroutines.empty() ? _fxStartPtr : _fxSubroutines.pop()._returnP;
+ srcP = _fxSubroutines.empty() ? _streams[FX]._startPtr : _fxSubroutines.pop()._returnP;
return false;
}
void SoundDriver::playFX(uint effectId, const byte *data) {
- if (!_fxPlaying || effectId < 7 || effectId >= 11) {
- _fxDataPtr = _fxStartPtr = data;
- _fxCountdownTimer = 0;
+ if (!_streams[FX]._playing || effectId < 7 || effectId >= 11) {
+ _streams[FX]._dataPtr = _streams[FX]._startPtr = data;
+ _streams[FX]._countdownTimer = 0;
_channels[7]._changeFrequency = _channels[8]._changeFrequency = false;
resetFX();
- _fxPlaying = true;
+ _streams[FX]._playing = true;
}
debugC(1, kDebugSound, "Starting FX %d", effectId);
@@ -205,24 +192,24 @@ void SoundDriver::playFX(uint effectId, const byte *data) {
void SoundDriver::stopFX() {
resetFX();
- _fxPlaying = false;
- _fxStartPtr = _fxDataPtr = nullptr;
+ _streams[FX]._playing = false;
+ _streams[FX]._startPtr = _streams[FX]._dataPtr = nullptr;
}
void SoundDriver::playSong(const byte *data) {
- _musDataPtr = _musStartPtr = data;
+ _streams[MUSIC]._dataPtr = _streams[MUSIC]._startPtr = data;
_musSubroutines.clear();
- _musCountdownTimer = 0;
- _musicPlaying = true;
+ _streams[MUSIC]._countdownTimer = 0;
+ _streams[MUSIC]._playing = true;
debugC(1, kDebugSound, "Starting song");
}
int SoundDriver::songCommand(uint commandId, byte musicVolume, byte sfxVolume) {
if (commandId == STOP_SONG) {
- _musicPlaying = false;
+ _streams[MUSIC]._playing = false;
} else if (commandId == RESTART_SONG) {
- _musicPlaying = true;
- _musDataPtr = nullptr;
+ _streams[MUSIC]._playing = true;
+ _streams[MUSIC]._dataPtr = nullptr;
_musSubroutines.clear();
}
diff --git a/engines/xeen/sound_driver.h b/engines/xeen/sound_driver.h
index e53587d4e5..a6fa1fc131 100644
--- a/engines/xeen/sound_driver.h
+++ b/engines/xeen/sound_driver.h
@@ -71,16 +71,29 @@ protected:
Channel() : _changeFrequency(false), _freqCtr(0), _freqCtrChange(0),
_freqChange(0), _volume(0), _totalLevel(0), _frequency(0), _isFx(false) {}
};
+ enum StreamType {
+ MUSIC,
+ FX,
+
+ LAST,
+ };
+ class Stream {
+ public:
+ Stream() {}
+ Stream(const CommandFn *commands) : _playing(false), _countdownTimer(0), _dataPtr(nullptr), _startPtr(nullptr), _commands(commands) {}
+
+ bool _playing;
+ int _countdownTimer;
+ const byte *_dataPtr;
+ const byte *_startPtr;
+ const CommandFn *_commands;
+ };
+
private:
static const CommandFn FX_COMMANDS[16];
static const CommandFn MUSIC_COMMANDS[16];
private:
Common::Stack<Subroutine> _musSubroutines, _fxSubroutines;
- int _musCountdownTimer;
- int _fxCountdownTimer;
- const byte *_fxDataPtr, *_musDataPtr;
- const byte *_fxStartPtr;
- const byte *_musStartPtr;
uint _frameCtr;
private:
/**
@@ -89,10 +102,12 @@ private:
* @returns If true, execution of commands for the current timer call stops
*/
bool command(const byte *&srcP);
+
+ Stream *tickStream();
protected:
Common::Array<Channel> _channels;
- bool _musicPlaying;
- bool _fxPlaying;
+ Stream _streams[StreamType::LAST];
+
protected:
/**
* Executes a series of commands until instructed to stop
@@ -174,7 +189,7 @@ public:
/**
* Returns whether music is currently playing
*/
- bool isPlaying() const { return _musicPlaying; }
+ bool isPlaying() const { return _streams[MUSIC]._playing; }
};
} // End of namespace Xeen
diff --git a/engines/xeen/sound_driver_adlib.cpp b/engines/xeen/sound_driver_adlib.cpp
index 3d71d9b982..cfbd59558c 100644
--- a/engines/xeen/sound_driver_adlib.cpp
+++ b/engines/xeen/sound_driver_adlib.cpp
@@ -95,9 +95,9 @@ int SoundDriverAdlib::songCommand(uint commandId, byte musicVolume, byte sfxVolu
resetFrequencies();
} else if (commandId == RESTART_SONG) {
_field180 = 0;
- _musicPlaying = true;
+ _streams[MUSIC]._playing = true;
} else if (commandId < 0x100) {
- if (_musicPlaying) {
+ if (_streams[MUSIC]._playing) {
_field180 = commandId;
_field182 = 63;
}
@@ -128,7 +128,7 @@ void SoundDriverAdlib::flush() {
void SoundDriverAdlib::pausePostProcess() {
if (_field180 && ((_field181 += _field180) < 0)) {
if (--_field182 < 0) {
- _musicPlaying = false;
+ _streams[MUSIC]._playing = false;
_field180 = 0;
resetFrequencies();
} else {
More information about the Scummvm-git-logs
mailing list