scummvm/engines/fullpipe/gfx.cpp

367 lines
7.3 KiB
C++
Raw Normal View History

/* 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 "fullpipe/fullpipe.h"
#include "fullpipe/objects.h"
2013-07-11 08:09:11 +03:00
#include "common/memstream.h"
namespace Fullpipe {
2013-07-11 08:09:11 +03:00
void Bitmap::load(Common::ReadStream *s) {
debug(5, "Bitmap::load()");
2013-07-11 08:09:11 +03:00
x = s->readUint32LE();
y = s->readUint32LE();
width = s->readUint32LE();
height = s->readUint32LE();
s->readUint32LE(); // pixels
type = s->readUint32LE();
field_18 = s->readUint32LE();
flags = s->readUint32LE();
debug(9, "x: %d y: %d w: %d h: %d", x, y, width, height);
debug(9, "type: %d field_18: %d flags: 0x%x", type, field_18, flags);
}
Background::Background() {
_x = 0;
_y = 0;
_messageQueueId = 0;
_bigPictureArray1Count = 0;
_bigPictureArray2Count = 0;
_bigPictureArray = 0;
2013-06-23 23:32:51 -04:00
_stringObj = 0;
_colorMemoryObj = 0;
}
bool Background::load(MfcArchive &file) {
debug(5, "Background::load()");
_stringObj = file.readPascalString();
int count = file.readUint16LE();
for (int i = 0; i < count; i++) {
PictureObject *pct = new PictureObject();
pct->load(file, i == 0);
addPictureObject(pct);
}
assert(g_fullpipe->_gameProjectVersion >= 4);
_bigPictureArray1Count = file.readUint32LE();
assert(g_fullpipe->_gameProjectVersion >= 5);
_bigPictureArray2Count = file.readUint32LE();
_bigPictureArray = (BigPicture ***)calloc(_bigPictureArray1Count, sizeof(BigPicture **));
debug(6, "bigPictureArray[%d][%d]", _bigPictureArray1Count, _bigPictureArray2Count);
for (int i = 0; i < _bigPictureArray1Count; i++) {
_bigPictureArray[i] = (BigPicture **)calloc(_bigPictureArray2Count, sizeof(BigPicture *));
for (int j = 0; j < _bigPictureArray2Count; j++) {
2013-07-06 22:56:11 +03:00
_bigPictureArray[i][j] = new BigPicture();
2013-07-06 22:56:11 +03:00
_bigPictureArray[i][j]->load(file);
}
}
return true;
}
void Background::addPictureObject(PictureObject *pct) {
if (pct->_field_4)
renumPictures(pct);
bool inserted = false;
for (uint i = 0; i < _picObjList.size(); i++) {
if (((PictureObject *)_picObjList[i])->_priority == pct->_priority) {
2013-07-06 22:56:11 +03:00
_picObjList.insert_at(i, pct);
inserted = true;
break;
}
}
if (!inserted) {
_picObjList.push_back(pct);
}
}
void Background::renumPictures(PictureObject *pct) {
2013-07-06 22:56:11 +03:00
int *buf = (int *)calloc(_picObjList.size() + 2, sizeof(int));
2013-07-13 11:51:36 +03:00
for (uint i = 0; i < _picObjList.size(); i++) {
if (pct->_id == ((PictureObject *)_picObjList[i])->_id)
buf[((PictureObject *)_picObjList[i])->_field_4] = 1;
}
if (buf[pct->_field_4]) {
uint count;
for (count = 1; buf[count] && count < _picObjList.size() + 2; count++)
;
pct->_field_4 = count;
}
free(buf);
}
PictureObject::PictureObject() {
_ox = 0;
_oy = 0;
_picture = 0;
}
bool PictureObject::load(MfcArchive &file, bool bigPicture) {
debug(5, "PictureObject::load()");
GameObject::load(file);
if (bigPicture)
_picture = new BigPicture();
else
_picture = new Picture();
_picture->load(file);
_pictureObject2List = new CPtrList();
int count = file.readUint16LE();
if (count > 0) {
GameObject *o = new GameObject();
o->load(file);
_pictureObject2List->push_back(o);
}
_ox2 = _ox;
_oy2 = _oy;
return true;
}
GameObject::GameObject() {
_field_4 = 0;
_flags = 0;
_id = 0;
_ox = 0;
_oy = 0;
_priority = 0;
_field_20 = 0;
_field_8 = 0;
}
bool GameObject::load(MfcArchive &file) {
debug(5, "GameObject::load()");
_field_4 = 0;
_flags = 0;
_field_20 = 0;
_id = file.readUint16LE();
_stringObj = file.readPascalString();
_ox = file.readUint32LE();
_oy = file.readUint32LE();
_priority = file.readUint16LE();
if (g_fullpipe->_gameProjectVersion >= 11) {
2013-07-06 22:56:11 +03:00
_field_8 = file.readUint32LE();
}
return true;
}
void GameObject::setOXY(int x, int y) {
_ox = x;
_oy = y;
}
Picture::Picture() {
_x = 0;
_y = 0;
_field_44 = 0;
_field_54 = 0;
_bitmap = 0;
_alpha = -1;
_paletteData = 0;
_convertedBitmap = 0;
}
bool Picture::load(MfcArchive &file) {
debug(5, "Picture::load()");
MemoryObject::load(file);
_x = file.readUint32LE();
_y = file.readUint32LE();
_field_44 = file.readUint16LE();
assert(g_fullpipe->_gameProjectVersion >= 2);
_width = file.readUint32LE();
_height = file.readUint32LE();
_flags |= 1;
_memoryObject2 = new MemoryObject2;
_memoryObject2->load(file);
if (_memoryObject2->_data) {
setAOIDs();
}
assert (g_fullpipe->_gameProjectVersion >= 12);
_alpha = file.readUint32LE();
int havePal = file.readUint32LE();
if (havePal > 0) {
_paletteData = (byte *)calloc(1024, 1);
file.read(_paletteData, 1024);
}
return true;
}
void Picture::setAOIDs() {
int w = (g_fullpipe->_pictureScale + _width - 1) / g_fullpipe->_pictureScale;
int h = (g_fullpipe->_pictureScale + _height - 1) / g_fullpipe->_pictureScale;
_memoryObject2->_rows = (byte **)malloc(w * sizeof(int *));
int pitch = 2 * h;
byte *ptr = _memoryObject2->getData();
for (int i = 0; i < w; i++) {
_memoryObject2->_rows[i] = ptr;
ptr += pitch;
}
}
2013-07-11 08:09:11 +03:00
void Picture::init() {
_bitmap = new Bitmap();
getDibInfo();
_bitmap->flags |= 0x1000000;
}
void Picture::getDibInfo() {
int off = _dataSize & ~0xf;
if (_dataSize != off) {
warning("Uneven data size: 0x%x", _dataSize);
}
Common::MemoryReadStream *s = new Common::MemoryReadStream(_data + off, 32);
_bitmap->load(s);
_bitmap->pixels = _data;
}
2013-07-12 10:38:30 +03:00
Bitmap *Picture::getPixelData() {
if (!_bitmap)
init();
return _bitmap;
}
2013-07-13 11:45:52 +03:00
void Picture::draw(int x, int y, int style, int angle) {
int x1 = x;
int y1 = y;
if (x != -1)
x1 = x;
if (y != -1)
y1 = y;
if (!_bitmap)
init();
if (!_bitmap)
return;
if (_alpha < 0xff) {
warning("Picture:draw: alpha = %0x", _alpha);
}
if (_bitmap->type == MKTAG('C', 'B', '\0', '\0') || _bitmap->type == MKTAG('R', 'B', '\0', '\0')) {
if (_paletteData) {
warning("Picture:draw: have palette");
}
}
switch (style) {
case 1:
//flip
warning("Picture::draw: style 1");
break;
case 2:
error("Picture::draw: style 2");
break;
default:
if (angle) {
warning("Picture:draw: angle = %d", angle);
drawRotated(x1, y1, angle);
} else {
putDib(x1, y1);
}
}
}
void Picture::drawRotated(int x, int y, int angle) {
}
void Picture::putDib(int x, int y) {
}
BigPicture::BigPicture() {
}
bool BigPicture::load(MfcArchive &file) {
debug(5, "BigPicture::load()");
Picture::load(file);
return true;
}
2013-06-24 08:28:07 -04:00
Shadows::Shadows() {
_staticAniObjectId = 0;
_movementId = 0;
_sceneId = 0;
}
bool Shadows::load(MfcArchive &file) {
debug(5, "Shadows::load()");
2013-06-24 08:28:07 -04:00
_sceneId = file.readUint32LE();
_staticAniObjectId = file.readUint32LE();
_movementId = file.readUint32LE();
return true;
}
} // End of namespace Fullpipe