Merge branch 'bm'

* bm:
  speed and benchmark options for movie
This commit is contained in:
Marcin Kulik 2012-03-16 20:47:45 +01:00
commit 1b2897573e
3 changed files with 19 additions and 4 deletions

View File

@ -1,8 +1,7 @@
class AsciiIo.Movie class AsciiIo.Movie
MIN_DELAY: 0.01 MIN_DELAY: 0.01
SPEED: 1.0
constructor: (@model) -> constructor: (@model, @options) ->
@reset() @reset()
@startTimeReporter() @startTimeReporter()
_.extend(this, Backbone.Events) _.extend(this, Backbone.Events)
@ -46,6 +45,9 @@ class AsciiIo.Movie
@start() @start()
start: -> start: ->
if @options.benchmark
@startTime = (new Date).getTime()
@playing = true @playing = true
@lastFrameTime = (new Date()).getTime() @lastFrameTime = (new Date()).getTime()
@nextFrame() @nextFrame()
@ -124,7 +126,7 @@ class AsciiIo.Movie
if delay <= @MIN_DELAY if delay <= @MIN_DELAY
@processFrame() @processFrame()
else else
realDelay = delay * 1000 * (1.0 / @SPEED) realDelay = delay * 1000 * (1.0 / @options.speed)
@processFrameWithDelay(realDelay) @processFrameWithDelay(realDelay)
true true
@ -132,6 +134,11 @@ class AsciiIo.Movie
@playing = false @playing = false
@stopTimeReporter() @stopTimeReporter()
@trigger('movie-finished') @trigger('movie-finished')
if @options.benchmark
now = (new Date).getTime()
console.log "finished in #{(now - @startTime) / 1000.0}s"
false false
processFrameWithDelay: (delay) -> processFrameWithDelay: (delay) ->

View File

@ -1,7 +1,11 @@
class AsciiIo.PlayerView extends Backbone.View class AsciiIo.PlayerView extends Backbone.View
initialize: (options) -> initialize: (options) ->
@movie = new AsciiIo.Movie(@model) @movie = new AsciiIo.Movie(
@model,
speed: options.speed,
benchmark: options.benchmark
)
@movie.on 'movie-loaded', @onMovieLoaded, this @movie.on 'movie-loaded', @onMovieLoaded, this
@movie.load() @movie.load()

View File

@ -27,6 +27,8 @@ module AsciicastsHelper
end end
def player_script(asciicast, options = {}) def player_script(asciicast, options = {})
speed = (params[:speed] || 1).to_f
benchmark = !!params[:bm]
auto_play = options.key?(:auto_play) ? !!options[:auto_play] : false auto_play = options.key?(:auto_play) ? !!options[:auto_play] : false
if custom_renderer = params[:renderer] if custom_renderer = params[:renderer]
@ -42,6 +44,8 @@ module AsciicastsHelper
el: $('.player'), el: $('.player'),
cols: #{asciicast.terminal_columns}, cols: #{asciicast.terminal_columns},
lines: #{asciicast.terminal_lines}, lines: #{asciicast.terminal_lines},
speed: #{speed},
benchmark: #{benchmark},
model: new AsciiIo.Asciicast({ id: #{asciicast.id} }), model: new AsciiIo.Asciicast({ id: #{asciicast.id} }),
rendererClass: #{renderer_class}, rendererClass: #{renderer_class},
autoPlay: #{auto_play} autoPlay: #{auto_play}