[Scummvm-git-logs] scummvm master -> f40bec1105f6b1cf966d3154fbc91a801c50609e
bluegr
noreply at scummvm.org
Sat Mar 5 00:19:10 UTC 2022
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:
f40bec1105 CHEWY: Rewrite the hotspot state file (diah.adh) using memory streams
Commit: f40bec1105f6b1cf966d3154fbc91a801c50609e
https://github.com/scummvm/scummvm/commit/f40bec1105f6b1cf966d3154fbc91a801c50609e
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2022-03-05T02:18:49+02:00
Commit Message:
CHEWY: Rewrite the hotspot state file (diah.adh) using memory streams
This allows us to avoid creating a temporary file to disk
Changed paths:
R engines/chewy/temp_file.cpp
R engines/chewy/temp_file.h
engines/chewy/atds.cpp
engines/chewy/atds.h
engines/chewy/chewy.cpp
engines/chewy/chewy.h
engines/chewy/data.cpp
engines/chewy/data.h
engines/chewy/defines.h
engines/chewy/inits.cpp
engines/chewy/main.cpp
engines/chewy/module.mk
diff --git a/engines/chewy/atds.cpp b/engines/chewy/atds.cpp
index 432934f63c9..f308d00f02d 100644
--- a/engines/chewy/atds.cpp
+++ b/engines/chewy/atds.cpp
@@ -113,6 +113,13 @@ Atdsys::Atdsys() {
_invBlockNr = -1;
_invUseMem = nullptr;
_inzeig = _G(in)->getPointer();
+
+ _atdsStream = new Common::MemoryReadWriteStream(DisposeAfterUse::YES);
+ Common::File tmp;
+ tmp.open(ADS_TXT_STEUER);
+ _atdsStreamSize = tmp.size();
+ _atdsStream->writeStream(&tmp, _atdsStreamSize);
+ tmp.close();
}
Atdsys::~Atdsys() {
@@ -121,6 +128,8 @@ Atdsys::~Atdsys() {
if (_invUseMem)
free(_invUseMem);
+
+ // NOTE: _atdsStream is deleted by close_handle() above
}
void Atdsys::set_delay(int16 *delay, int16 silent) {
@@ -357,8 +366,19 @@ void Atdsys::set_handle(const char *fname, int16 mode, Stream *handle, int16 chu
void Atdsys::open_handle(const char *fname, int16 mode) {
char *tmp_adr = nullptr;
+ if (mode == ADH_DATA) {
+ if (_atdsmem[mode])
+ free(_atdsmem[mode]);
+
+ _atdshandle[mode] = _atdsStream;
+ _atdsmem[mode] = (char *)MALLOC(_atdsStreamSize + 3);
+ _adsBlock = (AdsBlock *)_atdsmem[mode];
+ return;
+ }
+
if (mode != INV_IDX_DATA)
tmp_adr = atds_adr(fname, 0, 20000);
+
Common::File *f = new Common::File();
f->open(fname);
if (f->isOpen()) {
@@ -366,18 +386,8 @@ void Atdsys::open_handle(const char *fname, int16 mode) {
_atdshandle[mode] = f;
_atdsmem[mode] = tmp_adr;
- switch (mode) {
- case ADH_DATA:
- _adsBlock = (AdsBlock *)_atdsmem[ADH_HANDLE];
- break;
-
- case INV_IDX_DATA:
+ if (mode == INV_IDX_DATA)
_atdsmem[INV_IDX_HANDLE] = (char *)MALLOC(INV_STRC_ANZ * sizeof(InvUse));
- break;
-
- default:
- break;
- }
} else {
error("Error reading from %s", fname);
}
@@ -404,7 +414,7 @@ char *Atdsys::atds_adr(const char *fname, int16 chunk_start, int16 chunk_anz) {
char *tmp_adr = nullptr;
uint32 size = _G(mem)->file->get_poolsize(fname, chunk_start, chunk_anz);
if (size) {
- tmp_adr = (char *)MALLOC(size + 3l);
+ tmp_adr = (char *)MALLOC(size + 3);
}
return tmp_adr;
@@ -450,13 +460,8 @@ void Atdsys::save_ads_header(int16 dia_nr) {
error("save_ads_header error");
} else {
if (Ch.size) {
- Common::SeekableWriteStream *ws = g_engine->_tempFiles.createWriteStreamForMember(ADSH_TMP);
- ws->seek(rs->pos());
- if (ws->write(_atdsmem[ADH_HANDLE], Ch.size) != Ch.size) {
- error("save_ads_header error");
- }
-
- delete ws;
+ _atdsStream->seek(rs->pos(), SEEK_SET);
+ _atdsStream->write(_atdsmem[ADH_HANDLE], Ch.size);
}
}
} else {
@@ -1410,4 +1415,17 @@ int16 Atdsys::getStereoPos(int16 x) {
#endif
}
+void Atdsys::saveAtdsStream(Common::WriteStream *stream) {
+ _atdsStream->seek(0, SEEK_SET);
+ stream->writeStream(_atdsStream, _atdsStreamSize);
+}
+
+void Atdsys::loadAtdsStream(Common::SeekableReadStream* stream) {
+ _atdsStream->seek(0, SEEK_SET);
+ _atdsStream->writeStream(stream, _atdsStreamSize);
+}
+
+uint32 Atdsys::getAtdsStreamSize() const {
+ return _atdsStreamSize;
+}
} // namespace Chewy
diff --git a/engines/chewy/atds.h b/engines/chewy/atds.h
index ee56d84a619..8106be22786 100644
--- a/engines/chewy/atds.h
+++ b/engines/chewy/atds.h
@@ -22,6 +22,8 @@
#ifndef CHEWY_ATDS_H
#define CHEWY_ATDS_H
+#include "common/memstream.h"
+
namespace Chewy {
#define ATDS_VOC_OFFSET 20
@@ -321,6 +323,10 @@ public:
return _atdsv.Display;
}
+ void saveAtdsStream(Common::WriteStream *stream);
+ void loadAtdsStream(Common::SeekableReadStream *stream);
+ uint32 getAtdsStreamSize() const;
+
private:
int16 get_delay(int16 txt_len);
@@ -355,6 +361,8 @@ private:
bool _hasSpeech = false;
int16 _mousePush = 0;
int _printDelayCount1 = 0;
+ Common::MemoryReadWriteStream *_atdsStream;
+ uint32 _atdsStreamSize;
};
} // namespace Chewy
diff --git a/engines/chewy/chewy.cpp b/engines/chewy/chewy.cpp
index 1782dc270f4..61c512b113a 100644
--- a/engines/chewy/chewy.cpp
+++ b/engines/chewy/chewy.cpp
@@ -73,8 +73,6 @@ void ChewyEngine::initialize() {
_sound = new Sound(_mixer);
_video = new VideoPlayer();
- _tempFiles.add(ADSH_TMP, 5710);
- SearchMan.add("temp", &_tempFiles, 99, false);
setDebugger(new Debugger());
}
@@ -101,11 +99,10 @@ Common::Error ChewyEngine::loadGameStream(Common::SeekableReadStream *stream) {
return Common::kReadingFailed;
} else {
- Common::SeekableWriteStream *adh = _tempFiles.createWriteStreamForMember(ADSH_TMP);
if (stream->readUint32BE() != SCUMMVM_TAG ||
- stream->readUint32LE() != adh->size())
+ stream->readUint32LE() != _G(atds)->getAtdsStreamSize())
return Common::kReadingFailed;
- adh->writeStream(stream, adh->size());
+ _G(atds)->loadAtdsStream(stream);
_G(flags).LoadGame = true;
@@ -150,10 +147,9 @@ Common::Error ChewyEngine::saveGameStream(Common::WriteStream *stream, bool isAu
if (!_G(spieler).synchronize(s))
return Common::kWritingFailed;
- Common::SeekableReadStream *rs = _tempFiles.createReadStreamForMember(ADSH_TMP);
stream->writeUint32BE(SCUMMVM_TAG);
- stream->writeUint32LE(rs->size());
- stream->writeStream(rs);
+ stream->writeUint32LE(_G(atds)->getAtdsStreamSize());
+ _G(atds)->saveAtdsStream(stream);
return Common::kNoError;
}
diff --git a/engines/chewy/chewy.h b/engines/chewy/chewy.h
index 8b82c1cc9e6..5fd2683591f 100644
--- a/engines/chewy/chewy.h
+++ b/engines/chewy/chewy.h
@@ -69,7 +69,6 @@ protected:
public:
const ChewyGameDescription *_gameDescription;
Common::RandomSource _rnd;
- TempFileArchive _tempFiles;
EventsManager *_events = nullptr;
Globals *_globals = nullptr;
Sound *_sound = nullptr;
diff --git a/engines/chewy/data.cpp b/engines/chewy/data.cpp
index 7c0e4d9577d..b9e591a10c4 100644
--- a/engines/chewy/data.cpp
+++ b/engines/chewy/data.cpp
@@ -121,16 +121,4 @@ uint32 Data::get_poolsize(const char *fname, int16 chunk_start, int16 chunk_anz)
return size;
}
-void Data::fcopy(const char *d_fname, const char *s_fname) {
- assert(!strcmp(d_fname, ADSH_TMP));
-
- Common::File f;
- if (!f.open(s_fname))
- error("Could not find - %s", s_fname);
-
- Common::SeekableWriteStream *ws = g_engine->_tempFiles.createWriteStreamForMember(ADSH_TMP);
- ws->writeStream(&f);
- delete ws;
-}
-
} // namespace Chewy
diff --git a/engines/chewy/data.h b/engines/chewy/data.h
index ea38942b0c9..903ce69903d 100644
--- a/engines/chewy/data.h
+++ b/engines/chewy/data.h
@@ -40,7 +40,6 @@ public:
uint32 load_tmf(Stream *stream, TmfHeader *song);
uint32 get_poolsize(const char *fname, int16 chunk_start, int16 chunk_anz);
- void fcopy(const char *d_fname, const char *s_fname);
};
} // namespace Chewy
diff --git a/engines/chewy/defines.h b/engines/chewy/defines.h
index b0e99a0e0ae..16973b564dd 100644
--- a/engines/chewy/defines.h
+++ b/engines/chewy/defines.h
@@ -181,8 +181,6 @@ enum SetupScreenMode {
#define DETAIL_TVP "sound/details.tap"
-#define ADSH_TMP "adsh.tmp"
-
#define QUIT_MSG_EN "QUIT ?? Y/N "
#define QUIT_MSG_DE "BEENDEN ?? J/N "
diff --git a/engines/chewy/inits.cpp b/engines/chewy/inits.cpp
index b477b842cd9..813cbfe4a79 100644
--- a/engines/chewy/inits.cpp
+++ b/engines/chewy/inits.cpp
@@ -208,8 +208,7 @@ void init_atds() {
_G(atds)->init_ats_mode(INV_USE_DATA, _G(spieler).InvUse);
_G(atds)->init_ats_mode(INV_USE_DEF, _G(spieler).InvUseDef);
_G(atds)->open_handle(INV_USE_IDX, INV_IDX_DATA);
- _G(mem)->file->fcopy(ADSH_TMP, "txt/diah.adh");
- _G(atds)->open_handle(ADSH_TMP, 3);
+ _G(atds)->open_handle("", ADH_DATA);
_G(spieler).AadSilent = 10;
_G(spieler).DelaySpeed = 5;
_G(spieler_vector)[P_CHEWY].Delay = _G(spieler).DelaySpeed;
diff --git a/engines/chewy/main.cpp b/engines/chewy/main.cpp
index 7bcd70733b8..cfaa370c724 100644
--- a/engines/chewy/main.cpp
+++ b/engines/chewy/main.cpp
@@ -67,7 +67,6 @@ void game_main() {
Dialogs::MainMenu::execute();
}
- remove(ADSH_TMP);
tidy();
_G(out)->rest_palette();
}
diff --git a/engines/chewy/module.mk b/engines/chewy/module.mk
index 6eb6869166f..8c03be8cfab 100644
--- a/engines/chewy/module.mk
+++ b/engines/chewy/module.mk
@@ -35,7 +35,6 @@ MODULE_OBJS = \
sound_player.o \
sprite.o \
t_event.o \
- temp_file.o \
text.o \
timer.o \
types.o \
diff --git a/engines/chewy/temp_file.cpp b/engines/chewy/temp_file.cpp
deleted file mode 100644
index 45db3760ce4..00000000000
--- a/engines/chewy/temp_file.cpp
+++ /dev/null
@@ -1,150 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-#include "chewy/temp_file.h"
-#include "common/file.h"
-
-namespace Chewy {
-
-TempFileArchive::Entry::Entry(const Common::String &name) :
- _name(name), _data(nullptr), _size(0) {
-}
-
-TempFileArchive::Entry::~Entry() {
- delete[] _data;
-}
-
-void TempFileArchive::Entry::allocate(size_t maxSize) {
- _data = new byte[maxSize];
- _size = maxSize;
-}
-
-bool TempFileArchive::FileProxy::eos() const {
- return _pos >= _size;
-}
-
-uint32 TempFileArchive::FileProxy::read(void *dataPtr, uint32 dataSize) {
- int bytesRemaining = MIN(_size - _pos, (int32)dataSize);
- Common::copy(_ptr + _pos, _ptr + _pos + bytesRemaining, (byte *)dataPtr);
- _pos += bytesRemaining;
- assert(_pos >= 0 && _pos <= 0xffff);
-
- return bytesRemaining;
-}
-
-uint32 TempFileArchive::FileProxy::write(const void *dataPtr, uint32 dataSize) {
- assert((int32)(_pos + dataSize) <= _size);
- Common::copy((const byte *)dataPtr, (const byte *)dataPtr + dataSize, _ptr + _pos);
- _pos += dataSize;
- assert(_pos >= 0 && _pos <= 0xffff);
-
- return dataSize;
-}
-
-int64 TempFileArchive::FileProxy::pos() const {
- return _pos;
-}
-
-int64 TempFileArchive::FileProxy::size() const {
- return _size;
-}
-
-bool TempFileArchive::FileProxy::seek(int64 offset, int whence) {
- switch (whence) {
- case SEEK_END:
- offset = size() + offset;
- // Fall through
- case SEEK_SET:
- // Fall through
- default:
- _pos = offset;
- break;
- case SEEK_CUR:
- _pos += offset;
- break;
- }
-
- assert(_pos >= 0 && _pos <= 0xffff);
- return true;
-}
-
-bool TempFileArchive::FileProxy::flush() {
- return true;
-}
-
-void TempFileArchive::FileProxy::finalize() {
-}
-
-
-TempFileArchive::TempFileArchive() {
-}
-
-const TempFileArchive::Entry *TempFileArchive::getEntry(const Common::String &name) const {
- for (EntryList::const_iterator it = _files.begin(); it != _files.end(); ++it) {
- const Entry &e = *it;
- if (e._name.equalsIgnoreCase(name))
- return &e;
- }
-
- return nullptr;
-}
-
-bool TempFileArchive::hasFile(const Common::Path &path) const {
- return getEntry(path.toString()) != nullptr;
-}
-
-int TempFileArchive::listMembers(Common::ArchiveMemberList &list) const {
- int count = 0;
- for (EntryList::const_iterator it = _files.begin(); it != _files.end(); ++it) {
- const Entry &e = *it;
- list.push_back(Common::ArchiveMemberList::value_type(new Common::GenericArchiveMember(e._name, this)));
- ++count;
- }
-
- return count;
-}
-
-const Common::ArchiveMemberPtr TempFileArchive::getMember(const Common::Path &path) const {
- Common::String name = path.toString();
- if (getEntry(name))
- return Common::ArchiveMemberPtr(
- new Common::GenericArchiveMember(name, this));
-
- return Common::ArchiveMemberPtr();
-}
-
-Common::SeekableReadStream *TempFileArchive::createReadStreamForMember(const Common::Path &path) const {
- const Entry *entry = getEntry(path.toString());
- if (!entry)
- return nullptr;
-
- return new FileProxy(entry->_data, entry->_size);
-}
-
-Common::SeekableWriteStream *TempFileArchive::createWriteStreamForMember(const Common::Path &path) {
- const Entry *entry = getEntry(path.toString());
- if (!entry)
- return nullptr;
-
- return new FileProxy(entry->_data, entry->_size);
-}
-
-} // namespace Chewy
diff --git a/engines/chewy/temp_file.h b/engines/chewy/temp_file.h
deleted file mode 100644
index b8bc1cfc8b9..00000000000
--- a/engines/chewy/temp_file.h
+++ /dev/null
@@ -1,121 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-#ifndef CHEWY_TEMP_FILE_H
-#define CHEWY_TEMP_FILE_H
-
-#include "common/archive.h"
-#include "common/list.h"
-#include "common/memstream.h"
-#include "common/path.h"
-#include "common/str.h"
-
-namespace Chewy {
-
-class TempFileArchive : public Common::Archive {
- struct Entry {
- Common::String _name;
- byte *_data;
- size_t _size;
- Entry() : _data(nullptr), _size(0) {}
- Entry(const Common::String &name);
- ~Entry();
-
- void allocate(size_t maxSize);
- };
- typedef Common::List<Entry> EntryList;
-
- class FileProxy : public Common::SeekableReadStream,
- public Common::SeekableWriteStream {
- private:
- byte *_ptr;
- int32 _pos, _size;
- public:
- FileProxy(byte *ptr, size_t ptrSize) :
- _ptr(ptr), _size(ptrSize), _pos(0) {}
-
- bool eos() const override;
- uint32 read(void *dataPtr, uint32 dataSize) override;
- int64 pos() const override;
- int64 size() const override;
- bool seek(int64 offset, int whence = SEEK_SET) override;
-
- uint32 write(const void *dataPtr, uint32 dataSize) override;
- bool flush() override;
- void finalize() override;
- };
-private:
- EntryList _files;
-
- /**
- * Finds an entry
- */
- const Entry *getEntry(const Common::String &name) const;
-public:
- /**
- * Constructor
- */
- TempFileArchive();
-
- /**
- * Registers a temporary file by name.
- */
- void add(const Common::String &name, size_t maxSize) {
- _files.push_back(Entry(name));
- _files.back().allocate(maxSize);
- }
-
- /**
- * Check if a member with the given name is present in the Archive.
- * Patterns are not allowed, as this is meant to be a quick File::exists()
- * replacement.
- */
- bool hasFile(const Common::Path &path) const override;
-
- /**
- * Add all members of the Archive to list.
- * Must only append to list, and not remove elements from it.
- *
- * @return the number of names added to list
- */
- int listMembers(Common::ArchiveMemberList &list) const override;
-
- /**
- * Returns a ArchiveMember representation of the given file.
- */
- const Common::ArchiveMemberPtr getMember(const Common::Path &path) const override;
-
- /**
- * Create a stream bound to a member with the specified name in the
- * archive. If no member with this name exists, 0 is returned.
- * @return the newly created input stream
- */
- Common::SeekableReadStream *createReadStreamForMember(const Common::Path &path) const override;
-
- /**
- * Creates a write stream
- */
- Common::SeekableWriteStream *createWriteStreamForMember(const Common::Path &path);
-};
-
-} // End of namespace Chewy
-
-#endif
More information about the Scummvm-git-logs
mailing list