const displayObjectSystem: System = new DisplayObjectSystem();
const hash: Map<Entity, EntityNode[]> = new Map<Entity, EntityNode[]>();
const components: {[name: string]: Component} = {};
components['ElementComponent'] = ElementComponent;
components['RectangleComponent'] = RectangleComponent;
components['CursorComponent'] = CursorComponent;
const alias: {[name: string]: string} = {};
alias['element'] = 'ElementComponent';
alias['currentPosition'] = 'RectangleComponent';
alias['nextPosition'] = 'RectangleComponent';
alias['cursor'] = 'CursorComponent';
function register(entity: Entity, node: EntityNode): void {
if( ! hash.has(entity)){
hash.set(entity, []);
}
hash.get(entity).push(node);
}
function getComponentInstanceByName(name: string): Component {
return new (components[alias[name]] as Component)();
}
function lasyInstallEntityNode(name: string, entity: Entity): Component {
if( ! entity.hasComponent(name)){
entity.insertComponent(name, getComponentInstanceByName(name))
}
return entity.getComponentByName(name);
}
function buildDisplayObjectEntity(entity: Entity): Entity {
entity.insertComponent('element', new ElementComponent());
entity.insertComponent('currentPosition', new RectangleComponent());
entity.insertComponent('nextPosition', new RectangleComponent());
return entity;
}
function buildDisplayObjectNode(node: DisplayObjectNode, entity: Entity): EntityNode {
node.element = lasyInstallEntityNode('element', entity) as ElementComponent;
node.staticPosition = lasyInstallEntityNode('currentPosition', entity) as RectangleComponent;
node.dynamicPosition= lasyInstallEntityNode('nextPosition', entity) as RectangleComponent;
displayObjectSystem.nodes.push(node);
return node;
}
let entity: Entity = new Entity();
let node: DisplayObjectNode = new DisplayObjectNode();
let node: EntityNode = buildDisplayObjectNode(node, buildDisplayObjectEntity(entity));
register(entity, node);
'use strict';
const REPEAT = 5;
const ITERATION = 100000000;
const DELAY = 3000;
function run(){
for(var i = 0; i < REPEAT; i ++){
console.log(`тест №${i}, затраченное время: ${test()}`);
}
}
// var === 200
// const 200
// let 200
function test(){
var startTestTime = new Date().getTime();
for(var i = 0; i < ITERATION; i++){
var prop = 999;
}
var finishTestTime = new Date().getTime();
var elapsedTestTime = finishTestTime - startTestTime;
return elapsedTestTime;
}
var delay = window.setTimeout;
delay(function(){
clearTimeout(delay);
run();
}, DELAY);