Curation round 9: floors and walls, room transitions, collision, the first enemies, saving, damage, pickups

Seven agents took over the backdrop's floor and wall rendering, room transitions (StartRoomTransition, on_leave,
room_enter), grid collision with tear hits and decal baking, Entity_NPC's core with the AI dispatch and the first
enemies (flies, Gaper, Pooter, Clotty, Horf, Dip, Spider), the run's save, player damage, PlayerManager::Update,
ShowName, pickups, slots and the common effects. Integration added LuaEngine::PostNewLevel/PostNewRoom, one shared
lua_callback_check (4 copies merged) and the enemy type range the original checks.
Under gdb a run draws its rooms with floors and walls, walks between rooms, fights Gapers with contact damage and the
damage flash, and collects pickups. Next: tears hitting enemies, pathfinding, item pedestals, death.
2891 functions taken over.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shweetandClaude Opus 5.5 committed 2026-11-20 08:24:38 -05:00
1 parent 69a354f843
commit 48933cd312
59 files changed
+13387 -6056

No files matched your search

+71 -19
View File
@@ -30,6 +30,21 @@ constexpr uint32_t RENDER_Z_NORMAL_START = 10000;
constexpr int RENDER_LIST_CAPACITY = 0x4000;
constexpr int RENDER_SORT_SWAP_BUDGET = (RENDER_LIST_CAPACITY >> 4) + 1;
// The room's render surface, its size and margin, centered on the screen.
constexpr float ROOM_SURFACE_WIDTH = 338;
constexpr float ROOM_SURFACE_HEIGHT = 182;
constexpr float ROOM_SURFACE_MARGIN = 52;
// A surface surfaces_bake draws into: the flag of the entities drawn there, the flags that keep them, and whether any
// is to be drawn.
struct SurfacePass
{
KAGE::Graphics::ImageBase* surface = nullptr;
uint64_t flag = 0;
uint64_t keptFlags = 0;
bool isUsed = false;
};
// Formats a message for KAGE_LogMessage, whose declaration takes nothing to format with.
[[gnu::format(printf, 2, 3)]] static void log_format(uint32_t level, const char* format, ...)
{
@@ -47,13 +62,6 @@ static bool is_unit_size(const Entity& entity)
return entity.sizeMulti.x == 1 && entity.sizeMulti.y == 1;
}
// Pushes one entity off another: as circles when neither is stretched, as capsules otherwise.
static void entity_push_apart(Entity& pusher, Entity& other)
{
if (is_unit_size(pusher) && is_unit_size(other)) pusher.push_apart_circle(&other);
else pusher.push_apart_capsule(&other);
}
// 00417670 Drops every occurrence of the entity.
void EntityList_EL::remove(Entity* entity)
{
@@ -150,7 +158,7 @@ void CellSpace::collide_entity(Entity& entity)
{
Entity& other = *cell->entities[i];
if (&other == &entity || !owner->is_pair_new(other, entity)) continue;
entity_push_apart(other, entity);
other.collide_with_entity(&entity);
}
}
}
@@ -170,7 +178,7 @@ void CellSpace::collide(CellSpace& other)
{
Entity& first = *cells[c].entities[i];
Entity& second = *other.cells[c].entities[j];
if (&first != &second && owner->is_pair_new(first, second)) entity_push_apart(first, second);
if (&first != &second && owner->is_pair_new(first, second)) first.collide_with_entity(&second);
}
}
}
@@ -187,7 +195,7 @@ void CellSpace::collide_self()
{
Entity& first = *cell.entities[i];
Entity& second = *cell.entities[j];
if (&first != &second && owner->is_pair_new(first, second)) entity_push_apart(first, second);
if (&first != &second && owner->is_pair_new(first, second)) first.collide_with_entity(&second);
}
}
}
@@ -320,6 +328,53 @@ void EntityList::AddPersistentEntity(Entity* entity)
if (!isListed) persistentEL.push_back(entity);
}
// Draws the entities flagged to render into the floor or the walls into the backdrop's surfaces, at the room
// surface's corner on screen snapped to the display's pixels, and removes them. One drawn into both stays for the
// walls, and one with FLAG_NO_REMOVE_ON_TEX_RENDER stays. Whether any was removed.
static bool surfaces_bake(EntityList_EL& renderEL)
{
Backdrop& backdrop = g_game->room->backdrop;
std::array<SurfacePass, 2> passes = {{
{backdrop.floorBuffer.get(), FLAG_RENDER_FLOOR, FLAG_RENDER_WALL | FLAG_NO_REMOVE_ON_TEX_RENDER},
{backdrop.wallsBuffer.get(), FLAG_RENDER_WALL, FLAG_NO_REMOVE_ON_TEX_RENDER},
}};
auto isDrawn = [](Entity* entity, uint64_t flag) { return entity->isExists && entity->HasEntityFlags(flag); };
for (SurfacePass& pass : passes)
pass.isUsed = std::any_of(renderEL.begin(), renderEL.end(),
[&pass, &isDrawn](Entity* entity) { return isDrawn(entity, pass.flag); });
if (!passes[0].isUsed && !passes[1].isUsed) return false;
KAGE::Graphics::Manager& graphics = KAGE::Graphics::manager;
float pixelScale = g_displayPixelRatio * g_screenPointScale;
auto corner = [pixelScale](float screen, float surface)
{ return -(std::floor(pixelScale * ((screen - surface) * 0.5f - ROOM_SURFACE_MARGIN) + 0.5f) / pixelScale); };
Vector offset = vector_make(corner(g_screenWidth, ROOM_SURFACE_WIDTH), corner(g_screenHeight, ROOM_SURFACE_HEIGHT));
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);
graphics.isCullOffscreen = false;
graphics.blend_set(KAGE::Graphics::BLEND_NORMAL);
bool isRemoved = false;
for (SurfacePass& pass : passes)
{
if (!pass.isUsed) continue;
graphics.SetRenderTarget(pass.surface, KAGE::Graphics::TARGET_OWN_SIZE);
for (size_t i = 0; i < renderEL.size(); i++)
{
Entity* entity = renderEL[i];
if (!isDrawn(entity, pass.flag)) continue;
entity->Render(offset);
if (entity->HasEntityFlags(pass.keptFlags)) continue;
entity->Remove();
isRemoved = true;
}
graphics.Present(KAGE::Graphics::PRESENT_FINISH);
}
graphics.isCullOffscreen = true;
graphics.render_target_pop(KAGE::Graphics::PRESENT_FLUSH);
return isRemoved;
}
// 004186c0 One frame of the room's entities: pre-updates and updates (only those that update in transitions during
// one), the players' in-between updates without interpolation, the enemy and boss counts and the boss bar, the
// removal of the entities that stopped existing, then the collisions and the draw order.
@@ -341,13 +396,8 @@ void EntityList::Update(UpdateMode mode)
isAnyBaited = tally.isAnyBaited;
boss_bar_update(tally);
enemyDamageInflicted = tally.damageInflicted;
for (Entity* entity : renderEL)
{
if (entity->isExists && entity->HasEntityFlags(FLAG_RENDER_FLOOR | FLAG_RENDER_WALL))
reconstruction_missing("EntityList::Update 004186c0: drawing entities into the floor and wall surfaces");
}
if (tally.isAnyRemoved) removed_drop();
bool isBakedAway = surfaces_bake(renderEL);
if (tally.isAnyRemoved || isBakedAway) removed_drop();
if (mode == UPDATE_NORMAL) rebuild_sublists();
sort_by_render_z();
}
@@ -614,8 +664,10 @@ void EntityList::twins_push_apart()
if (twin->playerIndex != -1 && player->playerIndex > twin->playerIndex && twin != player) continue;
bool isEvenFrame = (g_game->frameCount & 1) == 0;
entity_push_apart(isEvenFrame ? *player : *twin, isEvenFrame ? *twin : *player);
entity_push_apart(isEvenFrame ? *twin : *player, isEvenFrame ? *player : *twin);
Entity_Player* first = isEvenFrame ? player : twin;
Entity_Player* second = isEvenFrame ? twin : player;
first->collide_with_entity(second);
second->collide_with_entity(first);
}
}