|
|
@ -8,7 +8,6 @@ class AsciiIo.Movie
|
|
|
|
|
|
|
|
|
|
|
|
reset: ->
|
|
|
|
reset: ->
|
|
|
|
@frameNo = 0
|
|
|
|
@frameNo = 0
|
|
|
|
@dataIndex = 0
|
|
|
|
|
|
|
|
@completedFramesTime = 0
|
|
|
|
@completedFramesTime = 0
|
|
|
|
@playing = false
|
|
|
|
@playing = false
|
|
|
|
@lastFrameAt = undefined
|
|
|
|
@lastFrameAt = undefined
|
|
|
@ -22,11 +21,8 @@ class AsciiIo.Movie
|
|
|
|
now: ->
|
|
|
|
now: ->
|
|
|
|
(new Date()).getTime()
|
|
|
|
(new Date()).getTime()
|
|
|
|
|
|
|
|
|
|
|
|
timing: ->
|
|
|
|
stdout: ->
|
|
|
|
@options.timing
|
|
|
|
@options.stdout
|
|
|
|
|
|
|
|
|
|
|
|
data: ->
|
|
|
|
|
|
|
|
@options.stdout_data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
play: ->
|
|
|
|
play: ->
|
|
|
|
return if @isPlaying()
|
|
|
|
return if @isPlaying()
|
|
|
@ -74,8 +70,8 @@ class AsciiIo.Movie
|
|
|
|
|
|
|
|
|
|
|
|
@playing = true
|
|
|
|
@playing = true
|
|
|
|
@resumedAt = @now()
|
|
|
|
@resumedAt = @now()
|
|
|
|
frame = @timing()[@frameNo]
|
|
|
|
frame = @stdout()[@frameNo]
|
|
|
|
[delay, count] = frame
|
|
|
|
[delay, data] = frame
|
|
|
|
delayMs = delay * 1000
|
|
|
|
delayMs = delay * 1000
|
|
|
|
delayLeft = delayMs - @totalFrameWaitTime
|
|
|
|
delayLeft = delayMs - @totalFrameWaitTime
|
|
|
|
@processFrameWithDelay(delayLeft)
|
|
|
|
@processFrameWithDelay(delayLeft)
|
|
|
@ -91,7 +87,7 @@ class AsciiIo.Movie
|
|
|
|
!@isPlaying() and !@isFinished() and @frameNo > 0
|
|
|
|
!@isPlaying() and !@isFinished() and @frameNo > 0
|
|
|
|
|
|
|
|
|
|
|
|
isFinished: ->
|
|
|
|
isFinished: ->
|
|
|
|
!@isPlaying() and @frameNo >= @timing().length
|
|
|
|
!@isPlaying() and @frameNo >= (@stdout().length - 1)
|
|
|
|
|
|
|
|
|
|
|
|
seek: (percent) ->
|
|
|
|
seek: (percent) ->
|
|
|
|
@stop()
|
|
|
|
@stop()
|
|
|
@ -105,26 +101,23 @@ class AsciiIo.Movie
|
|
|
|
frameNo = 0
|
|
|
|
frameNo = 0
|
|
|
|
time = 0
|
|
|
|
time = 0
|
|
|
|
totalCount = 0
|
|
|
|
totalCount = 0
|
|
|
|
delay = undefined
|
|
|
|
delay = data = undefined
|
|
|
|
count = undefined
|
|
|
|
|
|
|
|
|
|
|
|
@trigger 'reset'
|
|
|
|
|
|
|
|
|
|
|
|
while time < requestedTime
|
|
|
|
while time < requestedTime
|
|
|
|
[delay, count] = @timing()[frameNo]
|
|
|
|
[delay, data] = @stdout()[frameNo]
|
|
|
|
|
|
|
|
|
|
|
|
if time + delay >= requestedTime
|
|
|
|
if time + delay >= requestedTime
|
|
|
|
break
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
frameData = String.fromCharCode.apply(String, data)
|
|
|
|
|
|
|
|
@trigger 'data', [frameData]
|
|
|
|
time += delay
|
|
|
|
time += delay
|
|
|
|
totalCount += count
|
|
|
|
|
|
|
|
frameNo += 1
|
|
|
|
frameNo += 1
|
|
|
|
|
|
|
|
|
|
|
|
@frameNo = frameNo
|
|
|
|
@frameNo = frameNo
|
|
|
|
@completedFramesTime = time * 1000
|
|
|
|
@completedFramesTime = time * 1000
|
|
|
|
@dataIndex = totalCount
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data = @data().slice(0, totalCount)
|
|
|
|
|
|
|
|
@trigger 'reset'
|
|
|
|
|
|
|
|
@trigger 'data', [data]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@lastFrameAt = @now()
|
|
|
|
@lastFrameAt = @now()
|
|
|
|
wait = requestedTime - time
|
|
|
|
wait = requestedTime - time
|
|
|
@ -177,23 +170,25 @@ class AsciiIo.Movie
|
|
|
|
@totalFrameWaitTime = 0
|
|
|
|
@totalFrameWaitTime = 0
|
|
|
|
|
|
|
|
|
|
|
|
nextFrame: ->
|
|
|
|
nextFrame: ->
|
|
|
|
if frame = @timing()[@frameNo]
|
|
|
|
frame = @stdout()[@frameNo]
|
|
|
|
[delay, count] = frame
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if delay <= @MIN_DELAY and @framesProcessed < 100
|
|
|
|
|
|
|
|
@framesProcessed += 1
|
|
|
|
|
|
|
|
@processFrame()
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
@framesProcessed = 0
|
|
|
|
|
|
|
|
realDelay = delay * 1000 * (1.0 / @options.speed)
|
|
|
|
|
|
|
|
@processFrameWithDelay(realDelay)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
true
|
|
|
|
if not frame or frame.length is 0
|
|
|
|
else
|
|
|
|
|
|
|
|
@playing = false
|
|
|
|
@playing = false
|
|
|
|
@trigger 'finished'
|
|
|
|
@trigger 'finished'
|
|
|
|
|
|
|
|
|
|
|
|
false
|
|
|
|
return false
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[delay, data] = frame
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if delay <= @MIN_DELAY and @framesProcessed < 100
|
|
|
|
|
|
|
|
@framesProcessed += 1
|
|
|
|
|
|
|
|
@processFrame()
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
@framesProcessed = 0
|
|
|
|
|
|
|
|
realDelay = delay * 1000 * (1.0 / @options.speed)
|
|
|
|
|
|
|
|
@processFrameWithDelay(realDelay)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
true
|
|
|
|
|
|
|
|
|
|
|
|
processFrameWithDelay: (delay) ->
|
|
|
|
processFrameWithDelay: (delay) ->
|
|
|
|
@nextFrameTimeoutId = setTimeout(
|
|
|
|
@nextFrameTimeoutId = setTimeout(
|
|
|
@ -204,14 +199,13 @@ class AsciiIo.Movie
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
processFrame: ->
|
|
|
|
processFrame: ->
|
|
|
|
frame = @timing()[@frameNo]
|
|
|
|
frame = @stdout()[@frameNo]
|
|
|
|
[delay, count] = frame
|
|
|
|
[delay, data] = frame
|
|
|
|
|
|
|
|
|
|
|
|
frameData = @data().slice(@dataIndex, @dataIndex + count)
|
|
|
|
frameData = String.fromCharCode.apply(String, data)
|
|
|
|
@trigger 'data', [frameData]
|
|
|
|
@trigger 'data', [frameData]
|
|
|
|
|
|
|
|
|
|
|
|
@frameNo += 1
|
|
|
|
@frameNo += 1
|
|
|
|
@dataIndex += count
|
|
|
|
|
|
|
|
@completedFramesTime += delay * 1000
|
|
|
|
@completedFramesTime += delay * 1000
|
|
|
|
@lastFrameAt = @now()
|
|
|
|
@lastFrameAt = @now()
|
|
|
|
|
|
|
|
|
|
|
|