Skip to content

Commit

Permalink
Fix RaylibJsWorker
Browse files Browse the repository at this point in the history
  • Loading branch information
x0k committed Feb 25, 2024
1 parent 6789fa6 commit 8e3ff99
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 77 deletions.
7 changes: 5 additions & 2 deletions raylib.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,14 @@ export class RaylibJsBase {
if (transition === undefined) {
return
}
const stateChange = transition.target !== undefined
if (stateChange) {
this.state = transition.target
}
transition?.action(event)
if (transition.target === undefined) {
if (!stateChange) {
return
}
this.state = transition.target
for (const handler of this.subscribers) {
handler(this.state)
}
Expand Down
14 changes: 9 additions & 5 deletions raylib_factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ export const EVENT_TYPE = {

export class BlockingRaylibJs extends RaylibJsBase {

pullEvents = () => {
this.eventsQueue.pop(this.send)
requestAnimationFrame(this.pullEvents)
}

onStarted(params) {
cancelAnimationFrame(this.eventsPullId)
this.previous = performance.now()
super.onStarted(params)
this.send({ type: EVENT_TYPE.STOPPED })
Expand All @@ -27,6 +33,7 @@ export class BlockingRaylibJs extends RaylibJsBase {
onStopped() {
super.onStop()
this.windowShouldClose = false
this.eventsPullId = requestAnimationFrame(this.pullEvents)
}

constructor({ ctx, platform, eventsQueue }) {
Expand All @@ -51,7 +58,7 @@ export class BlockingRaylibJs extends RaylibJsBase {
}
}
this.send = this.send.bind(this)
this.eventsQueue.waitAndPop(this.send)
this.eventsPullId = requestAnimationFrame(this.pullEvents)
}

SetTargetFPS(fps) {
Expand All @@ -63,10 +70,7 @@ export class BlockingRaylibJs extends RaylibJsBase {
return this.windowShouldClose
}

CloseWindow() {
super.stop()
this.windowShouldClose = false
}
CloseWindow() {}

BeginDrawing() {
this.eventsQueue.pop(this.send)
Expand Down
Loading

0 comments on commit 8e3ff99

Please sign in to comment.