Added a Sprite class for handling sprites in the Draci format transparently. Modified the test animation to use it.

svn-id: r41509
This commit is contained in:
Denis Kasak 2009-06-14 12:44:12 +00:00
parent 02cd93421d
commit b8ec907ea0
4 changed files with 156 additions and 20 deletions

View File

@ -35,6 +35,7 @@
#include "draci/barchive.h"
#include "draci/gpldisasm.h"
#include "draci/font.h"
#include "draci/sprite.h"
namespace Draci {
@ -88,6 +89,13 @@ int DraciEngine::init() {
return 0;
}
// Temporary hack
void drawFrame(OSystem *syst, BAFile *frame) {
Sprite sp(frame->_data, frame->_length, ((320 - 50) / 2), 60, true);
syst->copyRectToScreen(sp._data, sp._width, sp._x, sp._y, sp._width, sp._height);
}
int DraciEngine::go() {
debugC(1, kDraciGeneralDebugLevel, "DraciEngine::go()");
@ -154,29 +162,11 @@ int DraciEngine::go() {
// Load frame to memory
f = ar[t];
Common::MemoryReadStream reader(f->_data, f->_length);
// Read in frame width and height
uint16 w = reader.readUint16LE();
uint16 h = reader.readUint16LE();
// Allocate frame memory
byte *scr = new byte[w * h];
// Draw frame
for (uint16 i = 0; i < w; ++i) {
for (uint16 j = 0; j < h; ++j) {
scr[j * w + i] = reader.readByte();
}
}
_system->copyRectToScreen(scr, w, (320 - w) / 2, 60, w, h);
drawFrame(_system, f);
_system->updateScreen();
_system->delayMillis(100);
debugC(5, kDraciGeneralDebugLevel, "Finished frame %d", t);
// Free frame memory
delete[] scr;
}
getchar();

View File

@ -5,7 +5,8 @@ MODULE_OBJS := \
detection.o \
barchive.o \
gpldisasm.o \
font.o
font.o \
sprite.o
MODULE_DIRS += \
engines/draci

85
engines/draci/sprite.cpp Normal file
View File

@ -0,0 +1,85 @@
/* 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.
*
* $URL$
* $Id$
*
*/
#include "common/stream.h"
#include "draci/sprite.h"
namespace Draci {
/**
* Constructor for loading sprites from a raw data buffer, one byte per pixel.
*/
Sprite::Sprite(byte *raw_data, uint16 width, uint16 height, uint16 x, uint16 y,
bool columnwise) : _width(width), _height(height), _x(x), _y(y), _data(NULL) {
_data = new byte[width * height];
if (!columnwise) {
memcpy(_data, raw_data, width * height);
return;
}
else {
for (uint16 i = 0; i < width; ++i) {
for (uint16 j = 0; j < height; ++j) {
_data[j * width + i] = *raw_data++;
}
}
}
}
/**
* Constructor for loading sprites from a sprite-formatted buffer, one byte per
* pixel.
*/
Sprite::Sprite(byte *sprite_data, uint16 length, uint16 x, uint16 y,
bool columnwise) : _x(x), _y(y), _data(NULL) {
Common::MemoryReadStream reader(sprite_data, length);
_width = reader.readUint16LE();
_height = reader.readUint16LE();
_data = new byte[_width * _height];
if (!columnwise) {
reader.read(_data, _width * _height);
}
else {
for (uint16 i = 0; i < _width; ++i) {
for (uint16 j = 0; j < _height; ++j) {
_data[j * _width + i] = reader.readByte();
}
}
}
}
Sprite::~Sprite() {
delete[] _data;
}
} // End of namespace Draci

60
engines/draci/sprite.h Normal file
View File

@ -0,0 +1,60 @@
/* 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.
*
* $URL$
* $Id$
*
*/
namespace Draci {
/**
* Represents a Draci Historie sprite. Supplies two constructors; one for
* loading a sprite from a raw data buffer and one for loading a sprite in
* the Draci sprite format. Supports loading the sprite from a column-wise
* format (transforming them to row-wise) since that is the way the sprites
* are stored in the original game files.
*
* Sprite format:
* [uint16LE] sprite width
* [uint16LE] sprite height
* [height * width bytes] image pixels stored column-wise, one byte per pixel
*/
class Sprite {
public:
Sprite(byte *raw_data, uint16 width, uint16 height, uint16 x = 0, uint16 y = 0,
bool columnwise = false);
Sprite(byte *sprite_data, uint16 length, uint16 x = 0, uint16 y = 0,
bool columnwise = false);
~Sprite();
byte *_data;
uint16 _width;
uint16 _height;
uint16 _x, _y;
};
} // End of namespace Draci