#include "room_transition.h" #include "entity_npc.h" #include "entity_player.h" #include "fx_layers.h" #include "game.h" #include "grid_entity_door.h" #include "level.h" #include "log.h" #include "manager.h" #include "platform.h" #include "render_passes.h" #include "room.h" #include #include #include #include constexpr const char* VERSUS_SCREEN_ANM2 = "gfx/ui/boss/versusscreen.anm2"; constexpr const char* OLD_ROOM_SURFACE = "Old Room Surface"; constexpr const char* NEW_ROOM_SURFACE = "New Room Surface"; constexpr const char* ANIMATION_DEATH_TELEPORT = "DeathTeleport"; constexpr KColor WHITE = kcolor_rgba(1, 1, 1, 1); constexpr float DEGREES_TO_RADIANS = std::numbers::pi_v / 180; constexpr int PIXELATION_DURATION = 30; constexpr int WALK_DURATION = 7; constexpr int UNDIRECTED_DURATION = 3; constexpr int SOUND_MIRROR_ENTER = 608; constexpr int SOUND_MIRROR_EXIT = 609; constexpr int MIRROR_DIMENSION = 1; constexpr std::string_view ANIMATION_DEATH_SUFFIX = "Death"; constexpr const char* ANIMATION_TELEPORT_DOWN = "TeleportDown"; constexpr const char* ANIMATION_PICKUP = "Pickup"; constexpr const char* ANIMATION_PICKUP_SPARKLE = "PlayerPickupSparkle"; constexpr const char* EVENT_POOF = "Poof"; constexpr int SLOWEST_FRAME_UNSET = 1000; constexpr int FOLLOW_MIN_FRAME = 6; constexpr float RANDOM_UNIT = 2.3283064e-10f; constexpr float RANDOM_PI = 3.14f; constexpr float MINECART_JITTER = 8; constexpr int VERSUS_FIRE_BLOCK_FRAMES = 10; constexpr int TELEPORT_SOUND_FRAME = 8; constexpr int SOUND_ONE_UP = 1; constexpr int SOUND_TELEPORT_LAND = 214; constexpr int ITEM_STATE_HELD = 604; constexpr int PITFALL_GONE = 4; constexpr int MINECART_RIDDEN = 10; constexpr int NPC_STATE_MINECART_MOVING = 4; constexpr int COLLECTIBLE_GLOWING_HOURGLASS = 422; constexpr int COLLECTIBLE_D7 = 437; constexpr const char* ANIMATION_APPEAR = "Appear"; constexpr float APPEAR_FRAME = 2; constexpr float SCREEN_CELL_SIZE = 26; constexpr int ROOM_CELLS_ACROSS = 13; constexpr int ROOM_CELLS_DOWN = 7; constexpr int DEATH_CERTIFICATE_DIMENSION = 2; constexpr int DOGMA_ROOM_VARIANT = 1000; constexpr uint32_t BOSS_DOGMA = 99; // The items whose pickup animation an extra life plays once the player is back, from the Ankh to Lazarus' Rags: Ankh, // Dead Cat, 1up!, Guppy's Collar, Judas' Shadow and Lazarus' Rags. constexpr std::array EXTRA_LIFE_ITEMS = {161, 81, 11, 212, 311, 332}; // Stops the boss overlay as BossOverlay's own stop does: it hides and the sound effects come back to full volume at // the normal fade. Its sprite waits for BossOverlay's takeover, so a shown overlay stops the game here. static void boss_overlay_stop(Game& game) { SFXManager& sounds = g_manager->sfxManager; if (game.bossOverlay._state != 0) reconstruction_missing("BossOverlay stop 00421260 on a shown overlay"); if (sounds.volumeModifier != 1) { sounds.volumeModifier = 1; sounds.ClearVolumeModifier(); } sounds.volumeModifierStep = VOLUME_MODIFIER_STEP; } // 0082ed00 Creates the surfaces the old and new rooms are captured into, of the framebuffer's size. void RoomTransition::surfaces_create() { KAGE::Graphics::Manager& graphics = KAGE::Graphics::manager; oldRoomSurface.reset(); newRoomSurface.reset(); oldRoomSurface = graphics.render_target_create( {kcolor_rgba(0, 0, 0, 0), OLD_ROOM_SURFACE, (int)DAT_00c79114, g_framebufferWidth}); newRoomSurface = graphics.render_target_create( {kcolor_rgba(0, 0, 0, 0), NEW_ROOM_SURFACE, (int)DAT_00c79114, g_framebufferWidth}); } // 0082ee40 Starts moving to a room, unless a stage transition runs (a forced boss transition starts anyway). The // versus screen loads the first time. The room the players are in is entered without a direction. The players (not // their babies) stop and lose control, teleporting ones animating it (all but the dead) or playing the Death // Certificate's teleport. A pixelation lasts 30 frames, a walk 7 and the rest 3, a mirror fade with its sound. void RoomTransition::start(const RoomTransitionRequest& request) { Game& game = *g_game; log_printf(LOG_INFO, "[Frame %d] Starting room transition (type %d) \n", game.frameCount, request.animation); if (!versusScreenANM2.isLoaded) versusScreenANM2.Load(VERSUS_SCREEN_ANM2, GRAPHICS_LOAD); if (game.stageTransition.state != 0 && request.animation != TRANSITION_BOSS_FORCED) return; bool isCurrentRoom = request.roomIndex == game.currentRoomIdx && request.dimension == game.currentDimensionIdx; roomIndex = request.roomIndex; frame = 0; animation = request.animation; direction = isCurrentRoom ? DIRECTION_NONE : request.direction; bossIntroBossId = 0; game.playerManager.roomTransitionPlayer = request.player; teleporterTarget = 0; flags = 0; roomDimension = request.dimension < 0 ? game.currentDimensionIdx : request.dimension; for (size_t i = 0; i < game.playerManager.playerList.size(); i++) { Entity_Player* player = game.GetPlayer((int)i); if (player->variant != PLAYER_VARIANT_PLAYER) continue; if (is_teleport() && !player->isDead) player->AnimateTeleport(request.animation != TRANSITION_WOMB_TELEPORT); else if (animation == TRANSITION_DEATH_CERTIFICATE) player->PlayExtraAnimation(ANIMATION_DEATH_TELEPORT); player->velocity = vector_make(0, 0); player->isControlsEnabled = false; } mode = TRANSITION_START; progress = 0; slideOffset = vector_make(0, 0); if (animation == TRANSITION_PIXELATION) return void(duration = PIXELATION_DURATION); duration = direction != DIRECTION_NONE ? WALK_DURATION : UNDIRECTED_DURATION; if (animation != TRANSITION_FADE_MIRROR) return; int sound = request.dimension != MIRROR_DIMENSION ? SOUND_MIRROR_EXIT : SOUND_MIRROR_ENTER; seed_fart_sound_override(&sound); g_manager->sfxManager.Play(sound); } // The distance between two rooms in screen pixels, mirrored in the mirror world: from their map cells when both lie on // the map of one dimension, else the size of the room on the side left through (the target's for left and up). static Vector room_distance_get(RoomDescriptor& current, RoomDescriptor& target, bool isOnMap, Direction direction) { Vector distance{}; if (isOnMap) { int columns = target.gridIndex % LEVEL_GRID_WIDTH - current.gridIndex % LEVEL_GRID_WIDTH; int rows = target.gridIndex / LEVEL_GRID_WIDTH - current.gridIndex / LEVEL_GRID_WIDTH; distance = vector_make((float)(columns * ROOM_CELLS_ACROSS) * SCREEN_CELL_SIZE, (float)(rows * ROOM_CELLS_DOWN) * SCREEN_CELL_SIZE); } else switch (direction) { case DIRECTION_LEFT: distance.x = -(float)target.data->width * SCREEN_CELL_SIZE; break; case DIRECTION_UP: distance.y = -(float)target.data->height * SCREEN_CELL_SIZE; break; case DIRECTION_RIGHT: distance.x = (float)current.data->width * SCREEN_CELL_SIZE; break; case DIRECTION_DOWN: distance.y = (float)current.data->height * SCREEN_CELL_SIZE; break; default: break; } if (Room::IsMirrorWorld()) distance.x = -distance.x; return distance; } // How far past a screen the rooms slide through a door: the rooms' distance less the camera's change between them, // across mirrored in the mirror world. void RoomTransition::slide_offset_set(Vector distance, Vector oldScroll) { Vector newScroll = g_game->room->renderScrollOffset; float across = Room::IsMirrorWorld() ? oldScroll.x - newScroll.x : newScroll.x - oldScroll.x; switch (direction) { case DIRECTION_LEFT: slideOffset.x = across - g_screenWidth - distance.x; break; case DIRECTION_UP: slideOffset.y = newScroll.y - oldScroll.y - g_screenHeight - distance.y; break; case DIRECTION_RIGHT: slideOffset.x = -across - g_screenWidth + distance.x; break; case DIRECTION_DOWN: slideOffset.y = oldScroll.y - newScroll.y - g_screenHeight + distance.y; break; default: break; } } // Puts the players in the new room. A teleport keeps them hidden, else the main players not held show. The Forgotten's // body, the Death Certificate's floor, a teleporter's pad and the Ventricle Razor's portals place them. void RoomTransition::arrival_place() { Game& game = *g_game; Room& room = *game.room; bool isTeleporterRoom = room.roomType == ROOM_TELEPORTER || room.roomType == ROOM_TELEPORTER_EXIT; if (animation == TRANSITION_WOMB_TELEPORT) { for (VentricleRazorPortal& portal : game.ventricleRazorPortals) if (portal.roomIndex == game.currentRoomIdx) reconstruction_missing("RoomTransition::ChangeRoom 00830950: the players jumping out of a Ventricle " "Razor portal (Entity_Player +0x14c, +0x98)"); return; } if (!is_teleport()) for (Entity_Player* player : game.playerManager.playerList) if (player->variant == PLAYER_VARIANT_PLAYER && !(player->flags & FLAG_HELD)) player->isVisible = true; if (animation == TRANSITION_FORGOTTEN_TELEPORT && game.playerManager.roomTransitionPlayer) { Entity_Player& player = *game.playerManager.roomTransitionPlayer; player.Teleport(player.forgottenBodyPos, false, false); } else if (animation == TRANSITION_DEATH_CERTIFICATE && game.currentDimensionIdx == DEATH_CERTIFICATE_DIMENSION) reconstruction_missing("RoomTransition::ChangeRoom 00830950: the players placed on the Death Certificate floor"); else if (animation == TRANSITION_DEATH_CERTIFICATE) for (Entity_Player* player : game.playerManager.playerList) { if (!player) continue; player->PlayExtraAnimation(ANIMATION_APPEAR); if (player->sprite.animState.animData) player->sprite.animState.SetFrameFloat(APPEAR_FRAME); player->isControlsEnabled = false; } else if (animation == TRANSITION_TELEPORT && teleporterTarget > 0 && isTeleporterRoom) reconstruction_missing("RoomTransition::ChangeRoom 00830950: Entity_Player::Teleport 007cd950 to a teleporter"); } // 00830950 Takes the players into the target room (the Glowing Hourglass rewinds the room instead), their controls on // while it loads, and works out how far a walk through a door slides. The new room's boss gets its versus screen // (Dogma's living room too), else the room plays its music. The players are placed and the new room is captured. void RoomTransition::ChangeRoom() { Game& game = *g_game; std::vector& players = game.playerManager.playerList; RoomDescriptor& current = *game.GetRoomByIdx(game.currentRoomIdx, game.currentDimensionIdx); RoomDescriptor& target = *game.GetRoomByIdx(roomIndex, roomDimension); bool isOnMap = roomIndex >= 0 && game.currentRoomIdx >= 0 && current.dimension == target.dimension; Vector distance = room_distance_get(current, target, isOnMap, direction); Vector oldScroll = game.room->renderScrollOffset; if (game.deathmatchManager.state < DEATHMATCH_INTRO) for (Entity_Player* player : players) player->isControlsEnabled = true; if (animation == TRANSITION_GLOWING_HOURGLASS) reconstruction_missing("Game::rewind 00706020"); else { if (direction == DIRECTION_NONE) game.leaveDoor = DOOR_NONE; game.ChangeRoom(roomIndex, roomDimension); } for (Entity_Player* player : players) player->isControlsEnabled = false; if (animation == TRANSITION_WALK) slide_offset_set(distance, oldScroll); Room& room = *game.room; RoomConfig_Room* data = room.descriptor->data; bool isDogmaRoom = data && data->stageId == STAGE_ID_HOME && data->type == ROOM_DEFAULT && data->variant == DOGMA_ROOM_VARIANT && !room.IsClear(); if (room.bossId != 0 && room.GetAliveBossesCount() >= 1) StartBossIntro(room.bossId, room.secondBossId); else if (isDogmaRoom) StartBossIntro(BOSS_DOGMA, 0); else if (game.deathmatchManager.state < DEATHMATCH_INTRO) room.PlayMusic(); arrival_place(); room_capture(newRoomSurface); } // Whether a player plays an extra or item animation that holds the transition: one not looping. static bool is_animating(Entity_Player& player) { const AnimationData* data = player.sprite.animState.animData; return (player.isPlayingExtraAnimation || player.isPlayingItemAnimation) && !(data && data->isLooping); } // Sets the minecart off along its rail, the players riding it. // The rail it stands on and the minecart's own fields wait for Room's and Entity_NPC's rails. static void minecart_launch(Entity_NPC&) { reconstruction_missing("RoomTransition::Update 008318a0: the minecart setting off on its rail"); } // The frame the players are captured on. They finish the animations that hold the transition, the room and the doors // (in a minecart) still updating. A player done animating a teleport or a minecart ride copies the slowest one's // animation and target, the minecart rider jittering about the cart. Then the old room renders into its surface, the // players hidden as they leave, and the old room fades out first or the new one comes in at once. void RoomTransition::start_update(Entity_NPC* minecartNpc) { Game& game = *g_game; Room& room = *game.room; Entity_Player* idlePlayer = nullptr; Entity_Player* slowestPlayer = nullptr; int slowestFrame = SLOWEST_FRAME_UNSET; bool isAllIdle = true; room.entityList.Update(UPDATE_TRANSITION); room.update_ambient_sounds(); if (animation == TRANSITION_MINECART) for (GridEntity_Door* door : room.doors) if (door) door->Update(); for (Entity_Player* player : game.playerManager.playerList) { if (!player) continue; if (player->isDead) { player->Update(); continue; } if (!is_animating(*player)) { if (!idlePlayer && player->isVisible) idlePlayer = player; if (animation == TRANSITION_MINECART) player->Update(); continue; } if (animation == TRANSITION_WALK) player->isPlayingExtraAnimation = player->isPlayingItemAnimation = false; player->Update(); if (player->itemState != 0 && player->itemState != ITEM_STATE_HELD) player->ResetItemState(); if (animation == TRANSITION_WALK) player->isPlayingExtraAnimation = player->isPlayingItemAnimation = false; bool isRidden = animation == TRANSITION_MINECART && minecartNpc && player->sprite.animState.animData && player->sprite.animState.IsEventTriggered(EVENT_POOF); if (isRidden) { player->AttachMinecart(minecartNpc); player->isVisible = false; } if ((!player->isPlayingExtraAnimation && !player->isPlayingItemAnimation) || player->pitfallState == PITFALL_GONE) { player->isVisible = false; continue; } int playerFrame = player->sprite.animState.animData ? (int)std::floor(player->sprite.animState.animFrame) : -1; isAllIdle = false; if (playerFrame < slowestFrame) { slowestFrame = playerFrame; slowestPlayer = player; } } bool isFollowing = animation == TRANSITION_WOMB_TELEPORT || animation == TRANSITION_PORTAL_TELEPORT || animation == TRANSITION_MINECART; if (isFollowing && slowestPlayer && idlePlayer && slowestFrame >= FOLLOW_MIN_FRAME) { idlePlayer->PlayExtraAnimation(slowestPlayer->sprite.animState.GetAnimation()); idlePlayer->moveToTarget = slowestPlayer->moveToTarget; if (animation == TRANSITION_MINECART && minecartNpc) { float angle = (float)Random() * RANDOM_UNIT * RANDOM_PI * 2; float reach = (float)Random() * RANDOM_UNIT * MINECART_JITTER; idlePlayer->moveToTarget = vector_make(reach * std::cos(angle) + minecartNpc->targetPosition.x, reach * std::sin(angle) + minecartNpc->targetPosition.y); } if (animation != TRANSITION_ARENA) return; } else if (!isAllIdle && animation != TRANSITION_ARENA) return; if (animation == TRANSITION_MINECART && minecartNpc) { if (minecartNpc->state != NPC_STATE_MINECART_MOVING) minecart_launch(*minecartNpc); return; } bool isWombTeleport = animation == TRANSITION_WOMB_TELEPORT || animation == TRANSITION_PORTAL_TELEPORT; if (isWombTeleport && roomIndex == game.currentRoomIdx) { for (Entity_Player* player : game.playerManager.playerList) if (player) { player->isVisible = false; player->isControlsEnabled = true; } frame = 0; mode = TRANSITION_NONE; return; } old_room_capture(); } // Renders the room as it stands, lit, into a surface. void RoomTransition::room_capture(KAGE::Graphics::ImagePtr& surface) { KAGE::Graphics::Manager& graphics = KAGE::Graphics::manager; g_game->room->render_lighting(); graphics.render_target_push(surface.get(), KAGE::Graphics::TARGET_SCREEN_SIZE, KAGE::Graphics::PRESENT_FLUSH); graphics.Clear(); graphics.blendMode.SetMode(KAGE::Graphics::BLEND_NORMAL); g_game->room->Render(); graphics.Present(KAGE::Graphics::PRESENT_FINISH); graphics.render_target_pop(KAGE::Graphics::PRESENT_FLUSH); } // Hides the players leaving (all of them, but only the one who walked out through a door or pixelated) and renders // the room into the old room surface. A fade shows it going out, a forced boss or arena transition changing room at // once, and anything else changes room and comes in. void RoomTransition::old_room_capture() { Game& game = *g_game; bool isWalking = animation == TRANSITION_WALK || animation == TRANSITION_PIXELATION; frame = 0; if (direction != DIRECTION_NONE || is_teleport() || animation == TRANSITION_PORTAL_TELEPORT) for (Entity_Player* player : game.playerManager.playerList) if (player && (!isWalking || direction == DIRECTION_NONE || player == game.playerManager.roomTransitionPlayer)) player->isVisible = false; room_capture(oldRoomSurface); bool isChangedAtOnce = animation == TRANSITION_BOSS_FORCED || animation == TRANSITION_ARENA; if (is_fade() || isChangedAtOnce) { mode = TRANSITION_OUT; if (isChangedAtOnce) ChangeRoom(); return; } mode = TRANSITION_IN; ChangeRoom(); } // Plays the versus screen and its extra layers until the screen ends, then the room's music, and shows the HUD // again for the new room to come in at once, the players unable to shoot for 10 more frames. void RoomTransition::versus_screen_update() { Game& game = *g_game; versusScreenANM2.Update(); for (auto& [layerId, sprite] : extraLayerANM2s) sprite.Update(); if (versusScreenANM2.animState.animData && versusScreenANM2.animState.isPlaying) return; game.room->PlayMusic(); game.hud.isVisible = true; frame = duration; mode = TRANSITION_IN; for (Entity_Player* player : game.playerManager.playerList) if (player) player->fireBlockCooldown = std::max(player->fireBlockCooldown, VERSUS_FIRE_BLOCK_FRAMES); } // Ends the coming in: the boss overlay stops. Teleported players reappear (falling in from a teleport) and the // Glowing Hourglass or the D7 plays its pickup animation, the extra lives theirs (1up with its sound), all landing // next. The fades land too, the teleports through the womb, a portal, the Forgotten's body or a minecart end with the // room's entities and players updated and the players in control, and the rest end the same, the players' control // back unless a versus match runs. void RoomTransition::arrival_update() { Game& game = *g_game; Entity_Player* player = game.playerManager.roomTransitionPlayer; PlayerManager& players = game.playerManager; boss_overlay_stop(game); frame = 0; mode = TRANSITION_LANDING; if (is_teleport()) { for (Entity_Player* teleported : players.playerList) { if (!teleported) continue; if (animation == TRANSITION_TELEPORT) teleported->PlayExtraAnimation(ANIMATION_TELEPORT_DOWN); if (!(teleported->flags & FLAG_HELD)) teleported->isVisible = true; } if (animation == TRANSITION_GLOWING_HOURGLASS && player) player->AnimateCollectible(COLLECTIBLE_GLOWING_HOURGLASS, ANIMATION_PICKUP, ANIMATION_PICKUP_SPARKLE); else if (animation == TRANSITION_D7 && player) player->AnimateCollectible(COLLECTIBLE_D7, ANIMATION_PICKUP, ANIMATION_PICKUP_SPARKLE); return; } switch (animation) { case TRANSITION_ONE_UP: { int sound = SOUND_ONE_UP; seed_fart_sound_override(&sound); g_manager->sfxManager.Play(sound); [[fallthrough]]; } case TRANSITION_ANKH: case TRANSITION_DEAD_CAT: case TRANSITION_COLLAR: case TRANSITION_JUDAS_SHADOW: case TRANSITION_LAZARUS: if (player) player->AnimateCollectible(EXTRA_LIFE_ITEMS[animation - TRANSITION_ANKH], ANIMATION_PICKUP, ANIMATION_PICKUP_SPARKLE); return; case TRANSITION_MISSING_POSTER: if (player) player->AnimateTrinket(TRINKET_MISSING_POSTER, ANIMATION_PICKUP, ANIMATION_PICKUP_SPARKLE); return; case TRANSITION_FADE: case TRANSITION_PIXELATION: case TRANSITION_FADE_MIRROR: case TRANSITION_DEATH_CERTIFICATE: return; default: break; } bool isTeleported = animation == TRANSITION_WOMB_TELEPORT || animation == TRANSITION_PORTAL_TELEPORT || animation == TRANSITION_FORGOTTEN_TELEPORT || animation == TRANSITION_MINECART; game.room->entityList.Update(UPDATE_TRANSITION); for (Entity_Player* arrived : players.playerList) { if (!arrived) continue; if (!isTeleported && game.deathmatchManager.state < DEATHMATCH_INTRO) arrived->isControlsEnabled = true; arrived->Update(); if (isTeleported) arrived->isControlsEnabled = true; } mode = TRANSITION_NONE; } // Waits on the players' landing (a teleport's sound on its 8th frame): the room updates, and players playing an // animation that does not loop update until none plays one (of 5 letters or more) other than a death. Then they show // and take control again. void RoomTransition::landing_update() { Game& game = *g_game; bool isLanded = true; if (animation == TRANSITION_TELEPORT && frame == TELEPORT_SOUND_FRAME) { int sound = SOUND_TELEPORT_LAND; seed_fart_sound_override(&sound); g_manager->sfxManager.Play(sound); } frame++; game.room->entityList.Update(UPDATE_TRANSITION); for (Entity_Player* player : game.playerManager.playerList) { if (!player || !is_animating(*player)) continue; player->Update(); std::string_view name; if (player->sprite.animState.animData) name = player->sprite.animState.animData->name; bool isPlaying = player->isPlayingExtraAnimation || player->isPlayingItemAnimation; bool isHolding = isPlaying && name.size() >= ANIMATION_DEATH_SUFFIX.size() && !name.ends_with(ANIMATION_DEATH_SUFFIX); isLanded = isLanded && !isHolding; } if (!isLanded) return; mode = TRANSITION_NONE; frame = 0; for (Entity_Player* player : game.playerManager.playerList) if (player) { player->isControlsEnabled = true; if (!(player->flags & FLAG_HELD)) player->isVisible = true; } } // 008318a0 Steps the transition: capturing the old room, the old room going (or the versus screen) and the new one // coming in frame by frame, then the landing. While a room goes or comes the HUD redraws in full, and progress follows // the frame. void RoomTransition::Update() { Game& game = *g_game; Entity* cart = minecart.get(); Entity_NPC* minecartNpc = cart && cart->type == ENTITY_MINECART && cart->variant == MINECART_RIDDEN ? static_cast(cart) : nullptr; switch (mode) { case TRANSITION_START: start_update(minecartNpc); break; case TRANSITION_OUT: if (bossIntroBossId != 0) versus_screen_update(); else if (frame < duration) frame++; else { frame = 0; mode = TRANSITION_IN; ChangeRoom(); } break; case TRANSITION_IN: if (frame < duration) frame++; else arrival_update(); break; case TRANSITION_LANDING: landing_update(); break; default: return; } progress = (float)frame / (float)duration; if (mode == TRANSITION_OUT || mode == TRANSITION_IN) game.hud.refresh_request(HUD_REFRESH_FULL); } // Draws the versus screen's layers about the middle of the screen, each extra layer sprite (a player's portrait) // following its layer's keyframe: its position, pivot, scale, rotation and color. static void versus_screen_render(RoomTransition& transition) { const ANM2& versus = transition.versusScreenANM2; const AnimationState& state = versus.animState; SpriteDraw draw; draw.position = vector_make(g_screenWidth * 0.5f, g_screenHeight * 0.5f); if (!state.animData) return; for (const AnimationLayer& layer : state.animData->animLayers) { const AnimationFrame* keyframe = state.GetLayerFrame(layer.layerId); if (!transition.versusScreenANM2.GetLayer(layer.layerId)->isVisible || !keyframe || !keyframe->isVisible) continue; layer.RenderFrame(draw, state.GetLayerFrameIdx(layer.layerId), versus); auto extra = transition.extraLayerANM2s.find(layer.layerId); if (extra == transition.extraLayerANM2s.end() || !extra->second.isLoaded) continue; ANM2& sprite = extra->second; float angle = keyframe->rotation * DEGREES_TO_RADIANS; float pivotX = -keyframe->pivot.x * keyframe->scale.x; float pivotY = -keyframe->pivot.y * keyframe->scale.y; sprite.color = keyframe->color; sprite.rotation = keyframe->rotation; sprite.scale = keyframe->scale; sprite.offset.x = std::cos(angle) * pivotX - std::sin(angle) * pivotY + versus.offset.x + keyframe->pos.x; sprite.offset.y = std::cos(angle) * pivotY + std::sin(angle) * pivotX + versus.offset.y + keyframe->pos.y; sprite.Render(draw); } } // 00832850 Draws the transition over the room: the versus screen while a boss intro goes out, the old and new rooms // sliding past each other (eased) through a door, or else the captured room fading to black (white for a teleport or // a mirror). void RoomTransition::Render() { KAGE::Graphics::Manager& graphics = KAGE::Graphics::manager; Vector screen = vector_make(g_screenWidth, g_screenHeight); if (mode != TRANSITION_OUT && mode != TRANSITION_IN) return; if (bossIntroBossId != 0 && mode == TRANSITION_OUT) return versus_screen_render(*this); if (is_fade()) { graphics.blendMode = KAGE::Graphics::BLEND_MODE_OPAQUE; KAGE::Graphics::ColorQuad room = KAGE::Graphics::color_quad_rect({}, screen, WHITE); (mode == TRANSITION_OUT ? oldRoomSurface : newRoomSurface)->Render(room, WHITE); graphics.blendMode.SetMode(KAGE::Graphics::BLEND_NORMAL); bool isWhite = animation == TRANSITION_TELEPORT || animation == TRANSITION_FADE_MIRROR; float shade = isWhite ? 1 : 0; render_color_shader_pass( KAGE::Graphics::color_quad_rect({}, screen, kcolor_rgba(shade, shade, shade, 1 - get_hud_alpha()))); return; } float eased = (3 - 2 * progress) * progress * progress; Vector oldPosition{}; Vector newPosition{}; float width = slideOffset.x + g_screenWidth; float height = slideOffset.y + g_screenHeight; switch (direction) { case DIRECTION_LEFT: oldPosition.x = width * eased; newPosition.x = (eased - 1) * width; break; case DIRECTION_UP: oldPosition.y = height * eased; newPosition.y = (eased - 1) * height; break; case DIRECTION_RIGHT: oldPosition.x = -eased * width; newPosition.x = (1 - eased) * width; break; case DIRECTION_DOWN: oldPosition.y = -eased * height; newPosition.y = (1 - eased) * height; break; default: break; } graphics.blendMode.SetMode(KAGE::Graphics::BLEND_NORMAL); oldRoomSurface->Render(KAGE::Graphics::color_quad_rect(oldPosition, screen, WHITE), kcolor_rgba(1, 1, 1, 1 - eased)); newRoomSurface->Render(KAGE::Graphics::color_quad_rect(newPosition, screen, WHITE), kcolor_rgba(1, 1, 1, eased)); } // 0082ee30 Whether a transition runs. bool RoomTransition::is_active() { return mode != TRANSITION_NONE; } // 006f0070 Whether a transition shows a boss's versus screen. bool RoomTransition::is_versus_screen() { return mode != TRANSITION_NONE && bossIntroBossId != 0; } // 0082eb90 Whether the players teleport out: a teleport, a womb teleport, the Glowing Hourglass or the D7. bool RoomTransition::is_teleport() { return animation == TRANSITION_TELEPORT || animation == TRANSITION_GLOWING_HOURGLASS || animation == TRANSITION_D7 || animation == TRANSITION_WOMB_TELEPORT; } // Whether the rooms fade rather than slide: every animation but a walk, the maze, the extra lives and the forced boss // one, and any without a direction. bool RoomTransition::is_fade() { switch (animation) { case TRANSITION_FADE: case TRANSITION_PIXELATION: case TRANSITION_WOMB_TELEPORT: case TRANSITION_PORTAL_TELEPORT: case TRANSITION_FORGOTTEN_TELEPORT: case TRANSITION_FADE_MIRROR: case TRANSITION_MINECART: case TRANSITION_DEATH_CERTIFICATE: return true; default: return direction == DIRECTION_NONE; } } // 008327e0 How much of the HUD and minimap shows: a fade dims them with the room, anything else leaves them. float RoomTransition::get_hud_alpha() { if (mode == TRANSITION_OUT && is_fade()) return 1 - progress; if (mode == TRANSITION_IN && is_fade()) return progress; return 1; } // 00832fd0 How far the screen has faded out, by frames: rising going out, falling coming in, -1 otherwise. float RoomTransition::get_fade_progress() { if (mode != TRANSITION_OUT && mode != TRANSITION_IN) return -1; float phase = (float)frame / (float)duration; return mode == TRANSITION_IN ? 1 - phase : phase; }