diff options
author | johndoe123 | 2011-07-06 11:01:21 +0000 |
---|---|---|
committer | Willem Jan Palenstijn | 2013-05-08 20:30:58 +0200 |
commit | e6236a39781360d2d41f5818b903d215015a1829 (patch) | |
tree | 16428efd7c7959be450879f0125ffd4ef994433c /engines/neverhood | |
parent | 97f319c945baee44947d6013de2998651b79046f (diff) | |
download | scummvm-rg350-e6236a39781360d2d41f5818b903d215015a1829.tar.gz scummvm-rg350-e6236a39781360d2d41f5818b903d215015a1829.tar.bz2 scummvm-rg350-e6236a39781360d2d41f5818b903d215015a1829.zip |
NEVERHOOD: Add transparency and x flipping to sprite drawing (flip y still TODO but rarely used)
- Add Class511 (the lever) to Module1000
Diffstat (limited to 'engines/neverhood')
-rw-r--r-- | engines/neverhood/background.cpp | 2 | ||||
-rw-r--r-- | engines/neverhood/graphics.cpp | 35 | ||||
-rw-r--r-- | engines/neverhood/graphics.h | 2 | ||||
-rw-r--r-- | engines/neverhood/module1000.cpp | 54 | ||||
-rw-r--r-- | engines/neverhood/module1000.h | 9 | ||||
-rw-r--r-- | engines/neverhood/screen.cpp | 24 | ||||
-rw-r--r-- | engines/neverhood/screen.h | 2 | ||||
-rw-r--r-- | engines/neverhood/smackerplayer.cpp | 2 |
8 files changed, 109 insertions, 21 deletions
diff --git a/engines/neverhood/background.cpp b/engines/neverhood/background.cpp index abfa50733d..c47acd15a9 100644 --- a/engines/neverhood/background.cpp +++ b/engines/neverhood/background.cpp @@ -46,6 +46,7 @@ Background::~Background() { void Background::createSurface(int surfacePriority, int16 width, int16 height) { _surface = new BaseSurface(_vm, surfacePriority, width, height); + _surface->setTransparent(false); _spriteResource.getPosition().x = width; _spriteResource.getPosition().y = height; } @@ -80,6 +81,7 @@ void DirtyBackground::createSurface(int surfacePriority, int16 width, int16 heig // TODO: Later use a DirtySurface once it is implemented _surface = new BaseSurface(_vm, surfacePriority, width, height); + _surface->setTransparent(false); _spriteResource.getPosition().x = width; _spriteResource.getPosition().y = height; diff --git a/engines/neverhood/graphics.cpp b/engines/neverhood/graphics.cpp index b6d883c168..f6ae118fa6 100644 --- a/engines/neverhood/graphics.cpp +++ b/engines/neverhood/graphics.cpp @@ -27,7 +27,7 @@ namespace Neverhood { BaseSurface::BaseSurface(NeverhoodEngine *vm, int priority, int16 width, int16 height) - : _vm(vm), _priority(priority), _visible(true) { + : _vm(vm), _priority(priority), _visible(true), _transparent(true) { _drawRect.x = 0; _drawRect.y = 0; @@ -54,7 +54,7 @@ void BaseSurface::draw() { debug(8, "BaseSurface::draw()"); if (_surface && _visible && _drawRect.width > 0 && _drawRect.height > 0) { // TODO: _sysRect alternate drawing code (is that used?) - _vm->_screen->drawSurface2(_surface, _drawRect, _clipRect); + _vm->_screen->drawSurface2(_surface, _drawRect, _clipRect, _transparent); } } @@ -152,7 +152,7 @@ void parseBitmapResource(byte *sprite, bool *rle, NDimensions *dimensions, NPoin void unpackSpriteRle(byte *source, int width, int height, byte *dest, int destPitch, bool flipX, bool flipY) { - // TODO: Flip + // TODO: Flip Y int16 rows, chunks; int16 skip, copy; @@ -171,7 +171,14 @@ void unpackSpriteRle(byte *source, int width, int height, byte *dest, int destPi skip = READ_LE_UINT16(source); copy = READ_LE_UINT16(source + 2); source += 4; - memcpy(dest + skip, source, copy); + if (!flipX) + memcpy(dest + skip, source, copy); + else { + byte *flipDest = dest + width - skip - 1; + for (int xc = 0; xc < copy; xc++) { + *flipDest-- = source[xc]; + } + } source += copy; } dest += destPitch; @@ -186,14 +193,24 @@ 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 + // TODO: Flip Y int sourcePitch = (width + 3) & 0xFFFC; - while (height-- > 0) { - memcpy(dest, source, width); - source += sourcePitch; - dest += destPitch; + if (!flipX) { + while (height-- > 0) { + memcpy(dest, source, width); + source += sourcePitch; + dest += destPitch; + } + } else { + while (height-- > 0) { + dest += width - 1; + for (int xc = 0; xc < width; xc++) + *dest-- = source[xc]; + source += sourcePitch; + dest += destPitch; + } } } diff --git a/engines/neverhood/graphics.h b/engines/neverhood/graphics.h index bf8333c1f5..59db1e5ee5 100644 --- a/engines/neverhood/graphics.h +++ b/engines/neverhood/graphics.h @@ -73,6 +73,7 @@ public: void setClipRect(NRect clipRect) { _clipRect = clipRect; } bool getVisible() const { return _visible; } void setVisible(bool value) { _visible = value; } + void setTransparent(bool value) { _transparent = value; } protected: NeverhoodEngine *_vm; int _priority; @@ -81,6 +82,7 @@ protected: NDrawRect _drawRect; NDrawRect _sysRect; NRect _clipRect; + bool _transparent; }; // Misc diff --git a/engines/neverhood/module1000.cpp b/engines/neverhood/module1000.cpp index 162618ec0b..c3aa0c9ccd 100644 --- a/engines/neverhood/module1000.cpp +++ b/engines/neverhood/module1000.cpp @@ -240,7 +240,55 @@ void Class509::callback3() { setFileHash1(); _surface->setVisible(false); } - + +Class511::Class511(NeverhoodEngine *vm, Scene *parentScene, int16 x, int16 y, int deltaXType) + : AnimatedSprite(vm, 1100), _soundResource(vm), _parentScene(parentScene) { + + createSurface(1010, 71, 73); + setDoDeltaX(deltaXType); + setFileHash(0x04A98C36, 0, -1); + _newHashListIndex = 0; + _x = x; + _y = y; + SetUpdateHandler(&AnimatedSprite::update); + SetMessageHandler(&Class511::handleMessage); +} + +uint32 Class511::handleMessage(int messageNum, const MessageParam ¶m, Entity *sender) { + uint32 messageResult = Sprite::handleMessage(messageNum, param, sender); + switch (messageNum) { + case 0x100D: + if (param._integer == 0x00C0C444) { + _parentScene->sendMessage(0x480F, 0, this); + } else if (param._integer == 0xC41A02C0) { +#if 0 + _soundResource.set(0x40581882); + _soundResource.load(); + _soundResource.play(false); +#endif + } + break; + case 0x1011: + _parentScene->sendMessage(0x4826, 0, this); + messageResult = 1; + break; + case 0x3002: + setFileHash(0x04A98C36, 0, -1); + _newHashListIndex = 0; + break; + case 0x480F: + setFileHash(0x04A98C36, 0, -1); + break; + case 0x482A: + _parentScene->sendMessage(0x1022, 0x3DE, this); + break; + case 0x482B: + _parentScene->sendMessage(0x1022, 0x3F2, this); + break; + } + return messageResult; +} + Scene1001::Scene1001(NeverhoodEngine *vm, Module *parentModule, int which) : Scene(vm, parentModule, true), _fieldE4(-1), _fieldE6(-1) { @@ -307,9 +355,7 @@ Scene1001::Scene1001(NeverhoodEngine *vm, Module *parentModule, int which) _class509 = NULL; } -#if 0 _class511 = addSprite(new Class511(_vm, this, 150, 433, 1)); -#endif addSprite(new StaticSprite(_vm, 0x809861A6, 950)); addSprite(new StaticSprite(_vm, 0x89C03848, 1100)); @@ -335,6 +381,8 @@ Scene1001::Scene1001(NeverhoodEngine *vm, Module *parentModule, int which) _class508 = addSprite(new Class508(_vm, _class509)); #endif + _class511->sendMessage(0x480F, 0, this); + } uint32 Scene1001::handleMessage(int messageNum, const MessageParam ¶m, Entity *sender) { diff --git a/engines/neverhood/module1000.h b/engines/neverhood/module1000.h index 4e7b2922a3..219448a2bf 100644 --- a/engines/neverhood/module1000.h +++ b/engines/neverhood/module1000.h @@ -68,6 +68,15 @@ protected: void callback3(); }; +class Class511 : public AnimatedSprite { +public: + Class511(NeverhoodEngine *vm, Scene *parentScene, int16 x, int16 y, int deltaXType); +protected: + Scene *_parentScene; + SoundResource _soundResource; + uint32 handleMessage(int messageNum, const MessageParam ¶m, Entity *sender); +}; + class Scene1001 : public Scene { public: Scene1001(NeverhoodEngine *vm, Module *parentModule, int which); diff --git a/engines/neverhood/screen.cpp b/engines/neverhood/screen.cpp index 77e8c02693..db1c16a1ce 100644 --- a/engines/neverhood/screen.cpp +++ b/engines/neverhood/screen.cpp @@ -94,7 +94,7 @@ void Screen::clear() { memset(_backScreen->pixels, 0, _backScreen->pitch * _backScreen->h); } -void Screen::drawSurface2(const Graphics::Surface *surface, NDrawRect &drawRect, NRect &clipRect) { +void Screen::drawSurface2(const Graphics::Surface *surface, NDrawRect &drawRect, NRect &clipRect, bool transparent) { int16 destX, destY; NRect ddRect; @@ -131,12 +131,22 @@ void Screen::drawSurface2(const Graphics::Surface *surface, NDrawRect &drawRect, byte *dest = (byte*)_backScreen->getBasePtr(destX, destY); int width = ddRect.x2 - ddRect.x1; int height = ddRect.y2 - ddRect.y1; - - while (height--) { - memcpy(dest, source, width); - source += surface->pitch; - dest += _backScreen->pitch; - } + + if (!transparent) { + while (height--) { + memcpy(dest, source, width); + source += surface->pitch; + dest += _backScreen->pitch; + } + } else { + while (height--) { + for (int xc = 0; xc < width; xc++) + if (source[xc] != 0) + dest[xc] = source[xc]; + source += surface->pitch; + dest += _backScreen->pitch; + } + } #if 0 if ( ddRect.right > ddRect.left ) diff --git a/engines/neverhood/screen.h b/engines/neverhood/screen.h index fc56a18ea6..922ad481f3 100644 --- a/engines/neverhood/screen.h +++ b/engines/neverhood/screen.h @@ -42,7 +42,7 @@ public: void testPalette(byte *paletteData); void updatePalette(); void clear(); - void drawSurface2(const Graphics::Surface *surface, NDrawRect &drawRect, NRect &clipRect); + void drawSurface2(const Graphics::Surface *surface, NDrawRect &drawRect, NRect &clipRect, bool transparent); void drawDoubleSurface2(const Graphics::Surface *surface, NDrawRect &drawRect); protected: NeverhoodEngine *_vm; diff --git a/engines/neverhood/smackerplayer.cpp b/engines/neverhood/smackerplayer.cpp index c914b42482..bbb0db144c 100644 --- a/engines/neverhood/smackerplayer.cpp +++ b/engines/neverhood/smackerplayer.cpp @@ -35,7 +35,7 @@ SmackerSurface::SmackerSurface(NeverhoodEngine *vm) void SmackerSurface::draw() { if (_smackerFrame && _visible && _drawRect.width > 0 && _drawRect.height > 0) { - _vm->_screen->drawSurface2(_smackerFrame, _drawRect, _clipRect); + _vm->_screen->drawSurface2(_smackerFrame, _drawRect, _clipRect, false); } } |