diff options
author | johndoe123 | 2013-01-17 09:50:10 +0000 |
---|---|---|
committer | Willem Jan Palenstijn | 2013-05-08 20:47:40 +0200 |
commit | f945448c7ba3884cded68314a13aa2132603121d (patch) | |
tree | 01287dcf95c60ab21bc35551a1cb6084f7f0c2bc /engines | |
parent | 57497817e1f086a62471587e3601d8f0f7d7f13b (diff) | |
download | scummvm-rg350-f945448c7ba3884cded68314a13aa2132603121d.tar.gz scummvm-rg350-f945448c7ba3884cded68314a13aa2132603121d.tar.bz2 scummvm-rg350-f945448c7ba3884cded68314a13aa2132603121d.zip |
NEVERHOOD: Change graphic resource draw method to get a Surface instead of separate pixels/pitch
- Merge SpriteResource::load and load2
Diffstat (limited to 'engines')
-rw-r--r-- | engines/neverhood/graphics.cpp | 12 | ||||
-rw-r--r-- | engines/neverhood/menumodule.cpp | 6 | ||||
-rw-r--r-- | engines/neverhood/module2200.cpp | 8 | ||||
-rw-r--r-- | engines/neverhood/resource.cpp | 32 | ||||
-rw-r--r-- | engines/neverhood/resource.h | 9 | ||||
-rw-r--r-- | engines/neverhood/sprite.cpp | 4 |
6 files changed, 33 insertions, 38 deletions
diff --git a/engines/neverhood/graphics.cpp b/engines/neverhood/graphics.cpp index 5426821133..913954532f 100644 --- a/engines/neverhood/graphics.cpp +++ b/engines/neverhood/graphics.cpp @@ -71,7 +71,7 @@ void BaseSurface::drawSpriteResource(SpriteResource &spriteResource) { if (spriteResource.getDimensions().width <= _drawRect.width && spriteResource.getDimensions().height <= _drawRect.height) { clear(); - spriteResource.draw((byte*)_surface->pixels, _surface->pitch, false, false); + spriteResource.draw(_surface, false, false); ++_version; } } @@ -85,7 +85,7 @@ void BaseSurface::drawSpriteResourceEx(SpriteResource &spriteResource, bool flip _drawRect.height = height; if (_surface) { clear(); - spriteResource.draw((byte*)_surface->pixels, _surface->pitch, flipX, flipY); + spriteResource.draw(_surface, flipX, flipY); ++_version; } } @@ -99,7 +99,7 @@ void BaseSurface::drawAnimResource(AnimResource &animResource, uint frameIndex, if (_surface) { clear(); if (frameIndex < animResource.getFrameCount()) { - animResource.draw(frameIndex, (byte*)_surface->pixels, _surface->pitch, flipX, flipY); + animResource.draw(frameIndex, _surface, flipX, flipY); ++_version; } } @@ -107,7 +107,7 @@ void BaseSurface::drawAnimResource(AnimResource &animResource, uint frameIndex, void BaseSurface::drawMouseCursorResource(MouseCursorResource &mouseCursorResource, int frameNum) { if (frameNum < 3) { - mouseCursorResource.draw(frameNum, (byte*)_surface->pixels, _surface->pitch); + mouseCursorResource.draw(frameNum, _surface); ++_version; } } @@ -156,7 +156,7 @@ FontSurface::FontSurface(NeverhoodEngine *vm, uint32 fileHash, uint charsPerRow, _firstChar(firstChar), _charWidth(charWidth), _charHeight(charHeight), _tracking(NULL) { SpriteResource fontSpriteResource(_vm); - fontSpriteResource.load2(fileHash); + fontSpriteResource.load(fileHash, true); drawSpriteResourceEx(fontSpriteResource, false, false, 0, 0); } @@ -200,7 +200,7 @@ FontSurface *FontSurface::createFontSurface(NeverhoodEngine *vm, uint32 fileHash uint16 charWidth = fontData.getPoint(calcHash("meCharWidth")).x; uint16 charHeight = fontData.getPoint(calcHash("meCharHeight")).x; NPointArray *tracking = fontData.getPointArray(calcHash("meTracking")); - fontSprite.load2(fileHash); + fontSprite.load(fileHash, true); fontSurface = new FontSurface(vm, tracking, 16, numRows, firstChar, charWidth, charHeight); fontSurface->drawSpriteResourceEx(fontSprite, false, false, 0, 0); return fontSurface; diff --git a/engines/neverhood/menumodule.cpp b/engines/neverhood/menumodule.cpp index 2b7561c431..71b216b940 100644 --- a/engines/neverhood/menumodule.cpp +++ b/engines/neverhood/menumodule.cpp @@ -540,7 +540,7 @@ void TextEditWidget::onClick() { void TextEditWidget::addSprite() { SpriteResource cursorSpriteResource(_vm); - _spriteResource.load2(_fileHash); + _spriteResource.load(_fileHash, true); createSurface(_baseSurfacePriority, _spriteResource.getDimensions().width, _spriteResource.getDimensions().height); refreshPosition(); _parentScene->addSprite(this); @@ -550,7 +550,7 @@ void TextEditWidget::addSprite() { 0, _parentScene, _baseObjectPriority + 1, _baseSurfacePriority + 1, (const byte*)_entryString.c_str(), _entryString.size(), _surface, _x, _y, _fontSurface); _textLabelWidget->addSprite(); - cursorSpriteResource.load2(_cursorFileHash); + cursorSpriteResource.load(_cursorFileHash, true); _cursorSurface = new BaseSurface(_vm, 0, cursorSpriteResource.getDimensions().width, cursorSpriteResource.getDimensions().height); _cursorSurface->drawSpriteResourceEx(cursorSpriteResource, false, false, cursorSpriteResource.getDimensions().width, cursorSpriteResource.getDimensions().height); _cursorSurface->setVisible(true); @@ -704,7 +704,7 @@ void SavegameListBox::onClick() { } void SavegameListBox::addSprite() { - _spriteResource.load2(_bgFileHash); + _spriteResource.load(_bgFileHash, true); createSurface(_baseSurfacePriority, _spriteResource.getDimensions().width, _spriteResource.getDimensions().height); refreshPosition(); _parentScene->addSprite(this); diff --git a/engines/neverhood/module2200.cpp b/engines/neverhood/module2200.cpp index a53bd468f4..9f5f7fb9ee 100644 --- a/engines/neverhood/module2200.cpp +++ b/engines/neverhood/module2200.cpp @@ -2139,15 +2139,17 @@ Scene2208::Scene2208(NeverhoodEngine *vm, Module *parentModule, int which) _fontSurface = FontSurface::createFontSurface(_vm, 0x0800090C); _backgroundSurface = new BaseSurface(_vm, 0, 640, 480); - spriteResource.load2(0x08100289); + spriteResource.load(0x08100289, true); _backgroundSurface->drawSpriteResourceEx(spriteResource, false, false, 0, 0); _topBackgroundSurface = new BaseSurface(_vm, 0, 640, 192); - spriteResource.load2(!getGlobalVar(V_COLUMN_BACK_NAME) ? kScene2208FileHashes1[getGlobalVar(V_CLICKED_COLUMN_INDEX) % 6] : getGlobalVar(V_COLUMN_BACK_NAME)); + spriteResource.load(!getGlobalVar(V_COLUMN_BACK_NAME) + ? kScene2208FileHashes1[getGlobalVar(V_CLICKED_COLUMN_INDEX) % 6] + : getGlobalVar(V_COLUMN_BACK_NAME), true); _topBackgroundSurface->drawSpriteResourceEx(spriteResource, false, false, 0, 0); _bottomBackgroundSurface = new BaseSurface(_vm, 0, 640, 192); - spriteResource.load2(kScene2208FileHashes2[getGlobalVar(V_CLICKED_COLUMN_INDEX) % 6]); + spriteResource.load(kScene2208FileHashes2[getGlobalVar(V_CLICKED_COLUMN_INDEX) % 6], true); _bottomBackgroundSurface->drawSpriteResourceEx(spriteResource, false, false, 0, 0); SetUpdateHandler(&Scene2208::update); diff --git a/engines/neverhood/resource.cpp b/engines/neverhood/resource.cpp index 6cbbf12a25..3350b80e61 100644 --- a/engines/neverhood/resource.cpp +++ b/engines/neverhood/resource.cpp @@ -37,8 +37,10 @@ SpriteResource::~SpriteResource() { unload(); } -void SpriteResource::draw(byte *dest, int destPitch, bool flipX, bool flipY) { +void SpriteResource::draw(Graphics::Surface *destSurface, bool flipX, bool flipY) { if (_pixels) { + byte *dest = (byte*)destSurface->pixels; + const int destPitch = destSurface->pitch; if (_rle) unpackSpriteRle(_pixels, _dimensions.width, _dimensions.height, dest, destPitch, flipX, flipY); else @@ -46,27 +48,15 @@ void SpriteResource::draw(byte *dest, int destPitch, bool flipX, bool flipY) { } } -bool SpriteResource::load(uint32 fileHash) { +bool SpriteResource::load(uint32 fileHash, bool doLoadPosition) { debug(2, "SpriteResource::load(%08X)", fileHash); - // TODO: Later merge with load2 and make the mode a parameter unload(); _vm->_res->queryResource(fileHash, _resourceHandle); if (_resourceHandle.isValid() && _resourceHandle.type() == kResTypeBitmap) { _vm->_res->loadResource(_resourceHandle); const byte *spriteData = _resourceHandle.data(); - parseBitmapResource(spriteData, &_rle, &_dimensions, NULL, NULL, &_pixels); - } - return _pixels != NULL; -} - -bool SpriteResource::load2(uint32 fileHash) { - debug(2, "SpriteResource::load2(%08X)", fileHash); - unload(); - _vm->_res->queryResource(fileHash, _resourceHandle); - if (_resourceHandle.isValid() && _resourceHandle.type() == kResTypeBitmap) { - _vm->_res->loadResource(_resourceHandle); - const byte *spriteData = _resourceHandle.data(); - parseBitmapResource(spriteData, &_rle, &_dimensions, &_position, NULL, &_pixels); + NPoint *position = doLoadPosition ? &_position : NULL; + parseBitmapResource(spriteData, &_rle, &_dimensions, position, NULL, &_pixels); } return _pixels != NULL; } @@ -128,8 +118,10 @@ AnimResource::~AnimResource() { unload(); } -void AnimResource::draw(uint frameIndex, byte *dest, int destPitch, bool flipX, bool flipY) { +void AnimResource::draw(uint frameIndex, Graphics::Surface *destSurface, bool flipX, bool flipY) { const AnimFrameInfo frameInfo = _frames[frameIndex]; + byte *dest = (byte*)destSurface->pixels; + const int destPitch = destSurface->pitch; _currSpriteData = _spriteData + frameInfo.spriteDataOffs; _width = frameInfo.drawOffset.width; _height = frameInfo.drawOffset.height; @@ -305,10 +297,12 @@ NDrawRect& MouseCursorResource::getRect() { return _rect; } -void MouseCursorResource::draw(int frameNum, byte *dest, int destPitch) { +void MouseCursorResource::draw(int frameNum, Graphics::Surface *destSurface) { if (_cursorSprite.getPixels()) { - int sourcePitch = (_cursorSprite.getDimensions().width + 3) & 0xFFFC; // 4 byte alignment + const int sourcePitch = (_cursorSprite.getDimensions().width + 3) & 0xFFFC; // 4 byte alignment + const int destPitch = destSurface->pitch; const byte *source = _cursorSprite.getPixels() + _cursorNum * (sourcePitch * 32) + frameNum * 32; + byte *dest = (byte*)destSurface->pixels; for (int16 yc = 0; yc < 32; yc++) { memcpy(dest, source, 32); source += sourcePitch; diff --git a/engines/neverhood/resource.h b/engines/neverhood/resource.h index c6f63bf92d..e2609b6fd2 100644 --- a/engines/neverhood/resource.h +++ b/engines/neverhood/resource.h @@ -46,9 +46,8 @@ 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 draw(Graphics::Surface *destSurface, bool flipX, bool flipY); + bool load(uint32 fileHash, bool doLoadPosition = false); void unload(); const NDimensions& getDimensions() { return _dimensions; } NPoint& getPosition() { return _position; } @@ -90,7 +89,7 @@ class AnimResource { public: AnimResource(NeverhoodEngine *vm); ~AnimResource(); - void draw(uint frameIndex, byte *dest, int destPitch, bool flipX, bool flipY); + void draw(uint frameIndex, Graphics::Surface *destSurface, bool flipX, bool flipY); bool load(uint32 fileHash); void unload(); void clear(); @@ -120,7 +119,7 @@ public: void load(uint32 fileHash); void unload(); NDrawRect& getRect(); - void draw(int frameNum, byte *dest, int destPitch); + void draw(int frameNum, Graphics::Surface *destSurface); int getCursorNum() const { return _cursorNum; } void setCursorNum(int cursorNum) { _cursorNum = cursorNum; } protected: diff --git a/engines/neverhood/sprite.cpp b/engines/neverhood/sprite.cpp index 241912286c..45d131fd3c 100644 --- a/engines/neverhood/sprite.cpp +++ b/engines/neverhood/sprite.cpp @@ -116,7 +116,7 @@ StaticSprite::StaticSprite(NeverhoodEngine *vm, int objectPriority) StaticSprite::StaticSprite(NeverhoodEngine *vm, uint32 fileHash, int surfacePriority, int16 x, int16 y) : Sprite(vm, 0), _spriteResource(vm) { - _spriteResource.load2(fileHash); + _spriteResource.load(fileHash, true); createSurface(surfacePriority, _spriteResource.getDimensions().width, _spriteResource.getDimensions().height); _x = x == kDefPosition ? _spriteResource.getPosition().x : x; _y = y == kDefPosition ? _spriteResource.getPosition().y : y; @@ -126,7 +126,7 @@ StaticSprite::StaticSprite(NeverhoodEngine *vm, uint32 fileHash, int surfacePrio } void StaticSprite::loadSprite(uint32 fileHash, uint flags, int surfacePriority, int16 x, int16 y) { - _spriteResource.load2(fileHash); + _spriteResource.load(fileHash, true); if (!_surface) createSurface(surfacePriority, _spriteResource.getDimensions().width, _spriteResource.getDimensions().height); if (flags & kSLFDefDrawOffset) |