From 6565c95279cbea8c2f94fc3d5d05adb675e7f327 Mon Sep 17 00:00:00 2001 From: lukaslw Date: Fri, 2 May 2014 22:31:18 +0200 Subject: PRINCE: makeShadowTable(), shadowMinus, begin of showHeroShadow() --- engines/prince/graphics.cpp | 18 ++++++++++++++++++ engines/prince/graphics.h | 4 ++++ engines/prince/hero.cpp | 38 +++++++++++++++++++++++++++++++++++--- engines/prince/hero.h | 5 ++++- engines/prince/hero_set.h | 1 + engines/prince/prince.cpp | 5 ++++- engines/prince/prince.h | 1 + 7 files changed, 67 insertions(+), 5 deletions(-) (limited to 'engines/prince') diff --git a/engines/prince/graphics.cpp b/engines/prince/graphics.cpp index 3f9517a6e9..c4e994fe7e 100644 --- a/engines/prince/graphics.cpp +++ b/engines/prince/graphics.cpp @@ -26,6 +26,8 @@ #include "graphics/palette.h" +#include "common/memstream.h" + namespace Prince { GraphicsMan::GraphicsMan(PrinceEngine *vm) @@ -33,11 +35,15 @@ GraphicsMan::GraphicsMan(PrinceEngine *vm) initGraphics(640, 480, true); _frontScreen = new Graphics::Surface(); _frontScreen->create(640, 480, Graphics::PixelFormat::createFormatCLUT8()); + _shadowTable70 = new byte[256 * 3]; + _shadowTable50 = new byte[256 * 3]; } GraphicsMan::~GraphicsMan() { _frontScreen->free(); delete _frontScreen; + delete[] _shadowTable70; + delete[] _shadowTable50; } void GraphicsMan::update() { @@ -82,6 +88,18 @@ void GraphicsMan::drawTransparent(uint16 posX, uint16 posY, const Graphics::Surf change(); } +void GraphicsMan::makeShadowTable(int brightness, byte *shadowPallete) { + int shadow = brightness * 256 / 100; + byte *orginalPallete = new byte[256 * 3]; + _vm->_system->getPaletteManager()->grabPalette(orginalPallete, 0, 256); + Common::MemoryReadStream readS(orginalPallete, 256 * 3); + Common::MemoryWriteStream writeS(shadowPallete, 256 * 3); + for(int i = 0; i < 256 * 3; i++) { + writeS.writeByte(readS.readByte() * shadow / 256); + } + delete[] orginalPallete; +} + } /* vim: set tabstop=4 noexpandtab: */ diff --git a/engines/prince/graphics.h b/engines/prince/graphics.h index 1766e2a04e..62dd89c9ee 100644 --- a/engines/prince/graphics.h +++ b/engines/prince/graphics.h @@ -41,6 +41,7 @@ public: void change(); void setPalette(const byte *palette); + void makeShadowTable(int brightness, byte *shadowTable); void draw(uint16 x, uint16 y, const Graphics::Surface *s); void drawTransparent(uint16 x, uint16 y, const Graphics::Surface *s); @@ -49,6 +50,9 @@ public: Graphics::Surface *_backScreen; const Graphics::Surface *_roomBackground; + byte *_shadowTable70; + byte *_shadowTable50; + private: PrinceEngine *_vm; diff --git a/engines/prince/hero.cpp b/engines/prince/hero.cpp index b4c1f8304b..251f31f7c1 100644 --- a/engines/prince/hero.cpp +++ b/engines/prince/hero.cpp @@ -31,7 +31,7 @@ namespace Prince { Hero::Hero() : _number(0), _visible(false), _state(MOVE), _middleX(0), _middleY(0) - , _boreNum(1), _currHeight(0), _moveDelay(0), _shadMinus(1), _moveSetType(0) + , _boreNum(1), _currHeight(0), _moveDelay(0), _shadMinus(0), _moveSetType(0) , _lastDirection(DOWN), _destDirection(DOWN), _talkTime(0), _boredomTime(0), _phase(0) , _specAnim(0), _drawX(0), _drawY(0), _randomSource("prince"), _zoomFactor(0), _scaleValue(0) , _shadZoomFactor(0), _shadScaleValue(0) @@ -49,6 +49,8 @@ bool Hero::loadAnimSet(uint32 animSetNr) { return false; } + _shadMinus = heroSetBack[animSetNr]; + for (uint32 i = 0; i < _moveSet.size(); ++i) { delete _moveSet[i]; } @@ -188,7 +190,7 @@ Graphics::Surface *Hero::zoomSprite(Graphics::Surface *heroFrame) { } } // loop_lin: - for (int i = 0; i < scaledXSize; i++) { + for (int j = 0; j < scaledXSize; j++) { sprZoomX -= 100; if (sprZoomX >= 0) { // its_all_r @@ -196,7 +198,7 @@ Graphics::Surface *Hero::zoomSprite(Graphics::Surface *heroFrame) { xDest++; } else { sprZoomX += _scaleValue; - i--; + j--; } xSource++; } @@ -246,6 +248,35 @@ void Hero::countDrawPosition() { } } +Graphics::Surface *Hero::showHeroShadow(Graphics::Surface *heroFrame) { + int16 frameXSize = _moveSet[_moveSetType]->getFrameWidth(_phase); + int16 frameYSize = _moveSet[_moveSetType]->getFrameHeight(_phase); + + Graphics::Surface *makeShadow = new Graphics::Surface(); + makeShadow->create(frameXSize, frameYSize, Graphics::PixelFormat::createFormatCLUT8()); + + //make_shadow: + for (int y = 0; y < frameYSize; y++) { + //ms_loop: + for (int x = 0; x < frameXSize; x++) { + byte pixel = *(byte*) makeShadow->getBasePtr(x, y); + if (pixel == -1) { + *(byte*)(makeShadow->getBasePtr(x, y)) = kShadowColor; + } else { + memcpy(makeShadow->getBasePtr(x, y), heroFrame->getBasePtr(x, y), 1); + //*(byte*)(makeShadow->getBasePtr(x, y)) = pixel; + } + } + } + return makeShadow; + // TODO + /* + int scaledX = getScaledValue(frameXSize); + int drawX = _middleX - scaledX / 2; // just _drawX + int DN_ECX5070 = _middleY - _shadMinus; + */ +} + void Hero::showHeroAnimFrame() { if (_phase < _moveSet[_moveSetType]->getFrameCount() - 1) { _phase++; @@ -253,6 +284,7 @@ void Hero::showHeroAnimFrame() { _phase = 0; } countDrawPosition(); + //showHeroShadow(); //debug("_drawX: %d", _drawX); //debug("_drawY: %d", _drawY); //debug("_middleX: %d", _middleX); diff --git a/engines/prince/hero.h b/engines/prince/hero.h index 36856ea921..211eed8a3a 100644 --- a/engines/prince/hero.h +++ b/engines/prince/hero.h @@ -39,6 +39,8 @@ public: static const int16 kMaxPicWidth = 1280; static const int16 kZoomBitmapWidth = kMaxPicWidth / kZoomStep; + static const uint8 kShadowColor = 191; + enum State { STAY = 0, TURN = 1, @@ -108,6 +110,7 @@ public: void checkNak(); Graphics::Surface *zoomSprite(Graphics::Surface *heroFrame); void showHeroAnimFrame(); + Graphics::Surface *showHeroShadow(Graphics::Surface *heroFrame); void setShadowScale(int32 shadowScale); void specialAnim(); void getState(); @@ -160,7 +163,7 @@ public: Animation *_shadowBitmap; uint32 _moveDelay; - uint32 _shadMinus; //?? + uint32 _shadMinus; }; } diff --git a/engines/prince/hero_set.h b/engines/prince/hero_set.h index 335f70a6ab..e0c7887b94 100644 --- a/engines/prince/hero_set.h +++ b/engines/prince/hero_set.h @@ -24,6 +24,7 @@ namespace Prince { typedef const char *HeroSetAnimNames[26]; +const int heroSetBack[7] = { 0, 0, 10, 0, 6, 0, 0 }; extern const HeroSetAnimNames *heroSetTable[7]; } diff --git a/engines/prince/prince.cpp b/engines/prince/prince.cpp index 7bb51411f1..1402581b0d 100644 --- a/engines/prince/prince.cpp +++ b/engines/prince/prince.cpp @@ -290,9 +290,9 @@ bool PrinceEngine::loadLocation(uint16 locationNr) { _mainHero->_lightX = _script->getLightX(_locationNr); _mainHero->_lightY = _script->getLightY(_locationNr); + _mainHero->setShadowScale(_script->getShadowScale(_locationNr)); debug("lightX: %d", _mainHero->_lightX); debug("lightY: %d", _mainHero->_lightY); - _mainHero->setShadowScale(_script->getShadowScale(_locationNr)); _mobList.clear(); Resource::loadResource(_mobList, "mob.lst", false); @@ -306,6 +306,9 @@ bool PrinceEngine::loadLocation(uint16 locationNr) { _animList.clear(); Resource::loadResource(_animList, "anim.lst", false); + _graph->makeShadowTable(70, _graph->_shadowTable70); + _graph->makeShadowTable(50, _graph->_shadowTable50); + return true; } diff --git a/engines/prince/prince.h b/engines/prince/prince.h index a48f056d4d..487a197177 100644 --- a/engines/prince/prince.h +++ b/engines/prince/prince.h @@ -150,6 +150,7 @@ private: void showTexts(); void init(); void showLogo(); + void makeShadowTable(int brightness); uint32 getTextWidth(const char *s); void debugEngine(const char *s, ...); -- cgit v1.2.3