From 6a1dfc8e2a776046b93401c5410feca3f1dac8f2 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 30 Apr 2018 15:47:32 +0200 Subject: [PATCH] Logs and Error Handling at the Animation Module --- .vs/AAWeb/v15/.suo | Bin 67584 -> 62976 bytes Animation.js | 135 +++++++++++++++++++++++++++++++++------------ Canvas.js | 69 +++++++++++++++++------ 3 files changed, 153 insertions(+), 51 deletions(-) diff --git a/.vs/AAWeb/v15/.suo b/.vs/AAWeb/v15/.suo index 363efc75ff16ab803f2f4e6533b775d65c2e69c7..d69fdfb982989eb1a4377ccb2be2e6d9659a0f8c 100644 GIT binary patch delta 4048 zcmeH~YgAO%702(n+<_TD7@h$nI1GX)!z&S^h&afIV2OZ_hz6?|m4GM;BNb!AB&N-3 zq?OEGQR9b7M%rdoO)Yn=#?{akYm#b0Ya~V!Q;jt?X=|*H;w!06|NG92A|Y8OO~3W5 z^_#uVKF@phKKtHrv@4EJ{Mz%PhD(y<2X4CEZU{*L<1Z_Q%OMx~m(~5?)Z1b@EDkHJ zlh?^Y&=vVfkwqa7ws;T@3}6gkC&U6X2m?boa~SMAug{qosIxQK z<}XRD5_^*?1HBmxo6nn3(Ak?4z(8+?pw8apV@iYMImSW`bY>3f6j8O5h?T9SX%5Qe*O<_`EP1`W)~OH&z;~`dTQwCUqEMNC_%-8uh9Ya!ojc z?Xo1OIrwqmrpv*t;wG&bR;EPoxB{ysj3Ik4F+g^iWLJpn8tG4tR5Q6!Qj|(>C$f(( z(?<7uq;3})o}-ot(+z^3alW@-F#F~Sz@;mrP|*I&N#w{ZRyYE9x!{3M5O@n5 z27Tada0I*qj)G(0UGN?_4*tUVkm`eCT2G_)Avgp63O)iKgTH~lgMWat;1h5T{1co9 z7r;eu3H%H6gUjFwxC*X;>)=!H8TdE20kojuz~NJLyH&ru8^RSYyR81MT)C@QR!GjD zqHyB;oFllu<{>`!{`@k76pe1TJu$h>HA4#*)m-#bq0Hquw64=Es_CIq!c{7}=F3jA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o$^5#L)+<)KbPTph8=&aF0Dc z%0H9*s;BpKE>&FIObX651!ZTzMERUSCrYWMjC)ZzjG(fo7qQf4G+ue!!SlUF{T~{RYgQHg>s6uT%A2MC{Ocjm4;$fhj}cmXmi>=J zj+J^n_4+e6w=8LWGrv92cI`J2-?eD{-!M;lR{n?L5rsJqc%c@#2X>#ppYic{o3kBdTBg zIg7M$cFuvnO*P zI5{@K6n3r+*hz!9^>*)puPyZ20A;y=+v%v5)<5r4!H3bODI#z%6+t8WX8wL$V& SCFtLN7$(OA@#;T*%Ki Entering function."); } + + /* Nothing to do here yet. */ + callBackFunction(GLOBAL.CUSTOM_OK_RESPONSE); + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> err = " + err); } + callBackFunction(GLOBAL.CUSTOM_FAIL_RESPONSE); + } } - function start() { + function start(callBackFunction) { - animationLoop(); // Inside this function the animation process is started, and at the same time it creates a loop. + try { + if (INFO_LOG === true) { logger.write("[INFO] start -> Entering function."); } + + animationLoop(); // Inside this function the animation process is started, and at the same time it creates a loop. + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] start -> err = " + err); } + callBackFunction(GLOBAL.CUSTOM_FAIL_RESPONSE); + } } - function stop() { + function stop(callBackFunction) { - window.cancelAnimationFrame(animationLoopHandle); + try { + if (INFO_LOG === true) { logger.write("[INFO] stop -> Entering function."); } + + window.cancelAnimationFrame(animationLoopHandle); + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] stop -> err = " + err); } + callBackFunction(GLOBAL.CUSTOM_FAIL_RESPONSE); + } } - function addCallBackFunction(key, callBackFunction) { + function addCallBackFunction(key, callBack, callBackFunction) { - callBackFunctions.set(key, callBackFunction); + try { + + if (INFO_LOG === true) { logger.write("[INFO] addCallBackFunction -> Entering function."); } + + callBackFunctions.set(key, callBack); + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] addCallBackFunction -> err = " + err); } + callBackFunction(GLOBAL.CUSTOM_FAIL_RESPONSE); + } } function removeCallBackFunction(key, callBackFunction) { - callBackFunctions.delete(key); + try { + + if (INFO_LOG === true) { logger.write("[INFO] removeCallBackFunction -> Entering function."); } + + callBackFunctions.delete(key); + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] removeCallBackFunction -> err = " + err); } + callBackFunction(GLOBAL.CUSTOM_FAIL_RESPONSE); + } } - function animationLoop() { + function animationLoop(callBackFunction) { - /* First thing is to clear the actual canvas */ + try { - clearCanvasFunction(); + if (INFO_LOG === true) { logger.write("[INFO] animationLoop -> Entering function."); } - /* We loop through the callback functions collections and execute them all. */ + /* First thing is to clear the actual canvas */ - callBackFunctions.forEach(function (callBackFunction) { + clearBrowserCanvas(); - callBackFunction(); + /* We loop through the callback functions collections and execute them all. */ - }); + callBackFunctions.forEach(function (callBackFunction) { + callBackFunction(); - /* We animate the zoom of the viewPort */ + }); - viewPort.animate(); - viewPort.draw(); + /* We request the next frame to be drawn, and stablishing a loop */ - /* We request the next frame to be drawn, and stablishing a loop */ + animationLoopHandle = window.requestAnimationFrame(animationLoop); - animationLoopHandle = window.requestAnimationFrame(animationLoop); + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] animationLoop -> err = " + err); } + + if (callBackFunction !== undefined) { // When the loop is called by the browser there will be no callBackFunction. + callBackFunction(GLOBAL.CUSTOM_FAIL_RESPONSE); + } + } + } + + function clearBrowserCanvas() { + + if (INFO_LOG === true) { logger.write("[INFO] clearBrowserCanvas -> Entering function."); } + + browserCanvasContext.clearRect(0, 0, browserCanvas.width, browserCanvas.height); } } diff --git a/Canvas.js b/Canvas.js index 6ec8c9138..2478b2a94 100644 --- a/Canvas.js +++ b/Canvas.js @@ -38,6 +38,7 @@ function newCanvas() { const MODULE_NAME = "Canvas"; const INFO_LOG = false; + const ERROR_LOG = true; const logger = newDebugLog(); logger.fileName = MODULE_NAME; @@ -73,7 +74,7 @@ function newCanvas() { return thisObject; - function initialize() { + function initialize(callBackFunction) { if (INFO_LOG === true) { logger.write("[INFO] initialize -> Entering function."); } @@ -104,18 +105,60 @@ function newCanvas() { splashScreen.initialize(); let animation = newAnimation(); - animation.initialize(clearBrowserCanvas); + animation.initialize(onAnimationInitialized); - this.animation = animation; + function onAnimationInitialized(err) { - /* Here we add all the functions that will be called during the animation cycle. */ + this.animation = animation; - animation.addCallBackFunction("Chart Space", thisObject.chartSpace.draw); - animation.addCallBackFunction("Floating Space", thisObject.floatingSpace.physicsLoop); - animation.addCallBackFunction("Panels Space", thisObject.panelsSpace.draw); - animation.addCallBackFunction("Splash Screen", splashScreen.draw); - animation.start(); + /* Here we add all the functions that will be called during the animation cycle. */ + animation.addCallBackFunction("Chart Space", thisObject.chartSpace.draw, onFunctionAdded); + animation.addCallBackFunction("Floating Space", thisObject.floatingSpace.physicsLoop, onFunctionAdded); + animation.addCallBackFunction("Panels Space", thisObject.panelsSpace.draw, onFunctionAdded); + animation.addCallBackFunction("Splash Screen", splashScreen.draw, onFunctionAdded); + animation.addCallBackFunction("ViewPort Animate", viewPort.animate, onFunctionAdded); + animation.addCallBackFunction("ViewPort Draw", viewPort.draw, onFunctionAdded); + animation.start(onStart); + + function onFunctionAdded(err) { + + if (err.result === GLOBAL.CUSTOM_FAIL_RESPONSE.result) { + + animation.stop(); + + if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> onAnimationInitialized -> onFunctionAdded -> Animation Stopped since a vital funtion could not be added."); } + + /* Display some Error Page here. */ + } + } + + function onStart(err) { + + switch (err.result) { + case GLOBAL.DEFAULT_OK_RESPONSE.result: { + + if (INFO_LOG === true) { logger.write("[INFO] initialize -> onAnimationInitialized -> onStart -> Received OK Response."); } + callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE); + return; + } + + case GLOBAL.DEFAULT_FAIL_RESPONSE.result: { + + if (INFO_LOG === true) { logger.write("[INFO] initialize -> onAnimationInitialized -> onStart -> Received FAIL Response."); } + callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE); + return; + } + + default: { + + if (INFO_LOG === true) { logger.write("[INFO] initialize -> onAnimationInitialized -> onStart -> Received Unexpected Response."); } + callBackFunction(err); + return; + } + } + } + } } function initializeBrowserCanvas() { @@ -134,14 +177,6 @@ function newCanvas() { viewPort.initialize(); } - function clearBrowserCanvas() { - - if (INFO_LOG === true) { logger.write("[INFO] clearBrowserCanvas -> Entering function."); } - - browserCanvasContext.clearRect(0, 0, browserCanvas.width, browserCanvas.height); - - } - function addCanvasEvents() { if (INFO_LOG === true) { logger.write("[INFO] addCanvasEvents -> Entering function."); }