mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-02-17 08:50:58 -05:00
World streaming is getting there!
This commit is contained in:
parent
611ecbf470
commit
92f0a68dd1
6 changed files with 13 additions and 10 deletions
|
@ -366,7 +366,7 @@ self.runWorld = function runWorld(args) {
|
|||
};
|
||||
|
||||
self.serializeFramesSoFar = function serializeFramesSoFar() {
|
||||
if(!self.world) return console.error("hmm, no world when we went to serialize some frames?");
|
||||
if(!self.world) return; // We probably got this message late, after delivering the world.
|
||||
if(self.world.framesSerializedSoFar == self.world.frames.length) return;
|
||||
self.onWorldLoaded();
|
||||
self.world.framesSerializedSoFar = self.world.frames.length;
|
||||
|
|
|
@ -93,7 +93,7 @@ module.exports = class Angel extends CocoClass
|
|||
|
||||
# We have some or all of the frames serialized, so let's send the (partially?) simulated world to the Surface.
|
||||
when 'some-frames-serialized', 'new-world'
|
||||
deserializationArgs = [event.data.serialized, event.data.goalStates, event.data.startFrame, event.data.endFrame, @shared.streamingWorld]
|
||||
deserializationArgs = [event.data.serialized, event.data.goalStates, event.data.startFrame, event.data.endFrame, @streamingWorld]
|
||||
@deserializationQueue.push deserializationArgs
|
||||
if @deserializationQueue.length is 1
|
||||
@beholdWorld deserializationArgs...
|
||||
|
@ -116,7 +116,7 @@ module.exports = class Angel extends CocoClass
|
|||
|
||||
finishBeholdingWorld: (goalStates) -> (world) =>
|
||||
return if @aborting
|
||||
@shared.streamingWorld = world
|
||||
@streamingWorld = world
|
||||
finished = world.frames.length is world.totalFrames
|
||||
firstChangedFrame = world.findFirstChangedFrame @shared.world
|
||||
eventType = if finished then 'god:new-world-created' else 'god:streaming-world-updated'
|
||||
|
@ -134,7 +134,7 @@ module.exports = class Angel extends CocoClass
|
|||
@beholdWorld deserializationArgs...
|
||||
|
||||
finishWork: ->
|
||||
@shared.streamingWorld = null
|
||||
@streamingWorld = null
|
||||
@shared.firstWorld = false
|
||||
@deserializationQueue = []
|
||||
@running = false
|
||||
|
@ -177,6 +177,8 @@ module.exports = class Angel extends CocoClass
|
|||
@say 'Aborting...'
|
||||
@running = false
|
||||
@work = null
|
||||
@streamingWorld = null
|
||||
@deserializationQueue = null
|
||||
_.remove @shared.busyAngels, @
|
||||
@abortTimeout = _.delay @fireWorker, @abortTimeoutDuration
|
||||
@aborting = true
|
||||
|
|
|
@ -246,7 +246,7 @@ module.exports = Surface = class Surface extends CocoClass
|
|||
getCurrentFrame: ->
|
||||
return Math.max(0, Math.min(Math.floor(@currentFrame), @world.frames.length - 1))
|
||||
|
||||
getProgress: -> @currentFrame / @world.totalFrames
|
||||
getProgress: -> @currentFrame / @world.frames.length
|
||||
|
||||
onLevelRestarted: (e) ->
|
||||
@setProgress 0, 0
|
||||
|
|
|
@ -94,7 +94,7 @@ module.exports = class World
|
|||
else
|
||||
frameToLoadUntil = @totalFrames
|
||||
i = @frames.length
|
||||
while i < frameToLoadUntil
|
||||
while i < frameToLoadUntil and i < @totalFrames
|
||||
if @debugging
|
||||
for thang in @thangs when thang.isProgrammable
|
||||
userCode = @userCodeMap[thang.id] ? {}
|
||||
|
@ -291,7 +291,7 @@ module.exports = class World
|
|||
# Code hotspot; optimize it
|
||||
startFrame = @framesSerializedSoFar
|
||||
endFrame = @frames.length
|
||||
#console.log "... world serializing frames from", startFrame, "to", endFrame
|
||||
#console.log "... world serializing frames from", startFrame, "to", endFrame, "of", @totalFrames
|
||||
[transferableObjects, nontransferableObjects] = [0, 0]
|
||||
o = {totalFrames: @totalFrames, maxTotalFrames: @maxTotalFrames, frameRate: @frameRate, dt: @dt, victory: @victory, userCodeMap: {}, trackedProperties: {}}
|
||||
o.trackedProperties[prop] = @[prop] for prop in @trackedProperties or []
|
||||
|
|
|
@ -70,6 +70,8 @@ module.exports = class LevelHUDView extends CocoView
|
|||
@thang = e.world.thangMap[@thang.id] if @thang
|
||||
if hadThang and not @thang
|
||||
@setThang null, null
|
||||
else if @thang
|
||||
@createActions() # Make sure it updates its actions.
|
||||
|
||||
setThang: (thang, thangType) ->
|
||||
unless @speaker
|
||||
|
|
|
@ -150,8 +150,7 @@ module.exports = class LevelPlaybackView extends CocoView
|
|||
@barWidth = $('.progress', @$el).width()
|
||||
|
||||
onNewWorld: (e) ->
|
||||
@totalLoadedTime = e.world.frames.length * e.world.dt
|
||||
@totalTime = e.world.totalFrames * e.world.dt
|
||||
@totalTime = e.world.frames.length * e.world.dt
|
||||
pct = parseInt(100 * e.world.frames.length / e.world.maxTotalFrames) + '%'
|
||||
@barWidth = $('.progress', @$el).css('width', pct).show().width()
|
||||
$('.scrubber .progress', @$el).slider('enable', true)
|
||||
|
@ -273,7 +272,7 @@ module.exports = class LevelPlaybackView extends CocoView
|
|||
@timePopup.show()
|
||||
|
||||
updateProgress: (progress) ->
|
||||
$('.scrubber .progress-bar', @$el).css('width', "#{progress * 100 * @totalTime / @totalLoadedTime}%")
|
||||
$('.scrubber .progress-bar', @$el).css('width', "#{progress * 100}%")
|
||||
|
||||
updatePlayButton: (progress) ->
|
||||
if progress >= 0.99 and @lastProgress < 0.99
|
||||
|
|
Loading…
Reference in a new issue