2236 lines
103 KiB
C++
2236 lines
103 KiB
C++
#include "level/backdrop.h"
|
|
#include "entity/boss/pool.h"
|
|
#include "engine/data.h"
|
|
#include "entity/entity.h"
|
|
#include "entity/config.h"
|
|
#include "entity/effect/effect.h"
|
|
#include "entity/player/player.h"
|
|
#include "engine/fx_layers.h"
|
|
#include "game/game.h"
|
|
#include "level/grid/grid_entity.h"
|
|
#include "engine/kage_input.h"
|
|
#include "game/key_configs.h"
|
|
#include "engine/log.h"
|
|
#include "game/manager.h"
|
|
#include "ui/menu/manager.h"
|
|
#include "entity/npc/ai.h"
|
|
#include "engine/platform.h"
|
|
#include "engine/render_passes.h"
|
|
#include "level/room.h"
|
|
#include "level/room_config.h"
|
|
#include "engine/seeds.h"
|
|
#include <algorithm>
|
|
#include <cmath>
|
|
#include <cstdlib>
|
|
#ifdef ISAAC_REPENTOGON
|
|
#include "repentogon/callbacks.h"
|
|
#endif
|
|
|
|
constexpr std::string_view DEFAULT_PROPS = "gfx/grid/props_01_basement.anm2";
|
|
constexpr std::string_view DEFAULT_ROCKS = "gfx/grid/rocks_basement.png";
|
|
constexpr std::string_view DEFAULT_PIT = "gfx/grid/grid_pit.png";
|
|
constexpr std::string_view DEFAULT_WATER_PIT = "gfx/grid/grid_pit_water.png";
|
|
constexpr std::string_view DEFAULT_BRIDGE = "gfx/grid/grid_bridge.png";
|
|
constexpr std::string_view DEFAULT_DOOR = "gfx/grid/door_01_normaldoor.png";
|
|
constexpr std::string_view DEFAULT_HOLE_IN_WALL = "gfx/grid/door_08_holeinwall.png";
|
|
constexpr std::string_view DEFAULT_SPIKES = "gfx/grid/grid_spikes.png";
|
|
|
|
// The surfaces the backdrop draws into, each the size of the largest room.
|
|
constexpr int SURFACE_WIDTH = 780;
|
|
constexpr int SURFACE_HEIGHT = 468;
|
|
constexpr const char* SURFACE_NAMES[] = {"Floor Surface", "Wall Surface", "Floor Surface 2", "Temp Backdrop Surface"};
|
|
|
|
constexpr uint32_t BACKDROP_SEED_DEFAULT = 0x11111111;
|
|
// The xorshift triples (5, 9, 7), (4, 3, 27) and (5, 15, 17).
|
|
constexpr uint32_t RNG_SHIFT_DEFAULT = 35;
|
|
constexpr uint32_t RNG_SHIFT_LEVEL_FLOOR = 31;
|
|
constexpr uint32_t RNG_SHIFT_CONTROLS = 39;
|
|
|
|
// A room's grid cells on the surfaces, and the walls two cells thick that frame its floor.
|
|
constexpr float GRID_SIZE = 26;
|
|
constexpr float WALL_SIZE = WALL_CELLS * GRID_SIZE;
|
|
|
|
constexpr uint32_t FLOOR_SECOND = 1;
|
|
constexpr uint32_t HOME_CLOSET_FIRST_SUBTYPE = 10;
|
|
|
|
// Where Mega Satan's floor sprite draws past the room's corner, and the half cell its surface reaches past the walls.
|
|
constexpr float MEGA_SATAN_FLOOR_X = 0;
|
|
constexpr float MEGA_SATAN_FLOOR_Y = 130;
|
|
constexpr float MEGA_SATAN_BORDER = GRID_SIZE / 2;
|
|
constexpr std::string_view MEGA_SATAN_CLOSED_ANIMATION = "Idle2";
|
|
constexpr std::string_view MEGA_SATAN_OPEN_ANIMATION = "Idle1";
|
|
|
|
// The sheets cut into blocks of 9 by 6 cells, two to a row: a corner, the walls, and a quarter of a floor, each block
|
|
// one variant.
|
|
constexpr int BLOCK_WIDTH = 9;
|
|
constexpr int BLOCK_HEIGHT = 6;
|
|
constexpr int BLOCK_FLOOR = 2;
|
|
constexpr int TILE_WIDTH = 7;
|
|
constexpr int TILE_HEIGHT = 4;
|
|
constexpr int TILE_STEP_X = 6;
|
|
constexpr int TILE_STEP_Y = 3;
|
|
constexpr size_t FLOOR_TILES_MIN = 32;
|
|
|
|
// The Dark Room's and Mega Satan's fixed tiles, in texels: four floor tiles, then two for the bottom row.
|
|
constexpr int DARK_FLOOR_TILES = 4;
|
|
constexpr int DARK_EDGE_TILES = 2;
|
|
constexpr float DARK_TILES[DARK_FLOOR_TILES + DARK_EDGE_TILES][4] = {{52, 52, 234, 156}, {286, 52, 468, 156},
|
|
{52, 208, 234, 312}, {286, 208, 468, 312},
|
|
{52, 312, 234, 468}, {286, 312, 468, 468}};
|
|
|
|
// The Cathedral's big rooms: their floor in tiles of 2 by 2 cells, one of four at random, and the cell set in each
|
|
// corner of the floor.
|
|
constexpr int CATHEDRAL_TILES[4][2] = {{11, 14}, {13, 14}, {13, 16}, {11, 16}};
|
|
constexpr int CATHEDRAL_CORNER[2] = {15, 14};
|
|
constexpr float CATHEDRAL_TILE = 2 * GRID_SIZE;
|
|
constexpr float EDGE_EPSILON = 0.001f;
|
|
|
|
// A 1x1 room's floor in cells, which an L room has three of and a narrow room one row or column of.
|
|
constexpr int ROOM_FLOOR_COLUMNS = 13;
|
|
constexpr int ROOM_FLOOR_ROWS = 7;
|
|
|
|
// The L floor sheets: three quarters of the room in pieces the size of a 1x1 room's floor, two variants one under the
|
|
// other, and where each piece goes (in cells from the floor's corner) with its mirroring, by the missing quarter.
|
|
struct LFloorLayout
|
|
{
|
|
int cells[3][2];
|
|
Flip flip;
|
|
};
|
|
constexpr LFloorLayout L_FLOOR_LAYOUTS[4] = {{{{0, 7}, {13, 7}, {13, 0}}, FLIP_Y},
|
|
{{{13, 7}, {0, 7}, {0, 0}}, FLIP_XY},
|
|
{{{0, 0}, {13, 0}, {13, 7}}, FLIP_NONE},
|
|
{{{13, 0}, {0, 0}, {0, 7}}, FLIP_X}};
|
|
|
|
// The narrow floor sheets: a horizontal room's floor in rows of 3 cells under 7 rows of a vertical room's in columns
|
|
// of 5.
|
|
constexpr int NARROW_ROW_HEIGHT = 3;
|
|
constexpr int NARROW_ROW_SHEET_Y = 7;
|
|
constexpr int NARROW_COLUMN_WIDTH = 5;
|
|
|
|
// The start room's controls picture: how far under the top wall it sits, and the Burning Basement's darker tint.
|
|
constexpr float CONTROLS_Y = 91;
|
|
constexpr std::array<float, 4> CONTROLS_BURNT_TINT = {0.7f, 0.6f, 0.6f, 1};
|
|
constexpr std::array<float, 4> CONTROLS_TINT = {1, 1, 1, 1};
|
|
constexpr std::string_view CONTROLS_ANIMATION = "Controls";
|
|
constexpr std::string_view KEYBOARD_ANIMATION = "Keyboard";
|
|
constexpr std::string_view GAMEPAD_ANIMATION = "XboxOne";
|
|
constexpr int KEYBOARD_CONTROLLER = 0;
|
|
constexpr int ACTION_NONE = -1;
|
|
constexpr float SPACE_KEY_PADDING = 4;
|
|
constexpr float ICON_PADDING = 4;
|
|
constexpr float ICON_WIDTH = 8;
|
|
constexpr int GLYPH_JITTER = 3;
|
|
constexpr int JACOB_ESAU_SPLIT_CONTROLS = 1;
|
|
constexpr int ASCENT_START_ROOM = 84;
|
|
|
|
// The control icons the start room shows, a row to each of the controls picture's nulls: moving, shooting, then the
|
|
// bomb, item, card, drop and card buttons, and shooting again.
|
|
constexpr int CONTROL_ROW_COUNT = 8;
|
|
constexpr int CONTROL_ROW_ICONS = 5;
|
|
constexpr int CONTROL_ROWS[CONTROL_ROW_COUNT][CONTROL_ROW_ICONS] = {
|
|
{ACTION_UP, ACTION_LEFT, ACTION_DOWN, ACTION_RIGHT, ACTION_NONE},
|
|
{ACTION_SHOOT_UP, ACTION_SHOOT_LEFT, ACTION_SHOOT_DOWN, ACTION_SHOOT_RIGHT, ACTION_NONE},
|
|
{ACTION_BOMB, ACTION_NONE},
|
|
{ACTION_ITEM, ACTION_NONE},
|
|
{ACTION_PILL_CARD, ACTION_NONE},
|
|
{ACTION_DROP, ACTION_NONE},
|
|
{ACTION_PILL_CARD, ACTION_NONE},
|
|
{ACTION_SHOOT_UP, ACTION_SHOOT_LEFT, ACTION_SHOOT_DOWN, ACTION_SHOOT_RIGHT, ACTION_NONE}};
|
|
|
|
// The walls: one cell in three shows a variant other than its row's first, fewer in the better shops.
|
|
constexpr int WALL_VARIANT_CHANCE = 3;
|
|
constexpr int SHOP_LEVEL_FIRST_CHANCE = 2;
|
|
constexpr int SHOP_WALL_CHANCES[4] = {4, 3, 2, 1};
|
|
constexpr int CORNER_COUNT = 4;
|
|
constexpr int WALL_EDGE_COLUMNS = 7;
|
|
constexpr int WALL_EDGE_ROWS = 4;
|
|
constexpr int WALL_MIDDLE_COLUMN = 7;
|
|
constexpr int WALL_MIDDLE_ROW = 4;
|
|
constexpr int NARROW_ROW_INSET = 2;
|
|
constexpr int L_CORNER_SHEET_X = 18;
|
|
|
|
// The blood splats a room may start with: on world cells 40 apart, kept 20 from the walls or 100 from the middle.
|
|
constexpr float WORLD_CELL = 40;
|
|
constexpr float SPLAT_MARGIN = 20;
|
|
constexpr float SPLAT_RADIUS = 100;
|
|
constexpr float SPLAT_SQUASH = 0.6f;
|
|
constexpr float SPLAT_SCALE_MIN = 0.5f;
|
|
constexpr float SPLAT_SCALE_RANGE = 2.5f;
|
|
constexpr ColorMod CORPSE_SPLAT_COLOR = {{0.7f, 0.7f, 0.7f, 1}, {0, 0, 0, 0}, {0, 0, 0}};
|
|
|
|
// The wall surface is the world at 0.65 scale, two world cells out from the room's corner.
|
|
constexpr float SURFACE_SCALE = 0.65f;
|
|
constexpr float SURFACE_ORIGIN = 80;
|
|
constexpr float NARROW_SHIFT_X = 160;
|
|
constexpr float NARROW_SHIFT_Y = 80;
|
|
constexpr float WALL_DETAIL_CHANCE = 0.18f;
|
|
constexpr float ASHPIT_DETAIL_CHANCE = 0.45f;
|
|
constexpr int ASHPIT_DARK_WALLS = 2;
|
|
constexpr float LIGHT_SCALE = 3;
|
|
constexpr int DETAIL_RENDER_Z = 1 << 30;
|
|
constexpr int COLOR_DURATION_FOREVER = -1;
|
|
constexpr float WALL_LIGHT_OUT = 20;
|
|
constexpr ColorMod EMBER_COLOR = {{1, 0.7f, 0.5f, 1}, {0, 0, 0, 0}, {0, 0, 0}};
|
|
constexpr float BURNING_EMBER_DRAW_BACK = -8;
|
|
constexpr float BURNING_EMBER_MIN = 0.5f;
|
|
constexpr float BURNING_EMBER_RANGE = 0.3f;
|
|
constexpr float ASHPIT_EMBER_DRAW_BACK = 16;
|
|
constexpr float ASHPIT_EMBER_MIN = 0.2f;
|
|
constexpr float ASHPIT_EMBER_RANGE = 0.1f;
|
|
constexpr int CATHEDRAL_WINDOW_SLOT = 5;
|
|
constexpr int CATHEDRAL_PLAIN_VARIANT = 2;
|
|
constexpr float CATHEDRAL_LIGHT_X = 10;
|
|
constexpr float CATHEDRAL_LIGHT_Y = 20;
|
|
constexpr float CATHEDRAL_LIGHT_ANGLE = -20;
|
|
constexpr float CATHEDRAL_LIGHT_SCALE_X = 0.15f;
|
|
constexpr float CATHEDRAL_LIGHT_SCALE_Y = 0.2f;
|
|
constexpr ColorMod CATHEDRAL_LIGHT_COLOR = {{1, 0.8f, 0.7f, 0.8f}, {0, 0, 0, 0}, {0, 0, 0}};
|
|
constexpr std::string_view DANK_DETAILS = "gfx/backdrop/15_The Dank Depths_details.anm2";
|
|
constexpr int DANK_PILLAR_SLOT = 3;
|
|
constexpr int DANK_DETAIL_VARIANT = 3;
|
|
constexpr ColorMod TAR_COLOR = {{0, 0, 0, 0.8f}, {0, 0, 0, 0}, {0x1.010102p-4f, 0x1.e1e1e4p-5f, 0x1.515152p-4f}};
|
|
constexpr float TAR_OUT_MIN = 20;
|
|
constexpr float TAR_OUT_RANGE = 40;
|
|
constexpr float TAR_SHIFT_RANGE = 10;
|
|
constexpr float TAR_SCALE_RANGE = 4;
|
|
constexpr int DROSS_LIGHT_FIRST = 3;
|
|
constexpr int DROSS_LIGHT_ODDS = 40;
|
|
constexpr float DROSS_LIGHT_SCALE = 0.5f;
|
|
constexpr ColorMod DROSS_LIGHT_COLOR = {{0.9f, 0.9f, 1, 1}, {0, 0, 0, 0}, {0, 0, 0}};
|
|
constexpr float DROSS_PIPE_REACH = 40;
|
|
constexpr GridEntityType DROSS_PIPE_BLOCKERS[] = {GRID_ROCK, GRID_ROCKB, GRID_ROCKT, GRID_ROCK_BOMB,
|
|
GRID_ROCK_ALT, GRID_LOCK, GRID_TNT, GRID_POOP};
|
|
constexpr float DROSS_LEAK_SIDE[2] = {6, 28};
|
|
constexpr float DROSS_LEAK_TOP[2] = {10, 24};
|
|
constexpr float DROSS_LEAK_RANGE = 0.4f;
|
|
constexpr int DOOR_SIDE_SLOT = 2;
|
|
constexpr int MINES_LANTERN_ODDS = 4;
|
|
constexpr int MAUSOLEUM_TORCH_ODDS = 3;
|
|
constexpr int GEHENNA_CHAIN_ODDS = 3;
|
|
|
|
// RenderFloor: the Error room's floor sprite repeats every 100 pixels.
|
|
constexpr float ERROR_TILE = 100;
|
|
|
|
// render_wall_borders: black over everything outside the room, and the corner an L room lacks.
|
|
constexpr KColor BORDER_COLOR = kcolor_rgba(0, 0, 0, 1);
|
|
constexpr float NARROW_BORDER_X = 104;
|
|
constexpr float NARROW_BORDER_Y = 52;
|
|
constexpr float L_BORDER_WIDTH = 364;
|
|
constexpr float L_BORDER_HEIGHT = 208;
|
|
|
|
constexpr const char* COLOR_OFFSET_SHADER = "ColorOffset";
|
|
|
|
constexpr Flip operator|(Flip first, Flip second)
|
|
{
|
|
return Flip((int)first | (int)second);
|
|
}
|
|
|
|
static bool is_l_shape(int shape)
|
|
{
|
|
return shape >= ROOMSHAPE_LTL && shape <= ROOMSHAPE_LBR;
|
|
}
|
|
|
|
static bool is_narrow_shape(int shape)
|
|
{
|
|
return shape == ROOMSHAPE_IH || shape == ROOMSHAPE_IV || shape == ROOMSHAPE_IIV || shape == ROOMSHAPE_IIH;
|
|
}
|
|
|
|
static bool is_horizontal_narrow(int shape)
|
|
{
|
|
return shape == ROOMSHAPE_IH || shape == ROOMSHAPE_IIH;
|
|
}
|
|
|
|
static bool is_vertical_narrow(int shape)
|
|
{
|
|
return shape == ROOMSHAPE_IV || shape == ROOMSHAPE_IIV;
|
|
}
|
|
|
|
static bool is_ashpit(uint32_t id)
|
|
{
|
|
return id == BACKDROP_ASHPIT || id == BACKDROP_ASHPIT_SHAFT;
|
|
}
|
|
|
|
// 009321c0 An empty backdrop with its four surfaces made and its generator seeded.
|
|
Backdrop::Backdrop()
|
|
{
|
|
std::array<KAGE::Graphics::ImagePtr*, 4> surfaces = {&floorBuffer, &wallsBuffer, &floorSurface2,
|
|
&tempBackdropSurface};
|
|
for (size_t i = 0; i < surfaces.size(); i++)
|
|
{
|
|
KAGE::Graphics::RenderTargetDesc desc;
|
|
desc.name = SURFACE_NAMES[i];
|
|
desc.width = SURFACE_WIDTH;
|
|
desc.height = SURFACE_HEIGHT;
|
|
*surfaces[i] = KAGE::Graphics::manager.render_target_create(desc);
|
|
}
|
|
seed = BACKDROP_SEED_DEFAULT;
|
|
rng.SetSeed(BACKDROP_SEED_DEFAULT, RNG_SHIFT_DEFAULT);
|
|
}
|
|
|
|
// An attribute as the game reads booleans: "true", "True" or a nonzero number.
|
|
static bool is_attr_true(std::string_view value)
|
|
{
|
|
return value == "true" || value == "True" || std::atoi(std::string(value).c_str()) != 0;
|
|
}
|
|
|
|
static int attr_int(DataNode node, std::string_view name)
|
|
{
|
|
return std::atoi(std::string(node_attr(node, name)).c_str());
|
|
}
|
|
|
|
// A grid graphic's path under the grid root, or none for an empty value.
|
|
static std::string grid_path(std::string_view root, std::string_view value)
|
|
{
|
|
return value.empty() ? std::string() : std::string(root) + std::string(value);
|
|
}
|
|
|
|
// A <backdrop>, starting from the default config. Sheets go under the backdrop root, grid graphics under the grid root.
|
|
static BackdropConfig config_load(DataNode node, const BackdropConfig& base, std::string_view gfxRoot,
|
|
std::string_view gridRoot)
|
|
{
|
|
BackdropConfig config = base;
|
|
|
|
for (auto [name, value] : node_attrs(node))
|
|
{
|
|
std::string sheet = std::string(gfxRoot) + std::string(value);
|
|
|
|
if (name == "id") config.backdropId = attr_int(node, name);
|
|
else if (name == "gfx") config.gfx = sheet;
|
|
else if (name == "lfloorgfx") config.lFloorGfx = sheet;
|
|
else if (name == "nfloorgfx") config.nFloorGfx = sheet;
|
|
else if (name == "watergfx") config.waterGfx = sheet;
|
|
else if (name == "walls") config.walls = attr_int(node, name);
|
|
else if (name == "wallvariants") config.wallVariants = attr_int(node, name);
|
|
else if (name == "floors") config.floors = attr_int(node, name);
|
|
else if (name == "floorvariants") config.floorVariants = attr_int(node, name);
|
|
else if (name == "fullimage") config.isFullImage = is_attr_true(value);
|
|
else if (name == "props") config.props = grid_path(gridRoot, value);
|
|
else if (name == "rocks") config.rocks = grid_path(gridRoot, value);
|
|
else if (name == "pit") config.pit = grid_path(gridRoot, value);
|
|
else if (name == "waterpit") config.waterPit = grid_path(gridRoot, value);
|
|
else if (name == "bridge") config.bridge = grid_path(gridRoot, value);
|
|
else if (name == "door") config.door = grid_path(gridRoot, value);
|
|
else if (name == "holeinwall") config.holeInWall = grid_path(gridRoot, value);
|
|
else if (name == "spikes") config.spikes = grid_path(gridRoot, value);
|
|
else if (name == "waterpitsmode") config.waterPitsMode = (uint8_t)attr_int(node, name);
|
|
else if (name == "reversewatergfx") config.isReverseWaterGfx = is_attr_true(value);
|
|
}
|
|
return config;
|
|
}
|
|
|
|
// 00932810 Reads backdrops.xml into the configs, ids 1 to 62, each starting from the default config (id 0) of the
|
|
// basement's grid graphics. The effects root is read but unused. False when the file is missing.
|
|
bool Backdrop::LoadConfig(std::string_view path)
|
|
{
|
|
Data data;
|
|
|
|
data_load(data, path);
|
|
if (!data.isLoaded) return false;
|
|
if (node_tag(data.root) != "backdrops")
|
|
{
|
|
// The original reads on from a missing root and crashes.
|
|
log_printf(LOG_ASSERT, "Could not find root node 'backdrops' in %.*s\n", (int)path.size(), path.data());
|
|
return true;
|
|
}
|
|
|
|
std::string_view gfxRoot = node_attr(data.root, "gfxroot");
|
|
std::string_view gridRoot = node_attr(data.root, "gridgfxroot");
|
|
BackdropConfig& base = configs[0];
|
|
base = BackdropConfig();
|
|
base.props = DEFAULT_PROPS;
|
|
base.rocks = DEFAULT_ROCKS;
|
|
base.pit = DEFAULT_PIT;
|
|
base.waterPit = DEFAULT_WATER_PIT;
|
|
base.bridge = DEFAULT_BRIDGE;
|
|
base.door = DEFAULT_DOOR;
|
|
base.holeInWall = DEFAULT_HOLE_IN_WALL;
|
|
base.spikes = DEFAULT_SPIKES;
|
|
|
|
for (DataNode node : node_children(data.root))
|
|
{
|
|
BackdropConfig config = config_load(node, base, gfxRoot, gridRoot);
|
|
if (config.backdropId >= 1 && config.backdropId < BACKDROP_COUNT) configs[config.backdropId] = config;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
// 0093d960 Takes a backdrop for the current room (backdrop 1 for an id out of range) and the room's corners, and
|
|
// loads its graphics if asked.
|
|
void Backdrop::Init(uint32_t id, bool isLoadGraphics)
|
|
{
|
|
#ifdef ISAAC_REPENTOGON
|
|
CallbackRun run = {"PreBackdropChange", MC_PRE_BACKDROP_CHANGE, std::nullopt};
|
|
id = (uint32_t)callback_integer_run(lua_engine_get(), run, (int)id, id);
|
|
#endif
|
|
Room& room = *g_game->room;
|
|
|
|
backdropId = (int)id < 0 || (int)id >= BACKDROP_COUNT ? 1 : id;
|
|
roomTopLeft = vector_make(WALL_SIZE, WALL_SIZE);
|
|
roomBottomRight = vector_make((float)((int)room.gridWidth - WALL_CELLS) * GRID_SIZE + WALL_SIZE,
|
|
(float)((int)room.gridHeight - WALL_CELLS) * GRID_SIZE + WALL_SIZE);
|
|
if (isLoadGraphics) load_details();
|
|
}
|
|
|
|
// 00935270 A floor variant for the room: one of the backdrop's floors at random, with exceptions by backdrop and room.
|
|
// Dross and Mausoleum's large rooms leave out the last floor, Ashpit keeps one floor per level and shows the second in
|
|
// rooms with the alternate backdrop, Gehenna keeps one floor per level.
|
|
uint32_t Backdrop::get_random_floor_variant()
|
|
{
|
|
RoomDescriptor* descriptor = g_game->room->descriptor;
|
|
uint32_t floors = (uint32_t)configs[backdropId].floors;
|
|
RNG levelRng = {};
|
|
levelRng.SetSeed(seed, RNG_SHIFT_LEVEL_FLOOR);
|
|
|
|
switch (backdropId)
|
|
{
|
|
case BACKDROP_DROSS:
|
|
if (descriptor->flags & ROOM_DESCRIPTOR_FLAG_USE_ALTERNATE_BACKDROP) return rng.RandomInt(floors - 1);
|
|
break;
|
|
case BACKDROP_ASHPIT:
|
|
case BACKDROP_ASHPIT_SHAFT:
|
|
return descriptor->flags & ROOM_DESCRIPTOR_FLAG_USE_ALTERNATE_BACKDROP ? FLOOR_SECOND
|
|
: levelRng.RandomInt(floors);
|
|
case BACKDROP_MAUSOLEUM:
|
|
case BACKDROP_MAUSOLEUM2:
|
|
if (descriptor && descriptor->data && descriptor->data->shape != ROOMSHAPE_1x1)
|
|
return rng.RandomInt(floors - 1);
|
|
break;
|
|
case BACKDROP_GEHENNA: return levelRng.RandomInt(floors);
|
|
}
|
|
return rng.RandomInt(floors);
|
|
}
|
|
|
|
// A quad by its edges, corners in KAGE's order.
|
|
static DestinationQuad quad_edges(float left, float top, float right, float bottom)
|
|
{
|
|
DestinationQuad quad;
|
|
|
|
quad._topLeft = vector_make(left, top);
|
|
quad._topRight = vector_make(right, top);
|
|
quad._bottomLeft = vector_make(left, bottom);
|
|
quad._bottomRight = vector_make(right, bottom);
|
|
return quad;
|
|
}
|
|
|
|
// A rectangle of texels by its edges, mirrored as asked.
|
|
static SourceQuad source_edges(float left, float top, float right, float bottom, Flip flip)
|
|
{
|
|
SourceQuad source;
|
|
bool isFlipX = flip & FLIP_X;
|
|
bool isFlipY = flip & FLIP_Y;
|
|
|
|
static_cast<DestinationQuad&>(source) =
|
|
quad_edges(isFlipX ? right : left, isFlipY ? bottom : top, isFlipX ? left : right, isFlipY ? top : bottom);
|
|
source._coordinateSpace = KAGE::Graphics::COORDINATES_PIXEL;
|
|
return source;
|
|
}
|
|
|
|
// 00932090 The texels of a rectangle of a sheet's cells, mirrored as asked.
|
|
static SourceQuad source_cells(int x, int y, int width, int height, Flip flip = FLIP_NONE)
|
|
{
|
|
return source_edges((float)x * GRID_SIZE, (float)y * GRID_SIZE, (float)(x + width) * GRID_SIZE,
|
|
(float)(y + height) * GRID_SIZE, flip);
|
|
}
|
|
|
|
// (00931f50, 00931fc0, 00932020) A source rectangle mirrored across x, y or both.
|
|
static SourceQuad source_flip(const SourceQuad& source, Flip flip)
|
|
{
|
|
return source_edges(source._topLeft.x, source._topLeft.y, source._bottomRight.x, source._bottomRight.y, flip);
|
|
}
|
|
|
|
// The cells of a rectangle inside a variant's block of a sheet.
|
|
static SourceQuad block_cells(uint32_t block, int x, int y, int width, int height, Flip flip)
|
|
{
|
|
return source_cells((int)(block & 1) * BLOCK_WIDTH + x, (int)(block >> 1) * BLOCK_HEIGHT + y, width, height, flip);
|
|
}
|
|
|
|
// Draws a rectangle of an image into a quad, in its own colors. Returns the vertices, as ImageBase::Render does.
|
|
static float* image_draw(KAGE::Graphics::ImageBase& image, const SourceQuad& source, const DestinationQuad& quad)
|
|
{
|
|
return image.Render(source, KAGE::Graphics::ColorQuad(quad, WHITE), WHITE);
|
|
}
|
|
|
|
// Makes the ColorOffset shader current, when it is loaded.
|
|
static void color_offset_shader_select()
|
|
{
|
|
if (KAGE::Graphics::Shader* shader = KAGE::Graphics::manager.shader_find(COLOR_OFFSET_SHADER))
|
|
KAGE::Graphics::manager.currentShader = shader;
|
|
}
|
|
|
|
// Turns the screen shake off for the sprites drawn into a surface, or back on.
|
|
static void screen_shake_set(bool isApplied)
|
|
{
|
|
DAT_00c33910 = isApplied;
|
|
}
|
|
|
|
// 00932120 The quad of a rectangle of grid cells, in surface pixels from the room's floor corner.
|
|
DestinationQuad Backdrop::render_grid_rect(int x, int y, int width, int height)
|
|
{
|
|
return quad_edges((float)x * GRID_SIZE + roomTopLeft.x, (float)y * GRID_SIZE + roomTopLeft.y,
|
|
(float)(width + x) * GRID_SIZE + roomTopLeft.x, (float)(height + y) * GRID_SIZE + roomTopLeft.y);
|
|
}
|
|
|
|
// The wall details of a backdrop with them: the Downpour's pipes, the Mines' and Ashpit's (dark in a pitch black room
|
|
// or the abandoned mineshaft), Mausoleum's chains and Gehenna's. None for the others.
|
|
static std::string_view wall_details_path_get(uint32_t backdropId)
|
|
{
|
|
bool isDark = g_game->room->descriptor->flags & ROOM_DESCRIPTOR_FLAG_PITCH_BLACK;
|
|
|
|
switch (backdropId)
|
|
{
|
|
case BACKDROP_DOWNPOUR: return "gfx/backdrop/01x_downpour_pipes.anm2";
|
|
case BACKDROP_MINES:
|
|
case BACKDROP_MINES_SHAFT:
|
|
if (isDark || backdropId == BACKDROP_MINES_SHAFT) return "gfx/backdrop/03x_mines_details_dark.anm2";
|
|
return "gfx/backdrop/03x_mines_details.anm2";
|
|
case BACKDROP_MAUSOLEUM4: return "gfx/backdrop/05x_mausoleum_chains.anm2";
|
|
case BACKDROP_ASHPIT:
|
|
case BACKDROP_ASHPIT_SHAFT:
|
|
if (isDark || backdropId == BACKDROP_ASHPIT_SHAFT) return "gfx/backdrop/04x_ashpit_details_dark.anm2";
|
|
return "gfx/backdrop/04x_ashpit_details.anm2";
|
|
case BACKDROP_GEHENNA: return "gfx/backdrop/06x_gehenna_details.anm2";
|
|
default: return {};
|
|
}
|
|
}
|
|
|
|
// Mega Satan's floor, drawn once into the floor surface from its closed animation, then left on the open one.
|
|
static void mega_satan_floor_render(Backdrop& backdrop)
|
|
{
|
|
KAGE::Graphics::Manager& graphics = KAGE::Graphics::manager;
|
|
|
|
graphics.SetRenderTarget(backdrop.floorBuffer.get(), KAGE::Graphics::TARGET_OWN_SIZE);
|
|
graphics.Clear();
|
|
KAGE::Graphics::BlendMode savedBlend = graphics.blendMode;
|
|
graphics.blend_set(KAGE::Graphics::BLEND_NORMAL);
|
|
backdrop.floorSprite.Play(MEGA_SATAN_CLOSED_ANIMATION);
|
|
graphics.isCullOffscreen = false;
|
|
backdrop.floorSprite.Render({.position = vector_make(MEGA_SATAN_FLOOR_X + backdrop.roomTopLeft.x,
|
|
MEGA_SATAN_FLOOR_Y + backdrop.roomTopLeft.y)});
|
|
graphics.isCullOffscreen = true;
|
|
graphics.blendMode = savedBlend;
|
|
graphics.Present(KAGE::Graphics::PRESENT_FINISH);
|
|
backdrop.floorSprite.Play(MEGA_SATAN_OPEN_ANIMATION);
|
|
}
|
|
|
|
// 0093da00 Loads the room's backdrop graphics and draws its surfaces: the controls sprites once, then the one sprite
|
|
// floors (the Error room's, Mega Satan's drawn into the floor surface, the Planetarium's by the room's shape, Home's
|
|
// closets by their side and Dogma's), or the walls and floor sheets, the water, an L or narrow room's floor and the
|
|
// wall details, drawn into the wall and floor surfaces. The render target is back as it was after.
|
|
void Backdrop::load_details()
|
|
{
|
|
KAGE::Graphics::Manager& graphics = KAGE::Graphics::manager;
|
|
RoomConfig_Room* data = g_game->room->descriptor ? g_game->room->descriptor->data : nullptr;
|
|
RoomShape shape = data ? data->shape : ROOMSHAPE_1x1;
|
|
BackdropConfig& config = configs[backdropId];
|
|
|
|
isTempSurfaceUsed = false;
|
|
floorSprite.Reset();
|
|
wallDetailSprite.Reset();
|
|
if (!controlsSprite.isLoaded) controlsSprite.Load("gfx/backdrop/controls.anm2", GRAPHICS_LOAD);
|
|
if (!controlsButtonsSprite.isLoaded)
|
|
controlsButtonsSprite.Load("gfx/backdrop/controls_buttons.anm2", GRAPHICS_LOAD);
|
|
auto size = graphics.isScreenTarget ? KAGE::Graphics::TARGET_SCREEN_SIZE : KAGE::Graphics::TARGET_OWN_SIZE;
|
|
graphics.render_target_push(graphics.renderTarget, size, KAGE::Graphics::PRESENT_FLUSH);
|
|
waterGfx.reset();
|
|
|
|
switch (backdropId)
|
|
{
|
|
case BACKDROP_ERROR_ROOM:
|
|
case BACKDROP_MEGA_SATAN:
|
|
floorSprite.Load(config.gfx, GRAPHICS_LOAD);
|
|
if (backdropId == BACKDROP_MEGA_SATAN) mega_satan_floor_render(*this);
|
|
break;
|
|
case BACKDROP_PLANETARIUM:
|
|
floorSprite.Load(config.gfx, GRAPHICS_LOAD);
|
|
floorSprite.SetFrame("Idle", 0);
|
|
for (int i = 0; i < (int)floorSprite.layerStates.size(); i++)
|
|
floorSprite.GetLayer(i)->isVisible = i + 1 == shape;
|
|
break;
|
|
case BACKDROP_CLOSET:
|
|
case BACKDROP_CLOSET_B:
|
|
case BACKDROP_DOGMA:
|
|
floorSprite.Load(config.gfx, GRAPHICS_LOAD);
|
|
floorSprite.SetFrame("Idle",
|
|
backdropId == BACKDROP_DOGMA ? 0 : data->subtype - (int)HOME_CLOSET_FIRST_SUBTYPE);
|
|
graphics.isCullOffscreen = false;
|
|
render_ashpit_ash();
|
|
graphics.isCullOffscreen = true;
|
|
break;
|
|
default:
|
|
{
|
|
if (!config.gfx.empty()) gfx = Manager::LoadImage(config.gfx);
|
|
if (!config.waterGfx.empty())
|
|
{
|
|
waterGfx = Manager::LoadImage(config.waterGfx);
|
|
if (waterGfx && (waterGfx->wrapS != 0 || waterGfx->wrapT != 0)) waterGfx->wrap_set(0, 0);
|
|
}
|
|
if (is_l_shape(g_game->room->descriptor->data->shape) && !config.lFloorGfx.empty())
|
|
nlFloorGfx = Manager::LoadImage(config.lFloorGfx);
|
|
else if (!config.nFloorGfx.empty() && is_narrow_shape(g_game->room->GetRoomShape()))
|
|
nlFloorGfx = Manager::LoadImage(config.nFloorGfx);
|
|
|
|
std::string_view detailsPath = wall_details_path_get(backdropId);
|
|
if (!detailsPath.empty())
|
|
{
|
|
wallDetailSprite.Load(detailsPath, GRAPHICS_LOAD);
|
|
wallDetailSprite.Play(wallDetailSprite.GetDefaultAnimationName());
|
|
}
|
|
if (!gfx) break;
|
|
|
|
graphics.isCullOffscreen = false;
|
|
render_ashpit_ash();
|
|
pre_render_walls();
|
|
#ifdef ISAAC_REPENTOGON
|
|
callback_notify(lua_engine_get(), {"MC_POST_BACKDROP_PRE_RENDER_WALLS", MC_POST_BACKDROP_PRE_RENDER_WALLS,
|
|
std::nullopt});
|
|
#endif
|
|
graphics.isCullOffscreen = true;
|
|
gfx.reset();
|
|
nlFloorGfx.reset();
|
|
}
|
|
}
|
|
graphics.render_target_pop(KAGE::Graphics::PRESENT_FLUSH);
|
|
}
|
|
|
|
// 009353b0 Draws the floor surface: Ashpit's ash floor in rooms with the alternate backdrop (with its L or narrow
|
|
// overlay), the closets' and Dogma's floor sprite, or the backdrop's own floor sheets. The floor variant is drawn
|
|
// first, and drawn again for the backdrop's own sheets.
|
|
void Backdrop::render_ashpit_ash()
|
|
{
|
|
KAGE::Graphics::Manager& graphics = KAGE::Graphics::manager;
|
|
Room& room = *g_game->room;
|
|
uint32_t variant = get_random_floor_variant();
|
|
|
|
if (is_ashpit(backdropId) && (room.descriptor->flags & ROOM_DESCRIPTOR_FLAG_USE_ALTERNATE_BACKDROP))
|
|
{
|
|
KAGE::Graphics::ImagePtr ash = Manager::LoadImage("gfx/backdrop/04x_ashpit_ash.png");
|
|
KAGE::Graphics::ImagePtr overlay;
|
|
if (is_l_shape(room.descriptor->data->shape))
|
|
overlay = Manager::LoadImage("gfx/backdrop/04x_ashpit_ash_Lfloor.png");
|
|
else if (is_narrow_shape(room.GetRoomShape()))
|
|
overlay = Manager::LoadImage("gfx/backdrop/04x_ashpit_ash_Nfloor.png");
|
|
render_floor_to_target(variant, ash, overlay);
|
|
return;
|
|
}
|
|
if (backdropId == BACKDROP_CLOSET || backdropId == BACKDROP_CLOSET_B || backdropId == BACKDROP_DOGMA)
|
|
{
|
|
graphics.SetRenderTarget(floorBuffer.get(), KAGE::Graphics::TARGET_OWN_SIZE);
|
|
graphics.Clear();
|
|
screen_shake_set(false);
|
|
floorSprite.RenderLayer(0, {});
|
|
screen_shake_set(true);
|
|
graphics.Present(KAGE::Graphics::PRESENT_FINISH);
|
|
return;
|
|
}
|
|
render_floor_to_target(get_random_floor_variant(), gfx, nlFloorGfx);
|
|
}
|
|
|
|
// Whether a floor tile at a cell falls in the quarter an L room lacks, the middle being past cell 7 across and 4 down.
|
|
static bool is_tile_cut(int shape, int x, int y)
|
|
{
|
|
if (!is_l_shape(shape)) return false;
|
|
|
|
int missing = shape - ROOMSHAPE_LTL;
|
|
return (x > WALL_MIDDLE_COLUMN) == (bool)(missing & FLIP_X) && (y > WALL_MIDDLE_ROW) == (bool)(missing & FLIP_Y);
|
|
}
|
|
|
|
// The cells floor tiles start at along a floor: every 6, the second moved to 7 when there is room.
|
|
static std::vector<int> tile_origins(int end, int step, int moved)
|
|
{
|
|
std::vector<int> origins;
|
|
|
|
for (int cell = 0; cell < end; cell += step)
|
|
{
|
|
if (cell == step && end > moved) cell = moved;
|
|
origins.push_back(cell);
|
|
}
|
|
return origins;
|
|
}
|
|
|
|
// The floor of 7 by 4 cell tiles: the backdrop's variants of the floor shuffled (repeated up to 32 first), the Dark
|
|
// Room's and Mega Satan's four drawn at random. Each tile past the first row or column is mirrored, and a last row
|
|
// and column (and their corner) meet the far walls. An L room skips the tiles of its missing quarter.
|
|
static void floor_tiles_render(Backdrop& backdrop, uint32_t variant, KAGE::Graphics::ImageBase& sheet, int shape)
|
|
{
|
|
Room& room = *g_game->room;
|
|
BackdropConfig& config = backdrop.configs[backdrop.backdropId];
|
|
bool isDark = backdrop.backdropId == BACKDROP_DARK_ROOM || backdrop.backdropId == BACKDROP_MEGA_SATAN;
|
|
std::vector<SourceQuad> tiles;
|
|
|
|
if (isDark)
|
|
for (const float (&edges)[4] : DARK_TILES)
|
|
tiles.push_back(source_edges(edges[0], edges[1], edges[2], edges[3], FLIP_NONE));
|
|
else
|
|
{
|
|
uint32_t first = (uint32_t)config.floorVariants * variant;
|
|
for (uint32_t i = first; i < first + (uint32_t)config.floorVariants; i++)
|
|
tiles.push_back(block_cells(i, BLOCK_FLOOR, BLOCK_FLOOR, TILE_WIDTH, TILE_HEIGHT, FLIP_NONE));
|
|
// The original repeats an empty list forever. A backdrop without floor variants draws no floor.
|
|
if (tiles.empty()) return;
|
|
|
|
while (tiles.size() < FLOOR_TILES_MIN)
|
|
{
|
|
std::vector<SourceQuad> copy = tiles;
|
|
tiles.insert(tiles.end(), copy.begin(), copy.end());
|
|
}
|
|
for (size_t i = tiles.size() - 1; i > 0; i--) std::swap(tiles[i], tiles[backdrop.rng.Next() % (i + 1)]);
|
|
}
|
|
|
|
int endX = room.gridWidth - WALL_CELLS - TILE_WIDTH;
|
|
int endY = room.gridHeight - (isDark ? WALL_CELLS + TILE_HEIGHT - 1 : WALL_CELLS + TILE_HEIGHT);
|
|
std::vector<int> columns = tile_origins(endX, TILE_STEP_X, WALL_MIDDLE_COLUMN);
|
|
std::vector<int> rows = tile_origins(endY, TILE_STEP_Y, WALL_MIDDLE_ROW);
|
|
int tile = -1;
|
|
auto tile_next = [&](uint32_t mask, uint32_t base) {
|
|
tile = isDark ? (int)((backdrop.rng.Next() & mask) + base) : tile + 1;
|
|
};
|
|
auto tile_draw = [&](int x, int y) {
|
|
Flip flip = (x >= 1 ? FLIP_X : FLIP_NONE) | (y >= 1 ? FLIP_Y : FLIP_NONE);
|
|
image_draw(sheet, source_flip(tiles[tile], flip), backdrop.render_grid_rect(x, y, TILE_WIDTH, TILE_HEIGHT));
|
|
};
|
|
|
|
for (int y : rows)
|
|
for (int x : columns)
|
|
{
|
|
if (is_tile_cut(shape, x, y)) continue;
|
|
tile_next(DARK_FLOOR_TILES - 1, 0);
|
|
tile_draw(x, y);
|
|
}
|
|
for (int y : rows)
|
|
{
|
|
if (is_tile_cut(shape, endX, y)) continue;
|
|
tile_next(DARK_FLOOR_TILES - 1, 0);
|
|
tile_draw(endX, y);
|
|
}
|
|
for (int x : columns)
|
|
{
|
|
if (is_tile_cut(shape, x, endY)) continue;
|
|
tile_next(DARK_EDGE_TILES - 1, DARK_FLOOR_TILES);
|
|
tile_draw(x, endY);
|
|
}
|
|
// The original reads before the tiles when none was drawn. Then the corner stays empty.
|
|
if (!is_tile_cut(shape, endX, endY) && tile >= 0) tile_draw(endX, endY);
|
|
}
|
|
|
|
// The Cathedral's big rooms: 2 by 2 cell tiles of four kinds at random across the floor, and a cell in each corner.
|
|
static void cathedral_floor_render(Backdrop& backdrop, KAGE::Graphics::ImageBase& sheet)
|
|
{
|
|
Room& room = *g_game->room;
|
|
float x = backdrop.roomTopLeft.x;
|
|
float y = backdrop.roomTopLeft.y;
|
|
|
|
while (y < backdrop.roomBottomRight.y - EDGE_EPSILON)
|
|
{
|
|
const int (&cells)[2] = CATHEDRAL_TILES[backdrop.rng.Next() & 3];
|
|
image_draw(sheet, source_cells(cells[0], cells[1], 2, 2),
|
|
quad_edges(x, y, x + CATHEDRAL_TILE, y + CATHEDRAL_TILE));
|
|
x += CATHEDRAL_TILE;
|
|
if (backdrop.roomBottomRight.x - EDGE_EPSILON < x)
|
|
{
|
|
x = backdrop.roomTopLeft.x;
|
|
y += CATHEDRAL_TILE;
|
|
}
|
|
}
|
|
|
|
int farX = room.gridWidth - WALL_CELLS - 1;
|
|
int farY = room.gridHeight - WALL_CELLS - 1;
|
|
for (int corner = 0; corner < CORNER_COUNT; corner++)
|
|
image_draw(sheet, source_cells(CATHEDRAL_CORNER[0], CATHEDRAL_CORNER[1], 1, 1, Flip(corner)),
|
|
backdrop.render_grid_rect(corner & FLIP_X ? farX : 0, corner & FLIP_Y ? farY : 0, 1, 1));
|
|
}
|
|
|
|
// An L room's floor from its L sheet: three 13 by 7 cell pieces of one of two variants (Ashpit's by its floor variant)
|
|
// placed and mirrored by the missing quarter.
|
|
static void l_floor_render(Backdrop& backdrop, uint32_t variant, KAGE::Graphics::ImageBase& sheet, int shape)
|
|
{
|
|
uint32_t row = backdrop.rng.RandomInt(2);
|
|
if (is_ashpit(backdrop.backdropId)) row = variant == FLOOR_SECOND;
|
|
|
|
const LFloorLayout& layout = L_FLOOR_LAYOUTS[shape - ROOMSHAPE_LTL];
|
|
for (int piece = 0; piece < 3; piece++)
|
|
image_draw(sheet,
|
|
source_cells(piece * ROOM_FLOOR_COLUMNS, (int)row * ROOM_FLOOR_ROWS, ROOM_FLOOR_COLUMNS,
|
|
ROOM_FLOOR_ROWS, layout.flip),
|
|
backdrop.render_grid_rect(layout.cells[piece][0], layout.cells[piece][1], ROOM_FLOOR_COLUMNS,
|
|
ROOM_FLOOR_ROWS));
|
|
}
|
|
|
|
// A narrow room's floor from its narrow sheet: one of two strips (Ashpit's by its floor variant), the far end mirrored.
|
|
static void narrow_floor_render(Backdrop& backdrop, uint32_t variant, KAGE::Graphics::ImageBase& sheet, int shape)
|
|
{
|
|
uint32_t pick = backdrop.rng.RandomInt(2);
|
|
if (is_ashpit(backdrop.backdropId)) pick = variant == FLOOR_SECOND;
|
|
|
|
int row = (int)pick * NARROW_ROW_HEIGHT + NARROW_ROW_SHEET_Y;
|
|
int column = (int)pick * NARROW_COLUMN_WIDTH;
|
|
int width = ROOM_FLOOR_COLUMNS;
|
|
int height = ROOM_FLOOR_ROWS;
|
|
|
|
switch (shape)
|
|
{
|
|
case ROOMSHAPE_IH:
|
|
image_draw(sheet, source_cells(0, row, width - 1, NARROW_ROW_HEIGHT),
|
|
backdrop.render_grid_rect(0, WALL_CELLS, width - 1, NARROW_ROW_HEIGHT));
|
|
image_draw(sheet, source_cells(0, row, 1, NARROW_ROW_HEIGHT, FLIP_X),
|
|
backdrop.render_grid_rect(width - 1, WALL_CELLS, 1, NARROW_ROW_HEIGHT));
|
|
break;
|
|
case ROOMSHAPE_IIH:
|
|
image_draw(sheet, source_cells(0, row, width, NARROW_ROW_HEIGHT),
|
|
backdrop.render_grid_rect(0, WALL_CELLS, width, NARROW_ROW_HEIGHT));
|
|
image_draw(sheet, source_cells(0, row, width, NARROW_ROW_HEIGHT, FLIP_X),
|
|
backdrop.render_grid_rect(width, WALL_CELLS, width, NARROW_ROW_HEIGHT));
|
|
break;
|
|
case ROOMSHAPE_IV:
|
|
image_draw(sheet, source_cells(column, 0, NARROW_COLUMN_WIDTH, height - 1),
|
|
backdrop.render_grid_rect(NARROW_COLUMN_INSET, 0, NARROW_COLUMN_WIDTH, height - 1));
|
|
image_draw(sheet, source_cells(column, 0, NARROW_COLUMN_WIDTH, 1, FLIP_Y),
|
|
backdrop.render_grid_rect(NARROW_COLUMN_INSET, height - 1, NARROW_COLUMN_WIDTH, 1));
|
|
break;
|
|
case ROOMSHAPE_IIV:
|
|
image_draw(sheet, source_cells(column, 0, NARROW_COLUMN_WIDTH, height),
|
|
backdrop.render_grid_rect(NARROW_COLUMN_INSET, 0, NARROW_COLUMN_WIDTH, height));
|
|
image_draw(sheet, source_cells(column, 0, NARROW_COLUMN_WIDTH, height, FLIP_Y),
|
|
backdrop.render_grid_rect(NARROW_COLUMN_INSET, height, NARROW_COLUMN_WIDTH, height));
|
|
break;
|
|
}
|
|
}
|
|
|
|
// Whether the room is the start room of the Basement, or the Ascent's first room, where the controls show.
|
|
static bool is_controls_room()
|
|
{
|
|
Game& game = *g_game;
|
|
int startRoom = game.startingRoomIdx;
|
|
|
|
if (game.stage - 1 < ASCENT_LAST_STAGE && (game.gameStateFlags & 1ull << GAME_STATE_BACKWARDS_PATH))
|
|
startRoom = ASCENT_START_ROOM;
|
|
return game.stage == STAGE_BASEMENT_I && game.stageType != STAGETYPE_REPENTANCE &&
|
|
game.stageType != STAGETYPE_REPENTANCE_B && startRoom == game.currentRoomIdx;
|
|
}
|
|
|
|
// 009356a0 Draws the floor surface from the floor sheet (and the L or narrow sheet when the room has one): the
|
|
// Cathedral's big rooms in small tiles, a full image as it is, or the floor tiles, then the controls in the start
|
|
// room. Backdrop 0 leaves the surface empty.
|
|
void Backdrop::render_floor_to_target(uint32_t variant, const KAGE::Graphics::ImagePtr& sheet,
|
|
const KAGE::Graphics::ImagePtr& alternate)
|
|
{
|
|
KAGE::Graphics::Manager& graphics = KAGE::Graphics::manager;
|
|
Room& room = *g_game->room;
|
|
int shape = room.GetRoomShape();
|
|
|
|
graphics.SetRenderTarget(floorBuffer.get(), KAGE::Graphics::TARGET_OWN_SIZE);
|
|
graphics.Clear();
|
|
if (backdropId == BACKDROP_CATHEDRAL && shape != ROOMSHAPE_1x1 && !is_l_shape(shape) && !is_narrow_shape(shape))
|
|
cathedral_floor_render(*this, *sheet);
|
|
else if (backdropId != 0 && configs[backdropId].isFullImage) sheet->Render(Vector{}, WHITE);
|
|
else if (backdropId != 0 && is_l_shape(shape) && alternate) l_floor_render(*this, variant, *alternate, shape);
|
|
else if (backdropId != 0 && is_narrow_shape(shape) && alternate)
|
|
narrow_floor_render(*this, variant, *alternate, shape);
|
|
else if (backdropId != 0) floor_tiles_render(*this, variant, *sheet, shape);
|
|
|
|
if (is_controls_room()) PreRenderControls();
|
|
graphics.Present(KAGE::Graphics::PRESENT_FINISH);
|
|
}
|
|
|
|
// 0095aba0 The frame of the controller glyph sheet that shows a gamepad button or stick direction, or -1.
|
|
int controller_button_to_glyph_frame(int button)
|
|
{
|
|
constexpr int BUTTON_FRAMES[] = {7, 6, 5, 4, 3, 2, 0, 1, 10, 12, 8, 11, 13, 9, 15, 14};
|
|
constexpr int STICK_FRAMES[] = {19, 18, 17, 16, 23, 22, 21, 20};
|
|
constexpr int BUTTON_MENU_CONFIRM = 17;
|
|
constexpr int BUTTON_MENU_BACK = 18;
|
|
|
|
if (button == BUTTON_MENU_CONFIRM) button = KAGE::Input::BUTTON_FACE_DOWN;
|
|
else if (button == BUTTON_MENU_BACK) button = KAGE::Input::BUTTON_FACE_RIGHT;
|
|
if (button >= 0 && button < (int)std::size(BUTTON_FRAMES)) return BUTTON_FRAMES[button];
|
|
if (button >= KAGE::Input::STICK_LEFT_LEFT && button < KAGE::Input::STICK_END)
|
|
return STICK_FRAMES[button - KAGE::Input::STICK_LEFT_LEFT];
|
|
return -1;
|
|
}
|
|
|
|
// 00935010 Lays out the next icon of a row of controls: the button frame of the key or button the controller has the
|
|
// action on, and its place after the icons before it (the button frame's width, spaced from the one before). The
|
|
// space bar on a keyboard moves the row right to stay centered.
|
|
void Backdrop::render_control_icon(ControlRow& row, int action)
|
|
{
|
|
std::shared_ptr<KAGE::Input::InputDevice> device = KAGE::Input::manager.device_find(row.controllerIndex);
|
|
bool isPadded = !row.frames.empty();
|
|
int frame = device ? g_manager->keyConfigs.binding_get(*device, action)[0] : -1;
|
|
|
|
if (row.controllerIndex != KEYBOARD_CONTROLLER) frame = controller_button_to_glyph_frame(frame);
|
|
else if (isPadded && frame == KEY_SPACE) row.cursorX += SPACE_KEY_PADDING;
|
|
|
|
AnimationState& state = controlsButtonsSprite.animState;
|
|
if (state.animData) state.SetFrameFloat((float)frame);
|
|
else log_printf(LOG_ASSERT, "AnimationData is NULL\n");
|
|
|
|
const AnimationFrame* glyph = state.GetLayerFrame(0);
|
|
float iconX;
|
|
if (glyph && glyph->isVisible)
|
|
{
|
|
if (isPadded)
|
|
{
|
|
row.x += glyph->pivot.x;
|
|
row.cursorX -= glyph->pivot.x;
|
|
}
|
|
iconX = row.x;
|
|
row.x = glyph->width - glyph->pivot.x + iconX;
|
|
}
|
|
else
|
|
{
|
|
if (isPadded)
|
|
{
|
|
row.x += ICON_PADDING;
|
|
row.cursorX -= ICON_PADDING;
|
|
}
|
|
iconX = row.x;
|
|
frame = 0;
|
|
row.x = iconX + ICON_WIDTH;
|
|
}
|
|
row.frames.push_back(frame);
|
|
row.positions.push_back(iconX);
|
|
}
|
|
|
|
// The controls picture of the run's character: the vanilla one's frame, a modded character's own picture, or the
|
|
// first frame for a modded character without one.
|
|
static ANM2& controls_picture_pick(Backdrop& backdrop, int playerType)
|
|
{
|
|
if (playerType < PLAYER_TYPE_COUNT)
|
|
{
|
|
backdrop.controlsSprite.SetFrame(CONTROLS_ANIMATION, playerType);
|
|
return backdrop.controlsSprite;
|
|
}
|
|
|
|
std::vector<EntityConfig_Player>& players = g_manager->entityConfig.players;
|
|
EntityConfig_Player* config = playerType < (int)players.size() ? &players[playerType] : nullptr;
|
|
ANM2* modded = config ? config->moddedSprites[PLAYER_SPRITE_CONTROLS] : nullptr;
|
|
if (modded)
|
|
{
|
|
modded->SetFrame(config->GetDisplayName(), 0);
|
|
return *modded;
|
|
}
|
|
backdrop.controlsSprite.SetFrame(CONTROLS_ANIMATION, 0);
|
|
return backdrop.controlsSprite;
|
|
}
|
|
|
|
// 00934770 Draws the controls into the start room's floor: the character's controls picture, then on each of its
|
|
// visible nulls a row of the first player's keys or gamepad buttons, each a pixel up or down at random. A gamepad the
|
|
// game cannot show buttons of shows none. Online play is not part of this build, so netplay's player type and
|
|
// controller are never read.
|
|
void Backdrop::PreRenderControls()
|
|
{
|
|
int playerType = g_manager->startPlayerType;
|
|
ANM2& controls = controls_picture_pick(*this, playerType);
|
|
Vector position = vector_make((roomBottomRight.x + roomTopLeft.x) * 0.5f, roomTopLeft.y + CONTROLS_Y);
|
|
|
|
const std::array<float, 4>& tint = backdropId == BACKDROP_BURNING_BASEMENT ? CONTROLS_BURNT_TINT : CONTROLS_TINT;
|
|
std::copy(tint.begin(), tint.end(), controls.color._tint);
|
|
controls.Render({.position = position});
|
|
controlsButtonsSprite.color = controls.color;
|
|
|
|
int controller = g_game->playerManager.GetPlayer(0)->controllerIndex;
|
|
if (controller == KEYBOARD_CONTROLLER) controlsButtonsSprite.SetFrame(KEYBOARD_ANIMATION, 0);
|
|
else
|
|
{
|
|
std::shared_ptr<KAGE::Input::InputDevice> device = KAGE::Input::manager.device_find(controller);
|
|
if (!device || device->type != KAGE::Input::DEVICE_GAMEPAD) return;
|
|
controlsButtonsSprite.SetFrame(GAMEPAD_ANIMATION, 0);
|
|
}
|
|
|
|
bool isSplitJacob =
|
|
playerType == PLAYER_JACOB && g_manager->optionsConfig.jacobEsauControls == JACOB_ESAU_SPLIT_CONTROLS;
|
|
RNG jitter = {};
|
|
jitter.SetSeed(rng._seed, RNG_SHIFT_CONTROLS);
|
|
for (int rowIndex = 0; rowIndex < CONTROL_ROW_COUNT; rowIndex++)
|
|
{
|
|
const NullFrame* null = controls.animState.animData ? controls.animState.GetNullFrameById(rowIndex) : nullptr;
|
|
if (!null || !null->isVisible) continue;
|
|
|
|
ControlRow row;
|
|
row.controllerIndex = controller;
|
|
for (int action : CONTROL_ROWS[rowIndex])
|
|
{
|
|
if (action == ACTION_NONE) break;
|
|
if (isSplitJacob && action == ACTION_PILL_CARD)
|
|
{
|
|
row.cursorX -= ICON_PADDING;
|
|
render_control_icon(row, ACTION_DROP);
|
|
action = ACTION_ITEM;
|
|
}
|
|
render_control_icon(row, action);
|
|
}
|
|
|
|
for (size_t i = 0; i < row.frames.size(); i++)
|
|
{
|
|
Vector glyph;
|
|
glyph.y = position.y + null->pos.y + (float)((int)(jitter.Next() % GLYPH_JITTER) - 1);
|
|
glyph.x = row.cursorX + row.positions[i] + position.x + null->pos.x;
|
|
if (controlsButtonsSprite.animState.animData)
|
|
controlsButtonsSprite.animState.SetFrameFloat((float)row.frames[i]);
|
|
controlsButtonsSprite.Render({.position = glyph});
|
|
}
|
|
}
|
|
}
|
|
|
|
// The wall sheet a room draws its walls from: its row of variants, how many variants the row has, and one cell in
|
|
// how many shows a variant other than the row's first.
|
|
struct WallSheet
|
|
{
|
|
int chance = WALL_VARIANT_CHANCE;
|
|
int row = 0;
|
|
int variants = 0;
|
|
};
|
|
|
|
// A rectangle of floor cells by its corners, both included, as the shape tables give them.
|
|
struct CellRect
|
|
{
|
|
int minX;
|
|
int minY;
|
|
int maxX;
|
|
int maxY;
|
|
};
|
|
|
|
// The wall row: one at random, Ashpit's and Gehenna's one per level (Ashpit's second in rooms with the alternate
|
|
// backdrop), the Basement boss rooms' own row past the variants, the Dross's last with a water current. The shop's
|
|
// walls show their variants more the better the shop.
|
|
static WallSheet wall_sheet_pick(Backdrop& backdrop)
|
|
{
|
|
Room& room = *g_game->room;
|
|
uint32_t id = backdrop.backdropId;
|
|
BackdropConfig& config = backdrop.configs[id];
|
|
WallSheet sheet{.variants = config.wallVariants};
|
|
RNG levelRng = {};
|
|
levelRng.SetSeed(backdrop.seed, RNG_SHIFT_LEVEL_FLOOR);
|
|
|
|
if (id == BACKDROP_SHOP && (room.roomType == ROOM_SHOP || g_game->IsGreedMode()))
|
|
{
|
|
int level = room.shopLevel - SHOP_LEVEL_FIRST_CHANCE;
|
|
if (level >= 0 && level < (int)std::size(SHOP_WALL_CHANCES)) sheet.chance = SHOP_WALL_CHANCES[level];
|
|
else sheet.variants = 1;
|
|
sheet.row = (int)backdrop.rng.RandomInt(config.walls);
|
|
}
|
|
else if (is_ashpit(id) && (room.descriptor->flags & ROOM_DESCRIPTOR_FLAG_USE_ALTERNATE_BACKDROP)) sheet.row = 1;
|
|
else if (is_ashpit(id) || id == BACKDROP_GEHENNA) sheet.row = (int)levelRng.RandomInt(config.walls);
|
|
else sheet.row = (int)backdrop.rng.RandomInt(config.walls);
|
|
|
|
if (id == BACKDROP_BASEMENT && room.roomType == ROOM_BOSS)
|
|
{
|
|
sheet.row = sheet.variants;
|
|
sheet.variants = 1;
|
|
}
|
|
else if (id == BACKDROP_DROSS && (room.waterCurrent.x != 0 || room.waterCurrent.y != 0)) sheet.row = config.walls;
|
|
return sheet;
|
|
}
|
|
|
|
// A coordinate pushed onto a range, its low end first.
|
|
static float clamp_edge(float value, float low, float high)
|
|
{
|
|
if (value <= low) value = low;
|
|
if (high <= value) value = high;
|
|
return value;
|
|
}
|
|
|
|
// Whether the room is Mom's in the Mausoleum before the Ascent.
|
|
static bool is_pre_ascent_mom_room(Room& room)
|
|
{
|
|
return room.roomType == ROOM_BOSS && room.descriptor->data->subtype == BOSS_MOM_MAUSOLEUM && g_game->IsPreAscent();
|
|
}
|
|
|
|
// A blood splat of a random size from the backdrop's generator, darker in the Corpse's entrance.
|
|
static void blood_splat_spawn(Backdrop& backdrop, Vector position, bool isDarkened)
|
|
{
|
|
Entity* splat =
|
|
g_game->Spawn({.position = position, .type = ENTITY_EFFECT, .variant = EFFECT_BLOOD_SPLAT, .seed = Random()});
|
|
float scale = backdrop.rng.RandomFloat() * SPLAT_SCALE_RANGE + SPLAT_SCALE_MIN;
|
|
|
|
splat->sprite.scale = vector_make(scale, scale);
|
|
if (isDarkened) splat->SetColor(CORPSE_SPLAT_COLOR, COLOR_DURATION_FOREVER, COLOR_PRIORITY_DEFAULT, false, true);
|
|
splat->Update();
|
|
}
|
|
|
|
// The blood a room starts with: on half the cells of a Basement boss room (those away from the walls), and on half the
|
|
// cells near the middle of the Sacrifice room, the Corpse's entrance, and Mom's room before the Ascent.
|
|
static void blood_splats_spawn(Backdrop& backdrop)
|
|
{
|
|
Room& room = *g_game->room;
|
|
uint32_t id = backdrop.backdropId;
|
|
int cells = room.gridHeight * room.gridWidth;
|
|
auto cell_position = [&](int cell) {
|
|
return vector_make((float)(cell % room.gridWidth) * WORLD_CELL + GRID_ORIGIN_X,
|
|
(float)(cell / room.gridWidth) * WORLD_CELL + GRID_ORIGIN_Y);
|
|
};
|
|
|
|
if (id == BACKDROP_BASEMENT && room.roomType == ROOM_BOSS)
|
|
for (int cell = 0; cell < cells; cell++)
|
|
{
|
|
if (!(backdrop.rng.Next() & 1)) continue;
|
|
|
|
Vector position = cell_position(cell);
|
|
float y = clamp_edge(position.y, room.topLeftPos.y + SPLAT_MARGIN, room.bottomRightPos.y - SPLAT_MARGIN);
|
|
float x = clamp_edge(position.x, room.topLeftPos.x + SPLAT_MARGIN, room.bottomRightPos.x - SPLAT_MARGIN);
|
|
if (x == position.x && y == position.y) blood_splat_spawn(backdrop, position, false);
|
|
}
|
|
|
|
bool isCentered = id == BACKDROP_SACRIFICE || id == BACKDROP_CORPSE_ENTRANCE ||
|
|
(is_pre_ascent_mom_room(room) && !g_game->IsAscent());
|
|
if (!isCentered) return;
|
|
|
|
Vector center = Room::GetCenterPos();
|
|
int shape = room.GetRoomShape();
|
|
for (int cell = 0; cell < cells; cell++)
|
|
{
|
|
Vector position = cell_position(cell);
|
|
float dy = position.y - center.y;
|
|
float dx = (position.x - center.x) * SPLAT_SQUASH;
|
|
if (is_horizontal_narrow(shape)) dy += dy;
|
|
if (is_vertical_narrow(shape)) dx += dx;
|
|
if ((backdrop.rng.Next() & 1) && std::sqrt(dy * dy + dx * dx) < SPLAT_RADIUS)
|
|
blood_splat_spawn(backdrop, position, id == BACKDROP_CORPSE_ENTRANCE);
|
|
}
|
|
}
|
|
|
|
// The variant of the row's a cell of wall shows, past the row's first: none, or one at random when the chance hits.
|
|
static int wall_variant_pick(RNG& rng, const WallSheet& sheet)
|
|
{
|
|
return rng.RandomInt(sheet.chance) == 0 ? (int)rng.RandomInt(sheet.variants) : 0;
|
|
}
|
|
|
|
static CellRect cell_rect_a(const LRoomTileDesc& tiles)
|
|
{
|
|
return {tiles.topLeftAX, tiles.topLeftAY, tiles.bottomRightAX, tiles.bottomRightAY};
|
|
}
|
|
|
|
static CellRect cell_rect_b(const LRoomTileDesc& tiles)
|
|
{
|
|
return {tiles.topLeftBX, tiles.topLeftBY, tiles.bottomRightBX, tiles.bottomRightBY};
|
|
}
|
|
|
|
// The quad of a corner piece of wall outside a rectangle of floor cells (corner bit 1 the right, bit 2 the bottom).
|
|
static DestinationQuad corner_quad(Backdrop& backdrop, const CellRect& rect, int corner)
|
|
{
|
|
int x = corner & FLIP_X ? rect.maxX : rect.minX - WALL_CELLS - 1;
|
|
int y = corner & FLIP_Y ? rect.maxY : rect.minY - WALL_CELLS - 1;
|
|
return backdrop.render_grid_rect(x, y, WALL_CELLS, WALL_CELLS);
|
|
}
|
|
|
|
// The four corners of the walls, each a variant's corner mirrored to its side. An L room draws the corner of its
|
|
// missing quarter twice, at its two inner rooms' corners.
|
|
static void wall_corners_render(Backdrop& backdrop, const WallSheet& sheet, int shape, const LRoomTileDesc& tiles)
|
|
{
|
|
CellRect a = cell_rect_a(tiles);
|
|
CellRect b = cell_rect_b(tiles);
|
|
CellRect bounds = {std::min(a.minX, b.minX), std::min(a.minY, b.minY), std::max(a.maxX, b.maxX),
|
|
std::max(a.maxY, b.maxY)};
|
|
int missing = is_l_shape(shape) ? shape - ROOMSHAPE_LTL : -1;
|
|
|
|
for (int corner = 0; corner < CORNER_COUNT; corner++)
|
|
{
|
|
int variant = sheet.row * sheet.variants + wall_variant_pick(backdrop.rng, sheet);
|
|
SourceQuad source = block_cells((uint32_t)variant, 0, 0, WALL_CELLS, WALL_CELLS, Flip(corner));
|
|
DestinationQuad quad = corner_quad(backdrop, bounds, corner);
|
|
if (corner == missing)
|
|
{
|
|
bool isBottom = corner & FLIP_Y;
|
|
image_draw(*backdrop.gfx, source, corner_quad(backdrop, isBottom ? b : a, corner));
|
|
quad = corner_quad(backdrop, isBottom ? a : b, corner);
|
|
}
|
|
image_draw(*backdrop.gfx, source, quad);
|
|
backdrop.spawn_wall_details({.quad = quad, .variant = variant, .wallRow = sheet.row, .flip = Flip(corner)});
|
|
}
|
|
}
|
|
|
|
// Where a line of wall cells sits for a cell along it: how far in the near wall (the top or left) is moved and the far
|
|
// wall (the bottom or right), and whether the cell has walls at all. L rooms move the walls of their missing quarter,
|
|
// narrow rooms their long walls, and draw their short walls only across the floor.
|
|
struct WallPlace
|
|
{
|
|
int near = 0;
|
|
int far = 0;
|
|
bool isDrawn = true;
|
|
};
|
|
|
|
// The top and bottom walls over a column of the floor.
|
|
static WallPlace wall_column_place(int shape, int x, const LRoomTileDesc& tiles)
|
|
{
|
|
switch (shape)
|
|
{
|
|
case ROOMSHAPE_LTL: return x < ROOM_FLOOR_COLUMNS ? WallPlace{.near = ROOM_FLOOR_ROWS} : WallPlace{};
|
|
case ROOMSHAPE_LTR: return x >= ROOM_FLOOR_COLUMNS ? WallPlace{.near = ROOM_FLOOR_ROWS} : WallPlace{};
|
|
case ROOMSHAPE_LBL: return x < ROOM_FLOOR_COLUMNS ? WallPlace{.far = -ROOM_FLOOR_ROWS} : WallPlace{};
|
|
case ROOMSHAPE_LBR: return x >= ROOM_FLOOR_COLUMNS ? WallPlace{.far = -ROOM_FLOOR_ROWS} : WallPlace{};
|
|
case ROOMSHAPE_IH:
|
|
case ROOMSHAPE_IIH: return {.near = NARROW_ROW_INSET, .far = -NARROW_ROW_INSET};
|
|
case ROOMSHAPE_IV:
|
|
case ROOMSHAPE_IIV: return {.isDrawn = tiles.topLeftAX - 1 <= x && x <= tiles.bottomRightAX - 1};
|
|
default: return {};
|
|
}
|
|
}
|
|
|
|
// The side walls beside a row of the floor.
|
|
static WallPlace wall_row_place(int shape, int y, const LRoomTileDesc& tiles)
|
|
{
|
|
switch (shape)
|
|
{
|
|
case ROOMSHAPE_LTL: return y < ROOM_FLOOR_ROWS ? WallPlace{.near = ROOM_FLOOR_COLUMNS} : WallPlace{};
|
|
case ROOMSHAPE_LTR: return y < ROOM_FLOOR_ROWS ? WallPlace{.far = -ROOM_FLOOR_COLUMNS} : WallPlace{};
|
|
case ROOMSHAPE_LBL: return y >= ROOM_FLOOR_ROWS ? WallPlace{.near = ROOM_FLOOR_COLUMNS} : WallPlace{};
|
|
case ROOMSHAPE_LBR: return y >= ROOM_FLOOR_ROWS ? WallPlace{.far = -ROOM_FLOOR_COLUMNS} : WallPlace{};
|
|
case ROOMSHAPE_IV:
|
|
case ROOMSHAPE_IIV: return {.near = NARROW_COLUMN_INSET, .far = -NARROW_COLUMN_INSET};
|
|
case ROOMSHAPE_IH:
|
|
case ROOMSHAPE_IIH: return {.isDrawn = tiles.topLeftAY - 1 <= y && y <= tiles.bottomRightAY - 1};
|
|
default: return {};
|
|
}
|
|
}
|
|
|
|
// The cell of a variant's block a line of wall shows at a cell along it: the block's own cells near the start, the
|
|
// two middle cells taking turns across the middle, and near the end the block's cells again, mirrored.
|
|
static int wall_piece(int cell, int count, int edgeCells, int middle, Flip mirror, Flip& flip)
|
|
{
|
|
flip = FLIP_NONE;
|
|
if (cell < edgeCells) return cell + WALL_CELLS;
|
|
if (cell < count - edgeCells - 1) return middle + (cell & 1);
|
|
|
|
flip = mirror;
|
|
return count - 1 - cell;
|
|
}
|
|
|
|
// One cell of wall: the sheet's piece for its variant drawn into the wall surface, and the backdrop's effects there.
|
|
static void wall_cell_draw(Backdrop& backdrop, const WallSlot& slot, const SourceQuad& source)
|
|
{
|
|
image_draw(*backdrop.gfx, source, slot.quad);
|
|
backdrop.spawn_wall_details(slot);
|
|
}
|
|
|
|
// The top and bottom walls, a column at a time from the left, and the side walls, a row at a time from the top.
|
|
static void wall_lines_render(Backdrop& backdrop, const WallSheet& sheet, int shape, const LRoomTileDesc& tiles)
|
|
{
|
|
Room& room = *g_game->room;
|
|
Flip flip;
|
|
|
|
for (int x = 0; x < room.gridWidth - WALL_CELLS; x++)
|
|
{
|
|
WallPlace place = wall_column_place(shape, x, tiles);
|
|
if (!place.isDrawn) continue;
|
|
|
|
int top = wall_variant_pick(backdrop.rng, sheet);
|
|
int bottom = wall_variant_pick(backdrop.rng, sheet);
|
|
int slotX = wall_piece(x, room.gridWidth, WALL_EDGE_COLUMNS, WALL_MIDDLE_COLUMN, FLIP_X, flip);
|
|
uint32_t first = (uint32_t)(sheet.row * sheet.variants);
|
|
wall_cell_draw(backdrop,
|
|
{.quad = backdrop.render_grid_rect(x, place.near - WALL_CELLS, 1, WALL_CELLS),
|
|
.slotX = slotX,
|
|
.variant = top,
|
|
.wallRow = sheet.row,
|
|
.flip = flip},
|
|
block_cells(first + top, slotX, 0, 1, WALL_CELLS, flip));
|
|
wall_cell_draw(backdrop,
|
|
{.quad = backdrop.render_grid_rect(x, room.gridHeight + place.far - WALL_CELLS, 1, WALL_CELLS),
|
|
.slotX = slotX,
|
|
.variant = bottom,
|
|
.wallRow = sheet.row,
|
|
.flip = flip | FLIP_Y},
|
|
block_cells(first + bottom, slotX, 0, 1, WALL_CELLS, flip | FLIP_Y));
|
|
}
|
|
|
|
for (int y = 0; y < room.gridHeight - WALL_CELLS; y++)
|
|
{
|
|
WallPlace place = wall_row_place(shape, y, tiles);
|
|
if (!place.isDrawn) continue;
|
|
|
|
int left = wall_variant_pick(backdrop.rng, sheet);
|
|
int right = wall_variant_pick(backdrop.rng, sheet);
|
|
int slotY = wall_piece(y, room.gridHeight, WALL_EDGE_ROWS, WALL_MIDDLE_ROW, FLIP_Y, flip);
|
|
uint32_t first = (uint32_t)(sheet.row * sheet.variants);
|
|
wall_cell_draw(backdrop,
|
|
{.quad = backdrop.render_grid_rect(place.near - WALL_CELLS, y, WALL_CELLS, 1),
|
|
.slotY = slotY,
|
|
.variant = left,
|
|
.wallRow = sheet.row,
|
|
.flip = flip},
|
|
block_cells(first + left, 0, slotY, WALL_CELLS, 1, flip));
|
|
wall_cell_draw(backdrop,
|
|
{.quad = backdrop.render_grid_rect(room.gridWidth + place.far - WALL_CELLS, y, WALL_CELLS, 1),
|
|
.slotY = slotY,
|
|
.variant = right,
|
|
.wallRow = sheet.row,
|
|
.flip = flip | FLIP_X},
|
|
block_cells(first + right, 0, slotY, WALL_CELLS, 1, flip | FLIP_X));
|
|
}
|
|
}
|
|
|
|
// An L room's inner corner: the sheet's corner piece of the wall row, mirrored toward the missing quarter.
|
|
static void l_corner_render(Backdrop& backdrop, const WallSheet& sheet, int shape)
|
|
{
|
|
if (!is_l_shape(shape)) return;
|
|
|
|
int missing = shape - ROOMSHAPE_LTL;
|
|
int x = missing & FLIP_X ? ROOM_FLOOR_COLUMNS : ROOM_FLOOR_COLUMNS - WALL_CELLS;
|
|
int y = missing & FLIP_Y ? ROOM_FLOOR_ROWS : ROOM_FLOOR_ROWS - WALL_CELLS;
|
|
image_draw(*backdrop.gfx,
|
|
source_cells(L_CORNER_SHEET_X, sheet.row * WALL_CELLS, WALL_CELLS, WALL_CELLS, Flip(missing)),
|
|
backdrop.render_grid_rect(x, y, WALL_CELLS, WALL_CELLS));
|
|
}
|
|
|
|
// The Cathedral's narrow and L rooms: its pillars where the walls turn, from the sheet's first block (a side piece, its
|
|
// end, and a top piece) mirrored to each place.
|
|
static void cathedral_pieces_render(Backdrop& backdrop, int shape, const LRoomTileDesc& tiles)
|
|
{
|
|
if (g_game->stage != STAGE_SHEOL || g_game->stageType != STAGETYPE_WOTL) return;
|
|
|
|
SourceQuad side = source_cells(0, WALL_CELLS, WALL_CELLS, 1);
|
|
SourceQuad sideEnd = source_cells(0, WALL_CELLS, WALL_CELLS, WALL_CELLS, FLIP_Y);
|
|
SourceQuad top = source_cells(WALL_CELLS, 0, 1, WALL_CELLS);
|
|
CellRect a = cell_rect_a(tiles);
|
|
CellRect b = cell_rect_b(tiles);
|
|
int wall = WALL_CELLS + 1;
|
|
auto draw = [&](const SourceQuad& source, Flip flip, int x, int y, int width, int height) {
|
|
image_draw(*backdrop.gfx, source_flip(source, flip), backdrop.render_grid_rect(x, y, width, height));
|
|
};
|
|
|
|
switch (shape)
|
|
{
|
|
case ROOMSHAPE_IH:
|
|
case ROOMSHAPE_IIH:
|
|
case ROOMSHAPE_IV:
|
|
case ROOMSHAPE_IIV:
|
|
draw(side, FLIP_NONE, a.minX - wall, a.minY - 1, WALL_CELLS, 1);
|
|
draw(sideEnd, FLIP_NONE, a.minX - wall, a.maxY - WALL_CELLS, WALL_CELLS, WALL_CELLS);
|
|
draw(side, FLIP_X, a.maxX, a.minY - 1, WALL_CELLS, 1);
|
|
draw(sideEnd, FLIP_X, a.maxX, a.maxY - WALL_CELLS, WALL_CELLS, WALL_CELLS);
|
|
draw(top, FLIP_NONE, a.minX - 1, a.minY - wall, 1, WALL_CELLS);
|
|
draw(top, FLIP_Y, a.minX - 1, a.maxY, 1, WALL_CELLS);
|
|
draw(top, FLIP_X, a.maxX - 1, a.minY - wall, 1, WALL_CELLS);
|
|
draw(top, FLIP_XY, a.maxX - 1, a.maxY, 1, WALL_CELLS);
|
|
break;
|
|
case ROOMSHAPE_LBL:
|
|
draw(side, FLIP_Y, a.minX - wall, a.maxY - 1, WALL_CELLS, 1);
|
|
draw(top, FLIP_Y, b.minX - 1, b.maxY, 1, WALL_CELLS);
|
|
break;
|
|
case ROOMSHAPE_LBR:
|
|
draw(side, FLIP_XY, a.maxX, a.maxY - 1, WALL_CELLS, 1);
|
|
draw(top, FLIP_XY, b.maxX - 1, b.maxY, 1, WALL_CELLS);
|
|
break;
|
|
case ROOMSHAPE_LTL:
|
|
draw(top, FLIP_NONE, a.minX - 1, a.minY - wall, 1, WALL_CELLS);
|
|
draw(side, FLIP_NONE, b.minX - wall, b.minY - 1, WALL_CELLS, 1);
|
|
break;
|
|
case ROOMSHAPE_LTR:
|
|
draw(top, FLIP_X, a.maxX - 1, a.minY - wall, 1, WALL_CELLS);
|
|
draw(side, FLIP_X, b.maxX, b.minY - 1, WALL_CELLS, 1);
|
|
break;
|
|
}
|
|
}
|
|
|
|
// Whether the backdrop's wall details show with this wall row: the Downpour's and the Dross's pipes with the second,
|
|
// the Mines' with the first, Ashpit's but with the second, Mausoleum's chains and Gehenna's always.
|
|
static bool is_wall_details_shown(uint32_t id, int row)
|
|
{
|
|
if ((id == BACKDROP_DOWNPOUR || id == BACKDROP_DROSS) && row == 1) return true;
|
|
if (id == BACKDROP_MINES || id == BACKDROP_MINES_SHAFT) return row == 0;
|
|
if (is_ashpit(id)) return row != 1;
|
|
return id == BACKDROP_MAUSOLEUM4 || id == BACKDROP_GEHENNA;
|
|
}
|
|
|
|
// The wall detail sprite at each outer corner of the walls, mirrored to it. An L room shows it at both corners of its
|
|
// missing quarter's inner rooms, and narrow rooms keep it on their long walls.
|
|
static void wall_details_render(Backdrop& backdrop, const WallSheet& sheet, int shape)
|
|
{
|
|
if (!backdrop.wallDetailSprite.isLoaded) return;
|
|
|
|
Room& room = *g_game->room;
|
|
uint32_t id = backdrop.backdropId;
|
|
screen_shake_set(false);
|
|
if (is_wall_details_shown(id, sheet.row))
|
|
{
|
|
int width = room.gridWidth;
|
|
int height = room.gridHeight;
|
|
int left = -WALL_CELLS;
|
|
int top = -WALL_CELLS;
|
|
if (is_vertical_narrow(shape))
|
|
{
|
|
width -= NARROW_COLUMN_INSET;
|
|
left = WALL_CELLS;
|
|
}
|
|
else if (is_horizontal_narrow(shape))
|
|
{
|
|
height -= WALL_CELLS;
|
|
top = 0;
|
|
}
|
|
|
|
WallDetail detail;
|
|
detail.chance = is_ashpit(id) && sheet.row == ASHPIT_DARK_WALLS ? ASHPIT_DETAIL_CHANCE : WALL_DETAIL_CHANCE;
|
|
detail.sides = WallSides((is_vertical_narrow(shape) ? WALL_SIDES_NONE : WALL_SIDES_HORIZONTAL) |
|
|
(is_horizontal_narrow(shape) ? WALL_SIDES_NONE : WALL_SIDES_VERTICAL));
|
|
int missing = is_l_shape(shape) ? shape - ROOMSHAPE_LTL : -1;
|
|
auto render_at = [&](int x, int y, int corner) {
|
|
detail.position = vector_make((float)x * GRID_SIZE + backdrop.roomTopLeft.x,
|
|
(float)y * GRID_SIZE + backdrop.roomTopLeft.y);
|
|
detail.flip = Flip(corner);
|
|
backdrop.render_wall_detail(detail);
|
|
};
|
|
|
|
for (int corner = 0; corner < CORNER_COUNT; corner++)
|
|
{
|
|
bool isRight = corner & FLIP_X;
|
|
bool isBottom = corner & FLIP_Y;
|
|
int x = isRight ? width : left;
|
|
int y = isBottom ? height : top;
|
|
if (corner != missing)
|
|
{
|
|
render_at(x, y, corner);
|
|
continue;
|
|
}
|
|
render_at(isRight ? x - ROOM_FLOOR_COLUMNS : x + ROOM_FLOOR_COLUMNS, y, corner);
|
|
render_at(x, isBottom ? y - ROOM_FLOOR_ROWS : y + ROOM_FLOOR_ROWS, corner);
|
|
}
|
|
}
|
|
screen_shake_set(true);
|
|
}
|
|
|
|
// 00937420 Draws the wall surface from the wall sheet: first the blood some rooms start with, then the corners, the top
|
|
// and bottom walls and the side walls cell by cell (each cell a variant of the room's wall row now and then, the
|
|
// backdrop's effects spawned on it), an L room's inner corner, the Cathedral's pillars and the wall details.
|
|
// A backdrop without walls leaves the surface alone, backdrop 0 and full images leave it empty.
|
|
void Backdrop::pre_render_walls()
|
|
{
|
|
BackdropConfig& config = configs[backdropId];
|
|
if (config.walls == 0) return;
|
|
|
|
KAGE::Graphics::Manager& graphics = KAGE::Graphics::manager;
|
|
Room& room = *g_game->room;
|
|
int shape = room.GetRoomShape();
|
|
LRoomTileDesc tiles = room.GetLRoomTileDesc();
|
|
|
|
graphics.SetRenderTarget(wallsBuffer.get(), KAGE::Graphics::TARGET_OWN_SIZE);
|
|
graphics.Clear();
|
|
if (backdropId != 0 && !config.isFullImage)
|
|
{
|
|
WallSheet sheet = wall_sheet_pick(*this);
|
|
blood_splats_spawn(*this);
|
|
wall_corners_render(*this, sheet, shape, tiles);
|
|
wall_lines_render(*this, sheet, shape, tiles);
|
|
l_corner_render(*this, sheet, shape);
|
|
cathedral_pieces_render(*this, shape, tiles);
|
|
wall_details_render(*this, sheet, shape);
|
|
}
|
|
graphics.Present(KAGE::Graphics::PRESENT_FINISH);
|
|
}
|
|
|
|
// 0093b480 A point of the wall surface in the world: the surface is the world at 0.65 scale from two cells out of the
|
|
// room's corner, narrow rooms' surfaces moved to their walls.
|
|
Vector backdrop_detail_to_world_pos(Vector position)
|
|
{
|
|
Room& room = *g_game->room;
|
|
Vector world = vector_make((room.topLeftPos.x - SURFACE_ORIGIN) + position.x / SURFACE_SCALE,
|
|
(room.topLeftPos.y - SURFACE_ORIGIN) + position.y / SURFACE_SCALE);
|
|
int shape = room.GetRoomShape();
|
|
|
|
if (is_horizontal_narrow(shape)) world.y -= NARROW_SHIFT_Y;
|
|
else if (is_vertical_narrow(shape)) world.x -= NARROW_SHIFT_X;
|
|
return world;
|
|
}
|
|
|
|
// 0093b580 The direction out of the room a wall cell faces: down or up for the top and bottom walls (slot past 0),
|
|
// right or left for the side walls, by its mirroring.
|
|
Vector backdrop_wall_normal(int slotX, Flip flip)
|
|
{
|
|
if (slotX != 0) return vector_make(0, flip & FLIP_Y ? -1 : 1);
|
|
return vector_make(flip & FLIP_X ? -1 : 1, 0);
|
|
}
|
|
|
|
// 0093b530 The middle of a cell of wall in the world.
|
|
static Vector wall_center(const DestinationQuad& quad)
|
|
{
|
|
return backdrop_detail_to_world_pos(
|
|
vector_make((quad._topLeft.x + quad._bottomRight.x) * 0.5f, (quad._bottomRight.y + quad._topLeft.y) * 0.5f));
|
|
}
|
|
|
|
// The animation of a wall detail sprite for a slot: "h" and the column along the top wall, "v" and the row down the
|
|
// side wall.
|
|
static std::string slot_animation(const WallSlot& slot)
|
|
{
|
|
bool isSide = slot.slotX == 0;
|
|
return {isSide ? 'v' : 'h', (char)('0' + (isSide ? slot.slotY : slot.slotX))};
|
|
}
|
|
|
|
// A point of the world a null's frame of a surface sprite is at, mirrored with the sprite.
|
|
static Vector null_world_pos(const NullFrame& frame, Vector base, Flip flip)
|
|
{
|
|
float x = frame.pos.x / SURFACE_SCALE;
|
|
float y = frame.pos.y / SURFACE_SCALE;
|
|
return vector_make((flip & FLIP_X ? -x : x) + base.x, (flip & FLIP_Y ? -y : y) + base.y);
|
|
}
|
|
|
|
// A light (1000.121) on a backdrop detail, in a null frame's color and scale.
|
|
static Entity* null_light_spawn(Vector position, const NullFrame& frame)
|
|
{
|
|
Entity* light =
|
|
g_game->Spawn({.position = position, .type = ENTITY_EFFECT, .variant = EFFECT_LIGHT, .seed = Random()});
|
|
|
|
light->flags |= FLAG_BACKDROP_DETAIL;
|
|
static_cast<Entity_Effect*>(light)->scale = LIGHT_SCALE;
|
|
light->SetColor(frame.color, COLOR_DURATION_FOREVER, COLOR_PRIORITY_DEFAULT, false, true);
|
|
light->sprite.scale = frame.scale;
|
|
return light;
|
|
}
|
|
|
|
// 0093b620 A light on every visible null of a backdrop decoration shown at a world position, drawn over the room.
|
|
static void detail_lights_spawn(const ANM2& sprite, Vector position, Flip flip)
|
|
{
|
|
int count = sprite.file ? (int)sprite.file->nullLayerNames.size() : 0;
|
|
|
|
for (int nullId = 0; nullId < count; nullId++)
|
|
{
|
|
const NullFrame* frame = sprite.animState.animData ? sprite.animState.GetNullFrameById(nullId) : nullptr;
|
|
if (frame && frame->isVisible)
|
|
null_light_spawn(null_world_pos(*frame, position, flip), *frame)->renderZOffset = DETAIL_RENDER_Z;
|
|
}
|
|
}
|
|
|
|
// A light on a cell of wall: 20 pixels out of it into the room, drawn back toward the wall.
|
|
static Entity* wall_light_spawn(const WallSlot& slot, float drawBack, int subType)
|
|
{
|
|
Vector normal = backdrop_wall_normal(slot.slotX, slot.flip);
|
|
Vector center = wall_center(slot.quad);
|
|
Vector position = vector_make(normal.x * WALL_LIGHT_OUT + center.x, normal.y * WALL_LIGHT_OUT + center.y);
|
|
Entity* light = g_game->Spawn(
|
|
{.position = position, .subType = subType, .type = ENTITY_EFFECT, .variant = EFFECT_LIGHT, .seed = Random()});
|
|
|
|
light->flags |= FLAG_BACKDROP_DETAIL;
|
|
light->posOffset = vector_make(normal.x * drawBack, normal.y * drawBack);
|
|
return light;
|
|
}
|
|
|
|
// An ember glowing on a cell of wall, of a random size from the backdrop's generator.
|
|
static void ember_spawn(Backdrop& backdrop, const WallSlot& slot, float drawBack, bool isFlattened)
|
|
{
|
|
Vector normal = backdrop_wall_normal(slot.slotX, slot.flip);
|
|
Entity* ember = wall_light_spawn(slot, drawBack, 0);
|
|
|
|
static_cast<Entity_Effect*>(ember)->scale = LIGHT_SCALE;
|
|
ember->SetColor(EMBER_COLOR, COLOR_DURATION_FOREVER, COLOR_PRIORITY_DEFAULT, false, true);
|
|
if (!isFlattened)
|
|
{
|
|
float scale = backdrop.rng.RandomFloat() * BURNING_EMBER_RANGE + BURNING_EMBER_MIN;
|
|
ember->sprite.scale = vector_make(scale, scale);
|
|
return;
|
|
}
|
|
float scale = backdrop.rng.RandomFloat() * ASHPIT_EMBER_RANGE + ASHPIT_EMBER_MIN;
|
|
ember->sprite.scale = vector_make((std::fabs(normal.y) + 1) * scale, (std::fabs(normal.x) + 1) * scale);
|
|
}
|
|
|
|
// A backdrop decoration (1000.140) showing a wall detail sprite in the walls' color.
|
|
static Entity* decoration_spawn(Vector position, std::string_view path)
|
|
{
|
|
Entity* decoration = g_game->Spawn(
|
|
{.position = position, .type = ENTITY_EFFECT, .variant = EFFECT_BACKDROP_DECORATION, .seed = Random()});
|
|
|
|
decoration->sprite.Load(path, GRAPHICS_LOAD);
|
|
decoration->sprite.color = g_game->room->wallColor;
|
|
return decoration;
|
|
}
|
|
|
|
// A decoration on a cell of wall playing its slot's animation, mirrored with the wall.
|
|
static Entity* slot_decoration_spawn(Vector position, std::string_view path, const WallSlot& slot,
|
|
std::string_view name)
|
|
{
|
|
Entity* decoration = decoration_spawn(position, path);
|
|
|
|
decoration->sprite.Play(name, PLAY_FORCED);
|
|
decoration->sprite.isFlipX = slot.flip & FLIP_X;
|
|
decoration->sprite.isFlipY = slot.flip & FLIP_Y;
|
|
return decoration;
|
|
}
|
|
|
|
// Where a decoration hangs beside a top wall's door column: a cell out from the column, in the world.
|
|
static Vector hanging_position(const WallSlot& slot)
|
|
{
|
|
bool isFlipX = slot.flip & FLIP_X;
|
|
return backdrop_detail_to_world_pos(isFlipX
|
|
? vector_make(slot.quad._topRight.x + WALL_SIZE, slot.quad._topRight.y + 0)
|
|
: vector_make(slot.quad._topLeft.x - WALL_SIZE, slot.quad._topLeft.y - 0));
|
|
}
|
|
|
|
// A decoration hung beside a top wall's door column, mirrored with the wall, drawn over the room.
|
|
static Entity* hanging_decoration_spawn(const WallSlot& slot, Vector position, std::string_view path)
|
|
{
|
|
bool isFlipX = slot.flip & FLIP_X;
|
|
Entity* decoration = decoration_spawn(position, path);
|
|
|
|
decoration->flags |= FLAG_BACKDROP_DETAIL;
|
|
decoration->sprite.SetFrame(decoration->sprite.GetDefaultAnimationName(), 0);
|
|
decoration->sprite.isFlipX = isFlipX;
|
|
decoration->sprite.isFlipY = false;
|
|
decoration->renderZOffset = DETAIL_RENDER_Z;
|
|
return decoration;
|
|
}
|
|
|
|
// A blood splat colored as asked, a random size from the global generator, its seed from the backdrop's.
|
|
static void colored_splat_spawn(Backdrop& backdrop, Vector position, const ColorMod& color, float range)
|
|
{
|
|
float scale = random_unit() * range + 1;
|
|
Entity* splat = g_game->Spawn(
|
|
{.position = position, .type = ENTITY_EFFECT, .variant = EFFECT_BLOOD_SPLAT, .seed = backdrop.rng.Next()});
|
|
|
|
splat->sprite.scale = vector_make(scale, scale);
|
|
splat->SetColor(color, COLOR_DURATION_FOREVER, COLOR_PRIORITY_DEFAULT, false, true);
|
|
splat->Update();
|
|
}
|
|
|
|
// The Cathedral's light through the top walls' windows, slanted with the corner.
|
|
static void cathedral_light_spawn(const WallSlot& slot)
|
|
{
|
|
if (slot.slotY != 0 || slot.slotX != CATHEDRAL_WINDOW_SLOT || slot.variant == CATHEDRAL_PLAIN_VARIANT) return;
|
|
|
|
float xSign = slot.flip & FLIP_X ? -1.0f : 1.0f;
|
|
float ySign = slot.flip & FLIP_Y ? -1.0f : 1.0f;
|
|
Vector center = wall_center(slot.quad);
|
|
Vector position = vector_make(xSign * CATHEDRAL_LIGHT_X + center.x, ySign * CATHEDRAL_LIGHT_Y + center.y);
|
|
Entity* light =
|
|
g_game->Spawn({.position = position, .type = ENTITY_EFFECT, .variant = EFFECT_LIGHT, .seed = Random()});
|
|
|
|
light->flags |= FLAG_BACKDROP_DETAIL;
|
|
light->SetColor(CATHEDRAL_LIGHT_COLOR, COLOR_DURATION_FOREVER, COLOR_PRIORITY_DEFAULT, false, true);
|
|
light->sprite.scale = vector_make(CATHEDRAL_LIGHT_SCALE_X, CATHEDRAL_LIGHT_SCALE_Y);
|
|
light->sprite.rotation = ySign * xSign * CATHEDRAL_LIGHT_ANGLE;
|
|
}
|
|
|
|
// The Dank Depths: tar dripped off each cell of wall but the corners, a pillar on the fourth column, and the sheet's
|
|
// details on the variants that have them.
|
|
static void dank_details_spawn(Backdrop& backdrop, const WallSlot& slot)
|
|
{
|
|
if (slot.slotX != 0 || slot.slotY != 0)
|
|
{
|
|
Vector normal = backdrop_wall_normal(slot.slotX, slot.flip);
|
|
Vector center = wall_center(slot.quad);
|
|
float out = backdrop.rng.RandomFloat() * TAR_OUT_RANGE + TAR_OUT_MIN;
|
|
Vector position = vector_make(normal.x * out + center.x, normal.y * out + center.y);
|
|
float cosine = cos_float(QUARTER_TURN);
|
|
float sine = sin_float(QUARTER_TURN);
|
|
Vector along = vector_make(normal.x * cosine - normal.y * sine, normal.y * cosine + normal.x * sine);
|
|
float shift = backdrop.rng.RandomFloat() * TAR_SHIFT_RANGE - TAR_SHIFT_RANGE;
|
|
position.x += shift * along.x;
|
|
position.y += shift * along.y;
|
|
colored_splat_spawn(backdrop, position, TAR_COLOR, TAR_SCALE_RANGE);
|
|
|
|
if (slot.slotX == DANK_PILLAR_SLOT)
|
|
slot_decoration_spawn(wall_center(slot.quad), DANK_DETAILS, slot, "pillar")->flags |= FLAG_RENDER_FLOOR;
|
|
}
|
|
if (slot.wallRow != 0 || (slot.variant != 1 && slot.variant != DANK_DETAIL_VARIANT)) return;
|
|
|
|
std::string name = slot.slotX == 0 && slot.slotY == 0 ? "0" : slot_animation(slot);
|
|
slot_decoration_spawn(wall_center(slot.quad), DANK_DETAILS, slot, name)->flags |=
|
|
FLAG_RENDER_FLOOR | FLAG_RENDER_WALL;
|
|
}
|
|
|
|
// The Dross: lights on the second row's every other cell (one in 40 another kind), and on the first row's second
|
|
// variant pipes out of the walls (but into rocks, locks, TNT and poop), leaking in rooms with the alternate backdrop.
|
|
static void dross_details_spawn(Backdrop& backdrop, const WallSlot& slot, bool isDark)
|
|
{
|
|
if (slot.wallRow == 1)
|
|
{
|
|
bool isLit = (slot.slotX >= DROSS_LIGHT_FIRST && slot.slotX % 2 == 1) ||
|
|
(slot.slotY >= DROSS_LIGHT_FIRST && slot.slotY % 2 == 1);
|
|
if (!isLit || isDark) return;
|
|
|
|
int subType = backdrop.rng.RandomInt(DROSS_LIGHT_ODDS) == 0;
|
|
Entity* light = wall_light_spawn(slot, -WALL_LIGHT_OUT, subType);
|
|
light->SetColor(DROSS_LIGHT_COLOR, COLOR_DURATION_FOREVER, COLOR_PRIORITY_DEFAULT, false, true);
|
|
light->sprite.scale = vector_make(DROSS_LIGHT_SCALE, DROSS_LIGHT_SCALE);
|
|
return;
|
|
}
|
|
bool isPipeSlot = slot.slotX == 3 || slot.slotX == 5 || slot.slotX == 7 || slot.slotY == 3 || slot.slotY == 5;
|
|
if (slot.wallRow != 0 || slot.variant != 1 || !isPipeSlot) return;
|
|
|
|
Room& room = *g_game->room;
|
|
Vector normal = backdrop_wall_normal(slot.slotX, slot.flip);
|
|
Vector center = wall_center(slot.quad);
|
|
Vector position = vector_make(normal.x * WALL_LIGHT_OUT + center.x, normal.y * WALL_LIGHT_OUT + center.y);
|
|
Vector inside = vector_make(position.x + normal.x * DROSS_PIPE_REACH, normal.y * DROSS_PIPE_REACH + position.y);
|
|
GridEntity* grid = room.GetGridEntity((uint32_t)room.GetGridIndex(inside));
|
|
if (grid && std::find(std::begin(DROSS_PIPE_BLOCKERS), std::end(DROSS_PIPE_BLOCKERS), grid->type) !=
|
|
std::end(DROSS_PIPE_BLOCKERS))
|
|
return;
|
|
|
|
Entity* pipe = slot_decoration_spawn(position, "gfx/backdrop/02x_dross_pipes.anm2", slot, slot_animation(slot));
|
|
pipe->flags |= FLAG_BACKDROP_DETAIL;
|
|
pipe->posOffset = vector_make(-normal.x * WALL_LIGHT_OUT, -normal.y * WALL_LIGHT_OUT);
|
|
if (!(room.descriptor->flags & ROOM_DESCRIPTOR_FLAG_USE_ALTERNATE_BACKDROP)) return;
|
|
|
|
const float (&leak)[2] = slot.slotX == 0 ? DROSS_LEAK_SIDE : DROSS_LEAK_TOP;
|
|
Vector drip = vector_make(normal.y * leak[0] + normal.x * leak[1] + position.x,
|
|
-normal.x * leak[0] + normal.y * leak[1] + position.y);
|
|
colored_splat_spawn(backdrop, drip, LIGHT_POOP_SPLAT_COLOR, DROSS_LEAK_RANGE);
|
|
}
|
|
|
|
// The Mines: the background details on the second and third rows' first corner (the second's with their lights), and
|
|
// one lantern in four beside the first row's top wall doors, with its lights.
|
|
static void mines_details_spawn(Backdrop& backdrop, const WallSlot& slot, bool isDark)
|
|
{
|
|
std::string_view background =
|
|
isDark ? "gfx/backdrop/03x_mines_bg_details_dark.anm2" : "gfx/backdrop/03x_mines_bg_details.anm2";
|
|
|
|
if (slot.wallRow == 1 || slot.wallRow == 2)
|
|
{
|
|
if (slot.slotX != 0 || slot.slotY != 0) return;
|
|
|
|
Vector center = wall_center(slot.quad);
|
|
Entity* details = slot_decoration_spawn(center, background, slot, slot.wallRow == 1 ? "0" : "1");
|
|
if (slot.wallRow == 2)
|
|
{
|
|
details->flags |= FLAG_RENDER_FLOOR;
|
|
return;
|
|
}
|
|
detail_lights_spawn(details->sprite, center, slot.flip);
|
|
details->flags |= FLAG_RENDER_FLOOR | FLAG_RENDER_WALL;
|
|
return;
|
|
}
|
|
if (slot.wallRow != 0 || slot.slotX != DOOR_SIDE_SLOT || (slot.flip & FLIP_Y)) return;
|
|
if (backdrop.rng.RandomInt(MINES_LANTERN_ODDS) != 0) return;
|
|
|
|
Vector position = hanging_position(slot);
|
|
Entity* lantern = hanging_decoration_spawn(
|
|
slot, position, isDark ? "gfx/backdrop/03x_mines_lanterns_dark.anm2" : "gfx/backdrop/03x_mines_lanterns.anm2");
|
|
detail_lights_spawn(lantern->sprite, position, Flip(slot.flip & FLIP_X));
|
|
}
|
|
|
|
// Mausoleum's torches on every other top wall cell and the side walls' middle, one in three out.
|
|
static void mausoleum_torch_spawn(Backdrop& backdrop, const WallSlot& slot)
|
|
{
|
|
if (slot.slotX != 2 && slot.slotX != 4 && slot.slotX != 6 && slot.slotY != 3) return;
|
|
|
|
Vector normal = backdrop_wall_normal(slot.slotX, slot.flip);
|
|
Vector center = wall_center(slot.quad);
|
|
Vector position = vector_make(normal.x * WALL_LIGHT_OUT + center.x, normal.y * WALL_LIGHT_OUT + center.y);
|
|
bool isB = backdrop.backdropId == BACKDROP_MAUSOLEUM3;
|
|
bool isOff = backdrop.rng.RandomInt(MAUSOLEUM_TORCH_ODDS) == 0;
|
|
std::string_view path =
|
|
isOff ? (isB ? "gfx/backdrop/05x_mausoleumB_torches_off.anm2" : "gfx/backdrop/05x_mausoleum_torches_off.anm2")
|
|
: (isB ? "gfx/backdrop/05x_mausoleumB_torches.anm2" : "gfx/backdrop/05x_mausoleum_torches.anm2");
|
|
Entity* torch = slot_decoration_spawn(position, path, slot, slot_animation(slot));
|
|
|
|
torch->posOffset = vector_make(-normal.x * WALL_LIGHT_OUT, -normal.y * WALL_LIGHT_OUT);
|
|
torch->flags |= FLAG_BACKDROP_DETAIL;
|
|
}
|
|
|
|
// Gehenna: wall details on half the first row's second variant cells, and chains (each link one in three) beside two
|
|
// of three top wall doors.
|
|
static void gehenna_details_spawn(Backdrop& backdrop, const WallSlot& slot)
|
|
{
|
|
bool isDetailSlot = (slot.slotX > 1 && slot.slotX < 7) || (slot.slotY > 1 && slot.slotY < 5);
|
|
if (slot.wallRow == 0 && slot.variant == 1 && isDetailSlot && backdrop.rng.RandomInt(2) == 0)
|
|
{
|
|
Entity* details = slot_decoration_spawn(wall_center(slot.quad), "gfx/backdrop/06x_gehenna_wall_details.anm2",
|
|
slot, slot_animation(slot));
|
|
details->sortingLayer = SORTING_DOOR;
|
|
}
|
|
if (slot.slotX != DOOR_SIDE_SLOT || (slot.flip & FLIP_Y)) return;
|
|
if (backdrop.rng.RandomInt(GEHENNA_CHAIN_ODDS) == 0) return;
|
|
|
|
Entity* chains = hanging_decoration_spawn(slot, hanging_position(slot), "gfx/backdrop/06x_gehenna_chains.anm2");
|
|
chains->sprite.SetFrame(chains->sprite.GetDefaultAnimationName(), (int)backdrop.rng.RandomInt(2));
|
|
for (LayerState& layer : chains->sprite.layerStates)
|
|
layer.isVisible = backdrop.rng.RandomInt(GEHENNA_CHAIN_ODDS) == 0;
|
|
}
|
|
|
|
// 0093b760 The effects a backdrop adds on a cell of wall as it is drawn: the Burning Basement's and Ashpit's embers,
|
|
// the Cathedral's window light, the Dank Depths' tar and details, the Dross's lights and pipes, the Mines' details and
|
|
// lanterns, Mausoleum's torches and Gehenna's details and chains.
|
|
void Backdrop::spawn_wall_details(const WallSlot& slot)
|
|
{
|
|
bool isDark = g_game->room->descriptor->flags & ROOM_DESCRIPTOR_FLAG_PITCH_BLACK;
|
|
|
|
switch (backdropId)
|
|
{
|
|
case BACKDROP_BURNING_BASEMENT:
|
|
if (slot.variant == 1) ember_spawn(*this, slot, BURNING_EMBER_DRAW_BACK, false);
|
|
break;
|
|
case BACKDROP_CATHEDRAL: cathedral_light_spawn(slot); break;
|
|
case BACKDROP_DANK_DEPTHS: dank_details_spawn(*this, slot); break;
|
|
case BACKDROP_DROSS: dross_details_spawn(*this, slot, isDark); break;
|
|
case BACKDROP_MINES_SHAFT: mines_details_spawn(*this, slot, true); break;
|
|
case BACKDROP_MINES: mines_details_spawn(*this, slot, isDark); break;
|
|
case BACKDROP_ASHPIT:
|
|
case BACKDROP_ASHPIT_SHAFT:
|
|
if (slot.wallRow <= 1 && (slot.slotX >= 2 || slot.slotY >= 2) && slot.variant == 1)
|
|
ember_spawn(*this, slot, ASHPIT_EMBER_DRAW_BACK, true);
|
|
break;
|
|
case BACKDROP_MAUSOLEUM:
|
|
case BACKDROP_MAUSOLEUM3: mausoleum_torch_spawn(*this, slot); break;
|
|
case BACKDROP_GEHENNA: gehenna_details_spawn(*this, slot); break;
|
|
}
|
|
}
|
|
|
|
// The frames of the track a layer of an animation has, 0 for a layer the animation does not key.
|
|
static uint32_t layer_frame_count(const AnimationData* data, int layerId)
|
|
{
|
|
// The original reads the track before the first for an unkeyed layer.
|
|
if (!data || layerId >= ANM2_LAYER_LIMIT || data->layerMap[layerId] < 0) return 0;
|
|
return (uint32_t)data->animLayers[data->layerMap[layerId]].frames.size();
|
|
}
|
|
|
|
// 0093d510 Draws the wall detail sprite at a corner of the walls: each of its layers on the walls it is for (named h...
|
|
// or v...) shows at the chance, on a random frame (Mausoleum's chains always on the top corners, never the bottom).
|
|
// Then, unless the room is dark or a shaft, a light spawns on each null named "*" and a shown layer's id, from the
|
|
// null's frame at the layer's keyframe.
|
|
void Backdrop::render_wall_detail(const WallDetail& detail)
|
|
{
|
|
ANM2& sprite = wallDetailSprite;
|
|
const AnimationData* data = sprite.animState.animData;
|
|
float chance = backdropId == BACKDROP_MAUSOLEUM4 ? (detail.flip & FLIP_Y ? 0.0f : 1.0f) : detail.chance;
|
|
|
|
for (int layerId = 0; layerId < (int)sprite.layerStates.size(); layerId++)
|
|
{
|
|
LayerState& layer = *sprite.GetLayer(layerId);
|
|
char kind = layer.layerData && !layer.layerData->name.empty() ? layer.layerData->name[0] : '\0';
|
|
bool isOnWall = (kind == 'h' && (detail.sides & WALL_SIDES_HORIZONTAL)) ||
|
|
(kind == 'v' && (detail.sides & WALL_SIDES_VERTICAL));
|
|
layer.isVisible = isOnWall && rng.RandomFloat() < chance;
|
|
if (layer.isVisible) sprite.SetLayerFrame(layerId, (int)rng.RandomInt(layer_frame_count(data, layerId)));
|
|
}
|
|
sprite.isFlipX = detail.flip & FLIP_X;
|
|
sprite.isFlipY = detail.flip & FLIP_Y;
|
|
sprite.Render({.position = detail.position});
|
|
|
|
bool isDark = backdropId == BACKDROP_MINES_SHAFT || backdropId == BACKDROP_ASHPIT_SHAFT ||
|
|
(g_game->room->descriptor->flags & ROOM_DESCRIPTOR_FLAG_PITCH_BLACK);
|
|
int nullCount = sprite.file ? (int)sprite.file->nullLayerNames.size() : 0;
|
|
if (isDark || !data) return;
|
|
|
|
for (int nullId = 0; nullId < nullCount; nullId++)
|
|
{
|
|
const std::string& name = sprite.GetNullLayerName(nullId);
|
|
if (name.empty() || name[0] != '*') continue;
|
|
|
|
int layerId = std::atoi(name.c_str() + 1);
|
|
if (!sprite.GetLayer(layerId)->isVisible) continue;
|
|
|
|
int frameIndex = sprite.animState.GetLayerFrameIdx(layerId);
|
|
auto track =
|
|
std::find_if(data->nullLayers.begin(), data->nullLayers.end(), [&](const AnimationNullLayer& null) {
|
|
return null.nullLayerId == nullId && frameIndex >= 0 && frameIndex < (int)null.frames.size();
|
|
});
|
|
if (track == data->nullLayers.end() || !track->frames[frameIndex].isVisible) continue;
|
|
|
|
const NullFrame& frame = track->frames[frameIndex];
|
|
null_light_spawn(null_world_pos(frame, backdrop_detail_to_world_pos(detail.position), detail.flip), frame);
|
|
}
|
|
}
|
|
|
|
// 0093ea00 Draws the floor: the Error room's sprite repeated over the floor, Mega Satan's sprite (or its surface while
|
|
// the closed floor shows), the Planetarium's sprite, or the floor surface in the room's floor color. Ultra Greed's shop
|
|
// blends its floor, the others draw it opaque.
|
|
void Backdrop::RenderFloor(Vector renderOffset, ColorMod color)
|
|
{
|
|
#ifdef ISAAC_REPENTOGON
|
|
callback_notify(lua_engine_get(), {"MC_PRE_BACKDROP_RENDER_FLOOR", MC_PRE_BACKDROP_RENDER_FLOOR, std::nullopt}, &color);
|
|
#endif
|
|
KAGE::Graphics::Manager& graphics = KAGE::Graphics::manager;
|
|
KAGE::Graphics::BlendMode savedBlend = graphics.blendMode;
|
|
graphics.blend_set(backdropId == BACKDROP_GREED_SHOP ? KAGE::Graphics::BLEND_NORMAL : KAGE::Graphics::BLEND_OPAQUE);
|
|
|
|
if (backdropId == BACKDROP_ERROR_ROOM)
|
|
{
|
|
screen_shake_set(false);
|
|
for (float y = roomTopLeft.y, x = roomTopLeft.x; y < roomBottomRight.y - EDGE_EPSILON;)
|
|
{
|
|
SpriteDraw draw{.position = vector_make(x + renderOffset.x, y + renderOffset.y)};
|
|
draw.bottomRightClamp = vector_make(std::max(x - roomBottomRight.x + ERROR_TILE, 0.0f),
|
|
std::max(y - roomBottomRight.y + ERROR_TILE, 0.0f));
|
|
floorSprite.Render(draw);
|
|
x += ERROR_TILE;
|
|
if (roomBottomRight.x - EDGE_EPSILON < x)
|
|
{
|
|
x = roomTopLeft.x;
|
|
y += ERROR_TILE;
|
|
}
|
|
}
|
|
screen_shake_set(true);
|
|
}
|
|
else if (backdropId == BACKDROP_MEGA_SATAN)
|
|
{
|
|
screen_shake_set(false);
|
|
if (floorSprite.animState.is_finished(MEGA_SATAN_CLOSED_ANIMATION))
|
|
{
|
|
color_offset_shader_select();
|
|
Vector size = vector_make(MEGA_SATAN_BORDER + MEGA_SATAN_BORDER + (roomBottomRight.x - roomTopLeft.x),
|
|
(roomBottomRight.y - roomTopLeft.y) + MEGA_SATAN_BORDER + MEGA_SATAN_BORDER);
|
|
Vector source = vector_make((WALL_SIZE - MEGA_SATAN_BORDER) + MEGA_SATAN_FLOOR_X,
|
|
(WALL_SIZE - MEGA_SATAN_BORDER) + MEGA_SATAN_FLOOR_Y);
|
|
Vector position = vector_make(((renderOffset.x + WALL_SIZE) - MEGA_SATAN_BORDER) + MEGA_SATAN_FLOOR_X,
|
|
((renderOffset.y + WALL_SIZE) - MEGA_SATAN_BORDER) + MEGA_SATAN_FLOOR_Y);
|
|
apply_sprite_shader_params(COLOR_DEFAULT, SPRITE_SHADER_COLOR_APPLY, *floorBuffer);
|
|
floorBuffer->Render(KAGE::Graphics::source_quad_rect(source, size),
|
|
KAGE::Graphics::color_quad_rect(position, size, WHITE), WHITE);
|
|
}
|
|
else
|
|
floorSprite.Render({.position = vector_make(renderOffset.x + roomTopLeft.x + MEGA_SATAN_FLOOR_X,
|
|
renderOffset.y + roomTopLeft.y + MEGA_SATAN_FLOOR_Y)});
|
|
screen_shake_set(true);
|
|
}
|
|
else if (backdropId == BACKDROP_PLANETARIUM)
|
|
{
|
|
screen_shake_set(false);
|
|
floorSprite.Render({.position = renderOffset});
|
|
screen_shake_set(true);
|
|
}
|
|
else
|
|
{
|
|
color_offset_shader_select();
|
|
Vector size =
|
|
vector_make((roomBottomRight.x - roomTopLeft.x) + 0, (roomBottomRight.y - roomTopLeft.y) + GRID_SIZE);
|
|
Vector position = vector_make(renderOffset.x + WALL_SIZE, renderOffset.y + WALL_SIZE);
|
|
apply_sprite_shader_params(color, SPRITE_SHADER_COLOR_APPLY, *floorBuffer);
|
|
floorBuffer->Render(KAGE::Graphics::source_quad_rect(vector_make(WALL_SIZE, WALL_SIZE), size),
|
|
KAGE::Graphics::color_quad_rect(position, size, WHITE), WHITE);
|
|
}
|
|
|
|
graphics.blendMode = savedBlend;
|
|
graphics.shader_default_set();
|
|
}
|
|
|
|
// 0093f000 Draws the second floor surface over the floor, blended, in the room's floor color.
|
|
void Backdrop::render_floor_surface(Vector renderOffset, ColorMod color)
|
|
{
|
|
KAGE::Graphics::Manager& graphics = KAGE::Graphics::manager;
|
|
KAGE::Graphics::BlendMode savedBlend = graphics.blendMode;
|
|
|
|
graphics.blend_set(KAGE::Graphics::BLEND_NORMAL);
|
|
color_offset_shader_select();
|
|
Vector size = vector_make((roomBottomRight.x - roomTopLeft.x) + 0, (roomBottomRight.y - roomTopLeft.y) + GRID_SIZE);
|
|
SourceQuad source = source_edges(WALL_SIZE, WALL_SIZE, size.x + WALL_SIZE, size.y + WALL_SIZE, FLIP_NONE);
|
|
Vector position = vector_make(renderOffset.x + WALL_SIZE, renderOffset.y + WALL_SIZE);
|
|
apply_sprite_shader_params(color, SPRITE_SHADER_COLOR_APPLY, *floorSurface2);
|
|
floorSurface2->Render(source, KAGE::Graphics::color_quad_rect(position, size, WHITE), WHITE);
|
|
|
|
graphics.blendMode = savedBlend;
|
|
graphics.shader_default_set();
|
|
}
|
|
|
|
// A rectangle of the wall surface, each side in halves of the floor's size plus pixels.
|
|
struct SurfaceRect
|
|
{
|
|
float xHalves;
|
|
float x;
|
|
float yHalves;
|
|
float y;
|
|
float widthHalves;
|
|
float width;
|
|
float heightHalves;
|
|
float height;
|
|
};
|
|
|
|
// The wall surface a room shows: the left and right walls (with their corners) and the top and bottom walls between.
|
|
constexpr SurfaceRect WALL_LEFT = {0, 0, 0, 0, 0, WALL_SIZE, 2, 2 * WALL_SIZE};
|
|
constexpr SurfaceRect WALL_RIGHT = {2, WALL_SIZE, 0, 0, 0, WALL_SIZE, 2, 2 * WALL_SIZE};
|
|
constexpr SurfaceRect WALL_TOP = {0, WALL_SIZE, 0, 0, 2, 0, 0, WALL_SIZE};
|
|
constexpr SurfaceRect WALL_BOTTOM = {0, WALL_SIZE, 2, WALL_SIZE, 2, 0, 0, WALL_SIZE};
|
|
constexpr SurfaceRect ROOM_WALLS[4] = {WALL_LEFT, WALL_RIGHT, WALL_TOP, WALL_BOTTOM};
|
|
|
|
// An L room's walls, by its missing quarter: the two outer walls it keeps whole, the outer walls cut short, and the
|
|
// two inner walls.
|
|
constexpr SurfaceRect L_ROOM_WALLS[4][6] = {{WALL_RIGHT,
|
|
WALL_BOTTOM,
|
|
{0, 0, 1, 0, 0, WALL_SIZE, 1, 2 * WALL_SIZE},
|
|
{1, 0, 0, 0, 0, WALL_SIZE, 1, 2 * WALL_SIZE},
|
|
{0, WALL_SIZE, 1, 0, 1, 0, 0, WALL_SIZE},
|
|
{1, WALL_SIZE, 0, 0, 1, 0, 0, WALL_SIZE}},
|
|
{WALL_LEFT,
|
|
WALL_BOTTOM,
|
|
{2, WALL_SIZE, 1, 0, 0, WALL_SIZE, 1, 2 * WALL_SIZE},
|
|
{1, WALL_SIZE, 0, 0, 0, WALL_SIZE, 1, 2 * WALL_SIZE},
|
|
{1, WALL_SIZE, 1, 0, 1, 0, 0, WALL_SIZE},
|
|
{0, WALL_SIZE, 0, 0, 1, 0, 0, WALL_SIZE}},
|
|
{WALL_RIGHT,
|
|
WALL_TOP,
|
|
{1, 0, 1, 0, 0, WALL_SIZE, 1, 2 * WALL_SIZE},
|
|
{0, 0, 0, 0, 0, WALL_SIZE, 1, 2 * WALL_SIZE},
|
|
{0, WALL_SIZE, 1, WALL_SIZE, 1, 0, 0, WALL_SIZE},
|
|
{1, WALL_SIZE, 2, WALL_SIZE, 1, 0, 0, WALL_SIZE}},
|
|
{WALL_LEFT,
|
|
WALL_TOP,
|
|
{1, WALL_SIZE, 1, 0, 0, WALL_SIZE, 1, 2 * WALL_SIZE},
|
|
{2, WALL_SIZE, 0, 0, 0, WALL_SIZE, 1, 2 * WALL_SIZE},
|
|
{0, WALL_SIZE, 2, WALL_SIZE, 1, 0, 0, WALL_SIZE},
|
|
{1, WALL_SIZE, 1, WALL_SIZE, 1, 0, 0, WALL_SIZE}}};
|
|
|
|
// Copies a rectangle of the wall surface (moved in by an inset) to the same place on screen.
|
|
static void wall_surface_blit(KAGE::Graphics::ImageBase& surface, const SurfaceRect& rect, Vector half, Vector inset,
|
|
Vector offset)
|
|
{
|
|
Vector position = vector_make(rect.xHalves * half.x + rect.x + inset.x, rect.yHalves * half.y + rect.y + inset.y);
|
|
Vector size = vector_make(rect.widthHalves * half.x + rect.width, rect.heightHalves * half.y + rect.height);
|
|
SourceQuad source = source_edges(position.x, position.y, position.x + size.x, position.y + size.y, FLIP_NONE);
|
|
|
|
image_draw(surface, source,
|
|
KAGE::Graphics::color_quad_rect(vector_make(position.x + offset.x, position.y + offset.y), size, WHITE));
|
|
}
|
|
|
|
// 0093f1d0 Draws the walls: the water first, Mega Satan's borders, the Planetarium's sprite, the closets' and Dogma's
|
|
// sprite past its floor layer (and nothing more), then for backdrops with walls the black borders around the room and
|
|
// the wall surface's walls in the room's wall color, piece by piece around the floor.
|
|
void Backdrop::RenderWalls(Vector renderOffset, ColorMod color)
|
|
{
|
|
#ifdef ISAAC_REPENTOGON
|
|
callback_notify(lua_engine_get(), {"MC_PRE_BACKDROP_RENDER_WALLS", MC_PRE_BACKDROP_RENDER_WALLS, std::nullopt}, &color);
|
|
#endif
|
|
KAGE::Graphics::Manager& graphics = KAGE::Graphics::manager;
|
|
|
|
if (waterGfx) RenderWater(renderOffset);
|
|
if (backdropId == BACKDROP_MEGA_SATAN)
|
|
{
|
|
Vector size = vector_make(MEGA_SATAN_BORDER + MEGA_SATAN_BORDER + (roomBottomRight.x - roomTopLeft.x),
|
|
(roomBottomRight.y - roomTopLeft.y) + MEGA_SATAN_BORDER + MEGA_SATAN_BORDER);
|
|
render_wall_borders(vector_make(((renderOffset.x + WALL_SIZE) - MEGA_SATAN_BORDER) + MEGA_SATAN_FLOOR_X,
|
|
((renderOffset.y + WALL_SIZE) - MEGA_SATAN_BORDER) + MEGA_SATAN_FLOOR_Y),
|
|
size);
|
|
return;
|
|
}
|
|
if (backdropId == BACKDROP_PLANETARIUM)
|
|
{
|
|
screen_shake_set(false);
|
|
floorSprite.Render({.position = renderOffset});
|
|
screen_shake_set(true);
|
|
return;
|
|
}
|
|
if (backdropId == BACKDROP_CLOSET || backdropId == BACKDROP_CLOSET_B || backdropId == BACKDROP_DOGMA)
|
|
{
|
|
screen_shake_set(false);
|
|
for (int layer = 1; layer < (int)floorSprite.layerStates.size(); layer++)
|
|
floorSprite.RenderLayer(layer, {.position = renderOffset});
|
|
screen_shake_set(true);
|
|
return;
|
|
}
|
|
if (configs[backdropId].walls == 0) return;
|
|
|
|
KAGE::Graphics::BlendMode savedBlend = graphics.blendMode;
|
|
graphics.blend_set(KAGE::Graphics::BLEND_NORMAL);
|
|
Vector floorSize = vector_make(roomBottomRight.x - roomTopLeft.x, roomBottomRight.y - roomTopLeft.y);
|
|
int shape = g_game->room->GetRoomShape();
|
|
render_wall_borders(renderOffset,
|
|
vector_make(WALL_SIZE + WALL_SIZE + floorSize.x, WALL_SIZE + WALL_SIZE + floorSize.y));
|
|
color_offset_shader_select();
|
|
apply_sprite_shader_params(color, SPRITE_SHADER_COLOR_APPLY, *wallsBuffer);
|
|
|
|
Vector inset{};
|
|
if (is_horizontal_narrow(shape))
|
|
{
|
|
inset.y = WALL_SIZE;
|
|
floorSize.y -= 2 * WALL_SIZE;
|
|
}
|
|
else if (is_vertical_narrow(shape))
|
|
{
|
|
inset.x = 2 * WALL_SIZE;
|
|
floorSize.x -= 4 * WALL_SIZE;
|
|
}
|
|
Vector half = vector_make(floorSize.x * 0.5f, floorSize.y * 0.5f);
|
|
if (is_l_shape(shape))
|
|
for (const SurfaceRect& rect : L_ROOM_WALLS[shape - ROOMSHAPE_LTL])
|
|
wall_surface_blit(*wallsBuffer, rect, half, inset, renderOffset);
|
|
else
|
|
for (const SurfaceRect& rect : ROOM_WALLS) wall_surface_blit(*wallsBuffer, rect, half, inset, renderOffset);
|
|
|
|
graphics.blendMode = savedBlend;
|
|
graphics.shader_default_set();
|
|
}
|
|
|
|
// 0093e770 Blacks out the screen around the room (the walls' outer edge moved in for narrow rooms), and the corner an
|
|
// L room lacks.
|
|
void Backdrop::render_wall_borders(Vector roomTopLeftPos, Vector roomSize)
|
|
{
|
|
float left = roomTopLeftPos.x;
|
|
float top = roomTopLeftPos.y;
|
|
float right = roomTopLeftPos.x + roomSize.x;
|
|
float bottom = roomTopLeftPos.y + roomSize.y;
|
|
std::array<DestinationQuad, 4> borders = {quad_edges(0, 0, left, g_screenHeight), quad_edges(left, 0, right, top),
|
|
quad_edges(right, 0, g_screenWidth, g_screenHeight),
|
|
quad_edges(left, bottom, right, g_screenHeight)};
|
|
int shape = g_game->room->GetRoomShape();
|
|
|
|
if (is_horizontal_narrow(shape))
|
|
{
|
|
borders[1]._bottomLeft.y += NARROW_BORDER_Y;
|
|
borders[1]._bottomRight.y += NARROW_BORDER_Y;
|
|
borders[3]._topLeft.y -= NARROW_BORDER_Y;
|
|
borders[3]._topRight.y -= NARROW_BORDER_Y;
|
|
}
|
|
else if (is_vertical_narrow(shape))
|
|
{
|
|
borders[0]._topRight.x += NARROW_BORDER_X;
|
|
borders[0]._bottomRight.x += NARROW_BORDER_X;
|
|
borders[2]._topLeft.x -= NARROW_BORDER_X;
|
|
borders[2]._bottomLeft.x -= NARROW_BORDER_X;
|
|
}
|
|
for (const DestinationQuad& border : borders)
|
|
render_color_shader_pass(KAGE::Graphics::ColorQuad(border, BORDER_COLOR));
|
|
if (!is_l_shape(shape)) return;
|
|
|
|
int missing = shape - ROOMSHAPE_LTL;
|
|
Vector corner = roomTopLeftPos;
|
|
if (missing & FLIP_X) corner.x = roomSize.x * 0.5f + roomTopLeftPos.x + GRID_SIZE;
|
|
if (missing & FLIP_Y) corner.y = roomSize.y * 0.5f + roomTopLeftPos.y + GRID_SIZE;
|
|
render_color_shader_pass(
|
|
KAGE::Graphics::color_quad_rect(corner, vector_make(L_BORDER_WIDTH, L_BORDER_HEIGHT), BORDER_COLOR));
|
|
}
|
|
|
|
// A length along the room for the water under the walls: pixels plus a number of room widths and heights (in cells of
|
|
// 26 pixels).
|
|
struct WaterLength
|
|
{
|
|
float pixels;
|
|
int widths;
|
|
int heights;
|
|
};
|
|
|
|
// How a strip of water maps the water sheet: running down a side wall (mirrored on the right), or along the top or
|
|
// bottom wall (the sheet turned, mirrored along the bottom).
|
|
enum WaterMapping
|
|
{
|
|
WATER_DOWN,
|
|
WATER_DOWN_MIRRORED,
|
|
WATER_ALONG,
|
|
WATER_ALONG_MIRRORED
|
|
};
|
|
|
|
// A strip of water: its mapping with the two ends of the sheet it shows, and its edges on the wall surface.
|
|
struct WaterStrip
|
|
{
|
|
WaterMapping mapping;
|
|
WaterLength start;
|
|
WaterLength end;
|
|
WaterLength left;
|
|
WaterLength top;
|
|
WaterLength right;
|
|
WaterLength bottom;
|
|
};
|
|
|
|
constexpr WaterLength px(float pixels)
|
|
{
|
|
return {pixels, 0, 0};
|
|
}
|
|
|
|
constexpr WaterLength wide(float pixels, int widths = 1)
|
|
{
|
|
return {pixels, widths, 0};
|
|
}
|
|
|
|
constexpr WaterLength tall(float pixels)
|
|
{
|
|
return {pixels, 0, 1};
|
|
}
|
|
|
|
// The strips under each shape's walls: down the side walls, then along the top and bottom walls, an L room's inner
|
|
// walls with the outer walls they meet.
|
|
constexpr WaterStrip WATER_ROOM[] = {{WATER_DOWN, px(0), tall(-52), px(0), px(52), px(52), tall(0)},
|
|
{WATER_DOWN_MIRRORED, px(0), tall(-52), wide(0), px(52), wide(52), tall(0)},
|
|
{WATER_ALONG, px(0), wide(52, -1), px(52), px(0), wide(0), px(52)},
|
|
{WATER_ALONG_MIRRORED, px(0), wide(52, -1), px(52), tall(0), wide(0), tall(52)}};
|
|
constexpr WaterStrip WATER_LTL[] = {{WATER_DOWN, px(0), px(182), px(338), px(52), px(390), px(182)},
|
|
{WATER_DOWN, px(182), tall(-52), px(0), px(182), px(52), tall(0)},
|
|
{WATER_DOWN_MIRRORED, px(0), tall(-52), wide(0), px(52), wide(52), tall(0)},
|
|
{WATER_ALONG, px(0), px(-338), px(52), px(182), px(338), px(234)},
|
|
{WATER_ALONG, px(-338), wide(52, -1), px(338), px(0), wide(0), px(52)},
|
|
{WATER_ALONG_MIRRORED, px(0), wide(52, -1), px(52), tall(0), wide(0), tall(52)}};
|
|
constexpr WaterStrip WATER_LTR[] = {{WATER_DOWN, px(0), tall(-52), px(0), px(52), px(52), tall(0)},
|
|
{WATER_DOWN_MIRRORED, px(0), px(182), wide(-338), px(52), wide(-286), px(182)},
|
|
{WATER_DOWN_MIRRORED, px(182), tall(-52), wide(0), px(182), wide(52), tall(0)},
|
|
{WATER_ALONG, px(0), px(-390), px(52), px(0), px(390), px(52)},
|
|
{WATER_ALONG, px(15), wide(52, -1), px(390), px(182), wide(0), px(234)},
|
|
{WATER_ALONG_MIRRORED, px(0), wide(52, -1), px(52), tall(0), wide(0), tall(52)}};
|
|
constexpr WaterStrip WATER_LBL[] = {{WATER_DOWN, px(0), px(234), px(0), px(52), px(52), px(234)},
|
|
{WATER_DOWN, px(234), tall(-52), px(338), px(234), px(390), tall(0)},
|
|
{WATER_DOWN_MIRRORED, px(0), tall(-52), wide(0), px(52), wide(52), tall(0)},
|
|
{WATER_ALONG, px(0), wide(52, -1), px(52), px(0), wide(0), px(52)},
|
|
{WATER_ALONG_MIRRORED, px(0), px(-338), px(52), tall(-182), px(338), tall(-130)},
|
|
{WATER_ALONG_MIRRORED, px(13), wide(52, -1), px(338), tall(0), wide(0), tall(52)}};
|
|
constexpr WaterStrip WATER_LBR[] = {
|
|
{WATER_DOWN, px(0), tall(-52), px(0), px(52), px(52), tall(0)},
|
|
{WATER_DOWN_MIRRORED, px(0), px(234), wide(0), px(52), wide(52), px(234)},
|
|
{WATER_DOWN_MIRRORED, px(234), tall(-52), wide(-338), px(234), wide(-286), tall(0)},
|
|
{WATER_ALONG, px(0), wide(52, -1), px(52), px(0), wide(0), px(52)},
|
|
{WATER_ALONG_MIRRORED, px(0), px(-390), px(52), tall(0), px(390), tall(52)},
|
|
{WATER_ALONG_MIRRORED, px(15), wide(52, -1), px(390), tall(-182), wide(0), tall(-130)}};
|
|
constexpr WaterStrip WATER_IH[] = {{WATER_DOWN, px(0), px(78), px(0), px(104), px(52), px(182)},
|
|
{WATER_DOWN_MIRRORED, px(0), px(78), wide(0), px(104), wide(52), px(182)},
|
|
{WATER_ALONG, px(0), wide(52, -1), px(52), px(52), wide(0), px(104)},
|
|
{WATER_ALONG_MIRRORED, px(0), wide(52, -1), px(52), tall(-52), wide(0), tall(0)}};
|
|
constexpr WaterStrip WATER_IV[] = {{WATER_DOWN, px(0), tall(-52), px(104), px(52), px(156), tall(0)},
|
|
{WATER_DOWN_MIRRORED, px(0), tall(-52), wide(-104), px(52), wide(-52), tall(0)},
|
|
{WATER_ALONG, px(0), px(-130), px(156), px(0), wide(-104), px(52)},
|
|
{WATER_ALONG_MIRRORED, px(0), px(-130), px(156), tall(0), wide(-104), tall(52)}};
|
|
|
|
// The water scrolls half a pixel a frame and draws behind the walls' depth.
|
|
constexpr float WATER_SCROLL = 0.5f;
|
|
constexpr float WATER_DEPTH_STEP = 0.04f;
|
|
constexpr int WATER_DEPTH_STEPS = 4;
|
|
|
|
// The strips of water under a shape's walls.
|
|
static std::span<const WaterStrip> water_strips_get(int shape)
|
|
{
|
|
switch (shape)
|
|
{
|
|
case ROOMSHAPE_LTL: return WATER_LTL;
|
|
case ROOMSHAPE_LTR: return WATER_LTR;
|
|
case ROOMSHAPE_LBL: return WATER_LBL;
|
|
case ROOMSHAPE_LBR: return WATER_LBR;
|
|
case ROOMSHAPE_IH:
|
|
case ROOMSHAPE_IIH: return WATER_IH;
|
|
case ROOMSHAPE_IV:
|
|
case ROOMSHAPE_IIV: return WATER_IV;
|
|
default: return WATER_ROOM;
|
|
}
|
|
}
|
|
|
|
// 00940d30 (009426b0) Draws the water under the walls, opaque: strips of the water sheet down the side walls and along
|
|
// the top and bottom walls, scrolling with the frames (backward for a reversed sheet), each pushed behind the walls.
|
|
void Backdrop::RenderWater(Vector renderOffset)
|
|
{
|
|
#ifdef ISAAC_REPENTOGON
|
|
callback_notify(lua_engine_get(), {"MC_PRE_BACKDROP_RENDER_WATER", MC_PRE_BACKDROP_RENDER_WATER, std::nullopt});
|
|
#endif
|
|
KAGE::Graphics::Manager& graphics = KAGE::Graphics::manager;
|
|
KAGE::Graphics::BlendMode savedBlend = graphics.blendMode;
|
|
Room& room = *g_game->room;
|
|
float scroll = (float)g_game->frameCount * WATER_SCROLL;
|
|
if (configs[backdropId].isReverseWaterGfx) scroll *= -1;
|
|
|
|
float left = -scroll;
|
|
float right = WALL_SIZE - scroll;
|
|
auto length = [&](const WaterLength& value) {
|
|
return value.pixels + (float)(value.widths * room.gridWidth) * GRID_SIZE +
|
|
(float)(value.heights * room.gridHeight) * GRID_SIZE;
|
|
};
|
|
|
|
graphics.blend_set(KAGE::Graphics::BLEND_OPAQUE);
|
|
for (const WaterStrip& strip : water_strips_get(room.GetRoomShape()))
|
|
{
|
|
float start = length(strip.start);
|
|
float end = length(strip.end);
|
|
bool isMirrored = strip.mapping == WATER_DOWN_MIRRORED || strip.mapping == WATER_ALONG_MIRRORED;
|
|
float near = isMirrored ? right : left;
|
|
float far = isMirrored ? left : right;
|
|
SourceQuad source;
|
|
if (strip.mapping == WATER_DOWN || strip.mapping == WATER_DOWN_MIRRORED)
|
|
static_cast<DestinationQuad&>(source) = quad_edges(near, start, far, end);
|
|
else
|
|
{
|
|
source._topLeft = vector_make(near, start);
|
|
source._topRight = vector_make(near, end);
|
|
source._bottomLeft = vector_make(far, start);
|
|
source._bottomRight = vector_make(far, end);
|
|
}
|
|
source._coordinateSpace = KAGE::Graphics::COORDINATES_PIXEL;
|
|
|
|
float* vertices =
|
|
image_draw(*waterGfx, source,
|
|
quad_edges(renderOffset.x + length(strip.left), renderOffset.y + length(strip.top),
|
|
renderOffset.x + length(strip.right), renderOffset.y + length(strip.bottom)));
|
|
if (!vertices) continue;
|
|
|
|
size_t stride = graphics.currentShader->vertex_size_get() / sizeof(float);
|
|
for (int corner = 0; corner < KAGE::Graphics::QUAD_CORNERS; corner++)
|
|
for (int step = 0; step < WATER_DEPTH_STEPS; step++) vertices[corner * stride + 2] += WATER_DEPTH_STEP;
|
|
}
|
|
graphics.blendMode = savedBlend;
|
|
}
|