void MadsSpriteSlots::drawForeground(M4Surface *viewport) { DepthList depthList; // Get a list of sprite object depths for active objects for (int i = 0; i < startIndex; ++i) { if (_entries[i].spriteType >= SPRITE_ZERO) { DepthEntry rec(16 - _entries[i].depth, i); depthList.push_back(rec); } } // Sort the list in order of the depth Common::sort(depthList.begin(), depthList.end(), sortHelper); // Loop through each of the objects DepthList::iterator i; for (i = depthList.begin(); i != depthList.end(); ++i) { DepthEntry &de = *i; MadsSpriteSlot &slot = _entries[de.index]; assert(slot.spriteListIndex < (int)_sprites.size()); SpriteAsset &spriteSet = *_sprites[slot.spriteListIndex]; // Get the sprite frame int frameNumber = slot.frameNumber & 0x7fff; bool flipped = (slot.frameNumber & 0x8000) != 0; M4Sprite *sprite = spriteSet.getFrame(frameNumber - 1); M4Surface *spr = sprite; if (flipped) { // Create a flipped copy of the sprite temporarily spr = sprite->flipHorizontal(); } if ((slot.scale < 100) && (slot.scale != -1)) { // Minimalised drawing viewport->copyFrom(spr, slot.xp, slot.yp, slot.depth, _owner._depthSurface, slot.scale, sprite->getTransparencyIndex()); } else { int xp, yp; if (slot.scale == -1) { xp = slot.xp - _owner._posAdjust.x; yp = slot.yp - _owner._posAdjust.y; } else { xp = slot.xp - (spr->width() / 2) - _owner._posAdjust.x; yp = slot.yp - spr->height() - _owner._posAdjust.y + 1; } if (slot.depth > 1) { // Draw the frame with depth processing viewport->copyFrom(spr, xp, yp, slot.depth, _owner._depthSurface, 100, sprite->getTransparencyIndex()); } else { // No depth, so simply draw the image spr->copyTo(viewport, xp, yp, sprite->getTransparencyIndex()); } } // Free sprite if it was a flipped one if (flipped) delete spr; } }
void SpriteSlots::drawSprites(MSurface *s) { DepthList depthList; Scene &scene = _vm->_game->_scene; // Get a list of sprite object depths for active objects for (uint i = 0; i < size(); ++i) { SpriteSlot &spriteSlot = (*this)[i]; if (spriteSlot._flags >= IMG_STATIC) { DepthEntry rec(16 - spriteSlot._depth, i); depthList.push_back(rec); } } // Sort the list in order of the depth Common::sort(depthList.begin(), depthList.end(), sortHelper); // Loop through each of the objects DepthList::iterator i; for (i = depthList.begin(); i != depthList.end(); ++i) { DepthEntry &de = *i; SpriteSlot &slot = (*this)[de.index]; assert(slot._spritesIndex < (int)scene._sprites.size()); SpriteAsset &spriteSet = *scene._sprites[slot._spritesIndex]; // Get the sprite frame int frameNumber = ABS(slot._frameNumber); bool flipped = slot._frameNumber < 0; assert(frameNumber > 0); MSprite *sprite = spriteSet.getFrame(frameNumber - 1); if ((slot._scale < 100) && (slot._scale != -1)) { // Scaled drawing s->copyFrom(*sprite, slot._position, slot._depth, &scene._depthSurface, slot._scale, flipped, sprite->getTransparencyIndex()); } else { int xp, yp; if (slot._scale == -1) { xp = slot._position.x - scene._posAdjust.x; yp = slot._position.y - scene._posAdjust.y; } else { xp = slot._position.x - (sprite->w / 2) - scene._posAdjust.x; yp = slot._position.y - sprite->h - scene._posAdjust.y + 1; } if (slot._depth > 1) { // Draw the frame with depth processing s->copyFrom(*sprite, Common::Point(xp, yp), slot._depth, &scene._depthSurface, -1, flipped, sprite->getTransparencyIndex()); } else { MSurface *spr = sprite; if (flipped) { // Create a flipped copy of the sprite temporarily spr = sprite->flipHorizontal(); } // No depth, so simply draw the image s->transBlitFrom(*spr, Common::Point(xp, yp), sprite->getTransparencyIndex()); // Free sprite if it was a flipped one if (flipped) { spr->free(); delete spr; } } } } }