Refactor entity dispatch entry management and enhance item grab search tests

This commit is contained in:
Maddo 2026-10-07 18:04:47 +02:00
commit 49a15602b6
6 changed files with 57 additions and 12 deletions

View file

@ -14,6 +14,7 @@ add_library(remorse_core
src/map_renderer.cpp
src/map_sorter.cpp
src/palette.cpp
src/ported/entity_dispatch_entry_set_group_id.cpp
src/runtime.cpp
src/shape_archive.cpp
src/type_flags.cpp

View file

@ -2,6 +2,7 @@
#include "remorse/animation_archive.h"
#include "remorse/collision.h"
#include "remorse/fixed_map.h"
#include "ported/entity_dispatch_entry_port.h"
#include <algorithm>
#include <cstring>
@ -1230,15 +1231,7 @@ void EntityDispatchEntry::setGroupId(EntityDispatchEntryBase& entry, u8 groupId,
if (groupId == 0 || groupId > 31) {
throw std::invalid_argument("process group ID must be in 1..31");
}
const u8 oldGroupId = entry.bytes[groupIdOffset] & 0x1f;
if (oldGroupId == groupId) {
return;
}
if (oldGroupId != 0) {
--groupCounts[oldGroupId];
}
entry.bytes[groupIdOffset] = groupId;
++groupCounts[groupId];
ported::setEntityDispatchEntryGroupId(entry, groupId, groupCounts);
}
void EntityDispatchEntry::incrementGroupId(EntityDispatchEntryBase& entry, ProcessKernel& kernel, u16 (&groupCounts)[32])

View file

@ -0,0 +1,10 @@
#pragma once
#include "remorse/entity_dispatch_entry.h"
namespace remorse::ported {
void setEntityDispatchEntryGroupId(EntityDispatchEntryBase& entry, u8 groupId,
u16 (&groupCounts)[32]);
} // namespace remorse::ported

View file

@ -0,0 +1,18 @@
#include "entity_dispatch_entry_port.h"
namespace remorse::ported {
void setEntityDispatchEntryGroupId(EntityDispatchEntryBase& entry, u8 groupId,
u16 (&groupCounts)[32])
{
const u8 oldGroupId = entry.bytes[0x08] & 0x1f;
if (oldGroupId == 0 || oldGroupId != groupId) {
if (oldGroupId != 0) {
--groupCounts[oldGroupId];
}
entry.bytes[0x08] = groupId;
++groupCounts[groupId];
}
}
} // namespace remorse::ported

View file

@ -360,6 +360,25 @@ int main()
integratedStartupKernel.processAt(processIdOf(integratedTimer)) == &integratedTimer->base &&
integratedStartupKernel.processAt(processIdOf(integratedKeyboard)) == &integratedKeyboard->base &&
integratedStartupKernel.processAt(processIdOf(integratedController)) == &integratedController->base);
const auto destinationUseCandidates = remorse::itemGrabSearchCandidates(
*integratedAvatar, integratedStartupWorld.mapItems(), *typeFlags);
assert(destinationUseCandidates);
const std::array<remorse::u16, 6> expectedDestinationCandidates{6812, 6811, 6810, 6804, 6786, 6785};
assert(destinationUseCandidates->size() == expectedDestinationCandidates.size());
unsigned eligibleDestinationUses = 0;
for (std::size_t index = 0; index < destinationUseCandidates->size(); ++index) {
const auto& candidate = (*destinationUseCandidates)[index];
assert(candidate.itemNumber == expectedDestinationCandidates[index]);
const auto* item = integratedStartupWorld.findItem(candidate.itemNumber);
assert(item && item->data.shape < typeFlags->size());
const auto& shape = (*typeFlags)[item->data.shape];
const remorse::UsecodeItemIdentity destinationIdentity{item->itemNumber, item->data.shape,
item->data.flags, item->data.quality, shape.family, false};
const auto eligible = remorse::selectEligibleUsecodeEvent(*usecode, *retailOwnerRows,
destinationIdentity, remorse::UsecodeClassBases{0, 0x800, 0x900}, 0x02, 1);
eligibleDestinationUses += eligible.has_value();
}
assert(eligibleDestinationUses == 0);
const auto spawnUseCandidates = remorse::itemGrabSearchCandidates(
*spawnedAvatar, spawnSearchWorld.mapItems(), *typeFlags);
assert(spawnUseCandidates);