gryff Posted March 11, 2014 Share Posted March 11, 2014 I am continuing to build my 10 Bells scenes by adding some simple javascript coding. One feature I have added is output to the screen of the FPS. 10Bells -WIP 2 I have also accessed scene switching using code I essentially got from Xanmia scripts. TY Xanmia But the FPS output is behaving in an odd way - it keeps going up as I repeatedly switch scenes back and forth. Open the initially scene at link below, wait a few seconds then click on the dark figure. Will take you to the 10 Bells bar. Click on the guy at the bar and it will take you back to the start scene. repeat a few times and watch the FPS output climb. I am loading scenes with this script:function ContentLoad(){ if (sceneNum > 0) { //engine.dispose(); myScene.dispose(); divTitle.innerHTML = ""; } BABYLON.SceneLoader.Load("", theScenes[sceneNum], engine, function (newScene) { newScene.executeWhenReady(function () { // Attach camera to canvas inputs if(sceneNum > 0){ newScene.activeCamera.attachControl(canvas); divTitle.innerHTML = ""; } //added NEW line of code to get meshes. myScene = newScene; if ( sceneNum < 1) myScene.executeWhenReady(theTitle()); //Once the scene is loaded, just register a render loop to render it engine.runRenderLoop(function() { myScene.render(); divFps.innerHTML = "0"; divFps.innerHTML = BABYLON.Tools.GetFps().toFixed() + " fps"; }); }); }); }function theTitle(){divTitle.innerHTML = "Streets Of Whitechapel 1888";}any ideas why the FPS climbs? cheers, gryff Quote Link to comment Share on other sites More sharing options...
Xanmia Posted March 11, 2014 Share Posted March 11, 2014 Hey Gryff, I only got a chance to look at it for a second. First off, very cool! The reason might be because you are only disposing the scene when it's scene 0. And you would want to do it on both scenes. If you drop the if (sceneNum > 0) and just leave the dispose and title what happens? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 11, 2014 Share Posted March 11, 2014 I think you also need to check if a renderLoop is already registered. I think this is why you get this result: multiple calls to runRenderLoop without a stopRenderLoop Quote Link to comment Share on other sites More sharing options...
gryff Posted March 12, 2014 Author Share Posted March 12, 2014 Well I changed my loading code as suggested by Xanmia and DK - new version here; 10 Bells - WIP 2a and here is the new Loader code:function ContentLoad(){ if (sceneNum > 0) { sound.stop(); } engine.stopRenderLoop(); engine.dispose(); myScene.dispose(); divTitle.innerHTML = ""; divMesh.innerHTML = ""; BABYLON.SceneLoader.Load("", theScenes[sceneNum], engine, function (newScene) { newScene.executeWhenReady(function () { // Attach camera to canvas inputs if(sceneNum > 0){ newScene.activeCamera.attachControl(canvas); divTitle.innerHTML = ""; } //added NEW line of code to get meshes. myScene = newScene; if ( sceneNum < 1) myScene.executeWhenReady(theTitle()); //Once the scene is loaded, just register a render loop to render it engine.runRenderLoop(function() { myScene.render(); divFps.innerHTML = "0"; divFps.innerHTML = BABYLON.Tools.GetFps().toFixed() + " fps"; }); }); }); }function theTitle(){divTitle.innerHTML = "Streets Of Whitechapel 1888";sound.play();}Still getting the FPS rate going up. Really don't understand why it goes up - would have expected it to drop if processes were not being stopped. Any more suggestions very welcome. At the same time, added a new little feature - click on the barmaid before you return to the opening scene. (The info you get is all true ;-) ) cheers, gryff Quote Link to comment Share on other sites More sharing options...
Dad72 Posted March 12, 2014 Share Posted March 12, 2014 Try:function ContentLoad() { if (sceneNum > 0) { sound.stop(); } if(engine != undefined) { engine.stopRenderLoop(); engine.dispose(); myScene.dispose(); engine = null; myScene = null; } divTitle.innerHTML = ""; divMesh.innerHTML = ""; BABYLON.SceneLoader.Load("", theScenes[sceneNum], engine, function (newScene) { // Attach camera to canvas inputs if(sceneNum > 0){ newScene.activeCamera.attachControl(canvas); divTitle.innerHTML = ""; } //added NEW line of code to get meshes. myScene = newScene; if ( sceneNum < 1) myScene.executeWhenReady(theTitle()); }); //Once the scene is loaded, just register a render loop to render it engine.runRenderLoop(function() { myScene.render(); divFps.innerHTML = BABYLON.Tools.GetFps().toFixed() + " fps"; });}function theTitle() { divTitle.innerHTML = "Streets Of Whitechapel 1888"; sound.play();} Quote Link to comment Share on other sites More sharing options...
gryff Posted March 16, 2014 Author Share Posted March 16, 2014 I have the scene switching working well using the the second script I posted- switches nicely and quickly back and forth. So thanks for the tips people The problem seemed to be associated with my PC hardware - now fixed. However it did lead me to test my scenes on another computer - and that raised an interesting question. More about that in another post. TY again folks! cheers, gryff Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.