Refactor USECODE tooling documentation and enhance map-viewer decompiler
- Updated the USECODE Tool Improvement Plan to focus on the map-viewer decompiler/editor, emphasizing its role as the primary development target for USECODE editing and recompilation. - Revised the tooling comparison document to include the newer map-viewer decompiler, clarifying its purpose and distinguishing it from the Python parser. - Introduced a new ClearAvatarInStasisProcessEntry structure in the entity dispatch entry header, along with related process creation and execution logic in the ProcessKernel. - Implemented the setItemShape method in LiveFixedMapItems to allow dynamic shape updates for items. - Enhanced the teleporter process to handle avatar stasis and integrated it into the game main loop, ensuring proper process management and state handling. - Added tests for the new functionality, including shape setting and teleporter process behavior, to ensure correctness and stability.
This commit is contained in:
parent
0771c86043
commit
6d4972933f
17 changed files with 1868 additions and 114 deletions
|
|
@ -6,6 +6,7 @@
|
|||
#include <cstddef>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
namespace remorse {
|
||||
|
|
@ -56,6 +57,11 @@ struct TeleporterProcessEntry {
|
|||
u8 extra[0x04];
|
||||
} CR_PACKED;
|
||||
|
||||
struct ClearAvatarInStasisProcessEntry {
|
||||
EntityDispatchEntryBase base;
|
||||
u8 extra[0x01];
|
||||
} CR_PACKED;
|
||||
|
||||
struct AnimPrimitiveProcessEntry {
|
||||
EntityDispatchEntryBase base;
|
||||
u8 extra[0x29];
|
||||
|
|
@ -82,6 +88,9 @@ struct EntityDispatchEntryRuntimeState {
|
|||
} CR_PACKED;
|
||||
CR_PACK_POP
|
||||
|
||||
static_assert(sizeof(ClearAvatarInStasisProcessEntry) == 0x33,
|
||||
"Clear-avatar-stasis process size must match allocation evidence");
|
||||
|
||||
static_assert(sizeof(EntityDispatchEntryBase) == 0x32, "EntityDispatchEntryBase size must match allocation evidence");
|
||||
static_assert(sizeof(StandProcessEntry) == 0x42, "StandProcessEntry size must match allocation evidence");
|
||||
static_assert(sizeof(GravityProcessEntry) == 0x42, "GravityProcessEntry size must match allocation evidence");
|
||||
|
|
@ -127,6 +136,10 @@ public:
|
|||
ControllerProcessEntry* createControllerProcess(u8 activeGroup, u16 (&groupCounts)[32]);
|
||||
TeleporterProcessEntry* createTeleporterProcess(u8 activeGroup, u16 mapNumber, u16 teleportId,
|
||||
u16 (&groupCounts)[32]);
|
||||
TeleporterProcessEntry* createTeleporterProcess(u8 activeGroup, u16 mapNumber, u16 teleportId,
|
||||
u16 (&groupCounts)[32], bool doStasis, bool avatarTeleporting, bool& avatarInStasis);
|
||||
bool runClearAvatarInStasisProcess(u16 processId, bool& avatarInStasis,
|
||||
u16 (&groupCounts)[32]);
|
||||
AnimPrimitiveProcessEntry* createAnimPrimitiveProcess(u8 activeGroup, u16 itemNumber,
|
||||
u16 animationNumber, u8 direction, const AnimationClip& clip, u16 (&groupCounts)[32]);
|
||||
EntityVmContextProcessEntry* createUsecodeProcess(u8 activeGroup, u16 (&groupCounts)[32]);
|
||||
|
|
@ -172,6 +185,8 @@ public:
|
|||
std::size_t capacity() const;
|
||||
|
||||
private:
|
||||
ClearAvatarInStasisProcessEntry* createClearAvatarInStasisProcess(u8 activeGroup,
|
||||
bool& avatarInStasis, u16 (&groupCounts)[32]);
|
||||
void releaseOwnedProcess(u16 id);
|
||||
void refreshItemPresence(u16 itemNumber);
|
||||
void refreshItemProcessType(u16 itemNumber, u16 eventType);
|
||||
|
|
@ -183,12 +198,14 @@ private:
|
|||
std::vector<std::unique_ptr<GravityProcessEntry>> ownedGravityProcesses_;
|
||||
std::vector<std::unique_ptr<AnimPrimitiveProcessEntry>> ownedAnimPrimitiveProcesses_;
|
||||
std::vector<std::unique_ptr<TeleporterProcessEntry>> ownedTeleporterProcesses_;
|
||||
std::vector<std::unique_ptr<ClearAvatarInStasisProcessEntry>> ownedClearAvatarInStasisProcesses_;
|
||||
std::vector<std::unique_ptr<EntityVmContextProcessEntry>> ownedUsecodeProcesses_;
|
||||
std::unique_ptr<SystemTimerProcessEntry> systemTimerProcess_;
|
||||
std::unique_ptr<KeyboardProcessEntry> keyboardProcess_;
|
||||
std::unique_ptr<KeyDaemonProcessEntry> keyDaemonProcess_;
|
||||
std::unique_ptr<ControllerProcessEntry> controllerProcess_;
|
||||
std::vector<u16> keyboardSubscriberIds_;
|
||||
std::vector<std::pair<u16, u16>> processWaits_;
|
||||
std::array<KeyEvent, 32> pendingKeyEvents_{};
|
||||
u8 nextKeyEventOffset_ = 0;
|
||||
u8 keyEventOffset_ = 0;
|
||||
|
|
@ -255,6 +272,11 @@ public:
|
|||
u16 currentMapNumber, const std::vector<ShapeTypeInfo>& shapes);
|
||||
};
|
||||
|
||||
class ClearAvatarInStasisProcess {
|
||||
public:
|
||||
static constexpr u16 vtableOffset = 0x0f5e;
|
||||
};
|
||||
|
||||
class KeyboardProcess {
|
||||
public:
|
||||
static bool handleKeyEvent(KeyboardProcessEntry& process, u16 selector, u16 filter,
|
||||
|
|
|
|||
|
|
@ -132,6 +132,7 @@ public:
|
|||
std::optional<std::vector<u16>> hatchGlobEgg(u16 eggItemNumber, const GlobObject& glob,
|
||||
const std::vector<ShapeTypeInfo>& shapes);
|
||||
bool isGlobHatched(u16 eggItemNumber) const;
|
||||
bool setItemShape(u16 itemNumber, u16 shape);
|
||||
bool setItemFrame(u16 itemNumber, u8 frame);
|
||||
bool moveItem(u16 itemNumber, u16 x, u16 y, u8 z);
|
||||
std::optional<std::vector<u16>> grabItem(u16 itemNumber, const std::vector<ShapeTypeInfo>& shapes,
|
||||
|
|
|
|||
|
|
@ -195,6 +195,44 @@ TeleporterProcessEntry* ProcessKernel::createTeleporterProcess(u8 activeGroup, u
|
|||
return result;
|
||||
}
|
||||
|
||||
TeleporterProcessEntry* ProcessKernel::createTeleporterProcess(u8 activeGroup, u16 mapNumber,
|
||||
u16 teleportId, u16 (&groupCounts)[32], bool doStasis, bool avatarTeleporting,
|
||||
bool& avatarInStasis)
|
||||
{
|
||||
auto* teleporter = createTeleporterProcess(activeGroup, mapNumber, teleportId, groupCounts);
|
||||
if (doStasis && !avatarTeleporting) {
|
||||
auto* clearStasis = createClearAvatarInStasisProcess(activeGroup, avatarInStasis, groupCounts);
|
||||
processWaits_.emplace_back(readLe16(teleporter->base, 0x02),
|
||||
readLe16(clearStasis->base, 0x02));
|
||||
}
|
||||
return teleporter;
|
||||
}
|
||||
|
||||
ClearAvatarInStasisProcessEntry* ProcessKernel::createClearAvatarInStasisProcess(u8 activeGroup,
|
||||
bool& avatarInStasis, u16 (&groupCounts)[32])
|
||||
{
|
||||
if (processes_.size() == 1020 && std::find(processes_.begin(), processes_.end(), nullptr) == processes_.end()) {
|
||||
throw std::overflow_error("process table exhausted");
|
||||
}
|
||||
if (std::find(processes_.begin(), processes_.end(), nullptr) == processes_.end()) {
|
||||
processes_.reserve(processes_.size() + 30);
|
||||
allocationSizes_.reserve(allocationSizes_.size() + 30);
|
||||
processNames_.reserve(processNames_.size() + 30);
|
||||
}
|
||||
ownedClearAvatarInStasisProcesses_.reserve(ownedClearAvatarInStasisProcesses_.size() + 1);
|
||||
auto process = std::make_unique<ClearAvatarInStasisProcessEntry>();
|
||||
EntityDispatchEntry::initBase(&process->base, activeGroup, groupCounts);
|
||||
writeLe16(process->base, 0x00, ClearAvatarInStasisProcess::vtableOffset);
|
||||
process->extra[0] = avatarInStasis ? 1 : 0;
|
||||
avatarInStasis = true;
|
||||
setLastAllocationSize(sizeof(ClearAvatarInStasisProcessEntry));
|
||||
const u16 id = addProcess(process->base);
|
||||
processNames_[id] = "ClearAvatarInStasis";
|
||||
ClearAvatarInStasisProcessEntry* result = process.get();
|
||||
ownedClearAvatarInStasisProcesses_.push_back(std::move(process));
|
||||
return result;
|
||||
}
|
||||
|
||||
bool TeleporterProcess::run(const TeleporterProcessEntry& process, LiveFixedMapItems& items,
|
||||
u16 currentMapNumber, const std::vector<ShapeTypeInfo>& shapes)
|
||||
{
|
||||
|
|
@ -211,6 +249,27 @@ bool TeleporterProcess::run(const TeleporterProcessEntry& process, LiveFixedMapI
|
|||
return destination && items.teleportAvatar(*destination, static_cast<u8>(targetMap));
|
||||
}
|
||||
|
||||
bool ProcessKernel::runClearAvatarInStasisProcess(u16 processId, bool& avatarInStasis,
|
||||
u16 (&groupCounts)[32])
|
||||
{
|
||||
EntityDispatchEntryBase* entry = processAt(processId);
|
||||
const auto ownedProcess = std::find_if(ownedClearAvatarInStasisProcesses_.begin(),
|
||||
ownedClearAvatarInStasisProcesses_.end(), [entry](const auto& process) {
|
||||
return &process->base == entry;
|
||||
});
|
||||
if (entry == nullptr || readLe16(*entry, 0x00) != ClearAvatarInStasisProcess::vtableOffset ||
|
||||
ownedProcess == ownedClearAvatarInStasisProcesses_.end()) {
|
||||
return false;
|
||||
}
|
||||
const auto* process = reinterpret_cast<const ClearAvatarInStasisProcessEntry*>(entry);
|
||||
if (process->extra[0] == 0) {
|
||||
avatarInStasis = false;
|
||||
}
|
||||
entry->bytes[0x18] |= 0x04;
|
||||
terminateProcess(processId, groupCounts);
|
||||
return true;
|
||||
}
|
||||
|
||||
EntityVmContextProcessEntry* ProcessKernel::createUsecodeProcess(u8 activeGroup,
|
||||
u16 (&groupCounts)[32])
|
||||
{
|
||||
|
|
@ -690,6 +749,9 @@ void ProcessKernel::clearProcessSlot(u16 id)
|
|||
if (id >= processes_.size()) {
|
||||
throw std::out_of_range("process ID outside table");
|
||||
}
|
||||
processWaits_.erase(std::remove_if(processWaits_.begin(), processWaits_.end(), [id](const auto& wait) {
|
||||
return wait.first == id || wait.second == id;
|
||||
}), processWaits_.end());
|
||||
processes_[id] = nullptr;
|
||||
allocationSizes_[id] = 0;
|
||||
processNames_[id] = nullptr;
|
||||
|
|
@ -723,6 +785,13 @@ void ProcessKernel::releaseOwnedProcess(u16 id)
|
|||
ownedTeleporterProcesses_.erase(teleporter);
|
||||
return;
|
||||
}
|
||||
const auto clearAvatarInStasis = std::find_if(ownedClearAvatarInStasisProcesses_.begin(),
|
||||
ownedClearAvatarInStasisProcesses_.end(),
|
||||
[entry](const auto& process) { return &process->base == entry; });
|
||||
if (clearAvatarInStasis != ownedClearAvatarInStasisProcesses_.end()) {
|
||||
ownedClearAvatarInStasisProcesses_.erase(clearAvatarInStasis);
|
||||
return;
|
||||
}
|
||||
const auto usecode = std::find_if(ownedUsecodeProcesses_.begin(), ownedUsecodeProcesses_.end(),
|
||||
[entry](const auto& process) { return &process->base == entry; });
|
||||
if (usecode != ownedUsecodeProcesses_.end()) {
|
||||
|
|
@ -771,6 +840,9 @@ void ProcessKernel::terminateProcess(u16 id, u16 (&groupCounts)[32])
|
|||
const bool ownedTeleporterProcess = std::any_of(ownedTeleporterProcesses_.begin(),
|
||||
ownedTeleporterProcesses_.end(),
|
||||
[entry](const auto& process) { return &process->base == entry; });
|
||||
const bool ownedClearAvatarInStasisProcess = std::any_of(ownedClearAvatarInStasisProcesses_.begin(),
|
||||
ownedClearAvatarInStasisProcesses_.end(),
|
||||
[entry](const auto& process) { return &process->base == entry; });
|
||||
if (itemNumber != 0 && (stand == ownedStandProcesses_.end() && !ownedItemProcess &&
|
||||
!ownedGravityProcess && !ownedAnimationProcess && !ownedUsecodeProcess || id < 3 ||
|
||||
readLe16(*entry, 0x24) != 0 || readLe16(*entry, 0x26) != 0 ||
|
||||
|
|
@ -778,7 +850,7 @@ void ProcessKernel::terminateProcess(u16 id, u16 (&groupCounts)[32])
|
|||
throw std::logic_error("item process child cleanup is not ported");
|
||||
}
|
||||
if (stand == ownedStandProcesses_.end() && !ownedGravityProcess && !ownedAnimationProcess &&
|
||||
!ownedUsecodeProcess && !ownedTeleporterProcess &&
|
||||
!ownedUsecodeProcess && !ownedTeleporterProcess && !ownedClearAvatarInStasisProcess &&
|
||||
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");
|
||||
|
|
@ -923,7 +995,21 @@ void ProcessKernel::scanRunnableProcesses(u8 activeGroup, void (*run)(EntityDisp
|
|||
try {
|
||||
for (std::size_t id = 0; id < processes_.size(); ++id) {
|
||||
EntityDispatchEntryBase* entry = processes_[id];
|
||||
if (entry != nullptr && (readLe16(*entry, 0x16) & 0x08) == 0) {
|
||||
bool waitingForProcess = false;
|
||||
if (entry != nullptr) {
|
||||
const u16 processId = readLe16(*entry, 0x02);
|
||||
const auto wait = std::find_if(processWaits_.begin(), processWaits_.end(),
|
||||
[processId](const auto& candidate) { return candidate.first == processId; });
|
||||
if (wait != processWaits_.end()) {
|
||||
const EntityDispatchEntryBase* target = processAt(wait->second);
|
||||
waitingForProcess = target != nullptr &&
|
||||
(readLe16(*target, 0x16) & 0x08) == 0;
|
||||
if (!waitingForProcess) {
|
||||
processWaits_.erase(wait);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (entry != nullptr && !waitingForProcess && (readLe16(*entry, 0x16) & 0x08) == 0) {
|
||||
if ((readLe16(*entry, 0x18) & 0x1000) != 0) {
|
||||
const u32 sleepStart = readLe16(*entry, 0x0a) | (static_cast<u32>(readLe16(*entry, 0x0c)) << 16);
|
||||
const u32 sleepLength = readLe16(*entry, 0x0e) | (static_cast<u32>(readLe16(*entry, 0x10)) << 16);
|
||||
|
|
|
|||
|
|
@ -854,6 +854,18 @@ bool LiveFixedMapItems::isGlobHatched(u16 eggItemNumber) const
|
|||
return eggItemNumber < hatchedGlobIds_.size() && hatchedGlobIds_[eggItemNumber];
|
||||
}
|
||||
|
||||
bool LiveFixedMapItems::setItemShape(u16 itemNumber, u16 shape)
|
||||
{
|
||||
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.shape = shape;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LiveFixedMapItems::setItemFrame(u16 itemNumber, u8 frame)
|
||||
{
|
||||
const auto item = std::find_if(items_.begin(), items_.end(), [itemNumber](const auto& candidate) {
|
||||
|
|
|
|||
|
|
@ -299,8 +299,16 @@ void runUsecodeTasks(AppState& state)
|
|||
const auto* item = app.liveItems ? app.liveItems->findItem(*itemNumber) : nullptr;
|
||||
return item ? std::optional<remorse::u16>{item->data.mapNumber} : std::nullopt;
|
||||
}
|
||||
if (ordinal == 0x24 && argumentBytes == 6) {
|
||||
const remorse::u16 shape = static_cast<remorse::u16>(arguments[4] |
|
||||
(static_cast<remorse::u16>(arguments[5]) << 8));
|
||||
if (!app.liveItems || !app.liveItems->setItemShape(*itemNumber, shape)) {
|
||||
return std::nullopt;
|
||||
}
|
||||
app.usecodeWorldMutationPending = true;
|
||||
return remorse::u16{0};
|
||||
}
|
||||
if (ordinal == 0x59 && argumentBytes == 6) {
|
||||
std::lock_guard<std::mutex> lock(app.sceneMutex);
|
||||
const remorse::u8 frame = static_cast<remorse::u8>(arguments[4] |
|
||||
(static_cast<remorse::u16>(arguments[5]) << 8));
|
||||
if (!app.liveItems || !app.liveItems->setItemFrame(*itemNumber, frame)) {
|
||||
|
|
@ -526,15 +534,51 @@ void loadSceneAsync(HWND window, AppState& state)
|
|||
for (int reservedSlot = 0; reservedSlot < 3; ++reservedSlot) {
|
||||
teleporterKernel.createProcess(1, teleporterGroupCounts);
|
||||
}
|
||||
bool avatarInStasis = false;
|
||||
auto* teleporter = teleporterKernel.createTeleporterProcess(1,
|
||||
static_cast<remorse::u16>(state.mapIndex), 0x1e, teleporterGroupCounts);
|
||||
static_cast<remorse::u16>(state.mapIndex), 0x1e, teleporterGroupCounts,
|
||||
true, false, avatarInStasis);
|
||||
const remorse::u16 processId = static_cast<remorse::u16>(teleporter->base.bytes[2] |
|
||||
(static_cast<remorse::u16>(teleporter->base.bytes[3]) << 8));
|
||||
const bool teleported = remorse::TeleporterProcess::run(*teleporter, liveItems,
|
||||
static_cast<remorse::u16>(state.mapIndex), *shapeTypes);
|
||||
teleporter->base.bytes[0x18] |= 4;
|
||||
teleporterKernel.terminateProcess(processId, teleporterGroupCounts);
|
||||
if (!teleported) {
|
||||
struct StartupContext {
|
||||
remorse::ProcessKernel& kernel;
|
||||
remorse::LiveFixedMapItems& items;
|
||||
const std::vector<remorse::ShapeTypeInfo>& shapes;
|
||||
remorse::u16 (&groupCounts)[32];
|
||||
bool& avatarInStasis;
|
||||
remorse::u16 mapNumber;
|
||||
bool teleported = false;
|
||||
bool valid = true;
|
||||
} startup{teleporterKernel, liveItems, *shapeTypes, teleporterGroupCounts,
|
||||
avatarInStasis, static_cast<remorse::u16>(state.mapIndex)};
|
||||
const auto runStartupProcess = [](remorse::EntityDispatchEntryBase& entry,
|
||||
void* opaque) {
|
||||
auto& context = *static_cast<StartupContext*>(opaque);
|
||||
const remorse::u16 processId = static_cast<remorse::u16>(entry.bytes[2] |
|
||||
(static_cast<remorse::u16>(entry.bytes[3]) << 8));
|
||||
if (processId < 3) return;
|
||||
const remorse::u16 vtable = static_cast<remorse::u16>(entry.bytes[0] |
|
||||
(static_cast<remorse::u16>(entry.bytes[1]) << 8));
|
||||
if (vtable == remorse::ClearAvatarInStasisProcess::vtableOffset) {
|
||||
context.valid = context.kernel.runClearAvatarInStasisProcess(processId,
|
||||
context.avatarInStasis, context.groupCounts);
|
||||
} else if (vtable == remorse::TeleporterProcess::vtableOffset) {
|
||||
const auto& teleporterProcess =
|
||||
*reinterpret_cast<remorse::TeleporterProcessEntry*>(&entry);
|
||||
context.teleported = remorse::TeleporterProcess::run(teleporterProcess,
|
||||
context.items, context.mapNumber, context.shapes);
|
||||
entry.bytes[0x18] |= 4;
|
||||
context.kernel.terminateProcess(processId, context.groupCounts);
|
||||
} else {
|
||||
context.valid = false;
|
||||
}
|
||||
};
|
||||
for (unsigned pass = 0; pass < 2 && teleporterKernel.processAt(processId) != nullptr;
|
||||
++pass) {
|
||||
teleporterKernel.scanRunnableProcesses(1, runStartupProcess, &startup);
|
||||
}
|
||||
if (!startup.valid || !startup.teleported || avatarInStasis ||
|
||||
teleporterKernel.processAt(processId) != nullptr) {
|
||||
setLoadFailure(state, L"The teleporter process could not resolve its map and egg destination.");
|
||||
PostMessageW(window, sceneReadyMessage, 0, 0);
|
||||
return;
|
||||
|
|
@ -968,6 +1012,7 @@ void updatePlayer(HWND window, AppState& state)
|
|||
runUsecodeTasks(state);
|
||||
const auto movement = state.controllerMovement.request();
|
||||
state.diagnosticKernel.deliverSystemTimerEvent();
|
||||
bool gravityMoved = false;
|
||||
if (state.diagnostics) {
|
||||
const bool wasSleeping = (state.diagnosticStand->base.bytes[0x19] & 0x10) != 0;
|
||||
const remorse::u32 previousSleepStart = standSleepStart(*state.diagnosticStand);
|
||||
|
|
@ -1016,8 +1061,13 @@ void updatePlayer(HWND window, AppState& state)
|
|||
if (wasSleeping && standSleepStart(*state.diagnosticStand) != previousSleepStart) {
|
||||
++state.standWakeCount;
|
||||
}
|
||||
} else if (state.liveItems) {
|
||||
gravityMoved = state.diagnosticKernel.scanResolvedGravity(
|
||||
state.diagnosticKernel.activeGroup(), *state.liveItems, state.shapeTypes,
|
||||
remorse::calculateFastAreaRange(avatarWorld(state)), 1,
|
||||
state.diagnosticKernel.systemTimerTick(), state.diagnosticGroupCounts) != 0;
|
||||
}
|
||||
changed = changed || state.diagnostics;
|
||||
changed = changed || state.diagnostics || gravityMoved;
|
||||
if (movement.animation == 0) {
|
||||
if (state.animationProcessId != 0) {
|
||||
auto* process = state.diagnosticKernel.processAt(state.animationProcessId);
|
||||
|
|
@ -1028,6 +1078,13 @@ void updatePlayer(HWND window, AppState& state)
|
|||
changed = changed || state.playerAnimation != 0 || state.playerFrame != 0;
|
||||
state.playerAnimation = 0;
|
||||
state.playerFrame = 0;
|
||||
const bool usecodeMutation = state.usecodeWorldMutationPending;
|
||||
state.usecodeWorldMutationPending = false;
|
||||
changed = changed || usecodeMutation;
|
||||
if (state.renderThread.joinable() && (gravityMoved || usecodeMutation)) {
|
||||
state.renderRequested = true;
|
||||
state.renderWake.notify_one();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -1078,7 +1135,7 @@ void updatePlayer(HWND window, AppState& state)
|
|||
*state.liveItems, *state.renderer, remorse::calculateFastAreaRange(avatarWorld(state)));
|
||||
const bool usecodeMutation = state.usecodeWorldMutationPending;
|
||||
state.usecodeWorldMutationPending = false;
|
||||
if (state.renderThread.joinable() && (moved || hatched || usecodeMutation)) {
|
||||
if (state.renderThread.joinable() && (moved || hatched || usecodeMutation || gravityMoved)) {
|
||||
state.renderRequested = true;
|
||||
state.renderWake.notify_one();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -180,6 +180,11 @@ int main()
|
|||
liveKernel.createProcess(1, liveGroups);
|
||||
}
|
||||
assert(!liveItems.findItem(0x106) && !liveItems.moveItem(0x106, 0, 0, 0));
|
||||
const auto originalShape = liveItems.findItem(0x100)->data.shape;
|
||||
assert(liveItems.setItemShape(0x100, 0x1234));
|
||||
assert(liveItems.findItem(0x100)->data.shape == 0x1234 && blockItems[0].data.shape == originalShape);
|
||||
assert(!liveItems.setItemShape(0x106, 0));
|
||||
assert(liveItems.setItemShape(0x100, originalShape));
|
||||
assert(!liveItems.moveItem(0x100, 0x8000, 0, 0));
|
||||
assert(liveItems.moveItem(0x100, 768, 511, 81));
|
||||
assert(liveItems.findItem(0x100)->data.x == 768 && blockItems[0].data.x == 511);
|
||||
|
|
|
|||
|
|
@ -250,14 +250,48 @@ int main()
|
|||
for (int reservedSlot = 0; reservedSlot < 3; ++reservedSlot) {
|
||||
teleporterKernel.createProcess(1, teleporterGroups);
|
||||
}
|
||||
auto* teleporterProcess = teleporterKernel.createTeleporterProcess(1, 1, 0x1e, teleporterGroups);
|
||||
bool avatarInStasis = false;
|
||||
auto* teleporterProcess = teleporterKernel.createTeleporterProcess(1, 1, 0x1e,
|
||||
teleporterGroups, true, false, avatarInStasis);
|
||||
const remorse::u16 teleporterProcessId = static_cast<remorse::u16>(
|
||||
teleporterProcess->base.bytes[2] | (static_cast<remorse::u16>(teleporterProcess->base.bytes[3]) << 8));
|
||||
assert(avatarInStasis && teleporterKernel.allocationSizeAt(4) == 0x33 &&
|
||||
teleporterKernel.processAt(4)->bytes[0] == 0x5e &&
|
||||
teleporterKernel.processAt(4)->bytes[1] == 0x0f);
|
||||
assert(!remorse::TeleporterProcess::run(*teleporterProcess, spawnSearchWorld, 2, *typeFlags));
|
||||
assert(spawnSearchWorld.findItem(1)->data.x == 0 && spawnSearchWorld.findItem(1)->data.y == 0);
|
||||
assert(remorse::TeleporterProcess::run(*teleporterProcess, spawnSearchWorld, 1, *typeFlags));
|
||||
teleporterProcess->base.bytes[0x18] |= 4;
|
||||
teleporterKernel.terminateProcess(teleporterProcessId, teleporterGroups);
|
||||
struct TeleporterPassContext {
|
||||
remorse::ProcessKernel& kernel;
|
||||
remorse::LiveFixedMapItems& items;
|
||||
const std::vector<remorse::ShapeTypeInfo>& shapes;
|
||||
remorse::u16 (&groupCounts)[32];
|
||||
bool& avatarInStasis;
|
||||
bool teleported = false;
|
||||
} teleporterPass{teleporterKernel, spawnSearchWorld, *typeFlags, teleporterGroups, avatarInStasis};
|
||||
const auto runTeleporterPass = [](remorse::EntityDispatchEntryBase& entry, void* opaque) {
|
||||
auto& context = *static_cast<TeleporterPassContext*>(opaque);
|
||||
const remorse::u16 processId = static_cast<remorse::u16>(entry.bytes[2] |
|
||||
(static_cast<remorse::u16>(entry.bytes[3]) << 8));
|
||||
if (processId < 3) return;
|
||||
const remorse::u16 vtable = static_cast<remorse::u16>(entry.bytes[0] |
|
||||
(static_cast<remorse::u16>(entry.bytes[1]) << 8));
|
||||
if (vtable == remorse::ClearAvatarInStasisProcess::vtableOffset) {
|
||||
assert(context.kernel.runClearAvatarInStasisProcess(processId,
|
||||
context.avatarInStasis, context.groupCounts));
|
||||
} else if (vtable == remorse::TeleporterProcess::vtableOffset) {
|
||||
const auto& process = *reinterpret_cast<remorse::TeleporterProcessEntry*>(&entry);
|
||||
context.teleported = remorse::TeleporterProcess::run(process, context.items, 1,
|
||||
context.shapes);
|
||||
entry.bytes[0x18] |= 4;
|
||||
context.kernel.terminateProcess(processId, context.groupCounts);
|
||||
}
|
||||
};
|
||||
teleporterKernel.scanRunnableProcesses(1, runTeleporterPass, &teleporterPass);
|
||||
assert(!avatarInStasis && !teleporterPass.teleported &&
|
||||
teleporterKernel.processAt(teleporterProcessId) == &teleporterProcess->base &&
|
||||
spawnSearchWorld.findItem(1)->data.x == 0 && spawnSearchWorld.findItem(1)->data.y == 0);
|
||||
teleporterKernel.scanRunnableProcesses(1, runTeleporterPass, &teleporterPass);
|
||||
assert(teleporterPass.teleported);
|
||||
assert(teleporterKernel.processAt(teleporterProcessId) == nullptr &&
|
||||
teleporterKernel.allocationSizeAt(teleporterProcessId) == 0 && teleporterGroups[1] == 3);
|
||||
assert(spawnEgg->recordIndex < fixedMap->entries.size());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue