diff options
-rw-r--r-- | engines/neverhood/graphics.cpp | 6 | ||||
-rw-r--r-- | engines/neverhood/module1500.cpp | 20 | ||||
-rw-r--r-- | engines/neverhood/neverhood.cpp | 8 | ||||
-rw-r--r-- | engines/neverhood/palette.cpp | 82 | ||||
-rw-r--r-- | engines/neverhood/palette.h | 13 | ||||
-rw-r--r-- | engines/neverhood/screen.cpp | 73 | ||||
-rw-r--r-- | engines/neverhood/screen.h | 3 |
7 files changed, 182 insertions, 23 deletions
diff --git a/engines/neverhood/graphics.cpp b/engines/neverhood/graphics.cpp index 2a86966cf5..fa7c15211a 100644 --- a/engines/neverhood/graphics.cpp +++ b/engines/neverhood/graphics.cpp @@ -22,6 +22,7 @@ #include "neverhood/graphics.h" #include "neverhood/resource.h" +#include "neverhood/screen.h" namespace Neverhood { @@ -51,7 +52,10 @@ BaseSurface::~BaseSurface() { void BaseSurface::draw() { debug("BaseSurface::draw()"); - // TODO + if (_surface && _visible && _drawRect.width > 0 && _drawRect.height > 0) { + // TODO: _sysRect alternate drawing code (is that used?) + _vm->_screen->drawSurface2(_surface, _drawRect, _clipRect); + } } void BaseSurface::addDirtyRect() { diff --git a/engines/neverhood/module1500.cpp b/engines/neverhood/module1500.cpp index 8c4cb9c021..c3c0864a59 100644 --- a/engines/neverhood/module1500.cpp +++ b/engines/neverhood/module1500.cpp @@ -110,6 +110,8 @@ Scene1501::Scene1501(NeverhoodEngine *vm, Module *parentModule, uint32 backgroun _countdown3(countdown3), _countdown2(countdown2), _countdown1(0), _flag(false) { debug("Create Scene1501(%08X, %08X, %d, %d)", backgroundFileHash, soundFileHash, countdown2, countdown3); + + Palette2 *palette2; SetUpdateHandler(&Scene1501::update); SetMessageHandler(&Scene1501::handleMessage); @@ -118,16 +120,14 @@ Scene1501::Scene1501(NeverhoodEngine *vm, Module *parentModule, uint32 backgroun _background = addBackground(new DirtyBackground(_vm, backgroundFileHash, 0, 0)); - _palette = new Palette(_vm);//DUMMY! - - /* TODO - - _palette = new Palette2(_vm); - _palette->usePalette(); + palette2 = new Palette2(_vm); + palette2->usePalette(); + _palette = palette2; addEntity(_palette); - Palette2_sub_47BF00(backgroundFileHash, 0, 256, 0); - Palette2_sub_47C060(12); - + palette2->addPalette(backgroundFileHash, 0, 256, 0); + palette2->startFadeToPalette(12); + + /* if (soundFileHash != 0) { _soundResource.set(soundFileHash); _soundResource.load(); @@ -150,7 +150,7 @@ void Scene1501::update() { _vm->_screen->clear(); _parentModule->sendMessage(0x1009, 0, this); } - } else if ((_countdown2 != 0 && (--_countdown2 == 0)) || !_soundResource.isPlaying()) { + } else if ((_countdown2 != 0 && (--_countdown2 == 0)) /*|| !_soundResource.isPlaying()*/) { _countdown1 = 12; _palette->startFadeToBlack(11); } diff --git a/engines/neverhood/neverhood.cpp b/engines/neverhood/neverhood.cpp index 207bd382cf..9019409193 100644 --- a/engines/neverhood/neverhood.cpp +++ b/engines/neverhood/neverhood.cpp @@ -164,10 +164,14 @@ Common::Error NeverhoodEngine::run() { break; } } - + + debug("millis %d", _system->getMillis()); _gameModule->handleUpdate(); _gameModule->draw(); - _system->updateScreen(); + _screen->wait(); + _screen->update(); + + debug("---------------------------------------"); } diff --git a/engines/neverhood/palette.cpp b/engines/neverhood/palette.cpp index b45f8eeb78..bfabf8998a 100644 --- a/engines/neverhood/palette.cpp +++ b/engines/neverhood/palette.cpp @@ -22,9 +22,12 @@ #include "neverhood/palette.h" #include "neverhood/resource.h" +#include "neverhood/screen.h" namespace Neverhood { +// Palette + Palette::Palette(NeverhoodEngine *vm) : Entity(vm, 0) { _status = 0; _palette = new byte[1024]; @@ -58,12 +61,12 @@ Palette::Palette(NeverhoodEngine *vm, uint32 fileHash) : Entity(vm, 0) { } Palette::~Palette() { - // TODO: _vm->_screen->unsetPaletteData(_palette); + _vm->_screen->unsetPaletteData(_palette); delete[] _palette; } void Palette::usePalette() { - // TODO: _vm->_screen->setPaletteData(_palette); + _vm->_screen->setPaletteData(_palette); } void Palette::addPalette(const char *filename, int toIndex, int count, int fromIndex) { @@ -76,10 +79,11 @@ void Palette::addPalette(uint32 fileHash, int toIndex, int count, int fromIndex) count = 256 - toIndex; paletteResource.load(fileHash); memcpy(_palette + toIndex * 4, paletteResource.palette() + fromIndex * 4, count * 4); - // TODO: _vm->_screen->testPalette(_palette); + _vm->_screen->testPalette(_palette); } void Palette::startFadeToBlack(int counter) { + debug("Palette::startFadeToBlack(%d)", counter); if (counter == 0) counter = 1; _fadeToR = 0; @@ -91,6 +95,7 @@ void Palette::startFadeToBlack(int counter) { } void Palette::startFadeToWhite(int counter) { + debug("Palette::startFadeToWhite(%d)", counter); if (counter == 0) counter = 1; _fadeToR = 255; @@ -102,15 +107,18 @@ void Palette::startFadeToWhite(int counter) { } void Palette::update() { + debug("Palette::update() _status = %d", _status); if (_status == 1) { - memset(_palette, 0, 1024); - _status = 0; - } else { - for (int i = 0; i < 256; i++) { - fadeColor(_palette + i * 4, _fadeToR, _fadeToG, _fadeToB); + if (_palCounter > 1) { + for (int i = 0; i < 256; i++) { + fadeColor(_palette + i * 4, _fadeToR, _fadeToG, _fadeToB); + } + _vm->_screen->testPalette(_palette); + _palCounter--; + } else { + memset(_palette, 0, 1024); + _status = 0; } - // TODO: _vm->_screen->testPalette(_palette); - _palCounter--; } } @@ -122,4 +130,58 @@ void Palette::fadeColor(byte *rgb, byte toR, byte toG, byte toB) { #undef FADE } +// Palette2 + +Palette2::Palette2(NeverhoodEngine *vm) + : Palette(vm) { + _basePalette = new byte[1024]; + SetUpdateHandler(&Palette2::update); +} + +Palette2::Palette2(NeverhoodEngine *vm, uint32 fileHash) + : Palette(vm, fileHash) { + _basePalette = new byte[1024]; + SetUpdateHandler(&Palette2::update); +} + +Palette2::~Palette2() { + delete _basePalette; +} + +void Palette2::update() { + debug("Palette2::update() _status = %d", _status); + if (_status == 1) { + Palette::update(); + } else if (_status == 2) { + debug("... _palCounter = %d", _palCounter); + if (_palCounter > 1) { + for (int i = 0; i < 256; i++) { + fadeColor(_palette + i * 4, _basePalette[i * 4 + 0], _basePalette[i * 4 + 1], _basePalette[i * 4 + 2]); + } + _vm->_screen->testPalette(_palette); + _palCounter--; + } else { + memcpy(_palette, _basePalette, 256 * 4); + _status = 0; + } + } +} + +void Palette2::addPalette(uint32 fileHash, int toIndex, int count, int fromIndex) { + PaletteResource paletteResource(_vm); + if (toIndex + count > 256) + count = 256 - toIndex; + paletteResource.load(fileHash); + memcpy(_basePalette + toIndex * 4, paletteResource.palette() + fromIndex * 4, count * 4); +} + +void Palette2::startFadeToPalette(int counter) { + debug("Palette2::startFadeToPalette(%d)", counter); + if (counter == 0) + counter = 1; + _palCounter = counter; + _fadeStep = 255 / counter; + _status = 2; +} + } // End of namespace Neverhood diff --git a/engines/neverhood/palette.h b/engines/neverhood/palette.h index b29d77181b..752ae3aedb 100644 --- a/engines/neverhood/palette.h +++ b/engines/neverhood/palette.h @@ -54,6 +54,19 @@ protected: void fadeColor(byte *rgb, byte toR, byte toG, byte toB); }; +class Palette2 : public Palette { +public: + Palette2(NeverhoodEngine *vm); + // TODO: Other ctors + Palette2(NeverhoodEngine *vm, uint32 fileHash); + ~Palette2(); + void addPalette(uint32 fileHash, int toIndex, int count, int fromIndex); + void startFadeToPalette(int counter); +public: + byte *_basePalette; + void update(); +}; + } // End of namespace Neverhood #endif /* NEVERHOOD_PALETTE_H */ diff --git a/engines/neverhood/screen.cpp b/engines/neverhood/screen.cpp index 4b531ca139..807e241ccd 100644 --- a/engines/neverhood/screen.cpp +++ b/engines/neverhood/screen.cpp @@ -39,7 +39,16 @@ Screen::~Screen() { delete _backScreen; } +void Screen::update() { + updatePalette(); + // TODO: Implement actual code + _vm->_system->copyRectToScreen((const byte*)_backScreen->pixels, _backScreen->pitch, 0, 0, 640, 480); + _vm->_system->updateScreen(); +} + void Screen::wait() { + // TODO + _vm->_system->delayMillis(40); } void Screen::setFps(int fps) { @@ -69,6 +78,7 @@ void Screen::testPalette(byte *paletteData) { void Screen::updatePalette() { if (_paletteChanged && _paletteData) { + debug("Screen::updatePalette() Set palette"); byte *tempPalette = new byte[768]; for (int i = 0; i < 256; i++) { tempPalette[i * 3 + 0] = _paletteData[i * 4 + 0]; @@ -85,4 +95,67 @@ void Screen::clear() { memset(_backScreen->pixels, 0, _backScreen->pitch * _backScreen->h); } +void Screen::drawSurface2(Graphics::Surface *surface, NDrawRect &drawRect, NRect &clipRect) { + + int16 destX, destY; + NRect ddRect; + + if (drawRect.x + drawRect.width >= clipRect.x2) + ddRect.x2 = clipRect.x2 - drawRect.x; + else + ddRect.x2 = drawRect.width; + + if (drawRect.x <= clipRect.x1) { + destX = clipRect.x1; + ddRect.x1 = clipRect.x1 - drawRect.x; + } else { + destX = drawRect.x; + ddRect.x1 = 0; + } + + if (drawRect.y + drawRect.height >= clipRect.y2) + ddRect.y2 = clipRect.y2 - drawRect.y; + else + ddRect.y2 = drawRect.height; + + if (drawRect.y <= clipRect.y1) { + destY = clipRect.y1; + ddRect.y1 = clipRect.y1 - drawRect.y; + } else { + destY = drawRect.y; + ddRect.y1 = 0; + } + + debug("draw: x = %d; y = %d; (%d, %d, %d, %d)", destX, destY, ddRect.x1, ddRect.y1, ddRect.x2, ddRect.y2); + + byte *source = (byte*)surface->getBasePtr(ddRect.x1, ddRect.y1); + 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 0 + if ( ddRect.right > ddRect.left ) + { + if ( ddRect.top < ddRect.bottom ) + { + (*(int (__stdcall **)(_DWORD, _DWORD, _DWORD, LPDIRECTDRAWSURFACE, struct tagRECT *, unsigned int))(**(_DWORD **)(this + 8) + 28))( + *(_DWORD *)(this + 8), + destX, + destY, + ddSurface, + &ddRect, + blitFlags | (unsigned int)DDBLTFAST_WAIT); + } + } + #endif + +} + + } // End of namespace Neverhood diff --git a/engines/neverhood/screen.h b/engines/neverhood/screen.h index 0e7ce3d7d6..e25b3b5dba 100644 --- a/engines/neverhood/screen.h +++ b/engines/neverhood/screen.h @@ -25,6 +25,7 @@ #include "graphics/surface.h" #include "neverhood/neverhood.h" +#include "neverhood/graphics.h" namespace Neverhood { @@ -32,6 +33,7 @@ class Screen { public: Screen(NeverhoodEngine *vm); ~Screen(); + void update(); void wait(); void setFps(int fps); int getFps(); @@ -40,6 +42,7 @@ public: void testPalette(byte *paletteData); void updatePalette(); void clear(); + void drawSurface2(Graphics::Surface *surface, NDrawRect &drawRect, NRect &clipRect); protected: NeverhoodEngine *_vm; Graphics::Surface *_backScreen; |