[Scummvm-git-logs] scummvm master -> c1b91890e511721d30b95cbe588628a5d605b810
OMGPizzaGuy
48367439+OMGPizzaGuy at users.noreply.github.com
Wed Feb 24 01:22:24 UTC 2021
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:
c1b91890e5 ULTIMA8: Replace IDataSource and ODataSource with utility functions for common streams
Commit: c1b91890e511721d30b95cbe588628a5d605b810
https://github.com/scummvm/scummvm/commit/c1b91890e511721d30b95cbe588628a5d605b810
Author: Matthew Jimenez (matthew.jimenez at outlook.com)
Date: 2021-02-23T19:22:02-06:00
Commit Message:
ULTIMA8: Replace IDataSource and ODataSource with utility functions for common streams
Changed paths:
A engines/ultima/ultima8/misc/stream_util.h
R engines/ultima/ultima8/filesys/idata_source.h
R engines/ultima/ultima8/filesys/odata_source.h
R test/engines/ultima/ultima8/filesys/idata_source.h
engines/ultima/ultima8/audio/music_flex.cpp
engines/ultima/ultima8/convert/convert_shape.cpp
engines/ultima/ultima8/convert/convert_shape.h
engines/ultima/ultima8/filesys/file_system.h
engines/ultima/ultima8/filesys/savegame.cpp
engines/ultima/ultima8/games/game_info.cpp
engines/ultima/ultima8/graphics/raw_shape_frame.cpp
engines/ultima/ultima8/graphics/shape.cpp
engines/ultima/ultima8/graphics/shape.h
engines/ultima/ultima8/graphics/skf_player.cpp
engines/ultima/ultima8/graphics/wpn_ovlay_dat.cpp
engines/ultima/ultima8/kernel/object_manager.h
engines/ultima/ultima8/world/world.cpp
diff --git a/engines/ultima/ultima8/audio/music_flex.cpp b/engines/ultima/ultima8/audio/music_flex.cpp
index 6dcf9ba0bf..02e1a3fb2f 100644
--- a/engines/ultima/ultima8/audio/music_flex.cpp
+++ b/engines/ultima/ultima8/audio/music_flex.cpp
@@ -23,7 +23,6 @@
#include "ultima/ultima8/misc/pent_include.h"
#include "ultima/ultima8/audio/music_flex.h"
-#include "ultima/ultima8/filesys/idata_source.h"
#include "common/memstream.h"
namespace Ultima {
diff --git a/engines/ultima/ultima8/convert/convert_shape.cpp b/engines/ultima/ultima8/convert/convert_shape.cpp
index 50bd51a027..260d6583d2 100644
--- a/engines/ultima/ultima8/convert/convert_shape.cpp
+++ b/engines/ultima/ultima8/convert/convert_shape.cpp
@@ -22,8 +22,8 @@
#include "common/memstream.h"
#include "ultima/ultima8/convert/convert_shape.h"
-#include "ultima/ultima8/filesys/idata_source.h"
-#include "ultima/ultima8/filesys/odata_source.h"
+#include "ultima/ultima8/misc/stream_util.h"
+#include "ultima/ultima8/misc/pent_include.h"
namespace Ultima {
namespace Ultima8 {
@@ -55,14 +55,14 @@ void ConvertShape::Free() {
_num_frames = 0;
}
-void ConvertShape::Read(IDataSource *source, const ConvertShapeFormat *csf, uint32 real_len) {
+void ConvertShape::Read(Common::SeekableReadStream &source, const ConvertShapeFormat *csf, uint32 real_len) {
// Just to be safe
- uint32 start_pos = source->pos();
+ uint32 start_pos = source.pos();
// Read the ident
if (csf->_bytes_ident) {
char ident[4];
- source->read(ident, csf->_bytes_ident);
+ source.read(ident, csf->_bytes_ident);
if (memcmp (ident, csf->_ident, csf->_bytes_ident)) {
perr << "Warning: Corrupt shape!" << Std::endl;
@@ -74,11 +74,11 @@ void ConvertShape::Read(IDataSource *source, const ConvertShapeFormat *csf, uint
uint8 special[256];
if (csf->_bytes_special) {
memset(special, 0, 256);
- for (uint32 i = 0; i < csf->_bytes_special; i++) special[source->readByte()&0xFF] = i + 2;
+ for (uint32 i = 0; i < csf->_bytes_special; i++) special[source.readByte()&0xFF] = i + 2;
}
// Read the header unknown
- if (csf->_bytes_header_unk) source->read(_header_unknown, csf->_bytes_header_unk);
+ if (csf->_bytes_header_unk) source.read(_header_unknown, csf->_bytes_header_unk);
#ifdef COMP_SHAPENUM
if (shapenum == COMP_SHAPENUM) pout << Std::hex;
@@ -86,7 +86,7 @@ void ConvertShape::Read(IDataSource *source, const ConvertShapeFormat *csf, uint
// Now read _num_frames
_num_frames = 1;
- if (csf->_bytes_num_frames) _num_frames = source->readX(csf->_bytes_num_frames);
+ if (csf->_bytes_num_frames) _num_frames = readX(source, csf->_bytes_num_frames);
if (_num_frames == 0) _num_frames = CalcNumFrames(source,csf,real_len,start_pos);
#ifdef COMP_SHAPENUM
@@ -117,31 +117,31 @@ void ConvertShape::Read(IDataSource *source, const ConvertShapeFormat *csf, uint
if (shapenum == COMP_SHAPENUM) pout << "Real " << (start_pos + csf->_len_header + (csf->_len_frameheader * f)) << Std::endl;
#endif
// Seek to initial pos
- source->seek(start_pos + csf->_len_header + (csf->_len_frameheader * f));
+ source.seek(start_pos + csf->_len_header + (csf->_len_frameheader * f));
#ifdef COMP_SHAPENUM
- if (shapenum == COMP_SHAPENUM) pout << "seeked to " << source->pos() << Std::endl;
+ if (shapenum == COMP_SHAPENUM) pout << "seeked to " << source.pos() << Std::endl;
#endif
// Read the offset
uint32 frame_offset = csf->_len_header + (csf->_len_frameheader * f);
- if (csf->_bytes_frame_offset) frame_offset = source->readX(csf->_bytes_frame_offset);
+ if (csf->_bytes_frame_offset) frame_offset = readX(source, csf->_bytes_frame_offset);
#ifdef COMP_SHAPENUM
if (shapenum == COMP_SHAPENUM) pout << "frame_offset " << frame_offset << Std::endl;
#endif
// Read the unknown
- if (csf->_bytes_frameheader_unk) source->read(frame->_header_unknown, csf->_bytes_frameheader_unk);
+ if (csf->_bytes_frameheader_unk) source.read(frame->_header_unknown, csf->_bytes_frameheader_unk);
// Read frame_length
uint32 frame_length = real_len-frame_offset;
- if (csf->_bytes_frame_length) frame_length = source->readX(csf->_bytes_frame_length) + csf->_bytes_frame_length_kludge;
+ if (csf->_bytes_frame_length) frame_length = readX(source, csf->_bytes_frame_length) + csf->_bytes_frame_length_kludge;
#ifdef COMP_SHAPENUM
if (shapenum == COMP_SHAPENUM) pout << "frame_length " << frame_length << Std::endl;
#endif
// Seek to start of frame
- source->seek(start_pos + frame_offset + csf->_bytes_special);
+ source.seek(start_pos + frame_offset + csf->_bytes_special);
if (csf->_bytes_special)
frame->ReadCmpFrame(source, csf, special, f > 0 ? _frames + f - 1 : 0);
@@ -154,16 +154,16 @@ void ConvertShape::Read(IDataSource *source, const ConvertShapeFormat *csf, uint
#endif
}
-void ConvertShapeFrame::Read(IDataSource *source, const ConvertShapeFormat *csf, uint32 frame_length) {
+void ConvertShapeFrame::Read(Common::SeekableReadStream &source, const ConvertShapeFormat *csf, uint32 frame_length) {
// Read unknown
- if (csf->_bytes_frame_unknown) source->read(_unknown, csf->_bytes_frame_unknown);
+ if (csf->_bytes_frame_unknown) source.read(_unknown, csf->_bytes_frame_unknown);
// Frame details
- _compression = source->readX(csf->_bytes_frame_compression);
- _width = source->readXS(csf->_bytes_frame_width);
- _height = source->readXS(csf->_bytes_frame_height);
- _xoff = source->readXS(csf->_bytes_frame_xoff);
- _yoff = source->readXS(csf->_bytes_frame_yoff);
+ _compression = readX(source, csf->_bytes_frame_compression);
+ _width = readXS(source, csf->_bytes_frame_width);
+ _height = readXS(source, csf->_bytes_frame_height);
+ _xoff = readXS(source, csf->_bytes_frame_xoff);
+ _yoff = readXS(source, csf->_bytes_frame_yoff);
#ifdef COMP_SHAPENUM
if (_width <= 0 || _height <= 0 ||shapenum == COMP_SHAPENUM )
@@ -191,7 +191,7 @@ void ConvertShapeFrame::Read(IDataSource *source, const ConvertShapeFormat *csf,
_line_offsets = new uint32 [_height];
for (int32 i = 0; i < _height; ++i) {
- _line_offsets[i] = source->readX(csf->_bytes_line_offset);
+ _line_offsets[i] = readX(source, csf->_bytes_line_offset);
// Now fudge with the value and turn it into an offset into the rle data
// If required
@@ -215,24 +215,24 @@ void ConvertShapeFrame::Read(IDataSource *source, const ConvertShapeFormat *csf,
// Read the RLE Data
if (_bytes_rle) {
_rle_data = new uint8[_bytes_rle];
- source->read(_rle_data, _bytes_rle);
+ source.read(_rle_data, _bytes_rle);
} else
_rle_data = nullptr;
}
-void ConvertShapeFrame::ReadCmpFrame(IDataSource *source, const ConvertShapeFormat *csf, const uint8 special[256], ConvertShapeFrame *prev) {
+void ConvertShapeFrame::ReadCmpFrame(Common::SeekableReadStream &source, const ConvertShapeFormat *csf, const uint8 special[256], ConvertShapeFrame *prev) {
Common::MemoryWriteStreamDynamic rlebuf(DisposeAfterUse::YES);
uint8 outbuf[512];
// Read unknown
- if (csf->_bytes_frame_unknown) source->read(_unknown, csf->_bytes_frame_unknown);
+ if (csf->_bytes_frame_unknown) source.read(_unknown, csf->_bytes_frame_unknown);
// Frame details
- _compression = source->readX(csf->_bytes_frame_compression);
- _width = source->readXS(csf->_bytes_frame_width);
- _height = source->readXS(csf->_bytes_frame_height);
- _xoff = source->readXS(csf->_bytes_frame_xoff);
- _yoff = source->readXS(csf->_bytes_frame_yoff);
+ _compression = readX(source, csf->_bytes_frame_compression);
+ _width = readXS(source, csf->_bytes_frame_width);
+ _height = readXS(source, csf->_bytes_frame_height);
+ _xoff = readXS(source, csf->_bytes_frame_xoff);
+ _yoff = readXS(source, csf->_bytes_frame_yoff);
_line_offsets = new uint32 [_height];
@@ -242,11 +242,11 @@ void ConvertShapeFrame::ReadCmpFrame(IDataSource *source, const ConvertShapeForm
int32 xpos = 0;
do {
- uint8 skip = source->readByte();
+ uint8 skip = source.readByte();
xpos += skip;
if (xpos > _width) {
- source->seek(-1, SEEK_CUR);
+ source.seek(-1, SEEK_CUR);
skip = _width-(xpos-skip);
}
@@ -254,12 +254,12 @@ void ConvertShapeFrame::ReadCmpFrame(IDataSource *source, const ConvertShapeForm
if (xpos >= _width) break;
- uint32 dlen = source->readByte();
+ uint32 dlen = source.readByte();
uint8 *o = outbuf;
// Is this required???? It seems hacky and pointless
if (dlen == 0 || dlen == 1) {
- source->seek(-1, SEEK_CUR);
+ source.seek(-1, SEEK_CUR);
rlebuf.seek(-1, SEEK_CUR);
rlebuf.writeByte(skip + (_width - xpos));
break;
@@ -278,7 +278,7 @@ void ConvertShapeFrame::ReadCmpFrame(IDataSource *source, const ConvertShapeForm
for (uint32 j = 0; j < dlen; j++) {
- uint8 c = source->readByte();
+ uint8 c = source.readByte();
if (special[c] && prev) {
int32 count = special[c];
@@ -287,7 +287,7 @@ void ConvertShapeFrame::ReadCmpFrame(IDataSource *source, const ConvertShapeForm
extra += count - 1;
xpos += count;
} else if (c == 0xFF && prev) {
- int32 count = source->readByte();
+ int32 count = source.readByte();
prev->GetPixels(o, count, xpos - _xoff, y - _yoff);
o+=count;
extra += count - 2;
@@ -307,7 +307,7 @@ void ConvertShapeFrame::ReadCmpFrame(IDataSource *source, const ConvertShapeForm
rlebuf.write(outbuf,dlen+extra);
} else {
rlebuf.writeByte((dlen << 1) | 1);
- rlebuf.writeByte(source->readByte());
+ rlebuf.writeByte(source.readByte());
xpos+=dlen;
}
@@ -378,71 +378,71 @@ void ConvertShapeFrame::GetPixels(uint8 *buf, int32 count, int32 x, int32 y) {
} while (xpos < _width);
}
-int ConvertShape::CalcNumFrames(IDataSource *source, const ConvertShapeFormat *csf, uint32 real_len, uint32 start_pos) {
+int ConvertShape::CalcNumFrames(Common::SeekableReadStream &source, const ConvertShapeFormat *csf, uint32 real_len, uint32 start_pos) {
int f = 0;
uint32 first_offset = 0xFFFFFFFF;
- uint32 save_pos = source->pos();
+ uint32 save_pos = source.pos();
for (f = 0;; f++) {
// Seek to initial pos
- source->seek(start_pos + csf->_len_header + (csf->_len_frameheader * f));
+ source.seek(start_pos + csf->_len_header + (csf->_len_frameheader * f));
- if ((source->pos()-start_pos) >= first_offset) break;
+ if ((source.pos()-start_pos) >= first_offset) break;
// Read the offset
uint32 frame_offset = csf->_len_header + (csf->_len_frameheader * f);
- if (csf->_bytes_frame_offset) frame_offset = source->readX(csf->_bytes_frame_offset) + csf->_bytes_special;
+ if (csf->_bytes_frame_offset) frame_offset = readX(source, csf->_bytes_frame_offset) + csf->_bytes_special;
if (frame_offset < first_offset) first_offset = frame_offset;
// Read the unknown
- if (csf->_bytes_frameheader_unk) source->skip(csf->_bytes_frameheader_unk);
+ if (csf->_bytes_frameheader_unk) source.skip(csf->_bytes_frameheader_unk);
// Read frame_length
uint32 frame_length = real_len-frame_offset;
if (csf->_bytes_frame_length)
- frame_length = source->readX(csf->_bytes_frame_length) + csf->_bytes_frame_length_kludge;
+ frame_length = readX(source, csf->_bytes_frame_length) + csf->_bytes_frame_length_kludge;
debug(MM_INFO, "Frame %d length = %xh", f, frame_length);
}
- source->seek(save_pos);
+ source.seek(save_pos);
return f;
}
-bool ConvertShape::Check(IDataSource *source, const ConvertShapeFormat *csf, uint32 real_len) {
+bool ConvertShape::Check(Common::SeekableReadStream &source, const ConvertShapeFormat *csf, uint32 real_len) {
#if 0
pout << "Testing " << csf->_name << "..." << Std::endl;
#endif
bool result = true;
// Just to be safe
- int start_pos = source->pos();
+ int start_pos = source.pos();
// Read the ident
if (csf->_bytes_ident) {
char ident[5];
ident[csf->_bytes_ident] = 0;
- source->read(ident, csf->_bytes_ident);
+ source.read(ident, csf->_bytes_ident);
if (memcmp (ident, csf->_ident, csf->_bytes_ident)) {
// Return to start position
- source->seek(start_pos);
+ source.seek(start_pos);
return false;
}
}
// Read the header special colour
- if (csf->_bytes_special) source->skip(csf->_bytes_special);
+ if (csf->_bytes_special) source.skip(csf->_bytes_special);
// Read the header unknown
- if (csf->_bytes_header_unk) source->skip(csf->_bytes_header_unk);
+ if (csf->_bytes_header_unk) source.skip(csf->_bytes_header_unk);
// Now read _num_frames
int numFrames = 1;
- if (csf->_bytes_num_frames) numFrames = source->readX(csf->_bytes_num_frames);
+ if (csf->_bytes_num_frames) numFrames = readX(source, csf->_bytes_num_frames);
if (numFrames == 0) numFrames = CalcNumFrames(source,csf,real_len,start_pos);
// Create _frames array
@@ -454,18 +454,18 @@ bool ConvertShape::Check(IDataSource *source, const ConvertShapeFormat *csf, uin
ConvertShapeFrame *frame = &oneframe;
// Seek to initial pos
- source->seek(start_pos + csf->_len_header + (csf->_len_frameheader * f));
+ source.seek(start_pos + csf->_len_header + (csf->_len_frameheader * f));
// Read the offset
uint32 frame_offset = csf->_len_header + (csf->_len_frameheader * f);
- if (csf->_bytes_frame_offset) frame_offset = source->readX(csf->_bytes_frame_offset) + csf->_bytes_special;
+ if (csf->_bytes_frame_offset) frame_offset = readX(source, csf->_bytes_frame_offset) + csf->_bytes_special;
// Read the unknown
- if (csf->_bytes_frameheader_unk) source->read(frame->_header_unknown, csf->_bytes_frameheader_unk);
+ if (csf->_bytes_frameheader_unk) source.read(frame->_header_unknown, csf->_bytes_frameheader_unk);
// Read frame_length
uint32 frame_length = real_len-frame_offset;
- if (csf->_bytes_frame_length) frame_length = source->readX(csf->_bytes_frame_length) + csf->_bytes_frame_length_kludge;
+ if (csf->_bytes_frame_length) frame_length = readX(source, csf->_bytes_frame_length) + csf->_bytes_frame_length_kludge;
// Invalid frame length
if ((frame_length + frame_offset) > real_len) {
@@ -474,17 +474,17 @@ bool ConvertShape::Check(IDataSource *source, const ConvertShapeFormat *csf, uin
}
// Seek to start of frame
- source->seek(start_pos + frame_offset);
+ source.seek(start_pos + frame_offset);
// Read unknown
- if (csf->_bytes_frame_unknown) source->read(frame->_unknown, csf->_bytes_frame_unknown);
+ if (csf->_bytes_frame_unknown) source.read(frame->_unknown, csf->_bytes_frame_unknown);
// Frame details
- frame->_compression = source->readX(csf->_bytes_frame_compression);
- frame->_width = source->readXS(csf->_bytes_frame_width);
- frame->_height = source->readXS(csf->_bytes_frame_height);
- frame->_xoff = source->readXS(csf->_bytes_frame_xoff);
- frame->_yoff = source->readXS(csf->_bytes_frame_yoff);
+ frame->_compression = readX(source, csf->_bytes_frame_compression);
+ frame->_width = readXS(source, csf->_bytes_frame_width);
+ frame->_height = readXS(source, csf->_bytes_frame_height);
+ frame->_xoff = readXS(source, csf->_bytes_frame_xoff);
+ frame->_yoff = readXS(source, csf->_bytes_frame_yoff);
if ((frame->_compression != 0 && frame->_compression != 1) || frame->_width < 0 || frame->_height < 0) {
frame->_compression = 0;
@@ -513,11 +513,11 @@ bool ConvertShape::Check(IDataSource *source, const ConvertShapeFormat *csf, uin
if (!csf->_bytes_special) {
// Seek to first in offset table
- source->seek(start_pos + frame_offset + csf->_len_frameheader2);
+ source.seek(start_pos + frame_offset + csf->_len_frameheader2);
// Loop through each of the _frames and find the last rle run
for (int i = 0; i < frame->_height; i++) {
- int32 line_offset = source->readX(csf->_bytes_line_offset);
+ int32 line_offset = readX(source, csf->_bytes_line_offset);
// Now fudge with the value and turn it into an offset into the rle data
// if required
@@ -536,22 +536,22 @@ bool ConvertShape::Check(IDataSource *source, const ConvertShapeFormat *csf, uin
if (result == false) break;
// Jump to the line offset and calculate the length of the run
- source->seek(highest_offset_byte + start_pos + frame_offset + csf->_len_frameheader2 + frame->_height * csf->_bytes_line_offset);
+ source.seek(highest_offset_byte + start_pos + frame_offset + csf->_len_frameheader2 + frame->_height * csf->_bytes_line_offset);
int xpos = 0;
uint32 dlen = 0;
// Compressed
if (frame->_compression) {
do {
- xpos += source->readByte();
+ xpos += source.readByte();
if (xpos == frame->_width) break;
- dlen = source->readByte();
+ dlen = source.readByte();
int type = dlen & 1;
dlen >>= 1;
- if (!type) source->skip(dlen);
- else source->skip(1);
+ if (!type) source.skip(dlen);
+ else source.skip(1);
xpos += dlen;
@@ -559,18 +559,18 @@ bool ConvertShape::Check(IDataSource *source, const ConvertShapeFormat *csf, uin
// Uncompressed
} else {
do {
- xpos += source->readByte();
+ xpos += source.readByte();
if (xpos == frame->_width) break;
- dlen = source->readByte();
- source->skip(dlen);
+ dlen = source.readByte();
+ source.skip(dlen);
xpos += dlen;
} while (xpos < frame->_width);
}
// Calc 'real' bytes rle
- int32 highest_rle_byte = source->pos();
+ int32 highest_rle_byte = source.pos();
highest_rle_byte -= start_pos + frame_offset + csf->_len_frameheader2 + frame->_height * csf->_bytes_line_offset;
// Too many bytes
@@ -586,42 +586,42 @@ bool ConvertShape::Check(IDataSource *source, const ConvertShapeFormat *csf, uin
oneframe.Free();
// Return to start position
- source->seek(start_pos);
+ source.seek(start_pos);
return result;
}
-bool ConvertShape::CheckUnsafe(IDataSource *source, const ConvertShapeFormat *csf, uint32 real_len) {
+bool ConvertShape::CheckUnsafe(Common::SeekableReadStream &source, const ConvertShapeFormat *csf, uint32 real_len) {
#if 0
pout << "Testing " << csf->_name << "..." << Std::endl;
#endif
bool result = true;
// Just to be safe
- const uint32 start_pos = source->pos();
+ const uint32 start_pos = source.pos();
// Read the ident
if (csf->_bytes_ident) {
char ident[5];
ident[csf->_bytes_ident] = 0;
- source->read(ident, csf->_bytes_ident);
+ source.read(ident, csf->_bytes_ident);
if (memcmp (ident, csf->_ident, csf->_bytes_ident)) {
// Return to start position
- source->seek(start_pos);
+ source.seek(start_pos);
return false;
}
}
// Read the header special colour
- if (csf->_bytes_special) source->skip(csf->_bytes_special);
+ if (csf->_bytes_special) source.skip(csf->_bytes_special);
// Read the header unknown
- if (csf->_bytes_header_unk) source->skip(csf->_bytes_header_unk);
+ if (csf->_bytes_header_unk) source.skip(csf->_bytes_header_unk);
// Now read _num_frames
int numFrames = 1;
- if (csf->_bytes_num_frames) numFrames = source->readX(csf->_bytes_num_frames);
+ if (csf->_bytes_num_frames) numFrames = readX(source, csf->_bytes_num_frames);
if (numFrames == 0) numFrames = CalcNumFrames(source,csf,real_len,start_pos);
// Create _frames array
@@ -633,18 +633,18 @@ bool ConvertShape::CheckUnsafe(IDataSource *source, const ConvertShapeFormat *cs
ConvertShapeFrame *frame = &oneframe;
// Seek to initial pos
- source->seek(start_pos + csf->_len_header + (csf->_len_frameheader * f));
+ source.seek(start_pos + csf->_len_header + (csf->_len_frameheader * f));
// Read the offset
uint32 frame_offset = csf->_len_header + (csf->_len_frameheader * f);
- if (csf->_bytes_frame_offset) frame_offset = source->readX(csf->_bytes_frame_offset) + csf->_bytes_special;
+ if (csf->_bytes_frame_offset) frame_offset = readX(source, csf->_bytes_frame_offset) + csf->_bytes_special;
// Read the unknown
- if (csf->_bytes_frameheader_unk) source->read(frame->_header_unknown, csf->_bytes_frameheader_unk);
+ if (csf->_bytes_frameheader_unk) source.read(frame->_header_unknown, csf->_bytes_frameheader_unk);
// Read frame_length
uint32 frame_length = real_len-frame_offset;
- if (csf->_bytes_frame_length) frame_length = source->readX(csf->_bytes_frame_length) + csf->_bytes_frame_length_kludge;
+ if (csf->_bytes_frame_length) frame_length = readX(source, csf->_bytes_frame_length) + csf->_bytes_frame_length_kludge;
// Invalid frame length
if ((frame_length + frame_offset) > real_len) {
@@ -653,17 +653,17 @@ bool ConvertShape::CheckUnsafe(IDataSource *source, const ConvertShapeFormat *cs
}
// Seek to start of frame
- source->seek(start_pos + frame_offset);
+ source.seek(start_pos + frame_offset);
// Read unknown
- if (csf->_bytes_frame_unknown) source->read(frame->_unknown, csf->_bytes_frame_unknown);
+ if (csf->_bytes_frame_unknown) source.read(frame->_unknown, csf->_bytes_frame_unknown);
// Frame details
- frame->_compression = source->readX(csf->_bytes_frame_compression);
- frame->_width = source->readXS(csf->_bytes_frame_width);
- frame->_height = source->readXS(csf->_bytes_frame_height);
- frame->_xoff = source->readXS(csf->_bytes_frame_xoff);
- frame->_yoff = source->readXS(csf->_bytes_frame_yoff);
+ frame->_compression = readX(source, csf->_bytes_frame_compression);
+ frame->_width = readXS(source, csf->_bytes_frame_width);
+ frame->_height = readXS(source, csf->_bytes_frame_height);
+ frame->_xoff = readXS(source, csf->_bytes_frame_xoff);
+ frame->_yoff = readXS(source, csf->_bytes_frame_yoff);
if ((frame->_compression != 0 && frame->_compression != 1) || frame->_width < 0 || frame->_height < 0) {
frame->_compression = 0;
@@ -691,65 +691,65 @@ bool ConvertShape::CheckUnsafe(IDataSource *source, const ConvertShapeFormat *cs
oneframe.Free();
// Return to start position
- source->seek(start_pos);
+ source.seek(start_pos);
return result;
}
-void ConvertShape::Write(ODataSource *dest, const ConvertShapeFormat *csf, uint32 &write_len) {
+void ConvertShape::Write(Common::SeekableWriteStream &dest, const ConvertShapeFormat *csf, uint32 &write_len) {
// Just to be safe
- const uint32 start_pos = dest->pos();
+ const uint32 start_pos = dest.pos();
// Write the ident
- if (csf->_bytes_ident) dest->write(csf->_ident, csf->_bytes_ident);
+ if (csf->_bytes_ident) dest.write(csf->_ident, csf->_bytes_ident);
// Write the header unknown
- if (csf->_bytes_header_unk) dest->write(_header_unknown, csf->_bytes_header_unk);
+ if (csf->_bytes_header_unk) dest.write(_header_unknown, csf->_bytes_header_unk);
// Now write _num_frames
- if (csf->_bytes_num_frames) dest->writeX(_num_frames, csf->_bytes_num_frames);
+ if (csf->_bytes_num_frames) writeX(dest, _num_frames, csf->_bytes_num_frames);
else if (!csf->_bytes_num_frames && _num_frames > 1) {
perr << "Error: Unable to convert multiple frame shapes to " << csf->_name << Std::endl;
return;
}
// Write filler space for the frame details
- for (uint32 i = 0; i < _num_frames*csf->_len_frameheader; i++) dest->writeByte(0);
+ for (uint32 i = 0; i < _num_frames*csf->_len_frameheader; i++) dest.writeByte(0);
// Now write the _frames
for(uint32 f = 0; f < _num_frames; f++) {
ConvertShapeFrame *frame = _frames + f;
// Get the frame offset
- uint32 frame_offset = dest->pos() - start_pos;
+ uint32 frame_offset = dest.pos() - start_pos;
// Seek to the frame header pos
- dest->seek(start_pos + csf->_len_header + (csf->_len_frameheader * f));
+ dest.seek(start_pos + csf->_len_header + (csf->_len_frameheader * f));
// Write the offset
- if (csf->_bytes_frame_offset) dest->writeX(frame_offset, csf->_bytes_frame_offset);
+ if (csf->_bytes_frame_offset) writeX(dest, frame_offset, csf->_bytes_frame_offset);
// Write the unknown
- if (csf->_bytes_frameheader_unk) dest->write(frame->_header_unknown, csf->_bytes_frameheader_unk);
+ if (csf->_bytes_frameheader_unk) dest.write(frame->_header_unknown, csf->_bytes_frameheader_unk);
// Calc and write frame_length
if (csf->_bytes_frame_length) {
uint32 frame_length = csf->_len_frameheader2 + (frame->_height * csf->_bytes_line_offset) + frame->_bytes_rle;
- dest->writeX(frame_length - csf->_bytes_frame_length_kludge, csf->_bytes_frame_length);
+ writeX(dest, frame_length - csf->_bytes_frame_length_kludge, csf->_bytes_frame_length);
}
// Seek to start of frame
- dest->seek(start_pos + frame_offset);
+ dest.seek(start_pos + frame_offset);
// Write unknown
- if (csf->_bytes_frame_unknown) dest->write(frame->_unknown, csf->_bytes_frame_unknown);
+ if (csf->_bytes_frame_unknown) dest.write(frame->_unknown, csf->_bytes_frame_unknown);
// Frame details
- dest->writeX(frame->_compression, csf->_bytes_frame_compression);
- dest->writeX(frame->_width, csf->_bytes_frame_width);
- dest->writeX(frame->_height, csf->_bytes_frame_height);
- dest->writeX(frame->_xoff, csf->_bytes_frame_xoff);
- dest->writeX(frame->_yoff, csf->_bytes_frame_yoff);
+ writeX(dest, frame->_compression, csf->_bytes_frame_compression);
+ writeX(dest, frame->_width, csf->_bytes_frame_width);
+ writeX(dest, frame->_height, csf->_bytes_frame_height);
+ writeX(dest, frame->_xoff, csf->_bytes_frame_xoff);
+ writeX(dest, frame->_yoff, csf->_bytes_frame_yoff);
// Line offsets
for (int32 i = 0; i < frame->_height; i++) {
@@ -759,15 +759,15 @@ void ConvertShape::Write(ODataSource *dest, const ConvertShapeFormat *csf, uint3
if (!csf->_line_offset_absolute)
actual_offset += (frame->_height - i) * csf->_bytes_line_offset;
- dest->writeX(actual_offset, csf->_bytes_line_offset);
+ writeX(dest, actual_offset, csf->_bytes_line_offset);
}
// Write the RLE Data
- dest->write(frame->_rle_data, frame->_bytes_rle);
+ dest.write(frame->_rle_data, frame->_bytes_rle);
}
// Just cheat
- write_len = dest->pos() - start_pos;
+ write_len = dest.pos() - start_pos;
}
diff --git a/engines/ultima/ultima8/convert/convert_shape.h b/engines/ultima/ultima8/convert/convert_shape.h
index 2f17829c21..276742bff1 100644
--- a/engines/ultima/ultima8/convert/convert_shape.h
+++ b/engines/ultima/ultima8/convert/convert_shape.h
@@ -24,12 +24,11 @@
#define ULTIMA8_CONVERT_CONVERTSHAPE_H
#include "common/scummsys.h"
+#include "common/stream.h"
namespace Ultima {
namespace Ultima8 {
-class IDataSource;
-class ODataSource;
// Convert shape C
@@ -81,9 +80,9 @@ struct ConvertShapeFrame {
void Free();
- void Read(IDataSource *source, const ConvertShapeFormat *csf, uint32 frame_length);
+ void Read(Common::SeekableReadStream &source, const ConvertShapeFormat *csf, uint32 frame_length);
- void ReadCmpFrame(IDataSource *source, const ConvertShapeFormat *csf, const uint8 special[256], ConvertShapeFrame *prev);
+ void ReadCmpFrame(Common::SeekableReadStream &source, const ConvertShapeFormat *csf, const uint8 special[256], ConvertShapeFrame *prev);
void GetPixels(uint8 *buf, int32 count, int32 x, int32 y);
};
@@ -107,18 +106,18 @@ public:
void Free();
- void Read(IDataSource *source, const ConvertShapeFormat *csf, uint32 real_len);
- void Write(ODataSource *source, const ConvertShapeFormat *csf, uint32 &write_len);
+ void Read(Common::SeekableReadStream &source, const ConvertShapeFormat *csf, uint32 real_len);
+ void Write(Common::SeekableWriteStream &source, const ConvertShapeFormat *csf, uint32 &write_len);
// This will check to see if a Shape is of a certain type. Return true if ok, false if bad
- static bool Check(IDataSource *source, const ConvertShapeFormat *csf, uint32 real_len);
+ static bool Check(Common::SeekableReadStream &source, const ConvertShapeFormat *csf, uint32 real_len);
// This will also check to see if a shape is of a certain type. However it won't check
// the rle data, it only checks headers. Return true if ok, false if bad
- static bool CheckUnsafe(IDataSource *source, const ConvertShapeFormat *csf, uint32 real_len);
+ static bool CheckUnsafe(Common::SeekableReadStream &source, const ConvertShapeFormat *csf, uint32 real_len);
// Algorithmically calculate the number of frames
- static int CalcNumFrames(IDataSource *source, const ConvertShapeFormat *csf, uint32 real_len, uint32 start_pos);
+ static int CalcNumFrames(Common::SeekableReadStream &source, const ConvertShapeFormat *csf, uint32 real_len, uint32 start_pos);
};
// Shape format configuration for Pentagram format
diff --git a/engines/ultima/ultima8/filesys/file_system.h b/engines/ultima/ultima8/filesys/file_system.h
index 8cc2114b33..992838ab6e 100644
--- a/engines/ultima/ultima8/filesys/file_system.h
+++ b/engines/ultima/ultima8/filesys/file_system.h
@@ -24,8 +24,6 @@
#define ULTIMA8_FILESYS_FILESYSTEM_H
#include "ultima/shared/std/string.h"
-#include "ultima/ultima8/filesys/idata_source.h"
-#include "ultima/ultima8/filesys/odata_source.h"
#include "common/file.h"
namespace Ultima {
diff --git a/engines/ultima/ultima8/filesys/idata_source.h b/engines/ultima/ultima8/filesys/idata_source.h
deleted file mode 100644
index 7457498ea3..0000000000
--- a/engines/ultima/ultima8/filesys/idata_source.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 2
- * 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, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#ifndef ULTIMA8_FILESYS_IDATASOURCE_H
-#define ULTIMA8_FILESYS_IDATASOURCE_H
-
-#include "common/stream.h"
-#include "ultima/shared/std/string.h"
-
-namespace Ultima {
-namespace Ultima8 {
-
-class IDataSource : public Common::SeekableReadStream {
-public:
- IDataSource() {}
- virtual ~IDataSource() {}
-
- // Read a 3-byte value, lsb first.
- virtual uint32 readUint24LE() {
- uint32 val = 0;
- val |= static_cast<uint32>(readByte());
- val |= static_cast<uint32>(readByte() << 8);
- val |= static_cast<uint32>(readByte() << 16);
- return val;
- }
-
- uint32 readX(uint32 num_bytes) {
- assert(num_bytes > 0 && num_bytes <= 4);
- if (num_bytes == 1) return readByte();
- else if (num_bytes == 2) return readUint16LE();
- else if (num_bytes == 3) return readUint24LE();
- else return readUint32LE();
- }
-
- int32 readXS(uint32 num_bytes) {
- assert(num_bytes > 0 && num_bytes <= 4);
- if (num_bytes == 1) return static_cast<int8>(readByte());
- else if (num_bytes == 2) return static_cast<int16>(readUint16LE());
- else if (num_bytes == 3) return (((static_cast<int32>(readUint24LE())) << 8) >> 8);
- else return static_cast<int32>(readUint32LE());
- }
-};
-
-class IBufferDataSource : public IDataSource {
-protected:
- const uint8 *_buf;
- const uint8 *_bufPtr;
- bool _freeBuffer;
- uint32 _size;
-
-public:
- IBufferDataSource(const void *data, unsigned int len, bool is_text = false,
- bool delete_data = false) : _size(len), _freeBuffer(delete_data) {
- assert(!is_text);
- assert(data != nullptr || len == 0);
- _buf = _bufPtr = static_cast<const uint8 *>(data);
- }
-
- ~IBufferDataSource() override {
- if (_freeBuffer && _buf)
- delete[] const_cast<uint8 *>(_buf);
- _freeBuffer = false;
- _buf = _bufPtr = nullptr;
- }
-
- uint32 read(void *str, uint32 num_bytes) override {
- if (_bufPtr >= _buf + _size) return 0;
- uint32 count = num_bytes;
- if (_bufPtr + num_bytes > _buf + _size)
- count = static_cast<int32>(_buf - _bufPtr + _size);
- memcpy(str, _bufPtr, count);
- _bufPtr += count;
- return count;
- }
-
- bool seek(int32 position, int whence = SEEK_SET) override {
- assert(whence == SEEK_SET || whence == SEEK_CUR);
- if (whence == SEEK_CUR) {
- _bufPtr += position;
- } else if (whence == SEEK_SET) {
- _bufPtr = _buf + position;
- }
- return true;
- }
-
- int32 size() const override {
- return _size;
- }
-
- int32 pos() const override {
- return static_cast<int32>(_bufPtr - _buf);
- }
-
- bool eos() const override {
- return (static_cast<uint32>(_bufPtr - _buf)) >= _size;
- }
-};
-
-} // End of namespace Ultima8
-} // End of namespace Ultima
-
-#endif
diff --git a/engines/ultima/ultima8/filesys/odata_source.h b/engines/ultima/ultima8/filesys/odata_source.h
deleted file mode 100644
index 5b39545953..0000000000
--- a/engines/ultima/ultima8/filesys/odata_source.h
+++ /dev/null
@@ -1,55 +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 2
- * 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, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#ifndef ULTIMA8_FILESYS_ODATASOURCE_H
-#define ULTIMA8_FILESYS_ODATASOURCE_H
-
-#include "ultima/ultima8/misc/pent_include.h"
-#include "common/stream.h"
-
-namespace Ultima {
-namespace Ultima8 {
-
-class ODataSource : public Common::SeekableWriteStream {
-public:
- ODataSource() {}
- virtual ~ODataSource() {}
-
- virtual void writeUint24LE(uint32 val) {
- writeByte(static_cast<byte>(val & 0xff));
- writeByte(static_cast<byte>((val >> 8) & 0xff));
- writeByte(static_cast<byte>((val >> 16) & 0xff));
- }
-
- void writeX(uint32 val, uint32 num_bytes) {
- assert(num_bytes > 0 && num_bytes <= 4);
- if (num_bytes == 1) writeByte(static_cast<byte>(val));
- else if (num_bytes == 2) writeUint16LE(static_cast<uint16>(val));
- else if (num_bytes == 3) writeUint24LE(val);
- else writeUint32LE(val);
- }
-};
-
-} // End of namespace Ultima8
-} // End of namespace Ultima
-
-#endif
diff --git a/engines/ultima/ultima8/filesys/savegame.cpp b/engines/ultima/ultima8/filesys/savegame.cpp
index 17a9426334..4d2995d6ea 100644
--- a/engines/ultima/ultima8/filesys/savegame.cpp
+++ b/engines/ultima/ultima8/filesys/savegame.cpp
@@ -21,7 +21,6 @@
*/
#include "ultima/ultima8/filesys/savegame.h"
-#include "ultima/ultima8/filesys/idata_source.h"
namespace Ultima {
namespace Ultima8 {
diff --git a/engines/ultima/ultima8/games/game_info.cpp b/engines/ultima/ultima8/games/game_info.cpp
index eb88c53b46..8ea32a6c92 100644
--- a/engines/ultima/ultima8/games/game_info.cpp
+++ b/engines/ultima/ultima8/games/game_info.cpp
@@ -23,7 +23,6 @@
#include "ultima/ultima8/misc/pent_include.h"
#include "ultima/ultima8/games/game_info.h"
-#include "ultima/ultima8/filesys/idata_source.h"
#include "ultima/ultima8/misc/util.h"
namespace Ultima {
diff --git a/engines/ultima/ultima8/graphics/raw_shape_frame.cpp b/engines/ultima/ultima8/graphics/raw_shape_frame.cpp
index 65a6ad6514..36012abac3 100644
--- a/engines/ultima/ultima8/graphics/raw_shape_frame.cpp
+++ b/engines/ultima/ultima8/graphics/raw_shape_frame.cpp
@@ -24,7 +24,7 @@
#include "ultima/ultima8/graphics/raw_shape_frame.h"
#include "ultima/ultima8/convert/u8/convert_shape_u8.h"
-#include "ultima/ultima8/filesys/idata_source.h"
+#include "ultima/ultima8/misc/stream_util.h"
#include "common/memstream.h"
@@ -101,13 +101,13 @@ void RawShapeFrame::loadPentagramFormat(const uint8 *data, uint32 size) {
// This will load any sort of shape via a ConvertShapeFormat struct
void RawShapeFrame::loadGenericFormat(const uint8 *data, uint32 size, const ConvertShapeFormat *format) {
- IBufferDataSource ds(data + format->_bytes_frame_unknown, size);
+ Common::MemoryReadStream ds(data + format->_bytes_frame_unknown, size);
- _compressed = ds.readX(format->_bytes_frame_compression);
- _width = ds.readXS(format->_bytes_frame_width);
- _height = ds.readXS(format->_bytes_frame_height);
- _xoff = ds.readXS(format->_bytes_frame_xoff);
- _yoff = ds.readXS(format->_bytes_frame_yoff);
+ _compressed = readX(ds, format->_bytes_frame_compression);
+ _width = readXS(ds, format->_bytes_frame_width);
+ _height = readXS(ds, format->_bytes_frame_height);
+ _xoff = readXS(ds, format->_bytes_frame_xoff);
+ _yoff = readXS(ds, format->_bytes_frame_yoff);
if (_height == 0)
return;
@@ -123,13 +123,13 @@ void RawShapeFrame::loadGenericFormat(const uint8 *data, uint32 size, const Conv
for (int32 i = 0; i < _height; i++) {
if (format->_line_offset_absolute) {
- _line_offsets[i] = ds.readX(format->_bytes_line_offset);
+ _line_offsets[i] = readX(ds, format->_bytes_line_offset);
} else {
if (ds.size() - ds.pos() < (int32)format->_bytes_line_offset) {
warning("going off end of %d buffer at %d reading %d",
ds.size(), ds.pos(), format->_bytes_line_offset);
}
- _line_offsets[i] = ds.readX(format->_bytes_line_offset) - ((_height - i) * format->_bytes_line_offset);
+ _line_offsets[i] = readX(ds, format->_bytes_line_offset) - ((_height - i) * format->_bytes_line_offset);
}
}
@@ -138,11 +138,11 @@ void RawShapeFrame::loadGenericFormat(const uint8 *data, uint32 size, const Conv
// This will load an U8-compressed shape
void RawShapeFrame::loadU8CMPFormat(const uint8 *data, uint32 size, const ConvertShapeFormat *format, const uint8 special[256], ConvertShapeFrame *prev) {
- IBufferDataSource ds(data, size);
+ Common::MemoryReadStream ds(data, size);
ConvertShapeFrame f;
- f.ReadCmpFrame(&ds, format, special, prev);
+ f.ReadCmpFrame(ds, format, special, prev);
uint32 to_alloc = f._height + (f._bytes_rle + 3) / 4;
_line_offsets = new uint32[to_alloc];
diff --git a/engines/ultima/ultima8/graphics/shape.cpp b/engines/ultima/ultima8/graphics/shape.cpp
index 6c60a5965c..8d3591f729 100644
--- a/engines/ultima/ultima8/graphics/shape.cpp
+++ b/engines/ultima/ultima8/graphics/shape.cpp
@@ -27,7 +27,7 @@
#include "ultima/ultima8/graphics/raw_shape_frame.h"
#include "ultima/ultima8/convert/u8/convert_shape_u8.h"
#include "ultima/ultima8/convert/crusader/convert_shape_crusader.h"
-#include "ultima/ultima8/filesys/idata_source.h"
+#include "ultima/ultima8/misc/stream_util.h"
#include "common/memstream.h"
@@ -143,7 +143,7 @@ Common::Array<RawShapeFrame *> Shape::loadGenericFormat(const uint8 *data, uint3
uint32 framecount;
uint32 frameoffset;
uint32 framesize;
- IBufferDataSource ds(data, size);
+ Common::MemoryReadStream ds(data, size);
Common::Array<RawShapeFrame *> frames;
@@ -169,7 +169,7 @@ Common::Array<RawShapeFrame *> Shape::loadGenericFormat(const uint8 *data, uint3
// Skip unknown
if (format->_bytes_header_unk && format != &Crusader2DShapeFormat) {
//uint32 val =
- ds.readX(format->_bytes_header_unk);
+ readX(ds, format->_bytes_header_unk);
//uint16 lowval = val & 0xff;
//uint16 highval = (val >> 16) & 0xff;
//uint32 dummy = 0 + lowval + highval + val;
@@ -180,24 +180,24 @@ Common::Array<RawShapeFrame *> Shape::loadGenericFormat(const uint8 *data, uint3
}
// Read framecount, default 1 if no
- if (format->_bytes_num_frames) framecount = ds.readX(format->_bytes_num_frames);
+ if (format->_bytes_num_frames) framecount = readX(ds, format->_bytes_num_frames);
else framecount = 1;
- if (framecount == 0) framecount = ConvertShape::CalcNumFrames(&ds, format, size, 0);
+ if (framecount == 0) framecount = ConvertShape::CalcNumFrames(ds, format, size, 0);
frames.reserve(framecount);
for (uint i = 0; i < framecount; ++i) {
// Read the offset
- if (format->_bytes_frame_offset) frameoffset = ds.readX(format->_bytes_frame_offset) + format->_bytes_special;
+ if (format->_bytes_frame_offset) frameoffset = readX(ds, format->_bytes_frame_offset) + format->_bytes_special;
else frameoffset = format->_len_header + (format->_len_frameheader * i);
// Skip the unknown
if (format->_bytes_frameheader_unk) {
- ds.readX(format->_bytes_frameheader_unk);
+ readX(ds, format->_bytes_frameheader_unk);
}
// Read frame_length
- if (format->_bytes_frame_length) framesize = ds.readX(format->_bytes_frame_length) + format->_bytes_frame_length_kludge;
+ if (format->_bytes_frame_length) framesize = readX(ds, format->_bytes_frame_length) + format->_bytes_frame_length_kludge;
else framesize = size - frameoffset;
if (framesize > size) {
@@ -220,11 +220,11 @@ Common::Array<RawShapeFrame *> Shape::loadGenericFormat(const uint8 *data, uint3
// This will detect the format of a shape
const ConvertShapeFormat *Shape::DetectShapeFormat(const uint8 *data, uint32 size) {
- IBufferDataSource ds(data, size);
- return Shape::DetectShapeFormat(&ds, size);
+ Common::MemoryReadStream ds(data, size);
+ return Shape::DetectShapeFormat(ds, size);
}
-const ConvertShapeFormat *Shape::DetectShapeFormat(IDataSource *ds, uint32 size) {
+const ConvertShapeFormat *Shape::DetectShapeFormat(Common::SeekableReadStream &ds, uint32 size) {
const ConvertShapeFormat *ret = nullptr;
if (ConvertShape::CheckUnsafe(ds, &PentagramShapeFormat, size))
diff --git a/engines/ultima/ultima8/graphics/shape.h b/engines/ultima/ultima8/graphics/shape.h
index a1a6393ac9..41cc191405 100644
--- a/engines/ultima/ultima8/graphics/shape.h
+++ b/engines/ultima/ultima8/graphics/shape.h
@@ -33,7 +33,6 @@ class RawShapeFrame;
struct Palette;
struct Rect;
struct ConvertShapeFormat;
-class IDataSource;
class Shape {
public:
@@ -66,7 +65,7 @@ public:
// This will detect the format of a shape
static const ConvertShapeFormat *DetectShapeFormat(const uint8 *data, uint32 size);
- static const ConvertShapeFormat *DetectShapeFormat(IDataSource *ds, uint32 size);
+ static const ConvertShapeFormat *DetectShapeFormat(Common::SeekableReadStream &ds, uint32 size);
private:
void loadFrames(const uint8 *data, uint32 size, const ConvertShapeFormat *format);
diff --git a/engines/ultima/ultima8/graphics/skf_player.cpp b/engines/ultima/ultima8/graphics/skf_player.cpp
index 3fe95a08fd..8e86862e31 100644
--- a/engines/ultima/ultima8/graphics/skf_player.cpp
+++ b/engines/ultima/ultima8/graphics/skf_player.cpp
@@ -30,7 +30,6 @@
#include "ultima/ultima8/graphics/palette_manager.h"
#include "ultima/ultima8/audio/music_process.h"
#include "ultima/ultima8/audio/audio_process.h"
-#include "ultima/ultima8/filesys/idata_source.h"
#include "ultima/ultima8/audio/raw_audio_sample.h"
#include "ultima/ultima8/graphics/fonts/font.h"
#include "ultima/ultima8/graphics/fonts/font_manager.h"
diff --git a/engines/ultima/ultima8/graphics/wpn_ovlay_dat.cpp b/engines/ultima/ultima8/graphics/wpn_ovlay_dat.cpp
index fe933b0b7f..de322aaad4 100644
--- a/engines/ultima/ultima8/graphics/wpn_ovlay_dat.cpp
+++ b/engines/ultima/ultima8/graphics/wpn_ovlay_dat.cpp
@@ -24,7 +24,6 @@
#include "ultima/ultima8/graphics/wpn_ovlay_dat.h"
-#include "ultima/ultima8/filesys/idata_source.h"
#include "ultima/ultima8/world/actors/weapon_overlay.h"
#include "ultima/ultima8/filesys/raw_archive.h"
#include "ultima/ultima8/games/game_data.h"
diff --git a/engines/ultima/ultima8/kernel/object_manager.h b/engines/ultima/ultima8/kernel/object_manager.h
index e7d2d94a94..ad3b72e3b4 100644
--- a/engines/ultima/ultima8/kernel/object_manager.h
+++ b/engines/ultima/ultima8/kernel/object_manager.h
@@ -24,6 +24,7 @@
#define ULTIMA8_KERNEL_OBJECTMANAGER_H
#include "ultima/shared/std/containers.h"
+#include "ultima/ultima8/misc/common_types.h"
namespace Ultima {
namespace Ultima8 {
diff --git a/engines/ultima/ultima8/misc/stream_util.h b/engines/ultima/ultima8/misc/stream_util.h
new file mode 100644
index 0000000000..b033b76bb2
--- /dev/null
+++ b/engines/ultima/ultima8/misc/stream_util.h
@@ -0,0 +1,73 @@
+/* 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 2
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef ULTIMA8_MISC_STREAM_H
+#define ULTIMA8_MISC_STREAM_H
+
+#include "common/stream.h"
+
+namespace Ultima {
+namespace Ultima8 {
+
+// Read a 3-byte value, lsb first.
+inline uint32 readUint24LE(Common::ReadStream &rs) {
+ uint32 val = 0;
+ val |= static_cast<uint32>(rs.readByte());
+ val |= static_cast<uint32>(rs.readByte() << 8);
+ val |= static_cast<uint32>(rs.readByte() << 16);
+ return val;
+}
+
+inline uint32 readX(Common::ReadStream &rs, uint32 num_bytes) {
+ assert(num_bytes > 0 && num_bytes <= 4);
+ if (num_bytes == 1) return rs.readByte();
+ else if (num_bytes == 2) return rs.readUint16LE();
+ else if (num_bytes == 3) return readUint24LE(rs);
+ else return rs.readUint32LE();
+}
+
+inline int32 readXS(Common::ReadStream &rs, uint32 num_bytes) {
+ assert(num_bytes > 0 && num_bytes <= 4);
+ if (num_bytes == 1) return static_cast<int8>(rs.readByte());
+ else if (num_bytes == 2) return static_cast<int16>(rs.readUint16LE());
+ else if (num_bytes == 3) return (((static_cast<int32>(readUint24LE(rs))) << 8) >> 8);
+ else return static_cast<int32>(rs.readUint32LE());
+}
+
+inline void writeUint24LE(Common::WriteStream &ws, uint32 val) {
+ ws.writeByte(static_cast<byte>(val & 0xff));
+ ws.writeByte(static_cast<byte>((val >> 8) & 0xff));
+ ws.writeByte(static_cast<byte>((val >> 16) & 0xff));
+}
+
+inline void writeX(Common::WriteStream &ws, uint32 val, uint32 num_bytes) {
+ assert(num_bytes > 0 && num_bytes <= 4);
+ if (num_bytes == 1) ws.writeByte(static_cast<byte>(val));
+ else if (num_bytes == 2) ws.writeUint16LE(static_cast<uint16>(val));
+ else if (num_bytes == 3) writeUint24LE(ws, val);
+ else ws.writeUint32LE(val);
+}
+
+} // End of namespace Ultima8
+} // End of namespace Ultima
+
+#endif
diff --git a/engines/ultima/ultima8/world/world.cpp b/engines/ultima/ultima8/world/world.cpp
index 3c83c76d74..66ac15aa8a 100644
--- a/engines/ultima/ultima8/world/world.cpp
+++ b/engines/ultima/ultima8/world/world.cpp
@@ -38,7 +38,6 @@
#include "ultima/ultima8/gumps/gump.h" // For CloseItemDependents notification
#include "ultima/ultima8/world/get_object.h"
#include "ultima/ultima8/audio/audio_process.h"
-#include "ultima/ultima8/filesys/idata_source.h"
namespace Ultima {
namespace Ultima8 {
diff --git a/test/engines/ultima/ultima8/filesys/idata_source.h b/test/engines/ultima/ultima8/filesys/idata_source.h
deleted file mode 100644
index f3b2848161..0000000000
--- a/test/engines/ultima/ultima8/filesys/idata_source.h
+++ /dev/null
@@ -1,64 +0,0 @@
-#include <cxxtest/TestSuite.h>
-#include "engines/ultima/ultima8/filesys/idata_source.h"
-/**
- * Test suite for the functions in engines/ultima/ultima8/filesys/idata_source.h
- */
-
-class U8IDataSourceTestSuite : public CxxTest::TestSuite {
- public:
- U8IDataSourceTestSuite() {
- }
-
- void test_empty_ibuffer_source() {
- Ultima::Ultima8::IBufferDataSource source(NULL, 0, false, false);
-
- TS_ASSERT_EQUALS(source.size(), 0);
- TS_ASSERT_EQUALS(source.pos(), 0);
- TS_ASSERT(source.eos());
- }
-
- void test_ibuffer_source() {
- uint8 buf[256];
- for (int i = 0; i < 255; i++) {
- buf[i] = 0x80 + i+1;
- }
-
- Ultima::Ultima8::IBufferDataSource source(buf, 256, false, false);
- TS_ASSERT_EQUALS(source.size(), 256);
- TS_ASSERT_EQUALS(source.pos(), 0);
- TS_ASSERT(!source.eos());
-
- TS_ASSERT_EQUALS(source.readByte(), 0x81);
- TS_ASSERT_EQUALS(source.readUint16LE(), 0x8382);
- TS_ASSERT_EQUALS(source.readUint24LE(), 0x868584);
- TS_ASSERT_EQUALS(source.readUint32LE(), 0x8A898887);
- source.skip(-2);
- TS_ASSERT_EQUALS(source.readUint16LE(), 0x8A89);
- source.seek(16);
- TS_ASSERT_EQUALS(source.readUint16LE(), 0x9291);
- TS_ASSERT_EQUALS(source.readX(1), 0x93);
- TS_ASSERT_EQUALS(source.readX(3), 0x969594);
- TS_ASSERT_EQUALS(source.readXS(1), (int8)0x97);
- TS_ASSERT_EQUALS(source.readXS(3), (int32)0xFF9A9998);
- source.seek(256);
- TS_ASSERT(source.eos());
- }
-
- void test_ibuffer_str_source() {
- /*
- const char *buf = "this is a \r\n dos string and a \n unix string.";
- Ultima::Std::string str;
- Ultima::Ultima8::IBufferDataSource source(buf, strlen(buf), true, false);
- TS_ASSERT(!source.eos());
- source.readline(str);
- TS_ASSERT(!source.eos());
- TS_ASSERT_EQUALS(str, "this is a ");
- source.readline(str);
- TS_ASSERT_EQUALS(str, " dos string and a ");
- source.readline(str);
- TS_ASSERT_EQUALS(str, " unix string.");
- TS_ASSERT(source.eos());
- */
- }
-
-};
More information about the Scummvm-git-logs
mailing list