From bb56ba08967cc12d9ff895e4e10893a396cfff27 Mon Sep 17 00:00:00 2001 From: Joshua Sigona Date: Mon, 6 Dec 2021 07:13:34 +0900 Subject: [PATCH] save --- src/sig/Panel.java | 15 +------- src/sig/SigRenderer.java | 5 +-- src/sig/utils/DrawUtils.java | 66 +++++++++++++++++++++++++++++++----- 3 files changed, 61 insertions(+), 25 deletions(-) diff --git a/src/sig/Panel.java b/src/sig/Panel.java index fe38e44..821c03d 100644 --- a/src/sig/Panel.java +++ b/src/sig/Panel.java @@ -23,7 +23,7 @@ import java.awt.GraphicsConfiguration; import java.awt.Toolkit; import java.util.Queue; -public class Panel extends JPanel implements Runnable { +public class Panel extends JPanel{ long startTime = System.nanoTime(); long endTime = System.nanoTime(); public int pixel[]; @@ -32,7 +32,6 @@ public class Panel extends JPanel implements Runnable { private Image imageBuffer; private MemoryImageSource mImageProducer; private ColorModel cm; - private Thread thread; Thread[] workerThread = new Thread[9]; String[][] keySets = new String[9][]; ConcurrentLinkedQueue newTris = new ConcurrentLinkedQueue<>(); @@ -46,7 +45,6 @@ public class Panel extends JPanel implements Runnable { public Panel() { super(true); - thread = new Thread(this, "MyPanel Thread"); } /** @@ -77,9 +75,6 @@ public class Panel extends JPanel implements Runnable { mImageProducer.setAnimated(true); mImageProducer.setFullBufferUpdates(true); imageBuffer = Toolkit.getDefaultToolkit().createImage(mImageProducer); - if(thread.isInterrupted() || !thread.isAlive()){ - thread.start(); - } SigRenderer.depthBuffer = new float[width*height]; SigRenderer.depthBuffer_tri = new Triangle[width*height]; SigRenderer.translucencyBuffer = new boolean[width*height]; @@ -588,12 +583,4 @@ public class Panel extends JPanel implements Runnable { public boolean imageUpdate(Image image, int a, int b, int c, int d, int e) { return true; } - @Override - public void run() { - while (true) { - // request a JPanel re-drawing - repaint(); - try {Thread.sleep(5);} catch (InterruptedException e) {} - } - } } \ No newline at end of file diff --git a/src/sig/SigRenderer.java b/src/sig/SigRenderer.java index 00a7db6..c4d97f2 100644 --- a/src/sig/SigRenderer.java +++ b/src/sig/SigRenderer.java @@ -57,7 +57,7 @@ public class SigRenderer implements WindowFocusListener,KeyListener,MouseListene public static float fAspectRatio = (float)SCREEN_HEIGHT/SCREEN_WIDTH; public static Matrix matProj = Matrix.MakeProjection(fFov,fAspectRatio,fNear,fFar); - public static Vector vCamera = new Vector(31.5f,20f,31.5f); + public static Vector vCamera = new Vector(15.5f,20f,15.5f); public static final float cameraCollisionPadding = 0.2f; public static final float cameraHeight = 1.75f; @@ -402,6 +402,7 @@ public class SigRenderer implements WindowFocusListener,KeyListener,MouseListene for (int x=0;x<64;x++) { for (int z=0;z<64;z++) { addBlock(new Vector(x,0,z),Cube.class,BlockType.SOIL_WET,FacingDirection.SOUTH); + addBlock(new Vector(x,1,z),Plant.class,BlockType.valueOf("WHEAT_"+(r.nextInt(7))),FacingDirection.SOUTH); //addBlock(new Vector(x,1,z),Staircase.class,BlockType.JUNGLE_PLANK,FacingDirection.SOUTH); //addBlock(new Vector(x,2,z),Staircase.class,BlockType.SPRUCE_PLANK,FacingDirection.SOUTH); /*for (int y=1;ySigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+j]) { + if (tex_w>SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+j]&& + tex_w>SigRenderer.depthBuffer[(i+1)*SigRenderer.SCREEN_WIDTH+j]&& + tex_w>SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+(j+1)]&& + tex_w>SigRenderer.depthBuffer[(i+1)*SigRenderer.SCREEN_WIDTH+(j+1)]) { int col = texture.getColor(tex_u/tex_w,tex_v/tex_w,colorMult/255f); if (((col&0xFF000000)>>>24)!=0) { if (((col&0xFF000000)>>>24)!=255) { @@ -110,17 +113,38 @@ public class DrawUtils { SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+j] = tex_w; SigRenderer.depthBuffer_tri[i*SigRenderer.SCREEN_WIDTH+j] = ref.unmodifiedTri; SigRenderer.translucencyBuffer[i*SigRenderer.SCREEN_WIDTH+j] = true; + Draw(canvas,j+1,i,col); + SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+(j+1)] = tex_w; + SigRenderer.depthBuffer_tri[i*SigRenderer.SCREEN_WIDTH+(j+1)] = ref.unmodifiedTri; + SigRenderer.translucencyBuffer[i*SigRenderer.SCREEN_WIDTH+(j+1)] = true; + Draw(canvas,j,i+1,col); + SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+j] = tex_w; + SigRenderer.depthBuffer_tri[(i+1)*SigRenderer.SCREEN_WIDTH+j] = ref.unmodifiedTri; + SigRenderer.translucencyBuffer[(i+1)*SigRenderer.SCREEN_WIDTH+j] = true; + Draw(canvas,j+1,i+1,col); + SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+(j+1)] = tex_w; + SigRenderer.depthBuffer_tri[(i+1)*SigRenderer.SCREEN_WIDTH+(j+1)] = ref.unmodifiedTri; + SigRenderer.translucencyBuffer[(i+1)*SigRenderer.SCREEN_WIDTH+(j+1)] = true; } } else { if (rendering_state!=TRANSLUCENT_ONLY_RENDERING) { Draw(canvas,j,i,col); SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+j] = tex_w; SigRenderer.depthBuffer_tri[i*SigRenderer.SCREEN_WIDTH+j] = ref.unmodifiedTri; + Draw(canvas,j+1,i,col); + SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+(j+1)] = tex_w; + SigRenderer.depthBuffer_tri[i*SigRenderer.SCREEN_WIDTH+(j+1)] = ref.unmodifiedTri; + Draw(canvas,j,i+1,col); + SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+j] = tex_w; + SigRenderer.depthBuffer_tri[(i+1)*SigRenderer.SCREEN_WIDTH+j] = ref.unmodifiedTri; + Draw(canvas,j+1,i+1,col); + SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+(j+1)] = tex_w; + SigRenderer.depthBuffer_tri[(i+1)*SigRenderer.SCREEN_WIDTH+(j+1)] = ref.unmodifiedTri; } } } } - t+=tstep; + t+=tstep*4; } } } @@ -139,7 +163,7 @@ public class DrawUtils { if (dy1!=0) {dw1_step=dw1/((float)Math.abs(dy1));} if (dy1!=0) { - for (int i=y2;i<=y3;i++) { + for (int i=y2;i<=y3-3;i+=4) { int ax=(int)(x2+((float)(i-y2))*dax_step); int bx=(int)(x1+((float)(i-y1))*dbx_step); @@ -164,7 +188,7 @@ public class DrawUtils { float tstep = 1.0f/(float)(bx-ax); float t=0.0f; - for (int j=ax;j<=bx;j++) { + for (int j=ax;j<=bx-3;j+=4) { tex_u=(1.0f-t)*tex_su+t*tex_eu; tex_v=(1.0f-t)*tex_sv+t*tex_ev; tex_w=(1.0f-t)*tex_sw+t*tex_ew; @@ -176,7 +200,10 @@ public class DrawUtils { } } } - if (tex_w>SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+j]) { + if (tex_w>SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+j]&& + tex_w>SigRenderer.depthBuffer[(i+1)*SigRenderer.SCREEN_WIDTH+j]&& + tex_w>SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+(j+1)]&& + tex_w>SigRenderer.depthBuffer[(i+1)*SigRenderer.SCREEN_WIDTH+(j+1)]) { int col = texture.getColor(tex_u/tex_w,tex_v/tex_w,colorMult/255f); if (((col&0xFF000000)>>>24)!=0) { if (((col&0xFF000000)>>>24)!=255) { @@ -184,21 +211,42 @@ public class DrawUtils { rendering_state==NORMAL_RENDERING) { Draw(canvas,j,i,col); SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+j] = tex_w; + SigRenderer.translucencyBuffer[i*SigRenderer.SCREEN_WIDTH+j] = true; + Draw(canvas,j,i+1,col); + SigRenderer.depthBuffer[(i+1)*SigRenderer.SCREEN_WIDTH+j] = tex_w; + SigRenderer.translucencyBuffer[(i+1)*SigRenderer.SCREEN_WIDTH+j] = true; + Draw(canvas,j+1,i,col); + SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+(j+1)] = tex_w; + SigRenderer.translucencyBuffer[i*SigRenderer.SCREEN_WIDTH+(j+1)] = true; + Draw(canvas,j+1,i+1,col); + SigRenderer.depthBuffer[(i+1)*SigRenderer.SCREEN_WIDTH+(j+1)] = tex_w; + SigRenderer.translucencyBuffer[(i+1)*SigRenderer.SCREEN_WIDTH+(j+1)] = true; if (rendering_state!=TRANSLUCENT_ONLY_RENDERING) { SigRenderer.depthBuffer_tri[i*SigRenderer.SCREEN_WIDTH+j] = ref.unmodifiedTri; + SigRenderer.depthBuffer_tri[i*SigRenderer.SCREEN_WIDTH+(j+1)] = ref.unmodifiedTri; + SigRenderer.depthBuffer_tri[(i+1)*SigRenderer.SCREEN_WIDTH+j] = ref.unmodifiedTri; + SigRenderer.depthBuffer_tri[(i+1)*SigRenderer.SCREEN_WIDTH+(j+1)] = ref.unmodifiedTri; } - SigRenderer.translucencyBuffer[i*SigRenderer.SCREEN_WIDTH+j] = true; } } else { if (rendering_state!=TRANSLUCENT_ONLY_RENDERING) { Draw(canvas,j,i,col); SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+j] = tex_w; SigRenderer.depthBuffer_tri[i*SigRenderer.SCREEN_WIDTH+j] = ref.unmodifiedTri; + Draw(canvas,j,i+1,col); + SigRenderer.depthBuffer[(i+1)*SigRenderer.SCREEN_WIDTH+j] = tex_w; + SigRenderer.depthBuffer_tri[(i+1)*SigRenderer.SCREEN_WIDTH+j] = ref.unmodifiedTri; + Draw(canvas,j+1,i,col); + SigRenderer.depthBuffer[i*SigRenderer.SCREEN_WIDTH+(j+1)] = tex_w; + SigRenderer.depthBuffer_tri[i*SigRenderer.SCREEN_WIDTH+(j+1)] = ref.unmodifiedTri; + Draw(canvas,j+1,i+1,col); + SigRenderer.depthBuffer[(i+1)*SigRenderer.SCREEN_WIDTH+(j+1)] = tex_w; + SigRenderer.depthBuffer_tri[(i+1)*SigRenderer.SCREEN_WIDTH+(j+1)] = ref.unmodifiedTri; } } } } - t+=tstep; + t+=tstep*4; } } }