Performance Improvements: Shutting Down Floating Objects when only charts are visible.

This commit is contained in:
Luis Fernando Molina committed 2019-09-26 11:21:02 +02:00
1 parent a214752b26
commit 7307f91193
4 files changed
+46 -9

No files matched your search

+38 -4
View File
@@ -69,15 +69,48 @@ function newAnimation () {
/* We loop through the callback functions collections and execute them all. */
callBackFunctions.forEach(function (callBackFunction) {
callBackFunction()
})
let performanceMap = new Map()
let totalTimeConsumed = 0
let totalElements = 0
let chanceToExecute
let randomNumber
let mustExecute
for (const [key, callBackFunction] of callBackFunctions.entries()) {
switch (key) {
case 'Floating Space Physics':
chanceToExecute = 100
randomNumber = Math.random() * 100 * chanceToExecute
if (randomNumber > 100 - chanceToExecute) { mustExecute = true } else { mustExecute = false }
break
default: {
mustExecute = true
}
}
if (mustExecute === true) {
let t0 = performance.now()
callBackFunction()
let t1 = performance.now()
let timeConsumed = t1 - t0
performanceMap.set(key, timeConsumed)
totalTimeConsumed = totalTimeConsumed + timeConsumed
totalElements++
}
}
/* Performance Check */
console.clear()
for (const [key, timeConsumed] of performanceMap.entries()) {
let percentage = timeConsumed * 100 / totalTimeConsumed
console.log(key, percentage.toFixed(2))
}
} else {
browserCanvas.width = 1
browserCanvas.height = 1
}
/* We request the next frame to be drawn, and stablishing a loop */
/* We request the next frame to be drawn, and stablishing a loop */
/* Use this code for full animation speed. */
animationLoopHandle = window.requestAnimationFrame(animationLoop)
@@ -104,3 +137,4 @@ function newAnimation () {
browserCanvasContext.fill()
}
}
+2
View File
@@ -119,8 +119,10 @@
thisObject.container.frame.position.y = browserCanvas.height - COCKPIT_SPACE_HEIGHT
thisObject.status = 'BOTTOM'
canvas.strategySpace.makeInvisible()
canvas.floatingSpace.makeInvisible()
} else {
canvas.strategySpace.makeVisible()
canvas.floatingSpace.makeVisible()
}
if (thisObject.container.frame.position.y < browserCanvas.height * 0.5 / 100) {
+6 -4
View File
@@ -137,8 +137,10 @@ function newFloatingSpace () {
}
function physics () {
browserZoomPhysics()
thisObject.floatingLayer.physics()
if (visible === true) {
browserZoomPhysics()
thisObject.floatingLayer.physics()
}
}
function browserZoomPhysics () {
@@ -153,9 +155,8 @@ function newFloatingSpace () {
function draw () {
if (visible === true) {
drawBackground()
thisObject.floatingLayer.draw()
}
thisObject.floatingLayer.draw()
}
function drawBackground () {
@@ -168,3 +169,4 @@ function newFloatingSpace () {
browserCanvasContext.fill()
}
}
-1
View File
@@ -187,7 +187,6 @@ function newStrategySpace () {
}
function makeVisible () {
canvas.floatingSpace.makeVisible()
visible = true
}