Skip to content

Commit 228e8ca

Browse files
committed
Implement pointer lock support for DingusPPC
Makes it easier to use the mouse (until support for passing in absolute coordinates is implemented). Updates #219
1 parent fa99e64 commit 228e8ca

File tree

6 files changed

+53
-19
lines changed

6 files changed

+53
-19
lines changed

dingusppc

src/emulator/dingusppc.js

Lines changed: 18 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/emulator/dingusppc.wasm

-8.8 KB
Binary file not shown.

src/emulator/emulator-common-emulators.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ export function emulatorSupportsAppleTalk(type: EmulatorType): boolean {
3838
return type === "BasiliskII" || type === "SheepShaver";
3939
}
4040

41+
export function emulatorNeedsPointerLock(type: EmulatorType): boolean {
42+
return type === "DingusPPC";
43+
}
44+
4145
export function emulatorCpuId(
4246
type: EmulatorType,
4347
cpu: EmulatorCpu

src/emulator/emulator-ui.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
emulatorUsesCDROMDrive,
1515
emulatorUsesPrefs,
1616
emulatorUsesArgs,
17+
emulatorNeedsPointerLock,
1718
} from "./emulator-common-emulators";
1819
import {getEmulatorWasmPath} from "./emulator-ui-emulators";
1920
import Worker from "./emulator-worker?worker";
@@ -153,6 +154,8 @@ export class Emulator {
153154
// some edge cases.
154155
#downKeyCodes = new Set<string>();
155156

157+
#requestedPointerLock = false;
158+
156159
constructor(config: EmulatorConfig, delegate?: EmulatorDelegate) {
157160
console.time("Emulator first blit");
158161
console.time("Emulator quiescent");
@@ -253,6 +256,10 @@ export class Emulator {
253256
"visibilitychange",
254257
this.#handleVisibilityChange
255258
);
259+
document.addEventListener(
260+
"pointerlockchange",
261+
this.#handlePointerLockChange
262+
);
256263

257264
await this.#startWorker();
258265
}
@@ -383,6 +390,10 @@ export class Emulator {
383390
"visibilitychange",
384391
this.#handleVisibilityChange
385392
);
393+
document.addEventListener(
394+
"pointerlockchange",
395+
this.#handlePointerLockChange
396+
);
386397

387398
this.#input.handleInput({type: "stop"});
388399
this.#ethernetPinger.stop();
@@ -444,6 +455,21 @@ export class Emulator {
444455

445456
#handleMouseDown = (event: MouseEvent) => {
446457
this.#input.handleInput({type: "mousedown"});
458+
if (
459+
emulatorNeedsPointerLock(this.#config.machine.emulatorType) &&
460+
!this.#requestedPointerLock
461+
) {
462+
this.#config.screenCanvas.requestPointerLock({
463+
unadjustedMovement: true,
464+
});
465+
this.#requestedPointerLock = true;
466+
}
467+
};
468+
469+
#handlePointerLockChange = (event: Event): void => {
470+
if (!document.pointerLockElement) {
471+
this.#requestedPointerLock = false;
472+
}
447473
};
448474

449475
#handleMouseUp = (event: MouseEvent) => {

src/vite-env.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ interface Document {
3535
webkitFullscreenElement?: HTMLElement;
3636
}
3737

38+
interface Element {
39+
requestPointerLock(options?: {unadjustedMovement?: boolean}): void;
40+
}
41+
3842
interface HTMLElement {
3943
webkitRequestFullscreen?: () => Promise<void>;
4044
}

0 commit comments

Comments
 (0)