aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Snover2017-04-30 12:38:50 -0500
committerColin Snover2017-04-30 12:47:32 -0500
commit94dc6ae05234b33677b10bca438819e59f6175fa (patch)
treed0088fdf1600f7494a32ad2dfad8082d9de44a89
parent0560a1d04119190535ed887f3dae6590930d9d09 (diff)
downloadscummvm-rg350-94dc6ae05234b33677b10bca438819e59f6175fa.tar.gz
scummvm-rg350-94dc6ae05234b33677b10bca438819e59f6175fa.tar.bz2
scummvm-rg350-94dc6ae05234b33677b10bca438819e59f6175fa.zip
SCI: Hold script data as mutable internally
Script buffer data is modified after a script is loaded by savegame operations, and, in SCI16, by string operations. Casting away const to allow these mutations to happen is not a very good design, so this patch just changes the privately held reference to data to be mutable. (Public accessors still return immutable data.)
-rw-r--r--engines/sci/engine/savegame.cpp7
-rw-r--r--engines/sci/engine/script.cpp2
-rw-r--r--engines/sci/engine/script.h6
3 files changed, 7 insertions, 8 deletions
diff --git a/engines/sci/engine/savegame.cpp b/engines/sci/engine/savegame.cpp
index 427e32deb3..5ba88d9417 100644
--- a/engines/sci/engine/savegame.cpp
+++ b/engines/sci/engine/savegame.cpp
@@ -467,7 +467,7 @@ void HunkTable::saveLoadWithSerializer(Common::Serializer &s) {
void Script::syncStringHeap(Common::Serializer &s) {
if (getSciVersion() < SCI_VERSION_1_1) {
// Sync all of the SCI_OBJ_STRINGS blocks
- SciSpan<byte> buf = (SciSpan<byte> &)*_buf;
+ SciSpan<byte> buf = *_buf;
bool oldScriptHeader = (getSciVersion() == SCI_VERSION_0_EARLY);
if (oldScriptHeader)
@@ -490,7 +490,7 @@ void Script::syncStringHeap(Common::Serializer &s) {
} else if (getSciVersion() >= SCI_VERSION_1_1 && getSciVersion() <= SCI_VERSION_2_1_LATE){
// Strings in SCI1.1 come after the object instances
- SciSpan<byte> buf = _heap.subspan<byte>(4 + _heap.getUint16SEAt(2) * 2);
+ SciSpan<byte> buf = _heap.subspan(4 + _heap.getUint16SEAt(2) * 2);
// Skip all of the objects
while (buf.getUint16SEAt(0) == SCRIPT_OBJECT_MAGIC_NUMBER)
@@ -502,8 +502,7 @@ void Script::syncStringHeap(Common::Serializer &s) {
} else if (getSciVersion() == SCI_VERSION_3) {
const int stringOffset = _buf->getInt32SEAt(4);
const int length = _buf->getInt32SEAt(8) - stringOffset;
- SciSpan<byte> buf = _buf->subspan<byte>(stringOffset, length);
- s.syncBytes(buf.getUnsafeDataAt(0, length), length);
+ s.syncBytes(_buf->getUnsafeDataAt(stringOffset, length), length);
}
}
diff --git a/engines/sci/engine/script.cpp b/engines/sci/engine/script.cpp
index 8cf6ad0c90..7e3a661501 100644
--- a/engines/sci/engine/script.cpp
+++ b/engines/sci/engine/script.cpp
@@ -882,7 +882,7 @@ SegmentRef Script::dereference(reg_t pointer) {
SegmentRef ret;
ret.isRaw = true;
ret.maxSize = _buf->size() - pointer.getOffset();
- ret.raw = const_cast<byte *>(_buf->getUnsafeDataAt(pointer.getOffset(), ret.maxSize));
+ ret.raw = _buf->getUnsafeDataAt(pointer.getOffset(), ret.maxSize);
return ret;
}
diff --git a/engines/sci/engine/script.h b/engines/sci/engine/script.h
index e0faa11575..f9b3845f6a 100644
--- a/engines/sci/engine/script.h
+++ b/engines/sci/engine/script.h
@@ -68,9 +68,9 @@ typedef Common::Array<offsetLookupArrayEntry> offsetLookupArrayType;
class Script : public SegmentObj {
private:
int _nr; /**< Script number */
- Common::SpanOwner<SciSpan<const byte> > _buf; /**< Static data buffer, or NULL if not used */
- SciSpan<const byte> _script; /**< Script size includes alignment byte */
- SciSpan<const byte> _heap; /**< Start of heap if SCI1.1, NULL otherwise */
+ Common::SpanOwner<SciSpan<byte> > _buf; /**< Static data buffer, or NULL if not used */
+ SciSpan<byte> _script; /**< Script size includes alignment byte */
+ SciSpan<byte> _heap; /**< Start of heap if SCI1.1, NULL otherwise */
int _lockers; /**< Number of classes and objects that require this script */