Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prueba: mover flushEvents al frontend #140

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions public/game/sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var cellPixelSize
var images = new Array()
var visuals = new Array()
var sounds = new Map()
const fps = 10

function preload() {
loadAllImages()
Expand All @@ -30,10 +31,14 @@ function setup() {
})
loadBackground()
loadVisuals()
frameRate(fps);
socket.emit("ready")

}

function draw() {
console.log("draw")
socket.emit("flushEvents", 1000/fps)
clear()
if (backgroundImage) background(backgroundImage)
drawVisuals()
Expand Down Expand Up @@ -78,6 +83,7 @@ function loadAllImages() {

function loadVisuals() {
socket.on("visuals", (visualsList) => {
console.log("visuals")
visuals = visualsList
})
}
Expand Down
28 changes: 26 additions & 2 deletions src/commands/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,32 @@
socket.emit('sizeCanvasInic', [sizeCanvas.width, sizeCanvas.height])
socket.emit('cellPixelSize', gameSingleton.get('cellSize')!.innerNumber!)
socket.emit('background', background)
interpreter.send('flushEvents', gameSingleton, interpreter.reify(100))

Check warning on line 210 in src/commands/run.ts

View check run for this annotation

Codecov / codecov/patch

src/commands/run.ts#L210

Added line #L210 was not covered by tests

})

socket.on('flushEvents', time => {
try {
const tsInicio = performance.now()
timer += time
interpreter.send('flushEvents', gameSingleton, interpreter.reify(timer))

Check warning on line 218 in src/commands/run.ts

View check run for this annotation

Codecov / codecov/patch

src/commands/run.ts#L214-L218

Added lines #L214 - L218 were not covered by tests
// We could pass the interpreter but a program does not change it
dynamicDiagramClient.onReload()
const tsFin = performance.now()
if(tsFin - tsInicio > time) {
logger.warn(failureDescription(`flushEvents took ${(tsFin - tsInicio).toFixed(2)} ms`))

Check warning on line 223 in src/commands/run.ts

View check run for this annotation

Codecov / codecov/patch

src/commands/run.ts#L220-L223

Added lines #L220 - L223 were not covered by tests
}

if (!gameSingleton.get('running')?.innerBoolean) {
process.exit(0)

Check warning on line 227 in src/commands/run.ts

View check run for this annotation

Codecov / codecov/patch

src/commands/run.ts#L226-L227

Added lines #L226 - L227 were not covered by tests
}
} catch (error: any) {
interpreter.send('stop', gameSingleton)
socket.emit('errorDetected', error.message)

Check warning on line 231 in src/commands/run.ts

View check run for this annotation

Codecov / codecov/patch

src/commands/run.ts#L230-L231

Added lines #L230 - L231 were not covered by tests
}
})

Check warning on line 233 in src/commands/run.ts

View workflow job for this annotation

GitHub Actions / test

Expected indentation of 4 spaces but found 2

/*

Check warning on line 235 in src/commands/run.ts

View workflow job for this annotation

GitHub Actions / test

Expected indentation of 4 spaces but found 0
const flushInterval = 100
const id = setInterval(() => {
try {
Expand All @@ -226,9 +250,9 @@
clearInterval(id)
}
}, flushInterval)

*/
socket.on('disconnect', () => {
clearInterval(id)
// clearInterval(id)
logger.info(successDescription('Game finished'))
})

Expand Down
Loading