Enhance teleporter and map rendering tests

- Added initialization of startup processes in flex_archive_tests to ensure proper setup before teleporter operations.
- Updated assertions to verify the correct allocation and state of processes during teleporter execution.
- Introduced new tests in map_renderer_tests to validate shape rendering, including isolated shape rendering and player sprite integration.
- Enhanced map_sorter_tests with additional checks for occlusion handling and boundary conditions in render order resolution.
This commit is contained in:
Maddo 2026-10-06 21:07:35 +02:00
commit e00f9f3186
16 changed files with 954 additions and 398 deletions

View file

@ -250,14 +250,27 @@ int main()
for (int reservedSlot = 0; reservedSlot < 3; ++reservedSlot) {
teleporterKernel.createProcess(1, teleporterGroups);
}
auto* startupTimer = teleporterKernel.createSystemTimerProcess(1, teleporterGroups);
auto* startupKeyboard = teleporterKernel.createKeyboardProcess(1, teleporterGroups);
auto* startupController = teleporterKernel.createControllerProcess(1, teleporterGroups);
assert(startupTimer && startupKeyboard && startupController);
const auto processIdOf = [](const auto& process) {
return static_cast<remorse::u16>(process->base.bytes[2] |
(static_cast<remorse::u16>(process->base.bytes[3]) << 8));
};
const remorse::u16 startupTimerId = processIdOf(startupTimer);
const remorse::u16 startupKeyboardId = processIdOf(startupKeyboard);
const remorse::u16 startupControllerId = processIdOf(startupController);
bool avatarInStasis = false;
auto* teleporterProcess = teleporterKernel.createTeleporterProcess(1, 1, 0x1e,
teleporterGroups, true, false, avatarInStasis);
const remorse::u16 teleporterProcessId = static_cast<remorse::u16>(
teleporterProcess->base.bytes[2] | (static_cast<remorse::u16>(teleporterProcess->base.bytes[3]) << 8));
assert(avatarInStasis && teleporterKernel.allocationSizeAt(4) == 0x33 &&
teleporterKernel.processAt(4)->bytes[0] == 0x5e &&
teleporterKernel.processAt(4)->bytes[1] == 0x0f);
const remorse::u16 clearStasisProcessId = static_cast<remorse::u16>(teleporterProcessId + 1);
assert(avatarInStasis && clearStasisProcessId > startupControllerId &&
teleporterKernel.allocationSizeAt(clearStasisProcessId) == 0x33 &&
teleporterKernel.processAt(clearStasisProcessId)->bytes[0] == 0x5e &&
teleporterKernel.processAt(clearStasisProcessId)->bytes[1] == 0x0f);
assert(!remorse::TeleporterProcess::run(*teleporterProcess, spawnSearchWorld, 2, *typeFlags));
assert(spawnSearchWorld.findItem(1)->data.x == 0 && spawnSearchWorld.findItem(1)->data.y == 0);
struct TeleporterPassContext {
@ -288,12 +301,19 @@ int main()
};
teleporterKernel.scanRunnableProcesses(1, runTeleporterPass, &teleporterPass);
assert(!avatarInStasis && !teleporterPass.teleported &&
teleporterKernel.processAt(startupTimerId) == &startupTimer->base &&
teleporterKernel.processAt(startupKeyboardId) == &startupKeyboard->base &&
teleporterKernel.processAt(startupControllerId) == &startupController->base &&
teleporterKernel.processAt(clearStasisProcessId) == nullptr &&
teleporterKernel.processAt(teleporterProcessId) == &teleporterProcess->base &&
spawnSearchWorld.findItem(1)->data.x == 0 && spawnSearchWorld.findItem(1)->data.y == 0);
teleporterKernel.scanRunnableProcesses(1, runTeleporterPass, &teleporterPass);
assert(teleporterPass.teleported);
assert(teleporterKernel.processAt(teleporterProcessId) == nullptr &&
teleporterKernel.allocationSizeAt(teleporterProcessId) == 0 && teleporterGroups[1] == 3);
teleporterKernel.allocationSizeAt(teleporterProcessId) == 0 && teleporterGroups[1] == 6 &&
teleporterKernel.processAt(startupTimerId) == &startupTimer->base &&
teleporterKernel.processAt(startupKeyboardId) == &startupKeyboard->base &&
teleporterKernel.processAt(startupControllerId) == &startupController->base);
assert(spawnEgg->recordIndex < fixedMap->entries.size());
const auto& startingEggRecord = fixedMap->entries[spawnEgg->recordIndex];
const auto* spawnedAvatar = spawnSearchWorld.findItem(1);
@ -302,6 +322,44 @@ int main()
assert(spawnedAvatar && spawnedAvatar->itemNumber == 1 &&
spawnedAvatar->data.x == spawnEgg->data.x && spawnedAvatar->data.y == spawnEgg->data.y &&
spawnedAvatar->data.z == spawnEgg->data.z && spawnedAvatar->data.mapNumber == 1);
remorse::LiveFixedMapItems integratedStartupWorld(*stagedItems);
assert(integratedStartupWorld.initializeAvatar());
remorse::ProcessKernel integratedStartupKernel;
remorse::u16 integratedStartupGroups[32]{};
for (int reservedSlot = 0; reservedSlot < 3; ++reservedSlot) {
integratedStartupKernel.createProcess(1, integratedStartupGroups);
}
auto* integratedTimer = integratedStartupKernel.createSystemTimerProcess(1, integratedStartupGroups);
auto* integratedKeyboard = integratedStartupKernel.createKeyboardProcess(1, integratedStartupGroups);
auto* integratedController = integratedStartupKernel.createControllerProcess(1, integratedStartupGroups);
assert(remorse::runFreshGameTeleporterStartup(integratedStartupKernel, integratedStartupWorld,
1, 0x1e, *typeFlags, integratedStartupGroups));
const auto* integratedAvatar = integratedStartupWorld.findItem(1);
assert(integratedTimer && integratedKeyboard && integratedController && integratedAvatar &&
integratedAvatar->data.x == spawnEgg->data.x && integratedAvatar->data.y == spawnEgg->data.y &&
integratedAvatar->data.mapNumber == 1 && integratedStartupGroups[1] == 6 &&
integratedStartupKernel.processAt(processIdOf(integratedTimer)) == &integratedTimer->base &&
integratedStartupKernel.processAt(processIdOf(integratedKeyboard)) == &integratedKeyboard->base &&
integratedStartupKernel.processAt(processIdOf(integratedController)) == &integratedController->base);
const auto stagingTeleporter = remorse::findNearbyActiveTeleportEgg(*integratedAvatar,
integratedStartupWorld.mapItems(), *typeFlags, 1);
const auto levelStartEgg = remorse::findTeleportEgg(*stagedItems, *typeFlags, 0x63);
assert(stagingTeleporter && stagingTeleporter->itemNumber == 1598 &&
stagingTeleporter->data.shape == 0x0194 && stagingTeleporter->data.frame == 0 &&
stagingTeleporter->data.quality == 0x0063 && stagingTeleporter->data.mapNumber == 1 &&
levelStartEgg && levelStartEgg->itemNumber == 6812 && levelStartEgg->data.x == 30328 &&
levelStartEgg->data.y == 29656 && levelStartEgg->data.z == 16);
assert(remorse::runFreshGameTeleporterStartup(integratedStartupKernel, integratedStartupWorld,
stagingTeleporter->data.mapNumber,
static_cast<remorse::u8>(stagingTeleporter->data.quality & 0xff), *typeFlags,
integratedStartupGroups));
integratedAvatar = integratedStartupWorld.findItem(1);
assert(integratedAvatar && integratedAvatar->data.x == levelStartEgg->data.x &&
integratedAvatar->data.y == levelStartEgg->data.y && integratedAvatar->data.z == levelStartEgg->data.z &&
integratedAvatar->data.mapNumber == 1 && integratedStartupGroups[1] == 6 &&
integratedStartupKernel.processAt(processIdOf(integratedTimer)) == &integratedTimer->base &&
integratedStartupKernel.processAt(processIdOf(integratedKeyboard)) == &integratedKeyboard->base &&
integratedStartupKernel.processAt(processIdOf(integratedController)) == &integratedController->base);
const auto spawnUseCandidates = remorse::itemGrabSearchCandidates(
*spawnedAvatar, spawnSearchWorld.mapItems(), *typeFlags);
assert(spawnUseCandidates);

