Add effective simulation frames per second to verifier

This commit is contained in:
Nick Winter 2016-06-29 12:40:30 -07:00
parent 50a017b1e9
commit ede12ed50f
5 changed files with 33 additions and 18 deletions

View file

@ -428,17 +428,18 @@ self.onWorldLoaded = function onWorldLoaded() {
if(self.world.framesSerializedSoFar == self.world.frames.length) return;
if(self.world.ended)
self.goalManager.worldGenerationEnded();
var goalStates = self.goalManager.getGoalStates();
var overallStatus = self.goalManager.checkOverallStatus();
var totalFrames = self.world.totalFrames;
if(self.world.ended) {
var lastFrameHash = self.world.frames[totalFrames - 2].hash
self.postMessage({type: 'end-load-frames', goalStates: goalStates, overallStatus: overallStatus, totalFrames: totalFrames, lastFrameHash: lastFrameHash});
}
var t1 = new Date();
var diff = t1 - self.t0;
if(self.world.headless)
return console.log('Headless simulation completed in ' + diff + 'ms.');
var goalStates = self.goalManager.getGoalStates();
var totalFrames = self.world.totalFrames;
if(self.world.ended) {
var overallStatus = self.goalManager.checkOverallStatus();
var lastFrameHash = self.world.frames[totalFrames - 2].hash
var simulationFrameRate = self.world.frames.length / diff * 1000 * 30 / self.world.frameRate
self.postMessage({type: 'end-load-frames', goalStates: goalStates, overallStatus: overallStatus, totalFrames: totalFrames, lastFrameHash: lastFrameHash, simulationFrameRate: simulationFrameRate});
if(self.world.headless)
return console.log('Headless simulation completed in ' + diff + 'ms, ' + simulationFrameRate.toFixed(1) + ' FPS.');
}
var worldEnded = self.world.ended;
var serialized;
@ -469,7 +470,7 @@ self.onWorldLoaded = function onWorldLoaded() {
if(worldEnded) {
var t3 = new Date();
console.log("And it was so: (" + (diff / totalFrames).toFixed(3) + "ms per frame,", totalFrames, "frames)\nSimulation :", diff + "ms \nSerialization:", (t2 - t1) + "ms\nDelivery :", (t3 - t2) + "ms");
console.log("And it was so: (" + (diff / totalFrames).toFixed(3) + "ms per frame,", totalFrames, "frames)\nSimulation :", diff + "ms \nSerialization:", (t2 - t1) + "ms\nDelivery :", (t3 - t2) + "ms\nFPS :", simulationFrameRate.toFixed(1));
}
};
@ -483,7 +484,10 @@ self.onWorldPreloaded = function onWorldPreloaded() {
self.goalManager.worldGenerationEnded();
var goalStates = self.goalManager.getGoalStates();
var overallStatus = self.goalManager.checkOverallStatus();
self.postMessage({type: 'end-preload-frames', goalStates: goalStates, overallStatus: overallStatus});
var t1 = new Date();
var diff = t1 - self.t0;
var simulationFrameRate = self.world.frames.length / diff * 1000 * 30 / self.world.frameRate
self.postMessage({type: 'end-preload-frames', goalStates: goalStates, overallStatus: overallStatus, simulationFrameRate: simulationFrameRate});
};
self.onWorldError = function onWorldError(error) {

View file

@ -82,11 +82,10 @@ module.exports = class Angel extends CocoClass
clearTimeout @condemnTimeout
when 'end-load-frames'
clearTimeout @condemnTimeout
@beholdGoalStates event.data.goalStates, event.data.overallStatus, false, event.data.totalFrames, event.data.lastFrameHash # Work ends here if we're headless.
@beholdGoalStates {goalStates: event.data.goalStates, overallStatus: event.data.overallStatus, preload: false, totalFrames: event.data.totalFrames, lastFrameHash: event.data.lastFrameHash, simulationFrameRate: event.data.simulationFrameRate} # Work ends here if we're headless.
when 'end-preload-frames'
clearTimeout @condemnTimeout
@beholdGoalStates event.data.goalStates, event.data.overallStatus, true
@beholdGoalStates {goalStates: event.data.goalStates, overallStatus: event.data.overallStatus, preload: true, simulationFrameRate: event.data.simulationFrameRate}
# We have to abort like an infinite loop if we see one of these; they're not really recoverable
when 'non-user-code-problem'
@ -125,11 +124,12 @@ module.exports = class Angel extends CocoClass
else
@log 'Received unsupported message:', event.data
beholdGoalStates: (goalStates, overallStatus, preload=false, totalFrames=undefined, lastFrameHash=undefined) ->
beholdGoalStates: ({goalStates, overallStatus, preload, totalFrames, lastFrameHash, simulationFrameRate}) ->
return if @aborting
event = goalStates: goalStates, preload: preload, overallStatus: overallStatus
event = goalStates: goalStates, preload: preload ? false, overallStatus: overallStatus
event.totalFrames = totalFrames if totalFrames?
event.lastFrameHash = lastFrameHash if lastFrameHash?
event.simulationFrameRate = simulationFrameRate if simulationFrameRate?
@publishGodEvent 'goals-calculated', event
@finishWork() if @shared.headless
@ -306,7 +306,8 @@ module.exports = class Angel extends CocoClass
work.world.goalManager.worldGenerationEnded() if work.world.ended
if work.headless
@beholdGoalStates goalStates, testGM.checkOverallStatus(), false, work.world.totalFrames, work.world.frames[work.world.totalFrames - 2]?.hash
simulationFrameRate = work.world.frames.length / (work.t2 - work.t1) * 1000 * 30 / work.world.frameRate
@beholdGoalStates {goalStates, overallStatus: testGM.checkOverallStatus(), preload: false, totalFrames: work.world.totalFrames, lastFrameHash: work.world.frames[work.world.totalFrames - 2]?.hash, simulationFrameRate: simulationFrameRate}
return
serialized = world.serialize()

View file

@ -52,6 +52,7 @@ module.exports =
overallStatus: {type: ['string', 'null'], enum: ['success', 'failure', 'incomplete', null]}
totalFrames: {type: ['integer', 'undefined']}
lastFrameHash: {type: ['number', 'undefined']}
simulationFrameRate: {type: ['number', 'undefined']}
'god:world-load-progress-changed': c.object {required: ['progress', 'god']},
god: {type: 'object'}

View file

@ -105,6 +105,14 @@ block content
h4.test-failed User Code Problems
pre.test-failed #{JSON.stringify(test.userCodeProblems, null, 2)}
if test.simulationFrameRate
if test.simulationFrameRate > 90
div.test-success ✓ #{test.simulationFrameRate.toFixed(1)} FPS
else if test.simulationFrameRate > 30
div.test-running ~ #{test.simulationFrameRate.toFixed(1)} FPS
else
div.test-failed ✘ #{test.simulationFrameRate.toFixed(1)} FPS
else
h1 Loading Level...

View file

@ -81,10 +81,10 @@ module.exports = class VerifierTest extends CocoClass
@updateCallback? state: 'running'
processSingleGameResults: (e) ->
console.log(e)
@goals = e.goalStates
@frames = e.totalFrames
@lastFrameHash = e.lastFrameHash
@simulationFrameRate = e.simulationFrameRate
@state = 'complete'
@updateCallback? state: @state
@scheduleCleanup()
@ -92,6 +92,7 @@ module.exports = class VerifierTest extends CocoClass
isSuccessful: () ->
return false unless @solution?
return false unless @frames == @solution.frameCount or @options.dontCareAboutFrames
return false if @simulationFrameRate < 30
if @goals and @solution.goals
for k of @goals
continue if not @solution.goals[k]