Enhance animation and control tests; improve rendering and shape loading validation

- Added tests for player animations in animation_archive_tests to ensure all animations are loaded correctly.
- Updated entity_dispatch_entry_tests to validate animation direction updates and added tests for sixteen-direction animations.
- Expanded isometric_controls_tests with comprehensive key event handling and action requests for various controller states.
- Improved map_renderer_tests by adding viewport rendering tests to compare unbounded and bounded views.
- Enhanced shape_archive_tests to validate shape frame loading and decoding consistency.
This commit is contained in:
Maddo 2026-10-07 00:18:08 +02:00
commit a76b071049
28 changed files with 1608 additions and 154 deletions

View file

@ -66,6 +66,8 @@ struct AppState {
remorse::StandProcessEntry* diagnosticStand = nullptr;
remorse::KeyboardProcessEntry* diagnosticKeyboard = nullptr;
remorse::ControllerMovementState controllerMovement;
std::optional<remorse::ControllerCommandRequest> lastControllerCommand;
std::optional<remorse::ControllerMovementRequest> activeOneShotMovement;
remorse::u16 animationProcessId = 0;
std::optional<remorse::LiveFixedMapItems> liveItems;
std::optional<remorse::StagedFixedMapItem> diagnosticItem;
@ -82,14 +84,12 @@ struct AppState {
std::condition_variable renderWake;
bool renderRequested = false;
bool renderFullRequested = false;
std::uint64_t renderGeneration = 0;
bool renderFullInFlight = false;
bool renderStop = false;
std::optional<remorse::RenderedMapImage> scene;
std::optional<remorse::RenderedMapImage> playerPatch;
std::optional<remorse::MapSceneRenderer> renderer;
std::optional<remorse::AnimationClip> standAnimation;
std::optional<remorse::AnimationClip> walkAnimation;
std::optional<remorse::AnimationClip> runAnimation;
std::array<std::optional<remorse::AnimationClip>, 0x40> playerAnimations;
std::vector<std::optional<remorse::DecodedShapeFrame>> playerFrames;
remorse::CollisionBody playerCollisionBody{};
std::vector<remorse::CollisionBody> collisionBodies;
@ -111,7 +111,10 @@ struct AppState {
remorse::u8 playerAnimation = 0;
remorse::u8 playerDirection = 14;
remorse::u8 playerFrame = 0;
bool playerKneeling = false;
bool playerHasActiveWeapon = false;
std::wstring loadError;
bool loadErrorShown = false;
bool sceneLoaded = false;
std::thread sceneThread;
std::thread renderThread;
@ -153,6 +156,29 @@ void setLoadFailure(AppState& state, const std::wstring& message)
state.sceneLoaded = true;
}
void reportLoadFailure(HWND window, AppState& state, const std::wstring& message)
{
setLoadFailure(state, message);
if (!PostMessageW(window, sceneReadyMessage, 0, 0)) {
InvalidateRect(window, nullptr, FALSE);
}
}
void displayLoadFailure(HWND window, AppState& state)
{
std::wstring message;
{
std::lock_guard<std::mutex> lock(state.sceneMutex);
if (state.loadError.empty() || state.loadErrorShown) {
return;
}
state.loadErrorShown = true;
message = state.loadError;
}
InvalidateRect(window, nullptr, FALSE);
MessageBoxW(window, message.c_str(), L"Crusader map loading failed", MB_OK | MB_ICONERROR);
}
remorse::WorldPoint avatarWorld(const AppState& state)
{
const auto* avatar = state.liveItems ? state.liveItems->findItem(1) : nullptr;
@ -176,19 +202,25 @@ remorse::MapRenderOptions playerPatchOptions(remorse::u32 mapIndex,
return options;
}
remorse::MapRenderOptions fullSceneOptions(remorse::u32 mapIndex,
const remorse::WorldPoint& center)
{
remorse::MapRenderOptions options;
options.mapIndex = mapIndex;
options.maxWidth = backingWidth;
options.maxHeight = backingHeight;
options.includeRoofs = true;
options.viewCenter = center;
return options;
}
std::optional<remorse::MapRenderSprite> playerRenderSprite(const AppState& state)
{
const remorse::AnimationClip* clip = nullptr;
if (state.playerAnimation == 1 && state.walkAnimation) {
clip = &*state.walkAnimation;
} else if (state.playerAnimation == 3 && state.runAnimation) {
clip = &*state.runAnimation;
} else if (state.standAnimation) {
clip = &*state.standAnimation;
}
if (!clip) {
if (state.playerAnimation >= state.playerAnimations.size() ||
!state.playerAnimations[state.playerAnimation]) {
return std::nullopt;
}
const remorse::AnimationClip* clip = &*state.playerAnimations[state.playerAnimation];
const remorse::u8 frameIndex = state.playerAnimation == 0 ? 0 : state.playerFrame;
const auto metadata = remorse::getAnimationFrame(*clip, state.playerDirection, frameIndex);
@ -438,7 +470,8 @@ void runUsecodeTasks(AppState& state)
void loadSceneAsync(HWND window, AppState& state)
{
state.sceneThread = std::thread([window, &state]() {
try {
state.sceneThread = std::thread([window, &state]() {
try {
const auto fixedPath = remorse::resolveGameDataPath(
state.root, std::filesystem::path("STATIC") / "FIXED.DAT");
@ -458,7 +491,7 @@ void loadSceneAsync(HWND window, AppState& state)
}
const auto archive = remorse::loadFixedMapArchive(*fixedPath);
const auto map = archive ? remorse::loadFixedMap(*archive, state.mapIndex) : std::nullopt;
auto map = archive ? remorse::loadFixedMap(*archive, state.mapIndex) : std::nullopt;
if (!map || map->entries.empty()) {
setLoadFailure(state, L"The selected map could not be loaded or contains no records.");
PostMessageW(window, sceneReadyMessage, 0, 0);
@ -470,9 +503,8 @@ void loadSceneAsync(HWND window, AppState& state)
PostMessageW(window, sceneReadyMessage, 0, 0);
return;
}
const auto shapeTypes = remorse::loadTypeFlags(*typeFlagsPath);
const auto globObjects = remorse::loadGlobObjects(*globPath);
auto globObjects = remorse::loadGlobObjects(*globPath);
if (!shapeTypes || !globObjects || shapeTypes->size() <= 1) {
setLoadFailure(state, L"Collision shape metadata could not be loaded.");
PostMessageW(window, sceneReadyMessage, 0, 0);
@ -508,22 +540,23 @@ void loadSceneAsync(HWND window, AppState& state)
}
const auto animationArchive = remorse::loadAnimationArchive(*animationPath);
const auto shapeArchive = remorse::loadShapeArchive(*shapesPath);
auto shapeArchive = remorse::loadShapeArchive(*shapesPath);
const auto palette = remorse::loadPalette256(*palettePath);
const auto standAnimation = animationArchive
? remorse::loadAnimationClip(*animationArchive, 1, 0) : std::nullopt;
const auto walkAnimation = animationArchive
? remorse::loadAnimationClip(*animationArchive, 1, 1) : std::nullopt;
const auto runAnimation = animationArchive
? remorse::loadAnimationClip(*animationArchive, 1, 3) : std::nullopt;
std::array<std::optional<remorse::AnimationClip>, 0x40> playerAnimations;
if (animationArchive) {
for (const remorse::u8 index : remorse::controllerAnimationIndices) {
playerAnimations[index] = remorse::loadAnimationClip(
*animationArchive, 1, index);
}
}
const auto shapeFrames = shapeArchive
? remorse::loadShapeFrames(*shapeArchive, 1) : std::nullopt;
if (!shapeArchive || !palette || !standAnimation || !walkAnimation || !runAnimation || !shapeFrames) {
if (!shapeArchive || !palette || !playerAnimations[0] || !playerAnimations[1] ||
!playerAnimations[3] || !shapeFrames) {
setLoadFailure(state, L"The player stand, walk, or run animation could not be loaded.");
PostMessageW(window, sceneReadyMessage, 0, 0);
return;
}
std::vector<std::optional<remorse::DecodedShapeFrame>> playerFrames(shapeFrames->size());
const auto cacheAnimationFrames = [&](const remorse::AnimationClip& clip) {
for (remorse::u8 direction = 0; direction < 16; ++direction) {
@ -538,7 +571,7 @@ void loadSceneAsync(HWND window, AppState& state)
return false;
}
if (!playerFrames[shapeFrame]) {
auto decoded = remorse::decodeShapeFrame(*shapeArchive, 1, shapeFrame);
auto decoded = remorse::decodeShapeFrame((*shapeFrames)[shapeFrame]);
if (!decoded) {
return false;
}
@ -548,13 +581,13 @@ void loadSceneAsync(HWND window, AppState& state)
}
return true;
};
if (!cacheAnimationFrames(*standAnimation) || !cacheAnimationFrames(*walkAnimation) ||
!cacheAnimationFrames(*runAnimation)) {
setLoadFailure(state, L"A player animation references a missing shape frame.");
PostMessageW(window, sceneReadyMessage, 0, 0);
return;
for (const auto& clip : playerAnimations) {
if (clip && !cacheAnimationFrames(*clip)) {
setLoadFailure(state, L"A player animation references a missing shape frame.");
PostMessageW(window, sceneReadyMessage, 0, 0);
return;
}
}
remorse::s32 minX = map->entries.front().x;
remorse::s32 minY = map->entries.front().y;
remorse::s32 maxX = minX;
@ -586,12 +619,7 @@ void loadSceneAsync(HWND window, AppState& state)
? remorse::WorldPoint{startingEgg->data.x * 2, startingEgg->data.y * 2,
startingEgg->data.z}
: remorse::WorldPoint{(minX + maxX) / 2, (minY + maxY) / 2, 0};
remorse::MapRenderOptions options;
options.mapIndex = state.mapIndex;
options.maxWidth = backingWidth;
options.maxHeight = backingHeight;
options.includeRoofs = true;
options.viewCenter = spawn;
remorse::MapRenderOptions options = fullSceneOptions(state.mapIndex, spawn);
remorse::LiveFixedMapItems liveItems(std::move(*stagedItems), std::move(containedItems));
liveItems.initializeAvatar();
if (startingEgg) {
@ -625,11 +653,11 @@ void loadSceneAsync(HWND window, AppState& state)
directStart.data.z = static_cast<remorse::u8>(spawn.z);
liveItems.teleportAvatar(directStart, static_cast<remorse::u8>(state.mapIndex));
}
auto renderer = remorse::loadMapSceneRenderer(state.root, state.mapIndex);
if (renderer) {
hatchGlobsInFastArea(liveItems, *renderer, remorse::calculateFastAreaRange(spawn));
}
const auto initialMetadata = remorse::getAnimationFrame(*standAnimation, 14, 0);
remorse::MapSceneRenderer renderer{
std::move(*map), std::move(*globObjects), std::move(*shapeArchive),
*palette, *shapeTypes, {}};
hatchGlobsInFastArea(liveItems, renderer, remorse::calculateFastAreaRange(spawn));
const auto initialMetadata = remorse::getAnimationFrame(*playerAnimations[0], 14, 0);
if (!initialMetadata) {
setLoadFailure(state, L"The player stand frame could not be resolved.");
PostMessageW(window, sceneReadyMessage, 0, 0);
@ -645,27 +673,25 @@ void loadSceneAsync(HWND window, AppState& state)
static_cast<remorse::u8>(initialShapeFrame),
remorse::isAnimationFrameFlipped(*initialMetadata), &*playerFrames[initialShapeFrame],
&*palette};
auto scene = renderer ? renderer->render(options, &liveItems) : std::nullopt;
auto scene = renderer.render(options, &liveItems);
if (!scene) {
setLoadFailure(state, L"Map graphics or palette data could not be loaded.");
PostMessageW(window, sceneReadyMessage, 0, 0);
return;
}
auto playerPatch = renderer ? renderer->render(
playerPatchOptions(state.mapIndex, spawn), &liveItems, &initialPlayer) : std::nullopt;
auto playerPatch = renderer.render(
playerPatchOptions(state.mapIndex, spawn), &liveItems, &initialPlayer);
if (!playerPatch) {
setLoadFailure(state, L"The initial player render patch could not be built.");
PostMessageW(window, sceneReadyMessage, 0, 0);
return;
}
std::vector<std::uint8_t> dibPixels(scene->pixels.size() * 3);
for (std::size_t index = 0; index < scene->pixels.size(); ++index) {
dibPixels[index * 3] = scene->pixels[index].blue;
dibPixels[index * 3 + 1] = scene->pixels[index].green;
dibPixels[index * 3 + 2] = scene->pixels[index].red;
}
{
std::lock_guard<std::mutex> lock(state.sceneMutex);
state.spawn = spawn;
@ -685,9 +711,9 @@ void loadSceneAsync(HWND window, AppState& state)
state.playerPatch = std::move(playerPatch);
state.renderer = std::move(renderer);
state.dibPixels = std::move(dibPixels);
state.standAnimation = *standAnimation;
state.walkAnimation = *walkAnimation;
state.runAnimation = *runAnimation;
state.playerAnimations = std::move(playerAnimations);
state.controllerMovement.setTurnStep(
state.playerAnimations[1]->directionCount == 8 ? 2 : 1);
state.playerFrames = std::move(playerFrames);
state.playerPalette = *palette;
state.liveItems.emplace(std::move(liveItems));
@ -699,7 +725,12 @@ void loadSceneAsync(HWND window, AppState& state)
setLoadFailure(state, L"An unexpected error occurred while building the map scene.");
}
PostMessageW(window, sceneReadyMessage, 0, 0);
});
});
} catch (const std::exception& error) {
reportLoadFailure(window, state, widen(error.what()));
} catch (...) {
reportLoadFailure(window, state, L"Could not start the map-loading worker thread.");
}
}
bool hatchGlobsInFastArea(remorse::LiveFixedMapItems& items,
@ -728,13 +759,14 @@ bool hatchGlobsInFastArea(remorse::LiveFixedMapItems& items,
void startLiveRenderer(HWND window, AppState& state)
{
state.renderThread = std::thread([window, &state]() {
try {
state.renderThread = std::thread([window, &state]() {
try {
for (;;) {
std::optional<remorse::LiveFixedMapItems> snapshot;
std::optional<remorse::MapRenderSprite> playerSprite;
remorse::WorldPoint center{};
bool fullRender = false;
std::uint64_t generation = 0;
{
std::unique_lock<std::mutex> lock(state.sceneMutex);
state.renderWake.wait(lock, [&state]() { return state.renderStop || state.renderRequested; });
@ -744,27 +776,34 @@ void startLiveRenderer(HWND window, AppState& state)
state.renderRequested = false;
fullRender = state.renderFullRequested;
state.renderFullRequested = false;
generation = state.renderGeneration;
state.renderFullInFlight = fullRender;
snapshot.emplace(*state.liveItems);
center = avatarWorld(state);
playerSprite = playerRenderSprite(state);
}
auto playerPatch = state.renderer->render(playerPatchOptions(state.mapIndex, center),
&*snapshot, playerSprite ? &*playerSprite : nullptr);
if (!playerPatch) {
reportLoadFailure(window, state, L"The live player-patch renderer returned no image.");
return;
}
{
std::lock_guard<std::mutex> lock(state.sceneMutex);
if (state.renderStop) {
return;
}
state.playerPatch = std::move(playerPatch);
}
PostMessageW(window, sceneReadyMessage, 0, 0);
std::optional<remorse::RenderedMapImage> scene;
std::vector<std::uint8_t> pixels;
if (fullRender) {
remorse::MapRenderOptions options;
options.mapIndex = state.mapIndex;
options.maxWidth = backingWidth;
options.maxHeight = backingHeight;
options.includeRoofs = true;
options.viewCenter = center;
const remorse::s32 radius = static_cast<remorse::s32>(
backingWidth + backingHeight * 2 + 512);
options.worldRect = remorse::WorldRect{
center.x - radius, center.y - radius, center.x + radius, center.y + radius};
remorse::MapRenderOptions options = fullSceneOptions(state.mapIndex, center);
scene = state.renderer->render(options, &*snapshot);
if (!scene) {
continue;
reportLoadFailure(window, state, L"The live full-map renderer returned no image.");
return;
}
pixels.resize(scene->pixels.size() * 3);
for (std::size_t index = 0; index < scene->pixels.size(); ++index) {
@ -772,37 +811,36 @@ void startLiveRenderer(HWND window, AppState& state)
pixels[index * 3 + 1] = scene->pixels[index].green;
pixels[index * 3 + 2] = scene->pixels[index].red;
}
}
auto playerPatch = state.renderer->render(playerPatchOptions(state.mapIndex, center),
&*snapshot, playerSprite ? &*playerSprite : nullptr);
if (!playerPatch) {
continue;
}
{
std::lock_guard<std::mutex> lock(state.sceneMutex);
if (state.renderStop) {
return;
}
if (state.renderGeneration != generation && state.renderFullRequested) {
state.renderRequested = true;
continue;
}
if (fullRender) {
{
std::lock_guard<std::mutex> lock(state.sceneMutex);
if (state.renderStop) {
return;
}
state.scene = std::move(scene);
state.dibPixels = std::move(pixels);
state.renderFullInFlight = false;
}
state.playerPatch = std::move(playerPatch);
PostMessageW(window, sceneReadyMessage, 0, 0);
}
PostMessageW(window, sceneReadyMessage, 0, 0);
}
});
} catch (const std::exception& error) {
reportLoadFailure(window, state, widen(error.what()));
} catch (...) {
reportLoadFailure(window, state, L"An unexpected error occurred in the live map renderer.");
}
});
} catch (const std::exception& error) {
reportLoadFailure(window, state, widen(error.what()));
} catch (...) {
reportLoadFailure(window, state, L"Could not start the live map-rendering worker thread.");
}
}
void requestLiveRender(AppState& state, bool fullRender)
void requestLiveRender(AppState& state, bool fullRender, bool forceFullRender = false)
{
state.renderRequested = true;
state.renderFullRequested = state.renderFullRequested || fullRender;
++state.renderGeneration;
state.renderFullRequested = state.renderFullRequested ||
(fullRender && (!state.renderFullInFlight || forceFullRender));
state.renderWake.notify_one();
}
@ -904,9 +942,16 @@ void paintWindow(HWND window, AppState& state)
const auto avatarScreen = remorse::projectToScreen(avatarWorld(state));
const int centeredLeft = avatarScreen.x - state.scene->sourceLeft - viewWidth / 2;
const int centeredTop = avatarScreen.y - state.scene->sourceTop - viewHeight / 2;
const int sourceLeft = std::clamp(centeredLeft, 0, static_cast<int>(state.scene->width) - viewWidth);
const int sourceTop = std::clamp(centeredTop, 0, static_cast<int>(state.scene->height) - viewHeight);
if ((sourceLeft != centeredLeft || sourceTop != centeredTop) && state.renderThread.joinable()) {
const int maxSourceLeft = static_cast<int>(state.scene->width) - viewWidth;
const int maxSourceTop = static_cast<int>(state.scene->height) - viewHeight;
const int sourceLeft = std::clamp(centeredLeft, 0, maxSourceLeft);
const int sourceTop = std::clamp(centeredTop, 0, maxSourceTop);
const int prefetchMarginX = std::max(1, viewWidth / 4);
const int prefetchMarginY = std::max(1, viewHeight / 4);
const bool nearingSceneEdge = centeredLeft < prefetchMarginX ||
centeredLeft > maxSourceLeft - prefetchMarginX ||
centeredTop < prefetchMarginY || centeredTop > maxSourceTop - prefetchMarginY;
if (nearingSceneEdge && state.renderThread.joinable()) {
requestLiveRender(state, true);
}
@ -1058,19 +1103,78 @@ void updatePlayer(HWND window, AppState& state)
bool changed = false;
while (state.simulationAccumulator >= simulationTickSeconds) {
state.simulationAccumulator -= simulationTickSeconds;
remorse::ControllerActorState controllerActor;
controllerActor.mapNumber = static_cast<remorse::u16>(state.mapIndex);
controllerActor.direction = state.playerDirection;
controllerActor.lastAnimation = state.playerAnimation;
controllerActor.lastAnimationNotCombat = remorse::controllerLastAnimationIsNotCombat(
state.playerAnimation);
controllerActor.kneeling = state.playerKneeling;
controllerActor.activeWeapon = state.playerHasActiveWeapon;
controllerActor.busy = state.animationProcessId != 0 &&
state.diagnosticKernel.processAt(state.animationProcessId) != nullptr;
state.controllerMovement.setActorState(controllerActor);
state.diagnosticKernel.dispatchPendingKeyEvents([](remorse::EntityDispatchEntryBase& entry,
remorse::u16 selector, remorse::u16 filter, remorse::KeyEvent& event, void* context) {
auto& app = *static_cast<AppState*>(context);
if (entry.bytes[0] == 0xa6 && entry.bytes[1] == 0x3a && selector == 0x10 && filter == 0) {
app.controllerMovement.handleDirectionalKey(event.scanCode, event.modifiers, event.field8 != 0);
app.controllerMovement.handleKeyEvent(
event.scanCode, event.modifiers, event.field8, event.field9,
event.fieldA, event.field6);
}
}, &state);
if (auto command = state.controllerMovement.takeCommandRequest()) {
state.lastControllerCommand = command;
if (command->command == remorse::ControllerCommand::CycleWeaponForward) {
state.playerHasActiveWeapon = !state.playerHasActiveWeapon;
controllerActor.activeWeapon = state.playerHasActiveWeapon;
state.controllerMovement.setActorState(controllerActor);
}
}
if (state.useRequested) {
state.useRequested = false;
changed = startNearbyUsecode(state) || changed;
}
runUsecodeTasks(state);
const auto movement = state.controllerMovement.request();
if (state.activeOneShotMovement && (state.animationProcessId == 0 ||
state.diagnosticKernel.processAt(state.animationProcessId) == nullptr)) {
state.activeOneShotMovement.reset();
state.animationProcessId = 0;
state.playerAnimation = 0;
state.playerFrame = 0;
}
if (const auto action = state.controllerMovement.takeActionRequest()) {
state.activeOneShotMovement = action;
if (action->animation == 0x28) {
state.playerKneeling = true;
} else if (action->animation == 0x29) {
state.playerKneeling = false;
}
}
auto movement = state.activeOneShotMovement
? *state.activeOneShotMovement : state.controllerMovement.request();
bool directionUpdatedInPlace = false;
if (movement.updateDirectionInPlace) {
const auto requestedDirection = state.controllerMovement.takeInPlaceDirectionUpdate();
if (requestedDirection && state.liveItems && state.animationProcessId != 0) {
const auto updatedDirection = state.diagnosticKernel.updateAnimPrimitiveDirection(
state.animationProcessId, *state.liveItems, *requestedDirection);
if (updatedDirection) {
movement.animation = state.playerAnimation;
movement.direction = *updatedDirection;
directionUpdatedInPlace = true;
}
}
if (!directionUpdatedInPlace) {
movement = state.activeOneShotMovement
? *state.activeOneShotMovement : state.controllerMovement.request();
}
}
if (movement.animation >= state.playerAnimations.size() ||
!state.playerAnimations[movement.animation]) {
state.activeOneShotMovement.reset();
movement = state.controllerMovement.request();
}
state.diagnosticKernel.deliverSystemTimerEvent();
bool gravityMoved = false;
if (state.diagnostics) {
@ -1129,22 +1233,27 @@ void updatePlayer(HWND window, AppState& state)
}
changed = changed || state.diagnostics || gravityMoved;
if (movement.animation == 0) {
const bool facingChanged = state.playerDirection != movement.direction;
state.playerDirection = movement.direction;
const bool playerSpriteChanged = state.playerAnimation != 0 || state.playerFrame != 0;
if (state.animationProcessId != 0) {
auto* process = state.diagnosticKernel.processAt(state.animationProcessId);
process->bytes[0x18] |= 4;
state.diagnosticKernel.terminateProcess(state.animationProcessId, state.diagnosticGroupCounts);
if (process != nullptr) {
process->bytes[0x18] |= 4;
state.diagnosticKernel.terminateProcess(state.animationProcessId, state.diagnosticGroupCounts);
}
state.animationProcessId = 0;
}
changed = changed || state.playerAnimation != 0 || state.playerFrame != 0;
state.playerAnimation = 0;
state.playerFrame = 0;
changed = changed || facingChanged;
const bool usecodeMutation = state.usecodeWorldMutationPending;
state.usecodeWorldMutationPending = false;
changed = changed || usecodeMutation;
if (state.renderThread.joinable() &&
(gravityMoved || usecodeMutation || playerSpriteChanged)) {
requestLiveRender(state, gravityMoved || usecodeMutation);
(gravityMoved || usecodeMutation || playerSpriteChanged || facingChanged)) {
requestLiveRender(state, gravityMoved || usecodeMutation, true);
}
continue;
}
@ -1153,10 +1262,9 @@ void updatePlayer(HWND window, AppState& state)
const remorse::u8 previousPlayerDirection = state.playerDirection;
const remorse::u8 previousPlayerFrame = state.playerFrame;
const remorse::u8 requestedAnimation = movement.animation;
const remorse::AnimationClip& clip = requestedAnimation == 1
? *state.walkAnimation : *state.runAnimation;
if (state.animationProcessId == 0 || state.playerAnimation != requestedAnimation ||
state.playerDirection != movement.direction) {
const remorse::AnimationClip& clip = *state.playerAnimations[requestedAnimation];
if (!directionUpdatedInPlace && (state.animationProcessId == 0 ||
state.playerAnimation != requestedAnimation || state.playerDirection != movement.direction)) {
if (state.animationProcessId != 0) {
auto* process = state.diagnosticKernel.processAt(state.animationProcessId);
process->bytes[0x18] |= 4;
@ -1179,12 +1287,22 @@ void updatePlayer(HWND window, AppState& state)
[](remorse::EntityDispatchEntryBase& entry, void* context) {
auto& app = *static_cast<AppState*>(context);
if (&entry == app.diagnosticKernel.processAt(app.animationProcessId)) {
const remorse::AnimationClip& activeClip = app.playerAnimation == 1
? *app.walkAnimation : *app.runAnimation;
const remorse::AnimationClip& activeClip = *app.playerAnimations[app.playerAnimation];
const auto* item = app.liveItems->findItem(1);
app.diagnosticKernel.advanceGroundedAnimPrimitive(app.animationProcessId,
const auto advanced = app.diagnosticKernel.advanceGroundedAnimPrimitive(app.animationProcessId,
*app.liveItems, activeClip, app.shapeTypes,
remorse::calculateFastAreaRange({item->data.x, item->data.y, item->data.z}));
if (app.activeOneShotMovement && (!advanced || !*advanced)) {
auto* finished = app.diagnosticKernel.processAt(app.animationProcessId);
if (finished != nullptr) {
finished->bytes[0x18] |= 4;
app.diagnosticKernel.terminateProcess(
app.animationProcessId, app.diagnosticGroupCounts);
}
app.animationProcessId = 0;
app.playerAnimation = 0;
app.playerFrame = 0;
}
}
}, &state);
state.fastArea = fastArea;
@ -1203,7 +1321,7 @@ void updatePlayer(HWND window, AppState& state)
state.playerDirection != previousPlayerDirection || state.playerFrame != previousPlayerFrame;
if (state.renderThread.joinable() &&
(moved || hatched || usecodeMutation || gravityMoved || playerSpriteChanged)) {
requestLiveRender(state, hatched || usecodeMutation || gravityMoved);
requestLiveRender(state, hatched || usecodeMutation || gravityMoved, true);
}
changed = true;
}
@ -1233,6 +1351,7 @@ LRESULT CALLBACK windowProcedure(HWND window, UINT message, WPARAM wParam, LPARA
return 0;
case WM_TIMER:
if (wParam == timerId) {
displayLoadFailure(window, *state);
updatePlayer(window, *state);
}
return 0;
@ -1272,7 +1391,15 @@ LRESULT CALLBACK windowProcedure(HWND window, UINT message, WPARAM wParam, LPARA
wParam == 'Z' || wParam == 'C') event.modifiers &= ~0x20;
if (GetKeyState(VK_LSHIFT) & 0x8000) event.modifiers |= 1;
if (GetKeyState(VK_RSHIFT) & 0x8000) event.modifiers |= 2;
event.field8 = message == WM_KEYDOWN ? 1 : 0;
if (GetKeyState(VK_LMENU) & 0x8000 || GetKeyState(VK_RMENU) & 0x8000) {
event.modifiers |= 0x0a00;
}
if (GetKeyState(VK_LCONTROL) & 0x8000 || GetKeyState(VK_RCONTROL) & 0x8000) {
event.modifiers |= 0x0500;
}
event.field8 = 1;
event.field9 = message == WM_KEYDOWN ? 1 : 0;
event.fieldA = message == WM_KEYDOWN ? 1 : 0;
std::lock_guard<std::mutex> lock(state->kernelMutex);
state->diagnosticKernel.queuePendingKeyEvent(event);
}
@ -1319,12 +1446,16 @@ LRESULT CALLBACK windowProcedure(HWND window, UINT message, WPARAM wParam, LPARA
paintWindow(window, *state);
return 0;
case sceneReadyMessage: {
bool shouldStartRenderer = false;
{
std::lock_guard<std::mutex> lock(state->sceneMutex);
if (state->sceneLoaded && state->renderer && !state->renderThread.joinable()) {
startLiveRenderer(window, *state);
}
shouldStartRenderer = state->sceneLoaded && state->renderer.has_value() &&
!state->renderThread.joinable();
}
if (shouldStartRenderer) {
startLiveRenderer(window, *state);
}
displayLoadFailure(window, *state);
InvalidateRect(window, nullptr, FALSE);
return 0;
}