2019-05-31 12:51:09 +05:30
|
|
|
/* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2019-06-05 14:12:53 +05:30
|
|
|
#include "hdb/hdb.h"
|
2019-05-31 12:51:09 +05:30
|
|
|
|
|
|
|
namespace HDB {
|
|
|
|
|
|
|
|
DrawMan::DrawMan() {
|
2019-06-07 22:27:29 +05:30
|
|
|
_tLookupArray = NULL;
|
2019-05-31 12:51:09 +05:30
|
|
|
_systemInit = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DrawMan::init() {
|
2019-06-07 19:46:16 +05:30
|
|
|
|
2019-06-07 22:27:29 +05:30
|
|
|
// Read total number of tiles in game
|
2019-06-07 19:46:16 +05:30
|
|
|
_numTiles = g_hdb->_fileMan->getCount("t32_", TYPE_TILE32);
|
|
|
|
if (!_numTiles) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-06-07 22:27:29 +05:30
|
|
|
// Setup Tile Lookup Array
|
|
|
|
_tLookupArray = new TileLookup[_numTiles];
|
|
|
|
Common::Array<const char *> tileData = *g_hdb->_fileMan->findFiles("t32_", TYPE_TILE32);
|
|
|
|
|
|
|
|
int index = 0, skyIndex = 0;
|
|
|
|
for (; index < _numTiles; index++) {
|
|
|
|
_tLookupArray[index].filename = tileData[index];
|
|
|
|
_tLookupArray[index].tData = NULL;
|
|
|
|
_tLookupArray[index].skyIndex = 0;
|
|
|
|
_tLookupArray[index].animIndex = index;
|
|
|
|
// Check if the loaded Tile is a Sky Tile
|
|
|
|
if (((Common::String)tileData[index]).contains("sky") && (skyIndex < kMaxSkies)) {
|
|
|
|
_tLookupArray[index].skyIndex = skyIndex + 1;
|
|
|
|
_skyTiles[skyIndex] = index;
|
|
|
|
skyIndex++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
TODO: Add Animating Tile Info
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Init Sky Data
|
|
|
|
_currentSky = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
TODO: Setup Gamma Table
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
TODO: Load Mouse Pointer and Display Cursor
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
TODO: Load all 4 levels of star colors and the snowflake
|
|
|
|
*/
|
|
|
|
|
2019-05-31 12:51:09 +05:30
|
|
|
_systemInit = true;
|
2019-05-31 19:52:13 +05:30
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-06-07 23:23:58 +05:30
|
|
|
Tile *DrawMan::getTile(int index) {
|
2019-06-07 22:28:45 +05:30
|
|
|
|
2019-06-07 23:23:58 +05:30
|
|
|
if (index < 0 || index > _numTiles) {
|
|
|
|
return NULL;
|
2019-06-07 22:28:45 +05:30
|
|
|
}
|
|
|
|
if (_tLookupArray[index].skyIndex) {
|
2019-06-07 23:23:58 +05:30
|
|
|
// We don't draw Sky Tiles, so return NULL
|
|
|
|
return NULL;
|
2019-06-07 22:28:45 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
if (_tLookupArray[index].tData == NULL) {
|
|
|
|
Common::SeekableReadStream *stream = g_hdb->_fileMan->findFirstData(_tLookupArray[index].filename, TYPE_TILE32);
|
|
|
|
Tile *tile = new Tile;
|
|
|
|
tile->load(stream);
|
|
|
|
_tLookupArray[index].tData = tile;
|
|
|
|
}
|
|
|
|
|
2019-06-07 23:23:58 +05:30
|
|
|
return _tLookupArray[index].tData;
|
2019-06-07 22:28:45 +05:30
|
|
|
}
|
|
|
|
|
2019-06-07 23:25:06 +05:30
|
|
|
int DrawMan::isSky(int index) {
|
|
|
|
if (!index) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < kMaxSkies; i++) {
|
|
|
|
if(_skyTiles[i] == index) {
|
|
|
|
return index + 1; // The skyTiles are indexed from 1. 0 => No Sky tile
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-06-01 21:42:25 +05:30
|
|
|
Picture::~Picture() {
|
|
|
|
_surface.free();
|
|
|
|
}
|
|
|
|
|
2019-06-01 16:20:56 +05:30
|
|
|
Graphics::Surface Picture::load(Common::SeekableReadStream *stream) {
|
|
|
|
_width = stream->readUint32LE();
|
|
|
|
_height = stream->readUint32LE();
|
|
|
|
stream->read(_name, 64);
|
2019-06-01 17:56:04 +05:30
|
|
|
|
2019-06-01 16:20:56 +05:30
|
|
|
Graphics::PixelFormat format(2, 5, 6, 5, 0, 11, 5, 0, 0);
|
|
|
|
|
|
|
|
debug(8, "Picture: _width: %d, _height: %d", _width, _height);
|
|
|
|
debug(8, "Picture: _name: %s", _name);
|
|
|
|
|
|
|
|
_surface.create(_width, _height, format);
|
|
|
|
stream->readUint32LE(); // Skip Win32 Surface
|
|
|
|
|
|
|
|
uint16 *ptr;
|
|
|
|
|
|
|
|
for (uint y = 0; y < _height; y++) {
|
|
|
|
ptr = (uint16 *) _surface.getBasePtr(0, y);
|
|
|
|
for (uint x = 0; x < _width; x++) {
|
|
|
|
*ptr = TO_LE_16(stream->readUint16LE());
|
|
|
|
ptr++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return _surface;
|
|
|
|
}
|
|
|
|
|
2019-06-01 21:42:25 +05:30
|
|
|
Tile::~Tile() {
|
|
|
|
_surface.free();
|
|
|
|
}
|
|
|
|
|
2019-06-01 17:56:04 +05:30
|
|
|
Graphics::Surface Tile::load(Common::SeekableReadStream *stream) {
|
|
|
|
_flags = stream->readUint32LE();
|
|
|
|
stream->read(_name, 64);
|
|
|
|
|
|
|
|
Graphics::PixelFormat format(2, 5, 6, 5, 0, 11, 5, 0, 0);
|
|
|
|
|
|
|
|
_surface.create(32, 32, format);
|
|
|
|
stream->readUint32LE(); // Skip Win32 Surface
|
|
|
|
|
|
|
|
uint16 *ptr;
|
|
|
|
|
|
|
|
for (uint y = 0; y < 32; y++) {
|
|
|
|
ptr = (uint16 *)_surface.getBasePtr(0, y);
|
|
|
|
for (uint x = 0; x < 32; x++) {
|
|
|
|
*ptr = TO_LE_16(stream->readUint16LE());
|
|
|
|
ptr++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return _surface;
|
|
|
|
}
|
|
|
|
|
2019-06-01 01:58:15 +05:30
|
|
|
}
|