PRINCE: Migrate engine to Path

This commit is contained in:
Le Philousophe 2023-09-17 18:23:45 +02:00 committed by Eugene Sandulenko
parent e8a4a8af80
commit d7526ad280
10 changed files with 24 additions and 25 deletions

View File

@ -45,7 +45,7 @@ static void decrypt(byte *buffer, uint32 size) {
}
}
bool PtcArchive::open(const Common::String &filename) {
bool PtcArchive::open(const Common::Path &filename) {
_stream = SearchMan.createReadStreamForMember(filename);
if (!_stream)
return false;
@ -78,7 +78,7 @@ bool PtcArchive::open(const Common::String &filename) {
return true;
}
bool PtcArchive::openTranslation(const Common::String &filename) {
bool PtcArchive::openTranslation(const Common::Path &filename) {
_stream = SearchMan.createReadStreamForMember(filename);
if (!_stream)
return false;
@ -147,11 +147,10 @@ int PtcArchive::listMembers(Common::ArchiveMemberList &list) const {
}
const Common::ArchiveMemberPtr PtcArchive::getMember(const Common::Path &path) const {
Common::String name = path.toString();
if (!_items.contains(name)) {
if (!hasFile(path)) {
Common::ArchiveMemberPtr();
}
return Common::ArchiveMemberList::value_type(new Common::GenericArchiveMember(name, *this));
return Common::ArchiveMemberList::value_type(new Common::GenericArchiveMember(path, *this));
}
Common::SeekableReadStream *PtcArchive::createReadStreamForMember(const Common::Path &path) const {

View File

@ -33,8 +33,8 @@ public:
PtcArchive();
~PtcArchive() override;
bool open(const Common::String &filename);
bool openTranslation(const Common::String &filename);
bool open(const Common::Path &filename);
bool openTranslation(const Common::Path &filename);
void close();
bool isOpen() const { return _stream != 0; }

View File

@ -70,7 +70,7 @@ bool Object::loadFromStream(Common::SeekableReadStream &stream) {
_x = x;
_y = stream.readSint16LE(); // skull mini-game has some signed y coords
const Common::String obStreamName = Common::String::format("OB%02d", stream.readUint16LE());
const Common::Path obStreamName(Common::String::format("OB%02d", stream.readUint16LE()));
Common::SeekableReadStream *obStream = SearchMan.createReadStreamForMember(obStreamName);
if (obStream) {
obStream = Resource::getDecompressedStream(obStream);

View File

@ -193,9 +193,9 @@ PrinceEngine::~PrinceEngine() {
void PrinceEngine::init() {
const Common::FSNode gameDataDir(ConfMan.get("path"));
const Common::FSNode gameDataDir(ConfMan.getPath("path"));
debugEngine("Adding all path: %s", gameDataDir.getPath().c_str());
debugEngine("Adding all path: %s", gameDataDir.getPath().toString(Common::Path::kNativeSeparator).c_str());
if (!(getFeatures() & GF_EXTRACTED)) {
PtcArchive *all = new PtcArchive();

View File

@ -284,7 +284,7 @@ public:
Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave = false) override;
Common::Error loadGameState(int slot) override;
void playVideo(Common::String videoFilename);
void playVideo(const Common::Path &videoFilename);
WARN_UNUSED_RESULT static bool readSavegameHeader(Common::InSaveFile *in, SavegameHeader &header, bool skipThumbnail = true);
void writeSavegameHeader(Common::OutSaveFile *out, SavegameHeader &header);

View File

@ -61,7 +61,7 @@ bool PScr::loadFromStream(Common::SeekableReadStream &stream) {
_y = stream.readUint16LE();
_step = stream.readUint16LE();
const Common::String pscrStreamName = Common::String::format("PS%02d", file);
const Common::Path pscrStreamName(Common::String::format("PS%02d", file));
Common::SeekableReadStream *pscrStream = SearchMan.createReadStreamForMember(pscrStreamName);
if (pscrStream != nullptr) {
pscrStream = Resource::getDecompressedStream(pscrStream);

View File

@ -99,7 +99,7 @@ bool PrinceEngine::loadLocation(uint16 locationNr) {
freeAllSamples();
debugEngine("PrinceEngine::loadLocation %d", locationNr);
const Common::FSNode gameDataDir(ConfMan.get("path"));
const Common::FSNode gameDataDir(ConfMan.getPath("path"));
SearchMan.remove(Common::String::format("%02d", _locationNr));
_locationNr = locationNr;
@ -115,7 +115,7 @@ bool PrinceEngine::loadLocation(uint16 locationNr) {
if (!(getFeatures() & GF_EXTRACTED)) {
PtcArchive *locationArchive = new PtcArchive();
if (!locationArchive->open(locationNrStr + "/databank.ptc"))
if (!locationArchive->open(Common::Path(locationNrStr).appendComponent("databank.ptc")))
error("Can't open location %s", locationNrStr.c_str());
SearchMan.add(locationNrStr, locationArchive);
@ -203,21 +203,21 @@ bool PrinceEngine::loadLocation(uint16 locationNr) {
}
bool PrinceEngine::loadAnim(uint16 animNr, bool loop) {
Common::String streamName = Common::String::format("AN%02d", animNr);
Common::Path streamName(Common::String::format("AN%02d", animNr));
Common::SeekableReadStream *flicStream = SearchMan.createReadStreamForMember(streamName);
if (!flicStream) {
error("Can't open %s", streamName.c_str());
error("Can't open %s", streamName.toString().c_str());
return false;
}
flicStream = Resource::getDecompressedStream(flicStream);
if (!_flicPlayer.loadStream(flicStream)) {
error("Can't load flic stream %s", streamName.c_str());
error("Can't load flic stream %s", streamName.toString().c_str());
}
debugEngine("%s loaded", streamName.c_str());
debugEngine("%s loaded", streamName.toString().c_str());
_flicLooped = loop;
_flicPlayer.start();
playNextFLCFrame();
@ -321,7 +321,7 @@ bool PrinceEngine::loadAllInv() {
for (int i = 0; i < kMaxInv; i++) {
InvItem tempInvItem;
const Common::String invStreamName = Common::String::format("INV%02d", i);
const Common::Path invStreamName(Common::String::format("INV%02d", i));
Common::SeekableReadStream *invStream = SearchMan.createReadStreamForMember(invStreamName);
if (!invStream) {
delete invStream;

View File

@ -381,13 +381,13 @@ bool Script::loadAllMasks(Common::Array<Mask> &maskList, int offset) {
tempMask._z = maskStream.readUint16LE();
tempMask._number = maskStream.readUint16LE();
const Common::String msStreamName = Common::String::format("MS%02d", tempMask._number);
const Common::Path msStreamName(Common::String::format("MS%02d", tempMask._number));
Common::SeekableReadStream *msStream = SearchMan.createReadStreamForMember(msStreamName);
if (!msStream) {
tempMask._width = 0;
tempMask._height = 0;
tempMask._data = nullptr;
warning("loadAllMasks: Can't load %s", msStreamName.c_str());
warning("loadAllMasks: Can't load %s", msStreamName.toString().c_str());
delete msStream;
} else {
msStream = Resource::getDecompressedStream(msStream);

View File

@ -79,7 +79,7 @@ bool PrinceEngine::loadSample(uint32 sampleSlot, const Common::String &streamNam
debugEngine("loadSample slot %d, name %s", sampleSlot, normalizedPath.c_str());
freeSample(sampleSlot);
Common::SeekableReadStream *sampleStream = SearchMan.createReadStreamForMember(normalizedPath);
Common::SeekableReadStream *sampleStream = SearchMan.createReadStreamForMember(Common::Path(normalizedPath));
if (sampleStream == nullptr) {
delete sampleStream;
error("Can't load sample %s to slot %d", normalizedPath.c_str(), sampleSlot);
@ -103,7 +103,7 @@ bool PrinceEngine::loadVoice(uint32 slot, uint32 sampleSlot, const Common::Strin
}
freeSample(sampleSlot);
Common::SeekableReadStream *sampleStream = SearchMan.createReadStreamForMember(streamName);
Common::SeekableReadStream *sampleStream = SearchMan.createReadStreamForMember(Common::Path(streamName));
if (sampleStream == nullptr) {
warning("loadVoice: Can't open %s", streamName.c_str());
_missingVoice = true; // Insert END tag if needed

View File

@ -27,7 +27,7 @@
namespace Prince {
void PrinceEngine::playVideo(Common::String videoFilename) {
void PrinceEngine::playVideo(const Common::Path &videoFilename) {
// Set the correct video mode
initGraphics(640, 480, nullptr);
if (_system->getScreenFormat().bytesPerPixel == 1) {
@ -40,7 +40,7 @@ void PrinceEngine::playVideo(Common::String videoFilename) {
Video::VideoDecoder *videoDecoder = new Video::AVIDecoder();
if (!videoDecoder->loadFile(videoFilename)) {
delete videoDecoder;
warning("Unable to open video %s", videoFilename.c_str());
warning("Unable to open video %s", videoFilename.toString().c_str());
initGraphics(640, 480);
return;
}