diff options
Diffstat (limited to 'src/koopatlas/map.cpp')
-rw-r--r-- | src/koopatlas/map.cpp | 197 |
1 files changed, 129 insertions, 68 deletions
diff --git a/src/koopatlas/map.cpp b/src/koopatlas/map.cpp index f4b953c..38610e6 100644 --- a/src/koopatlas/map.cpp +++ b/src/koopatlas/map.cpp @@ -117,6 +117,8 @@ void dWMMap_c::renderer_c::drawLayers() { renderTileLayer(layer, data->sectors); else if (layer->type == dKPLayer_s::DOODADS) renderDoodadLayer(layer); + else if (layer->type == dKPLayer_s::PATHS) + renderPathLayer(layer); } endRendering(); @@ -298,82 +300,92 @@ void dWMMap_c::renderer_c::renderDoodadLayer(dKPLayer_s *layer) { for (int j = 0; j < doodad->animationCount; j++) { dKPDoodad_s::animation_s *anim = &doodad->animations[j]; - u32 baseTick = anim->baseTick; - if (baseTick == 0) { - anim->baseTick = baseTick = GlobalTickCount; - } + if (anim->delayOffset == 0) { + u32 baseTick = anim->baseTick; + if (baseTick == 0) { + anim->baseTick = baseTick = GlobalTickCount; + } - u32 elapsed = GlobalTickCount - baseTick; - if (anim->isReversed) - elapsed = anim->frameCount - 1 - elapsed; + u32 elapsed = GlobalTickCount - baseTick; + u32 elapsedAdjusted = elapsed; + if (anim->isReversed) + elapsed = anim->frameCount - 1 - elapsed; + + if (elapsed >= anim->frameCount) { + if (elapsed >= (anim->frameCount + delay)) { + + // we've reached the end + switch (anim->loop) { + case dKPDoodad_s::animation_s::CONTIGUOUS: + // Stop here + elapsed = anim->frameCount - 1; + break; + + case dKPDoodad_s::animation_s::LOOP: + // Start over + elapsed = 0; + anim->baseTick = GlobalTickCount; + break; + + case dKPDoodad_s::animation_s::REVERSE_LOOP: + // Change direction + anim->isReversed = !anim->isReversed; + elapsed = (anim->isReversed) ? (anim->frameCount - 1) : 0; + anim->baseTick = GlobalTickCount; + break; + } + } + elapsedAdjusted = anim->frameCount; + } - if (elapsed >= anim->frameCount) { - // we've reached the end - switch (anim->loop) { - case dKPDoodad_s::animation_s::CONTIGUOUS: - // Stop here - elapsed = anim->frameCount - 1; - break; + // now calculate the thing + float progress = elapsedAdjusted / (float)anim->frameCount; + float value; - case dKPDoodad_s::animation_s::LOOP: - // Start over - elapsed = 0; - anim->baseTick = GlobalTickCount; + switch (anim->curve) { + case dKPDoodad_s::animation_s::LINEAR: + value = progress; break; - - case dKPDoodad_s::animation_s::REVERSE_LOOP: - // Change direction - anim->isReversed = !anim->isReversed; - elapsed = (anim->isReversed) ? (anim->frameCount - 1) : 0; - anim->baseTick = GlobalTickCount; + case dKPDoodad_s::animation_s::SIN: + value = (sin(((progress * M_PI * 2)) - M_PI_2) + 1) / 2; + break; + case dKPDoodad_s::animation_s::COS: + value = (cos(((progress * M_PI * 2)) - M_PI_2) + 1) / 2; break; } - } - // now calculate the thing - float progress = elapsed / (float)anim->frameCount; - float value; - - switch (anim->curve) { - case dKPDoodad_s::animation_s::LINEAR: - value = progress; - break; - case dKPDoodad_s::animation_s::SIN: - value = (sin(((progress * M_PI * 2)) - M_PI_2) + 1) / 2; - break; - case dKPDoodad_s::animation_s::COS: - value = (cos(((progress * M_PI * 2)) - M_PI_2) + 1) / 2; - break; - } + float delta = anim->end - anim->start; + float frame; - float delta = anim->end - anim->start; - float frame; - - if (anim->isReversed) - frame = anim->start + ceil(delta * value); - else - frame = anim->start + (delta * value); - - // and apply it! - switch (anim->type) { - case dKPDoodad_s::animation_s::X_POS: - effectiveX += frame; - break; - case dKPDoodad_s::animation_s::Y_POS: - effectiveY += frame; - break; - case dKPDoodad_s::animation_s::ANGLE: - effectiveAngle += frame; - break; - case dKPDoodad_s::animation_s::X_SCALE: - effectiveWidth = (effectiveWidth * frame / 100.0); - break; - case dKPDoodad_s::animation_s::Y_SCALE: - effectiveHeight = (effectiveHeight * frame / 100.0); - break; - case dKPDoodad_s::animation_s::OPACITY: - // TODO - break; + if (anim->isReversed) + frame = anim->start + ceil(delta * value); + else + frame = anim->start + (delta * value); + + // and apply it! + switch (anim->type) { + case dKPDoodad_s::animation_s::X_POS: + effectiveX += frame; + break; + case dKPDoodad_s::animation_s::Y_POS: + effectiveY += frame; + break; + case dKPDoodad_s::animation_s::ANGLE: + effectiveAngle += frame; + break; + case dKPDoodad_s::animation_s::X_SCALE: + effectiveWidth = (effectiveWidth * frame / 100.0); + break; + case dKPDoodad_s::animation_s::Y_SCALE: + effectiveHeight = (effectiveHeight * frame / 100.0); + break; + case dKPDoodad_s::animation_s::OPACITY: + // TODO + break; + } + } + else { + anim->delayOffset -= 1; } } } @@ -406,6 +418,55 @@ void dWMMap_c::renderer_c::renderDoodadLayer(dKPLayer_s *layer) { } } +void dWMMap_c::renderer_c::renderPathLayer(dKPLayer_s *layer) { + for (int i = 0; i < layer->nodeCount; i++) { + dKPNode_s **node = layer->nodes[i]; + + int world = node->levelNumber[0]; + int level = node->levelNumber[1]; + + SaveBlock *save = GetSaveFile()->GetBlock(-1); + u32 conds = save->GetLevelCondition(world-1, level-1); + + bool isUnlocked = true; + bool exitComplete = false; + bool secretComplete = false; + + if (conds & 0x10) + exitComplete = true; + if (conds & 0x20) + secretComplete = true; + + // Is it unlocked? + if (!isUnlocked) + node->color.setCurrentFrame(0); // Black + + // Is it complete? + else if ((exitComplete) || (secretComplete)) + // Does it have two exits? + if ((node->hasSecret) && ((!exitComplete) || (!secretComplete))) + node->color.setCurrentFrame(2); // Yellow + + // All exits are complete + else + node->color.setCurrentFrame(1); // Blue + + // Not complete after all + else + node->color.setCurrentFrame(3); // Red + + matrix.translation(node->x, node->y, 500.0); } + matrix.applyRotationYXZ(&rot.x, &rot.y, &rot.z); + node->model.setDrawMatrix(matrix); + node->model.setScale(1.0f, 1.0f, 1.0f); + node->model.calcWorld(false); + + node->model.scheduleForDrawing(); + } +} + + + void dWMMap_c::renderer_c::endRendering() { } |