[Scummvm-git-logs] scummvm master -> 9dbbe16d01dacf8d5c12eb504d45b1c37b339045
bluegr
noreply at scummvm.org
Wed Oct 30 16:19:09 UTC 2024
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:
9dbbe16d01 M4: Simplify file resource reading code
Commit: 9dbbe16d01dacf8d5c12eb504d45b1c37b339045
https://github.com/scummvm/scummvm/commit/9dbbe16d01dacf8d5c12eb504d45b1c37b339045
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2024-10-30T18:18:57+02:00
Commit Message:
M4: Simplify file resource reading code
This adds wrapper functions, and helps to avoid needless conversions.
There are no functional changes
Changed paths:
engines/m4/adv_r/adv_chk.cpp
engines/m4/adv_r/adv_file.cpp
engines/m4/adv_r/chunk_ops.cpp
engines/m4/adv_r/conv_io.cpp
engines/m4/fileio/fstream.cpp
engines/m4/fileio/sys_file.cpp
engines/m4/fileio/sys_file.h
engines/m4/graphics/gr_font.cpp
engines/m4/graphics/gr_font.h
engines/m4/platform/tile/tile_read.cpp
diff --git a/engines/m4/adv_r/adv_chk.cpp b/engines/m4/adv_r/adv_chk.cpp
index f9c1548cac7..fd4045f775f 100644
--- a/engines/m4/adv_r/adv_chk.cpp
+++ b/engines/m4/adv_r/adv_chk.cpp
@@ -28,38 +28,16 @@
namespace M4 {
static HotSpotRec *read_hotspots(SysFile *fpdef, HotSpotRec *h, int32 num) {
- int32 str_len = 0;
- int32 a;
- int8 b;
- int16 c;
- bool d;
- char e;
+ int32 str_len;
char s[MAX_FILENAME_SIZE];
int32 x1, x2, y1, y2;
HotSpotRec *head = nullptr;
- void *buffPtr;
- int32 i = 0;
-
- for (i = 0; i < num; i++) {
- buffPtr = &x1;
- if (!fpdef->read(&buffPtr, sizeof(int32)))
- error_show(FL, 0, "Could not read ul_x");
- x1 = convert_intel32(x1);
-
- buffPtr = &y1;
- if (!fpdef->read(&buffPtr, sizeof(int32)))
- error_show(FL, 0, "Could not read ul_y");
- y1 = convert_intel32(y1);
-
- buffPtr = &x2;
- if (!fpdef->read(&buffPtr, sizeof(int32)))
- error_show(FL, 0, "Could not read lr_x");
- x2 = convert_intel32(x2);
-
- buffPtr = &y2;
- if (!fpdef->read(&buffPtr, sizeof(int32)))
- error_show(FL, 0, "Could not read lr_y");
- y2 = convert_intel32(y2);
+
+ for (int32 i = 0; i < num; i++) {
+ x1 = fpdef->readSint32LE();
+ y1 = fpdef->readSint32LE();
+ x2 = fpdef->readSint32LE();
+ y2 = fpdef->readSint32LE();
h = hotspot_new(x1, y1, x2, y2);
if (!head)
@@ -67,169 +45,82 @@ static HotSpotRec *read_hotspots(SysFile *fpdef, HotSpotRec *h, int32 num) {
else
head = hotspot_add(head, h, false);
- buffPtr = &a;
- if (!fpdef->read(&buffPtr, sizeof(int32)))
- error_show(FL, 0, "Could not read feet_x");
- a = convert_intel32(a);
- h->feet_x = a;
-
- if (!fpdef->read(&buffPtr, sizeof(int32)))
- error_show(FL, 0, "Could not read feet_y");
- a = convert_intel32(a);
- h->feet_y = a;
-
- buffPtr = &b;
- if (!fpdef->read(&buffPtr, sizeof(int8)))
- error_show(FL, 0, "Could not read facing");
- h->facing = b;
-
- buffPtr = &d;
- if (!fpdef->read(&buffPtr, sizeof(bool)))
- error_show(FL, 0, "Could not read active");
- h->active = d;
-
- buffPtr = &e;
- if (!fpdef->read(&buffPtr, sizeof(char)))
- error_show(FL, 0, "Could not read cursor_number");
- h->cursor_number = e;
-
- if (!fpdef->read(&buffPtr, sizeof(char)))
- error_show(FL, 0, "Could not read syntax");
- h->syntax = e;
-
- buffPtr = &a;
- if (!fpdef->read(&buffPtr, sizeof(int32)))
- error_show(FL, 0, "Could not read vocabID");
- a = convert_intel32(a);
- h->vocabID = a;
-
- if (!fpdef->read(&buffPtr, sizeof(int32)))
- error_show(FL, 0, "Could not read verbID");
- a = convert_intel32(a);
- h->verbID = a;
+ h->feet_x = fpdef->readSint32LE();
+ h->feet_y = fpdef->readSint32LE();
+ h->facing = fpdef->readSByte();
+ h->active = fpdef->readSByte();
+ h->cursor_number = fpdef->readSByte();
+ h->syntax = fpdef->readSByte();
+ h->vocabID = fpdef->readSint32LE();
+ h->verbID = fpdef->readSint32LE();
// -------
- buffPtr = &str_len;
- if (!fpdef->read(&buffPtr, sizeof(int32)))
- error_show(FL, 0, "Could not read vocab length");
- str_len = convert_intel32(str_len);
+ str_len = fpdef->readSint32LE();
if (str_len) {
- buffPtr = &s[0];
- if (!fpdef->read(&buffPtr, str_len))
+ if (!fpdef->read((byte *)s, str_len))
error_show(FL, 0, "Could not read vocab");
hotspot_newVocab(h, s);
}
- buffPtr = &str_len;
- if (!fpdef->read(&buffPtr, sizeof(int32)))
- error_show(FL, 0, "Could not read verb length");
- str_len = convert_intel32(str_len);
+ str_len = fpdef->readSint32LE();
if (str_len) {
- buffPtr = &s[0];
- if (!fpdef->read(&buffPtr, str_len))
+ if (!fpdef->read((byte *)s, str_len))
error_show(FL, 0, "Could not read verb");
hotspot_newVerb(h, s);
}
- buffPtr = &str_len;
- if (!fpdef->read(&buffPtr, sizeof(int32)))
- error_show(FL, 0, "Could not read prep length");
- str_len = convert_intel32(str_len);
+ str_len = fpdef->readSint32LE();
if (str_len) {
- buffPtr = &s[0];
- if (!fpdef->read(&buffPtr, str_len))
+ if (!fpdef->read((byte *)s, str_len))
error_show(FL, 0, "Could not read prep");
hotspot_newPrep(h, s);
}
- buffPtr = &str_len;
- if (!fpdef->read(&buffPtr, sizeof(int32)))
- error_show(FL, 0, "Could not read sprite");
- str_len = convert_intel32(str_len);
+ str_len = fpdef->readSint32LE();
if (str_len) {
- buffPtr = &s[0];
- if (!fpdef->read(&buffPtr, str_len))
+ if (!fpdef->read((byte *)s, str_len))
error_show(FL, 0, "Could not read sprite");
hotspot_new_sprite(h, s);
}
- buffPtr = &c;
- if (!fpdef->read(&buffPtr, sizeof(int16)))
- error_show(FL, 0, "Could not read sprite");
- c = convert_intel16(c);
- h->hash = c;
+ h->hash = fpdef->readSint16LE();
}
return head;
}
static void load_def(SysFile *fpdef) {
- int32 i, a;
- int16 b;
- int32 c, x, y;
+ int32 x, y;
char s[MAX_FILENAME_SIZE];
- void *buffPtr;
- buffPtr = &s[0];
- fpdef->read(&buffPtr, MAX_FILENAME_SIZE);
+ fpdef->read((byte *)s, MAX_FILENAME_SIZE);
Common::strlcpy(_G(myDef)->art_base, s, MAX_FILENAME_SIZE);
- fpdef->read(&buffPtr, MAX_FILENAME_SIZE);
+ fpdef->read((byte *)s, MAX_FILENAME_SIZE);
Common::strlcpy(_G(myDef)->picture_base, s, MAX_FILENAME_SIZE);
- buffPtr = &a;
- fpdef->read(&buffPtr, sizeof(int32));
- a = convert_intel32(a);
- _G(myDef)->num_hotspots = a;
-
- buffPtr = &a;
- fpdef->read(&buffPtr, sizeof(int32));
- a = convert_intel32(a);
- _G(myDef)->num_parallax = a;
-
- fpdef->read(&buffPtr, sizeof(int32));
- a = convert_intel32(a);
- _G(myDef)->num_props = a;
-
- fpdef->read(&buffPtr, sizeof(int32));
- a = convert_intel32(a);
- _G(myDef)->front_y = a;
-
- fpdef->read(&buffPtr, sizeof(int32));
- a = convert_intel32(a);
- _G(myDef)->back_y = a;
-
- fpdef->read(&buffPtr, sizeof(int32));
- a = convert_intel32(a);
- _G(myDef)->front_scale = a;
-
- fpdef->read(&buffPtr, sizeof(int32));
- a = convert_intel32(a);
- _G(myDef)->back_scale = a;
-
- buffPtr = &b;
- for (i = 0; i < 16; i++) {
- fpdef->read(&buffPtr, sizeof(int16));
- b = convert_intel16(b);
- _G(myDef)->depth_table[i] = b;
+ _G(myDef)->num_hotspots = fpdef->readSint32LE();
+ _G(myDef)->num_parallax = fpdef->readSint32LE();
+ _G(myDef)->num_props = fpdef->readSint32LE();
+ _G(myDef)->front_y = fpdef->readSint32LE();
+ _G(myDef)->back_y = fpdef->readSint32LE();
+ _G(myDef)->front_scale = fpdef->readSint32LE();
+ _G(myDef)->back_scale = fpdef->readSint32LE();
+
+ for (int32 i = 0; i < 16; i++) {
+ _G(myDef)->depth_table[i] = fpdef->readSint16LE();
}
- buffPtr = &c;
- fpdef->read(&buffPtr, sizeof(int32));
- c = convert_intel32(c);
- _G(myDef)->numRailNodes = c;
- for (i = 0; i < _G(myDef)->numRailNodes; i++) {
- fpdef->read(&buffPtr, sizeof(int32));
- c = convert_intel32(c);
- x = c;
- fpdef->read(&buffPtr, sizeof(int32));
- c = convert_intel32(c);
- y = c;
+ _G(myDef)->numRailNodes = fpdef->readSint32LE();
+
+ for (int32 i = 0; i < _G(myDef)->numRailNodes; i++) {
+ x = fpdef->readSint32LE();
+ y = fpdef->readSint32LE();
if (AddRailNode(x, y, nullptr, true) < 0)
error_show(FL, 0, "more than %d (defn. in intrrail.h) nodes", MAXRAILNODES);
diff --git a/engines/m4/adv_r/adv_file.cpp b/engines/m4/adv_r/adv_file.cpp
index d2445b1e370..5132c54550d 100644
--- a/engines/m4/adv_r/adv_file.cpp
+++ b/engines/m4/adv_r/adv_file.cpp
@@ -243,16 +243,8 @@ GrBuff *load_codes(SysFile *code_file) {
if (!code_file)
return nullptr;
- int16 x_size, y_size;
- char *bufferHandle;
-
- bufferHandle = (char *)&x_size;
- code_file->read((MemHandle)&bufferHandle, sizeof(int16));
- bufferHandle = (char *)&y_size;
- code_file->read((MemHandle)&bufferHandle, sizeof(int16));
-
- x_size = convert_intel16(x_size);
- y_size = convert_intel16(y_size);
+ int16 x_size = code_file->readSint16LE();
+ int16 y_size = code_file->readSint16LE();
GrBuff *temp = new GrBuff(x_size, y_size);
if (!temp) {
@@ -261,11 +253,10 @@ GrBuff *load_codes(SysFile *code_file) {
}
Buffer *mybuff = temp->get_buffer();
+ byte *bufferHandle = mybuff->data;
- uint8 *buffer = mybuff->data;
- bufferHandle = (char *)buffer;
for (int i = 0; i < y_size; i++) {
- code_file->read((MemHandle)&bufferHandle, x_size);
+ code_file->read(bufferHandle, x_size);
bufferHandle += mybuff->stride;
}
diff --git a/engines/m4/adv_r/chunk_ops.cpp b/engines/m4/adv_r/chunk_ops.cpp
index 2067a3542b9..ae17e14cfa2 100644
--- a/engines/m4/adv_r/chunk_ops.cpp
+++ b/engines/m4/adv_r/chunk_ops.cpp
@@ -420,13 +420,8 @@ static void swap_c_reply(c_reply_chunk *c) {
}
c_reply_chunk *get_c_reply(Conv *c, int32 cSize) {
- char *s = nullptr;
- c_reply_chunk *c_r = nullptr;
-
- s = &(c->conv[c->myCNode]);
- c_r = (c_reply_chunk *)&s[cSize];
-
- return c_r;
+ char *s = &(c->conv[c->myCNode]);
+ return (c_reply_chunk *)&s[cSize];
}
static void swap_w_reply(w_reply_chunk *c) {
diff --git a/engines/m4/adv_r/conv_io.cpp b/engines/m4/adv_r/conv_io.cpp
index 3b3ca3f4f13..a63d0b32886 100644
--- a/engines/m4/adv_r/conv_io.cpp
+++ b/engines/m4/adv_r/conv_io.cpp
@@ -735,7 +735,6 @@ Conv *conv_load(const char *filename, int x1, int y1, int32 myTrigger, bool want
Conv *convers = nullptr;
int32 cSize = 0;
char fullpathname[MAX_FILENAME_SIZE];
- void *bufferHandle;
term_message("conv_load");
@@ -770,7 +769,9 @@ Conv *conv_load(const char *filename, int x1, int y1, int32 myTrigger, bool want
error_show(FL, 'CNVL', "couldn't conv_load %s", fullpathname);
conv_set_handle(nullptr);
convers = nullptr;
- goto done;
+ fp.close();
+
+ return nullptr;
}
cSize = fp.size();
@@ -784,7 +785,9 @@ Conv *conv_load(const char *filename, int x1, int y1, int32 myTrigger, bool want
if (!convers) {
conv_set_handle(nullptr);
convers = nullptr;
- goto done;
+ fp.close();
+
+ return nullptr;
}
convers->chunkSize = cSize;
@@ -798,14 +801,13 @@ Conv *conv_load(const char *filename, int x1, int y1, int32 myTrigger, bool want
convers->conv = (char *)mem_alloc(cSize * sizeof(char), "conv char data");
- bufferHandle = convers->conv;
- if (!fp.read((MemHandle)&bufferHandle, cSize)) {
+ if (!fp.read((byte *)convers->conv, cSize)) {
conv_set_handle(nullptr);
- if (convers)
- delete convers;
-
+ delete convers;
convers = nullptr;
- goto done;
+ fp.close();
+
+ return nullptr;
}
conv_swap_words(convers);
@@ -823,7 +825,6 @@ Conv *conv_load(const char *filename, int x1, int y1, int32 myTrigger, bool want
conv_set_handle(convers);
-done:
fp.close();
return convers;
diff --git a/engines/m4/fileio/fstream.cpp b/engines/m4/fileio/fstream.cpp
index 8bec05858f9..bb1223344ea 100644
--- a/engines/m4/fileio/fstream.cpp
+++ b/engines/m4/fileio/fstream.cpp
@@ -73,7 +73,6 @@ strmRequest *f_stream_Open(SysFile *srcFile, int32 fileOffset, int32 strmMinBuff
strmRequest *newStream;
int32 bytesRead, i, bytesToRead;
bool finished;
- void *bufferHandle;
int32 memAvail;
// Parameter verification
@@ -199,9 +198,7 @@ got_mem:
if (bytesToRead > 0) {
// Read in the initial bytes to read
- //bytesRead = fread((void*)newStream->strmHead, 1, bytesToRead, newStream->srcFile);
- bufferHandle = newStream->strmHead;
- bytesRead = newStream->srcFile->read((MemHandle)&bufferHandle, bytesToRead);
+ bytesRead = newStream->srcFile->read(newStream->strmHead, bytesToRead);
//did we actually read that many? If not, close the file
if (bytesRead < bytesToRead) {
@@ -283,7 +280,6 @@ void f_stream_DumpPreviouslyRead(strmRequest *myStream) {
int32 f_stream_Read(strmRequest *myStream, uint8 **dest, int32 numBytes) {
int32 bytesAvail, bytesNeeded, bytesRead;
- void *bufferHandle;
// Parameter verification
if (!myStream)
@@ -354,8 +350,7 @@ int32 f_stream_Read(strmRequest *myStream, uint8 **dest, int32 numBytes) {
}
// Read in the bytesNeeded
- bufferHandle = myStream->strmHead;
- bytesRead = myStream->srcFile->read((MemHandle)&bufferHandle, bytesNeeded);
+ bytesRead = myStream->srcFile->read(myStream->strmHead, bytesNeeded);
if (bytesRead < bytesNeeded) {
// If we could not read that much in, close the srcFile
@@ -412,7 +407,6 @@ void f_stream_Process(int32 numToProcess) {
int32 buffEndBytesAvail = 0, buffStartBytesAvail = 0;
int32 bytesRead, bytesAvail, nextReadSize;
bool buffWrap, useBlockSizeArray;
- void *bufferHandle;
// No sense wasting time if there are no stream requests to process
if (!_G(firstStream)) {
@@ -468,8 +462,7 @@ void f_stream_Process(int32 numToProcess) {
if ((buffWrap && (buffEndBytesAvail >= nextReadSize)) ||
((!buffWrap) && (bytesAvail >= nextReadSize))) {
// Read the bytes into the stream buffer
- bufferHandle = myStream->strmHead;
- bytesRead = myStream->srcFile->read((MemHandle)&bufferHandle, nextReadSize);
+ bytesRead = myStream->srcFile->read(myStream->strmHead, nextReadSize);
// If we could not read that much in, close the srcFile
if (bytesRead < nextReadSize) {
@@ -498,9 +491,7 @@ void f_stream_Process(int32 numToProcess) {
myStream->strmWrap = myStream->strmHead;
// Read the bytes into the stream buffer
- //bytesRead = (int32)fread((void*)myStream->strmBuff, 1, nextReadSize, myStream->srcFile);
- bufferHandle = myStream->strmBuff;
- bytesRead = myStream->srcFile->read((MemHandle)&bufferHandle, nextReadSize);
+ bytesRead = myStream->srcFile->read(myStream->strmBuff, nextReadSize);
// If we could not read that much in, close the srcFile
if (bytesRead < nextReadSize) {
@@ -524,8 +515,7 @@ void f_stream_Process(int32 numToProcess) {
if (buffEndBytesAvail > 0) {
// Read into the end of the buffer
- bufferHandle = myStream->strmHead;
- bytesRead = (int32)myStream->srcFile->read((MemHandle)&bufferHandle, buffEndBytesAvail);
+ bytesRead = (int32)myStream->srcFile->read(myStream->strmHead, buffEndBytesAvail);
// If we could not read that much in, close the srcFile and update the head pointer
if (bytesRead < buffEndBytesAvail) {
@@ -539,8 +529,7 @@ void f_stream_Process(int32 numToProcess) {
if (myStream->srcFile) {
// Read into the beginning of the buffer
- bufferHandle = myStream->strmBuff;
- bytesRead = myStream->srcFile->read((MemHandle)&bufferHandle, nextReadSize - buffEndBytesAvail);
+ bytesRead = myStream->srcFile->read(myStream->strmBuff, nextReadSize - buffEndBytesAvail);
// If we could not read that much in, close the srcFile
if (bytesRead < (nextReadSize - buffEndBytesAvail)) {
diff --git a/engines/m4/fileio/sys_file.cpp b/engines/m4/fileio/sys_file.cpp
index 3cf0d7fbb9b..0f6acad239b 100644
--- a/engines/m4/fileio/sys_file.cpp
+++ b/engines/m4/fileio/sys_file.cpp
@@ -586,17 +586,20 @@ bool SysFile::seek_ahead(int32 amount) {
uint32 SysFile::read(MemHandle bufferHandle) {
- int32 bytesToRead;
-
- bytesToRead = size() - get_pos();
+ int32 bytesToRead = size() - get_pos();
if (bytesToRead < 0)
error("SysFile::read - %s", filename.c_str());
return read(bufferHandle, (int32)bytesToRead);
}
+int32 SysFile::read(byte *bufferHandle, int32 n) {
+ void *h = bufferHandle;
+ return read((MemHandle)&h, n);
+}
+
int32 SysFile::read(MemHandle bufferHandle, int32 n) {
- uint32 temp_size;
+ uint32 temp_size;
if (!bufferHandle)
error("reading %s", filename.c_str());
@@ -639,6 +642,14 @@ byte SysFile::readByte() {
return buf[0];
}
+uint16 SysFile::readUint16LE() {
+ byte buf[2];
+ void *ptr = (void *)buf;
+ read(&ptr, 2);
+
+ return READ_LE_UINT16(buf);
+}
+
uint32 SysFile::readUint32LE() {
byte buf[4];
void *ptr = (void *)buf;
diff --git a/engines/m4/fileio/sys_file.h b/engines/m4/fileio/sys_file.h
index 9366c8ba2bc..d47489713ff 100644
--- a/engines/m4/fileio/sys_file.h
+++ b/engines/m4/fileio/sys_file.h
@@ -122,6 +122,7 @@ public:
*/
uint32 read(MemHandle bufferHandle);
int32 read(MemHandle bufferHandle, int32 n);
+ int32 read(byte *bufferHandle, int32 n);
/**
* Read in a 8-bit value
@@ -131,6 +132,14 @@ public:
return (int8)readByte();
}
+ /**
+ * Read in a 16-bit value
+ */
+ uint16 readUint16LE();
+ int16 readSint16LE() {
+ return (int16)readUint16LE();
+ }
+
/**
* Read in a 32-bit value
*/
diff --git a/engines/m4/graphics/gr_font.cpp b/engines/m4/graphics/gr_font.cpp
index 614fbae4e69..cfb53b535f4 100644
--- a/engines/m4/graphics/gr_font.cpp
+++ b/engines/m4/graphics/gr_font.cpp
@@ -270,7 +270,8 @@ int32 gr_font_write(Buffer *target, char *out_string, int32 x, int32 y, int32 w,
else
target_w = target->w;
- x += 1; y += 1;
+ x += 1;
+ y += 1;
int32 skipTop = 0;
if (y < 0) {
skipTop = -y;
@@ -310,7 +311,7 @@ int32 gr_font_write(Buffer *target, char *out_string, int32 x, int32 y, int32 w,
int32 offset = offsetArray[c];
Byte *charData = &fontPixData[offset];
- int32 bytesInChar = (_G(font)->width[c] >> 2) + 1; //bytesPer[wdth]; // 2 bits per pixel
+ int32 bytesInChar = (_G(font)->width[c] >> 2) + 1; // bytesPer[wdth]; // 2 bits per pixel
if (skipTop)
charData += bytesInChar * skipTop;
@@ -344,7 +345,7 @@ int32 gr_font_write(Buffer *target, char *out_string, int32 x, int32 y, int32 w,
cursX += w;
} // end while there is a character to draw loop
- return(cursX);
+ return cursX;
}
int32 gr_font_write(Buffer *target, const char *out_string, int32 x, int32 y, int32 w, int32 auto_spacing) {
@@ -358,7 +359,6 @@ int32 gr_font_write(Buffer *target, const char *out_string, int32 x, int32 y, in
Font *gr_font_load(const char *fontName) {
uint32 tag;
Font *newFont;
- void *bufferHandle;
SysFile fontFile(fontName, BINARY);
if (!fontFile.exists())
@@ -386,8 +386,7 @@ Font *gr_font_load(const char *fontName) {
if (!newFont->width)
error_show(FL, 'OOM!', "_G(font) width table");
- bufferHandle = newFont->width;
- fontFile.read(&bufferHandle, 256);
+ fontFile.read(newFont->width, 256);
// read 'OFFS' into tag
tag = fontFile.readUint32LE();
@@ -399,11 +398,8 @@ Font *gr_font_load(const char *fontName) {
if (!newFont->offset)
error_show(FL, 'OOM!', "font offset table");
- bufferHandle = newFont->offset;
- fontFile.read(&bufferHandle, 256 * sizeof(int16));
-
for (int i = 0; i < 256; i++)
- newFont->offset[i] = convert_intel16(newFont->offset[i]);
+ newFont->offset[i] = fontFile.readSint16LE();
// read 'PIXS' into tag
tag = fontFile.readUint32LE();
@@ -415,8 +411,7 @@ Font *gr_font_load(const char *fontName) {
if (!newFont->pixData)
error_show(FL, 'OOM!', "font pix data");
- bufferHandle = newFont->pixData;
- fontFile.read(&bufferHandle, newFont->dataSize);
+ fontFile.read(newFont->pixData, newFont->dataSize);
// we don't need to close the file, because the destructor will close fontFile automagically
return newFont;
diff --git a/engines/m4/graphics/gr_font.h b/engines/m4/graphics/gr_font.h
index 40ced13e07c..6259c631904 100644
--- a/engines/m4/graphics/gr_font.h
+++ b/engines/m4/graphics/gr_font.h
@@ -51,7 +51,6 @@ int32 gr_font_write(Buffer *target, const char *out_string, int32 x, int32 y,
int32 gr_font_string_width(char *out_string, int32 auto_spacing = 1);
int32 gr_font_string_width(const Common::String &str, int32 auto_spacing = 1);
-//Font *gr_font_file_read(const char *fontName);
Font *gr_font_load(const char *fontName);
void font_set_colors(uint8 alt1, uint8 alt2, uint8 foreground);
diff --git a/engines/m4/platform/tile/tile_read.cpp b/engines/m4/platform/tile/tile_read.cpp
index 9f26bcdadd9..dac3ab1dea9 100644
--- a/engines/m4/platform/tile/tile_read.cpp
+++ b/engines/m4/platform/tile/tile_read.cpp
@@ -29,10 +29,6 @@ namespace M4 {
void tt_read_header(SysFile *ifp, int32 *file_x, int32 *file_y,
int32 *num_x_tiles, int32 *num_y_tiles, int32 *tile_x, int32 *tile_y, RGB8 *pal) {
int32 value;
- uint8 buf[4];
- int i;
- //byte *byte_ptr;
- void *bufferHandle;
// Initalize return parameters
*num_x_tiles = 0;
@@ -46,58 +42,22 @@ void tt_read_header(SysFile *ifp, int32 *file_x, int32 *file_y,
if (!ifp->exists())
error_show(FL, 'FNF!', ".TT file");
- // Read chunk id
- bufferHandle = &buf[0];
- ifp->read((MemHandle)&bufferHandle, 4);
- value = (buf[3] << 24) + (buf[2] << 16) + (buf[1] << 8) + buf[0]; //because in intel chip, swap order of high bits and low bits
-
- // Read chunk size
- bufferHandle = &buf[0];
- ifp->read((MemHandle)&bufferHandle, 4);
- value = (buf[3] << 24) + (buf[2] << 16) + (buf[1] << 8) + buf[0];
-
- // Read file_x size
- bufferHandle = &buf[0];
- ifp->read((MemHandle)&bufferHandle, 4);
- *file_x = (buf[3] << 24) + (buf[2] << 16) + (buf[1] << 8) + buf[0];
-
- // Read file_y size
- bufferHandle = &buf[0];
- ifp->read((MemHandle)&bufferHandle, 4);
- *file_y = (buf[3] << 24) + (buf[2] << 16) + (buf[1] << 8) + buf[0];
-
- // Read number of x tiles
- bufferHandle = &buf[0];
- ifp->read((MemHandle)&bufferHandle, 4);
- *num_x_tiles = (buf[3] << 24) + (buf[2] << 16) + (buf[1] << 8) + buf[0];
-
- // Read number of y tiles
- bufferHandle = &buf[0];
- ifp->read((MemHandle)&bufferHandle, 4);
- *num_y_tiles = (buf[3] << 24) + (buf[2] << 16) + (buf[1] << 8) + buf[0];
-
- // Read size of tile_x
- bufferHandle = &buf[0];
- ifp->read((MemHandle)&bufferHandle, 4);
- *tile_x = (buf[3] << 24) + (buf[2] << 16) + (buf[1] << 8) + buf[0];
-
- // Read size of tile_y
- bufferHandle = &buf[0];
- ifp->read((MemHandle)&bufferHandle, 4);
- *tile_y = (buf[3] << 24) + (buf[2] << 16) + (buf[1] << 8) + buf[0];
+ ifp->readUint32LE(); // skip chunk ID
+ ifp->readUint32LE(); // skip chunk size
+
+ *file_x = ifp->readSint32LE();
+ *file_y = ifp->readSint32LE();
+ *num_x_tiles = ifp->readSint32LE();
+ *num_y_tiles = ifp->readSint32LE();
+ *tile_x = ifp->readSint32LE();
+ *tile_y = ifp->readSint32LE();
// Write color table
- for (i = 0; i < 256; i++) {
- //byte_ptr = (byte *)&value;
- bufferHandle = &buf[0];
- ifp->read((MemHandle)&bufferHandle, 4);
- value = (buf[3] << 24) + (buf[2] << 16) + (buf[1] << 8) + buf[0];
+ for (int i = 0; i < 256; i++) {
+ value = ifp->readSint32LE();
- //byte_ptr++;
pal[i].r = (value >> 16) & 0x0ff;
- //byte_ptr++;
pal[i].g = (value >> 8) & 0x0ff;
- //byte_ptr++;
pal[i].b = (value) & 0x0ff;
}
}
@@ -105,10 +65,8 @@ void tt_read_header(SysFile *ifp, int32 *file_x, int32 *file_y,
Buffer *tt_read(SysFile *ifp, int index, int32 tile_x, int32 tile_y) {
int32 tile_size;
int offset;
- Buffer *out;
- void *bufferHandle;
+ Buffer *out = (Buffer *)mem_alloc(sizeof(Buffer), "tile buffer");
- out = (Buffer *)mem_alloc(sizeof(Buffer), "tile buffer");
if (!out)
error_show(FL, 'OOM!', "fail to allocate mem for buffer structure");
@@ -145,8 +103,7 @@ Buffer *tt_read(SysFile *ifp, int index, int32 tile_x, int32 tile_y) {
out->w = out->stride = tile_x;
out->h = tile_y;
- bufferHandle = out->data;
- ifp->read((MemHandle)&bufferHandle, tile_size);
+ ifp->read(out->data, tile_size);
return out;
}
More information about the Scummvm-git-logs
mailing list