scummvm/engines/gnap/resource.cpp

120 lines
3.8 KiB
C++
Raw Normal View History

2014-01-07 21:37:29 +01:00
/* 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.
*
2014-01-07 21:37:29 +01:00
* 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.
*
2014-01-07 21:37:29 +01:00
* 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.
*
*/
2016-04-12 08:00:11 +02:00
#include "gnap/gnap.h"
2014-01-07 21:37:29 +01:00
#include "gnap/resource.h"
namespace Gnap {
// SequenceFrame
void SequenceFrame::loadFromStream(Common::MemoryReadStream &stream) {
2016-03-18 07:39:38 +01:00
_duration = stream.readUint16LE();
_isScaled = (stream.readUint16LE() != 0);
2016-03-18 07:39:38 +01:00
_rect.left = stream.readUint32LE();
_rect.top = stream.readUint32LE();
_rect.right = stream.readUint32LE();
_rect.bottom = stream.readUint32LE();
_spriteId = stream.readUint32LE();
_soundId = stream.readUint32LE();
_unusedVal = stream.readUint32LE();
2016-04-12 08:00:11 +02:00
debugC(kDebugBasic, "SequenceFrame() spriteId: %d; soundId: %d", _spriteId, _soundId);
2014-01-07 21:37:29 +01:00
}
// SequenceAnimation
void SequenceAnimation::loadFromStream(Common::MemoryReadStream &stream) {
2016-03-18 07:48:29 +01:00
_unusedVal1 = stream.readUint16LE();
_unusedVal2 = stream.readUint16LE();
_additionalDelay = stream.readUint32LE();
_framesCount = stream.readUint16LE();
_maxTotalDuration = stream.readUint16LE();
2016-04-12 08:00:11 +02:00
debugC(kDebugBasic, "SequenceAnimation() framesCount: %d", _framesCount);
2016-03-18 07:48:29 +01:00
frames = new SequenceFrame[_framesCount];
for (int i = 0; i < _framesCount; ++i)
2014-01-07 21:37:29 +01:00
frames[i].loadFromStream(stream);
}
// SequenceResource
SequenceResource::SequenceResource(int resourceId, byte *data, uint32 size) {
Common::MemoryReadStream stream(data, size, DisposeAfterUse::NO);
2016-03-18 07:48:29 +01:00
_unusedVal1 = stream.readUint32LE();
2014-01-07 21:37:29 +01:00
_sequenceId = stream.readUint32LE();
2016-03-18 07:48:29 +01:00
_defaultId = stream.readUint32LE();
2014-01-07 21:37:29 +01:00
_sequenceId2 = stream.readUint32LE();
2016-03-18 07:48:29 +01:00
_defaultId2 = stream.readUint32LE();
2014-01-07 21:37:29 +01:00
_flags = stream.readUint32LE();
_totalDuration = stream.readUint32LE();
_xOffs = stream.readUint16LE();
_yOffs = stream.readUint16LE();
_animationsCount = stream.readUint32LE();
_animations = new SequenceAnimation[_animationsCount];
2016-04-12 08:00:11 +02:00
debugC(kDebugBasic, "SequenceResource() _animationsCount: %d", _animationsCount);
2014-01-07 21:37:29 +01:00
for (int i = 0; i < _animationsCount; ++i) {
uint32 animationOffs = stream.readUint32LE();
2016-04-12 08:00:11 +02:00
debugC(kDebugBasic, "animationOffs: %08X", animationOffs);
2014-01-07 21:37:29 +01:00
uint32 oldOffs = stream.pos();
stream.seek(animationOffs);
_animations[i].loadFromStream(stream);
stream.seek(oldOffs);
}
// TODO Convert resourceIds
}
SequenceResource::~SequenceResource() {
delete[] _animations;
}
// SpriteResource
SpriteResource::SpriteResource(int resourceId, byte *data, uint32 size) {
_data = data;
_width = READ_LE_UINT16(_data);
_height = READ_LE_UINT16(_data + 2);
2016-03-18 07:48:29 +01:00
_unknownVal1 = READ_LE_UINT16(_data + 4);
_unknownVal2 = READ_LE_UINT16(_data + 6);
_transparent = (READ_LE_UINT16(_data + 8) != 0);
2014-01-07 21:37:29 +01:00
_colorsCount = READ_LE_UINT16(_data + 10);
_palette = (uint32*)(_data + 12);
_pixels = _data + 12 + _colorsCount * 4;
2016-04-12 08:00:11 +02:00
debugC(kDebugBasic, "SpriteResource() width: %d; height: %d; colorsCount: %d", _width, _height, _colorsCount);
2014-01-07 21:37:29 +01:00
}
SpriteResource::~SpriteResource() {
delete[] _data;
}
// SoundResource
SoundResource::SoundResource(int resourceId, byte *data, uint32 size) {
_data = data;
_size = size;
}
SoundResource::~SoundResource() {
delete[] _data;
}
} // End of namespace Gnap