You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.3 KiB
CoffeeScript
57 lines
1.3 KiB
CoffeeScript
13 years ago
|
class AsciiIo.Movie
|
||
13 years ago
|
MIN_DELAY: 0.01
|
||
|
SPEED: 1.0
|
||
|
|
||
13 years ago
|
constructor: (@data, @timing) ->
|
||
|
@currentTime = 0
|
||
|
@processedFramesTime = 0
|
||
|
|
||
|
play: ->
|
||
13 years ago
|
@nextFrame()
|
||
|
|
||
|
nextFrame: () ->
|
||
13 years ago
|
return if @currentData.length > 100
|
||
|
|
||
13 years ago
|
frame = @timing[@frameNo]
|
||
13 years ago
|
|
||
13 years ago
|
unless frame
|
||
|
@terminal.stopCursorBlink()
|
||
13 years ago
|
console.log "finished in #{((new Date()).getTime() - @startTime) / 1000} seconds"
|
||
13 years ago
|
return
|
||
|
|
||
13 years ago
|
@frameNo += 1
|
||
13 years ago
|
|
||
13 years ago
|
[delay, count] = frame
|
||
13 years ago
|
|
||
13 years ago
|
if delay > @MIN_DELAY
|
||
|
realDelay = delay * 1000 * (1.0 / @SPEED)
|
||
13 years ago
|
|
||
13 years ago
|
setTimeout(
|
||
|
=>
|
||
|
@terminal.restartCursorBlink()
|
||
|
@processFrame(count)
|
||
|
@nextFrame()
|
||
|
realDelay
|
||
|
)
|
||
|
else
|
||
|
@processFrame(count)
|
||
|
@nextFrame()
|
||
13 years ago
|
|
||
13 years ago
|
processFrame: (count) ->
|
||
|
@currentData += @data.slice(@dataIndex, @dataIndex + count)
|
||
|
@dataIndex += count
|
||
13 years ago
|
|
||
13 years ago
|
@currentData = @interpreter.feed(@currentData)
|
||
13 years ago
|
|
||
13 years ago
|
if @currentData.length > 0
|
||
13 years ago
|
@logStatus(count)
|
||
13 years ago
|
|
||
13 years ago
|
logStatus: (count) ->
|
||
13 years ago
|
console.log 'rest: ' + Utf8.decode(@currentData)
|
||
13 years ago
|
|
||
13 years ago
|
if @currentData.length > 100
|
||
|
head = @currentData.slice(0, 100)
|
||
|
hex = ("0x#{c.charCodeAt(0).toString(16)}" for c in head)
|
||
|
console.log "failed matching: '" + Utf8.decode(head) + "' (" + hex.join() + ") [pos: " + (@dataIndex - count) + "]"
|
||
|
return
|