зеркало из https://github.com/mozilla/shumway.git
Adds scoring to the swfm player.
This commit is contained in:
Родитель
9de7c7ae69
Коммит
af1bbab7ae
|
@ -347,6 +347,7 @@ var currentEasel;
|
|||
function createEasel() {
|
||||
Shumway.GFX.WebGL.SHADER_ROOT = "../../src/gfx/gl/shaders/";
|
||||
currentEasel = new Easel(document.getElementById("easelContainer"));
|
||||
currentEasel.startRendering();
|
||||
return currentEasel;
|
||||
}
|
||||
|
||||
|
|
|
@ -35,6 +35,8 @@ function parseQueryString(qs) {
|
|||
var queryVariables = parseQueryString(window.location.search);
|
||||
|
||||
var movieURL = queryVariables['swfm'] || 'tiger.swfm';
|
||||
var scoreRun = queryVariables['score'] === 'true';
|
||||
var fastRun = queryVariables['fast'] === 'true';
|
||||
var easelHost;
|
||||
|
||||
function startMovie(file) {
|
||||
|
@ -45,6 +47,16 @@ function startMovie(file) {
|
|||
|
||||
easelHost = new Shumway.GFX.Test.PlaybackEaselHost(easel);
|
||||
easelHost.playUrl(file);
|
||||
|
||||
if (scoreRun) {
|
||||
easelHost.alwaysRenderFrame = true;
|
||||
easelHost.ignoreTimestamps = fastRun;
|
||||
easelHost.onComplete = function () {
|
||||
alert('Score: ' + Math.round(easelHost.cpuTime));
|
||||
};
|
||||
} else {
|
||||
easel.startRendering();
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener('DOMContentLoaded', function () {
|
||||
|
|
|
@ -215,5 +215,7 @@ function createEasel(backgroundColor) {
|
|||
var Canvas2DRenderer = Shumway.GFX.Canvas2DRenderer;
|
||||
|
||||
Shumway.GFX.WebGL.SHADER_ROOT = SHUMWAY_ROOT + "gfx/gl/shaders/";
|
||||
return new Easel(document.getElementById("easelContainer"), false, backgroundColor);
|
||||
var easel = new Easel(document.getElementById("easelContainer"), false, backgroundColor);
|
||||
easel.startRendering();
|
||||
return easel;
|
||||
}
|
||||
|
|
|
@ -280,6 +280,9 @@ module Shumway.GFX {
|
|||
|
||||
private _selectedNodes: Node [] = [];
|
||||
|
||||
private _isRendering: boolean = false;
|
||||
private _rAF: number = undefined;
|
||||
|
||||
private _eventListeners: Shumway.Map<any []> = Object.create(null);
|
||||
private _fps: FPS;
|
||||
private _fullScreen: boolean = false;
|
||||
|
@ -385,8 +388,6 @@ module Shumway.GFX {
|
|||
self._persistentState.onKeyUp(self, event);
|
||||
}
|
||||
}, false);
|
||||
|
||||
this._enterRenderLoop();
|
||||
}
|
||||
|
||||
private _listenForContainerSizeChanges() {
|
||||
|
@ -435,14 +436,26 @@ module Shumway.GFX {
|
|||
}
|
||||
}
|
||||
|
||||
private _enterRenderLoop() {
|
||||
public startRendering() {
|
||||
if (this._isRendering) {
|
||||
return;
|
||||
}
|
||||
this._isRendering = true;
|
||||
|
||||
var self = this;
|
||||
requestAnimationFrame(function tick() {
|
||||
this._rAF = requestAnimationFrame(function tick() {
|
||||
self.render();
|
||||
requestAnimationFrame(tick);
|
||||
self._rAF = requestAnimationFrame(tick);
|
||||
});
|
||||
}
|
||||
|
||||
public stopRendering() {
|
||||
if (this._isRendering) {
|
||||
this._isRendering = false;
|
||||
cancelAnimationFrame(this._rAF);
|
||||
}
|
||||
}
|
||||
|
||||
set state(state: UIState) {
|
||||
this._state = state;
|
||||
}
|
||||
|
|
|
@ -88,7 +88,8 @@
|
|||
|
||||
var container = document.getElementById("container");
|
||||
|
||||
var easel = new Easel(container, Backend.Canvas2D)
|
||||
var easel = new Easel(container, Backend.Canvas2D);
|
||||
easel.startRendering();
|
||||
var stage = easel.stage;
|
||||
var world = easel.world;
|
||||
|
||||
|
|
|
@ -73,6 +73,7 @@
|
|||
var containers = [];
|
||||
function createEasel(container) {
|
||||
var easel = new Easel(container, Backend.Canvas2D);
|
||||
easel.startRendering();
|
||||
easels.push(easel);
|
||||
map.set(container, easel);
|
||||
var stage = easel.stage;
|
||||
|
@ -86,6 +87,7 @@
|
|||
|
||||
function destroyEasel(container) {
|
||||
var easel = map.get(container);
|
||||
easel.stopRendering();
|
||||
var i = easels.indexOf(easel);
|
||||
easels.splice(i, 1);
|
||||
}
|
||||
|
|
|
@ -24,13 +24,20 @@ module Shumway.GFX.Test {
|
|||
import VideoPlaybackEvent = Shumway.Remoting.VideoPlaybackEvent;
|
||||
import DisplayParameters = Shumway.Remoting.DisplayParameters;
|
||||
|
||||
var MINIMAL_TIMER_INTERVAL = 5;
|
||||
|
||||
export class PlaybackEaselHost extends EaselHost {
|
||||
private _parser: MovieRecordParser;
|
||||
private _lastTimestamp: number;
|
||||
|
||||
public ignoreTimestamps: boolean = false;
|
||||
public alwaysRenderFrame: boolean = false;
|
||||
public cpuTime: number = 0;
|
||||
|
||||
public onComplete: () => void = null;
|
||||
|
||||
public constructor(easel: Easel) {
|
||||
super(easel);
|
||||
|
||||
}
|
||||
|
||||
private playUrl(url: string) {
|
||||
|
@ -68,14 +75,27 @@ module Shumway.GFX.Test {
|
|||
private _parseNext() {
|
||||
var type = this._parser.readNextRecord();
|
||||
if (type !== MovieRecordType.None) {
|
||||
var runRecordBound = this._runRecord.bind(this);
|
||||
var interval = this._parser.currentTimestamp - this._lastTimestamp;
|
||||
this._lastTimestamp = this._parser.currentTimestamp;
|
||||
setTimeout(this._runRecord.bind(this), interval);
|
||||
if (interval < MINIMAL_TIMER_INTERVAL) {
|
||||
// Records are too close to each other, running on next script turn.
|
||||
Promise.resolve(undefined).then(runRecordBound);
|
||||
} else if (this.ignoreTimestamps) {
|
||||
setTimeout(runRecordBound);
|
||||
} else {
|
||||
setTimeout(runRecordBound, interval);
|
||||
}
|
||||
} else {
|
||||
if (this.onComplete) {
|
||||
this.onComplete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private _runRecord() {
|
||||
var data;
|
||||
var start = performance.now();
|
||||
switch (this._parser.currentType) {
|
||||
case MovieRecordType.PlayerCommand:
|
||||
case MovieRecordType.PlayerCommandAsync:
|
||||
|
@ -90,6 +110,9 @@ module Shumway.GFX.Test {
|
|||
}
|
||||
break;
|
||||
case MovieRecordType.Frame:
|
||||
if (this.alwaysRenderFrame) {
|
||||
this.easel.render();
|
||||
}
|
||||
this.processFrame();
|
||||
break;
|
||||
case MovieRecordType.FontOrImage:
|
||||
|
@ -104,6 +127,7 @@ module Shumway.GFX.Test {
|
|||
default:
|
||||
throw new Error('Invalid movie record type');
|
||||
}
|
||||
this.cpuTime += performance.now() - start;
|
||||
this._parseNext();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -132,6 +132,7 @@ function createEasel() {
|
|||
Shumway.GFX.hud.value = true;
|
||||
Shumway.GFX.WebGL.SHADER_ROOT = "../../src/gfx/gl/shaders/";
|
||||
var easel = new Shumway.GFX.Easel(document.getElementById("easelContainer"), true);
|
||||
easel.startRendering();
|
||||
return easel;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
(function displayTests() {
|
||||
var easel = createEasel();
|
||||
easel.startRendering();
|
||||
|
||||
var Grid = Shumway.GFX.Grid;
|
||||
var Shape = Shumway.GFX.Shape;
|
||||
|
|
|
@ -87,7 +87,9 @@ function createEasel() {
|
|||
var Canvas2DRenderer = Shumway.GFX.Canvas2DRenderer;
|
||||
|
||||
Shumway.GFX.WebGL.SHADER_ROOT = "../src/gfx/gl/shaders/";
|
||||
return new Easel(document.getElementById("easelContainer"));
|
||||
var easel = new Easel(document.getElementById("easelContainer"));
|
||||
easel.startRendering();
|
||||
return easel;
|
||||
}
|
||||
|
||||
function waitForParametersMessage(e) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче