aboutsummaryrefslogtreecommitdiff
path: root/engines/toon/anim.cpp
diff options
context:
space:
mode:
authorSylvain Dupont2011-01-30 02:18:53 +0000
committerSylvain Dupont2011-01-30 02:18:53 +0000
commit5934ccd184a302720103f7e803bdf4c9157db54b (patch)
treeb1ecdfac5e2c92258abda96bc9d4930317874bce /engines/toon/anim.cpp
parent01c32f7287481e6784619167d5de344fe8209c12 (diff)
downloadscummvm-rg350-5934ccd184a302720103f7e803bdf4c9157db54b.tar.gz
scummvm-rg350-5934ccd184a302720103f7e803bdf4c9157db54b.tar.bz2
scummvm-rg350-5934ccd184a302720103f7e803bdf4c9157db54b.zip
TOON: Fix the last known z-order issues
Rewrote the Z-order management, it's now very close to the original code svn-id: r55650
Diffstat (limited to 'engines/toon/anim.cpp')
-rw-r--r--engines/toon/anim.cpp57
1 files changed, 39 insertions, 18 deletions
diff --git a/engines/toon/anim.cpp b/engines/toon/anim.cpp
index 00cfdad9cc..bb5a1e7dbc 100644
--- a/engines/toon/anim.cpp
+++ b/engines/toon/anim.cpp
@@ -604,6 +604,8 @@ void AnimationInstance::setZ(int32 z, bool relative) {
void AnimationInstance::setLayerZ(int32 z) {
_layerZ = z;
+ if (_vm->getAnimationManager()->hasInstance(this))
+ _vm->getAnimationManager()->updateInstance(this);
}
int32 AnimationInstance::getLayerZ() const {
@@ -678,8 +680,44 @@ void AnimationInstance::reset() {
AnimationManager::AnimationManager(ToonEngine *vm) : _vm(vm) {
}
+bool AnimationManager::hasInstance(AnimationInstance* instance) {
+ for (uint32 i = 0; i < _instances.size(); i++) {
+ if(_instances[i] == instance)
+ return true;
+ }
+ return false;
+}
+
+void AnimationManager::updateInstance(AnimationInstance* instance) {
+ // simply remove and readd the instance in the ordered list
+ removeInstance(instance);
+ addInstance(instance);
+}
+
void AnimationManager::addInstance(AnimationInstance *instance) {
- _instances.push_back(instance);
+
+ // if the instance already exists, we skip the add
+ for (uint32 i = 0; i < _instances.size(); i++) {
+ if(_instances[i] == instance)
+ return;
+ }
+
+ int found = -1;
+
+ // here we now do an ordered insert (closer to the original game)
+ for (uint32 i = 0; i < _instances.size(); i++) {
+ if (_instances[i]->getLayerZ() >= instance->getLayerZ()) {
+ found = i;
+ break;
+ }
+ }
+
+ if ( found == -1 ) {
+ _instances.push_back(instance);
+ } else {
+ _instances.insert_at(found, instance);
+ }
+
}
void AnimationManager::removeInstance(AnimationInstance *instance) {
@@ -712,23 +750,6 @@ void AnimationManager::update(int32 timeIncrement) {
void AnimationManager::render() {
debugC(5, kDebugAnim, "render()");
- // sort the instance by layer z
- // bubble sort (replace by faster afterwards)
- bool changed = true;
- while (changed) {
- changed = false;
- for (uint32 i = 0; i < _instances.size() - 1; i++) {
- if ((_instances[i]->getLayerZ() > _instances[i + 1]->getLayerZ()) ||
- ((_instances[i]->getLayerZ() == _instances[i + 1]->getLayerZ()) &&
- (_instances[i]->getId() < _instances[i+1]->getId()))) {
- AnimationInstance *instance = _instances[i];
- _instances[i] = _instances[i + 1];
- _instances[i + 1] = instance;
- changed = true;
- }
- }
- }
-
for (uint32 i = 0; i < _instances.size(); i++) {
if (_instances[i]->getVisible())
_instances[i]->render();