Enhance item handling and collision detection in remorse

- Introduced new functionality for staging and managing fixed map items, including the ability to build block chains and find candidates for item interactions.
- Updated the main application logic to utilize staged item block chains for improved item finding and grabbing mechanics.
- Added weight attribute to shape type information, allowing for more nuanced item interactions based on weight.
- Enhanced collision tests to cover new item handling scenarios, including gravity sweeps and item grabbing.
- Implemented additional tests for entity dispatch entries and fixed map items to ensure robustness of item spawning and movement logic.
- Improved type flags loading to validate weight against binary data, ensuring consistency in item attributes.
This commit is contained in:
Maddo 2026-09-26 19:20:20 +02:00
commit b99fb59c12
15 changed files with 961 additions and 18 deletions

View file

@ -77,6 +77,35 @@ void appendSolidBody(std::vector<CollisionBody>& bodies, const std::vector<Shape
} // namespace
SweepBoundsResult clampAreaSweepBounds(WorldPoint from, WorldPoint destination)
{
SweepBoundsResult result{destination};
if (destination.x < 0 || destination.x > 0x7fff) {
result.destination.x = destination.x < from.x ? 0 : 0x7fff;
result.failedDirections |= 1;
result.failed = true;
}
if (destination.y < 0 || destination.y > 0x7fff) {
result.destination.y = destination.y < from.y ? 0 : 0x7fff;
result.failedDirections |= 2;
result.failed = true;
}
if (destination.z < 0 || destination.z > 0xfa) {
result.destination.z = std::clamp(destination.z, 0, 0xfa);
result.failedDirections |= 4;
}
return result;
}
GravitySweepPlan planGravitySweep(WorldPoint location, s16 xSpeed, s16 ySpeed, s16 zSpeed,
s16 gravity, u32 timeScale)
{
const s32 multiplier = static_cast<s32>(std::clamp(timeScale, 1u, 4u));
return {{location.x + xSpeed * multiplier, location.y + ySpeed * multiplier,
static_cast<u8>(location.z + zSpeed * multiplier)},
static_cast<s16>(zSpeed - gravity * multiplier)};
}
CollisionBody makeCollisionBody(WorldPoint location, const ShapeTypeInfo& shapeInfo, bool flipped)
{
const s32 extentX = static_cast<s32>(flipped ? shapeInfo.y : shapeInfo.x) * shapeDimensionScale;

View file

@ -1,4 +1,6 @@
#include "remorse/entity_dispatch_entry.h"
#include "remorse/collision.h"
#include "remorse/fixed_map.h"
#include <algorithm>
#include <cstring>
@ -122,11 +124,115 @@ EntityDispatchEntryBase* ProcessKernel::createItemProcess(u8 activeGroup, u16 it
setLastAllocationSize(sizeof(EntityDispatchEntryBase));
const u16 id = addProcess(*process);
processNames_[id] = "ItemProcess";
if (syncEnabled_) {
EntityDispatchEntryBase* current = currentProcessId_ == 0 ? nullptr : processAt(currentProcessId_);
if (current != nullptr && (current->bytes[0x16] & 0x08) == 0 && (current->bytes[0x18] & 0x02) != 0) {
current->bytes[0x18] |= 0x04;
}
if (id > currentProcessId_) {
process->bytes[0x16] |= 0x40;
}
}
EntityDispatchEntryBase* result = process.get();
ownedProcesses_.push_back(std::move(process));
return result;
}
u16 ProcessKernel::hurlItem(u8 activeGroup, u16 itemNumber, s16 xs, s16 ys, s16 zs, s16 gravity,
u32 timerTick, u16 (&groupCounts)[32])
{
if (itemNumber == 0 || itemNumber > maxTrackedItemNumber) {
throw std::out_of_range("gravity item number exceeds process lookup tables");
}
if (auto* existing = findProcessForItemAndType(itemNumber, 0x203)) {
const u16 processId = readLe16(*existing, 0x02);
if (allocationSizeAt(processId) != sizeof(GravityProcessEntry) ||
std::none_of(ownedGravityProcesses_.begin(), ownedGravityProcesses_.end(),
[existing](const auto& process) { return &process->base == existing; })) {
throw std::logic_error("gravity process ownership is not ported");
}
writeLe16(*existing, 0x32, static_cast<u16>(readLe16(*existing, 0x32) + xs));
writeLe16(*existing, 0x34, static_cast<u16>(readLe16(*existing, 0x34) + ys));
writeLe16(*existing, 0x36, static_cast<u16>(readLe16(*existing, 0x36) + zs));
return processId;
}
if (processes_.size() == 1020 && std::find(processes_.begin(), processes_.end(), nullptr) == processes_.end()) {
throw std::overflow_error("process table exhausted");
}
ownedGravityProcesses_.reserve(ownedGravityProcesses_.size() + 1);
auto process = std::make_unique<GravityProcessEntry>();
EntityDispatchEntry::initBase(&process->base, activeGroup, groupCounts);
writeLe16(process->base, 0x00, 0x0610);
setProcessSourceType(process->base, itemNumber);
setProcessEventTypeChecked(process->base, 0x203);
writeLe16(process->base, 0x32, static_cast<u16>(xs));
writeLe16(process->base, 0x34, static_cast<u16>(ys));
writeLe16(process->base, 0x36, static_cast<u16>(zs));
writeLe16(process->base, 0x38, static_cast<u16>(gravity));
writeLe16(process->base, 0x3b, 200);
process->base.bytes[0x3a] = 1;
process->base.bytes[0x3d] = 1;
setLastAllocationSize(sizeof(GravityProcessEntry));
const u16 id = addProcess(process->base);
processNames_[id] = "Gravity";
if (syncEnabled_) {
EntityDispatchEntryBase* current = currentProcessId_ == 0 ? nullptr : processAt(currentProcessId_);
if (current != nullptr && (current->bytes[0x16] & 0x08) == 0 && (current->bytes[0x18] & 0x02) != 0) {
current->bytes[0x18] |= 0x04;
}
if (id > currentProcessId_) {
process->base.bytes[0x16] |= 0x40;
}
}
EntityDispatchEntry::sleep(process->base, timerTick, 0x14);
ownedGravityProcesses_.push_back(std::move(process));
return id;
}
bool ProcessKernel::runUnobstructedGravity(u16 processId, LiveFixedMapItems& items,
u32 timeScale, u32 timerTick,
bool (*approveSweep)(u16, const WorldPoint&, const WorldPoint&, void*), void* context,
const std::vector<ShapeTypeInfo>* shapes, u16 (*groupCounts)[32])
{
const auto* process = processAt(processId);
if (process == nullptr || approveSweep == nullptr || allocationSizeAt(processId) != sizeof(GravityProcessEntry) ||
(process->bytes[0x16] & 0x08) != 0 || (process->bytes[0x19] & 0x10) != 0 ||
std::none_of(ownedGravityProcesses_.begin(), ownedGravityProcesses_.end(),
[process](const auto& owned) { return &owned->base == process; })) {
return false;
}
const u16 itemNumber = readLe16(*process, 0x04);
const auto* item = items.findItem(itemNumber);
const auto zSpeed = static_cast<s16>(readLe16(*process, 0x36));
if (item == nullptr || item->data.z > 250) {
return false;
}
if (zSpeed == 0) {
if (shapes == nullptr || groupCounts == nullptr ||
(readLe16(*process, 0x32) == 0 && readLe16(*process, 0x34) == 0) ||
!items.grabItem(itemNumber, *shapes, *this, *groupCounts, timerTick)) {
return false;
}
}
const WorldPoint from{item->data.x, item->data.y, item->data.z};
const auto step = planGravitySweep(from, static_cast<s16>(readLe16(*process, 0x32)),
static_cast<s16>(readLe16(*process, 0x34)), zSpeed,
static_cast<s16>(readLe16(*process, 0x38)), timeScale);
if (step.destination.x < 0 || step.destination.x > 0x7fff ||
step.destination.y < 0 || step.destination.y > 0x7fff || step.destination.z > 250 ||
!approveSweep(itemNumber, from, step.destination, context)) {
return false;
}
if (!items.moveItem(itemNumber, static_cast<u16>(step.destination.x),
static_cast<u16>(step.destination.y), static_cast<u8>(step.destination.z))) {
return false;
}
auto* mutableProcess = processAt(processId);
writeLe16(*mutableProcess, 0x36, static_cast<u16>(step.nextZSpeed));
EntityDispatchEntry::sleep(*mutableProcess, timerTick, 4 * std::clamp(timeScale, 1u, 4u));
return true;
}
SystemTimerProcessEntry* ProcessKernel::createSystemTimerProcess(u8 activeGroup, u16 (&groupCounts)[32])
{
if (systemTimerProcess_ != nullptr) {
@ -312,6 +418,12 @@ void ProcessKernel::releaseOwnedProcess(u16 id)
ownedStandProcesses_.erase(stand);
return;
}
const auto gravity = std::find_if(ownedGravityProcesses_.begin(), ownedGravityProcesses_.end(),
[entry](const auto& process) { return &process->base == entry; });
if (gravity != ownedGravityProcesses_.end()) {
ownedGravityProcesses_.erase(gravity);
return;
}
const auto owned = std::find_if(ownedProcesses_.begin(), ownedProcesses_.end(),
[entry](const auto& process) { return process.get() == entry; });
ownedProcesses_.erase(owned);
@ -336,15 +448,19 @@ void ProcessKernel::terminateProcess(u16 id, u16 (&groupCounts)[32])
}
const auto stand = std::find_if(ownedStandProcesses_.begin(), ownedStandProcesses_.end(),
[entry](const auto& process) { return &process->base == entry; });
const bool ownedGravityProcess = readLe16(*entry, 0x00) == 0x0610 &&
std::any_of(ownedGravityProcesses_.begin(), ownedGravityProcesses_.end(),
[entry](const auto& process) { return &process->base == entry; });
const bool ownedItemProcess = readLe16(*entry, 0x00) == ItemProcess::vtableOffset &&
std::any_of(ownedProcesses_.begin(), ownedProcesses_.end(),
[entry](const auto& process) { return process.get() == entry; });
if (itemNumber != 0 && (stand == ownedStandProcesses_.end() && !ownedItemProcess || id < 3 ||
if (itemNumber != 0 && (stand == ownedStandProcesses_.end() && !ownedItemProcess && !ownedGravityProcess || id < 3 ||
readLe16(*entry, 0x24) != 0 || readLe16(*entry, 0x26) != 0 ||
readLe16(*entry, 0x2e) != 0 || readLe16(*entry, 0x30) != 0)) {
throw std::logic_error("item process child cleanup is not ported");
}
if (stand == ownedStandProcesses_.end() && std::none_of(ownedProcesses_.begin(), ownedProcesses_.end(),
if (stand == ownedStandProcesses_.end() && !ownedGravityProcess &&
std::none_of(ownedProcesses_.begin(), ownedProcesses_.end(),
[entry](const auto& process) { return process.get() == entry; })) {
throw std::logic_error("external process ownership is not ported");
}
@ -533,6 +649,19 @@ EntityDispatchEntryBase* ProcessKernel::processAt(u16 id) const
return id < processes_.size() ? processes_[id] : nullptr;
}
EntityDispatchEntryBase* ProcessKernel::findProcessForItemAndType(u16 itemNumber, u16 eventType) const
{
for (std::size_t id = 3; id < processes_.size(); ++id) {
EntityDispatchEntryBase* process = processes_[id];
if (process != nullptr && (itemNumber == 0 || readLe16(*process, 0x04) == itemNumber) &&
(eventType == 0x0c || readLe16(*process, 0x06) == eventType) &&
(readLe16(*process, 0x16) & 0x08) == 0) {
return process;
}
}
return nullptr;
}
u16 ProcessKernel::allocationSizeAt(u16 id) const
{
return id < allocationSizes_.size() ? allocationSizes_[id] : 0;

View file

@ -1,8 +1,13 @@
#include "remorse/fixed_map.h"
#include "remorse/entity_dispatch_entry.h"
#include "remorse/file_system.h"
#include "remorse/type_flags.h"
#include <algorithm>
#include <stdexcept>
#include <utility>
namespace remorse {
namespace {
@ -147,6 +152,54 @@ std::optional<std::vector<StagedFixedMapItem>> stageFixedMapItems(const FixedMap
return items;
}
std::optional<std::vector<StagedContainedFixedMapItem>> stageContainedFixedMapItems(
const FixedMap& map, const std::vector<ShapeTypeInfo>& shapes)
{
if (map.index == 0) {
return std::nullopt;
}
std::vector<StagedContainedFixedMapItem> contained;
std::vector<u16> parentById(0x2800);
std::vector<u16> shapeById(0x2800);
u16 previousItemNumber = 0;
u16 currentParent = 0;
u16 currentDepth = 0;
std::size_t allocated = 0;
for (std::size_t index = 0; index < map.entries.size(); ++index) {
const auto& record = map.entries[index];
if (record.shape == 0) {
continue;
}
if (allocated == 0x2700 || record.shape >= shapes.size()) {
return std::nullopt;
}
const auto itemNumber = static_cast<u16>(0x100 + allocated++);
shapeById[itemNumber] = record.shape;
if ((record.flags & 8) != 0) {
const u16 depth = record.x / crusaderCoordinateScale;
if (depth > currentDepth) {
currentParent = previousItemNumber;
currentDepth = depth;
}
while (depth < currentDepth) {
currentParent = parentById[currentParent];
--currentDepth;
}
if (currentParent == 0 || (shapes[shapeById[currentParent]].family != 6 &&
shapes[shapeById[currentParent]].family != 7)) {
return std::nullopt;
}
parentById[itemNumber] = currentParent;
contained.push_back({itemNumber, currentParent, index});
} else {
currentParent = 0;
currentDepth = 0;
}
previousItemNumber = itemNumber;
}
return contained;
}
std::optional<StagedFixedMapItem> nearestStagedFixedMapItem(
const std::vector<StagedFixedMapItem>& items, s32 worldX, s32 worldY, s32 maxDistance)
{
@ -173,6 +226,11 @@ bool itemGrabCanCreateProcess(const StagedFixedMapItem& item)
return (item.data.flags & 0x02) == 0;
}
bool itemFallStartsHurl(const ShapeTypeInfo& shape)
{
return (shape.flags & 1) == 0 && shape.weight != 0;
}
u8 classifyItemFindZMatch(const StagedFixedMapItem& origin, const ShapeTypeInfo& originShape,
const StagedFixedMapItem& candidate, const ShapeTypeInfo& candidateShape, u8 zMatchFlags)
{
@ -224,4 +282,209 @@ std::vector<u16> itemFindBlockOrder(const ItemFindArea& area)
return blocks;
}
std::optional<StagedItemBlockChains> buildStagedItemBlockChains(const std::vector<StagedFixedMapItem>& items)
{
StagedItemBlockChains chains;
chains.heads.resize(0x1000);
chains.next.resize(0x2800);
std::vector<bool> seen(chains.next.size());
for (const auto& item : items) {
if (item.itemNumber < 0x100 || item.itemNumber >= chains.next.size() || seen[item.itemNumber] ||
item.data.x > 0x7fff || item.data.y > 0x7fff) {
return std::nullopt;
}
seen[item.itemNumber] = true;
const auto block = (item.data.x >> 9) * 0x40 + (item.data.y >> 9);
chains.next[item.itemNumber] = chains.heads[block];
chains.heads[block] = item.itemNumber;
}
return chains;
}
std::vector<u16> itemFindCandidateOrder(const ItemFindArea& area, const StagedItemBlockChains& chains)
{
std::vector<u16> candidates;
for (const auto block : itemFindBlockOrder(area)) {
for (u16 itemNumber = chains.heads[block]; itemNumber != 0; itemNumber = chains.next[itemNumber]) {
candidates.push_back(itemNumber);
}
}
return candidates;
}
namespace {
std::optional<std::vector<ItemFindZCandidate>> collectZMatches(const StagedFixedMapItem& origin,
const std::vector<StagedFixedMapItem>& items, const std::vector<ShapeTypeInfo>& shapes,
u8 zMatchFlags, bool checkRectangle)
{
if (origin.data.shape >= shapes.size()) {
return std::nullopt;
}
const auto chains = buildStagedItemBlockChains(items);
if (!chains) {
return std::nullopt;
}
std::vector<const StagedFixedMapItem*> byId(chains->next.size());
for (const auto& item : items) {
if (item.data.shape >= shapes.size()) {
return std::nullopt;
}
byId[item.itemNumber] = &item;
}
std::vector<ItemFindZCandidate> matches;
const auto area = itemFindAreaAroundItem(origin, shapes[origin.data.shape]);
for (const auto itemNumber : itemFindCandidateOrder(area, *chains)) {
const auto& candidate = *byId[itemNumber];
if (checkRectangle && (candidate.data.x < area.minX || candidate.data.x > area.maxX ||
candidate.data.y < area.minY || candidate.data.y > area.maxY)) {
continue;
}
const auto matchType = classifyItemFindZMatch(origin, shapes[origin.data.shape],
candidate, shapes[candidate.data.shape], zMatchFlags);
if (matchType != 0) {
matches.push_back({itemNumber, matchType});
}
}
return matches;
}
} // namespace
std::optional<std::vector<ItemFindZCandidate>> itemFindZMatches(const StagedFixedMapItem& origin,
const std::vector<StagedFixedMapItem>& items, const std::vector<ShapeTypeInfo>& shapes, u8 zMatchFlags)
{
return collectZMatches(origin, items, shapes, zMatchFlags, false);
}
std::optional<std::vector<ItemFindZCandidate>> itemGrabSearchCandidates(const StagedFixedMapItem& origin,
const std::vector<StagedFixedMapItem>& items, const std::vector<ShapeTypeInfo>& shapes)
{
return collectZMatches(origin, items, shapes, 3, true);
}
std::optional<std::vector<ItemGrabAction>> planItemGrabActions(const StagedFixedMapItem& origin,
const std::vector<StagedFixedMapItem>& items, const std::vector<ShapeTypeInfo>& shapes)
{
const auto candidates = itemGrabSearchCandidates(origin, items, shapes);
if (!candidates) {
return std::nullopt;
}
std::vector<const StagedFixedMapItem*> byId(0x2800);
for (const auto& item : items) {
byId[item.itemNumber] = &item;
}
std::vector<ItemGrabAction> actions;
for (const auto& candidate : *candidates) {
const auto& item = *byId[candidate.itemNumber];
if (candidate.matchType == 1 && itemFallStartsHurl(shapes[item.data.shape])) {
actions.push_back({candidate.itemNumber, ItemGrabActionKind::Hurl});
} else if (candidate.matchType == 2 && itemGrabCanCreateProcess(item)) {
actions.push_back({candidate.itemNumber, ItemGrabActionKind::CreateProcess});
}
}
return actions;
}
std::optional<std::vector<u16>> dispatchStagedItemGrab(const StagedFixedMapItem& origin,
const std::vector<StagedFixedMapItem>& items, const std::vector<ShapeTypeInfo>& shapes,
ProcessKernel& kernel, u16 (&groupCounts)[32], u32 timerTick)
{
const auto actions = planItemGrabActions(origin, items, shapes);
if (!actions) {
return std::nullopt;
}
for (const auto& action : *actions) {
if (action.itemNumber > ProcessKernel::maxTrackedItemNumber) {
return std::nullopt;
}
}
std::vector<u16> processIds;
for (const auto& action : *actions) {
if (action.kind == ItemGrabActionKind::Hurl) {
processIds.push_back(kernel.hurlItem(kernel.activeGroup(), action.itemNumber, 0, 0, 0, 2,
timerTick, groupCounts));
} else {
auto* process = kernel.createItemProcess(kernel.activeGroup(), action.itemNumber, groupCounts);
processIds.push_back(static_cast<u16>(process->bytes[2] | (static_cast<u16>(process->bytes[3]) << 8)));
}
}
return processIds;
}
LiveFixedMapItems::LiveFixedMapItems(std::vector<StagedFixedMapItem> items) : items_(std::move(items))
{
if (!buildStagedItemBlockChains(items_)) {
throw std::invalid_argument("invalid live item IDs or coordinates");
}
}
const StagedFixedMapItem* LiveFixedMapItems::findItem(u16 itemNumber) const
{
for (const auto& item : items_) {
if (item.itemNumber == itemNumber) {
return &item;
}
}
return nullptr;
}
std::optional<StagedFixedMapItem> LiveFixedMapItems::nearestItem(s32 worldX, s32 worldY,
s32 maxDistance) const
{
return nearestStagedFixedMapItem(items_, worldX, worldY, maxDistance);
}
bool LiveFixedMapItems::insertItem(StagedFixedMapItem item)
{
if (item.itemNumber < 0x100 || item.itemNumber >= 0x2800 || item.data.x > 0x7fff ||
item.data.y > 0x7fff || findItem(item.itemNumber)) {
return false;
}
item.data.z = std::min<u8>(item.data.z, 0xfa);
items_.push_back(item);
return true;
}
bool LiveFixedMapItems::moveItem(u16 itemNumber, u16 x, u16 y, u8 z)
{
if (x > 0x7fff || y > 0x7fff) {
return false;
}
const auto item = std::find_if(items_.begin(), items_.end(), [itemNumber](const auto& candidate) {
return candidate.itemNumber == itemNumber;
});
if (item == items_.end()) {
return false;
}
item->data.x = x;
item->data.y = y;
item->data.z = std::min<u8>(z, 0xfa);
std::rotate(item, item + 1, items_.end());
return true;
}
std::optional<std::vector<u16>> LiveFixedMapItems::grabItem(u16 itemNumber,
const std::vector<ShapeTypeInfo>& shapes, ProcessKernel& kernel,
u16 (&groupCounts)[32], u32 timerTick) const
{
const auto* origin = findItem(itemNumber);
return origin == nullptr ? std::nullopt : dispatchStagedItemGrab(*origin, items_, shapes,
kernel, groupCounts, timerTick);
}
std::optional<std::vector<u16>> LiveFixedMapItems::moveApprovedItem(u16 itemNumber, u16 x, u16 y,
u8 z, const std::vector<ShapeTypeInfo>& shapes, ProcessKernel& kernel,
u16 (&groupCounts)[32], u32 timerTick)
{
if (x > 0x7fff || y > 0x7fff || !findItem(itemNumber)) {
return std::nullopt;
}
auto processIds = grabItem(itemNumber, shapes, kernel, groupCounts, timerTick);
if (processIds) {
moveItem(itemNumber, x, y, z);
}
return processIds;
}
} // namespace remorse

View file

@ -77,6 +77,8 @@ int main(int argc, char** argv)
std::cout << "Game data root: " << (gameDataRoot ? gameDataRoot->path.string() : "not found") << '\n';
if (gameDataRoot) {
std::optional<remorse::StagedFixedMapItem> firstStagedItem;
std::optional<remorse::StagedItemBlockChains> stagedBlockChains;
std::optional<std::vector<remorse::StagedFixedMapItem>> stagedMapItems;
const auto palettePath = remorse::resolveGameDataPath(*gameDataRoot, std::filesystem::path("STATIC") / "GAMEPAL.PAL");
const auto paletteBytes = palettePath ? remorse::readBinaryFile(*palettePath) : std::nullopt;
std::cout << "GAMEPAL.PAL bytes: " << (paletteBytes ? paletteBytes->size() : 0) << '\n';
@ -101,6 +103,8 @@ int main(int argc, char** argv)
const auto items = remorse::stageFixedMapItems(*map);
if (items && !items->empty()) {
firstStagedItem = items->front();
stagedBlockChains = remorse::buildStagedItemBlockChains(*items);
stagedMapItems = *items;
struct ItemScanContext {
remorse::ProcessKernel* kernel;
remorse::u16 (*groups)[32];
@ -141,6 +145,23 @@ int main(int argc, char** argv)
const auto area = remorse::itemFindAreaAroundItem(
*firstStagedItem, (*typeFlags)[firstStagedItem->data.shape]);
std::cout << "Staged item ItemFind blocks: " << remorse::itemFindBlockOrder(area).size() << '\n';
if (stagedBlockChains) {
std::cout << "Staged item ItemFind candidates: " <<
remorse::itemFindCandidateOrder(area, *stagedBlockChains).size() << '\n';
}
if (stagedMapItems) {
const auto matches = remorse::itemFindZMatches(*firstStagedItem, *stagedMapItems, *typeFlags, 3);
std::cout << "Staged item ItemFind Z matches (script-free): " <<
(matches ? matches->size() : 0) << '\n';
const auto grabCandidates = remorse::itemGrabSearchCandidates(
*firstStagedItem, *stagedMapItems, *typeFlags);
const auto grabActions = remorse::planItemGrabActions(
*firstStagedItem, *stagedMapItems, *typeFlags);
std::cout << "Staged item Item_Grab candidates: " <<
(grabCandidates ? grabCandidates->size() : 0) << '\n';
std::cout << "Staged item Item_Grab planned actions: " <<
(grabActions ? grabActions->size() : 0) << '\n';
}
}
const auto usecodePath = remorse::resolveGameDataPath(*gameDataRoot, std::filesystem::path("USECODE") / "EUSECODE.FLX");

View file

@ -29,6 +29,7 @@ std::optional<std::vector<ShapeTypeInfo>> loadTypeFlags(const std::filesystem::p
info.y = static_cast<u8>((byte3 >> 2) & 0x1f);
info.z = static_cast<u8>(((byte4 << 1) | (byte3 >> 7)) & 0x1f);
info.animationType = static_cast<u8>(byte4 >> 4);
info.weight = (*bytes)[offset + 7];
infos.push_back(info);
}

View file

@ -47,7 +47,7 @@ struct AppState {
remorse::u16 diagnosticGroupCounts[32]{};
remorse::StandProcessEntry* diagnosticStand = nullptr;
remorse::KeyboardProcessEntry* diagnosticKeyboard = nullptr;
std::vector<remorse::StagedFixedMapItem> stagedItems;
std::optional<remorse::LiveFixedMapItems> liveItems;
std::optional<remorse::StagedFixedMapItem> diagnosticItem;
remorse::u16 diagnosticItemProcessId = 0;
remorse::u16 diagnosticReleaseEventItem = 0;
@ -281,7 +281,7 @@ void loadSceneAsync(HWND window, AppState& state)
state.playerFrames = std::move(playerFrames);
state.playerPalette = *palette;
if (stagedItems) {
state.stagedItems = std::move(*stagedItems);
state.liveItems.emplace(std::move(*stagedItems));
}
state.sceneLoaded = true;
}
@ -557,8 +557,8 @@ void paintWindow(HWND window, AppState& state)
RECT diagnosticsBounds{20, 30, viewWidth - 12, 54};
SetTextColor(device, RGB(74, 207, 184));
DrawTextW(device, diagnostics.str().c_str(), -1, &diagnosticsBounds, DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS);
const auto nearbyItem = remorse::nearestStagedFixedMapItem(
state.stagedItems, state.playerWorld.x, state.playerWorld.y, diagnosticItemRange);
const auto nearbyItem = state.liveItems ? state.liveItems->nearestItem(
state.playerWorld.x, state.playerWorld.y, diagnosticItemRange) : std::nullopt;
if (state.diagnosticItem || nearbyItem) {
const auto& displayItem = state.diagnosticItem ? state.diagnosticItem : nearbyItem;
std::wostringstream itemStatus;
@ -729,8 +729,8 @@ LRESULT CALLBACK windowProcedure(HWND window, UINT message, WPARAM wParam, LPARA
std::lock_guard<std::mutex> lock(state->sceneMutex);
if (state->sceneLoaded && state->scene && !state->diagnosticItemCompleted &&
state->diagnosticItemProcessId == 0) {
state->diagnosticItem = remorse::nearestStagedFixedMapItem(
state->stagedItems, state->playerWorld.x, state->playerWorld.y, diagnosticItemRange);
state->diagnosticItem = state->liveItems ? state->liveItems->nearestItem(
state->playerWorld.x, state->playerWorld.y, diagnosticItemRange) : std::nullopt;
}
if (state->diagnosticItem && state->diagnosticItemProcessId == 0 &&
state->diagnosticItem->itemNumber <= remorse::ProcessKernel::maxTrackedItemNumber &&