Skip to content

Commit

Permalink
Added fps meter to debug mode
Browse files Browse the repository at this point in the history
  • Loading branch information
jaks6 committed Dec 15, 2015
1 parent 6d176cf commit 0f527d6
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 5 deletions.
2 changes: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<!-- external js libs -->
<script type="text/javascript" src="lib/three.js/build/three.min.js"></script>
<script type="text/javascript" src="lib/cannon.min.js"></script>
<script type="text/javascript" src="lib/stats.min.js"></script>
<script type="text/javascript" src="lib/OrbitControls.js"></script>

<script type="text/javascript" src="js/CannonUtils.js"></script>
Expand Down Expand Up @@ -96,6 +97,7 @@ <h5>Player 2 (<span></span>)</h5>
<div class="timer">
30
</div>
<div id="fps_stats_container"></div>
</div>

<div id="gameover" class="hide">
Expand Down
3 changes: 2 additions & 1 deletion js/Gui.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ var GameGui = function () {
btn_ball.onclick = function () {
eightballgame.hitButtonClicked(Number(document.getElementById('range_strength').value));
};
}
if (debug) document.getElementById('fps_stats_container').appendChild( stats.domElement );
};

GameGui.prototype.setupGameHud = function() {
this.hide(document.getElementById('mainMenu'));
Expand Down
4 changes: 2 additions & 2 deletions js/Table.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var Table = function () {
var mesh = new THREE.Mesh(geometry, new THREE.MeshPhongMaterial({
color: new THREE.Color(TABLE_COLORS.cloth),
specular: 0x404040,
shininess: 20,
shininess: 10,
shading: THREE.SmoothShading
}));

Expand All @@ -42,7 +42,7 @@ var Table = function () {
var mesh = new THREE.Mesh(geometry, new THREE.MeshPhongMaterial({
color: new THREE.Color(0x7a5230),
specular: 0x404040,
shininess: 20,
shininess: 100,
shading: THREE.SmoothShading
}));

Expand Down
9 changes: 7 additions & 2 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ var debug = false; // if true then collision wireframes are drawn

var progressBar;

var stats = new Stats();
stats.setMode( 0 ); // 0: fps, 1: ms, 2: mb

var textureLoader = new THREE.TextureLoader();
THREE.DefaultLoadingManager.onProgress = function (item, loaded, total) {
if (typeof progressBar !== 'undefined') {
Expand Down Expand Up @@ -123,8 +126,8 @@ function setCollisionBehaviour() {
}

function draw() {
requestAnimationFrame(draw);

stats.begin();
// Controls
controls.target.copy(game.balls[0].mesh.position);
controls.update();
Expand All @@ -136,6 +139,8 @@ function draw() {
var dt = clock.getDelta();
game.tick(dt);

stats.end();
requestAnimationFrame(draw);
renderer.render(scene, camera); // We render our scene with our camera
}

Expand Down
5 changes: 5 additions & 0 deletions lib/stats.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -265,3 +265,11 @@
.player.unknown span:before {
content: '?';
}


#stats {
position: absolute;
top: 420px;
left: 810px;
z-index: 1;
}

0 comments on commit 0f527d6

Please sign in to comment.