Skip to content

Commit

Permalink
* Stop rendering if not in simulator tab and python not running
Browse files Browse the repository at this point in the history
  • Loading branch information
QuirkyCort committed Apr 14, 2021
1 parent a222ba7 commit cf1ae84
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 14 deletions.
2 changes: 1 addition & 1 deletion public/arena.html
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
}
}
</script>
<script src="js/babylon.js?v=cfeb42f1"></script>
<script src="js/babylon.js?v=35120996"></script>
<script src="js/botsPanel.js?v=dedf08f0"></script>
<script src="js/arenaPanel.js?v=0cf8c5d9"></script>
<script src="js/arena.js?v=156022dd"></script>
Expand Down
4 changes: 2 additions & 2 deletions public/builder.html
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@
robot.player = 'single';
robots.push(robot);
</script>
<script src="js/babylon.js?v=cfeb42f1"></script>
<script src="js/simPanel.js?v=2a4d903c"></script>
<script src="js/babylon.js?v=35120996"></script>
<script src="js/simPanel.js?v=4675cb7c"></script>
<script src="js/builtInImages.js?v=e9621db6"></script>
<script src="js/builder.js?v=2646c124"></script>

Expand Down
4 changes: 2 additions & 2 deletions public/configurator.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@
robot.player = 'single';
robots.push(robot);
</script>
<script src="js/babylon.js?v=cfeb42f1"></script>
<script src="js/simPanel.js?v=2a4d903c"></script>
<script src="js/babylon.js?v=35120996"></script>
<script src="js/simPanel.js?v=4675cb7c"></script>
<script src="js/builtInImages.js?v=e9621db6"></script>
<script src="js/configurator.js?v=ecca0287"></script>

Expand Down
4 changes: 2 additions & 2 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,11 @@
robot.player = 'single';
robots.push(robot);
</script>
<script src="js/babylon.js?v=cfeb42f1"></script>
<script src="js/babylon.js?v=35120996"></script>
<script src="js/blocklyPanel.js?v=d21cc31d"></script>
<script src="js/pythonPanel.js?v=ae836351"></script>
<script src="js/pythonLibPanel.js?v=01359988"></script>
<script src="js/simPanel.js?v=2a4d903c"></script>
<script src="js/simPanel.js?v=4675cb7c"></script>
<script src="js/main.js?v=6017d223"></script>

<script>
Expand Down
16 changes: 9 additions & 7 deletions public/js/babylon.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ var babylon = new function() {
});

// Register a render loop to repeatedly render the scene
self.engine.runRenderLoop(function () {
self.scene.render();
});
// self.engine.runRenderLoop(function () {
// self.scene.render();
// });

// Watch for browser/canvas resize events
window.addEventListener('resize', function () {
Expand Down Expand Up @@ -113,7 +113,7 @@ var babylon = new function() {
let up = self.cameraArc.upVector;
let mode = self.cameraMode;

self.engine.stopRenderLoop(self.engine._activeRenderLoops[0]);
self.engine.stopRenderLoop();
self.scene.dispose();

self.scene = self.createScene();
Expand All @@ -127,9 +127,11 @@ var babylon = new function() {
self.cameraArc.target = target;

self.loadMeshes(self.scene);
self.engine.runRenderLoop(function () {
self.scene.render();
});
if (main.$navs.siblings('.active').attr('id') == 'navSim') {
self.engine.runRenderLoop(function () {
self.scene.render();
});
}
};

// Remove all RTT cameras
Expand Down
15 changes: 15 additions & 0 deletions public/js/simPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,21 @@ var simPanel = new function() {
self.updateSensorsPanelTimer = setInterval(self.updateSensorsPanel, 250);
};

// Run when the simPanel in inactive
this.onInActive = function() {
if (! skulpt.running) {
babylon.engine.stopRenderLoop();
}
};

// Run when the simPanel in active
this.onActive = function() {
if (babylon.engine._activeRenderLoops.length == 0)
babylon.engine.runRenderLoop(function(){
babylon.scene.render();
});
};

// Setup virtual joystick
this.setupJoystick = function() {
function moveSteering(steering, speed) {
Expand Down

1 comment on commit cf1ae84

@germanicianus
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolves #75.

Please sign in to comment.