88 lines
3.4 KiB
C++
88 lines
3.4 KiB
C++
#include "beast_arena.h"
|
|
#include "game.h"
|
|
#include "log.h"
|
|
#include "room.h"
|
|
|
|
constexpr int BACKGROUND_LAYER_COUNT = 15;
|
|
constexpr int BACKGROUND_GLOW_LAYER = 8;
|
|
constexpr int BACKGROUND_ADDITIVE_LAYER = 13;
|
|
constexpr int BACKGROUND_MULTIPLY_LAYER = 14;
|
|
constexpr unsigned int WRAP_REPEAT = 0;
|
|
constexpr unsigned int WRAP_CLAMP = 1;
|
|
constexpr float BACKGROUND_PARALLAX = 0.1f;
|
|
|
|
// The background's layer blending: plain alpha, the glow over what is behind it, added light, and a darkening multiply.
|
|
// The source factor takes premultiplied alpha into account.
|
|
static std::array<int, BLEND_PART_COUNT> blend_get(int layerId)
|
|
{
|
|
int source = KAGE::Graphics::manager.isPremultipliedAlpha ? BLEND_FACTOR_ONE : BLEND_FACTOR_SRC_ALPHA;
|
|
|
|
if (layerId == BACKGROUND_GLOW_LAYER)
|
|
return {BLEND_EQUATION_ADD, source, BLEND_FACTOR_ONE_MINUS_SRC_ALPHA, BLEND_FACTOR_ONE,
|
|
BLEND_FACTOR_ONE_MINUS_SRC_ALPHA};
|
|
if (layerId == BACKGROUND_ADDITIVE_LAYER)
|
|
return {BLEND_EQUATION_ADD, source, BLEND_FACTOR_ONE, BLEND_FACTOR_ONE, BLEND_FACTOR_ONE};
|
|
if (layerId == BACKGROUND_MULTIPLY_LAYER)
|
|
return {BLEND_EQUATION_ADD, BLEND_FACTOR_ZERO, BLEND_FACTOR_SRC_COLOR, BLEND_FACTOR_ZERO, BLEND_FACTOR_SRC_COLOR};
|
|
return {BLEND_EQUATION_ADD, BLEND_FACTOR_ONE, BLEND_FACTOR_ZERO, BLEND_FACTOR_ONE, BLEND_FACTOR_ZERO};
|
|
}
|
|
|
|
// 00839b80 Turns on in Home's Beast crawlspace: loads the hell background once, wraps its layers sideways, sets their
|
|
// blending and stops the scroll.
|
|
void BeastArena::init()
|
|
{
|
|
RoomConfig_Room* config = g_game->room->descriptor->data;
|
|
|
|
isActive = config && config->type == ROOM_DUNGEON && config->stageId == STAGE_ID_HOME;
|
|
if (!isActive) return;
|
|
|
|
if (!background.isLoaded)
|
|
{
|
|
background.Load("gfx/backdrop/hell/background.anm2", GRAPHICS_DEFER);
|
|
background.bitflags |= ANIM_RENDER_SHADER_KEPT;
|
|
background.LoadGraphics();
|
|
background.Play(background.GetDefaultAnimationName(), PLAY_FORCED);
|
|
}
|
|
for (LayerState& layer : background.layerStates)
|
|
{
|
|
layer.wrapSMode = WRAP_REPEAT;
|
|
layer.wrapTMode = WRAP_CLAMP;
|
|
}
|
|
for (int i = 0; i < BACKGROUND_LAYER_COUNT; i++) background.GetLayer(i)->blendMode = blend_get(i);
|
|
scrollRendered = 0;
|
|
scrollSpeed = 0;
|
|
scroll = 0;
|
|
}
|
|
|
|
// 0083a080 Animates the background, scrolls it, and carries the room's entities along: a tenth as far on the
|
|
// background sorting layer, the players and familiars not at all. The Beast's second variant moves its target too,
|
|
// and the players collide with the grid where they are.
|
|
void BeastArena::update()
|
|
{
|
|
if (!isActive) return;
|
|
|
|
background.Update();
|
|
scroll += scrollSpeed;
|
|
scrollRendered = scroll;
|
|
|
|
for (Entity* entity : g_game->room->entityList.updateEL)
|
|
{
|
|
if (entity->type == ENTITY_PLAYER)
|
|
{
|
|
entity->PlayerCollideWithGrid(GRID_COLLISION_APPLY);
|
|
continue;
|
|
}
|
|
if (entity->type == ENTITY_FAMILIAR) continue;
|
|
|
|
float shift = entity->sortingLayer == SORTING_BACKGROUND ? scrollSpeed * BACKGROUND_PARALLAX : scrollSpeed;
|
|
entity->pos.x += shift;
|
|
if (entity->type == ENTITY_BEAST && entity->variant == 1) entity->targetPosition.x += scrollSpeed;
|
|
}
|
|
}
|
|
|
|
// 0083a1b0 Draws the background's light layer over the screen, following the camera.
|
|
void BeastArena::render_light()
|
|
{
|
|
reconstruction_missing("BeastArena::render_light 0083a1b0");
|
|
}
|