Curation round 8: the first room plays: Isaac walks and shoots tears
Eight agents took over Room::Init's pieces, RailManager, Room::Render/render_lighting/Update, the GridEntity hierarchy (walls, doors, rocks, pits, poop ...), Game::Update and interpolate_update, the run's save, update_ingame_input, Game::Spawn with the entity factory and grid collision, the player's movement and tears through Weapon/Weapon_Tears, PlayerManager's positions, the camera focus, MinimapConfig, PlayerHUD, mod shader rendering, Entity_Tear and Entity_Effect. Integration wrote Level::get_secret_exit_kind, shared the secret-exit enum (four copies merged) and fixed the generator's vtable-stub check (word boundary and namespace, not a substring). Under gdb a run reaches the first room: doors, HUD with hearts and minimap, WASD movement with acceleration, arrow-key tears that fly and splash. Floor and walls (Backdrop::RenderFloor/RenderWalls) and room transitions are next. The official build/isaac reaches the start room and stops at Entity_NPC::Redirect. 2770 functions taken over. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b85591bdf4
commit
69a354f843
140 files changed
+23561
-20206
No files matched your search
@@ -0,0 +1,293 @@
|
||||
#include "entity_player.h"
|
||||
#include "game.h"
|
||||
#include "grid_entity_door.h"
|
||||
#include "log.h"
|
||||
#include "room.h"
|
||||
#include <cmath>
|
||||
|
||||
// What crushes rocks on contact: The Nail, Leo (worn or rolled by Zodiac), Thunder Thighs, Stompy and Mega Mush.
|
||||
constexpr int COLLECTIBLE_THE_NAIL = 83;
|
||||
constexpr int COLLECTIBLE_LEO = 302;
|
||||
constexpr int COLLECTIBLE_THUNDER_THIGHS = 314;
|
||||
constexpr int PLAYERFORM_STOMPY = 13;
|
||||
|
||||
// A poop's reach for a player's collision: a giga poop's quarter from its shared center, any other from its cell's.
|
||||
constexpr int POOP_GIGA_FIRST = 7;
|
||||
constexpr int POOP_GIGA_LAST = 10;
|
||||
constexpr float POOP_GIGA_REACH = 38;
|
||||
constexpr float POOP_REACH = 18;
|
||||
constexpr float POOP_GIGA_QUARTER = 20;
|
||||
constexpr std::array<float, 4> POOP_GIGA_CENTER_X = {POOP_GIGA_QUARTER, -POOP_GIGA_QUARTER, POOP_GIGA_QUARTER,
|
||||
-POOP_GIGA_QUARTER};
|
||||
constexpr std::array<float, 4> POOP_GIGA_CENTER_Y = {POOP_GIGA_QUARTER, POOP_GIGA_QUARTER, -POOP_GIGA_QUARTER,
|
||||
-POOP_GIGA_QUARTER};
|
||||
|
||||
// The grid collision a player passes, through the Lost's mirror door or past a wall it is pushed out of.
|
||||
constexpr uint32_t GRID_COLLISION_WALL_EXCEPT_PLAYER = 5;
|
||||
constexpr int MIRROR_DIMENSION = 1;
|
||||
|
||||
// The Beast's dungeon keeps players this far above its floor's center line.
|
||||
constexpr float BEAST_DUNGEON_OFFSET_Y = 20;
|
||||
// A wall hit keeps this much of the speed into it, and pushes back this much more.
|
||||
constexpr float WALL_BOUNCE = 0.9f;
|
||||
constexpr float WALL_PUSH = 0.1f;
|
||||
constexpr float NORMAL_EPSILON = 0.001f;
|
||||
constexpr float PUSH_OUT_MIN_SPEED = 2;
|
||||
constexpr int PUSH_OUT_STEPS_GROUND = 12;
|
||||
constexpr int PUSH_OUT_STEPS = 6;
|
||||
|
||||
// The room types whose doors Notched Axe hacks open.
|
||||
constexpr int ROOM_TYPE_SECRET = 7;
|
||||
constexpr int ROOM_TYPE_SUPERSECRET = 8;
|
||||
|
||||
// A world position's cell index in the room, or -1 off its grid.
|
||||
static int grid_index_at(Room& room, Vector position)
|
||||
{
|
||||
int column = (int)((position.x - GRID_ORIGIN_X) / GRID_CELL_SIZE + 0.5f);
|
||||
int row = (int)((position.y - GRID_ORIGIN_Y) / GRID_CELL_SIZE + 0.5f);
|
||||
if (column < 0 || column >= room.gridWidth || row < 0 || row >= room.gridHeight) return -1;
|
||||
return room.gridWidth * row + column;
|
||||
}
|
||||
|
||||
// The grid entity on a cell, or none past the grid.
|
||||
static GridEntity* grid_entity_at(Room& room, int gridIndex)
|
||||
{
|
||||
return gridIndex >= 0 && gridIndex < ROOM_GRID_CELLS ? room.gridEntities[gridIndex] : nullptr;
|
||||
}
|
||||
|
||||
// 006b5fd0 The grid collision a player meets at a position: a poop only within its reach, the Lost's way through a
|
||||
// mirror door, and walls for anyone but a main player.
|
||||
uint32_t Entity_Player::get_grid_collision_at(Vector position)
|
||||
{
|
||||
Room& room = *g_game->room;
|
||||
int gridIndex = grid_index_at(room, position);
|
||||
uint32_t collision = room.GetGridCollision(gridIndex);
|
||||
GridEntity* grid = grid_entity_at(room, gridIndex);
|
||||
if (collision == COLLISION_SOLID && grid && grid->type == GRID_POOP)
|
||||
{
|
||||
bool isGiga = grid->variant >= POOP_GIGA_FIRST && grid->variant <= POOP_GIGA_LAST;
|
||||
Vector center = room.GetGridPosition(grid->gridIndex);
|
||||
if (isGiga)
|
||||
{
|
||||
center.x += POOP_GIGA_CENTER_X[grid->variant - POOP_GIGA_FIRST];
|
||||
center.y += POOP_GIGA_CENTER_Y[grid->variant - POOP_GIGA_FIRST];
|
||||
}
|
||||
float dx = position.x - center.x;
|
||||
float dy = position.y - center.y;
|
||||
float reach = isGiga ? POOP_GIGA_REACH : POOP_REACH;
|
||||
if (dy * dy + dx * dx > reach * reach) collision = COLLISION_NONE;
|
||||
}
|
||||
|
||||
if (collision == COLLISION_WALL)
|
||||
{
|
||||
if (type != ENTITY_PLAYER || !grid || grid->type != GRID_DOOR) return COLLISION_WALL;
|
||||
GridEntity_Door& door = static_cast<GridEntity_Door&>(*grid);
|
||||
if (!(door.doorFlags & DOOR_FLAG_MIRROR) || door.state == DOOR_STATE_OPEN) return COLLISION_WALL;
|
||||
bool isSpirit = GetHealthType() == HEALTH_NO_HEALTH || HasInstantDeathCurse();
|
||||
if (!isSpirit && g_game->currentDimensionIdx != MIRROR_DIMENSION) return COLLISION_WALL;
|
||||
collision = GRID_COLLISION_WALL_EXCEPT_PLAYER;
|
||||
}
|
||||
else if (collision != GRID_COLLISION_WALL_EXCEPT_PLAYER) return collision;
|
||||
|
||||
// The original reads a non-player's fields here. A non-player meets the wall.
|
||||
if (type != ENTITY_PLAYER || variant != 0 || isCoopGhost || parent || IsHologram()) return COLLISION_WALL;
|
||||
return collision;
|
||||
}
|
||||
|
||||
// 007c3380 Whether the player crushes rocks it walks into.
|
||||
bool Entity_Player::CanCrushRocks()
|
||||
{
|
||||
return temporaryEffects.HasCollectibleEffect(COLLECTIBLE_THE_NAIL) || HasCollectible(COLLECTIBLE_LEO) ||
|
||||
temporaryEffects.HasCollectibleEffect(COLLECTIBLE_LEO) || GetZodiacEffect() == COLLECTIBLE_LEO ||
|
||||
HasCollectible(COLLECTIBLE_THUNDER_THIGHS) || HasPlayerForm(PLAYERFORM_STOMPY) ||
|
||||
temporaryEffects.HasCollectibleEffect(COLLECTIBLE_MEGA_MUSH);
|
||||
}
|
||||
|
||||
// Mega Mush's stomp on a block, pillar or lock: the cell becomes a plain rock (the original's inlined
|
||||
// Room::SpawnGridEntity), which the stomp breaks.
|
||||
static void mega_mush_crush(Room& room, Entity& player, GridEntity& grid, int gridIndex)
|
||||
{
|
||||
uint32_t seed = grid.spawnSeed;
|
||||
GridEntity* old = room.gridEntities[gridIndex];
|
||||
if (old && old->type != GRID_DECORATION)
|
||||
{
|
||||
room.gridPaths[gridIndex] = GRID_PATH_FREED;
|
||||
room.gridEntities[gridIndex] = nullptr;
|
||||
delete old;
|
||||
}
|
||||
if (room.gridPaths[gridIndex] <= GRID_PATH_FREED)
|
||||
{
|
||||
GridEntity* rock = CreateGridEntity(GRID_ROCK, gridIndex);
|
||||
delete room.gridEntities[gridIndex];
|
||||
room.gridEntities[gridIndex] = rock;
|
||||
rock->variant = 0;
|
||||
rock->varData = 0;
|
||||
rock->Init(seed);
|
||||
}
|
||||
if (room.gridEntities[gridIndex]) room.gridEntities[gridIndex]->Destroy(false, EntityRef(&player));
|
||||
}
|
||||
|
||||
// A crushed rock bridges the pit beyond it, on the axis the player came along.
|
||||
static void crush_bridge(Room& room, Entity& player, GridEntity& rock)
|
||||
{
|
||||
Vector center = room.GetGridPosition(rock.gridIndex);
|
||||
float dx = center.x - player.pos.x;
|
||||
float dy = center.y - player.pos.y;
|
||||
float directionX = 0;
|
||||
float directionY = 0;
|
||||
if (std::abs(dx) > std::abs(dy)) directionX = dx < 0 ? -1 : 1;
|
||||
else directionY = dy < 0 ? -1 : 1;
|
||||
|
||||
int beyond = grid_index_at(
|
||||
room, vector_make(center.x + directionX * GRID_CELL_SIZE, center.y + directionY * GRID_CELL_SIZE));
|
||||
if (beyond < 0) return;
|
||||
GridEntity* pit = grid_entity_at(room, beyond);
|
||||
if (pit && pit->type == GRID_PIT) reconstruction_missing("Room::TryMakeBridge 0081e6e0");
|
||||
}
|
||||
|
||||
// What a player does to the grid entity at one of its collision points: Mega Mush stomps blocks and kicks doors and
|
||||
// webs, rock crushers break what they touch, Notched Axe opens secret doors. Returns whether the point is spent on it.
|
||||
static bool player_grid_act(Room& room, Entity_Player& player, GridEntity* grid, int gridIndex, uint32_t collision)
|
||||
{
|
||||
if (player.temporaryEffects.HasCollectibleEffect(COLLECTIBLE_MEGA_MUSH) && grid)
|
||||
{
|
||||
bool isStompable = grid->type == GRID_ROCKB || grid->type == GRID_PILLAR || grid->type == GRID_LOCK;
|
||||
if (isStompable && collision != COLLISION_NONE)
|
||||
{
|
||||
mega_mush_crush(room, player, *grid, gridIndex);
|
||||
return true;
|
||||
}
|
||||
if (grid->type == GRID_DOOR && collision == COLLISION_WALL)
|
||||
{
|
||||
static_cast<GridEntity_Door*>(grid)->TryBlowOpen(true, &player);
|
||||
return true;
|
||||
}
|
||||
if (grid->type == GRID_SPIDERWEB) grid->Destroy(false, EntityRef(&player));
|
||||
}
|
||||
if (!grid) return false;
|
||||
|
||||
bool isSolid = collision == COLLISION_SOLID || collision == COLLISION_OBJECT;
|
||||
bool isCrusher = player.CanCrushRocks() ||
|
||||
(grid->type == GRID_POOP && player.temporaryEffects.HasCollectibleEffect(COLLECTIBLE_MARS));
|
||||
bool isBreakable = grid->collisionClass == COLLISION_SOLID || grid->collisionClass == COLLISION_OBJECT;
|
||||
if (isSolid && isCrusher && isBreakable && grid->Destroy(false, EntityRef(&player)))
|
||||
{
|
||||
crush_bridge(room, player, *grid);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (collision != COLLISION_WALL || grid->type != GRID_DOOR || player.itemState != COLLECTIBLE_NOTCHED_AXE)
|
||||
return false;
|
||||
GridEntity_Door& door = static_cast<GridEntity_Door&>(*grid);
|
||||
bool isSecret = door.currentRoomType == ROOM_TYPE_SECRET || door.targetRoomType == ROOM_TYPE_SECRET ||
|
||||
door.currentRoomType == ROOM_TYPE_SUPERSECRET || door.targetRoomType == ROOM_TYPE_SUPERSECRET;
|
||||
if (!isSecret) return false;
|
||||
if (GridEntity* target = grid_entity_at(room, gridIndex)) target->Destroy(false, EntityRef(&player));
|
||||
return true;
|
||||
}
|
||||
|
||||
// Keeps a player inside the room: out of the walls, and in the Beast's dungeon above its floor's line.
|
||||
static void player_room_clamp(Entity& player, Room& room, GridCollisionMode mode)
|
||||
{
|
||||
bool isSimulated = mode == GRID_COLLISION_SIMULATE;
|
||||
Vector clamped = room.GetClampedPositionImpl(player.pos, 0, 0, 0, 0);
|
||||
if (room.IsBeastDungeon())
|
||||
{
|
||||
float margin = player.size;
|
||||
Vector lifted = room.GetClampedPositionImpl(vector_make(player.pos.x, player.pos.y - BEAST_DUNGEON_OFFSET_Y),
|
||||
margin, margin, margin, margin);
|
||||
lifted.y += BEAST_DUNGEON_OFFSET_Y;
|
||||
if (!isSimulated) player.isCollidesWithGrid = player.pos.x != lifted.x || player.pos.y != lifted.y;
|
||||
player.pos = lifted;
|
||||
return;
|
||||
}
|
||||
|
||||
Entity_Player& self = static_cast<Entity_Player&>(player);
|
||||
if (room.GetGridIndex(player.pos) >= 0 && self.get_grid_collision_at(player.pos) != COLLISION_WALL) return;
|
||||
if (!isSimulated) player.isCollidesWithGrid = player.pos.x != clamped.x || player.pos.y != clamped.y;
|
||||
if (room.roomType != ROOM_DUNGEON) player.pos = clamped;
|
||||
}
|
||||
|
||||
// 006ab440 A player's collision with the room's grid: clamped into the room, acting on what its collision points touch,
|
||||
// then pushed out along the walls' normal and slowed against them. Simulating (Interpolate's prediction) only moves the
|
||||
// position.
|
||||
void Entity::PlayerCollideWithGrid(GridCollisionMode mode)
|
||||
{
|
||||
Entity_Player* player = dynamic_cast<Entity_Player*>(this);
|
||||
// The original carries on with a non-player and crashes on its effects. It stops here instead.
|
||||
if (!player)
|
||||
{
|
||||
KAGE_LogMessage(LOG_ASSERT, (uint8_t*)"Called PlayerCollideWithGrid with "
|
||||
"Entity type != Entity_Player\n");
|
||||
return;
|
||||
}
|
||||
bool isSimulated = mode == GRID_COLLISION_SIMULATE;
|
||||
if (!isSimulated) isCollidesWithGrid = false;
|
||||
if (entityGridCollisionClass == GRIDCOLL_NONE || collisionPoints.empty() || minecart) return;
|
||||
|
||||
Room& room = *g_game->room;
|
||||
player_room_clamp(*this, room, mode);
|
||||
|
||||
Vector normal{};
|
||||
for (const Vector& point : collisionPoints)
|
||||
{
|
||||
Vector position = vector_make(pos.x + point.x, pos.y + point.y);
|
||||
int gridIndex = grid_index_at(room, position);
|
||||
if (gridIndex < 0) continue;
|
||||
GridEntity* grid = grid_entity_at(room, gridIndex);
|
||||
uint32_t collision = player->get_grid_collision_at(position);
|
||||
if (!isSimulated && player_grid_act(room, *player, grid, gridIndex, collision)) continue;
|
||||
|
||||
bool isWall = collision == COLLISION_WALL || (collision == COLLISION_SOLID && grid && grid->type == GRID_DOOR);
|
||||
bool isBlocked = collision != COLLISION_NONE && collision != GRID_COLLISION_WALL_EXCEPT_PLAYER;
|
||||
if ((entityGridCollisionClass == GRIDCOLL_WALLS && isWall) ||
|
||||
(entityGridCollisionClass == GRIDCOLL_GROUND && isBlocked))
|
||||
{
|
||||
normal.x += point.x;
|
||||
normal.y += point.y;
|
||||
}
|
||||
}
|
||||
|
||||
float lengthSquared = normal.x * normal.x + normal.y * normal.y;
|
||||
if (lengthSquared < NORMAL_EPSILON)
|
||||
{
|
||||
if (!isSimulated) gridCollisionNormal = {};
|
||||
return;
|
||||
}
|
||||
float length = std::sqrt(lengthSquared);
|
||||
if (length > 0)
|
||||
{
|
||||
normal.x *= 1 / length;
|
||||
normal.y *= 1 / length;
|
||||
}
|
||||
if (!isSimulated) gridCollisionNormal = normal;
|
||||
|
||||
float approach = -normal.x * velocity.x - normal.y * velocity.y;
|
||||
if (approach < 0 && !isSimulated)
|
||||
{
|
||||
isCollidesWithGrid = true;
|
||||
gridCollisionVelocity = velocity;
|
||||
float push = approach * WALL_BOUNCE - WALL_PUSH;
|
||||
velocity.x += push * gridCollisionNormal.x;
|
||||
velocity.y += push * gridCollisionNormal.y;
|
||||
}
|
||||
|
||||
float depth = std::sqrt(normal.y * sizeMulti.y * (normal.y * sizeMulti.y) +
|
||||
normal.x * sizeMulti.x * (normal.x * sizeMulti.x)) *
|
||||
size;
|
||||
float speed = std::sqrt(velocity.x * velocity.x + velocity.y * velocity.y);
|
||||
float freeDepth = depth - std::max(speed, PUSH_OUT_MIN_SPEED);
|
||||
float blockedDepth = depth;
|
||||
bool isGround = entityGridCollisionClass == GRIDCOLL_GROUND;
|
||||
for (int step = 0; step < (isGround ? PUSH_OUT_STEPS_GROUND : PUSH_OUT_STEPS); step++)
|
||||
{
|
||||
float middle = (blockedDepth - freeDepth) * 0.5f + freeDepth;
|
||||
uint32_t collision =
|
||||
player->get_grid_collision_at(vector_make(normal.x * middle + pos.x, normal.y * middle + pos.y));
|
||||
bool isFree = isGround ? collision == COLLISION_NONE || collision == GRID_COLLISION_WALL_EXCEPT_PLAYER
|
||||
: collision != COLLISION_WALL;
|
||||
(isFree ? freeDepth : blockedDepth) = middle;
|
||||
}
|
||||
pos.x += normal.x * (freeDepth - depth);
|
||||
pos.y += normal.y * (freeDepth - depth);
|
||||
}
|
||||
Reference in new issue
Block a user