implement stats.min.js, improve fps
This commit is contained in:
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
// stats.js - http://github.com/mrdoob/stats.js
|
||||
(function(f,e){"object"===typeof exports&&"undefined"!==typeof module?module.exports=e():"function"===typeof define&&define.amd?define(e):f.Stats=e()})(this,function(){var f=function(){function e(a){c.appendChild(a.dom);return a}function u(a){for(var d=0;d<c.children.length;d++)c.children[d].style.display=d===a?"block":"none";l=a}var l=0,c=document.createElement("div");c.style.cssText="position:fixed;top:0;left:0;cursor:pointer;opacity:0.9;z-index:10000";c.addEventListener("click",function(a){a.preventDefault();
|
||||
u(++l%c.children.length)},!1);var k=(performance||Date).now(),g=k,a=0,r=e(new f.Panel("FPS","#0ff","#002")),h=e(new f.Panel("MS","#0f0","#020"));if(self.performance&&self.performance.memory)var t=e(new f.Panel("MB","#f08","#201"));u(0);return{REVISION:16,dom:c,addPanel:e,showPanel:u,begin:function(){k=(performance||Date).now()},end:function(){a++;var c=(performance||Date).now();h.update(c-k,200);if(c>=g+1E3&&(r.update(1E3*a/(c-g),100),g=c,a=0,t)){var d=performance.memory;t.update(d.usedJSHeapSize/
|
||||
1048576,d.jsHeapSizeLimit/1048576)}return c},update:function(){k=this.end()},domElement:c,setMode:u}};f.Panel=function(e,f,l){var c=Infinity,k=0,g=Math.round,a=g(window.devicePixelRatio||1),r=80*a,h=48*a,t=3*a,v=2*a,d=3*a,m=15*a,n=74*a,p=30*a,q=document.createElement("canvas");q.width=r;q.height=h;q.style.cssText="width:80px;height:48px";var b=q.getContext("2d");b.font="bold "+9*a+"px Helvetica,Arial,sans-serif";b.textBaseline="top";b.fillStyle=l;b.fillRect(0,0,r,h);b.fillStyle=f;b.fillText(e,t,v);
|
||||
b.fillRect(d,m,n,p);b.fillStyle=l;b.globalAlpha=.9;b.fillRect(d,m,n,p);return{dom:q,update:function(h,w){c=Math.min(c,h);k=Math.max(k,h);b.fillStyle=l;b.globalAlpha=1;b.fillRect(0,0,r,m);b.fillStyle=f;b.fillText(g(h)+" "+e+" ("+g(c)+"-"+g(k)+")",t,v);b.drawImage(q,d+a,m,n-a,p,d,m,n-a,p);b.fillRect(d+n-a,m,a,p);b.fillStyle=l;b.globalAlpha=.9;b.fillRect(d+n-a,m,a,g((1-h/w)*p))}}};return f});
|
||||
@@ -8,9 +8,16 @@ window.GameWindow = class {
|
||||
this.mouseMotionY = 0;
|
||||
this.mouseLocked = false;
|
||||
|
||||
let wrapper = document.getElementById(this.canvasWrapperId);
|
||||
|
||||
// Stats
|
||||
this.stats = new Stats()
|
||||
this.stats.showPanel(1);
|
||||
wrapper.appendChild(this.stats.dom);
|
||||
|
||||
// Add web renderer canvas to wrapper
|
||||
let canvas = renderer.canvasElement;
|
||||
document.getElementById(this.canvasWrapperId).appendChild(canvas);
|
||||
wrapper.appendChild(canvas);
|
||||
|
||||
// Init
|
||||
this.onResize();
|
||||
|
||||
@@ -42,6 +42,8 @@ window.Minecraft = class {
|
||||
}
|
||||
|
||||
onLoop() {
|
||||
this.window.stats.begin();
|
||||
|
||||
// Update the timer
|
||||
this.timer.advanceTime();
|
||||
|
||||
@@ -63,6 +65,8 @@ window.Minecraft = class {
|
||||
this.lastTime += 1000;
|
||||
this.frames = 0;
|
||||
}
|
||||
|
||||
this.window.stats.end();
|
||||
}
|
||||
|
||||
onRender(partialTicks) {
|
||||
@@ -84,27 +88,29 @@ window.Minecraft = class {
|
||||
}
|
||||
|
||||
onMouseClicked(button) {
|
||||
let hitResult = this.player.rayTrace(5, this.timer.partialTicks);
|
||||
if (this.window.mouseLocked) {
|
||||
let hitResult = this.player.rayTrace(5, this.timer.partialTicks);
|
||||
|
||||
// Destroy block
|
||||
if (button === 0) {
|
||||
if (hitResult != null) {
|
||||
this.world.setBlockAt(hitResult.x, hitResult.y, hitResult.z, 0);
|
||||
// Destroy block
|
||||
if (button === 0) {
|
||||
if (hitResult != null) {
|
||||
this.world.setBlockAt(hitResult.x, hitResult.y, hitResult.z, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Place block
|
||||
if (button === 2) {
|
||||
if (hitResult != null) {
|
||||
let x = hitResult.x + hitResult.face.x;
|
||||
let y = hitResult.y + hitResult.face.y;
|
||||
let z = hitResult.z + hitResult.face.z;
|
||||
// Place block
|
||||
if (button === 2) {
|
||||
if (hitResult != null) {
|
||||
let x = hitResult.x + hitResult.face.x;
|
||||
let y = hitResult.y + hitResult.face.y;
|
||||
let z = hitResult.z + hitResult.face.z;
|
||||
|
||||
let placedBoundingBox = new BoundingBox(x, y, z, x + 1, y + 1, z + 1);
|
||||
let placedBoundingBox = new BoundingBox(x, y, z, x + 1, y + 1, z + 1);
|
||||
|
||||
// Don't place blocks if the player is standing there
|
||||
if (!placedBoundingBox.intersects(this.player.boundingBox)) {
|
||||
this.world.setBlockAt(x, y, z, 1);
|
||||
// Don't place blocks if the player is standing there
|
||||
if (!placedBoundingBox.intersects(this.player.boundingBox)) {
|
||||
this.world.setBlockAt(x, y, z, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,14 +16,9 @@ window.BlockRenderer = class {
|
||||
|
||||
// Check if face is hidden by other block
|
||||
if (block.shouldRenderFace(world, x, y, z, face)) {
|
||||
// Start drawing
|
||||
this.tessellator.startDrawing();
|
||||
|
||||
// Render face
|
||||
this.renderFace(world, block, boundingBox, face, x, y, z);
|
||||
|
||||
// Draw
|
||||
this.tessellator.draw(group);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,8 +6,6 @@ window.Tessellator = class {
|
||||
side: THREE.BackSide,
|
||||
transparent: true
|
||||
});
|
||||
|
||||
this.index = new THREE.BufferAttribute(new Uint32Array([0, 2, 1, 0, 3, 2]), 1);
|
||||
}
|
||||
|
||||
bindTexture(texture) {
|
||||
@@ -50,7 +48,19 @@ window.Tessellator = class {
|
||||
geometry.setAttribute('position', new THREE.BufferAttribute(new Float32Array(this.vertices), 3));
|
||||
geometry.setAttribute('color', new THREE.BufferAttribute(new Float32Array(this.colors), 3));
|
||||
geometry.setAttribute('uv', new THREE.BufferAttribute(new Float32Array(this.uv), 2));
|
||||
geometry.setIndex(this.index);
|
||||
|
||||
// Create index array
|
||||
let index = [];
|
||||
let verticesPerFace = 4;
|
||||
for (let i = 0; i < this.addedVertices / verticesPerFace; i++) {
|
||||
index.push(i * verticesPerFace + 0);
|
||||
index.push(i * verticesPerFace + 2);
|
||||
index.push(i * verticesPerFace + 1);
|
||||
index.push(i * verticesPerFace + 0);
|
||||
index.push(i * verticesPerFace + 3);
|
||||
index.push(i * verticesPerFace + 2);
|
||||
}
|
||||
geometry.setIndex(new THREE.BufferAttribute(new Uint32Array(index), 1));
|
||||
|
||||
let mesh = new THREE.Mesh(geometry, this.material);
|
||||
group.matrixAutoUpdate = false;
|
||||
|
||||
@@ -26,6 +26,10 @@ window.ChunkSection = class {
|
||||
this.dirty = false;
|
||||
this.group.clear();
|
||||
|
||||
// Start drawing chunk section
|
||||
let tessellator = renderer.blockRenderer.tessellator;
|
||||
tessellator.startDrawing();
|
||||
|
||||
for (let x = 0; x < ChunkSection.SIZE; x++) {
|
||||
for (let y = 0; y < ChunkSection.SIZE; y++) {
|
||||
for (let z = 0; z < ChunkSection.SIZE; z++) {
|
||||
@@ -42,6 +46,9 @@ window.ChunkSection = class {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Draw chunk section
|
||||
tessellator.draw(this.group);
|
||||
}
|
||||
|
||||
getBlockAt(x, y, z) {
|
||||
|
||||
@@ -45,6 +45,7 @@ function updatePreStatus(message) {
|
||||
loadScripts([
|
||||
// Dependencies
|
||||
"libraries/three.min.js",
|
||||
"libraries/stats.min.js",
|
||||
|
||||
// Minecraft Source
|
||||
"src/js/net/minecraft/util/EnumBlockFace.js",
|
||||
|
||||
Reference in New Issue
Block a user