From 3f6db4f669fe659af25169cc22b1d8e6b288d2b6 Mon Sep 17 00:00:00 2001 From: Treeki Date: Tue, 3 Apr 2012 03:47:46 +0200 Subject: magic platform fixes and updates --- src/magicplatform.cpp | 56 +++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 45 insertions(+), 11 deletions(-) diff --git a/src/magicplatform.cpp b/src/magicplatform.cpp index e9fa940..ae6631d 100644 --- a/src/magicplatform.cpp +++ b/src/magicplatform.cpp @@ -33,6 +33,11 @@ class daEnMagicPlatform_c : public dEn_c { void deleteTiles(); void updateTilePositions(); + void checkVisibility(); + void setVisible(bool shown); + + bool isVisible; + int srcX, srcY; int width, height; }; @@ -79,8 +84,8 @@ static void PhysCB3(daEnMagicPlatform_c *one, dStageActor_c *two, bool unkMaybeN if (two->stageActorType != 1) return; - // if left/right - if (one->moveDirection <= 1) + // if up/down + if (one->moveDirection > 1) return; if (unkMaybeNotBool) { @@ -157,6 +162,8 @@ int daEnMagicPlatform_c::onDelete() { int daEnMagicPlatform_c::onExecute() { handleMovement(); + checkVisibility(); + updateTilePositions(); physics.update(); @@ -308,8 +315,6 @@ void daEnMagicPlatform_c::findSourceArea() { void daEnMagicPlatform_c::createTiles() { - TileRenderer::List *list = dBgGm_c::instance->getTileRendererList(0); - rendererCount = width * height; renderers = new TileRenderer[rendererCount]; @@ -326,7 +331,6 @@ void daEnMagicPlatform_c::createTiles() { TileRenderer *r = &renderers[rendererID]; r->tileNumber = *pExistingTile; r->z = pos.z; - list->add(r); } worldX += 16; @@ -340,12 +344,7 @@ void daEnMagicPlatform_c::createTiles() { void daEnMagicPlatform_c::deleteTiles() { if (renderers != 0) { - TileRenderer::List *list = dBgGm_c::instance->getTileRendererList(0); - - for (int i = 0; i < rendererCount; i++) { - if (renderers[i].isInList()) - list->remove(&renderers[i]); - } + setVisible(false); delete[] renderers; renderers = 0; @@ -377,3 +376,38 @@ void daEnMagicPlatform_c::updateTilePositions() { +void daEnMagicPlatform_c::checkVisibility() { + float effectiveLeft = pos.x, effectiveRight = pos.x + (width * 16.0f); + float effectiveBottom = pos.y - (height * 16.0f), effectiveTop = pos.y; + + ClassWithCameraInfo *cwci = ClassWithCameraInfo::instance; + + float screenRight = cwci->screenLeft + cwci->screenWidth; + float screenBottom = cwci->screenTop - cwci->screenHeight; + + bool isOut = (effectiveLeft > screenRight) || + (effectiveRight < cwci->screenLeft) || + (effectiveTop < screenBottom) || + (effectiveBottom > cwci->screenTop); + + setVisible(!isOut); +} + +void daEnMagicPlatform_c::setVisible(bool shown) { + if (isVisible == shown) + return; + isVisible = shown; + + TileRenderer::List *list = dBgGm_c::instance->getTileRendererList(0); + + for (int i = 0; i < rendererCount; i++) { + if (shown) { + if (!renderers[i].isInList() && renderers[i].tileNumber > 0) + list->add(&renderers[i]); + } else { + if (renderers[i].isInList()) + list->remove(&renderers[i]); + } + } +} + -- cgit v1.2.3