Skip to content

Commit

Permalink
chores: MD settings, no recompile module on init
Browse files Browse the repository at this point in the history
- Settings for Mega Drive were missing from the API
- Compile the module on the first initialize only; recreating a new
  binary is costly, and likely will consume a lot more memory than
  needed.
  • Loading branch information
stelcheck committed Mar 25, 2021
1 parent 6061efe commit 0084288
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 13 deletions.
14 changes: 14 additions & 0 deletions higan/target-web/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,20 @@ export const Settings: SettingsEntries = {
*/
SyncOnce: 'cpu/synconce'
}
},
[Emulator.MegaDrive]: {
PPU: {
/**
* Skip frame. When enabled, skip the rendering of half the frames, which
* may provide slighgtly better performance.
*/
Skipframe: 'ppu/skipframe',
/**
* Skip DMA execution when the DMA is inactive or disabled. Off by default, as
* it can break a number of games.
*/
OptimizeSteps: 'vdp/optimizeSteps'
}
}
}

Expand Down
42 changes: 29 additions & 13 deletions higan/target-web/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const EmulatorEvent = {
}

export const Settings = {
['Super Famicom']: {
[Emulator.SuperFamicom]: {
CPU: {
Lockstep: 'cpu/lockstep',
Fastmath: 'cpu/fastmath',
Expand All @@ -28,14 +28,20 @@ export const Settings = {
Skipframe: 'ppu/skipframe'
}
},
['Famicom']: {
[Emulator.Famicom]: {
PPU: {
Skipframe: 'ppu/skipframe',
Overscan: 'ppu/overscan'
},
CPU: {
SyncOnce: 'cpu/synconce'
}
},
[Emulator.MegaDrive]: {
PPU: {
Skipframe: 'ppu/skipframe',
OptimizeSteps: 'vdp/optimizeSteps'
}
}
}

Expand Down Expand Up @@ -132,6 +138,26 @@ byuu.initialize = async function (parent, ctxOptions) {
throw new Error('The DOM ID attribute "canvas" is reserved by byuu for it\'s own canvas')
}

function finalize() {
lib.initialize(document.title || 'byuu')

// Set callbacks, patch into event emission
lib.onFrameStart(() => byuu.emit('frame.start'))
lib.onFrameEnd(() => byuu.emit('frame.end'))
lib.onResize((width, height) => {
byuu.displayRatio = width / height;
byuu.emit('resize', { width, height });
})

initialized = true
}

// If the module was initialized at least once, do not reload;
// immediately complete the initialization steps, and return;
if (initialized) {
return finalize();
}

return new Promise((resolve) => {
// Module isn't a real promise, and unless we set
// things as follow the code seem to tight-loop
Expand All @@ -146,17 +172,7 @@ byuu.initialize = async function (parent, ctxOptions) {
canvas
}).then((result) => {
lib = result
lib.initialize(document.title || 'byuu')

// Set callbacks, patch into event emission
lib.onFrameStart(() => byuu.emit('frame.start'))
lib.onFrameEnd(() => byuu.emit('frame.end'))
lib.onResize((width, height) => {
byuu.displayRatio = width / height;
byuu.emit('resize', { width, height });
})

initialized = true
finalize()
resolve()
})
})
Expand Down

0 comments on commit 0084288

Please sign in to comment.