Skip to content
This repository has been archived by the owner on Nov 12, 2024. It is now read-only.

Commit

Permalink
rm global err hand
Browse files Browse the repository at this point in the history
  • Loading branch information
slmjkdbtl committed Oct 17, 2023
1 parent fbc6136 commit b27df21
Showing 1 changed file with 28 additions and 46 deletions.
74 changes: 28 additions & 46 deletions src/kaboom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2430,8 +2430,6 @@ export default (gopt: KaboomOpt = {}): KaboomCtx => {
return gfx.height
}

const winEvents: EventList<WindowEventMap> = {}

// transform a point from window space to content space
function windowToContent(pt: Vec2) {
return new Vec2(
Expand All @@ -2452,24 +2450,6 @@ export default (gopt: KaboomOpt = {}): KaboomCtx => {
return windowToContent(app.mousePos())
}

winEvents.error = (e) => {
if (e.error && e.error instanceof Error) {
handleErr(e.error)
} else if (e instanceof Error) {
handleErr(e)
}
}

winEvents.unhandledrejection = (e) => {
if (e.reason instanceof Error) {
handleErr(e.reason)
}
}

for (const name in winEvents) {
window.addEventListener(name, winEvents[name])
}

let debugPaused = false

const debug: Debug = {
Expand Down Expand Up @@ -6044,10 +6024,6 @@ export default (gopt: KaboomOpt = {}): KaboomCtx => {

app.quit()

for (const name in winEvents) {
window.removeEventListener(name, winEvents[name])
}

// clear canvas
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT)

Expand Down Expand Up @@ -6078,32 +6054,38 @@ export default (gopt: KaboomOpt = {}): KaboomCtx => {
// main game loop
app.run(() => {

if (!assets.loaded) {
if (loadProgress() === 1 && !isFirstFrame) {
assets.loaded = true
game.events.trigger("load")
try {

if (!assets.loaded) {
if (loadProgress() === 1 && !isFirstFrame) {
assets.loaded = true
game.events.trigger("load")
}
}
}

if (!assets.loaded && gopt.loadingScreen !== false || isFirstFrame) {
frameStart()
// TODO: Currently if assets are not initially loaded no updates or timers will be run, however they will run if loadingScreen is set to false. What's the desired behavior or should we make them consistent?
drawLoadScreen()
frameEnd()
} else {
if (!debug.paused) updateFrame()
checkFrame()
frameStart()
drawFrame()
if (gopt.debug !== false) drawDebug()
frameEnd()
}
if (!assets.loaded && gopt.loadingScreen !== false || isFirstFrame) {
frameStart()
// TODO: Currently if assets are not initially loaded no updates or timers will be run, however they will run if loadingScreen is set to false. What's the desired behavior or should we make them consistent?
drawLoadScreen()
frameEnd()
} else {
if (!debug.paused) updateFrame()
checkFrame()
frameStart()
drawFrame()
if (gopt.debug !== false) drawDebug()
frameEnd()
}

if (isFirstFrame) {
isFirstFrame = false
}
if (isFirstFrame) {
isFirstFrame = false
}

game.events.trigger("frameEnd")

game.events.trigger("frameEnd")
} catch (e) {
handleErr(e)
}

})

Expand Down

0 comments on commit b27df21

Please sign in to comment.