mirror of
https://gitlab.com/arnekeller/tunnel-racer.git
synced 2024-11-21 22:44:59 +00:00
Reduce render resolution on low FPS
This commit is contained in:
parent
a487890d83
commit
6d3a9f4d3a
@ -10,7 +10,7 @@
|
|||||||
<body>
|
<body>
|
||||||
<div id="info">Score: <span id="score">0</span></div>
|
<div id="info">Score: <span id="score">0</span></div>
|
||||||
<button id="start">Start</button>
|
<button id="start">Start</button>
|
||||||
<div id="version">Version 1.1</div>
|
<div id="version">Version 1.2c</div>
|
||||||
|
|
||||||
<script src="./gyronorm.complete.min.js"></script>
|
<script src="./gyronorm.complete.min.js"></script>
|
||||||
<script src="./three.min.js"></script>
|
<script src="./three.min.js"></script>
|
||||||
|
7
game.js
7
game.js
@ -115,6 +115,7 @@ const spheres = [];
|
|||||||
// wall segments
|
// wall segments
|
||||||
const borders = [];
|
const borders = [];
|
||||||
let time = Date.now() / 1000.0;
|
let time = Date.now() / 1000.0;
|
||||||
|
let averageFps = 60.0;
|
||||||
|
|
||||||
function logger(text) {
|
function logger(text) {
|
||||||
console.log(text);
|
console.log(text);
|
||||||
@ -216,7 +217,7 @@ init_gn();
|
|||||||
// setup three.js: materials, geometries, scene, lighting and camera
|
// setup three.js: materials, geometries, scene, lighting and camera
|
||||||
let scene, renderer;
|
let scene, renderer;
|
||||||
scene = new THREE.Scene();
|
scene = new THREE.Scene();
|
||||||
const camera = new THREE.PerspectiveCamera(70, window.innerWidth / window.innerHeight, 0.1, 10000);
|
const camera = new THREE.PerspectiveCamera(70, window.innerWidth / window.innerHeight, 0.1, 5000);
|
||||||
|
|
||||||
// obstacle geometry and material
|
// obstacle geometry and material
|
||||||
const geometrySphere = new THREE.SphereGeometry(11, 32, 32);
|
const geometrySphere = new THREE.SphereGeometry(11, 32, 32);
|
||||||
@ -348,6 +349,7 @@ function animate() {
|
|||||||
let now = Date.now() / 1000.0;
|
let now = Date.now() / 1000.0;
|
||||||
let delta = now - time;
|
let delta = now - time;
|
||||||
time = now;
|
time = now;
|
||||||
|
averageFps = (4 * averageFps + 1.0 / delta ) / 5.0;
|
||||||
|
|
||||||
requestAnimationFrame(animate);
|
requestAnimationFrame(animate);
|
||||||
|
|
||||||
@ -439,6 +441,9 @@ function animate() {
|
|||||||
removed = 0;
|
removed = 0;
|
||||||
document.getElementById("score").innerText = score;
|
document.getElementById("score").innerText = score;
|
||||||
}
|
}
|
||||||
|
if (averageFps < 30.0 && renderer.getPixelRatio() == window.devicePixelRatio) {
|
||||||
|
renderer.setPixelRatio(window.devicePixelRatio / 2);
|
||||||
|
}
|
||||||
|
|
||||||
// create new wall segments on demand
|
// create new wall segments on demand
|
||||||
if (borders.length == 0 || borders[borders.length - 1].position.z - camera.position.z > -1200) {
|
if (borders.length == 0 || borders[borders.length - 1].position.z - camera.position.z > -1200) {
|
||||||
|
Loading…
Reference in New Issue
Block a user