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

@ -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