From c934941e4f1d72723924f6f6fb7b76712784ff82 Mon Sep 17 00:00:00 2001 From: Peter Kohaut Date: Thu, 6 Oct 2016 22:32:27 +0200 Subject: BLADERUNNER: fixed some of endianness issues --- engines/bladerunner/fog.cpp | 8 ++++-- engines/bladerunner/font.cpp | 58 +++++++++++++++++++++++++------------------ engines/bladerunner/font.h | 6 +---- engines/bladerunner/light.cpp | 14 ++++++++--- 4 files changed, 51 insertions(+), 35 deletions(-) diff --git a/engines/bladerunner/fog.cpp b/engines/bladerunner/fog.cpp index b51ec1060a..73e802667f 100644 --- a/engines/bladerunner/fog.cpp +++ b/engines/bladerunner/fog.cpp @@ -44,8 +44,12 @@ int Fog::readCommon(Common::ReadStream *stream) { void Fog::readAnimationData(Common::ReadStream *stream, int size) { _animatedParameters = stream->readUint32LE(); - _animationData = new float[size / sizeof(float)]; - stream->read(_animationData, size); + + int floatsCount = size / 4; + _animationData = new float[floatsCount]; + for (int i = 0; i < floatsCount; i++) { + _animationData[i] = stream->readFloatLE(); + } _m11ptr = _animationData; _m12ptr = _m11ptr + (_animatedParameters & 0x1 ? _framesCount : 1); diff --git a/engines/bladerunner/font.cpp b/engines/bladerunner/font.cpp index 2f15780719..972f50a784 100644 --- a/engines/bladerunner/font.cpp +++ b/engines/bladerunner/font.cpp @@ -61,8 +61,16 @@ bool Font::open(const Common::String &fileName, int screenWidth, int screenHeigh return false; } - stream->read(_characters, _characterCount * sizeof(FontCharacter)); - stream->read(_data, _dataSize * sizeof(uint16)); + for (int i = 0; i < _characterCount; i++) { + _characters[i]._x = stream->readUint32LE(); + _characters[i]._y = stream->readUint32LE(); + _characters[i]._width = stream->readUint32LE(); + _characters[i]._height = stream->readUint32LE(); + _characters[i]._dataOffset = stream->readUint32LE(); + } + for(int i = 0; i < _dataSize; i++) { + _data[i] = stream->readUint16LE(); + } return true; } @@ -88,28 +96,30 @@ void Font::setColor(uint16 color) { } void Font::draw(const Common::String &text, Graphics::Surface &surface, int x, int y) { - if (_data) { - if (x < 0) { - x = 0; - } - if (y < 0) { - y = 0; - } + if (!_data) { + return; + } - int textWidth = getTextWidth(text); - if (textWidth + x >= _screenWidth) { - x = _screenWidth - (textWidth + 1); - } - if (_maxHeight + y >= _screenHeight) { - y = _screenHeight - _maxHeight; - } + if (x < 0) { + x = 0; + } + if (y < 0) { + y = 0; + } - const char *character = text.c_str(); - while (*character != 0) { - drawCharacter(*character, surface, x, y); - x += _spacing1 + _characters[*character + 1]._width; - character++; - } + int textWidth = getTextWidth(text); + if (textWidth + x >= _screenWidth) { + x = _screenWidth - (textWidth + 1); + } + if (_maxHeight + y >= _screenHeight) { + y = _screenHeight - _maxHeight; + } + + const char *character = text.c_str(); + while (*character != 0) { + drawCharacter(*character, surface, x, y); + x += _spacing1 + _characters[*character + 1]._width; + character++; } } @@ -151,7 +161,7 @@ void Font::reset() { _color = 0x7FFF; _intersperse = 0; - memset(_characters, 0, 5120); + memset(_characters, 0, 256 * sizeof(FontCharacter)); } void Font::replaceColor(uint16 oldColor, uint16 newColor) { @@ -166,7 +176,7 @@ void Font::replaceColor(uint16 oldColor, uint16 newColor) { } void Font::drawCharacter(const char character, Graphics::Surface &surface, int x, int y) { - if (x < 0 || x >= this->_screenWidth || y < 0 || y >= _screenHeight || !_data || character + 1 >= _characterCount) { + if (x < 0 || x >= _screenWidth || y < 0 || y >= _screenHeight || !_data || character + 1 >= _characterCount) { return; } diff --git a/engines/bladerunner/font.h b/engines/bladerunner/font.h index 329bc48abe..de790b0244 100644 --- a/engines/bladerunner/font.h +++ b/engines/bladerunner/font.h @@ -33,17 +33,13 @@ namespace BladeRunner { class BladeRunnerEngine; -#include "common/pack-start.h" - struct FontCharacter { int _x; int _y; int _width; int _height; int _dataOffset; -} PACKED_STRUCT; - -#include "common/pack-end.h" +}; class Font { BladeRunnerEngine *_vm; diff --git a/engines/bladerunner/light.cpp b/engines/bladerunner/light.cpp index fbbf595493..08eb8ab5be 100644 --- a/engines/bladerunner/light.cpp +++ b/engines/bladerunner/light.cpp @@ -43,8 +43,11 @@ void Light::read(Common::ReadStream *stream, int framesCount, int frame, int ani _animatedParameters = stream->readUint32LE(); - _animationData = new float[size / sizeof(float)]; - stream->read(_animationData, size); + int floatsCount = size / 4; + _animationData = new float[floatsCount]; + for (int i = 0; i < floatsCount; i++) { + _animationData[i] = stream->readFloatLE(); + } _m11ptr = _animationData; _m12ptr = _m11ptr + (_animatedParameters & 0x1 ? framesCount : 1); @@ -77,8 +80,11 @@ void Light::readVqa(Common::ReadStream *stream, int framesCount, int frame, int int size = stream->readUint32LE(); - _animationData = new float[size / sizeof(float)]; - stream->read(_animationData, size); + int floatsCount = size / 4; + _animationData = new float[floatsCount]; + for (int i = 0; i < floatsCount; i++) { + _animationData[i] = stream->readFloatLE(); + } _m11ptr = _animationData; _m12ptr = _m11ptr + (_animatedParameters & 0x1 ? framesCount : 1); -- cgit v1.2.3