Jump to content

Strange FPS output behaviour


gryff
 Share

Recommended Posts

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 :)

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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();}

 

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...