mirror of
https://github.com/DaanVandenBosch/phantasmal-world.git
synced 2025-04-05 15:28:29 +08:00
Breakpoints now cause VM to pause.
This commit is contained in:
parent
144e9513ac
commit
90ad66e96d
@ -3,6 +3,7 @@ import { QuestModel } from "./model/QuestModel";
|
||||
import { VirtualMachineIO } from "./scripting/vm/io";
|
||||
import { AsmToken } from "./scripting/instructions";
|
||||
import { quest_editor_store } from "./stores/QuestEditorStore";
|
||||
import { asm_editor_store } from "./stores/AsmEditorStore";
|
||||
|
||||
const logger = quest_editor_store.get_logger("quest_editor/QuestRunner");
|
||||
|
||||
@ -34,29 +35,34 @@ export class QuestRunner {
|
||||
}
|
||||
|
||||
private execution_loop = (): void => {
|
||||
this.vm.vsync();
|
||||
|
||||
let result: ExecutionResult;
|
||||
|
||||
do {
|
||||
exec_loop:
|
||||
while (true) {
|
||||
result = this.vm.execute();
|
||||
} while (result == ExecutionResult.Ok);
|
||||
|
||||
switch (result) {
|
||||
case ExecutionResult.WaitingVsync:
|
||||
this.schedule_frame();
|
||||
break;
|
||||
case ExecutionResult.WaitingInput:
|
||||
// TODO: implement input from gui
|
||||
this.schedule_frame();
|
||||
break;
|
||||
case ExecutionResult.WaitingSelection:
|
||||
// TODO: implement input from gui
|
||||
this.vm.list_select(0);
|
||||
this.schedule_frame();
|
||||
break;
|
||||
case ExecutionResult.Halted:
|
||||
break;
|
||||
const srcloc = this.vm.get_current_source_location();
|
||||
if (srcloc && asm_editor_store.breakpoints.val.includes(srcloc.line_no)) {
|
||||
break exec_loop;
|
||||
}
|
||||
|
||||
switch (result) {
|
||||
case ExecutionResult.WaitingVsync:
|
||||
this.vm.vsync();
|
||||
this.schedule_frame();
|
||||
break;
|
||||
case ExecutionResult.WaitingInput:
|
||||
// TODO: implement input from gui
|
||||
this.schedule_frame();
|
||||
break;
|
||||
case ExecutionResult.WaitingSelection:
|
||||
// TODO: implement input from gui
|
||||
this.vm.list_select(0);
|
||||
this.schedule_frame();
|
||||
break;
|
||||
case ExecutionResult.Halted:
|
||||
break exec_loop;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -158,6 +158,7 @@ export class VirtualMachine {
|
||||
private set_episode_called = false;
|
||||
private list_open = false;
|
||||
private selection_reg = 0;
|
||||
private cur_srcloc?: AsmToken;
|
||||
|
||||
constructor(private io: VirtualMachineIO = new VMIOStub()) {
|
||||
srand(GetTickCount());
|
||||
@ -187,6 +188,7 @@ export class VirtualMachine {
|
||||
this.set_episode_called = false;
|
||||
this.list_open = false;
|
||||
this.selection_reg = 0;
|
||||
this.cur_srcloc = undefined;
|
||||
|
||||
let i = 0;
|
||||
|
||||
@ -239,7 +241,10 @@ export class VirtualMachine {
|
||||
execute(): ExecutionResult {
|
||||
let srcloc: AsmToken | undefined;
|
||||
|
||||
if (this.thread.length === 0) return ExecutionResult.Halted;
|
||||
if (this.thread.length === 0) {
|
||||
this.cur_srcloc = undefined;
|
||||
return ExecutionResult.Halted
|
||||
}
|
||||
|
||||
try {
|
||||
const exec = this.thread[this.thread_idx];
|
||||
@ -249,6 +254,8 @@ export class VirtualMachine {
|
||||
srcloc = inst.asm.mnemonic;
|
||||
}
|
||||
|
||||
this.cur_srcloc = srcloc;
|
||||
|
||||
return this.execute_instruction(exec, inst, srcloc);
|
||||
} catch (err) {
|
||||
if (!(err instanceof Error)) {
|
||||
@ -1141,6 +1148,10 @@ export class VirtualMachine {
|
||||
|
||||
return template;
|
||||
}
|
||||
|
||||
public get_current_source_location(): AsmToken | undefined {
|
||||
return this.cur_srcloc;
|
||||
}
|
||||
}
|
||||
|
||||
class ExecutionLocation {
|
||||
|
Loading…
Reference in New Issue
Block a user