Profiler togling.

origin
Joshua Sigona 3 years ago
parent 87c2c555b8
commit 8e0af6413e
  1. 20
      src/sig/Panel.java
  2. 7
      src/sig/SigRenderer.java

@ -26,6 +26,7 @@ public class Panel extends JPanel implements Runnable {
private ColorModel cm;
private Thread thread;
List<Triangle> accumulatedTris = new ArrayList<Triangle>();
long profileStartTime;
public Panel() {
super(true);
@ -73,6 +74,10 @@ public class Panel extends JPanel implements Runnable {
int[] p = pixel; // this avoid crash when resizing
//a=h/w
if (SigRenderer.PROFILING) {
profileStartTime = System.currentTimeMillis();
}
final int h=SigRenderer.SCREEN_HEIGHT;
if(p.length != width * height) return;
for (int x=0;x<width;x++) {
@ -209,7 +214,9 @@ public class Panel extends JPanel implements Runnable {
}
}
}
if (SigRenderer.PROFILING) {
System.out.println((System.currentTimeMillis()-profileStartTime)+"ms");profileStartTime=System.currentTimeMillis();
}
/*Collections.sort(accumulatedTris, new Comparator<Triangle>() {
@Override
public int compare(Triangle t1, Triangle t2) {
@ -219,6 +226,8 @@ public class Panel extends JPanel implements Runnable {
}
});*/
SigRenderer.tempAnswer=null;
long totalTime=0;
long startTime2=0;
for (Triangle t : accumulatedTris) {
Triangle[] clipped = new Triangle[]{new Triangle(),new Triangle()};
@ -244,6 +253,9 @@ public class Panel extends JPanel implements Runnable {
newTriangles=triList.size();
}
if (SigRenderer.PROFILING) {
startTime2 = System.nanoTime();
}
for (Triangle tt : triList) {
if (tt.tex!=null) {
DrawUtils.TexturedTriangle(p,
@ -258,9 +270,15 @@ public class Panel extends JPanel implements Runnable {
DrawUtils.DrawTriangle(p,(int)tt.A.x,(int)tt.A.y,(int)tt.B.x,(int)tt.B.y,(int)tt.C.x,(int)tt.C.y,Color.WHITE.getRGB());
}
}
if (SigRenderer.PROFILING) {
totalTime+=System.nanoTime()-startTime2;
}
}
SigRenderer.request=null;
SigRenderer.answer=SigRenderer.tempAnswer;
if (SigRenderer.PROFILING) {
System.out.println((totalTime/1000000f)+"ms/"+(System.currentTimeMillis()-profileStartTime)+"ms");
}
}
public void repaint() {

@ -25,6 +25,7 @@ import java.awt.BorderLayout;
public class SigRenderer implements KeyListener,MouseListener,MouseMotionListener{
public static boolean WIREFRAME = false;
public static boolean PROFILING = false;
public static List<Triangle> triRender = new ArrayList<>();
public static int SCREEN_WIDTH=1280;
@ -102,7 +103,6 @@ public class SigRenderer implements KeyListener,MouseListener,MouseMotionListene
Block b = new Block(pos,new Cube(type));
blockGrid.put(pos.x+"_"+pos.y+"_"+pos.z,b);
b.updateFaces();
updateRenderGrid();
}
public static void updateRenderGrid() {
@ -121,8 +121,8 @@ public class SigRenderer implements KeyListener,MouseListener,MouseMotionListene
SigRenderer(JFrame f) {
//cube = new Mesh(OBJReader.ReadOBJFile("teapot.obj",false));
Random r = new Random(438107);
for (int x=0;x<32;x++) {
for (int z=0;z<32;z++) {
for (int x=0;x<64;x++) {
for (int z=0;z<64;z++) {
if (Math.random()<=0.5) {
addBlock(new Vector(x,0,z),BlockType.DIRT);
} else {
@ -130,6 +130,7 @@ public class SigRenderer implements KeyListener,MouseListener,MouseMotionListene
}
}
}
updateRenderGrid();
Panel p = new Panel();

Loading…
Cancel
Save