aboutsummaryrefslogtreecommitdiff
path: root/engines/gnap/resource.cpp
blob: 8244213a7fe9d2771c7f92f2f1dd059201a1e0f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/* 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.
 *
 */

#include "gnap/gnap.h"
#include "gnap/resource.h"

namespace Gnap {

// SequenceFrame

void SequenceFrame::loadFromStream(Common::MemoryReadStream &stream) {
	_duration = stream.readUint16LE();
	_isScaled = (stream.readUint16LE() != 0);
	_rect.left = stream.readUint32LE();
	_rect.top = stream.readUint32LE();
	_rect.right = stream.readUint32LE();
	_rect.bottom = stream.readUint32LE();
	_spriteId = stream.readUint32LE();
	_soundId = stream.readUint32LE();

	// Skip an unused value
	stream.readUint32LE();

	debugC(kDebugBasic, "SequenceFrame() spriteId: %d; soundId: %d", _spriteId, _soundId);
}

// SequenceAnimation

void SequenceAnimation::loadFromStream(Common::MemoryReadStream &stream) {
	// Skip two unused values
	stream.readUint32LE();

	_additionalDelay = stream.readUint32LE();
	_framesCount = stream.readUint16LE();
	_maxTotalDuration = stream.readUint16LE();
	debugC(kDebugBasic, "SequenceAnimation() framesCount: %d", _framesCount);
	frames = new SequenceFrame[_framesCount];
	for (int i = 0; i < _framesCount; ++i)
		frames[i].loadFromStream(stream);
}

// SequenceResource
SequenceResource::SequenceResource(byte *data, uint32 size) {
	Common::MemoryReadStream stream(data, size, DisposeAfterUse::NO);

	// Skip an unused value
	stream.readUint32LE();

	_sequenceId = stream.readUint32LE();
	_defaultId = stream.readUint32LE();
	_sequenceId2 = stream.readUint32LE();
	_defaultId2 = stream.readUint32LE();
	_flags = stream.readUint32LE();
	_totalDuration = stream.readUint32LE();
	_xOffs = stream.readUint16LE();
	_yOffs = stream.readUint16LE();
	_animationsCount = stream.readUint32LE();
	_animations = new SequenceAnimation[_animationsCount];
	debugC(kDebugBasic, "SequenceResource() _animationsCount: %d", _animationsCount);
	for (int i = 0; i < _animationsCount; ++i) {
		uint32 animationOffs = stream.readUint32LE();
		debugC(kDebugBasic, "animationOffs: %08X", animationOffs);
		uint32 oldOffs = stream.pos();
		stream.seek(animationOffs);
		_animations[i].loadFromStream(stream);
		stream.seek(oldOffs);
	}
}

SequenceResource::~SequenceResource() {
	delete[] _animations;
}

// SpriteResource
SpriteResource::SpriteResource(byte *data, uint32 size) {
	_data = data;
	_width = READ_LE_UINT16(_data);
	_height = READ_LE_UINT16(_data + 2);
	_unknownVal1 = READ_LE_UINT16(_data + 4);
	_unknownVal2 = READ_LE_UINT16(_data + 6);
	_transparent = (READ_LE_UINT16(_data + 8) != 0);
	_colorsCount = READ_LE_UINT16(_data + 10);
	_palette = (uint32 *)(_data + 12);
	_pixels = _data + 12 + _colorsCount * 4;
	debugC(kDebugBasic, "SpriteResource() width: %d; height: %d; colorsCount: %d", _width, _height, _colorsCount);
}

SpriteResource::~SpriteResource() {
	delete[] _data;
}

// SoundResource
SoundResource::SoundResource(byte *data, uint32 size) {
	_data = data;
	_size = size;
}

SoundResource::~SoundResource() {
	delete[] _data;
}

} // End of namespace Gnap