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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
/* 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 "neverhood/resource.h"
#include "neverhood/resourceman.h"
namespace Neverhood {
SpriteResource::SpriteResource(NeverhoodEngine *vm)
: _vm(vm), _resourceHandle(-1), _pixels(NULL) {
}
SpriteResource::~SpriteResource() {
unload();
}
void SpriteResource::draw(byte *dest, int destPitch, bool flipX, bool flipY) {
if (_pixels) {
if (_rle) {
unpackSpriteRle(_pixels, _dimensions.width, _dimensions.height, dest, destPitch, flipX, flipY);
} else {
unpackSpriteNormal(_pixels, _dimensions.width, _dimensions.height, dest, destPitch, flipX, flipY);
}
}
}
bool SpriteResource::load(uint32 fileHash) {
// TODO: Later merge with load2 and make the mode a parameter
unload();
_resourceHandle = _vm->_res->useResource(fileHash);
debug("SpriteResource::load(0x%08X) _resourceHandle = %d", fileHash, _resourceHandle);
if (_resourceHandle != -1) {
if (_vm->_res->getResourceType(_resourceHandle) == 2) {
byte *spriteData = _vm->_res->loadResource(_resourceHandle, true);
parseBitmapResource(spriteData, &_rle, &_dimensions, NULL, NULL, &_pixels);
} else {
_vm->_res->unuseResource(_resourceHandle);
_resourceHandle = -1;
}
}
return _pixels != NULL;
}
bool SpriteResource::load2(uint32 fileHash) {
unload();
_resourceHandle = _vm->_res->useResource(fileHash);
if (_resourceHandle != -1) {
if (_vm->_res->getResourceType(_resourceHandle) == 2) {
byte *spriteData = _vm->_res->loadResource(_resourceHandle, true);
parseBitmapResource(spriteData, &_rle, &_dimensions, &_unknown, NULL, &_pixels);
} else {
_vm->_res->unuseResource(_resourceHandle);
_resourceHandle = -1;
}
}
return _pixels != NULL;
}
void SpriteResource::unload() {
if (_resourceHandle != -1) {
_vm->_res->unloadResource(_resourceHandle);
_vm->_res->unuseResource(_resourceHandle);
_resourceHandle = -1;
} else {
delete[] _pixels;
}
_pixels = NULL;
_rle = false;
}
PaletteResource::PaletteResource(NeverhoodEngine *vm)
: _vm(vm), _resourceHandle(-1), _palette(NULL) {
}
PaletteResource::~PaletteResource() {
unload();
}
bool PaletteResource::load(uint32 fileHash) {
unload();
_resourceHandle = _vm->_res->useResource(fileHash);
if (_resourceHandle != -1) {
_palette = _vm->_res->loadResource(_resourceHandle, true);
switch (_vm->_res->getResourceType(_resourceHandle)) {
case 2:
// Palette is stored in a bitmap
parseBitmapResource(_palette, NULL, NULL, NULL, &_palette, NULL);
break;
case 3:
// _palette already points to the correct data
break;
default:
_vm->_res->unuseResource(_resourceHandle);
_resourceHandle = -1;
break;
}
}
return _palette != NULL;
}
void PaletteResource::unload() {
if (_resourceHandle != -1) {
_vm->_res->unloadResource(_resourceHandle);
_vm->_res->unuseResource(_resourceHandle);
_resourceHandle = -1;
_palette = NULL;
}
}
void PaletteResource::copyPalette(byte *destPalette) {
if (_palette) {
memcpy(destPalette, _palette, 1024);
} else {
// TODO?: buildDefaultPalette(palette);
}
}
} // End of namespace Neverhood
|