View file

@ -3,6 +3,7 @@
#include "remorse/fixed_map.h"
#include "remorse/glob_archive.h"
#include "remorse/map_renderer.h"
#include "remorse/shape_archive.h"
#include "remorse/type_flags.h"
#include <algorithm>
@ -80,6 +81,31 @@ int main()
remorse::LiveFixedMapItems liveSceneItems(*stagedItems);
auto cachedRenderer = remorse::loadMapSceneRenderer(*root, 1);
assert(cachedRenderer);
const auto shape60Item = std::find_if(stagedItems->begin(), stagedItems->end(), [](const auto& item) {
return item.data.shape == 0x003c;
});
assert(shape60Item != stagedItems->end());
const auto shape60Frame = remorse::decodeShapeFrame(cachedRenderer->shapes, 0x003c,
shape60Item->data.frame);
assert(shape60Frame && std::any_of(shape60Frame->pixels.begin(), shape60Frame->pixels.end(),
[](remorse::s16 color) { return color >= 0; }));
assert(((*shapeTypes)[0x003c].flags & 0x400) != 0);
remorse::MapSceneRenderer isolatedShape60 = *cachedRenderer;
isolatedShape60.map.entries = {fixedMap->entries[shape60Item->recordIndex]};
remorse::MapRenderOptions shape60Options;
shape60Options.mapIndex = 1;
shape60Options.maxWidth = 320;
shape60Options.maxHeight = 200;
shape60Options.includeHiddenMarkers = true;
shape60Options.viewCenter = remorse::WorldPoint{
static_cast<remorse::s32>(fixedMap->entries[shape60Item->recordIndex].x),
static_cast<remorse::s32>(fixedMap->entries[shape60Item->recordIndex].y),
fixedMap->entries[shape60Item->recordIndex].z};
assert(!isolatedShape60.render(shape60Options));
shape60Options.includeRoofs = true;
const auto isolatedShape60Image = isolatedShape60.render(shape60Options);
assert(isolatedShape60Image && isolatedShape60Image->renderItemCount == 1 &&
isolatedShape60Image->decodedItemCount == 1 && isolatedShape60Image->paintedItemCount == 1);
const auto liveBefore = cachedRenderer->render(options, &liveSceneItems);
const auto samePixels = [](const auto& left, const auto& right) {
return left.size() == right.size() && std::equal(left.begin(), left.end(), right.begin(),
@ -88,6 +114,57 @@ int main()
});
};
assert(liveBefore && samePixels(liveBefore->pixels, startingScene->pixels));
const auto playerFrame = remorse::decodeShapeFrame(cachedRenderer->shapes, 1, 0);
assert(playerFrame);
const remorse::MapRenderSprite playerSprite{spawn, 1, 0, false,
&*playerFrame, &cachedRenderer->palette};
const auto sceneWithPlayer = cachedRenderer->render(options, &liveSceneItems, &playerSprite);
assert(sceneWithPlayer && sceneWithPlayer->renderItemCount == liveBefore->renderItemCount + 1 &&
!samePixels(sceneWithPlayer->pixels, liveBefore->pixels));
assert(sceneWithPlayer->coverage.size() == sceneWithPlayer->pixels.size() &&
std::any_of(sceneWithPlayer->coverage.begin(), sceneWithPlayer->coverage.end(),
[](remorse::u8 covered) { return covered != 0; }));
remorse::MapRenderOptions fullPlayerReferenceOptions = options;
fullPlayerReferenceOptions.maxWidth = 512;
fullPlayerReferenceOptions.maxHeight = 384;
const auto fullPlayerReference = cachedRenderer->render(
fullPlayerReferenceOptions, &liveSceneItems, &playerSprite);
assert(fullPlayerReference);
remorse::MapRenderOptions playerPatchOptions = fullPlayerReferenceOptions;
playerPatchOptions.worldRect = remorse::WorldRect{
spawn.x - 2048, spawn.y - 2048, spawn.x + 2048, spawn.y + 2048};
const auto playerPatch = cachedRenderer->render(playerPatchOptions, &liveSceneItems, &playerSprite);
assert(playerPatch && playerPatch->sourceLeft == fullPlayerReference->sourceLeft &&
playerPatch->sourceTop == fullPlayerReference->sourceTop);
for (std::size_t index = 0; index < playerPatch->coverage.size(); ++index) {
if (playerPatch->coverage[index] != 0) {
assert(playerPatch->pixels[index].red == fullPlayerReference->pixels[index].red &&
playerPatch->pixels[index].green == fullPlayerReference->pixels[index].green &&
playerPatch->pixels[index].blue == fullPlayerReference->pixels[index].blue);
}
}
const remorse::WorldPoint warpPosition{30463 * 2, 29951 * 2, 0};
const remorse::MapRenderSprite warpPlayer{warpPosition, 1, 0, false,
&*playerFrame, &cachedRenderer->palette};
remorse::MapRenderOptions warpReferenceOptions = fullPlayerReferenceOptions;
warpReferenceOptions.includeRoofs = true;
warpReferenceOptions.viewCenter = warpPosition;
const auto warpReference = cachedRenderer->render(warpReferenceOptions, nullptr, &warpPlayer);
assert(warpReference);
remorse::MapRenderOptions warpPatchOptions = warpReferenceOptions;
warpPatchOptions.worldRect = remorse::WorldRect{
warpPosition.x - 2560, warpPosition.y - 2560,
warpPosition.x + 2560, warpPosition.y + 2560};
const auto warpPatch = cachedRenderer->render(warpPatchOptions, nullptr, &warpPlayer);
assert(warpPatch && warpPatch->sourceLeft == warpReference->sourceLeft &&
warpPatch->sourceTop == warpReference->sourceTop);
for (std::size_t index = 0; index < warpPatch->coverage.size(); ++index) {
if (warpPatch->coverage[index] != 0) {
assert(warpPatch->pixels[index].red == warpReference->pixels[index].red &&
warpPatch->pixels[index].green == warpReference->pixels[index].green &&
warpPatch->pixels[index].blue == warpReference->pixels[index].blue);
}
}
const remorse::s32 redrawRadius = static_cast<remorse::s32>(
options.maxWidth + options.maxHeight * 2 + 512);
options.worldRect = remorse::WorldRect{spawn.x - redrawRadius, spawn.y - redrawRadius,

View file

@ -49,6 +49,28 @@ int main()
assert(order[0] == 1);
assert(order[1] == 0);
remorse::detail::RenderSortItem occluder = elevated;
occluder.occludes = true;
const std::vector<remorse::detail::RenderSortItem> occludedPlayerItems{occluder, ground};
const std::vector<std::size_t> occludedPlayerOrder =
remorse::detail::resolveRenderOrder(occludedPlayerItems);
assert(occludedPlayerOrder.size() == 1 && occludedPlayerOrder[0] == 0);
remorse::detail::RenderSortItem boundaryOccluder = occluder;
boundaryOccluder.left = 120;
boundaryOccluder.top = 120;
boundaryOccluder.right = 184;
boundaryOccluder.bottom = 184;
remorse::detail::RenderSortItem boundaryPlayer = ground;
boundaryPlayer.left = 128;
boundaryPlayer.top = 128;
boundaryPlayer.right = 160;
boundaryPlayer.bottom = 160;
const std::vector<remorse::detail::RenderSortItem> boundaryItems{
boundaryOccluder, boundaryPlayer};
const std::vector<std::size_t> boundaryOrder = remorse::detail::resolveRenderOrder(boundaryItems);
assert(boundaryOrder.size() == 1 && boundaryOrder[0] == 0);
remorse::detail::RenderSortItem animatedFlat = elevated;
animatedFlat.x = 64;
animatedFlat.xLeft = 64;