diff options
author | johndoe123 | 2011-06-27 11:06:40 +0000 |
---|---|---|
committer | Willem Jan Palenstijn | 2013-05-08 20:30:57 +0200 |
commit | 108368e9b5282a72d0f582e89803f5ee099baa94 (patch) | |
tree | 7b2c45d2e99b367840bf4ef35d9b96ee9ef3e8e6 /engines | |
parent | a262055df25b0b00fcb0fe9e7919153f5089d615 (diff) | |
download | scummvm-rg350-108368e9b5282a72d0f582e89803f5ee099baa94.tar.gz scummvm-rg350-108368e9b5282a72d0f582e89803f5ee099baa94.tar.bz2 scummvm-rg350-108368e9b5282a72d0f582e89803f5ee099baa94.zip |
NEVERHOOD: Add more
- SpriteResource and PaletteResource resource classes
- Extend BaseSurface to be able to draw SpriteResources onto it
- Implement Entity base class (this may need some work concerning the update/message callbacks later since I'm not sure if the way it's done now is portable)
Diffstat (limited to 'engines')
-rw-r--r-- | engines/neverhood/entity.cpp | 27 | ||||
-rw-r--r-- | engines/neverhood/entity.h | 64 | ||||
-rw-r--r-- | engines/neverhood/graphics.cpp | 27 | ||||
-rw-r--r-- | engines/neverhood/graphics.h | 15 | ||||
-rw-r--r-- | engines/neverhood/module.mk | 3 | ||||
-rw-r--r-- | engines/neverhood/neverhood.cpp | 12 | ||||
-rw-r--r-- | engines/neverhood/palette.cpp | 44 | ||||
-rw-r--r-- | engines/neverhood/palette.h | 44 | ||||
-rw-r--r-- | engines/neverhood/resource.cpp | 137 | ||||
-rw-r--r-- | engines/neverhood/resource.h | 64 |
10 files changed, 437 insertions, 0 deletions
diff --git a/engines/neverhood/entity.cpp b/engines/neverhood/entity.cpp new file mode 100644 index 0000000000..9070d5c8c4 --- /dev/null +++ b/engines/neverhood/entity.cpp @@ -0,0 +1,27 @@ +/* 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/entity.h" + +namespace Neverhood { + +} // End of namespace Neverhood diff --git a/engines/neverhood/entity.h b/engines/neverhood/entity.h new file mode 100644 index 0000000000..b7ebdd1486 --- /dev/null +++ b/engines/neverhood/entity.h @@ -0,0 +1,64 @@ +/* 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. + * + */ + +#ifndef NEVERHOOD_ENTITY_H +#define NEVERHOOD_ENTITY_H + +#include "neverhood/neverhood.h" + +namespace Neverhood { + +struct MessageParam { + union { + uint32 _integer; + // TODO: Other types... + }; + // TODO: Constructors for the param types... +}; + +#define SetUpdateHandler(handler) _updateHandlerCb = static_cast <void (Entity::*)(void)> (handler) +#define SetMessageHandler(handler) _messageHandlerCb = static_cast <uint32 (Entity::*)(int messageNum, MessageParam ¶m, Entity *sender)> (handler) + +class Entity { +public: + Entity(NeverhoodEngine *vm, int priority) + : _vm(vm), _updateHandlerCb(NULL), _messageHandlerCb(NULL), _priority(priority) { + } + ~Entity() { + } + void handleUpdate() { + if (_updateHandlerCb) + (this->*_updateHandlerCb)(); + } + uint32 handleMessage(int messageNum, MessageParam ¶m, Entity *sender) { + return _messageHandlerCb ? (this->*_messageHandlerCb)(messageNum, param, sender) : 0; + } +protected: + void (Entity::*_updateHandlerCb)(); + uint32 (Entity::*_messageHandlerCb)(int messageNum, MessageParam ¶m, Entity *sender); + NeverhoodEngine *_vm; + int _priority; +}; + +} // End of namespace Neverhood + +#endif /* NEVERHOOD_ENTITY_H */ diff --git a/engines/neverhood/graphics.cpp b/engines/neverhood/graphics.cpp index fb8ec4ad72..315c62dbec 100644 --- a/engines/neverhood/graphics.cpp +++ b/engines/neverhood/graphics.cpp @@ -21,6 +21,7 @@ */ #include "neverhood/graphics.h" +#include "neverhood/resource.h" namespace Neverhood { @@ -55,6 +56,18 @@ void BaseSurface::addDirtyRect() { // TODO } +void BaseSurface::clear() { + _surface->fillRect(Common::Rect(0, 0, _surface->w, _surface->h), 0); +} + +void BaseSurface::drawSpriteResource(SpriteResource &spriteResource) { + if (spriteResource.dimensions().width <= _drawRect.width && + spriteResource.dimensions().height <= _drawRect.height) { + clear(); + spriteResource.draw((byte*)_surface->pixels, _surface->pitch, false, false); + } +} + // Misc void parseBitmapResource(byte *sprite, bool *rle, NDimensions *dimensions, NUnknown *unknown, byte **palette, byte **pixels) { @@ -138,4 +151,18 @@ void unpackSpriteRle(byte *source, int width, int height, byte *dest, int destPi } +void unpackSpriteNormal(byte *source, int width, int height, byte *dest, int destPitch, bool flipX, bool flipY) { + + // TODO: Flip + + int sourcePitch = (width + 3) & 0xFFFC; + + while (height-- > 0) { + memcpy(dest, source, width); + source += sourcePitch; + dest += destPitch; + } + +} + } // End of namespace Neverhood diff --git a/engines/neverhood/graphics.h b/engines/neverhood/graphics.h index bc592870d3..27ef6cdee6 100644 --- a/engines/neverhood/graphics.h +++ b/engines/neverhood/graphics.h @@ -48,6 +48,8 @@ struct NDrawRect { NDrawRect() : x(0), y(0), width(0), height(0) {} }; +class SpriteResource; + // NOTE: "Restore" methods aren't need in the reimplementation as they're DirectDraw-specific class BaseSurface { @@ -56,6 +58,8 @@ public: virtual ~BaseSurface(); virtual void draw(); virtual void addDirtyRect(); + void clear(); + void drawSpriteResource(SpriteResource &spriteResource); protected: NeverhoodEngine *_vm; int _priority; @@ -66,10 +70,21 @@ protected: NRect _clipRect; }; +/* +class Palette { +public: + Palette(); + ~Palette(); +protected: + +}; +*/ + // Misc void parseBitmapResource(byte *sprite, bool *rle, NDimensions *dimensions, NUnknown *unknown, byte **palette, byte **pixels); void unpackSpriteRle(byte *source, int width, int height, byte *dest, int destPitch, bool flipX, bool flipY); +void unpackSpriteNormal(byte *source, int width, int height, byte *dest, int destPitch, bool flipX, bool flipY); } // End of namespace Neverhood diff --git a/engines/neverhood/module.mk b/engines/neverhood/module.mk index 57491e6b72..d70c4a96af 100644 --- a/engines/neverhood/module.mk +++ b/engines/neverhood/module.mk @@ -3,8 +3,11 @@ MODULE := engines/neverhood MODULE_OBJS = \ blbarchive.o \ detection.o \ + entity.o \ graphics.o \ neverhood.o \ + palette.o \ + resource.o \ resourceman.o # This module can be built as a plugin diff --git a/engines/neverhood/neverhood.cpp b/engines/neverhood/neverhood.cpp index fa781fba1e..f7bf0327d4 100644 --- a/engines/neverhood/neverhood.cpp +++ b/engines/neverhood/neverhood.cpp @@ -40,6 +40,7 @@ #include "neverhood/blbarchive.h" #include "neverhood/graphics.h" #include "neverhood/resourceman.h" +#include "neverhood/resource.h" namespace Neverhood { @@ -111,6 +112,17 @@ Common::Error NeverhoodEngine::run() { _res->unuseResource(resourceHandle); #endif +#if 1 + { // Create a new scope + SpriteResource r(this); + BaseSurface *surf = new BaseSurface(this, 0, 640, 480); + r.load(0x0CA04202); + debug("r: width = %d; height = %d", r.dimensions().width, r.dimensions().height); + surf->drawSpriteResource(r); + delete surf; + } +#endif + delete _res; return Common::kNoError; diff --git a/engines/neverhood/palette.cpp b/engines/neverhood/palette.cpp new file mode 100644 index 0000000000..385cadeef8 --- /dev/null +++ b/engines/neverhood/palette.cpp @@ -0,0 +1,44 @@ +/* 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/palette.h" +#include "neverhood/resource.h" + +namespace Neverhood { + +Palette::Palette(NeverhoodEngine *vm) : Entity(vm, 0) { + _status = 0; + _palette = new byte[1024]; + memset(_palette, 0, 1024); + SetUpdateHandler(&Palette::update); +} + +Palette::~Palette() { + // TODO: _vm->_screen->unsetPaletteData(_palette); + delete[] _palette; +} + +void Palette::update() { + // TODO +} + +} // End of namespace Neverhood diff --git a/engines/neverhood/palette.h b/engines/neverhood/palette.h new file mode 100644 index 0000000000..961b4ac909 --- /dev/null +++ b/engines/neverhood/palette.h @@ -0,0 +1,44 @@ +/* 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. + * + */ + +#ifndef NEVERHOOD_PALETTE_H +#define NEVERHOOD_PALETTE_H + +#include "neverhood/neverhood.h" +#include "neverhood/entity.h" + +namespace Neverhood { + +class Palette : public Entity { +public: + // Default constructor with black palette + Palette(NeverhoodEngine *vm); + ~Palette(); +protected: + int _status; + byte *_palette; + void update(); +}; + +} // End of namespace Neverhood + +#endif /* NEVERHOOD_PALETTE_H */ diff --git a/engines/neverhood/resource.cpp b/engines/neverhood/resource.cpp new file mode 100644 index 0000000000..6c77c48fb7 --- /dev/null +++ b/engines/neverhood/resource.cpp @@ -0,0 +1,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::getPalette(byte *palette) { + if (_palette) { + memcpy(palette, _palette, 1024); + } else { + // TODO?: buildDefaultPalette(palette); + } +} + +} // End of namespace Neverhood diff --git a/engines/neverhood/resource.h b/engines/neverhood/resource.h new file mode 100644 index 0000000000..7f61af660a --- /dev/null +++ b/engines/neverhood/resource.h @@ -0,0 +1,64 @@ +/* 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. + * + */ + +#ifndef NEVERHOOD_RESOURCE_H +#define NEVERHOOD_RESOURCE_H + +#include "neverhood/neverhood.h" +#include "neverhood/graphics.h" + +namespace Neverhood { + +class SpriteResource { +public: + SpriteResource(NeverhoodEngine *vm); + ~SpriteResource(); + void draw(byte *dest, int destPitch, bool flipX, bool flipY); + bool load(uint32 fileHash); + bool load2(uint32 fileHash); + void unload(); + const NDimensions& dimensions() { return _dimensions; }; +protected: + NeverhoodEngine *_vm; + int _resourceHandle; + NDimensions _dimensions; + NUnknown _unknown; + byte *_pixels; + bool _rle; +}; + +class PaletteResource { +public: + PaletteResource(NeverhoodEngine *vm); + ~PaletteResource(); + bool load(uint32 fileHash); + void unload(); + void getPalette(byte *palette); +protected: + NeverhoodEngine *_vm; + int _resourceHandle; + byte *_palette; +}; + +} // End of namespace Neverhood + +#endif /* NEVERHOOD_RESOURCE_H */ |