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

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

Loading…
Cancel
Save