This commit is contained in:
Nick Winter 2014-05-09 15:07:55 -07:00
commit df88be1ab1
4 changed files with 33 additions and 56 deletions

View file

@ -223,7 +223,7 @@ self.retrieveValueFromFrame = function retrieveValueFromFrame(args) {
var flowStates = self.debugWorld.userCodeMap[currentThangID][currentSpellID].flow.states; var flowStates = self.debugWorld.userCodeMap[currentThangID][currentSpellID].flow.states;
//we have to go to the second last flowState as we run the world for one additional frame //we have to go to the second last flowState as we run the world for one additional frame
//to collect the flow //to collect the flow
value = _.last(flowStates[flowStates.length - 2].statements).variables[prop]; value = _.last(flowStates[flowStates.length - 1].statements).variables[prop];
} }
catch (e) catch (e)
{ {
@ -260,11 +260,12 @@ self.retrieveValueFromFrame = function retrieveValueFromFrame(args) {
}; };
self.enableFlowOnThangSpell(args.currentThangID, args.currentSpellID, args.userCodeMap); self.enableFlowOnThangSpell(args.currentThangID, args.currentSpellID, args.userCodeMap);
self.setupDebugWorldToRunUntilFrame(args); self.setupDebugWorldToRunUntilFrame(args);
self.debugWorld.loadFramesUntilFrame( self.debugWorld.loadFrames(
args.frame,
retrieveProperty.bind({},args.currentThangID, args.currentSpellID, args.variableChain), retrieveProperty.bind({},args.currentThangID, args.currentSpellID, args.variableChain),
self.onDebugWorldError, self.onDebugWorldError,
self.onDebugWorldProgress self.onDebugWorldProgress,
false,
args.frame
); );
}; };
@ -297,8 +298,8 @@ self.setupDebugWorldToRunUntilFrame = function (args) {
var stringifiedUserCodeMap = JSON.stringify(args.userCodeMap); var stringifiedUserCodeMap = JSON.stringify(args.userCodeMap);
var userCodeMapHasChanged = ! _.isEqual(self.currentUserCodeMapCopy, stringifiedUserCodeMap); var userCodeMapHasChanged = ! _.isEqual(self.currentUserCodeMapCopy, stringifiedUserCodeMap);
self.currentUserCodeMapCopy = stringifiedUserCodeMap; self.currentUserCodeMapCopy = stringifiedUserCodeMap;
if (!self.debugWorld || userCodeMapHasChanged || args.frame != self.currentDebugWorldFrame) { if (args.frame != self.currentDebugWorldFrame) self.invalidateCache();
self.invalidateCache(); if (!self.debugWorld || userCodeMapHasChanged || args.frame < self.currentDebugWorldFrame) {
try { try {
self.debugWorld = new World(args.worldName, args.userCodeMap); self.debugWorld = new World(args.worldName, args.userCodeMap);
if (args.level) if (args.level)
@ -314,23 +315,18 @@ self.setupDebugWorldToRunUntilFrame = function (args) {
return; return;
} }
Math.random = self.debugWorld.rand.randf; // so user code is predictable Math.random = self.debugWorld.rand.randf; // so user code is predictable
self.debugWorld.totalFrames = args.frame; //hack to work around error checking
self.currentDebugWorldFrame = args.frame;
} }
self.debugWorld.totalFrames = args.frame; //hack to work around error checking
self.currentDebugWorldFrame = args.frame;
}; };
self.runDebugWorldUntilFrame = function (args) {
self.setupDebugWorldToRunUntilFrame(args);
self.debugWorld.loadFramesUntilFrame(args.frame, self.onDebugWorldLoaded, self.onDebugWorldError, self.onDebugWorldProgress);
};
self.onDebugWorldLoaded = function onDebugWorldLoaded() { self.onDebugWorldLoaded = function onDebugWorldLoaded() {
console.log("World loaded!"); console.log("World loaded!");
}; };
self.onDebugWorldError = function onDebugWorldError(error) { self.onDebugWorldError = function onDebugWorldError(error) {
if(!error.isUserCodeProblem) { if(!error.isUserCodeProblem) {
console.log("Debug Non-UserCodeError:", error.toString() + "\n" + error.stack || error.stackTrace); console.log("Debug Non-UserCodeError:", error.toString() + "\n" + error.stack || error.stackTrace);
} }

View file

@ -593,8 +593,6 @@ module.exports = Surface = class Surface extends CocoClass
@paths.parent.removeChild @paths @paths.parent.removeChild @paths
@paths = null @paths = null
# Screenshot
screenshot: (scale=0.25, format='image/jpeg', quality=0.8, zoom=2) -> screenshot: (scale=0.25, format='image/jpeg', quality=0.8, zoom=2) ->
# Quality doesn't work with image/png, just image/jpeg and image/webp # Quality doesn't work with image/png, just image/jpeg and image/webp
[w, h] = [@camera.canvasWidth, @camera.canvasHeight] [w, h] = [@camera.canvasWidth, @camera.canvasHeight]
@ -604,6 +602,5 @@ module.exports = Surface = class Surface extends CocoClass
#console.log "Screenshot with scale", scale, "format", format, "quality", quality, "was", Math.floor(imageData.length / 1024), "kB" #console.log "Screenshot with scale", scale, "format", format, "quality", quality, "was", Math.floor(imageData.length / 1024), "kB"
screenshot = document.createElement("img") screenshot = document.createElement("img")
screenshot.src = imageData screenshot.src = imageData
#$('body').append(screenshot)
@stage.uncache() @stage.uncache()
imageData imageData

View file

@ -71,14 +71,18 @@ module.exports = class World
(@runtimeErrors ?= []).push error (@runtimeErrors ?= []).push error
(@unhandledRuntimeErrors ?= []).push error (@unhandledRuntimeErrors ?= []).push error
loadFrames: (loadedCallback, errorCallback, loadProgressCallback, skipDeferredLoading) -> loadFrames: (loadedCallback, errorCallback, loadProgressCallback, skipDeferredLoading, loadUntilFrame) ->
return if @aborted return if @aborted
unless @thangs.length unless @thangs.length
console.log "Warning: loadFrames called on empty World (no thangs)." console.log "Warning: loadFrames called on empty World (no thangs)."
t1 = now() t1 = now()
@t0 ?= t1 @t0 ?= t1
if loadUntilFrame
frameToLoadUntil = loadUntilFrame + 1
else
frameToLoadUntil = @totalFrames
i = @frames.length i = @frames.length
while i < @totalFrames while i < frameToLoadUntil
try try
@getFrame(i) @getFrame(i)
++i # increment this after we have succeeded in getting the frame, otherwise we'll have to do that frame again ++i # increment this after we have succeeded in getting the frame, otherwise we'll have to do that frame again
@ -95,43 +99,19 @@ module.exports = class World
if t2 - @t0 > 1000 if t2 - @t0 > 1000
console.log(' Loaded', i, 'of', @totalFrames, "(+" + (t2 - @t0).toFixed(0) + "ms)") console.log(' Loaded', i, 'of', @totalFrames, "(+" + (t2 - @t0).toFixed(0) + "ms)")
@t0 = t2 @t0 = t2
continueFn = => @loadFrames(loadedCallback, errorCallback, loadProgressCallback, skipDeferredLoading) continueFn = =>
if loadUntilFrame
@loadFrames(loadedCallback,errorCallback,loadProgressCallback, skipDeferredLoading, loadUntilFrame)
else
@loadFrames(loadedCallback, errorCallback, loadProgressCallback, skipDeferredLoading)
if skipDeferredLoading if skipDeferredLoading
continueFn() continueFn()
else else
setTimeout(continueFn, 0) setTimeout(continueFn, 0)
return return
@ended = true unless loadUntilFrame
system.finish @thangs for system in @systems @ended = true
loadProgressCallback? 1 system.finish @thangs for system in @systems
loadedCallback()
loadFramesUntilFrame: (frameToLoadUntil, loadedCallback, errorCallback, loadProgressCallback) ->
return if @aborted
unless @thangs.length
console.log "Warning: loadFrames called on empty World"
t1 = now()
@t0 ?= t1
i = @frames.length
while i <= frameToLoadUntil #state is gathered at next frame
try
@getFrame(i)
++i # increment this after we have succeeded in getting the frame, otherwise we'll have to do that frame again
catch error
# Not an Aether.errors.UserCodeError; maybe we can't recover
@addError error
for error in (@unhandledRuntimeErrors ? [])
return unless errorCallback error # errorCallback tells us whether the error is recoverable
@unhandledRuntimeErrors = []
t2 = now()
if t2 - t1 > PROGRESS_UPDATE_INTERVAL
loadProgressCallback? i / @totalFrames
t1 = t2
if t2 - @t0 > 1000
console.log(' Loaded', i, 'of', frameToLoadUntil, "(+" + (t2 - @t0).toFixed(0) + "ms)")
@t0 = t2
setTimeout((=> @loadFrames(loadedCallback, errorCallback, loadProgressCallback)), 0)
return
loadProgressCallback? 1 loadProgressCallback? 1
loadedCallback() loadedCallback()

View file

@ -15,6 +15,7 @@ module.exports = class DebugView extends View
'god:new-world-created': 'onNewWorld' 'god:new-world-created': 'onNewWorld'
'god:debug-value-return': 'handleDebugValue' 'god:debug-value-return': 'handleDebugValue'
'tome:spell-shown': 'changeCurrentThangAndSpell' 'tome:spell-shown': 'changeCurrentThangAndSpell'
'surface:frame-changed': 'onFrameChanged'
events: {} events: {}
@ -24,7 +25,6 @@ module.exports = class DebugView extends View
@thang = options.thang @thang = options.thang
@spell = options.spell @spell = options.spell
@variableStates = {} @variableStates = {}
@globals = {Math: Math, _: _, String: String, Number: Number, Array: Array, Object: Object} # ... add more as documented @globals = {Math: Math, _: _, String: String, Number: Number, Array: Array, Object: Object} # ... add more as documented
for className, serializedClass of serializedClasses for className, serializedClass of serializedClasses
@globals[className] = serializedClass @globals[className] = serializedClass
@ -94,12 +94,16 @@ module.exports = class DebugView extends View
onNewWorld: (e) -> onNewWorld: (e) ->
@thang = @options.thang = e.world.thangMap[@thang.id] if @thang @thang = @options.thang = e.world.thangMap[@thang.id] if @thang
onFrameChanged: (data) ->
@currentFrame = data.frame
update: -> update: ->
if @variableChain if @variableChain
Backbone.Mediator.publish 'tome:spell-debug-value-request', Backbone.Mediator.publish 'tome:spell-debug-value-request',
thangID: @thang.id thangID: @thang.id
spellID: @spell.name spellID: @spell.name
variableChain: @variableChain variableChain: @variableChain
frame: @currentFrame
@$el.find("code").text "Finding value..." @$el.find("code").text "Finding value..."
@$el.show().css(@pos) @$el.show().css(@pos)
else else