implement main menu, implement textfield widget, implement create world screen, implement splash screen
This commit is contained in:
@@ -21,17 +21,17 @@ export default class WorldRenderer {
|
||||
this.tessellator = new Tessellator();
|
||||
|
||||
// Load terrain texture
|
||||
this.textureTerrain = new THREE.TextureLoader().load('src/resources/terrain/terrain.png');
|
||||
this.textureTerrain = minecraft.getThreeTexture('terrain/terrain.png');
|
||||
this.textureTerrain.magFilter = THREE.NearestFilter;
|
||||
this.textureTerrain.minFilter = THREE.NearestFilter;
|
||||
|
||||
// Load sun texture
|
||||
this.textureSun = new THREE.TextureLoader().load('src/resources/terrain/sun.png');
|
||||
this.textureSun = minecraft.getThreeTexture('terrain/sun.png');
|
||||
this.textureSun.magFilter = THREE.NearestFilter;
|
||||
this.textureSun.minFilter = THREE.NearestFilter;
|
||||
|
||||
// Load moon texture
|
||||
this.textureMoon = new THREE.TextureLoader().load('src/resources/terrain/moon.png');
|
||||
this.textureMoon = minecraft.getThreeTexture('terrain/moon.png');
|
||||
this.textureMoon.magFilter = THREE.NearestFilter;
|
||||
this.textureMoon.minFilter = THREE.NearestFilter;
|
||||
|
||||
@@ -540,13 +540,6 @@ export default class WorldRenderer {
|
||||
let world = this.minecraft.world;
|
||||
let renderDistance = WorldRenderer.RENDER_DISTANCE;
|
||||
|
||||
// Load chunks
|
||||
for (let x = -renderDistance + 1; x < renderDistance; x++) {
|
||||
for (let z = -renderDistance + 1; z < renderDistance; z++) {
|
||||
world.getChunkAt(cameraChunkX + x, cameraChunkZ + z);
|
||||
}
|
||||
}
|
||||
|
||||
// Update chunks
|
||||
for (let [index, chunk] of world.chunks) {
|
||||
let distanceX = Math.abs(cameraChunkX - chunk.x);
|
||||
@@ -563,7 +556,7 @@ export default class WorldRenderer {
|
||||
let chunkSection = chunk.sections[y];
|
||||
|
||||
// Is in camera view check
|
||||
if (this.frustum.intersectsBox(chunkSection.boundingBox)) {
|
||||
if (this.frustum.intersectsBox(chunkSection.boundingBox) && !chunkSection.isEmpty()) {
|
||||
// Make section visible
|
||||
chunkSection.group.visible = true;
|
||||
|
||||
@@ -590,7 +583,7 @@ export default class WorldRenderer {
|
||||
// TODO Implement chunk unloading
|
||||
//let index = chunk.x + (chunk.z << 16);
|
||||
//world.chunks.delete(index);
|
||||
//world.group.add(chunk.group);
|
||||
//world.group.remove(chunk.group);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -602,8 +595,15 @@ export default class WorldRenderer {
|
||||
return distance1 - distance2;
|
||||
});
|
||||
|
||||
// Rebuild 16 chunk sections per frame (An entire chunk)
|
||||
for (let i = 0; i < 16; i++) {
|
||||
// Update render order of chunks
|
||||
world.group.children.sort((a, b) => {
|
||||
let distance1 = Math.floor(Math.pow(a.chunkX - cameraChunkX, 2) + Math.pow(a.chunkZ - cameraChunkZ, 2));
|
||||
let distance2 = Math.floor(Math.pow(b.chunkX - cameraChunkX, 2) + Math.pow(b.chunkZ - cameraChunkZ, 2));
|
||||
return distance2 - distance1;
|
||||
});
|
||||
|
||||
// Rebuild 8 chunk sections each frame
|
||||
for (let i = 0; i < 8; i++) {
|
||||
if (this.chunkSectionUpdateQueue.length !== 0) {
|
||||
let chunkSection = this.chunkSectionUpdateQueue.shift();
|
||||
if (chunkSection != null) {
|
||||
@@ -612,13 +612,6 @@ export default class WorldRenderer {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update render order of chunks
|
||||
world.group.children.sort((a, b) => {
|
||||
let distance1 = Math.floor(Math.pow(a.chunkX - cameraChunkX, 2) + Math.pow(a.chunkZ - cameraChunkZ, 2));
|
||||
let distance2 = Math.floor(Math.pow(b.chunkX - cameraChunkX, 2) + Math.pow(b.chunkZ - cameraChunkZ, 2));
|
||||
return distance2 - distance1;
|
||||
});
|
||||
}
|
||||
|
||||
rebuildAll() {
|
||||
@@ -775,4 +768,12 @@ export default class WorldRenderer {
|
||||
stack.rotateX(MathHelper.toRadians(Math.abs(Math.cos(walked * Math.PI - 0.2) * yaw) * 5.0));
|
||||
stack.rotateX(MathHelper.toRadians(pitch));
|
||||
}
|
||||
|
||||
reset() {
|
||||
if (this.minecraft.world !== null) {
|
||||
this.scene.remove(this.minecraft.world.group);
|
||||
}
|
||||
this.webRenderer.clear();
|
||||
this.overlay.clear();
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ export default class PlayerRenderer extends EntityRenderer {
|
||||
this.worldRenderer = worldRenderer;
|
||||
|
||||
// Load character texture
|
||||
this.textureCharacter = new THREE.TextureLoader().load('src/resources/char.png');
|
||||
this.textureCharacter = worldRenderer.minecraft.getThreeTexture('char.png');
|
||||
this.textureCharacter.magFilter = THREE.NearestFilter;
|
||||
this.textureCharacter.minFilter = THREE.NearestFilter;
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import Gui from "../../gui/Gui.js";
|
||||
import MathHelper from "../../../util/MathHelper.js";
|
||||
|
||||
export default class FontRenderer {
|
||||
|
||||
@@ -47,17 +48,18 @@ export default class FontRenderer {
|
||||
}
|
||||
|
||||
drawString(stack, string, x, y, color = -1) {
|
||||
if (!this.isSafari) { // TODO Fix brightness filter on Safari
|
||||
this.drawStringRaw(stack, string, x + 1, y + 1, (color & 0xFCFCFC) >> 2, true);
|
||||
if (!this.isSafari) { // TODO Fix filter on Safari
|
||||
this.drawStringRaw(stack, string, x + 1, y + 1, color, true);
|
||||
}
|
||||
this.drawStringRaw(stack, string, x, y, color, false);
|
||||
this.drawStringRaw(stack, string, x, y, color);
|
||||
}
|
||||
|
||||
drawStringRaw(stack, string, x, y, color = -1, isShadow = true) {
|
||||
drawStringRaw(stack, string, x, y, color = -1, isShadow = false) {
|
||||
stack.save();
|
||||
|
||||
if (isShadow) {
|
||||
stack.filter = "brightness(20%)";
|
||||
// Set color
|
||||
if (color !== -1 || isShadow) {
|
||||
this.setColor(stack, color, isShadow);
|
||||
}
|
||||
|
||||
// For each character
|
||||
@@ -71,7 +73,7 @@ export default class FontRenderer {
|
||||
let nextCharacter = string[i + 1];
|
||||
|
||||
// Change color of string
|
||||
//this.setColor(this.getColorOfCharacter(nextCharacter), isShadow);
|
||||
this.setColor(stack, this.getColorOfCharacter(nextCharacter), isShadow);
|
||||
|
||||
// Skip the color code for rendering
|
||||
i += 1;
|
||||
@@ -138,4 +140,32 @@ export default class FontRenderer {
|
||||
canvas.getContext('2d').drawImage(img, 0, 0, img.width, img.height);
|
||||
return canvas.getContext('2d').getImageData(0, 0, img.width, img.height).data;
|
||||
}
|
||||
|
||||
setColor(stack, color, isShadow = false) {
|
||||
if (isShadow) {
|
||||
color = (color & 0xFCFCFC) >> 2;
|
||||
}
|
||||
|
||||
let r = (color & 0xFF0000) >> 16;
|
||||
let g = (color & 0x00FF00) >> 8;
|
||||
let b = (color & 0x0000FF);
|
||||
let hsv = MathHelper.rgb2hsv(r, g, b);
|
||||
let hue = hsv[0] + 270;
|
||||
let saturation = hsv[1];
|
||||
let brightness = hsv[2] / 255 * 100;
|
||||
|
||||
// TODO fix colors
|
||||
let saturate1 = saturation * 1000;
|
||||
let saturate2 = saturation * 5000;
|
||||
let saturate3 = saturation * 100;
|
||||
|
||||
if (!this.isSafari) { // TODO Fix filter on Safari
|
||||
stack.filter = "sepia()"
|
||||
+ " saturate(" + saturate1 + "%)"
|
||||
+ " hue-rotate(" + hue + "deg)"
|
||||
+ " saturate(" + saturate2 + "%)"
|
||||
+ " brightness(" + brightness + "%)"
|
||||
+ " saturate(" + saturate3 + "%)";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -87,4 +87,12 @@ export default class ItemRenderer {
|
||||
}
|
||||
this.itemInHand = null;
|
||||
}
|
||||
|
||||
reset() {
|
||||
for (let i in this.items) {
|
||||
this.scene.remove(this.items[i].group);
|
||||
}
|
||||
this.items = [];
|
||||
this.webRenderer.clear();
|
||||
}
|
||||
}
|
||||
@@ -6,9 +6,11 @@ export default class ScreenRenderer {
|
||||
}
|
||||
|
||||
initialize() {
|
||||
this.resolution = this.minecraft.isInGame() ? 1 : this.minecraft.window.scaleFactor; // Increase resolution for the splash text
|
||||
|
||||
// Update camera size
|
||||
this.window.canvas2d.width = this.window.width;
|
||||
this.window.canvas2d.height = this.window.height;
|
||||
this.window.canvas2d.width = this.window.width * this.resolution;
|
||||
this.window.canvas2d.height = this.window.height * this.resolution;
|
||||
|
||||
// Get context stack of 2d canvas
|
||||
this.stack2d = this.window.canvas2d.getContext('2d');
|
||||
@@ -21,18 +23,31 @@ export default class ScreenRenderer {
|
||||
let mouseX = this.minecraft.window.mouseX;
|
||||
let mouseY = this.minecraft.window.mouseY;
|
||||
|
||||
this.stack2d.save();
|
||||
this.stack2d.scale(this.resolution, this.resolution, this.resolution);
|
||||
|
||||
// Reset 2d canvas
|
||||
this.stack2d.clearRect(0, 0, this.window.width, this.window.height);
|
||||
|
||||
// Render in-game overlay
|
||||
if (this.minecraft.loadingScreen === null) {
|
||||
this.minecraft.ingameOverlay.render(this.stack2d, mouseX, mouseY, partialTicks);
|
||||
try {
|
||||
// Render in-game overlay
|
||||
if (this.minecraft.isInGame() && this.minecraft.loadingScreen === null) {
|
||||
this.minecraft.ingameOverlay.render(this.stack2d, mouseX, mouseY, partialTicks);
|
||||
}
|
||||
|
||||
// Render current screen
|
||||
if (this.minecraft.currentScreen !== null) {
|
||||
this.minecraft.currentScreen.drawScreen(this.stack2d, mouseX, mouseY, partialTicks)
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
|
||||
// Render current screen
|
||||
if (!(this.minecraft.currentScreen === null)) {
|
||||
this.minecraft.currentScreen.drawScreen(this.stack2d, mouseX, mouseY, partialTicks);
|
||||
}
|
||||
this.stack2d.restore();
|
||||
}
|
||||
|
||||
reset() {
|
||||
this.stack2d.clearRect(0, 0, this.window.width, this.window.height);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user