aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorMatthew Stewart2018-05-14 14:02:28 -0400
committerEugene Sandulenko2018-08-09 08:37:30 +0200
commit1110fee2e462f28d2013530fa23e692aeec7d5dc (patch)
treecbc3413d120dd88ba79032796f73632d6f04685e /engines
parent65d24b04519a5e0bbd7b1efbf6b379d539b424e5 (diff)
downloadscummvm-rg350-1110fee2e462f28d2013530fa23e692aeec7d5dc.tar.gz
scummvm-rg350-1110fee2e462f28d2013530fa23e692aeec7d5dc.tar.bz2
scummvm-rg350-1110fee2e462f28d2013530fa23e692aeec7d5dc.zip
STARTREK: Sprite layering
Diffstat (limited to 'engines')
-rw-r--r--engines/startrek/graphics.cpp18
1 files changed, 17 insertions, 1 deletions
diff --git a/engines/startrek/graphics.cpp b/engines/startrek/graphics.cpp
index 2a9902560e..250453466c 100644
--- a/engines/startrek/graphics.cpp
+++ b/engines/startrek/graphics.cpp
@@ -22,6 +22,7 @@
#include "startrek/common.h"
#include "startrek/graphics.h"
+#include "common/algorithm.h"
#include "common/config-manager.h"
#include "common/events.h"
#include "common/rendermode.h"
@@ -336,13 +337,28 @@ void Graphics::drawSprite(const Sprite &sprite, const Common::Rect &rect) {
_vm->_system->unlockScreen();
}
+/**
+ * Compare 2 sprites for the purpose of sorting them by layer before drawing.
+ * FIXME: Original returned an int, not a bool. This may affect the stability of the sort...
+ */
+bool compareSpritesByLayer(Sprite *s1, Sprite *s2) {
+ if (s1->drawPriority != s2->drawPriority)
+ return s1->drawPriority < s2->drawPriority;
+ if (s1->field6 != s2->field6)
+ return s1->field6 < s2->field6;
+ if (s1->pos.y != s2->pos.y)
+ return s1->pos.y < s2->pos.y;
+ return s1->pos.x < s2->pos.x;
+}
+
void Graphics::drawAllSprites() {
// TODO: different video modes?
if (_numSprites == 0)
return;
- // TODO: calculateSpriteDrawPriority()
+ // Sort sprites by layer
+ Common::sort(_sprites, _sprites + _numSprites, &compareSpritesByLayer);
// Update sprite rectangles
for (int i=0; i<_numSprites; i++) {