Skip to content

Commit

Permalink
SCI: Hold script data as mutable internally
Browse files Browse the repository at this point in the history
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.)
  • Loading branch information
csnover committed Apr 30, 2017
1 parent 0560a1d commit 94dc6ae
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
7 changes: 3 additions & 4 deletions engines/sci/engine/savegame.cpp
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion engines/sci/engine/script.cpp
Expand Up @@ -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;
}

Expand Down
6 changes: 3 additions & 3 deletions engines/sci/engine/script.h
Expand Up @@ -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 */

Expand Down

0 comments on commit 94dc6ae

Please sign in to comment.