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
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue