diff --git a/Sources/ScenesShell/Block.swift b/Sources/ScenesShell/Block.swift index 6e5a5cf..a9ad271 100644 --- a/Sources/ScenesShell/Block.swift +++ b/Sources/ScenesShell/Block.swift @@ -12,6 +12,8 @@ class Block { var breaking = false var hardness : Int var isVisible = true + + var sidesToRender : [String] = [] func updateBlock() { switch type{ @@ -117,7 +119,7 @@ class Block { let blockColor = Color(red:UInt8(Double(color.red) * timeOfDayMultiplier), green:UInt8(Double(color.green) * timeOfDayMultiplier), blue:UInt8(Double(color.blue) * timeOfDayMultiplier)) - Cube(center:location.convertToDouble()).renderCube(camera:camera, canvas:canvas, color:blockColor, outline:selected) + Cube(center:location.convertToDouble(), sidesToRender:sidesToRender).renderCube(camera:camera, canvas:canvas, color:blockColor, outline:selected) } else { var colorMultiplier = 0.0 @@ -128,7 +130,7 @@ class Block { let redBreak = UInt8(Double(color.red) * colorMultiplier * timeOfDayMultiplier) let greenBreak = UInt8(Double(color.green) * colorMultiplier * timeOfDayMultiplier) let blueBreak = UInt8(Double(color.blue) * colorMultiplier * timeOfDayMultiplier) - Cube(center:location.convertToDouble()).renderCube(camera:camera, canvas:canvas, color:Color(red:redBreak, green:greenBreak, blue:blueBreak), outline:selected) + Cube(center:location.convertToDouble(), sidesToRender:sidesToRender).renderCube(camera:camera, canvas:canvas, color:Color(red:redBreak, green:greenBreak, blue:blueBreak), outline:selected) self.breaking = false } } diff --git a/Sources/ScenesShell/Cube.swift b/Sources/ScenesShell/Cube.swift index 49d0c95..e883679 100644 --- a/Sources/ScenesShell/Cube.swift +++ b/Sources/ScenesShell/Cube.swift @@ -4,21 +4,35 @@ import Scenes class Cube { var center : Point3d var size : Double + var sidesToRender : [String] = [] - init(center:Point3d, size:Double=1.0) { + init(center:Point3d, size:Double=1.0, sidesToRender:[String]=["+x", "-x", "+y", "-y", "+z", "-z"]) { self.center = center self.size = size + self.sidesToRender = sidesToRender } func getSquares() -> [Square] { //get squares for sides of the cube var sides : [Square] = [] - sides.append(Square(center:Point3d(x:center.x+(size/2),y:center.y,z:center.z), axis:"x", size:size)) - sides.append(Square(center:Point3d(x:center.x-(size/2),y:center.y,z:center.z), axis:"x", size:size)) - sides.append(Square(center:Point3d(x:center.x,y:center.y+(size/2),z:center.z), axis:"y", size:size)) - sides.append(Square(center:Point3d(x:center.x,y:center.y-(size/2),z:center.z), axis:"y", size:size)) - sides.append(Square(center:Point3d(x:center.x,y:center.y,z:center.z+(size/2)), axis:"z", size:size)) - sides.append(Square(center:Point3d(x:center.x,y:center.y,z:center.z-(size/2)), axis:"z", size:size)) + if sidesToRender.contains("+x") { + sides.append(Square(center:Point3d(x:center.x+(size/2),y:center.y,z:center.z), axis:"x", size:size)) + } + if sidesToRender.contains("-x") { + sides.append(Square(center:Point3d(x:center.x-(size/2),y:center.y,z:center.z), axis:"x", size:size)) + } + if sidesToRender.contains("+y") { + sides.append(Square(center:Point3d(x:center.x,y:center.y+(size/2),z:center.z), axis:"y", size:size)) + } + if sidesToRender.contains("-y") { + sides.append(Square(center:Point3d(x:center.x,y:center.y-(size/2),z:center.z), axis:"y", size:size)) + } + if sidesToRender.contains("+z") { + sides.append(Square(center:Point3d(x:center.x,y:center.y,z:center.z+(size/2)), axis:"z", size:size)) + } + if sidesToRender.contains("-z") { + sides.append(Square(center:Point3d(x:center.x,y:center.y,z:center.z-(size/2)), axis:"z", size:size)) + } return sides } diff --git a/Sources/ScenesShell/NewWorld.swift b/Sources/ScenesShell/NewWorld.swift index d9354d2..8b101cd 100644 --- a/Sources/ScenesShell/NewWorld.swift +++ b/Sources/ScenesShell/NewWorld.swift @@ -117,6 +117,7 @@ class SimpleWorld { private func nearbyBlocks(cameraPosition:Point3d) -> [Block] { var output : [Block] = [] var workingArray : [Double] = [] + var sidesRendered = 0 for y in verticalInBounds(Int(cameraPosition.y)-renderDistance) ... verticalInBounds(Int(cameraPosition.y)+renderDistance) { for x in horizontalInBounds(Int(cameraPosition.x)-renderDistance) ... horizontalInBounds(Int(cameraPosition.x)+renderDistance) { @@ -125,15 +126,16 @@ class SimpleWorld { if block.isVisible && block.type != "air" { output.append(block) workingArray.append(block.location.convertToDouble().distanceFrom(point:cameraPosition)) + sidesRendered += block.sidesToRender.count } } } } - if output.count > 448 && renderDistance > 2 { + if sidesRendered > 1800 && renderDistance > 2 { renderDistance -= 1 } - if output.count < 320 && renderDistance < 12 { + if sidesRendered < 1500 && renderDistance < 32 { renderDistance += 1 } @@ -163,6 +165,10 @@ class SimpleWorld { updateNeighborVisibility(at:at) } } + + private func updateBlockSidesToRender(at:BlockPoint3d, to:[String]) { + Blocks[verticalInBounds(at.y)][horizontalInBounds(at.x)][horizontalInBounds(at.z)].sidesToRender = to + } private func createTree(at:BlockPoint3d) { let trunkHeight = Int.random(in:3...5) @@ -190,18 +196,21 @@ class SimpleWorld { public func updateBlockVisibility(at:BlockPoint3d) { var visible = false - if getBlock(at:BlockPoint3d(x:at.x+1, y:at.y, z:at.z)).type == "air" {visible = true} - if getBlock(at:BlockPoint3d(x:at.x-1, y:at.y, z:at.z)).type == "air" {visible = true} - if getBlock(at:BlockPoint3d(x:at.x, y:at.y+1, z:at.z)).type == "air" {visible = true} - if getBlock(at:BlockPoint3d(x:at.x, y:at.y-1, z:at.z)).type == "air" {visible = true} - if getBlock(at:BlockPoint3d(x:at.x, y:at.y, z:at.z+1)).type == "air" {visible = true} - if getBlock(at:BlockPoint3d(x:at.x, y:at.y, z:at.z-1)).type == "air" {visible = true} + var sidesToRender : [String] = [] + if getBlock(at:BlockPoint3d(x:at.x+1, y:at.y, z:at.z)).type == "air" {visible = true; sidesToRender.append("+x")} + if getBlock(at:BlockPoint3d(x:at.x-1, y:at.y, z:at.z)).type == "air" {visible = true; sidesToRender.append("-x")} + if getBlock(at:BlockPoint3d(x:at.x, y:at.y+1, z:at.z)).type == "air" {visible = true; sidesToRender.append("+y")} + if getBlock(at:BlockPoint3d(x:at.x, y:at.y-1, z:at.z)).type == "air" {visible = true; sidesToRender.append("-y")} + if getBlock(at:BlockPoint3d(x:at.x, y:at.y, z:at.z+1)).type == "air" {visible = true; sidesToRender.append("+z")} + if getBlock(at:BlockPoint3d(x:at.x, y:at.y, z:at.z-1)).type == "air" {visible = true; sidesToRender.append("-z")} if visible { - setBlock(at:BlockPoint3d(x:at.x, y:at.y, z:at.z), to:"visible") + setBlock(at:at, to:"visible") } else { - setBlock(at:BlockPoint3d(x:at.x, y:at.y, z:at.z), to:"invisible") + setBlock(at:at, to:"invisible") } + + updateBlockSidesToRender(at:at, to:sidesToRender) } public func updateNeighborVisibility(at:BlockPoint3d) { @@ -289,7 +298,7 @@ class SimpleWorld { canvas.render(FillStyle(color:Color(red:255, green:255, blue:0))) canvas.render(splash) - let version = Text(location:Point(x:0, y:(canvas.canvasSize!.height)), text:" v0.3.2") + let version = Text(location:Point(x:0, y:(canvas.canvasSize!.height)), text:" v0.3.3") version.font = "\((canvas.canvasSize!.height/64))pt Arial" version.baseline = .bottom version.alignment = .left diff --git a/Sources/ScenesShell/Path3d.swift b/Sources/ScenesShell/Path3d.swift index 2dfbe46..ab66de4 100644 --- a/Sources/ScenesShell/Path3d.swift +++ b/Sources/ScenesShell/Path3d.swift @@ -46,14 +46,14 @@ class Path3d { canvas.render(StrokeStyle(color:Color(red:64, green:64, blue:64))) } else { var colorOutline = (red:color.red, green:color.green, blue:color.blue) - if color.red > 0 { - colorOutline.red -= 1 + if color.red >= 4 { + colorOutline.red -= 4 } - if color.green > 0 { - colorOutline.green -= 1 + if color.green >= 4 { + colorOutline.green -= 4 } - if color.blue > 0 { - colorOutline.blue -= 1 + if color.blue >= 4 { + colorOutline.blue -= 4 } canvas.render(StrokeStyle(color:Color(red:colorOutline.red, green:colorOutline.green, blue:colorOutline.blue))) } diff --git a/Sources/ScenesShell/Splash.swift b/Sources/ScenesShell/Splash.swift index fa9224a..bc327ec 100644 --- a/Sources/ScenesShell/Splash.swift +++ b/Sources/ScenesShell/Splash.swift @@ -11,6 +11,15 @@ public func splashText() -> String { "No more walking through walls!", "The IGIS servers are on fire right now!", "Now with better Render Distance!"] + + let quotes = ["\"I'm a doctor, not a world-builder!\" -McCoy, early 2300s", + "\"How do you have so much free time?\" -Garrett, 2021", + "\"Eat any good books lately?\" -Q, late 2300s", + "\"Stop playing Minecraft in class\" -All of my teachers, 2021"] - return text[Int.random(in:0..