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

@ -145,6 +145,8 @@ public:
EntityVmContextProcessEntry* createUsecodeProcess(u8 activeGroup, u16 (&groupCounts)[32]);
bool startAnimPrimitiveProcess(u16 processId, LiveFixedMapItems& items,
const AnimationClip& clip, u8 frameSkip = 0);
std::optional<u8> updateAnimPrimitiveDirection(u16 processId, LiveFixedMapItems& items,
u8 direction);
std::optional<bool> advanceGroundedAnimPrimitive(u16 processId, LiveFixedMapItems& items,
const AnimationClip& clip, const std::vector<ShapeTypeInfo>& shapes,
const FastAreaRange& fastArea);

View file

@ -110,6 +110,7 @@ struct NpcAnimationState {
u16 lastAnimation = 0xffff;
u8 frame = 0;
u8 moreFlags = 0;
u8 direction = 0;
};
class LiveFixedMapItems {

View file

@ -4,10 +4,15 @@
#include "remorse/compat.h"
#include <algorithm>
#include <array>
#include <vector>
namespace remorse {
inline constexpr std::array<u8, 25> controllerAnimationIndices{
0, 1, 2, 3, 4, 0x0b, 0x10, 0x17, 0x18, 0x1c, 0x1d, 0x20, 0x22,
0x24, 0x26, 0x28, 0x29, 0x2e, 0x30, 0x37, 0x38, 0x3a, 0x3b, 0x3d, 0x3e};
struct WorldPositionD {
double x = 0.0;
double y = 0.0;
@ -20,6 +25,48 @@ inline bool controllerWalkRequested(u16 modifiers)
return shiftDown == capsLockOn;
}
inline bool controllerAllowsInPlaceDirectionUpdate(u8 animation)
{
switch (animation) {
case 1: case 3: case 4: case 7: case 8: case 10: case 12: case 13: case 15:
case 25: case 34: case 35: case 36: case 37: case 38: case 39: case 42: case 43:
case 44: case 45: case 46: case 47: case 48: case 49: case 50: case 54:
return true;
default:
return false;
}
}
inline bool controllerLastAnimationIsRunning(u8 animation)
{
switch (animation) {
case 1: case 3: case 34: case 35: case 38: case 48: case 49: case 56:
return true;
default:
return false;
}
}
inline bool controllerLastAnimationIsRunningJumping(u8 animation)
{
switch (animation) {
case 3: case 48: case 49: case 56:
return true;
default:
return false;
}
}
inline bool controllerLastAnimationIsNotCombat(u8 animation)
{
switch (animation) {
case 0: case 1: case 11: case 16: case 32: case 55: case 58: case 59:
return true;
default:
return false;
}
}
inline std::optional<u8> controllerDirectionFromScan(u8 scanCode)
{
// Controller_PickNextAnimByKeyevent (1130:12d6), directional keys with Num Lock off.
@ -39,41 +86,324 @@ inline std::optional<u8> controllerDirectionFromScan(u8 scanCode)
struct ControllerMovementRequest {
u8 animation = 0;
u8 direction = 14;
bool oneShot = false;
bool updateDirectionInPlace = false;
};
enum class ControllerCommand : u8 {
FireWeapon,
SelectNextItem,
CycleWeaponForward,
OpenInventory
};
struct ControllerCommandRequest {
ControllerCommand command = ControllerCommand::FireWeapon;
};
struct ControllerActorState {
u16 npcNumber = 1;
u16 mapNumber = 1;
u8 direction = 14;
u8 lastAnimation = 0;
bool controllerEnabled = true;
bool dead = false;
bool avatarInStasis = false;
bool kneeling = false;
bool activeWeapon = false;
bool busy = false;
bool lastAnimationNotCombat = true;
bool avatarSomethingCombatty = false;
};
class ControllerMovementState {
public:
void setActorState(const ControllerActorState& state)
{
if (state.direction != actor_.direction) {
lastDirection_ = state.direction;
}
actor_ = state;
setFacingDirection(state.direction);
crouched_ = state.kneeling;
}
void handleDirectionalKey(u8 scanCode, u16 modifiers, bool pressed)
{
modifiers_ = modifiers;
const auto direction = controllerDirectionFromScan(scanCode);
if (!direction) {
handleKeyEvent(scanCode, modifiers, 1, pressed ? 1 : 0, pressed ? 1 : 0);
}
void handleKeyEvent(u8 scanCode, u16 modifiers, u8 eventMode, u8 keyState,
u16 keyAction = 1, u16 eventFlags = 0)
{
if (!actor_.controllerEnabled || actor_.npcNumber == 0 || actor_.dead ||
(actor_.npcNumber == 1 && actor_.avatarInStasis)) {
return;
}
modifiers_ = modifiers;
if (eventMode == 0) {
return;
}
if (keyState != 0 && keyAction == 1 && actor_.npcNumber == 1 &&
(scanCode == 0x0f || scanCode == 0x24)) {
if (!actor_.busy || (actor_.lastAnimation != 56 &&
controllerLastAnimationIsRunningJumping(actor_.lastAnimation))) {
pendingAction_ = ControllerMovementRequest{56, actor_.direction, true};
}
return;
}
if (keyState != 0 && keyAction == 1 && actor_.npcNumber == 1) {
if ((scanCode == 0x39 || scanCode == 0x52) && actor_.mapNumber != 0x40 &&
!actor_.busy && (scanCode != 0x52 || eventFlags == 0)) {
pendingCommand_ = ControllerCommandRequest{ControllerCommand::FireWeapon};
return;
}
if (scanCode == 0x4a) {
pendingCommand_ = ControllerCommandRequest{ControllerCommand::SelectNextItem};
return;
}
if (scanCode == 0x37 && eventFlags == 0) {
pendingCommand_ = ControllerCommandRequest{ControllerCommand::CycleWeaponForward};
return;
}
if (scanCode == 0x4e || (scanCode == 0x53 && eventFlags == 0)) {
pendingCommand_ = ControllerCommandRequest{ControllerCommand::OpenInventory};
return;
}
}
const auto held = std::find(heldScans_.begin(), heldScans_.end(), scanCode);
if (held != heldScans_.end()) {
heldScans_.erase(held);
}
if (pressed && (modifiers & 0x20) == 0) {
constexpr u16 actionModifierMask = 0x0f00;
if ((modifiers & actionModifierMask) != 0) {
if (keyState != 0) {
queueModifiedAction(scanCode, modifiers, keyAction);
}
return;
}
const bool numLockOn = (modifiers & 0x20) != 0;
if (keyState != 0 && !numLockOn && actor_.mapNumber != 0x40 && !actor_.busy &&
actor_.avatarSomethingCombatty && (scanCode == 0x4b || scanCode == 0x4d)) {
const int turn = scanCode == 0x4b ? -1 : 1;
lastDirection_ = static_cast<u8>((actor_.direction + turn + 16) & 0x0f);
pendingAction_ = ControllerMovementRequest{
static_cast<u8>(actor_.kneeling ? 0x2e : 4), lastDirection_, true};
return;
}
if (numLockOn && (scanCode == 0x4b || scanCode == 0x4d)) {
if (keyState != 0) {
if (actor_.busy) {
if (controllerAllowsInPlaceDirectionUpdate(actor_.lastAnimation)) {
pendingInPlaceDirection_ = static_cast<u8>(scanCode == 0x4b ? 0x12 : 0x11);
}
} else {
const int turn = scanCode == 0x4b ? -turnStep_ : turnStep_;
lastDirection_ = static_cast<u8>((facingDirection_ + turn + 16) & 0x0f);
}
}
return;
}
if (numLockOn && scanCode != 0x48 && scanCode != 0x50) {
return;
}
const auto direction = controllerDirectionFromScan(scanCode);
if (!direction) {
if (keyState != 0) {
queueModifiedAction(scanCode, modifiers, keyAction);
}
return;
}
if (keyState != 0) {
heldScans_.push_back(scanCode);
}
if (keyState != 0) {
queueModifiedAction(scanCode, modifiers, keyAction);
}
}
ControllerMovementRequest request() const
{
if (!actor_.controllerEnabled || actor_.npcNumber == 0 || actor_.dead ||
(actor_.npcNumber == 1 && actor_.avatarInStasis)) {
return {0, actor_.direction};
}
if (pendingInPlaceDirection_) {
return {actor_.lastAnimation, *pendingInPlaceDirection_, false, true};
}
if (heldScans_.empty()) {
return {0, lastDirection_};
}
lastDirection_ = *controllerDirectionFromScan(heldScans_.back());
return {static_cast<u8>(controllerWalkRequested(modifiers_) ? 1 : 3), lastDirection_};
const u8 runAnimation = actor_.activeWeapon ? 0x30 : 3;
const u8 scanCode = heldScans_.back();
const bool numLockOn = (modifiers_ & 0x20) != 0;
const u8 requestedDirection = numLockOn && (scanCode == 0x48 || scanCode == 0x50)
? facingDirection_ : *controllerDirectionFromScan(scanCode);
lastDirection_ = requestedDirection;
const bool walkRequested = controllerWalkRequested(modifiers_);
if (actor_.mapNumber == 0x40) {
if (controllerLastAnimationIsRunning(actor_.lastAnimation)) {
return {static_cast<u8>(walkRequested ? 1 : runAnimation), requestedDirection};
}
if (requestedDirection == actor_.direction) {
return {static_cast<u8>(walkRequested ? 1 : 0x26), requestedDirection};
}
return {0, requestedDirection};
}
if (!walkRequested && requestedDirection == actor_.direction &&
!controllerLastAnimationIsRunning(actor_.lastAnimation)) {
return {0x22, requestedDirection};
}
if ((modifiers_ & 0x20) != 0) {
if (scanCode == 0x48) {
return {static_cast<u8>(walkRequested ? 1 : runAnimation), requestedDirection};
}
if (scanCode == 0x50) {
return {2, requestedDirection};
}
}
return {static_cast<u8>(walkRequested ? 1 : runAnimation), requestedDirection};
}
void clear() { heldScans_.clear(); }
std::optional<u8> takeInPlaceDirectionUpdate()
{
auto direction = pendingInPlaceDirection_;
pendingInPlaceDirection_.reset();
return direction;
}
void setFacingDirection(u8 direction)
{
if (direction <= 15) {
facingDirection_ = direction;
}
}
void setTurnStep(u8 step)
{
turnStep_ = step == 1 ? 1 : 2;
}
std::optional<ControllerMovementRequest> takeActionRequest()
{
auto action = pendingAction_;
pendingAction_.reset();
return action;
}
std::optional<ControllerCommandRequest> takeCommandRequest()
{
auto command = pendingCommand_;
pendingCommand_.reset();
return command;
}
void clear()
{
heldScans_.clear();
pendingAction_.reset();
pendingCommand_.reset();
pendingInPlaceDirection_.reset();
modifiers_ = 0;
}
private:
void queueModifiedAction(u8 scanCode, u16 modifiers, u16 keyAction)
{
constexpr u16 altMask = 0x0a00;
constexpr u16 ctrlMask = 0x0500;
constexpr u8 animationNone = 0x40;
u8 animation = animationNone;
u8 actionDirection = lastDirection_;
if (scanCode == 0x4c) {
if (keyAction == 1) {
animation = crouched_ ? 0x29 : 0x28;
}
} else if ((modifiers & (altMask | ctrlMask)) == 0 && scanCode == 0x35) {
if (actor_.mapNumber != 0x40 && !controllerLastAnimationIsRunning(actor_.lastAnimation)) {
animation = 0x24;
}
} else if ((modifiers & altMask) != 0) {
const bool numLockOn = (modifiers & 0x20) != 0;
const auto scanDirection = controllerDirectionFromScan(scanCode);
if (numLockOn && scanDirection) {
int newDirection = *scanDirection;
if (scanCode == 0x4b) {
newDirection = 0x12;
} else if (scanCode == 0x4d) {
newDirection = 0x11;
}
const int direction = actor_.direction;
const int directionDelta = newDirection < direction
? direction - newDirection : direction + 0x10 - newDirection;
if (0x10 - directionDelta < directionDelta) {
animation = 0x1d;
actionDirection = static_cast<u8>((newDirection - 4) & 0x0f);
} else {
animation = 0x1c;
actionDirection = static_cast<u8>((newDirection + 4) & 0x0f);
}
} else {
switch (scanCode) {
case 0x48: animation = 0x24; break;
case 0x4b: animation = 0x1c; break;
case 0x4d: animation = 0x1d; break;
case 0x50: animation = 2; break;
default: break;
}
}
} else if ((modifiers & ctrlMask) != 0) {
const auto requestedDirection = controllerDirectionFromScan(scanCode);
if ((modifiers & 0x20) == 0 && requestedDirection &&
(scanCode == 0x47 || scanCode == 0x49 || scanCode == 0x4f || scanCode == 0x51)) {
const int direction = actor_.direction;
const int directionDelta = *requestedDirection < direction
? direction - *requestedDirection : direction + 0x10 - *requestedDirection;
if (0x10 - directionDelta < directionDelta) {
animation = 0x18;
actionDirection = static_cast<u8>((*requestedDirection - 4) & 0x0f);
} else {
animation = 0x17;
actionDirection = static_cast<u8>((*requestedDirection + 4) & 0x0f);
}
} else switch (scanCode) {
case 0x48:
if (crouched_) {
animation = 0x29;
} else if (!actor_.lastAnimationNotCombat) {
animation = 0x0b;
} else if (actor_.npcNumber == 1) {
animation = 0x3a;
}
break;
case 0x4b: animation = crouched_ ? 0x17 : 0x3d; break;
case 0x4d: animation = crouched_ ? 0x18 : 0x3e; break;
case 0x50:
if (keyAction == 1) {
animation = crouched_ ? 0x29 : 0x28;
}
break;
default: break;
}
}
if (animation != animationNone) {
pendingAction_ = ControllerMovementRequest{animation, actionDirection, true};
if (animation == 0x28 || animation == 0x29) {
crouched_ = !crouched_;
}
}
}
std::vector<u8> heldScans_;
std::optional<ControllerMovementRequest> pendingAction_;
std::optional<ControllerCommandRequest> pendingCommand_;
std::optional<u8> pendingInPlaceDirection_;
u16 modifiers_ = 0;
mutable u8 lastDirection_ = 14;
u8 facingDirection_ = 14;
u8 turnStep_ = 2;
bool crouched_ = false;
ControllerActorState actor_{};
};
inline std::optional<AnimationDisplacement> hostMovementStep(

View file

@ -30,6 +30,7 @@ struct ShapeArchive {
std::optional<ShapeArchive> loadShapeArchive(const std::filesystem::path& path);
std::optional<std::vector<ShapeFrame>> loadShapeFrames(const ShapeArchive& archive, u32 shapeIndex);
std::optional<DecodedShapeFrame> decodeShapeFrame(const ShapeFrame& frame);
std::optional<DecodedShapeFrame> decodeShapeFrame(const ShapeArchive& archive, u32 shapeIndex, u32 frameIndex);
} // namespace remorse

View file

@ -367,6 +367,37 @@ bool ProcessKernel::startAnimPrimitiveProcess(u16 processId, LiveFixedMapItems&
return true;
}
std::optional<u8> ProcessKernel::updateAnimPrimitiveDirection(u16 processId,
LiveFixedMapItems& items, u8 direction)
{
auto* process = processAt(processId);
if (direction > 0x12 || process == nullptr ||
allocationSizeAt(processId) != sizeof(AnimPrimitiveProcessEntry) ||
(readLe16(*process, 0x16) & 0x08) != 0 || process->bytes[0x3a] == 0 ||
std::none_of(ownedAnimPrimitiveProcesses_.begin(), ownedAnimPrimitiveProcesses_.end(),
[process](const auto& owned) { return &owned->base == process; })) {
return std::nullopt;
}
auto* npc = items.editNpcAnimation(readLe16(*process, 0x04));
if (npc == nullptr) {
return std::nullopt;
}
const bool relative = direction >= 0x10;
const bool turnClockwise = direction == 0x11;
const bool turnCounterclockwise = direction == 0x12;
direction = relative ? npc->direction : direction;
if ((process->bytes[0x4d] & 0x40) == 0) {
direction = static_cast<u8>(direction & 0x0e);
}
if (turnClockwise || turnCounterclockwise) {
const u8 step = (process->bytes[0x4d] & 0x40) == 0 ? 2 : 1;
direction = static_cast<u8>((direction + (turnClockwise ? step : 16 - step)) & 0x0f);
}
process->bytes[0x38] = direction;
npc->direction = direction;
return direction;
}
std::optional<bool> ProcessKernel::advanceGroundedAnimPrimitive(u16 processId,
LiveFixedMapItems& items, const AnimationClip& clip,
const std::vector<ShapeTypeInfo>& shapes, const FastAreaRange& fastArea)
@ -400,9 +431,13 @@ std::optional<bool> ProcessKernel::advanceGroundedAnimPrimitive(u16 processId,
}
const u8 direction = process->bytes[0x38];
const auto metadata = getAnimationFrame(clip, direction, nextFrame);
if (!metadata || (metadata->bytes[5] & 2) == 0) {
if (!metadata) {
return std::nullopt;
}
if ((metadata->bytes[5] & 2) == 0) {
npc->frame = nextFrame;
return true;
}
const auto step = decodeAnimationDisplacement(*metadata, direction, (clip.header[2] & 0x10) != 0);
if (!step) {
return std::nullopt;

View file

@ -501,6 +501,7 @@ bool LiveFixedMapItems::initializeAvatar()
avatar_->data.shape = 1;
avatar_->data.npcNumber = 1;
npcAnimations_.resize(2);
npcAnimations_[1].direction = 14;
return true;
}

View file

@ -9,6 +9,7 @@
#include <algorithm>
#include <fstream>
#include <map>
#include <unordered_map>
namespace remorse {
namespace {
@ -71,16 +72,6 @@ RgbColor scalePaletteColor(const RgbColor& color)
return scaled;
}
std::optional<GlobObject> findGlobObject(const std::vector<GlobObject>& globs, u32 index)
{
for (const GlobObject& object : globs) {
if (object.index == index) {
return object;
}
}
return std::nullopt;
}
std::vector<SceneItem> collectSceneItems(
const FixedMap& fixedMap,
const std::vector<ShapeTypeInfo>& typeFlags,
@ -88,6 +79,12 @@ std::vector<SceneItem> collectSceneItems(
const MapRenderOptions& options,
const LiveFixedMapItems* liveItems)
{
std::unordered_map<u32, const GlobObject*> globsByIndex;
globsByIndex.reserve(globs.size());
for (const GlobObject& glob : globs) {
globsByIndex.try_emplace(glob.index, &glob);
}
std::vector<SceneItem> pending;
pending.reserve(fixedMap.entries.size());
std::vector<const StagedFixedMapItem*> liveByRecord;
@ -145,9 +142,9 @@ std::vector<SceneItem> collectSceneItems(
const auto* stagedEgg = liveByRecord.empty() || index >= liveByRecord.size()
? nullptr : liveByRecord[index];
const auto glob = stagedEgg && liveItems->isGlobHatched(stagedEgg->itemNumber)
? std::nullopt : findGlobObject(globs, item.quality);
if (glob) {
for (const GlobObjectEntry& entry : glob->entries) {
? globsByIndex.end() : globsByIndex.find(item.quality);
if (glob != globsByIndex.end()) {
for (const GlobObjectEntry& entry : glob->second->entries) {
pending.push_back(SceneItem{
(item.x & globCoordMask) + (static_cast<s32>(entry.x) << globCoordShift) + globCoordOffset,
(item.y & globCoordMask) + (static_cast<s32>(entry.y) << globCoordShift) + globCoordOffset,
@ -184,6 +181,7 @@ s32 screenY(const SceneItem& item)
const DecodedShapeFrame* cachedDecode(
const ShapeArchive& archive,
std::map<u32, std::vector<ShapeFrame>>& parsedFrames,
std::map<std::pair<u32, u32>, DecodedShapeFrame>& cache,
u32 shape,
u32 frame)
@ -193,7 +191,18 @@ const DecodedShapeFrame* cachedDecode(
if (found != cache.end()) {
return &found->second;
}
const auto decoded = decodeShapeFrame(archive, shape, frame);
auto parsed = parsedFrames.find(shape);
if (parsed == parsedFrames.end()) {
auto frames = loadShapeFrames(archive, shape);
if (!frames) {
return nullptr;
}
parsed = parsedFrames.emplace(shape, std::move(*frames)).first;
}
if (frame >= parsed->second.size()) {
return nullptr;
}
const auto decoded = decodeShapeFrame(parsed->second[frame]);
if (!decoded) {
return nullptr;
}
@ -203,6 +212,7 @@ const DecodedShapeFrame* cachedDecode(
std::vector<RenderNode> prepareRenderNodes(
const std::vector<SceneItem>& items,
const ShapeArchive& shapeArchive,
std::map<u32, std::vector<ShapeFrame>>& parsedFrames,
const std::vector<ShapeTypeInfo>& typeFlags,
std::map<std::pair<u32, u32>, DecodedShapeFrame>& cache)
{
@ -212,7 +222,8 @@ std::vector<RenderNode> prepareRenderNodes(
sortItems.reserve(items.size());
for (const SceneItem& item : items) {
const auto* decoded = item.decodedOverride != nullptr
? item.decodedOverride : cachedDecode(shapeArchive, cache, item.shape, item.frame);
? item.decodedOverride : cachedDecode(
shapeArchive, parsedFrames, cache, item.shape, item.frame);
if (!decoded) {
continue;
}
@ -371,7 +382,8 @@ std::optional<RenderedMapImage> MapSceneRenderer::render(const MapRenderOptions&
items.push_back(sceneSprite);
}
}
auto nodes = prepareRenderNodes(items, shapes, typeFlags, decodedFrames);
std::map<u32, std::vector<ShapeFrame>> parsedFrames;
auto nodes = prepareRenderNodes(items, shapes, parsedFrames, typeFlags, decodedFrames);
if (nodes.empty()) {
return std::nullopt;
}

View file

@ -185,21 +185,27 @@ std::optional<std::vector<ShapeFrame>> loadShapeFrames(const ShapeArchive& archi
return frames;
}
std::optional<DecodedShapeFrame> decodeShapeFrame(const ShapeArchive& archive, u32 shapeIndex, u32 frameIndex)
std::optional<DecodedShapeFrame> decodeShapeFrame(const ShapeFrame& frame)
{
const auto frames = loadShapeFrames(archive, shapeIndex);
if (!frames || frameIndex >= frames->size()) {
return std::nullopt;
}
const auto pixels = decodePixels((*frames)[frameIndex]);
const auto pixels = decodePixels(frame);
if (!pixels) {
return std::nullopt;
}
DecodedShapeFrame decoded;
decoded.frame = (*frames)[frameIndex];
decoded.frame = frame;
decoded.pixels = *pixels;
return decoded;
}
std::optional<DecodedShapeFrame> decodeShapeFrame(
const ShapeArchive& archive, u32 shapeIndex, u32 frameIndex)
{
const auto frames = loadShapeFrames(archive, shapeIndex);
if (!frames || frameIndex >= frames->size()) {
return std::nullopt;
}
return decodeShapeFrame((*frames)[frameIndex]);
}
} // namespace remorse

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;
}

View file

@ -4,6 +4,7 @@
#include "remorse/shape_archive.h"
#include <cassert>
#include <array>
#include <filesystem>
namespace {
@ -100,6 +101,14 @@ int main()
assert(stand.has_value() && stand->frameCount > 0);
assert(walk.has_value() && walk->frameCount == 17);
assert(run.has_value() && run->frameCount == 12);
std::array<std::optional<remorse::AnimationClip>, 0x40> playerAnimations;
for (const remorse::u8 index : remorse::controllerAnimationIndices) {
playerAnimations[index] = remorse::loadAnimationClip(
*animationArchive, 1, index);
}
for (const remorse::u8 animation : remorse::controllerAnimationIndices) {
assert(playerAnimations[animation] && playerAnimations[animation]->frameCount != 0);
}
for (const remorse::AnimationClip* clip : {&*walk, &*run}) {
assert(clip->header[1] == 5);
for (remorse::u8 direction = 0; direction < 16; ++direction) {
@ -148,7 +157,10 @@ int main()
const auto playerFrames = remorse::loadShapeFrames(*shapeArchive, 1);
assert(playerFrames.has_value() && playerFrames->size() >= walk->frameCount);
std::vector<bool> referencedFrames(playerFrames->size(), false);
for (const remorse::AnimationClip* clip : {&*stand, &*walk, &*run}) {
for (const auto& clip : playerAnimations) {
if (!clip) {
continue;
}
for (remorse::u8 direction = 0; direction < 16; ++direction) {
for (remorse::u8 frame = 0; frame < clip->frameCount; ++frame) {
const auto metadata = remorse::getAnimationFrame(*clip, direction, frame);
@ -159,14 +171,13 @@ int main()
}
}
}
bool decodedReferencedFrame = false;
for (std::size_t frame = 0; frame < referencedFrames.size(); ++frame) {
if (referencedFrames[frame]) {
assert(remorse::decodeShapeFrame(*shapeArchive, 1, static_cast<remorse::u32>(frame)).has_value());
decodedReferencedFrame = true;
break;
assert(remorse::decodeShapeFrame((*playerFrames)[frame]).has_value());
}
}
assert(decodedReferencedFrame);
assert(std::any_of(referencedFrames.begin(), referencedFrames.end(), [](bool referenced) {
return referenced;
}));
return 0;
}

View file

@ -997,6 +997,10 @@ int main()
assert(animationKernel.startAnimPrimitiveProcess(3, animationItems, walking));
const auto* npcAnimation = animationItems.findNpcAnimation(1);
assert(npcAnimation && npcAnimation->lastAnimation == 1 && npcAnimation->frame == 0);
assert(animationKernel.updateAnimPrimitiveDirection(3, animationItems, 7) == 6);
assert(animation->extra[6] == 6 && npcAnimation->frame == 0 && npcAnimation->direction == 6);
assert(animationKernel.updateAnimPrimitiveDirection(3, animationItems, 0x11) == 8);
assert(animationKernel.updateAnimPrimitiveDirection(3, animationItems, 0x12) == 6);
assert(!animationKernel.startAnimPrimitiveProcess(3, animationItems, walking));
auto* repeatedWalk = animationKernel.createAnimPrimitiveProcess(1, 1, 1, 6, walking, animationGroups);
assert(animationKernel.startAnimPrimitiveProcess(4, animationItems, walking));
@ -1004,6 +1008,21 @@ int main()
auto* turning = animationKernel.createAnimPrimitiveProcess(1, 1, 0, 6, walking, animationGroups);
assert(animationKernel.startAnimPrimitiveProcess(5, animationItems, walking));
assert(turning->base.bytes[0x3a] == 1 && animationItems.findNpcAnimation(1)->frame == 0);
remorse::ProcessKernel sixteenDirectionKernel;
remorse::u16 sixteenDirectionGroups[32]{};
for (int reservedSlot = 0; reservedSlot < 3; ++reservedSlot) {
sixteenDirectionKernel.createProcess(1, sixteenDirectionGroups);
}
auto sixteenWalking = walking;
sixteenWalking.header[3] |= 0x40;
auto* sixteenDirection = sixteenDirectionKernel.createAnimPrimitiveProcess(1, 1, 1, 6,
sixteenWalking, sixteenDirectionGroups);
remorse::LiveFixedMapItems sixteenItems({});
assert(sixteenItems.initializeAvatar());
assert(sixteenDirectionKernel.startAnimPrimitiveProcess(3, sixteenItems, sixteenWalking));
assert(sixteenDirectionKernel.updateAnimPrimitiveDirection(3, sixteenItems, 0x11) == 15);
assert(sixteenDirection->extra[6] == 15);
assert(sixteenDirectionKernel.updateAnimPrimitiveDirection(3, sixteenItems, 0x12) == 14);
remorse::StagedFixedMapItem animationSpawn{};
animationSpawn.data.x = 512;
animationSpawn.data.y = 512;
@ -1022,6 +1041,11 @@ int main()
walking, animationShapes, animationArea) == true);
assert(animationItems.findItem(1)->data.x == 514 && animationItems.findItem(1)->data.y == 514);
assert(movingNpc.frame == 1);
nextWalkFrame.bytes[5] = 0;
assert(animationKernel.advanceGroundedAnimPrimitive(3, animationItems,
walking, animationShapes, animationArea) == true);
assert(animationItems.findItem(1)->data.x == 514 && movingNpc.frame == 2);
nextWalkFrame.bytes[5] = 2;
nextWalkFrame.bytes[4] = 100;
movingNpc.frame = 0;
remorse::StagedFixedMapItem animationWall{};

View file

@ -9,12 +9,258 @@ int main()
assert(controller.request().animation == 0);
controller.handleDirectionalKey(0x48, 0, true);
assert(controller.request().animation == 1 && controller.request().direction == 14);
controller.handleKeyEvent(0x50, 0, 0, 1);
assert(controller.request().direction == 14);
controller.handleKeyEvent(0x48, 0x0a00, 1, 1);
const auto jump = controller.takeActionRequest();
assert(jump && jump->animation == 0x24 && jump->direction == 14 && jump->oneShot);
remorse::ControllerMovementState keypadKneelController;
keypadKneelController.handleKeyEvent(0x4c, 0, 1, 1, 0);
assert(!keypadKneelController.takeActionRequest());
keypadKneelController.handleKeyEvent(0x4c, 0, 1, 1, 1);
assert(keypadKneelController.takeActionRequest()->animation == 0x28);
keypadKneelController.handleKeyEvent(0x4c, 0, 1, 1, 1);
assert(keypadKneelController.takeActionRequest()->animation == 0x29);
remorse::ControllerMovementState ctrlDownKneelController;
ctrlDownKneelController.handleKeyEvent(0x50, 0x0100, 1, 1, 0);
assert(!ctrlDownKneelController.takeActionRequest());
ctrlDownKneelController.handleKeyEvent(0x50, 0x0100, 1, 1, 1);
assert(ctrlDownKneelController.takeActionRequest()->animation == 0x28);
ctrlDownKneelController.handleKeyEvent(0x50, 0x0100, 1, 1, 1);
assert(ctrlDownKneelController.takeActionRequest()->animation == 0x29);
remorse::ControllerMovementState commandController;
commandController.handleKeyEvent(0x39, 0, 1, 1, 1);
assert(commandController.takeCommandRequest()->command == remorse::ControllerCommand::FireWeapon);
commandController.handleKeyEvent(0x52, 0, 1, 1, 1);
assert(commandController.takeCommandRequest()->command == remorse::ControllerCommand::FireWeapon);
commandController.handleKeyEvent(0x52, 0x0100, 1, 1, 1, 0);
assert(commandController.takeCommandRequest()->command == remorse::ControllerCommand::FireWeapon);
commandController.handleKeyEvent(0x4a, 0, 1, 1, 1);
assert(commandController.takeCommandRequest()->command == remorse::ControllerCommand::SelectNextItem);
commandController.handleKeyEvent(0x37, 0, 1, 1, 1, 1);
assert(!commandController.takeCommandRequest());
commandController.handleKeyEvent(0x37, 0, 1, 1, 1, 0);
assert(commandController.takeCommandRequest()->command == remorse::ControllerCommand::CycleWeaponForward);
commandController.handleKeyEvent(0x4e, 0, 1, 1, 1);
assert(commandController.takeCommandRequest()->command == remorse::ControllerCommand::OpenInventory);
commandController.handleKeyEvent(0x53, 0x0100, 1, 1, 1, 0);
assert(commandController.takeCommandRequest()->command == remorse::ControllerCommand::OpenInventory);
commandController.handleKeyEvent(0x53, 0, 1, 1, 1, 1);
assert(!commandController.takeCommandRequest());
commandController.handleKeyEvent(0x53, 0, 1, 1, 1, 0);
assert(commandController.takeCommandRequest()->command == remorse::ControllerCommand::OpenInventory);
commandController.handleKeyEvent(0x39, 0, 1, 1, 0);
assert(!commandController.takeCommandRequest());
remorse::ControllerActorState restrictedCommandActor;
restrictedCommandActor.mapNumber = 0x40;
commandController.setActorState(restrictedCommandActor);
commandController.handleKeyEvent(0x39, 0, 1, 1, 1);
assert(!commandController.takeCommandRequest());
restrictedCommandActor.mapNumber = 1;
restrictedCommandActor.npcNumber = 2;
commandController.setActorState(restrictedCommandActor);
commandController.handleKeyEvent(0x4a, 0, 1, 1, 1);
assert(!commandController.takeCommandRequest());
remorse::ControllerMovementState altNumLockRight;
remorse::ControllerActorState altTurnActor;
altTurnActor.direction = 14;
altNumLockRight.setActorState(altTurnActor);
altNumLockRight.handleKeyEvent(0x4d, 0x0a20, 1, 1);
const auto altTurn = altNumLockRight.takeActionRequest();
assert(altTurn && altTurn->animation == 0x1d && altTurn->direction == 13);
remorse::ControllerMovementState jumpController;
jumpController.handleKeyEvent(0x35, 0, 1, 1);
const auto slashJump = jumpController.takeActionRequest();
assert(slashJump && slashJump->animation == 0x24 && slashJump->oneShot);
jumpController.handleKeyEvent(0x35, 0, 1, 0);
assert(!jumpController.takeActionRequest());
remorse::ControllerMovementState modifierReleaseController;
modifierReleaseController.handleKeyEvent(0x48, 0, 1, 1);
assert(modifierReleaseController.request().animation == 1);
modifierReleaseController.handleKeyEvent(0x1d, 0x0100, 1, 1);
modifierReleaseController.handleKeyEvent(0x48, 0x0100, 1, 0);
assert(modifierReleaseController.request().animation == 0);
remorse::ControllerMovementState combatTurnController;
remorse::ControllerActorState combatTurnActor;
combatTurnActor.avatarSomethingCombatty = true;
combatTurnActor.direction = 14;
combatTurnController.setActorState(combatTurnActor);
combatTurnController.handleKeyEvent(0x4b, 0, 1, 1);
const auto combatTurn = combatTurnController.takeActionRequest();
assert(combatTurn && combatTurn->animation == 4 && combatTurn->direction == 13);
combatTurnActor.kneeling = true;
combatTurnActor.direction = 13;
combatTurnController.setActorState(combatTurnActor);
combatTurnController.handleKeyEvent(0x4d, 0, 1, 1);
const auto kneelingCombatTurn = combatTurnController.takeActionRequest();
assert(kneelingCombatTurn && kneelingCombatTurn->animation == 0x2e && kneelingCombatTurn->direction == 14);
remorse::ControllerMovementState ctrlDiagonalController;
remorse::ControllerActorState ctrlDiagonalActor;
ctrlDiagonalActor.direction = 14;
ctrlDiagonalController.setActorState(ctrlDiagonalActor);
ctrlDiagonalController.handleKeyEvent(0x47, 0x0100, 1, 1);
const auto ctrlDiagonalLeft = ctrlDiagonalController.takeActionRequest();
assert(ctrlDiagonalLeft && ctrlDiagonalLeft->animation == 0x17 && ctrlDiagonalLeft->direction == 0);
ctrlDiagonalController.handleKeyEvent(0x49, 0x0100, 1, 1);
const auto ctrlDiagonalRight = ctrlDiagonalController.takeActionRequest();
assert(ctrlDiagonalRight && ctrlDiagonalRight->animation == 0x18 && ctrlDiagonalRight->direction == 12);
ctrlDiagonalController.handleKeyEvent(0x47, 0x0120, 1, 1);
assert(!ctrlDiagonalController.takeActionRequest());
modifierReleaseController.handleKeyEvent(0x48, 0x0100, 1, 1);
assert(modifierReleaseController.takeActionRequest()->animation == 0x3a);
modifierReleaseController.handleKeyEvent(0x48, 0x0100, 1, 0);
assert(modifierReleaseController.request().animation == 0);
controller.handleKeyEvent(0x4b, 0x0500, 1, 1);
const auto combatStep = controller.takeActionRequest();
assert(combatStep && combatStep->animation == 0x3d && combatStep->oneShot);
controller.handleKeyEvent(0x4c, 0x0500, 1, 1);
const auto crouch = controller.takeActionRequest();
assert(crouch && crouch->animation == 0x28);
controller.handleKeyEvent(0x4c, 0x0500, 1, 1);
assert(controller.takeActionRequest()->animation == 0x29);
remorse::ControllerMovementState numLockController;
numLockController.setFacingDirection(14);
numLockController.setTurnStep(2);
numLockController.handleKeyEvent(0x4d, 0x20, 1, 1);
assert(numLockController.request().animation == 0 && numLockController.request().direction == 0);
numLockController.setFacingDirection(0);
numLockController.handleKeyEvent(0x48, 0x21, 1, 1);
assert(numLockController.request().animation == 3 && numLockController.request().direction == 0);
numLockController.handleKeyEvent(0x50, 0x20, 1, 1);
assert(numLockController.request().animation == 2 && numLockController.request().direction == 0);
numLockController.handleKeyEvent(0x50, 0x20, 1, 0);
assert(numLockController.request().animation == 1 && numLockController.request().direction == 0);
remorse::ControllerMovementState gatedController;
remorse::ControllerActorState actorState;
actorState.controllerEnabled = false;
gatedController.setActorState(actorState);
gatedController.handleDirectionalKey(0x48, 0, true);
assert(gatedController.request().animation == 0);
actorState.controllerEnabled = true;
actorState.avatarInStasis = true;
gatedController.setActorState(actorState);
gatedController.handleDirectionalKey(0x48, 0, true);
assert(gatedController.request().animation == 0);
actorState.npcNumber = 2;
gatedController.setActorState(actorState);
gatedController.handleDirectionalKey(0x48, 0, true);
assert(gatedController.request().animation == 1);
assert(remorse::controllerAllowsInPlaceDirectionUpdate(0x30));
assert(!remorse::controllerAllowsInPlaceDirectionUpdate(0x28));
constexpr remorse::u8 nonCombatAnimations[] = {0, 1, 11, 16, 32, 55, 58, 59};
for (const remorse::u8 animation : nonCombatAnimations) {
assert(remorse::controllerLastAnimationIsNotCombat(animation));
}
assert(!remorse::controllerLastAnimationIsNotCombat(4));
assert(!remorse::controllerLastAnimationIsNotCombat(3));
assert(remorse::controllerLastAnimationIsRunningJumping(3));
assert(remorse::controllerLastAnimationIsRunningJumping(48));
assert(remorse::controllerLastAnimationIsRunningJumping(49));
assert(remorse::controllerLastAnimationIsRunningJumping(56));
assert(!remorse::controllerLastAnimationIsRunningJumping(34));
remorse::ControllerMovementState jumpKeyController;
jumpKeyController.handleKeyEvent(0x0f, 0, 1, 1, 1);
assert(jumpKeyController.takeActionRequest()->animation == 56);
remorse::ControllerActorState busyRunner;
busyRunner.busy = true;
busyRunner.lastAnimation = 3;
jumpKeyController.setActorState(busyRunner);
jumpKeyController.handleKeyEvent(0x24, 0, 1, 1, 1);
assert(jumpKeyController.takeActionRequest()->animation == 56);
busyRunner.lastAnimation = 56;
jumpKeyController.setActorState(busyRunner);
jumpKeyController.handleKeyEvent(0x0f, 0, 1, 1, 1);
assert(!jumpKeyController.takeActionRequest());
busyRunner.lastAnimation = 4;
jumpKeyController.setActorState(busyRunner);
jumpKeyController.handleKeyEvent(0x0f, 0, 1, 1, 1);
assert(!jumpKeyController.takeActionRequest());
remorse::ControllerMovementState busyTurnController;
actorState.npcNumber = 1;
actorState.avatarInStasis = false;
actorState.busy = true;
actorState.lastAnimation = 1;
busyTurnController.setActorState(actorState);
busyTurnController.handleKeyEvent(0x4d, 0x20, 1, 1);
const auto busyTurn = busyTurnController.request();
assert(busyTurn.updateDirectionInPlace && busyTurn.animation == 1 && busyTurn.direction == 0x11);
assert(busyTurnController.takeInPlaceDirectionUpdate() == 0x11);
actorState.lastAnimation = 0x28;
busyTurnController.setActorState(actorState);
busyTurnController.handleKeyEvent(0x4d, 0x20, 1, 1);
assert(!busyTurnController.takeInPlaceDirectionUpdate());
assert(busyTurnController.request().animation == 0 && busyTurnController.request().direction == 14);
remorse::ControllerMovementState clearedBusyTurnController;
actorState.lastAnimation = 1;
clearedBusyTurnController.setActorState(actorState);
clearedBusyTurnController.handleKeyEvent(0x4d, 0x20, 1, 1);
assert(clearedBusyTurnController.request().updateDirectionInPlace);
clearedBusyTurnController.clear();
assert(!clearedBusyTurnController.request().updateDirectionInPlace);
remorse::ControllerMovementState armedRunController;
actorState.busy = false;
actorState.activeWeapon = true;
actorState.mapNumber = 1;
actorState.direction = 14;
actorState.lastAnimation = 0;
armedRunController.setActorState(actorState);
armedRunController.handleKeyEvent(0x48, 0x01, 1, 1);
assert(armedRunController.request().animation == 0x22);
actorState.lastAnimation = 48;
armedRunController.setActorState(actorState);
assert(armedRunController.request().animation == 0x30);
remorse::ControllerMovementState unarmedRunController;
actorState.activeWeapon = false;
actorState.lastAnimation = 0;
unarmedRunController.setActorState(actorState);
unarmedRunController.handleKeyEvent(0x48, 0x01, 1, 1);
assert(unarmedRunController.request().animation == 0x22);
actorState.lastAnimation = 0x22;
unarmedRunController.setActorState(actorState);
assert(unarmedRunController.request().animation == 3);
remorse::ControllerMovementState combatControlController;
actorState.lastAnimationNotCombat = false;
actorState.kneeling = false;
actorState.npcNumber = 1;
combatControlController.setActorState(actorState);
combatControlController.handleKeyEvent(0x48, 0x0100, 1, 1);
assert(combatControlController.takeActionRequest()->animation == 0x0b);
remorse::ControllerMovementState kneelingControlController;
actorState.kneeling = true;
kneelingControlController.setActorState(actorState);
kneelingControlController.handleKeyEvent(0x48, 0x0100, 1, 1);
assert(kneelingControlController.takeActionRequest()->animation == 0x29);
remorse::ControllerMovementState nonAvatarControlController;
actorState.kneeling = false;
actorState.lastAnimationNotCombat = true;
actorState.npcNumber = 2;
nonAvatarControlController.setActorState(actorState);
nonAvatarControlController.handleKeyEvent(0x48, 0x0100, 1, 1);
assert(!nonAvatarControlController.takeActionRequest());
remorse::ControllerMovementState mapFortyController;
actorState.mapNumber = 0x40;
actorState.lastAnimation = 0;
actorState.direction = 14;
mapFortyController.setActorState(actorState);
mapFortyController.handleKeyEvent(0x48, 0x01, 1, 1);
assert(mapFortyController.request().animation == 0x26);
remorse::ControllerMovementState mapFortyContinuation;
actorState.lastAnimation = 38;
mapFortyContinuation.setActorState(actorState);
mapFortyContinuation.handleKeyEvent(0x48, 0x01, 1, 1);
assert(mapFortyContinuation.request().animation == 3);
remorse::ControllerMovementState mapFortyMisfacing;
actorState.lastAnimation = 0;
actorState.direction = 12;
mapFortyMisfacing.setActorState(actorState);
mapFortyMisfacing.handleKeyEvent(0x48, 0x01, 1, 1);
assert(mapFortyMisfacing.request().animation == 0);
controller.handleDirectionalKey(0x4d, 1, true);
assert(controller.request().animation == 3 && controller.request().direction == 2);
controller.handleDirectionalKey(0x4d, 1, false);
assert(controller.request().animation == 3 && controller.request().direction == 14);
assert(controller.request().animation == 0 && controller.request().direction == 2);
controller.handleDirectionalKey(0x48, 0, false);
assert(controller.request().animation == 0 && controller.request().direction == 14);
assert(controller.request().animation == 0 && controller.request().direction == 2);
controller.handleDirectionalKey(0x49, 0x20, true);
assert(controller.request().animation == 0);
controller.handleDirectionalKey(0x47, 0x40, true);

View file

@ -114,6 +114,22 @@ int main()
});
};
assert(liveBefore && samePixels(liveBefore->pixels, startingScene->pixels));
remorse::MapRenderOptions viewportOptions;
viewportOptions.mapIndex = 1;
viewportOptions.maxWidth = 2560;
viewportOptions.maxHeight = 1440;
viewportOptions.includeRoofs = true;
viewportOptions.viewCenter = spawn;
const auto unboundedViewport = cachedRenderer->render(viewportOptions, &liveSceneItems);
const remorse::s32 viewportRadius = 2560 + 1440 * 2 + 512;
viewportOptions.worldRect = remorse::WorldRect{
spawn.x - viewportRadius, spawn.y - viewportRadius,
spawn.x + viewportRadius, spawn.y + viewportRadius};
const auto boundedViewport = cachedRenderer->render(viewportOptions, &liveSceneItems);
assert(unboundedViewport && boundedViewport);
assert(samePixels(unboundedViewport->pixels, boundedViewport->pixels));
assert(unboundedViewport->coverage == boundedViewport->coverage);
assert(boundedViewport->renderItemCount < unboundedViewport->renderItemCount);
const auto playerFrame = remorse::decodeShapeFrame(cachedRenderer->shapes, 1, 0);
assert(playerFrame);
const remorse::MapRenderSprite playerSprite{spawn, 1, 0, false,

View file

@ -21,6 +21,10 @@ int main()
if (frame && !frame->pixels.empty()) {
assert(frame->frame.width > 0);
assert(frame->frame.height > 0);
const auto parsedFrames = remorse::loadShapeFrames(*archive, shape);
assert(parsedFrames && !parsedFrames->empty());
const auto decodedFromParsed = remorse::decodeShapeFrame(parsedFrames->front());
assert(decodedFromParsed && decodedFromParsed->pixels == frame->pixels);
decodedFrame = true;
break;
}